Skip to content

Commit

Permalink
Format modified code with clang-format
Browse files Browse the repository at this point in the history
Format the files which were changed in
commit 297d7d8.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Mar 24, 2019
1 parent 06acbaf commit 91e2b25
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 316 deletions.
118 changes: 57 additions & 61 deletions src/ccmain/tessedit.cpp
Expand Up @@ -21,42 +21,42 @@

// Include automatically generated configuration file if running autoconf.
#ifdef HAVE_CONFIG_H
#include "config_auto.h"
# include "config_auto.h"
#endif

#include "basedir.h"
#include "tessvars.h"
#include "control.h"
#include "reject.h"
#include "pageres.h"
#include "pgedit.h"
#include "tprintf.h"
#include "tessedit.h"
#include "reject.h"
#include "stopper.h"
#include "tessedit.h"
#include "tessvars.h"
#include "tprintf.h"
#ifndef DISABLED_LEGACY_ENGINE
#include "intmatcher.h"
#include "chop.h"
# include "chop.h"
# include "intmatcher.h"
#endif
#ifndef ANDROID_BUILD
#include "lstmrecognizer.h"
# include "lstmrecognizer.h"
#endif
#include "tesseractclass.h"
#include "params.h"
#include "tesseractclass.h"
#ifdef DISABLED_LEGACY_ENGINE
#include "matchdefs.h"
# include "matchdefs.h"
#endif

// config under api
#define API_CONFIG "configs/api_config"
// config under api
#define API_CONFIG "configs/api_config"

ETEXT_DESC *global_monitor = nullptr; // progress monitor
ETEXT_DESC* global_monitor = nullptr; // progress monitor

