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