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