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