diff options
-rw-r--r-- | exar/exar.c | 70 | ||||
-rw-r--r-- | exar/exar.h | 26 | ||||
-rw-r--r-- | src/view.c | 4 |
3 files changed, 86 insertions, 14 deletions
diff --git a/exar/exar.c b/exar/exar.c index fad142ef..c2b5ef09 100644 --- a/exar/exar.c +++ b/exar/exar.c @@ -63,7 +63,6 @@ struct exar_header_s { char eh_name[EXAR_NAME_MAX]; }; - #define LOG(level, ...) do { if (s_verbose & EXAR_VERBOSE_L##level) { \ fprintf(stderr, "exar-log%d: ", level); \ fprintf(stderr, __VA_ARGS__); } } while(0) @@ -240,16 +239,57 @@ get_file_header(FILE *f, struct exar_header_s *head) return EE_OK; } static int +next_file(FILE *f, struct exar_header_s *header) +{ + if (*(header->eh_name)) + { + if (header->eh_flag == FILE_FLAG) + { + if (fseek(f, header->eh_size, SEEK_CUR) != 0) + return EE_ERROR; + else + LOG(3, "Skipping %s\n", header->eh_name); + } + } + return get_file_header(f, header); +} +static int find_cmp(const char *name, const char *search) { char buffer[EXAR_NAME_MAX]; - size_t offset = get_offset(buffer, EXAR_NAME_MAX, name, NULL); - return strcmp(&name[offset], search); + if (strcmp(name, search) != 0) + { + size_t offset = get_offset(buffer, EXAR_NAME_MAX, name, NULL); + return strcmp(&name[offset], search); + } + return 0; +} +static int +contains(const char *archive, const char *name, int (*cmp)(const char *, const char *)) +{ + FILE *f = NULL; + struct exar_header_s header = { 0, 0, {0} }; + int result = EE_ERROR; + + if ((f = open_archive(archive, "r")) == NULL) + goto finish; + while (next_file(f, &header) == 0) + { + if (cmp(header.eh_name, name) == 0) + { + result = EE_OK; + break; + } + } + +finish: + close_file(f, archive); + return result; } static unsigned char * extract(const char *archive, const char *file, off_t *s, int (*cmp)(const char *, const char *)) { - struct exar_header_s header; + struct exar_header_s header = { 0, 0, { 0 }}; FILE *f = NULL; unsigned char *ret = NULL; if (s != NULL) @@ -596,19 +636,29 @@ exar_info(const char *archive) assert(archive != NULL); FILE *f = NULL; - struct exar_header_s header; + struct exar_header_s header = { 0, 0, {0} }; if ((f = open_archive(archive, "r")) == NULL) goto finish; - while(get_file_header(f, &header) == 0) - { + while(next_file(f, &header) == 0) fprintf(stdout, "%c %-14jd %s\n", header.eh_flag, (intmax_t)header.eh_size, header.eh_name); - if (header.eh_flag == FILE_FLAG) - fseek(f, header.eh_size, SEEK_CUR); - } finish: close_file(f, archive); } +int +exar_contains(const char *archive, const char *name) +{ + assert(archive != NULL); + + return contains(archive, name, strcmp); +} +int +exar_search_contains(const char *archive, const char *name) +{ + assert(archive != NULL); + + return contains(archive, name, find_cmp); +} int exar_check_version(const char *archive) diff --git a/exar/exar.h b/exar/exar.h index 1fa6f109..f52cfa1e 100644 --- a/exar/exar.h +++ b/exar/exar.h @@ -92,8 +92,8 @@ exar_extract(const char *archive, const char *file, off_t *size); * Searches for a file and extracts the content from the archive. * * @archive The archive - * @search The search term. The term is is compared with the end of each - * filename in the archive + * @search The search term. The search term must either match the full path or + * the filename * @size Return location for the size, if an error occurs size will be set to -1 * * @returns A newly allocated char buffer with the file content or NULL if an error @@ -133,6 +133,28 @@ exar_check_version(const char *archive); void exar_info(const char *archive); +/* + * Checks if an archive contains a file + * + * @archive The archive + * @path The path of the file in the archive + * + * @returns 0 if the file was found, -1 otherwise + * */ +int +exar_contains(const char *archive, const char *path); + +/* + * Checks if an archive contains a file + * + * @archive The archive + * @search The search term. The search term must either match the full path or + * the filename + * + * @returns 0 if the file was found, -1 otherwise + * */ +int +exar_search_contains(const char *archive, const char *search); /* * Set verbosity flags, exar will be most verbose if all flags are set, log * messages are printed to stderr. @@ -1183,9 +1183,9 @@ view_load_error_cb(WebKitWebView *web, WebKitWebFrame *frame, char *uri, GError * The webframe that emitted the signal * @param {Object} error * The error - * @param {Object} error.message + * @param {String} error.message * The error message - * @param {Object} error.code + * @param {Number} error.code * The error code * * @returns {Boolean} |