lilypond-0.0.32
[lilypond.git] / src / main.cc
blobe100ec2884f21156d8b6b85eff4591142fdd65de
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 "sourcefile.hh"
12 #include "source.hh"
14 Source source;
15 Source* source_global_l = &source;
17 extern void parse_file(String,String);
20 void
21 destill_inname( String &inName);
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,0,0
32 void
33 help()
35 cout <<
36 "--help, -h This help\n"
37 "--warranty, -w show warranty & copyright\n"
38 "--output, -o set default output\n"
39 "--debug, -d enable debug output\n"
40 "--init, -i set init file\n"
41 "--include, -I add to file search path.\n"
46 void notice()
48 cout <<
49 "\n"
50 "LilyPond, a music typesetter.\n"
51 "Copyright (C) 1996,97 by\n"
52 " Han-Wen Nienhuys <hanwen@stack.nl>\n"
53 "Contributors\n"
54 " Jan Nieuwenhuizen <jan@digicash.com>\n"
55 " Mats Bengtsson <matsb@s3.kth.se>\n"
56 "\n"
57 " This program is free software; you can redistribute it and/or\n"
58 "modify it under the terms of the GNU General Public License version 2\n"
59 "as published by the Free Software Foundation.\n"
60 "\n"
61 " This program is distributed in the hope that it will be useful,\n"
62 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
63 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
64 "General Public License for more details.\n"
65 "\n"
66 " You should have received a copy (refer to the file COPYING) of the\n"
67 "GNU General Public License along with this program; if not, write to\n"
68 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
69 "USA.\n";
72 static File_path * path =0;
73 struct Main_init {
74 Main_init() {
75 path = new File_path(LIBDIR);
76 path->push(String(LIBDIR)+"init/");
77 debug_init();
79 ~Main_init() {
80 delete path;
82 } main_init;
84 int
85 main (int argc, char **argv)
87 Getopt_long oparser(argc, argv,theopts);
88 cout << get_version();
89 String init_str("symbol.ini");
91 while (long_option_init * opt = oparser()) {
92 switch ( opt->shortname){
93 case 'o':
94 set_default_output(oparser.optarg);
95 break;
96 case 'w':
97 notice();
98 exit(0);
99 break;
100 case 'I':
101 path->push(oparser.optarg);
102 break;
103 case 'i':
104 init_str = oparser.optarg;
105 break;
106 case 'h':
107 help();
108 exit(0);
109 break;
110 case 'd':
111 set_debug(true);
112 break;
113 default:
114 assert(false);
115 break;
119 int p=0;
120 char *arg ;
121 while ( (arg= oparser.get_next_arg()) ) {
122 String f(arg);
123 destill_inname(f);
124 parse_file(init_str,f);
125 do_scores();
126 p++;
128 if (!p) {
129 parse_file(init_str, "");
130 do_scores();
133 return 0;
136 String
137 find_file(String f)
139 return path->find(f);
142 /// make input file name: add default extension. "" is stdin.
143 void
144 destill_inname( String &inName)
146 if ( inName.len() )
148 if( inName[ 0 ] != '-' )
150 String a,b,c,d;
151 split_path(inName,a,b,c,d);
153 // add extension if not present.
154 if (d == "")
155 d = ".ly";
156 inName = a+b+c+d;
158 } else inName = "";