1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 1998--2011 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;;; GNU General Public License for more details.
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
19 ;; Internationalisation: (_i "to be translated") gets an entry in the
20 ;; POT file; (gettext ...) must be invoked explicitly to do the actual
23 ;; (define-macro (_i x) x)
24 ;; (define-macro-public _i (x) x)
25 ;; (define-public-macro _i (x) x)
28 (defmacro-public _i (x) x)
30 ;;; Boolean thunk - are we integrating Guile V2.0 or higher with LilyPond?
31 (define-public (guile-v2)
32 (string>? (version) "1.9.10"))
34 (read-enable 'positions)
38 (debug-enable 'backtrace)
39 (debug-set! show-file-name #t)))
41 (define-public PLATFORM
44 (car (string-tokenize (utsname:sysname (uname)))))))
46 (define scheme-options-definitions
50 ;; - [subject-]object-object-verb +"ing"
51 ;; - [subject-]-verb-object-object
53 ;; Avoid overlong lines in `lilypond -dhelp'! Strings should not
54 ;; be longer than 48 characters per line.
57 "Render at higher resolution (using given factor)
58 and scale down result to prevent jaggies in
61 "Create .tex, .texi, .count files in the
64 "Select backend. Possible values: 'eps, 'null,
65 'ps, 'scm, 'socket, 'svg.")
66 (check-internal-types #f
67 "Check every property assignment for types.")
69 "Generate cut-out snippets of a score.")
71 "LilyPond prefix for data files (read-only).")
73 "Dump memory debugging statistics.")
74 (debug-gc-assert-parsed-dead #f
75 "For memory debugging: Ensure that all
76 references to parsed objects are dead. This is
77 an internal option, and is switched on
78 automatically for `-ddebug-gc'.")
80 "Debug the flex lexer.")
81 (debug-page-breaking-scoring #f
82 "Dump scores for many different page breaking
85 "Debug the bison parser.")
86 (debug-property-callbacks #f
87 "Debug cyclic callback chains.")
90 (delete-intermediate-files #t
91 "Delete unusable, intermediate PostScript files.")
93 "Dump memory and time information for each file.")
95 "Dump timing information (system-dependent).")
97 "Dump output signatures of each system. Used for
100 "Pad left edge of the output EPS bounding box by
101 given amount (in mm).")
103 "Load fonts via Ghostscript.")
104 (gs-load-lily-fonts #f
105 "Load only LilyPond fonts via Ghostscript.")
107 "Run LilyPond from a GUI and redirect stderr to
111 (include-book-title-preview #t
112 "Include book titles in preview images.")
113 (include-eps-fonts #t
114 "Include fonts in separate-system EPS files.")
116 "Include file for global settings, included before the score is processed.")
118 "Process in parallel, using the given number of
121 "If string FOO is given as argument, redirect
122 output to log file `FOO.log'.")
123 (max-markup-depth 1024
124 "Maximum depth for the markup tree. If a markup has more levels,
125 assume it will not terminate on its own, print a warning and return a
126 null markup instead.")
127 (midi-extension ,(if (eq? PLATFORM 'windows)
130 "Set the default file extension for MIDI output
131 file to given string.")
132 (music-strings-to-paths #f
133 "Convert text strings to paths when glyphs belong
136 "Make \\relative mode for simultaneous music work
137 similar to chord syntax.")
139 "Add point & click links to PDF output.")
141 "Set default paper size.")
142 (pixmap-format "png16m"
143 "Set GhostScript's output format for pixel images.")
145 "Create preview images also.")
147 "Print pages in the normal way.")
148 (protected-scheme-parsing #t
149 "Continue when errors in inline scheme are caught
150 in the parser. If #f, halt on errors and print
152 (profile-property-accesses #f
153 "Keep statistics of get_property() calls.")
155 "Set resolution for generating PNG pixmaps to
156 given value (in dpi).")
158 "Specify name of a file which contains a list of
159 input files to be processed.")
160 (relative-includes #f
161 "When processing an \\include command, look for
162 the included file relative to the current file
163 (instead of the root file)")
165 "Run in safer mode.")
166 (separate-log-files #f
167 "For input files `FILE1.ly', `FILE2.ly', ...
168 output log data to files `FILE1.log',
170 (show-available-fonts #f
171 "List available font names.")
172 (strict-infinity-checking #f
173 "Force a crash on encountering Inf and NaN
174 floating point exceptions.")
176 "Don't use directories from input files while
177 constructing output file names.")
179 "Use woff font files in SVG backend.")
180 (trace-memory-frequency #f
181 "Record Scheme cell usage this many times per
182 second. Dump results to `FILE.stacks' and
184 (trace-scheme-coverage #f
185 "Record coverage of Scheme files in `FILE.cov'.")
186 (verbose ,(ly:verbose-output?)
187 "Verbose output, i.e. loglevel at least DEBUG (read-only).")
189 "Change all warning and programming_error
190 messages into errors.")
193 ;; Need to do this in the beginning. Other parts of the Scheme
194 ;; initialization depend on these options.
196 (for-each (lambda (x)
197 (ly:add-option (car x) (cadr x) (caddr x)))
198 scheme-options-definitions)
200 (for-each (lambda (x)
201 (ly:set-option (car x) (cdr x)))
202 (eval-string (ly:command-line-options)))
206 (if (defined? 'set-debug-cell-accesses!)
207 (set-debug-cell-accesses! #f))
209 ;;(set-debug-cell-accesses! 1000)
211 (use-modules (ice-9 regex)
224 (define-public _ gettext)
225 ;;; There are new modules defined in Guile V2.0 which we need to use.
227 ;; Modules and scheme files loaded by lily.scm use currying
228 ;; in Guile V2 this needs a module which is not present in Guile V1.8
233 (ly:debug (_ "Using (ice-9 curried-definitions) module\n"))
234 (use-modules (ice-9 curried-definitions)))
236 (ly:debug (_ "Guile 1.8\n"))))
238 ;; TODO add in modules for V1.8.7 deprecated in V2.0 and integrated
239 ;; into Guile base code, like (ice-9 syncase).
242 (define-public fancy-format
245 (define-public (ergonomic-simple-format dest . rest)
246 "Like ice-9's @code{format}, but without the memory consumption."
248 (apply simple-format (cons #f (cons dest rest)))
249 (apply simple-format (cons dest rest))))
252 ergonomic-simple-format)
255 (define-public (myd k v)
262 (define-public (print . args)
263 (apply format (cons (current-output-port) args)))
266 ;;; General settings.
268 ;;; Debugging evaluator is slower. This should have a more sensible
272 (if (or (ly:get-option 'verbose)
273 (ly:get-option 'trace-memory-frequency)
274 (ly:get-option 'trace-scheme-coverage))
276 (ly:set-option 'protected-scheme-parsing #f)
277 (debug-enable 'backtrace)
278 (read-enable 'positions)))
280 (if (ly:get-option 'trace-scheme-coverage)
283 (define-public parser #f)
285 (define music-string-to-path-backends
288 (if (memq (ly:get-option 'backend) music-string-to-path-backends)
289 (ly:set-option 'music-strings-to-paths #t))
292 (define-public (ly:load x)
293 (let* ((file-name (%search-load-path x)))
294 (ly:debug "[~A" file-name)
296 (ly:error (_ "cannot find: ~A") x))
297 (primitive-load-path file-name) ;; to support Guile V2 autocompile
298 ;; TODO: Any chance to use ly:debug here? Need to extend it to prevent
299 ;; a newline in this case
300 (if (ly:get-option 'verbose)
301 (ly:progress "]\n"))))
304 (let ((platform (string-tokenize
305 (vector-ref (uname) 0) char-set:letter+digit)))
306 (if (null? (cdr platform)) #f
307 (member (string-downcase (cadr platform)) '("95" "98" "me")))))
310 (if (string-index x #\\)
312 (string-regexp-substitute
314 (string-regexp-substitute "\\\\" "/" x))))
316 (define-public (ly-getcwd)
317 (if (eq? PLATFORM 'windows)
321 (define-public (is-absolute? file-name)
322 (let ((file-name-length (string-length file-name)))
323 (if (= file-name-length 0)
325 (or (eq? (string-ref file-name 0) #\/)
326 (and (eq? PLATFORM 'windows)
327 (> file-name-length 2)
328 (eq? (string-ref file-name 1) #\:)
329 (eq? (string-ref file-name 2) #\/))))))
331 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
332 ;;; If necessary, emulate Guile V2 module_export_all! for Guile V1.8.n
335 (define (module-export-all! mod)
336 (define (fresh-interface!)
337 (let ((iface (make-module)))
338 (set-module-name! iface (module-name mod))
339 ;; for guile 2: (set-module-version! iface (module-version mod))
340 (set-module-kind! iface 'interface)
341 (set-module-public-interface! mod iface)
343 (let ((iface (or (module-public-interface mod)
344 (fresh-interface!))))
345 (set-module-obarray! iface (module-obarray mod))))))
347 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
348 (define (type-check-list location signature arguments)
349 "Typecheck a list of arguments against a list of type predicates.
350 Print a message at LOCATION if any predicate failed."
351 (define (recursion-helper signature arguments count)
352 (define (helper pred? arg count)
353 (if (not (pred? arg))
357 (_ "wrong type for argument ~a. Expecting ~a, found ~s")
358 count (type-name pred?) arg)
362 (if (null? signature)
364 (and (helper (car signature) (car arguments) count)
365 (recursion-helper (cdr signature) (cdr arguments) (1+ count)))))
366 (recursion-helper signature arguments 1))
369 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
370 ;; Safe definitions utility
375 (define-macro (define-safe-public arglist . body)
376 "Define a variable, export it, and mark it as safe, i.e. usable in
377 LilyPond safe mode. The syntax is the same as `define*-public'."
378 (define (get-symbol arg)
380 (get-symbol (car arg))
383 (let ((safe-symbol (get-symbol arglist)))
385 (define*-public ,arglist
387 (set! safe-objects (cons (cons ',safe-symbol ,safe-symbol)
391 (define-safe-public (lilypond-version)
393 (map (lambda (x) (if (symbol? x)
399 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
402 (ly:set-default-scale (ly:make-scale #(0 1 2 5/2 7/2 9/2 11/2)))
404 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
408 ;; List of Scheme files to be loaded into the (lily) module.
410 ;; - Library definitions, need to be at the head of the list
411 (define init-scheme-files-lib
414 ;; - Files containing definitions used later by other files later in load
415 (define init-scheme-files-used
416 '("markup-macros.scm"))
417 ;; - Main body of files to be loaded
418 (define init-scheme-files-body
420 "define-event-classes.scm"
421 "define-music-callbacks.scm"
422 "define-music-types.scm"
423 "define-note-names.scm"
427 "define-markup-commands.scm"
429 "modal-transforms.scm"
430 "chord-generic-names.scm"
431 "chord-ignatzek-names.scm"
432 "music-functions.scm"
435 "define-music-properties.scm"
436 "time-signature-settings.scm"
440 "parser-ly-from-scheme.scm"
441 "ly-syntax-constructors.scm"
443 "define-context-properties.scm"
444 "translation-functions.scm"
457 "define-woodwind-diagrams.scm"
458 "display-woodwind-diagrams.scm"
459 "predefined-fretboards.scm"
460 "define-grob-properties.scm"
462 "define-grob-interfaces.scm"
463 "define-stencil-commands.scm"
467 "backend-library.scm"
469 ;; - Files to be loaded last
470 (define init-scheme-files-tail
471 ;; - must be after everything has been defined
474 ;; Now construct the load list
476 (define init-scheme-files
477 (append init-scheme-files-lib
478 init-scheme-files-used
479 init-scheme-files-body
480 init-scheme-files-tail))
482 (for-each ly:load init-scheme-files)
484 (define-public r5rs-primary-predicates
485 `((,boolean? . "boolean")
486 (,char? . "character")
487 (,number? . "number")
490 (,procedure? . "procedure")
491 (,string? . "string")
492 (,symbol? . "symbol")
493 (,vector? . "vector")))
495 (define-public r5rs-secondary-predicates
496 `((,char-alphabetic? . "alphabetic character")
497 (,char-lower-case? . "lower-case character")
498 (,char-numeric? . "numeric character")
499 (,char-upper-case? . "upper-case character")
500 (,char-whitespace? . "whitespace character")
502 (,complex? . "complex number")
503 (,even? . "even number")
504 (,exact? . "exact number")
505 (,inexact? . "inexact number")
506 (,integer? . "integer")
507 (,negative? . "negative number")
508 (,odd? . "odd number")
509 (,positive? . "positive number")
510 (,rational? . "rational number")
511 (,real? . "real number")
517 (,input-port? . "input port")
518 (,output-port? . "output port")
520 ;; would this ever be used?
521 (,eof-object? . "end-of-file object")
524 (define-public guile-predicates
525 `((,hash-table? . "hash table")
528 (define-public lilypond-scheme-predicates
529 `((,boolean-or-symbol? . "boolean or symbol")
531 (,cheap-list? . "list")
532 (,grob-list? . "list of grobs")
533 ;; this is built on cheap-list
534 (,list-or-symbol? . "list or symbol")
535 (,markup? . "markup")
536 (,markup-command-list? . "markup command list")
537 (,markup-list? . "markup list")
538 (,moment-pair? . "pair of moment objects")
539 (,number-or-grob? . "number or grob")
540 (,number-or-pair? . "number or pair")
541 (,number-or-string? . "number or string")
542 (,number-pair? . "pair of numbers")
543 (,rhythmic-location? . "rhythmic location")
544 (,scheme? . "any type")
545 (,string-or-pair? . "string or pair")
546 (,string-or-symbol? . "string or symbol")
549 (define-public lilypond-exported-predicates
551 (,ly:context? . "context")
552 (,ly:dimension? . "dimension, in staff space")
553 (,ly:dir? . "direction")
554 (,ly:dispatcher? . "dispatcher")
555 (,ly:duration? . "duration")
556 (,ly:font-metric? . "font metric")
557 (,ly:grob? . "graphical (layout) object")
558 (,ly:grob-array? . "array of grobs")
559 (,ly:input-location? . "input location")
561 (,ly:iterator? . "iterator")
562 (,ly:lily-lexer? . "lily-lexer")
563 (,ly:lily-parser? . "lily-parser")
564 (,ly:listener? . "listener")
565 (,ly:moment? . "moment")
566 (,ly:music? . "music")
567 (,ly:music-function? . "music function")
568 (,ly:music-list? . "list of music objects")
569 (,ly:music-output? . "music output")
570 (,ly:otf-font? . "OpenType font")
571 (,ly:output-def? . "output definition")
572 (,ly:page-marker? . "page marker")
573 (,ly:pango-font? . "pango font")
574 (,ly:paper-book? . "paper book")
575 (,ly:paper-system? . "paper-system Prob")
576 (,ly:pitch? . "pitch")
577 (,ly:prob? . "property object")
578 (,ly:score? . "score")
579 (,ly:simple-closure? . "simple closure")
580 (,ly:skyline? . "skyline")
581 (,ly:skyline-pair? . "pair of skylines")
582 (,ly:source-file? . "source file")
583 (,ly:spanner? . "spanner")
584 (,ly:stencil? . "stencil")
585 (,ly:stream-event? . "stream event")
586 (,ly:translator? . "translator")
587 (,ly:translator-group? . "translator group")
591 (set! type-p-name-alist
592 (append r5rs-primary-predicates
593 r5rs-secondary-predicates
595 lilypond-scheme-predicates
596 lilypond-exported-predicates))
599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
602 (define (profile-measurements)
605 (list (- (+ (tms:cutime t)
607 (assoc-get 'gc-time-taken stats))
608 (assoc-get 'total-cells-allocated stats 0))))
610 (define (dump-profile base last this)
611 (let* ((outname (format #f "~a.profile" (dir-basename base ".ly")))
612 (diff (map (lambda (y) (apply - y)) (zip this last))))
613 (ly:progress "\nWriting timing to ~a..." outname)
614 (format (open-file outname "w")
615 "time: ~a\ncells: ~a\n"
616 (if (ly:get-option 'dump-cpu-profile)
621 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
622 ;; debug memory leaks
627 (define gc-protect-stat-count
630 (define-public (dump-live-object-stats outfile)
631 (for-each (lambda (x)
632 (format outfile "~a: ~a\n" (car x) (cdr x)))
633 (sort (gc-live-object-stats)
635 (string<? (car x) (car y))))))
637 (define-public (dump-gc-protects)
638 (set! gc-protect-stat-count (1+ gc-protect-stat-count))
639 (let* ((protects (sort (hash-table->alist (ly:protects))
641 (< (object-address (car a))
642 (object-address (car b))))))
643 (out-file-name (string-append
644 "gcstat-" (number->string gc-protect-stat-count)
646 (outfile (open-file out-file-name "w")))
648 (ly:progress "Dumping GC statistics ~a...\n" out-file-name)
649 (for-each (lambda (y)
652 (format outfile "~a (~a) = ~a\n" (object-address x) c x)))
655 (not (symbol? (car x))))
657 (format outfile "\nprotected symbols: ~a\n"
658 (apply + (map (lambda (obj-count)
659 (if (symbol? (car obj-count))
664 ;; (display (ly:smob-protects))
666 (if (defined? 'gc-live-object-stats)
668 (ly:progress "Live object statistics: GC'ing\n")
672 (ly:progress "Asserting dead objects\n")
673 (ly:set-option 'debug-gc-assert-parsed-dead #t)
675 (ly:set-option 'debug-gc-assert-parsed-dead #f)
676 (set! stats (gc-live-object-stats))
677 (ly:progress "Dumping live object statistics.\n")
678 (dump-live-object-stats outfile)))
680 (let* ((stats (gc-stats)))
681 (for-each (lambda (sym)
682 (format outfile "~a ~a ~a\n"
683 gc-protect-stat-count
685 (assoc-get sym stats "?")))
686 '(protected-objects bytes-malloced cell-heap-size)))
688 (close-port outfile)))
690 (define (check-memory)
691 "Read `/proc/self' to check up on memory use."
692 (define (gulp-file name)
693 (let* ((file (open-input-file name))
694 (text (read-delimited "" file)))
698 (let* ((stat (gulp-file "/proc/self/status"))
699 (lines (string-split stat #\newline))
700 (interesting (filter identity
703 (string-match "^VmData:[ \t]*([0-9]*) kB" l))
705 (mem (string->number (match:substring (car interesting) 1))))
706 (format #t "VMDATA: ~a\n" mem)
710 (begin (dump-gc-protects)
713 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
715 (define (multi-fork count)
716 "Split this process into COUNT helpers. Returns either a list of
717 PIDs or the number of the process."
718 (define (helper count acc)
720 (let* ((pid (primitive-fork)))
723 (helper (1- count) (cons pid acc))))
728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
730 (define* (ly:exit status #:optional (silently #f))
731 "Exit function for lilypond"
734 ((0) (ly:basic-progress (_ "Success: compilation successfully completed")))
735 ((1) (ly:warning (_ "Compilation completed with warnings or errors")))
736 (else (ly:message ""))))
739 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
741 (define-public (lilypond-main files)
742 "Entry point for LilyPond."
743 (eval-string (ly:command-line-code))
744 (if (ly:get-option 'help)
745 (begin (ly:option-usage)
747 (if (ly:get-option 'show-available-fonts)
748 (begin (ly:font-config-display-fonts)
750 (if (ly:get-option 'gui)
755 (if (ly:get-option 'read-file-list)
758 (> (string-length s) 0))
761 (string-split (ly:gulp-file f) #\nl))
763 (if (and (number? (ly:get-option 'job-count))
764 (>= (length files) (ly:get-option 'job-count)))
765 (let* ((count (ly:get-option 'job-count))
766 (split-todo (split-list files count))
767 (joblist (multi-fork count))
769 (if (not (string-or-symbol? (ly:get-option 'log-file)))
770 (ly:set-option 'log-file "lilypond-multi-run"))
771 (if (number? joblist)
772 (begin (ly:set-option
773 'log-file (format #f "~a-~a"
774 (ly:get-option 'log-file) joblist))
775 (set! files (vector-ref split-todo joblist)))
776 (begin (ly:progress "\nForking into jobs: ~a\n" joblist)
779 (let* ((stat (cdr (waitpid pid))))
782 (acons (list-element-index joblist pid)
789 (logfile (format #f "~a-~a.log"
790 (ly:get-option 'log-file) job))
791 (log (ly:gulp-file logfile))
792 (len (string-length log))
793 (tail (substring log (max 0 (- len 1024)))))
794 (if (status:term-sig state)
797 (format #f (_ "job ~a terminated with signal: ~a")
798 job (status:term-sig state)))
800 (_ "logfile ~a (exit ~a):\n~a")
801 logfile (status:exit-val state) tail))))
804 (ly:error "Children ~a exited with errors."
806 ;; must overwrite individual entries
807 (if (ly:get-option 'dump-profile)
808 (dump-profile "lily-run-total"
809 '(0 0) (profile-measurements)))
814 (if (string-or-symbol? (ly:get-option 'log-file))
815 (ly:stderr-redirect (format #f "~a.log" (ly:get-option 'log-file)) "w"))
816 (let ((failed (lilypond-all files)))
817 (if (ly:get-option 'trace-scheme-coverage)
819 (coverage:show-all (lambda (f)
820 (string-contains f "lilypond")))))
822 (begin (ly:error (_ "failed files: ~S") (string-join failed))
828 (define-public (lilypond-all files)
830 (separate-logs (ly:get-option 'separate-log-files))
833 (open-file (if (string-or-symbol? (ly:get-option 'log-file))
834 (format #f "~a.log" (ly:get-option 'log-file))
835 "/dev/stderr") "a") #f))
836 (do-measurements (ly:get-option 'dump-profile))
837 (handler (lambda (key failed-file)
838 (set! failed (append (list failed-file) failed)))))
842 (let* ((start-measurements (if do-measurements
843 (profile-measurements)
845 (base (dir-basename x ".ly"))
846 (all-settings (ly:all-options)))
848 (ly:stderr-redirect (format #f "~a.log" base) "w"))
850 (format ping-log "Processing ~a\n" base))
851 (if (ly:get-option 'trace-memory-frequency)
852 (mtrace:start-trace (ly:get-option 'trace-memory-frequency)))
853 (lilypond-file handler x)
854 (if start-measurements
855 (dump-profile x start-measurements (profile-measurements)))
856 (if (ly:get-option 'trace-memory-frequency)
857 (begin (mtrace:stop-trace)
858 (mtrace:dump-results base)))
859 (for-each (lambda (s)
860 (ly:set-option (car s) (cdr s)))
862 (ly:set-option 'debug-gc-assert-parsed-dead #t)
864 (ly:set-option 'debug-gc-assert-parsed-dead #f)
865 (if (ly:get-option 'debug-gc)
867 (ly:reset-all-fonts))
871 ;; Ensure a notice re failed files is written to aggregate logfile.
873 (format ping-log "Failed files: ~a\n" failed))
874 (if (ly:get-option 'dump-profile)
875 (dump-profile "lily-run-total" '(0 0) (profile-measurements)))
878 (define (lilypond-file handler file-name)
879 (catch 'ly-file-failed
880 (lambda () (ly:parse-file file-name))
881 (lambda (x . args) (handler x file-name))))
883 (use-modules (scm editor))
885 (define-public (gui-main files)
887 (gui-no-files-handler))
888 (if (not (string? (ly:get-option 'log-file)))
889 (let* ((base (dir-basename (car files) ".ly"))
890 (log-name (string-append base ".log")))
891 (if (not (ly:get-option 'gui))
892 (ly:message (_ "Redirecting output to ~a...") log-name))
893 (ly:stderr-redirect log-name "w")
894 (ly:message "# -*-compilation-*-"))
895 (let ((failed (lilypond-all files)))
899 (ly:stderr-redirect "foo" "r")
900 (system (get-editor-command log-name 0 0 0))
901 (ly:error (_ "failed files: ~S") (string-join failed))
906 (define (gui-no-files-handler)
907 (let* ((ly (string-append (ly:effective-prefix) "/ly/"))
908 ;; FIXME: soft-code, localize
909 (welcome-ly (string-append ly "Welcome_to_LilyPond.ly"))
910 (cmd (get-editor-command welcome-ly 0 0 0)))
911 (ly:message (_ "Invoking `~a'...\n") cmd)