Subject: patch 5.4.36 (was: [Comparing strings?])
From: Bram Moolenaar <[email-masked]>
To: Mike Steed <[email-masked]>
Cc: [email-masked]

------------

Mike Steed wrote:

> Okay, I think I found the problem.  My build of Vim had
> 
>    #define STRICMP(d, s)   vim_stricmp((char *)(d), (char *)(s))
> 
> And it turns out that vim_stricmp() returns 0 when d == s, and 1 when d != s. 
> Shouldn't this routine be fixed to behave like strcasecmp() -- to return -1,
> 0, or 1, telling whether d < s, d == s, or d > s?

Yes, this needs to be fixed.  But I don't understand why your build was using
vim_stricmp().  On Win32 the library stricmp() should have been used.  In
fact, most machines would not use this.

Patch 5.4.36
Problem:    Comparing strings while ignoring case didn't work correctly for
	    some machines. (Mide Steed)
Solution:   vim_stricmp() and vim_strnicmp() only returned 0 or 1.  Changed
	    them to return -1 when the first argument is smaller.
Files:	    src/misc2.c

*** ../vim-5.4.35/src/misc2.c	Fri Jul  2 21:59:18 1999
--- src/misc2.c	Thu Aug 19 12:03:13 1999
***************
*** 954,970 ****
  #if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)) || defined(PROTO)
  /*
   * Compare two strings, ignoring case.
!  * return 0 for match, 1 for difference
   */
      int
  vim_stricmp(s1, s2)
!     char    *s1;
!     char    *s2;
  {
      for (;;)
      {
! 	if (TO_LOWER(*s1) != TO_LOWER(*s2))
! 	    return 1;			    /* this character different */
  	if (*s1 == NUL)
  	    break;			    /* strings match until NUL */
  	++s1;
--- 954,973 ----
  #if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)) || defined(PROTO)
  /*
   * Compare two strings, ignoring case.
!  * return 0 for match, < 0 for smaller, > 0 for bigger
   */
      int
  vim_stricmp(s1, s2)
!     char	*s1;
!     char	*s2;
  {
+     int		i;
+ 
      for (;;)
      {
! 	i = (int)TO_LOWER(*s1) - (int)TO_LOWER(*s2);
! 	if (i != 0)
! 	    return i;			    /* this character different */
  	if (*s1 == NUL)
  	    break;			    /* strings match until NUL */
  	++s1;
***************
*** 977,994 ****
  #if (!defined(HAVE_STRNCASECMP) && !defined(HAVE_STRNICMP)) || defined(PROTO)
  /*
   * Compare two strings, for length "len", ignoring case.
!  * return 0 for match, 1 for difference
   */
      int
  vim_strnicmp(s1, s2, len)
!     char    *s1;
!     char    *s2;
!     size_t  len;
  {
!     while (len)
      {
! 	if (TO_LOWER(*s1) != TO_LOWER(*s2))
! 	    return 1;			    /* this character different */
  	if (*s1 == NUL)
  	    break;			    /* strings match until NUL */
  	++s1;
--- 980,1000 ----
  #if (!defined(HAVE_STRNCASECMP) && !defined(HAVE_STRNICMP)) || defined(PROTO)
  /*
   * Compare two strings, for length "len", ignoring case.
!  * return 0 for match, < 0 for smaller, > 0 for bigger
   */
      int
  vim_strnicmp(s1, s2, len)
!     char	*s1;
!     char	*s2;
!     size_t	len;
  {
!     int		i;
! 
!     while (len > 0)
      {
! 	i = (int)TO_LOWER(*s1) - (int)TO_LOWER(*s2);
! 	if (i != 0)
! 	    return i;			    /* this character different */
  	if (*s1 == NUL)
  	    break;			    /* strings match until NUL */
  	++s1;
*** ../vim-5.4.35/src/version.h	Wed Aug 18 13:05:54 1999
--- src/version.h	Thu Aug 19 11:51:10 1999
***************
*** 19,26 ****
  #define VIM_VERSION_MINOR_STR		"4"
  #define VIM_VERSION_BUILD		 57
  #define VIM_VERSION_BUILD_STR		"57"
! #define VIM_VERSION_PATCHLEVEL		 35
! #define VIM_VERSION_PATCHLEVEL_STR	"35"
  
  /*
   * VIM_VERSION_NODOT is used for the runtime directory name.
--- 19,26 ----
  #define VIM_VERSION_MINOR_STR		"4"
  #define VIM_VERSION_BUILD		 57
  #define VIM_VERSION_BUILD_STR		"57"
! #define VIM_VERSION_PATCHLEVEL		 36
! #define VIM_VERSION_PATCHLEVEL_STR	"36"
  
  /*
   * VIM_VERSION_NODOT is used for the runtime directory name.
***************
*** 30,35 ****
   */
  #define VIM_VERSION_NODOT	"vim54"
  #define VIM_VERSION_SHORT	"5.4"
! #define VIM_VERSION_MEDIUM	"5.4.35"
! #define VIM_VERSION_LONG	"VIM - Vi IMproved 5.4.35 (1999 Aug 18)"
! #define VIM_VERSION_LONG_DATE	"VIM - Vi IMproved 5.4.35 (1999 Aug 18, compiled "
--- 30,35 ----
   */
  #define VIM_VERSION_NODOT	"vim54"
  #define VIM_VERSION_SHORT	"5.4"
! #define VIM_VERSION_MEDIUM	"5.4.36"
! #define VIM_VERSION_LONG	"VIM - Vi IMproved 5.4.36 (1999 Aug 19)"
! #define VIM_VERSION_LONG_DATE	"VIM - Vi IMproved 5.4.36 (1999 Aug 19, compiled "

--
hundred-and-one symptoms of being an internet addict:
147. You finally give up smoking...because it made the monitor dirty.

--/-/---- Bram Moolenaar ---- [email-masked] ---- [email-masked] ---\-\--
  \ \    www.vim.org/iccf      www.moolenaar.net       www.vim.org    / /