From 1bb5316d8d7e07806c7ffb2c7b3aab9281748ed6 Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Thu, 31 Jul 2025 22:59:00 +0100 Subject: [PATCH] utils/magsgtty.h removal and fixup --- graphics/grMain.c | 1 - graphics/grNull.c | 1 - graphics/grOGL1.c | 1 - graphics/grOGL4.c | 1 - graphics/grTCairo1.c | 1 - graphics/grTCairo4.c | 1 - graphics/grTOGL1.c | 1 - graphics/grTOGL4.c | 1 - graphics/grTk1.c | 1 - graphics/grTk4.c | 1 - graphics/grX11su1.c | 1 - graphics/grX11su4.c | 1 - textio/textioInt.h | 14 ----- textio/txCommands.c | 1 - textio/txInput.c | 125 +++++++++++++++---------------------------- textio/txMain.c | 1 - textio/txOutput.c | 1 - utils/magsgtty.h | 74 ++++++++++++++----------- utils/main.c | 1 - utils/signals.c | 1 - 20 files changed, 85 insertions(+), 145 deletions(-) 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 #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 #include -#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 6b3945b9..154c2c11 100644 --- a/graphics/grOGL1.c +++ b/graphics/grOGL1.c @@ -17,7 +17,6 @@ #include #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 #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 2a6cb0ce..ef96fedf 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 1b64c548..e15d3325 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 ddbc80fa..de5a59d2 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 77c6e41f..d77efe13 100644 --- a/graphics/grX11su1.c +++ b/graphics/grX11su1.c @@ -31,7 +31,6 @@ #include #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 #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 /* replaced sgtty.h */ -#elif defined(HAVE_SGTTY_H) -#include /* 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 39a7c432..1d52b31e 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 5ecb63b8..e3c64bbf 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 -#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" @@ -1225,36 +1224,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 */ /* @@ -1273,24 +1257,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 } @@ -1313,37 +1290,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; @@ -1366,21 +1333,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 *) <); @@ -1393,7 +1360,7 @@ txSaveTerm(void) TxEOFChar = closeTermState.tx_i_tchars.t_eofc; TxInterruptChar = closeTermState.tx_i_tchars.t_intrc; haveCloseState = TRUE; -#endif /* SYSV */ +#endif } @@ -1414,13 +1381,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 aa8a52a7..c1e05e81 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 #include -#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 62f37081..dbc4e032 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 #include -#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 - -#ifdef HAVE_SYS_IOCTL_H -#include -#endif #if defined(HAVE_TERMIOS_H) -#include -#elif defined(HAVE_SYS_IOCTL_COMPAT_H) -/* unclear which platform(s) require 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 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 /* replaced sgtty.h */ -#elif defined(HAVE_SGTTY_H) -#include /* legacy - struct sgttyb{} defn */ + /* In modern times everything has POSIX */ + #include + + #ifdef HAVE_SYS_IOCTL_H + /* Linux glibx 2.x - present + * FreeBSD 14.3-RELEASE - present + * Solaris 11.4 - present + */ + #include + #endif + +#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 +#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 /* 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 /* legacy - struct sgttyb{} defn */ + #endif #endif -#else -#if defined(HAVE_TERMIO_H) -#include +/* 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 d1b400bb..c2ed8682 100644 --- a/utils/main.c +++ b/utils/main.c @@ -38,7 +38,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"