2 main.cc -- implement main: entrypoints
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "lily-guile.hh"
14 #include "lily-version.hh"
16 #include "all-fonts.hh"
18 #include "dimensions.hh"
20 #include "getopt-long.hh"
24 #include "file-path.hh"
26 #include "file-results.hh"
28 #include "lily-guile.hh"
29 #include "paper-def.hh"
30 #include "midi-def.hh"
31 #include "global-ctor.hh"
38 bool version_ignore_global_b = false;
39 bool no_paper_global_b = false;
40 bool no_timestamps_global_b = false;
41 bool find_old_relative_b = false;
43 char const* output_global_ch = "tex";
44 All_font_metrics *all_fonts_global_p;
46 String default_outname_base_global = "lelie";
47 String outname_str_global;
48 String init_str_global;
50 int default_count_global;
51 File_path global_path;
53 bool safe_global_b = false;
54 bool experimental_features_global_b = false;
55 bool dependency_global_b = false;
59 Getopt_long * oparser_global_p = 0;
61 String distill_inname_str (String name_str, String& ext_r);
63 Long_option_init theopts[] = {
73 {0, "dependencies", 'd'},
74 {0, "no-timestamps", 'T'},
75 {0, "find-old-relative", 'Q'},
76 {0, "ignore-version", 'V'},
77 {1, "output-format", 'f'},
85 cout << _f ("Usage: %s [OPTION]... [FILE]...", "lilypond") << '\n';
86 cout << _ ("Typeset music and or play MIDI from FILE or <stdin>");
89 cout << _ ("Options:");
92 " -a, --about about LilyPond\n"
95 " -D, --debug enable debugging output\n"
98 " -d, --dependencies write Makefile dependencies for every input file\n"
101 " -h, --help this help\n"
104 " -f, --output-format=X use output format X\n"
107 " -I, --include=DIR add DIR to search path\n"
110 " -i, --init=FILE use FILE as init file\n"
113 " -M, --no-paper produce midi output only\n"
116 " -o, --output=FILE set FILE as default output base\n"
119 " -Q, --find-old-relative show all changes in relative syntax\n"
122 " -s, --safe inhibit file output naming and exporting TeX macros\n");
124 " -t, --test switch on experimental features\n"
127 " -T, --no-timestamps don't timestamp the output\n"
130 " -V, --ignore-version ignore mudela version\n"
133 " -w, --warranty show warranty and copyright\n"
136 cout << _ ("GNU LilyPond was compiled with the following settings:");
145 #ifdef STRING_UTILS_INLINED
146 "STRING_UTILS_INLINED "
148 "datadir=" DIR_DATADIR
150 "localedir=" DIR_LOCALEDIR
164 cout << _ ("GNU LilyPond is Free software, see --warranty");
167 cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
169 cout << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
170 cout << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
178 cout << _ ("GNU LilyPond -- The GNU Project music typesetter");
180 cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
182 cout << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
183 cout << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
186 " This program is free software; you can redistribute it and/or\n"
187 "modify it under the terms of the GNU General Public License version 2\n"
188 "as published by the Free Software Foundation.\n"
190 " This program is distributed in the hope that it will be useful,\n"
191 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
192 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
193 "General Public License for more details.\n"
195 " You should have received a copy (refer to the file COPYING) of the\n"
196 "GNU General Public License along with this program; if not, write to\n"
197 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
204 *mlog << gnu_lilypond_version_str () << endl;
210 // facilitate binary distributions
211 char const *env_lily = getenv ("LILYPONDPREFIX");
212 String prefix_directory;
214 prefix_directory = env_lily;
217 setlocale (LC_ALL, ""); /* enable locales */
218 setlocale (LC_NUMERIC, "C"); /* musn't have comma's in TeX output... */
219 String lily_locale_dir;
220 String name (PACKAGE);
222 if (!prefix_directory.empty_b())
224 lily_locale_dir = prefix_directory + "/share/locale";
225 bindtextdomain (name.ch_C (), lily_locale_dir.ch_C());
228 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
229 textdomain (name.ch_C ());
232 global_path.add ("");
233 // must override (come before) "/usr/local/share/lilypond"!
234 char const *env_sz = getenv ("LILYINCLUDE");
236 global_path.parse_path (env_sz);
239 char *suffixes[] = {"ly", "afm", "scm", "tfm", 0};
240 for (char **s = suffixes; *s; s++){
241 if (!prefix_directory.empty_b())
242 global_path.add (prefix_directory + to_str ('/') + String (*s));
244 global_path.add (String (DIR_DATADIR) + to_str ('/') + String(*s));
250 main_prog (int argc, char **argv)
253 need to do this first. Engravers use lily.scm contents.
255 read_lily_scm_file ( "lily.scm");
258 call_constructors ();
259 default_outname_base_global = "lelie";
260 all_fonts_global_p = new All_font_metrics (global_path.str ());
264 while ((arg= oparser_global_p->get_next_arg ()))
267 if (outname_str_global == "")
269 Midi_def::reset_default_count ();
270 Paper_def::reset_default_count ();
274 f = distill_inname_str (f, i);
276 default_outname_base_global = "-";
280 split_path (f, a, b, c, d);
281 default_outname_base_global = c;
283 if (outname_str_global.length_i ())
284 default_outname_base_global = outname_str_global;
285 if (init_str_global.length_i ())
295 if (init_str_global.length_i ())
299 default_outname_base_global = "-";
300 if (outname_str_global.length_i ())
301 default_outname_base_global = outname_str_global;
302 do_one_file (i, default_outname_base_global);
304 delete oparser_global_p;
305 exit( exit_status_i_);
310 main (int argc, char **argv)
313 debug_init (); // should be first
316 oparser_global_p = new Getopt_long(argc, argv,theopts);
317 while (Long_option_init const * opt = (*oparser_global_p)())
319 switch (opt->shortname)
322 experimental_features_global_b = true;
323 *mlog << "*** enabling experimental features, you're on your own now ***\n";
326 outname_str_global = oparser_global_p->optional_argument_ch_C_;
333 output_global_ch = oparser_global_p->optional_argument_ch_C_;
336 find_old_relative_b= true;
339 global_path.push (oparser_global_p->optional_argument_ch_C_);
342 init_str_global = oparser_global_p->optional_argument_ch_C_;
352 version_ignore_global_b = true;
355 safe_global_b = true;
358 dependency_global_b = true;
364 no_paper_global_b = true;
367 no_timestamps_global_b = true;
376 gh_enter (argc, argv, main_prog);
378 gh_enter (argc, argv, (void(*)())main_prog);
381 return 0; // unreachable
385 make input file name from command arg.
389 @output file name with added default extension. "" is stdin.
390 in reference argument: the extension. ".ly" if none
393 distill_inname_str (String name_str, String& ext_r)
395 String str = name_str;
401 split_path (str,a,b,c,ext_r);
403 // add extension if not present.
404 // UGH. Should parametrise in list of default extensions.
405 if (ext_r.empty_b ())
408 if (global_path.find (a+b+c+ext_r).empty_b ())