Reinsert initialiser for __UNUSED_loglevel
[yaz-moved-to-github.git] / src / matchstr.c
1 /*
2  * Copyright (C) 1995-2005, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: matchstr.c,v 1.5 2005-06-25 15:46:04 adam Exp $
6  */
7
8 /**
9  * \file matchstr.c
10  * \brief Implements loose string matching 
11  */
12
13 #if HAVE_CONFIG_H
14 #include <config.h>
15 #endif
16
17 #include <stdio.h>
18 #include <assert.h>
19 #include <ctype.h>
20 #include <string.h>
21 #include <yaz/yaz-util.h>
22
23 /*
24  * Match strings, independently of case and occurences of '-'.
25  * fairly inefficient - will be replaced with an indexing scheme for
26  * the various subsystems if we get a bottleneck here.
27  */
28
29 int yaz_matchstr(const char *s1, const char *s2)
30 {
31     while (*s1 && *s2)
32     {
33         unsigned char c1 = *s1;
34         unsigned char c2 = *s2;
35
36         if (c2 == '?')
37             return 0;
38         if (c1 == '-')
39             c1 = *++s1;
40         if (c2 == '-')
41             c2 = *++s2;
42         if (!c1 || !c2)
43             break;
44         if (c2 != '.')
45         {
46             if (isupper(c1))
47                 c1 = tolower(c1);
48             if (isupper(c2))
49                 c2 = tolower(c2);
50             if (c1 != c2)
51                 break;
52         }
53         s1++;
54         s2++;
55     }
56     return *s1 || *s2;
57 }
58
59 int yaz_strcmp_del(const char *a, const char *b, const char *b_del)
60 {
61     while (*a && *b)
62     {
63         if (*a != *b)
64             return *a - *b;
65         a++;
66         b++;
67     }
68     if (b_del && strchr(b_del, *b))
69         return *a;
70     return *a - *b;
71 }
72
73 #ifdef __GNUC__
74 #ifdef __CHECKER__
75 void __assert_fail (const char *assertion, const char *file, 
76                     unsigned int line, const char *function)
77 {
78     fprintf (stderr, "%s in file %s line %d func %s\n",
79              assertion, file, line, function);
80     abort ();
81 }
82 #endif
83 #endif
84 /*
85  * Local variables:
86  * c-basic-offset: 4
87  * indent-tabs-mode: nil
88  * End:
89  * vim: shiftwidth=4 tabstop=8 expandtab
90  */
91