]> git.donarmstrong.com Git - lilypond.git/blob - scm/documentation-lib.scm
remove tail, filter-list, filter-out-list,
[lilypond.git] / scm / documentation-lib.scm
1 ;;;
2 ;;; documentation-lib.scm -- Assorted Functions for generated documentation
3 ;;;
4 ;;; source file of the GNU LilyPond music typesetter
5 ;;; 
6 ;;; (c)  2000--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 ;;; Jan Nieuwenhuizen <janneke@gnu.org>
8
9 (use-modules (oop goops)
10              (srfi srfi-13)
11              )
12
13 (define-class <texi-node> ()
14   (children #:init-value '() #:accessor node-children #:init-keyword #:children)
15   (text #:init-value "" #:accessor node-text #:init-keyword #:text)
16   (name #:init-value "" #:accessor node-name #:init-keyword #:name)
17   (description #:init-value "" #:accessor node-desc #:init-keyword #:desc)
18   )
19
20 (define (menu-entry x)
21   (cons
22    (node-name x)
23    (node-desc x))
24   )
25
26 (define (dump-node node port level)
27   (display
28    (string-append
29     "\n@html"
30     "\n<hr>"
31     "\n@end html\n@node "
32     (node-name node)
33     "\n\n"
34     (texi-section-command level) " "
35     (node-name node)
36     "\n\n"
37     (node-text node)
38     "\n\n"
39     (if (pair? (node-children node))
40         (texi-menu
41          (map (lambda (x) (menu-entry x) )
42               (node-children node)))
43          ""))
44    port)
45   (map (lambda (x) (dump-node x port (+ 1 level)))
46         (node-children node))
47   )
48
49 (define (processing name)
50   (display (string-append "\nProcessing " name " ... ") (current-error-port)))
51
52 (define (self-evaluating? x)
53   (or (number? x) (string? x) (procedure? x) (boolean? x)))
54
55 (define (texify x)
56   x)
57
58 (define (scm->texi x)
59   (string-append "@code{" (texify (scm->string x)) "}")
60   )
61
62
63 ;;
64 ;; don't confuse users with #<procedure .. > syntax. 
65 ;; 
66 (define (scm->string val)
67   (if (and (procedure? val) (symbol? (procedure-name val)))
68       (symbol->string (procedure-name val))
69       (string-append
70        (if (self-evaluating? val) "" "'")
71        (call-with-output-string (lambda (port) (display val port)))
72        )))
73
74
75 (define (texi-section-command level)
76   (cdr (assoc level '(
77     ;; Hmm, texinfo doesn't have ``part''
78     (0 . "@top")
79     (1 . "@unnumbered")
80     (2 . "@unnumberedsec")
81     (3 . "@unnumberedsubsec")
82     (4 . "@unnumberedsubsubsec")
83     (5 . "@unnumberedsubsubsec")
84     ))))
85
86 (define (one-item->texi label-desc-pair)
87   "Document one (LABEL . DESC); return empty string if LABEL is empty string. 
88 "
89   (if (eq? (car label-desc-pair) "")
90       ""
91       (string-append "\n@item " (car label-desc-pair) "\n" (cdr label-desc-pair))
92   ))
93
94
95 (define (description-list->texi items-alist)
96   "Document ITEMS-ALIST in a table. entries contain (item-label
97 . string-to-use)
98 "
99   (string-append
100    "\n@table @asis\n"
101    (apply string-append (map one-item->texi items-alist))
102    "\n@end table\n"))
103
104 (define (texi-menu items-alist)
105   "Generate what is between @menu and @end menu."
106   (let
107       (
108        (maxwid (apply max (map (lambda (x) (string-length (car x)))
109                                items-alist)))
110        )
111     
112
113     
114   (string-append
115   "\n@menu"
116   (apply string-append
117          (map (lambda (x)
118                 (string-append
119                 (string-pad-right 
120                  (string-append "\n* " (car x) ":: ")
121                  (+ maxwid 8)
122                  )
123                 (cdr x))
124                 )
125               items-alist))
126   "\n@end menu\n"
127   ;; Menus don't appear in html, so we make a list ourselves
128   "\n@ignore\n"
129   "\n@ifhtml\n"
130   (description-list->texi (map (lambda (x) (cons (ref-ify (car x)) (cdr x)))
131                          items-alist))
132   "\n@end ifhtml\n"
133   "\n@end ignore\n")))
134
135   
136
137
138 (define (texi-file-head name file-name top)
139   (string-append
140    "\\input texinfo @c -*-texinfo-*-"
141    "\n@setfilename " file-name ".info"
142    "\n@settitle " name
143    "\n@dircategory GNU music project"
144    "\n@direntry"
145    ;; prepend GNU for dir, must be unique
146    "\n* GNU " name ": (" file-name ").          " name "."
147    "\n@end direntry"
148    ))
149
150
151 (define (context-name name)
152   name)
153
154 (define (engraver-name name)
155   name)
156
157 (define (grob-name name)
158   (if (symbol? name)
159       (symbol->string name)
160       name))
161
162 (define (interface-name name)
163   name)
164
165 (define (ref-ify x)
166   "Add ref to X"
167   (string-append "@ref{" x "}"))
168
169 (define (human-listify l)
170   "Produce a textual enumeration from L, a list of strings"
171   
172   (cond
173    ((null? l) "none")
174    ((null? (cdr l)) (car l))
175    ((null? (cddr l)) (string-append (car l) " and " (cadr l)))
176    (else (string-append (car l) ", " (human-listify (cdr l))))
177    ))
178
179 (define (writing-wip x)
180   (display (string-append "\nWriting " x " ... ") (current-error-port)))
181
182
183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
184 ;; property  stuff.
185
186 (define (property->texi where sym)
187   "Document SYM for WHERE (which can be translation, backend, music)"
188   (let* (
189          (name (symbol->string sym))
190          (type?-name (string->symbol
191                       (string-append (symbol->string where) "-type?")))
192          (doc-name (string->symbol                  
193                     (string-append (symbol->string where) "-doc")))
194          (type (object-property sym type?-name))
195          (typename (type-name type))
196          (desc (object-property sym doc-name)))
197
198     (if (eq? desc #f)
199         (error "No description for property ~S" sym)
200         )
201     (cons
202      (string-append "@code{" name "} "
203                     "(" typename ")")
204      desc)
205      
206     ))
207
208 (define (document-property-value sym alist)
209   "Extract value for SYM from ALIST, return as texi string"
210   (let* ((handle (assoc sym alist)))
211     (if (eq? handle #f)
212         "(unset)"
213         (scm->texi (cdr handle)))))
214
215 (define (backend-property->texi sym)
216   (property->texi 'backend sym))
217
218 (define (document-property sym where alist)
219   "Document SYM. If GROB-DESCRIPTION is not #f, it's an alist
220 containing default values."
221   (let*
222       ((without (property->texi where sym))
223        (rv
224
225         (cons (car without)
226               (if (eq? alist #f)
227                   (cdr without)
228                   (string-append
229                    (cdr without)
230                    "\nDefault value: "
231                    (document-property-value sym alist))))))
232     rv))