]> git.donarmstrong.com Git - lilypond.git/blob - lily/scores.cc
release: 1.3.75
[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           if (flower_dstream && !flower_dstream->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   junk_pointer_array (score_global_array);
96
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       warning (_f ("(search path: `%s')", global_path.str ().ch_C()));
110       return;
111     }
112   if ((file_str != "-") && global_path.find (file_str).empty_b ())
113     {
114       warning (_f ("can't find file: `%s'", file_str));
115       return;
116     }
117
118   Sources sources;
119   source_global_l = &sources;
120   source_global_l->set_path (&global_path);
121   {
122     My_lily_parser parser (source_global_l);
123     parser.set_version_check (false);
124     progress_indication (_f ("Now processing: `%s'", file_str.ch_C ()));
125     progress_indication ("\n");
126     parser.parse_file (init_str, file_str);
127
128     if (parser.error_level_i_)
129       {
130         exit_status_i_  = 1;
131       }
132     else
133       do_scores ();
134     clear_scores ();
135   }
136   source_global_l = 0;
137 }
138