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 | extern int xstrmatch __P((char *, char *, int));
|
---|
28 | #if defined (HAVE_MULTIBYTE)
|
---|
29 | extern int internal_wstrmatch __P((wchar_t *, wchar_t *, int));
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | int
|
---|
33 | strmatch (pattern, string, flags)
|
---|
34 | char *pattern;
|
---|
35 | char *string;
|
---|
36 | int flags;
|
---|
37 | {
|
---|
38 | if (string == 0 || pattern == 0)
|
---|
39 | return FNM_NOMATCH;
|
---|
40 |
|
---|
41 | return (xstrmatch (pattern, string, flags));
|
---|
42 | }
|
---|
43 |
|
---|
44 | #if defined (HANDLE_MULTIBYTE)
|
---|
45 | int
|
---|
46 | wcsmatch (wpattern, wstring, flags)
|
---|
47 | wchar_t *wpattern;
|
---|
48 | wchar_t *wstring;
|
---|
49 | int flags;
|
---|
50 | {
|
---|
51 | if (wstring == 0 || wpattern == 0)
|
---|
52 | return (FNM_NOMATCH);
|
---|
53 |
|
---|
54 | return (internal_wstrmatch (wpattern, wstring, flags));
|
---|
55 | }
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | #ifdef TEST
|
---|
59 | main (c, v)
|
---|
60 | int c;
|
---|
61 | char **v;
|
---|
62 | {
|
---|
63 | char *string, *pat;
|
---|
64 |
|
---|
65 | string = v[1];
|
---|
66 | pat = v[2];
|
---|
67 |
|
---|
68 | if (strmatch (pat, string, 0) == 0)
|
---|
69 | {
|
---|
70 | printf ("%s matches %s\n", string, pat);
|
---|
71 | exit (0);
|
---|
72 | }
|
---|
73 | else
|
---|
74 | {
|
---|
75 | printf ("%s does not match %s\n", string, pat);
|
---|
76 | exit (1);
|
---|
77 | }
|
---|
78 | }
|
---|
79 | #endif
|
---|