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"
33 bool version_ignore_global_b = false;
34 bool no_paper_global_b = false;
35 bool no_timestamps_global_b = false;
36 bool find_quarts_global_b = false;
38 char const* output_global_ch = "tex";
39 // temporarily default to ps, because tex is even more broken
40 //char const* output_global_ch = "ps";
42 String default_outname_base_global = "lelie";
43 int default_count_global;
44 File_path global_path;
46 bool experimental_features_global_b = false;
47 bool dependency_global_b = false;
51 String distill_inname_str (String name_str, String& ext_r);
53 Long_option_init theopts[] = {
63 {0, "dependencies", 'd'},
64 {0, "no-timestamps", 'T'},
65 {0, "find-fourths", 'Q'},
66 {0, "ignore-version", 'V'},
67 {1, "output-format", 'f'},
74 cout << _f ("Usage: %s [OPTION]... [FILE]...", "lilypond") << '\n';
75 cout << _ ("Typeset music and or play MIDI from FILE or <stdin>");
78 cout << _ ("Options:");
81 " -a, --about about LilyPond\n"
84 " -D, --debug enable debugging output\n"
87 " -d, --dependencies write Makefile dependencies for every input file\n"
90 " -h, --help this help\n"
93 " -f, --output-format=X use output format X\n"
96 " -I, --include=DIR add DIR to search path\n"
99 " -i, --init=FILE use FILE as init file\n"
102 " -M, --no-paper produce midi output only\n"
105 " -o, --output=FILE set FILE as default output base\n"
108 " -Q, --find-fourths show all intervals greater than a fourth\n"
111 " -t, --test switch on experimental features\n"
114 " -T, --no-timestamps don't timestamp the output\n"
117 " -V, --ignore-version ignore mudela version\n"
120 " -w, --warranty show warranty and copyright\n"
123 cout << _ ("GNU LilyPond was compiled with the following settings:");
132 #ifdef STRING_UTILS_INLINED
133 "STRING_UTILS_INLINED "
135 "datadir=" DIR_DATADIR
137 "localedir=" DIR_LOCALEDIR
151 cout << _ ("GNU LilyPond is Free software, see --warranty");
154 cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
156 cout << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
157 cout << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
165 cout << _ ("GNU LilyPond -- The GNU Project music typesetter");
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";
173 " This program is free software; you can redistribute it and/or\n"
174 "modify it under the terms of the GNU General Public License version 2\n"
175 "as published by the Free Software Foundation.\n"
177 " This program is distributed in the hope that it will be useful,\n"
178 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
179 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
180 "General Public License for more details.\n"
182 " You should have received a copy (refer to the file COPYING) of the\n"
183 "GNU General Public License along with this program; if not, write to\n"
184 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
191 *mlog << get_version_str () << endl;
197 // facilitate binary distributions
198 char const *env_lily = getenv ("LILYPONDPREFIX");
199 String prefix_directory;
201 prefix_directory = env_lily;
204 setlocale (LC_ALL, ""); /* enable locales */
205 setlocale (LC_NUMERIC, "C"); /* musn't have comma's in TeX output... */
206 String lily_locale_dir;
207 String name (PACKAGE);
209 if (!prefix_directory.empty_b())
211 lily_locale_dir = prefix_directory + "/share/locale";
212 bindtextdomain (name.ch_C (), lily_locale_dir.ch_C());
215 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
216 textdomain (name.ch_C ());
219 global_path.add ("");
220 // must override (come before) "/usr/local/share/lilypond"!
221 char const *env_sz = getenv ("LILYINCLUDE");
223 global_path.parse_path (env_sz);
225 if (!prefix_directory.empty_b())
227 global_path.add (prefix_directory + "/share/lilypond/init/");
228 global_path.add (prefix_directory + "/share/lilypond");
231 global_path.add (String (DIR_DATADIR) + "/ly/");
232 global_path.add (String (DIR_DATADIR) + "/afm/");
237 main_prog (int argc, char **argv)
240 call_constructors ();
241 debug_init (); // should be first
248 Getopt_long oparser (argc, argv,theopts);
249 while (Long_option_init const * opt = oparser ())
251 switch (opt->shortname)
254 experimental_features_global_b = true;
255 *mlog << "*** enabling experimental features, you're on your own now ***\n";
258 outname_str = oparser.optional_argument_ch_C_;
265 output_global_ch = oparser.optional_argument_ch_C_;
268 find_quarts_global_b = true;
271 global_path.push (oparser.optional_argument_ch_C_);
274 init_str = oparser.optional_argument_ch_C_;
284 version_ignore_global_b = true;
287 dependency_global_b = true;
293 no_paper_global_b = true;
296 no_timestamps_global_b = true;
304 default_outname_base_global = "lelie";
310 while ((arg= oparser.get_next_arg ()))
314 f = distill_inname_str (f, i);
316 default_outname_base_global = "-";
320 split_path (f, a, b, c, d);
321 default_outname_base_global = c;
323 if (outname_str.length_i ())
324 default_outname_base_global = outname_str;
325 if (init_str.length_i ())
335 if (init_str.length_i ())
339 default_outname_base_global = "-";
340 if (outname_str.length_i ())
341 default_outname_base_global = outname_str;
342 do_one_file (i, default_outname_base_global);
347 main (int argc, char **argv)
350 gh_enter (argc, argv, (void(*)())main_prog);
351 return exit_status_i_;
353 main_prog (argc, argv);
354 return exit_status_i_;
359 urg: make input file name:
363 output: file name with added default extension. "" is stdin.
364 in reference argument: the extension. ".ly" if none
367 distill_inname_str (String name_str, String& ext_r)
369 String str = name_str;
375 split_path (str,a,b,c,ext_r);
377 // add extension if not present.
378 if (ext_r.empty_b ())
381 if (global_path.find (a+b+c+ext_r).empty_b ())