+ 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;
}
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() );
}
}

View file

@ -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;
}
}

View file

@ -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.