]> git.donarmstrong.com Git - lilypond.git/blob - lily/main.cc
release: 1.0.16
[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 int
198 main_prog (int argc, char **argv)
199 {
200   guile_init ();
201   
202   // facilitate binary distributions
203   char const *env_lily = getenv ("LILYPONDPREFIX");
204   String prefix_directory;
205   if (env_lily)
206     prefix_directory = env_lily;
207
208 #if HAVE_GETTEXT
209   setlocale (LC_ALL, ""); /* enable locales */
210   setlocale (LC_NUMERIC, "C"); /* musn't have comma's in TeX output... */
211   String lily_locale_dir;
212   String name (PACKAGE);
213   name.to_lower ();
214   if (!prefix_directory.empty_b())
215     {
216       lily_locale_dir = prefix_directory + "/share/locale";
217       bindtextdomain (name.ch_C (), lily_locale_dir.ch_C());
218     }
219   else
220     bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
221   textdomain (name.ch_C ());
222 #endif
223
224   identify ();
225   call_constructors ();
226   debug_init ();                // should be first
227
228   global_path.add ("");
229   // must override (come before) "/usr/local/share/lilypond"!
230   char const *env_sz = getenv ("LILYINCLUDE");
231   if (env_sz)
232     global_path.parse_path (env_sz);
233
234   if (!prefix_directory.empty_b())
235     {
236       global_path.add (prefix_directory + "/share/lilypond/init/");
237       global_path.add (prefix_directory + "/share/lilypond");
238     }
239
240   global_path.add (String (DIR_DATADIR) + "/ly/");
241   global_path.add (String (DIR_DATADIR) + "/afm/");  
242
243   Getopt_long oparser (argc, argv,theopts);
244   String init_str;
245
246   String outname_str;
247   while (Long_option_init const * opt = oparser ())
248     {
249       switch (opt->shortname)
250         {
251         case 't':
252           experimental_features_global_b = true;
253           global_lookup_l = &ps_lookup;
254           break;
255         case 'o':
256           outname_str = oparser.optional_argument_ch_C_;
257           break;
258         case 'w':
259           notice ();
260           exit (0);
261           break;
262         case 'Q':
263           find_quarts_global_b = true;
264           break;
265         case 'I':
266           global_path.push (oparser.optional_argument_ch_C_);
267           break;
268         case 'i':
269           init_str = oparser.optional_argument_ch_C_;
270           break;
271         case 'a':
272           about ();
273           exit (0);
274         case 'h':
275           usage ();
276           exit (0);
277           break;
278         case 'V':
279           version_ignore_global_b = true;
280           break;
281         case 'd':
282           dependency_global_b = true;
283           break; 
284         case 'D':
285           set_debug (true);
286           break;
287         case 'M':
288           no_paper_global_b = true;
289           break;
290         case 'T':
291           no_timestamps_global_b = true;
292           break;
293         default:
294           assert (false);
295           break;
296         }
297     }
298
299   default_outname_base_global = "lelie";
300
301   
302
303   int p=0;
304   const char *arg ;
305   while ((arg= oparser.get_next_arg ()))
306     {
307       String f (arg);
308       String i;
309       f = distill_inname_str (f, i);
310       if (f == "-")
311         default_outname_base_global = "-";
312       else
313         {
314           String a,b,c,d;
315           split_path (f, a, b, c, d);
316           default_outname_base_global = c;
317         }
318       if (outname_str.length_i ())
319         default_outname_base_global = outname_str;
320       if (init_str.length_i ())
321         i = init_str;
322       else
323         i = "init" + i;
324       do_one_file (i, f);
325       p++;
326     }
327   if (!p)
328     {
329       String i;
330       if (init_str.length_i ())
331         i = init_str;
332       else
333         i = "init.ly";
334       default_outname_base_global = "-";
335       if (outname_str.length_i ())
336         default_outname_base_global = outname_str;
337       do_one_file (i, default_outname_base_global);
338     }
339
340   return exit_status_i_;
341 }
342
343 /*
344   urg: make input file name: 
345
346   input: file name
347
348   output: file name with added default extension. "" is stdin.
349           in reference argument: the extension. ".ly" if none
350  */
351 String
352 distill_inname_str (String name_str, String& ext_r)
353 {
354   String str = name_str;
355   if (str.length_i ())
356     {
357       if (str != "-")
358         {
359           String a,b,c;
360           split_path (str,a,b,c,ext_r);
361
362           // add extension if not present.
363           if (ext_r.empty_b ())
364             {
365               ext_r = ".fly";
366               if (global_path.find (a+b+c+ext_r).empty_b ())
367                 ext_r = ".ly";
368             }
369           str = a+b+c+ext_r;
370         }
371     }
372   else 
373     {
374       str = "-";
375       ext_r = ".ly";
376     }
377   return str;
378 }
379
380
381 #ifdef HAVE_LIBGUILE
382 int
383 main (int argc, char **argv)
384 {
385   gh_enter (argc, argv, (void(*)())main_prog);
386   return exit_status_i_;
387 }
388
389 #else
390 int main (int argc, char **argv)
391 {
392   return main_prog (argc, argv);
393 }
394
395 #endif