]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/scores.cc
release: 0.1.61
[lilypond.git] / lily / scores.cc
index 5badc05fb00bb0f2e53c445c417aa8a17b361675..4a25a85a0fc78201c2013868b05a20a770d8acd6 100644 (file)
@@ -3,9 +3,9 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c)  1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
 */
-
+#include <fstream.h>
 #include "main.hh"
 #include "score.hh"
 #include "string.hh"
 #include "header.hh"
 #include "debug.hh"
 #include "parray.hh"
+#include "file-path.hh"
+#include "file-results.hh"
+#include "my-lily-parser.hh"
+#include "source.hh"
+
+Sources* source_global_l = 0;
+Array<String> inclusion_global_array;
+Array<String> target_str_global_array;
+Link_array<Score> score_global_array;
+
+
+void write_dependency_file (String fn, Array<String> targets,
+                           Array<String> deps)
+{
+  const int WRAPWIDTH = 65;
+
+
+  cout << "Writing dependency file " << fn << " ...\n";
+  ofstream f (fn.ch_C ());
+  if (!f)
+    warning ( _("Can't open dependency file `" + fn + "\'"));
+
+  f << "# Automatically generated by " << get_version_str ()  << "\n";
+  String out;
+  for (int i=0; i < targets.size (); i ++)
+     out += targets[i] + " ";
+  out +=  ": ";
+  for (int i=0; i < deps.size (); i ++)
+    {
+      if (out.length_i() > WRAPWIDTH)
+       {
+         f << out << "\\\n";
+         out = "  ";
+       }
+      out  += " " +  deps[i];
+    }
+  f << out << endl; 
+}
 
-static Link_array<Score> global_score_array;
-String default_outname_suffix_global = "";
-String default_outname_base_global =  "lelie";
-int default_count_global;
+void
+do_deps()
+{
+  if (dependency_global_b)
+    {
+      write_dependency_file (default_outname_base_global  + ".dep", target_str_global_array,
+                            inclusion_global_array);
+    }
+}
 
 
 void
 do_scores()
 {
-  for (int i=0; i < global_score_array.size(); i++)
+  for (int i=0; i < score_global_array.size(); i++)
     {
-//      Score *&is_p = global_score_array[i];
-      Score* is_p = global_score_array[i];
+      Score* is_p = score_global_array[i];
       if (!is_p->header_p_)
        is_p->header_p_ = new Header;
       
@@ -43,21 +85,61 @@ do_scores()
          is_p->process();
        }
     }
+  do_deps ();
 }
 
 void
 clear_scores ()
 {
-  for (int i=0; i < global_score_array.size(); i++)
+  for (int i=0; i < score_global_array.size(); i++)
     {
-      delete global_score_array[i];
+      delete score_global_array[i];
     }
-  global_score_array.clear();
+  score_global_array.clear();
+  inclusion_global_array.clear ();
 }
 
+extern File_path path;
+
 void
-add_score (Score * s)
+do_one_file (String init_str, String file_str)
 {
-  global_score_array.push (s);
-}
+  if (init_str.length_i () && path.find (init_str).empty_b ())
+    {
+      error (_("Can not find `") + init_str +"\'");
+      return ;
+    }
+  if (file_str.length_i () && path.find (file_str).empty_b ())
+    {
+      error (_("Can not find `") + file_str + "'");
+      return ;
+    }
+
+  Sources sources;
+  source_global_l = &sources;
+  source_global_l->set_path (&path);
+  {
+    My_lily_parser parser (source_global_l);
+    parser.set_version_check (version_ignore_global_b);
+    parser.parse_file (init_str, file_str);
 
+    
+    if (file_str.length_i () && file_str[0] != '-')
+      {
+       String a,b,c,d;
+       split_path (file_str, a, b, c, d);
+       default_outname_base_global = c;
+      }
+    else
+      default_outname_base_global = "lelie";
+  
+    if (parser.error_level_i_)
+      {
+       exit_status_i_  = 1;
+      }
+    else
+      do_scores ();
+    clear_scores ();
+  }
+  source_global_l = 0;
+}