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