init version.
[bush.git] / lib / glob / strmatch.c
blob0cc2cb791ca584b436806b17fd1fcbad1b76f2ef
1 /* strmatch.c -- ksh-like extended pattern matching for the shell and filename
2 globbing. */
4 /* Copyright (C) 1991-2020 Free Software Foundation, Inc.
6 This file is part of GNU Bush, the Bourne Again SHell.
8 Bush is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 Bush is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Bush. If not, see <http://www.gnu.org/licenses/>.
22 #include <config.h>
24 #include "stdc.h"
25 #include "strmatch.h"
27 extern int xstrmatch PARAMS((char *, char *, int));
28 #if defined (HANDLE_MULTIBYTE)
29 extern int internal_wstrmatch PARAMS((wchar_t *, wchar_t *, int));
30 #endif
32 int
33 strmatch (pattern, string, flags)
34 char *pattern;
35 char *string;
36 int flags;
38 if (string == 0 || pattern == 0)
39 return FNM_NOMATCH;
41 return (xstrmatch (pattern, string, flags));
44 #if defined (HANDLE_MULTIBYTE)
45 int
46 wcsmatch (wpattern, wstring, flags)
47 wchar_t *wpattern;
48 wchar_t *wstring;
49 int flags;
51 if (wstring == 0 || wpattern == 0)
52 return (FNM_NOMATCH);
54 return (internal_wstrmatch (wpattern, wstring, flags));
56 #endif
58 #ifdef TEST
59 main (c, v)
60 int c;
61 char **v;
63 char *string, *pat;
65 string = v[1];
66 pat = v[2];
68 if (strmatch (pat, string, 0) == 0)
70 printf ("%s matches %s\n", string, pat);
71 exit (0);
73 else
75 printf ("%s does not match %s\n", string, pat);
76 exit (1);
79 #endif