From: Mikael Magnusson <mikachu@gmail.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Random sort qualifier
Date: Wed, 17 Feb 2010 16:59:21 +0100 [thread overview]
Message-ID: <237967ef1002170759x11931f8fj8c61a3e7b081146d@mail.gmail.com> (raw)
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
next reply other threads:[~2010-02-17 15:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-17 15:59 Mikael Magnusson [this message]
2010-02-17 16:02 ` Mikael Magnusson
2010-02-17 16:02 ` Mikael Magnusson
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=237967ef1002170759x11931f8fj8c61a3e7b081146d@mail.gmail.com \
--to=mikachu@gmail.com \
--cc=zsh-workers@zsh.org \
/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).