]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.44
authorfred <fred>
Sun, 24 Mar 2002 19:36:10 +0000 (19:36 +0000)
committerfred <fred>
Sun, 24 Mar 2002 19:36:10 +0000 (19:36 +0000)
lib/includable-lexer.cc [new file with mode: 0644]
lib/source-file.cc
lib/template.cc [new file with mode: 0644]
lily/template3.cc

diff --git a/lib/includable-lexer.cc b/lib/includable-lexer.cc
new file mode 100644 (file)
index 0000000..f394907
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+  includable-lexer.cc -- implement Includable_lexer
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+#include "includable-lexer.hh"
+#include "source-file.hh"
+#include "source.hh"
+
+Includable_lexer::Includable_lexer()
+{
+    yy_current_buffer = 0;
+}
+
+/** set the  new input to s, remember old file.
+*/
+void
+Includable_lexer::new_input(String s, Sources  * global_sources)
+{
+    Source_file * sl = global_sources->get_file_l(s);
+    if (!sl) {
+       LexerError("can't find file");
+       return; 
+    }
+    char_count_stack_.push(0);
+    if (yy_current_buffer) 
+       state_stack_.push(yy_current_buffer);
+    cout << "[" << s<<flush;
+    include_stack_.push(sl);    
+    
+    // ugh. We'd want to create a buffer from the bytes directly.
+    yy_switch_to_buffer(yy_create_buffer( sl->istream_l(), sl->length_off() )); 
+}
+
+/** pop the inputstack.  conceptually this is a destructor, but it
+  does not destruct the Source_file it creates.  */
+bool
+Includable_lexer::close_input()
+{
+    include_stack_.pop();
+    char_count_stack_.pop();
+    cout << "]"<<flush;
+    yy_delete_buffer(yy_current_buffer );
+    if (state_stack_.empty()) {
+       yy_current_buffer = 0;
+       return false;
+    }else {
+       yy_switch_to_buffer(state_stack_.pop());
+       return true;
+    }    
+}
+
+char const*
+Includable_lexer::here_ch_C()
+{
+    if (include_stack_.empty())
+       return 0;
+    return include_stack_.top()->ch_C() + char_count_stack_.top();
+}
+
+Includable_lexer::~Includable_lexer()
+{
+    while (!include_stack_.empty()) {
+       close_input();
+    };
+}
+/** 
+  Since we don't create the buffer state from the bytes directly, we
+  don't know about the location of the lexer. Add this as a
+  YY_USER_ACTION */
+void
+Includable_lexer::add_lexed_char(int count)
+{
+    char_count_stack_.top() += count;
+}
index a39a57cbfa276973f23840a513f26301c38e7bde..28ede975d6ac6cefed262325bf1bd5aaf02b0934 100644 (file)
 #include "proto.hh"
 #include "plist.hh"
 
-//#include "lexer.hh"
 
 #include "debug.hh"
 #include "windhoos-suck-suck-suck-thank-you-cygnus.hh"
-// #include "parseconstruct.hh" // defined_ch_c_l
-extern char const* defined_ch_c_l;
-
-// ugh
-// #include "main.hh"                  // find_file
-String find_file(String);
 
 #include "source-file.hh"
 
-Source_file::Source_file( String &filename_str )
+Source_file::Source_file( String filename_str )
 {
     data_caddr_ = 0;
     fildes_i_ = 0;
@@ -41,8 +34,21 @@ Source_file::Source_file( String &filename_str )
 
     open();
     map();
-    // ugh!?, should call name_str() ! 
-    filename_str = name_str_;
+}
+
+istream*
+Source_file::istream_l()
+{
+    assert( fildes_i_ );
+    if ( !istream_p_ ) {
+       if ( size_off_ ) // can-t this be done without such a hack?
+           istream_p_ = new istrstream( ch_C(), size_off_ );
+        else {
+           istream_p_ = new istrstream( "", 0 );
+           istream_p_->set(ios::eofbit);
+       }
+    }
+    return istream_p_;
 }
 
 Source_file::~Source_file()
