Skip to content

Commit cb1b4b9

Browse files
committed
Allow simultaneous support of different archive libraries
Signed-off-by: Stefan Weil <[email protected]>
1 parent 4a8a26f commit cb1b4b9

File tree

5 files changed

+61
-38
lines changed

5 files changed

+61
-38
lines changed

src/api/Makefile.am

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,16 @@ tesseract_LDADD += $(LEPTONICA_LIBS)
7676
tesseract_LDADD += $(OPENMP_CXXFLAGS)
7777
if HAVE_LIBARCHIVE
7878
tesseract_LDADD += $(libarchive_LIBS)
79-
else
79+
endif
8080
if HAVE_LIBZIP
8181
tesseract_LDADD += $(libzip_LIBS)
82-
else
82+
endif
8383
if HAVE_MINIZIP
8484
tesseract_LDADD += $(minizip_LIBS)
85-
else
85+
endif
8686
if HAVE_ZZIPLIB
8787
tesseract_LDADD += $(zziplib_LIBS)
8888
endif
89-
endif
90-
endif
91-
endif
9289

9390
if T_WIN
9491
tesseract_LDADD += -ltiff

src/ccutil/Makefile.am

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,16 @@ libtesseract_ccutil_la_SOURCES = \
4040

4141
if HAVE_LIBARCHIVE
4242
AM_CPPFLAGS += $(libarchive_CFLAGS)
43-
else
43+
endif
4444
if HAVE_LIBZIP
4545
AM_CPPFLAGS += $(libzip_CFLAGS)
46-
else
46+
endif
4747
if HAVE_MINIZIP
4848
AM_CPPFLAGS += $(minizip_CFLAGS)
49-
else
49+
endif
5050
if HAVE_ZZIPLIB
5151
AM_CPPFLAGS += $(zziplib_CFLAGS)
5252
endif
53-
endif
54-
endif
55-
endif
5653

5754
if T_WIN
5855
AM_CPPFLAGS += -DWINDLLNAME=\"lib@GENERIC_LIBRARY_NAME@\"

src/ccutil/tessdatamanager.cpp

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,21 @@
2929
#if defined(HAVE_LIBARCHIVE)
3030
#include <archive.h>
3131
#include <archive_entry.h>
32-
#elif defined(HAVE_LIBZIP)
32+
#endif
33+
#if defined(HAVE_LIBZIP)
34+
#if defined(HAVE_MINIZIP)
35+
// libminizip provides minizip/zip.h. Hack to get the right one.
36+
#include "/usr/include/zip.h"
37+
#else
3338
#include <zip.h>
34-
#elif defined(HAVE_MINIZIP)
39+
#endif
40+
#endif
41+
#if defined(HAVE_MINIZIP)
3542
#include <unzip.h>
36-
#elif defined(HAVE_ZZIPLIB)
43+
#endif
44+
#if defined(HAVE_ZZIPLIB)
3745
#include <zzip/lib.h>
38-
#endif // ZIP supported
46+
#endif
3947

4048
#include "errcode.h"
4149
#include "helpers.h"
@@ -65,7 +73,7 @@ void TessdataManager::LoadFileLater(const char *data_file_name) {
6573
}
6674

