]> git.donarmstrong.com Git - lilypond.git/blob - mi2mu/my-midi-lexer.cc
release: 0.0.45
[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 ( !source_file_l_ ) {
33         cerr << "error at EOF" << sz_l << '\n';
34     } else {
35         char const* ch_C = here_ch_C();
36         if ( ch_C ) {
37             ch_C--;
38             while ( ( *ch_C == ' ' ) || ( *ch_C == '\t' ) || ( *ch_C == '\n' ) )
39                 ch_C--;
40             ch_C++;
41         }
42         errorlevel_i_ |= 1;
43         ::error( sz_l, ch_C );
44     }
45 }
46
47 char const*
48 My_midi_lexer::here_ch_C()
49 {
50     return source_file_l_->ch_C() + char_count_ ;
51 }
52
53 int
54 My_midi_lexer::varint2_i( String str )
55 {
56     int var_i = 0;
57
58     for ( int i = 0; i < str.length_i(); i++ ) {
59         Byte byte = str[ i ];
60         var_i <<= 7;
61         var_i += byte & 0x7f;
62         if ( ! ( byte & 0x80 ) )
63             return var_i;
64     }
65     cout << "\nvarint2_i:" << String_convert::bin2hex_str( str ) << endl;
66     assert( 0 ); // illegal varint
67     return 0;
68 }
69
70 int
71 My_midi_lexer::close_i()
72 {
73     return 0;
74 }
75