[PATCH] Cygwin: console: Ignore 0x00 on write().

Corinna Vinschen corinna-cygwin@cygwin.com
Thu Feb 20 13:35:00 GMT 2020


On Feb 20 20:51, Takashi Yano wrote:
> - In xterm compatible mode, 0x00 on write() behaves incompatible
>   with real xterm. In xterm, 0x00 completely ignored. Therefore,
>   0x00 is ignored by console with this patch.
> ---
>  winsup/cygwin/fhandler_console.cc | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
> index 66e645aa1..705ce696e 100644
> --- a/winsup/cygwin/fhandler_console.cc
> +++ b/winsup/cygwin/fhandler_console.cc
> @@ -1794,6 +1794,16 @@ bool fhandler_console::write_console (PWCHAR buf, DWORD len, DWORD& done)
>  	  len -= 4;
>  	}
>      }
> +  /* Workaround for ^@ (0x00) handling in xterm compatible mode. */
> +  if (wincap.has_con_24bit_colors () && !con_is_legacy)
> +    {
> +      WCHAR *p = buf;
> +      while ((p = wmemchr (p, L'\0', len - (p - buf))))
> +	{
> +	  memmove (p, p+1, (len - (p+1 - buf))*sizeof (WCHAR));
> +	  len --;
> +	}
> +    }
>  
>    if (con.iso_2022_G1
>  	? con.vt100_graphics_mode_G1
> -- 
> 2.21.0

Counter-proposal:

diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 66e645aa1774..1b3aa0f34aa6 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -2641,8 +2641,9 @@ fhandler_console::write_normal (const unsigned char *src,
   memset (&ps, 0, sizeof ps);
   while (found < end
 	 && found - src < CONVERT_LIMIT
+	 && base_chars[*found] != IGN
 	 && ((wincap.has_con_24bit_colors () && !con_is_legacy)
-	     || base_chars[*found] == NOR) )
+	     || base_chars[*found] == NOR))
     {
       switch (ret = f_mbtowc (_REENT, NULL, (const char *) found,
 			       end - found, &ps))
@@ -2732,7 +2733,8 @@ do_print:
 	  cursor_rel (-1, 0);
 	  break;
 	case IGN:
-	  cursor_rel (1, 0);
+	 if (!wincap.has_con_24bit_colors () || con_is_legacy)
+	    cursor_rel (1, 0);
 	  break;
 	case CR:
 	  cursor_get (&x, &y);

But, here's a question: Why do we move the cursor to the right at all?
I assume this is compatible with legacy mode, right?


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20200220/77a19425/attachment.sig>


More information about the Cygwin-patches mailing list