]> git.donarmstrong.com Git - lilypond.git/blob - scm/lily.scm
(sane_putenv): Oops. Should supply a private copy
[lilypond.git] / scm / lily.scm
1 ;;;; lily.scm -- implement Scheme output routines for TeX and PostScript
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8 ;;; Library functions
9
10 (use-modules (ice-9 regex))
11
12 ;;(write standalone (current-error-port))
13
14 ; (set-debug-cell-accesses! #t)
15
16 ;;; General settings
17
18
19
20 (debug-enable 'backtrace)
21
22
23 (define point-and-click #f)
24 (define security-paranoia #f)
25 (define midi-debug #f)
26
27 (define (line-column-location line col file)
28   "Print an input location, including column number ."
29   (string-append (number->string line) ":"
30                  (number->string col) " " file)
31   )
32
33 (define (line-location line col file)
34   "Print an input location, without column number ."
35   (string-append (number->string line) " " file)
36   )
37
38 ;; cpp hack to get useful error message
39 (define ifdef "First run this through cpp.")
40 (define ifndef "First run this through cpp.")
41   
42 (define default-script-alist '())
43 (define font-name-alist  '())
44
45 (if (not (defined? 'standalone))
46     (define standalone (not (defined? 'ly-gulp-file))))
47
48 ;; The regex module may not be available, or may be broken.
49 (define use-regex
50   (let ((os (string-downcase (vector-ref (uname) 0))))
51     (not (equal? "cygwin" (substring os 0 (min 6 (string-length os)))))))
52
53 ;; If you have trouble with regex, define #f
54 (define use-regex #t)
55 ;;(define use-regex #f)
56
57
58 ;;; Un-assorted stuff
59
60 ;; URG guile-1.4/1.4.x compatibility
61 (if (not (defined? 'primitive-eval))
62     (define (primitive-eval form)
63       (eval2 form #f)))
64
65 (define (sign x)
66   (if (= x 0)
67       0
68       (if (< x 0) -1 1)))
69
70 (define (write-me n x)
71   (display n)
72   (write x)
73   (newline)
74   x)
75
76 (define (empty? x)
77   (equal? x '()))
78
79 (define (!= l r)
80   (not (= l r)))
81
82 (define (filter-list pred? list)
83   "return that part of LIST for which PRED is true."
84   (if (null? list) '()
85       (let* ((rest  (filter-list pred? (cdr list))))
86         (if (pred?  (car list))
87             (cons (car list)  rest)
88             rest))))
89
90 (define (filter-out-list pred? list)
91   "return that part of LIST for which PRED is true."
92   (if (null? list) '()
93       (let* ((rest  (filter-list pred? (cdr list))))
94         (if (not (pred?  (car list)))
95             (cons (car list)  rest)
96             rest))))
97
98 (define (uniqued-alist  alist acc)
99   (if (null? alist) acc
100       (if (assoc (caar alist) acc)
101           (uniqued-alist (cdr alist) acc)
102           (uniqued-alist (cdr alist) (cons (car alist) acc)))))
103
104 (define (uniq-list list)
105   (if (null? list) '()
106       (if (null? (cdr list))
107           list
108           (if (equal? (car list) (cadr list))
109               (uniq-list (cdr list))
110               (cons (car list) (uniq-list (cdr list)))))))
111
112 (define (alist<? x y)
113   (string<? (symbol->string (car x))
114             (symbol->string (car y))))
115
116 (define (ly-load x)
117   (let* ((fn (%search-load-path x)))
118     (if (ly-verbose)
119         (format (current-error-port) "[~A]" fn))
120     (primitive-load fn)))
121
122
123 (use-modules (scm tex)
124              (scm ps)
125              (scm pysk)
126              (scm ascii-script)
127              (scm sketch)
128              (scm pdftex)
129              )
130
131 (define output-alist
132   `(
133     ("tex" . ("TeX output. The default output form." ,tex-output-expression))
134     ("ps" . ("Direct postscript. Requires setting GS_LIB and GS_FONTPATH" ,ps-output-expression))
135     ("scm" . ("Scheme dump: debug scheme molecule expressions" ,write))
136     ("as" . ("Asci-script. Postprocess with as2txt to get ascii art"  ,as-output-expression))
137     ("sketch" . ("Bare bones Sketch output. Requires sketch 0.7" ,sketch-output-expression))
138     ("pdftex" . ("PDFTeX output. Was last seen nonfunctioning." ,pdftex-output-expression))
139     ))
140
141 (define (pad-string-to str wid)
142   (string-append str (make-string (max (- wid (string-length str)) 0) #\ ))
143   )
144
145 (define (document-format-dumpers)
146   (map
147    (lambda (x)
148      (display (string-append  (pad-string-to 5 (car x)) (cadr x) "\n"))
149      output-alist)
150    ))
151
152 (define (find-dumper format )
153   (let*
154       ((d (assoc format output-alist)))
155     
156     (if (pair? d)
157         (caddr d)
158         (scm-error "Could not find dumper for format ~s" format))
159     ))
160
161 (define X 0)
162 (define Y 1)
163 (define LEFT -1)
164 (define RIGHT 1)
165 (define UP 1)
166 (define DOWN -1)
167 (define CENTER 0)
168
169 (if (not standalone)
170     (map ly-load
171                                         ; load-from-path
172          '("output-lib.scm"
173            "c++.scm"
174            "molecule.scm"
175            "bass-figure.scm"
176            "grob-property-description.scm"
177            "context-description.scm"
178            "interface-description.scm"
179            "beam.scm"
180            "clef.scm"
181            "slur.scm"
182            "font.scm"
183            "music-functions.scm"
184            "music-property-description.scm"
185            "auto-beam.scm"
186            "basic-properties.scm"
187            "chord-name.scm"
188            "grob-description.scm"
189            "translator-property-description.scm"
190            "script.scm"
191            "drums.scm"
192            "midi.scm"
193            )))
194