]> git.donarmstrong.com Git - lilypond.git/commitdiff
Optionally preserve input path.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 30 Mar 2008 19:36:12 +0000 (16:36 -0300)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 13 Apr 2008 19:09:29 +0000 (16:09 -0300)
- 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
lily/lily-parser.cc
scm/backend-library.scm
scm/framework-tex.scm
scm/lily-library.scm
scm/lily.scm
scm/ps-to-png.scm
scripts/lilypond-book.py

index 1631c4a3daa85036b1089bfe62377af3578af684..61ea288fc608221868fc0832234a4deca0a9f5f6 100644 (file)
@@ -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));
index 05412ad05a6ede933174598b2caba5eb3f8a665b..b508860efa2acd19c93dba40c2d338fe39a9de48 100644 (file)
@@ -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;
index 45b156a6c8d84a67a46ef4159f7d5f158b78a5e6..8963fe15caf9b344f55ec26cd19a1aba39d0bcfa 100644 (file)
@@ -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
 (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
index 8b10bac42c8ab0cc8803660ce1cd3be6c1d11cdc..8cfa09b76f30cf00a73744f1ee80c03f8394c841 100644 (file)
         (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))
      (* 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?
            #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)))
 
index ae13bbebf0ec748142485952847b75a2d1273587..f772d0527e931efa53cdf0917fcf359012e911bb 100644 (file)
@@ -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,
index efa40f338be6236123df3c4c50d881e573af4155..a538b3f3edca73f8b0bfea5edd12fb7030073ded 100644 (file)
@@ -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))
index deca66008a977edd6738e895c9695ff5f5c24e6a..474a89628adad1fe968adfa9724618595629868d 100644 (file)
                      ((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))
index 86e78e2449427b2218bd99d6b7dd8c67a9973fad..2c3870a3366ff437469f8806e2283e79ca882c06 100644 (file)
@@ -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.