@@ -54,7 +60,7 @@ Source_file::~Source_file()
 }
 
 char const*
-Source_file::ch_c_l()
+Source_file::ch_C()
 {
     assert( this );
     return (char const*)data_caddr_;
@@ -70,73 +76,52 @@ Source_file::close()
 }
 
 String
-Source_file::error_str( char const* pos_ch_c_l )
+Source_file::error_str( char const* pos_ch_C )
 {
-    assert( this );
-    if ( !in_b( pos_ch_c_l ) )
-       return "";
-
-    char const* begin_ch_c_l = pos_ch_c_l;
-    char const* data_ch_c_l = ch_c_l();
-    while ( begin_ch_c_l > data_ch_c_l )
-        if ( *--begin_ch_c_l == '\n' ) {
-           begin_ch_c_l++;
+    char const* data_ch_C = ch_C();
+    char const * eof_C_ = data_ch_C + size_off_;
+    if ( !in_b( pos_ch_C ) )
+       return "(position unknown)";
+
+    
+    if ( pos_ch_C == eof_C_)
+       pos_ch_C --;
+    char const* begin_ch_C = pos_ch_C;
+    while ( begin_ch_C > data_ch_C )
+        if ( *--begin_ch_C == '\n' ) {
+           begin_ch_C++;
            break;
        }
 
-    char const* end_ch_c_l = pos_ch_c_l;
-    while ( end_ch_c_l < data_ch_c_l + size_off_ )
-        if ( *end_ch_c_l++ == '\n' ) {
-           break;
+    char const* end_ch_C = pos_ch_C;
+    while ( end_ch_C < eof_C_ )
+        if ( *end_ch_C++ == '\n' ) {
+         end_ch_C--;
+         break;
        }
-    end_ch_c_l--;
-
-#if 1
-//    String( char const* p, int length ) is missing!?
-    String line_str( (Byte const*)begin_ch_c_l, end_ch_c_l - begin_ch_c_l );
-#else
-    int length_i = end_ch_c_l - begin_ch_c_l;
-    char* ch_p = new char[ length_i + 1 ];
-    strncpy( ch_p, begin_ch_c_l, length_i );
-    ch_p[ length_i ] = 0;
-    String line_str( ch_p );
-    delete ch_p;
-#endif
+  
+       //    String( char const* p, int length ) is missing!?
+    String line_str( (Byte const*)begin_ch_C, end_ch_C - begin_ch_C );
 
     int error_col_i = 0;
-    char const* scan_ch_c_l = begin_ch_c_l;
-    while ( scan_ch_c_l < pos_ch_c_l )
-       if ( *scan_ch_c_l++ == '\t' )
+    char const* scan_ch_C = begin_ch_C;
+    while ( scan_ch_C < pos_ch_C )
+       if ( *scan_ch_C++ == '\t' )
            error_col_i = ( error_col_i / 8 + 1 ) * 8;
        else
            error_col_i++;
 
-    String str = line_str.left_str( pos_ch_c_l - begin_ch_c_l ) 
+    String str = line_str.left_str( pos_ch_C - begin_ch_C ) 
        + String( '\n' )
        + String( ' ', error_col_i ) 
-       + line_str.mid_str( pos_ch_c_l - begin_ch_c_l, INT_MAX ); // String::mid should take 0 arg..
+       + line_str.mid_str( pos_ch_C - begin_ch_C, INT_MAX ); // String::mid should take 0 arg..
     return str;
 }
 
 bool
-Source_file::in_b( char const* pos_ch_c_l )
-{
-    return ( pos_ch_c_l && ( pos_ch_c_l >= ch_c_l() ) && ( pos_ch_c_l < ch_c_l() + size_off_ ) );
-}
-
-istream*
-Source_file::istream_l()
+Source_file::in_b( char const* pos_ch_C )
 {
-    assert( fildes_i_ );
-    if ( !istream_p_ ) {
-       if ( size_off_ ) // can-t this be done without such a hack?
-           istream_p_ = new istrstream( ch_c_l(), size_off_ );
-        else {
-           istream_p_ = new istrstream( "", 0 );
-           istream_p_->set(ios::eofbit);
-       }
-    }
-    return istream_p_;
+    return ( pos_ch_C && ( pos_ch_C >= ch_C() ) && ( pos_ch_C <= ch_C() + size_off_ ) );
 }
 
 off_t
@@ -146,15 +131,15 @@ Source_file::length_off()
 }
 
 int
-Source_file::line_i( char const* pos_ch_c_l )
+Source_file::line_i( char const* pos_ch_C )
 {
-    if ( !in_b( pos_ch_c_l ) )
+    if ( !in_b( pos_ch_C ) )
        return 0;
 
     int i = 1;
-    char const* scan_ch_c_l = ch_c_l();
-    while ( scan_ch_c_l < pos_ch_c_l )
-       if ( *scan_ch_c_l++ == '\n' )
+    char const* scan_ch_C = ch_C();
+    while ( scan_ch_C < pos_ch_C )
+       if ( *scan_ch_C++ == '\n' )
                i++;
     return i;
 }
@@ -168,8 +153,7 @@ Source_file::map()
     data_caddr_ = (caddr_t)mmap( (void*)0, size_off_, PROT_READ, MAP_SHARED, fildes_i_, 0 );
 
     if ( (int)data_caddr_ == -1 )
-       // ugh: defined_ch_c_l...
-       warning( String( "can't map: " ) + name_str_ + String( ": " ) + strerror( errno ), defined_ch_c_l ); //lexer->here_ch_c_l() );
+       warning( String( "can't map: " ) + name_str_ + String( ": " ) + strerror( errno ),  0);
 }
 
 String
