zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: Re: Btw.: glob-qualifier
@ 1999-02-01  8:21 Sven Wischnowsky
  0 siblings, 0 replies; 5+ messages in thread
From: Sven Wischnowsky @ 1999-02-01  8:21 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> On Jan 29,  2:37pm, Sven Wischnowsky wrote:
> } Subject: PATCH: Re: Btw.: glob-qualifier
> }
> } > [...] (o(ug=w,o+r)) for "user and group must have exactly the write
> } > bit set, and other must have at least r" and (o(u+x,go-w)) for "user
> } > must have at least the execute bit set, and group and other must not
> } > have write" and so on.
> } 
> } The patch below implements this (with a few extras).
> 
> Nifty!  Now I only have one question ... is there another, better letter
> than `o' that could be adopted (since the mode is no longer `o'ctal),
> thus giving us both o and O for ascending/descending sorts, as in the
> parameter flags?

(...and print.) Yes, I wanted to do it in exactly this way, when I
discovered the old `o' modifier. I also thought about altering the
name of the `o' modifier.

This would also reverse the meaning of the `O' qualifier.

But since `o' wasn't documented and `O' is new, it hopefully wouldn't
cause too much trouble.

> (I'd ask about this on zsh-users first, though, just in case anybody is
> making some important use of the old undocumented `o'.)

Ok.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* Re: PATCH: Re: Btw.: glob-qualifier
@ 1999-02-03 11:06 Sven Wischnowsky
  0 siblings, 0 replies; 5+ messages in thread
From: Sven Wischnowsky @ 1999-02-03 11:06 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> On Jan 29,  2:37pm, Sven Wischnowsky wrote:
> } Subject: PATCH: Re: Btw.: glob-qualifier
> }
> } > [...] (o(ug=w,o+r)) for "user and group must have exactly the write
> } > bit set, and other must have at least r" and (o(u+x,go-w)) for "user
> } > must have at least the execute bit set, and group and other must not
> } > have write" and so on.
> } 
> } The patch below implements this (with a few extras).
> 
> Nifty!  Now I only have one question ... is there another, better letter
> than `o' that could be adopted (since the mode is no longer `o'ctal),
> thus giving us both o and O for ascending/descending sorts, as in the
> parameter flags?

Maybe we want to wait some more time before we use the patch below to
find out if we get a reply to the message I send (asking if it's ok to 
change this). I just had some free time...

Anyway, I'd really like to clean this up, so the patch

- changes what was the `o' qualifier to `f' (= file-modes?); I haven't 
  found a better character, but it's easy to change; other free
  characters are: behijknqvyzBCFHJKPQVYZ
- changes the `O' qualifier to `o' and introduces a new qualifier `O'
  that behaves like `^o' (sorts in descending order); and yes, `(^oc)' 
  is the same as `(Oc)'; the uses in the zls example function have
  been changed, are there any more uses?


Bye
 Sven

--- os/glob.c	Wed Feb  3 10:56:32 1999
+++ Src/glob.c	Wed Feb  3 11:44:33 1999
@@ -1432,7 +1432,7 @@
 			    }
 			}
 			break;
-		    case 'o':
+		    case 'f':
 			/* Match modes with chmod-spec. */
 			func = qualmodeflags;
 			data = qgetmodespec(&s);
@@ -1501,6 +1501,7 @@
 			data = qgetnum(&s);
 			break;
 
+		    case 'o':
 		    case 'O':
 			{
 			    int t;
@@ -1524,7 +1525,7 @@
 			    }
 			    gf_sorts |= t;
 			    gf_sortlist[gf_nsorts++] = t |
-				((sense & 1) ? GS_DESC : 0);
+				(((sense & 1) ^ (s[-1] == 'O')) ? GS_DESC : 0);
 			    s++;
 			    break;
 			}
--- od/Zsh/expn.yo	Wed Feb  3 11:08:04 1999
+++ Doc/Zsh/expn.yo	Wed Feb  3 11:51:00 1999
@@ -1098,7 +1098,7 @@
 item(tt(t))(
 files with the sticky bit (01000)
 )
-item(tt(o)var(spec))(
+item(tt(f)var(spec))(
 files with access rights matching var(spec). This var(spec) may be a
 octal number optionally preceded by a `tt(=)', a `tt(PLUS())', or a
 `tt(-)'. If none of these characters is given, the behavior is the
@@ -1111,7 +1111,7 @@
 inthe file-modes are not checked, this is only useful in combination
 with `tt(=)'.
 
