On 26/02/2020 15:32, Takashi Yano wrote:
- Cygwin console with xterm compatible mode causes problem reported
   in https://www.cygwin.com/ml/cygwin-patches/2020-q1/msg00212.html
   if background/foreground colors are set to gray/black respectively
   in Win10 1903/1909. This is caused by "CSI Ps L" (IL), "CSI Ps M"
   (DL) and "ESC M" (RI) control sequences which are broken. This
   patch adds a workaround for the issue.
---
  winsup/cygwin/fhandler_console.cc | 156 +++++++++++++++++++++++++++++-
  winsup/cygwin/wincap.cc           |  10 ++
  winsup/cygwin/wincap.h            |   2 +
  3 files changed, 166 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/fhandler_console.cc 
b/winsup/cygwin/fhandler_console.cc
index 328424a7d..c2198ea1e 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -57,6 +57,16 @@ bool NO_COPY fhandler_console::invisible_console;
     Only one console can exist in a process, therefore, static is suitable. */
  static struct fhandler_base::rabuf_t con_ra;
+/* Write pending buffer for ESC sequence handling
+   in xterm compatible mode */
+#define WPBUF_LEN 256
+static unsigned char wpbuf[WPBUF_LEN];
+static int wpixput;
+#define wpbuf_put(x) \
+  wpbuf[wpixput++] = x; \
+  if (wpixput > WPBUF_LEN) \
+    wpixput--;
+
  static void
  beep ()
[...]
+               }
+             else
+               wpbuf_put (*src);
+             WriteConsoleA (get_output_handle (), wpbuf, wpixput, &n, 0);
+             con.state = normal;
+             wpixput = 0;
+           }

This generates a (useful!) warning with gcc 9.2.0:

../../../../winsup/cygwin/fhandler_console.cc: In member function 'virtual 
ssize_t fhandler_console::write(const void*, size_t)':
../../../../winsup/cygwin/fhandler_console.cc:67:3: error: macro expands to 
multiple statements [-Werror=multistatement-macros]
   67 |   wpbuf[wpixput++] = x; \
      |   ^~~~~
../../../../winsup/cygwin/fhandler_console.cc:67:3: note: in definition of 
macro 'wpbuf_put'
   67 |   wpbuf[wpixput++] = x; \
      |   ^~~~~
../../../../winsup/cygwin/fhandler_console.cc:2993:8: note: some parts of macro 
expansion are not guarded by this 'else' clause
 2993 |        else
      |        ^~~~

So I think either the macro need it contents contained by a 'do { ... } while(0)', or that instance of it needs to be surrounded by braces, to do what you intend.

Reply via email to