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