Add DLR's excellent workaround for strcasecmp not being available

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1511 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2003-08-04 02:51:12 +00:00
parent 653d614439
commit 4f5335d93e
4 changed files with 43 additions and 2 deletions

View File

@ -8,6 +8,10 @@ CVS code -
align()
- Tweak to avoid a potential problem when strp is non-NULL but
*strp is NULL. (David Benbennick)
nstricmp(), nstrnicmp()
- Add these functions, equivalent to strcasecmp() and
strncasecmp(), and convert nano to use them when strcasecmp()
and/or strncasecmp() are unavailable. (DLR)
- winio.c:
do_help()
- Get rid of keypad_on() call for bottomwin, which should not be

4
nano.h
View File

@ -80,11 +80,11 @@
#endif
#ifndef HAVE_STRCASECMP
#define strcasecmp strcmp
#define strcasecmp nstricmp
#endif
#ifndef HAVE_STRNCASECMP
#define strncasecmp strncmp
#define strncasecmp nstrnicmp
#endif
/* HP-UX 10 & 11 do not seem to support KEY_HOME and KEY_END */

View File

@ -399,6 +399,12 @@ void align(char **strp);
void null_at(char **data, size_t index);
void unsunder(char *str, size_t true_len);
void sunder(char *str);
#ifndef HAVE_STRCASECMP
int nstricmp(const char *s1, const char *s2);
#endif
#ifndef HAVE_STRNCASECMP
int nstrnicmp(const char *s1, const char *s2, size_t n);
#endif
#ifndef NANO_SMALL
const char *revstrstr(const char *haystack, const char *needle,
const char *rev_start);

31
utils.c
View File

@ -99,6 +99,37 @@ void sunder(char *str)
*str = '\0';
}
#ifndef HAVE_STRCASECMP
/* This function is equivalent to strcasecmp(). */
int nstricmp(const char *s1, const char *s2)
{
assert(s1 != NULL && s2 != NULL);
for (; *s1 != '\0' && *s2 != '\0'; s1++, s2++) {
if (tolower(*s1) != tolower(*s2))
break;
}
return (tolower(*s1) - tolower(*s2));
}
#endif
#ifndef HAVE_STRNCASECMP
/* This function is equivalent to strncasecmp(). */
int nstrnicmp(const char *s1, const char *s2, size_t n)
{
assert(s1 != NULL && s2 != NULL);
for (; n > 0 && *s1 != '\0' && *s2 != '\0'; n--, s1++, s2++) {
if (tolower(*s1) != tolower(*s2))
break;
}
if (n > 0)
return (tolower(*s1) - tolower(*s2));
else if (n == 0)
return 0;
else if (n < 0)
return -1;
}
#endif
/* None of this is needed if we're using NANO_SMALL! */
#ifndef NANO_SMALL
const char *revstrstr(const char *haystack, const char *needle,