lilypond-0.0.40
[lilypond.git] / lily / main.cc
blob1073f940bf60f2293d06901a57033b1cecad5a23
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"
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);
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
34 void
35 help()
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"
49 void
50 notice()
52 cout <<
53 "\n"
54 "LilyPond, a music typesetter.\n"
55 "Copyright (C) 1996,97 by\n"
56 " Han-Wen Nienhuys <hanwen@stack.nl>\n"
57 "Contributors\n"
58 " Jan Nieuwenhuizen <jan@digicash.com>\n"
59 " Mats Bengtsson <matsb@s3.kth.se>\n"
60 "\n"
61 " This program is free software; you can redistribute it and/or\n"
62 "modify it under the terms of the GNU General Public License version 2\n"
63 "as published by the Free Software Foundation.\n"
64 "\n"
65 " This program is distributed in the hope that it will be useful,\n"
66 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
67 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
68 "General Public License for more details.\n"
69 "\n"
70 " You should have received a copy (refer to the file COPYING) of the\n"
71 "GNU General Public License along with this program; if not, write to\n"
72 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
73 "USA.\n";
76 static File_path * path =0;
77 struct Main_init {
78 Main_init() {
79 path = new File_path(LIBDIR);
80 path->push(String(LIBDIR)+"init/");
81 debug_init();
83 ~Main_init() {
84 delete path;
86 } main_init;
88 int
89 main (int argc, char **argv)
91 Getopt_long oparser(argc, argv,theopts);
92 cout << get_version();
93 String init_str("symbol.ini");
95 while (Long_option_init * opt = oparser()) {
96 switch ( opt->shortname){
97 case 'o':
98 set_default_output(oparser.optarg);
99 break;
100 case 'w':
101 notice();
102 exit(0);
103 break;
104 case 'I':
105 path->push(oparser.optarg);
106 break;
107 case 'i':
108 init_str = oparser.optarg;
109 break;
110 case 'h':
111 help();
112 exit(0);
113 break;
114 case 'd':
115 set_debug(true);
116 break;
117 case 'M':
118 only_midi = true;
119 break;
120 default:
121 assert(false);
122 break;
126 int p=0;
127 char *arg ;
128 while ( (arg= oparser.get_next_arg()) ) {
129 String f(arg);
130 destill_inname(f);
131 infile_str_g = f;
132 parse_file(init_str,f);
133 do_scores();
134 p++;
136 if (!p) {
137 parse_file(init_str, "");
138 do_scores();
141 return 0;
144 String
145 find_file(String f)
147 return path->find(f);
150 /// make input file name: add default extension. "" is stdin.
151 void
152 destill_inname( String &name_str_r)
154 if ( name_str_r.length_i() )
156 if( name_str_r[ 0 ] != '-' )
158 String a,b,c,d;
159 split_path(name_str_r,a,b,c,d);
161 // add extension if not present.
162 if (d == "")
163 d = ".ly";
164 name_str_r = a+b+c+d;
166 } else name_str_r = "";