From 81c227d221b959329dc67121146a1c1960d2e602 Mon Sep 17 00:00:00 2001 From: cboesch Date: Sun, 12 Jun 2011 10:55:24 +0000 Subject: 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 --- sub/vobsub.c | 67 +++++++++--------------------------------------------------- 1 file changed, 10 insertions(+), 57 deletions(-) (limited to 'sub') 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) -- cgit v1.2.3