lilypond-1.1.13
[lilypond.git] / src / my-midi-lexer.cc
blob4aa37d31469ad43c2d908f1e820bece172f5cf43
1 //
2 // my-midi-lexer.cc -- implement My_midi_lexer
3 //
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
6 #include "debug.hh"
7 #include "input-file.hh"
8 #include "source-file.hh"
9 #include "my-midi-lexer.hh"
11 int
12 yylex()
14 return midi_lexer_l_g->yylex();
17 My_midi_lexer* midi_lexer_l_g;
19 My_midi_lexer::My_midi_lexer( String filename_str )
21 input_file_p_ = new Input_file( filename_str );
22 switch_streams( input_file_p_->is );
23 midi_lexer_l_g = this;
24 errorlevel_i_ = 0;
27 My_midi_lexer::~My_midi_lexer()
29 delete input_file_p_;
30 midi_lexer_l_g = 0;
33 void
34 My_midi_lexer::error( char const* sz_l )
36 if ( !input_file_p_ ) {
37 // *mlog << "error at EOF" << sz_l << '\n';
38 cerr << "error at EOF" << sz_l << '\n';
39 } else {
40 char const* ch_c_l = here_ch_c_l();
41 if ( ch_c_l ) {
42 ch_c_l--;
43 while ( ( *ch_c_l == ' ' ) || ( *ch_c_l == '\t' ) || ( *ch_c_l == '\n' ) )
44 ch_c_l--;
45 ch_c_l++;
47 errorlevel_i_ |= 1;
48 // ::error( sz_l, ch_c_l );
49 ::error( sz_l, ch_c_l );
53 char const*
54 My_midi_lexer::here_ch_c_l()
56 return input_file_p_->sourcefile_l_->ch_c_l() + yyin->tellg();
59 int
60 My_midi_lexer::varint2_i( String str )
62 int var_i = 0;
64 for ( int i = 0; i < str.length_i(); i++ ) {
65 Byte byte = str[ i ];
66 var_i <<= 7;
67 var_i += byte & 0x7f;
68 if ( ! ( byte & 0x80 ) )
69 return var_i;
71 cout << "\nvarint2_i:" << String_convert::bin2hex_str( str ) << endl;
72 assert( 0 ); // illegal varint
73 return 0;
76 int
77 My_midi_lexer::close_i()
79 return 0;