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