2 scores.cc -- implement some globals
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include <sys/types.h>
24 #include "paper-def.hh"
27 #include "file-path.hh"
28 #include "input-file-results.hh"
29 #include "my-lily-parser.hh"
31 #include "lily-version.hh"
32 #include "scm-hash.hh"
33 #include "ly-modules.hh"
35 bool store_locations_global_b;
38 TODO: should merge with My_lily_parser.
42 no ! suffix since it doesn't modify 1st argument.
44 LY_DEFINE(ly_set_point_and_click, "ly:set-point-and-click", 1, 0, 0,
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}")
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");
59 extern SCM lily_module;
60 scm_module_define (lily_module, ly_symbol2scm ("point-and-click"), val);
62 store_locations_global_b =gh_procedure_p (val);
63 return SCM_UNSPECIFIED;
67 write_dependency_file (String fn,
68 Array<String> targets,
71 const int WRAPWIDTH = 65;
73 progress_indication (_f ("dependencies output to `%s'...", fn.to_str0 ()));
74 progress_indication ("\n");
75 FILE * f = fopen (fn.to_str0 (), "w");
77 warning (_f ("can't open file: `%s'", fn));
79 fprintf (f, "# Generated automatically by: %s\n", gnu_lilypond_version_string ().to_str0 ());
82 for (int i=0; i < targets.size (); i ++)
83 out += dependency_prefix_global + targets[i] + " ";
86 for (int i=0; i < deps.size (); i ++)
88 if (out.length () > WRAPWIDTH)
90 fprintf (f, "%s\\\n", out.to_str0 ());
94 if (!dependency_prefix_global.is_empty ())
96 if (dep.index ('/') < 0)
97 dep = dependency_prefix_global + dep;
101 fprintf (f, "%s\n", out.to_str0 ());
106 Input_file_results::do_deps (String output)
108 if (dependency_global_b)
110 Path p = split_path (output);
112 write_dependency_file (p.to_string (),
118 Input_file_results::~Input_file_results ()
120 inclusion_names_.clear ();
124 global_input_file =0;
126 ly_clear_anonymous_modules();
131 Input_file_results* global_input_file;
133 Input_file_results::Input_file_results (String init, String in_file, String out_file)
135 header_ = ly_make_anonymous_module ();
136 global_input_file = this;
138 sources_.set_path (&global_path);
141 progress_indication (_f ("Now processing: `%s'", in_file.to_str0 ()));
142 progress_indication ("\n");
144 My_lily_parser parser (this);
145 parser.parse_file (init, in_file, out_file);
147 if (parser.error_level_)
149 exit_status_global = 1;
150 failed_files.push (in_file);
157 /* Distill full input file name from command argument. PATH describes
158 file name with added default extension, ".ly" if none. "-" is
161 distill_inname (String str)
163 Path p = split_path (str);
164 if (str.is_empty () || str == "-")
168 String orig_ext = p.ext;
169 char const *extensions[] = {"ly", "", 0};
170 for (int i = 0; extensions[i]; i++)
173 if (*extensions[i] && !p.ext.is_empty ())
175 p.ext += extensions[i];
176 if (!global_path.find (p.to_string ()).is_empty ())
179 /* Reshuffle extension */
180 p = split_path (p.to_string ());
187 do_one_file (char const *file)
189 String infile (file);
190 Path inpath = distill_inname (infile);
192 /* By default, use base name of input file for output file name */
193 Path outpath = inpath;
194 if (inpath.to_string () != "-")
195 outpath.ext = output_format_global;
197 /* By default, write output to cwd; do not copy directory part
198 of input file name */
202 if (!output_name_global.is_empty ())
203 outpath = split_path (output_name_global);
206 if (!init_name_global.is_empty ())
207 init = init_name_global;
211 String in_file = inpath.to_string ();
212 String out_file = outpath.to_string ();
215 /* Code to debug memory leaks. Cannot call from within .ly
216 since then we get the protects from the parser state too. */
219 proc = scm_c_eval_string ("dump-gc-protects");
224 if (init.length () && global_path.find (init).is_empty ())
226 warning (_f ("can't find file: `%s'", init));
227 warning (_f ("(search path: `%s')", global_path.to_string ().to_str0 ()));
231 if ((in_file != "-") && global_path.find (in_file).is_empty ())
233 warning (_f ("can't find file: `%s'", in_file));
239 proc = scm_c_eval_string ("dump-gc-protects");
241 Input_file_results inp_file (init, in_file, out_file);