diff --git a/src/dsl.cc b/src/dsl.cc index dc4ec558..9e5d220c 100644 --- a/src/dsl.cc +++ b/src/dsl.cc @@ -1359,6 +1359,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries( continue; } + unsigned atLine = 0; // Indicates current line in .dsl, for debug purposes + try { vector< string > dictFiles( 1, *i ); @@ -1385,6 +1387,9 @@ vector< sptr< Dictionary::Class > > makeDictionaries( { DslScanner scanner( *i ); + try { // Here we intercept any errors during the read to save line at + // which the incident happened. We need alive scanner for that. + if ( scanner.getDictionaryName() == GD_NATIVE_TO_WS( L"Abbrev" ) ) continue; // For now just skip abbreviations @@ -1643,16 +1648,24 @@ vector< sptr< Dictionary::Class > > makeDictionaries( idx.rewind(); idx.write( &idxHeader, sizeof( idxHeader ) ); + + } // In-place try for saving line count + catch( ... ) + { + atLine = scanner.getLinesRead(); + throw; } + } // if need to rebuild + dictionaries.push_back( new DslDictionary( dictId, indexFile, dictFiles ) ); } catch( std::exception & e ) { - fprintf( stderr, "DSL dictionary reading failed: %s, error: %s\n", - i->c_str(), e.what() ); + fprintf( stderr, "DSL dictionary reading failed: %s:%u, error: %s\n", + i->c_str(), atLine, e.what() ); } } diff --git a/src/dsl_details.cc b/src/dsl_details.cc index 9b96b432..aa234c72 100644 --- a/src/dsl_details.cc +++ b/src/dsl_details.cc @@ -494,7 +494,7 @@ void ArticleDom::nextChar() throw( eot ) DslScanner::DslScanner( string const & fileName ) throw( Ex, Iconv::Ex ): encoding( Windows1252 ), iconv( encoding ), readBufferPtr( readBuffer ), - readBufferLeft( 0 ) + readBufferLeft( 0 ), linesRead( 0 ) { // Since .dz is backwards-compatible with .gz, we use gz- functions to // read it -- they are much nicer than the dict_data- ones. @@ -705,6 +705,8 @@ bool DslScanner::readNextLine( wstring & out, size_t & offset ) throw( Ex, out = wstring( &wcharBuffer.front(), outPtr - &wcharBuffer.front() ); + ++linesRead; + return true; } else @@ -752,6 +754,8 @@ bool DslScanner::readNextLine( wstring & out, size_t & offset ) throw( Ex, out = wstring( &wcharBuffer.front(), outPtr - &wcharBuffer.front() ); + ++linesRead; + return true; } } diff --git a/src/dsl_details.hh b/src/dsl_details.hh index 63645f3b..517b4241 100644 --- a/src/dsl_details.hh +++ b/src/dsl_details.hh @@ -107,6 +107,7 @@ class DslScanner char * readBufferPtr; size_t readBufferLeft; vector< wchar > wcharBuffer; + unsigned linesRead; public: @@ -144,6 +145,10 @@ public: /// with #). bool readNextLine( wstring &, size_t & offset ) throw( Ex, Iconv::Ex ); + /// Returns the number of lines read so far from the file. + unsigned getLinesRead() const + { return linesRead; } + /// Converts the given number of characters to the number of bytes they /// would occupy in the file, knowing its encoding. It's possible to know /// that because no multibyte encodings are supported in .dsls.