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