ccutil/mainblk.cpp

Go to the documentation of this file.
00001 
00020 #define BLOB_MATCHING_ON
00021 
00022 #include "mfcpch.h"
00023 #include          "fileerr.h"
00024 #ifdef __UNIX__
00025 #include          <unistd.h>
00026 #include          <signal.h>
00027 #else
00028 #include          <io.h>
00029 #endif
00030 #include          <stdlib.h>
00031 #include          "basedir.h"
00032 #include          "mainblk.h"
00033 
00034 #define VARDIR        "configs/" /*variables files */
00035 #define EXTERN
00036 
00037 EXTERN DLLSYM STRING datadir;    //dir for data files
00038                                  //name of image
00039 EXTERN DLLSYM STRING imagebasename;
00040 
00043 EXTERN BOOL_VAR (m_print_variables, FALSE,
00044 "Print initial values of all variables");
00045 EXTERN STRING_VAR (m_data_sub_dir, "tessdata/", "Directory for data files");
00046 EXTERN INT_VAR (memgrab_size, 13000000, "Preallocation size for batch use");
00049 const ERRCODE NO_PATH =
00050 "Warning:explicit path for executable will not be used for configs";
00051 static const ERRCODE USAGE = "Usage";
00052 
00053 /* ================== */
00059 void main_setup(                         /*main demo program */
00060                 const char *argv0,       //program name
00061                 const char *basename,    //name of image
00062                 int argc,                /*argument count */
00063                 const char *const *argv  /*arguments */
00064                ) {
00065   INT32 arg;                     /*argument */
00066   INT32 offset;                  //for flag
00067   FILE *fp;                      /*variables file */
00068   char flag[2];                  //+/-
00069   STRING varfile;                /*name of file */
00070 
00071   imagebasename = basename;      /*name of image */
00072   if (getpath (argv0, datadir) < 0)
00073   #ifdef __UNIX__
00074     CANTOPENFILE.error ("main", ABORT, "%s to get path", argv[0]);
00075   #else
00076   NO_PATH.error ("main", DBG, NULL);
00077   #endif
00078 
00079   for (arg = 0; arg < argc; arg++) {
00080     if (argv[arg][0] == '+' || argv[arg][0] == '-') {
00081       offset = 1;
00082       flag[0] = argv[arg][0];
00083     }
00084     else {
00085       offset = 0;
00086     }
00087     flag[offset] = '\0';
00088     varfile = flag;
00089                                  /*attempt open */
00090     fp = fopen (argv[arg] + offset, "r");
00091     if (fp != NULL) {
00092       fclose(fp);  /*was only to test */
00093     }
00094     else {
00095       varfile += datadir;
00096       varfile += m_data_sub_dir; /*data directory */
00097       varfile += VARDIR;         /*variables dir */
00098     }
00099                                  /*actual name */
00100     varfile += argv[arg] + offset;
00101     read_variables_file (varfile.string ());
00102   }
00103 
00104   if (m_print_variables)
00105     print_variables(stdout);  /*print them all */
00106 
00107 /*
00108 Allows the required data files to be at a fixed location
00109 not relative to the directory where the binary was executed
00110 From a patch posted on the tesseract-ocr forums on sf.net
00111 
00112 Run configure with --with-prefix /usr/local/tesseract-1.03/
00113 Or uncomment and modify the following #define */
00114 
00115 // #define TESSDATA_PREFIX /usr/local/tesseract-1.03f3/
00116 
00117 #ifdef TESSDATA_PREFIX
00118 # define _STR(a) #a
00119 # define _XSTR(a) _STR(a)
00120   datadir = _XSTR(TESSDATA_PREFIX);
00121 # undef _XSTR
00122 # undef _STR
00123 #endif
00124 
00125   datadir += m_data_sub_dir;     /*data directory */
00126 
00127   #ifdef __UNIX__
00128   if (memgrab_size > 0) {
00129     void *membuf;                //test virtual mem
00130                                  //test memory
00131     membuf = malloc (memgrab_size);
00132     if (membuf == NULL) {
00133       raise(SIGTTOU);  //hangup for jobber
00134       sleep (10);
00135     }
00136     else
00137       free(membuf); 
00138   }
00139   #endif
00140 }

Generated on Wed Feb 28 19:49:09 2007 for Tesseract by  doxygen 1.5.1