YAZ  5.23.1
match_glob.c
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12 
13 #include <assert.h>
14 #include <stdlib.h>
15 #include <string.h>
16 
17 #include <yaz/xmalloc.h>
18 #include <yaz/wrbuf.h>
19 #include <yaz/match_glob.h>
20 
21 int yaz_match_glob(const char *glob, const char *text)
22 {
23  if (glob[0] == '\0')
24  return *text == '\0';
25  if (glob[0] == '*')
26  {
27  do
28  {
29  if (yaz_match_glob(glob+1, text))
30  return 1;
31  }
32  while (*text++);
33  return 0;
34  }
35  if (*text && (glob[0] == '?' || glob[0] == *text))
36  return yaz_match_glob(glob+1, text+1);
37  return 0;
38 }
39 
40 /*
41  * Local variables:
42  * c-basic-offset: 4
43  * c-file-style: "Stroustrup"
44  * indent-tabs-mode: nil
45  * End:
46  * vim: shiftwidth=4 tabstop=8 expandtab
47  */
48 
Header for WRBUF (growing buffer)
int yaz_match_glob(const char *glob, const char *text)
matches a glob expression against text
Definition: match_glob.c:21
Glob expression matcher.
Header for memory handling functions.