ncurses 6.2 - patch 20201017
[ncurses.git] / ncurses / trace / lib_tracebits.c
index ce483c69bd40a68d13c1c7f929238519cb4b000f..a760d13502b5c0729ef40008e84ccb6872dc1a49 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
+ * Copyright 2019,2020 Thomas E. Dickey                                     *
+ * Copyright 1998-2012,2015 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -34,7 +35,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_tracebits.c,v 1.22 2012/02/22 22:26:58 tom Exp $")
+MODULE_ID("$Id: lib_tracebits.c,v 1.30 2020/09/05 22:54:47 tom Exp $")
 
 #if HAVE_SYS_TERMIO_H
 #include <sys/termio.h>                /* needed for ISC */
@@ -71,9 +72,15 @@ MODULE_ID("$Id: lib_tracebits.c,v 1.22 2012/02/22 22:26:58 tom Exp $")
 
 #ifdef TRACE
 
+#if defined(EXP_WIN32_DRIVER)
+#define BITNAMELEN 36
+#else
+#define BITNAMELEN 8
+#endif
+
 typedef struct {
     unsigned int val;
-    const char *name;
+    const char name[BITNAMELEN];
 } BITNAMES;
 
 #define TRACE_BUF_SIZE(num) (_nc_globals.tracebuf_ptr[num].size)
@@ -85,7 +92,7 @@ lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int v
 
     _nc_STRCAT(buf, label, TRACE_BUF_SIZE(0));
     _nc_STRCAT(buf, ": {", TRACE_BUF_SIZE(0));
