From c2ad6549fb337ce707e04aa441c9b492171a3b9d Mon Sep 17 00:00:00 2001 From: yzrh Date: Sun, 25 Dec 2022 18:03:01 +0000 Subject: Handle headless HN and page with no image. Signed-off-by: yzrh --- src/cnki.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/cnki.c') diff --git a/src/cnki.c b/src/cnki.c index 5f120d0..cc49d73 100644 --- a/src/cnki.c +++ b/src/cnki.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, yzrh + * Copyright (c) 2020-2022, yzrh * * SPDX-License-Identifier: Apache-2.0 */ @@ -54,6 +54,11 @@ cnki_destroy(cnki_t **param) object_hn_t *ptr_hn; while ((ptr_hn = (*param)->object_hn) != NULL) { (*param)->object_hn = (*param)->object_hn->next; + free(ptr_hn->text); + if (ptr_hn->image_data != NULL) + for (int i = 0; i < ptr_hn->image_length; i++) + free(ptr_hn->image_data[i].image); + free(ptr_hn->image_data); free(ptr_hn); } @@ -71,12 +76,19 @@ cnki_info(cnki_t **param) printf("Reading file header at 0x%x\n", ADDRESS_HEAD); int addr[2]; + unsigned char str[2]; fseek((*param)->fp_i, ADDRESS_HEAD, SEEK_SET); fread((*param)->file_stat->type, 4, 1, (*param)->fp_i); - if ((*param)->stat > 0) - printf("File type is '%s'\n", (*param)->file_stat->type); + fread(str, 2, 1, (*param)->fp_i); + + if ((*param)->stat > 0) { + if ((unsigned char) (*param)->file_stat->type[0] > 0x7f) + printf("File type is '%02x'\n", (unsigned char) (*param)->file_stat->type[0]); + else + printf("File type is '%s'\n", (*param)->file_stat->type); + } if (strncmp((*param)->file_stat->type, "%PDF", 4) == 0) { return 0; @@ -86,6 +98,9 @@ cnki_info(cnki_t **param) } else if (strncmp((*param)->file_stat->type, "HN", 2) == 0) { addr[0] = ADDRESS_HN_PAGE; addr[1] = ADDRESS_HN_OUTLINE; + } else if ((unsigned char) (*param)->file_stat->type[0] == 0xc8) { + addr[0] = ADDRESS_C8_PAGE; + addr[1] = ADDRESS_HN_OUTLINE; } else if (strncmp((*param)->file_stat->type, "KDH ", 4) == 0) { return 0; } else { @@ -102,6 +117,14 @@ cnki_info(cnki_t **param) printf("Advised %d page(s)\n", (*param)->file_stat->page); + if (strncmp((*param)->file_stat->type, "HN", 2) == 0 && str[0] == 0xc8 && str[1] == 0x00) { + fseek((*param)->fp_i, 0xd8, SEEK_SET); + return 0; + } else if ((unsigned char) (*param)->file_stat->type[0] == 0xc8) { + fseek((*param)->fp_i, 0x50, SEEK_SET); + return 0; + } + if ((*param)->stat > 1) printf("Reading outline count at 0x%x\n", addr[1]); -- cgit v1.2.3