2 main.cc -- implement main: entrypoints
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "lily-guile.hh"
14 #include "lily-version.hh"
16 #include "all-font-metrics.hh"
18 #include "dimensions.hh"
19 #include "getopt-long.hh"
23 #include "file-path.hh"
25 #include "file-results.hh"
27 #include "lily-guile.hh"
28 #include "paper-def.hh"
29 #include "midi-def.hh"
30 #include "global-ctor.hh"
37 bool version_ignore_global_b = false;
38 bool no_paper_global_b = false;
39 bool no_timestamps_global_b = false;
40 bool find_old_relative_b = false;
42 char const* output_global_ch = "tex";
43 All_font_metrics *all_fonts_global_p;
45 String default_outname_base_global = "lelie";
46 String outname_str_global;
47 String init_str_global;
49 int default_count_global;
50 File_path global_path;
52 bool safe_global_b = false;
53 bool experimental_features_global_b = false;
54 bool dependency_global_b = false;
58 Getopt_long * oparser_global_p = 0;
60 String distill_inname_str (String name_str, String& ext_r);
63 Internationalisation kludge in two steps:
64 * use _i () to get entry in POT file
65 * call gettext () explicitely for actual "translation"
67 Note: these messages all start with lower case (ie, don't
68 follow regular localisation guidelines).
70 Long_option_init theopts[] = {
71 {0, "debug", 'd', _i ("enable debugging output")},
72 {_i ("EXT"), "output-format", 'f', _i ("use output format EXT")},
73 {0, "help", 'h', _i ("this help")},
74 {_i ("DIR"), "include", 'I', _i ("add DIR to search path")},
75 {_i ("FILE"), "init", 'i', _i ("use FILE as init file")},
76 {0, "dependencies", 'M', _i ("write Makefile dependencies for every input file")},
77 {0, "no-paper", 'm', _i ("produce MIDI output only")},
78 {_i ("BASENAME"), "output", 'o', _i ("write output to BASENAME[-x].extension")},
79 {0, "find-old-relative", 'Q', _i ("show all changes in relative syntax")},
80 {0, "safe", 's', _i ("inhibit file output naming and exporting")},
81 {0, "no-timestamps", 'T', _i ("don't timestamp the output")},
82 {0, "test", 't', _i ("switch on experimental features")},
83 {0, "ignore-version", 'V', _i ("ignore mudela version")},
84 {0, "version", 'v', _i ("print version number")},
85 {0, "warranty", 'w', _i ("show warranty and copyright")},
92 cout << _f ("Usage: %s [OPTION]... [FILE]...", "lilypond");
94 cout << _ ("Typeset music and or play MIDI from FILE");
98 "LilyPond is a music typesetter. It produces beautiful sheet music\n"
99 "using a high level description file as input. LilyPond is part of \n"
104 cout << _ ("Options:");
106 cout << Long_option_init::table_str (theopts);
108 cout << _ ("This binary was compiled with the following options:")
116 #ifdef STRING_UTILS_INLINED
117 "STRING_UTILS_INLINED "
120 "datadir: `" DIR_DATADIR "'\n"
121 "localedir: `" DIR_LOCALEDIR "'\n"
124 print_mudela_versions (cout);
127 cout << _f ("Report bugs to %s", "bug-gnu-music@gnu.org") << endl;
133 cout << gnu_lilypond_version_str () << endl;
142 "This is free software. It is covered by the GNU General Public License,\n"
143 "and you are welcome to change it and/or distribute copies of it under\n"
144 "certain conditions. Invoke as `%s --warranty' for more information.\n",
148 cout << _f ("Copyright (c) %s by", "1996--1999");
149 cout << "Han-Wen Nienhuys <hanwen@cs.uu.nl>\n"
150 << "Jan Nieuwenhuizen <janneke@gnu.org>\n";
158 cout << _ ("GNU LilyPond -- The GNU Project music typesetter");
160 cout << _f ("Copyright (c) %s by", "1996--1999");
162 cout << " Han-Wen Nienhuys <hanwen@cs.uu.nl>\n";
163 cout << " Jan Nieuwenhuizen <janneke@gnu.org>\n";
166 " This program is free software; you can redistribute it and/or\n"
167 "modify it under the terms of the GNU General Public License version 2\n"
168 "as published by the Free Software Foundation.\n"
170 " This program is distributed in the hope that it will be useful,\n"
171 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
172 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
173 "General Public License for more details.\n"
175 " You should have received a copy (refer to the file COPYING) of the\n"
176 "GNU General Public License along with this program; if not, write to\n"
177 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
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);
199 urg; what *do* we want with $LILYPONDPREFIX, DIR_DATADIR and $prefix/share
200 handy for multiple source-dir runs, though...
202 if (!prefix_directory.empty_b())
204 lily_locale_dir = prefix_directory + "/share/locale";
205 bindtextdomain (name.ch_C (), lily_locale_dir.ch_C());
208 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
209 textdomain (name.ch_C ());
212 global_path.add ("");
213 // must override (come before) "/usr/local/share/lilypond"!
214 char const *env_sz = getenv ("LILYINCLUDE");
216 global_path.parse_path (env_sz);
219 char *suffixes[] = {"ly", "afm", "scm", "tfm", "cmtfm", "ps", 0};
220 for (char **s = suffixes; *s; s++){
221 if (!prefix_directory.empty_b())
222 global_path.add (prefix_directory + to_str ('/') + String (*s));
224 global_path.add (String (DIR_DATADIR) + to_str ('/') + String(*s));
230 main_prog (int, char**)
233 need to do this first. Engravers use lily.scm contents.
236 read_lily_scm_file ( "lily.scm");
239 call_constructors ();
240 default_outname_base_global = "lelie";
241 all_fonts_global_p = new All_font_metrics (global_path.str ());
245 while ((arg= oparser_global_p->get_next_arg ()))
248 if (outname_str_global == "")
250 Midi_def::reset_default_count ();
251 Paper_def::reset_default_count ();
255 f = distill_inname_str (f, i);
257 default_outname_base_global = "-";
261 split_path (f, a, b, c, d);
262 default_outname_base_global = c;
264 if (outname_str_global.length_i ())
265 default_outname_base_global = outname_str_global;
266 if (init_str_global.length_i ())
276 if (init_str_global.length_i ())
280 default_outname_base_global = "-";
281 if (outname_str_global.length_i ())
282 default_outname_base_global = outname_str_global;
283 do_one_file (i, default_outname_base_global);
285 delete oparser_global_p;
286 exit( exit_status_i_);
291 main (int argc, char **argv)
293 debug_init (); // should be first
296 oparser_global_p = new Getopt_long(argc, argv,theopts);
297 while (Long_option_init const * opt = (*oparser_global_p)())
299 switch (opt->shortname_ch_)
303 exit (0); // we print a version anyway.
306 experimental_features_global_b = true;
307 *mlog << "*** enabling experimental features, you're on your own now ***\n";
310 outname_str_global = oparser_global_p->optional_argument_ch_C_;
317 output_global_ch = oparser_global_p->optional_argument_ch_C_;
320 find_old_relative_b= true;
323 global_path.push (oparser_global_p->optional_argument_ch_C_);
326 init_str_global = oparser_global_p->optional_argument_ch_C_;
333 version_ignore_global_b = true;
336 safe_global_b = true;
339 dependency_global_b = true;
345 no_paper_global_b = true;
348 no_timestamps_global_b = true;
358 gh_enter (argc, argv, main_prog);
360 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 char const* extensions[] = {"", ".ly", ".fly", ".sly", "", 0};
387 extensions[0] = ext_r.ch_C ();
388 for (int i = 0; extensions[i]; i++)
390 if (!global_path.find (a+b+c+extensions[i]).empty_b ())
392 ext_r = extensions[i];
397 // in any case, assume (init).ly
398 if (!ext_r.length_i ())