]> git.donarmstrong.com Git - lilypond.git/blob - lily/scores.cc
f41666b0ad7f8d8d202ac43e193c0890485f1c95
[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--1998 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 "lookup.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 Header * 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
35   cout << _f ("writing dependency file: `%s\'...", fn) << '\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 " << get_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 Header;
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           if (!monitor->silent_b ("do_scores"))
85               is_p->print ();
86           is_p->process();
87         }
88     }
89   do_deps ();
90 }
91
92 void
93 clear_scores ()
94 {
95   for (int i=0; i < score_global_array.size(); i++)
96     {
97       delete score_global_array[i];
98     }
99   score_global_array.clear();
100   inclusion_global_array.clear ();
101   delete  header_global_p ;
102   header_global_p =0; 
103 }
104
105
106 void
107 do_one_file (String init_str, String file_str)
108 {
109   if (init_str.length_i () && global_path.find (init_str).empty_b ())
110     {
111       warning (_f ("can't find file: `%s\'", init_str));
112       return;
113     }
114   if ((file_str != "-") && global_path.find (file_str).empty_b ())
115     {
116       warning (_f ("can't find file: `%s\'", file_str));
117       return;
118     }
119
120   Sources sources;
121   source_global_l = &sources;
122   source_global_l->set_path (&global_path);
123   {
124     My_lily_parser parser (source_global_l);
125     parser.set_version_check (version_ignore_global_b);
126     parser.parse_file (init_str, file_str);
127
128     /*
129        urg
130        when calling {Ps,Tex}_lookup::paper_stream_p (),
131        it *appears* (aaargh, latest gdb on ppc is gdb 4.16.97)
132        that (global_lookup_l's) 
133        paper_l_ is invalid but not NULL
134        (deleted without being reset maybe?)
135      */
136     global_lookup_l->paper_l_ = parser.default_paper_p ();
137
138     if (parser.error_level_i_)
139       {
140         exit_status_i_  = 1;
141       }
142     else
143       do_scores ();
144     clear_scores ();
145   }
146   source_global_l = 0;
147 }
148