File boo1201384.patch of Package ncurses.31889

---
 progs/reset_cmd.c           |  239 +++++++++++++++++++++++++-------------------
 1 file changed, 141 insertions(+), 98 deletions(-)

--- progs/reset_cmd.c
+++ progs/reset_cmd.c	2023-12-12 09:57:14.586500611 +0000
@@ -74,6 +74,9 @@ MODULE_ID("$Id: reset_cmd.c,v 1.13 2017/
 # endif
 #endif
 
+#define set_flags(target, mask)    target |= mask
+#define clear_flags(target, mask)  target &= ~((unsigned)(mask))
+
 static FILE *my_file;
 
 static bool use_reset = FALSE;	/* invoked as reset */
@@ -188,12 +191,90 @@ out_char(int c)
     tty_settings->c_cc[item] = CHK(tty_settings->c_cc[item], value)
 
 /*
+ * Simplify ifdefs
+ */
+#ifndef BSDLY
+#define BSDLY 0
+#endif
+#ifndef CRDLY
+#define CRDLY 0
+#endif
+#ifndef ECHOCTL
+#define ECHOCTL 0
+#endif
+#ifndef ECHOKE
+#define ECHOKE 0
+#endif
+#ifndef ECHOPRT
+#define ECHOPRT 0
+#endif
+#ifndef FFDLY
+#define FFDLY 0
+#endif
+#ifndef IMAXBEL
+#define IMAXBEL 0
+#endif
+#ifndef IUCLC
+#define IUCLC 0
+#endif
+#ifndef IXANY
+#define IXANY 0
+#endif
+#ifndef NLDLY
+#define NLDLY 0
+#endif
+#ifndef OCRNL
+#define OCRNL 0
+#endif
+#ifndef OFDEL
+#define OFDEL 0
+#endif
+#ifndef OFILL
+#define OFILL 0
+#endif
+#ifndef OLCUC
+#define OLCUC 0
+#endif
+#ifndef ONLCR
+#define ONLCR 0
+#endif
+#ifndef ONLRET
+#define ONLRET 0
+#endif
+#ifndef ONOCR
+#define ONOCR 0
+#endif
+#ifndef OXTABS
+#define OXTABS 0
+#endif
+#ifndef TAB3
+#define TAB3 0
+#endif
+#ifndef TABDLY
+#define TABDLY 0
+#endif
+#ifndef TOSTOP
+#define TOSTOP 0
+#endif
+#ifndef VTDLY
+#define VTDLY 0
+#endif
+#ifndef XCASE
+#define XCASE 0
+#endif
+
+/*
  * Reset the terminal mode bits to a sensible state.  Very useful after
  * a child program dies in raw mode.
  */
 void
 reset_tty_settings(int fd, TTY * tty_settings)
 {
+    unsigned mask;
+#ifdef TIOCMGET
+    int modem_bits;
+#endif
+
     GET_TTY(fd, tty_settings);
 
 #ifdef TERMIOS
@@ -202,6 +283,9 @@ reset_tty_settings(int fd, TTY * tty_set
 #endif
     reset_char(VEOF, CEOF);
     reset_char(VERASE, CERASE);
+#if defined(VERASE2) && defined(CERASE2)
+    reset_char(VERASE2, CERASE2);
+#endif
 #if defined(VFLUSH) && defined(CFLUSH)
     reset_char(VFLUSH, CFLUSH);
 #endif
@@ -227,106 +311,65 @@ reset_tty_settings(int fd, TTY * tty_set
     reset_char(VWERASE, CWERASE);
 #endif
 
-    tty_settings->c_iflag &= ~((unsigned) (IGNBRK
-					   | PARMRK
-					   | INPCK
-					   | ISTRIP
-					   | INLCR
-					   | IGNCR
-#ifdef IUCLC
-					   | IUCLC
-#endif
-#ifdef IXANY
-					   | IXANY
-#endif
-					   | IXOFF));
-
-    tty_settings->c_iflag |= (BRKINT
-			      | IGNPAR
-			      | ICRNL
-			      | IXON
-#ifdef IMAXBEL
-			      | IMAXBEL
-#endif
-	);
-
-    tty_settings->c_oflag &= ~((unsigned) (0
-#ifdef OLCUC
-					   | OLCUC
-#endif
-#ifdef OCRNL
-					   | OCRNL
-#endif
-#ifdef ONOCR
-					   | ONOCR
-#endif
-#ifdef ONLRET
-					   | ONLRET
-#endif
-#ifdef OFILL
-					   | OFILL
-#endif
-#ifdef OFDEL
-					   | OFDEL
-#endif
-#ifdef NLDLY
-					   | NLDLY
-#endif
-#ifdef CRDLY
-					   | CRDLY
-#endif
-#ifdef TABDLY
-					   | TABDLY
-#endif
-#ifdef BSDLY
-					   | BSDLY
-#endif
-#ifdef VTDLY
-					   | VTDLY
-#endif
-#ifdef FFDLY
-					   | FFDLY
-#endif
-			       ));
-
-    tty_settings->c_oflag |= (OPOST
-#ifdef ONLCR
-			      | ONLCR
-#endif
-	);
-
-    tty_settings->c_cflag &= ~((unsigned) (CSIZE
-					   | CSTOPB
-					   | PARENB
-					   | PARODD
-					   | CLOCAL));
-    tty_settings->c_cflag |= (CS8 | CREAD);
-    tty_settings->c_lflag &= ~((unsigned) (ECHONL
-					   | NOFLSH
-#ifdef TOSTOP
-					   | TOSTOP
-#endif
-#ifdef ECHOPTR
-					   | ECHOPRT
-#endif
-#ifdef XCASE
-					   | XCASE
+    clear_flags(tty_settings->c_iflag, (IGNBRK
+					| PARMRK
+					| INPCK
+					| ISTRIP
+					| INLCR
+					| IGNCR
+					| IUCLC
+					| IXANY
+					| IXOFF));
+
+    set_flags(tty_settings->c_iflag, (BRKINT
+				      | IGNPAR
+				      | ICRNL
+				      | IXON
+				      | IMAXBEL));
+
+    clear_flags(tty_settings->c_oflag, (0
+					| OLCUC
+					| OCRNL
+					| ONOCR
+					| ONLRET
+					| OFILL
+					| OFDEL
+					| NLDLY
+					| CRDLY
+					| TABDLY
+					| BSDLY
+					| VTDLY
+					| FFDLY));
+
+    set_flags(tty_settings->c_oflag, (OPOST
+				      | ONLCR));
+
+    mask = (CSIZE | CSTOPB | PARENB | PARODD);
+#ifdef TIOCMGET
+    /* leave clocal alone if this appears to use a modem */
+    if (ioctl(fd, TIOCMGET, &modem_bits) == -1)
+	mask |= CLOCAL;
+#else
+    /* cannot check - use the behavior from tset */
+    mask |= CLOCAL;
 #endif
-			       ));
+    clear_flags(tty_settings->c_cflag, mask);
 
-    tty_settings->c_lflag |= (ISIG
-			      | ICANON
-			      | ECHO
-			      | ECHOE
-			      | ECHOK
-#ifdef ECHOCTL
-			      | ECHOCTL
-#endif
-#ifdef ECHOKE
-			      | ECHOKE
-#endif
-	);
-#endif
+    set_flags(tty_settings->c_cflag, (CS8 | CREAD));
+    clear_flags(tty_settings->c_lflag, (ECHONL
+					| NOFLSH
+					| TOSTOP
+					| ECHOPRT
+					| XCASE));
+
+    set_flags(tty_settings->c_lflag, (ISIG
+				      | ICANON
+				      | ECHO
+				      | ECHOE
+				      | ECHOK
+				      | ECHOCTL
+				      | ECHOKE));
+#endif /* TERMIOS */
 
     SET_TTY(fd, tty_settings);
 }
openSUSE Build Service is sponsored by