]> git.donarmstrong.com Git - lilypond.git/blob - lily/main.cc
release: 0.0.52
[lilypond.git] / lily / main.cc
1 /*
2   main.cc -- implement main: entrypoints
3
4   source file of the 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         "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         "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 //    File_path path(String(DIR_DATADIR)+"/init/") ;
123     // silly File_path, now has two .:.
124     File_path path( "." );
125     
126     // must override (come before) "/usr/local/share/lilypond"!
127     char const * env_l=getenv("LILYINCLUDE");
128     if (env_l) {
129         path.add(env_l);
130     }
131     
132     path.add( String( DIR_DATADIR ) + "/init/" );
133     
134     path_l = & path;
135     path_l->push(DIR_DATADIR );
136
137     Getopt_long oparser(argc, argv,theopts);
138     cout << get_version_str() << endl;
139     String init_str("symbol.ini");
140     
141     while (Long_option_init * opt = oparser()) {
142         switch ( opt->shortname){
143         case 'o':
144             set_default_output(oparser.optarg);
145             break;
146         case 'w':
147             notice();
148             exit(0);
149             break;
150         case 'I':
151             path.push(oparser.optarg);
152             break;
153         case 'i':
154             init_str = oparser.optarg;
155             break;
156         case 'h':
157             usage();
158             exit(0);
159             break;
160         case 'V':
161             version_ignore_b_ = true;
162             break;
163         case 'd':
164             set_debug(true);
165             break;
166         case 'M':
167             only_midi = true;
168             break;
169         default:
170             assert(false);
171             break;
172         }
173     }
174
175     int p=0;
176     char *arg ;
177     while ( (arg= oparser.get_next_arg()) ) {
178         String f(arg);
179         destill_inname(f);
180         do_one_file(init_str,f);
181         p++;
182     }
183     if (!p) {
184         do_one_file(init_str, "");      
185     }
186
187     return 0;
188 }
189
190 /// make input file name: add default extension. "" is stdin.
191 void
192 destill_inname( String &name_str_r)
193 {
194     if ( name_str_r.length_i() )
195         {
196         if( name_str_r[ 0 ] != '-' ) 
197             {
198             String a,b,c,d;
199             split_path(name_str_r,a,b,c,d);
200
201             // add extension if not present.
202             if (d == "") 
203                 d = ".ly";
204             name_str_r = a+b+c+d;
205             }
206         } else name_str_r = "";   
207 }
208