]> git.donarmstrong.com Git - lilypond.git/blob - lily/scores.cc
release: 1.5.29
[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--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "config.h"
9
10 #include <errno.h>
11 #include <sys/types.h>
12 #if HAVE_SYS_STAT_H 
13 #include <sys/stat.h>
14 #endif
15 #include <unistd.h>
16
17 #include <fstream.h>
18 #include "main.hh"
19 #include "score.hh"
20 #include "string.hh"
21 #include "paper-def.hh"
22 #include "scope.hh"
23 #include "debug.hh"
24 #include "parray.hh"
25 #include "file-path.hh"
26 #include "file-results.hh"
27 #include "my-lily-parser.hh"
28 #include "source.hh"
29 #include "lily-version.hh"
30 #include "scm-hash.hh"
31
32 Sources* source_global_l = 0;
33 Array<String> inclusion_global_array;
34 Array<String> target_str_global_array;
35 Link_array<Score> score_global_array;
36 Scheme_hash_table * global_header_p;
37
38
39 void write_dependency_file (String fn, Array<String> targets,
40                             Array<String> deps)
41 {
42   const int WRAPWIDTH = 65;
43
44   progress_indication (_f ("dependencies output to `%s'...", fn.ch_C ()));
45   progress_indication ("\n");
46   ofstream f (fn.ch_C ());
47   if (!f)
48     warning (_f ("can't open file: `%s'", fn));
49
50   f << "# Generated automatically by: " << gnu_lilypond_version_str ()  << '\n';
51   String out;
52   for (int i=0; i < targets.size (); i ++)
53      out += dependency_prefix_global + targets[i] + " ";
54   out +=  ": ";
55 #if 0
56   struct stat stat_buf;
57 #endif
58   for (int i=0; i < deps.size (); i ++)
59     {
60       if (out.length_i () > WRAPWIDTH)
61         {
62           f << out << "\\\n";
63           out = "  ";
64         }
65       String dep = deps[i];
66       if (!dependency_prefix_global.empty_b ())
67         {
68 #if 0//thinko?
69           if (stat (dep.ch_C (), &stat_buf) == -1 && errno == ENOENT)
70             ; //make emacs happy
71 #else
72           if (dep.index_i ('/') < 0)
73 #endif
74             dep = dependency_prefix_global + dep;
75         }
76       out  += " " +  dep;
77     }
78   f << out << endl; 
79 }
80
81 void
82 do_deps ()
83 {
84   if (dependency_global_b)
85     {
86       Path p = split_path (output_name_global);
87       p.ext = "dep";
88       write_dependency_file (p.str (),
89                              target_str_global_array,
90                              inclusion_global_array);
91     }
92 }
93
94
95 void
96 do_scores ()
97 {
98   if (!global_header_p)
99     global_header_p = new Scheme_hash_table;
100   for (int i=0; i < score_global_array.size (); i++)
101     {
102       Score* is_p = score_global_array[i];
103
104       if (is_p->errorlevel_i_)
105         {
106           is_p->warning (_ ("Score contains errors; will not process it"));
107           exit_status_global |= 1;
108         }
109       else
110         {
111           is_p->process ();
112         }
113     }
114   do_deps ();
115 }
116
117 void
118 clear_scores ()
119 {
120   for (int i=0; i < score_global_array.size (); i++)
121     scm_gc_unprotect_object (score_global_array[i]->self_scm ());
122   score_global_array.clear ();
123   
124   inclusion_global_array.clear ();
125   if (global_header_p)
126     scm_gc_unprotect_object (global_header_p ->self_scm ());
127   global_header_p =0; 
128 }
129
130
131 void
132 do_one_file (String init_str, String file_str)
133 {
134   if (init_str.length_i () && global_path.find (init_str).empty_b ())
135     {
136       warning (_f ("can't find file: `%s'", init_str));
137       warning (_f ("(search path: `%s')", global_path.str ().ch_C ()));
138       return;
139     }
140   if ((file_str != "-") && global_path.find (file_str).empty_b ())
141     {
142       warning (_f ("can't find file: `%s'", file_str));
143       return;
144     }
145
146   Sources sources;
147   source_global_l = &sources;
148   source_global_l->set_path (&global_path);
149   {
150     My_lily_parser parser (source_global_l);
151     parser.set_version_check (false);
152     progress_indication (_f ("Now processing: `%s'", file_str.ch_C ()));
153     progress_indication ("\n");
154     parser.parse_file (init_str, file_str);
155
156     if (parser.error_level_i_)
157       {
158         exit_status_global  = 1;
159       }
160     else
161       do_scores ();
162     clear_scores ();
163   }
164   source_global_l = 0;
165 }
166