2 ;;; documentation-lib.scm -- Assorted Functions for generated documentation
4 ;;; source file of the GNU LilyPond music typesetter
6 ;;; (c) 2000--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 ;;; Jan Nieuwenhuizen <janneke@gnu.org>
9 (use-modules (oop goops))
11 (define-class <texi-node> ()
12 (children #:init-value '() #:accessor node-children #:init-keyword #:children)
13 (text #:init-value "" #:accessor node-text #:init-keyword #:text)
14 (name #:init-value "" #:accessor node-name #:init-keyword #:name)
15 (description #:init-value "" #:accessor node-desc #:init-keyword #:desc)
18 (define (menu-entry x)
24 (define (dump-node node port level)
32 (texi-section-command level) " "
37 (if (pair? (node-children node))
39 (map (lambda (x) (menu-entry x) )
40 (node-children node)))
43 (map (lambda (x) (dump-node x port (+ 1 level)))
47 (define (processing name)
48 (display (string-append "\nProcessing " name " ... ") (current-error-port)))
50 (define (self-evaluating? x)
51 (or (number? x) (string? x) (procedure? x) (boolean? x)))
57 (string-append "@code{" (texify (scm->string x)) "}")
62 ;; don't confuse users with #<procedure .. > syntax.
64 (define (scm->string val)
65 (if (and (procedure? val) (symbol? (procedure-name val)))
66 (symbol->string (procedure-name val))
68 (if (self-evaluating? val) "" "'")
69 (call-with-output-string (lambda (port) (display val port)))
73 (define (texi-section-command level)
75 ;; Hmm, texinfo doesn't have ``part''
78 (2 . "@unnumberedsec")
79 (3 . "@unnumberedsubsec")
80 (4 . "@unnumberedsubsubsec")
81 (5 . "@unnumberedsubsubsec")
84 (define (one-item->texi label-desc-pair)
85 "Document one (LABEL . DESC); return empty string if LABEL is empty string.
87 (if (eq? (car label-desc-pair) "")
89 (string-append "\n@item " (car label-desc-pair) "\n" (cdr label-desc-pair))
93 (define (description-list->texi items-alist)
94 "Document ITEMS-ALIST in a table. entries contain (item-label
99 (apply string-append (map one-item->texi items-alist))
102 (define (texi-menu items-alist)
103 "Generate what is between @menu and @end menu."
106 (maxwid (apply max (map (lambda (x) (string-length (car x)))
118 (string-append "\n* " (car x) ":: ")
125 ;; Menus don't appear in html, so we make a list ourselves
128 (description-list->texi (map (lambda (x) (cons (ref-ify (car x)) (cdr x)))
136 (define (texi-file-head name file-name top)
138 "\\input texinfo @c -*-texinfo-*-"
139 "\n@setfilename " file-name ".info"
141 "\n@dircategory GNU music project"
143 ;; prepend GNU for dir, must be unique
144 "\n* GNU " name ": (" file-name "). " name "."
149 (define (context-name name)
152 (define (engraver-name name)
155 (define (grob-name name)
157 (symbol->string name)
160 (define (interface-name name)
165 (string-append "@ref{" x "}"))
167 (define (human-listify l)
168 "Produce a textual enumeration from L, a list of strings"
172 ((null? (cdr l)) (car l))
173 ((null? (cddr l)) (string-append (car l) " and " (cadr l)))
174 (else (string-append (car l) ", " (human-listify (cdr l))))
177 (define (writing-wip x)
178 (display (string-append "\nWriting " x " ... ") (current-error-port)))
182 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
185 (define (property->texi where sym)
186 "Document SYM for WHERE (which can be translation, backend, music)"
188 (name (symbol->string sym))
189 (type?-name (string->symbol
190 (string-append (symbol->string where) "-type?")))
191 (doc-name (string->symbol
192 (string-append (symbol->string where) "-doc")))
193 (type (object-property sym type?-name))
194 (typename (type-name type))
195 (desc (object-property sym doc-name)))
198 (error "No description for property ~S" sym)
201 (string-append "@code{" name "} "
207 (define (document-property-value sym alist)
208 "Extract value for SYM from ALIST, return as texi string"
209 (let* ((handle (assoc sym alist)))
212 (scm->texi (cdr handle)))))
215 (define (backend-property->texi sym)
216 (property->texi 'backend sym))
218 (define (document-property sym where alist)
219 "Document SYM. If GROB-DESCRIPTION is not #f, it's an alist
220 containing default values."
222 ((without (property->texi where sym))
231 (document-property-value sym alist)))))