-If the qualifier `tt(o)' is followed by any other character anything
+If the qualifier `tt(f)' is followed by any other character anything
 up to the next matching character (`tt([)', `tt({)', and `tt(<)' match 
 `tt(])', `tt(})', and `tt(>)' respectively, any other character
 matches itself) is taken as a list of comma-separated
@@ -1132,11 +1132,11 @@
 `tt(s)' for the setuid and setgid bits, and `tt(t)' for the sticky
 bit.
 
-Thus, `tt(*(o70?))' gives the files for which the owner has read,
+Thus, `tt(*(f70?))' gives the files for which the owner has read,
 write, and execute permission, and for which other group members have
 no rights, independent of the permissions for other user. The pattern
-`tt(*(o-100))' gives all files for which the owner does not have
-execute permission, and `tt(*(o:gu+w,o-rx))' gives the files for which 
+`tt(*(f-100))' gives all files for which the owner does not have
+execute permission, and `tt(*(f:gu+w,o-rx))' gives the files for which 
 the owner and the other members of the group have at least write
 permission, and fo which other users don't have read or execute
 permission.
@@ -1215,7 +1215,7 @@
 sets the tt(GLOB_DOTS) option for the current pattern
 pindex(GLOB_DOTS, setting in pattern)
 )
-item(tt(O)var(c))(
+item(tt(o)var(c))(
 specifies how the names of the files should be sorted. If var(c) is
 tt(n) they are sorted by name (the default), if var(c) is tt(L) they
 are sorted depending on the size (length) of the files, tt(l) makes
@@ -1224,16 +1224,20 @@
 inode change respectively. Note that tt(a), tt(m), and tt(c) compare
 the age to the current time, so the first name in the list is the 
 one of the youngest file. Also note that the modifiers tt(^) and tt(-) are 
-used, so `tt(*(^-OL))' gives a list of all files sorted by file size in 
+used, so `tt(*(^-oL))' gives a list of all files sorted by file size in 
 descending order working not on symbolic links but on the files they
 point to.
 )
+item(tt(O)var(c))(
+like `tt(o)', but sorts in descending order; i.e. `tt(*(^oc))' is the
+same as `tt(*(Oc))' and `tt(*(^Oc))' is the same as `tt(*(oc))'
+)
 item(tt([)var(beg)[tt(,)var(end)]tt(]))(
 specifies which of the matched filenames should be included in the
 returned list. The syntax is the same as for array
 subscripts. var(beg) and the optional var(end) may be mathematical
 expressions. As in parameter subscripting they may be negative to make 
-them count from the last match backward. E.g.: `tt(*(^-OL[1,3]))'
+them count from the last match backward. E.g.: `tt(*(-OL[1,3]))'
 gives a list of the names of three biggest files.
 )
 enditem()
--- of/zls	Wed Feb  3 12:02:02 1999
+++ Functions/zls	Wed Feb  3 12:02:32 1999
@@ -32,7 +32,7 @@
 
 if ((! ARGC)) then
     if [[ $opts = *t* ]]; then
-        set *(O$tmod)
+        set *(o$tmod)
     else
         set *
     fi
@@ -44,7 +44,7 @@
     for (( f = 2; f <= $ARGC; f++ )); do
 	n="$n|\$$f"
     done
-    eval "argv=(($n)(O$tmod))"
+    eval "argv=(($n)(o$tmod))"
 fi
 
 for f in $*

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* Re: PATCH: Re: Btw.: glob-qualifier
  1999-01-29 13:37 Sven Wischnowsky
@ 1999-01-29 17:31 ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 1999-01-29 17:31 UTC (permalink / raw)
  To: zsh-workers

On Jan 29,  2:37pm, Sven Wischnowsky wrote:
} Subject: PATCH: Re: Btw.: glob-qualifier
}
} > [...] (o(ug=w,o+r)) for "user and group must have exactly the write
} > bit set, and other must have at least r" and (o(u+x,go-w)) for "user
} > must have at least the execute bit set, and group and other must not
} > have write" and so on.
} 
} The patch below implements this (with a few extras).

