tesseract
3.04.00
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 "
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
33
const
ERRCODE
NO_PATH
=
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
90
datadir
+=
m_data_sub_dir
;
91
}
92
}
// namespace tesseract
tesseract::CCUtil::imagebasename
STRING imagebasename
Definition:
ccutil.h:68
NO_PATH
const ERRCODE NO_PATH
Definition:
mainblk.cpp:33
STRING::length
inT32 length() const
Definition:
strngs.cpp:188
ERRCODE
Definition:
errcode.h:69
tesseract::CCUtil::m_data_sub_dir
char * m_data_sub_dir
Definition:
ccutil.h:84
tesseract::CCUtil::datadir
STRING datadir
Definition:
ccutil.h:67
STRING::truncate_at
void truncate_at(inT32 index)
Definition:
strngs.cpp:264
fileerr.h
tesseract-c_api-demo.tesseract
tuple tesseract
Definition:
tesseract-c_api-demo.py:45
tesseract::CCUtil::main_setup
void main_setup(const char *argv0, const char *basename)
CCUtil::main_setup - set location of tessdata and name of image.
Definition:
mainblk.cpp:53
NULL
#define NULL
Definition:
host.h:144
STRING::string
const char * string() const
Definition:
strngs.cpp:193
tesseract-c_api-demo.TESSDATA_PREFIX
tuple TESSDATA_PREFIX
Definition:
tesseract-c_api-demo.py:32
ccutil.h
ccutil
mainblk.cpp
Generated by
1.8.6