summaryrefslogtreecommitdiff
path: root/source/fitz/string.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-06-16 12:21:16 +0200
committerRobin Watts <robin.watts@artifex.com>2016-06-16 18:08:15 +0100
commit000e932a844ecc6cd59ae9cadc3c3150d4a6bf5b (patch)
tree6f746b61ed74038e208a0ca96adcb2e7e19009ff /source/fitz/string.c
parentb8f6455de4c500807bf85825d32a69a9c71efcd7 (diff)
downloadmupdf-000e932a844ecc6cd59ae9cadc3c3150d4a6bf5b.tar.xz
Add fz_format_output_path function.
Diffstat (limited to 'source/fitz/string.c')
-rw-r--r--source/fitz/string.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/source/fitz/string.c b/source/fitz/string.c
index df171795..de9ee80f 100644
--- a/source/fitz/string.c
+++ b/source/fitz/string.c
@@ -142,6 +142,50 @@ fz_urldecode(char *url)
return url;
}
+void
+fz_format_output_path(fz_context *ctx, char *path, int size, const char *fmt, int page)
+{
+ const char *s, *p;
+ char num[40];
+ int i, n;
+ int z = 0;
+
+ for (i = 0; page; page /= 10)
+ num[i++] = '0' + page % 10;
+ num[i] = 0;
+
+ s = p = strchr(fmt, '%');
+ if (p)
+ {
+ ++p;
+ while (*p >= '0' && *p <= '9')
+ z = z * 10 + (*p++ - '0');
+ }
+ if (p && *p == 'd')
+ {
+ ++p;
+ }
+ else
+ {
+ s = p = strrchr(fmt, '.');
+ if (!p)
+ s = p = fmt + strlen(fmt);
+ }
+
+ if (z < 1)
+ z = 1;
+ while (i < z && i < sizeof num)
+ num[i++] = '0';
+ n = s - fmt;
+ if (n + i + strlen(p) >= size)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "path name buffer overflow");
+ memcpy(path, fmt, n);
+ while (i > 0)
+ path[n++] = num[--i];
+ fz_strlcpy(path + n, p, size - n);
+
+}
+
#define SEP(x) ((x)=='/' || (x) == 0)
char *