diff options
author | yzrh <yzrh@noema.org> | 2022-12-25 18:03:01 +0000 |
---|---|---|
committer | yzrh <yzrh@noema.org> | 2022-12-25 23:18:17 +0000 |
commit | c2ad6549fb337ce707e04aa441c9b492171a3b9d (patch) | |
tree | 611b43986a0c50d335ba69aafc8ace26cdcaffd3 /src/cnki_hn.c | |
parent | d2826fa075544ada1fb9f530a375ef85f58c8ea0 (diff) | |
download | melon-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_hn.c')
-rw-r--r-- | src/cnki_hn.c | 110 |
1 files changed, 61 insertions, 49 deletions
diff --git a/src/cnki_hn.c b/src/cnki_hn.c index feabb48..4d32092 100644 --- a/src/cnki_hn.c +++ b/src/cnki_hn.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 */ @@ -27,12 +27,13 @@ cnki_hn(cnki_t **param) if ((*param)->stat > 1) { printf("Loading page(s)\n"); - printf("\t%8s\t%8s\t%6s\t%4s\t%16s\t%4s\t%8s\t%8s\n", + printf("\t%8s\t%8s\t%6s\t%4s\t%8s\t%8s\t%4s\t%8s\t%8s\n", "address", "text", "length", "page", "unknown", + "next", "code", "address", "image"); @@ -44,7 +45,8 @@ cnki_hn(cnki_t **param) fread(&ptr->text_size, 4, 1, (*param)->fp_i); fread(&ptr->image_length, 2, 1, (*param)->fp_i); fread(&ptr->page, 2, 1, (*param)->fp_i); - fread(&ptr->unknown, 8, 1, (*param)->fp_i); + fread(&ptr->unknown, 4, 1, (*param)->fp_i); + fread(&ptr->address_next, 4, 1, (*param)->fp_i); ptr->text = NULL; ptr->image_data = NULL; @@ -62,66 +64,76 @@ cnki_hn(cnki_t **param) ptr = (*param)->object_hn; while (ptr != NULL) { - ptr->text = malloc(ptr->text_size); + if (ptr->text_size > 0) { + ptr->text = malloc(ptr->text_size); - if (ptr->text == NULL) - return 1; + if (ptr->text == NULL) + return 1; - fseek((*param)->fp_i, ptr->address, SEEK_SET); - fread(ptr->text, ptr->text_size, 1, (*param)->fp_i); + fseek((*param)->fp_i, ptr->address, SEEK_SET); + fread(ptr->text, ptr->text_size, 1, (*param)->fp_i); + } if ((*param)->stat > 1) - printf("\t%08x\t%8d\t%6d\t%4d\t{%4d, %8d}", + printf("\t%08x\t%8d\t%6d\t%4d\t%8d\t%08x", ptr->address, ptr->text_size, ptr->image_length, ptr->page, - ptr->unknown[0], - ptr->unknown[1]); - - ptr->image_data = malloc(ptr->image_length * sizeof(hn_image_t)); - - if (ptr->image_data == NULL) - return 1; + ptr->unknown, + ptr->address_next); - for (int i = 0; i < ptr->image_length; i++) { - fread(&ptr->image_data[i].format, 4, 1, (*param)->fp_i); - fread(&ptr->image_data[i].address, 4, 1, (*param)->fp_i); - fread(&ptr->image_data[i].size, 4, 1, (*param)->fp_i); - fseek((*param)->fp_i, - ptr->image_data[i].address + ptr->image_data[i].size, - SEEK_SET); - } - - for (int i = 0; i < ptr->image_length; i++) { - ptr->image_data[i].image = malloc(ptr->image_data[i].size); + if (ptr->image_length > 0) { + ptr->image_data = malloc(ptr->image_length * sizeof(hn_image_t)); - if (ptr->image_data[i].image == NULL) + if (ptr->image_data == NULL) return 1; - fseek((*param)->fp_i, ptr->image_data[i].address, SEEK_SET); - fread(ptr->image_data[i].image, - ptr->image_data[i].size, 1, - (*param)->fp_i); - - if ((*param)->stat > 1) { - if (i == 0) { - printf("\t%4d\t%08x\t%8d\n", - ptr->image_data[i].format, - ptr->image_data[i].address, - ptr->image_data[i].size); - } else { - printf("\t%8s\t%8s\t%6s\t%4s\t%16s\t%4d\t%08x\t%8d\n", - "", - "", - "", - "", - "", - ptr->image_data[i].format, - ptr->image_data[i].address, - ptr->image_data[i].size); + for (int i = 0; i < ptr->image_length; i++) { + fread(&ptr->image_data[i].format, 4, 1, (*param)->fp_i); + fread(&ptr->image_data[i].address, 4, 1, (*param)->fp_i); + fread(&ptr->image_data[i].size, 4, 1, (*param)->fp_i); + fseek((*param)->fp_i, + ptr->image_data[i].address + ptr->image_data[i].size, + SEEK_SET); + } + + for (int i = 0; i < ptr->image_length; i++) { + ptr->image_data[i].image = malloc(ptr->image_data[i].size); + + if (ptr->image_data[i].image == NULL) + return 1; + + fseek((*param)->fp_i, ptr->image_data[i].address, SEEK_SET); + fread(ptr->image_data[i].image, + ptr->image_data[i].size, 1, + (*param)->fp_i); + + if ((*param)->stat > 1) { + if (i == 0) { + printf("\t%4d\t%08x\t%8d\n", + ptr->image_data[i].format, + ptr->image_data[i].address, + ptr->image_data[i].size); + } else { + printf("\t%8s\t%8s\t%6s\t%4s\t%8s\t%8s\t%4d\t%08x\t%8d\n", + "", + "", + "", + "", + "", + "", + ptr->image_data[i].format, + ptr->image_data[i].address, + ptr->image_data[i].size); + } } } + } else if ((*param)->stat > 1) { + printf("\t%4s\t%8s\t%8s\n", + "", + "", + ""); } ptr = ptr->next; |