zsh-workers
 help / color / mirror / code / Atom feed
* zshexpn(1) doc suggestion
@ 1995-08-28 21:09 Mark Borges
  1995-08-30 14:34 ` P.Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Borges @ 1995-08-28 21:09 UTC (permalink / raw)
  To: ZSH mailing list; +Cc: ZSH archivist


I just spent more time than I should have (or at least I think I
should have) tracking down the glob qualifier to get filename
expansion to operate with a different time unit for the modification
(m) qualifier. I would have given up were it not for the fact I was
*sure* zsh could do this.

Currently, it's buried in the inode change (c) qualifier in the
zshexpn(1) page:

          c[-|+]n
               files whose inode changed within last n days  (-),
               more  than  n days ago (+), or n days ago.  If any   <
               of the flags a, m, or c is directly followed by  a   <
               M,  w,  h, or m (e.g. mh+5) the check is performed   <
               with months (of 30 days), weeks, hours, or minutes   <
               instead of days, respectively.

I think this information should be more prominent, and propose the
following patch, which points out the existence of the optional unit
specifiers near the qualifier (sans the text beautification):

          a[Mwhm][-|+]n
               files accessed exactly n days ago.  Optional  unit
               specifier  flags M, w, h, or m (e.g. ah5) mean the
               check is  performed  with  months  (of  30  days),
               weeks,  hours, or minutes instead of days, respec-
               tively. Files accessed within the last n days  are
               selected  using a negative value for n (-n); files
               accessed more than n days ago are  selected  by  a
               positive  n value (+n). For instance, echo *(ah-5)
               would echo files accessed  within  the  last  five
               hours while echo *(ah+5) would echo files accessed
               more than five hours ago.

although it may be overly verbose now (but better too wordy than not
enough, in my opinion).

Anyway, please consider it, or something similar. It's just too hard
to find right now.

Thanks,
  -mb-


*** zshexpn.1.orig	Mon Aug 28 14:56:23 1995
--- zshexpn.1	Mon Aug 28 15:00:10 1995
***************
*** 548,568 ****
  \fBg\fIid\fR
  like \fBu\fIid\fR but with group ids or names
  .TP
! \fBa\fI[-|+]n\fR
! files accessed within last \fIn\fP days (-), more than \fIn\fP days
! ago (+), or \fIn\fP days ago\fP
  .TP
! \fBm\fI[-|+]n\fR
! files modified within last \fIn\fP days (-), more than \fIn\fP days
! ago (+), or \fIn\fP days ago\fP
  .TP
! \fBc\fI[-|+]n\fR
! files whose inode changed within last \fIn\fP days (-), more than
! \fIn\fP days ago (+), or \fIn\fP days ago.
! If any of the flags \fBa\fP, \fBm\fP, or \fBc\fP is directly followed by a
! \fBM\fP, \fBw\fP, \fBh\fP, or \fBm\fP (e.g. \fBmh+5\fP) the check is
! performed with months (of 30 days), weeks, hours, or minutes instead
! of days, respectively.
  .TP
  \fBL\fI[+|-]n\fR
  files less than n bytes (-), more than n bytes (+), or
--- 548,569 ----
  \fBg\fIid\fR
  like \fBu\fIid\fR but with group ids or names
  .TP
! \fBa[Mwhm]\fI[-|+]n\fR
! files accessed exactly \fIn\fP days ago. Optional unit specifier flags
! \fBM\fP, \fBw\fP, \fBh\fP, or \fBm\fP (e.g. \fBah5\fP) mean the check
! is performed with months (of 30 days), weeks, hours, or minutes
! instead of days, respectively. Files accessed within the last \fIn\fP
! days are selected using a negative value for \fIn\fP (\fI-n\fP); files
! accessed more than \fIn\fP days ago are selected by a positive \fIn\fP
! value (\fI+n\fP). For instance, \fBecho *(ah-5)\fP would echo files
! accessed within the last five hours while \fBecho *(ah+5)\fP would echo files
! accessed more than five hours ago.
  .TP
! \fBm[Mwhm]\fI[-|+]n\fR
! like the access qualifier, except use file modification time as the criterion.
  .TP
! \fBc[Mwhm]\fI[-|+]n\fR
! like the access qualifier, except use file inode change time as the criterion.
  .TP
  \fBL\fI[+|-]n\fR
  files less than n bytes (-), more than n bytes (+), or


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: zshexpn(1) doc suggestion
  1995-08-28 21:09 zshexpn(1) doc suggestion Mark Borges
@ 1995-08-30 14:34 ` P.Stephenson
  1995-09-22 22:42   ` size glob qualifier patch Thorsten Meinecke
  0 siblings, 1 reply; 3+ messages in thread
From: P.Stephenson @ 1995-08-30 14:34 UTC (permalink / raw)
  To: Zsh hackers list

mdb@cdc.noaa.gov wrote:
> I just spent more time than I should have (or at least I think I
> should have) tracking down the glob qualifier to get filename
> expansion to operate with a different time unit for the modification
> (m) qualifier.

This is not exactly relevant, but I've always wanted the L (size)
qualifier to accept k or m (or K or M) as modifiers.  I never seem to
want to check for anything smaller than about 50k, in which case
zeros proliferate.  Often, I just assume it's there and find it
isn't.  Unfortunately there's never been a gap between feature freezes
long enough for me to write it.  It needs bearing in mind, though.

-- 
Peter Stephenson <P.Stephenson@swansea.ac.uk>  Tel: +44 1792 205678 extn. 4461
WWW:  http://python.swan.ac.uk/~pypeters/      Fax: +44 1792 295324
Department of Physics, University of Wales, Swansea,
Singleton Park, Swansea, SA2 8PP, U.K.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* size glob qualifier patch
  1995-08-30 14:34 ` P.Stephenson