Nifty!  Now I only have one question ... is there another, better letter
than `o' that could be adopted (since the mode is no longer `o'ctal),
thus giving us both o and O for ascending/descending sorts, as in the
parameter flags?

(I'd ask about this on zsh-users first, though, just in case anybody is
making some important use of the old undocumented `o'.)

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* PATCH: Re: Btw.: glob-qualifier
@ 1999-01-29 13:37 Sven Wischnowsky
  1999-01-29 17:31 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Sven Wischnowsky @ 1999-01-29 13:37 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> Oof.  If you're going to make it usable, then REALLY make it usable.
> At the risk of further abusing the already over-used parentheses, how
> about (o(ug=w,o+r)) for "user and group must have exactly the write
> bit set, and other must have at least r" and (o(u+x,go-w)) for "user
> must have at least the execute bit set, and group and other must not
> have write" and so on.

The patch below implements this (with a few extras). The patch
contains a hunk for the docs and I dont' want to write it again here,
at least, Bart's examples work (with a different separator than the
parenthese, of course).

Of course, many of the things you can specify with this can also be
achieved by using the already existing qualifiers. Because of this,
I'm not sure, if this is important enough to be included. However,
some of the things you can do with `(o...)' can not be achieved with
the existing modifiers and for others it may be easier to remember.

Bye
 Sven

--- os/glob.c	Fri Jan 29 10:04:57 1999
+++ Src/glob.c	Fri Jan 29 14:11:56 1999
@@ -1006,21 +1006,96 @@
     return v;
 }
 
-/* get octal number after qualifier */
+/* get mode spec after qualifier */
 
 /**/
 static long
