[MPlayer-dev-eng] [PATCH] SAMI subtitle files (subreader.c)

Bruno Lecointre bruno-lecointre at pacbell.net
Sun Aug 24 03:59:53 CEST 2003


Hi,
yes I agree that it would be nicer to be case insensitive. But since the
format was somewhat well defined I thought it was enough.
Anyway, here is a new patch for subreader.c where the search for
"Start=" is case insensitive.
As I am not very familiar with all the code in mplayer, nor with the
multi arch support, I decided to implement a somewhat optimized
strcasestr that I called stristr. I know that linux has a better
optimized version of that function but I am not using it since it is
GNU specific.
Here is a new patch for subreader.c.

Bruno
-------------- next part --------------
--- subreader.c	2003-08-23 18:46:34.000000000 -0700
+++ subreader.c.new	2003-08-23 18:44:22.000000000 -0700
@@ -74,6 +74,17 @@
 	while (i > 0 && isspace(s[i])) s[i--] = '\0';
 }
 
+static char *stristr(const char *haystack, const char *needle) {
+    int len = 0;
+    const char *p = haystack;
+
+    if (!(haystack && needle)) return NULL;
+
+    len=strlen(needle);
+    while (*p++ != '\0')
+	if (strncasecmp(p, needle, len) == 0) return (char*)p;
+    return NULL;
+}
 
 subtitle *sub_read_line_sami(FILE *fd, subtitle *current) {
     static char line[LINE_LEN+1];
@@ -92,11 +103,11 @@
 	switch (state) {
 
 	case 0: /* find "START=" or "Slacktime:" */
-	    slacktime_s = strstr (s, "Slacktime:");
+	    slacktime_s = stristr (s, "Slacktime:");
 	    if (slacktime_s) 
                 sub_slacktime = strtol (slacktime_s+10, NULL, 0) / 10;
 
-	    s = strstr (s, "Start=");
+	    s = stristr (s, "Start=");
 	    if (s) {
 		current->start = strtol (s + 6, &s, 0) / 10;
 		state = 1; continue;
@@ -104,7 +115,7 @@
 	    break;
  
 	case 1: /* find "<P" */
-	    if ((s = strstr (s, "<P"))) { s += 2; state = 2; continue; }
+	    if ((s = stristr (s, "<P"))) { s += 2; state = 2; continue; }
 	    break;
  
 	case 2: /* find ">" */
@@ -131,7 +142,7 @@
 	    continue;
 
 	case 4: /* get current->end or skip <TAG> */
-	    q = strstr (s, "Start=");
+	    q = stristr (s, "Start=");
 	    if (q) {
 		current->end = strtol (q + 6, &q, 0) / 10 - 1;
 		*p = '\0'; trail_space (text);


More information about the MPlayer-dev-eng mailing list