Tesseract  3.02
tesseract-ocr/ccutil/mainblk.cpp
Go to the documentation of this file.
00001 /**********************************************************************
00002  * File:        mainblk.c  (Formerly main.c)
00003  * Description: Function to call from main() to setup.
00004  * Author:                                      Ray Smith
00005  * Created:                                     Tue Oct 22 11:09:40 BST 1991
00006  *
00007  * (C) Copyright 1991, Hewlett-Packard Ltd.
00008  ** Licensed under the Apache License, Version 2.0 (the "License");
00009  ** you may not use this file except in compliance with the License.
00010  ** You may obtain a copy of the License at
00011  ** http://www.apache.org/licenses/LICENSE-2.0
00012  ** Unless required by applicable law or agreed to in writing, software
00013  ** distributed under the License is distributed on an "AS IS" BASIS,
00014  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  ** See the License for the specific language governing permissions and
00016  ** limitations under the License.
00017  *
00018  **********************************************************************/
00019 
00020 #include "mfcpch.h"
00021 #include          "fileerr.h"
00022 #ifdef __UNIX__
00023 #include          <unistd.h>
00024 #include          <signal.h>
00025 #else
00026 #include          <io.h>
00027 #endif
00028 #include          <stdlib.h>
00029 #include          "basedir.h"
00030 #include          "ccutil.h"
00031 
00032 #define VARDIR        "configs/" /*variables files */
00033 #define EXTERN
00034 
00035 const ERRCODE NO_PATH =
00036 "Warning:explicit path for executable will not be used for configs";
00037 static const ERRCODE USAGE = "Usage";
00038 
00039 namespace tesseract {
00040 /**********************************************************************
00041  * main_setup
00042  *
00043  * Main for mithras demo program. Read the arguments and set up globals.
00044  **********************************************************************/
00045 
00046 void CCUtil::main_setup(                 /*main demo program */
00047                 const char *argv0,       //program name
00048                 const char *basename     //name of image
00049                ) {
00050   imagebasename = basename;      /*name of image */
00051   STRING dll_module_name;
00052   #ifdef _WIN32
00053   dll_module_name = tessedit_module_name;
00054   #endif
00055 
00056   // TESSDATA_PREFIX Environment variable overrules everything.
00057   // Compiled in -DTESSDATA_PREFIX is next.
00058   // NULL goes to current directory.
00059   // An actual value of argv0 is used if getpath is successful.
00060   if (!getenv("TESSDATA_PREFIX")) {
00061 #ifdef TESSDATA_PREFIX
00062 #define _STR(a) #a
00063 #define _XSTR(a) _STR(a)
00064     datadir = _XSTR(TESSDATA_PREFIX);
00065 #undef _XSTR
00066 #undef _STR
00067 #else
00068     if (argv0 != NULL) {
00069       if (getpath(argv0, dll_module_name, datadir) < 0)
00070 #ifdef __UNIX__
00071         CANTOPENFILE.error("main", ABORT, "%s to get path", argv0);
00072 #else
00073         NO_PATH.error("main", DBG, NULL);
00074 #endif
00075     } else {
00076       datadir = "./";
00077     }
00078 #endif
00079   } else {
00080     datadir = getenv("TESSDATA_PREFIX");
00081   }
00082 
00083   datadir += m_data_sub_dir;     /*data directory */
00084 }
00085 }  // namespace tesseract