1 /**********************************************************************
2 * File: mainblk.c (Formerly main.c)
3 * Description: Function to call from main() to setup.
4 * Author: Ray Smith
5 * Created: Tue Oct 22 11:09:40 BST 1991
6 *
7 * (C) Copyright 1991, Hewlett-Packard Ltd.
8 ** Licensed under the Apache License, Version 2.0 (the "License");
9 ** you may not use this file except in compliance with the License.
10 ** You may obtain a copy of the License at
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
17 *
18 **********************************************************************/
19
20 #include "mfcpch.h"
21 #include "fileerr.h"
22 #ifdef __UNIX__
23 #include <unistd.h>
24 #include <signal.h>
25 #endif
26 #include <stdlib.h>
27 #include "basedir.h"
28 #include "mainblk.h"
29 #include "ccutil.h"
30
31 #define VARDIR "configs/" /*variables files */
32 #define EXTERN
33
34 /*
35 EXTERN DLLSYM STRING datadir; //dir for data files
36 //name of image
37 EXTERN DLLSYM STRING imagebasename;
38 EXTERN BOOL_VAR (m_print_variables, FALSE,
39 "Print initial values of all variables");
40 EXTERN STRING_VAR (m_data_sub_dir, "tessdata/", "Directory for data files");
41 EXTERN INT_VAR (memgrab_size, 0, "Preallocation size for batch use");*/
42
43
44 const ERRCODE NO_PATH =
45 "Warning:explicit path for executable will not be used for configs";
46 static const ERRCODE USAGE = "Usage";
47
48 namespace tesseract {
49 /**********************************************************************
50 * main_setup
51 *
52 * Main for mithras demo program. Read the arguments and set up globals.
53 **********************************************************************/
54
main_setup(const char * argv0,const char * basename)55 void CCUtil::main_setup( /*main demo program */
56 const char *argv0, //program name
57 const char *basename //name of image
58 ) {
59 imagebasename = basename; /*name of image */
60
61 // TESSDATA_PREFIX Environment variable overrules everything.
62 // Compiled in -DTESSDATA_PREFIX is next.
63 // NULL goes to current directory.
64 // An actual value of argv0 is used if getpath is successful.
65 if(!getenv("TESSDATA_PREFIX")) {
66 #ifdef TESSDATA_PREFIX
67 #define _STR(a) #a
68 #define _XSTR(a) _STR(a)
69 datadir = _XSTR(TESSDATA_PREFIX);
70 #undef _XSTR
71 #undef _STR
72 #else
73 if (argv0 != NULL) {
74 if (getpath (argv0, datadir) < 0)
75 #ifdef __UNIX__
76 CANTOPENFILE.error("main", ABORT, "%s to get path", argv0);
77 #else
78 NO_PATH.error ("main", DBG, NULL);
79 #endif
80 } else {
81 datadir = "./";
82 }
83 #endif
84 } else {
85 datadir = getenv("TESSDATA_PREFIX");
86 }
87
88 datadir += m_data_sub_dir; /*data directory */
89 }
90 } // namespace tesseract
91