File 0003-fix-termio.patch of Package magic
diff --git a/graphics/grMain.c b/graphics/grMain.c
index 8d98ef0b..59480ce5 100644
--- a/graphics/grMain.c
+++ b/graphics/grMain.c
@@ -63,7 +63,6 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/
#include <unistd.h>
#include "utils/magic.h"
-#include "utils/magsgtty.h"
#include "textio/textio.h"
#include "utils/geometry.h"
#include "utils/hash.h"
diff --git a/graphics/grNull.c b/graphics/grNull.c
index a4d64519..5aa3f5aa 100644
--- a/graphics/grNull.c
+++ b/graphics/grNull.c
@@ -20,7 +20,6 @@
#include <stdio.h>
#include <string.h>
-#include "utils/magsgtty.h"
#include "utils/magic.h"
#include "utils/geometry.h"
#include "windows/windows.h"
diff --git a/graphics/grOGL1.c b/graphics/grOGL1.c
index 2ba1b1b0..4f84e282 100644
--- a/graphics/grOGL1.c
+++ b/graphics/grOGL1.c
@@ -17,7 +17,6 @@
#include <signal.h>
#include "utils/magic.h"
-#include "utils/magsgtty.h"
#include "utils/geometry.h"
#include "graphics/graphics.h"
#include "windows/windows.h"
diff --git a/graphics/grOGL4.c b/graphics/grOGL4.c
index 472b1caa..339bca23 100644
--- a/graphics/grOGL4.c
+++ b/graphics/grOGL4.c
@@ -22,7 +22,6 @@
#include <X11/Xlib.h>
#include "utils/magic.h"
-#include "utils/magsgtty.h"
#include "textio/textio.h"
#include "utils/geometry.h"
#include "graphics/graphics.h"
diff --git a/graphics/grTCairo1.c b/graphics/grTCairo1.c
index a3f99563..5c6aeee3 100644
--- a/graphics/grTCairo1.c
+++ b/graphics/grTCairo1.c
@@ -28,7 +28,6 @@
#include "utils/main.h"
#include "utils/magic.h"
#include "utils/malloc.h"
-#include "utils/magsgtty.h"
#include "utils/geometry.h"
#include "windows/windows.h"
#include "graphics/graphics.h"
diff --git a/graphics/grTCairo4.c b/graphics/grTCairo4.c
index 506b03b0..b841e784 100644
--- a/graphics/grTCairo4.c
+++ b/graphics/grTCairo4.c
@@ -15,7 +15,6 @@
#include "tcltk/tclmagic.h"
#include "utils/magic.h"
-#include "utils/magsgtty.h"
#include "textio/textio.h"
#include "utils/geometry.h"
#include "windows/windows.h"
diff --git a/graphics/grTOGL1.c b/graphics/grTOGL1.c
index 7849f659..6e747e71 100644
--- a/graphics/grTOGL1.c
+++ b/graphics/grTOGL1.c
@@ -26,7 +26,6 @@
#include "utils/main.h"
#include "utils/magic.h"
#include "utils/malloc.h"
-#include "utils/magsgtty.h"
#include "utils/geometry.h"
#include "windows/windows.h"
#include "graphics/graphics.h"
diff --git a/graphics/grTOGL4.c b/graphics/grTOGL4.c
index 9912d3ef..37798281 100644
--- a/graphics/grTOGL4.c
+++ b/graphics/grTOGL4.c
@@ -13,7 +13,6 @@
#include "tcltk/tclmagic.h"
#include "utils/magic.h"
-#include "utils/magsgtty.h"
#include "textio/textio.h"
#include "utils/geometry.h"
#include "windows/windows.h"
diff --git a/graphics/grTk1.c b/graphics/grTk1.c
index 01c59d8c..0d745ef0 100644
--- a/graphics/grTk1.c
+++ b/graphics/grTk1.c
@@ -23,7 +23,6 @@
#include "utils/main.h"
#include "utils/magic.h"
#include "utils/malloc.h"
-#include "utils/magsgtty.h"
#include "utils/geometry.h"
#include "windows/windows.h"
#include "graphics/graphics.h"
diff --git a/graphics/grTk4.c b/graphics/grTk4.c
index 207f5359..1042ee60 100644
--- a/graphics/grTk4.c
+++ b/graphics/grTk4.c
@@ -13,7 +13,6 @@
#include "tcltk/tclmagic.h"
#include "utils/magic.h"
-#include "utils/magsgtty.h"
#include "textio/textio.h"
#include "utils/geometry.h"
#include "windows/windows.h"
diff --git a/graphics/grX11su1.c b/graphics/grX11su1.c
index 5c883489..8e5cc201 100644
--- a/graphics/grX11su1.c
+++ b/graphics/grX11su1.c
@@ -31,7 +31,6 @@
#include <X11/Xutil.h>
#include "utils/magic.h"
-#include "utils/magsgtty.h"
#include "textio/textio.h"
#include "utils/geometry.h"
#include "textio/txcommands.h"
diff --git a/graphics/grX11su4.c b/graphics/grX11su4.c
index 2a4c45ca..5a041f67 100644
--- a/graphics/grX11su4.c
+++ b/graphics/grX11su4.c
@@ -22,7 +22,6 @@
#include <X11/Xlib.h>
#include "utils/magic.h"
-#include "utils/magsgtty.h"
#include "textio/textio.h"
#include "utils/geometry.h"
#include "graphics/graphics.h"
diff --git a/textio/textioInt.h b/textio/textioInt.h
index f33f55d3..2168cb0e 100644
--- a/textio/textioInt.h
+++ b/textio/textioInt.h
@@ -42,20 +42,6 @@ typedef struct {
#define TX_PROMPT '>'
#define TX_CMD_PROMPT ":"
-/* all of the state associated with a tty terminal */
-#if !defined(SYSV) && !defined(CYGWIN) && !defined(__OpenBSD__) && !defined(EMSCRIPTEN)
-#if defined(HAVE_SYS_IOCTL_COMPAT_H) || defined(HAVE_SGTTY_H)
-#if defined(HAVE_SYS_IOCTL_COMPAT_H)
-#include <sys/ioctl_compat.h> /* replaced sgtty.h */
-#elif defined(HAVE_SGTTY_H)
-#include <sgtty.h>/* legacy - struct sgttyb{} defn */
-#endif
-typedef struct {
- struct sgttyb tx_i_sgtty;
- struct tchars tx_i_tchars;
-} txTermState;
-#endif /* HAVE_SYS_IOCTL_COMPAT_H || HAVE_SGTTY_H */
-#endif /* SYSV */
extern bool TxGetInputEvent(bool block, bool returnOnSigWinch);
diff --git a/textio/txCommands.c b/textio/txCommands.c
index 15ec17c3..d057cc58 100644
--- a/textio/txCommands.c
+++ b/textio/txCommands.c
@@ -39,7 +39,6 @@ static char rcsid[] __attribute__ ((unused)) ="$Header: /usr/cvsroot/magic-8.0/t
#endif
#include "tcltk/tclmagic.h"
-#include "utils/magsgtty.h"
#include "utils/magic.h"
#include "textio/textio.h"
#include "utils/geometry.h"
diff --git a/textio/txInput.c b/textio/txInput.c
index 1955daf6..c0f5218c 100644
--- a/textio/txInput.c
+++ b/textio/txInput.c
@@ -32,14 +32,13 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/
#include <dirent.h>
-#include "utils/magsgtty.h"
#include "utils/magic.h"
-#include "utils/magsgtty.h"
#include "utils/main.h"
#include "textio/textio.h"
#include "utils/geometry.h"
#include "textio/txcommands.h"
#include "textio/textioInt.h"
+#include "utils/magsgtty.h" /* txTermState */
#include "utils/dqueue.h"
#include "utils/macros.h"
#include "utils/hash.h"
@@ -1223,36 +1222,21 @@ TxGetLine(
* ----------------------------------------------------------------------------
*/
-#if defined(SYSV) || defined(CYGWIN)
-
-void
-txGetTermState(
- struct termio *buf)
-{
- ioctl( fileno( stdin ), TCGETA, buf);
-}
-
-#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
-
-void
-txGetTermState(
- struct termios *buf)
-{
- (void) tcgetattr(fileno(stdin), buf);
-}
-
-#else
-
void
txGetTermState(
txTermState *buf)
{
+#if defined(HAVE_TERMIOS_H)
+ (void) tcgetattr(fileno(stdin), &buf->termios);
+#elif defined(HAVE_TERMIO_H)
+ ioctl(fileno(stdin), TCGETA, &buf->termio);
+#else /* sgtty */
ASSERT(TxStdinIsatty, "txGetTermState");
/* save the current terminal characteristics */
- (void) ioctl(fileno(stdin), TIOCGETP, (char *) &(buf->tx_i_sgtty) );
- (void) ioctl(fileno(stdin), TIOCGETC, (char *) &(buf->tx_i_tchars) );
+ (void) ioctl(fileno(stdin), TIOCGETP, (char *) &buf->tx_i_sgtty);
+ (void) ioctl(fileno(stdin), TIOCGETC, (char *) &buf->tx_i_tchars);
+#endif
}
-#endif /* SYSV */
/*
@@ -1271,24 +1255,17 @@ txGetTermState(
void
txSetTermState(
-#if defined(SYSV) || defined(CYGWIN)
- struct termio *buf
-#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
- struct termios *buf
-#else
- txTermState *buf
-#endif /* SYSV */
- )
+ txTermState *buf)
{
-#if defined(SYSV) || defined(CYGWIN)
- ioctl( fileno(stdin), TCSETAF, buf );
-#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
- (void) tcsetattr( fileno(stdin), TCSANOW, buf );
-#else
+#if defined(HAVE_TERMIOS_H)
+ (void) tcsetattr(fileno(stdin), TCSANOW, &buf->termios);
+#elif defined(HAVE_TERMIO_H)
+ ioctl(fileno(stdin), TCSETAF, &buf->termio);
+#else /* sgtty */
/* set the current terminal characteristics */
- (void) ioctl(fileno(stdin), TIOCSETN, (char *) &(buf->tx_i_sgtty) );
- (void) ioctl(fileno(stdin), TIOCSETC, (char *) &(buf->tx_i_tchars) );
-#endif /* SYSV */
+ (void) ioctl(fileno(stdin), TIOCSETN, (char *) &buf->tx_i_sgtty);
+ (void) ioctl(fileno(stdin), TIOCSETC, (char *) &buf->tx_i_tchars);
+#endif
}
@@ -1311,37 +1288,27 @@ txSetTermState(
void
txInitTermRec(
-#if defined(SYSV) || defined(CYGWIN)
- struct termio *buf
-#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
- struct termios *buf
-#else
- txTermState *buf
-#endif /* SYSV */
- )
+ txTermState *buf)
{
-#if defined(SYSV) || defined(CYGWIN) || defined(__OpenBSD__) || defined(EMSCRIPTEN)
- buf->c_lflag = ISIG; /* raw: no echo and no processing, allow signals */
- buf->c_cc[ VMIN ] = 1;
- buf->c_cc[ VTIME ] = 0;
-#else
+#if defined(HAVE_TERMIOS_H)
+ buf->termios.c_lflag = ISIG; /* raw: no echo and no processing, allow signals */
+ buf->termios.c_cc[ VMIN ] = 1;
+ buf->termios.c_cc[ VTIME ] = 0;
+#elif defined(HAVE_TERMIO_H)
+ buf->termio.c_lflag = ISIG; /* raw: no echo and no processing, allow signals */
+ buf->termio.c_cc[ VMIN ] = 1;
+ buf->termio.c_cc[ VTIME ] = 0;
+#else /* sgtty */
/* set things up for us, turn off echo, turn on cbreak, no EOF */
buf->tx_i_sgtty.sg_flags |= CBREAK;
buf->tx_i_sgtty.sg_flags &= ~ECHO;
buf->tx_i_tchars.t_eofc = -1;
-
-#endif /* SYSV */
+#endif
}
-#if defined(SYSV) || defined(CYGWIN)
-struct termio closeTermState;
-#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
-struct termios closeTermState;
-#else
static txTermState closeTermState;
-#endif /* SYSV */
static bool haveCloseState = FALSE;
@@ -1364,21 +1331,21 @@ static bool haveCloseState = FALSE;
void
txSaveTerm(void)
{
-#if defined(SYSV) || defined(CYGWIN)
- ioctl( fileno( stdin ), TCGETA, &closeTermState);
- txEraseChar = closeTermState.c_cc[VERASE];
- txKillChar = closeTermState.c_cc[VKILL];
- TxEOFChar = closeTermState.c_cc[VEOF];
- TxInterruptChar = closeTermState.c_cc[VINTR];
+#if defined(HAVE_TERMIOS_H)
+ (void) tcgetattr(fileno(stdin), &closeTermState.termios);
+ txEraseChar = closeTermState.termios.c_cc[VERASE];
+ txKillChar = closeTermState.termios.c_cc[VKILL];
+ TxEOFChar = closeTermState.termios.c_cc[VEOF];
+ TxInterruptChar = closeTermState.termios.c_cc[VINTR];
haveCloseState = TRUE;
-#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
- (void) tcgetattr( fileno( stdin ), &closeTermState);
- txEraseChar = closeTermState.c_cc[VERASE];
- txKillChar = closeTermState.c_cc[VKILL];
- TxEOFChar = closeTermState.c_cc[VEOF];
- TxInterruptChar = closeTermState.c_cc[VINTR];
+#elif defined(HAVE_TERMIO_H)
+ ioctl(fileno(stdin), TCGETA, &closeTermState.termio);
+ txEraseChar = closeTermState.termio.c_cc[VERASE];
+ txKillChar = closeTermState.termio.c_cc[VKILL];
+ TxEOFChar = closeTermState.termio.c_cc[VEOF];
+ TxInterruptChar = closeTermState.termio.c_cc[VINTR];
haveCloseState = TRUE;
-#else
+#else /* sgtty */
struct ltchars lt;
txGetTermState(&closeTermState);
(void) ioctl(fileno(stdin), TIOCGLTC, (char *) <);
@@ -1391,7 +1358,7 @@ txSaveTerm(void)
TxEOFChar = closeTermState.tx_i_tchars.t_eofc;
TxInterruptChar = closeTermState.tx_i_tchars.t_intrc;
haveCloseState = TRUE;
-#endif /* SYSV */
+#endif
}
@@ -1412,13 +1379,7 @@ txSaveTerm(void)
void
TxSetTerminal(void)
{
-#if defined(SYSV) || defined(CYGWIN)
- struct termio buf;
-#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
- struct termios buf;
-#else
txTermState buf;
-#endif /* SYSV */
#ifdef MAGIC_WRAPPER
/* If using Tk console, don't mess with the terminal settings; */
diff --git a/textio/txMain.c b/textio/txMain.c
index 17e2b185..e202cc2f 100644
--- a/textio/txMain.c
+++ b/textio/txMain.c
@@ -26,7 +26,6 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/
#include <string.h>
#include <unistd.h>
-#include "utils/magsgtty.h"
#include "utils/magic.h"
#include "textio/textio.h"
#include "utils/geometry.h"
diff --git a/textio/txOutput.c b/textio/txOutput.c
index f4f2d1ee..fd0eb8d0 100644
--- a/textio/txOutput.c
+++ b/textio/txOutput.c
@@ -31,7 +31,6 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/
#include <sys/stat.h>
#include <unistd.h>
-#include "utils/magsgtty.h"
#include "utils/magic.h"
#include "textio/textio.h"
#include "utils/geometry.h"
diff --git a/utils/magsgtty.h b/utils/magsgtty.h
index 59e0678a..c7f31b31 100644
--- a/utils/magsgtty.h
+++ b/utils/magsgtty.h
@@ -21,44 +21,54 @@
#ifndef _MAGIC__UTILS__MAGSGTTY_H
#define _MAGIC__UTILS__MAGSGTTY_H
-/* maybe this can be #ifndef HAVE_TERMIO_H */
-#if !defined(SYSV) && !defined(CYGWIN)
-# ifdef ALPHA
-# undef MAX
-# undef MIN
-# endif
-
-/* unclear what platform requires this OpenBSD/FreeBSD ? */
-# ifndef COMPAT_43TTY
-# define COMPAT_43TTY
-# endif
+#if defined(HAVE_TERMIOS_H)
+ /* In modern times everything has POSIX */
+ #include <termios.h>
-#ifdef HAVE_SYS_IOCTL_H
-#include <sys/ioctl.h>
-#endif
+ #ifdef HAVE_SYS_IOCTL_H
+ /* Linux glibx 2.x - present
+ * FreeBSD 14.3-RELEASE - present
+ * Solaris 11.4 - present
+ */
+ #include <sys/ioctl.h>
+ #endif
-#if defined(HAVE_TERMIOS_H)
-#include <termios.h>
-#elif defined(HAVE_SYS_IOCTL_COMPAT_H)
-/* unclear which platform(s) require <sys/ioctl_compat.h> and the structure
- * of this file is such that it will try to include it by default, better
- * to invert the #if and only select this on the known platforms that need
- * it so that <termios.h> goes by default, which exists on MacOSX, Linux, etc..
- * many possible solutions to make this work by default:
- * HAVE_SYS_IOCTL_COMPAT_H ? HAVE_TERMIOS_H ? !defined(linux) at top (MaxOSX is BSD type)
- */
-#include <sys/ioctl_compat.h> /* replaced sgtty.h */
-#elif defined(HAVE_SGTTY_H)
-#include <sgtty.h> /* legacy - struct sgttyb{} defn */
+#elif defined(HAVE_TERMIO_H)
+ /* Linux glibx 2.x - present (just includes termios.h & sys/ioctl.h)
+ * Linux glibc 2.45+ - not present
+ * FreeBSD 14.3-RELEASE - not present
+ * Solaris 11.4 - present
+ */
+ #include <termio.h>
+#else /* sgtty */
+ #if defined(HAVE_SYS_IOCTL_COMPAT_H)
+ /* Linux glibc2.x - not present
+ * FreeBSD 14.3-RELEASE - not present
+ * Solaris 11.4 - not present
+ */
+ #include <sys/ioctl_compat.h> /* replaced sgtty.h */
+ #elif defined(HAVE_SGTTY_H)
+ /* Linux glibc2.x - present (includes sys/ioctl.h)
+ * FreeBSD 14.3-RELEASE - not present
+ * Solaris 11.4 - present
+ */
+ #include <sgtty.h> /* legacy - struct sgttyb{} defn */
+ #endif
#endif
-#else
-#if defined(HAVE_TERMIO_H)
-#include <termio.h>
+/* all of the state associated with a tty terminal */
+typedef struct {
+#if defined(HAVE_TERMIOS_H)
+ struct termios termios;
+#elif defined(HAVE_TERMIO_H)
+ struct termio termio;
+#else /* sgtty */
+ struct sgttyb tx_i_sgtty;
+ struct tchars tx_i_tchars;
#endif
+} txTermState;
-#endif /* !SYSV && !CYGWIN */
#endif /* _MAGIC__UTILS__MAGSGTTY_H */
diff --git a/utils/main.c b/utils/main.c
index b7d05131..b613ec23 100644
--- a/utils/main.c
+++ b/utils/main.c
@@ -37,7 +37,6 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/
#include "utils/main.h"
#include "utils/magic.h"
#include "utils/malloc.h"
-#include "utils/magsgtty.h"
#include "utils/hash.h"
#include "utils/macros.h"
#include "textio/textio.h"
diff --git a/utils/signals.c b/utils/signals.c
index 16ed2599..74e80aef 100644
--- a/utils/signals.c
+++ b/utils/signals.c
@@ -33,7 +33,6 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/
#include "tcltk/tclmagic.h"
#include "utils/main.h"
#include "utils/magic.h"
-#include "utils/magsgtty.h"
#include "textio/textio.h"
#include "utils/geometry.h"
#include "utils/signals.h"