lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PATCH for getting output-suffix to work (Trackers 714 and 404)


From: Ian Hulin
Subject: PATCH for getting output-suffix to work (Trackers 714 and 404)
Date: Sat, 29 Aug 2009 14:06:44 +0100
User-agent: Thunderbird 2.0.0.23 (X11/20090817)

Apologies for not putting this one on rietveld, but I couldn't get the Create Issue form to accept the patch or work out what the exact set of options and parameters was for the upload.py python script.

So I've fallen back to sending it to the list direct.

If it looks OK, could someone please push it to the main git repo?

Cheers,

Ian
>From 87504a757a98b6a5ff64c8dd67bc2f114de6acfb Mon Sep 17 00:00:00 2001
From: Ian Hulin <address@hidden(none)>
Date: Fri, 21 Aug 2009 16:35:40 +0100
Subject: [PATCH] Issues 714 and 404: Add greater user flexibility in naming 
output files
    using output-suffix.
    output name handling now moved to its own procedure in lily-library.scm
   Amended to use ly:get-assoc to pick up initial value of parser variable
    output-count and remove redundant check on initial call.
   Accented characters now supported in output-suffix.

---
 scm/lily-library.scm |   36 ++++++++++++++++++++++--------------
 1 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/scm/lily-library.scm b/scm/lily-library.scm
index e7f1d29..1b10b5b 100644
--- a/scm/lily-library.scm
+++ b/scm/lily-library.scm
@@ -134,27 +134,35 @@
 
   (ly:make-score music))
 
+
+(define (get-outfile-name parser base)
+(let*
+    ((output-suffix (ly:parser-lookup parser 'output-suffix))
+     (counter-alist (ly:parser-lookup parser 'counter-alist))
+     (output-count (assoc-get output-suffix counter-alist 0))
+     (result base ))
+    ;; Allow all ASCII alphanumerics, including accents
+    (if (string? output-suffix)
+        (set! result (format "~a-~a" base (string-regexp-substitute
+            "[^-[:alnum:]]" "_" output-suffix))))
+
+    ;; assoc-get call will always have returned a number
+    (if (> output-count 0) (set! result (format #f "~a-~a" result 
output-count)))
+
+    (ly:parser-define!
+        parser 'counter-alist
+        (assoc-set! counter-alist output-suffix (1+ output-count)))
+    result))
+
 (define (print-book-with parser book process-procedure)
   (let*
       ((paper (ly:parser-lookup parser '$defaultpaper))
        (layout (ly:parser-lookup parser '$defaultlayout))
        (count (ly:parser-lookup parser 'output-count))
        (base (ly:parser-output-name parser))
-       (output-suffix (ly:parser-lookup parser 'output-suffix)) )
+       (outfile-name (get-outfile-name parser base)))
 
-    (if (string? output-suffix)
-       (set! base (format "~a-~a" base (string-regexp-substitute
-                                          "[^a-zA-Z0-9-]" "_" output-suffix))))
-
-    ;; must be careful: output-count is under user control.
-    (if (not (integer? count))
-       (set! count 0))
-
-    (if (> count 0)
-       (set! base (format #f "~a-~a" base count)))
-    (ly:parser-define! parser 'output-count (1+ count))
-    (process-procedure book paper layout base)
-    ))
+      (process-procedure book paper layout outfile-name)))
 
 (define-public (print-book-with-defaults parser book)
   (print-book-with parser book ly:book-process))
-- 
1.6.0.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]