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