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