Implement -iname for case insensitive matching on file names.

From freebsd/openbsd.  Approved by jaromir@, manu@, perry@.
This commit is contained in:
provos 2003-08-03 19:46:03 +00:00
parent 69f1e70775
commit ccc5fba3de
5 changed files with 45 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.18 2003/02/23 14:43:25 jhawk Exp $ */
/* $NetBSD: extern.h,v 1.19 2003/08/03 19:46:03 provos Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@ -64,6 +64,7 @@ PLAN *c_flags __P((char ***, int));
PLAN *c_follow __P((char ***, int));
PLAN *c_fstype __P((char ***, int));
PLAN *c_group __P((char ***, int));
PLAN *c_iname __P((char ***, int));
PLAN *c_inum __P((char ***, int));
PLAN *c_iregex __P((char ***, int));
PLAN *c_links __P((char ***, int));

View File

@ -1,4 +1,4 @@
.\" $NetBSD: find.1,v 1.45 2003/06/26 17:46:36 wiz Exp $
.\" $NetBSD: find.1,v 1.46 2003/08/03 19:46:03 provos Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -291,6 +291,11 @@ If
is numeric and there is no such group name, then
.Ar gname
is treated as a group id.
.It Ic -iname Ar pattern
True if the last component of the pathname being examined
matches
.Ar pattern .
Case insensitive.
.It Ic -inum Ar n
True if the file has inode number
.Ar n .
@ -614,6 +619,7 @@ The options and the
.Ic -empty ,
.Ic -follow ,
.Ic -fstype ,
.Ic -iname ,
.Ic -inum ,
.Ic -iregex ,
.Ic -links ,

View File

@ -1,4 +1,4 @@
/* $NetBSD: find.h,v 1.16 2003/02/23 14:41:30 jhawk Exp $ */
/* $NetBSD: find.h,v 1.17 2003/08/03 19:46:04 provos Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -46,7 +46,7 @@ enum ntype {
N_AMIN, N_ANEWER, N_ATIME, N_CLOSEPAREN, N_CMIN, N_CNEWER, N_CTIME,
N_DEPTH, N_EMPTY,
N_EXEC, N_EXECDIR, N_EXPR, N_FLAGS, N_FOLLOW, N_FSTYPE, N_GROUP,
N_INUM, N_IREGEX, N_LINKS, N_LS, N_MINDEPTH, N_MAXDEPTH,
N_INAME, N_INUM, N_IREGEX, N_LINKS, N_LS, N_MINDEPTH, N_MAXDEPTH,
N_MMIN, N_MTIME, N_NAME, N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_OK,
N_OPENPAREN, N_OR, N_PATH, N_PERM, N_PRINT, N_PRINT0, N_PRINTX,
N_PRUNE, N_REGEX, N_SIZE, N_TYPE, N_USER, N_XDEV

View File

@ -1,4 +1,4 @@
/* $NetBSD: function.c,v 1.44 2003/07/12 13:57:49 itojun Exp $ */
/* $NetBSD: function.c,v 1.45 2003/08/03 19:46:04 provos Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "from: @(#)function.c 8.10 (Berkeley) 5/4/95";
#else
__RCSID("$NetBSD: function.c,v 1.44 2003/07/12 13:57:49 itojun Exp $");
__RCSID("$NetBSD: function.c,v 1.45 2003/08/03 19:46:04 provos Exp $");
#endif
#endif /* not lint */
@ -94,6 +94,7 @@ static int64_t find_parsenum __P((PLAN *, char *, char *, char *));
int f_flags __P((PLAN *, FTSENT *));
int f_fstype __P((PLAN *, FTSENT *));
int f_group __P((PLAN *, FTSENT *));
int f_iname __P((PLAN *, FTSENT *));
int f_inum __P((PLAN *, FTSENT *));
int f_links __P((PLAN *, FTSENT *));
int f_ls __P((PLAN *, FTSENT *));
@ -1092,6 +1093,34 @@ c_name(argvp, isok)
return (new);
}
/*
* -iname functions --
*
* Similar to -name, but does case insensitive matching
*
*/
int
f_iname(plan, entry)
PLAN *plan;
FTSENT *entry;
{
return (!fnmatch(plan->c_data, entry->fts_name, FNM_CASEFOLD));
}
PLAN *
c_iname(argvp, isok)
char ***argvp;
int isok;
{
char *pattern = **argvp;
PLAN *new;
(*argvp)++;
new = palloc(N_INAME, f_iname);
new->c_data = pattern;
return (new);
}
/*
* -newer file functions --
*

View File

@ -1,4 +1,4 @@
/* $NetBSD: option.c,v 1.18 2002/09/27 15:56:28 provos Exp $ */
/* $NetBSD: option.c,v 1.19 2003/08/03 19:46:04 provos Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "from: @(#)option.c 8.2 (Berkeley) 4/16/94";
#else
__RCSID("$NetBSD: option.c,v 1.18 2002/09/27 15:56:28 provos Exp $");
__RCSID("$NetBSD: option.c,v 1.19 2003/08/03 19:46:04 provos Exp $");
#endif
#endif /* not lint */
@ -80,6 +80,7 @@ static OPTION const options[] = {
{ "-follow", N_FOLLOW, c_follow, 0 },
{ "-fstype", N_FSTYPE, c_fstype, 1 },
{ "-group", N_GROUP, c_group, 1 },
{ "-iname", N_INAME, c_iname, 1 },
{ "-inum", N_INUM, c_inum, 1 },
{ "-iregex", N_IREGEX, c_iregex, 1 },
{ "-links", N_LINKS, c_links, 1 },