From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1150 invoked from network); 1 Apr 2004 18:41:18 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 1 Apr 2004 18:41:18 -0000 Received: (qmail 1608 invoked by alias); 1 Apr 2004 18:41:06 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 19717 Received: (qmail 1558 invoked from network); 1 Apr 2004 18:41:05 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 1 Apr 2004 18:41:05 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [130.225.247.86] by sunsite.dk (MessageWall 1.0.8) with SMTP; 1 Apr 2004 18:41:5 -0000 Received: (qmail 26613 invoked from network); 1 Apr 2004 18:41:05 -0000 Received: from cmailg2.svr.pol.co.uk (195.92.195.172) by a.mx.sunsite.dk with SMTP; 1 Apr 2004 18:41:03 -0000 Received: from modem-114.orange-tail-butterfly.dialup.pol.co.uk ([62.137.43.242] helo=pwstephenson.fsnet.co.uk) by cmailg2.svr.pol.co.uk with esmtp (Exim 4.14) id 1B977d-00071b-NI for zsh-workers@sunsite.dk; Thu, 01 Apr 2004 19:41:02 +0100 Received: by pwstephenson.fsnet.co.uk (Postfix, from userid 501) id DC34B8646; Thu, 1 Apr 2004 13:43:36 -0500 (EST) Received: from pwstephenson.fsnet.co.uk (localhost [127.0.0.1]) by pwstephenson.fsnet.co.uk (Postfix) with ESMTP id B139B8543 for ; Thu, 1 Apr 2004 19:43:36 +0100 (BST) To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: Re: Globbing for Empty Directories? In-reply-to: "Aaron Davies"'s message of "Sun, 28 Mar 2004 02:00:38 CDT." <9E7AF602-8085-11D8-AA68-000502631FBD@louisville.edu> Date: Thu, 01 Apr 2004 19:43:35 +0100 From: Peter Stephenson Message-Id: <20040401184336.DC34B8646@pwstephenson.fsnet.co.uk> X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: * X-Spam-Status: No, hits=1.5 required=6.0 tests=RCVD_IN_SORBS autolearn=no version=2.63 X-Spam-Hits: 1.5 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 Work: pws@csr.com Web: http://www.pwstephenson.fsnet.co.uk