commit 4f5335d93e9a00860fe4c8e38a9632ef0106fc37
parent 653d6144390e9579ccb51417ac514978a47661da
Author: Chris Allegretta <chrisa@asty.org>
Date: Mon, 4 Aug 2003 02:51:12 +0000
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
Diffstat:
4 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -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
diff --git a/nano.h b/nano.h
@@ -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 */
diff --git a/proto.h b/proto.h
@@ -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);
diff --git a/utils.c b/utils.c
@@ -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,