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-module.hh"
35 #include "paper-book.hh"
37 bool store_locations_global_b;
40 TODO: should merge with My_lily_parser.
44 no ! suffix since it doesn't modify 1st argument.
46 LY_DEFINE (ly_set_point_and_click, "ly:set-point-and-click", 1, 0, 0,
48 "Set the options for Point-and-click source specials output. The\n"
49 "argument is a symbol. Possible options are @code{none} (no source specials),\n"
50 "@code{line} and @code{line-column}")
56 if (ly_symbol2scm ("line-column") == what)
57 val = gh_eval_str ("line-column-location");
58 else if (what == ly_symbol2scm ("line"))
59 val = gh_eval_str ("line-location");
61 extern SCM lily_module;
62 scm_module_define (lily_module, ly_symbol2scm ("point-and-click"), val);
64 store_locations_global_b =gh_procedure_p (val);
65 return SCM_UNSPECIFIED;
69 write_dependency_file (String fn,
70 Array<String> targets,
73 const int WRAPWIDTH = 65;
75 progress_indication (_f ("dependencies output to `%s'...", fn.to_str0 ()));
76 progress_indication ("\n");
77 FILE * f = fopen (fn.to_str0 (), "w");
79 warning (_f ("can't open file: `%s'", fn));
81 fprintf (f, "# Generated automatically by: %s\n", gnu_lilypond_version_string ().to_str0 ());
84 for (int i=0; i < targets.size (); i ++)
85 out += dependency_prefix_global + targets[i] + " ";
88 for (int i=0; i < deps.size (); i ++)
90 if (out.length () > WRAPWIDTH)
92 fprintf (f, "%s\\\n", out.to_str0 ());
96 if (!dependency_prefix_global.is_empty ())
98 if (dep.index ('/') < 0)
99 dep = dependency_prefix_global + dep;
103 fprintf (f, "%s\n", out.to_str0 ());
108 Input_file_results::do_deps (String output)
110 if (dependency_global_b)
112 Path p = split_path (output);
114 write_dependency_file (p.to_string (),
120 Input_file_results::~Input_file_results ()
122 inclusion_names_.clear ();
126 global_input_file =0;
128 ly_clear_anonymous_modules ();
133 Input_file_results* global_input_file;
135 Input_file_results::Input_file_results (String init, String in_file, String out_file)
137 header_ = ly_make_anonymous_module ();
138 global_input_file = this;
140 sources_.set_path (&global_path);
143 progress_indication (_f ("Now processing: `%s'", in_file.to_str0 ()));
144 progress_indication ("\n");
146 My_lily_parser parser (this);
147 parser.parse_file (init, in_file, out_file);
149 if (parser.error_level_)
151 exit_status_global = 1;
152 failed_files.push (in_file);
159 /* Distill full input file name from command argument. PATH describes
160 file name with added default extension, ".ly" if none. "-" is
163 distill_inname (String str)
165 Path p = split_path (str);
166 if (str.is_empty () || str == "-")
170 String orig_ext = p.ext;
171 char const *extensions[] = {"ly", "", 0};
172 for (int i = 0; extensions[i]; i++)
175 if (*extensions[i] && !p.ext.is_empty ())
177 p.ext += extensions[i];
178 if (!global_path.find (p.to_string ()).is_empty ())
181 /* Reshuffle extension */
182 p = split_path (p.to_string ());
189 do_one_file (char const *file)
191 String infile (file);
192 Path inpath = distill_inname (infile);
194 /* By default, use base name of input file for output file name */
195 Path outpath = inpath;
196 if (inpath.to_string () != "-")
197 outpath.ext = output_format_global;
199 /* By default, write output to cwd; do not copy directory part
200 of input file name */
204 if (!output_name_global.is_empty ())
205 outpath = split_path (output_name_global);
208 if (!init_name_global.is_empty ())
209 init = init_name_global;
213 String in_file = inpath.to_string ();
214 String out_file = outpath.to_string ();
216 if (init.length () && global_path.find (init).is_empty ())
218 warning (_f ("can't find file: `%s'", init));
219 warning (_f ("(search path: `%s')", global_path.to_string ().to_str0 ()));
223 if ((in_file != "-") && global_path.find (in_file).is_empty ())
225 warning (_f ("can't find file: `%s'", in_file));
231 proc = scm_c_eval_string ("dump-gc-protects");
235 Input_file_results inp_file (init, in_file, out_file);
236 if (output_format_global == PAGE_LAYOUT)
237 book.output (out_file);