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