1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;;; GNU General Public License for more details.
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
19 (use-modules (oop goops)
23 (define-class <texi-node> ()
24 (appendix #:init-value #f #:accessor appendix? #:init-keyword #:appendix)
25 (children #:init-value '() #:accessor node-children #:init-keyword #:children)
26 (text #:init-value "" #:accessor node-text #:init-keyword #:text)
27 (name #:init-value "" #:accessor node-name #:init-keyword #:name)
28 (description #:init-value "" #:accessor node-desc #:init-keyword #:desc))
30 (define (menu-entry x)
35 (define* (dump-node node port level)
39 (if (= level 0) "Top" (node-name node))
42 (texi-appendix-section-command level)
43 (texi-section-command level))
49 (if (pair? (node-children node))
51 (map (lambda (x) (menu-entry x))
52 (node-children node)))
55 (for-each (lambda (x) (dump-node x port (+ 1 level)))
56 (node-children node)))
58 (define (processing name)
59 (ly:basic-progress (_ "Processing ~S...") name))
61 (define (self-evaluating? x)
62 (or (number? x) (string? x) (procedure? x) (boolean? x)))
68 (string-append "@code{" (texify (scm->string x)) "}"))
72 (define (texi-section-command level)
74 ;; Hmm, texinfo doesn't have ``part''
79 (4 . "@unnumberedsubsubsec")
80 (5 . "@unnumberedsubsubsec"))))
82 (define (texi-appendix-section-command level)
83 (assoc-get level '((0 . "@top")
86 (3 . "@appendixsubsec")
87 (4 . "@appendixsubsubsec")
88 (5 . "@appendixsubsubsec"))))
90 (define (one-item->texi label-desc-pair)
91 "Document one (LABEL . DESC); return empty string if LABEL is empty string."
92 (if (eq? (car label-desc-pair) "")
94 (string-append "\n@item " (car label-desc-pair) "\n" (cdr label-desc-pair))))
97 (define (description-list->texi items-alist quote?)
98 "Document ITEMS-ALIST in a table; entries contain (item-label .
99 string-to-use). If QUOTE? is #t, embed table in a @quotation environment."
102 (if quote? "@quotation\n" "")
104 (string-concatenate (map one-item->texi items-alist))
107 (if quote? "@end quotation\n" "")))
109 (define (texi-menu items-alist)
110 "Generate what is between @menu and @end menu."
112 (apply max (map (lambda (x) (string-length (car x))) items-alist))))
120 (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)))
134 (define (texi-file-head name file-name top)
136 "\\input texinfo @c -*-texinfo-*-"
137 "\n@setfilename " file-name ".info"
139 "\n@dircategory LilyPond"
141 ;; prepend GNU for dir, must be unique
142 "\n* GNU " name ": (" file-name "). " name "."
144 "@documentlanguage en\n"
145 "@documentencoding utf-8\n"))
147 (define (context-name name)
150 (define (engraver-name name)
153 (define (grob-name name)
155 (symbol->string name)
158 (define (interface-name name)
162 "Return @ref{X}. If mapping ref-ify to a list that needs to be sorted,
163 sort the list first."
164 (string-append "@ref{" x "}"))
166 (define (human-listify lst)
167 "Produce a textual enumeration from LST, a list of strings"
171 ((null? (cdr lst)) (car lst))
172 ((null? (cddr lst)) (string-append (car lst) " and " (cadr lst)))
173 (else (string-append (car lst) ", " (human-listify (cdr lst))))))
175 (define (writing-wip x)
176 (ly:message (_ "Writing ~S...") x))
178 (define (identifier<? a b)
180 (symbol->string (car a))
181 (symbol->string (car b))))
183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
186 (define (verify-type-name where sym type)
188 (ly:error (_ "cannot find description for property `~S' (~S)")
193 (define (property->texi where sym . rest)
194 "Document SYM for WHERE (which can be translation, backend, music),
195 with init values from ALIST (1st optional argument)
197 (let* ((name (symbol->string sym))
198 (alist (if (pair? rest) (car rest) '()))
199 (type?-name (string->symbol
200 (string-append (symbol->string where) "-type?")))
201 (doc-name (string->symbol
202 (string-append (symbol->string where) "-doc")))
203 (type (object-property sym type?-name))
204 (typename (verify-type-name where sym type))
205 (desc (object-property sym doc-name))
206 (init-value (assoc-get sym alist)))
209 (ly:error (_ "cannot find description for property ~S (~S)") sym where))
212 (string-append "@code{" name "} "
217 (scm->texi init-value)