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 experimental_features_global_b = false;
49 bool dependency_global_b = false;
53 String distill_inname_str (String name_str, String& ext_r);
55 Long_option_init theopts[] = {
65 {0, "dependencies", 'd'},
66 {0, "no-timestamps", 'T'},
67 {0, "find-fourths", 'Q'},
68 {0, "ignore-version", 'V'},
69 {1, "output-format", 'f'},
76 cout << _f ("Usage: %s [OPTION]... [FILE]...", "lilypond") << '\n';
77 cout << _ ("Typeset music and or play MIDI from FILE or <stdin>");
80 cout << _ ("Options:");
83 " -a, --about about LilyPond\n"
86 " -D, --debug enable debugging output\n"
89 " -d, --dependencies write Makefile dependencies for every input file\n"
92 " -h, --help this help\n"
95 " -f, --output-format=X use output format X\n"
98 " -I, --include=DIR add DIR to search path\n"
101 " -i, --init=FILE use FILE as init file\n"
104 " -M, --no-paper produce midi output only\n"
107 " -o, --output=FILE set FILE as default output base\n"
110 " -Q, --find-fourths show all intervals greater than a fourth\n"
113 " -t, --test switch on experimental features\n"
116 " -T, --no-timestamps don't timestamp the output\n"
119 " -V, --ignore-version ignore mudela version\n"
122 " -w, --warranty show warranty and copyright\n"
125 cout << _ ("GNU LilyPond was compiled with the following settings:");
134 #ifdef STRING_UTILS_INLINED
135 "STRING_UTILS_INLINED "
137 "datadir=" DIR_DATADIR
139 "localedir=" DIR_LOCALEDIR
153 cout << _ ("GNU LilyPond is Free software, see --warranty");
156 cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
158 cout << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
159 cout << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
167 cout << _ ("GNU LilyPond -- The GNU Project music typesetter");
169 cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
171 cout << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
172 cout << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
175 " This program is free software; you can redistribute it and/or\n"
176 "modify it under the terms of the GNU General Public License version 2\n"
177 "as published by the Free Software Foundation.\n"
179 " This program is distributed in the hope that it will be useful,\n"
180 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
181 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
182 "General Public License for more details.\n"
184 " You should have received a copy (refer to the file COPYING) of the\n"
185 "GNU General Public License along with this program; if not, write to\n"
186 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
193 *mlog << get_version_str () << endl;
199 // facilitate binary distributions
200 char const *env_lily = getenv ("LILYPONDPREFIX");
201 String prefix_directory;
203 prefix_directory = env_lily;
206 setlocale (LC_ALL, ""); /* enable locales */
207 setlocale (LC_NUMERIC, "C"); /* musn't have comma's in TeX output... */
208 String lily_locale_dir;
209 String name (PACKAGE);
211 if (!prefix_directory.empty_b())
213 lily_locale_dir = prefix_directory + "/share/locale";
214 bindtextdomain (name.ch_C (), lily_locale_dir.ch_C());
217 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
218 textdomain (name.ch_C ());
221 global_path.add ("");
222 // must override (come before) "/usr/local/share/lilypond"!
223 char const *env_sz = getenv ("LILYINCLUDE");
225 global_path.parse_path (env_sz);
228 char *suffixes[] = {"ly", "afm", "scm", "init", 0};
229 for (char **s = suffixes; *s; s++){
230 if (!prefix_directory.empty_b())
231 global_path.add (prefix_directory + to_str ('/') + String (*s));
233 global_path.add (String (DIR_DATADIR) + to_str ('/') + String(*s));
238 main_prog (int argc, char **argv)
241 call_constructors ();
242 debug_init (); // should be first
249 Getopt_long oparser (argc, argv,theopts);
250 while (Long_option_init const * opt = oparser ())
252 switch (opt->shortname)
255 experimental_features_global_b = true;
256 *mlog << "*** enabling experimental features, you're on your own now ***\n";
259 outname_str = oparser.optional_argument_ch_C_;
266 output_global_ch = oparser.optional_argument_ch_C_;
269 find_quarts_global_b = true;
272 global_path.push (oparser.optional_argument_ch_C_);
275 init_str = oparser.optional_argument_ch_C_;
285 version_ignore_global_b = true;
288 dependency_global_b = true;
294 no_paper_global_b = true;
297 no_timestamps_global_b = true;
305 default_outname_base_global = "lelie";
309 while ((arg= oparser.get_next_arg ()))
312 if (outname_str == "")
314 Midi_def::reset_default_count ();
315 Paper_def::reset_default_count ();
319 f = distill_inname_str (f, i);
321 default_outname_base_global = "-";
325 split_path (f, a, b, c, d);
326 default_outname_base_global = c;
328 if (outname_str.length_i ())
329 default_outname_base_global = outname_str;
330 if (init_str.length_i ())
340 if (init_str.length_i ())
344 default_outname_base_global = "-";
345 if (outname_str.length_i ())
346 default_outname_base_global = outname_str;
347 do_one_file (i, default_outname_base_global);
349 exit( exit_status_i_);
353 main (int argc, char **argv)
355 gh_enter (argc, argv, (void(*)())main_prog);
356 return 0; // unreachable
360 make input file name from command arg.
364 @output file name with added default extension. "" is stdin.
365 in reference argument: the extension. ".ly" if none
368 distill_inname_str (String name_str, String& ext_r)
370 String str = name_str;
376 split_path (str,a,b,c,ext_r);
378 // add extension if not present.
379 // UGH. Should parametrise in list of default extensions.
380 if (ext_r.empty_b ())
383 if (global_path.find (a+b+c+ext_r).empty_b ())