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