From c44e624300d9877c1790830902a10fd3868dd6d3 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 30 Mar 2008 16:36:12 -0300 Subject: [PATCH] Optionally preserve input path. - Add (dir-basename file "ext1" "ext2" ... ) function - Use dir-basename everywhere. Guile's (basename ) strips paths. - Introduce -dno-strip-output-dir option. --- lily/lily-parser-scheme.cc | 31 ++++++++++++------------------- lily/lily-parser.cc | 3 +-- scm/backend-library.scm | 9 ++++----- scm/framework-tex.scm | 8 ++++---- scm/lily-library.scm | 5 +++++ scm/lily.scm | 8 ++++---- scm/ps-to-png.scm | 2 +- scripts/lilypond-book.py | 3 --- 8 files changed, 31 insertions(+), 38 deletions(-) diff --git a/lily/lily-parser-scheme.cc b/lily/lily-parser-scheme.cc index 1631c4a3da..61ea288fc6 100644 --- a/lily/lily-parser-scheme.cc +++ b/lily/lily-parser-scheme.cc @@ -51,31 +51,25 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", out_file_name.ext_ = ""; out_file_name.root_ = ""; - out_file_name.dir_ = ""; - + if (ly_get_option (ly_symbol2scm ("gui")) != SCM_BOOL_T + && ly_get_option (ly_symbol2scm ("strip-output-dir")) == SCM_BOOL_T) { + out_file_name.dir_ = ""; + } + /* When running from gui, generate output in .ly source directory. */ - if (output_name_global.empty () - && ly_get_option (ly_symbol2scm ("gui")) == SCM_BOOL_T) - { - File_name f (file); - f.base_ = ""; - f.ext_ = ""; - output_name_global = f.to_string (); - } - - if (!output_name_global.empty ()) + string output_name = output_name_global; + if (!output_name.empty ()) { - /* Interpret --output=DIR to mean --output=DIR/BASE. */ string dir; - if (is_dir (output_name_global)) + if (is_dir (output_name)) { - dir = output_name_global; - output_name_global = ""; + dir = output_name; + output_name = ""; } else { - File_name out (output_name_global); + File_name out (output_name); if (is_dir (out.dir_part ())) { dir = out.dir_part (); @@ -91,7 +85,7 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", chdir (dir.c_str ()); } else - out_file_name = File_name (output_name_global); + out_file_name = File_name (output_name); } string init; @@ -101,7 +95,6 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", init = "init.ly"; string out_file = out_file_name.to_string (); - if (init.length () && global_path.find (init).empty ()) { warning (_f ("cannot find init file: `%s'", init)); diff --git a/lily/lily-parser.cc b/lily/lily-parser.cc index 05412ad05a..b508860efa 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -90,8 +90,7 @@ Lily_parser::parse_file (string init, string name, string out_name) try_load_text_metrics (out_name); // TODO: use $parser - lexer_->set_identifier (ly_symbol2scm ("parser"), - self_scm ()); + lexer_->set_identifier (ly_symbol2scm ("parser"), self_scm ()); output_basename_ = out_name; lexer_->main_input_name_ = name; diff --git a/scm/backend-library.scm b/scm/backend-library.scm index 45b156a6c8..8963fe15ca 100644 --- a/scm/backend-library.scm +++ b/scm/backend-library.scm @@ -71,7 +71,7 @@ (define-public (postscript->pdf paper-width paper-height name) (let* ((pdf-name (string-append - (basename (basename name ".ps") ".eps") + (dir-basename name ".ps" ".eps") ".pdf")) (is-eps (string-match "\\.eps$" name)) (paper-size-string (if is-eps @@ -121,12 +121,11 @@ (use-modules (scm ps-to-png)) (define-public (postscript->png resolution paper-width paper-height name) - ;; Do not try to guess the name of the png file, - ;; GS produces PNG files like BASE-page%d.png. - ;;(ly:message (_ "Converting to `~a'...") - ;; (string-append (basename name ".ps") "-page1.png" ))) (let* ((verbose (ly:get-option 'verbose)) (rename-page-1 #f)) + + ;; Do not try to guess the name of the png file, + ;; GS produces PNG files like BASE-page%d.png. (ly:message (_ "Converting to ~a...") "PNG") (make-ps-images name #:resolution resolution diff --git a/scm/framework-tex.scm b/scm/framework-tex.scm index 8b10bac42c..8cfa09b76f 100644 --- a/scm/framework-tex.scm +++ b/scm/framework-tex.scm @@ -296,7 +296,7 @@ (output-scale (ly:output-def-lookup defs 'output-scale))) (postscript->pdf (* paper-width output-scale (/ (ly:bp 1))) (* paper-height output-scale (/ (ly:bp 1))) - (string-append (basename name ".tex") ".ps")))) + (string-append (dir-basename name ".tex") ".ps")))) (define-public (convert-to-png book name) (let* ((defs (ly:paper-book-paper book)) @@ -312,14 +312,14 @@ (* paper-width output-scale (/ (ly:bp 1))) (* paper-height output-scale (/ (ly:bp 1))) - (string-append (basename name ".tex") ".ps")))) + (string-append (dir-basename name ".tex") ".ps")))) (define-public (convert-to-ps book name) (let* ((paper (ly:paper-book-paper book)) (preview? (string-contains name ".preview")) (papersizename (ly:output-def-lookup paper 'papersizename)) (landscape? (eq? #t (ly:output-def-lookup paper 'landscape))) - (base (basename name ".tex")) + (base (dir-basename name ".tex")) (ps-name (format "~a.ps" base ".ps")) (cmd (string-append "dvips" (if preview? @@ -352,7 +352,7 @@ #f " *%.*\n?" (ly:kpathsea-expand-variable "extra_mem_top") 'pre "" 'post))) - (base (basename name ".tex")) + (base (dir-basename name ".tex")) (cmd (format #f "latex \\\\nonstopmode \\\\input '~a'" name))) diff --git a/scm/lily-library.scm b/scm/lily-library.scm index ae13bbebf0..f772d0527e 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -491,6 +491,11 @@ found." (string-append (ly:number->string (car c)) " " (ly:number->string (cdr c)))) +(define-public (dir-basename file . rest) + "Strip suffixes in REST, but leave directory component for FILE." + (define (inverse-basename x y) (basename y x)) + (simple-format #f "~a/~a" (dirname file) + (fold inverse-basename file rest))) (define-public (write-me message x) "Return X. Display MESSAGE and write X. Handy for debugging, diff --git a/scm/lily.scm b/scm/lily.scm index efa40f338b..a538b3f3ed 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -74,6 +74,7 @@ on errors, and print a stack trace.") (safe #f "Run safely") (strict-infinity-checking #f "If yes, crash on encountering Inf/NaN.") + (strip-output-dir #t "If yes, strip directories from input files.") (separate-log-files #f "Output to FILE.log per file.") (trace-memory-frequency #f "Record Scheme cell usage this many times per second, and dump to file.") (trace-scheme-coverage #f "Record coverage of Scheme files") @@ -410,7 +411,7 @@ The syntax is the same as `define*-public'." (define (dump-profile base last this) (let* - ((outname (format "~a.profile" (basename base ".ly"))) + ((outname (format "~a.profile" (dir-basename base ".ly"))) (diff (map (lambda (y) (apply - y)) (zip this last)))) (ly:progress "\nWriting timing to ~a..." outname) @@ -559,7 +560,6 @@ The syntax is the same as `define*-public'." (define-public (lilypond-main files) "Entry point for LilyPond." - (eval-string (ly:command-line-code)) (if (ly:get-option 'help) @@ -682,7 +682,7 @@ The syntax is the same as `define*-public'." ((start-measurements (if do-measurements (profile-measurements) #f)) - (base (basename x ".ly")) + (base (dir-basename x ".ly")) (all-settings (ly:all-options))) (if separate-logs @@ -741,7 +741,7 @@ The syntax is the same as `define*-public'." (gui-no-files-handler)) (if (not (string? (ly:get-option 'log-file))) - (let* ((base (basename (car files) ".ly")) + (let* ((base (dir-basename (car files) ".ly")) (log-name (string-append base ".log"))) (if (not (ly:get-option 'gui)) (ly:message (_ "Redirecting output to ~a...") log-name)) diff --git a/scm/ps-to-png.scm b/scm/ps-to-png.scm index deca66008a..474a89628a 100644 --- a/scm/ps-to-png.scm +++ b/scm/ps-to-png.scm @@ -108,7 +108,7 @@ ((string-contains format-str "jpeg") "jpeg") (else (ly:error "Unknown pixmap format ~a" pixmap-format)))) - (base (basename (re-sub "[.]e?ps" "" ps-name))) + (base (dir-basename ps-name ".ps" ".eps")) (png1 (format "~a.~a" base extension)) (pngn (format "~a-page%d.~a" base extension)) (page-count (ps-page-count ps-name)) diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 86e78e2449..2c3870a336 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -1107,9 +1107,6 @@ class LilypondSnippet (Snippet): return self.checksum def basename (self): - if FILENAME in self.option_dict: - return self.option_dict[FILENAME] - cs = self.get_checksum () # TODO: use xx/xxxxx directory layout. -- 2.39.5