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