"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "user_filter.cc" between
ocrad-0.25-pre5.tar.gz and ocrad-0.25-pre6.tar.gz

About: GNU Ocrad is an OCR (Optical Character Recognition) program. Pre-release.

user_filter.cc  (ocrad-0.25-pre5):user_filter.cc  (ocrad-0.25-pre6)
skipping to change at line 172 skipping to change at line 172
} }
void User_filter::set_file_error( const char * const file_name, const int linenu m ) void User_filter::set_file_error( const char * const file_name, const int linenu m )
{ {
char buf[80]; char buf[80];
snprintf( buf, sizeof buf, "error in file '%s', line %d.", file_name, linenum ); snprintf( buf, sizeof buf, "error in file '%s', line %d.", file_name, linenum );
error_ = buf; error_ = buf;
} }
User_filter::User_filter( const char * const file_name ) User_filter::User_filter( const char * const file_name )
: table1( 256, -1 ), retval_( 0 ) : table1( 256, -1 ), retval_( 0 ), default_( d_discard )
{ {
FILE * const f = std::fopen( file_name, "r" ); FILE * const f = std::fopen( file_name, "r" );
if( !f ) if( !f )
{ {
error_ = "Can't open file '"; error_ += file_name; error_ += '\''; error_ = "Can't open file '"; error_ += file_name; error_ += '\'';
retval_ = 1; retval_ = 1;
return; return;
} }
std::string line; std::string line;
int linenum = 0; int linenum = 0;
while( retval_ == 0 ) while( retval_ == 0 )
{ {
if( my_fgets( f, line, linenum ) <= 0 ) break; if( my_fgets( f, line, linenum ) <= 0 ) break;
if( line == "leave" )
{ if( !default_ ) default_ = d_leave; else retval_ = 2; continue; }
else if( line == "mark" )
{ if( !default_ ) default_ = d_mark; else retval_ = 2; continue; }
int new_code = -1; // parse new_code first (if any) int new_code = -1; // parse new_code first (if any)
for( unsigned equ = line.size(), j = 0; j < 2; ++j ) for( unsigned equ = line.size(), j = 0; j < 2; ++j )
{ {
equ = line.rfind( '=', equ - 1 ); equ = line.rfind( '=', equ - 1 );
if( equ >= line.size() ) break; if( equ >= line.size() ) break;
unsigned i = equ + 1; unsigned i = equ + 1;
const int tmp = parse_char( line, i ); const int tmp = parse_char( line, i );
if( tmp >= 0 && i == line.size() && enable_char( tmp, tmp ) ) if( tmp >= 0 && i == line.size() && enable_char( tmp, tmp ) )
{ new_code = tmp; line.resize( equ ); break; } { new_code = tmp; line.resize( equ ); break; }
} }
skipping to change at line 247 skipping to change at line 252
int result = -1; int result = -1;
if( code >= 0 ) if( code >= 0 )
{ {
if( code < 256 ) result = table1[code]; if( code < 256 ) result = table1[code];
else else
{ {
for( unsigned i = 0; i < table2.size(); ++i ) for( unsigned i = 0; i < table2.size(); ++i )
if( code == table2[i].code ) { result = table2[i].new_code; break; } if( code == table2[i].code ) { result = table2[i].new_code; break; }
} }
} }
if( result < 0 && default_ == d_leave ) result = code;
return result; return result;
} }
 End of changes. 3 change blocks. 
1 lines changed or deleted 7 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS