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 scm_module_define (global_lily_module, ly_symbol2scm ("point-and-click"), val);
63 store_locations_global_b =gh_procedure_p (val);
64 return SCM_UNSPECIFIED;
68 write_dependency_file (String fn,
69 Array<String> targets,
72 const int WRAPWIDTH = 65;
74 progress_indication (_f ("dependencies output to `%s'...", fn.to_str0 ()));
75 progress_indication ("\n");
76 FILE * f = fopen (fn.to_str0 (), "w");
78 warning (_f ("can't open file: `%s'", fn));
80 fprintf (f, "# Generated automatically by: %s\n", gnu_lilypond_version_string ().to_str0 ());
83 for (int i=0; i < targets.size (); i ++)
84 out += dependency_prefix_global + targets[i] + " ";
87 for (int i=0; i < deps.size (); i ++)
89 if (out.length () > WRAPWIDTH)
91 fprintf (f, "%s\\\n", out.to_str0 ());
95 if (!dependency_prefix_global.is_empty ())
97 if (dep.index ('/') < 0)
98 dep = dependency_prefix_global + dep;
102 fprintf (f, "%s\n", out.to_str0 ());
107 Input_file_results::do_deps (String output)
109 if (dependency_global_b)
111 Path p = split_path (output);
113 write_dependency_file (p.to_string (),
119 Input_file_results::~Input_file_results ()
121 inclusion_names_.clear ();
125 global_input_file = 0;
127 ly_clear_anonymous_modules ();
132 Input_file_results* global_input_file;
134 Input_file_results::Input_file_results (String init, String in_file, String out_file)
136 header_ = ly_make_anonymous_module ();
137 global_input_file = this;
139 sources_.set_path (&global_path);
142 progress_indication (_f ("Now processing `%s'", in_file.to_str0 ()));
143 progress_indication ("\n");
145 My_lily_parser parser (this);
146 parser.parse_file (init, in_file, out_file);
148 if (parser.error_level_)
150 exit_status_global = 1;
151 failed_files.push (in_file);
158 /* Distill full input file name from command argument. PATH describes
159 file name with added default extension, ".ly" if none. "-" is
162 distill_inname (String str)
164 Path p = split_path (str);
165 if (str.is_empty () || str == "-")
169 String orig_ext = p.ext;
170 char const *extensions[] = {"ly", "", 0};
171 for (int i = 0; extensions[i]; i++)
174 if (*extensions[i] && !p.ext.is_empty ())
176 p.ext += extensions[i];
177 if (!global_path.find (p.to_string ()).is_empty ())
180 /* Reshuffle extension */
181 p = split_path (p.to_string ());
188 do_one_file (char const *file)
190 String infile (file);
191 Path inpath = distill_inname (infile);
193 /* By default, use base name of input file for output file name */
194 Path outpath = inpath;
195 if (inpath.to_string () != "-")
196 outpath.ext = output_format_global;
198 /* By default, write output to cwd; do not copy directory part
199 of input file name */
203 if (!output_name_global.is_empty ())
204 outpath = split_path (output_name_global);
207 if (!init_name_global.is_empty ())
208 init = init_name_global;
212 String in_file = inpath.to_string ();
213 String out_file = outpath.to_string ();
215 if (init.length () && global_path.find (init).is_empty ())
217 warning (_f ("can't find file: `%s'", init));
218 warning (_f ("(search path: `%s')", global_path.to_string ().to_str0 ()));
222 if ((in_file != "-") && global_path.find (in_file).is_empty ())
224 warning (_f ("can't find file: `%s'", in_file));
228 paper_book = new Paper_book ();;
229 Input_file_results inp_file (init, in_file, out_file);
230 if (output_format_global == PAGE_LAYOUT)
231 paper_book->output (out_file);
233 scm_gc_unprotect_object (paper_book->self_scm ());