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