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