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