1 ;;;; backend-library.scm -- helpers for the backends.
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2005 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 (define-public (ly:system command)
14 (string-append command (if (ly:get-option 'verbose)
16 " > /dev/null 2>&1 "))))
17 (if (ly:get-option 'verbose)
18 (ly:message (_ "Invoking `~a'...") command))
20 (set! status (system silenced))
23 (ly:message (_ "`~a' failed (~a)") command status)
25 ;; hmmm. what's the best failure option?
26 (throw 'ly-file-failed)))))
28 (define-public (sanitize-command-option str)
31 (regexp-substitute/global #f "[^- 0-9,.a-zA-Z'\"\\]" str 'pre 'post)
34 (define-public (postscript->pdf papersizename name)
35 (let* ((cmd (format #f "ps2pdf -sPAPERSIZE=~a '~a'"
36 (sanitize-command-option papersizename) name))
37 (pdf-name (string-append (basename name ".ps") ".pdf" )))
39 (if (access? pdf-name W_OK)
40 (delete-file pdf-name))
42 (ly:message (_ "Converting to `~a'...") pdf-name)
46 (define-public (postscript->png resolution papersizename name)
47 (let* ((prefix (ly:effective-prefix))
48 ;; FIXME: should scripts/ps2png.py be installed in PREFIX?
49 (ps2png-source (if prefix
50 (format "~a/scripts/ps2png.py" prefix)
53 "~a --resolution=~S --papersize=~a~a '~a'"
54 (if (file-exists? ps2png-source)
55 (format "python ~a" ps2png-source)
58 (sanitize-command-option papersizename)
59 (if (ly:get-option 'verbose) " --verbose " "")
61 ;; Do not try to guess the name of the png file,
62 ;; GS produces PNG files like BASE-page%d.png.
63 ;;(ly:message (_ "Converting to `~a'...")
64 ;; (string-append (basename name ".ps") "-page1.png" )))
65 (ly:message (_ "Converting to ~a...") "PNG")
69 (define-public (postprocess-output paper-book module filename formats)
72 ((eval (string->symbol (string-append "convert-to-" f)) module)
76 (define-public (completize-formats formats)
79 (if (member "png" formats)
80 (set! formats (cons "ps" formats)))
81 (if (member "pdf" formats)
82 (set! formats (cons "ps" formats)))
86 (if (member x formats) (set! new-fmts (cons x new-fmts))))
87 '("tex" "dvi" "ps" "pdf" "png"))
89 (uniq-list (reverse new-fmts)))
91 (define (header-to-file file-name key value)
92 (set! key (symbol->string key))
93 (if (not (equal? "-" file-name))
94 (set! file-name (string-append file-name "." key)))
95 (ly:message (_ "Writing header field `~a' to `~a'...")
97 (if (equal? "-" file-name) "<stdout>" file-name))
98 (if (equal? file-name "-")
100 (display value (open-file file-name "w")))
104 (define-public (output-scopes scopes fields basename)
105 (define (output-scope scope)
110 (let ((val (if (variable-bound? var) (variable-ref var) "")))
111 (if (and (memq sym fields) (string? val))
112 (header-to-file basename sym val))
115 (apply string-append (map output-scope scopes)))