namespace tesseract {

// Read a "config" file containing a set of variable, value pairs.
// Searches the standard places: tessdata/configs, tessdata/tessconfigs
// and also accepts a relative or absolute path name.
void Tesseract::read_config_file(const char *filename,
void Tesseract::read_config_file(const char* filename,
SetParamConstraint constraint) {
STRING path = datadir;
path += "configs/";
Expand Down Expand Up @@ -88,11 +88,11 @@ void Tesseract::read_config_file(const char *filename,
// the config files specified on the command line or left as the default
// OEM_TESSERACT_ONLY if none of the configs specify this variable.
bool Tesseract::init_tesseract_lang_data(
const char *arg0, const char *textbase, const char *language,
OcrEngineMode oem, char **configs, int configs_size,
const GenericVector<STRING> *vars_vec,
const GenericVector<STRING> *vars_values, bool set_only_non_debug_params,
TessdataManager *mgr) {
const char* arg0, const char* textbase, const char* language,
OcrEngineMode oem, char** configs, int configs_size,
const GenericVector<STRING>* vars_vec,
const GenericVector<STRING>* vars_values, bool set_only_non_debug_params,
TessdataManager* mgr) {
// Set the basename, compute the data directory.
main_setup(arg0, textbase);

Expand All @@ -106,8 +106,9 @@ bool Tesseract::init_tesseract_lang_data(
STRING tessdata_path = language_data_path_prefix + kTrainedDataSuffix;
if (!mgr->is_loaded() && !mgr->Init(tessdata_path.string())) {
tprintf("Error opening data file %s\n", tessdata_path.string());
tprintf("Please make sure the TESSDATA_PREFIX environment variable is set"
" to your \"tessdata\" directory.\n");
tprintf(
"Please make sure the TESSDATA_PREFIX environment variable is set"
" to your \"tessdata\" directory.\n");
return false;
}
#ifndef DISABLED_LEGACY_ENGINE
Expand All @@ -131,8 +132,9 @@ bool Tesseract::init_tesseract_lang_data(
this->params());
}

SetParamConstraint set_params_constraint = set_only_non_debug_params ?
SET_PARAM_CONSTRAINT_NON_DEBUG_ONLY : SET_PARAM_CONSTRAINT_NONE;
SetParamConstraint set_params_constraint =
set_only_non_debug_params ? SET_PARAM_CONSTRAINT_NON_DEBUG_ONLY
: SET_PARAM_CONSTRAINT_NONE;
// Load tesseract variables from config files. This is done after loading
// language-specific variables from [lang].traineddata file, so that custom
// config files can override values in [lang].traineddata file.
Expand All @@ -153,8 +155,8 @@ bool Tesseract::init_tesseract_lang_data(
}
}

if (((STRING &)tessedit_write_params_to_file).length() > 0) {
FILE *params_file = fopen(tessedit_write_params_to_file.string(), "wb");
if (((STRING&)tessedit_write_params_to_file).length() > 0) {
FILE* params_file = fopen(tessedit_write_params_to_file.string(), "wb");
if (params_file != nullptr) {
ParamUtils::PrintParams(params_file, this->params());
fclose(params_file);
Expand All @@ -177,16 +179,16 @@ bool Tesseract::init_tesseract_lang_data(
// engine-specific data files need to be loaded.
// If LSTM_ONLY is requested, the base Tesseract files are *Not* required.
#ifndef ANDROID_BUILD
#ifdef DISABLED_LEGACY_ENGINE
# ifdef DISABLED_LEGACY_ENGINE
if (tessedit_ocr_engine_mode == OEM_LSTM_ONLY) {
#else
# else
if (tessedit_ocr_engine_mode == OEM_LSTM_ONLY ||
tessedit_ocr_engine_mode == OEM_TESSERACT_LSTM_COMBINED) {
#endif // ndef DISABLED_LEGACY_ENGINE
# endif // ndef DISABLED_LEGACY_ENGINE
if (mgr->IsComponentAvailable(TESSDATA_LSTM)) {
lstm_recognizer_ = new LSTMRecognizer;
ASSERT_HOST(
lstm_recognizer_->Load(this->params(), lstm_use_matrix ? language : nullptr, mgr));
ASSERT_HOST(lstm_recognizer_->Load(
this->params(), lstm_use_matrix ? language : nullptr, mgr));
} else {
tprintf("Error: LSTM requested, but not present!! Loading tesseract.\n");
tessedit_ocr_engine_mode.set_value(OEM_TESSERACT_ONLY);
Expand All @@ -203,7 +205,7 @@ bool Tesseract::init_tesseract_lang_data(
}
#ifndef DISABLED_LEGACY_ENGINE
else if (!mgr->GetComponent(TESSDATA_UNICHARSET, &fp) ||
!unicharset.load_from_file(&fp, false)) {
!unicharset.load_from_file(&fp, false)) {
return false;
}
#endif // ndef DISABLED_LEGACY_ENGINE
Expand All @@ -228,8 +230,8 @@ bool Tesseract::init_tesseract_lang_data(
// Init ParamsModel.
// Load pass1 and pass2 weights (for now these two sets are the same, but in
// the future separate sets of weights can be generated).
for (int p = ParamsModel::PTRAIN_PASS1;
p < ParamsModel::PTRAIN_NUM_PASSES; ++p) {
for (int p = ParamsModel::PTRAIN_PASS1; p < ParamsModel::PTRAIN_NUM_PASSES;
++p) {
language_model_->getParamsModel().SetPass(
static_cast<ParamsModel::PassEnum>(p));
if (mgr->GetComponent(TESSDATA_PARAMS_MODEL, &fp)) {
Expand All @@ -247,8 +249,7 @@ bool Tesseract::init_tesseract_lang_data(
static bool IsStrInList(const STRING& str,
const GenericVector<STRING>& str_list) {
for (int i = 0; i < str_list.size(); ++i) {
if (str_list[i] == str)
return true;
if (str_list[i] == str) return true;
}
return false;
}
Expand All @@ -265,8 +266,7 @@ void Tesseract::ParseLanguageString(const char* lang_str,
while (remains.length() > 0) {
// Find the start of the lang code and which vector to add to.
const char* start = remains.string();
while (*start == '+')
++start;
while (*start == '+') ++start;
GenericVector<STRING>* target = to_load;
if (*start == '~') {
target = not_to_load;
Expand All @@ -275,8 +275,7 @@ void Tesseract::ParseLanguageString(const char* lang_str,
// Find the index of the end of the lang code in string start.
int end = strlen(start);
const char* plus = strchr(start, '+');
if (plus != nullptr && plus - start < end)
end = plus - start;
if (plus != nullptr && plus - start < end) end = plus - start;
STRING lang_code(start);
lang_code.truncate_at(end);
STRING next(start + end);
Expand All @@ -292,13 +291,13 @@ void Tesseract::ParseLanguageString(const char* lang_str,
// string and recursively any additional languages required by any language
// traineddata file (via tessedit_load_sublangs in its config) that is loaded.
// See init_tesseract_internal for args.
int Tesseract::init_tesseract(const char *arg0, const char *textbase,
const char *language, OcrEngineMode oem,
char **configs, int configs_size,
const GenericVector<STRING> *vars_vec,
const GenericVector<STRING> *vars_values,
int Tesseract::init_tesseract(const char* arg0, const char* textbase,
const char* language, OcrEngineMode oem,
char** configs, int configs_size,
const GenericVector<STRING>* vars_vec,
const GenericVector<STRING>* vars_values,
bool set_only_non_debug_params,
TessdataManager *mgr) {
TessdataManager* mgr) {
GenericVector<STRING> langs_to_load;
GenericVector<STRING> langs_not_to_load;
ParseLanguageString(language, &langs_to_load, &langs_not_to_load);
Expand All @@ -311,8 +310,8 @@ int Tesseract::init_tesseract(const char *arg0, const char *textbase,
// Load the rest into sub_langs_.
for (int lang_index = 0; lang_index < langs_to_load.size(); ++lang_index) {
if (!IsStrInList(langs_to_load[lang_index], langs_not_to_load)) {
const char *lang_str = langs_to_load[lang_index].string();
Tesseract *tess_to_init;
const char* lang_str = langs_to_load[lang_index].string();
Tesseract* tess_to_init;
if (!loaded_primary) {
tess_to_init = this;
} else {
Expand Down Expand Up @@ -392,13 +391,13 @@ int Tesseract::init_tesseract(const char *arg0, const char *textbase,
// in vars_vec.
// If set_only_init_params is true, then only the initialization variables
// will be set.
int Tesseract::init_tesseract_internal(const char *arg0, const char *textbase,
const char *language, OcrEngineMode oem,
char **configs, int configs_size,
const GenericVector<STRING> *vars_vec,
const GenericVector<STRING> *vars_values,
int Tesseract::init_tesseract_internal(const char* arg0, const char* textbase,
const char* language, OcrEngineMode oem,
char** configs, int configs_size,
const GenericVector<STRING>* vars_vec,
const GenericVector<STRING>* vars_values,
bool set_only_non_debug_params,
TessdataManager *mgr) {
TessdataManager* mgr) {
if (!init_tesseract_lang_data(arg0, textbase, language, oem, configs,
configs_size, vars_vec, vars_values,
set_only_non_debug_params, mgr)) {
Expand All @@ -412,7 +411,7 @@ int Tesseract::init_tesseract_internal(const char *arg0, const char *textbase,
bool init_tesseract = tessedit_ocr_engine_mode != OEM_LSTM_ONLY;
program_editup(textbase, init_tesseract ? mgr : nullptr,
init_tesseract ? mgr : nullptr);
return 0; //Normal exit
return 0; // Normal exit
}

#ifndef DISABLED_LEGACY_ENGINE
Expand Down Expand Up @@ -458,8 +457,8 @@ void Tesseract::SetupUniversalFontIds() {
}

// init the LM component
int Tesseract::init_tesseract_lm(const char *arg0, const char *textbase,
const char *language, TessdataManager *mgr) {
int Tesseract::init_tesseract_lm(const char* arg0, const char* textbase,
const char* language, TessdataManager* mgr) {
if (!init_tesseract_lang_data(arg0, textbase, language, OEM_TESSERACT_ONLY,
nullptr, 0, nullptr, nullptr, false, mgr))
return -1;
Expand All @@ -471,14 +470,11 @@ int Tesseract::init_tesseract_lm(const char *arg0, const char *textbase,

#endif // ndef DISABLED_LEGACY_ENGINE

void Tesseract::end_tesseract() {
end_recog();
}
void Tesseract::end_tesseract() { end_recog(); }

/* Define command type identifiers */

enum CMD_EVENTS
{
enum CMD_EVENTS {
ACTION_1_CMD_EVENT,
RECOG_WERDS,
RECOG_PSEUDO,
Expand Down

0 comments on commit 91e2b25

Please sign in to comment.