diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-06-16 12:21:16 +0200 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-06-16 18:08:15 +0100 |
commit | 000e932a844ecc6cd59ae9cadc3c3150d4a6bf5b (patch) | |
tree | 6f746b61ed74038e208a0ca96adcb2e7e19009ff /source | |
parent | b8f6455de4c500807bf85825d32a69a9c71efcd7 (diff) | |
download | mupdf-000e932a844ecc6cd59ae9cadc3c3150d4a6bf5b.tar.xz |
Add fz_format_output_path function.
Diffstat (limited to 'source')
-rw-r--r-- | source/fitz/string.c | 44 |
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 * |