Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 1 | /* strmatch.c -- ksh-like extended pattern matching for the shell and filename |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 2 | globbing. */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 3 | |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 4 | /* Copyright (C) 1991-2002 Free Software Foundation, Inc. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 5 | |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 6 | This file is part of GNU Bash, the Bourne Again SHell. |
| 7 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 8 | Bash 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. |
| 12 | |
| 13 | Bash 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. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with Bash. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 21 | |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 22 | #include <config.h> |
Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 23 | |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 24 | #include "stdc.h" |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 25 | #include "strmatch.h" |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 26 | |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 27 | extern int xstrmatch __P((char *, char *, int)); |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 28 | #if defined (HANDLE_MULTIBYTE) |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 29 | extern int internal_wstrmatch __P((wchar_t *, wchar_t *, int)); |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 30 | #endif |
| 31 | |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 32 | int |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 33 | strmatch (pattern, string, flags) |
| 34 | char *pattern; |
| 35 | char *string; |
| 36 | int flags; |
| 37 | { |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 38 | if (string == 0 || pattern == 0) |
| 39 | return FNM_NOMATCH; |
| 40 | |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 41 | return (xstrmatch (pattern, string, flags)); |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 42 | } |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 43 | |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 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 | |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 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 | |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 68 | if (strmatch (pat, string, 0) == 0) |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 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 |