Karsten Hopp b08297
To: vim-dev@vim.org
Karsten Hopp b08297
Subject: Patch 7.1.158 (extra)
Karsten Hopp b08297
Fcc: outbox
Karsten Hopp b08297
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp b08297
Mime-Version: 1.0
Karsten Hopp b08297
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp b08297
Content-Transfer-Encoding: 8bit
Karsten Hopp b08297
------------
Karsten Hopp b08297
Karsten Hopp b08297
Patch 7.1.158 (extra)
Karsten Hopp b08297
Problem:    Win32 console: When 'encoding' is "utf-8" and typing Alt-y the
Karsten Hopp b08297
            result is wrong.  Win32 GUI: Alt-y results in "u" when 'encoding'
Karsten Hopp b08297
            is "cp1250" (Lukas Cerman)
Karsten Hopp b08297
Solution:   For utf-8 don't set the 7th bit in a byte, convert to the correct
Karsten Hopp b08297
            byte sequence.  For cp1250, when conversion to 'encoding' results
Karsten Hopp b08297
            in the 7th bit not set, set the 7th bit after conversion.
Karsten Hopp b08297
Files:      src/os_win32.c, src/gui_w48.c
Karsten Hopp b08297
Karsten Hopp b08297
Karsten Hopp b08297
*** ../vim-7.1.157/src/os_win32.c	Mon Oct  1 20:33:45 2007
Karsten Hopp b08297
--- src/os_win32.c	Sat Oct 27 17:35:04 2007
Karsten Hopp b08297
***************
Karsten Hopp b08297
*** 1521,1527 ****
Karsten Hopp b08297
--- 1521,1532 ----
Karsten Hopp b08297
  #endif
Karsten Hopp b08297
  		   )
Karsten Hopp b08297
  		{
Karsten Hopp b08297
+ #ifdef FEAT_MBYTE
Karsten Hopp b08297
+ 		    n = (*mb_char2bytes)(typeahead[typeaheadlen] | 0x80,
Karsten Hopp b08297
+ 						    typeahead + typeaheadlen);
Karsten Hopp b08297
+ #else
Karsten Hopp b08297
  		    typeahead[typeaheadlen] |= 0x80;
Karsten Hopp b08297
+ #endif
Karsten Hopp b08297
  		    modifiers &= ~MOD_MASK_ALT;
Karsten Hopp b08297
  		}
Karsten Hopp b08297
  
Karsten Hopp b08297
*** ../vim-7.1.157/src/gui_w48.c	Sun Sep 30 14:00:41 2007
Karsten Hopp b08297
--- src/gui_w48.c	Mon Oct 29 20:00:25 2007
Karsten Hopp b08297
***************
Karsten Hopp b08297
*** 486,495 ****
Karsten Hopp b08297
  
Karsten Hopp b08297
  /*
Karsten Hopp b08297
   * Convert Unicode character "ch" to bytes in "string[slen]".
Karsten Hopp b08297
   * Return the length.
Karsten Hopp b08297
   */
Karsten Hopp b08297
      static int
