Skip to content

Commit 74e226b

Browse files
authored
Merge pull request #3878 from stweil/exit
Replace call of exit function by return statement in main function
2 parents ee34b10 + 989956c commit 74e226b

13 files changed

+50
-49
lines changed

src/training/ambiguous_words.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ int main(int argc, char **argv) {
3333
// Parse input arguments.
3434
if (argc > 1 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))) {
3535
printf("%s\n", tesseract::TessBaseAPI::Version());
36-
return 0;
36+
return EXIT_SUCCESS;
3737
} else if (argc != 4 && (argc != 6 || strcmp(argv[1], "-l") != 0)) {
3838
printf(
3939
"Usage: %s -v | --version | %s [-l lang] tessdata_dir wordlist_file"
4040
" output_ambiguous_wordlist_file\n",
4141
argv[0], argv[0]);
42-
return 1;
42+
return EXIT_FAILURE;
4343
}
4444
int argv_offset = 0;
4545
std::string lang;
@@ -65,7 +65,7 @@ int main(int argc, char **argv) {
6565
FILE *input_file = fopen(input_file_str, "rb");
6666
if (input_file == nullptr) {
6767
tesseract::tprintf("Failed to open input wordlist file %s\n", input_file_str);
68-
exit(1);
68+
return EXIT_FAILURE;
6969
}
7070
char str[CHARS_PER_LINE];
7171

@@ -78,4 +78,5 @@ int main(int argc, char **argv) {
7878
}
7979
// Clean up.
8080
fclose(input_file);
81+
return EXIT_SUCCESS;
8182
}

src/training/classifier_tester.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ int main(int argc, char **argv) {
109109
InitializeClassifier(FLAGS_classifier.c_str(), trainer->unicharset(), argc, argv, &api);
110110
if (shape_classifier == nullptr) {
111111
fprintf(stderr, "Classifier init failed!:%s\n", FLAGS_classifier.c_str());
112-
return 1;
112+
return EXIT_FAILURE;
113113
}
114114

115115
// We want to test junk as well if it is available.
@@ -123,5 +123,5 @@ int main(int argc, char **argv) {
123123
delete shape_classifier;
124124
delete api;
125125

126-
return 0;
126+
return EXIT_SUCCESS;
127127
} /* main */

src/training/cntraining.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ int main(int argc, char *argv[]) {
141141
Clusterer = SetUpForClustering(FeatureDefs, CharSample, PROGRAM_FEATURE_TYPE);
142142
if (Clusterer == nullptr) { // To avoid a SIGSEGV
143143
fprintf(stderr, "Error: nullptr clusterer!\n");
144-
return 1;
144+
return EXIT_FAILURE;
145145
}
146146
float SavedMinSamples = Config.MinSamples;
147147
// To disable the tendency to produce a single cluster for all fonts,
@@ -173,7 +173,7 @@ int main(int argc, char *argv[]) {
173173
FreeProtoList(&freeable_proto);
174174
}
175175
printf("\n");
176-
return 0;
176+
return EXIT_SUCCESS;
177177
} // main
178178

179179
/*----------------------------------------------------------------------------

src/training/combine_lang_model.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int main(int argc, char **argv) {
5858
UNICHARSET unicharset;
5959
if (!unicharset.load_from_file(FLAGS_input_unicharset.c_str(), false)) {
6060
tprintf("Failed to load unicharset from %s\n", FLAGS_input_unicharset.c_str());
61-
return 1;
61+
return EXIT_FAILURE;
6262
}
6363
tprintf("Loaded unicharset of size %zu from file %s\n", unicharset.size(),
6464
FLAGS_input_unicharset.c_str());

src/training/combine_tessdata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ int main(int argc, char **argv) {
269269
"Usage for compacting LSTM component to int:\n"
270270
" %s -c traineddata_file\n",
271271
argv[0]);
272-
return 1;
272+
return EXIT_FAILURE;
273273
}
274274
tm.Directory();
275275
return EXIT_SUCCESS;

src/training/dawg2wordlist.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static int WriteDawgAsWordlist(const UNICHARSET &unicharset, const tesseract::Da
6060
FILE *out = fopen(outfile_name, "wb");
6161
if (out == nullptr) {
6262
tprintf("Could not open %s for writing.\n", outfile_name);
63-
return 1;
63+
return EXIT_FAILURE;
6464
}
6565
WordOutputter outputter(out);
6666
using namespace std::placeholders; // for _1
@@ -80,20 +80,20 @@ int main(int argc, char *argv[]) {
8080
"Usage: %s -v | --version | %s <unicharset> <dawgfile> "
8181
"<wordlistfile>\n",
8282
argv[0], argv[0]);
83-
return 1;
83+
return EXIT_FAILURE;
8484
}
8585
const char *unicharset_file = argv[1];
8686
const char *dawg_file = argv[2];
8787
const char *wordlist_file = argv[3];
8888
UNICHARSET unicharset;
8989
if (!unicharset.load_from_file(unicharset_file)) {
9090
tprintf("Error loading unicharset from %s.\n", unicharset_file);
91-
return 1;
91+
return EXIT_FAILURE;
9292
}
9393
auto dict = LoadSquishedDawg(unicharset, dawg_file);
9494
if (dict == nullptr) {
9595
tprintf("Error loading dictionary from %s.\n", dawg_file);
96-
return 1;
96+
return EXIT_FAILURE;
9797
}
9898
int retval = WriteDawgAsWordlist(unicharset, dict.get(), wordlist_file);
9999
return retval;

src/training/lstmeval.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,38 @@ int main(int argc, char **argv) {
3434
ParseArguments(&argc, &argv);
3535
if (FLAGS_model.empty()) {
3636
tprintf("Must provide a --model!\n");
37-
return 1;
37+
return EXIT_FAILURE;
3838
}
3939
if (FLAGS_eval_listfile.empty()) {
4040
tprintf("Must provide a --eval_listfile!\n");
41-
return 1;
41+
return EXIT_FAILURE;
4242
}
4343
tesseract::TessdataManager mgr;
4444
if (!mgr.Init(FLAGS_model.c_str())) {
4545
if (FLAGS_traineddata.empty()) {
4646
tprintf("Must supply --traineddata to eval a training checkpoint!\n");
47-
return 1;
47+
return EXIT_FAILURE;
4848
}
4949
tprintf("%s is not a recognition model, trying training checkpoint...\n", FLAGS_model.c_str());
5050
if (!mgr.Init(FLAGS_traineddata.c_str())) {
5151
tprintf("Failed to load language model from %s!\n", FLAGS_traineddata.c_str());
52-
return 1;
52+
return EXIT_FAILURE;
5353
}
5454
std::vector<char> model_data;
5555
if (!tesseract::LoadDataFromFile(FLAGS_model.c_str(), &model_data)) {
5656
tprintf("Failed to load model from: %s\n", FLAGS_model.c_str());
57-
return 1;
57+
return EXIT_FAILURE;
5858
}
5959
mgr.OverwriteEntry(tesseract::TESSDATA_LSTM, &model_data[0], model_data.size());
6060
}
6161
tesseract::LSTMTester tester(static_cast<int64_t>(FLAGS_max_image_MB) * 1048576);
6262
if (!tester.LoadAllEvalData(FLAGS_eval_listfile.c_str())) {
6363
tprintf("Failed to load eval data from: %s\n", FLAGS_eval_listfile.c_str());
64-
return 1;
64+
return EXIT_FAILURE;
6565
}
6666
double errs = 0.0;
6767
std::string result = tester.RunEvalSync(0, &errs, mgr,
6868
/*training_stage (irrelevant)*/ 0, FLAGS_verbosity);
6969
tprintf("%s\n", result.c_str());
70-
return 0;
70+
return EXIT_SUCCESS;
7171
} /* main */

