"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "common.cc" between
ocrad-0.24.tar.gz and ocrad-0.25.tar.gz

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

common.cc  (ocrad-0.24):common.cc  (ocrad-0.25)
/* GNU Ocrad - Optical Character Recognition program /* GNU Ocrad - Optical Character Recognition program
Copyright (C) 2003-2014 Antonio Diaz Diaz. Copyright (C) 2003-2015 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or the Free Software Foundation, either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <algorithm> #include <algorithm>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <string>
#include <vector> #include <vector>
#include "common.h" #include "common.h"
#include "user_filter.h"
namespace { namespace {
const int charsets = 3; const int charsets = 3;
const Charset::Value charset_value[charsets] = const Charset::Value charset_value[charsets] =
{ Charset::ascii, Charset::iso_8859_9, Charset::iso_8859_15 }; { Charset::ascii, Charset::iso_8859_9, Charset::iso_8859_15 };
const char * const charset_name[charsets] = const char * const charset_name[charsets] =
{ "ascii", "iso-8859-9", "iso-8859-15" }; { "ascii", "iso-8859-9", "iso-8859-15" };
skipping to change at line 49 skipping to change at line 51
Filter::Type type; Filter::Type type;
}; };
const F_entry F_table[] = const F_entry F_table[] =
{ {
{ "letters", Filter::letters }, { "letters", Filter::letters },
{ "letters_only", Filter::letters_only }, { "letters_only", Filter::letters_only },
{ "numbers", Filter::numbers }, { "numbers", Filter::numbers },
{ "numbers_only", Filter::numbers_only }, { "numbers_only", Filter::numbers_only },
{ "same_height", Filter::same_height }, { "same_height", Filter::same_height },
{ "text_block", Filter::text_block },
{ "upper_num", Filter::upper_num }, { "upper_num", Filter::upper_num },
{ "upper_num_mark", Filter::upper_num_mark },
{ "upper_num_only", Filter::upper_num_only }, { "upper_num_only", Filter::upper_num_only },
{ 0, (Filter::Type)0 } { 0, Filter::user } // not a valid name
}; };
struct T_entry struct T_entry
{ {
const char * const name; const char * const name;
Transformation::Type type; Transformation::Type type;
}; };
const T_entry T_table[] = const T_entry T_table[] =
{ {
skipping to change at line 148 skipping to change at line 152
{ {
if( arg && std::strcmp( arg, "help" ) != 0 ) if( arg && std::strcmp( arg, "help" ) != 0 )
std::fprintf( stderr,"%s: bad bitmap trasformation '%s'\n", program_name, arg ); std::fprintf( stderr,"%s: bad bitmap trasformation '%s'\n", program_name, arg );
std::fputs( "Valid transformation names:", stderr ); std::fputs( "Valid transformation names:", stderr );
for( int i = 0; T_table[i].name != 0; ++i ) for( int i = 0; T_table[i].name != 0; ++i )
std::fprintf( stderr, " %s", T_table[i].name ); std::fprintf( stderr, " %s", T_table[i].name );
std::fputs( "\nRotations are made counter-clockwise.\n", stderr ); std::fputs( "\nRotations are made counter-clockwise.\n", stderr );
} }
} }
Control::~Control()
{
for( unsigned f = filters.size(); f > 0; --f )
if( filters[f-1].user_filterp )
delete filters[f-1].user_filterp;
}
bool Control::add_filter( const char * const program_name, bool Control::add_filter( const char * const program_name,
const char * const name ) const char * const name )
{ {
for( int i = 0; F_table[i].name != 0; ++i ) for( int i = 0; F_table[i].name != 0; ++i )
if( std::strcmp( name, F_table[i].name ) == 0 ) if( std::strcmp( name, F_table[i].name ) == 0 )
{ filters.push_back( F_table[i].type ); return true; } { filters.push_back( Filter( F_table[i].type ) ); return true; }
if( verbosity >= 0 ) if( verbosity >= 0 )
{ {
if( name && std::strcmp( name, "help" ) != 0 ) if( name && std::strcmp( name, "help" ) != 0 )
std::fprintf( stderr,"%s: bad filter '%s'\n", program_name, name ); std::fprintf( stderr,"%s: bad filter '%s'\n", program_name, name );
std::fputs( "Valid filter names:", stderr ); std::fputs( "Valid filter names:", stderr );
for( int i = 0; F_table[i].name != 0; ++i ) for( int i = 0; F_table[i].name != 0; ++i )
std::fprintf( stderr, " %s", F_table[i].name ); std::fprintf( stderr, " %s", F_table[i].name );
std::fputs( "\n", stderr ); std::fputs( "\n", stderr );
} }
return false; return false;
} }
int Control::add_user_filter( const char * const program_name,
const char * const file_name )
{
const User_filter * const user_filterp = new User_filter( file_name );
const int retval = user_filterp->retval();
if( retval == 0 )
filters.push_back( Filter( user_filterp ) );
else
{
if( verbosity >= 0 )
std::fprintf( stderr,"%s: user filter: %s\n",
program_name, user_filterp->error().c_str() );
delete user_filterp;
}
return retval;
}
bool Control::set_format( const char * const name ) bool Control::set_format( const char * const name )
{ {
if( std::strcmp( name, "byte" ) == 0 ) { utf8 = false; return true; } if( std::strcmp( name, "byte" ) == 0 ) { utf8 = false; return true; }
if( std::strcmp( name, "utf8" ) == 0 ) { utf8 = true; return true; } if( std::strcmp( name, "utf8" ) == 0 ) { utf8 = true; return true; }
return false; return false;
} }
 End of changes. 9 change blocks. 
3 lines changed or deleted 31 lines changed or added

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