Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: case-insensitivity modifiers for globbing



The patch below adds to modifiers to globbing:

`f' makes the pattern one-way-case-insensitive (i.e. lowercase letters 
    match the corresponding uppercase letter)
`F' makes the pattern really case-insensitive (both lowercase and
    uppercase letters match both forms)

I would have preferred to use `i/I' or `c/C', but `I' and `c' were already 
used.

This helps in building completion functions, but of course it may be
helpful otherwise, too.

Bye
 Sven

*** Src/glob.c	Thu Aug 27 13:41:51 1998
--- ../Src/glob.c	Thu Aug 27 13:10:18 1998
***************
*** 81,86 ****
--- 81,87 ----
  static int qualct, qualorct;
  static int range, amc, units;
  static int gf_nullglob, gf_markdirs, gf_noglobdots, gf_listtypes, gf_follow;
+ static int gf_case = 0;
  
  /* Prefix, suffix for doing zle trickery */
  
***************
*** 854,859 ****
--- 855,861 ----
      Complist q;				/* pattern after parsing         */
      char *ostr = (char *)getdata(np);	/* the pattern before the parser */
  					/* chops it up                   */
+     int gfc = 0;			/* case insensitive?             */
  
      MUSTUSEHEAP("glob");
      if (unset(GLOBOPT) || !haswilds(ostr)) {
***************
*** 1178,1183 ****
--- 1180,1191 ----
  			    ++s;
  			data = qgetnum(&s);
  			break;
+ 		    case 'f':
+ 			gfc = 1;
+ 			break;
+ 		    case 'F':
+ 			gfc = 2;
+ 			break;
  
  		    default:
  			zerr("unknown file attribute", NULL, 0);
***************
*** 1234,1240 ****
--- 1242,1250 ----
  
      /* The actual processing takes place here: matches go into  *
       * matchbuf.  This is the only top-level call to scanner(). */
+     gf_case = gfc;
      scanner(q);
+     gf_case = 0;
  
      /* Deal with failures to match depending on options */
      if (matchct)
***************
*** 2414,2420 ****
  	    }
  	    continue;
  	}
! 	if (*pptr == *pat) {
  	    /* just plain old characters */
  	    pptr++;
  	    pat++;
--- 2424,2432 ----
  	    }
  	    continue;
  	}
! 	if (*pptr == *pat ||
! 	    (gf_case == 1 ? (islower(*pat) && tuupper(*pat) == *pptr) :
! 	     (gf_case == 2 ? (tulower(*pat) == tulower(*pptr)) : 0))) {
  	    /* just plain old characters */
  	    pptr++;
  	    pat++;
*** Doc/Zsh/expn.yo	Thu Aug 27 13:20:27 1998
--- ../Doc/Zsh/expn.yo	Thu Aug 27 13:39:39 1998
***************
*** 984,989 ****
--- 984,997 ----
  sets the tt(GLOB_DOTS) option for the current pattern
  pindex(GLOB_DOTS, setting in pattern)
  )
+ item(tt(f))(
+ makes lower case letters in the pettern match themselves and the
+ corresponding uppercase letter
+ )
+ item(tt(F))(
+ makes all letters match themselves and their uppercase or lowercase
+ counterpart
+ )
  enditem()
  
  More than one of these lists can be combined, separated by commas. The


--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author