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