434182aab993e273fd729a62ac8c55a27366dbee
[egate.git] / ccl / cclstr.c
1 /* CCL string compare utilities
2  * Europagate, 1995
3  *
4  * $Log: cclstr.c,v $
5  * Revision 1.1  1995/05/11 14:03:57  adam
6  * Changes in the reading of qualifier(s). New function: ccl_qual_fitem.
7  * New variable ccl_case_sensitive, which controls whether reserved
8  * words and field names are case sensitive or not.
9  *
10  */
11 #include <ctype.h>
12 #include <stdio.h>
13
14 #include <ccl.h>
15
16 static int ccli_toupper (int c)
17 {
18     return toupper (c);
19 }
20
21 int (*ccl_toupper)(int c) = NULL;
22
23 int ccl_stricmp (const char *s1, const char *s2)
24 {
25     if (!ccl_toupper)
26         ccl_toupper = ccli_toupper;
27     while (*s1 && *s2)
28     {
29         int c1, c2;
30         c1 = (*ccl_toupper)(*s1);
31         c2 = (*ccl_toupper)(*s2);
32         if (c1 != c2)
33             return c1 - c2;
34         s1++;
35         s2++;
36     }
37     return (*ccl_toupper)(*s1) - (*ccl_toupper)(*s2);
38 }
39
40 int ccl_memicmp (const char *s1, const char *s2, size_t n)
41 {
42     if (!ccl_toupper)
43         ccl_toupper = ccli_toupper;
44     while (1)
45     {
46         int c1, c2;
47
48         c1 = (*ccl_toupper)(*s1);
49         c2 = (*ccl_toupper)(*s2);
50         if (n <= 1 || c1 != c2)
51             return c1 - c2;
52         s1++;
53         s2++;
54         --n;
55     }
56 }
57