X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lib%2Fsource-file.cc;h=dc6c092519a66eaec827c602ebc3a3cd7d8dbf3c;hb=cec6dfa6bf0fb931eb7f42b1ee44ca2ec19a9f34;hp=4ac7017f051eb67ca1a774ba31e6fc1458b88e4b;hpb=388e4a0e9c5f5d470357709b2ec205b1a1c7351e;p=lilypond.git diff --git a/lib/source-file.cc b/lib/source-file.cc index 4ac7017f05..dc6c092519 100644 --- a/lib/source-file.cc +++ b/lib/source-file.cc @@ -1,5 +1,5 @@ /* - source-file.cc -- implement + source-file.cc -- implement Source_file source file of the GNU LilyPond music typesetter @@ -19,126 +19,134 @@ #include "source-file.hh" #include "file-storage.hh" -Source_file::Source_file( String filename_str ) +Source_file::Source_file(String filename_str) { - name_str_ = filename_str; - istream_p_ = 0; - storage_p_ = new Simple_file_storage(filename_str); + name_str_ = filename_str; + istream_p_ = 0; + storage_p_ = new Simple_file_storage(filename_str); } istream* Source_file::istream_l() { - if ( !name_str_.length_i()) - return &cin; - - if ( !istream_p_ ) - { - if ( length_i() ) // can-t this be done without such a hack? - istream_p_ = new istrstream( ch_C(), length_i() ); - else - { - istream_p_ = new istrstream( "", 0 ); - istream_p_->set(ios::eofbit); - } - } - return istream_p_; + /* + if (!name_str_.length_i()) + return &cin; + */ + + if (!istream_p_) + { + if (length_i()) // can-t this be done without such a hack? + istream_p_ = new istrstream(ch_C(), length_i()); + else + { + istream_p_ = new istrstream("", 0); + istream_p_->set(ios::eofbit); + } + } + return istream_p_; } String -Source_file::file_line_no_str(char const *ch_C )const +Source_file::file_line_no_str(char const *context_ch_C) const { + if (!ch_C()) + return "(unknown)"; + else return name_str() + ": " - + String( line_i( ch_C ) ); + + String(line_i(context_ch_C)); } String -Source_file::name_str()const +Source_file::name_str() const { - return name_str_; + return name_str_; } Source_file::~Source_file() { - delete istream_p_; - istream_p_ = 0; - delete storage_p_; + delete istream_p_; + istream_p_ = 0; + delete storage_p_; } String -Source_file::error_str( char const* pos_ch_C )const +Source_file::error_str(char const* pos_ch_C) const { - char const* data_ch_C = ch_C(); - char const * eof_C_ = data_ch_C + length_i(); - if ( !in_b( pos_ch_C ) ) - return "(position unknown)"; + char const* data_ch_C = ch_C(); + char const * eof_C_ = data_ch_C + length_i(); + 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 = pos_ch_C; - while ( end_ch_C < eof_C_ ) - if ( *end_ch_C++ == '\n' ) - { - end_ch_C--; - break; - } + 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 = pos_ch_C; + while (end_ch_C < eof_C_) + if (*end_ch_C++ == '\n') + { + end_ch_C--; + break; + } - // 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 = 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 - begin_ch_C ) - + String( '\n' ) - + String( ' ', error_col_i ) - + line_str.mid_str( pos_ch_C - begin_ch_C, INT_MAX ); // String::mid should take 0 arg.. - return str; + // 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 = 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 - begin_ch_C) + + String('\n') + + String(' ', error_col_i) + + 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 )const +Source_file::in_b(char const* pos_ch_C) const { - return ( pos_ch_C && ( pos_ch_C >= ch_C() ) && ( pos_ch_C <= ch_C() + length_i() ) ); + return (pos_ch_C && (pos_ch_C >= ch_C()) && (pos_ch_C <= ch_C() + length_i())); } int -Source_file::line_i( char const* pos_ch_C )const +Source_file::line_i(char const* pos_ch_C) const { - if ( !in_b( pos_ch_C ) ) - return 0; - - int i = 1; - char const* scan_ch_C = ch_C(); - while ( scan_ch_C < pos_ch_C ) - if ( *scan_ch_C++ == '\n' ) - i++; - return i; + if (!in_b(pos_ch_C)) + return 0; + + int i = 1; + char const* scan_ch_C = ch_C(); + if (!scan_ch_C) + return 0; + + while (scan_ch_C < pos_ch_C) + if (*scan_ch_C++ == '\n') + i++; + return i; } int -Source_file::length_i()const +Source_file::length_i() const { - return storage_p_->length_i(); + return storage_p_->length_i(); } char const * -Source_file::ch_C()const +Source_file::ch_C() const { - return storage_p_->ch_C(); + return storage_p_->ch_C(); }