]> git.sesse.net Git - vlc/commitdiff
* backport of local_stristr to vlc_strcasestr in libc.c
authorDerk-Jan Hartman <hartman@videolan.org>
Tue, 15 Jun 2004 13:47:42 +0000 (13:47 +0000)
committerDerk-Jan Hartman <hartman@videolan.org>
Tue, 15 Jun 2004 13:47:42 +0000 (13:47 +0000)
  fixes a problem with missing strcasestr on platforms in combination with ncurses intf.

configure.ac
modules/demux/util/sub.c
src/extras/libc.c

index cc39a929054247706cceac226dc0b7de9ccbac8e..8ea337c200138882998ac67e12cdb3463e601b9a 100644 (file)
@@ -294,6 +294,7 @@ dnl Check for usual libc functions
 AC_CHECK_FUNCS(strdup strndup atof lseek)
 AC_CHECK_FUNCS(strcasecmp,,[AC_CHECK_FUNCS(stricmp)])
 AC_CHECK_FUNCS(strncasecmp,,[AC_CHECK_FUNCS(strnicmp)])
+AC_CHECK_FUNCS(strcasestr,,[AC_CHECK_FUNCS(stristr)])
 
 dnl Check for setlocal and langinfo
 AC_CHECK_FUNCS(setlocale)
index a06175b8cdd9774143d5216956ffac0523d5489a..22330f6b276e846d62794c9cb24e476d896ac1b8 100644 (file)
@@ -234,30 +234,6 @@ static struct
     { NULL,         SUB_TYPE_UNKNOWN,   "Unknown",  NULL }
 };
 
-static char * local_stristr( char *psz_big, char *psz_little)
-{
-    char *p_pos = psz_big;
-
-    if (!psz_big || !psz_little || !*psz_little) return psz_big;
-
-    while (*p_pos)
-    {
-        if (toupper(*p_pos) == toupper(*psz_little))
-        {
-            char * psz_cur1 = p_pos + 1;
-            char * psz_cur2 = psz_little + 1;
-            while (*psz_cur1 && *psz_cur2 && toupper(*psz_cur1) == toupper(*psz_cur2))
-            {
-                psz_cur1++;
-                psz_cur2++;
-            }
-            if (!*psz_cur2) return p_pos;
-        }
-        p_pos++;
-    }
-    return NULL;
-}
-
 /*****************************************************************************
  * sub_open: Open a subtitle file and add subtitle ES
  *****************************************************************************/
@@ -352,7 +328,7 @@ static int sub_open( subtitle_demux_t *p_sub, input_thread_t  *p_input,
                 break;
             }
 
-            if( local_stristr( s, "<SAMI>" ) )
+            if( strcasestr( s, "<SAMI>" ) )
             {
                 i_sub_type = SUB_TYPE_SAMI;
                 break;
@@ -385,7 +361,7 @@ static int sub_open( subtitle_demux_t *p_sub, input_thread_t  *p_input,
                 }
                 break;
             }
-            else if( local_stristr( s, "This is a Sub Station Alpha v4 script" ) )
+            else if( strcasestr( s, "This is a Sub Station Alpha v4 script" ) )
             {
                 i_sub_type = SUB_TYPE_SSA2_4; /* I hope this will work */
                 break;
@@ -395,7 +371,7 @@ static int sub_open( subtitle_demux_t *p_sub, input_thread_t  *p_input,
                 i_sub_type = SUB_TYPE_SSA2_4; /* could be wrong */
                 break;
             }
-            else if( local_stristr( s, "[INFORMATION]" ) )
+            else if( strcasestr( s, "[INFORMATION]" ) )
             {
                 i_sub_type = SUB_TYPE_SUBVIEWER; /* I hope this will work */
                 break;
@@ -406,7 +382,7 @@ static int sub_open( subtitle_demux_t *p_sub, input_thread_t  *p_input,
                 i_sub_type = SUB_TYPE_VPLAYER;
                 break;
             }
-            else if( local_stristr( s, "# VobSub index file" ) )
+            else if( strcasestr( s, "# VobSub index file" ) )
             {
                 i_sub_type = SUB_TYPE_VOBSUB;
                 break;
@@ -1114,9 +1090,9 @@ static char *sub_SamiSearch( text_t *txt, char *psz_start, char *psz_str )
 {
     if( psz_start )
     {
-        if( local_stristr( psz_start, psz_str ) )
+        if( strcasestr( psz_start, psz_str ) )
         {
-            char *s = local_stristr( psz_start, psz_str );
+            char *s = strcasestr( psz_start, psz_str );
 
             s += strlen( psz_str );
 
@@ -1130,9 +1106,9 @@ static char *sub_SamiSearch( text_t *txt, char *psz_start, char *psz_str )
         {
             return NULL;
         }
-        if( local_stristr( p, psz_str ) )
+        if( strcasestr( p, psz_str ) )
         {
-            char *s = local_stristr( p, psz_str );
+            char *s = strcasestr( p, psz_str );
 
             s += strlen( psz_str );
 
@@ -1194,7 +1170,7 @@ static int  sub_Sami( subtitle_demux_t *p_sub, text_t *txt, subtitle_t *p_subtit
                 {
                     ADDC( '\n' );
                 }
-                else if( local_stristr( p, "Start=" ) )
+                else if( strcasestr( p, "Start=" ) )
                 {
                     text_previous_line( txt );
                     break;
index cad26a92a567849a464f6507ab6bbd65e6dbedb9..c129dccdf84b1f88f1a029b5d78e92d4cc4aeafe 100644 (file)
@@ -2,7 +2,7 @@
  * libc.c: Extra libc function for some systems.
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: libc.c,v 1.16 2004/02/09 16:12:25 sigmunau Exp $
+ * $Id$
  *
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
  *          Samuel Hocevar <sam@zoy.org>
@@ -127,6 +127,36 @@ int vlc_strncasecmp( const char *s1, const char *s2, size_t n )
 }
 #endif
 
+/******************************************************************************
+ * strcasestr: find a substring (little) in another substring (big)
+ * Case sensitive. Return NULL if not found, return big if little == null
+ *****************************************************************************/
+#if !defined( HAVE_STRCASESTR ) && !defined( HAVE_STRISTR )
+static char * vlc_strncasestr( const char *psz_big, const char *psz_little )
+{
+    char *p_pox = psz_big;
+
+    if( !psz_big || !psz_little || !*psz_little ) return psz_big;
+    while( *p_pos ) 
+    {
+        if( toupper( *p_pos ) == toupper( *psz_little ) )
+        {
+            char * psz_cur1 = p_pos + 1;
+            char * psz_cur2 = psz_little + 1;
+            while( *psz_cur1 && *psz_cur2 && toupper( *psz_cur1 ) == toupper( *psz_cur2 ) )
+            {
+                psz_cur1++;
+                psz_cur2++;
+            }
+            if( !*psz_cur2 ) return p_pos;
+        }
+        p_pos++;
+    }
+    return NULL;
+}
+#endif
+
 /*****************************************************************************
  * vasprintf:
  *****************************************************************************/