lev_main's own internal case-insensitive compare
TEST SUITE
int case_insensitive_comp(const char *, const char *);
/* define your built-in compiler library variation here */
/* #define BUILTIN(a,b) strcasecmp(a,b) */
/* #define BUILTIN(a,b) stricmp(a,b) */
int main(int argc, char *argv[])
{
const char *t1 = "NetHack";
const char *t2 = "nethack";
const char *t3 = "Fred";
const char *t4 = "Barney lived next door";
/* try the results with built-in strcmpi first */
printf("builtin:\tcompare <%s> to <%s>, result %d.\n",
t1, t2, BUILTIN(t1,t2));
printf("builtin:\tcompare <%s> to <%s>, result %d.\n",
t3, t4, BUILTIN(t3,t4));
/* try the results with case_insensitive_comp 2nd */
printf("ours:\tcompare <%s> to <%s>, result %d.\n",
t1, t2, case_insensitive_comp(t1,t2));
printf("ours:\tcompare <%s> to <%s>, result %d.\n",
t3, t4, case_insensitive_comp(t3,t4));
}
int
case_insensitive_comp(s1, s2)
const char *s1;
const char *s2;
{
unsigned char u1, u2;
for ( ; ; s1++, s2++) {
u1 = tolower((unsigned char) *s1);
u2 = tolower((unsigned char) *s2);
if ((u1 == '\0') || (u1 != u2)) {
break;
}
}
return u1-u2;
}
======================== END TEST SUITE ===========================