summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorcboesch <cboesch@b3059339-0415-0410-9bf9-f77b7e298cf2>2011-06-12 10:55:24 +0000
committerUoti Urpala <uau@mplayer2.org>2011-07-06 13:01:07 +0300
commit81c227d221b959329dc67121146a1c1960d2e602 (patch)
tree785a9bbcb66b5de061909b05ac8b51847d86cfaa /sub
parent58834653c01d95196d4efa012e49fd6a1c270851 (diff)
downloadmpv-81c227d221b959329dc67121146a1c1960d2e602.tar.bz2
mpv-81c227d221b959329dc67121146a1c1960d2e602.tar.xz
cleanup: vobsub.c: simplify parsing
vobsub: simplify timestamp parsing. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33601 b3059339-0415-0410-9bf9-f77b7e298cf2 vobsub: simplify origin parsing. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33602 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'sub')
-rw-r--r--sub/vobsub.c67
1 files changed, 10 insertions, 57 deletions
diff --git a/sub/vobsub.c b/sub/vobsub.c
index 2d64541d53..bfee3eb98f 100644
--- a/sub/vobsub.c
+++ b/sub/vobsub.c
@@ -694,72 +694,25 @@ static int vobsub_parse_id(vobsub_t *vob, const char *line)
static int vobsub_parse_timestamp(vobsub_t *vob, const char *line)
{
- // timestamp: HH:MM:SS.mmm, filepos: 0nnnnnnnnn
- const char *p;
int h, m, s, ms;
off_t filepos;
- while (isspace(*line))
- ++line;
- p = line;
- while (isdigit(*p))
- ++p;
- if (p - line != 2)
- return -1;
- h = atoi(line);
- if (*p != ':')
- return -1;
- line = ++p;
- while (isdigit(*p))
- ++p;
- if (p - line != 2)
- return -1;
- m = atoi(line);
- if (*p != ':')
- return -1;
- line = ++p;
- while (isdigit(*p))
- ++p;
- if (p - line != 2)
- return -1;
- s = atoi(line);
- if (*p != ':')
- return -1;
- line = ++p;
- while (isdigit(*p))
- ++p;
- if (p - line != 3)
+ if (sscanf(line, " %02d:%02d:%02d:%03d, filepos: %09lx",
+ &h, &m, &s, &ms, &filepos) != 5)
return -1;
- ms = atoi(line);
- if (*p != ',')
- return -1;
- line = p + 1;
- while (isspace(*line))
- ++line;
- if (strncmp("filepos:", line, 8))
- return -1;
- line += 8;
- while (isspace(*line))
- ++line;
- if (! isxdigit(*line))
- return -1;
- filepos = strtol(line, NULL, 16);
return vobsub_add_timestamp(vob, filepos, vob->delay + ms + 1000 * (s + 60 * (m + 60 * h)));
}
static int vobsub_parse_origin(vobsub_t *vob, const char *line)
{
// org: X,Y
- char *p;
- while (isspace(*line))
- ++line;
- if (!isdigit(*line))
- return -1;
- vob->origin_x = strtoul(line, &p, 10);
- if (*p != ',')
- return -1;
- ++p;
- vob->origin_y = strtoul(p, NULL, 10);
- return 0;
+ unsigned x, y;
+
+ if (sscanf(line, " %u,%u", &x, &y) == 2) {
+ vob->origin_x = x;
+ vob->origin_y = y;
+ return 0;
+ }
+ return -1;
}
unsigned int vobsub_palette_to_yuv(unsigned int pal)