]> git.donarmstrong.com Git - lilypond.git/blob - scm/backend-library.scm
remove latin1.enc rules.
[lilypond.git] / scm / backend-library.scm
1 ;;;; backend-library.scm -- helpers for the backends.
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c)  2005 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
9 ;; backend helpers.
10
11 (define-public (ly:system command)
12   (let* ((status 0)
13          (silenced
14           (string-append command (if (ly:get-option 'verbose)
15                                      ""
16                                      " > /dev/null 2>&1 "))))
17
18     (if (ly:get-option 'verbose)
19         (format (current-error-port) (_ "Invoking `~a'...") command))
20     
21     (set! status (system silenced))
22     (if (> status 0)
23         (begin
24           (format (current-error-port) (_ "`~a' failed (~a)") command status)
25           (newline (current-error-port))
26           
27           ;; hmmm.  what's the best failure option? 
28           (throw 'ly-file-failed))))
29
30 (define-public (sanitize-command-option str)
31   (string-append
32    "\""
33    (regexp-substitute/global #f "[^- 0-9,.a-zA-Z'\"\\]" str 'pre 'post)
34    "\""))
35
36 (define-public (postscript->pdf papersizename name)
37   (let* ((cmd (string-append "ps2pdf "
38                              (string-append
39                               " -sPAPERSIZE="
40                               (sanitize-command-option papersizename)
41                               " "
42                               name)))
43          (pdf-name (string-append (basename name ".ps") ".pdf" )))
44
45     (if (access? pdf-name W_OK)
46         (delete-file pdf-name))
47
48     (format (current-error-port) (_ "Converting to `~a'...") pdf-name)
49     (ly:system cmd)))
50
51 (define-public (postscript->png resolution name)
52   (let ((cmd (string-append
53               "ps2png --resolution="
54               (if (number? resolution)
55                   (number->string resolution)
56                   "90 ")
57               (if (ly:get-option 'verbose)
58                   " --verbose "
59                   " ")
60               name)))
61
62     (ly:system cmd)))
63
64 (define-public (postprocess-output paper-book module filename formats)
65   (for-each
66    (lambda (f)
67      ((eval (string->symbol (string-append "convert-to-" f))
68             module)
69       paper-book filename))
70    
71    formats))
72
73 (define-public (completize-formats formats)
74   (define new-fmts '())
75
76   (if (member "png" formats)
77       (set! formats (cons "ps" formats)))
78   (if (member "pdf" formats)
79       (set! formats (cons "ps" formats)))
80
81   (for-each
82    (lambda (x)
83      (if (member x formats) (set! new-fmts (cons x new-fmts))))
84    '("tex" "dvi" "ps" "pdf" "png"))
85
86   new-fmts)
87