Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [vincent@xxxxxxxxxx: Bug#185228: zsh: Incorrect filename generation with glob qualifier mh+]
- X-seq: zsh-workers 24243
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx, 185228@xxxxxxxxxxxxxxx
- Subject: Re: [vincent@xxxxxxxxxx: Bug#185228: zsh: Incorrect filename generation with glob qualifier mh+]
- Date: Thu, 13 Dec 2007 22:35:16 +0000
- In-reply-to: <20071213182503.GA29544@xxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20030318031615.GG29480@xxxxxxxxxxxxxxxxxxx> <1030318162510.ZM28121@xxxxxxxxxxxxxxxxxxxxxxx> <20050711121700.GA16217@xxxxxxxxxxxxxxxx> <20071213182503.GA29544@xxxxxxxxxxx>
On Thu, 13 Dec 2007 13:25:03 -0500
Clint Adams <schizo@xxxxxxxxxx> 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@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author