From e8df8f7f4e861f1dd3f2368b43998aa44a58d98d Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 24 Mar 2002 19:36:10 +0000 Subject: [PATCH] lilypond-0.0.44 --- lib/includable-lexer.cc | 77 ++++++++++++++++++++++++ lib/source-file.cc | 128 +++++++++++++++++----------------------- lib/template.cc | 6 ++ lily/template3.cc | 3 - 4 files changed, 137 insertions(+), 77 deletions(-) create mode 100644 lib/includable-lexer.cc create mode 100644 lib/template.cc diff --git a/lib/includable-lexer.cc b/lib/includable-lexer.cc new file mode 100644 index 0000000000..f394907823 --- /dev/null +++ b/lib/includable-lexer.cc @@ -0,0 +1,77 @@ +/* + includable-lexer.cc -- implement Includable_lexer + + source file of the LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys +*/ +#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<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 << "]"<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; +} diff --git a/lib/source-file.cc b/lib/source-file.cc index a39a57cbfa..28ede975d6 100644 --- a/lib/source-file.cc +++ b/lib/source-file.cc @@ -18,20 +18,13 @@ #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 index 0000000000..2e3d527baf --- /dev/null +++ b/lib/template.cc @@ -0,0 +1,6 @@ +#include "source-file.hh" +#include "plist.tcc" +#include "pcursor.tcc" + + +IPL_instantiate(Source_file); diff --git a/lily/template3.cc b/lily/template3.cc index 7df0ef372b..4881783f5c 100644 --- a/lily/template3.cc +++ b/lily/template3.cc @@ -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); -- 2.39.5