From owner-freebsd-bugs Mon Jul 23 6:40:16 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 18DFD37B406 for ; Mon, 23 Jul 2001 06:40:02 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.4/8.11.4) id f6NDe2X97482; Mon, 23 Jul 2001 06:40:02 -0700 (PDT) (envelope-from gnats) Received: from serv1.ilse.nl (serv1.ilse.nl [195.18.92.131]) by hub.freebsd.org (Postfix) with ESMTP id E55C937B403 for ; Mon, 23 Jul 2001 06:35:15 -0700 (PDT) (envelope-from marcolz@serv4.ilse.nl) Received: from serv4.ilse.nl (serv4.ilse.nl [10.1.8.14]) by serv1.ilse.nl (8.11.0/8.10.2) with ESMTP id f6NDYxU59001; Mon, 23 Jul 2001 15:34:59 +0200 (MEST) Received: (from marcolz@localhost) by serv4.ilse.nl (8.11.4/8.11.1) id f6NDYwS11128; Mon, 23 Jul 2001 15:34:58 +0200 (CEST) (envelope-from marcolz) Message-Id: <200107231334.f6NDYwS11128@serv4.ilse.nl> Date: Mon, 23 Jul 2001 15:34:58 +0200 (CEST) From: Marc Olzheim Reply-To: Marc Olzheim To: FreeBSD-gnats-submit@freebsd.org Cc: marcolz@ilse.nl X-Send-Pr-Version: 3.113 Subject: bin/29165: The time related functions are limited to units of one day or one minute. Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 29165 >Category: bin >Synopsis: The time related functions are limited to units of one day or one minute. >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Jul 23 06:40:01 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Marc Olzheim >Release: FreeBSD 4.3-STABLE i386 >Organization: ilse technology >Environment: System: FreeBSD serv4.ilse.nl 4.3-STABLE FreeBSD 4.3-STABLE #0: Thu Jun 14 16:50:54 CEST 2001 marcolz@serv4.ilse.nl:/usr/src/sys/compile/serv4 i386 >Description: find's time related functions are only capable of calculations with minutes or days. With this patch, it's possible to specify time units for -[acm]time. --- /usr/src/usr.bin/find/find.1 Wed Jul 4 14:16:59 2001 --- /usr/src/usr.bin/find/find.1 Mon Jul 23 13:26:19 2001 @@ -534,14 +534,16 @@ .Pp All primaries which take a numeric argument allow the number to be preceded by a plus sign -.Pq Dq Li + +.Pq Dq Li + , +an equals sign +.Pq Dq Li = or a minus sign .Pq Dq Li - . A preceding plus sign means .Dq more than n , a preceding minus sign means .Dq less than n -and neither means +and a preceding equals sign or neither means .Dq exactly n . .Sh OPERATORS The primaries may be combined using the following operators. --- /usr/src/usr.bin/find/find.h Sun May 6 11:53:22 2001 --- /usr/src/usr.bin/find/find.h Mon Jul 23 13:19:03 2001 @@ -74,6 +74,7 @@ struct _plandata *next; /* next node */ exec_f *execute; /* node evaluation function */ int flags; /* private flags */ + int t_unit; union { gid_t _g_data; /* gid */ ino_t _i_data; /* inode */ --- /usr/src/usr.bin/find/function.c Sun May 6 11:53:22 2001 --- /usr/src/usr.bin/find/function.c Mon Jul 23 13:25:43 2001 @@ -94,12 +94,47 @@ return new; } +#define UNIT_STR "smhdwMy" + +#define TIME_UNIT(a, b) { \ + switch(b) { \ + case 's': /* 1 second */ \ + a->t_unit = 1; \ + break; \ + case 'm': /* 1 minute */ \ + a->t_unit = 60; \ + break; \ + case 'q': /* 15 minutes */ \ + a->t_unit = 900; \ + break; \ + case 'h': /* 1 hour */ \ + a->t_unit = 3600; \ + break; \ + case 0: /* default */ \ + case 'd': /* 1 day */ \ + a->t_unit = 86400; \ + break; \ + case 'w': /* 1 week */ \ + a->t_unit = 604800; \ + break; \ + case 'M': /* 1 synodic month */ \ + a->t_unit = 2551478; \ + break; \ + case 'y': /* 1 sidereal year */ \ + a->t_unit = 31558118; \ + break; \ + default: \ + errx(1, "Unknown time unit %c\n", b ); \ + } \ +} + + /* * find_parsenum -- - * Parse a string of the form [+-]# and return the value. + * Parse a string of the form [+-=]# and return the value. */ static long long -find_parsenum(plan, option, vp, endch) +find_parsenum(plan, option, vp, endstr, endch) PLAN *plan; char *option, *vp, *endch; { @@ -117,6 +152,9 @@ ++str; plan->flags |= F_LESSTHAN; break; + case '=': + ++str; + /* Fallthrough */ default: plan->flags |= F_EQUAL; break; @@ -130,10 +168,14 @@ value = strtoq(str, &endchar, 10); if (value == 0 && endchar == str) errx(1, "%s: %s: illegal numeric value", option, vp); - if (endchar[0] && (endch == NULL || endchar[0] != *endch)) - errx(1, "%s: %s: illegal trailing character", option, vp); + if (endchar[0] && (endstr == NULL || !strchr(endstr, endchar[0]))) + errx(1, "%s: %s: %c: illegal trailing character", + option, vp, endchar[0]); if (endch) *endch = endchar[0]; + if (endchar[0] && endchar[1]) + errx(1, "%s: %s: %c: illegal trailing character", + option, vp, endchar[1]); return value; } @@ -205,7 +247,7 @@ ftsoptions &= ~FTS_NOSTAT; new = palloc(option); - new->t_data = find_parsenum(new, option->name, nmins, NULL); + new->t_data = find_parsenum(new, option->name, nmins, NULL, NULL); TIME_CORRECT(new); return new; } @@ -229,13 +271,13 @@ if (plan->flags & F_TIME_C) { COMPARE((now - entry->fts_statp->st_ctime + - 86400 - 1) / 86400, plan->t_data); + plan->t_unit - 1) / plan->t_unit, plan->t_data); } else if (plan->flags & F_TIME_A) { COMPARE((now - entry->fts_statp->st_atime + - 86400 - 1) / 86400, plan->t_data); + plan->t_unit - 1) / plan->t_unit, plan->t_data); } else { COMPARE((now - entry->fts_statp->st_mtime + - 86400 - 1) / 86400, plan->t_data); + plan->t_unit - 1) / plan->t_unit, plan->t_data); } } @@ -246,13 +288,15 @@ { char *ndays; PLAN *new; + char endch; ndays = nextarg(option, argvp); ftsoptions &= ~FTS_NOSTAT; new = palloc(option); - new->t_data = find_parsenum(new, option->name, ndays, NULL); + new->t_data = find_parsenum(new, option->name, ndays, UNIT_STR, &endch); TIME_CORRECT(new); + TIME_UNIT(new, endch); return new; } @@ -280,9 +324,9 @@ new = palloc(option); if (option->flags & F_MAXDEPTH) - maxdepth = find_parsenum(new, option->name, dstr, NULL); + maxdepth = find_parsenum(new, option->name, dstr, NULL, NULL); else - mindepth = find_parsenum(new, option->name, dstr, NULL); + mindepth = find_parsenum(new, option->name, dstr, NULL, NULL); return new; } @@ -778,7 +822,7 @@ ftsoptions &= ~FTS_NOSTAT; new = palloc(option); - new->i_data = find_parsenum(new, option->name, inum_str, NULL); + new->i_data = find_parsenum(new, option->name, inum_str, NULL, NULL); return new; } @@ -807,7 +851,7 @@ ftsoptions &= ~FTS_NOSTAT; new = palloc(option); - new->l_data = (nlink_t)find_parsenum(new, option->name, nlinks, NULL); + new->l_data = (nlink_t)find_parsenum(new, option->name, nlinks, NULL, NULL); return new; } @@ -1213,7 +1257,7 @@ new = palloc(option); endch = 'c'; - new->o_data = find_parsenum(new, option->name, size_str, &endch); + new->o_data = find_parsenum(new, option->name, size_str, "c", &endch); if (endch == 'c') divsize = 0; return new; >How-To-Repeat: >Fix: >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message