lilypond-1.4.1
[lilypond.git] / m2m / my-midi-lexer.cc
blob22ebe7537243a2a011f33ac65b4886afd539dd49
1 //
2 // my-midi-lexer.cc -- implement My_midi_lexer
3 //
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
6 #include "m2m.hh"
8 int
9 yylex()
11 return midi_lexer_l_g->yylex();
14 My_midi_lexer* midi_lexer_l_g = 0;
16 My_midi_lexer::My_midi_lexer( String filename_str )
18 midi_lexer_l_g = this;
19 input_file_p_ = new Input_file( filename_str );
20 switch_streams( input_file_p_->is );
21 errorlevel_i_ = 0;
24 My_midi_lexer::~My_midi_lexer()
26 delete input_file_p_;
27 midi_lexer_l_g = 0;
30 void
31 My_midi_lexer::error( char const* sz_l )
33 if ( !input_file_p_ ) {
34 // *mlog << "error at EOF" << sz_l << '\n';
35 cerr << "error at EOF" << sz_l << '\n';
36 } else {
37 char const* ch_c_l = here_ch_c_l();
38 if ( ch_c_l ) {
39 ch_c_l--;
40 while ( ( *ch_c_l == ' ' ) || ( *ch_c_l == '\t' ) || ( *ch_c_l == '\n' ) )
41 ch_c_l--;
42 ch_c_l++;
44 errorlevel_i_ |= 1;
45 // ::error( sz_l, ch_c_l );
46 ::error( sz_l, ch_c_l );
50 char const*
51 My_midi_lexer::here_ch_c_l()
53 return input_file_p_->sourcefile_l_->ch_c_l() + yyin->tellg();
56 int
57 My_midi_lexer::varint2_i( String str )
59 int var_i = 0;
61 for ( int i = 0; i < str.length_i(); i++ ) {
62 Byte byte = str[ i ];
63 var_i <<= 7;
64 var_i += byte & 0x7f;
65 if ( ! ( byte & 0x80 ) )
66 return var_i;
68 cout << "\nvarint2_i:" << String_convert::bin2hex_str( str ) << endl;
69 assert( 0 ); // illegal varint
70 return 0;
73 int
74 My_midi_lexer::close_i()
76 return 0;