@ 1995-09-22 22:42   ` Thorsten Meinecke
  0 siblings, 0 replies; 3+ messages in thread
From: Thorsten Meinecke @ 1995-09-22 22:42 UTC (permalink / raw)
  To: zsh-workers

In message #346, Subject: Re: zshexpn(1) doc suggestion,
Peter Stephenson <P.Stephenson@swansea.ac.uk> wrote:

>This is not exactly relevant, but I've always wanted the L (size)
>qualifier to accept k or m (or K or M) as modifiers.  I never seem to
>want to check for anything smaller than about 50k, in which case
>zeros proliferate.

This is maybe not exactly what you want, but it is easy to mimic
the behaviour of find(1)'s -size option, with modifiers similiar
to those used by the time glob qualifiers. The relevant part of
the zshexpn.1 man page would then read: 

              L[+|-]n
                     files  less  than  n  bytes (-), more than n
                     bytes (+), or exactly n bytes in length.  If
                     this flag is directly followed by a k (K), m
                     (M), or p (P) (e.g. Lk+50) the check is per-
                     formed  with kilobytes, megabytes, or blocks
                     (of 512 bytes) instead.

Since I'm used to the use of Kbyte (2^10) to denote the difference
to the SI-prefix k (10^3), it seems preferable to accept these
modifiers case-insensitive.

What this patch does. Data is passed to the qual*() functions by
means of parameter, and of a couple of static vars. Of those, which
are reloaded each time before a different function is called, `timef'
as time multiplier was renamed to `units' and serves now as size mul-
tiplier, too. In qualsize(), the range adjustment for e.g.

       `*(Lk1)' == `find . -size 1k' == 1 .. 1024 bytes

is done by adding factor-1 before the division by factor, thus re-
quiring an unsigned var. For size qualifier without unit modifier,
operation hasn't changed.

Side notes:

o  The size code has still a hard limit, in that it will break when
   there are filesizes greater than One Less Than Two Gigabytes
   (2^31-1) on machines with 32-bit longs. What about POSIX (off_t)?

