]> git.donarmstrong.com Git - lilypond.git/blob - scm/lily.scm
Merge with master
[lilypond.git] / scm / lily.scm
1 ;;;; lily.scm -- toplevel Scheme stuff
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c) 1998--2006 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 ;; Internationalisation: (_i "to be translated") gets an entry in the
9 ;; POT file (gettext ) must be invoked explicitely to do the actual
10 ;; "translation".
11 ;;(define-macro (_i x) x)
12 ;;(define-macro-public _i (x) x)
13 ;;(define-public-macro _i (x) x)
14 ;; Abbrv-PWR!
15 (defmacro-public _i (x) x)
16
17 (read-enable 'positions)
18 (debug-enable 'debug)
19
20
21
22 (define scheme-options-definitions
23   `(
24
25     ;; NAMING: either
26
27     ;; - [subject-]object-object-verb +"ing"
28     ;; - [subject-]-verb-object-object
29
30     (anti-alias-factor 1 "render at higher resolution and scale down result\nto prevent jaggies in PNG")
31     (check-internal-types #f "check every property assignment for types")
32     (clip-systems #f "Generate cut-out snippets of a score")
33     (debug-gc #f "dump memory debugging statistics")
34     (debug-gc-assert-parsed-dead #f "for memory debugging:
35 ensure that all refs to parsed objects are dead.  This is an internal option, and is switched on automatically for -ddebug-gc.") 
36     (debug-lexer #f "debug the flex lexer")
37     (debug-parser #f "debug the bison parser")
38     (debug-skylines #f "debug skylines")
39     (delete-intermediate-files #f
40                                "delete unusable PostScript files")
41     (dump-profile #f "dump timing information for each file")
42     (dump-signatures #f "dump output signatures of each system.  Used for regression testing.")
43     
44     (eps-box-padding #f "Pad EPS bounding box left edge.  Guarantee alignment between systems in LaTeX.")
45     (gs-load-fonts #f
46                    "load fonts via Ghostscript.")
47     (gui #f "running from gui; redirect stderr to log file")
48     (help #f "show this help.") 
49     (include-book-title-preview #t "include book-titles in preview images.")
50     (include-eps-fonts #t "Include fonts in separate-system EPS files.")
51     (job-count #f "Process in parallel") 
52     (log-file #f "redirect output to log FILE.log")
53
54     (old-relative #f
55                   "relative for simultaneous music works
56 similar to chord syntax")
57     (point-and-click #t "use point & click")
58     (paper-size "a4" "the default paper size")
59     (pixmap-format "png16m" "GS format to use for pixel images")
60     (protected-scheme-parsing #t "continue when finding errors in inline
61 scheme are caught in the parser. If off, halt 
62 on errors, and print a stack trace.")
63     (profile-property-accesses #f "keep statistics of get_property() calls.")
64     
65     (resolution 101 "resolution for generating PNG bitmaps")
66     (read-file-list #f "Read files to be processed from command line arguments")
67
68     (safe #f "Run safely")
69     (strict-infinity-checking #f "If yes, crash on encountering Inf/NaN.")
70     (separate-log-files #f "Output to FILE.log per file.")
71     (trace-memory-frequency #f "Record Scheme cell usage this many times per second, and dump to file.")
72     (trace-scheme-coverage #f "Record coverage of Scheme files") 
73     (ttf-verbosity 0
74                    "how much verbosity for TTF font embedding?")
75     (show-available-fonts #f
76                           "List font names available.")
77     (verbose ,(ly:command-line-verbose?) "value for the --verbose flag")
78     ))
79
80 ;; need to do this in the beginning. Other parts of the
81 ;; Scheme init depend on these options.
82 ;;
83 (for-each
84  (lambda (x)
85    (ly:add-option (car x) (cadr x) (caddr x)))
86  scheme-options-definitions)
87
88 (for-each
89  (lambda (x)
90    (ly:set-option (car x) (cdr x)))
91  (eval-string (ly:command-line-options)))
92
93 (debug-set! stack 0)
94
95 (if (defined? 'set-debug-cell-accesses!)
96     (set-debug-cell-accesses! #f))
97
98                                         ;(set-debug-cell-accesses! 1000)
99
100 (use-modules (ice-9 regex)
101              (ice-9 safe)
102              (ice-9 rdelim)
103              (ice-9 optargs)
104              (oop goops)
105              (srfi srfi-1)
106              (srfi srfi-13)
107              (srfi srfi-14)
108              (scm clip-region)
109              (scm memory-trace)
110              (scm coverage)
111              )
112
113 ;; my display
114 (define-public (myd k v) (display k) (display ": ") (display v) (display ", ")
115   v)
116
117 (define-public (print . args)
118   (apply format (cons (current-output-port) args)))
119
120
121 ;;; General settings
122 ;;; debugging evaluator is slower.  This should
123 ;;; have a more sensible default.
124
125 (if (or (ly:get-option 'verbose)
126         (ly:get-option 'trace-memory-frequencency)
127         (ly:get-option 'trace-scheme-coverage)
128         )
129     (begin
130       (ly:set-option 'protected-scheme-parsing #f)
131       (debug-enable 'debug)
132       (debug-enable 'backtrace)
133       (read-enable 'positions)))
134
135
136 (if (ly:get-option 'trace-scheme-coverage)
137     (coverage:enable))
138
139 (define-public tex-backend?
140   (member (ly:output-backend) '("texstr" "tex")))
141
142 (define-public parser #f)
143
144 (define-public (lilypond-version)
145   (string-join
146    (map (lambda (x) (if (symbol? x)
147                         (symbol->string x)
148                         (number->string x)))
149         (ly:version))
150    "."))
151
152
153 ;; TeX C++ code actually hooks into TEX_STRING_HASHLIMIT 
154 (define-public TEX_STRING_HASHLIMIT 10000000)
155
156
157
158 ;; gettext wrapper for guile < 1.7.2
159 (if (defined? 'gettext)
160     (define-public _ gettext)
161     (define-public _ ly:gettext))
162
163 (define-public (ly:load x)
164   (let* ((file-name (%search-load-path x)))
165     (if (ly:get-option 'verbose)
166         (ly:progress "[~A" file-name))
167     (if (not file-name)
168         (ly:error (_ "cannot find: ~A") x))
169     (primitive-load file-name)
170     (if (ly:get-option 'verbose)
171         (ly:progress "]"))))
172
173 ;; Cygwin
174 ;; #(CYGWIN_NT-5.1 Hostname 1.5.12(0.116/4/2) 2004-11-10 08:34 i686)
175 ;;
176 ;; Debian
177 ;; #(Linux hostname 2.4.27-1-686 #1 Fri Sep 3 06:28:00 UTC 2004 i686)
178 ;;
179 ;; Mingw
180 ;; #(Windows XP HOSTNAME build 2600 5.01 Service Pack 1 i686)
181 ;;
182
183 ;; ugh, code dup.
184 (define-public PLATFORM
185   (string->symbol
186    (string-downcase
187     (car (string-tokenize (vector-ref (uname) 0) char-set:letter)))))
188
189 (define-public DOS
190   (let ((platform (string-tokenize
191                    (vector-ref (uname) 0) char-set:letter+digit)))
192     (if (null? (cdr platform)) #f
193         (member (string-downcase (cadr platform)) '("95" "98" "me")))))
194
195 (case PLATFORM
196   ((windows)
197    (define native-getcwd getcwd)
198    (define (slashify x)
199      (if (string-index x #\\)
200          x
201          (string-regexp-substitute
202           "//*" "/"
203           (string-regexp-substitute "\\\\" "/" x))))
204    ;; FIXME: this prints a warning.
205    (define-public (ly-getcwd)
206      (slashify (native-getcwd))))
207   (else (define-public ly-getcwd getcwd)))
208
209 (define-public (is-absolute? file-name)
210   (let ((file-name-length (string-length file-name)))
211     (if (= file-name-length 0)
212         #f
213         (or (eq? (string-ref file-name 0) #\/)
214             (and (eq? PLATFORM 'windows)
215                  (> file-name-length 2)
216                  (eq? (string-ref file-name 1) #\:)
217                  (eq? (string-ref file-name 2) #\/))))))
218
219 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
220
221 (define (type-check-list location signature arguments)
222   "Typecheck a list of arguments against a list of type
223 predicates. Print a message at LOCATION if any predicate failed."
224
225   (define (recursion-helper signature arguments count) 
226     (define (helper pred? arg count) 
227       (if (not (pred? arg))
228
229           (begin
230             (ly:input-message
231              location
232              (format
233               #f (_ "wrong type for argument ~a.  Expecting ~a, found ~s")
234               count (type-name pred?) arg))
235             #f)
236           #t))
237
238     (if (null? signature)
239         #t
240         (and (helper (car signature) (car arguments) count)
241              (recursion-helper (cdr signature) (cdr arguments) (1+ count)))))
242
243   (recursion-helper signature arguments 1))
244
245 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
246 ;;  output
247
248
249 ;;(define-public (output-framework) (write "hello\n"))
250
251 (define output-tex-module
252   (make-module 1021 (list (resolve-interface '(scm output-tex)))))
253 (define output-ps-module
254   (make-module 1021 (list (resolve-interface '(scm output-ps)))))
255
256 (define-public (ps-output-expression expr port)
257   (display (eval expr output-ps-module) port))
258
259 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
260 ;; Safe definitions utility
261 (define safe-objects (list))
262
263 (define-macro (define-safe-public arglist . body)
264   "Define a variable, export it, and mark it as safe, ie usable in LilyPond safe mode.
265 The syntax is the same as `define*-public'."
266   (define (get-symbol arg)
267     (if (pair? arg)
268         (get-symbol (car arg))
269         arg))
270   (let ((safe-symbol (get-symbol arglist)))
271     `(begin
272        (define*-public ,arglist
273          ,@body)
274        (set! safe-objects (cons (cons ',safe-symbol ,safe-symbol)
275                                 safe-objects))
276        ,safe-symbol)))
277
278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
279 ;; init pitch system
280
281 (ly:set-default-scale (ly:make-scale #(0 1 2 5/2 7/2 9/2 11/2)))
282
283
284
285 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
286 ;; other files.
287
288
289 (define
290   init-scheme-files
291   '("lily-library.scm"
292             "file-cache.scm"
293             "define-event-classes.scm"
294             "define-music-types.scm"
295             "output-lib.scm"
296             "c++.scm"
297             "chord-ignatzek-names.scm"
298             "chord-entry.scm"
299             "chord-generic-names.scm"
300             "stencil.scm"
301             "markup.scm"
302             "music-functions.scm"
303             "part-combiner.scm"
304             "autochange.scm"
305             "define-music-properties.scm"
306             "auto-beam.scm"
307             "chord-name.scm"
308
309             "parser-ly-from-scheme.scm"
310             "ly-syntax-constructors.scm"
311             
312             "define-context-properties.scm"
313             "translation-functions.scm"
314             "script.scm"
315             "midi.scm"
316             "layout-beam.scm"
317             "parser-clef.scm"
318             "layout-slur.scm"
319             "font.scm"
320             "encoding.scm"
321             
322             "fret-diagrams.scm"
323             "define-markup-commands.scm"
324             "define-grob-properties.scm"
325             "define-grobs.scm"
326             "define-grob-interfaces.scm"
327             "define-stencil-commands.scm"
328             "titling.scm"
329             
330             "paper.scm"
331             "backend-library.scm"
332             "x11-color.scm"
333
334             ;; must be after everything has been defined
335             "safe-lily.scm"))
336
337
338 (for-each ly:load init-scheme-files)
339
340
341 (set! type-p-name-alist
342       `(
343         (,boolean-or-symbol? . "boolean or symbol")
344         (,boolean? . "boolean")
345         (,char? . "char")
346         (,grob-list? . "list of grobs")
347         (,hash-table? . "hash table")
348         (,input-port? . "input port")
349         (,integer? . "integer")
350         (,list? . "list")
351         (,ly:context? . "context")
352         (,ly:dimension? . "dimension, in staff space")
353         (,ly:dir? . "direction")
354         (,ly:duration? . "duration")
355         (,ly:grob? . "layout object")
356         (,ly:input-location? . "input location")
357         (,ly:moment? . "moment")
358         (,ly:music? . "music")
359         (,ly:pitch? . "pitch")
360         (,ly:translator? . "translator")
361         (,ly:font-metric? . "font metric")
362         (,ly:simple-closure? . "simple closure")
363         (,markup-list? . "list of markups")
364         (,markup? . "markup")
365         (,ly:music-list? . "list of music")
366         (,number-or-grob? . "number or grob")
367         (,number-or-string? . "number or string")
368         (,number-pair? . "pair of numbers")
369         (,number? . "number")
370         (,output-port? . "output port")   
371         (,pair? . "pair")
372         (,procedure? . "procedure")
373         (,rhythmic-location? . "rhythmic location")
374         (,scheme? . "any type")
375         (,string? . "string")
376         (,symbol? . "symbol")
377         (,vector? . "vector")))
378
379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
380 ;; timing
381
382 (define (profile-measurements)
383   (let* ((t (times))
384          (stats (gc-stats)))
385     
386     (list
387      (- (+ (tms:cutime t)
388            (tms:utime t))
389         (ly:assoc-get 'gc-time-taken stats))
390      
391      (ly:assoc-get 'total-cells-allocated  stats 0)
392      )))
393
394 (define (dump-profile base last this)
395   (let*
396       ((outname (format "~a.profile" (basename base ".ly")))
397        (diff (map (lambda (y) (apply - y)) (zip this last))))
398     
399     (ly:progress "\nWriting timing to ~a..." outname)
400     (format (open-file outname "w")
401             "time: ~a\ncells: ~a\n"
402             (car diff)
403             (cadr diff)
404             )))
405
406
407 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
408 ;; debug mem leaks
409
410 (define gc-dumping #f)
411 (define gc-protect-stat-count 0)
412
413 (define-public (dump-live-object-stats outfile)
414   (for-each
415    (lambda (x)
416      (format outfile "~a: ~a\n" (car x) (cdr x)))
417    (sort (gc-live-object-stats)
418          (lambda (x y)
419            (string<? (car x) (car y))))))
420
421 (define-public (dump-gc-protects)
422   (set! gc-protect-stat-count (1+ gc-protect-stat-count))
423   (let* ((protects (sort
424                     (hash-table->alist (ly:protects))
425                     (lambda (a b)
426                       (< (object-address (car a))
427                          (object-address (car b))))))
428
429          (out-file-name (string-append
430                          "gcstat-" (number->string gc-protect-stat-count)
431                          ".scm"))
432          (outfile    (open-file  out-file-name  "w")))
433
434     (set! gc-dumping #t)
435     (display (format "Dumping GC statistics ~a...\n" out-file-name))
436     (display
437      (map (lambda (y)
438             (let ((x (car y))
439                   (c (cdr y)))
440               (display 
441                (format "~a (~a) = ~a\n" (object-address x) c x)
442                outfile)))
443           (filter
444            (lambda (x)
445              (not (symbol? (car x))))
446            protects))
447      outfile)
448
449     (format outfile "\nprotected symbols: ~a\n"
450             (length (filter symbol?  (map car protects))))
451     
452              
453
454     ;; (display (ly:smob-protects))
455     (newline outfile)
456     (if (defined? 'gc-live-object-stats)
457         (let* ((stats #f))
458           (display "Live object statistics: GC'ing\n")
459           (ly:reset-all-fonts)
460           (gc)
461           (gc)
462           (display "Asserting dead objects\n")
463           (ly:set-option 'debug-gc-assert-parsed-dead #t)
464           (gc)
465           (ly:set-option 'debug-gc-assert-parsed-dead #f)
466
467           (set! stats (gc-live-object-stats))
468           (display "Dumping live object statistics.\n")
469           (dump-live-object-stats outfile)))
470
471     (newline outfile)
472     (let*
473         ((stats (gc-stats)))
474       
475       (for-each
476        (lambda (sym)
477          (display
478           (format "~a ~a ~a\n"
479                   gc-protect-stat-count
480                   sym
481                   (let ((sym-stat (assoc sym stats)))
482                     (if sym-stat 
483                         (cdr sym-stat)
484                         "?")))
485           outfile))
486        '(protected-objects bytes-malloced cell-heap-size
487                            
488                            )))
489
490     (set! gc-dumping #f)
491     (close-port outfile)
492     
493     ))
494
495
496 (define (check-memory)
497   "read /proc/self to check up on memory use." 
498   (define (gulp-file name)
499     (let* ((file (open-input-file name))
500            (text (read-delimited "" file)))
501       (close file)
502       text))
503   (let*
504       ((stat (gulp-file "/proc/self/status"))
505        (lines (string-split stat #\newline))
506        (interesting (filter identity
507                             (map
508                              (lambda (l)
509                                (string-match "^VmData:[ \t]*([0-9]*) kB" l))
510                              lines)))
511        (mem (string->number (match:substring (car interesting) 1)))
512        )
513
514     
515     (display (format  "VMDATA: ~a\n" mem))
516     (display (gc-stats))
517     (if (> mem 100000)
518         (begin
519           (dump-gc-protects)
520           (raise 1)))
521     
522     ))
523
524 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
525
526
527 (define (multi-fork count)
528   (define (helper count acc)
529     (if (> count 0)
530       (let*
531           ((pid  (primitive-fork)))
532         (if (= pid 0)
533             (1- count)
534             (helper (1- count) (cons pid acc))))
535       acc))
536   (helper count '()))
537
538
539 (define-public (lilypond-main files)
540   "Entry point for LilyPond."
541
542   (define (no-files-handler)
543     (ly:usage)
544     (exit 2))
545
546   (eval-string (ly:command-line-code))
547   
548   (if (ly:get-option 'gui)
549       (gui-main files))
550
551   (if (null? files)
552       (no-files-handler))
553
554   (if (ly:get-option 'read-file-list)
555       (set! files
556             (filter (lambda (s)
557                       (> (string-length s) 0))
558                     (apply append
559                            (map (lambda (f) (string-split (ly:gulp-file f) #\nl))
560                                 files)))
561             ))
562   
563   (if (and (number? (ly:get-option 'job-count))
564            (>= (length files) (ly:get-option 'job-count)))
565       
566       (let*
567           ((count (ly:get-option 'job-count))
568            (split-todo (split-list files count)) 
569            (joblist (multi-fork count))
570            (errors '()))
571
572         (if (not (string-or-symbol? (ly:get-option 'log-file)))
573             (ly:set-option 'log-file "lilypond-multi-run"))
574         
575         (if (number? joblist)
576             (begin
577               (ly:set-option 'log-file (format "~a-~a"
578                                                (ly:get-option 'log-file) joblist))
579               (set! files (vector-ref split-todo joblist)))
580
581             (begin
582               (ly:progress "\nForking into jobs:  ~a\n" joblist)
583               (for-each
584                (lambda (pid)
585                  (let* ((stat (cdr (waitpid pid))))
586                    
587                    (if (not (= stat 0))
588                        (set! errors (acons (list-element-index joblist pid) stat errors)))))
589                joblist)
590
591               (for-each
592                (lambda (x)
593                  (let* ((job (car x))
594                         (state (cdr x))
595                         (logfile  (format "~a-~a.log"
596                                           (ly:get-option 'log-file) job))
597                         (log (ly:gulp-file logfile))
598                         (len (string-length log))
599                         (tail (substring  log (max 0 (- len 1024)))))
600
601                    (if (status:term-sig state)
602                        (ly:message "\n\n~a\n"
603                                    (format (_ "job ~a terminated with signal: ~a")
604                                            job
605                                            (status:term-sig state)))
606                        (ly:message (_ "logfile ~a (exit ~a):\n~a") logfile (status:exit-val state) tail))))
607
608                errors)
609
610               (if (pair? errors)
611                   (ly:error "Children ~a exited with errors." (map car errors)))
612
613               ;; must overwrite individual entries
614               (if (ly:get-option 'dump-profile)
615                   (dump-profile "lily-run-total" '(0 0) (profile-measurements)))
616
617             (exit (if (null? errors) 0 1))))))
618               
619            
620   (if (string-or-symbol? (ly:get-option 'log-file))
621       (ly:stderr-redirect (format "~a.log" (ly:get-option 'log-file)) "w"))
622
623   
624   (let ((failed (lilypond-all files)))
625     (if (ly:get-option 'trace-scheme-coverage)
626         (begin
627           (coverage:show-all (lambda (f) (string-contains f "lilypond"))
628                              )))
629           
630     
631     (if (pair? failed)
632         (begin
633           (ly:error (_ "failed files: ~S") (string-join failed))
634           (exit 1))
635         (begin
636           (ly:do-atexit)
637           ;; HACK: be sure to exit with single newline
638           (ly:message "")
639           (exit 0)))))
640
641 (define-public (lilypond-all files)
642   (if (ly:get-option 'help)
643       (begin
644         (ly:option-usage)
645         (exit 0)))
646   (if (ly:get-option 'show-available-fonts)
647       (begin
648         (ly:font-config-display-fonts)
649         (exit 0)
650         ))
651   
652   (let* ((failed '())
653          (separate-logs (ly:get-option 'separate-log-files))
654          (do-measurements (ly:get-option 'dump-profile))
655          (handler (lambda (key failed-file)
656                     (set! failed (append (list failed-file) failed)))))
657
658     (gc)
659     (for-each
660      (lambda (x)
661        (let*
662            ((start-measurements (if do-measurements
663                                     (profile-measurements)
664                                     #f))
665             (base (basename x ".ly"))
666             (all-settings (ly:all-options)))
667
668          (if separate-logs
669              (ly:stderr-redirect (format "~a.log" base) "w"))
670          (if (ly:get-option 'trace-memory-frequency) 
671              (mtrace:start-trace  (ly:get-option 'trace-memory-frequency)))
672          
673          (lilypond-file handler x)
674          (if start-measurements
675              (dump-profile x start-measurements (profile-measurements)))
676
677          (if (ly:get-option 'trace-memory-frequency)
678              (begin
679                (mtrace:stop-trace)
680                (mtrace:dump-results base)))
681                  
682          (for-each
683           (lambda (s)
684             (ly:set-option (car s) (cdr s)))
685           all-settings)
686
687          (ly:clear-anonymous-modules)
688          (ly:set-option 'debug-gc-assert-parsed-dead #t)
689          (gc)
690          (ly:set-option 'debug-gc-assert-parsed-dead #f)
691
692          
693          (if (ly:get-option 'debug-gc)
694              (dump-gc-protects)
695              (if (= (random 40) 1)
696                  (ly:reset-all-fonts)))))
697
698      files)
699
700     ;; we want the failed-files notice in the aggregrate logfile.
701     (if (ly:get-option 'separate-logs)
702         (ly:stderr-redirect
703          (if (string-or-symbol? (ly:get-option 'log-file))
704              (format "~a.log" (ly:get-option 'log-file))
705              "/dev/tty") "a"))
706
707     (if (ly:get-option 'dump-profile)
708         (dump-profile "lily-run-total" '(0 0) (profile-measurements)))
709
710     failed))
711
712 (define (lilypond-file handler file-name)
713   (catch 'ly-file-failed
714          (lambda () (ly:parse-file file-name))
715          (lambda (x . args) (handler x file-name))))
716
717 (use-modules (scm editor))
718
719 (define-public (gui-main files)
720   (if (null? files)
721       (gui-no-files-handler))
722
723   (if (not (string? (ly:get-option 'log-file)))
724       (let* ((base (basename (car files) ".ly"))
725              (log-name (string-append base ".log")))
726         (if (not (ly:get-option 'gui))
727             (ly:message (_ "Redirecting output to ~a...") log-name))
728         (ly:stderr-redirect log-name "w")
729         (ly:message "# -*-compilation-*-"))
730     
731     (let ((failed (lilypond-all files)))
732       (if (pair? failed)
733           (begin
734             ;; ugh
735             (ly:stderr-redirect "foo" "r")
736             (system (get-editor-command log-name 0 0 0))
737             (ly:error (_ "failed files: ~S") (string-join failed))
738             ;; not reached?
739             (exit 1))
740           (exit 0)))))
741
742 (define (gui-no-files-handler)
743   (let* ((ly (string-append (ly:effective-prefix) "/ly/"))
744          ;; FIXME: soft-code, localize
745          (welcome-ly (string-append ly "Welcome_to_LilyPond.ly"))
746          (cmd (get-editor-command welcome-ly 0 0 0)))
747     (ly:message (_ "Invoking `~a'...") cmd)
748     (system cmd)
749     (exit 1)))