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