@@ -181,14 +165,10 @@ Source_file::name_str()
 void
 Source_file::open()
 {
-    String name_str = find_file( name_str_ );
-    if ( name_str != "" ) 
-        name_str_ = name_str;
-
     fildes_i_ = ::open( name_str_, O_RDONLY ); 
            
     if ( fildes_i_ == -1 ) {
-       warning( String( "can't open: " ) + name_str_ + String( ": " ) + strerror( errno ), defined_ch_c_l ); // lexer->here_ch_c_l() );
+       warning( String( "can't open: " ) + name_str_ + String( ": " ) + strerror( errno ), 0 ); 
         return;
     }
 
@@ -207,8 +187,8 @@ Source_file::unmap()
     }
 }
 String
-Source_file::file_line_no_str(char const *ch_c_l )
+Source_file::file_line_no_str(char const *ch_C )
 {
     return name_str() + ": "
-       + String( line_i( ch_c_l ) );
+       + String( line_i( ch_C ) );
 }
diff --git a/lib/template.cc b/lib/template.cc
new file mode 100644 (file)
index 0000000..2e3d527
--- /dev/null
@@ -0,0 +1,6 @@
+#include "source-file.hh"
+#include "plist.tcc"
+#include "pcursor.tcc"
+
+
+IPL_instantiate(Source_file);
index 7df0ef372bcb373b8ac6d42eec74285110bfad76..4881783f5c84ddd5a0fff28bf6275f0ac1b8adfe 100644 (file)
@@ -3,13 +3,10 @@
 #include "input-staff.hh"
 #include "input-music.hh"
 #include "molecule.hh"
-#include "source-file.hh"
 #include "voice-element.hh"
 #include "plist.tcc"
 #include "pcursor.tcc"
 
-IPL_instantiate(Atom);
 IPL_instantiate(Atom);
 IPL_instantiate(Input_staff);
 IPL_instantiate(Input_music);
-IPL_instantiate(Source_file);