src/training/merge_unicharsets.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ int main(int argc, char **argv) {
2424

2525
if (argc > 1 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))) {
2626
printf("%s\n", tesseract::TessBaseAPI::Version());
27-
return 0;
27+
return EXIT_SUCCESS;
2828
} else if (argc < 4) {
2929
// Print usage
3030
printf(
3131
"Usage: %s -v | --version |\n"
3232
" %s unicharset-in-1 ... unicharset-in-n unicharset-out\n",
3333
argv[0], argv[0]);
34-
return 1;
34+
return EXIT_FAILURE;
3535
}
3636

3737
tesseract::UNICHARSET input_unicharset, result_unicharset;
@@ -42,7 +42,7 @@ int main(int argc, char **argv) {
4242
result_unicharset.AppendOtherUnicharset(input_unicharset);
4343
} else {
4444
printf("Failed to load unicharset from file %s!!\n", argv[arg]);
45-
exit(1);
45+
return EXIT_FAILURE;
4646
}
4747
}
4848

@@ -51,7 +51,7 @@ int main(int argc, char **argv) {
5151
printf("Wrote unicharset file %s.\n", argv[argc - 1]);
5252
} else {
5353
printf("Cannot save unicharset file %s.\n", argv[argc - 1]);
54-
exit(1);
54+
return EXIT_FAILURE;
5555
}
56-
return 0;
56+
return EXIT_SUCCESS;
5757
}

src/training/mftraining.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ int main(int argc, char **argv) {
201201
// Load the training data.
202202
auto trainer = tesseract::LoadTrainingData(argv + 1, false, &shape_table, file_prefix);
203203
if (trainer == nullptr) {
204-
return 1; // Failed.
204+
return EXIT_FAILURE; // Failed.
205205
}
206206

207207
// Setup an index mapping from the shapes in the shape table to the classes
@@ -269,5 +269,5 @@ int main(int argc, char **argv) {
269269
;
270270
}
271271
}
272-
return 0;
272+
return EXIT_SUCCESS;
273273
} /* main */

src/training/set_unicharset_properties.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ int main(int argc, char **argv) {
2929
// Check validity of input flags.
3030
if (FLAGS_U.empty() || FLAGS_O.empty()) {
3131
tprintf("Specify both input and output unicharsets!\n");
32-
exit(1);
32+
return EXIT_FAILURE;
3333
}
3434
if (FLAGS_script_dir.empty()) {
3535
tprintf("Must specify a script_dir!\n");
36-
exit(1);
36+
return EXIT_FAILURE;
3737
}
3838

3939
tesseract::SetPropertiesForInputFile(FLAGS_script_dir.c_str(), FLAGS_U.c_str(), FLAGS_O.c_str(),
4040
FLAGS_X.c_str());
41-
return 0;
41+
return EXIT_SUCCESS;
4242
}

0 commit comments

Comments
 (0)