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