2
* (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
3
* All rights reserved. The file named COPYRIGHT specifies the terms
4
* and conditions for redistribution.
15
#define TRIVIAL_STR_FIND 1
17
#ifndef TRIVIAL_STR_FIND
19
#define LOWER_CASE( c ) ( (c) + 'a' - 'A' )
22
* look for an instance of sstr in str
23
* Returns a pointer to the beginning of sstr in str.
24
* It ignores the case of the alphabetic characters
26
char *str_casefind( register char *str, char *sstr )
28
register int ssfc = *sstr++ ; /* sub-string first char */
33
if ( isalpha( ssfc ) && isupper( ssfc ) )
34
ssfc = LOWER_CASE( ssfc ) ;
39
register int strc = *str++ ;
40
char *sp ; /* string pointer */
41
char *ssp ; /* sub-string pointer */
43
if ( isalpha( strc ) && isupper( strc ) )
44
strc = LOWER_CASE( strc ) ;
48
for ( sp = str, ssp = sstr ;; sp++, ssp++ )
50
register int sc = *sp ; /* string char */
51
register int ssc = *ssp ; /* substring char */
54
* End-of-substring means we got a match
60
* Convert to lower case if alphanumeric
62
if ( isalpha( sc ) && isupper( sc ) )
63
sc = LOWER_CASE( sc ) ;
64
if ( isalpha( ssc ) && isupper( ssc ) )
65
ssc = LOWER_CASE( ssc ) ;
75
#else /* defined( TRIVIAL_STR_FIND ) */
78
* look for an instance of s2 in s1
79
* Returns a pointer to the beginning of s2 in s1.
80
* It ignores the case of the alphabetic characters
82
char *str_casefind( char *s1, const char *s2 )
85
unsigned long l1 = strlen( s1 ) ;
86
unsigned long l2 = strlen( s2 ) ;
91
for ( i = 0 ; i < l1 - l2 + 1 ; i++ )
92
if ( strncasecmp( &s1[ i ], s2, l2 ) == 0 )
93
return( (char *) &s1[ i ] ) ;
97
#endif /* TRIVIAL_STR_FIND */
101
* Fill string s with character c
103
void str_fill( char *s, char c )
105
while ( *s ) *s++ = c ;