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 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 = scm_c_eval_string ("line-column-location");
56 else if (what == ly_symbol2scm ("line"))
57 val = scm_c_eval_string ("line-location");
59 scm_module_define (global_lily_module, ly_symbol2scm ("point-and-click"), val);
61 store_locations_global_b =is_procedure (val);
62 return SCM_UNSPECIFIED;
66 write_dependency_file (String fn,
67 Array<String> targets,
70 const int WRAPWIDTH = 65;
72 progress_indication (_f ("dependencies output to `%s'...", fn.to_str0 ()));
73 progress_indication ("\n");
74 FILE * f = fopen (fn.to_str0 (), "w");
76 warning (_f ("can't open file: `%s'", fn));
78 fprintf (f, "# Generated automatically by: %s\n", gnu_lilypond_version_string ().to_str0 ());
81 for (int i=0; i < targets.size (); i ++)
82 out += dependency_prefix_global + targets[i] + " ";
85 for (int i=0; i < deps.size (); i ++)
87 if (out.length () > WRAPWIDTH)
89 fprintf (f, "%s\\\n", out.to_str0 ());
93 if (!dependency_prefix_global.is_empty ())
95 if (dep.index ('/') < 0)
96 dep = dependency_prefix_global + dep;
100 fprintf (f, "%s\n", out.to_str0 ());
105 Input_file_results::do_deps (String output)
107 if (dependency_global_b)
109 Path p = split_path (output);
111 write_dependency_file (p.to_string (),
117 Input_file_results::~Input_file_results ()
119 inclusion_names_.clear ();
123 global_input_file = 0;
125 ly_clear_anonymous_modules ();
128 Input_file_results* global_input_file;
130 Input_file_results::Input_file_results (String init,
131 String in_file, String out_file)
133 header_ = ly_make_anonymous_module ();
134 global_input_file = this;
137 sources_.set_path (&global_path);
139 progress_indication (_f ("Now processing `%s'", in_file.to_str0 ()));
140 progress_indication ("\n");
142 My_lily_parser parser (this);
143 parser.parse_file (init, in_file, out_file);
145 if (parser.error_level_)
147 exit_status_global = 1;
148 failed_files.push (in_file);
154 /* Distill full input file name from command argument. PATH describes
155 file name with added default extension, ".ly" if none. "-" is
158 distill_inname (String str)
160 Path p = split_path (str);
161 if (str.is_empty () || str == "-")
165 String orig_ext = p.ext;
166 char const *extensions[] = {"ly", "", 0};
167 for (int i = 0; extensions[i]; i++)
170 if (*extensions[i] && !p.ext.is_empty ())
172 p.ext += extensions[i];
173 if (!global_path.find (p.to_string ()).is_empty ())
176 /* Reshuffle extension */
177 p = split_path (p.to_string ());
184 do_one_file (char const *file)
186 String infile (file);
187 Path inpath = distill_inname (infile);
189 /* By default, use base name of input file for output file name */
190 Path outpath = inpath;
191 if (inpath.to_string () != "-")
192 outpath.ext = output_format_global;
194 /* By default, write output to cwd; do not copy directory part
195 of input file name */
199 if (!output_name_global.is_empty ())
200 outpath = split_path (output_name_global);
203 if (!init_name_global.is_empty ())
204 init = init_name_global;
208 String in_file = inpath.to_string ();
209 String out_file = outpath.to_string ();
211 if (init.length () && global_path.find (init).is_empty ())
213 warning (_f ("can't find file: `%s'", init));
214 warning (_f ("(search path: `%s')", global_path.to_string ().to_str0 ()));
218 if ((in_file != "-") && global_path.find (in_file).is_empty ())
220 warning (_f ("can't find file: `%s'", in_file));
224 Input_file_results inp_file (init, in_file, out_file);