aboutsummaryrefslogtreecommitdiffstats
path: root/src/cnki.c
diff options
context:
space:
mode:
authoryzrh <yzrh@noema.org>2022-12-25 18:03:01 +0000
committeryzrh <yzrh@noema.org>2022-12-25 23:18:17 +0000
commitc2ad6549fb337ce707e04aa441c9b492171a3b9d (patch)
tree611b43986a0c50d335ba69aafc8ace26cdcaffd3 /src/cnki.c
parentd2826fa075544ada1fb9f530a375ef85f58c8ea0 (diff)
downloadmelon-c2ad6549fb337ce707e04aa441c9b492171a3b9d.tar.gz
melon-c2ad6549fb337ce707e04aa441c9b492171a3b9d.tar.zst
Handle headless HN and page with no image.
Signed-off-by: yzrh <yzrh@noema.org>
Diffstat (limited to 'src/cnki.c')
-rw-r--r--src/cnki.c29
1 files changed, 26 insertions, 3 deletions
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 <yzrh@noema.org>
+ * Copyright (c) 2020-2022, yzrh <yzrh@noema.org>
*
* 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]);