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