]> git.donarmstrong.com Git - lilypond.git/blob - lily/main.cc
release: 0.0.42
[lilypond.git] / lily / main.cc
1 #include <iostream.h>
2 #include <assert.h>
3 #include "proto.hh"
4 #include "plist.hh"
5 #include "lgetopt.hh"
6 #include "misc.hh"
7 #include "string.hh"
8 #include "main.hh"
9 #include "path.hh"
10 #include "config.hh"
11 #include "source-file.hh"
12 #include "source.hh"
13
14 Source source;
15 Source* source_l_g = &source;
16 String infile_str_g;
17 bool only_midi = false;
18 extern void parse_file(String,String);
19
20
21 void
22 destill_inname( String &name_str_r);
23 Long_option_init theopts[] = {
24     1, "output", 'o',
25     0, "warranty", 'w',
26     0, "help", 'h',
27     0, "debug", 'd',
28     1, "init", 'i',
29     1, "include", 'I',
30     0, "midi", 'M',
31     0,0,0
32 };
33
34 void
35 help()
36 {
37     cout <<
38         "--help, -h             This help\n"
39         "--warranty, -w         show warranty & copyright\n"
40         "--output, -o           set default output\n"
41         "--debug, -d            enable debug output\n"
42         "--init, -i             set init file\n"
43         "--include, -I          add to file search path.\n"
44         "--midi, -M             midi output only\n"
45         "\n"
46         "LilyPond was compiled with the following settings:\n"
47 #ifdef NDEBUG
48         "NDEBUG "       
49 #endif
50 #ifdef NPRINT
51         "NPRINT "
52 #endif
53 #ifdef STRING_UTILS_INLINED
54         "STRING_UTILS_INLINED "
55 #endif
56         "datadir= " DIR_DATADIR "\n" 
57         ;
58     
59     
60 }
61
62 void 
63 notice()
64 {
65     cout <<
66         "\n"
67         "LilyPond, a music typesetter.\n"
68         "Copyright (C) 1996,97 by\n"
69         "  Han-Wen Nienhuys <hanwen@stack.nl>\n"
70         "  Jan Nieuwenhuizen <jan@digicash.com>\n"
71         "Contributors\n"
72         "  Mats Bengtsson <matsb@s3.kth.se>\n"
73         "\n"
74         "    This program is free software; you can redistribute it and/or\n"
75         "modify it under the terms of the GNU General Public License version 2\n"
76         "as published by the Free Software Foundation.\n"
77         "\n"
78         "    This program is distributed in the hope that it will be useful,\n"
79         "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
80         "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
81         "General Public License for more details.\n"
82         "\n"
83         "    You should have received a copy (refer to the file COPYING) of the\n"
84         "GNU General Public License along with this program; if not, write to\n"
85         "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
86         "USA.\n";
87 }
88
89 static File_path * path =0;
90 struct Main_init {
91     Main_init() {
92         path = new File_path(String(DIR_DATADIR)+"/init/");
93         path->push(DIR_DATADIR );
94         debug_init();
95     }
96     ~Main_init() {
97         delete path;
98     }
99 } main_init;
100
101 int
102 main (int argc, char **argv)
103 {    
104     Getopt_long oparser(argc, argv,theopts);
105     cout << get_version_str() << endl;
106     String init_str("symbol.ini");
107     
108     while (Long_option_init * opt = oparser()) {
109         switch ( opt->shortname){
110         case 'o':
111             set_default_output(oparser.optarg);
112             break;
113         case 'w':
114             notice();
115             exit(0);
116             break;
117         case 'I':
118             path->push(oparser.optarg);
119             break;
120         case 'i':
121             init_str = oparser.optarg;
122             break;
123         case 'h':
124             help();
125             exit(0);
126             break;
127         case 'd':
128             set_debug(true);
129             break;
130         case 'M':
131             only_midi = true;
132             break;
133         default:
134             assert(false);
135             break;
136         }
137     }
138
139     int p=0;
140     char *arg ;
141     while ( (arg= oparser.get_next_arg()) ) {
142         String f(arg);
143         destill_inname(f);
144         infile_str_g = f;
145         parse_file(init_str,f);
146         do_scores();
147         p++;
148     }
149     if (!p) {
150         parse_file(init_str, "");       
151         do_scores();
152     }
153
154     return 0;
155 }
156
157 String
158 find_file(String f)
159 {
160     return path->find(f);
161 }
162
163 /// make input file name: add default extension. "" is stdin.
164 void
165 destill_inname( String &name_str_r)
166 {
167     if ( name_str_r.length_i() )
168         {
169         if( name_str_r[ 0 ] != '-' ) 
170             {
171             String a,b,c,d;
172             split_path(name_str_r,a,b,c,d);
173
174             // add extension if not present.
175             if (d == "") 
176                 d = ".ly";
177             name_str_r = a+b+c+d;
178             }
179         } else name_str_r = "";   
180 }
181