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