-qgetoctnum(char **s)
+qgetmodespec(char **s)
 {
-    long v = 0;
+    long yes = 0, no = 0, val, mask, t;
+    char *p = *s, c, how, end;
 
-    if (!idigit(**s)) {
-	zerr("octal number expected", NULL, 0);
-	return 0;
-    }
-    while (**s >= '0' && **s <= '7')
-	v = v * 010 + *(*s)++ - '0';
-    return v;
+    if ((c = *p) == '=' || c == Equals || c == '+' || c == '-' ||
+	c == '?' || c == Quest || (c >= '0' && c <= '7')) {
+	end = 0;
+	c = 0;
+    } else {
+	end = (c == '<' ? '>' :
+	       (c == '[' ? ']' :
+		(c == '{' ? '}' :
+		 (c == Inang ? Outang :
+		  (c == Inbrack ? Outbrack :
+		   (c == Inbrace ? Outbrace : c))))));
+	p++;
+    }
+    do {
+	mask = 0;
+	while (((c = *p) == 'u' || c == 'g' || c == 'o' || c == 'a') && end) {
+	    switch (c) {
+	    case 'o': mask |= 01007; break;
+	    case 'g': mask |= 02070; break;
+	    case 'u': mask |= 04700; break;
+	    case 'a': mask |= 07777; break;
+	    }
+	    p++;
+	}
+	how = ((c == '+' || c == '-') ? c : '=');
+	if (c == '+' || c == '-' || c == '=' || c == Equals)
+	    p++;
+	val = 0;
+	if (mask) {
+	    while ((c = *p++) != ',' && c != end) {
+		switch (c) {
+		case 'x': val |= 00111; break;
+		case 'w': val |= 00222; break;
+		case 'r': val |= 00444; break;
+		case 's': val |= 06000; break;
+		case 't': val |= 01000; break;
+		case '0': case '1': case '2': case '3':
+		case '4': case '5': case '6': case '7':
+		    t = ((long) c - '0');
+		    val |= t | (t << 3) | (t << 6);
+		    break;
+		default:
+		    zerr("invalid mode specification", NULL, 0);
+		    return 0;
+		}
+	    }
+	    if (how == '=' || how == '+') {
+		yes |= val & mask;
+		val = ~val;
+	    }
+	    if (how == '=' || how == '-')
+		no |= val & mask;
+	} else {
+	    t = 07777;
+	    while ((c = *p) == '?' || c == Quest ||
+		   (c >= '0' && c <= '7')) {
+		if (c == '?' || c == Quest) {
+		    t = (t << 3) | 7;
+		    val <<= 3;
+		} else {
+		    t <<= 3;
+		    val = (val << 3) | ((long) c - '0');
+		}
+		p++;
+	    }
+	    if (end && c != end && c != ',') {
+		zerr("invalid mode specification", NULL, 0);
+		return 0;
+	    }
+	    if (how == '=') {
+		yes = (yes & ~t) | val;
+		no = (no & ~t) | (~val & ~t);
+	    } else if (how == '+')
+		yes |= val;
+	    else
+		no |= val;
+	}
+    } while (end && c != end);
+
+    *s = p;
+    return ((yes & 07777) | ((no & 07777) << 12));
 }
 
 static int
@@ -1358,10 +1433,9 @@
 			}
 			break;
 		    case 'o':
-			/* Match octal mode of file exactly. *
-			 * Currently undocumented.           */
-			func = qualeqflags;
-			data = qgetoctnum(&s);
+			/* Match modes with chmod-spec. */
+			func = qualmodeflags;
+			data = qgetmodespec(&s);
 			break;
 		    case 'M':
 			/* Mark directories with a / */
@@ -3093,13 +3167,15 @@
     return mode_to_octal(buf->st_mode) & mod;
 }
 
-/* mode matches number supplied exactly  */
+/* mode matches specification */
 
 /**/
 static int
-qualeqflags(struct stat *buf, long mod)
+qualmodeflags(struct stat *buf, long mod)
 {
-    return mode_to_octal(buf->st_mode) == mod;
+    long v = mode_to_octal(buf->st_mode), y = mod & 07777, n = mod >> 12;
+
+    return ((v & y) == y && !(v & n));
 }
 
 /* regular executable file? */
--- od/Zsh/expn.yo	Fri Jan 29 10:05:09 1999
+++ Doc/Zsh/expn.yo	Fri Jan 29 14:28:21 1999
@@ -1088,6 +1088,49 @@
 item(tt(t))(
 files with the sticky bit (01000)
 )
