2 main.cc -- implement main: entrypoints
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "lily-guile.hh"
15 #include "all-fonts.hh"
17 #include "dimensions.hh"
19 #include "getopt-long.hh"
23 #include "file-path.hh"
25 #include "file-results.hh"
27 #include "lily-guile.hh"
28 #include "paper-def.hh"
29 #include "midi-def.hh"
36 bool version_ignore_global_b = false;
37 bool no_paper_global_b = false;
38 bool no_timestamps_global_b = false;
39 bool find_old_relative_b = false;
41 char const* output_global_ch = "tex";
42 All_font_metrics *all_fonts_global_p;
44 String default_outname_base_global = "lelie";
45 String outname_str_global;
46 String init_str_global;
48 int default_count_global;
49 File_path global_path;
51 bool safe_global_b = false;
52 bool experimental_features_global_b = false;
53 bool dependency_global_b = false;
57 Getopt_long * oparser_global_p = 0;
59 String distill_inname_str (String name_str, String& ext_r);
61 Long_option_init theopts[] = {
71 {0, "dependencies", 'd'},
72 {0, "no-timestamps", 'T'},
73 {0, "find-old-relative", 'Q'},
74 {0, "ignore-version", 'V'},
75 {1, "output-format", 'f'},
83 cout << _f ("Usage: %s [OPTION]... [FILE]...", "lilypond") << '\n';
84 cout << _ ("Typeset music and or play MIDI from FILE or <stdin>");
87 cout << _ ("Options:");
90 " -a, --about about LilyPond\n"
93 " -D, --debug enable debugging output\n"
96 " -d, --dependencies write Makefile dependencies for every input file\n"
99 " -h, --help this help\n"
102 " -f, --output-format=X use output format X\n"
105 " -I, --include=DIR add DIR to search path\n"
108 " -i, --init=FILE use FILE as init file\n"
111 " -M, --no-paper produce midi output only\n"
114 " -o, --output=FILE set FILE as default output base\n"
117 " -Q, --find-old-relative show all changes in relative syntax\n"
120 " -s, --safe inhibit file output naming and exporting TeX macros\n");
122 " -t, --test switch on experimental features\n"
125 " -T, --no-timestamps don't timestamp the output\n"
128 " -V, --ignore-version ignore mudela version\n"
131 " -w, --warranty show warranty and copyright\n"
134 cout << _ ("GNU LilyPond was compiled with the following settings:");
143 #ifdef STRING_UTILS_INLINED
144 "STRING_UTILS_INLINED "
146 "datadir=" DIR_DATADIR
148 "localedir=" DIR_LOCALEDIR
162 cout << _ ("GNU LilyPond is Free software, see --warranty");
165 cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
167 cout << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
168 cout << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
176 cout << _ ("GNU LilyPond -- The GNU Project music typesetter");
178 cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
180 cout << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
181 cout << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
184 " This program is free software; you can redistribute it and/or\n"
185 "modify it under the terms of the GNU General Public License version 2\n"
186 "as published by the Free Software Foundation.\n"
188 " This program is distributed in the hope that it will be useful,\n"
189 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
190 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
191 "General Public License for more details.\n"
193 " You should have received a copy (refer to the file COPYING) of the\n"
194 "GNU General Public License along with this program; if not, write to\n"
195 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
202 *mlog << get_version_str () << endl;
208 // facilitate binary distributions
209 char const *env_lily = getenv ("LILYPONDPREFIX");
210 String prefix_directory;
212 prefix_directory = env_lily;
215 setlocale (LC_ALL, ""); /* enable locales */
216 setlocale (LC_NUMERIC, "C"); /* musn't have comma's in TeX output... */
217 String lily_locale_dir;
218 String name (PACKAGE);
220 if (!prefix_directory.empty_b())
222 lily_locale_dir = prefix_directory + "/share/locale";
223 bindtextdomain (name.ch_C (), lily_locale_dir.ch_C());
226 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
227 textdomain (name.ch_C ());
230 global_path.add ("");
231 // must override (come before) "/usr/local/share/lilypond"!
232 char const *env_sz = getenv ("LILYINCLUDE");
234 global_path.parse_path (env_sz);
237 char *suffixes[] = {"ly", "afm", "scm", "init", 0};
238 for (char **s = suffixes; *s; s++){
239 if (!prefix_directory.empty_b())
240 global_path.add (prefix_directory + to_str ('/') + String (*s));
242 global_path.add (String (DIR_DATADIR) + to_str ('/') + String(*s));
252 main_prog (int argc, char **argv)
254 default_outname_base_global = "lelie";
255 all_fonts_global_p = new All_font_metrics (global_path.str ());
259 tfm.read_file ("cmr10.tfm");
260 String str = tfm.str ();
267 while ((arg= oparser_global_p->get_next_arg ()))
270 if (outname_str_global == "")
272 Midi_def::reset_default_count ();
273 Paper_def::reset_default_count ();
277 f = distill_inname_str (f, i);
279 default_outname_base_global = "-";
283 split_path (f, a, b, c, d);
284 default_outname_base_global = c;
286 if (outname_str_global.length_i ())
287 default_outname_base_global = outname_str_global;
288 if (init_str_global.length_i ())
298 if (init_str_global.length_i ())
302 default_outname_base_global = "-";
303 if (outname_str_global.length_i ())
304 default_outname_base_global = outname_str_global;
305 do_one_file (i, default_outname_base_global);
307 delete oparser_global_p;
308 exit( exit_status_i_);
312 main (int argc, char **argv)
315 call_constructors ();
316 debug_init (); // should be first
320 oparser_global_p = new Getopt_long(argc, argv,theopts);
321 while (Long_option_init const * opt = (*oparser_global_p)())
323 switch (opt->shortname)
326 experimental_features_global_b = true;
327 *mlog << "*** enabling experimental features, you're on your own now ***\n";
330 outname_str_global = oparser_global_p->optional_argument_ch_C_;
337 output_global_ch = oparser_global_p->optional_argument_ch_C_;
340 find_old_relative_b= true;
343 global_path.push (oparser_global_p->optional_argument_ch_C_);
346 init_str_global = oparser_global_p->optional_argument_ch_C_;
356 version_ignore_global_b = true;
359 safe_global_b = true;
362 dependency_global_b = true;
368 no_paper_global_b = true;
371 no_timestamps_global_b = true;
380 gh_enter (argc, argv, main_prog);
382 gh_enter (argc, argv, (void(*)())main_prog);
385 return 0; // unreachable
389 make input file name from command arg.
393 @output file name with added default extension. "" is stdin.
394 in reference argument: the extension. ".ly" if none
397 distill_inname_str (String name_str, String& ext_r)
399 String str = name_str;
405 split_path (str,a,b,c,ext_r);
407 // add extension if not present.
408 // UGH. Should parametrise in list of default extensions.
409 if (ext_r.empty_b ())
412 if (global_path.find (a+b+c+ext_r).empty_b ())