Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

follow-up to dev mailing list discuss + issue #3998: RFC: Consistent tprintf() use, ERROR: & WARNING: prefixes. #4020

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
32 changes: 16 additions & 16 deletions src/api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ void TessBaseAPI::SetSourceResolution(int ppi) {
if (thresholder_) {
thresholder_->SetSourceYResolution(ppi);
} else {
tprintf("Please call SetImage before SetSourceResolution.\n");
tprintf("ERROR: Please call SetImage before SetSourceResolution.\n");
}
}

Expand Down Expand Up @@ -1005,7 +1005,7 @@ bool TessBaseAPI::ProcessPagesFileList(FILE *flist, std::string *buf, const char
chomp_string(pagename);
Pix *pix = pixRead(pagename);
if (pix == nullptr) {
tprintf("Image file %s cannot be read!\n", pagename);
tprintf("ERROR: Image file %s cannot be read!\n", pagename);
return false;
}
tprintf("Page %u : %s\n", page, pagename);
Expand Down Expand Up @@ -1074,7 +1074,7 @@ bool TessBaseAPI::ProcessPages(const char *filename, const char *retry_config, i
#ifndef DISABLED_LEGACY_ENGINE
if (result) {
if (tesseract_->tessedit_train_from_boxes && !tesseract_->WriteTRFile(output_file_.c_str())) {
tprintf("Write of TR file failed: %s\n", output_file_.c_str());
tprintf("ERROR: Write of TR file failed: %s\n", output_file_.c_str());
return false;
}
}
Expand Down Expand Up @@ -1106,9 +1106,9 @@ bool TessBaseAPI::ProcessPagesInternal(const char *filename, const char *retry_c
int timeout_millisec, TessResultRenderer *renderer) {
bool stdInput = !strcmp(filename, "stdin") || !strcmp(filename, "-");
if (stdInput) {
#ifdef WIN32
#if defined(WIN32) || defined(_WIN32) || defined(_WIN64)
if (_setmode(_fileno(stdin), _O_BINARY) == -1)
tprintf("ERROR: cin to binary: %s", strerror(errno));
tprintf("ERROR: Cannot set STDIN to binary: %s", strerror(errno));
#endif // WIN32
}

Expand All @@ -1135,7 +1135,7 @@ bool TessBaseAPI::ProcessPagesInternal(const char *filename, const char *retry_c
} else {
CURLcode curlcode;
auto error = [curl, &curlcode](const char *function) {
fprintf(stderr, "Error, %s failed with error %s\n", function, curl_easy_strerror(curlcode));
tprintf("ERROR: %s failed with error %s\n", function, curl_easy_strerror(curlcode));
curl_easy_cleanup(curl);
return false;
};
Expand Down Expand Up @@ -1188,7 +1188,7 @@ bool TessBaseAPI::ProcessPagesInternal(const char *filename, const char *retry_c
if (FILE *file = fopen(filename, "rb")) {
fclose(file);
} else {
fprintf(stderr, "Error, cannot read input file %s: %s\n", filename, strerror(errno));
tprintf("ERROR: cannot read input file %s: %s\n", filename, strerror(errno));
return false;
}
}
Expand Down Expand Up @@ -1293,7 +1293,7 @@ bool TessBaseAPI::ProcessPage(Pix *pix, int page_index, const char *filename,
// Save current config variables before switching modes.
FILE *fp = fopen(kOldVarsFile, "wb");
if (fp == nullptr) {
tprintf("Error, failed to open file \"%s\"\n", kOldVarsFile);
tprintf("ERROR: Failed to open file \"%s\"\n", kOldVarsFile);
} else {
PrintVariables(fp);
fclose(fp);
Expand Down Expand Up @@ -2034,7 +2034,7 @@ void TessBaseAPI::SetProbabilityInContextFunc(ProbabilityInContextFunc f) {
/** Common code for setting the image. */
bool TessBaseAPI::InternalSetImage() {
if (tesseract_ == nullptr) {
tprintf("Please call Init before attempting to set an image.\n");
tprintf("ERROR: Please call Init before attempting to set an image.\n");
return false;
}
if (thresholder_ == nullptr) {
Expand All @@ -2061,7 +2061,7 @@ bool TessBaseAPI::Threshold(Pix **pix) {
int y_res = thresholder_->GetScaledYResolution();
if (user_dpi && (user_dpi < kMinCredibleResolution || user_dpi > kMaxCredibleResolution)) {
tprintf(
"Warning: User defined image dpi is outside of expected range "
"WARNING: User defined image dpi is outside of expected range "
"(%d - %d)!\n",
kMinCredibleResolution, kMaxCredibleResolution);
}
Expand All @@ -2071,7 +2071,7 @@ bool TessBaseAPI::Threshold(Pix **pix) {
} else if (y_res < kMinCredibleResolution || y_res > kMaxCredibleResolution) {
if (y_res != 0) {
// Show warning only if a resolution was given.
tprintf("Warning: Invalid resolution %d dpi. Using %d instead.\n",
tprintf("WARNING: Invalid resolution %d dpi. Using %d instead.\n",
y_res, kMinCredibleResolution);
}
thresholder_->SetSourceYResolution(kMinCredibleResolution);
Expand Down Expand Up @@ -2116,7 +2116,7 @@ bool TessBaseAPI::Threshold(Pix **pix) {
kMinCredibleResolution, kMaxCredibleResolution);
if (estimated_res != thresholder_->GetScaledEstimatedResolution()) {
tprintf(
"Estimated internal resolution %d out of range! "
"WARNING: Estimated internal resolution %d out of range! "
"Corrected to %d.\n",
thresholder_->GetScaledEstimatedResolution(), estimated_res);
}
Expand All @@ -2127,7 +2127,7 @@ bool TessBaseAPI::Threshold(Pix **pix) {
/** Find lines from the image making the BLOCK_LIST. */
int TessBaseAPI::FindLines() {
if (thresholder_ == nullptr || thresholder_->IsEmpty()) {
tprintf("Please call SetImage before attempting recognition.\n");
tprintf("ERROR: Please call SetImage before attempting recognition.\n");
return -1;
}
if (recognition_done_) {
Expand All @@ -2154,7 +2154,7 @@ int TessBaseAPI::FindLines() {
equ_detect_ = new EquationDetect(datapath_.c_str(), nullptr);
}
if (equ_detect_ == nullptr) {
tprintf("Warning: Could not set equation detector\n");
tprintf("WARNING: Could not set equation detector\n");
} else {
tesseract_->SetEquationDetect(equ_detect_);
}
Expand All @@ -2172,7 +2172,7 @@ int TessBaseAPI::FindLines() {
TessdataManager mgr(reader_);
if (datapath_.empty()) {
tprintf(
"Warning: Auto orientation and script detection requested,"
"WARNING: Auto orientation and script detection requested,"
" but data path is undefined\n");
delete osd_tesseract_;
osd_tesseract_ = nullptr;
Expand All @@ -2182,7 +2182,7 @@ int TessBaseAPI::FindLines() {
osd_tesseract_->set_source_resolution(thresholder_->GetSourceYResolution());
} else {
tprintf(
"Warning: Auto orientation and script detection requested,"
"WARNING: Auto orientation and script detection requested,"
" but osd language failed to load\n");
delete osd_tesseract_;
osd_tesseract_ = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/api/pdfrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ static void ClipBaseline(int ppi, int x1, int y1, int x2, int y2, int *line_x1,

static bool CodepointToUtf16be(int code, char utf16[kMaxBytesPerCodepoint]) {
if ((code > 0xD7FF && code < 0xE000) || code > 0x10FFFF) {
tprintf("Dropping invalid codepoint %d\n", code);
tprintf("ERROR: Dropping invalid codepoint %d\n", code);
return false;
}
if (code < 0x10000) {
Expand Down Expand Up @@ -633,7 +633,7 @@ bool TessPDFRenderer::BeginDocumentHandler() {
font = buffer.data();
} else {
#if !defined(NDEBUG)
tprintf("Cannot open file \"%s\"!\nUsing internal glyphless font.\n", stream.str().c_str());
tprintf("ERROR: Cannot open file \"%s\"!\nUsing internal glyphless font.\n", stream.str().c_str());
#endif
font = pdf_ttf;
size = sizeof(pdf_ttf);
Expand Down
2 changes: 1 addition & 1 deletion src/arch/simddetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void SIMDDetect::Update() {
dotproduct_method = "std::inner_product";
} else {
// Unsupported value of config variable.
tprintf("Warning, ignoring unsupported config variable value: dotproduct=%s\n",
tprintf("WARNING: Ignoring unsupported config variable value: dotproduct=%s\n",
dotproduct.c_str());
tprintf(
"Supported values for dotproduct: auto generic native"
Expand Down
4 changes: 2 additions & 2 deletions src/ccmain/applybox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ bool Tesseract::ResegmentCharBox(PAGE_RES *page_res, const TBOX *prev_box, const
}
}
if (applybox_debug > 0) {
tprintf("FAIL!\n");
tprintf("ERROR: FAIL!\n");
}
return false; // Failure.
}
Expand Down Expand Up @@ -485,7 +485,7 @@ bool Tesseract::ResegmentWordBox(BLOCK_LIST *block_list, const TBOX &box, const
}
}
if (new_word == nullptr && applybox_debug > 0) {
tprintf("FAIL!\n");
tprintf("ERROR: FAIL!\n");
}
return new_word != nullptr;
}
Expand Down
14 changes: 7 additions & 7 deletions src/ccmain/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ bool Tesseract::ProcessTargetWord(const TBOX &word_box, const TBOX &target_word_
backup_config_file_ = kBackUpConfigFile;
FILE *config_fp = fopen(backup_config_file_, "wb");
if (config_fp == nullptr) {
tprintf("Error, failed to open file \"%s\"\n", backup_config_file_);
tprintf("ERROR: Failed to open file \"%s\"\n", backup_config_file_);
} else {
ParamUtils::PrintParams(config_fp, params());
fclose(config_fp);
Expand Down Expand Up @@ -472,7 +472,7 @@ void Tesseract::bigram_correction_pass(PAGE_RES *page_res) {
}
if (w_prev->word->flag(W_REP_CHAR) || w->word->flag(W_REP_CHAR)) {
if (tessedit_bigram_debug) {
tprintf("Skipping because one of the words is W_REP_CHAR\n");
tprintf("WARNING: Skipping because one of the words is W_REP_CHAR\n");
}
continue;
}
Expand Down Expand Up @@ -1678,7 +1678,7 @@ void Tesseract::fix_rep_char(PAGE_RES_IT *page_res_it) {
// Find the best exemplar of a classifier result for maxch_id.
BLOB_CHOICE *best_choice = FindBestMatchingChoice(maxch_id, word_res);
if (best_choice == nullptr) {
tprintf("Failed to find a choice for %s, occurring %d times\n",
tprintf("WARNING: Failed to find a choice for %s, occurring %d times\n",
word_res->uch_set->debug_str(maxch_id).c_str(), max_count);
return;
}
Expand Down Expand Up @@ -1737,9 +1737,9 @@ ACCEPTABLE_WERD_TYPE Tesseract::acceptable_word_string(const UNICHARSET &char_se
goto not_a_word;
}
/*
Allow a single hyphen in a lower case word
- don't trust upper case - I've seen several cases of "H" -> "I-I"
*/
Allow a single hyphen in a lower case word
- don't trust upper case - I've seen several cases of "H" -> "I-I"
*/
if (lengths[i] == 1 && s[offset] == '-') {
hyphen_pos = i;
offset += lengths[i++];
Expand Down Expand Up @@ -1939,7 +1939,7 @@ void Tesseract::set_word_fonts(WERD_RES *word) {
}
if (tessedit_font_id > 0) {
if (tessedit_font_id >= fontinfo_size) {
tprintf("Error, invalid font ID provided: must be below %d.\n"
tprintf("ERROR: Invalid font ID provided: must be below %d.\n"
"Falling back to font auto-detection.\n", fontinfo_size);
} else {
word->fontinfo = &fontinfo_table_.at(tessedit_font_id);
Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/equationdetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ EquationDetect::EquationDetect(const char *equ_datapath, const char *equ_name) {

if (equ_tesseract_.init_tesseract(equ_datapath, equ_name, OEM_TESSERACT_ONLY)) {
tprintf(
"Warning: equation region detection requested,"
"WARNING: Equation region detection requested,"
" but %s failed to load from %s\n",
equ_name, equ_datapath);
}
Expand Down
8 changes: 4 additions & 4 deletions src/ccmain/linerec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool Tesseract::TrainLineRecognizer(const char *input_imagename, const std::stri
if (applybox_page > 0) {
// Load existing document for the previous pages.
if (!images.LoadDocument(lstmf_name.c_str(), 0, 0, nullptr)) {
tprintf("Failed to read training data from %s!\n", lstmf_name.c_str());
tprintf("ERROR: Failed to read training data from %s!\n", lstmf_name.c_str());
return false;
}
}
Expand All @@ -54,17 +54,17 @@ bool Tesseract::TrainLineRecognizer(const char *input_imagename, const std::stri
// Get the boxes for this page, if there are any.
if (!ReadAllBoxes(applybox_page, false, input_imagename, &boxes, &texts, nullptr, nullptr) ||
boxes.empty()) {
tprintf("Failed to read boxes from %s\n", input_imagename);
tprintf("ERROR: Failed to read boxes from %s\n", input_imagename);
return false;
}
TrainFromBoxes(boxes, texts, block_list, &images);
if (images.PagesSize() == 0) {
tprintf("Failed to read pages from %s\n", input_imagename);
tprintf("ERROR: Failed to read pages from %s\n", input_imagename);
return false;
}
images.Shuffle();
if (!images.SaveDocument(lstmf_name.c_str(), nullptr)) {
tprintf("Failed to write training data to %s!\n", lstmf_name.c_str());
tprintf("ERROR: Failed to write training data to %s!\n", lstmf_name.c_str());
return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/osdetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static void remove_nontext_regions(tesseract::Tesseract *tess, BLOCK_LIST *block
int resolution;
if (kMinCredibleResolution > pixGetXRes(pix)) {
resolution = kMinCredibleResolution;
tprintf("Warning. Invalid resolution %d dpi. Using %d instead.\n", pixGetXRes(pix), resolution);
tprintf("WARNING: Invalid resolution %d dpi. Using %d instead.\n", pixGetXRes(pix), resolution);
} else {
resolution = pixGetXRes(pix);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/pageiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ void PageIterator::BeginWord(int offset) {
word_length_ = word_res->best_choice->length();
if (word_res->box_word != nullptr) {
if (word_res->box_word->length() != static_cast<unsigned>(word_length_)) {
tprintf("Corrupted word! best_choice[len=%d] = %s, box_word[len=%d]: ",
tprintf("WARNING: Corrupted word! best_choice[len=%d] = %s, box_word[len=%d]: ",
word_length_, word_res->best_choice->unichar_string().c_str(),
word_res->box_word->length());
word_res->box_word->bounding_box().print();
Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/pagesegmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ int Tesseract::SegmentPage(const char *input_file, BLOCK_LIST *blocks, Tesseract

if (blocks->empty()) {
if (textord_debug_tabfind) {
tprintf("Empty page\n");
tprintf("WARNING: Empty page\n");
}
return 0; // AutoPageSeg found an empty page.
}
Expand Down
14 changes: 7 additions & 7 deletions src/ccmain/paragraphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static bool AcceptableRowArgs(int debug_level, int min_num_rows, const char *fun
const std::vector<RowScratchRegisters> *rows, int row_start,
int row_end) {
if (row_start < 0 || static_cast<size_t>(row_end) > rows->size() || row_start > row_end) {
tprintf("Invalid arguments rows[%d, %d) while rows is of size %zu.\n", row_start, row_end,
tprintf("ERROR: Invalid arguments rows[%d, %d) while rows is of size %zu.\n", row_start, row_end,
rows->size());
return false;
}
Expand Down Expand Up @@ -568,7 +568,7 @@ LineType RowScratchRegisters::GetLineType() const {
has_body = true;
break;
default:
tprintf("Encountered bad value in hypothesis list: %c\n", hypothese.ty);
tprintf("ERROR: Encountered bad value in hypothesis list: %c\n", hypothese.ty);
break;
}
}
Expand Down Expand Up @@ -596,7 +596,7 @@ LineType RowScratchRegisters::GetLineType(const ParagraphModel *model) const {
has_body = true;
break;
default:
tprintf("Encountered bad value in hypothesis list: %c\n", hypothese.ty);
tprintf("ERROR: Encountered bad value in hypothesis list: %c\n", hypothese.ty);
break;
}
}
Expand Down Expand Up @@ -1327,7 +1327,7 @@ int ParagraphTheory::IndexOf(const ParagraphModel *model) const {
bool ValidFirstLine(const std::vector<RowScratchRegisters> *rows, int row,
const ParagraphModel *model) {
if (!StrongModel(model)) {
tprintf("ValidFirstLine() should only be called with strong models!\n");
tprintf("WARNING: ValidFirstLine() should only be called with strong models!\n");
}
return StrongModel(model) && model->ValidFirstLine((*rows)[row].lmargin_, (*rows)[row].lindent_,
(*rows)[row].rindent_, (*rows)[row].rmargin_);
Expand All @@ -1336,7 +1336,7 @@ bool ValidFirstLine(const std::vector<RowScratchRegisters> *rows, int row,
bool ValidBodyLine(const std::vector<RowScratchRegisters> *rows, int row,
const ParagraphModel *model) {
if (!StrongModel(model)) {
tprintf("ValidBodyLine() should only be called with strong models!\n");
tprintf("WARNING: ValidBodyLine() should only be called with strong models!\n");
}
return StrongModel(model) && model->ValidBodyLine((*rows)[row].lmargin_, (*rows)[row].lindent_,
(*rows)[row].rindent_, (*rows)[row].rmargin_);
Expand Down Expand Up @@ -1758,7 +1758,7 @@ static ParagraphModel InternalParagraphModelByOutline(
cmin = cmax = 0;
for (int i = start + 1; i < end; i++) {
if ((*rows)[i].lmargin_ != lmargin || (*rows)[i].rmargin_ != rmargin) {
tprintf("Margins don't match! Software error.\n");
tprintf("ERROR: Margins don't match! Software error.\n");
*consistent = false;
return ParagraphModel();
}
Expand Down Expand Up @@ -2148,7 +2148,7 @@ static void ConvertHypothesizedModelRunsToParagraphs(int debug_level,
for (int row = start; row < end; row++) {
if ((*row_owners)[row] != nullptr) {
tprintf(
"Memory leak! ConvertHypothesizeModelRunsToParagraphs() called "
"ERROR: Memory leak! ConvertHypothesizeModelRunsToParagraphs() called "
"more than once!\n");
delete (*row_owners)[row];
}
Expand Down
4 changes: 2 additions & 2 deletions src/ccmain/recogtraining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ FILE *Tesseract::init_recog_training(const char *filename) {
output_fname += ".txt";
FILE *output_file = fopen(output_fname.c_str(), "a+");
if (output_file == nullptr) {
tprintf("Error: Could not open file %s\n", output_fname.c_str());
tprintf("ERROR: Could not open file %s\n", output_fname.c_str());
ASSERT_HOST(output_file);
}
return output_file;
Expand Down Expand Up @@ -94,7 +94,7 @@ void Tesseract::recog_training_segmented(const char *filename, PAGE_RES *page_re
// ReadNextBox() will close box_file
FILE *box_file = fopen(box_fname.c_str(), "r");
if (box_file == nullptr) {
tprintf("Error: Could not open file %s\n", box_fname.c_str());
tprintf("ERROR: Could not open file %s\n", box_fname.c_str());
ASSERT_HOST(box_file);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/reject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void Tesseract::make_reject_map(WERD_RES *word, ROW *row, int16_t pass) {
/* Ambig word rejection was here once !!*/
}
} else {
tprintf("BAD tessedit_reject_mode\n");
tprintf("ERROR: BAD tessedit_reject_mode\n");
ASSERT_HOST("Fatal error encountered!" == nullptr);
}

Expand Down
Loading