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>
13 #include "lily-guile.hh"
16 #include "dimensions.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"
35 bool version_ignore_global_b
= false;
36 bool no_paper_global_b
= false;
37 bool no_timestamps_global_b
= false;
38 bool find_old_relative_b
= false;
40 char const* output_global_ch
= "tex";
42 String default_outname_base_global
= "lelie";
43 String outname_str_global
;
44 String init_str_global
;
46 int default_count_global
;
47 File_path global_path
;
49 bool safe_global_b
= false;
50 bool experimental_features_global_b
= false;
51 bool dependency_global_b
= false;
55 Getopt_long
* oparser_global_p
= 0;
57 String
distill_inname_str (String name_str
, String
& ext_r
);
59 Long_option_init theopts
[] = {
69 {0, "dependencies", 'd'},
70 {0, "no-timestamps", 'T'},
71 {0, "find-old-relative", 'Q'},
72 {0, "ignore-version", 'V'},
73 {1, "output-format", 'f'},
81 cout
<< _f ("Usage: %s [OPTION]... [FILE]...", "lilypond") << '\n';
82 cout
<< _ ("Typeset music and or play MIDI from FILE or <stdin>");
85 cout
<< _ ("Options:");
88 " -a, --about about LilyPond\n"
91 " -D, --debug enable debugging output\n"
94 " -d, --dependencies write Makefile dependencies for every input file\n"
97 " -h, --help this help\n"
100 " -f, --output-format=X use output format X\n"
103 " -I, --include=DIR add DIR to search path\n"
106 " -i, --init=FILE use FILE as init file\n"
109 " -M, --no-paper produce midi output only\n"
112 " -o, --output=FILE set FILE as default output base\n"
115 " -Q, --find-old-relative show all changes in relative syntax\n"
118 " -s, --safe inhibit file output naming and exporting TeX macros\n");
120 " -t, --test switch on experimental features\n"
123 " -T, --no-timestamps don't timestamp the output\n"
126 " -V, --ignore-version ignore mudela version\n"
129 " -w, --warranty show warranty and copyright\n"
132 cout
<< _ ("GNU LilyPond was compiled with the following settings:");
141 #ifdef STRING_UTILS_INLINED
142 "STRING_UTILS_INLINED "
144 "datadir=" DIR_DATADIR
146 "localedir=" DIR_LOCALEDIR
160 cout
<< _ ("GNU LilyPond is Free software, see --warranty");
163 cout
<< _f ("Copyright (c) %s by", "1996, 1997, 1998");
165 cout
<< " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
166 cout
<< " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
174 cout
<< _ ("GNU LilyPond -- The GNU Project music typesetter");
176 cout
<< _f ("Copyright (c) %s by", "1996, 1997, 1998");
178 cout
<< " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
179 cout
<< " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
182 " This program is free software; you can redistribute it and/or\n"
183 "modify it under the terms of the GNU General Public License version 2\n"
184 "as published by the Free Software Foundation.\n"
186 " This program is distributed in the hope that it will be useful,\n"
187 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
188 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
189 "General Public License for more details.\n"
191 " You should have received a copy (refer to the file COPYING) of the\n"
192 "GNU General Public License along with this program; if not, write to\n"
193 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
200 *mlog
<< get_version_str () << endl
;
206 // facilitate binary distributions
207 char const *env_lily
= getenv ("LILYPONDPREFIX");
208 String prefix_directory
;
210 prefix_directory
= env_lily
;
213 setlocale (LC_ALL
, ""); /* enable locales */
214 setlocale (LC_NUMERIC
, "C"); /* musn't have comma's in TeX output... */
215 String lily_locale_dir
;
216 String
name (PACKAGE
);
218 if (!prefix_directory
.empty_b())
220 lily_locale_dir
= prefix_directory
+ "/share/locale";
221 bindtextdomain (name
.ch_C (), lily_locale_dir
.ch_C());
224 bindtextdomain (name
.ch_C (), DIR_LOCALEDIR
);
225 textdomain (name
.ch_C ());
228 global_path
.add ("");
229 // must override (come before) "/usr/local/share/lilypond"!
230 char const *env_sz
= getenv ("LILYINCLUDE");
232 global_path
.parse_path (env_sz
);
235 char *suffixes
[] = {"ly", "afm", "scm", "init", 0};
236 for (char **s
= suffixes
; *s
; s
++){
237 if (!prefix_directory
.empty_b())
238 global_path
.add (prefix_directory
+ to_str ('/') + String (*s
));
240 global_path
.add (String (DIR_DATADIR
) + to_str ('/') + String(*s
));
246 main_prog (int argc
, char **argv
)
248 default_outname_base_global
= "lelie";
252 while ((arg
= oparser_global_p
->get_next_arg ()))
255 if (outname_str_global
== "")
257 Midi_def::reset_default_count ();
258 Paper_def::reset_default_count ();
262 f
= distill_inname_str (f
, i
);
264 default_outname_base_global
= "-";
268 split_path (f
, a
, b
, c
, d
);
269 default_outname_base_global
= c
;
271 if (outname_str_global
.length_i ())
272 default_outname_base_global
= outname_str_global
;
273 if (init_str_global
.length_i ())
283 if (init_str_global
.length_i ())
287 default_outname_base_global
= "-";
288 if (outname_str_global
.length_i ())
289 default_outname_base_global
= outname_str_global
;
290 do_one_file (i
, default_outname_base_global
);
292 delete oparser_global_p
;
293 exit( exit_status_i_
);
297 main (int argc
, char **argv
)
300 call_constructors ();
301 debug_init (); // should be first
305 oparser_global_p
= new Getopt_long(argc
, argv
,theopts
);
306 while (Long_option_init
const * opt
= (*oparser_global_p
)())
308 switch (opt
->shortname
)
311 experimental_features_global_b
= true;
312 *mlog
<< "*** enabling experimental features, you're on your own now ***\n";
315 outname_str_global
= oparser_global_p
->optional_argument_ch_C_
;
322 output_global_ch
= oparser_global_p
->optional_argument_ch_C_
;
325 find_old_relative_b
= true;
328 global_path
.push (oparser_global_p
->optional_argument_ch_C_
);
331 init_str_global
= oparser_global_p
->optional_argument_ch_C_
;
341 version_ignore_global_b
= true;
344 safe_global_b
= true;
347 dependency_global_b
= true;
353 no_paper_global_b
= true;
356 no_timestamps_global_b
= true;
364 gh_enter (argc
, argv
, (void(*)())main_prog
);
365 return 0; // unreachable
369 make input file name from command arg.
373 @output file name with added default extension. "" is stdin.
374 in reference argument: the extension. ".ly" if none
377 distill_inname_str (String name_str
, String
& ext_r
)
379 String str
= name_str
;
385 split_path (str
,a
,b
,c
,ext_r
);
387 // add extension if not present.
388 // UGH. Should parametrise in list of default extensions.
389 if (ext_r
.empty_b ())
392 if (global_path
.find (a
+b
+c
+ext_r
).empty_b ())