]> git.donarmstrong.com Git - lilypond.git/blob - lily/scores.cc
patch::: 1.3.124.jcn1
[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 #include "scm-hash.hh"
22
23 Sources* source_global_l = 0;
24 Array<String> inclusion_global_array;
25 Array<String> target_str_global_array;
26 Link_array<Score> score_global_array;
27 Scheme_hash_table * global_header_p;
28
29
30 void write_dependency_file (String fn, Array<String> targets,
31                             Array<String> deps)
32 {
33   const int WRAPWIDTH = 65;
34
35   progress_indication (_f ("Writing dependency file: `%s'...", fn.ch_C ()));
36   progress_indication ("\n");
37   ofstream f (fn.ch_C ());
38   if (!f)
39     warning (_f ("can't open file: `%s'", fn));
40
41   f << "# Automatically generated by " << gnu_lilypond_version_str ()  << '\n';
42   String out;
43   for (int i=0; i < targets.size (); i ++)
44      out += targets[i] + " ";
45   out +=  ": ";
46   for (int i=0; i < deps.size (); i ++)
47     {
48       if (out.length_i() > WRAPWIDTH)
49         {
50           f << out << "\\\n";
51           out = "  ";
52         }
53       out  += " " +  deps[i];
54     }
55   f << out << endl; 
56 }
57
58 void
59 do_deps()
60 {
61   if (dependency_global_b)
62     {
63       write_dependency_file (default_outname_base_global  + ".dep", target_str_global_array,
64                              inclusion_global_array);
65     }
66 }
67
68
69 void
70 do_scores()
71 {
72   if (!global_header_p)
73     global_header_p = new Scheme_hash_table;
74   for (int i=0; i < score_global_array.size(); i++)
75     {
76       Score* is_p = score_global_array[i];
77
78       if (is_p->errorlevel_i_)
79         {
80           is_p->warning (_("Score contains errors; will not process it"));
81           exit_status_i_ |= 1;
82         }
83       else
84         {
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     scm_unprotect_object (score_global_array[i]->self_scm ());
96   score_global_array.clear();
97   
98   inclusion_global_array.clear ();
99   if (global_header_p)
100     scm_unprotect_object (global_header_p ->self_scm ());
101   global_header_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       warning (_f ("(search path: `%s')", global_path.str ().ch_C()));
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 (false);
126     progress_indication (_f ("Now processing: `%s'", file_str.ch_C ()));
127     progress_indication ("\n");
128     parser.parse_file (init_str, file_str);
129
130     if (parser.error_level_i_)
131       {
132         exit_status_i_  = 1;
133       }
134     else
135       do_scores ();
136     clear_scores ();
137   }
138   source_global_l = 0;
139 }
140