Files
nethack/util
nhmall f9d22e02cd 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 ===========================
2015-03-24 19:25:45 +02:00
..
2015-03-17 18:45:42 +02:00
2015-03-17 18:52:42 +02:00
2015-03-17 18:46:17 +02:00
2015-03-17 18:46:17 +02:00