aboutsummaryrefslogtreecommitdiffstats
path: root/src/cnki_kdh.c
diff options
context:
space:
mode:
authoryzrh <yzrh@noema.org>2020-12-30 17:06:55 +0000
committeryzrh <yzrh@noema.org>2020-12-30 21:12:52 +0000
commit1f62c53da6edc5a82a1e0eceb401b2274cd4a0d1 (patch)
tree24359d29576a26ae70c446d4d01a8a93a61d62c2 /src/cnki_kdh.c
parent98691d4203f4e578b84b2014db0fbe0c1209cc48 (diff)
downloadmelon-1f62c53da6edc5a82a1e0eceb401b2274cd4a0d1.tar.gz
melon-1f62c53da6edc5a82a1e0eceb401b2274cd4a0d1.tar.zst
Produce PDF directly from KDH.
Diffstat (limited to 'src/cnki_kdh.c')
-rw-r--r--src/cnki_kdh.c23
1 files changed, 20 insertions, 3 deletions
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;
}