[MPlayer-dev-eng] [PATCH] Parsing simplification in vobsub

ubitux ubitux at gmail.com
Tue Apr 13 04:54:58 CEST 2010


Are you interested in that kind of patches? The attached patch shows a
simpler way of parsing timestamp/filepos lines. I can also do it for
parse_origin and parse_id, but I'd like to know if this can be accepted.

Also, I noted vobsub_parse_id allows an id with n characters, with
mallocs/free, etc. But DVDs only allow 2 characters per language, it can't
be more, so can I make a patch to simplify this while reducing parsing
lines?

Regards,

-- 
ubitux
-------------- next part --------------
Index: vobsub.c
===================================================================
--- vobsub.c	(revision 31035)
+++ vobsub.c	(working copy)
@@ -694,55 +709,12 @@
 
 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)
+
+    /* Spaces matter; they allow n whitespaces */
+    if (sscanf(line, " %d:%d:%d:%d , filepos: %lx ", &h, &m, &s, &ms, &filepos) != 5)
         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)
-        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)));
 }
 


More information about the MPlayer-dev-eng mailing list