]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/main.cc (main_with_guile): call lilypond-main
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 11 Apr 2004 15:12:44 +0000 (15:12 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 11 Apr 2004 15:12:44 +0000 (15:12 +0000)
* scm/lily.scm (lilypond-main): new function: handle multiple files.

* lily/input-file-results.cc (LY_DEFINE): throw ly-file-failed
exception.

* lily/my-lily-parser.cc: remove paper_description function

* lily/main.cc: remove global_score_count.

* lily/ly-module.cc (ly_make_anonymous_module): don't protect
anonymous modules globally. Let's hope they get GCd

ChangeLog
lily/input-file-results.cc
lily/ly-module.cc
lily/main.cc
lily/my-lily-parser.cc
scm/lily.scm

index 135cf3ea3005decf2940f6496d3b95534e348541..f6d75da1822ae0204a093392b1601cdd64a5a5d0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2004-04-11  Han-Wen Nienhuys   <hanwen@xs4all.nl>
 
+       * lily/main.cc (main_with_guile): call lilypond-main
+
+       * scm/lily.scm (lilypond-main): new function: handle multiple files.
+
+       * lily/input-file-results.cc (LY_DEFINE): throw ly-file-failed
+       exception.
+
+       * lily/my-lily-parser.cc: remove paper_description function
+
        * lily/music-output-def.cc (LY_DEFINE): ly:output-description
        new function.
 
index 5c900200c76a076e8c557bb1218fee7a4cb3534a..5049a6bcac770ec43ed52bbd8fae06643e652a0e 100644 (file)
@@ -130,7 +130,7 @@ distill_inname (String str)
 LY_DEFINE(ly_parse_file, "ly:parse-file",
          1,0,0,
          (SCM name),
-         "Parse a single @code{.ly} file."
+         "Parse a single @code{.ly} file. If this fails, then throw @code{ly-file-failed} key. "
          )
 {
   SCM_ASSERT_TYPE (is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
@@ -161,45 +161,51 @@ LY_DEFINE(ly_parse_file, "ly:parse-file",
   String in_file = inpath.to_string ();
   String out_file = outpath.to_string ();
 
+
   if (init.length () && global_path.find (init).is_empty ())
     {
-      warning (_f ("can't find file: `%s'", init));
+      warning (_f ("can't find init file: `%s'", init));
       warning (_f ("(search path: `%s')", global_path.to_string ().to_str0 ()));
-      return SCM_UNSPECIFIED;
+      exit (2);
     }
 
   if ((in_file != "-") && global_path.find (in_file).is_empty ())
     {
       warning (_f ("can't find file: `%s'", in_file));
-      return SCM_UNSPECIFIED;
+      scm_throw (ly_symbol2scm ("ly-file-failed"), scm_list_1 (scm_makfrom0str (in_file.to_str0 ())));
     }
+  else
+    {
+      Sources sources;
+      sources.set_path (&global_path);
   
-  Sources sources;
-  sources.set_path (&global_path);
-  
-  progress_indication (_f ("Now processing `%s'", in_file.to_str0 ()));
-  progress_indication ("\n");
+      progress_indication (_f ("Now processing `%s'", in_file.to_str0 ()));
+      progress_indication ("\n");
 
-  My_lily_parser parser (&sources);
-  parser.parse_file (init, in_file, out_file);
+      My_lily_parser parser (&sources);
+      parser.parse_file (init, in_file, out_file);
   
-  if (parser.error_level_)
-    {
-      exit_status_global = 1;
-      failed_files.push (in_file);
-    }
+
 
 #if 0
-  // fixme dependencies
-  if (dependency_global_b)
-    {
-      Path p = split_path (output);
-      p.ext = "dep";
-      write_dependency_file (p.to_string (),
-                            target_strings_,
-                            inclusion_names_);
-    }
+      // fixme dependencies
+      if (dependency_global_b)
+       {
+         Path p = split_path (output);
+         p.ext = "dep";
+         write_dependency_file (p.to_string (),
+                                target_strings_,
+                                inclusion_names_);
+       }
 #endif
-
+  
+      if (parser.error_level_)
+       {
+         /*
+           TODO: pass renamed input file too.
+         */
+         scm_throw (ly_symbol2scm ("ly-file-failed"), scm_list_1 (scm_makfrom0str (in_file.to_str0 ()))); 
+       }
+    }
   return SCM_UNSPECIFIED;
 }
index d7d72fce5be2dfca1a4cfa8d67e109c5c7cc7b5f..1921c9084e262ebef3f623d68806c575b5150690 100644 (file)
@@ -113,11 +113,10 @@ ly_modules_lookup (SCM modules, SCM sym)
 }
 
 
-SCM export_function;
-
 void
 ly_export (SCM module, SCM namelist)
 {
+  static SCM export_function;
   if (!export_function)
     export_function = scm_permanent_object (scm_c_lookup ("module-export!"));
   
index c9a60ca970218c7da02314f358c68bc09757fbc6..7431bce28df601b951177c7cc1c9351651cb32b3 100644 (file)
@@ -34,8 +34,6 @@
 #include "global-ctor.hh"
 #include "kpath.hh"
 
-Array<String> failed_files;
-
 /*
  * Global options that can be overridden through command line.
  */
@@ -78,8 +76,6 @@ String init_scheme_code_string = "(begin #t ";
 /*
  * Miscellaneous global stuff.
  */
-
-int exit_status_global;
 File_path global_path;
 
 
@@ -281,38 +277,35 @@ main_with_guile (void *, int, char **)
   /* We accept multiple independent music files on the command line to
      reduce compile time when processing lots of small files.
      Starting the GUILE engine is very time consuming.  */
+
+  SCM files = SCM_EOL;
+  SCM *tail = &files;
   bool first = true;
   while (char const *arg = option_parser->get_next_arg ())
     {
-#if 0
-      /* Code to debug memory leaks.  Cannot call from within .ly
-        since then we get the protects from the parser state too.  */
-      scm_gc ();
-      scm_call_0 (ly_scheme_function ("dump-gc-protects"));
-#endif
-      ly_parse_file (scm_makfrom0str (arg));
-      first = false;
+      *tail = scm_cons (scm_makfrom0str (arg), SCM_EOL);
+      tail = SCM_CDRLOC(*tail);
     }
   delete option_parser;
   option_parser = 0;
 
-  /* No FILE arguments is now a usage error to help newbies.  If you
+  if (files == SCM_EOL)
+    {
+      /* No FILE arguments is now a usage error to help newbies.  If you
      want a filter, you're not a newbie and should know to use file
      argument `-'.  */
-  if (first)
-    {
       usage ();
       exit (2);
     }
 
-  if (exit_status_global)
-    {
-      printf ("Failed files: ");
-      for (int i = 0; i < failed_files.size (); i++)
-       printf ("%s ", failed_files[i].to_str0 ());
-      printf ("\n");
-    }
-  exit (exit_status_global);
+  SCM result = scm_call_1 (ly_scheme_function ("lilypond-main"),
+                          files);
+
+
+  /*
+    unreachable.
+   */
+  exit (0);
 }
 
 static void
index 7c5e9b16078fcc2ae68c3d2aba174dff0f79d17b..097a941bd7c820b07d8c9e41538338c00348b188 100644 (file)
@@ -82,7 +82,6 @@ My_lily_parser::parser_error (String s)
 {
   here_input ().error (s);
   error_level_ = 1;
-  exit_status_global = 1;
 }
 
 
index 0e994112d96d076a08126b54f633bc7c095e38e2..f163d26c71028b466f2c33e5a5b5edbb051f1924 100644 (file)
@@ -515,3 +515,30 @@ L1 is copied, L2 not.
 
     ))
 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
+
+(define-public (lilypond-main files)
+  "Entry point for Lilypond"
+  (let*
+      ((failed '())
+       (handler (lambda (key arg)
+                 (set! failed (cons arg failed))))
+       )
+
+    (for-each
+     (lambda (fn)
+       (catch 'ly-file-failed
+             (lambda () (ly:parse-file fn))
+             handler))
+       
+       files)
+
+    (if (pair? failed)
+       (begin
+         (display (string-append "\n *** Failed files: " (string-join failed) "\n" ))
+         (exit 1))
+       (exit 0))
+
+    ))
+
+