@@ -75,51 +75,29 @@ void TessdataManager::LoadFileLater(const char *data_file_name) {
75
75
#if defined(HAVE_LIBARCHIVE)
76
76
bool TessdataManager::LoadArchiveFile (const char *filename) {
77
77
bool result = false ;
78
- #ifndef NDEBUG
79
- tprintf (" TessdataManager::%s(%s)\n " , __func__, filename);
80
- #endif
81
78
archive *a = archive_read_new ();
82
79
if (a != nullptr ) {
83
- archive_read_support_filter_all (a); // new
80
+ archive_read_support_filter_all (a);
84
81
archive_read_support_format_all (a);
85
- std::string zipfile (filename);
86
- bool found = false ;
87
- if (archive_read_open_filename (a, zipfile.c_str (), 4096 ) == ARCHIVE_OK) {
88
- found = true ;
89
- } else {
90
- archive_read_free (a);
91
- zipfile += " .zip" ;
92
- a = archive_read_new ();
93
- archive_read_support_filter_all (a);
94
- archive_read_support_format_all (a);
95
- if (archive_read_open_filename (a, zipfile.c_str (), 4096 ) == ARCHIVE_OK) {
96
- found = true ;
97
- }
98
- }
99
- if (found) {
100
- archive_entry *ae;
101
- while (archive_read_next_header (a, &ae) == ARCHIVE_OK) {
102
- const char *fileName = archive_entry_pathname (ae);
82
+ if (archive_read_open_filename (a, filename, 4096 ) == ARCHIVE_OK) {
83
+ archive_entry *ae;
84
+ while (archive_read_next_header (a, &ae) == ARCHIVE_OK) {
85
+ const char *component = archive_entry_pathname (ae);
86
+ if (component != nullptr ) {
103
87
TessdataType type;
104
- if (fileName != nullptr &&
105
- TessdataTypeFromFileName (fileName, &type)) {
106
- #if !defined(NDEBUG)
107
- tprintf (" TessdataTypeFromFileName(%s, ...) passed, type %d\n " ,
108
- fileName, type);
109
- #endif
88
+ if (TessdataTypeFromFileName (component, &type)) {
110
89
int64_t size = archive_entry_size (ae);
111
90
if (size > 0 ) {
112
91
entries_[type].resize_no_init (size);
113
92
if (archive_read_data (a, &entries_[type][0 ], size) == size) {
93
+ is_loaded_ = true ;
114
94
}
115
95
}
116
96
}
117
97
}
118
- is_loaded_ = true ;
119
- result = true ;
120
98
}
121
- archive_read_close (a) ;
122
- // ~ }
99
+ result = is_loaded_ ;
100
+ }
123
101
archive_read_free (a);
124
102
}
125
103
return result;
@@ -129,46 +107,24 @@ bool TessdataManager::LoadArchiveFile(const char *filename) {
129
107
#if defined(HAVE_LIBZIP)
130
108
bool TessdataManager::LoadZipFile (const char *filename) {
131
109
bool result = false ;
132
- #ifndef NDEBUG
133
- tprintf (" TessdataManager::%s(%s)\n " , __func__, filename);
134
- #endif
135
- std::string zipfile (filename);
136
110
int err;
137
- zip_t *uf = zip_open (zipfile.c_str (), ZIP_RDONLY, &err);
138
- if (uf == nullptr ) {
139
- zipfile += " .zip" ;
140
- uf = zip_open (zipfile.c_str (), ZIP_RDONLY, &err);
141
- }
111
+ zip_t *uf = zip_open (filename, ZIP_RDONLY, &err);
142
112
if (uf != nullptr ) {
143
- #ifndef NDEBUG
144
- tprintf (" zip_open(%s) passed\n " , zipfile.c_str ());
145
- #endif
146
113
int64_t nEntries = zip_get_num_entries (uf, ZIP_FL_UNCHANGED);
147
114
for (int i = 0 ; i < nEntries; i++) {
148
115
zip_stat_t zipStat;
149
116
if (zip_stat_index (uf, i, ZIP_FL_UNCHANGED, &zipStat) == 0 &&
150
117
(zipStat.valid & ZIP_STAT_NAME) && (zipStat.valid & ZIP_STAT_SIZE)) {
151
- #ifndef NDEBUG
152
- tprintf (" zip_get_name(...) passed, file %s\n " , zipStat.name );
153
- #endif
154
118
TessdataType type;
155
119
if (TessdataTypeFromFileName (zipStat.name , &type)) {
156
- #ifndef NDEBUG
157
- tprintf (" TessdataTypeFromFileName(%s, ...) passed, type %d\n " ,
158
- zipStat.name , type);
159
- #endif
160
120
zip_file_t *zipFile = zip_fopen_index (uf, i, ZIP_FL_UNCHANGED);
161
121
if (zipFile == nullptr ) {
162
- #ifndef NDEBUG
163
122
tprintf (" zip_fopen_index(...) failed\n " );
164
- #endif
165
123
} else {
166
124
entries_[type].resize_no_init (zipStat.size );
167
125
if (zip_fread (zipFile, &entries_[type][0 ], zipStat.size ) !=
168
126
static_cast <int64_t >(zipStat.size )) {
169
- #ifndef NDEBUG
170
127
tprintf (" zip_fread(...) failed\n " );
171
- #endif
172
128
}
173
129
zip_fclose (zipFile);
174
130
}
@@ -178,15 +134,9 @@ bool TessdataManager::LoadZipFile(const char *filename) {
178
134
is_loaded_ = true ;
179
135
err = zip_close (uf);
180
136
if (err != 0 ) {
181
- #ifndef NDEBUG
182
137
tprintf (" zip_close(...) failed\n " );
183
- #endif
184
138
}
185
139
result = true ;
186
- } else {
187
- #ifndef NDEBUG
188
- tprintf (" zip_open(%s) failed\n " , zipfile.c_str ());
189
- #endif
190
140
}
191
141
return result;
192
142
}
@@ -195,95 +145,56 @@ bool TessdataManager::LoadZipFile(const char *filename) {
195
145
#if defined(HAVE_MINIZIP)
196
146
bool TessdataManager::LoadMinizipFile (const char *filename) {
197
147
bool result = false ;
198
- #ifndef NDEBUG
199
- tprintf (" TessdataManager::%s(%s)\n " , __func__, filename);
200
- #endif
201
- std::string zipfile (filename);
202
- unzFile uf = unzOpen (zipfile.c_str ());
203
- if (uf == nullptr ) {
204
- zipfile += " .zip" ;
205
- uf = unzOpen (zipfile.c_str ());
206
- }
148
+ unzFile uf = unzOpen (filename);
207
149
if (uf != nullptr ) {
208
- #ifndef NDEBUG
209
- tprintf (" unzOpen(%s) passed\n " , zipfile.c_str ());
210
- #endif
211
150
unz_global_info global_info;
212
151
int err;
213
152
err = unzGetGlobalInfo (uf, &global_info);
214
153
if (err == UNZ_OK) {
215
- #ifndef NDEBUG
216
- tprintf (" unzGetGlobalInfo(...) passed, zip file with %lu entries\n " ,
217
- global_info.number_entry );
218
- #endif
219
154
}
220
155
unz_file_info file_info;
221
- char fileName [32 ];
156
+ char component [32 ];
222
157
char extraField[32 ];
223
158
char comment[32 ];
224
159
// ~ $1 = {version = 798, version_needed = 20, flag = 0, compression_method = 8, dosDate = 1252768343, crc = 2481269679, compressed_size = 7131663, uncompressed_size = 16109842,
225
160
// ~ size_filename = 15, size_file_extra = 24, size_file_comment = 0, disk_num_start = 0, internal_fa = 0, external_fa = 2175008768, tmu_date = {tm_sec = 46, tm_min = 18,
226
161
// ~ tm_hour = 23, tm_mday = 11, tm_mon = 4, tm_year = 2017}}
227
162
for (unsigned i = 0 ; i < global_info.number_entry ; i++) {
228
163
err = unzGetCurrentFileInfo (uf, &file_info,
229
- fileName , sizeof (fileName ),
164
+ component , sizeof (component ),
230
165
extraField, sizeof (extraField),
231
166
comment, sizeof (comment));
232
167
if (err == UNZ_OK) {
233
- #ifndef NDEBUG
234
- tprintf (" unzGetCurrentFileInfo(...) passed, file %s, %lu byte\n " ,
235
- fileName, file_info.uncompressed_size );
236
- #endif
237
168
TessdataType type;
238
- if (TessdataTypeFromFileName (fileName, &type)) {
239
- #ifndef NDEBUG
240
- tprintf (" TessdataTypeFromFileName(%s, ...) passed, type %d\n " ,
241
- fileName, type);
242
- #endif
169
+ if (TessdataTypeFromFileName (component, &type)) {
243
170
err = unzOpenCurrentFilePassword (uf, nullptr );
244
171
if (err != UNZ_OK) {
245
- #ifndef NDEBUG
246
172
tprintf (" unzOpenCurrentFilePassword(...) failed, err %d\n " , err);
247
- #endif
248
173
} else {
249
174
entries_[type].resize_no_init (file_info.uncompressed_size );
250
175
err = unzReadCurrentFile (uf, &entries_[type][0 ], file_info.uncompressed_size );
251
176
if (err < UNZ_OK) {
252
- #ifndef NDEBUG
253
177
tprintf (" unzReadCurrentFile(...) failed, err %d\n " , err);
254
- #endif
255
178
}
256
179
err = unzCloseCurrentFile (uf);
257
180
if (err != UNZ_OK) {
258
- #ifndef NDEBUG
259
181
tprintf (" unzCloseCurrentFile(...) failed\n " );
260
- #endif
261
182
}
262
183
}
263
184
}
264
185
}
265
- // ~ err = unzGoToFirstFile(uf);
266
186
267
187
err = unzGoToNextFile (uf);
268
188
if (err != UNZ_OK) {
269
- #ifndef NDEBUG
270
189
tprintf (" unzGoToNextFile(...) failed\n " );
271
- #endif
272
190
}
273
191
}
274
192
is_loaded_ = true ;
275
193
err = unzClose (uf);
276
194
if (err != UNZ_OK) {
277
- #ifndef NDEBUG
278
195
tprintf (" unzClose(...) failed\n " );
279
- #endif
280
196
}
281
197
result = true ;
282
- } else {
283
- #ifndef NDEBUG
284
- tprintf (" unzOpen(%s) failed\n " , zipfile.c_str ());
285
- perror (zipfile.c_str ());
286
- #endif
287
198
}
288
199
return result;
289
200
}
@@ -292,28 +203,19 @@ bool TessdataManager::LoadMinizipFile(const char *filename) {
292
203
#if defined(HAVE_ZZIPLIB)
293
204
bool TessdataManager::LoadZzipFile (const char *filename) {
294
205
bool result = false ;
295
- #ifndef NDEBUG
296
- tprintf (" TessdataManager::%s(%s)\n " , __func__, filename);
297
- #endif
298
206
zzip_error_t err;
299
207
ZZIP_DIR *dir = zzip_dir_open (filename, &err);
300
208
if (dir != nullptr ) {
301
209
ZZIP_DIRENT d;
302
210
while (zzip_dir_read (dir, &d)) {
303
211
TessdataType type;
304
212
if (TessdataTypeFromFileName (d.d_name , &type)) {
305
- #ifndef NDEBUG
306
- tprintf (" TessdataTypeFromFileName(%s, ...) passed, type %d\n " ,
307
- d.d_name , type);
308
- #endif
309
213
ZZIP_FILE *f = zzip_file_open (dir, d.d_name , 0 );
310
214
if (f != nullptr ) {
311
215
entries_[type].resize_no_init (d.st_size );
312
216
ssize_t len = zzip_file_read (f, &entries_[type][0 ], d.st_size );
313
217
if (len != d.st_size ) {
314
- #ifndef NDEBUG
315
218
tprintf (" zzip_file_read(...) failed\n " );
316
- #endif
317
219
}
318
220
zzip_file_close (f);
319
221
}
@@ -328,9 +230,6 @@ bool TessdataManager::LoadZzipFile(const char *filename) {
328
230
#endif
329
231
330
232
bool TessdataManager::Init (const char *data_file_name) {
331
- #ifndef NDEBUG
332
- tprintf (" TessdataManager::%s(%s)\n " , __func__, data_file_name);
333
- #endif
334
233
GenericVector<char > data;
335
234
if (reader_ == nullptr ) {
336
235
const char *tessarchive = getenv (" TESSARCHIVE" );
@@ -495,7 +394,6 @@ bool TessdataManager::CombineDataFiles(
495
394
const char *language_data_path_prefix,
496
395
const char *output_filename) {
497
396
// Load individual tessdata components from files.
498
- // TODO: This method supports only the proprietary file format.
499
397
for (int i = 0 ; i < TESSDATA_NUM_ENTRIES; ++i) {
500
398
TessdataType type;
501
399
ASSERT_HOST (TessdataTypeFromFileSuffix (kTessdataFileSuffixes [i], &type));
0 commit comments