o  Is it considered useful to have Yet Another Globbing Qualifier,
   e.g. B, for size globbing based on the real amount of disk space
   used, as opposed to the `length' of possibly sparse files now?
   Cf. du(1)

o  Would it be fun if there was a zsh shell function as a find(1)-
   compatible front-end, or converter, to zsh's globbing capabilities?
   That is, long option names are easier to remember than one-letter
   qualifiers.


This is for hzoli10.3, but should also apply to plain zsh-2.6-beta10.

*** Doc/zshexpn.1.ORIG	Wed Sep 20 16:33:57 1995
--- Doc/zshexpn.1	Fri Sep 22 15:27:48 1995
***************
*** 643,649 ****
  .TP
  \fBL\fI[+|-]n\fR
  files less than n bytes (-), more than n bytes (+), or
! exactly n bytes in length.
  .TP
  \fB^\fP
  negates all qualifiers following it
--- 643,652 ----
  .TP
  \fBL\fI[+|-]n\fR
  files less than n bytes (-), more than n bytes (+), or
! exactly n bytes in length. If this flag is directly followed by a \fBk\fP
! (\fBK\fP), \fBm\fP (\fBM\fP), or \fBp\fP (\fBP\fP) (e.g. \fBLk+50\fP)
! the check is performed with kilobytes, megabytes, or blocks (of 512 bytes)
! instead.
  .TP
  \fB^\fP
  negates all qualifiers following it
*** Src/glob.c.ORIG	Wed Sep 20 16:34:03 1995
--- Src/glob.c	Fri Sep 22 15:17:38 1995
***************
*** 49,60 ****
--- 49,67 ----
  typedef struct stat *Statptr;	 /* This makes the Ultrix compiler happy.  Go figure. */
  #endif
  
+ /* modifier for unit conversions */
+ 
  #define TT_DAYS 0
  #define TT_HOURS 1
  #define TT_MINS 2
  #define TT_WEEKS 3
  #define TT_MONTHS 4
  
+ #define TT_BYTES 0
+ #define TT_POSIX_BLOCKS 1
+ #define TT_KILOBYTES 2
+ #define TT_MEGABYTES 3
+ 
  /* max # of qualifiers */
  
  typedef int (*TestMatchFunc) _((struct stat *, long));
***************
*** 67,73 ****
      int sense;			/* Whether asserting or negating             */
      int amc;			/* Flag for which time to test (a, m, c)     */
      int range;			/* Whether to test <, > or = (as per signum) */
!     int timef;			/* Multiplier for time                       */
  };
  
  /* Qualifiers pertaining to current pattern */
--- 74,80 ----
      int sense;			/* Whether asserting or negating             */
      int amc;			/* Flag for which time to test (a, m, c)     */
      int range;			/* Whether to test <, > or = (as per signum) */
!     int units;			/* Multiplier for time or size, respectively */
  };
  
  /* Qualifiers pertaining to current pattern */
***************
*** 75,81 ****
  
  /* Other state values for current pattern */
  static int qualct, qualorct;
! static int range, amc, timef;
  static int gf_nullglob, gf_markdirs, gf_noglobdots, gf_listtypes;
  
  /* Prefix, suffix for doing zle trickery */
--- 82,88 ----
  
  /* Other state values for current pattern */
  static int qualct, qualorct;
! static int range, amc, units;
  static int gf_nullglob, gf_markdirs, gf_noglobdots, gf_listtypes;
  
  /* Prefix, suffix for doing zle trickery */
***************
*** 436,453 ****
  			/* File size (Length) in given range */
  			func = qualsize;
  			amc = -1;
  		      getrange:
- 			timef = TT_DAYS;
  			/* Get time multiplier */
! 			if (amc >= 0)
  			    if (*s == 'h')
! 				timef = TT_HOURS, ++s;
  			    else if (*s == 'm')
! 				timef = TT_MINS, ++s;
  			    else if (*s == 'w')
! 				timef = TT_WEEKS, ++s;
  			    else if (*s == 'M')
! 				timef = TT_MONTHS, ++s;
  			/* See if it's greater than, equal to, or less than */
  			if ((range = *s == '+' ? 1 : *s == '-' ? -1 : 0))
  			    ++s;
--- 443,469 ----
  			/* File size (Length) in given range */
  			func = qualsize;
  			amc = -1;
+ 			/* Get size multiplier */
+ 			units = TT_BYTES;
+ 			if (*s == 'p' || *s == 'P')
+ 			    units = TT_POSIX_BLOCKS, ++s;
+ 			else if (*s == 'k' || *s == 'K')
+ 			    units = TT_KILOBYTES, ++s;
+ 			else if (*s == 'm' || *s == 'M')
+ 			    units = TT_MEGABYTES, ++s;
  		      getrange:
  			/* Get time multiplier */
! 			if (amc >= 0) {
! 			    units = TT_DAYS;
  			    if (*s == 'h')
! 				units = TT_HOURS, ++s;
  			    else if (*s == 'm')
! 				units = TT_MINS, ++s;
  			    else if (*s == 'w')
! 				units = TT_WEEKS, ++s;
  			    else if (*s == 'M')
! 				units = TT_MONTHS, ++s;
! 			}
  			/* See if it's greater than, equal to, or less than */
  			if ((range = *s == '+' ? 1 : *s == '-' ? -1 : 0))
  			    ++s;
***************
*** 471,477 ****
  		    qn->sense = sense;
  		    qn->data = data;
  		    qn->range = range;
! 		    qn->timef = timef;
  		    qn->amc = amc;
  		    qn = NULL;
  		    qualct++;
--- 487,493 ----
  		    qn->sense = sense;
  		    qn->data = data;
  		    qn->range = range;
! 		    qn->units = units;
  		    qn->amc = amc;
  		    qn = NULL;
  		    qualct++;
***************
*** 656,662 ****
  		for (qn = qo; t && qn && qn->func; qn = qn->next) {
  		    range = qn->range;
  		    amc = qn->amc;
! 		    timef = qn->timef;
  		    if ((qn->sense & 2) && !statted) {
  			/* If (sense & 2), we're following links */
  			statted = 1;
--- 672,678 ----
  		for (qn = qo; t && qn && qn->func; qn = qn->next) {
  		    range = qn->range;
  		    amc = qn->amc;
! 		    units = qn->units;
  		    if ((qn->sense & 2) && !statted) {
  			/* If (sense & 2), we're following links */
  			statted = 1;
***************
*** 2239,2247 ****
  int
  qualsize(struct stat *buf, long size)
  {
!     return (range < 0 ? buf->st_size < size :
! 	    range > 0 ? buf->st_size > size :
! 	    buf->st_size == size);
  }
  
  /* time in required range? */
--- 2255,2280 ----
  int
  qualsize(struct stat *buf, long size)
  {
!     unsigned long scaled = buf->st_size;
! 
!     switch (units) {
!     case TT_POSIX_BLOCKS:
! 	scaled += 511l;
! 	scaled /= 512l;
! 	break;
!     case TT_KILOBYTES:
! 	scaled += 1023l;
! 	scaled /= 1024l;
! 	break;
!     case TT_MEGABYTES:
! 	scaled += 1048575l;
! 	scaled /= 1048576l;
! 	break;
!     }
! 
!     return (range < 0 ? scaled < size :
! 	    range > 0 ? scaled > size :
! 	    scaled == size);
  }
  
  /* time in required range? */
***************
*** 2256,2262 ****
      diff = now - (amc == 0 ? buf->st_atime : amc == 1 ? buf->st_mtime :
  		  buf->st_ctime);
      /* handle multipliers indicating units */
!     switch (timef) {
      case TT_DAYS:
  	diff /= 86400l;
  	break;
--- 2289,2295 ----
      diff = now - (amc == 0 ? buf->st_atime : amc == 1 ? buf->st_mtime :
  		  buf->st_ctime);
      /* handle multipliers indicating units */
!     switch (units) {
      case TT_DAYS:
  	diff /= 86400l;
  	break;

-- 
Thorsten Meinecke
<kaefer@aglaia.snafu.de> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1995-09-22 23:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-08-28 21:09 zshexpn(1) doc suggestion Mark Borges
1995-08-30 14:34 ` P.Stephenson
1995-09-22 22:42   ` size glob qualifier patch Thorsten Meinecke

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).