]> git.donarmstrong.com Git - lilypond.git/blob - lily/main.cc
release: 1.0.17
[lilypond.git] / lily / main.cc
1 /*
2   main.cc -- implement main: entrypoints
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include <stdlib.h>
10 #include <iostream.h>
11 #include <assert.h>
12 #include <locale.h>
13 #include "proto.hh"
14 #include "dimensions.hh"
15 #include "plist.hh"
16 #include "getopt-long.hh"
17 #include "misc.hh"
18 #include "string.hh"
19 #include "main.hh"
20 #include "file-path.hh"
21 #include "config.hh"
22 #include "file-results.hh"
23 #include "debug.hh"
24 #include "ps-lookup.hh"
25 #include "tex-lookup.hh"
26 #include "lily-guile.hh"
27
28 #if HAVE_GETTEXT
29 #include <libintl.h>
30 #endif
31
32
33 bool version_ignore_global_b = false;
34 bool no_paper_global_b = false;
35 bool no_timestamps_global_b = false;
36 bool find_quarts_global_b = false;
37 String default_outname_base_global =  "lelie";
38 int default_count_global;
39 File_path global_path;
40
41 Ps_lookup ps_lookup;
42 Tex_lookup tex_lookup;
43 Lookup* global_lookup_l = &tex_lookup;
44
45 bool experimental_features_global_b = false;
46 bool dependency_global_b = false;
47
48 int exit_status_i_;
49
50 String distill_inname_str (String name_str, String& ext_r);
51
52 Long_option_init theopts[] = {
53   {0, "about", 'a'},
54   {1, "output", 'o'},
55   {0, "warranty", 'w'},
56   {0, "help", 'h'},
57   {0, "test", 't'},
58   {0, "debug", 'D'},
59   {1, "init", 'i'},
60   {1, "include", 'I'},
61   {0, "no-paper", 'M'},
62   {0, "dependencies", 'd'},
63   {0, "no-timestamps", 'T'},
64   {0, "find-fourths", 'Q'},
65   {0, "ignore-version", 'V'},
66   {0,0,0}
67 };
68
69 void
70 usage ()
71 {
72   cout << _f ("Usage: %s [OPTION]... [FILE]...", "lilypond") << '\n';
73   cout << _ ("Typeset music and or play MIDI from FILE or <stdin>");
74   cout << '\n';
75   cout << '\n';
76   cout << _ ("Options:");
77   cout << '\n';
78   cout  << _ (
79     "  -a, --about            about LilyPond\n"
80     );
81   cout  << _ (
82     "  -D, --debug            enable debugging output\n"
83     );
84   cout  << _ (
85     "  -d, --dependencies     write Makefile dependencies for every input file\n"
86     );
87   cout  << _ (
88     "  -I, --include=DIR      add DIR to search path\n"
89     );
90   cout  << _ (
91     "  -i, --init=FILE        use FILE as init file\n"
92     );
93   cout  << _ (
94     "  -h, --help             this help\n"
95     );
96   cout  << _ (
97     "  -M, --no-paper         produce midi output only\n"
98     );
99   cout  << _ (
100     "  -o, --output=FILE      set FILE as default output base\n"
101     );
102   cout  << _ (
103     "  -Q, --find-fourths     show all intervals greater than a fourth\n"
104     );
105   cout  << _ (
106     "  -t, --test             switch on experimental features\n"
107     );
108   cout  << _ (
109     "  -T, --no-timestamps    don't timestamp the output\n"
110     );
111   cout  << _ (
112     "  -V, --ignore-version   ignore mudela version\n"
113     );
114   cout  << _ (
115     "  -w, --warranty         show warranty and copyright\n"
116     );
117   cout << '\n';
118   cout << _ ("GNU LilyPond was compiled with the following settings:");
119   cout << '\n';
120   cout <<
121 #ifdef NDEBUG
122     "NDEBUG "
123 #endif
124 #ifdef NPRINT
125     "NPRINT "
126 #endif
127 #ifdef STRING_UTILS_INLINED
128     "STRING_UTILS_INLINED "
129 #endif
130         "datadir=" DIR_DATADIR
131         " "
132         "localedir=" DIR_LOCALEDIR
133
134     "\n";
135
136   ;
137 }
138
139 void
140 about ()
141 {
142   cout << '\n';
143   cout << 
144   #include "BLURB.hh"
145   cout << '\n';
146   cout << _ ("GNU LilyPond is Free software, see --warranty");
147   cout << '\n';
148   cout << '\n';
149   cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
150   cout << '\n';
151   cout << "  " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
152   cout << "  " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
153   cout << '\n';
154 }
155
156 void
157 notice ()
158 {
159   cout << '\n';
160   cout << _ ("GNU LilyPond -- The GNU Project music typesetter");
161   cout << '\n';
162   cout << _f ("Copyright (c) %s by", "1996, 1997, 1998");
163   cout << '\n';
164   cout << "  " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
165   cout << "  " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
166   cout << '\n';
167   cout << _ (
168     "    This program is free software; you can redistribute it and/or\n"
169     "modify it under the terms of the GNU General Public License version 2\n"
170     "as published by the Free Software Foundation.\n"
171     "\n"
172     "    This program is distributed in the hope that it will be useful,\n"
173     "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
174     "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
175     "General Public License for more details.\n"
176     "\n"
177     "    You should have received a copy (refer to the file COPYING) of the\n"
178     "GNU General Public License along with this program; if not, write to\n"
179     "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
180     "USA.\n");
181 }
182
183 void
184 identify ()
185 {
186   *mlog << get_version_str () << endl;
187 }
188
189 void 
190 guile_init ()
191 {
192 #ifdef   HAVE_LIBGUILE
193    gh_eval_str ("(define (add-column p) (display \"adding column (in guile): \") (display p) (newline))");
194 #endif
195 }
196
197
198 void
199 setup_paths ()
200 {
201   // facilitate binary distributions
202   char const *env_lily = getenv ("LILYPONDPREFIX");
203   String prefix_directory;
204   if (env_lily)
205     prefix_directory = env_lily;
206
207 #if HAVE_GETTEXT
208   setlocale (LC_ALL, ""); /* enable locales */
209   setlocale (LC_NUMERIC, "C"); /* musn't have comma's in TeX output... */
210   String lily_locale_dir;
211   String name (PACKAGE);
212   name.to_lower ();
213   if (!prefix_directory.empty_b())
214     {
215       lily_locale_dir = prefix_directory + "/share/locale";
216       bindtextdomain (name.ch_C (), lily_locale_dir.ch_C());
217     }
218   else
219     bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
220   textdomain (name.ch_C ());
221 #endif
222
223   global_path.add ("");
224   // must override (come before) "/usr/local/share/lilypond"!
225   char const *env_sz = getenv ("LILYINCLUDE");
226   if (env_sz)
227     global_path.parse_path (env_sz);
228
229   if (!prefix_directory.empty_b())
230     {
231       global_path.add (prefix_directory + "/share/lilypond/init/");
232       global_path.add (prefix_directory + "/share/lilypond");
233     }
234
235   global_path.add (String (DIR_DATADIR) + "/ly/");
236   global_path.add (String (DIR_DATADIR) + "/afm/");  
237 }
238
239
240
241 int
242 main_prog (int argc, char **argv)
243 {
244   guile_init ();
245   identify ();
246   call_constructors ();
247   debug_init ();                // should be first
248
249   setup_paths ();
250
251   String init_str;
252   String outname_str;
253
254   Getopt_long oparser (argc, argv,theopts);
255   while (Long_option_init const * opt = oparser ())
256     {
257       switch (opt->shortname)
258         {
259         case 't':
260           experimental_features_global_b = true;
261           global_lookup_l = &ps_lookup;
262           break;
263         case 'o':
264           outname_str = oparser.optional_argument_ch_C_;
265           break;
266         case 'w':
267           notice ();
268           exit (0);
269           break;
270         case 'Q':
271           find_quarts_global_b = true;
272           break;
273         case 'I':
274           global_path.push (oparser.optional_argument_ch_C_);
275           break;
276         case 'i':
277           init_str = oparser.optional_argument_ch_C_;
278           break;
279         case 'a':
280           about ();
281           exit (0);
282         case 'h':
283           usage ();
284           exit (0);
285           break;
286         case 'V':
287           version_ignore_global_b = true;
288           break;
289         case 'd':
290           dependency_global_b = true;
291           break; 
292         case 'D':
293           set_debug (true);
294           break;
295         case 'M':
296           no_paper_global_b = true;
297           break;
298         case 'T':
299           no_timestamps_global_b = true;
300           break;
301         default:
302           assert (false);
303           break;
304         }
305     }
306
307   default_outname_base_global = "lelie";
308
309   
310
311   int p=0;
312   const char *arg ;
313   while ((arg= oparser.get_next_arg ()))
314     {
315       String f (arg);
316       String i;
317       f = distill_inname_str (f, i);
318       if (f == "-")
319         default_outname_base_global = "-";
320       else
321         {
322           String a,b,c,d;
323           split_path (f, a, b, c, d);
324           default_outname_base_global = c;
325         }
326       if (outname_str.length_i ())
327         default_outname_base_global = outname_str;
328       if (init_str.length_i ())
329         i = init_str;
330       else
331         i = "init" + i;
332       do_one_file (i, f);
333       p++;
334     }
335   if (!p)
336     {
337       String i;
338       if (init_str.length_i ())
339         i = init_str;
340       else
341         i = "init.ly";
342       default_outname_base_global = "-";
343       if (outname_str.length_i ())
344         default_outname_base_global = outname_str;
345       do_one_file (i, default_outname_base_global);
346     }
347
348   return exit_status_i_;
349 }
350
351 /*
352   urg: make input file name: 
353
354   input: file name
355
356   output: file name with added default extension. "" is stdin.
357           in reference argument: the extension. ".ly" if none
358  */
359 String
360 distill_inname_str (String name_str, String& ext_r)
361 {
362   String str = name_str;
363   if (str.length_i ())
364     {
365       if (str != "-")
366         {
367           String a,b,c;
368           split_path (str,a,b,c,ext_r);
369
370           // add extension if not present.
371           if (ext_r.empty_b ())
372             {
373               ext_r = ".fly";
374               if (global_path.find (a+b+c+ext_r).empty_b ())
375                 ext_r = ".ly";
376             }
377           str = a+b+c+ext_r;
378         }
379     }
380   else 
381     {
382       str = "-";
383       ext_r = ".ly";
384     }
385   return str;
386 }
387
388
389 #ifdef HAVE_LIBGUILE
390 int
391 main (int argc, char **argv)
392 {
393   gh_enter (argc, argv, (void(*)())main_prog);
394   return exit_status_i_;
395 }
396
397 #else
398 int main (int argc, char **argv)
399 {
400   return main_prog (argc, argv);
401 }
402
403 #endif