]> git.donarmstrong.com Git - lilypond.git/blob - mi2mu/main.cc
release: 0.0.41
[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 Source source;
10 Source* source_l_g = &source;
11
12 Verbose level_ver = NORMAL_ver;
13
14 //ugh
15 char const* defined_ch_c_l = 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_l )
27 {
28     String str = "mi2mu: ";
29     Source_file* sourcefile_l = source_l_g->sourcefile_l( context_ch_c_l );
30     if ( sourcefile_l ) {
31         str += sourcefile_l->file_line_no_str(context_ch_c_l) + String(": ");
32     }
33     str += message_str;
34     if ( sourcefile_l ) {
35         str += ":\n";
36         str += sourcefile_l->error_str( context_ch_c_l );
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_l )
45 {
46     message( "warning: " + message_str, context_ch_c_l );
47 }
48
49 void
50 error( String message_str, char const* context_ch_c_l )
51 {
52     message( message_str, context_ch_c_l );
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     btor <<
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 << 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 //      "  Mats Bengtsson <matsb@s3.kth.se>\n"
93         "\n"
94         "    This program is free software; you can redistribute it and/or\n"
95         "modify it under the terms of the GNU General Public License version 2\n"
96         "as published by the Free Software Foundation.\n"
97         "\n"
98         "    This program is distributed in the hope that it will be useful,\n"
99         "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
100         "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
101         "General Public License for more details.\n"
102         "\n"
103         "    You should have received a copy (refer to the file COPYING) of the\n"
104         "GNU General Public License along with this program; if not, write to\n"
105         "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
106         "USA.\n";
107 }
108
109 int
110 main( int argc_i, char* argv_sz_a[] )
111 {
112         Long_option_init long_option_init_a[] = {
113                 0, "be-blonde", 'b',
114                 0, "debug", 'd',
115                 0, "help", 'h',
116 //              1, "include", 'I',
117                 0, "no-silly", 'n',
118                 1, "output", 'o',
119                 0, "quiet", 'q',
120                 0, "verbose", 'v',
121                 0, "warranty", 'w',
122                 0,0,0
123         };
124         Getopt_long getopt_long( argc_i, argv_sz_a, long_option_init_a );
125         identify();
126
127         String output_str;
128         while ( Long_option_init* long_option_init_p = getopt_long() )
129                 switch ( long_option_init_p->shortname ) {
130                         case 'b':
131                                 Duration_convert::be_blonde_b_s = true;
132                                 break;
133                         case 'd':
134                                 level_ver = DEBUG_ver;
135                                 break;
136                         case 'h':
137                                 help();
138                                 exit( 0 );
139                                 break;
140 //                      case 'I':
141 //                              path->push( getopt_long.optarg );
142 //                              break;
143                         case 'n':
144                                 Duration_convert::no_double_dots_b_s = false;
145                                 Duration_convert::no_triplets_b_s = true;
146                                 Duration_convert::no_smaller_than_i_s = 16;
147                                 break;
148                         case 'o':
149                                 output_str = getopt_long.optarg;
150                                 break;
151                         case 'q':
152                                 level_ver = QUIET_ver;
153                                 break;
154                         case 'v':
155                                 level_ver = VERBOSE_ver;
156                                 break;
157                         case 'w':
158                                 notice();
159                                 exit( 0 );
160                                 break;
161                         default:
162                                 assert( 0 );
163                                 break;
164                 }
165
166         char* arg_sz = 0;
167         while ( ( arg_sz = getopt_long.get_next_arg() ) ) {
168                 My_midi_parser midi_parser( arg_sz );
169                 int error_i = midi_parser.parse();
170                 if ( error_i )
171                         return error_i;
172                 if ( !output_str.length_i() ) {
173                         output_str = String( arg_sz ) + ".ly";
174                         // i-m sure there-s already some routine for this
175                         int name_i; // too bad we can-t declare local to if
176                         if ( ( name_i = output_str.index_last_i( '/' ) ) != -1 )
177                                 output_str = output_str.mid_str( name_i + 1, INT_MAX );
178                 }
179                 error_i = midi_parser.output_mudela( output_str );
180                 if ( error_i )
181                         return error_i;
182         }
183         return 0;
184 }