]> git.donarmstrong.com Git - lilypond.git/blob - lily/scores.cc
patch::: 1.0.12.hwn1
[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 "header.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
21 Sources* source_global_l = 0;
22 Array<String> inclusion_global_array;
23 Array<String> target_str_global_array;
24 Link_array<Score> score_global_array;
25 Header * header_global_p;
26
27
28 void write_dependency_file (String fn, Array<String> targets,
29                             Array<String> deps)
30 {
31   const int WRAPWIDTH = 65;
32
33
34   cout << _f ("writing dependency file: `%s\'...", fn) << '\n';
35   ofstream f (fn.ch_C ());
36   if (!f)
37     warning (_f ("can't open file: `%s\'", fn));
38
39   f << "# Automatically generated by " << get_version_str ()  << '\n';
40   String out;
41   for (int i=0; i < targets.size (); i ++)
42      out += targets[i] + " ";
43   out +=  ": ";
44   for (int i=0; i < deps.size (); i ++)
45     {
46       if (out.length_i() > WRAPWIDTH)
47         {
48           f << out << "\\\n";
49           out = "  ";
50         }
51       out  += " " +  deps[i];
52     }
53   f << out << endl; 
54 }
55
56 void
57 do_deps()
58 {
59   if (dependency_global_b)
60     {
61       write_dependency_file (default_outname_base_global  + ".dep", target_str_global_array,
62                              inclusion_global_array);
63     }
64 }
65
66
67 void
68 do_scores()
69 {
70   if (!header_global_p)
71     header_global_p = new Header;
72   for (int i=0; i < score_global_array.size(); i++)
73     {
74       Score* is_p = score_global_array[i];
75
76       if (is_p->errorlevel_i_)
77         {
78           is_p->warning (_("score contains errors; will not process it"));
79           exit_status_i_ |= 1;
80         }
81       else
82         {
83           if (!monitor->silent_b ("do_scores"))
84               is_p->print ();
85           is_p->process();
86         }
87     }
88   do_deps ();
89 }
90
91 void
92 clear_scores ()
93 {
94   for (int i=0; i < score_global_array.size(); i++)
95     {
96       delete score_global_array[i];
97     }
98   score_global_array.clear();
99   inclusion_global_array.clear ();
100   delete  header_global_p ;
101   header_global_p =0; 
102 }
103
104
105 void
106 do_one_file (String init_str, String file_str)
107 {
108   if (init_str.length_i () && global_path.find (init_str).empty_b ())
109     {
110       warning (_f ("can't find file: `%s\'", init_str));
111       return;
112     }
113   if ((file_str != "-") && global_path.find (file_str).empty_b ())
114     {
115       warning (_f ("can't find file: `%s\'", file_str));
116       return;
117     }
118
119   Sources sources;
120   source_global_l = &sources;
121   source_global_l->set_path (&global_path);
122   {
123     My_lily_parser parser (source_global_l);
124     parser.set_version_check (version_ignore_global_b);
125     parser.parse_file (init_str, file_str);
126
127     if (parser.error_level_i_)
128       {
129         exit_status_i_  = 1;
130       }
131     else
132       do_scores ();
133     clear_scores ();
134   }
135   source_global_l = 0;
136 }
137