lilypond-1.5.10
[lilypond.git] / m2m / midi-main.cc
blob488afc0a1055b89e46644c9008ce569c8b4b3ae3
1 //
2 // midi-main.cc -- implement silly main() entry point
3 // should have Root class.
4 //
5 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
7 #include "m2m.hh"
8 #include "fversion.hh"
9 #include "version.hh"
11 Source source;
12 Source* source_l_g = &source;
14 Verbose level_ver = NORMAL_ver;
16 // ugh
17 bool no_triplets_bo_g = false;
19 //ugh
20 char const* defined_ch_c_l = 0;
22 // ugh, another global
23 String
24 find_file( String str )
26 return str;
29 // ugh, copied from warn.cc, cannot use
30 void
31 message( String message_str, char const* context_ch_c_l )
33 String str = "m2m: ";
34 Source_file* sourcefile_l = source_l_g->sourcefile_l( context_ch_c_l );
35 if ( sourcefile_l ) {
36 str += sourcefile_l->file_line_no_str(context_ch_c_l) + String(": ");
38 str += message_str;
39 if ( sourcefile_l ) {
40 str += ":\n";
41 str += sourcefile_l->error_str( context_ch_c_l );
43 // if ( busy_parsing() )
44 // cerr << endl;
45 cerr << str << endl;
48 void
49 warning( String message_str, char const* context_ch_c_l )
51 message( "warning: " + message_str, context_ch_c_l );
54 void
55 error( String message_str, char const* context_ch_c_l )
57 message( message_str, context_ch_c_l );
58 // since when exits error again?
59 // i-d say: error: errorlevel |= 1; -> no output upon error
60 // warning: recovery -> output (possibly wrong)
61 if ( midi_lexer_l_g )
62 midi_lexer_l_g->errorlevel_i_ |= 1;
65 void
66 help()
68 btor <<
69 "--debug, -d be really verbose\n"
70 "--help, -h this help\n"
71 "--include=DIR, -I DIR add DIR to search path\n"
72 "--no-triplets, -n assume no triplets\n"
73 "--output=FILE, -o FILE set FILE as default output\n"
74 "--quiet, -q be quiet\n"
75 "--verbose, -v be verbose\n"
76 "--warranty, -w show warranty & copyright\n"
80 void
81 identify()
83 mtor << version_str() << endl;
86 void
87 notice()
89 mtor <<
90 "\n"
91 "M2m, translate midi to mudela.\n"
92 "Copyright (C) 1997 by\n"
93 " Han-Wen Nienhuys <hanwen@stack.nl>\n"
94 // "Contributors\n"
95 " Jan Nieuwenhuizen <jan@digicash.com>\n"
96 // " Mats Bengtsson <matsb@s3.kth.se>\n"
97 "\n"
98 " This program is free software; you can redistribute it and/or\n"
99 "modify it under the terms of the GNU General Public License version 2\n"
100 "as published by the Free Software Foundation.\n"
101 "\n"
102 " This program is distributed in the hope that it will be useful,\n"
103 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
104 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
105 "General Public License for more details.\n"
106 "\n"
107 " You should have received a copy (refer to the file COPYING) of the\n"
108 "GNU General Public License along with this program; if not, write to\n"
109 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
110 "USA.\n";
113 // should simply have Root class...
114 String
115 version_str()
117 return String ( "This is m2m " ) + VERSIONSTR
118 + "/FlowerLib " + FVERSIONSTR
119 + " of " + __DATE__ + " " + __TIME__;
123 main( int argc_i, char* argv_sz_a[] )
125 Long_option_init long_option_init_a[] = {
126 0, "debug", 'd',
127 0, "help", 'h',
128 // 1, "include", 'I',
129 0, "no-triplets", 'n',
130 1, "output", 'o',
131 0, "quiet", 'q',
132 0, "verbose", 'v',
133 0, "warranty", 'w',
134 0,0,0
136 Getopt_long getopt_long( argc_i, argv_sz_a, long_option_init_a );
137 identify();
139 String output_str;
140 while ( Long_option_init* long_option_init_p = getopt_long() )
141 switch ( long_option_init_p->shortname ) {
142 case 'd':
143 level_ver = DEBUG_ver;
144 break;
145 case 'h':
146 help();
147 exit( 0 );
148 break;
149 // case 'I':
150 // path->push( getopt_long.optarg );
151 // break;
152 case 'n':
153 no_triplets_bo_g = true;
154 break;
155 case 'o':
156 output_str = getopt_long.optarg;
157 break;
158 case 'q':
159 level_ver = QUIET_ver;
160 break;
161 case 'v':
162 level_ver = VERBOSE_ver;
163 break;
164 case 'w':
165 notice();
166 exit( 0 );
167 break;
168 default:
169 assert( 0 );
170 break;
173 char* arg_sz = 0;
174 while ( ( arg_sz = getopt_long.get_next_arg() ) ) {
175 My_midi_parser midi_parser( arg_sz );
176 int error_i = midi_parser.parse();
177 if ( error_i )
178 return error_i;
179 if ( !output_str.length_i() ) {
180 output_str = String( arg_sz ) + ".ly";
181 // i-m sure there-s already some routine for this
182 int name_i; // too bad we can-t declare local to if
183 if ( ( name_i = output_str.index_last_i( '/' ) ) != -1 )
184 output_str = output_str.mid_str( name_i + 1, INT_MAX );
186 error_i = midi_parser.output_mudela( output_str );
187 if ( error_i )
188 return error_i;
190 return 0;