2 // midi-main.cc -- implement silly main() entry point
3 // should have Root class.
5 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
12 #include "fversion.hh"
16 #include "source-file.hh"
17 #include "midi-main.hh"
19 #include "duration.hh"
20 #include "midi-event.hh"
21 #include "midi-track.hh"
22 #include "my-midi-lexer.hh"
23 #include "my-midi-parser.hh"
26 Source
* source_l_g
= &source
;
28 Verbose level_ver
= NORMAL_ver
;
31 bool no_triplets_bo_g
= false;
34 char const* defined_ch_c_l
= 0;
36 // ugh, another global
38 find_file( String str
)
43 // ugh, copied from warn.cc, cannot use
45 message( String message_str
, char const* context_ch_c_l
)
48 Source_file
* sourcefile_l
= source_l_g
->sourcefile_l( context_ch_c_l
);
50 str
+= sourcefile_l
->file_line_no_str(context_ch_c_l
) + String(": ");
55 str
+= sourcefile_l
->error_str( context_ch_c_l
);
57 // if ( busy_parsing() )
63 warning( String message_str
, char const* context_ch_c_l
)
65 message( "warning: " + message_str
, context_ch_c_l
);
69 error( String message_str
, char const* context_ch_c_l
)
71 message( message_str
, context_ch_c_l
);
72 // since when exits error again?
73 // i-d say: error: errorlevel |= 1; -> no output upon error
74 // warning: recovery -> output (possibly wrong)
76 midi_lexer_l_g
->errorlevel_i_
|= 1;
83 "--debug, -d be really verbose\n"
84 "--help, -h this help\n"
85 "--include=DIR, -I DIR add DIR to search path\n"
86 "--no-triplets, -n assume no triplets\n"
87 "--output=FILE, -o FILE set FILE as default output\n"
88 "--quiet, -q be quiet\n"
89 "--verbose, -v be verbose\n"
90 "--warranty, -w show warranty & copyright\n"
97 mtor
<< version_str() << endl
;
105 "M2m, translate midi to mudela.\n"
106 "Copyright (C) 1997 by\n"
107 " Han-Wen Nienhuys <hanwen@stack.nl>\n"
109 " Jan Nieuwenhuizen <jan@digicash.com>\n"
110 // " Mats Bengtsson <matsb@s3.kth.se>\n"
112 " This program is free software; you can redistribute it and/or\n"
113 "modify it under the terms of the GNU General Public License version 2\n"
114 "as published by the Free Software Foundation.\n"
116 " This program is distributed in the hope that it will be useful,\n"
117 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
118 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
119 "General Public License for more details.\n"
121 " You should have received a copy (refer to the file COPYING) of the\n"
122 "GNU General Public License along with this program; if not, write to\n"
123 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
127 // should simply have Root class...
131 return String ( "This is m2m " ) + VERSIONSTR
132 + "/FlowerLib " + FVERSIONSTR
133 + " of " + __DATE__
+ " " + __TIME__
;
137 main( int argc_i
, char* argv_sz_a
[] )
139 long_option_init long_option_init_a
[] = {
142 // 1, "include", 'I',
143 0, "no-triplets", 'n',
150 Getopt_long
getopt_long( argc_i
, argv_sz_a
, long_option_init_a
);
154 while ( long_option_init
* long_option_init_p
= getopt_long() )
155 switch ( long_option_init_p
->shortname
) {
157 level_ver
= DEBUG_ver
;
164 // path->push( getopt_long.optarg );
167 no_triplets_bo_g
= true;
170 output_str
= getopt_long
.optarg
;
173 level_ver
= QUIET_ver
;
176 level_ver
= VERBOSE_ver
;
188 while ( ( arg_sz
= getopt_long
.get_next_arg() ) ) {
189 My_midi_parser
midi_parser( arg_sz
);
190 int error_i
= midi_parser
.parse();
193 if ( !output_str
.length_i() ) {
194 output_str
= String( arg_sz
) + ".ly";
195 // i-m sure there-s already some routine for this
196 int name_i
; // too bad we can-t declare local to if
197 if ( ( name_i
= output_str
.index_last_i( '/' ) ) != -1 )
198 output_str
= output_str
.mid_str( name_i
+ 1, INT_MAX
);
200 error_i
= midi_parser
.output_mudela( output_str
);