Commit e444b4f6 authored by Derk-Jan Hartman's avatar Derk-Jan Hartman

* backport of local_stristr to vlc_strcasestr in libc.c

  fixes a problem with missing strcasestr on platforms in combination with ncurses intf.
parent 602e1fab
......@@ -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)
......
......@@ -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;
......
......@@ -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:
*****************************************************************************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment