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"
16 #include "dimensions.hh"
18 #include "getopt-long.hh"
22 #include "file-path.hh"
24 #include "file-results.hh"
26 #include "lily-guile.hh"
27 #include "paper-def.hh"
28 #include "midi-def.hh"
35 bool version_ignore_global_b = false;
36 bool no_paper_global_b = false;
37 bool no_timestamps_global_b = false;
38 bool find_quarts_global_b = false;
40 char const* output_global_ch = "tex";
41 // temporarily default to ps, because tex is even more broken
42 //char const* output_global_ch = "ps";
44 String default_outname_base_global = "lelie";
45 int default_count_global;
46 File_path global_path;
48 bool safe_global_b = false;
49 bool experimental_features_global_b = false;
50 bool dependency_global_b = false;
54 String distill_inname_str (String name_str, String& ext_r);
56 Long_option_init theopts[] = {
66 {0, "dependencies", 'd'},
67 {0, "no-timestamps", 'T'},
68 {0, "find-fourths", 'Q'},
69 {0, "ignore-version", 'V'},
70 {1, "output-format", 'f'},
78 cout << _f ("Usage: %s [OPTION]... [FILE]...", "lilypond") << '\n';
79 cout << _ ("Typeset music and or play MIDI from FILE or <stdin>");
82 cout << _ ("Options:");
85 " -a, --about about LilyPond\n"
88 " -D, --debug enable debugging output\n"
91 " -d, --dependencies write Makefile dependencies for every input file\n"
94 " -h, --help this help\n"
97 " -f, --output-format=X use output format X\n"
100 " -I, --include=DIR add DIR to search path\n"
103 " -i, --init=FILE use FILE as init file\n"
106 " -M, --no-paper produce midi output only\n"
109 " -o, --output=FILE set FILE as default output base\n"
112 " -Q, --find-fourths show all intervals greater than a fourth\n"
115 " -s, --safe inhibit file output naming and exporting TeX macros\n");
117 " -t, --test switch on experimental features\n"
120 " -T, --no-timestamps don't timestamp the output\n"
123 " -V, --ignore-version ignore mudela version\n"
126 " -w, --warranty show warranty and copyright\n"
129 cout << _ ("GNU LilyPond was compiled with the following settings:");
138 #ifdef STRING_UTILS_INLINED
139 "STRING_UTILS_INLINED "
141 "datadir=" DIR_DATADIR
143 "localedir=" DIR_LOCALEDIR
157 cout << _ ("GNU LilyPond is Free software, see --warranty");
160 cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
162 cout << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
163 cout << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
171 cout << _ ("GNU LilyPond -- The GNU Project music typesetter");
173 cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
175 cout << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
176 cout << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
179 " This program is free software; you can redistribute it and/or\n"
180 "modify it under the terms of the GNU General Public License version 2\n"
181 "as published by the Free Software Foundation.\n"
183 " This program is distributed in the hope that it will be useful,\n"
184 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
185 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
186 "General Public License for more details.\n"
188 " You should have received a copy (refer to the file COPYING) of the\n"
189 "GNU General Public License along with this program; if not, write to\n"
190 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
197 *mlog << get_version_str () << endl;
203 // facilitate binary distributions
204 char const *env_lily = getenv ("LILYPONDPREFIX");
205 String prefix_directory;
207 prefix_directory = env_lily;
210 setlocale (LC_ALL, ""); /* enable locales */
211 setlocale (LC_NUMERIC, "C"); /* musn't have comma's in TeX output... */
212 String lily_locale_dir;
213 String name (PACKAGE);
215 if (!prefix_directory.empty_b())
217 lily_locale_dir = prefix_directory + "/share/locale";
218 bindtextdomain (name.ch_C (), lily_locale_dir.ch_C());
221 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
222 textdomain (name.ch_C ());
225 global_path.add ("");
226 // must override (come before) "/usr/local/share/lilypond"!
227 char const *env_sz = getenv ("LILYINCLUDE");
229 global_path.parse_path (env_sz);
232 char *suffixes[] = {"ly", "afm", "scm", "init", 0};
233 for (char **s = suffixes; *s; s++){
234 if (!prefix_directory.empty_b())
235 global_path.add (prefix_directory + to_str ('/') + String (*s));
237 global_path.add (String (DIR_DATADIR) + to_str ('/') + String(*s));
242 main_prog (int argc, char **argv)
245 call_constructors ();
246 debug_init (); // should be first
253 Getopt_long oparser (argc, argv,theopts);
254 while (Long_option_init const * opt = oparser ())
256 switch (opt->shortname)
259 experimental_features_global_b = true;
260 *mlog << "*** enabling experimental features, you're on your own now ***\n";
263 outname_str = oparser.optional_argument_ch_C_;
270 output_global_ch = oparser.optional_argument_ch_C_;
273 find_quarts_global_b = true;
276 global_path.push (oparser.optional_argument_ch_C_);
279 init_str = oparser.optional_argument_ch_C_;
289 version_ignore_global_b = true;
292 safe_global_b = true;
295 dependency_global_b = true;
301 no_paper_global_b = true;
304 no_timestamps_global_b = true;
312 default_outname_base_global = "lelie";
316 while ((arg= oparser.get_next_arg ()))
319 if (outname_str == "")
321 Midi_def::reset_default_count ();
322 Paper_def::reset_default_count ();
326 f = distill_inname_str (f, i);
328 default_outname_base_global = "-";
332 split_path (f, a, b, c, d);
333 default_outname_base_global = c;
335 if (outname_str.length_i ())
336 default_outname_base_global = outname_str;
337 if (init_str.length_i ())
347 if (init_str.length_i ())
351 default_outname_base_global = "-";
352 if (outname_str.length_i ())
353 default_outname_base_global = outname_str;
354 do_one_file (i, default_outname_base_global);
356 exit( exit_status_i_);
360 main (int argc, char **argv)
362 gh_enter (argc, argv, (void(*)())main_prog);
363 return 0; // unreachable
367 make input file name from command arg.
371 @output file name with added default extension. "" is stdin.
372 in reference argument: the extension. ".ly" if none
375 distill_inname_str (String name_str, String& ext_r)
377 String str = name_str;
383 split_path (str,a,b,c,ext_r);
385 // add extension if not present.
386 // UGH. Should parametrise in list of default extensions.
387 if (ext_r.empty_b ())
390 if (global_path.find (a+b+c+ext_r).empty_b ())