lilypond-1.4.3
[lilypond.git] / lily / scores.cc
blobc711d24a2bf2f7ba1e110015c1e639477cf93063
1 /*
2 scores.cc -- implement some globals
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "config.h"
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>
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"
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;
39 void write_dependency_file (String fn, Array<String> targets,
40 Array<String> deps)
42 const int WRAPWIDTH = 65;
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));
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 ++)
60 if (out.length_i () > WRAPWIDTH)
62 f << out << "\\\n";
63 out = " ";
65 String dep = deps[i];
66 if (!dependency_prefix_global.empty_b ())
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;
76 out += " " + dep;
78 f << out << endl;
81 void
82 do_deps ()
84 if (dependency_global_b)
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);
95 void
96 do_scores ()
98 if (!global_header_p)
99 global_header_p = new Scheme_hash_table;
100 for (int i=0; i < score_global_array.size (); i++)
102 Score* is_p = score_global_array[i];
104 if (is_p->errorlevel_i_)
106 is_p->warning (_ ("Score contains errors; will not process it"));
107 exit_status_global |= 1;
109 else
111 is_p->process ();
114 do_deps ();
117 void
118 clear_scores ()
120 for (int i=0; i < score_global_array.size (); i++)
121 scm_unprotect_object (score_global_array[i]->self_scm ());
122 score_global_array.clear ();
124 inclusion_global_array.clear ();
125 if (global_header_p)
126 scm_unprotect_object (global_header_p ->self_scm ());
127 global_header_p =0;
131 void
132 do_one_file (String init_str, String file_str)
134 if (init_str.length_i () && global_path.find (init_str).empty_b ())
136 warning (_f ("can't find file: `%s'", init_str));
137 warning (_f ("(search path: `%s')", global_path.str ().ch_C ()));
138 return;
140 if ((file_str != "-") && global_path.find (file_str).empty_b ())
142 warning (_f ("can't find file: `%s'", file_str));
143 return;
146 Sources sources;
147 source_global_l = &sources;
148 source_global_l->set_path (&global_path);
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);
156 if (parser.error_level_i_)
158 exit_status_global = 1;
160 else
161 do_scores ();
162 clear_scores ();
164 source_global_l = 0;