]> git.donarmstrong.com Git - lilypond.git/blob - mi2mu/my-midi-lexer.cc
release: 0.0.49
[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, Sources * sources )
17 {
18     source_file_l_ =sources->get_file_l(filename_str);
19     switch_streams( source_file_l_->istream_l() );
20     errorlevel_i_ = 0;
21     char_count_ = 0;
22 }
23
24 My_midi_lexer::~My_midi_lexer()
25 {
26 //    delete source_file_p_;
27 }
28
29 void
30 My_midi_lexer::error( char const* sz_l )
31 {
32     if (1|| !source_file_l_ ) {
33         cerr << "error at EOF" << sz_l << '\n';
34     } else {
35         
36         // FIXME
37         #if 0
38         char const* ch_C = here_ch_C();
39         if ( ch_C ) {
40             ch_C--;
41             while ( ( *ch_C == ' ' ) || ( *ch_C == '\t' ) || ( *ch_C == '\n' ) )
42                 ch_C--;
43             ch_C++;
44         }
45         errorlevel_i_ |= 1;
46         error( sz_l);
47         #endif
48     }
49 }
50
51 char const*
52 My_midi_lexer::here_ch_C()
53 {
54     return source_file_l_->ch_C() + char_count_ ;
55 }
56
57 int
58 My_midi_lexer::varint2_i( String str )
59 {
60     int var_i = 0;
61
62     for ( int i = 0; i < str.length_i(); i++ ) {
63         Byte byte = str[ i ];
64         var_i <<= 7;
65         var_i += byte & 0x7f;
66         if ( ! ( byte & 0x80 ) )
67             return var_i;
68     }
69     cout << "\nvarint2_i:" << String_convert::bin2hex_str( str ) << endl;
70     assert( 0 ); // illegal varint
71     return 0;
72 }
73
74 int
75 My_midi_lexer::close_i()
76 {
77     return 0;
78 }
79