@@ -72,7 +72,7 @@ int main(int argc, char **argv) {
72
72
tesseract::TessdataManager tm ;
73
73
if (argc > 1 && (!strcmp (argv[1 ], " -v" ) || !strcmp (argv[1 ], " --version" ))) {
74
74
printf (" %s\n " , tesseract::TessBaseAPI::Version ());
75
- return 0 ;
75
+ return EXIT_SUCCESS ;
76
76
} else if (argc == 2 ) {
77
77
printf (" Combining tessdata files\n " );
78
78
STRING lang = argv[1 ];
@@ -92,16 +92,22 @@ int main(int argc, char **argv) {
92
92
// Initialize TessdataManager with the data in the given traineddata file.
93
93
if (!tm .Init (argv[2 ])) {
94
94
tprintf (" Failed to read %s\n " , argv[2 ]);
95
- exit ( 1 ) ;
95
+ return EXIT_FAILURE ;
96
96
}
97
97
printf (" Extracting tessdata components from %s\n " , argv[2 ]);
98
98
if (strcmp (argv[1 ], " -e" ) == 0 ) {
99
99
for (i = 3 ; i < argc; ++i) {
100
+ errno = 0 ;
100
101
if (tm .ExtractToFile (argv[i])) {
101
102
printf (" Wrote %s\n " , argv[i]);
102
- } else {
103
+ } else if (errno == 0 ) {
103
104
printf (" Not extracting %s, since this component"
104
105
" is not present\n " , argv[i]);
106
+ return EXIT_FAILURE;
107
+ } else {
108
+ printf (" Error, could not extract %s: %s\n " ,
109
+ argv[i], strerror (errno));
110
+ return EXIT_FAILURE;
105
111
}
106
112
}
107
113
} else { // extract all the components
@@ -111,8 +117,13 @@ int main(int argc, char **argv) {
111
117
if (*last != ' .' )
112
118
filename += ' .' ;
113
119
filename += tesseract::kTessdataFileSuffixes [i];
120
+ errno = 0 ;
114
121
if (tm .ExtractToFile (filename.string ())) {
115
122
printf (" Wrote %s\n " , filename.string ());
123
+ } else if (errno != 0 ) {
124
+ printf (" Error, could not extract %s: %s\n " ,
125
+ filename.string (), strerror (errno));
126
+ return EXIT_FAILURE;
116
127
}
117
128
}
118
129
}
@@ -124,7 +135,7 @@ int main(int argc, char **argv) {
124
135
if (rename (new_traineddata_filename, traineddata_filename.string ()) != 0 ) {
125
136
tprintf (" Failed to create a temporary file %s\n " ,
126
137
traineddata_filename.string ());
127
- exit ( 1 ) ;
138
+ return EXIT_FAILURE ;
128
139
}
129
140
130
141
// Initialize TessdataManager with the data in the given traineddata file.
@@ -135,17 +146,17 @@ int main(int argc, char **argv) {
135
146
} else if (argc == 3 && strcmp (argv[1 ], " -c" ) == 0 ) {
136
147
if (!tm .Init (argv[2 ])) {
137
148
tprintf (" Failed to read %s\n " , argv[2 ]);
138
- exit ( 1 ) ;
149
+ return EXIT_FAILURE ;
139
150
}
140
151
tesseract::TFile fp;
141
152
if (!tm .GetComponent (tesseract::TESSDATA_LSTM, &fp)) {
142
153
tprintf (" No LSTM Component found in %s!\n " , argv[2 ]);
143
- exit ( 1 ) ;
154
+ return EXIT_FAILURE ;
144
155
}
145
156
tesseract::LSTMRecognizer recognizer;
146
157
if (!recognizer.DeSerialize (&tm , &fp)) {
147
158
tprintf (" Failed to deserialize LSTM in %s!\n " , argv[2 ]);
148
- exit ( 1 ) ;
159
+ return EXIT_FAILURE ;
149
160
}
150
161
recognizer.ConvertToInt ();
151
162
GenericVector<char > lstm_data;
@@ -155,7 +166,7 @@ int main(int argc, char **argv) {
155
166
lstm_data.size ());
156
167
if (!tm .SaveFile (argv[2 ], nullptr )) {
157
168
tprintf (" Failed to write modified traineddata:%s!\n " , argv[2 ]);
158
- exit ( 1 ) ;
169
+ return EXIT_FAILURE ;
159
170
}
160
171
} else if (argc == 3 && strcmp (argv[1 ], " -d" ) == 0 ) {
161
172
// Initialize TessdataManager with the data in the given traineddata file.
@@ -186,4 +197,5 @@ int main(int argc, char **argv) {
186
197
return 1 ;
187
198
}
188
199
tm .Directory ();
200
+ return EXIT_SUCCESS;
189
201
}
0 commit comments