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