]> git.donarmstrong.com Git - lilypond.git/blob - lily/scores.cc
release: 1.0.1
[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           is_p->process();
84         }
85     }
86   do_deps ();
87 }
88
89 void
90 clear_scores ()
91 {
92   for (int i=0; i < score_global_array.size(); i++)
93     {
94       delete score_global_array[i];
95     }
96   score_global_array.clear();
97   inclusion_global_array.clear ();
98   delete  header_global_p ;
99   header_global_p =0; 
100 }
101
102
103 void
104 do_one_file (String init_str, String file_str)
105 {
106   if (init_str.length_i () && global_path.find (init_str).empty_b ())
107     {
108       warning (_f ("can't find file: `%s\'", init_str));
109       return;
110     }
111   if ((file_str != "-") && global_path.find (file_str).empty_b ())
112     {
113       warning (_f ("can't find file: `%s\'", file_str));
114       return;
115     }
116
117   Sources sources;
118   source_global_l = &sources;
119   source_global_l->set_path (&global_path);
120   {
121     My_lily_parser parser (source_global_l);
122     parser.set_version_check (version_ignore_global_b);
123     parser.parse_file (init_str, file_str);
124
125     if (parser.error_level_i_)
126       {
127         exit_status_i_  = 1;
128       }
129     else
130       do_scores ();
131     clear_scores ();
132   }
133   source_global_l = 0;
134 }
135