]> git.donarmstrong.com Git - lilypond.git/blob - lily/main.cc
release: 0.1.33
[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 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include <iostream.h>
10 #include <assert.h>
11 #include "proto.hh"
12 #include "plist.hh"
13 #include "lgetopt.hh"
14 #include "misc.hh"
15 #include "string.hh"
16 #include "main.hh"
17 #include "path.hh"
18 #include "config.hh"
19 #include "source.hh"
20 #include "debug.hh"
21 #include "my-lily-parser.hh"
22
23 static bool version_ignore_b = false;
24 Sources* source_l_g = 0;
25 bool only_midi = false;
26 bool experimental_features_global_b = false;
27 int exit_status_i_;
28
29 void destill_inname (String &name_str_r);
30
31 Long_option_init theopts[] = {
32   {1, "output", 'o'},
33   {0, "warranty", 'w'},
34   {0, "help", 'h'},
35   {0, "test", 't'},
36   {0, "debug", 'd'},
37   {1, "init", 'i'},
38   {1, "include", 'I'},
39   {0, "midi", 'M'},
40   {0, "ignore-version", 'V'},
41   {0,0,0}
42 };
43
44 void
45 usage()
46 {
47   cout <<
48     _("Usage: lilypond [options] [mudela-file]\n"
49     "Typeset and or produce midi output from mudela-file or stdin\n"
50     "\n"
51     "Options:\n"
52     "  -d, --debug            enable debugging output\n"
53     "  -I, --include=DIR      add DIR to search path\n"
54     "  -i, --init=FILE        use FILE as init file\n"
55     "  -h, --help             this help\n"
56     "  -w, --warranty         show warranty and copyright\n"
57     "  -o, --output=FILE      set FILE as default output\n"
58     "  -t, --test             switch on experimental features\n"
59     "  -M, --midi             produce midi output only\n"
60     "  -V, --ignore-version   ignore mudela version\n"
61     "\n"
62     "GNU LilyPond was compiled with the following settings:\n")
63 #ifdef NDEBUG
64     "NDEBUG "
65 #endif
66 #ifdef NPRINT
67     "NPRINT "
68 #endif
69 #ifdef STRING_UTILS_INLINED
70     "STRING_UTILS_INLINED "
71 #endif
72     "datadir= " DIR_DATADIR
73
74     "\n";
75
76   ;
77
78
79 }
80
81 void
82 notice()
83 {
84   cout <<
85     _("\n"
86     "GNU LilyPond -- The GNU Project music typesetter.\n"
87     "Copyright 1996,97 by\n"
88     "  Han-Wen Nienhuys <hanwen@stack.nl>\n"
89     "  Jan Nieuwenhuizen <jan@digicash.com>\n"
90     "\n"
91     "    This program is free software; you can redistribute it and/or\n"
92     "modify it under the terms of the GNU General Public License version 2\n"
93     "as published by the Free Software Foundation.\n"
94     "\n"
95     "    This program is distributed in the hope that it will be useful,\n"
96     "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
97     "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
98     "General Public License for more details.\n"
99     "\n"
100     "    You should have received a copy (refer to the file COPYING) of the\n"
101     "GNU General Public License along with this program; if not, write to\n"
102     "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
103     "USA.\n");
104 }
105
106
107 static File_path path;
108
109 void
110 do_one_file (String init_str, String file_str)
111 {
112   if (init_str.length_i () && path.find (init_str).empty_b ())
113     {
114       error (_("Can not find `") + init_str +"\'");
115       return ;
116     }
117   if (file_str.length_i () && path.find (file_str).empty_b ())
118     {
119       error (_("Can not find `") + file_str + "'");
120       return ;
121     }
122
123   Sources sources;
124   source_l_g = &sources;
125   source_l_g->set_path (&path);
126   {
127     My_lily_parser parser (source_l_g);
128     parser.set_version_check (version_ignore_b);
129     parser.parse_file (init_str, file_str);
130
131     if (parser.error_level_i_)
132       {
133         exit_status_i_  = 1;
134       }
135     else
136       do_scores();
137     clear_scores ();
138   }
139   source_l_g = 0;
140 }
141
142 int
143 main (int argc, char **argv)
144 {
145   debug_init();         // should be first
146
147
148   // must override (come before) "/usr/local/share/lilypond"!
149   char const * env_l=getenv ("LILYINCLUDE");
150   if (env_l)
151     {
152       path.add (env_l);
153     }
154   path.add ("");
155   path.add (String (DIR_DATADIR) + "/init/");
156
157   path.push (DIR_DATADIR);
158
159   Getopt_long oparser (argc, argv,theopts);
160   cout << get_version_str() << endl;
161   String init_str ("symbol.ly");
162
163   while (Long_option_init const * opt = oparser())
164     {
165       switch (opt->shortname)
166         {
167         case 't':
168           experimental_features_global_b = true;
169           break;
170         case 'o':
171           set_default_output (oparser.optional_argument_ch_C_);
172           break;
173         case 'w':
174           notice();
175           exit (0);
176           break;
177         case 'I':
178           path.push (oparser.optional_argument_ch_C_);
179           break;
180         case 'i':
181           init_str = oparser.optional_argument_ch_C_;
182           break;
183         case 'h':
184           usage();
185           exit (0);
186           break;
187         case 'V':
188           version_ignore_b = true;
189           break;
190         case 'd':
191           set_debug (true);
192           break;
193         case 'M':
194           only_midi = true;
195           break;
196         default:
197           assert (false);
198           break;
199         }
200     }
201
202   int p=0;
203   const char *arg ;
204   while ((arg= oparser.get_next_arg()))
205     {
206       String f (arg);
207       destill_inname (f);
208       do_one_file (init_str,f);
209       p++;
210     }
211   if (!p)
212     {
213       do_one_file (init_str, "");
214     }
215
216   return exit_status_i_;
217 }
218
219 /// make input file name: add default extension. "" is stdin.
220 void
221 destill_inname (String &name_str_r)
222 {
223   if (name_str_r.length_i())
224     {
225       if (name_str_r[ 0 ] != '-')
226         {
227           String a,b,c,d;
228           split_path (name_str_r,a,b,c,d);
229
230           // add extension if not present.
231           if (d.empty_b ())
232             d = ".ly";
233           name_str_r = a+b+c+d;
234         }
235     }
236   else name_str_r = "";
237 }