6775
#if defined(HAVE_LIBARCHIVE)
68-
bool TessdataManager::LoadZipFile(const char *filename) {
76+
bool TessdataManager::LoadArchiveFile(const char *filename) {
6977
bool result = false;
7078
#ifndef NDEBUG
7179
tprintf("TessdataManager::%s(%s)\n", __func__, filename);
@@ -116,7 +124,9 @@ bool TessdataManager::LoadZipFile(const char *filename) {
116124
}
117125
return result;
118126
}
119-
#elif defined(HAVE_LIBZIP)
127+
#endif
128+
129+
#if defined(HAVE_LIBZIP)
120130
bool TessdataManager::LoadZipFile(const char *filename) {
121131
bool result = false;
122132
#ifndef NDEBUG
@@ -180,8 +190,10 @@ bool TessdataManager::LoadZipFile(const char *filename) {
180190
}
181191
return result;
182192
}
183-
#elif defined(HAVE_MINIZIP)
184-
bool TessdataManager::LoadZipFile(const char *filename) {
193+
#endif
194+
195+
#if defined(HAVE_MINIZIP)
196+
bool TessdataManager::LoadMinizipFile(const char *filename) {
185197
bool result = false;
186198
#ifndef NDEBUG
187199
tprintf("TessdataManager::%s(%s)\n", __func__, filename);
@@ -275,8 +287,10 @@ bool TessdataManager::LoadZipFile(const char *filename) {
275287
}
276288
return result;
277289
}
278-
#elif defined(HAVE_ZZIPLIB)
279-
bool TessdataManager::LoadZipFile(const char *filename) {
290+
#endif
291+
292+
#if defined(HAVE_ZZIPLIB)
293+
bool TessdataManager::LoadZzipFile(const char *filename) {
280294
bool result = false;
281295
#ifndef NDEBUG
282296
tprintf("TessdataManager::%s(%s)\n", __func__, filename);
@@ -311,19 +325,31 @@ bool TessdataManager::LoadZipFile(const char *filename) {
311325
}
312326
return result;
313327
}
314-
#else
315-
#define HAVE_NOZIP
316-
#endif // ZIP supported
328+
#endif
317329

318330
bool TessdataManager::Init(const char *data_file_name) {
319331
#ifndef NDEBUG
320332
tprintf("TessdataManager::%s(%s)\n", __func__, data_file_name);
321333
#endif
322334
GenericVector<char> data;
323335
if (reader_ == nullptr) {
324-
#if !defined(HAVE_NOZIP)
336+
const char *tessarchive = getenv("TESSARCHIVE");
337+
#if defined(HAVE_LIBARCHIVE)
338+
if (tessarchive == nullptr || strcmp(tessarchive, "libarchive") == 0)
339+
if (LoadArchiveFile(data_file_name)) return true;
340+
#endif
341+
#if defined(HAVE_MINIZIP)
342+
if (tessarchive == nullptr || strcmp(tessarchive, "libminizip") == 0)
325343
if (LoadZipFile(data_file_name)) return true;
326344
#endif // HAVE_MINIZIP
345+
#if defined(HAVE_LIBZIP)
346+
if (tessarchive == nullptr || strcmp(tessarchive, "libzip") == 0)
347+
if (LoadZipFile(data_file_name)) return true;
348+
#endif // HAVE_MINIZIP
349+
#if defined(HAVE_ZZIPLIB)
350+
if (tessarchive == nullptr || strcmp(tessarchive, "libzzip") == 0)
351+
if (LoadZzipFile(data_file_name)) return true;
352+
#endif
327353
if (!LoadDataFromFile(data_file_name, &data)) return false;
328354
} else {
329355
if (!(*reader_)(data_file_name, &data)) return false;

src/ccutil/tessdatamanager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,14 @@ class TessdataManager {
219219

220220
private:
221221

222+
// Use libarchive.
223+
bool LoadArchiveFile(const char *filename);
224+
// Use libminizip.
225+
bool LoadMinizipFile(const char *filename);
226+
// Use libzip.
222227
bool LoadZipFile(const char *filename);
228+
// Use libzzip.
229+
bool LoadZzipFile(const char *filename);
223230

224231
/**
225232
* Fills type with TessdataType of the tessdata component represented by the

src/training/Makefile.am

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,22 +278,18 @@ text2image_LDADD += $(LEPTONICA_LIBS)
278278
unicharset_extractor_LDADD += $(LEPTONICA_LIBS)
279279
wordlist2dawg_LDADD += $(LEPTONICA_LIBS)
280280

281-
if HAVE_LIBARCHIVE
282-
extralib = $(libarchive_LIBS)
283-
else
284-
if HAVE_LIBZIP
285-
extralib = $(libzip_LIBS)
286-
else
287-
if HAVE_MINIZIP
288-
extralib = $(minizip_LIBS)
289-
else
290-
if HAVE_ZZIPLIB
291-
extralib = $(zziplib_LIBS)
292-
else
293281
extralib =
282+
if HAVE_LIBARCHIVE
283+
extralib += $(libarchive_LIBS)
294284
endif
285+
if HAVE_LIBZIP
286+
extralib += $(libzip_LIBS)
295287
endif
288+
if HAVE_MINIZIP
289+
extralib += $(minizip_LIBS)
296290
endif
291+
if HAVE_ZZIPLIB
292+
extralib += $(zziplib_LIBS)
297293
endif
298294

299295
ambiguous_words_LDADD += $(extralib)

0 commit comments

Comments
 (0)