Skip to content

Commit b4cf466

Browse files
committed
Issue #529: inside main() use return rather than exit
1 parent 9a5ed19 commit b4cf466

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

api/tesseractmain.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -440,33 +440,33 @@ int main(int argc, char** argv) {
440440
argc - arg_i, &vars_vec, &vars_values, false);
441441
if (init_failed) {
442442
fprintf(stderr, "Could not initialize tesseract.\n");
443-
exit(1);
443+
return EXIT_FAILURE;
444444
}
445445

446446
SetVariablesFromCLArgs(&api, argc, argv);
447447

448448
if (list_langs) {
449449
PrintLangsList(&api);
450-
exit(0);
450+
return EXIT_SUCCESS;
451451
}
452452

453453
if (print_parameters) {
454454
FILE* fout = stdout;
455455
fprintf(stdout, "Tesseract parameters:\n");
456456
api.PrintVariables(fout);
457457
api.End();
458-
exit(0);
458+
return EXIT_SUCCESS;
459459
}
460460

461461
FixPageSegMode(&api, pagesegmode);
462462

463463
if (pagesegmode == tesseract::PSM_AUTO_ONLY) {
464-
int ret_val = 0;
464+
int ret_val = EXIT_SUCCESS;
465465

466466
Pix* pixs = pixRead(image);
467467
if (!pixs) {
468468
fprintf(stderr, "Cannot open input file: %s\n", image);
469-
exit(2);
469+
return 2;
470470
}
471471

472472
api.SetImage(pixs);
@@ -484,13 +484,13 @@ int main(int argc, char** argv) {
484484
"Deskew angle: %.4f\n",
485485
orientation, direction, order, deskew_angle);
486486
} else {
487-
ret_val = 1;
487+
ret_val = EXIT_FAILURE;
488488
}
489489

490490
delete it;
491491

492492
pixDestroy(&pixs);
493-
exit(ret_val);
493+
return ret_val;
494494
}
495495

496496
// set in_training_mode to true when using one of these configs:
@@ -515,10 +515,11 @@ int main(int argc, char** argv) {
515515
bool succeed = api.ProcessPages(image, NULL, 0, renderers[0]);
516516
if (!succeed) {
517517
fprintf(stderr, "Error during processing.\n");
518-
exit(1);
518+
return EXIT_FAILURE;
519519
}
520520
}
521521

522522
PERF_COUNT_END
523-
return 0; // Normal exit
523+
524+
return EXIT_SUCCESS;
524525
}

0 commit comments

Comments
 (0)