Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mainblk.cpp
Go to the documentation of this file.
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 #else
26 #include <io.h>
27 #endif
28 #include <stdlib.h>
29 #include "ccutil.h"
30
31 #define VARDIR "configs/" /*variables files */
32 #define EXTERN
33
34 const ERRCODE NO_PATH =
35 "Warning:explicit path for executable will not be used for configs";
36 static const ERRCODE USAGE = "Usage";
37
38 namespace tesseract {
39 /**********************************************************************
40 * main_setup
41 *
42 * Main for mithras demo program. Read the arguments and set up globals.
43 **********************************************************************/
44
45 void CCUtil::main_setup( /*main demo program */
46 const char *argv0, //program name
47 const char *basename //name of image
48 ) {
49 imagebasename = basename; /*name of image */
50
51 // TESSDATA_PREFIX Environment variable overrules everything.
52 // Compiled in -DTESSDATA_PREFIX is next.
53 // An actual value of argv0 is used if not NULL, otherwise current directory.
54 if (!getenv("TESSDATA_PREFIX")) {
55 #ifdef TESSDATA_PREFIX
56 #define _STR(a) #a
57 #define _XSTR(a) _STR(a)
58 datadir = _XSTR(TESSDATA_PREFIX);
59 #undef _XSTR
60 #undef _STR
61 #else
62 if (argv0 != NULL) {
63 datadir = argv0;
64 // Remove tessdata from the end if present, as we will add it back!
65 int length = datadir.length();
66 if (length >= 8 && strcmp(&datadir[length - 8], "tessdata") == 0)
67 datadir.truncate_at(length - 8);
68 else if (length >= 9 && strcmp(&datadir[length - 9], "tessdata/") == 0)
69 datadir.truncate_at(length - 9);
70 if (datadir.length() == 0)
71 datadir = "./";
72 } else {
73 datadir = "./";
74 }
75 #endif
76 } else {
77 datadir = getenv("TESSDATA_PREFIX");
78 }
79
80 // check for missing directory separator
81 const char *lastchar = datadir.string();
82 lastchar += datadir.length() - 1;
83 if ((strcmp(lastchar, "/") != 0) && (strcmp(lastchar, "\\") != 0))
84 datadir += "/";
85
86 datadir += m_data_sub_dir; /*data directory */
87 }
88 } // namespace tesseract