Happy new year
[yaz-moved-to-github.git] / src / match_glob.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2011 Index Data
3  * See the file LICENSE for details.
4  */
5 /**
6  * \file
7  * \brief Glob expression match
8  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12
13 #include <assert.h>
14 #include <stdlib.h>
15 #include <ctype.h>
16 #include <string.h>
17
18 #include <yaz/xmalloc.h>
19 #include <yaz/wrbuf.h>
20 #include <yaz/match_glob.h>
21
22 int yaz_match_glob(const char *glob, const char *text)
23 {
24     if (glob[0] == '\0')
25         return *text == '\0';
26     if (glob[0] == '*')
27     {
28         do 
29         {
30             if (yaz_match_glob(glob+1, text))
31                 return 1;
32         }
33         while (*text++);
34         return 0;
35     }
36     if (*text && (glob[0] == '?' || glob[0] == *text))
37         return yaz_match_glob(glob+1, text+1);
38     return 0;
39 }
40
41 /*
42  * Local variables:
43  * c-basic-offset: 4
44  * c-file-style: "Stroustrup"
45  * indent-tabs-mode: nil
46  * End:
47  * vim: shiftwidth=4 tabstop=8 expandtab
48  */
49