]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/input-file-results.cc
* buildscripts/lilypond.words.py: remove.
[lilypond.git] / lily / input-file-results.cc
index 64113912ae70ca5750c3584308dd3e6195090cdd..0da68c899dffddd3672fcc5d8f4353d34728d92d 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 #include "config.h"
 
 #include "source.hh"
 #include "lily-version.hh"
 #include "scm-hash.hh"
-#include "ly-modules.hh"
+#include "ly-module.hh"
 
+#include "paper-book.hh"
 
-LY_DEFINE(ly_set_point_and_click_x, "set-point-and-click!", 1, 0, 0,
+bool store_locations_global_b;
+
+/*
+  TODO: should merge with My_lily_parser. 
+ */
+
+/*
+  no ! suffix since it doesn't modify 1st argument.
+ */
+LY_DEFINE (ly_set_point_and_click, "ly:set-point-and-click", 1, 0, 0,
          (SCM what),
-         "Set the options for Point-and-click source specials output. The
-argument is a symbol.  Possible options are @code{none} (no source specials),
-@code{line} and @code{line-column}")
+         "Set the options for Point-and-click source specials output. The\n"
+"argument is a symbol.  Possible options are @code{none} (no source specials),\n"
+"@code{line} and @code{line-column}")
 {
   /*
     UGH.
@@ -48,8 +58,7 @@ argument is a symbol.  Possible options are @code{none} (no source specials),
   else if (what == ly_symbol2scm ("line"))
     val = gh_eval_str ("line-location");
 
-  extern SCM lily_module; 
-  scm_module_define (lily_module, ly_symbol2scm ("point-and-click"), val);
+  scm_module_define (global_lily_module, ly_symbol2scm ("point-and-click"), val);
 
   store_locations_global_b =gh_procedure_p (val);
   return SCM_UNSPECIFIED;
@@ -83,14 +92,9 @@ write_dependency_file (String fn,
          out = "  ";
        }
       String dep = deps[i];
-      if (!dependency_prefix_global.empty_b ())
+      if (!dependency_prefix_global.is_empty ())
        {
-#if 0//thinko?
-         if (stat (dep.to_str0 (), &stat_buf) == -1 && errno == ENOENT)
-           ; //make emacs happy
-#else
          if (dep.index ('/') < 0)
-#endif
            dep = dependency_prefix_global + dep;
        }
       out  += " " +  dep;
@@ -100,100 +104,132 @@ write_dependency_file (String fn,
 
 
 void
-Input_file_results::do_deps ()
+Input_file_results::do_deps (String output)
 {
   if (dependency_global_b)
     {
-      Path p = split_path (output_name_global);
+      Path p = split_path (output);
       p.ext = "dep";
-      write_dependency_file (p.string (),
+      write_dependency_file (p.to_string (),
                             target_strings_,
                             inclusion_names_);
     }
 }
 
-
-void
-Input_file_results::do_scores ()
-{
-  if (header_ == SCM_EOL)
-    header_ = ly_make_anonymous_module ();
-
-  for (int i=0; i < scores_.size (); i++)
-    {
-      Score* is = scores_[i];
-      is->input_file_ = this;
-      
-      if (is->errorlevel_)
-       {
-         is->warning (_ ("Score contains errors; will not process it"));
-         exit_status_global |= 1;
-       }
-      else
-       {
-         is->process ();
-       }
-    }
-  do_deps ();
-}
-
 Input_file_results::~Input_file_results ()
 {
-  for (int i=0; i < scores_.size (); i++)
-    scm_gc_unprotect_object (scores_[i]->self_scm ());
-  scores_.clear ();
-  
   inclusion_names_.clear ();
   if (header_)
     header_ = SCM_EOL;
 
-  global_input_file =0;
+  global_input_file = 0;
 
-  ly_clear_anonymous_modules();
+  ly_clear_anonymous_modules ();
 }
 
 
 
 Input_file_results* global_input_file;
 
-Input_file_results::Input_file_results (String init_string, String file_string)
+Input_file_results::Input_file_results (String init, String in_file, String out_file)
 {
-  header_ = SCM_EOL;
+  header_ = ly_make_anonymous_module ();
   global_input_file = this;
-  ly_set_point_and_click_x (SCM_BOOL_F);
-  
+  score_count_ = 0;
   sources_.set_path (&global_path);
   
-  My_lily_parser parser (this);
 
-  progress_indication (_f ("Now processing: `%s'", file_string.to_str0 ()));
+  progress_indication (_f ("Now processing `%s'", in_file.to_str0 ()));
   progress_indication ("\n");
-  parser.parse_file (init_string, file_string);
+
+  My_lily_parser parser (this);
+  parser.parse_file (init, in_file, out_file);
   
   if (parser.error_level_)
     {
       exit_status_global  = 1;
+      failed_files.push (in_file);
     }
-  else
-    do_scores ();
+
   
+  do_deps (out_file);
 }
 
+/* Distill full input file name from command argument.  PATH describes
+   file name with added default extension, ".ly" if none.  "-" is
+   STDIN.  */
+Path
+distill_inname (String str)
+{
+  Path p = split_path (str);
+  if (str.is_empty () || str == "-")
+    p.base = "-";
+  else
+    {
+      String orig_ext = p.ext;
+      char const *extensions[] = {"ly", "", 0};
+      for (int i = 0; extensions[i]; i++)
+       {
+         p.ext = orig_ext;
+         if (*extensions[i] && !p.ext.is_empty ())
+           p.ext += ".";
+         p.ext += extensions[i];
+         if (!global_path.find (p.to_string ()).is_empty ())
+             break;
+       }
+      /* Reshuffle extension */
+      p = split_path (p.to_string ());
+    }
+  return p;
+}
 
+/* ugr. */
 void
-do_one_file (String init_string, String file_string) 
+do_one_file (char const *file)
 {
-   if (init_string.length () && global_path.find (init_string).empty_b ())
+  String infile (file);
+  Path inpath = distill_inname (infile);
+  
+  /* By default, use base name of input file for output file name */
+  Path outpath = inpath;
+  if (inpath.to_string () != "-")
+    outpath.ext = output_format_global;
+  
+  /* By default, write output to cwd; do not copy directory part
+     of input file name */
+  outpath.root = "";
+  outpath.dir = "";
+  
+  if (!output_name_global.is_empty ())
+    outpath = split_path (output_name_global);
+  
+  String init;
+  if (!init_name_global.is_empty ())
+    init = init_name_global;
+  else
+    init = "init.ly";
+  
+  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_string));
-      warning (_f ("(search path: `%s')", global_path.string ().to_str0 ()));
+      warning (_f ("can't find file: `%s'", init));
+      warning (_f ("(search path: `%s')", global_path.to_string ().to_str0 ()));
       return;
     }
-  if ((file_string != "-") && global_path.find (file_string).empty_b ())
+
+  if ((in_file != "-") && global_path.find (in_file).is_empty ())
     {
-      warning (_f ("can't find file: `%s'", file_string));
+      warning (_f ("can't find file: `%s'", in_file));
       return;
     }
 
-  Input_file_results inp_file(init_string, file_string);
+  paper_book = new Paper_book ();;
+  Input_file_results inp_file (init, in_file, out_file);
+  if (output_format_global == PAGE_LAYOUT)
+    paper_book->output (out_file);
+
+  scm_gc_unprotect_object (paper_book->self_scm ());
+  paper_book = 0;
 }