You need to sign in or sign up before continuing.
Commit 4f5335d9 authored by Chris Allegretta's avatar Chris Allegretta
Browse files

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
parent 653d6144
No related merge requests found
Showing with 43 additions and 2 deletions
+43 -2
...@@ -8,6 +8,10 @@ CVS code - ...@@ -8,6 +8,10 @@ CVS code -
align() align()
- Tweak to avoid a potential problem when strp is non-NULL but - Tweak to avoid a potential problem when strp is non-NULL but
*strp is NULL. (David Benbennick) *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: - winio.c:
do_help() do_help()
- Get rid of keypad_on() call for bottomwin, which should not be - Get rid of keypad_on() call for bottomwin, which should not be
......
...@@ -80,11 +80,11 @@ ...@@ -80,11 +80,11 @@
#endif #endif
#ifndef HAVE_STRCASECMP #ifndef HAVE_STRCASECMP
#define strcasecmp strcmp #define strcasecmp nstricmp
#endif #endif
#ifndef HAVE_STRNCASECMP #ifndef HAVE_STRNCASECMP
#define strncasecmp strncmp #define strncasecmp nstrnicmp
#endif #endif
/* HP-UX 10 & 11 do not seem to support KEY_HOME and KEY_END */ /* HP-UX 10 & 11 do not seem to support KEY_HOME and KEY_END */
......
...@@ -399,6 +399,12 @@ void align(char **strp); ...@@ -399,6 +399,12 @@ void align(char **strp);
void null_at(char **data, size_t index); void null_at(char **data, size_t index);
void unsunder(char *str, size_t true_len); void unsunder(char *str, size_t true_len);
void sunder(char *str); 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 #ifndef NANO_SMALL
const char *revstrstr(const char *haystack, const char *needle, const char *revstrstr(const char *haystack, const char *needle,
const char *rev_start); const char *rev_start);
......
...@@ -99,6 +99,37 @@ void sunder(char *str) ...@@ -99,6 +99,37 @@ void sunder(char *str)
*str = '\0'; *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! */ /* None of this is needed if we're using NANO_SMALL! */
#ifndef NANO_SMALL #ifndef NANO_SMALL
const char *revstrstr(const char *haystack, const char *needle, const char *revstrstr(const char *haystack, const char *needle,
......
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