lilypond-1.3.65
[lilypond.git] / lily / scores.cc
blob86c03032843b16604cffdfafbcc03581497f1379
1 /*
2 scores.cc -- implement some globals
4 source file of the GNU LilyPond music typesetter
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"
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;
29 void write_dependency_file (String fn, Array<String> targets,
30 Array<String> deps)
32 const int WRAPWIDTH = 65;
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));
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 ++)
47 if (out.length_i() > WRAPWIDTH)
49 f << out << "\\\n";
50 out = " ";
52 out += " " + deps[i];
54 f << out << endl;
57 void
58 do_deps()
60 if (dependency_global_b)
62 write_dependency_file (default_outname_base_global + ".dep", target_str_global_array,
63 inclusion_global_array);
68 void
69 do_scores()
71 if (!header_global_p)
72 header_global_p = new Scope;
73 for (int i=0; i < score_global_array.size(); i++)
75 Score* is_p = score_global_array[i];
77 if (is_p->errorlevel_i_)
79 is_p->warning (_("Score contains errors; will not process it"));
80 exit_status_i_ |= 1;
82 else
84 if (flower_dstream && !flower_dstream->silent_b ("do_scores"))
85 is_p->print ();
86 is_p->process();
89 do_deps ();
92 void
93 clear_scores ()
95 junk_pointer_array (score_global_array);
97 inclusion_global_array.clear ();
98 delete header_global_p ;
99 header_global_p =0;
103 void
104 do_one_file (String init_str, String file_str)
106 if (init_str.length_i () && global_path.find (init_str).empty_b ())
108 warning (_f ("can't find file: `%s'", init_str));
109 warning (_f ("(search path: `%s')", global_path.str ().ch_C()));
110 return;
112 if ((file_str != "-") && global_path.find (file_str).empty_b ())
114 warning (_f ("can't find file: `%s'", file_str));
115 return;
118 Sources sources;
119 source_global_l = &sources;
120 source_global_l->set_path (&global_path);
122 My_lily_parser parser (source_global_l);
123 parser.set_version_check (false);
124 cout << "\nNow processing `" << file_str << "'\n";
125 parser.parse_file (init_str, file_str);
127 if (parser.error_level_i_)
129 exit_status_i_ = 1;
131 else
132 do_scores ();
133 clear_scores ();
135 source_global_l = 0;