+item(tt(o)var(spec))(
+files with access rights matching var(spec). This var(spec) may be a
+octal number optionally preceded by a `tt(=)', a `tt(PLUS())', or a
+`tt(-)'. If none of these characters is given, the behavior is the
+same as for `tt(=)'. The octal number decribes the mode bits to be
+expected, if combined with a `tt(=)', the value given must match the
+file-modes exactly, with a `tt(PLUS())', at least the bits in the
+given number must be set in the file-modes, and with a `tt(-)', the
+bits in the number must not be set. Giving a `tt(?)' instead of a
+octal digit anywhere in the number ensures that the corresponding bits 
+inthe file-modes are not checked, this is only useful in combination
+with `tt(=)'.
+
+If the qualifier `tt(o)' is followed by any other character anything
+up to the next matching character (`tt([)', `tt({)', and `tt(<)' match 
+`tt(])', `tt(})', and `tt(>)' respectively, any other character
+matches itself) is taken as a list of comma-separated
+var(sub-spec)s. Each var(sub-spec) may be either a octal number as
+described above or a list of any of the characters `tt(u)', `tt(g)',
+`tt(o)', and `tt(a)', followed by a `tt(=)', a `tt(PLUS())', or a
+`tt(-)', followed by a list of any of the characters `tt(r)', `tt(w)', 
+`tt(x)', `tt(s)', and `tt(t)', or a octal digit. The first list of
+characters specify which acess rights are to be checked. If a `tt(u)'
+is given, those for the owner of the file are used, if a `tt(g)' is
+given, those of the group are checked, a `tt(o)' means to test those
+of other users, and the `tt(a)' says to test all three groups. The
+`tt(=)', `tt(PLUS())', and `tt(-)' again says how the modes are to be
+checked and have the same meaning as described for the first form
+above. The second list of characters finally says which access rights
+are to be expected: `tt(r)' for read access, `tt(w)' for write access, 
+`tt(x)' for the right to execute the file (or to search a directory),
+`tt(s)' for the setuid and setgid bits, and `tt(t)' for the sticky
+bit.
+
+Thus, `tt(*(o70?))' gives the files for which the owner has read,
+write, and execute permission, and for which other group members have
+no rights, independent of the permissions for other user. The pattern
+`tt(*(o-100))' gives all files for which the owner does not have
+execute permission, and `tt(*(o:gu+w,o-rx))' gives the files for which 
+the owner and the other members of the group have at least write
+permission, and fo which other users don't have read or execute
+permission.
+)
 item(tt(d)var(dev))(
 files on the device var(dev)
 )

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* PATCH: Re: Btw.: glob-qualifier
@ 1999-01-29  8:39 Sven Wischnowsky
  0 siblings, 0 replies; 5+ messages in thread
From: Sven Wischnowsky @ 1999-01-29  8:39 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> Parens don't work in 3.0.5 either, ever since the (x|y) grouping syntax
> got introduced.  (Now that I've actually read more than the first line
> of the info entry for the `uID' glob qualifier, I see that it still
> mentions parens even though they won't work.)

The patch below fixes the docs.

Bye
 Sven

--- od/Zsh/expn.yo	Fri Jan 29 09:00:40 1999
+++ Doc/Zsh/expn.yo	Fri Jan 29 09:38:09 1999
@@ -1105,8 +1105,8 @@
 files owned by user ID var(id) if it is a number, if not, than the
 character after the `tt(u)' will be used as a separator and the string
 between it and the next matching separator
-(`tt(LPAR())', `tt([)', `tt({)', and `tt(<)'
-match `tt(RPAR())', `tt(])', `tt(})', and `tt(>)' respectively,
+(`tt([)', `tt({)', and `tt(<)'
+match `tt(])', `tt(})', and `tt(>)' respectively,
 any other character matches
 itself) will be taken as a user name, and the user ID of this user will
 be taken (e.g. `tt(u:foo:)' or `tt(u[foo])' for user `tt(foo)')
@@ -1169,7 +1169,7 @@
 them be sorted by the number of links, and tt(a), tt(m), and tt(c)
 make them be sorted by the time of the last access, modification, and
 inode change respectively. Note that tt(a), tt(m), and tt(c) compare
-the age with to the current time, so the first name in the list is the 
+the age to the current time, so the first name in the list is the 
 one of the youngest file. Also note that the modifiers tt(^) and tt(-) are 
 used, so `tt(*(^-OL))' gives a list of all files sorted by file size in 
 descending order working not on symbolic links but on the files they

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

end of thread, other threads:[~1999-02-03 11:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-01  8:21 PATCH: Re: Btw.: glob-qualifier Sven Wischnowsky
  -- strict thread matches above, loose matches on Subject: below --
1999-02-03 11:06 Sven Wischnowsky
1999-01-29 13:37 Sven Wischnowsky
1999-01-29 17:31 ` Bart Schaefer
1999-01-29  8:39 Sven Wischnowsky

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