]> git.donarmstrong.com Git - lilypond.git/blob - mi2mu/my-midi-lexer.cc
partial: 0.0.40.jcn
[lilypond.git] / mi2mu / my-midi-lexer.cc
1 //
2 // my-midi-lexer.cc -- implement My_midi_lexer
3 //
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
5
6 #include "mi2mu.hh"
7
8 int
9 yylex() 
10 {
11         return midi_lexer_l_g->yylex();
12 }
13
14 My_midi_lexer* midi_lexer_l_g = 0;
15
16 My_midi_lexer::My_midi_lexer( String filename_str )
17 {
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;
22 }
23
24 My_midi_lexer::~My_midi_lexer()
25 {
26         delete input_file_p_;
27         midi_lexer_l_g = 0;
28 }
29
30 void
31 My_midi_lexer::error( char const* sz_l )
32 {
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++;
43         }
44         errorlevel_i_ |= 1;
45 //      ::error( sz_l, ch_c_l );
46         ::error( sz_l, ch_c_l );
47     }
48 }
49
50 char const*
51 My_midi_lexer::here_ch_c_l()
52 {
53     return input_file_p_->sourcefile_l_->ch_c_l() + yyin->tellg();
54 }
55
56 int
57 My_midi_lexer::varint2_i( String str )
58 {
59         int var_i = 0;
60
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;
67         }
68         cout << "\nvarint2_i:" << String_convert::bin2hex_str( str ) << endl;
69         assert( 0 ); // illegal varint
70         return 0;
71 }
72
73 int
74 My_midi_lexer::close_i()
75 {
76         return 0;
77 }
78