aboutsummaryrefslogtreecommitdiffstats
path: root/libav/utils.c
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2001-09-16 21:50:48 +0000
committerFabrice Bellard <fabrice@bellard.org>2001-09-16 21:50:48 +0000
commit9150f42ed529f41533211618e3ce2895742e71a9 (patch)
treed564646043bac9d063d3700e6d8a903f081a9ba7 /libav/utils.c
parent5a56c87c10df2a95cf8d2462bf0ff5bb145e297d (diff)
downloadffmpeg-9150f42ed529f41533211618e3ce2895742e71a9.tar.gz
fixed image number syntax problems
Originally committed as revision 128 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libav/utils.c')
-rw-r--r--libav/utils.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/libav/utils.c b/libav/utils.c
index 87f3f01da6..a2bc404742 100644
--- a/libav/utils.c
+++ b/libav/utils.c
@@ -548,3 +548,59 @@ int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
return 0;
}
+/* Return in 'buf' the path with '%d' replaced by number. Also handles
+ the '%0nd' format where 'n' is the total number of digits and
+ '%%'. Return 0 if OK, and -1 if format error */
+int get_frame_filename(char *buf, int buf_size,
+ const char *path, int number)
+{
+ const char *p;
+ char *q, buf1[20];
+ int nd, len, c, percentd_found;
+
+ q = buf;
+ p = path;
+ percentd_found = 0;
+ for(;;) {
+ c = *p++;
+ if (c == '\0')
+ break;
+ if (c == '%') {
+ nd = 0;
+ while (*p >= '0' && *p <= '9') {
+ nd = nd * 10 + *p++ - '0';
+ }
+ c = *p++;
+ switch(c) {
+ case '%':
+ goto addchar;
+ case 'd':
+ if (percentd_found)
+ goto fail;
+ percentd_found = 1;
+ snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
+ len = strlen(buf1);
+ if ((q - buf + len) > buf_size - 1)
+ goto fail;
+ memcpy(q, buf1, len);
+ q += len;
+ break;
+ default:
+ goto fail;
+ }
+ } else {
+ addchar:
+ if ((q - buf) < buf_size - 1)
+ *q++ = c;
+ }
+ }
+ if (!percentd_found)
+ goto fail;
+ *q = '\0';
+ return 0;
+ fail:
+ *q = '\0';
+ return -1;
+}
+
+