tesseract
3.03
|
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 "fileerr.h" 00021 #ifdef __UNIX__ 00022 #include <unistd.h> 00023 #include <signal.h> 00024 #else 00025 #include <io.h> 00026 #endif 00027 #include <stdlib.h> 00028 #include "ccutil.h" 00029 00030 #define VARDIR "configs/" 00031 #define EXTERN 00032 00033 const ERRCODE NO_PATH = 00034 "Warning:explicit path for executable will not be used for configs"; 00035 static const ERRCODE USAGE = "Usage"; 00036 00037 namespace tesseract { 00038 /********************************************************************** 00039 * main_setup 00040 * 00041 * Main for mithras demo program. Read the arguments and set up globals. 00042 **********************************************************************/ 00043 00053 void CCUtil::main_setup(const char *argv0, const char *basename) { 00054 imagebasename = basename; 00056 if (argv0 != NULL) { 00057 datadir = argv0; 00058 } else { 00059 if (getenv("TESSDATA_PREFIX")) { 00060 datadir = getenv("TESSDATA_PREFIX"); 00061 } else { 00062 #ifdef TESSDATA_PREFIX 00063 #define _STR(a) #a 00064 #define _XSTR(a) _STR(a) 00065 datadir = _XSTR(TESSDATA_PREFIX); 00066 #undef _XSTR 00067 #undef _STR 00068 #endif 00069 } 00070 } 00071 00072 // datadir may still be empty: 00073 if (datadir.length() == 0) { 00074 datadir = "./"; 00075 } else { 00076 // Remove tessdata from the end if present, as we will add it back! 00077 int length = datadir.length(); 00078 if (length >= 8 && strcmp(&datadir[length - 8], "tessdata") == 0) 00079 datadir.truncate_at(length - 8); 00080 else if (length >= 9 && strcmp(&datadir[length - 9], "tessdata/") == 0) 00081 datadir.truncate_at(length - 9); 00082 } 00083 00084 // check for missing directory separator 00085 const char *lastchar = datadir.string(); 00086 lastchar += datadir.length() - 1; 00087 if ((strcmp(lastchar, "/") != 0) && (strcmp(lastchar, "\\") != 0)) 00088 datadir += "/"; 00089 00090 datadir += m_data_sub_dir; 00091 } 00092 } // namespace tesseract