[MPlayer-dev-eng] [PATCHES] vobsub back to the future

Clément Bœsch ubitux at gmail.com
Sat Jun 11 18:40:38 CEST 2011


Two patches that were lying in a forgotten directory attached. I remember
sending them a while ago, but I can't remember the outcome :)

Also, I discarded the 3rd one because I think the code is simpler in the
current state.

-- 
Clément B.
-------------- next part --------------
From 42a350d87d04f4242a8ab3242ddc18d054146258 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Sat, 11 Jun 2011 18:27:38 +0200
Subject: [PATCH 1/2] vobsub: simplify timestamp parsing.

---
 sub/vobsub.c |   48 ++----------------------------------------------
 1 files changed, 2 insertions(+), 46 deletions(-)

diff --git a/sub/vobsub.c b/sub/vobsub.c
index c2d85cc..4d69fbb 100644
--- a/sub/vobsub.c
+++ b/sub/vobsub.c
@@ -693,55 +693,11 @@ 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)
-        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))
+    if (sscanf(line, " %02d:%02d:%02d:%03d, filepos: %09lx",
+               &h, &m, &s, &ms, &filepos) != 5)
         return -1;
-    filepos = strtol(line, NULL, 16);
     return vobsub_add_timestamp(vob, filepos, vob->delay + ms + 1000 * (s + 60 * (m + 60 * h)));
 }
 
-- 
1.7.5.2

-------------- next part --------------
From 5b57cb07306ead68834df58a5e10249a7470c617 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Sat, 11 Jun 2011 18:30:58 +0200
Subject: [PATCH 2/2] vobsub: simplify origin parsing.

---
 sub/vobsub.c |   19 ++++++++-----------
 1 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/sub/vobsub.c b/sub/vobsub.c
index 4d69fbb..5817605 100644
--- a/sub/vobsub.c
+++ b/sub/vobsub.c
@@ -704,17 +704,14 @@ static int vobsub_parse_timestamp(vobsub_t *vob, const char *line)
 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 int x, y;
+
+    if (sscanf(line, " %d,%d", &x, &y) == 2) {
+        vob->origin_x = x;
+        vob->origin_y = y;
+        return 0;
+    }
+    return -1;
 }
 
 unsigned int vobsub_palette_to_yuv(unsigned int pal)
-- 
1.7.5.2

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20110611/542480a6/attachment.asc>


More information about the MPlayer-dev-eng mailing list