Imported from ../bash-2.05b.tar.gz.
[platform/upstream/bash.git] / lib / glob / strmatch.c
1 /* strmatch.c -- ksh-like extended pattern matching for the shell and filename
2                 globbing. */
3
4 /* Copyright (C) 1991-2002 Free Software Foundation, Inc.
5
6    This file is part of GNU Bash, the Bourne Again SHell.
7    
8    Bash is free software; you can redistribute it and/or modify it under
9    the terms of the GNU General Public License as published by the Free
10    Software Foundation; either version 2, or (at your option) any later
11    version.
12               
13    Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14    WARRANTY; without even the implied warranty of MERCHANTABILITY or
15    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16    for more details.
17                          
18    You should have received a copy of the GNU General Public License along
19    with Bash; see the file COPYING.  If not, write to the Free Software
20    Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
21
22 #include <config.h>
23
24 #include "stdc.h"
25 #include "strmatch.h"
26
27 /* Structured this way so that if HAVE_LIBC_FNM_EXTMATCH is defined, the
28    matching portion of the library (smatch.c) is not linked into the shell. */
29
30 #ifndef HAVE_LIBC_FNM_EXTMATCH
31 extern int xstrmatch __P((char *, char *, int));
32 #else
33 #  define xstrmatch fnmatch
34 #endif
35
36 int
37 strmatch (pattern, string, flags)
38      char *pattern;
39      char *string;
40      int flags;
41 {
42   if (string == 0 || pattern == 0)
43     return FNM_NOMATCH;
44
45   return (xstrmatch (pattern, string, flags));
46 }
47
48 #ifdef TEST
49 main (c, v)
50      int c;
51      char **v;
52 {
53   char *string, *pat;
54
55   string = v[1];
56   pat = v[2];
57
58   if (strmatch (pat, string, 0) == 0)
59     {
60       printf ("%s matches %s\n", string, pat);
61       exit (0);
62     }
63   else
64     {
65       printf ("%s does not match %s\n", string, pat);
66       exit (1);
67     }
68 }
69 #endif