]> git.donarmstrong.com Git - lilypond.git/blob - mi2mu/main.cc
release: 0.0.44
[lilypond.git] / mi2mu / main.cc
1 //
2 // main.cc -- implement silly main() entry point
3 // should have Root class.
4 //
5 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
6
7 #include "mi2mu.hh"
8
9 Sources source;
10 Sources* source_l_g = &source;
11
12 Verbose level_ver = NORMAL_ver;
13
14 //ugh
15 char const* defined_ch_C = 0;
16
17 // ugh, another global
18 String
19 find_file( String str )
20 {
21     return str;
22 }
23
24 // ugh, copied from warn.cc, cannot use
25 void
26 message( String message_str, char const* context_ch_C )
27 {
28     String str = "mi2mu: ";
29     Source_file* sourcefile_l = source_l_g->sourcefile_l( context_ch_C );
30     if ( sourcefile_l ) {
31         str += sourcefile_l->file_line_no_str(context_ch_C) + String(": ");
32     }
33     str += message_str;
34     if ( sourcefile_l ) {
35         str += ":\n";
36         str += sourcefile_l->error_str( context_ch_C );
37     }
38 //    if ( busy_parsing() )
39     cerr << endl; // until we have fine output manager...
40     cerr << str << endl;
41 }
42
43 void
44 warning( String message_str, char const* context_ch_C )
45 {
46     message( "warning: " + message_str, context_ch_C );
47 }
48
49 void
50 error( String message_str, char const* context_ch_C )
51 {
52     message( message_str, context_ch_C );
53     // since when exits error again?
54     // i-d say: error: errorlevel |= 1; -> no output upon error
55     //          warning: recovery -> output (possibly wrong)
56     if ( midi_lexer_l_g )
57         midi_lexer_l_g->errorlevel_i_ |= 1;
58 }
59
60 void
61 help()
62 {
63     mtor <<
64         "--be-blonde, -b                use exact, blonde durations, e.g.: a[385]\n"
65         "--debug, -d            be really verbose\n"
66         "--help, -h             this help\n"
67         "--include=DIR, -I DIR  add DIR to search path\n"
68         "--no-silly, -n         assume no triplets and no smaller than 16\n"
69         "--output=FILE, -o FILE set FILE as default output\n"
70         "--quiet, -q            be quiet\n"
71         "--verbose, -v          be verbose\n"
72         "--warranty, -w         show warranty & copyright\n"
73         ;
74 }
75
76 void
77 identify()
78 {
79         mtor << mi2mu_version_str() << endl;
80 }
81     
82 void 
83 notice()
84 {
85     mtor <<
86         "\n"
87         "Mi2mu, translate midi to mudela.\n"
88         "Copyright (C) 1997 by\n"
89         "  Han-Wen Nienhuys <hanwen@stack.nl>\n"
90 //      "Contributors\n"
91         "  Jan Nieuwenhuizen <jan@digicash.com>\n"
92         "\n"
93         "    This program is free software; you can redistribute it and/or\n"
94         "modify it under the terms of the GNU General Public License version 2\n"
95         "as published by the Free Software Foundation.\n"
96         "\n"
97         "    This program is distributed in the hope that it will be useful,\n"
98         "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
99         "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
100         "General Public License for more details.\n"
101         "\n"
102         "    You should have received a copy (refer to the file COPYING) of the\n"
103         "GNU General Public License along with this program; if not, write to\n"
104         "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
105         "USA.\n";
106 }
107
108 int
109 main( int argc_i, char* argv_sz_a[] )
110 {
111         Long_option_init long_option_init_a[] = {
112                 0, "be-blonde", 'b',
113                 0, "debug", 'd',
114                 0, "help", 'h',
115                 0, "no-silly", 'n',
116                 1, "output", 'o',
117                 0, "quiet", 'q',
118                 0, "verbose", 'v',
119                 0, "warranty", 'w',
120                 0,0,0
121         };
122         Getopt_long getopt_long( argc_i, argv_sz_a, long_option_init_a );
123         identify();
124
125         String output_str;
126         while ( Long_option_init* long_option_init_p = getopt_long() )
127                 switch ( long_option_init_p->shortname ) {
128                         case 'b':
129                                 Duration_convert::be_blonde_b_s = true;
130                                 break;
131                         case 'd':
132                                 level_ver = DEBUG_ver;
133                                 break;
134                         case 'h':
135                                 help();
136                                 exit( 0 );
137                                 break;
138                         case 'n':
139                                 Duration_convert::no_double_dots_b_s = false;
140                                 Duration_convert::no_triplets_b_s = true;
141                                 Duration_convert::no_smaller_than_i_s = 16;
142                                 break;
143                         case 'o':
144                                 output_str = getopt_long.optarg;
145                                 break;
146                         case 'q':
147                                 level_ver = QUIET_ver;
148                                 break;
149                         case 'v':
150                                 level_ver = VERBOSE_ver;
151                                 break;
152                         case 'w':
153                                 notice();
154                                 exit( 0 );
155                                 break;
156                         default:
157                                 assert( 0 );
158                                 break;
159                 }
160
161         char* arg_sz = 0;
162         while ( ( arg_sz = getopt_long.get_next_arg() ) ) {
163                 My_midi_parser midi_parser( arg_sz, & source );
164                 midi_parser_l_g = &midi_parser;
165
166                 int error_i = midi_parser.parse();
167                 if ( error_i )
168                         return error_i;
169                 if ( !output_str.length_i() ) {
170                     String d, dir, base, ext;
171
172                     split_path(arg_sz, d, dir, base, ext);
173                     
174                     output_str = base + ext + ".ly";
175                 }
176                 error_i = midi_parser.output_mudela( output_str );
177                 if ( error_i )
178                         return error_i;
179                 midi_parser_l_g = 0;
180         }
181         return 0;
182 }