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 "ps-lookup.hh"
27 #include "tex-lookup.hh"
28 #include "lily-guile.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;
39 String default_outname_base_global = "lelie";
40 int default_count_global;
41 File_path global_path;
44 Tex_lookup tex_lookup;
45 Lookup* global_lookup_l = &tex_lookup;
47 bool experimental_features_global_b = false;
48 bool dependency_global_b = false;
52 String distill_inname_str (String name_str, String& ext_r);
54 Long_option_init theopts[] = {
64 {0, "dependencies", 'd'},
65 {0, "no-timestamps", 'T'},
66 {0, "find-fourths", 'Q'},
67 {0, "ignore-version", 'V'},
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 " -I, --include=DIR add DIR to search path\n"
93 " -i, --init=FILE use FILE as init file\n"
96 " -h, --help this help\n"
99 " -M, --no-paper produce midi output only\n"
102 " -o, --output=FILE set FILE as default output base\n"
105 " -Q, --find-fourths show all intervals greater than a fourth\n"
108 " -t, --test switch on experimental features\n"
111 " -T, --no-timestamps don't timestamp the output\n"
114 " -V, --ignore-version ignore mudela version\n"
117 " -w, --warranty show warranty and copyright\n"
120 cout << _ ("GNU LilyPond was compiled with the following settings:");
129 #ifdef STRING_UTILS_INLINED
130 "STRING_UTILS_INLINED "
132 "datadir=" DIR_DATADIR
134 "localedir=" DIR_LOCALEDIR
148 cout << _ ("GNU LilyPond is Free software, see --warranty");
151 cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
153 cout << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
154 cout << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
162 cout << _ ("GNU LilyPond -- The GNU Project music typesetter");
164 cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
166 cout << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
167 cout << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
170 " This program is free software; you can redistribute it and/or\n"
171 "modify it under the terms of the GNU General Public License version 2\n"
172 "as published by the Free Software Foundation.\n"
174 " This program is distributed in the hope that it will be useful,\n"
175 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
176 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
177 "General Public License for more details.\n"
179 " You should have received a copy (refer to the file COPYING) of the\n"
180 "GNU General Public License along with this program; if not, write to\n"
181 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
188 *mlog << get_version_str () << endl;
192 main_prog (int argc, char **argv)
194 // facilitate binary distributions
195 char const *env_lily = getenv ("LILYPONDPREFIX");
196 String prefix_directory;
198 prefix_directory = env_lily;
201 setlocale (LC_ALL, ""); /* enable locales */
202 setlocale (LC_NUMERIC, "C"); /* musn't have comma's in TeX output... */
203 String lily_locale_dir;
204 String name (PACKAGE);
206 if (!prefix_directory.empty_b())
208 lily_locale_dir = prefix_directory + "/share/locale";
209 bindtextdomain (name.ch_C (), lily_locale_dir.ch_C());
212 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
213 textdomain (name.ch_C ());
217 call_constructors ();
218 debug_init (); // should be first
220 global_path.add ("");
221 // must override (come before) "/usr/local/share/lilypond"!
222 char const *env_sz = getenv ("LILYINCLUDE");
224 global_path.parse_path (env_sz);
226 if (!prefix_directory.empty_b())
228 global_path.add (prefix_directory + "/share/lilypond/init/");
229 global_path.add (prefix_directory + "/share/lilypond");
232 global_path.add (String (DIR_DATADIR) + "/ly/");
233 global_path.add (String (DIR_DATADIR) + "/afm/");
235 Getopt_long oparser (argc, argv,theopts);
239 while (Long_option_init const * opt = oparser ())
241 switch (opt->shortname)
244 experimental_features_global_b = true;
245 global_lookup_l = &ps_lookup;
246 *mlog << "*** enabling experimental features, you're on your own now ***\n";
249 outname_str = oparser.optional_argument_ch_C_;
256 find_quarts_global_b = true;
259 global_path.push (oparser.optional_argument_ch_C_);
262 init_str = oparser.optional_argument_ch_C_;
272 version_ignore_global_b = true;
275 dependency_global_b = true;
281 no_paper_global_b = true;
284 no_timestamps_global_b = true;
292 default_outname_base_global = "lelie";
298 while ((arg= oparser.get_next_arg ()))
302 f = distill_inname_str (f, i);
304 default_outname_base_global = "-";
308 split_path (f, a, b, c, d);
309 default_outname_base_global = c;
311 if (outname_str.length_i ())
312 default_outname_base_global = outname_str;
313 if (init_str.length_i ())
323 if (init_str.length_i ())
327 default_outname_base_global = "-";
328 if (outname_str.length_i ())
329 default_outname_base_global = outname_str;
330 do_one_file (i, default_outname_base_global);
335 main (int argc, char **argv)
338 gh_enter (argc, argv, (void(*)())main_prog);
339 return exit_status_i_;
341 main_prog (argc, argv);
342 return exit_status_i_;
347 urg: make input file name:
351 output: file name with added default extension. "" is stdin.
352 in reference argument: the extension. ".ly" if none
355 distill_inname_str (String name_str, String& ext_r)
357 String str = name_str;
363 split_path (str,a,b,c,ext_r);
365 // add extension if not present.
366 if (ext_r.empty_b ())
369 if (global_path.find (a+b+c+ext_r).empty_b ())