From bfc7f4ddb6550ea2e65faff727b7f74aa29a5ba0 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 26 Oct 2019 14:39:28 -0400 Subject: [PATCH] progress bar fix --- CMakeLists.txt | 2 +- src/ctx.h | 4 ++-- src/io/serialize.c | 6 +++--- src/io/walk.c | 2 +- src/parsing/pdf.c | 32 +++++++++++--------------------- src/util.c | 2 +- 6 files changed, 19 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c33f1f..96cee42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,7 +85,7 @@ include_directories( target_compile_options(sist2 PRIVATE -O3 - -march=native +# -march=native -fno-stack-protector -fomit-frame-pointer ) diff --git a/src/ctx.h b/src/ctx.h index a29fc8a..1e32fa5 100644 --- a/src/ctx.h +++ b/src/ctx.h @@ -16,8 +16,8 @@ struct { int content_size; float tn_qscale; - int stat_tn_size; - int stat_index_size; + size_t stat_tn_size; + size_t stat_index_size; GHashTable *original_table; GHashTable *copy_table; diff --git a/src/io/serialize.c b/src/io/serialize.c index a331c1c..28245c7 100644 --- a/src/io/serialize.c +++ b/src/io/serialize.c @@ -66,7 +66,7 @@ index_descriptor_t read_index_descriptor(char *path) { strcpy(descriptor.root, cJSON_GetObjectItem(json, "root")->valuestring); strcpy(descriptor.name, cJSON_GetObjectItem(json, "name")->valuestring); strcpy(descriptor.rewrite_url, cJSON_GetObjectItem(json, "rewrite_url")->valuestring); - descriptor.root_len = (int)strlen(descriptor.root); + descriptor.root_len = (short)strlen(descriptor.root); strcpy(descriptor.version, cJSON_GetObjectItem(json, "version")->valuestring); strcpy(descriptor.uuid, cJSON_GetObjectItem(json, "uuid")->valuestring); @@ -127,8 +127,8 @@ void write_document(document_t *doc) { dyn_buffer_t buf = dyn_buffer_create(); // Ignore root directory in the file path - doc->ext = (short)(doc->ext - ScanCtx.index.desc.root_len); - doc->base = (short)(doc->base - ScanCtx.index.desc.root_len); + doc->ext = doc->ext - ScanCtx.index.desc.root_len; + doc->base = doc->base - ScanCtx.index.desc.root_len; doc->filepath += ScanCtx.index.desc.root_len; dyn_buffer_write(&buf, doc, sizeof(line_t)); diff --git a/src/io/walk.c b/src/io/walk.c index faac075..2d724ab 100644 --- a/src/io/walk.c +++ b/src/io/walk.c @@ -20,7 +20,7 @@ parse_job_t *create_parse_job(const char *filepath, const struct stat *info, int return job; } -int handle_entry(const char *filepath, const struct stat *info, const int typeflag, struct FTW *ftw) { +int handle_entry(const char *filepath, const struct stat *info, int typeflag, struct FTW *ftw) { if (typeflag == FTW_F && S_ISREG(info->st_mode)) { parse_job_t *job = create_parse_job(filepath, info, ftw->base); tpool_add_work(ScanCtx.pool, parse, job); diff --git a/src/parsing/pdf.c b/src/parsing/pdf.c index 5f4a058..88ec15e 100644 --- a/src/parsing/pdf.c +++ b/src/parsing/pdf.c @@ -42,7 +42,8 @@ fz_page *render_cover(fz_context *ctx, document_t *doc, fz_document *fzdoc) { return cover; } -void fz_noop_callback(void *user, const char *message) {} +void fz_noop_callback(__attribute__((unused)) void *user, __attribute__((unused)) const char *message) {} + void parse_pdf(void *buf, size_t buf_len, document_t *doc) { @@ -85,27 +86,14 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) { page = fz_load_page(ctx, fzdoc, current_page); } - fz_stext_page *stext; - fz_device *dev = NULL; + fz_stext_page *stext = fz_new_stext_page(ctx, fz_bound_page(ctx, page)); + fz_device *dev = fz_new_stext_device(ctx, stext, &opts); - fz_var(dev); + pthread_mutex_lock(&ScanCtx.mupdf_mu); + fz_run_page_contents(ctx, page, dev, fz_identity, NULL); + pthread_mutex_unlock(&ScanCtx.mupdf_mu); - stext = fz_new_stext_page(ctx, fz_bound_page(ctx, page)); - fz_try(ctx) - { - dev = fz_new_stext_device(ctx, stext, &opts); - pthread_mutex_lock(&ScanCtx.mupdf_mu); - fz_run_page_contents(ctx, page, dev, fz_identity, NULL); - pthread_mutex_unlock(&ScanCtx.mupdf_mu); - fz_close_device(ctx, dev); - } - fz_always(ctx) - fz_drop_device(ctx, dev); - fz_catch(ctx) - { - fz_drop_stext_page(ctx, stext); - fz_rethrow(ctx); - } + fz_drop_device(ctx, dev); fz_stext_block *block = stext->first_block; while (block != NULL) { @@ -147,6 +135,8 @@ void parse_pdf(void *buf, size_t buf_len, document_t *doc) { fz_drop_stream(ctx, stream); fz_drop_document(ctx, fzdoc); fz_drop_context(ctx); - } fz_catch(ctx) {} + } fz_catch(ctx) { + fprintf(stderr, "Error %s %s\n", doc->filepath, ctx->error.message); + } } diff --git a/src/util.c b/src/util.c index 6a1ee11..a73706d 100644 --- a/src/util.c +++ b/src/util.c @@ -34,7 +34,7 @@ char *expandpath(const char *path) { void progress_bar_print(double percentage, size_t tn_size, size_t index_size) { - static int last_val = 0; + static int last_val = -1; int val = (int) (percentage * 100); if (last_val == val || val > 100 || index_size < 1024) { return;