]> git.donarmstrong.com Git - lilypond.git/blob - lily/scores.cc
release: 1.3.93
[lilypond.git] / lily / scores.cc
1 /*
2   scores.cc -- implement some globals
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include <fstream.h>
9 #include "main.hh"
10 #include "score.hh"
11 #include "string.hh"
12 #include "paper-def.hh"
13 #include "scope.hh"
14 #include "debug.hh"
15 #include "parray.hh"
16 #include "file-path.hh"
17 #include "file-results.hh"
18 #include "my-lily-parser.hh"
19 #include "source.hh"
20 #include "lily-version.hh"
21
22 Sources* source_global_l = 0;
23 Array<String> inclusion_global_array;
24 Array<String> target_str_global_array;
25 Link_array<Score> score_global_array;
26 Scope * header_global_p;
27
28
29 void write_dependency_file (String fn, Array<String> targets,
30                             Array<String> deps)
31 {
32   const int WRAPWIDTH = 65;
33
34   progress_indication (_f ("Writing dependency file: `%s'...", fn.ch_C ()));
35   progress_indication ("\n");
36   ofstream f (fn.ch_C ());
37   if (!f)
38     warning (_f ("can't open file: `%s'", fn));
39
40   f << "# Automatically generated by " << gnu_lilypond_version_str ()  << '\n';
41   String out;
42   for (int i=0; i < targets.size (); i ++)
43      out += targets[i] + " ";
44   out +=  ": ";
45   for (int i=0; i < deps.size (); i ++)
46     {
47       if (out.length_i() > WRAPWIDTH)
48         {
49           f << out << "\\\n";
50           out = "  ";
51         }
52       out  += " " +  deps[i];
53     }
54   f << out << endl; 
55 }
56
57 void
58 do_deps()
59 {
60   if (dependency_global_b)
61     {
62       write_dependency_file (default_outname_base_global  + ".dep", target_str_global_array,
63                              inclusion_global_array);
64     }
65 }
66
67
68 void
69 do_scores()
70 {
71   if (!header_global_p)
72     header_global_p = new Scope;
73   for (int i=0; i < score_global_array.size(); i++)
74     {
75       Score* is_p = score_global_array[i];
76
77       if (is_p->errorlevel_i_)
78         {
79           is_p->warning (_("Score contains errors; will not process it"));
80           exit_status_i_ |= 1;
81         }
82       else
83         {
84           is_p->process();
85         }
86     }
87   do_deps ();
88 }
89
90 void
91 clear_scores ()
92 {
93   junk_pointer_array (score_global_array);
94
95   inclusion_global_array.clear ();
96   delete  header_global_p ;
97   header_global_p =0; 
98 }
99
100
101 void
102 do_one_file (String init_str, String file_str)
103 {
104   if (init_str.length_i () && global_path.find (init_str).empty_b ())
105     {
106       warning (_f ("can't find file: `%s'", init_str));
107       warning (_f ("(search path: `%s')", global_path.str ().ch_C()));
108       return;
109     }
110   if ((file_str != "-") && global_path.find (file_str).empty_b ())
111     {
112       warning (_f ("can't find file: `%s'", file_str));
113       return;
114     }
115
116   Sources sources;
117   source_global_l = &sources;
118   source_global_l->set_path (&global_path);
119   {
120     My_lily_parser parser (source_global_l);
121     parser.set_version_check (false);
122     progress_indication (_f ("Now processing: `%s'", file_str.ch_C ()));
123     progress_indication ("\n");
124     parser.parse_file (init_str, file_str);
125
126     if (parser.error_level_i_)
127       {
128         exit_status_i_  = 1;
129       }
130     else
131       do_scores ();
132     clear_scores ();
133   }
134   source_global_l = 0;
135 }
136