blob: cea9bd862c92409488acdfd37a02425c82c45252 [file] [log] [blame]
Jari Aaltof73dda02001-11-13 17:56:06 +00001/* strmatch.c -- ksh-like extended pattern matching for the shell and filename
Jari Aaltocce855b1998-04-17 19:52:44 +00002 globbing. */
Jari Aalto726f6381996-08-26 18:22:31 +00003
Jari Aalto7117c2d2002-07-17 14:10:11 +00004/* Copyright (C) 1991-2002 Free Software Foundation, Inc.
Jari Aalto726f6381996-08-26 18:22:31 +00005
Jari Aaltocce855b1998-04-17 19:52:44 +00006 This file is part of GNU Bash, the Bourne Again SHell.
7
Jari Aalto31859422009-01-12 13:36:28 +00008 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 Aalto726f6381996-08-26 18:22:31 +000021
Jari Aaltocce855b1998-04-17 19:52:44 +000022#include <config.h>
Jari Aaltobb706242000-03-17 21:46:59 +000023
Jari Aalto7117c2d2002-07-17 14:10:11 +000024#include "stdc.h"
Jari Aaltof73dda02001-11-13 17:56:06 +000025#include "strmatch.h"
Jari Aalto726f6381996-08-26 18:22:31 +000026
Jari Aalto7117c2d2002-07-17 14:10:11 +000027extern int xstrmatch __P((char *, char *, int));
Jari Aalto31859422009-01-12 13:36:28 +000028#if defined (HANDLE_MULTIBYTE)
Jari Aaltob80f6442004-07-27 13:29:18 +000029extern int internal_wstrmatch __P((wchar_t *, wchar_t *, int));
Jari Aalto726f6381996-08-26 18:22:31 +000030#endif
31
Jari Aalto726f6381996-08-26 18:22:31 +000032int
Jari Aaltof73dda02001-11-13 17:56:06 +000033strmatch (pattern, string, flags)
34 char *pattern;
35 char *string;
36 int flags;
37{
Jari Aaltof73dda02001-11-13 17:56:06 +000038 if (string == 0 || pattern == 0)
39 return FNM_NOMATCH;
40
Jari Aalto7117c2d2002-07-17 14:10:11 +000041 return (xstrmatch (pattern, string, flags));
Jari Aaltof73dda02001-11-13 17:56:06 +000042}
Jari Aaltocce855b1998-04-17 19:52:44 +000043
Jari Aaltob80f6442004-07-27 13:29:18 +000044#if defined (HANDLE_MULTIBYTE)
45int
46wcsmatch (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 Aaltocce855b1998-04-17 19:52:44 +000058#ifdef TEST
59main (c, v)
60 int c;
61 char **v;
62{
63 char *string, *pat;
64
65 string = v[1];
66 pat = v[2];
67
Jari Aaltof73dda02001-11-13 17:56:06 +000068 if (strmatch (pat, string, 0) == 0)
Jari Aaltocce855b1998-04-17 19:52:44 +000069 {
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