]> git.donarmstrong.com Git - lilypond.git/blob - lily/main.cc
release: 1.0.1
[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
186 #if HAVE_GETTEXT
187   setlocale (LC_ALL, "");
188 //  setlocale (LC_MESSAGES, "");
189   String name (PACKAGE);
190   name.to_lower ();
191   bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
192   textdomain (name.ch_C ());
193 #endif
194
195   identify ();
196   call_constructors ();
197   debug_init ();                // should be first
198
199   global_path.add ("");
200   // must override (come before) "/usr/local/share/lilypond"!
201   char const *env_sz = getenv ("LILYINCLUDE");
202   if (env_sz)
203     global_path.parse_path (env_sz);
204
205   global_path.add (String (DIR_DATADIR) + "/init/");
206
207   global_path.push (DIR_DATADIR);
208
209   Getopt_long oparser (argc, argv,theopts);
210   String init_str;
211
212   String outname_str;
213   while (Long_option_init const * opt = oparser ())
214     {
215       switch (opt->shortname)
216         {
217         case 't':
218           experimental_features_global_b = true;
219           break;
220         case 'o':
221           outname_str = oparser.optional_argument_ch_C_;
222           break;
223         case 'w':
224           notice ();
225           exit (0);
226           break;
227         case 'Q':
228           find_quarts_global_b = true;
229           break;
230         case 'I':
231           global_path.push (oparser.optional_argument_ch_C_);
232           break;
233         case 'i':
234           init_str = oparser.optional_argument_ch_C_;
235           break;
236         case 'a':
237           about ();
238           exit (0);
239         case 'h':
240           usage ();
241           exit (0);
242           break;
243         case 'V':
244           version_ignore_global_b = true;
245           break;
246         case 'd':
247           dependency_global_b = true;
248           break; 
249         case 'D':
250           set_debug (true);
251           break;
252         case 'M':
253           no_paper_global_b = true;
254           break;
255         case 'T':
256           no_timestamps_global_b = true;
257           break;
258         default:
259           assert (false);
260           break;
261         }
262     }
263
264   default_outname_base_global = "lelie";
265
266   
267
268   int p=0;
269   const char *arg ;
270   while ((arg= oparser.get_next_arg ()))
271     {
272       String f (arg);
273       String i;
274       f = distill_inname_str (f, i);
275       if (f == "-")
276         default_outname_base_global = "-";
277       else
278         {
279           String a,b,c,d;
280           split_path (f, a, b, c, d);
281           default_outname_base_global = c;
282         }
283       if (outname_str.length_i ())
284         default_outname_base_global = outname_str;
285       if (init_str.length_i ())
286         i = init_str;
287       else
288         i = "init" + i;
289       do_one_file (i, f);
290       p++;
291     }
292   if (!p)
293     {
294       String i;
295       if (init_str.length_i ())
296         i = init_str;
297       else
298         i = "init.ly";
299       default_outname_base_global = "-";
300       if (outname_str.length_i ())
301         default_outname_base_global = outname_str;
302       do_one_file (i, default_outname_base_global);
303     }
304
305   return exit_status_i_;
306 }
307
308 /*
309   urg: make input file name: 
310   input: file name
311   output: file name with added default extension. "" is stdin.
312           in reference argument: the extention. ".ly" if none
313  */
314
315 String
316 distill_inname_str (String name_str, String& ext_r)
317 {
318   String str = name_str;
319   if (str.length_i ())
320     {
321       if (str != "-")
322         {
323           String a,b,c;
324           split_path (str,a,b,c,ext_r);
325
326           // add extension if not present.
327           if (ext_r.empty_b ())
328             {
329               ext_r = ".fly";
330               if (global_path.find (a+b+c+ext_r).empty_b ())
331                 ext_r = ".ly";
332             }
333           str = a+b+c+ext_r;
334         }
335     }
336   else 
337     {
338       str = "-";
339       ext_r = ".ly";
340     }
341   return str;
342 }
343