Compare commits

...

3 Commits

Author SHA1 Message Date
Torleif Skår fc7aac1ca1
Merge d825f6cafe into 246c0ea7a4 2025-10-31 17:26:02 +01:00
Torleif Skår d825f6cafe textio/txInput.c: Refactor header includes
Rather than being dependent on OS-level defines,
refactor to use feature-level defines.
2025-07-31 20:13:45 +02:00
Torleif Skår 388572c1ff utils/magsgtty.h: Refactor header includes 2025-07-31 20:10:22 +02:00
2 changed files with 58 additions and 95 deletions

View File

@ -1225,36 +1225,29 @@ 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);
}
#if defined(HAVE_TERMIOS_H)
struct termios *buf
#elif defined(HAVE_TERMIO_H)
struct termio *buf
#else
void
txGetTermState(
txTermState *buf)
txTermState *buf
#endif
)
{
#if defined(HAVE_TERMIOS_H) /* POSIX */
(void) tcgetattr(fileno(stdin), buf);
#elif defined(HAVE_TERMIO_H) /* SYSV */
ioctl( fileno( stdin ), TCGETA, buf);
#else /* fallback to sgtty-style */
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) );
#endif
}
#endif /* SYSV */
/*
@ -1273,24 +1266,24 @@ txGetTermState(
void
txSetTermState(
#if defined(SYSV) || defined(CYGWIN)
struct termio *buf
#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
#if defined(HAVE_TERMIOS_H)
struct termios *buf
#elif defined(HAVE_TERMIO_H)
struct termio *buf
#else
txTermState *buf
#endif /* SYSV */
)
#endif
)
{
#if defined(SYSV) || defined(CYGWIN)
ioctl( fileno(stdin), TCSETAF, buf );
#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
#if defined(HAVE_TERMIOS_H) /* POSIX */
(void) tcsetattr( fileno(stdin), TCSANOW, buf );
#else
#elif defined(HAVE_TERMIO_H) /* SYSV */
ioctl( fileno(stdin), TCSETAF, buf );
#else /* fallback to sgtty-style */
/* 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 */
#endif
}
@ -1313,37 +1306,36 @@ txSetTermState(
void
txInitTermRec(
#if defined(SYSV) || defined(CYGWIN)
struct termio *buf
#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
#if defined(HAVE_TERMIOS_H)
struct termios *buf
#elif defined(HAVE_TERMIO_H)
struct termio *buf
#else
txTermState *buf
#endif /* SYSV */
)
#endif
)
{
#if defined(SYSV) || defined(CYGWIN) || defined(__OpenBSD__) || defined(EMSCRIPTEN)
#if defined(HAVE_TERMIOS_H) || defined(HAVE_TERMIO_H)
buf->c_lflag = ISIG; /* raw: no echo and no processing, allow signals */
buf->c_cc[ VMIN ] = 1;
buf->c_cc[ VTIME ] = 0;
#else
#else /* sgtty-style interface */
/* 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)
#if defined(HAVE_TERMIOS_H)
struct termios closeTermState;
#elif defined(HAVE_TERMIO_H)
struct termio closeTermState;
#else
static txTermState closeTermState;
#endif /* SYSV */
#endif
static bool haveCloseState = FALSE;
@ -1366,21 +1358,18 @@ 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];
haveCloseState = TRUE;
#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
#if defined(HAVE_TERMIOS_H) || defined(HAVE_TERMIO_H)
# if defined(HAVE_TERMIOS_H)
(void) tcgetattr( fileno( stdin ), &closeTermState);
# else /* HAVE_TERMIO_H */
ioctl( fileno( stdin ), TCGETA, &closeTermState);
# endif /* HAVE_TERMIOS_H || HAVE_TERMIO_H */
txEraseChar = closeTermState.c_cc[VERASE];
txKillChar = closeTermState.c_cc[VKILL];
TxEOFChar = closeTermState.c_cc[VEOF];
TxInterruptChar = closeTermState.c_cc[VINTR];
haveCloseState = TRUE;
#else
#else /* sgtty-style interface */
struct ltchars lt;
txGetTermState(&closeTermState);
(void) ioctl(fileno(stdin), TIOCGLTC, (char *) &lt);
@ -1393,7 +1382,7 @@ txSaveTerm(void)
TxEOFChar = closeTermState.tx_i_tchars.t_eofc;
TxInterruptChar = closeTermState.tx_i_tchars.t_intrc;
haveCloseState = TRUE;
#endif /* SYSV */
#endif
}
@ -1414,13 +1403,13 @@ txSaveTerm(void)
void
TxSetTerminal(void)
{
#if defined(SYSV) || defined(CYGWIN)
struct termio buf;
#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
#if defined(HAVE_TERMIOS_H)
struct termios buf;
#elif defined(HAVE_TERMIO_H)
struct termio buf;
#else
txTermState buf;
#endif /* SYSV */
#endif
#ifdef MAGIC_WRAPPER
/* If using Tk console, don't mess with the terminal settings; */

View File

@ -21,44 +21,18 @@
#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
#if defined(HAVE_TERMIOS_H) /* POSIX */
# include <termios.h>
#elif defined(HAVE_TERMIO_H) /* SYSV */
# include <termio.h>
# include <sys/ioctl.h>
#else /* Fallback for older BSD/V7 systems */
# if defined(HAVE_SGTTY_H)
# include <sgtty.h>
# elif defined(HAVE_SYS_IOCTL_COMPAT_H)
# include <sys/ioctl_compat.h>
# endif
/* unclear what platform requires this OpenBSD/FreeBSD ? */
# ifndef COMPAT_43TTY
# define COMPAT_43TTY
# endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
# 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 */
#endif
#else
#if defined(HAVE_TERMIO_H)
#include <termio.h>
#endif
#endif /* !SYSV && !CYGWIN */
#endif /* _MAGIC__UTILS__MAGSGTTY_H */