Debian Codegraph @

contrib/ecl-cdb/ecl-help.lisp

raw
1 ;;;; -*- Mode: Lisp; Syntax: Common-Lisp; Package: SYSTEM -*-
2 ;;;;
3 ;;;; Copyright (c) 2011, Juan Jose Garcia-Ripoll.
4 ;;;;
5 ;;;; This program is free software; you can redistribute it and/or
6 ;;;; modify it under the terms of the GNU Library General Public
7 ;;;; License as published by the Free Software Foundation; either
8 ;;;; version 2 of the License, or (at your option) any later version.
9 ;;;;
10 ;;;; See file '../Copyright' for full details.
11 ;;;;
12
13 (in-package "SYSTEM")
14
15 (defun to-cdb-vector (object)
16 (let* ((vector (make-array 128 :adjustable t
17 :fill-pointer 0
18 :element-type '(unsigned-byte 8)
19 :initial-element 0))
20 (stream (ext:make-sequence-output-stream
21 vector :external-format #+unicode :utf-8 #-unicode :default)))
22 (with-standard-io-syntax
23 (let ((si::*print-package* (find-package "CL")))
24 (write object :stream stream :pretty nil
25 :readably nil :escape t)))
26 vector))
27
28 (defun from-cdb-vector (vector)
29 (let* ((stream (ext:make-sequence-input-stream
30 vector :external-format #+unicode :utf-8 #-unicode :default)))
31 (read stream nil nil nil)))
32
33 (defun search-help-file (string path)
34 (let* ((key (to-cdb-vector string))
35 (value (ecl-cdb:lookup-cdb key path)))
36 (when value
37 (from-cdb-vector value))))
38
39 (defun dump-help-file (hash-table path &optional merge test)
40 (when merge
41 (error "DUMP-HELP-FILE does not suport yet the third argument"))
42 (ecl-cdb:with-output-to-cdb (cdb nil path)
43 (loop for k being the hash-key of hash-table
44 using (hash-value v)
45 do (ecl-cdb:add-record (to-cdb-vector k)
46 (to-cdb-vector v)
47 cdb)))
48 ;; Testing the consistency of the output
49 (when test
50 (loop for k being the hash-key of hash-table
51 using (hash-value v)
52 for other-value = (search-help-file k path)
53 unless (and other-value (equalp other-value v))
54 do (error "Symbol ~A not found in database ~A" k path))))