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 "))))
18 (if (ly:get-option 'verbose)
19 (format (current-error-port) (_ "Invoking `~a'...") command))
21 (set! status (system silenced))
24 (format (current-error-port) (_ "`~a' failed (~a)") command status)
25 (newline (current-error-port))
27 ;; hmmm. what's the best failure option?
28 (throw 'ly-file-failed)))))
30 (define-public (sanitize-command-option str)
33 (regexp-substitute/global #f "[^- 0-9,.a-zA-Z'\"\\]" str 'pre 'post)
36 (define-public (postscript->pdf papersizename name)
37 (let* ((cmd (format #f "ps2pdf -sPAPERSIZE=~a '~a'"
38 (sanitize-command-option papersizename) name))
39 (pdf-name (string-append (basename name ".ps") ".pdf" )))
41 (if (access? pdf-name W_OK)
42 (delete-file pdf-name))
44 (format (current-error-port) (_ "Converting to `~a'...") pdf-name)
45 (newline (current-error-port))
48 (define-public (postscript->png resolution papersizename name)
49 (let* ((prefix (ly:effective-prefix))
50 ;; FIXME: should scripts/ps2png.py be installed in PREFIX?
51 (ps2png-source (if prefix
52 (format "~a/scripts/ps2png.py" prefix)
55 "~a --resolution=~S --papersize=~a~a '~a'"
56 (if (file-exists? ps2png-source)
57 (format "python ~a" ps2png-source)
60 (sanitize-command-option papersizename)
61 (if (ly:get-option 'verbose) " --verbose " "")
63 ;; Do not try to guess the name of the png file,
64 ;; GS produces PNG files like BASE-page%d.png.
65 ;;(format (current-error-port) (_ "Converting to `~a'...")
66 ;; (string-append (basename name ".ps") "-page1.png" )))
67 (format (current-error-port) (_ "Converting to ~a...") "PNG")
68 (newline (current-error-port))
71 (define-public (postprocess-output paper-book module filename formats)
74 ((eval (string->symbol (string-append "convert-to-" f))
80 (define-public (completize-formats formats)
83 (if (member "png" formats)
84 (set! formats (cons "ps" formats)))
85 (if (member "pdf" formats)
86 (set! formats (cons "ps" formats)))
90 (if (member x formats) (set! new-fmts (cons x new-fmts))))
91 '("tex" "dvi" "ps" "pdf" "png"))
93 (uniq-list (reverse new-fmts)))
95 (define (header-to-file file-name key value)
96 (set! key (symbol->string key))
97 (if (not (equal? "-" file-name))
98 (set! file-name (string-append file-name "." key)))
99 (format (current-error-port)
100 (_ "Writing header field `~a' to `~a'...")
102 (if (equal? "-" file-name) "<stdout>" file-name))
103 (if (equal? file-name "-")
105 (display value (open-file file-name "w")))
106 (newline (current-error-port))
109 (define-public (output-scopes scopes fields basename)
110 (define (output-scope scope)
115 (let ((val (if (variable-bound? var) (variable-ref var) "")))
116 (if (and (memq sym fields) (string? val))
117 (header-to-file basename sym val))
120 (apply string-append (map output-scope scopes)))