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