From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@sunsite.dk, 185228@bugs.debian.org
Subject: Re: [vincent@vinc17.org: Bug#185228: zsh: Incorrect filename generation with glob qualifier mh+]
Date: Thu, 13 Dec 2007 22:35:16 +0000 [thread overview]
Message-ID: <20071213223516.c0f18f3e.p.w.stephenson@ntlworld.com> (raw)
In-Reply-To: <20071213182503.GA29544@scowler.net>
On Thu, 13 Dec 2007 13:25:03 -0500
Clint Adams <schizo@debian.org> wrote:
> On Mon, Jul 11, 2005 at 02:17:00PM +0200, Vincent Lefevre wrote:
> > BTW, could zsh define <n and >n, that would have the intuitive
> > meaning? e.g. echo *(ah>5) would display the files accessed more
> > that 5 hours (= 18000 seconds) ago.
>
> Sounds unlikely.
It turns out not to be too difficult, although I had to make < and > in
parentheses no longer be parse errors. There's no good reason why they
should be parse errors there that I can see and we already do similar
things in lots of other cases.
I'll let everyone worry about this overnight while I finally get some
rest.
Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.85
diff -u -r1.85 expn.yo
--- Doc/Zsh/expn.yo 13 Dec 2007 21:57:18 -0000 1.85
+++ Doc/Zsh/expn.yo 13 Dec 2007 22:33:48 -0000
@@ -2069,7 +2069,7 @@
item(tt(g)var(id))(
like tt(u)var(id) but with group IDs or names
)
-item(tt(a)[tt(Mwhms)][tt(-)|tt(PLUS())]var(n))(
+item(tt(a)[tt(Mwhms)][tt(-)|tt(PLUS())|tt(<)|tt(>)]var(n))(
files accessed exactly var(n) days ago. Files accessed within the last
var(n) days are selected using a negative value for var(n) (tt(-)var(n)).
Files accessed more than var(n) days ago are selected by a positive var(n)
@@ -2079,11 +2079,18 @@
instead of days, respectively.
Any fractional part of the difference between the access time and the
-current part in the appropriate units is ignored in the comparison. For
+current time in the appropriate units is ignored in the comparison. For
instance, `tt(echo *(ah-5))' would echo files accessed within the last
five hours, while `tt(echo *(ah+5))' would echo files accessed at least
-six hours ago, as times strictly between five and six hours are treated
-as five hours.
+six hours ago, as times between five and six hours are treated as five
+hours.
+
+To perform comparisons strictly rather than using the truncated value,
+tt(<) and tt(>) may be used in place of tt(-) and tt(PLUS()). The test
+with tt(<) is true if the time difference is less than the given period;
+this is equivalent to tt(-) because of the manner of truncation. The
+test with tt(>) is true if the time difference is strictly greater than
+the period specified.
)
item(tt(m)[tt(Mwhms)][tt(-)|tt(PLUS())]var(n))(
like the file access qualifier, except that it uses the file modification
Index: Src/glob.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/glob.c,v
retrieving revision 1.61
diff -u -r1.61 glob.c
--- Src/glob.c 1 Nov 2007 17:57:57 -0000 1.61
+++ Src/glob.c 13 Dec 2007 22:33:50 -0000
@@ -1440,7 +1440,32 @@
g_units = TT_SECONDS, ++s;
}
/* See if it's greater than, equal to, or less than */
- if ((g_range = *s == '+' ? 1 : *s == '-' ? -1 : 0))
+ switch (*s) {
+ /* integer greater than */
+ case '+':
+ g_range = 1;
+ break;
+
+ case '>':
+ case OUTPAR:
+ /* strictly greater than */
+ g_range = 2;
+ break;
+
+ case '-':
+ case '<':
+ case INANG:
+ /* integer less than, same as strictly less than */
+ g_range = -1;
+ break;
+
+ default:
+ /* integer match */
+ g_range = 0;
+ break;
+ }
+
+ if (g_range)
++s;
data = qgetnum(&s);
break;
@@ -3236,7 +3261,7 @@
static int
qualtime(UNUSED(char *name), struct stat *buf, off_t days, UNUSED(char *dummy))
{
- time_t now, diff;
+ time_t now, diff, div, units;
time(&now);
diff = now - (g_amc == 0 ? buf->st_atime : g_amc == 1 ? buf->st_mtime :
@@ -3244,25 +3269,33 @@
/* handle multipliers indicating units */
switch (g_units) {
case TT_DAYS:
- diff /= 86400l;
+ units = 86400l;
break;
case TT_HOURS:
- diff /= 3600l;
+ units = 3600l;
break;
case TT_MINS:
- diff /= 60l;
+ units = 60l;
break;
case TT_WEEKS:
- diff /= 604800l;
+ units = 604800l;
break;
case TT_MONTHS:
- diff /= 2592000l;
+ units = 2592000l;
+ break;
+ default:
+ units = 1l;
break;
}
- return (g_range < 0 ? diff < days :
- g_range > 0 ? diff > days :
- diff == days);
+ div = diff / units;
+ if (g_range == 2) {
+ /* strictly greater than */
+ return div > days || (div == days && diff > div * units);
+ }
+ return (g_range < 0 ? div < days :
+ g_range > 0 ? div > days :
+ div == days);
}
/* evaluate a string */
Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.41
diff -u -r1.41 lex.c
--- Src/lex.c 23 Aug 2007 22:04:25 -0000 1.41
+++ Src/lex.c 13 Dec 2007 22:33:51 -0000
@@ -1099,7 +1099,7 @@
break;
case LX2_OUTANG:
if (!intpos) {
- if (in_brace_param || sub)
+ if (in_brace_param || pct || sub)
break;
else
goto brk;
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
prev parent reply other threads:[~2007-12-13 22:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-18 3:16 Clint Adams
2003-03-18 16:25 ` Bart Schaefer
2005-07-11 12:17 ` Vincent Lefevre
2007-12-13 18:25 ` Clint Adams
2007-12-13 22:35 ` Peter Stephenson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071213223516.c0f18f3e.p.w.stephenson@ntlworld.com \
--to=p.w.stephenson@ntlworld.com \
--cc=185228@bugs.debian.org \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).