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