From 810471468e9b1691943ad24ded2951115cd265da Mon Sep 17 00:00:00 2001 From: simonb Date: Sat, 16 Jan 1999 13:27:30 +0000 Subject: [PATCH] Add GNU-style -{a,c,m}min primaries. --- usr.bin/find/extern.h | 7 ++- usr.bin/find/find.1 | 21 +++++++- usr.bin/find/find.h | 12 ++--- usr.bin/find/function.c | 106 +++++++++++++++++++++++++++++++++++++++- usr.bin/find/option.c | 7 ++- 5 files changed, 140 insertions(+), 13 deletions(-) diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h index 4c1ca6853fb4..5997eee259ab 100644 --- a/usr.bin/find/extern.h +++ b/usr.bin/find/extern.h @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.10 1999/01/12 00:18:50 lukem Exp $ */ +/* $NetBSD: extern.h,v 1.11 1999/01/16 13:27:30 simonb Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -50,7 +50,9 @@ struct stat; void printlong __P((char *, char *, struct stat *)); int queryuser __P((char **)); +PLAN *c_amin __P((char ***, int)); PLAN *c_atime __P((char ***, int)); +PLAN *c_cmin __P((char ***, int)); PLAN *c_ctime __P((char ***, int)); PLAN *c_depth __P((char ***, int)); PLAN *c_exec __P((char ***, int)); @@ -61,6 +63,8 @@ PLAN *c_group __P((char ***, int)); PLAN *c_inum __P((char ***, int)); PLAN *c_links __P((char ***, int)); PLAN *c_ls __P((char ***, int)); +PLAN *c_mmin __P((char ***, int)); +PLAN *c_mtime __P((char ***, int)); PLAN *c_name __P((char ***, int)); PLAN *c_newer __P((char ***, int)); PLAN *c_nogroup __P((char ***, int)); @@ -77,7 +81,6 @@ PLAN *c_user __P((char ***, int)); PLAN *c_xdev __P((char ***, int)); PLAN *c_openparen __P((char ***, int)); PLAN *c_closeparen __P((char ***, int)); -PLAN *c_mtime __P((char ***, int)); PLAN *c_not __P((char ***, int)); PLAN *c_or __P((char ***, int)); PLAN *c_null __P((char ***, int)); diff --git a/usr.bin/find/find.1 b/usr.bin/find/find.1 index e88eb412feca..f7d8480fe381 100644 --- a/usr.bin/find/find.1 +++ b/usr.bin/find/find.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: find.1,v 1.17 1999/01/12 00:18:50 lukem Exp $ +.\" $NetBSD: find.1,v 1.18 1999/01/16 13:27:30 simonb Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -147,12 +147,25 @@ than that of the file from which the descent began. .El .Sh PRIMARIES .Bl -tag -width Ds +.It Ic -amin Ar n +True if the difference between the file last access time and the time +.Nm +was started, rounded up to the next full minute, is +.Ar n +minutes. .It Ic -atime Ar n True if the difference between the file last access time and the time .Nm was started, rounded up to the next full 24\-hour period, is .Ar n 24\-hour periods. +.It Ic -cmin Ar n +True if the difference between the time of last change of file status +information and the time +.Nm +was started, rounded up to the next full minute, is +.Ar n +minutes. .It Ic -ctime Ar n True if the difference between the time of last change of file status information and the time @@ -240,6 +253,12 @@ will be displayed instead of the size in bytes. If the file is a symbolic link, the pathname of the linked\-to file will be displayed preceded by ``\->''. The format is identical to that produced by ``ls \-dgils''. +.It Ic -mmin Ar n +True if the difference between the file last modification time and the time +.Nm +was started, rounded up to the next full minute, is +.Ar n +minutes. .It Ic -mtime Ar n True if the difference between the file last modification time and the time .Nm diff --git a/usr.bin/find/find.h b/usr.bin/find/find.h index 5ffe310cee8c..af8ee6f42428 100644 --- a/usr.bin/find/find.h +++ b/usr.bin/find/find.h @@ -1,4 +1,4 @@ -/* $NetBSD: find.h,v 1.10 1999/01/12 00:18:50 lukem Exp $ */ +/* $NetBSD: find.h,v 1.11 1999/01/16 13:27:30 simonb Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,11 +41,11 @@ /* node type */ enum ntype { N_AND = 1, /* must start > 0 */ - N_ATIME, N_CLOSEPAREN, N_CTIME, N_DEPTH, N_EXEC, N_EXPR, N_FLAGS, - N_FOLLOW, N_FSTYPE, N_GROUP, N_INUM, N_LINKS, N_LS, 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_SIZE, N_TYPE, N_USER, - N_XDEV, + N_AMIN, N_ATIME, N_CLOSEPAREN, N_CMIN, N_CTIME, N_DEPTH, N_EXEC, + N_EXPR, N_FLAGS, N_FOLLOW, N_FSTYPE, N_GROUP, N_INUM, N_LINKS, N_LS, + 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_SIZE, N_TYPE, N_USER, N_XDEV, }; /* node definition */ diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index 0ca1953b2605..6b8615aaecc7 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -1,4 +1,4 @@ -/* $NetBSD: function.c,v 1.28 1999/01/12 00:18:50 lukem Exp $ */ +/* $NetBSD: function.c,v 1.29 1999/01/16 13:27:30 simonb 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.28 1999/01/12 00:18:50 lukem Exp $"); +__RCSID("$NetBSD: function.c,v 1.29 1999/01/16 13:27:30 simonb Exp $"); #endif #endif /* not lint */ @@ -80,7 +80,9 @@ __RCSID("$NetBSD: function.c,v 1.28 1999/01/12 00:18:50 lukem Exp $"); static long find_parsenum __P((PLAN *, char *, char *, char *)); int f_always_true __P((PLAN *, FTSENT *)); + int f_amin __P((PLAN *, FTSENT *)); int f_atime __P((PLAN *, FTSENT *)); + int f_cmin __P((PLAN *, FTSENT *)); int f_ctime __P((PLAN *, FTSENT *)); int f_exec __P((PLAN *, FTSENT *)); int f_flags __P((PLAN *, FTSENT *)); @@ -89,6 +91,7 @@ static long find_parsenum __P((PLAN *, char *, char *, char *)); int f_inum __P((PLAN *, FTSENT *)); int f_links __P((PLAN *, FTSENT *)); int f_ls __P((PLAN *, FTSENT *)); + int f_mmin __P((PLAN *, FTSENT *)); int f_mtime __P((PLAN *, FTSENT *)); int f_name __P((PLAN *, FTSENT *)); int f_newer __P((PLAN *, FTSENT *)); @@ -160,6 +163,39 @@ find_parsenum(plan, option, vp, endch) if ((p)->type == ttype && (p)->flags == F_LESSTHAN) \ ++((p)->t_data); +/* + * -amin n functions -- + * + * True if the difference between the file access time and the + * current time is n 1 minute periods. + */ +int +f_amin(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + extern time_t now; + + COMPARE((now - entry->fts_statp->st_atime + + SECSPERMIN - 1) / SECSPERMIN, plan->t_data); +} + +PLAN * +c_amin(argvp, isok) + char ***argvp; + int isok; +{ + char *arg = **argvp; + PLAN *new; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + new = palloc(N_AMIN, f_amin); + new->t_data = find_parsenum(new, "-amin", arg, NULL); + TIME_CORRECT(new, N_AMIN); + return (new); +} /* * -atime n functions -- * @@ -193,6 +229,39 @@ c_atime(argvp, isok) TIME_CORRECT(new, N_ATIME); return (new); } +/* + * -cmin n functions -- + * + * True if the difference between the last change of file + * status information and the current time is n 24 hour periods. + */ +int +f_cmin(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + extern time_t now; + + COMPARE((now - entry->fts_statp->st_ctime + + SECSPERMIN - 1) / SECSPERMIN, plan->t_data); +} + +PLAN * +c_cmin(argvp, isok) + char ***argvp; + int isok; +{ + char *arg = **argvp; + PLAN *new; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + new = palloc(N_CMIN, f_cmin); + new->t_data = find_parsenum(new, "-cmin", arg, NULL); + TIME_CORRECT(new, N_CMIN); + return (new); +} /* * -ctime n functions -- * @@ -645,6 +714,39 @@ c_ls(argvp, isok) return (palloc(N_LS, f_ls)); } +/* + * -mmin n functions -- + * + * True if the difference between the file modification time and the + * current time is n 24 hour periods. + */ +int +f_mmin(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + extern time_t now; + + COMPARE((now - entry->fts_statp->st_mtime + SECSPERMIN - 1) / + SECSPERMIN, plan->t_data); +} + +PLAN * +c_mmin(argvp, isok) + char ***argvp; + int isok; +{ + char *arg = **argvp; + PLAN *new; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + new = palloc(N_MMIN, f_mmin); + new->t_data = find_parsenum(new, "-mmin", arg, NULL); + TIME_CORRECT(new, N_MMIN); + return (new); +} /* * -mtime n functions -- * diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c index ae3d2801152c..15ee0e44ee85 100644 --- a/usr.bin/find/option.c +++ b/usr.bin/find/option.c @@ -1,4 +1,4 @@ -/* $NetBSD: option.c,v 1.11 1999/01/12 00:18:50 lukem Exp $ */ +/* $NetBSD: option.c,v 1.12 1999/01/16 13:27:31 simonb 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.11 1999/01/12 00:18:50 lukem Exp $"); +__RCSID("$NetBSD: option.c,v 1.12 1999/01/16 13:27:31 simonb Exp $"); #endif #endif /* not lint */ @@ -66,7 +66,9 @@ static OPTION const options[] = { { ")", N_CLOSEPAREN, c_closeparen, 0 }, { "-a", N_AND, c_null, 0 }, { "-and", N_AND, c_null, 0 }, + { "-amin", N_AMIN, c_amin, 1 }, { "-atime", N_ATIME, c_atime, 1 }, + { "-cmin", N_CMIN, c_cmin, 1 }, { "-ctime", N_CTIME, c_ctime, 1 }, { "-depth", N_DEPTH, c_depth, 0 }, { "-exec", N_EXEC, c_exec, 1 }, @@ -77,6 +79,7 @@ static OPTION const options[] = { { "-inum", N_INUM, c_inum, 1 }, { "-links", N_LINKS, c_links, 1 }, { "-ls", N_LS, c_ls, 0 }, + { "-mmin", N_MMIN, c_mmin, 1 }, { "-mtime", N_MTIME, c_mtime, 1 }, { "-name", N_NAME, c_name, 1 }, { "-newer", N_NEWER, c_newer, 1 },