*BSD News Article 11269


Return to BSD News archive

Received: by minnie.vk1xwt.ampr.org with NNTP
	id AA1484 ; Tue, 23 Feb 93 14:43:38 EST
Path: sserve!manuel.anu.edu.au!munnari.oz.au!bruce.cs.monash.edu.au!monu6!escargot!minyos.xx.rmit.OZ.AU!s902113
From: s902113@minyos.xx.rmit.OZ.AU (Luke Mewburn)
Newsgroups: comp.unix.bsd
Subject: tcsh glob hacks
Date: 18 Feb 1993 16:28:20 GMT
Organization: RMIT Computer Centre
Lines: 192
Message-ID: <1m0df4INNajk@escargot.xx.rmit.OZ.AU>
NNTP-Posting-Host: minyos.xx.rmit.oz.au

In previous posts I submitted patches to 386bsd's and Net/2's glob
code to add new functionality to it. This patch for tcsh 6.03 adds
the same stuff to it as well.


diff -c tcsh-6.03/glob.3 tcsh/glob.3
*** tcsh-6.03/glob.3	Fri Nov 20 09:04:38 1992
--- tcsh/glob.3	Sat Feb  6 16:51:57 1993
***************
*** 98,103 ****
--- 98,106 ----
  values defined in
  .IR glob.h :
  .TP
