i-bash/lib/glob/strmatch.c

70 lines
1.7 KiB
C
Raw Normal View History

2001-11-13 17:56:06 +00:00
/* strmatch.c -- ksh-like extended pattern matching for the shell and filename
1998-04-17 19:52:44 +00:00
globbing. */
2002-07-17 14:10:11 +00:00
/* Copyright (C) 1991-2002 Free Software Foundation, Inc.
1998-04-17 19:52:44 +00:00
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
2001-04-06 19:14:31 +00:00
1998-04-17 19:52:44 +00:00
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
2001-04-06 19:14:31 +00:00
1998-04-17 19:52:44 +00:00
You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
2000-03-17 21:46:59 +00:00
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
1998-04-17 19:52:44 +00:00
#include <config.h>
2000-03-17 21:46:59 +00:00
2002-07-17 14:10:11 +00:00
#include "stdc.h"
2001-11-13 17:56:06 +00:00
#include "strmatch.h"
1996-08-26 18:22:31 +00:00
2002-07-17 14:10:11 +00:00
/* Structured this way so that if HAVE_LIBC_FNM_EXTMATCH is defined, the
matching portion of the library (smatch.c) is not linked into the shell. */
1998-04-17 19:52:44 +00:00
2002-07-17 14:10:11 +00:00
#ifndef HAVE_LIBC_FNM_EXTMATCH
extern int xstrmatch __P((char *, char *, int));
1998-04-17 19:52:44 +00:00
#else
2002-07-17 14:10:11 +00:00
# define xstrmatch fnmatch
1998-04-17 19:52:44 +00:00
#endif
1996-08-26 18:22:31 +00:00
int
2001-11-13 17:56:06 +00:00
strmatch (pattern, string, flags)
1996-08-26 18:22:31 +00:00
char *pattern;
char *string;
int flags;
{
1998-04-17 19:52:44 +00:00
if (string == 0 || pattern == 0)
return FNM_NOMATCH;
2002-07-17 14:10:11 +00:00
return (xstrmatch (pattern, string, flags));
1996-08-26 18:22:31 +00:00
}
1998-04-17 19:52:44 +00:00
#ifdef TEST
main (c, v)
int c;
char **v;
{
char *string, *pat;
string = v[1];
pat = v[2];
2001-11-13 17:56:06 +00:00
if (strmatch (pat, string, 0) == 0)
1998-04-17 19:52:44 +00:00
{
printf ("%s matches %s\n", string, pat);
exit (0);
}
else
{
printf ("%s does not match %s\n", string, pat);
exit (1);
}
}
#endif