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 All_font_metrics *all_fonts_global_p;
46 String outname_global;
48 // (lytex-scm (quote all-definitions))
49 // String outext_global = "lytex";
50 String outext_global = "tex";
52 String init_name_global;
55 int default_count_global;
56 File_path global_path;
58 Array<String> global_dumped_header_fieldnames;
60 bool safe_global_b = false;
61 bool experimental_features_global_b = false;
62 bool dependency_global_b = false;
66 Getopt_long * oparser_global_p = 0;
68 Path distill_inname (String name_str);
71 Internationalisation kludge in two steps:
72 * use _i () to get entry in POT file
73 * call gettext () explicitely for actual "translation"
75 Note: these messages all start with lower case (ie, don't
76 follow regular localisation guidelines).
78 Long_option_init theopts[] = {
79 {_i ("EXT"), "output-format", 'f', _i ("use output format EXT (scm, ps, tex or as)")},
80 {0, "help", 'h', _i ("this help")},
81 {_i ("FIELD"), "header", 'H', _i ("write header field to BASENAME.FIELD")},
82 {_i ("DIR"), "include", 'I', _i ("add DIR to search path")},
83 {_i ("FILE"), "init", 'i', _i ("use FILE as init file")},
84 {0, "dependencies", 'M', _i ("write Makefile dependencies for every input file")},
85 {0, "no-paper", 'm', _i ("produce MIDI output only")},
86 {_i ("NAME"), "output", 'o', _i ("write output to NAME")},
87 {0, "find-old-relative", 'Q', _i ("show all changes in relative syntax")},
88 {0, "safe", 's', _i ("inhibit file output naming and exporting")},
89 {0, "no-timestamps", 'T', _i ("don't timestamp the output")},
90 {0, "test", 't', _i ("switch on experimental features")},
91 {0, "version", 'v', _i ("print version number")},
92 {0, "verbose", 'V', _i("verbose")},
93 {0, "warranty", 'w', _i ("show warranty and copyright")},
98 identify (ostream* os)
100 *os << gnu_lilypond_version_str ();
108 No version number or newline here. It confuses help2man
110 cout << _f ("Usage: %s [OPTION]... [FILE]...", "lilypond");
112 cout << _ ("Typeset music and or play MIDI from FILE");
116 "LilyPond is a music typesetter. It produces beautiful sheet music\n"
117 "using a high level description file as input. LilyPond is part of \n"
122 cout << _ ("Options:");
124 cout << Long_option_init::table_str (theopts);
126 cout << _ ("This binary was compiled with the following options:")
134 #ifdef STRING_UTILS_INLINED
135 "STRING_UTILS_INLINED "
138 "datadir: `" DIR_DATADIR "'\n"
139 "localedir: `" DIR_LOCALEDIR "'\n"
145 cout << _f ("Report bugs to %s", "bug-gnu-music@gnu.org") << endl;
154 "This is free software. It is covered by the GNU General Public License,\n"
155 "and you are welcome to change it and/or distribute copies of it under\n"
156 "certain conditions. Invoke as `%s --warranty' for more information.\n",
160 cout << _f ("Copyright (c) %s by", "1996--2000");
162 cout << " Han-Wen Nienhuys <hanwen@cs.uu.nl>\n";
163 cout << " Jan Nieuwenhuizen <janneke@gnu.org>\n";
170 cout << _ ("GNU LilyPond -- The music typesetter");
172 cout << _f ("Copyright (c) %s by", "1996--2000");
174 cout << " Han-Wen Nienhuys <hanwen@cs.uu.nl>\n";
175 cout << " Jan Nieuwenhuizen <janneke@gnu.org>\n";
178 " This program is free software; you can redistribute it and/or\n"
179 "modify it under the terms of the GNU General Public License version 2\n"
180 "as published by the Free Software Foundation.\n"
182 " This program is distributed in the hope that it will be useful,\n"
183 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
184 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
185 "General Public License for more details.\n"
187 " You should have received a copy (refer to the file COPYING) of the\n"
188 "GNU General Public License along with this program; if not, write to\n"
189 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
196 // facilitate binary distributions
197 char const *env_lily = getenv ("LILYPONDPREFIX");
198 String prefix_directory;
200 prefix_directory = env_lily;
203 setlocale (LC_ALL, ""); /* enable locales */
204 setlocale (LC_NUMERIC, "C"); /* musn't have comma's in TeX output... */
205 String lily_locale_dir;
206 String name (PACKAGE);
210 urg; what *do* we want with $LILYPONDPREFIX, DIR_DATADIR and $prefix/share
211 handy for multiple source-dir runs, though...
213 if (!prefix_directory.empty_b())
215 lily_locale_dir = prefix_directory + "/share/locale";
216 bindtextdomain (name.ch_C (), lily_locale_dir.ch_C());
219 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
220 textdomain (name.ch_C ());
223 global_path.add ("");
224 // must override (come before) "/usr/local/share/lilypond"!
225 char const *env_sz = getenv ("LILYINCLUDE");
227 global_path.parse_path (env_sz);
231 Should use kpathsea, this is getting out of hand.
233 char *suffixes[] = {"ly", "afm", "scm", "tfm", "ps", 0};
234 String prefix = prefix_directory;
235 if (prefix.empty_b ())
236 prefix = DIR_DATADIR;
237 for (char **s = suffixes; *s; s++)
239 String p = prefix + to_str ('/') + String (*s);
243 /* Urg: GNU make's $(word) index starts at 1 */
245 while (global_path.try_add (p + to_str (".") + to_str (i)))
253 main_prog (int, char**)
256 need to do this first. Engravers use lily.scm contents.
259 if (verbose_global_b)
260 progress_indication ("\n");
261 read_lily_scm_file ("lily.scm");
264 call_constructors ();
265 all_fonts_global_p = new All_font_metrics (global_path.str ());
269 while ((arg = oparser_global_p->get_next_arg ()) || p == 0)
278 // What/when was this supposed to do?
279 // It looks like it reset the outname_str_global for every new
280 // file, but only if user didn't specify a outname? Huh?
281 // if (outname_str_global == "")
283 Midi_def::reset_default_count ();
284 Paper_def::reset_default_count ();
287 Path inpath = distill_inname (infile);
288 Path outpath = inpath;
289 outpath.ext = outext_global;
290 if (!outname_global.empty_b ())
291 outpath = split_path (outname_global);
294 if (!init_name_global.empty_b ())
295 init = init_name_global;
297 init = "init." + inpath.ext;
299 /* Burp: output name communication goes through _global */
300 String save_outname_global = outname_global;
301 outname_global = outpath.path ();
302 do_one_file (init, inpath.path ());
303 outname_global = save_outname_global;
306 delete oparser_global_p;
307 exit (exit_status_i_);
312 main (int argc, char **argv)
314 debug_init (); // should be first
318 prepare guile for heavy mem usage.
320 putenv is POSIX, setenv is BSD 4.3
322 putenv ("GUILE_INIT_SEGMENT_SIZE_1=4194304");
323 putenv ("GUILE_MAX_SEGMENT_SIZE=8388608");
325 ly_init_kpath (argv[0]);
327 oparser_global_p = new Getopt_long(argc, argv,theopts);
328 while (Long_option_init const * opt = (*oparser_global_p)())
330 switch (opt->shortname_ch_)
334 exit (0); // we print a version anyway.
337 experimental_features_global_b = true;
338 progress_indication ("*** enabling experimental features, you're on your own now ***\n");
342 String s = oparser_global_p->optional_argument_ch_C_;
343 Path p = split_path (s);
344 if (p.ext.empty_b ())
345 p.ext = outext_global;
346 outname_global = p.path ();
354 outext_global = oparser_global_p->optional_argument_ch_C_;
357 find_old_relative_b= true;
360 global_dumped_header_fieldnames.push (oparser_global_p->optional_argument_ch_C_);
363 global_path.push (oparser_global_p->optional_argument_ch_C_);
366 init_name_global = oparser_global_p->optional_argument_ch_C_;
373 verbose_global_b = true;
376 safe_global_b = true;
379 dependency_global_b = true;
382 no_paper_global_b = true;
385 no_timestamps_global_b = true;
395 gh_enter (argc, argv, main_prog);
397 gh_enter (argc, argv, (void(*)(int, char**))main_prog);
400 return 0; // unreachable
404 Make input file name from command argument.
406 Path describes file name with added default extension,
407 ".ly" if none. "-" is stdin.
410 distill_inname (String str)
412 Path p = split_path (str);
413 if (str.empty_b () || str == "-")
417 String orig_ext = p.ext;
418 char const *extensions[] = {"ly", "fly", "sly", "", 0};
419 for (int i = 0; extensions[i]; i++)
422 if (*extensions[i] && !p.ext.empty_b ())
424 p.ext += extensions[i];
425 if (!global_path.find (p.path ()).empty_b ())
428 /* Reshuffle extension */
429 p = split_path (p.path ());