-    for (sp = table; sp->name; sp++)
+    for (sp = table; sp->name[0]; sp++)
        if (sp->val != 0
            && (val & sp->val) == sp->val) {
            _nc_STRCAT(buf, sp->name, TRACE_BUF_SIZE(0));
@@ -103,56 +110,59 @@ _nc_trace_ttymode(TTY * tty)
     char *buf;
 
 #ifdef TERMIOS
+#define DATA(name)        { name, { #name } }
+#define DATA2(name,name2) { name, { #name2 } }
+#define DATAX()           { 0,    { "" } }
     static const BITNAMES iflags[] =
     {
-       {BRKINT, "BRKINT"},
-       {IGNBRK, "IGNBRK"},
-       {IGNPAR, "IGNPAR"},
-       {PARMRK, "PARMRK"},
-       {INPCK, "INPCK"},
-       {ISTRIP, "ISTRIP"},
-       {INLCR, "INLCR"},
-       {IGNCR, "IGNC"},
-       {ICRNL, "ICRNL"},
-       {IXON, "IXON"},
-       {IXOFF, "IXOFF"},
-       {0, NULL}
+       DATA(BRKINT),
+       DATA(IGNBRK),
+       DATA(IGNPAR),
+       DATA(PARMRK),
+       DATA(INPCK),
+       DATA(ISTRIP),
+       DATA(INLCR),
+       DATA(IGNCR),
+       DATA(ICRNL),
+       DATA(IXON),
+       DATA(IXOFF),
+       DATAX()
 #define ALLIN  (BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF)
     }, oflags[] =
     {
-       {OPOST, "OPOST"},
-       {OFLAGS_TABS, "XTABS"},
-       {ONLCR, "ONLCR"},
-       {OCRNL, "OCRNL"},
-       {ONOCR, "ONOCR"},
-       {ONLRET, "ONLRET"},
-       {0, NULL}
-#define ALLOUT (OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET)
+       DATA(OPOST),
+       DATA2(OFLAGS_TABS, XTABS),
+       DATA(ONLCR),
+       DATA(OCRNL),
+       DATA(ONOCR),
+       DATA(ONLRET),
+       DATAX()
+#define ALLOUT (OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET|OFLAGS_TABS)
     }, cflags[] =
     {
-       {CLOCAL, "CLOCAL"},
-       {CREAD, "CREAD"},
-       {CSTOPB, "CSTOPB"},
+       DATA(CLOCAL),
+       DATA(CREAD),
+       DATA(CSTOPB),
 #if !defined(CS5) || !defined(CS8)
-       {CSIZE, "CSIZE"},
+       DATA(CSIZE),
 #endif
-       {HUPCL, "HUPCL"},
-       {PARENB, "PARENB"},
-       {PARODD | PARENB, "PARODD"},    /* concession to readability */
-       {0, NULL}
+       DATA(HUPCL),
+       DATA(PARENB),
+       DATA2(PARODD | PARENB, PARODD),
+       DATAX()
 #define ALLCTRL        (CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD)
     }, lflags[] =
     {
-       {ECHO, "ECHO"},
-       {ECHOE | ECHO, "ECHOE"},        /* concession to readability */
-       {ECHOK | ECHO, "ECHOK"},        /* concession to readability */
-       {ECHONL, "ECHONL"},
-       {ICANON, "ICANON"},
-       {ISIG, "ISIG"},
-       {NOFLSH, "NOFLSH"},
-       {TOSTOP, "TOSTOP"},
-       {IEXTEN, "IEXTEN"},
-       {0, NULL}
+       DATA(ECHO),
+       DATA2(ECHOE | ECHO, ECHOE),
+       DATA2(ECHOK | ECHO, ECHOK),
+       DATA(ECHONL),
+       DATA(ICANON),
+       DATA(ISIG),
+       DATA(NOFLSH),
+       DATA(TOSTOP),
+       DATA(IEXTEN),
+       DATAX()
 #define ALLLOCAL       (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
     };
 
@@ -175,11 +185,11 @@ _nc_trace_ttymode(TTY * tty)
 
 #if defined(CS5) && defined(CS8)
        {
-           static struct {
+           static const struct {
                int value;
-               const char *name;
+               const char name[5];
            } csizes[] = {
-#define CS_DATA(name) { name, #name " " }
+#define CS_DATA(name) { name, { #name " " } }
                CS_DATA(CS5),
 #ifdef CS6
                    CS_DATA(CS6),
@@ -190,7 +200,7 @@ _nc_trace_ttymode(TTY * tty)
                    CS_DATA(CS8),
            };
            const char *result = "CSIZE? ";
-           int value = (tty->c_cflag & CSIZE);
+           int value = (int) (tty->c_cflag & CSIZE);
            unsigned n;
 
            if (value != 0) {
@@ -208,6 +218,36 @@ _nc_trace_ttymode(TTY * tty)
        if (tty->c_lflag & ALLLOCAL)
            lookup_bits(buf, lflags, "lflags", tty->c_lflag);
     }
+#elif defined(EXP_WIN32_DRIVER)
+#define DATA(name)        { name, { #name } }
+    static const BITNAMES dwFlagsOut[] =
+    {
+       DATA(ENABLE_PROCESSED_OUTPUT),
+       DATA(ENABLE_WRAP_AT_EOL_OUTPUT),
+       DATA(ENABLE_VIRTUAL_TERMINAL_PROCESSING),
+       DATA(DISABLE_NEWLINE_AUTO_RETURN),
+       DATA(ENABLE_LVB_GRID_WORLDWIDE)
+    };
+    static const BITNAMES dwFlagsIn[] =
+    {
+       DATA(ENABLE_PROCESSED_INPUT),
+       DATA(ENABLE_LINE_INPUT),
+       DATA(ENABLE_ECHO_INPUT),
+       DATA(ENABLE_MOUSE_INPUT),
+       DATA(ENABLE_INSERT_MODE),
+       DATA(ENABLE_QUICK_EDIT_MODE),
+       DATA(ENABLE_EXTENDED_FLAGS),
+       DATA(ENABLE_AUTO_POSITION),
+       DATA(ENABLE_VIRTUAL_TERMINAL_INPUT)
+    };
+
+    buf = _nc_trace_buf(0,
+                       8 + sizeof(dwFlagsOut) +
+                       8 + sizeof(dwFlagsIn));
+    if (buf != 0) {
+       lookup_bits(buf, dwFlagsIn, "dwIn", tty->dwFlagIn);
+       lookup_bits(buf, dwFlagsOut, "dwOut", tty->dwFlagOut);
+    }
 #else
     /* reference: ttcompat(4M) on SunOS 4.1 */
 #ifndef EVENP
@@ -228,17 +268,17 @@ _nc_trace_ttymode(TTY * tty)
 
     static const BITNAMES cflags[] =
     {
-       {CBREAK, "CBREAK"},
-       {CRMOD, "CRMOD"},
-       {ECHO, "ECHO"},
-       {EVENP, "EVENP"},
-       {LCASE, "LCASE"},
-       {LLITOUT, "LLITOUT"},
-       {ODDP, "ODDP"},
-       {RAW, "RAW"},
-       {TANDEM, "TANDEM"},
-       {XTABS, "XTABS"},
-       {0, NULL}
+       DATA(CBREAK),
+       DATA(CRMOD),
+       DATA(ECHO),
+       DATA(EVENP),
+       DATA(LCASE),
+       DATA(LLITOUT),
+       DATA(ODDP),
+       DATA(RAW),
+       DATA(TANDEM),
+       DATA(XTABS),
+       DATAX()
 #define ALLCTRL        (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
     };