Karsten Hopp b08297
! char_to_string(int ch, char_u *string, int slen)
Karsten Hopp b08297
  {
Karsten Hopp b08297
      int		len;
Karsten Hopp b08297
      int		i;
Karsten Hopp b08297
--- 486,496 ----
Karsten Hopp b08297
  
Karsten Hopp b08297
  /*
Karsten Hopp b08297
   * Convert Unicode character "ch" to bytes in "string[slen]".
Karsten Hopp b08297
+  * When "had_alt" is TRUE the ALT key was included in "ch".
Karsten Hopp b08297
   * Return the length.
Karsten Hopp b08297
   */
Karsten Hopp b08297
      static int
Karsten Hopp b08297
! char_to_string(int ch, char_u *string, int slen, int had_alt)
Karsten Hopp b08297
  {
Karsten Hopp b08297
      int		len;
Karsten Hopp b08297
      int		i;
Karsten Hopp b08297
***************
Karsten Hopp b08297
*** 522,529 ****
Karsten Hopp b08297
--- 523,544 ----
Karsten Hopp b08297
  	 * "enc_codepage" is non-zero use the standard Win32 function,
Karsten Hopp b08297
  	 * otherwise use our own conversion function (e.g., for UTF-8). */
Karsten Hopp b08297
  	if (enc_codepage > 0)
Karsten Hopp b08297
+ 	{
Karsten Hopp b08297
  	    len = WideCharToMultiByte(enc_codepage, 0, wstring, len,
Karsten Hopp b08297
  						       string, slen, 0, NULL);
Karsten Hopp b08297
+ 	    /* If we had included the ALT key into the character but now the
Karsten Hopp b08297
+ 	     * upper bit is no longer set, that probably means the conversion
Karsten Hopp b08297
+ 	     * failed.  Convert the original character and set the upper bit
Karsten Hopp b08297
+ 	     * afterwards. */
Karsten Hopp b08297
+ 	    if (had_alt && len == 1 && ch >= 0x80 && string[0] < 0x80)
Karsten Hopp b08297
+ 	    {
Karsten Hopp b08297
+ 		wstring[0] = ch & 0x7f;
Karsten Hopp b08297
+ 		len = WideCharToMultiByte(enc_codepage, 0, wstring, len,
Karsten Hopp b08297
+ 						       string, slen, 0, NULL);
Karsten Hopp b08297
+ 		if (len == 1) /* safety check */
Karsten Hopp b08297
+ 		    string[0] |= 0x80;
Karsten Hopp b08297
+ 	    }
Karsten Hopp b08297
+ 	}
Karsten Hopp b08297
  	else
Karsten Hopp b08297
  	{
Karsten Hopp b08297
  	    len = 1;
Karsten Hopp b08297
***************
Karsten Hopp b08297
*** 573,579 ****
Karsten Hopp b08297
      char_u	string[40];
Karsten Hopp b08297
      int		len = 0;
Karsten Hopp b08297
  
Karsten Hopp b08297
!     len = char_to_string(ch, string, 40);
Karsten Hopp b08297
      if (len == 1 && string[0] == Ctrl_C && ctrl_c_interrupts)
Karsten Hopp b08297
      {
Karsten Hopp b08297
  	trash_input_buf();
Karsten Hopp b08297
--- 588,594 ----
Karsten Hopp b08297
      char_u	string[40];
Karsten Hopp b08297
      int		len = 0;
Karsten Hopp b08297
  
Karsten Hopp b08297
!     len = char_to_string(ch, string, 40, FALSE);
Karsten Hopp b08297
      if (len == 1 && string[0] == Ctrl_C && ctrl_c_interrupts)
Karsten Hopp b08297
      {
Karsten Hopp b08297
  	trash_input_buf();
Karsten Hopp b08297
***************
Karsten Hopp b08297
*** 640,646 ****
Karsten Hopp b08297
      {
Karsten Hopp b08297
  	/* Although the documentation isn't clear about it, we assume "ch" is
Karsten Hopp b08297
  	 * a Unicode character. */
Karsten Hopp b08297
! 	len += char_to_string(ch, string + len, 40 - len);
Karsten Hopp b08297
      }
Karsten Hopp b08297
  
Karsten Hopp b08297
      add_to_input_buf(string, len);
Karsten Hopp b08297
--- 655,661 ----
Karsten Hopp b08297
      {
Karsten Hopp b08297
  	/* Although the documentation isn't clear about it, we assume "ch" is
Karsten Hopp b08297
  	 * a Unicode character. */
Karsten Hopp b08297
! 	len += char_to_string(ch, string + len, 40 - len, TRUE);
Karsten Hopp b08297
      }
Karsten Hopp b08297
  
Karsten Hopp b08297
      add_to_input_buf(string, len);
Karsten Hopp b08297
***************
Karsten Hopp b08297
*** 1775,1781 ****
Karsten Hopp b08297
  		    int	len;
Karsten Hopp b08297
  
Karsten Hopp b08297
  		    /* Handle "key" as a Unicode character. */
Karsten Hopp b08297
! 		    len = char_to_string(key, string, 40);
Karsten Hopp b08297
  		    add_to_input_buf(string, len);
Karsten Hopp b08297
  		}
Karsten Hopp b08297
  		break;
Karsten Hopp b08297
--- 1790,1796 ----
Karsten Hopp b08297
  		    int	len;
Karsten Hopp b08297
  
Karsten Hopp b08297
  		    /* Handle "key" as a Unicode character. */
Karsten Hopp b08297
! 		    len = char_to_string(key, string, 40, FALSE);
Karsten Hopp b08297
  		    add_to_input_buf(string, len);
Karsten Hopp b08297
  		}
Karsten Hopp b08297
  		break;
Karsten Hopp b08297
*** ../vim-7.1.157/src/version.c	Tue Nov 20 12:30:31 2007
Karsten Hopp b08297
--- src/version.c	Tue Nov 20 17:19:18 2007
Karsten Hopp b08297
***************
Karsten Hopp b08297
*** 668,669 ****
Karsten Hopp b08297
--- 668,671 ----
Karsten Hopp b08297
  {   /* Add new patch number below this line */
Karsten Hopp b08297
+ /**/
Karsten Hopp b08297
+     158,
Karsten Hopp b08297
  /**/
Karsten Hopp b08297
Karsten Hopp b08297
-- 
Karsten Hopp b08297
hundred-and-one symptoms of being an internet addict:
Karsten Hopp b08297
123. You ask the car dealer to install an extra cigarette lighter
Karsten Hopp b08297
     on your new car to power your notebook.
Karsten Hopp b08297
Karsten Hopp b08297
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp b08297
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp b08297
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp b08297
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///