From 662a041dba78e488238947f05da4777575415d3a Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Fri, 2 Sep 2022 23:52:34 -0400 Subject: [PATCH] Make use of termios on OpenBSD --- textio/textioInt.h | 2 +- textio/txInput.c | 28 +++++++++++++++++++++++++++- utils/magsgtty.h | 5 +++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/textio/textioInt.h b/textio/textioInt.h index 5f35ecee..41fbc16f 100644 --- a/textio/textioInt.h +++ b/textio/textioInt.h @@ -41,7 +41,7 @@ typedef struct { #define TX_CMD_PROMPT ":" /* all of the state associated with a tty terminal */ -#if !defined(SYSV) && !defined(CYGWIN) +#if !defined(SYSV) && !defined(CYGWIN) && !defined(__OpenBSD__) typedef struct { struct sgttyb tx_i_sgtty; struct tchars tx_i_tchars; diff --git a/textio/txInput.c b/textio/txInput.c index c56060a1..6f23c685 100644 --- a/textio/txInput.c +++ b/textio/txInput.c @@ -1215,6 +1215,15 @@ txGetTermState(buf) ioctl( fileno( stdin ), TCGETA, buf); } +#elif defined (__OpenBSD__) + +void +txGetTermState(buf) + struct termios *buf; +{ + (void) tcgetattr(fileno(stdin), buf); +} + #else void @@ -1247,12 +1256,16 @@ void txSetTermState(buf) #if defined(SYSV) || defined(CYGWIN) struct termio *buf; +#elif defined(__OpenBSD__) + struct termios *buf; #else txTermState *buf; #endif /* SYSV */ { #if defined(SYSV) || defined(CYGWIN) ioctl( fileno(stdin), TCSETAF, buf ); +#elif defined (__OpenBSD__) + (void) tcsetattr( fileno(stdin), TCSANOW, buf ); #else /* set the current terminal characteristics */ (void) ioctl(fileno(stdin), TIOCSETN, (char *) &(buf->tx_i_sgtty) ); @@ -1282,11 +1295,13 @@ void txInitTermRec(buf) #if defined(SYSV) || defined(CYGWIN) struct termio *buf; +#elif defined(__OpenBSD__) + struct termios *buf; #else txTermState *buf; #endif /* SYSV */ { -#if defined(SYSV) || defined(CYGWIN) +#if defined(SYSV) || defined(CYGWIN) || defined(__OpenBSD__) buf->c_lflag = ISIG; /* raw: no echo and no processing, allow signals */ buf->c_cc[ VMIN ] = 1; buf->c_cc[ VTIME ] = 0; @@ -1303,6 +1318,8 @@ txInitTermRec(buf) #if defined(SYSV) || defined(CYGWIN) struct termio closeTermState; +#elif defined(__OpenBSD__) +struct termios closeTermState; #else static txTermState closeTermState; #endif /* SYSV */ @@ -1335,6 +1352,13 @@ txSaveTerm() TxEOFChar = closeTermState.c_cc[VEOF]; TxInterruptChar = closeTermState.c_cc[VINTR]; haveCloseState = TRUE; +#elif defined(__OpenBSD__) + (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]; + haveCloseState = TRUE; #else struct ltchars lt; txGetTermState(&closeTermState); @@ -1371,6 +1395,8 @@ TxSetTerminal() { #if defined(SYSV) || defined(CYGWIN) struct termio buf; +#elif defined(__OpenBSD__) + struct termios buf; #else txTermState buf; #endif /* SYSV */ diff --git a/utils/magsgtty.h b/utils/magsgtty.h index 89d3ef85..4d261c7a 100644 --- a/utils/magsgtty.h +++ b/utils/magsgtty.h @@ -33,7 +33,12 @@ # endif #include + +#if defined(__OpenBSD__) +#include +#else #include +#endif #else #include