+ Show line in .dsl when indicating an error processing it.

This commit is contained in:
Konstantin Isakov 2009-08-01 10:05:24 +00:00
parent 64867e9f1b
commit 4183d73b20
3 changed files with 25 additions and 3 deletions

View file

@ -1359,6 +1359,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
continue; continue;
} }
unsigned atLine = 0; // Indicates current line in .dsl, for debug purposes
try try
{ {
vector< string > dictFiles( 1, *i ); vector< string > dictFiles( 1, *i );
@ -1385,6 +1387,9 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
{ {
DslScanner scanner( *i ); 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" ) ) if ( scanner.getDictionaryName() == GD_NATIVE_TO_WS( L"Abbrev" ) )
continue; // For now just skip abbreviations continue; // For now just skip abbreviations
@ -1643,16 +1648,24 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
idx.rewind(); idx.rewind();
idx.write( &idxHeader, sizeof( idxHeader ) ); 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, dictionaries.push_back( new DslDictionary( dictId,
indexFile, indexFile,
dictFiles ) ); dictFiles ) );
} }
catch( std::exception & e ) catch( std::exception & e )
{ {
fprintf( stderr, "DSL dictionary reading failed: %s, error: %s\n", fprintf( stderr, "DSL dictionary reading failed: %s:%u, error: %s\n",
i->c_str(), e.what() ); i->c_str(), atLine, e.what() );
} }
} }

View file

@ -494,7 +494,7 @@ void ArticleDom::nextChar() throw( eot )
DslScanner::DslScanner( string const & fileName ) throw( Ex, Iconv::Ex ): DslScanner::DslScanner( string const & fileName ) throw( Ex, Iconv::Ex ):
encoding( Windows1252 ), iconv( encoding ), readBufferPtr( readBuffer ), encoding( Windows1252 ), iconv( encoding ), readBufferPtr( readBuffer ),
readBufferLeft( 0 ) readBufferLeft( 0 ), linesRead( 0 )
{ {
// Since .dz is backwards-compatible with .gz, we use gz- functions to // Since .dz is backwards-compatible with .gz, we use gz- functions to
// read it -- they are much nicer than the dict_data- ones. // 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() ); out = wstring( &wcharBuffer.front(), outPtr - &wcharBuffer.front() );
++linesRead;
return true; return true;
} }
else else
@ -752,6 +754,8 @@ bool DslScanner::readNextLine( wstring & out, size_t & offset ) throw( Ex,
out = wstring( &wcharBuffer.front(), outPtr - &wcharBuffer.front() ); out = wstring( &wcharBuffer.front(), outPtr - &wcharBuffer.front() );
++linesRead;
return true; return true;
} }
} }

View file

@ -107,6 +107,7 @@ class DslScanner
char * readBufferPtr; char * readBufferPtr;
size_t readBufferLeft; size_t readBufferLeft;
vector< wchar > wcharBuffer; vector< wchar > wcharBuffer;
unsigned linesRead;
public: public:
@ -144,6 +145,10 @@ public:
/// with #). /// with #).
bool readNextLine( wstring &, size_t & offset ) throw( Ex, Iconv::Ex ); 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 /// 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 /// would occupy in the file, knowing its encoding. It's possible to know
/// that because no multibyte encodings are supported in .dsls. /// that because no multibyte encodings are supported in .dsls.