]> git.donarmstrong.com Git - lilypond.git/blob - src/main.cc
67ccf5dfeb24f8250e5b7bfef26573a9ad030eb5
[lilypond.git] / src / main.cc
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"
9
10 extern void parse_file(String s);
11
12
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
22 };
23
24 void
25 help()
26 {
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"
33         ;
34     
35 }
36
37 void notice()
38 {
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         "  Jan-Nieuwenhuizen <jan@digicash.com>\n"
45         "\n"
46         "    This program is free software; you can redistribute it and/or\n"
47         "modify it under the terms of the GNU General Public License version 2\n"
48         "as published by the Free Software Foundation.\n"
49         "\n"
50         "    This program is distributed in the hope that it will be useful,\n"
51         "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
52         "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
53         "General Public License for more details.\n"
54         "\n"
55         "    You should have received a copy (refer to the file COPYING) of the\n"
56         "GNU General Public License along with this program; if not, write to\n"
57         "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
58         "USA.\n";
59 }
60
61 static File_path * path =0;
62 struct Main_init {
63     Main_init() {
64         path = new File_path(LIBDIR);
65         path->add(String(LIBDIR)+"init/");
66         debug_init();
67     }
68     ~Main_init() {
69         delete path;
70     }
71 } main_init;
72
73 int
74 main (int argc, char **argv)
75 {    
76     Getopt_long oparser(argc, argv,theopts);
77     cout << get_version();
78     
79     while (long_option_init * opt = oparser()) {
80         switch ( opt->shortname){
81         case 'o':
82             set_default_output(oparser.optarg);
83             break;
84         case 'w':
85             notice();
86             exit(0);
87             break;
88         case 'I':
89             path->add(oparser.optarg);
90             break;
91         case 'h':
92             help();
93             exit(0);
94             break;
95         case 'd':
96             set_debug(true);
97             break;
98         default:
99             assert(false);
100             break;
101         }
102     }
103
104     int p=0;
105     char *arg ;
106     while ( (arg= oparser.get_next_arg()) ) {
107         String f(arg);
108         destill_inname(f);
109         parse_file(f);
110         do_scores();
111         p++;
112     }
113     if (!p) {
114         parse_file(""); 
115         do_scores();
116     }
117
118     return 0;
119 }
120
121 String
122 find_file(String f)
123 {
124     return path->find(f);
125 }
126
127 /// make input file name: add default extension. "" is stdin.
128 void
129 destill_inname( String &inName)
130 {
131     if ( inName.len() )
132         {
133         if( inName[ 0 ] != '-' ) 
134             {
135             String a,b,c,d;
136             split_path(inName,a,b,c,d);
137
138             // add extension if not present.
139             if (d == "") 
140                 d = ".ly";
141             inName = a+b+c+d;
142             }
143         } else inName = "";   
144 }
145