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>
15 #include "getopt-long.hh"
19 #include "file-path.hh"
21 #include "file-results.hh"
29 bool version_ignore_global_b = false;
30 bool no_paper_global_b = false;
31 bool no_timestamps_global_b = false;
32 bool find_quarts_global_b = false;
33 String default_outname_base_global = "lelie";
34 int default_count_global;
35 File_path global_path;
38 bool experimental_features_global_b = false;
39 bool dependency_global_b = false;
43 String distill_inname_str (String name_str, String& ext_r);
45 Long_option_init theopts[] = {
55 {0, "dependencies", 'd'},
56 {0, "no-timestamps", 'T'},
57 {0, "find-fourths", 'Q'},
58 {0, "ignore-version", 'V'},
65 cout << _f ("Usage: %s [OPTION]... [FILE]...", "lilypond") << '\n';
66 cout << _ ("Typeset music and or play MIDI from FILE or <stdin>");
69 cout << _ ("Options:");
72 " -a, --about about LilyPond\n"
75 " -D, --debug enable debugging output\n"
78 " -d, --dependencies write Makefile dependencies for every input file\n"
81 " -I, --include=DIR add DIR to search path\n"
84 " -i, --init=FILE use FILE as init file\n"
87 " -h, --help this help\n"
90 " -M, --no-paper produce midi output only\n"
93 " -o, --output=FILE set FILE as default output base\n"
96 " -Q, --find-fourths show all intervals greater than a fourth\n"
99 " -t, --test switch on experimental features\n"
102 " -T, --no-timestamps don't timestamp the output\n"
105 " -V, --ignore-version ignore mudela version\n"
108 " -w, --warranty show warranty and copyright\n"
111 cout << _ ("GNU LilyPond was compiled with the following settings:");
120 #ifdef STRING_UTILS_INLINED
121 "STRING_UTILS_INLINED "
123 "datadir=" DIR_DATADIR
125 "localedir=" DIR_LOCALEDIR
139 cout << _ ("GNU LilyPond is Free software, see --warranty");
142 cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
144 cout << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
145 cout << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
153 cout << _ ("GNU LilyPond -- The GNU Project music typesetter");
155 cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
157 cout << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
158 cout << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
161 " This program is free software; you can redistribute it and/or\n"
162 "modify it under the terms of the GNU General Public License version 2\n"
163 "as published by the Free Software Foundation.\n"
165 " This program is distributed in the hope that it will be useful,\n"
166 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
167 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
168 "General Public License for more details.\n"
170 " You should have received a copy (refer to the file COPYING) of the\n"
171 "GNU General Public License along with this program; if not, write to\n"
172 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
179 *mlog << get_version_str () << endl;
183 main (int argc, char **argv)
185 // facilitate binary distributions
186 char const *env_lily = getenv ("LILYPONDPREFIX");
187 String prefix_directory;
189 prefix_directory = env_lily;
192 setlocale (LC_ALL, ""); /* enable locales */
193 setlocale (LC_NUMERIC, "C"); /* musn't have comma's in TeX output... */
194 String lily_locale_dir;
195 String name (PACKAGE);
197 if (!prefix_directory.empty_b())
199 lily_locale_dir = prefix_directory + "/share/locale";
200 bindtextdomain (name.ch_C (), lily_locale_dir.ch_C());
203 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
204 textdomain (name.ch_C ());
208 call_constructors ();
209 debug_init (); // should be first
211 global_path.add ("");
212 // must override (come before) "/usr/local/share/lilypond"!
213 char const *env_sz = getenv ("LILYINCLUDE");
215 global_path.parse_path (env_sz);
217 if (!prefix_directory.empty_b())
219 global_path.add (prefix_directory + "/share/lilypond/init/");
220 global_path.add (prefix_directory + "/share/lilypond");
223 global_path.add (String (DIR_DATADIR) + "/init/");
225 global_path.push (DIR_DATADIR);
227 Getopt_long oparser (argc, argv,theopts);
231 while (Long_option_init const * opt = oparser ())
233 switch (opt->shortname)
236 experimental_features_global_b = true;
239 outname_str = oparser.optional_argument_ch_C_;
246 find_quarts_global_b = true;
249 global_path.push (oparser.optional_argument_ch_C_);
252 init_str = oparser.optional_argument_ch_C_;
262 version_ignore_global_b = true;
265 dependency_global_b = true;
271 no_paper_global_b = true;
274 no_timestamps_global_b = true;
282 default_outname_base_global = "lelie";
288 while ((arg= oparser.get_next_arg ()))
292 f = distill_inname_str (f, i);
294 default_outname_base_global = "-";
298 split_path (f, a, b, c, d);
299 default_outname_base_global = c;
301 if (outname_str.length_i ())
302 default_outname_base_global = outname_str;
303 if (init_str.length_i ())
313 if (init_str.length_i ())
317 default_outname_base_global = "-";
318 if (outname_str.length_i ())
319 default_outname_base_global = outname_str;
320 do_one_file (i, default_outname_base_global);
323 return exit_status_i_;
327 urg: make input file name:
331 output: file name with added default extension. "" is stdin.
332 in reference argument: the extension. ".ly" if none
335 distill_inname_str (String name_str, String& ext_r)
337 String str = name_str;
343 split_path (str,a,b,c,ext_r);
345 // add extension if not present.
346 if (ext_r.empty_b ())
349 if (global_path.find (a+b+c+ext_r).empty_b ())