New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
[yaz-moved-to-github.git] / util / matchstr.c
1 /*
2  * Copyright (c) 1995-1997, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: matchstr.c,v $
7  * Revision 1.1  1999-06-08 10:10:16  adam
8  * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
9  *
10  * Revision 1.7  1997/09/30 11:47:47  adam
11  * Added function 'cause checkergcc doesn't include assert handler.
12  *
13  * Revision 1.6  1997/09/04 07:54:34  adam
14  * Right hande side operand of yaz_matchstr may include a ? in
15  * which case it returns "match ok".
16  *
17  * Revision 1.5  1997/07/21 12:48:11  adam
18  * Removed windows DLL stubs.
19  *
20  * Revision 1.4  1997/05/01 15:07:55  adam
21  * Added DLL entry point routines.
22  *
23  * Revision 1.3  1996/10/29 13:36:28  adam
24  * Added header.
25  *
26  * Revision 1.2  1996/02/20 17:58:42  adam
27  * Added const to yaz_matchstr.
28  *
29  * Revision 1.1  1996/02/20  16:33:06  quinn
30  * Moved matchstr to global util
31  *
32  * Revision 1.1  1995/11/01  11:56:08  quinn
33  * Added Retrieval (data management) functions en masse.
34  *
35  *
36  */
37 #include <stdio.h>
38 #include <assert.h>
39 #include <ctype.h>
40 #include <yaz-util.h>
41
42 /*
43  * Match strings, independently of case and occurences of '-'.
44  * fairly inefficient - will be replaced with an indexing scheme for
45  * the various subsystems if we get a bottleneck here.
46  */
47
48 int yaz_matchstr(const char *s1, const char *s2)
49 {
50     while (*s1 && *s2)
51     {
52         char c1, c2;
53
54         if (*s2 == '?')
55             return 0;
56         if (*s1 == '-')
57             s1++;
58         if (*s2 == '-')
59             s2++;
60         if (!*s1 || !*s2)
61             break;
62         c1 = *s1;
63         c2 = *s2;
64         if (isupper(c1))
65             c1 = tolower(c1);
66         if (isupper(c2))
67             c2 = tolower(c2);
68         if (c1 != c2)
69             break;
70         s1++;
71         s2++;
72     }
73     return *s1 || *s2;
74 }
75
76 #ifdef __GNUC__
77 #ifdef __CHECKER__
78 void __assert_fail (const char *assertion, const char *file, 
79                     unsigned int line, const char *function)
80 {
81     fprintf (stderr, "%s in file %s line %d func %s\n",
82              assertion, file, line, function);
83     abort ();
84 }
85 #endif
86 #endif