From: Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: Re: Globbing for Empty Directories?
Date: Thu, 01 Apr 2004 19:43:35 +0100 [thread overview]
Message-ID: <20040401184336.DC34B8646@pwstephenson.fsnet.co.uk> (raw)
In-Reply-To: "Aaron Davies"'s message of "Sun, 28 Mar 2004 02:00:38 CDT." <9E7AF602-8085-11D8-AA68-000502631FBD@louisville.edu>
The only non-trivial part is finding a suitable qualifier.
Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.46
diff -u -r1.46 expn.yo
--- Doc/Zsh/expn.yo 8 May 2003 10:30:49 -0000 1.46
+++ Doc/Zsh/expn.yo 1 Apr 2004 18:27:22 -0000
@@ -1630,6 +1630,9 @@
item(tt(/))(
directories
)
+item(tt(F))(
+`full' (i.e. non-empty) directories
+)
item(tt(.))(
plain files
)
Index: Src/glob.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/glob.c,v
retrieving revision 1.31
diff -u -r1.31 glob.c
--- Src/glob.c 6 Oct 2003 22:42:39 -0000 1.31
+++ Src/glob.c 1 Apr 2004 18:27:28 -0000
@@ -1322,6 +1322,9 @@
func = qualmodeflags;
data = qgetmodespec(&s);
break;
+ case 'F':
+ func = qualnonemptydir;
+ break;
case 'M':
/* Mark directories with a / */
if ((gf_markdirs = !(sense & 1)))
@@ -2799,3 +2802,24 @@
}
return 0;
}
+
+/**/
+static int
+qualnonemptydir(char *name, struct stat *buf, off_t days, char *str)
+{
+ DIR *dirh = opendir(name);
+ struct dirent *de;
+
+ if (dirh == NULL)
+ return 0;
+
+ while ((de = readdir(dirh))) {
+ if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
+ closedir(dirh);
+ return 1;
+ }
+ }
+
+ closedir(dirh);
+ return 0;
+}
--
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk
next parent reply other threads:[~2004-04-01 18:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <9E7AF602-8085-11D8-AA68-000502631FBD@louisville.edu>
2004-04-01 18:43 ` Peter Stephenson [this message]
2004-04-01 19:26 ` DervishD
2004-04-01 22:49 ` Geoff Wing
2004-04-02 2:02 ` Geoff Wing
2004-04-06 17:27 ` Wayne Davison
2004-04-06 17:41 ` Peter Stephenson
2004-04-06 17:55 ` Wayne Davison
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=20040401184336.DC34B8646@pwstephenson.fsnet.co.uk \
--to=pws@pwstephenson.fsnet.co.uk \
--cc=zsh-workers@sunsite.dk \
/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).