From c37c6f39d18274ccac28ed42559681ea271cc496 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Thu, 23 Feb 2012 19:19:37 +0100 Subject: [PATCH] Issue 2343: Faulty file-naming when outputting multiple \books --- lily/parser.yy | 2 -- ly/init.ly | 2 -- ly/music-functions-init.ly | 4 ++-- scm/lily-library.scm | 34 ++++++++++++++++++++++++++-------- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lily/parser.yy b/lily/parser.yy index 29f4f2a1e0..c26f2aae63 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -864,8 +864,6 @@ book_body: push_paper (parser, $$->paper_); $$->header_ = parser->lexer_->lookup_identifier ("$defaultheader"); parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ()); - parser->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F); - parser->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F); } | BOOK_IDENTIFIER { $$ = unsmob_book ($1); diff --git a/ly/init.ly b/ly/init.ly index 25c2ba0afb..6546ed422a 100644 --- a/ly/init.ly +++ b/ly/init.ly @@ -19,8 +19,6 @@ #(define expect-error #f) #(define output-empty-score-list #f) #(define output-suffix #f) -#(define book-filename #f) -#(define book-output-suffix #f) #(use-modules (scm clip-region)) $(if (ly:get-option 'include-settings) diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 4082ea9aec..3c8539e152 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -186,13 +186,13 @@ bendAfter = bookOutputName = #(define-void-function (parser location newfilename) (string?) (_i "Direct output for the current book block to @var{newfilename}.") - (set! book-filename newfilename)) + (set! (paper-variable parser #f 'output-filename) newfilename)) bookOutputSuffix = #(define-void-function (parser location newsuffix) (string?) (_i "Set the output filename suffix for the current book block to @var{newsuffix}.") - (set! book-output-suffix newsuffix)) + (set! (paper-variable parser #f 'output-suffix) newsuffix)) %% \breathe is defined as a music function rather than an event identifier to %% ensure it gets useful input location information: as an event identifier, diff --git a/scm/lily-library.scm b/scm/lily-library.scm index 9673c7b3e4..eb537a8e71 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -157,31 +157,31 @@ (ly:make-score music)) -(define (get-current-filename parser) +(define (get-current-filename parser book) "return any suffix value for output filename allowing for settings by calls to bookOutputName function" - (let ((book-filename (ly:parser-lookup parser 'book-filename))) + (let ((book-filename (paper-variable parser book 'output-filename))) (if (not book-filename) (ly:parser-output-name parser) book-filename))) -(define (get-current-suffix parser) +(define (get-current-suffix parser book) "return any suffix value for output filename allowing for settings by calls to bookoutput function" - (let ((book-output-suffix (ly:parser-lookup parser 'book-output-suffix))) + (let ((book-output-suffix (paper-variable parser book 'output-suffix))) (if (not (string? book-output-suffix)) (ly:parser-lookup parser 'output-suffix) book-output-suffix))) (define-public current-outfile-name #f) ; for use by regression tests -(define (get-outfile-name parser) +(define (get-outfile-name parser book) "return current filename for generating backend output files" ;; user can now override the base file name, so we have to use ;; the file-name concatenated with any potential output-suffix value ;; as the key to out internal a-list - (let* ((base-name (get-current-filename parser)) - (output-suffix (get-current-suffix parser)) + (let* ((base-name (get-current-filename parser book)) + (output-suffix (get-current-suffix parser book)) (alist-key (format #f "~a~a" base-name output-suffix)) (counter-alist (ly:parser-lookup parser 'counter-alist)) (output-count (assoc-get alist-key counter-alist 0)) @@ -209,7 +209,7 @@ bookoutput function" (define (print-book-with parser book process-procedure) (let* ((paper (ly:parser-lookup parser '$defaultpaper)) (layout (ly:parser-lookup parser '$defaultlayout)) - (outfile-name (get-outfile-name parser))) + (outfile-name (get-outfile-name parser book))) (process-procedure book paper layout outfile-name))) (define-public (print-book-with-defaults parser book) @@ -230,6 +230,24 @@ bookoutput function" (else ((ly:parser-lookup parser 'toplevel-score-handler) parser score)))) +(define-public paper-variable + (let + ((get-papers + (lambda (parser book) + (append (if (and book (ly:output-def? (ly:book-paper book))) + (list (ly:book-paper book)) + '()) + (ly:parser-lookup parser '$papers) + (list (ly:parser-lookup parser '$defaultpaper)))))) + (make-procedure-with-setter + (lambda (parser book symbol) + (any (lambda (p) (ly:output-def-lookup p symbol #f)) + (get-papers parser book))) + (lambda (parser book symbol value) + (ly:output-def-set-variable! + (car (get-papers parser book)) + symbol value))))) + (define-public (add-text parser text) (add-score parser (list text))) -- 2.39.2