delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/01/20/01:28:58

From: wrichard AT direct DOT ca (Wade Richards)
Subject: Patch: Bash.exe filename completion.
20 Jan 1997 01:28:58 -0800 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <1.5.4.32.19970120072626.008e16a8.cygnus.gnu-win32@mail.direct.ca>
Mime-Version: 1.0
X-Sender: wrichard AT mail DOT direct DOT ca
X-Mailer: Windows Eudora Light Version 1.5.4 (32)
Original-To: Geoffrey Noer <noer AT cygnus DOT com>
Original-Cc: gnu-win32 AT cygnus DOT com
Original-Sender: owner-gnu-win32 AT cygnus DOT com

Bash, being written for UNIX, is case-sensitive.  So, if you have a file
named "COPYING", and you press "cop" and <tab> for completions, it won't work.
Since win32 has case-insensitive file names, that doesn't make sense.

These three patches makes file-name completion *and* globbing
case-insensitive, when _WIN32 is defined.

*** complete.c.original	Sat Jan 18 21:51:13 1997
--- complete.c	Sun Jan 05 13:52:41 1997
***************
*** 1077,1083 ****
--- 1077,1087 ----
  /* **************************************************************** */
  
  /* Non-zero means that case is not significant in completion. */
+ #ifdef _WIN32
+ int completion_case_fold = 1;
+ #else
  int completion_case_fold = 0;
+ #endif
  
  /* Return an array of (char *) which is a list of completions for TEXT.
     If there are no completions, return a NULL pointer.
***************
*** 1176,1181 ****
--- 1180,1199 ----
    return (match_list);
  }
  
+ /* Case-insentitive "strncmp" function, for completion on case-insensitive
+    file systems. */
+ int
+ strncmpi ( str1, str2, len )
+     char * str1;
+     char * str2;
+     int len;
+ {
+   while (len-- && *str1)
+     if ( to_lower(*str1++) != to_lower(*str2++))
+       return 1;
+   return 0;
+ }
+ 
  /* Okay, now we write the entry_function for filename completion.  In the
     general case.  Note that completion in the shell is a little different
     because of all the pathnames that must be followed when looking up the
***************
*** 1265,1274 ****
  	{
  	  /* Otherwise, if these match up to the length of filename, then
  	     it is a match. */
! 	    if ((entry->d_name[0] == filename[0]) &&
! 		(((int)D_NAMLEN (entry)) >= filename_len) &&
! 		(strncmp (filename, entry->d_name, filename_len) == 0))
! 	      break;
  	}
      }
  
--- 1283,1302 ----
  	{
  	  /* Otherwise, if these match up to the length of filename, then
  	     it is a match. */
!             if (completion_case_fold)
! 	      {
! 	        if ((to_lower(entry->d_name[0]) == to_lower(filename[0])) &&
! 		    (((int)D_NAMLEN (entry)) >= filename_len) &&
! 		    (strncmpi (filename, entry->d_name, filename_len) == 0))
! 	          break;
! 	      }
! 	    else
! 	      {
! 	        if ((entry->d_name[0] == filename[0]) &&
! 		    (((int)D_NAMLEN (entry)) >= filename_len) &&
! 		    (strncmp (filename, entry->d_name, filename_len) == 0))
! 	          break;
! 	      }
  	}
      }
  



*** glob.c.original	Sat Jan 18 21:51:13 1997
--- glob.c	Sun Jan 05 14:28:09 1997
***************
*** 280,285 ****
--- 280,288 ----
  	continue;
  
        flags = (noglob_dot_filenames ? FNM_PERIOD : 0) | FNM_PATHNAME;
+ #ifdef _WIN32
+       flags |= FNM_FOLDCASE;
+ #endif
  
        if (fnmatch (pat, dp->d_name, flags) != FNM_NOMATCH)
  	{




*** fnmatch.h.original	Sat Jan 18 21:51:13 1997
--- fnmatch.h	Sun Jan 05 14:17:47 1997
***************
*** 24,30 ****
  #define	FNM_PATHNAME	(1 << 0)/* No wildcard can ever match `/'.  */
  #define	FNM_NOESCAPE	(1 << 1)/* Backslashes don't quote special chars.  */
  #define	FNM_PERIOD	(1 << 2)/* Leading `.' is matched only explicitly.  */
! #define	__FNM_FLAGS	(FNM_PATHNAME|FNM_NOESCAPE|FNM_PERIOD)
  
  /* Value returned by `fnmatch' if STRING does not match PATTERN.  */
  #define	FNM_NOMATCH	1
--- 24,31 ----
  #define	FNM_PATHNAME	(1 << 0)/* No wildcard can ever match `/'.  */
  #define	FNM_NOESCAPE	(1 << 1)/* Backslashes don't quote special chars.  */
  #define	FNM_PERIOD	(1 << 2)/* Leading `.' is matched only explicitly.  */
! #define FNM_FOLDCASE    (1 << 3)/* Ignore case when matching. */
! #define	__FNM_FLAGS	(FNM_PATHNAME|FNM_NOESCAPE|FNM_PERIOD|FNM_FOLDCASE)
  
  /* Value returned by `fnmatch' if STRING does not match PATTERN.  */
  #define	FNM_NOMATCH	1




*** fnmatch.c.original	Sat Jan 18 21:51:13 1997
--- fnmatch.c	Sun Jan 05 14:38:43 1997
***************
*** 79,87 ****
  	  {
  	    char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
  	    for (--p; *n != '\0'; ++n)
! 	      if ((c == '[' || *n == c1) &&
! 		  fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
! 		return (0);
  	    return (FNM_NOMATCH);
  	  }
  
--- 79,96 ----
  	  {
  	    char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
  	    for (--p; *n != '\0'; ++n)
! 	      if (flags & FNM_FOLDCASE)
! 	        {
! 	          if ((c == '[' || to_lower(*n) == to_lower(c1)) &&
! 		      fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
! 		    return (0);
! 		}
! 	      else
! 	        {
! 	          if ((c == '[' || *n == c1) &&
! 		      fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
! 		    return (0);
! 		}
  	    return (FNM_NOMATCH);
  	  }
  
***************
*** 175,182 ****
  	  break;
  
  	default:
! 	  if (c != *n)
! 	    return (FNM_NOMATCH);
  	}
  
        ++n;
--- 184,199 ----
  	  break;
  
  	default:
! 	  if (flags & FNM_FOLDCASE)
! 	    {
! 	      if (to_lower(c) != to_lower(*n))
! 	        return (FNM_NOMATCH);
! 	    }
! 	  else
! 	    {
! 	      if (c != *n)
! 	        return (FNM_NOMATCH);
! 	    }
  	}
  
        ++n;

----------
Wade Richards    -= WRichard AT Direct DOT CA =- 
"Never attribute to malice what can adequately be explained by stupidity."

-
For help on using this list, send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019