lilypond-0.0.27
[lilypond.git] / src / main.cc
blob8ac50296eefed0697451d3067b30ade549430faa
1 #include <iostream.h>
2 #include <assert.h>
3 #include "lgetopt.hh"
4 #include "misc.hh"
5 #include "string.hh"
6 #include "main.hh"
7 #include "path.hh"
8 #include "config.hh"
10 extern void parse_file(String s);
13 void
14 destill_inname( String &inName);
15 long_option_init theopts[] = {
16 1, "output", 'o',
17 0, "warranty", 'w',
18 0, "help", 'h',
19 0, "debug", 'd',
20 1, "include", 'I',
21 0,0,0
24 void
25 help()
27 cout <<
28 "--help, -h This help\n"
29 "--warranty, -w show warranty & copyright\n"
30 "--output, -o set default output\n"
31 "--debug, -d enable debug output\n"
32 "--include, -I add to file search path.\n"
37 void notice()
39 cout <<
40 "\n"
41 "LilyPond, a music typesetter.\n"
42 "Copyright (C) 1996,97 by\n"
43 " Han-Wen Nienhuys <hanwen@stack.nl>\n"
44 "Contributors\n"
45 " Jan-Nieuwenhuizen <jan@digicash.com>\n"
46 " Mats Bengtsson <matsb@s3.kth.se>\n"
47 "\n"
48 " This program is free software; you can redistribute it and/or\n"
49 "modify it under the terms of the GNU General Public License version 2\n"
50 "as published by the Free Software Foundation.\n"
51 "\n"
52 " This program is distributed in the hope that it will be useful,\n"
53 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
54 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
55 "General Public License for more details.\n"
56 "\n"
57 " You should have received a copy (refer to the file COPYING) of the\n"
58 "GNU General Public License along with this program; if not, write to\n"
59 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
60 "USA.\n";
63 static File_path * path =0;
64 struct Main_init {
65 Main_init() {
66 path = new File_path(LIBDIR);
67 path->push(String(LIBDIR)+"init/");
68 debug_init();
70 ~Main_init() {
71 delete path;
73 } main_init;
75 int
76 main (int argc, char **argv)
78 Getopt_long oparser(argc, argv,theopts);
79 cout << get_version();
81 while (long_option_init * opt = oparser()) {
82 switch ( opt->shortname){
83 case 'o':
84 set_default_output(oparser.optarg);
85 break;
86 case 'w':
87 notice();
88 exit(0);
89 break;
90 case 'I':
91 path->push(oparser.optarg);
92 break;
93 case 'h':
94 help();
95 exit(0);
96 break;
97 case 'd':
98 set_debug(true);
99 break;
100 default:
101 assert(false);
102 break;
106 int p=0;
107 char *arg ;
108 while ( (arg= oparser.get_next_arg()) ) {
109 String f(arg);
110 destill_inname(f);
111 parse_file(f);
112 do_scores();
113 p++;
115 if (!p) {
116 parse_file("");
117 do_scores();
120 return 0;
123 String
124 find_file(String f)
126 return path->find(f);
129 /// make input file name: add default extension. "" is stdin.
130 void
131 destill_inname( String &inName)
133 if ( inName.len() )
135 if( inName[ 0 ] != '-' )
137 String a,b,c,d;
138 split_path(inName,a,b,c,d);
140 // add extension if not present.
141 if (d == "")
142 d = ".ly";
143 inName = a+b+c+d;
145 } else inName = "";