# HG changeset patch # User cboesch # Date 1307876124 0 # Node ID 65e6c1de4afa4d29338387ad52e1e87748435959 # Parent 2d1fa588834a1a1fdcc74d53c2c6b9cad7b91460 vobsub: simplify timestamp parsing. diff -r 2d1fa588834a -r 65e6c1de4afa sub/vobsub.c --- a/sub/vobsub.c Sun Jun 12 10:41:49 2011 +0000 +++ b/sub/vobsub.c Sun Jun 12 10:55:24 2011 +0000 @@ -693,55 +693,11 @@ 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) + if (sscanf(line, " %02d:%02d:%02d:%03d, filepos: %09lx", + &h, &m, &s, &ms, &filepos) != 5) return -1; - s = atoi(line); - if (*p != ':') - return -1; - line = ++p; - while (isdigit(*p)) - ++p; - if (p - line != 3) - 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))); }