All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 "fileerr.h"
21 #ifdef __UNIX__
22 #include <unistd.h>
23 #include <signal.h>
24 #else
25 #include <io.h>
26 #endif
27 #include <stdlib.h>
28 #include "ccutil.h"
29 
30 #define VARDIR "configs/"
31 #define EXTERN
32 
34 "Warning:explicit path for executable will not be used for configs";
35 static const ERRCODE USAGE = "Usage";
36 
37 namespace tesseract {
38 /**********************************************************************
39  * main_setup
40  *
41  * Main for mithras demo program. Read the arguments and set up globals.
42  **********************************************************************/
43 
53 void CCUtil::main_setup(const char *argv0, const char *basename) {
54  imagebasename = basename;
56  if (argv0 != NULL) {
57  datadir = argv0;
58  } else {
59  if (getenv("TESSDATA_PREFIX")) {
60  datadir = getenv("TESSDATA_PREFIX");
61  } else {
62 #ifdef TESSDATA_PREFIX
63 #define _STR(a) #a
64 #define _XSTR(a) _STR(a)
65  datadir = _XSTR(TESSDATA_PREFIX);
66 #undef _XSTR
67 #undef _STR
68 #endif
69  }
70  }
71 
72  // datadir may still be empty:
73  if (datadir.length() == 0) {
74  datadir = "./";
75  } else {
76  // Remove tessdata from the end if present, as we will add it back!
77  int length = datadir.length();
78  if (length >= 8 && strcmp(&datadir[length - 8], "tessdata") == 0)
79  datadir.truncate_at(length - 8);
80  else if (length >= 9 && strcmp(&datadir[length - 9], "tessdata/") == 0)
81  datadir.truncate_at(length - 9);
82  }
83 
84  // check for missing directory separator
85  const char *lastchar = datadir.string();
86  lastchar += datadir.length() - 1;
87  if ((strcmp(lastchar, "/") != 0) && (strcmp(lastchar, "\\") != 0))
88  datadir += "/";
89 
91 }
92 } // namespace tesseract
STRING imagebasename
Definition: ccutil.h:68
const ERRCODE NO_PATH
Definition: mainblk.cpp:33
inT32 length() const
Definition: strngs.cpp:188
char * m_data_sub_dir
Definition: ccutil.h:84
STRING datadir
Definition: ccutil.h:67
void truncate_at(inT32 index)
Definition: strngs.cpp:264
void main_setup(const char *argv0, const char *basename)
CCUtil::main_setup - set location of tessdata and name of image.
Definition: mainblk.cpp:53
#define NULL
Definition: host.h:144
const char * string() const
Definition: strngs.cpp:193