summaryrefslogtreecommitdiff
path: root/source/luametatex/source/libraries/pplib/pptest1.c
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2022-09-16 15:53:42 +0200
committerContext Git Mirror Bot <phg@phi-gamma.net>2022-09-16 15:53:42 +0200
commitc161b7d6fe142231346cc1844e6e27c0ab7718c1 (patch)
tree3fd877b8986137703e987e4651a2db8e946a0f72 /source/luametatex/source/libraries/pplib/pptest1.c
parente94fa4dc30ec28a6727aa85e17aaac18b76aeadb (diff)
downloadcontext-c161b7d6fe142231346cc1844e6e27c0ab7718c1.tar.gz
2022-09-16 14:41:00
Diffstat (limited to 'source/luametatex/source/libraries/pplib/pptest1.c')
-rw-r--r--source/luametatex/source/libraries/pplib/pptest1.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/source/luametatex/source/libraries/pplib/pptest1.c b/source/luametatex/source/libraries/pplib/pptest1.c
new file mode 100644
index 000000000..eabb0eae9
--- /dev/null
+++ b/source/luametatex/source/libraries/pplib/pptest1.c
@@ -0,0 +1,104 @@
+
+#include <stdio.h>
+#include "ppapi.h"
+#include "util/utiliof.h"
+
+static const char * sizenum (size_t s)
+{
+ static char buffer[32];
+ if (s < 1000)
+ sprintf(buffer, "%uB", (unsigned)s);
+ else if (s < 1000000)
+ sprintf(buffer, "%.2fkB", (double)(s) / 1000);
+ else
+ sprintf(buffer, "%.2fMB", (double)(s) / 1000000);
+ return buffer;
+}
+
+static const char * crypt_info (ppdoc *pdf)
+{
+ switch (ppdoc_crypt_status(pdf))
+ {
+ case PPCRYPT_NONE:
+ return "none";
+ case PPCRYPT_DONE:
+ return "empty password";
+ case PPCRYPT_PASS:
+ return "nonempty password";
+ default:
+ break;
+ }
+ return "this shouldn't happen";
+}
+
+static void print_info (ppdoc *pdf)
+{
+ ppdict *info;
+ ppstring *creator, *producer;
+ size_t memused, memwaste;
+
+ if ((info = ppdoc_info(pdf)) != NULL)
+ {
+ if ((creator = ppdict_rget_string(info, "Creator")) != NULL)
+ printf(" creator: %s\n", ppstring_decoded_data(creator));
+ if ((producer = ppdict_rget_string(info, "Producer")) != NULL)
+ printf(" producer: %s\n", ppstring_decoded_data(producer));
+ }
+ printf(" version: %s\n", ppdoc_version_string(pdf));
+ printf(" protection: %s\n", crypt_info(pdf));
+ printf(" filesize: %s\n", sizenum(ppdoc_file_size(pdf)));
+ printf(" objects: %lu\n", (unsigned long)ppdoc_objects(pdf));
+ printf(" pagecount: %lu\n", (unsigned long)ppdoc_page_count(pdf));
+ memused = ppdoc_memory(pdf, &memwaste);
+ printf(" memused: %s\n", sizenum(memused));
+ printf(" memwaste: %s\n", sizenum(memwaste));
+}
+
+static int usage (const char *argv0)
+{
+ printf("pplib " pplib_version ", " pplib_author "\n");
+ printf("usage: %s file1.pdf file2.pdf ...\n", argv0);
+ return 0;
+}
+
+int main (int argc, const char **argv)
+{
+ const char *filepath;
+ int a;
+ ppdoc *pdf;
+ const void *data;
+ size_t size;
+
+ if (argc < 2)
+ return usage(argv[0]);
+ for (a = 1; a < argc; ++a)
+ {
+ filepath = argv[a];
+ printf("loading %s... ", filepath);
+ pdf = ppdoc_load(filepath);
+ if (pdf == NULL)
+ {
+ printf("failed\n");
+ continue;
+ }
+ printf("done.\n");
+ print_info(pdf);
+ ppdoc_free(pdf);
+ /* now loading from memory buffer */
+ printf("loading %s from mem buffer... ", filepath);
+ data = iof_copy_file_data(filepath, &size);
+ if (data != NULL)
+ {
+ pdf = ppdoc_mem(data, size);
+ if (pdf == NULL)
+ {
+ printf("failed\n");
+ continue;
+ }
+ printf("done.\n");
+ //print_info(pdf);
+ ppdoc_free(pdf);
+ }
+ }
+ return 0;
+}