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"
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 Array<String> global_score_header_fields;
56 bool safe_global_b = false;
57 bool experimental_features_global_b = false;
58 bool dependency_global_b = false;
62 Getopt_long * oparser_global_p = 0;
64 String distill_inname_str (String name_str, String& ext_r);
67 Internationalisation kludge in two steps:
68 * use _i () to get entry in POT file
69 * call gettext () explicitely for actual "translation"
71 Note: these messages all start with lower case (ie, don't
72 follow regular localisation guidelines).
74 Long_option_init theopts[] = {
75 {_i ("EXT"), "output-format", 'f', _i ("use output format EXT (scm, ps, tex or as)")},
76 {0, "help", 'h', _i ("this help")},
77 {_i ("FIELD"), "header", 'H', _i ("write header field to BASENAME.FIELD")},
78 {_i ("DIR"), "include", 'I', _i ("add DIR to search path")},
79 {_i ("FILE"), "init", 'i', _i ("use FILE as init file")},
80 {0, "dependencies", 'M', _i ("write Makefile dependencies for every input file")},
81 {0, "no-paper", 'm', _i ("produce MIDI output only")},
82 {_i ("BASENAME"), "output", 'o', _i ("write output to BASENAME[-x].extension")},
83 {0, "find-old-relative", 'Q', _i ("show all changes in relative syntax")},
84 {0, "safe", 's', _i ("inhibit file output naming and exporting")},
85 {0, "no-timestamps", 'T', _i ("don't timestamp the output")},
86 {0, "test", 't', _i ("switch on experimental features")},
87 {0, "version", 'v', _i ("print version number")},
88 {0, "verbose", 'V', _i("verbose")},
89 {0, "warranty", 'w', _i ("show warranty and copyright")},
94 identify (ostream* os)
96 //*os << gnu_lilypond_version_str () << endl;
97 *os << gnu_lilypond_version_str ();
105 No version number or newline here. It confuses help2man
107 cout << _f ("Usage: %s [OPTION]... [FILE]...", "lilypond");
109 cout << _ ("Typeset music and or play MIDI from FILE");
113 "LilyPond is a music typesetter. It produces beautiful sheet music\n"
114 "using a high level description file as input. LilyPond is part of \n"
119 cout << _ ("Options:");
121 cout << Long_option_init::table_str (theopts);
123 cout << _ ("This binary was compiled with the following options:")
131 #ifdef STRING_UTILS_INLINED
132 "STRING_UTILS_INLINED "
135 "datadir: `" DIR_DATADIR "'\n"
136 "localedir: `" DIR_LOCALEDIR "'\n"
142 cout << _f ("Report bugs to %s", "bug-gnu-music@gnu.org") << endl;
151 "This is free software. It is covered by the GNU General Public License,\n"
152 "and you are welcome to change it and/or distribute copies of it under\n"
153 "certain conditions. Invoke as `%s --warranty' for more information.\n",
157 cout << _f ("Copyright (c) %s by", "1996--2000");
158 cout << "Han-Wen Nienhuys <hanwen@cs.uu.nl>\n"
159 << "Jan Nieuwenhuizen <janneke@gnu.org>\n";
167 cout << _ ("GNU LilyPond -- The GNU Project music typesetter");
169 cout << _f ("Copyright (c) %s by", "1996--2000");
171 cout << " Han-Wen Nienhuys <hanwen@cs.uu.nl>\n";
172 cout << " Jan Nieuwenhuizen <janneke@gnu.org>\n";
175 " This program is free software; you can redistribute it and/or\n"
176 "modify it under the terms of the GNU General Public License version 2\n"
177 "as published by the Free Software Foundation.\n"
179 " This program is distributed in the hope that it will be useful,\n"
180 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
181 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
182 "General Public License for more details.\n"
184 " You should have received a copy (refer to the file COPYING) of the\n"
185 "GNU General Public License along with this program; if not, write to\n"
186 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
193 // facilitate binary distributions
194 char const *env_lily = getenv ("LILYPONDPREFIX");
195 String prefix_directory;
197 prefix_directory = env_lily;
200 setlocale (LC_ALL, ""); /* enable locales */
201 setlocale (LC_NUMERIC, "C"); /* musn't have comma's in TeX output... */
202 String lily_locale_dir;
203 String name (PACKAGE);
207 urg; what *do* we want with $LILYPONDPREFIX, DIR_DATADIR and $prefix/share
208 handy for multiple source-dir runs, though...
210 if (!prefix_directory.empty_b())
212 lily_locale_dir = prefix_directory + "/share/locale";
213 bindtextdomain (name.ch_C (), lily_locale_dir.ch_C());
216 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
217 textdomain (name.ch_C ());
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);
228 Should use kpathsea, this is getting out of hand.
230 char *suffixes[] = {"ly", "afm", "scm", "tfm", "ps", 0};
231 String prefix = prefix_directory;
232 if (prefix.empty_b ())
233 prefix = DIR_DATADIR;
234 for (char **s = suffixes; *s; s++)
236 String p = prefix + to_str ('/') + String (*s);
240 /* Urg: GNU make's $(word) index starts at 1 */
242 while (global_path.try_add (p + to_str (".") + to_str (i)))
250 main_prog (int, char**)
253 need to do this first. Engravers use lily.scm contents.
256 if (verbose_global_b)
257 progress_indication ("\n");
258 read_lily_scm_file ("lily.scm");
261 call_constructors ();
262 default_outname_base_global = "lelie";
263 all_fonts_global_p = new All_font_metrics (global_path.str ());
267 while ((arg= oparser_global_p->get_next_arg ()))
270 if (outname_str_global == "")
272 Midi_def::reset_default_count ();
273 Paper_def::reset_default_count ();
277 f = distill_inname_str (f, i);
279 default_outname_base_global = "-";
283 split_path (f, a, b, c, d);
284 default_outname_base_global = c;
286 if (outname_str_global.length_i ())
287 default_outname_base_global = outname_str_global;
288 if (init_str_global.length_i ())
298 if (init_str_global.length_i ())
302 default_outname_base_global = "-";
303 if (outname_str_global.length_i ())
304 default_outname_base_global = outname_str_global;
305 do_one_file (i, default_outname_base_global);
307 delete oparser_global_p;
308 exit( exit_status_i_);
313 main (int argc, char **argv)
315 debug_init (); // should be first
319 prepare guile for heavy mem usage.
321 putenv is POSIX, setenv is BSD 4.3
323 putenv ("GUILE_INIT_SEGMENT_SIZE_1=4194304");
324 putenv ("GUILE_MAX_SEGMENT_SIZE=8388608");
326 ly_init_kpath (argv[0]);
328 oparser_global_p = new Getopt_long(argc, argv,theopts);
329 while (Long_option_init const * opt = (*oparser_global_p)())
331 switch (opt->shortname_ch_)
335 exit (0); // we print a version anyway.
338 experimental_features_global_b = true;
339 progress_indication ("*** enabling experimental features, you're on your own now ***\n");
342 outname_str_global = oparser_global_p->optional_argument_ch_C_;
349 output_global_ch = oparser_global_p->optional_argument_ch_C_;
352 find_old_relative_b= true;
355 global_score_header_fields.push (oparser_global_p->optional_argument_ch_C_);
358 global_path.push (oparser_global_p->optional_argument_ch_C_);
361 init_str_global = oparser_global_p->optional_argument_ch_C_;
368 verbose_global_b = true;
371 safe_global_b = true;
374 dependency_global_b = true;
377 no_paper_global_b = true;
380 no_timestamps_global_b = true;
390 gh_enter (argc, argv, main_prog);
392 gh_enter (argc, argv, (void(*)(int, char**))main_prog);
395 return 0; // unreachable
399 make input file name from command arg.
403 @output file name with added default extension. "" is stdin.
404 in reference argument: the extension. ".ly" if none
407 distill_inname_str (String name_str, String& ext_r)
409 String str = name_str;
415 split_path (str,a,b,c,ext_r);
417 // add extension if not present.
418 char const* extensions[] = {"", ".ly", ".fly", ".sly", "", 0};
419 extensions[0] = ext_r.ch_C ();
420 for (int i = 0; extensions[i]; i++)
422 if (!global_path.find (a+b+c+extensions[i]).empty_b ())
424 ext_r = extensions[i];
429 // in any case, assume (init).ly
430 if (!ext_r.length_i ())