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