]> git.donarmstrong.com Git - lilypond.git/blob - lily/input-file-results.cc
lots of changes (see diff :-)
[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   return SCM_UNSPECIFIED;
54 }
55
56 void
57 write_dependency_file (String fn,
58                        Array<String> targets,
59                        Array<String> deps)
60 {
61   const int WRAPWIDTH = 65;
62
63   progress_indication (_f ("dependencies output to `%s'...", fn.to_str0 ()));
64   progress_indication ("\n");
65   FILE * f = fopen  (fn.to_str0 (), "w");
66   if (!f)
67     warning (_f ("can't open file: `%s'", fn));
68
69   fprintf (f, "# Generated automatically by: %s\n", gnu_lilypond_version_string ().to_str0 ());
70   
71   String out;
72   for (int i=0; i < targets.size (); i ++)
73      out += dependency_prefix_global + targets[i] + " ";
74   out +=  ": ";
75
76   for (int i=0; i < deps.size (); i ++)
77     {
78       if (out.length () > WRAPWIDTH)
79         {
80           fprintf (f, "%s\\\n", out.to_str0 ());
81           out = "  ";
82         }
83       String dep = deps[i];
84       if (!dependency_prefix_global.empty_b ())
85         {
86 #if 0//thinko?
87           if (stat (dep.to_str0 (), &stat_buf) == -1 && errno == ENOENT)
88             ; //make emacs happy
89 #else
90           if (dep.index ('/') < 0)
91 #endif
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.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
151
152 Input_file_results* global_input_file;
153
154 Input_file_results::Input_file_results (String init_string, String file_string)
155 {
156   header_ = SCM_EOL;
157   global_input_file = this;
158   ly_set_point_and_click_x (SCM_BOOL_F);
159   
160   sources_.set_path (&global_path);
161   
162   My_lily_parser parser (this);
163
164   progress_indication (_f ("Now processing: `%s'", file_string.to_str0 ()));
165   progress_indication ("\n");
166   parser.parse_file (init_string, file_string);
167   
168   if (parser.error_level_)
169     {
170       exit_status_global  = 1;
171     }
172   else
173     do_scores ();
174   
175 }
176
177
178 void
179 do_one_file (String init_string, String file_string) 
180 {
181    if (init_string.length () && global_path.find (init_string).empty_b ())
182     {
183       warning (_f ("can't find file: `%s'", init_string));
184       warning (_f ("(search path: `%s')", global_path.string ().to_str0 ()));
185       return;
186     }
187   if ((file_string != "-") && global_path.find (file_string).empty_b ())
188     {
189       warning (_f ("can't find file: `%s'", file_string));
190       return;
191     }
192
193   Input_file_results inp_file(init_string, file_string);
194 }