From 1f62c53da6edc5a82a1e0eceb401b2274cd4a0d1 Mon Sep 17 00:00:00 2001 From: yzrh Date: Wed, 30 Dec 2020 17:06:55 +0000 Subject: Produce PDF directly from KDH. --- src/cnki_kdh.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/cnki_kdh.c') diff --git a/src/cnki_kdh.c b/src/cnki_kdh.c index 450242d..78e8957 100644 --- a/src/cnki_kdh.c +++ b/src/cnki_kdh.c @@ -27,6 +27,11 @@ cnki_kdh(cnki_t **param) char buf[(*param)->size_buf]; + FILE *tmp = tmpfile(); + + if (tmp == NULL) + return 1; + for (;;) { fread(buf, (*param)->size_buf, 1, (*param)->fp_i); @@ -35,15 +40,27 @@ cnki_kdh(cnki_t **param) key_cur++; } - fwrite(buf, (*param)->size_buf, 1, (*param)->fp_o); + fwrite(buf, (*param)->size_buf, 1, tmp); if (ftell((*param)->fp_i) == size) break; } if ((*param)->stat > 0) - printf("Decryption ended total %ld byte(s) written\n", - ftell((*param)->fp_o)); + printf("Decrypted %ld byte(s)\n", ftell(tmp)); + + fseek(tmp, 0, SEEK_SET); + + FILE *orig = (*param)->fp_i; + (*param)->fp_i = tmp; + + cnki_pdf(param); + + (*param)->fp_i = orig; + fclose(tmp); + + if ((*param)->stat > 0) + printf("Conversion ended\n"); return 0; } -- cgit v1.2.3