]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/lily.scm
* scm/paper.scm (paper-alist): public.
[lilypond.git] / scm / lily.scm
index e5c27d303aed555e2a1d689f91df7212e3e29c97..f870cb6254483fd7b681d991a64a22c72d5ebfc3 100644 (file)
 (if (defined? 'set-debug-cell-accesses!)
     (set-debug-cell-accesses! #f))
 
+;(set-debug-cell-accesses! 5000)
+
 (use-modules (ice-9 regex)
             (ice-9 safe)
             (oop goops)
             (srfi srfi-1)  ; lists
             (srfi srfi-13)) ; strings
 
+
+; my display
+
 (define-public (myd k v) (display k) (display ": ") (display v) (display ", "))
 
+(define-public (print . args)
+  (apply format (cons (current-output-port) args)))
+  
+
 ;;; General settings
 ;;; debugging evaluator is slower.  This should
 ;;; have a more sensible default.
 (define ifdef "First run this through cpp.")
 (define ifndef "First run this through cpp.")
 
-
+;; gettext wrapper for guile < 1.7.2
+(if (defined? 'gettext)
+    (define-public _ gettext)
+    (define-public _ ly:gettext))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 ;; parser stuff.
 (define-public (print-music-as-book parser music)
   (let* ((head  (ly:parser-lookup parser '$globalheader))
-        (book (ly:make-book (ly:parser-lookup parser $defaultbookpaper)
+        (book (ly:make-book (ly:parser-lookup parser $defaultpaper)
                             head score)))
     (ly:parser-print-book parser book)))
 
 (define-public (print-score-as-book parser score)
   (let*
       ((head  (ly:parser-lookup parser '$globalheader))
-       (book (ly:make-book (ly:parser-lookup parser $defaultbookpaper)
+       (book (ly:make-book (ly:parser-lookup parser $defaultpaper)
                           head score)))
     (ly:parser-print-book parser book)))
 
 (define-public (print-score parser score)
   (let* ((head  (ly:parser-lookup parser '$globalheader))
-        (book (ly:make-book (ly:parser-lookup parser $defaultbookpaper)
+        (book (ly:make-book (ly:parser-lookup parser $defaultpaper)
                             head score)))
     (ly:parser-print-score parser book)))
                
     ))
 
 (define-public (collect-music-for-book parser music)
-  (collect-scores-for-book parser (ly:music-scorify music)))
+  (collect-scores-for-book parser (ly:music-scorify music parser)))
+
+
   
 ;;;;;;;;;;;;;;;;
 ; alist
-(define-public (assoc-get key alist . default)
-  "Return value if KEY in ALIST, else DEFAULT (or #f if not specified)."
-  (let ((entry (assoc key alist)))
-    (if (pair? entry)
-       (cdr entry)
-       (if (pair? default) (car default) #f))))
+(define-public assoc-get ly:assoc-get)
 
 (define-public (uniqued-alist alist acc)
   (if (null? alist) acc
@@ -315,7 +324,8 @@ L1 is copied, L2 not.
   "Length of the number-pair X, when an interval"
   (max 0 (- (cdr x) (car x)))
   )
-  
+(define-public interval-start car)
+(define-public interval-end cdr)
 
 (define (other-axis a)
   (remainder (+ a 1) 2))
@@ -331,7 +341,8 @@ L1 is copied, L2 not.
 
 
 (define-public (write-me message x)
-  "Return X.  Display MESSAGE and write X.  Handy for debugging, possibly turned off."
+  "Return X.  Display MESSAGE and write X.  Handy for debugging,
+possibly turned off."
   (display message) (write x) (newline) x)
 ;;  x)
 
@@ -529,8 +540,7 @@ L1 is copied, L2 not.
        (outfile    (open-file (string-append
               "gcstat-" (number->string gc-protect-stat-count)
               ".scm"
-              ) "w"))
-       )
+              ) "w")))
 
     (display "DUMPING...\n")
     (display
@@ -552,37 +562,68 @@ L1 is copied, L2 not.
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
 
-(define-public (postscript->pdf papersize name)
-  (display
-   (string-append
-    "Converting to "
-    (regexp-substitute/global #f "\\.ps" name 'pre ".pdf" 'post)
-    "\n"))
-  (system (string-append "ps2pdf -sPAPERSIZE=" papersize
-                        " "
-                        name)))
+(define-public (ly:system command)
+  (let*
+      ((status 0)
 
+       (silenced
+       (string-append command (if (ly:get-option 'verbose)
+                                ""
+                                " > /dev/null 2>&1 "))))
+    
+    (if (ly:get-option 'verbose)
+       (format  (current-error-port) (_ "Invoking `~a'...\n") command))
+    
+    (set! status (system silenced))
+    (if (> status 0)
+       (format (current-error-port) (_ "Error invoking `~a'. Return value ~a")
+               silenced status))))
+
+;;
+;; ugh  -   double check this. We are leaking
+;; untrusted (user-settable) info to a command-line
+;;
+;; (regexp-substitute/global #f "[^[:alnum:]]" papersizename 'pre 'post))
+(define-public (postscript->pdf papersizename name)
+  (let* ((set-papersize (if (member papersizename (map car paper-alist))
+                           (string-append "-sPAPERSIZE=" papersizename " ")
+                           ""))
+        (cmd (string-append "ps2pdf " set-papersize name))
+        (pdf-name (string-append (basename name ".ps") ".pdf" )))
+    (format (current-error-port) (_ "Converting to `~a'...") pdf-name)
+    (ly:system cmd)))
 
 (define-public (postscript->png resolution name)
-  (system (string-append
+  (let
+      ((cmd (string-append
           "ps2png --resolution="
           (if (number? resolution)
               (number->string resolution)
-              "90")
-          " "
+              "90 ")
+          (if (ly:get-option 'verbose)
+              "--verbose "
+              " ")
           name)))
+    (ly:system cmd)))
 
 (define-public (lilypond-main files)
   "Entry point for LilyPond."
   (let* ((failed '())
         (handler (lambda (key arg) (set! failed (cons arg failed)))))
     (for-each
-     (lambda (f) (catch 'ly-file-failed (lambda () (ly:parse-file f)) handler))
+     (lambda (f)
+       (catch 'ly-file-failed (lambda () (ly:parse-file f)) handler)
+;;;       (dump-gc-protects)
+       )
      files)
 
     (if (pair? failed)
        (begin
-         (display
-          (string-append "\n *** Failed files: " (string-join failed) "\n"))
+         (newline (current-error-port))
+         (display (_ "error: failed files: ") (current-error-port))
+         (display (string-join failed) (current-error-port))
+         (newline (current-error-port))
+         (newline (current-error-port))
          (exit 1))
        (exit 0))))
+