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