diff --git a/src/cli.c b/src/cli.c index 7580fef..d0663df 100644 --- a/src/cli.c +++ b/src/cli.c @@ -15,6 +15,13 @@ #define DEFAULT_BIND_ADDR "localhost" #define DEFAULT_PORT "4090" +const char* TESS_DATAPATHS[] = { + "/usr/share/tessdata/", + "/usr/share/tesseract-ocr/tessdata/", + "./", + NULL +}; + scan_args_t *scan_args_create() { scan_args_t *args = calloc(sizeof(scan_args_t), 1); @@ -136,13 +143,23 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) { if (args->tesseract_lang != NULL) { TessBaseAPI *api = TessBaseAPICreate(); - ret = TessBaseAPIInit3(api, TESS_DATAPATH, args->tesseract_lang); + + char filename[128]; + sprintf(filename, "%s.traineddata", args->tesseract_lang); + const char * path = find_file_in_paths(TESS_DATAPATHS, filename); + if (path == NULL) { + LOG_FATAL("cli.c", "Could not find tesseract language file!"); + } + + ret = TessBaseAPIInit3(api, path, args->tesseract_lang); if (ret != 0) { fprintf(stderr, "Could not initialize tesseract with lang '%s'\n", args->tesseract_lang); return 1; } TessBaseAPIEnd(api); TessBaseAPIDelete(api); + + args->tesseract_path = path; } LOG_DEBUGF("cli.c", "arg quality=%f", args->quality) @@ -156,7 +173,8 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) { LOG_DEBUGF("cli.c", "arg depth=%d", args->depth) LOG_DEBUGF("cli.c", "arg path=%s", args->path) LOG_DEBUGF("cli.c", "arg archive=%s", args->archive) - LOG_DEBUGF("cli.c", "arg ocr=%s", args->tesseract_lang) + LOG_DEBUGF("cli.c", "arg tesseract_lang=%s", args->tesseract_lang) + LOG_DEBUGF("cli.c", "arg tesseract_path=%s", args->tesseract_path) return 0; } diff --git a/src/cli.h b/src/cli.h index b12c840..f0eb163 100644 --- a/src/cli.h +++ b/src/cli.h @@ -17,6 +17,7 @@ typedef struct scan_args { char *archive; archive_mode_t archive_mode; char *tesseract_lang; + const char *tesseract_path; } scan_args_t; scan_args_t *scan_args_create(); diff --git a/src/ctx.h b/src/ctx.h index 19f769c..b841c47 100644 --- a/src/ctx.h +++ b/src/ctx.h @@ -28,6 +28,7 @@ struct { pthread_mutex_t mupdf_mu; char * tesseract_lang; + char * tesseract_path; } ScanCtx; struct { diff --git a/src/index/static_generated.c b/src/index/static_generated.c index 39fd485..38c3669 100644 --- a/src/index/static_generated.c +++ b/src/index/static_generated.c @@ -1,2 +1,2 @@ -char mappings_json[1982] = {123,10,32,32,34,112,114,111,112,101,114,116,105,101,115,34,58,32,123,10,32,32,32,32,34,112,97,116,104,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,44,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,112,97,116,104,95,97,110,97,108,121,122,101,114,34,44,10,32,32,32,32,32,32,34,99,111,112,121,95,116,111,34,58,32,34,115,117,103,103,101,115,116,45,112,97,116,104,34,10,32,32,32,32,125,44,10,32,32,32,32,34,115,117,103,103,101,115,116,45,112,97,116,104,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,99,111,109,112,108,101,116,105,111,110,34,44,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,107,101,121,119,111,114,100,34,10,32,32,32,32,125,44,10,32,32,32,32,34,109,105,109,101,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,107,101,121,119,111,114,100,34,10,32,32,32,32,125,44,10,32,32,32,32,34,118,105,100,101,111,99,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,107,101,121,119,111,114,100,34,44,10,32,32,32,32,32,32,34,105,110,100,101,120,34,58,32,102,97,108,115,101,10,32,32,32,32,125,44,10,32,32,32,32,34,97,117,100,105,111,99,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,107,101,121,119,111,114,100,34,44,10,32,32,32,32,32,32,34,105,110,100,101,120,34,58,32,102,97,108,115,101,10,32,32,32,32,125,44,10,32,32,32,32,34,100,117,114,97,116,105,111,110,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,102,108,111,97,116,34,44,10,32,32,32,32,32,32,34,105,110,100,101,120,34,58,32,102,97,108,115,101,10,32,32,32,32,125,44,10,32,32,32,32,34,119,105,100,116,104,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,105,110,116,101,103,101,114,34,44,10,32,32,32,32,32,32,34,105,110,100,101,120,34,58,32,102,97,108,115,101,10,32,32,32,32,125,44,10,32,32,32,32,34,104,101,105,103,104,116,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,105,110,116,101,103,101,114,34,44,10,32,32,32,32,32,32,34,105,110,100,101,120,34,58,32,102,97,108,115,101,10,32,32,32,32,125,44,10,32,32,32,32,34,109,116,105,109,101,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,105,110,116,101,103,101,114,34,10,32,32,32,32,125,44,10,32,32,32,32,34,115,105,122,101,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,108,111,110,103,34,10,32,32,32,32,125,44,10,32,32,32,32,34,105,110,100,101,120,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,107,101,121,119,111,114,100,34,10,32,32,32,32,125,44,10,32,32,32,32,34,110,97,109,101,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,99,111,110,116,101,110,116,95,97,110,97,108,121,122,101,114,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,44,10,32,32,32,32,32,32,34,102,105,101,108,100,115,34,58,32,123,10,32,32,32,32,32,32,32,32,34,110,71,114,97,109,34,58,32,123,10,32,32,32,32,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,44,10,32,32,32,32,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,10,32,32,32,32,32,32,32,32,125,10,32,32,32,32,32,32,125,10,32,32,32,32,125,44,10,32,32,32,32,34,102,111,110,116,95,110,97,109,101,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,10,32,32,32,32,125,44,10,32,32,32,32,34,97,108,98,117,109,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,10,32,32,32,32,125,44,10,32,32,32,32,34,97,114,116,105,115,116,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,10,32,32,32,32,125,44,10,32,32,32,32,34,116,105,116,108,101,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,10,32,32,32,32,125,44,10,32,32,32,32,34,103,101,110,114,101,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,10,32,32,32,32,125,44,10,32,32,32,32,34,97,108,98,117,109,95,97,114,116,105,115,116,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,10,32,32,32,32,125,44,10,32,32,32,32,34,95,107,101,121,119,111,114,100,46,42,34,58,32,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,107,101,121,119,111,114,100,34,10,32,32,32,32,125,44,10,32,32,32,32,34,95,116,101,120,116,46,42,34,58,32,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,99,111,110,116,101,110,116,95,97,110,97,108,121,122,101,114,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,44,10,32,32,32,32,32,32,34,102,105,101,108,100,115,34,58,32,123,10,32,32,32,32,32,32,32,32,34,110,71,114,97,109,34,58,32,123,10,32,32,32,32,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,44,10,32,32,32,32,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,10,32,32,32,32,32,32,32,32,125,10,32,32,32,32,32,32,125,10,32,32,32,32,125,44,10,32,32,32,32,34,95,117,114,108,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,107,101,121,119,111,114,100,34,44,10,32,32,32,32,32,32,34,105,110,100,101,120,34,58,32,102,97,108,115,101,10,32,32,32,32,125,44,10,32,32,32,32,34,99,111,110,116,101,110,116,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,99,111,110,116,101,110,116,95,97,110,97,108,121,122,101,114,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,44,10,32,32,32,32,32,32,34,105,110,100,101,120,95,111,112,116,105,111,110,115,34,58,32,34,111,102,102,115,101,116,115,34,44,10,32,32,32,32,32,32,34,102,105,101,108,100,115,34,58,32,123,10,32,32,32,32,32,32,32,32,34,110,71,114,97,109,34,58,32,123,10,32,32,32,32,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,44,10,32,32,32,32,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,10,32,32,32,32,32,32,32,32,125,10,32,32,32,32,32,32,125,10,32,32,32,32,125,44,10,32,32,32,32,34,116,97,103,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,107,101,121,119,111,114,100,34,10,32,32,32,32,125,10,32,32,125,10,125,10}; -char settings_json[752] = {123,10,32,32,34,105,110,100,101,120,34,58,32,123,10,32,32,32,32,34,114,101,102,114,101,115,104,95,105,110,116,101,114,118,97,108,34,58,32,34,51,48,115,34,44,10,32,32,32,32,34,99,111,100,101,99,34,58,32,34,98,101,115,116,95,99,111,109,112,114,101,115,115,105,111,110,34,10,32,32,125,44,10,32,32,34,97,110,97,108,121,115,105,115,34,58,32,123,10,32,32,32,32,34,116,111,107,101,110,105,122,101,114,34,58,32,123,10,32,32,32,32,32,32,34,112,97,116,104,95,116,111,107,101,110,105,122,101,114,34,58,32,123,10,32,32,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,112,97,116,104,95,104,105,101,114,97,114,99,104,121,34,10,32,32,32,32,32,32,125,44,10,32,32,32,32,32,32,34,109,121,95,110,71,114,97,109,95,116,111,107,101,110,105,122,101,114,34,58,32,123,10,32,32,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,110,71,114,97,109,34,44,10,32,32,32,32,32,32,32,32,34,109,105,110,95,103,114,97,109,34,58,32,51,44,10,32,32,32,32,32,32,32,32,34,109,97,120,95,103,114,97,109,34,58,32,51,10,32,32,32,32,32,32,125,10,32,32,32,32,125,44,10,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,123,10,32,32,32,32,32,32,34,112,97,116,104,95,97,110,97,108,121,122,101,114,34,58,32,123,10,32,32,32,32,32,32,32,32,34,116,111,107,101,110,105,122,101,114,34,58,32,34,112,97,116,104,95,116,111,107,101,110,105,122,101,114,34,44,10,32,32,32,32,32,32,32,32,34,102,105,108,116,101,114,34,58,32,91,10,32,32,32,32,32,32,32,32,32,32,34,108,111,119,101,114,99,97,115,101,34,10,32,32,32,32,32,32,32,32,93,10,32,32,32,32,32,32,125,44,10,32,32,32,32,32,32,34,109,121,95,110,71,114,97,109,34,58,32,123,10,32,32,32,32,32,32,32,32,34,116,111,107,101,110,105,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,95,116,111,107,101,110,105,122,101,114,34,44,10,32,32,32,32,32,32,32,32,34,102,105,108,116,101,114,34,58,32,91,10,32,32,32,32,32,32,32,32,32,32,34,108,111,119,101,114,99,97,115,101,34,44,10,32,32,32,32,32,32,32,32,32,32,34,97,115,99,105,105,102,111,108,100,105,110,103,34,10,32,32,32,32,32,32,32,32,93,10,32,32,32,32,32,32,125,44,10,32,32,32,32,32,32,34,99,111,110,116,101,110,116,95,97,110,97,108,121,122,101,114,34,58,32,123,10,32,32,32,32,32,32,32,32,34,116,111,107,101,110,105,122,101,114,34,58,32,34,115,116,97,110,100,97,114,100,34,44,10,32,32,32,32,32,32,32,32,34,102,105,108,116,101,114,34,58,32,91,10,32,32,32,32,32,32,32,32,32,32,34,108,111,119,101,114,99,97,115,101,34,44,10,32,32,32,32,32,32,32,32,32,32,34,97,115,99,105,105,102,111,108,100,105,110,103,34,10,32,32,32,32,32,32,32,32,93,10,32,32,32,32,32,32,125,10,32,32,32,32,125,10,32,32,125,10,125}; +char mappings_json[2003] = {123,10,32,32,34,112,114,111,112,101,114,116,105,101,115,34,58,32,123,10,32,32,32,32,34,112,97,116,104,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,44,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,112,97,116,104,95,97,110,97,108,121,122,101,114,34,44,10,32,32,32,32,32,32,34,99,111,112,121,95,116,111,34,58,32,34,115,117,103,103,101,115,116,45,112,97,116,104,34,10,32,32,32,32,125,44,10,32,32,32,32,34,115,117,103,103,101,115,116,45,112,97,116,104,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,99,111,109,112,108,101,116,105,111,110,34,44,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,99,97,115,101,95,105,110,115,101,110,115,105,116,105,118,101,95,107,119,95,97,110,97,108,121,122,101,114,34,10,32,32,32,32,125,44,10,32,32,32,32,34,109,105,109,101,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,107,101,121,119,111,114,100,34,10,32,32,32,32,125,44,10,32,32,32,32,34,118,105,100,101,111,99,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,107,101,121,119,111,114,100,34,44,10,32,32,32,32,32,32,34,105,110,100,101,120,34,58,32,102,97,108,115,101,10,32,32,32,32,125,44,10,32,32,32,32,34,97,117,100,105,111,99,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,107,101,121,119,111,114,100,34,44,10,32,32,32,32,32,32,34,105,110,100,101,120,34,58,32,102,97,108,115,101,10,32,32,32,32,125,44,10,32,32,32,32,34,100,117,114,97,116,105,111,110,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,102,108,111,97,116,34,44,10,32,32,32,32,32,32,34,105,110,100,101,120,34,58,32,102,97,108,115,101,10,32,32,32,32,125,44,10,32,32,32,32,34,119,105,100,116,104,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,105,110,116,101,103,101,114,34,44,10,32,32,32,32,32,32,34,105,110,100,101,120,34,58,32,102,97,108,115,101,10,32,32,32,32,125,44,10,32,32,32,32,34,104,101,105,103,104,116,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,105,110,116,101,103,101,114,34,44,10,32,32,32,32,32,32,34,105,110,100,101,120,34,58,32,102,97,108,115,101,10,32,32,32,32,125,44,10,32,32,32,32,34,109,116,105,109,101,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,105,110,116,101,103,101,114,34,10,32,32,32,32,125,44,10,32,32,32,32,34,115,105,122,101,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,108,111,110,103,34,10,32,32,32,32,125,44,10,32,32,32,32,34,105,110,100,101,120,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,107,101,121,119,111,114,100,34,10,32,32,32,32,125,44,10,32,32,32,32,34,110,97,109,101,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,99,111,110,116,101,110,116,95,97,110,97,108,121,122,101,114,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,44,10,32,32,32,32,32,32,34,102,105,101,108,100,115,34,58,32,123,10,32,32,32,32,32,32,32,32,34,110,71,114,97,109,34,58,32,123,10,32,32,32,32,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,44,10,32,32,32,32,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,10,32,32,32,32,32,32,32,32,125,10,32,32,32,32,32,32,125,10,32,32,32,32,125,44,10,32,32,32,32,34,102,111,110,116,95,110,97,109,101,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,10,32,32,32,32,125,44,10,32,32,32,32,34,97,108,98,117,109,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,10,32,32,32,32,125,44,10,32,32,32,32,34,97,114,116,105,115,116,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,10,32,32,32,32,125,44,10,32,32,32,32,34,116,105,116,108,101,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,10,32,32,32,32,125,44,10,32,32,32,32,34,103,101,110,114,101,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,10,32,32,32,32,125,44,10,32,32,32,32,34,97,108,98,117,109,95,97,114,116,105,115,116,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,10,32,32,32,32,125,44,10,32,32,32,32,34,95,107,101,121,119,111,114,100,46,42,34,58,32,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,107,101,121,119,111,114,100,34,10,32,32,32,32,125,44,10,32,32,32,32,34,95,116,101,120,116,46,42,34,58,32,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,99,111,110,116,101,110,116,95,97,110,97,108,121,122,101,114,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,44,10,32,32,32,32,32,32,34,102,105,101,108,100,115,34,58,32,123,10,32,32,32,32,32,32,32,32,34,110,71,114,97,109,34,58,32,123,10,32,32,32,32,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,44,10,32,32,32,32,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,10,32,32,32,32,32,32,32,32,125,10,32,32,32,32,32,32,125,10,32,32,32,32,125,44,10,32,32,32,32,34,95,117,114,108,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,107,101,121,119,111,114,100,34,44,10,32,32,32,32,32,32,34,105,110,100,101,120,34,58,32,102,97,108,115,101,10,32,32,32,32,125,44,10,32,32,32,32,34,99,111,110,116,101,110,116,34,58,32,123,10,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,99,111,110,116,101,110,116,95,97,110,97,108,121,122,101,114,34,44,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,44,10,32,32,32,32,32,32,34,105,110,100,101,120,95,111,112,116,105,111,110,115,34,58,32,34,111,102,102,115,101,116,115,34,44,10,32,32,32,32,32,32,34,102,105,101,108,100,115,34,58,32,123,10,32,32,32,32,32,32,32,32,34,110,71,114,97,109,34,58,32,123,10,32,32,32,32,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,116,101,120,116,34,44,10,32,32,32,32,32,32,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,34,10,32,32,32,32,32,32,32,32,125,10,32,32,32,32,32,32,125,10,32,32,32,32,125,44,10,32,32,32,32,34,116,97,103,34,58,32,123,10,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,107,101,121,119,111,114,100,34,10,32,32,32,32,125,10,32,32,125,10,125,10}; +char settings_json[885] = {123,10,32,32,34,105,110,100,101,120,34,58,32,123,10,32,32,32,32,34,114,101,102,114,101,115,104,95,105,110,116,101,114,118,97,108,34,58,32,34,51,48,115,34,44,10,32,32,32,32,34,99,111,100,101,99,34,58,32,34,98,101,115,116,95,99,111,109,112,114,101,115,115,105,111,110,34,10,32,32,125,44,10,32,32,34,97,110,97,108,121,115,105,115,34,58,32,123,10,32,32,32,32,34,116,111,107,101,110,105,122,101,114,34,58,32,123,10,32,32,32,32,32,32,34,112,97,116,104,95,116,111,107,101,110,105,122,101,114,34,58,32,123,10,32,32,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,112,97,116,104,95,104,105,101,114,97,114,99,104,121,34,10,32,32,32,32,32,32,125,44,10,32,32,32,32,32,32,34,109,121,95,110,71,114,97,109,95,116,111,107,101,110,105,122,101,114,34,58,32,123,10,32,32,32,32,32,32,32,32,34,116,121,112,101,34,58,32,34,110,71,114,97,109,34,44,10,32,32,32,32,32,32,32,32,34,109,105,110,95,103,114,97,109,34,58,32,51,44,10,32,32,32,32,32,32,32,32,34,109,97,120,95,103,114,97,109,34,58,32,51,10,32,32,32,32,32,32,125,10,32,32,32,32,125,44,10,32,32,32,32,34,97,110,97,108,121,122,101,114,34,58,32,123,10,32,32,32,32,32,32,34,112,97,116,104,95,97,110,97,108,121,122,101,114,34,58,32,123,10,32,32,32,32,32,32,32,32,34,116,111,107,101,110,105,122,101,114,34,58,32,34,112,97,116,104,95,116,111,107,101,110,105,122,101,114,34,44,10,32,32,32,32,32,32,32,32,34,102,105,108,116,101,114,34,58,32,91,10,32,32,32,32,32,32,32,32,32,32,34,108,111,119,101,114,99,97,115,101,34,10,32,32,32,32,32,32,32,32,93,10,32,32,32,32,32,32,125,44,10,32,32,32,32,32,32,34,99,97,115,101,95,105,110,115,101,110,115,105,116,105,118,101,95,107,119,95,97,110,97,108,121,122,101,114,34,58,32,123,10,32,32,32,32,32,32,32,32,34,116,111,107,101,110,105,122,101,114,34,58,32,34,107,101,121,119,111,114,100,34,44,10,32,32,32,32,32,32,32,32,34,102,105,108,116,101,114,34,58,32,91,10,32,32,32,32,32,32,32,32,32,32,34,108,111,119,101,114,99,97,115,101,34,10,32,32,32,32,32,32,32,32,93,10,32,32,32,32,32,32,125,44,10,32,32,32,32,32,32,34,109,121,95,110,71,114,97,109,34,58,32,123,10,32,32,32,32,32,32,32,32,34,116,111,107,101,110,105,122,101,114,34,58,32,34,109,121,95,110,71,114,97,109,95,116,111,107,101,110,105,122,101,114,34,44,10,32,32,32,32,32,32,32,32,34,102,105,108,116,101,114,34,58,32,91,10,32,32,32,32,32,32,32,32,32,32,34,108,111,119,101,114,99,97,115,101,34,44,10,32,32,32,32,32,32,32,32,32,32,34,97,115,99,105,105,102,111,108,100,105,110,103,34,10,32,32,32,32,32,32,32,32,93,10,32,32,32,32,32,32,125,44,10,32,32,32,32,32,32,34,99,111,110,116,101,110,116,95,97,110,97,108,121,122,101,114,34,58,32,123,10,32,32,32,32,32,32,32,32,34,116,111,107,101,110,105,122,101,114,34,58,32,34,115,116,97,110,100,97,114,100,34,44,10,32,32,32,32,32,32,32,32,34,102,105,108,116,101,114,34,58,32,91,10,32,32,32,32,32,32,32,32,32,32,34,108,111,119,101,114,99,97,115,101,34,44,10,32,32,32,32,32,32,32,32,32,32,34,97,115,99,105,105,102,111,108,100,105,110,103,34,10,32,32,32,32,32,32,32,32,93,10,32,32,32,32,32,32,125,10,32,32,32,32,125,10,32,32,125,10,125}; diff --git a/src/main.c b/src/main.c index 425ffa2..86a8ff5 100644 --- a/src/main.c +++ b/src/main.c @@ -51,6 +51,7 @@ void sist2_scan(scan_args_t *args) { strncpy(ScanCtx.index.desc.root, args->path, sizeof(ScanCtx.index.desc.root)); ScanCtx.index.desc.root_len = (short) strlen(ScanCtx.index.desc.root); ScanCtx.tesseract_lang = args->tesseract_lang; + ScanCtx.tesseract_path = args->tesseract_path; init_dir(ScanCtx.index.path); diff --git a/src/parsing/pdf.c b/src/parsing/pdf.c index 8aee466..b134352 100644 --- a/src/parsing/pdf.c +++ b/src/parsing/pdf.c @@ -141,7 +141,7 @@ void fill_image(fz_context *ctx, UNUSED(fz_device *dev), if (pix->h > MIN_OCR_SIZE && img->h > MIN_OCR_SIZE && img->xres != 0) { TessBaseAPI *api = TessBaseAPICreate(); - TessBaseAPIInit3(api, TESS_DATAPATH, ScanCtx.tesseract_lang); + TessBaseAPIInit3(api, ScanCtx.tesseract_path, ScanCtx.tesseract_lang); TessBaseAPISetImage(api, pix->samples, pix->w, pix->h, pix->n, pix->stride); TessBaseAPISetSourceResolution(api, pix->xres); @@ -157,8 +157,8 @@ void fill_image(fz_context *ctx, UNUSED(fz_device *dev), TessBaseAPIEnd(api); TessBaseAPIDelete(api); - fz_drop_pixmap(ctx, pix); } + fz_drop_pixmap(ctx, pix); } } diff --git a/src/sist.h b/src/sist.h index 021000c..ea40e22 100644 --- a/src/sist.h +++ b/src/sist.h @@ -3,7 +3,6 @@ #define UUID_STR_LEN 37 #define UNUSED(x) __attribute__((__unused__)) x -#define TESS_DATAPATH "/usr/share/tessdata/" #include #include diff --git a/src/util.c b/src/util.c index 7961ec9..c78b3cc 100644 --- a/src/util.c +++ b/src/util.c @@ -1,4 +1,5 @@ #include "util.h" +#include "src/ctx.h" dyn_buffer_t dyn_buffer_create() { dyn_buffer_t buf; @@ -317,4 +318,29 @@ GHashTable *incremental_get_table() { return file_table; } +const char *find_file_in_paths(const char *paths[], const char *filename) { + + for (int i = 0; paths[i] != NULL; i++) { + + char *apath = abspath(paths[i]); + if (apath == NULL) { + continue; + } + + char path[PATH_MAX]; + snprintf(path, sizeof(path), "%s%s", apath, filename); + + LOG_DEBUGF("util.c", "Looking for '%s' in folder '%s'", filename, apath) + free(apath); + + struct stat info; + int ret = stat(path, &info); + if (ret != -1) { + return paths[i]; + } + } + + return NULL; +} + diff --git a/src/util.h b/src/util.h index 15512db..2125870 100644 --- a/src/util.h +++ b/src/util.h @@ -74,5 +74,6 @@ int incremental_get(GHashTable *table, unsigned long inode_no); int incremental_mark_file_for_copy(GHashTable *table, unsigned long inode_no); +const char *find_file_in_paths(const char **paths, const char *filename); #endif