From e444b4f66ad187a14ef8ebb405837246f5be9746 Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Tue, 15 Jun 2004 13:47:42 +0000 Subject: [PATCH] * backport of local_stristr to vlc_strcasestr in libc.c fixes a problem with missing strcasestr on platforms in combination with ncurses intf. --- configure.ac | 1 + modules/demux/util/sub.c | 42 +++++++++------------------------------- src/extras/libc.c | 32 +++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/configure.ac b/configure.ac index cc39a92905..8ea337c200 100644 --- a/configure.ac +++ b/configure.ac @@ -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) diff --git a/modules/demux/util/sub.c b/modules/demux/util/sub.c index a06175b8cd..22330f6b27 100644 --- a/modules/demux/util/sub.c +++ b/modules/demux/util/sub.c @@ -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, "" ) ) + if( strcasestr( s, "" ) ) { 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; diff --git a/src/extras/libc.c b/src/extras/libc.c index cad26a92a5..c129dccdf8 100644 --- a/src/extras/libc.c +++ b/src/extras/libc.c @@ -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 * Samuel Hocevar @@ -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: *****************************************************************************/ -- 2.39.5