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