Update configure to generate config.h
[yaz-moved-to-github.git] / src / cclstr.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2010 Index Data
3  * See the file LICENSE for details.
4  */
5 /** 
6  * \file cclstr.c
7  * \brief Implements CCL string compare utilities
8  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12 #include <ctype.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15
16 #include <yaz/ccl.h>
17
18 static int ccli_toupper (int c)
19 {
20     return toupper (c);
21 }
22
23 int (*ccl_toupper)(int c) = NULL;
24
25 int ccl_stricmp (const char *s1, const char *s2)
26 {
27     if (!ccl_toupper)
28         ccl_toupper = ccli_toupper;
29     while (*s1 && *s2)
30     {
31         int c1, c2;
32         c1 = (*ccl_toupper)(*s1);
33         c2 = (*ccl_toupper)(*s2);
34         if (c1 != c2)
35             return c1 - c2;
36         s1++;
37         s2++;
38     }
39     return (*ccl_toupper)(*s1) - (*ccl_toupper)(*s2);
40 }
41
42 int ccl_memicmp (const char *s1, const char *s2, size_t n)
43 {
44     if (!ccl_toupper)
45         ccl_toupper = ccli_toupper;
46     while (1)
47     {
48         int c1, c2;
49
50         c1 = (*ccl_toupper)(*s1);
51         c2 = (*ccl_toupper)(*s2);
52         if (n <= 1 || c1 != c2)
53             return c1 - c2;
54         s1++;
55         s2++;
56         --n;
57     }
58 }
59
60 /*
61  * Local variables:
62  * c-basic-offset: 4
63  * c-file-style: "Stroustrup"
64  * indent-tabs-mode: nil
65  * End:
66  * vim: shiftwidth=4 tabstop=8 expandtab
67  */
68