Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Random sort qualifier
- X-seq: zsh-workers 27718
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxx>
- Subject: Random sort qualifier
- Date: Wed, 17 Feb 2010 16:59:21 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=H+NoePQW0KvVa2jto3OkKCRfk5traw0geb64roj5zhQ=; b=cM7+DFkY8e+MepwA91BxBNgoEJiYiOWyHkjJW3//TM9b5XlI5gHhD3B9VIYa5L+i5F SEPbzLAE9GW1JklHDMK2oVZkcOn/i1TpOi+x+6/Kf+dTu87PNynxp9zcKtxbiAqaHJ9H ygPHXMzBc7dmDcT0Kohv+7F2t2gOzvGOIETfI=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=TkZL1V2+aXM/ACgxgG/sP1BNwig3dOJacQ2oEhxjadxE8GrR5E4k7Amfpu775q8Sl1 W3Ucp3wlAjZGrQDChfP4Y2WJZGgy0LXlrKX/g57FaW+XlNrfMZqFRjaSi8/UsNIWtuvb gvfPOhDNL00BE2YPn9HbULMzxQ7X3I66KcwG8=
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Possibly mostly useful for selecting a single random file via *(or[1])
I only looked at the involved functions for about 3 minutes so I can
make no guarantees more than "It seems to work."
diff --git a/Src/glob.c b/Src/glob.c
index 036f88c..ead6dfe 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -74,8 +74,9 @@ struct gmatch {
#define GS_NAME 1
#define GS_DEPTH 2
#define GS_EXEC 4
+#define GS_RANDOM 8
-#define GS_SHIFT_BASE 8
+#define GS_SHIFT_BASE 16
#define GS_SIZE (GS_SHIFT_BASE)
#define GS_ATIME (GS_SHIFT_BASE << 1)
@@ -995,6 +996,9 @@ gmatchcmp(Gmatch a, Gmatch b)
case GS__LINKS:
r = b->_links - a->_links;
break;
+ case GS_RANDOM:
+ r = 1 - 2*(rand() & 1);
+ break;
}
if (r)
return (int) ((s->tp & GS_DESC) ? -r : r);
@@ -1560,6 +1564,7 @@ zglob(LinkList list, LinkNode np, int nountok)
case 'c': t = GS_CTIME; break;
case 'd': t = GS_DEPTH; break;
case 'N': t = GS_NONE; break;
+ case 'r': t = GS_RANDOM; break;
case 'e':
case '+':
{
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author