summaryrefslogtreecommitdiff
path: root/source/fitz/writer.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-05-04 18:00:37 +0200
committerTor Andersson <tor.andersson@artifex.com>2016-05-13 11:42:00 +0200
commit9dda5aa73d6dcb72c9f10b87564afe7491575faf (patch)
tree31c3e2b2fb16431ad7236f7a44e206a3a391061b /source/fitz/writer.c
parent74d75a7a6f3ea4bef5b4489c65e8a876ae480c76 (diff)
downloadmupdf-9dda5aa73d6dcb72c9f10b87564afe7491575faf.tar.xz
Add long output option parsing.
Use comma-separated list of flags and key/value pairs, for example: "linearize,resolution=72,colorspace=gray"
Diffstat (limited to 'source/fitz/writer.c')
-rw-r--r--source/fitz/writer.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/source/fitz/writer.c b/source/fitz/writer.c
index c25ff2f9..b015b5bb 100644
--- a/source/fitz/writer.c
+++ b/source/fitz/writer.c
@@ -1,5 +1,46 @@
#include "mupdf/fitz.h"
+/* Return non-null terminated pointers to key/value entries in comma separated
+ * option string. A plain key has the default value 'yes'. Use strncmp to compare
+ * key/value strings. */
+static const char *
+fz_get_option(fz_context *ctx, const char **key, const char **val, const char *opts)
+{
+ if (!opts || *opts == 0)
+ return NULL;
+
+ if (*opts == ',')
+ ++opts;
+
+ *key = opts;
+ while (*opts != 0 && *opts != ',' && *opts != '=')
+ ++opts;
+
+ if (*opts == '=')
+ {
+ *val = ++opts;
+ while (*opts != 0 && *opts != ',')
+ ++opts;
+ }
+ else
+ {
+ *val = "yes";
+ }
+
+ return opts;
+}
+
+int
+fz_has_option(fz_context *ctx, const char *opts, const char *key, const char **val)
+{
+ const char *straw;
+ int n = strlen(key);
+ while ((opts = fz_get_option(ctx, &straw, val, opts)))
+ if (!strncmp(straw, key, n) && (straw[n] == '=' || straw[n] == ',' || straw[n] == 0))
+ return 1;
+ return 0;
+}
+
fz_document_writer *
fz_new_document_writer(fz_context *ctx, const char *path, const char *format, const char *options)
{