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
#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 */
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);
*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,