]> git.donarmstrong.com Git - lilypond.git/blob - lily/main.cc
release: 0.0.44
[lilypond.git] / lily / main.cc
1 /*
2   main.cc -- implement main: entrypoints
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include <iostream.h>
10 #include <assert.h>
11 #include "proto.hh"
12 #include "plist.hh"
13 #include "lgetopt.hh"
14 #include "misc.hh"
15 #include "string.hh"
16 #include "main.hh"
17 #include "path.hh"
18 #include "config.hh"
19 #include "source.hh"
20 #include "my-lily-parser.hh"
21
22 Sources* source_l_g = 0;
23 bool only_midi = false;
24 extern void parse_file(String,String);
25
26
27 void
28 destill_inname( String &name_str_r);
29 Long_option_init theopts[] = {
30     1, "output", 'o',
31     0, "warranty", 'w',
32     0, "help", 'h',
33     0, "debug", 'd',
34     1, "init", 'i',
35     1, "include", 'I',
36     0, "midi", 'M',
37     0,0,0
38 };
39
40 void
41 help()
42 {
43     cout <<
44         "--help, -h             This help\n"
45         "--warranty, -w         show warranty & copyright\n"
46         "--output, -o           set default output\n"
47         "--debug, -d            enable debug output\n"
48         "--init, -i             set init file\n"
49         "--include, -I          add to file search path.\n"
50         "--midi, -M             midi output only\n"
51         "\n"
52         "LilyPond was compiled with the following settings:\n"
53 #ifdef NDEBUG
54         "NDEBUG "       
55 #endif
56 #ifdef NPRINT
57         "NPRINT "
58 #endif
59 #ifdef STRING_UTILS_INLINED
60         "STRING_UTILS_INLINED "
61 #endif
62         "datadir= " DIR_DATADIR "\n" 
63         ;
64     
65     
66 }
67
68 void 
69 notice()
70 {
71     cout <<
72         "\n"
73         "LilyPond, a music typesetter.\n"
74         "Copyright (C) 1996,97 by\n"
75         "  Han-Wen Nienhuys <hanwen@stack.nl>\n"
76         "  Jan Nieuwenhuizen <jan@digicash.com>\n"
77         "Contributors\n"
78         "  Mats Bengtsson <matsb@s3.kth.se>\n"
79         "\n"
80         "    This program is free software; you can redistribute it and/or\n"
81         "modify it under the terms of the GNU General Public License version 2\n"
82         "as published by the Free Software Foundation.\n"
83         "\n"
84         "    This program is distributed in the hope that it will be useful,\n"
85         "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
86         "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
87         "General Public License for more details.\n"
88         "\n"
89         "    You should have received a copy (refer to the file COPYING) of the\n"
90         "GNU General Public License along with this program; if not, write to\n"
91         "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
92         "USA.\n";
93 }
94
95 static File_path * path =0;
96 struct Main_init {
97     Main_init() {
98         path = new File_path(String(DIR_DATADIR)+"/init/");
99         path->push(DIR_DATADIR );
100         debug_init();
101     }
102     ~Main_init() {
103         delete path;
104     }
105 } main_init;
106
107 void
108 do_one_file(String init_str, String file_str)
109 {
110     source_l_g = new Sources;
111     source_l_g->set_path(path);
112     My_lily_parser parser(source_l_g);
113     parser.parse_file(init_str, file_str);
114     do_scores();
115     delete source_l_g;
116     source_l_g = 0;
117 }
118
119 int
120 main (int argc, char **argv)
121 {    
122     Getopt_long oparser(argc, argv,theopts);
123     cout << get_version_str() << endl;
124     String init_str("symbol.ini");
125     
126     while (Long_option_init * opt = oparser()) {
127         switch ( opt->shortname){
128         case 'o':
129             set_default_output(oparser.optarg);
130             break;
131         case 'w':
132             notice();
133             exit(0);
134             break;
135         case 'I':
136             path->push(oparser.optarg);
137             break;
138         case 'i':
139             init_str = oparser.optarg;
140             break;
141         case 'h':
142             help();
143             exit(0);
144             break;
145         case 'd':
146             set_debug(true);
147             break;
148         case 'M':
149             only_midi = true;
150             break;
151         default:
152             assert(false);
153             break;
154         }
155     }
156
157     int p=0;
158     char *arg ;
159     while ( (arg= oparser.get_next_arg()) ) {
160         String f(arg);
161         destill_inname(f);
162         do_one_file(init_str,f);
163         p++;
164     }
165     if (!p) {
166         do_one_file(init_str, "");      
167     }
168
169     return 0;
170 }
171 String
172 find_file(String f)
173 {
174     return path->find(f);
175 }
176
177 /// make input file name: add default extension. "" is stdin.
178 void
179 destill_inname( String &name_str_r)
180 {
181     if ( name_str_r.length_i() )
182         {
183         if( name_str_r[ 0 ] != '-' ) 
184             {
185             String a,b,c,d;
186             split_path(name_str_r,a,b,c,d);
187
188             // add extension if not present.
189             if (d == "") 
190                 d = ".ly";
191             name_str_r = a+b+c+d;
192             }
193         } else name_str_r = "";   
194 }
195