lilypond-0.0.38
[lilypond.git] / src / main.cc
blob058db492d9112bdb5e8ad357f9d020432593eba6
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 bool only_midi = false;
17 extern void parse_file(String,String);
20 void
21 destill_inname( String &name_str_r);
22 Long_option_init theopts[] = {
23 1, "output", 'o',
24 0, "warranty", 'w',
25 0, "help", 'h',
26 0, "debug", 'd',
27 1, "init", 'i',
28 1, "include", 'I',
29 0, "midi", 'M',
30 0,0,0
33 void
34 help()
36 cout <<
37 "--help, -h This help\n"
38 "--warranty, -w show warranty & copyright\n"
39 "--output, -o set default output\n"
40 "--debug, -d enable debug output\n"
41 "--init, -i set init file\n"
42 "--include, -I add to file search path.\n"
43 "--midi, -M midi output only\n"
48 void
49 notice()
51 cout <<
52 "\n"
53 "LilyPond, a music typesetter.\n"
54 "Copyright (C) 1996,97 by\n"
55 " Han-Wen Nienhuys <hanwen@stack.nl>\n"
56 "Contributors\n"
57 " Jan Nieuwenhuizen <jan@digicash.com>\n"
58 " Mats Bengtsson <matsb@s3.kth.se>\n"
59 "\n"
60 " This program is free software; you can redistribute it and/or\n"
61 "modify it under the terms of the GNU General Public License version 2\n"
62 "as published by the Free Software Foundation.\n"
63 "\n"
64 " This program is distributed in the hope that it will be useful,\n"
65 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
66 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
67 "General Public License for more details.\n"
68 "\n"
69 " You should have received a copy (refer to the file COPYING) of the\n"
70 "GNU General Public License along with this program; if not, write to\n"
71 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
72 "USA.\n";
75 static File_path * path =0;
76 struct Main_init {
77 Main_init() {
78 path = new File_path(LIBDIR);
79 path->push(String(LIBDIR)+"init/");
80 debug_init();
82 ~Main_init() {
83 delete path;
85 } main_init;
87 int
88 main (int argc, char **argv)
90 Getopt_long oparser(argc, argv,theopts);
91 cout << get_version();
92 String init_str("symbol.ini");
94 while (Long_option_init * opt = oparser()) {
95 switch ( opt->shortname){
96 case 'o':
97 set_default_output(oparser.optarg);
98 break;
99 case 'w':
100 notice();
101 exit(0);
102 break;
103 case 'I':
104 path->push(oparser.optarg);
105 break;
106 case 'i':
107 init_str = oparser.optarg;
108 break;
109 case 'h':
110 help();
111 exit(0);
112 break;
113 case 'd':
114 set_debug(true);
115 break;
116 case 'M':
117 only_midi = true;
118 break;
119 default:
120 assert(false);
121 break;
125 int p=0;
126 char *arg ;
127 while ( (arg= oparser.get_next_arg()) ) {
128 String f(arg);
129 destill_inname(f);
130 parse_file(init_str,f);
131 do_scores();
132 p++;
134 if (!p) {
135 parse_file(init_str, "");
136 do_scores();
139 return 0;
142 String
143 find_file(String f)
145 return path->find(f);
148 /// make input file name: add default extension. "" is stdin.
149 void
150 destill_inname( String &name_str_r)
152 if ( name_str_r.length_i() )
154 if( name_str_r[ 0 ] != '-' )
156 String a,b,c,d;
157 split_path(name_str_r,a,b,c,d);
159 // add extension if not present.
160 if (d == "")
161 d = ".ly";
162 name_str_r = a+b+c+d;
164 } else name_str_r = "";