2016-11-19 07:53:11 +08:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2018-04-15 16:27:32 +08:00
|
|
|
|
training: Support new argument --version
classifier_tester, cntraining, combine_lang_model, lstmeval, lstmtraining,
mftraining, set_unicharset_properties, shapeclustering, text2image and
unicharset_extractor now can show the version.
Still missing: ambiguous_words, combine_tessdata, dawg2wordlist,
merge_unicharsets and wordlist2dawg.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-04-15 18:39:18 +08:00
|
|
|
#include "baseapi.h" // TessBaseAPI::Version
|
2013-09-23 23:26:50 +08:00
|
|
|
#include "commandlineflags.h"
|
|
|
|
|
2017-07-20 07:42:48 +08:00
|
|
|
#ifndef GOOGLE_TESSERACT
|
2013-09-23 23:26:50 +08:00
|
|
|
|
|
|
|
namespace tesseract {
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
bool IntFlagExists(const char* flag_name, int32_t* value) {
|
2013-09-23 23:26:50 +08:00
|
|
|
STRING full_flag_name("FLAGS_");
|
|
|
|
full_flag_name += flag_name;
|
|
|
|
GenericVector<IntParam*> empty;
|
|
|
|
IntParam *p = ParamUtils::FindParam<IntParam>(
|
|
|
|
full_flag_name.string(), GlobalParams()->int_params, empty);
|
2016-12-13 15:08:01 +08:00
|
|
|
if (p == nullptr) return false;
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
*value = (int32_t)(*p);
|
2013-09-23 23:26:50 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DoubleFlagExists(const char* flag_name, double* value) {
|
|
|
|
STRING full_flag_name("FLAGS_");
|
|
|
|
full_flag_name += flag_name;
|
|
|
|
GenericVector<DoubleParam*> empty;
|
|
|
|
DoubleParam *p = ParamUtils::FindParam<DoubleParam>(
|
|
|
|
full_flag_name.string(), GlobalParams()->double_params, empty);
|
2016-12-13 15:08:01 +08:00
|
|
|
if (p == nullptr) return false;
|
2013-09-23 23:26:50 +08:00
|
|
|
*value = static_cast<double>(*p);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BoolFlagExists(const char* flag_name, bool* value) {
|
|
|
|
STRING full_flag_name("FLAGS_");
|
|
|
|
full_flag_name += flag_name;
|
|
|
|
GenericVector<BoolParam*> empty;
|
|
|
|
BoolParam *p = ParamUtils::FindParam<BoolParam>(
|
|
|
|
full_flag_name.string(), GlobalParams()->bool_params, empty);
|
2016-12-13 15:08:01 +08:00
|
|
|
if (p == nullptr) return false;
|
2013-09-23 23:26:50 +08:00
|
|
|
*value = (BOOL8)(*p);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StringFlagExists(const char* flag_name, const char** value) {
|
|
|
|
STRING full_flag_name("FLAGS_");
|
|
|
|
full_flag_name += flag_name;
|
|
|
|
GenericVector<StringParam*> empty;
|
|
|
|
StringParam *p = ParamUtils::FindParam<StringParam>(
|
|
|
|
full_flag_name.string(), GlobalParams()->string_params, empty);
|
2016-12-13 15:08:01 +08:00
|
|
|
*value = (p != nullptr) ? p->string() : nullptr;
|
|
|
|
return p != nullptr;
|
2013-09-23 23:26:50 +08:00
|
|
|
}
|
|
|
|
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
void SetIntFlagValue(const char* flag_name, const int32_t new_val) {
|
2013-09-23 23:26:50 +08:00
|
|
|
STRING full_flag_name("FLAGS_");
|
|
|
|
full_flag_name += flag_name;
|
|
|
|
GenericVector<IntParam*> empty;
|
|
|
|
IntParam *p = ParamUtils::FindParam<IntParam>(
|
|
|
|
full_flag_name.string(), GlobalParams()->int_params, empty);
|
2016-12-13 15:08:01 +08:00
|
|
|
ASSERT_HOST(p != nullptr);
|
2013-09-23 23:26:50 +08:00
|
|
|
p->set_value(new_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDoubleFlagValue(const char* flag_name, const double new_val) {
|
|
|
|
STRING full_flag_name("FLAGS_");
|
|
|
|
full_flag_name += flag_name;
|
|
|
|
GenericVector<DoubleParam*> empty;
|
|
|
|
DoubleParam *p = ParamUtils::FindParam<DoubleParam>(
|
|
|
|
full_flag_name.string(), GlobalParams()->double_params, empty);
|
2016-12-13 15:08:01 +08:00
|
|
|
ASSERT_HOST(p != nullptr);
|
2013-09-23 23:26:50 +08:00
|
|
|
p->set_value(new_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetBoolFlagValue(const char* flag_name, const bool new_val) {
|
|
|
|
STRING full_flag_name("FLAGS_");
|
|
|
|
full_flag_name += flag_name;
|
|
|
|
GenericVector<BoolParam*> empty;
|
|
|
|
BoolParam *p = ParamUtils::FindParam<BoolParam>(
|
|
|
|
full_flag_name.string(), GlobalParams()->bool_params, empty);
|
2016-12-13 15:08:01 +08:00
|
|
|
ASSERT_HOST(p != nullptr);
|
2013-09-23 23:26:50 +08:00
|
|
|
p->set_value(new_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetStringFlagValue(const char* flag_name, const char* new_val) {
|
|
|
|
STRING full_flag_name("FLAGS_");
|
|
|
|
full_flag_name += flag_name;
|
|
|
|
GenericVector<StringParam*> empty;
|
|
|
|
StringParam *p = ParamUtils::FindParam<StringParam>(
|
|
|
|
full_flag_name.string(), GlobalParams()->string_params, empty);
|
2016-12-13 15:08:01 +08:00
|
|
|
ASSERT_HOST(p != nullptr);
|
2013-09-23 23:26:50 +08:00
|
|
|
p->set_value(STRING(new_val));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SafeAtoi(const char* str, int* val) {
|
2017-01-26 08:20:19 +08:00
|
|
|
char* endptr = nullptr;
|
2013-09-23 23:26:50 +08:00
|
|
|
*val = strtol(str, &endptr, 10);
|
2016-12-13 15:08:01 +08:00
|
|
|
return endptr != nullptr && *endptr == '\0';
|
2013-09-23 23:26:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SafeAtod(const char* str, double* val) {
|
2017-01-26 08:20:19 +08:00
|
|
|
char* endptr = nullptr;
|
2013-09-23 23:26:50 +08:00
|
|
|
*val = strtod(str, &endptr);
|
2016-12-13 15:08:01 +08:00
|
|
|
return endptr != nullptr && *endptr == '\0';
|
2013-09-23 23:26:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrintCommandLineFlags() {
|
|
|
|
const char* kFlagNamePrefix = "FLAGS_";
|
|
|
|
const int kFlagNamePrefixLen = strlen(kFlagNamePrefix);
|
|
|
|
for (int i = 0; i < GlobalParams()->int_params.size(); ++i) {
|
|
|
|
if (!strncmp(GlobalParams()->int_params[i]->name_str(),
|
|
|
|
kFlagNamePrefix, kFlagNamePrefixLen)) {
|
2016-09-01 19:38:06 +08:00
|
|
|
printf(" --%s %s (type:int default:%d)\n",
|
2016-11-08 02:46:33 +08:00
|
|
|
GlobalParams()->int_params[i]->name_str() + kFlagNamePrefixLen,
|
|
|
|
GlobalParams()->int_params[i]->info_str(),
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
int32_t(*(GlobalParams()->int_params[i])));
|
2013-09-23 23:26:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < GlobalParams()->double_params.size(); ++i) {
|
|
|
|
if (!strncmp(GlobalParams()->double_params[i]->name_str(),
|
|
|
|
kFlagNamePrefix, kFlagNamePrefixLen)) {
|
2016-09-01 19:38:06 +08:00
|
|
|
printf(" --%s %s (type:double default:%g)\n",
|
2016-11-08 02:46:33 +08:00
|
|
|
GlobalParams()->double_params[i]->name_str() + kFlagNamePrefixLen,
|
|
|
|
GlobalParams()->double_params[i]->info_str(),
|
|
|
|
static_cast<double>(*(GlobalParams()->double_params[i])));
|
2013-09-23 23:26:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < GlobalParams()->bool_params.size(); ++i) {
|
|
|
|
if (!strncmp(GlobalParams()->bool_params[i]->name_str(),
|
|
|
|
kFlagNamePrefix, kFlagNamePrefixLen)) {
|
2016-09-01 19:38:06 +08:00
|
|
|
printf(" --%s %s (type:bool default:%s)\n",
|
2016-11-08 02:46:33 +08:00
|
|
|
GlobalParams()->bool_params[i]->name_str() + kFlagNamePrefixLen,
|
|
|
|
GlobalParams()->bool_params[i]->info_str(),
|
|
|
|
(BOOL8(*(GlobalParams()->bool_params[i])) ? "true" : "false"));
|
2013-09-23 23:26:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < GlobalParams()->string_params.size(); ++i) {
|
|
|
|
if (!strncmp(GlobalParams()->string_params[i]->name_str(),
|
|
|
|
kFlagNamePrefix, kFlagNamePrefixLen)) {
|
2016-09-01 19:38:06 +08:00
|
|
|
printf(" --%s %s (type:string default:%s)\n",
|
2016-11-08 02:46:33 +08:00
|
|
|
GlobalParams()->string_params[i]->name_str() + kFlagNamePrefixLen,
|
|
|
|
GlobalParams()->string_params[i]->info_str(),
|
|
|
|
GlobalParams()->string_params[i]->string());
|
2013-09-23 23:26:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParseCommandLineFlags(const char* usage,
|
|
|
|
int* argc, char*** argv,
|
|
|
|
const bool remove_flags) {
|
2016-05-22 16:16:42 +08:00
|
|
|
if (*argc == 1) {
|
2016-09-01 19:38:06 +08:00
|
|
|
printf("USAGE: %s\n", usage);
|
2016-05-22 16:16:42 +08:00
|
|
|
PrintCommandLineFlags();
|
|
|
|
exit(0);
|
training: Support new argument --version
classifier_tester, cntraining, combine_lang_model, lstmeval, lstmtraining,
mftraining, set_unicharset_properties, shapeclustering, text2image and
unicharset_extractor now can show the version.
Still missing: ambiguous_words, combine_tessdata, dawg2wordlist,
merge_unicharsets and wordlist2dawg.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-04-15 18:39:18 +08:00
|
|
|
} else if (*argc > 1 && !strcmp((*argv)[1], "--version")) {
|
|
|
|
printf("%s\n", TessBaseAPI::Version());
|
|
|
|
exit(0);
|
2016-05-22 16:16:42 +08:00
|
|
|
}
|
|
|
|
|
2013-09-23 23:26:50 +08:00
|
|
|
unsigned int i = 1;
|
|
|
|
for (i = 1; i < *argc; ++i) {
|
|
|
|
const char* current_arg = (*argv)[i];
|
|
|
|
// If argument does not start with a hyphen then break.
|
|
|
|
if (current_arg[0] != '-') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Position current_arg after startings hyphens. We treat a sequence of
|
2018-04-18 04:23:23 +08:00
|
|
|
// one or two consecutive hyphens identically.
|
|
|
|
++current_arg;
|
|
|
|
if (current_arg[0] == '-') {
|
2013-09-23 23:26:50 +08:00
|
|
|
++current_arg;
|
|
|
|
}
|
|
|
|
// If this is asking for usage, print the help message and abort.
|
2018-04-18 04:23:23 +08:00
|
|
|
if (!strcmp(current_arg, "help")) {
|
|
|
|
printf("Usage:\n %s [OPTION ...]\n\n", usage);
|
2013-09-23 23:26:50 +08:00
|
|
|
PrintCommandLineFlags();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
// Find the starting position of the value if it was specified in this
|
|
|
|
// string.
|
|
|
|
const char* equals_position = strchr(current_arg, '=');
|
2016-12-13 15:08:01 +08:00
|
|
|
const char* rhs = nullptr;
|
|
|
|
if (equals_position != nullptr) {
|
2013-09-23 23:26:50 +08:00
|
|
|
rhs = equals_position + 1;
|
|
|
|
}
|
|
|
|
// Extract the flag name.
|
|
|
|
STRING lhs;
|
2016-12-13 15:08:01 +08:00
|
|
|
if (equals_position == nullptr) {
|
2013-09-23 23:26:50 +08:00
|
|
|
lhs = current_arg;
|
|
|
|
} else {
|
|
|
|
lhs.assign(current_arg, equals_position - current_arg);
|
|
|
|
}
|
|
|
|
if (!lhs.length()) {
|
|
|
|
tprintf("ERROR: Bad argument: %s\n", (*argv)[i]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the flag name in the list of global flags.
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
// int32_t flag
|
|
|
|
int32_t int_val;
|
2013-09-23 23:26:50 +08:00
|
|
|
if (IntFlagExists(lhs.string(), &int_val)) {
|
2016-12-13 15:08:01 +08:00
|
|
|
if (rhs != nullptr) {
|
2013-09-23 23:26:50 +08:00
|
|
|
if (!strlen(rhs)) {
|
|
|
|
// Bad input of the format --int_flag=
|
|
|
|
tprintf("ERROR: Bad argument: %s\n", (*argv)[i]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!SafeAtoi(rhs, &int_val)) {
|
|
|
|
tprintf("ERROR: Could not parse int from %s in flag %s\n",
|
|
|
|
rhs, (*argv)[i]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We need to parse the next argument
|
|
|
|
if (i + 1 >= *argc) {
|
|
|
|
tprintf("ERROR: Could not find value argument for flag %s\n",
|
|
|
|
lhs.string());
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
if (!SafeAtoi((*argv)[i], &int_val)) {
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
tprintf("ERROR: Could not parse int32_t from %s\n", (*argv)[i]);
|
2013-09-23 23:26:50 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetIntFlagValue(lhs.string(), int_val);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// double flag
|
|
|
|
double double_val;
|
|
|
|
if (DoubleFlagExists(lhs.string(), &double_val)) {
|
2016-12-13 15:08:01 +08:00
|
|
|
if (rhs != nullptr) {
|
2013-09-23 23:26:50 +08:00
|
|
|
if (!strlen(rhs)) {
|
|
|
|
// Bad input of the format --double_flag=
|
|
|
|
tprintf("ERROR: Bad argument: %s\n", (*argv)[i]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!SafeAtod(rhs, &double_val)) {
|
|
|
|
tprintf("ERROR: Could not parse double from %s in flag %s\n",
|
|
|
|
rhs, (*argv)[i]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We need to parse the next argument
|
|
|
|
if (i + 1 >= *argc) {
|
|
|
|
tprintf("ERROR: Could not find value argument for flag %s\n",
|
|
|
|
lhs.string());
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
if (!SafeAtod((*argv)[i], &double_val)) {
|
|
|
|
tprintf("ERROR: Could not parse double from %s\n", (*argv)[i]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetDoubleFlagValue(lhs.string(), double_val);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bool flag. Allow input forms --flag (equivalent to --flag=true),
|
|
|
|
// --flag=false, --flag=true, --flag=0 and --flag=1
|
|
|
|
bool bool_val;
|
|
|
|
if (BoolFlagExists(lhs.string(), &bool_val)) {
|
2016-12-13 15:08:01 +08:00
|
|
|
if (rhs == nullptr) {
|
2013-09-23 23:26:50 +08:00
|
|
|
// --flag form
|
|
|
|
bool_val = true;
|
|
|
|
} else {
|
|
|
|
if (!strlen(rhs)) {
|
|
|
|
// Bad input of the format --bool_flag=
|
|
|
|
tprintf("ERROR: Bad argument: %s\n", (*argv)[i]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!strcmp(rhs, "false") || !strcmp(rhs, "0")) {
|
|
|
|
bool_val = false;
|
|
|
|
} else if (!strcmp(rhs, "true") || !strcmp(rhs, "1")) {
|
|
|
|
bool_val = true;
|
|
|
|
} else {
|
|
|
|
tprintf("ERROR: Could not parse bool from flag %s\n", (*argv)[i]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetBoolFlagValue(lhs.string(), bool_val);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// string flag
|
|
|
|
const char* string_val;
|
|
|
|
if (StringFlagExists(lhs.string(), &string_val)) {
|
2016-12-13 15:08:01 +08:00
|
|
|
if (rhs != nullptr) {
|
2013-09-23 23:26:50 +08:00
|
|
|
string_val = rhs;
|
|
|
|
} else {
|
|
|
|
// Pick the next argument
|
|
|
|
if (i + 1 >= *argc) {
|
|
|
|
tprintf("ERROR: Could not find string value for flag %s\n",
|
|
|
|
lhs.string());
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
string_val = (*argv)[++i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetStringFlagValue(lhs.string(), string_val);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flag was not found. Exit with an error message.
|
|
|
|
tprintf("ERROR: Non-existent flag %s\n", (*argv)[i]);
|
|
|
|
exit(1);
|
|
|
|
} // for each argv
|
|
|
|
if (remove_flags) {
|
|
|
|
(*argv)[i - 1] = (*argv)[0];
|
|
|
|
(*argv) += (i - 1);
|
|
|
|
(*argc) -= (i - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace tesseract
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#include "base/init_google.h"
|
|
|
|
|
|
|
|
namespace tesseract {
|
|
|
|
void ParseCommandLineFlags(const char* usage,
|
|
|
|
int* argc, char*** argv,
|
|
|
|
const bool remove_flags) {
|
|
|
|
InitGoogle(usage, argc, argv, remove_flags);
|
|
|
|
}
|
|
|
|
} // namespace tesseract
|
|
|
|
|
|
|
|
#endif
|