]> git.donarmstrong.com Git - lilypond.git/blob - src/main.cc
release: 0.0.34
[lilypond.git] / src / 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 "sourcefile.hh"
12 #include "source.hh"
13
14 Source source;
15 Source* source_l_g = &source;
16 bool only_midi = false;
17 extern void parse_file(String,String);
18
19
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, "midi", 'M',
30     0,0,0
31 };
32
33 void
34 help()
35 {
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"
44         ;
45     
46 }
47
48 void 
49 notice()
50 {
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";
73 }
74
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();
81     }
82     ~Main_init() {
83         delete path;
84     }
85 } main_init;
86
87 int
88 main (int argc, char **argv)
89 {    
90     Getopt_long oparser(argc, argv,theopts);
91     cout << get_version();
92     String init_str("symbol.ini");
93     
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;
122         }
123     }
124
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++;
133     }
134     if (!p) {
135         parse_file(init_str, "");       
136         do_scores();
137     }
138
139     return 0;
140 }
141
142 String
143 find_file(String f)
144 {
145     return path->find(f);
146 }
147
148 /// make input file name: add default extension. "" is stdin.
149 void
150 destill_inname( String &inName)
151 {
152     if ( inName.len() )
153         {
154         if( inName[ 0 ] != '-' ) 
155             {
156             String a,b,c,d;
157             split_path(inName,a,b,c,d);
158
159             // add extension if not present.
160             if (d == "") 
161                 d = ".ly";
162             inName = a+b+c+d;
163             }
164         } else inName = "";   
165 }
166