[FFmpeg-cvslog] parseutils: Extend small_strptime to be used in avformat
Luca Barbato
git at videolan.org
Tue Apr 7 20:08:53 CEST 2015
ffmpeg | branch: master | Luca Barbato <lu_zero at gentoo.org> | Mon Apr 6 01:25:52 2015 +0200| [108f2f381acb93827fb4add0517eeae859afa3bf] | committer: Luca Barbato
parseutils: Extend small_strptime to be used in avformat
The strptime implementation is supposed to support whitespace and %T.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=108f2f381acb93827fb4add0517eeae859afa3bf
---
libavutil/parseutils.c | 108 ++++++++++++++++++++++++++----------------------
1 file changed, 58 insertions(+), 50 deletions(-)
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index 4ae47ee..0e07b4a 100644
--- a/libavutil/parseutils.c
+++ b/libavutil/parseutils.c
@@ -404,61 +404,69 @@ static const char *small_strptime(const char *p, const char *fmt, struct tm *dt)
{
int c, val;
- for(;;) {
+ while((c = *fmt++)) {
+ if (c != '%') {
+ if (av_isspace(c))
+ for (; *p && av_isspace(*p); p++);
+ else if (*p != c)
+ return NULL;
+ else p++;
+ continue;
+ }
+
c = *fmt++;
- if (c == '\0') {
- return p;
- } else if (c == '%') {
- c = *fmt++;
- switch(c) {
- case 'H':
- val = date_get_num(&p, 0, 23, 2);
- if (val == -1)
- return NULL;
- dt->tm_hour = val;
- break;
- case 'M':
- val = date_get_num(&p, 0, 59, 2);
- if (val == -1)
- return NULL;
- dt->tm_min = val;
- break;
- case 'S':
- val = date_get_num(&p, 0, 59, 2);
- if (val == -1)
- return NULL;
- dt->tm_sec = val;
- break;
- case 'Y':
- val = date_get_num(&p, 0, 9999, 4);
- if (val == -1)
- return NULL;
- dt->tm_year = val - 1900;
- break;
- case 'm':
- val = date_get_num(&p, 1, 12, 2);
- if (val == -1)
- return NULL;
- dt->tm_mon = val - 1;
- break;
- case 'd':
- val = date_get_num(&p, 1, 31, 2);
- if (val == -1)
- return NULL;
- dt->tm_mday = val;
- break;
- case '%':
- goto match;
- default:
+ switch(c) {
+ case 'H':
+ val = date_get_num(&p, 0, 23, 2);
+ if (val == -1)
return NULL;
- }
- } else {
- match:
- if (c != *p)
+ dt->tm_hour = val;
+ break;
+ case 'M':
+ val = date_get_num(&p, 0, 59, 2);
+ if (val == -1)
return NULL;
- p++;
+ dt->tm_min = val;
+ break;
+ case 'S':
+ val = date_get_num(&p, 0, 59, 2);
+ if (val == -1)
+ return NULL;
+ dt->tm_sec = val;
+ break;
+ case 'Y':
+ val = date_get_num(&p, 0, 9999, 4);
+ if (val == -1)
+ return NULL;
+ dt->tm_year = val - 1900;
+ break;
+ case 'm':
+ val = date_get_num(&p, 1, 12, 2);
+ if (val == -1)
+ return NULL;
+ dt->tm_mon = val - 1;
+ break;
+ case 'd':
+ val = date_get_num(&p, 1, 31, 2);
+ if (val == -1)
+ return NULL;
+ dt->tm_mday = val;
+ break;
+ case 'T':
+ p = small_strptime(p, "%H:%M:%S", dt);
+ if (!p)
+ return NULL;
+ break;
+ case '%':
+ if (*p++ != '%')
+ return NULL;
+ break;
+ default:
+ return NULL;
}
}
+
+ return p;
}
time_t av_timegm(struct tm *tm)
More information about the ffmpeg-cvslog
mailing list