+ GLOB_ALTNOT
+ Use ``^'' instead of ``!'' as the negation character following ``[''.
+ .TP
  GLOB_APPEND
  Append pathnames generated to the ones from a previous call (or calls)
  to
***************
*** 116,121 ****
--- 119,129 ----
  for
  .I pglob.
  .TP
+ GLOB_DOTFILES
+ Match files that start with a ``.'', without the explicit need for a
+ ``.'' at the start of
+ .I pattern .
+ .TP
  GLOB_DOOFFS
  Make use of the
  .I gl_offs
***************
*** 168,173 ****
--- 176,184 ----
  .I GLOB_QUOTE
  is set, its effect is present in the pattern returned.
  .TP
+ GLOB_NODOT
+ Never match the filenames ``.'' and ``..''.
+ .TP
  GLOB_QUOTE
  Use the backslash (``\e'') character for quoting: every occurrence of
  a backslash followed by a character in the pattern is replaced by that
***************
*** 285,294 ****
  The
  .I glob
  function is expected to be POSIX 1003.2 compatible with the exception
! that the flag 
! .I GLOB_QUOTE 
  and the fields 
! .I gl_matchc 
  and 
  .I gl_flags 
  should not be used by applications striving for strict POSIX conformance.
--- 296,309 ----
  The
  .I glob
  function is expected to be POSIX 1003.2 compatible with the exception
! that the flags
! .I GLOB_ALTNOT ,
! .I GLOB_DOTFILES ,
! .I GLOB_NODOT ,
! and
! .I GLOB_QUOTE ,
  and the fields 
! .I gl_matchc ,
  and 
  .I gl_flags 
  should not be used by applications striving for strict POSIX conformance.
diff -c tcsh-6.03/glob.c tcsh/glob.c
*** tcsh-6.03/glob.c	Fri Nov 20 09:04:24 1992
--- tcsh/glob.c	Sat Feb 13 15:13:32 1993
***************
*** 51,56 ****
--- 51,60 ----
   *	Set in gl_flags if pattern contained a globbing character.
   * GLOB_ALTNOT:
   *	Use ^ instead of ! for "not".
+  * GLOB_DOTFILES:
+  *	.files don't need the explicit . at the start of the pattern
+  * GLOB_NODOT:
+  *	Never match . or ..
   * gl_matchc:
   *	Number of matches in the current invocation of glob.
   */
***************
*** 532,540 ****
--- 536,559 ----
  	register unsigned char *sc;
  	register Char *dc;
  
+ 
+ 	/* Initial DOT must be matched literally, unless GLOB_DOTFILES   */ 
+ 	/* Won't match DOT or DOTDOT if GLOB_NODOT set. (GLOB_DOTFILES & */
+ 	/* GLOB_NODOT added 930206 by Luke Mewburn <zak@rmit.edu.au>)    */
+ 	if (dp->d_name[0] == DOT) {
+ 	    if (pglob->gl_flags & GLOB_NODOT)
+ 		if ((dp->d_name[1] == EOS) ||
+ 		    (dp->d_name[1] == DOT && dp->d_name[2] == EOS))
+ 		    continue;
+ 	    if (!(pglob->gl_flags & GLOB_DOTFILES))
+ 		if (*pattern != '.')
+ 		    continue;
+ 	}
+ #if 0
  	/* initial DOT must be matched literally */
  	if (dp->d_name[0] == DOT && *pattern != DOT)
  	    continue;
+ #endif 0
  	for (sc = (unsigned char *) dp->d_name, dc = pathend; 
  	     (*dc++ = *sc++) != '\0';)
  	    continue;
diff -c tcsh-6.03/glob.h tcsh/glob.h
*** tcsh-6.03/glob.h	Fri Nov 20 09:04:25 1992
--- tcsh/glob.h	Sat Feb  6 16:27:39 1993
***************
*** 59,64 ****
--- 59,66 ----
  #define GLOB_NOMAGIC	0x100	/* like GLOB_NOCHECK but only if the pattern
  				 * did not have any magic characters */
  #define	GLOB_ALTNOT	0x200	/* use alternate glob character [^ not !] */
+ #define GLOB_DOTFILES	0x400	/* .files don't need explict . in pattern */
+ #define GLOB_NODOT	0x800	/* never match . or .. */
  
  #define	GLOB_NOSPACE	(-1)	/* malloc call failed */
  #define	GLOB_ABEND	(-2)	/* unignored error */
diff -c tcsh-6.03/sh.glob.c tcsh/sh.glob.c
*** tcsh-6.03/sh.glob.c	Fri Nov 20 09:04:20 1992
--- tcsh/sh.glob.c	Sat Feb  6 17:21:56 1993
***************
*** 479,484 ****
--- 479,492 ----
      globv.gl_pathv = 0;
      globv.gl_pathc = 0;
  
+     /*
+      * Luke Mewburn <zak@rmit.edu.au>, 930206: add support for
+      * dotfiles and nodot.
+      */
+     if (adrof(STRdotfiles))
+ 	gflgs |= GLOB_DOTFILES;
+     if (adrof(STRnodot))
+ 	gflgs |= GLOB_NODOT;
      if (nonomatch)
  	gflgs |= GLOB_NOCHECK;
  
diff -c tcsh-6.03/tc.const.c tcsh/tc.const.c
*** tcsh-6.03/tc.const.c	Fri Nov 20 09:04:32 1992
--- tcsh/tc.const.c	Sat Feb  6 17:17:10 1993
***************
*** 154,159 ****
--- 154,161 ----
  Char STRnotify[]	= { 'n', 'o', 't', 'i', 'f', 'y', '\0' };
  Char STRprintexitvalue[] = { 'p', 'r', 'i', 'n', 't', 'e', 'x', 'i', 't', 'v', 
  			    'a', 'l', 'u', 'e', '\0' };
+ Char STRdotfiles[] 	= { 'd', 'o', 't', 'f', 'i', 'l', 'e', 's', '\0' };
+ Char STRnodot[]		= { 'n', 'o', 'd', 'o', 't', '\0' };
  Char STRLparensp[]	= { '(', ' ', '\0' };
  Char STRspRparen[]	= { ' ', ')', '\0' };
  Char STRspace[]		= { ' ', '\0' };
diff -c tcsh-6.03/tcsh.man tcsh/tcsh.man
*** tcsh-6.03/tcsh.man	Fri Nov 20 09:04:39 1992
--- tcsh/tcsh.man	Sat Feb  6 17:16:44 1993
***************
*** 3214,3219 ****
--- 3214,3223 ----
  the first directory on the stack etc. Setting $dirstack resets all
  the stack entries, but the current working directory which is preserved.
  .TP 10
+ .B dotfiles
+ Glob files that start with a ``.'' without the explicit need for a
+ ``.'' at the start of the pattern.
+ .TP 10
  .B dunique 
  Push only directories that are not already in the directory stack.
  .TP 10
***************
*** 3290,3295 ****
--- 3294,3302 ----
  .TP 10
  .B nobeep 
  Disables beeping completely.
+ .TP 10
+ .B nodot
+ Never match the filenames ``.'' or ``..'' in filename globbing.
  .TP 10
  .B nokanji
  If kanji support is enable, setting this variable disables it, so that