Skip to content

Commit cfd72ff

Browse files
committed
Fix --print-parameters (regression)
Commit 629ded2 had broken that functionality. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 0e154ab commit cfd72ff

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

src/api/tesseractmain.cpp

+27-26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**********************************************************************
22
* File: tesseractmain.cpp (Formerly tessedit.c)
33
* Description: Main program for merge of tess and editor.
4-
* Author: Ray Smith
5-
* Created: Tue Jan 07 15:21:46 GMT 1992
4+
* Author: Ray Smith
5+
* Created: Tue Jan 07 15:21:46 GMT 1992
66
*
77
* (C) Copyright 1992, Hewlett-Packard Ltd.
88
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -124,7 +124,7 @@ static void PrintHelpForPSM() {
124124
" bypassing hacks that are Tesseract-specific.\n";
125125

126126
#ifdef DISABLED_LEGACY_ENGINE
127-
const char* disabled_osd_msg =
127+
const char* disabled_osd_msg =
128128
"\nNOTE: The OSD modes are currently disabled.\n";
129129
printf("%s%s", msg, disabled_osd_msg);
130130
#else
@@ -305,11 +305,11 @@ static void ParseArgs(const int argc, char** argv, const char** lang,
305305
} else if ((strcmp(argv[i], "--help-psm") == 0)) {
306306
PrintHelpForPSM();
307307
noocr = true;
308-
#ifndef DISABLED_LEGACY_ENGINE
308+
#ifndef DISABLED_LEGACY_ENGINE
309309
} else if ((strcmp(argv[i], "--help-oem") == 0)) {
310310
PrintHelpForOEM();
311311
noocr = true;
312-
#endif
312+
#endif
313313
} else if ((strcmp(argv[i], "-v") == 0) ||
314314
(strcmp(argv[i], "--version") == 0)) {
315315
PrintVersionInfo();
@@ -336,11 +336,11 @@ static void ParseArgs(const int argc, char** argv, const char** lang,
336336
*pagesegmode = static_cast<tesseract::PageSegMode>(atoi(argv[i + 1]));
337337
++i;
338338
} else if (strcmp(argv[i], "--oem") == 0 && i + 1 < argc) {
339-
#ifndef DISABLED_LEGACY_ENGINE
339+
#ifndef DISABLED_LEGACY_ENGINE
340340
int oem = atoi(argv[i + 1]);
341341
checkArgValues(oem, "OEM", tesseract::OEM_COUNT);
342342
*enginemode = static_cast<tesseract::OcrEngineMode>(oem);
343-
#endif
343+
#endif
344344
++i;
345345
} else if (strcmp(argv[i], "--print-parameters") == 0) {
346346
noocr = true;
@@ -464,14 +464,9 @@ int main(int argc, char** argv) {
464464
ParseArgs(argc, argv, &lang, &image, &outputbase, &datapath, &list_langs,
465465
&print_parameters, &vars_vec, &vars_values, &arg_i, &pagesegmode,
466466
&enginemode);
467-
if (image == nullptr && !list_langs)
468-
return EXIT_SUCCESS;
469467

470-
bool banner = false;
471-
if (outputbase != nullptr && strcmp(outputbase, "-") &&
472-
strcmp(outputbase, "stdout")) {
473-
banner = true;
474-
}
468+
if (image == nullptr && !list_langs && !print_parameters)
469+
return EXIT_SUCCESS;
475470

476471
PERF_COUNT_START("Tesseract:main")
477472

@@ -501,11 +496,11 @@ int main(int argc, char** argv) {
501496
}
502497

503498
if (print_parameters) {
504-
FILE* fout = stdout;
505-
fprintf(stdout, "Tesseract parameters:\n");
506-
api.PrintVariables(fout);
507-
api.End();
508-
return EXIT_SUCCESS;
499+
FILE* fout = stdout;
500+
fprintf(stdout, "Tesseract parameters:\n");
501+
api.PrintVariables(fout);
502+
api.End();
503+
return EXIT_SUCCESS;
509504
}
510505

511506
FixPageSegMode(&api, pagesegmode);
@@ -553,20 +548,20 @@ int main(int argc, char** argv) {
553548

554549
#ifdef DISABLED_LEGACY_ENGINE
555550
auto cur_psm = api.GetPageSegMode();
556-
auto osd_warning = std::string("");
557-
if (cur_psm == tesseract::PSM_OSD_ONLY) {
558-
const char* disabled_osd_msg =
551+
auto osd_warning = std::string("");
552+
if (cur_psm == tesseract::PSM_OSD_ONLY) {
553+
const char* disabled_osd_msg =
559554
"\nERROR: The page segmentation mode 0 (OSD Only) is currently disabled.\n\n";
560555
fprintf(stderr, "%s", disabled_osd_msg);
561556
return EXIT_FAILURE;
562557
} else if (cur_psm == tesseract::PSM_AUTO_OSD) {
563558
api.SetPageSegMode(tesseract::PSM_AUTO);
564-
osd_warning +=
559+
osd_warning +=
565560
"\nWarning: The page segmentation mode 1 (Auto+OSD) is currently disabled. "
566561
"Using PSM 3 (Auto) instead.\n\n";
567562
} else if (tesseract::PSM_SPARSE_TEXT_OSD) {
568563
api.SetPageSegMode(tesseract::PSM_SPARSE_TEXT);
569-
osd_warning +=
564+
osd_warning +=
570565
"\nWarning: The page segmentation mode 12 (Sparse text + OSD) is currently disabled. "
571566
"Using PSM 11 (Sparse text) instead.\n\n";
572567
}
@@ -581,13 +576,19 @@ int main(int argc, char** argv) {
581576
PreloadRenderers(&api, &renderers, pagesegmode, outputbase);
582577
}
583578

579+
bool banner = false;
580+
if (outputbase != nullptr && strcmp(outputbase, "-") &&
581+
strcmp(outputbase, "stdout")) {
582+
banner = true;
583+
}
584+
584585
if (!renderers.empty()) {
585586
if (banner) PrintBanner();
586-
#ifdef DISABLED_LEGACY_ENGINE
587+
#ifdef DISABLED_LEGACY_ENGINE
587588
if (!osd_warning.empty()) {
588589
fprintf(stderr, "%s",osd_warning.c_str());
589590
}
590-
#endif
591+
#endif
591592
bool succeed = api.ProcessPages(image, nullptr, 0, renderers[0]);
592593
if (!succeed) {
593594
fprintf(stderr, "Error during processing.\n");

0 commit comments

Comments
 (0)