]> git.donarmstrong.com Git - lilypond.git/blob - lily/input-file-results.cc
* lily/source-file.cc (get_line): oops. All line numbers were off
[lilypond.git] / lily / input-file-results.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 "input-file-results.hh"
29 #include "my-lily-parser.hh"
30 #include "source.hh"
31 #include "lily-version.hh"
32 #include "scm-hash.hh"
33 #include "ly-modules.hh"
34
35
36 LY_DEFINE(ly_set_point_and_click_x, "set-point-and-click!", 1, 0, 0,
37           (SCM what),
38           "Set the options for Point-and-click source specials output. The
39 argument is a symbol.  Possible options are @code{none} (no source specials),
40 @code{line} and @code{line-column}")
41 {
42   /*
43     UGH.
44    */
45   SCM val = SCM_BOOL_F;
46   if (ly_symbol2scm ("line-column") == what)
47     val = gh_eval_str ("line-column-location");
48   else if (what == ly_symbol2scm ("line"))
49     val = gh_eval_str ("line-location");
50
51   extern SCM lily_module; 
52   scm_module_define (lily_module, ly_symbol2scm ("point-and-click"), val);
53
54   store_locations_global_b =gh_procedure_p (val);
55   return SCM_UNSPECIFIED;
56 }
57
58 void
59 write_dependency_file (String fn,
60                        Array<String> targets,
61                        Array<String> deps)
62 {
63   const int WRAPWIDTH = 65;
64
65   progress_indication (_f ("dependencies output to `%s'...", fn.to_str0 ()));
66   progress_indication ("\n");
67   FILE * f = fopen  (fn.to_str0 (), "w");
68   if (!f)
69     warning (_f ("can't open file: `%s'", fn));
70
71   fprintf (f, "# Generated automatically by: %s\n", gnu_lilypond_version_string ().to_str0 ());
72   
73   String out;
74   for (int i=0; i < targets.size (); i ++)
75      out += dependency_prefix_global + targets[i] + " ";
76   out +=  ": ";
77
78   for (int i=0; i < deps.size (); i ++)
79     {
80       if (out.length () > WRAPWIDTH)
81         {
82           fprintf (f, "%s\\\n", out.to_str0 ());
83           out = "  ";
84         }
85       String dep = deps[i];
86       if (!dependency_prefix_global.empty_b ())
87         {
88 #if 0//thinko?
89           if (stat (dep.to_str0 (), &stat_buf) == -1 && errno == ENOENT)
90             ; //make emacs happy
91 #else
92           if (dep.index ('/') < 0)
93 #endif
94             dep = dependency_prefix_global + dep;
95         }
96       out  += " " +  dep;
97     }
98   fprintf (f, "%s\n",  out.to_str0 ());
99 }
100
101
102 void
103 Input_file_results::do_deps ()
104 {
105   if (dependency_global_b)
106     {
107       Path p = split_path (output_name_global);
108       p.ext = "dep";
109       write_dependency_file (p.string (),
110                              target_strings_,
111                              inclusion_names_);
112     }
113 }
114
115
116 void
117 Input_file_results::do_scores ()
118 {
119   if (header_ == SCM_EOL)
120     header_ = ly_make_anonymous_module ();
121
122   for (int i=0; i < scores_.size (); i++)
123     {
124       Score* is = scores_[i];
125       is->input_file_ = this;
126       
127       if (is->errorlevel_)
128         {
129           is->warning (_ ("Score contains errors; will not process it"));
130           exit_status_global |= 1;
131         }
132       else
133         {
134           is->process ();
135         }
136     }
137   do_deps ();
138 }
139
140 Input_file_results::~Input_file_results ()
141 {
142   for (int i=0; i < scores_.size (); i++)
143     scm_gc_unprotect_object (scores_[i]->self_scm ());
144   scores_.clear ();
145   
146   inclusion_names_.clear ();
147   if (header_)
148     header_ = SCM_EOL;
149
150   global_input_file =0;
151
152   ly_clear_anonymous_modules();
153 }
154
155
156
157 Input_file_results* global_input_file;
158
159 Input_file_results::Input_file_results (String init_string, String file_string)
160 {
161   header_ = SCM_EOL;
162   global_input_file = this;
163   ly_set_point_and_click_x (SCM_BOOL_F);
164   
165   sources_.set_path (&global_path);
166   
167   My_lily_parser parser (this);
168
169   progress_indication (_f ("Now processing: `%s'", file_string.to_str0 ()));
170   progress_indication ("\n");
171   parser.parse_file (init_string, file_string);
172   
173   if (parser.error_level_)
174     {
175       exit_status_global  = 1;
176     }
177   else
178     do_scores ();
179   
180 }
181
182
183 void
184 do_one_file (String init_string, String file_string) 
185 {
186    if (init_string.length () && global_path.find (init_string).empty_b ())
187     {
188       warning (_f ("can't find file: `%s'", init_string));
189       warning (_f ("(search path: `%s')", global_path.string ().to_str0 ()));
190       return;
191     }
192   if ((file_string != "-") && global_path.find (file_string).empty_b ())
193     {
194       warning (_f ("can't find file: `%s'", file_string));
195       return;
196     }
197
198   Input_file_results inp_file(init_string, file_string);
199 }