Main Page   Compound List   File List   Compound Members   File Members  

init.c

00001 /*
00002 GOCR Copyright (C) 2000  Joerg Schulenburg Joerg.Schulenburg@physik.uni-magdeburg.de 
00003 GOCR API Copyright (C) 2001 Bruno Barberi Gnecco <brunobg@sourceforge.net>
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019 */
00020 
00021 #include "_gocr.h"
00022 #include "gocr.h"
00023 #ifdef HAVE_PAM_H 
00024 #include <pam.h>
00025 #else if HAVE_PNM_H
00026 #include <pnm.h>
00027 #endif
00028 
00029 static int loaded = 0;
00030 _gocr_Data _data;
00031 
00042 int gocr_init ( int argc, char **argv ) {
00043   const char *interr = "Internal error";
00044 
00045   _gocr_debug(2, fprintf(_data.error, 
00046       "GOCR (C) 2000 Joerg Schulenburg <Joerg.Schulenburg@physik.uni-magdeburg.de>\n"
00047       "GOCR API Copyright (C) 2001 Bruno Barberi Gnecco <brunobg@sourceforge.net>\n"
00048       "Please report bugs you find, with the log, to http://jocr.sourceforge.net\n");)
00049 
00050   _gocr_debug(3, fprintf(_data.error, "gocr_init(%d, %p)\n", argc, argv);)
00051   if ( loaded ) {
00052     _gocr_debug(1, fprintf(_data.error, "gocr already loaded\n");)
00053     return -1;
00054   }
00055   loaded = 1;
00056 
00057   /* start internal data */
00058   _data.verbose = 1;
00059   _data.block_overlap = 0;
00060   _data.no_block = 1;
00061   _data.error = stderr;
00062   _data.print = 0;
00063   _data.print_image = 1;
00064 
00065   /* call other init functions */
00066   if ( _gocr_initModule() ) {
00067     _gocr_debug(1, fprintf(_data.error, "%s: initModules()\n", interr);)
00068     return -1;
00069   }
00070 
00071   if ( _gocr_initBlock() ) {
00072     _gocr_debug(1, fprintf(_data.error, "%s: initBlock()\n", interr);)
00073     return -1;
00074   }
00075 
00076   if ( _gocr_initUnicode() ) {
00077     _gocr_debug(1, fprintf(_data.error, "%s: initBlock()\n", interr);)
00078     return -1;
00079   }
00080 
00081   /* call external library init functions */
00082 #if defined HAVE_PAM_H || defined HAVE_PNM_H
00083   pnm_init( &argc, argv );
00084 #endif
00085   
00086   return 0;
00087 }
00088 
00094 void gocr_finalize ( void ) {
00095   _gocr_debug(3, fprintf(_data.error, "gocr_Finalize\n");)
00096   if ( !loaded )
00097     return;
00098 
00099   _gocr_endUnicode();
00100   _gocr_endModule();
00101   _gocr_endBlock();
00102 }
00103 
00112 int gocr_setAttribute ( gocrAttributeType t, void *value ) {
00113   _gocr_debug(3, fprintf(_data.error, "gocr_setAttribute(%d, %p)\n", t, value);)
00114   switch ( t ) {
00115     case VERBOSE:
00116       if ( (int)value < 0 || (int)value > 3 ) {
00117         _gocr_debug(2, fprintf(_data.error, "VERBOSE out of bonds: %d\n", (int)value);)
00118         return -1;
00119       }
00120       _data.verbose = (int)value;
00121       return 0;
00122     case BLOCK_OVERLAP:
00123       if ( (int)value != 0 && (int)value != 1 ) {
00124         _gocr_debug(2, fprintf(_data.error, "BLOCK_OVERLAP out of bonds: %d\n", (int)value);)
00125         return -1;
00126       }
00127       _data.block_overlap = (int)value;
00128       return 0;
00129     case NO_BLOCK:
00130       if ( (int)value != 0 && (int)value != 1 ) {
00131         _gocr_debug(2, fprintf(_data.error, "NO_BLOCK out of bonds: %d\n", (int)value);)
00132         return -1;
00133       }
00134       _data.no_block = (int)value;
00135       return 0;
00136     case ERROR_FILE:
00137       if ( !value ) {
00138         _gocr_debug(2, fprintf(_data.error, "OUTPUT_FILE: got NULL pointer");)
00139         return -1;
00140       }
00141       _data.error = (FILE *)value;
00142       return 0;
00143     case PRINT:
00144       if ( (int)value < 0 || (int)value > 6 ) {
00145         _gocr_debug(2, fprintf(_data.error, "PRINT: value out of bounds");)
00146         return -1;
00147       }
00148       _data.print = (int)value;
00149       return 0;
00150     case PRINT_IMAGE:
00151       if ( (int)value != 0 && (int)value != 1 ) {
00152         _gocr_debug(2, fprintf(_data.error, "PRINT_IMAGE: value out of bounds");)
00153         return -1;
00154       }
00155       _data.print_image = (int)value;
00156       return 0;
00157     default:
00158       _gocr_debug(2, fprintf(_data.error, "No such attribute %d\n", t);)
00159       return -1;
00160   }
00161 }
00162 
00170 void *gocr_getAttribute ( gocrAttributeType t ) {
00171   _gocr_debug(3, fprintf(_data.error, "gocr_getAttribute(%d)\n", t);)
00172   switch ( t ) {
00173     case VERBOSE:
00174       return (void *)_data.verbose;
00175     case BLOCK_OVERLAP:
00176       return (void *)_data.block_overlap;
00177     case NO_BLOCK:
00178       return (void *)_data.no_block;
00179     case ERROR_FILE:
00180       return (void *)_data.error;
00181     case PRINT:
00182       return (void *)_data.print;
00183     case PRINT_IMAGE:
00184       return (void *)_data.print_image;
00185     default:
00186       _gocr_debug(2, fprintf(_data.error, "No such attribute %d\n", t);)
00187   }
00188   return NULL;
00189 }

Generated at Thu Mar 1 10:05:32 2001 for GOCR API by doxygen1.2.2 written by Dimitri van Heesch, © 1997-2000