2 main.cc -- implement main: entrypoints
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
14 #include "lily-guile.hh"
15 #include "lily-version.hh"
17 #include "all-font-metrics.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"
29 #include "global-ctor.hh"
36 #include <kpathsea/kpathsea.h>
39 bool verbose_global_b = false;
40 bool no_paper_global_b = false;
41 bool no_timestamps_global_b = false;
42 bool find_old_relative_b = false;
44 char const* output_global_ch = "tex";
45 All_font_metrics *all_fonts_global_p;
47 String default_outname_base_global = "lelie";
48 String outname_str_global;
49 String init_str_global;
51 int default_count_global;
52 File_path global_path;
54 bool safe_global_b = false;
55 bool experimental_features_global_b = false;
56 bool dependency_global_b = false;
60 Getopt_long * oparser_global_p = 0;
62 String distill_inname_str (String name_str, String& ext_r);
65 Internationalisation kludge in two steps:
66 * use _i () to get entry in POT file
67 * call gettext () explicitely for actual "translation"
69 Note: these messages all start with lower case (ie, don't
70 follow regular localisation guidelines).
72 Long_option_init theopts[] = {
73 {0, "debug", 'd', _i ("enable debugging output")},
74 {_i ("EXT"), "output-format", 'f', _i ("use output format EXT (scm, ps, tex or as)")},
75 {0, "help", 'h', _i ("this help")},
76 {_i ("DIR"), "include", 'I', _i ("add DIR to search path")},
77 {_i ("FILE"), "init", 'i', _i ("use FILE as init file")},
78 {0, "dependencies", 'M', _i ("write Makefile dependencies for every input file")},
79 {0, "no-paper", 'm', _i ("produce MIDI output only")},
80 {_i ("BASENAME"), "output", 'o', _i ("write output to BASENAME[-x].extension")},
81 {0, "find-old-relative", 'Q', _i ("show all changes in relative syntax")},
82 {0, "safe", 's', _i ("inhibit file output naming and exporting")},
83 {0, "no-timestamps", 'T', _i ("don't timestamp the output")},
84 {0, "test", 't', _i ("switch on experimental features")},
85 {0, "version", 'v', _i ("print version number")},
86 {0, "verbose", 'V', _i("verbose")},
87 {0, "warranty", 'w', _i ("show warranty and copyright")},
92 identify (ostream* os)
94 *os << gnu_lilypond_version_str () << endl;
102 cout << _f ("Usage: %s [OPTION]... [FILE]...", "lilypond");
104 cout << _ ("Typeset music and or play MIDI from FILE");
108 "LilyPond is a music typesetter. It produces beautiful sheet music\n"
109 "using a high level description file as input. LilyPond is part of \n"
114 cout << _ ("Options:");
116 cout << Long_option_init::table_str (theopts);
118 cout << _ ("This binary was compiled with the following options:")
126 #ifdef STRING_UTILS_INLINED
127 "STRING_UTILS_INLINED "
130 "datadir: `" DIR_DATADIR "'\n"
131 "localedir: `" DIR_LOCALEDIR "'\n"
137 cout << _f ("Report bugs to %s", "bug-gnu-music@gnu.org") << endl;
146 "This is free software. It is covered by the GNU General Public License,\n"
147 "and you are welcome to change it and/or distribute copies of it under\n"
148 "certain conditions. Invoke as `%s --warranty' for more information.\n",
152 cout << _f ("Copyright (c) %s by", "1996--2000");
153 cout << "Han-Wen Nienhuys <hanwen@cs.uu.nl>\n"
154 << "Jan Nieuwenhuizen <janneke@gnu.org>\n";
162 cout << _ ("GNU LilyPond -- The GNU Project music typesetter");
164 cout << _f ("Copyright (c) %s by", "1996--2000");
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 // facilitate binary distributions
189 char const *env_lily = getenv ("LILYPONDPREFIX");
190 String prefix_directory;
192 prefix_directory = env_lily;
195 setlocale (LC_ALL, ""); /* enable locales */
196 setlocale (LC_NUMERIC, "C"); /* musn't have comma's in TeX output... */
197 String lily_locale_dir;
198 String name (PACKAGE);
202 urg; what *do* we want with $LILYPONDPREFIX, DIR_DATADIR and $prefix/share
203 handy for multiple source-dir runs, though...
205 if (!prefix_directory.empty_b())
207 lily_locale_dir = prefix_directory + "/share/locale";
208 bindtextdomain (name.ch_C (), lily_locale_dir.ch_C());
211 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
212 textdomain (name.ch_C ());
215 global_path.add ("");
216 // must override (come before) "/usr/local/share/lilypond"!
217 char const *env_sz = getenv ("LILYINCLUDE");
219 global_path.parse_path (env_sz);
223 Should use kpathsea, this is getting out of hand.
225 char *suffixes[] = {"ly", "afm", "scm", "tfm", "ps", 0};
226 String prefix = prefix_directory;
227 if (prefix.empty_b ()) prefix = DIR_DATADIR;
228 for (char **s = suffixes; *s; s++)
230 String p = prefix + to_str ('/') + String (*s);
238 main_prog (int, char**)
241 need to do this first. Engravers use lily.scm contents.
244 read_lily_scm_file ("lily.scm");
247 call_constructors ();
248 default_outname_base_global = "lelie";
249 all_fonts_global_p = new All_font_metrics (global_path.str ());
253 while ((arg= oparser_global_p->get_next_arg ()))
256 if (outname_str_global == "")
258 Midi_def::reset_default_count ();
259 Paper_def::reset_default_count ();
263 f = distill_inname_str (f, i);
265 default_outname_base_global = "-";
269 split_path (f, a, b, c, d);
270 default_outname_base_global = c;
272 if (outname_str_global.length_i ())
273 default_outname_base_global = outname_str_global;
274 if (init_str_global.length_i ())
284 if (init_str_global.length_i ())
288 default_outname_base_global = "-";
289 if (outname_str_global.length_i ())
290 default_outname_base_global = outname_str_global;
291 do_one_file (i, default_outname_base_global);
293 delete oparser_global_p;
294 exit( exit_status_i_);
299 main (int argc, char **argv)
301 debug_init (); // should be first
305 prepare guile for heavy mem usage.
307 setenv ("GUILE_INIT_SEGMENT_SIZE_1", "4194304", 0);
308 setenv ("GUILE_MAX_SEGMENT_SIZE", "8388608", 0);
313 kpse_set_program_name(argv[0], NULL);
314 kpse_maketex_option("tfm", TRUE);
316 oparser_global_p = new Getopt_long(argc, argv,theopts);
317 while (Long_option_init const * opt = (*oparser_global_p)())
319 switch (opt->shortname_ch_)
323 exit (0); // we print a version anyway.
326 experimental_features_global_b = true;
327 progress_indication ("*** enabling experimental features, you're on your own now ***\n");
330 outname_str_global = oparser_global_p->optional_argument_ch_C_;
337 output_global_ch = oparser_global_p->optional_argument_ch_C_;
340 find_old_relative_b= true;
343 global_path.push (oparser_global_p->optional_argument_ch_C_);
346 init_str_global = oparser_global_p->optional_argument_ch_C_;
353 verbose_global_b = true;
356 safe_global_b = true;
359 dependency_global_b = true;
365 no_paper_global_b = true;
368 no_timestamps_global_b = true;
378 gh_enter (argc, argv, main_prog);
380 gh_enter (argc, argv, (void(*)(...))main_prog);
383 return 0; // unreachable
387 make input file name from command arg.
391 @output file name with added default extension. "" is stdin.
392 in reference argument: the extension. ".ly" if none
395 distill_inname_str (String name_str, String& ext_r)
397 String str = name_str;
403 split_path (str,a,b,c,ext_r);
405 // add extension if not present.
406 char const* extensions[] = {"", ".ly", ".fly", ".sly", "", 0};
407 extensions[0] = ext_r.ch_C ();
408 for (int i = 0; extensions[i]; i++)
410 if (!global_path.find (a+b+c+extensions[i]).empty_b ())
412 ext_r = extensions[i];
417 // in any case, assume (init).ly
418 if (!ext_r.length_i ())