]> git.donarmstrong.com Git - lilypond.git/blob - lily/main.cc
release: 0.1.8
[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         error ( "Can not find `" + init_str +"\'");
111         return ;
112     }
113     if ( file_str!= "" && path.find (file_str) == "" ) {
114         error ( "Can not find `" + file_str + "'");
115         return ;
116     }
117     
118     Sources sources;
119     source_l_g = &sources; 
120     source_l_g->set_path (&path);
121     {
122         My_lily_parser parser (source_l_g);
123         parser.set_version_check (version_ignore_b_);
124         parser.parse_file (init_str, file_str);
125     }
126     do_scores();
127     source_l_g = 0;
128 }
129
130 int
131 main (int argc, char **argv)
132 {    
133     debug_init();               // should be first
134
135
136     // must override (come before) "/usr/local/share/lilypond"!
137     char const * env_l=getenv ("LILYINCLUDE");
138     if (env_l) {
139         path.add (env_l);
140     }
141     path.add ("");
142     path.add (String (DIR_DATADIR) + "/init/" );
143     
144     path.push (DIR_DATADIR);
145
146     Getopt_long oparser (argc, argv,theopts);
147     cout << get_version_str() << endl;
148     String init_str ("symbol.ly");
149     
150     while (Long_option_init const * opt = oparser()) {
151         switch ( opt->shortname){
152         case 'o':
153             set_default_output (oparser.optional_argument_ch_C_);
154             break;
155         case 'w':
156             notice();
157             exit (0);
158             break;
159         case 'I':
160             path.push (oparser.optional_argument_ch_C_);
161             break;
162         case 'i':
163             init_str = oparser.optional_argument_ch_C_;
164             break;
165         case 'h':
166             usage();
167             exit (0);
168             break;
169         case 'V':
170             version_ignore_b_ = true;
171             break;
172         case 'd':
173             set_debug (true);
174             break;
175         case 'M':
176             only_midi = true;
177             break;
178         default:
179             assert (false);
180             break;
181         }
182     }
183
184     int p=0;
185     const char *arg ;
186     while ( (arg= oparser.get_next_arg())) {
187         String f (arg);
188         destill_inname (f);
189         do_one_file (init_str,f);
190         p++;
191     }
192     if (!p) {
193         do_one_file (init_str, "");     
194     }
195
196     return exit_status_i_;
197 }
198
199 /// make input file name: add default extension. "" is stdin.
200 void
201 destill_inname (String &name_str_r)
202 {
203     if ( name_str_r.length_i())
204         {
205         if (name_str_r[ 0 ] != '-') 
206             {
207             String a,b,c,d;
208             split_path (name_str_r,a,b,c,d);
209
210             // add extension if not present.
211             if (d == "") 
212                 d = ".ly";
213             name_str_r = a+b+c+d;
214             }
215         } else name_str_r = "";   
216 }
217