$OpenBSD: patch-term_c,v 1.3 2018/12/21 15:00:42 sthen Exp $
Index: term.c
--- term.c.orig
+++ term.c
@@ -19,6 +19,9 @@
  *
  */
 
+#include <curses.h>
+#include <term.h>
+
 #include "logo.h"
 #include "globals.h"
 
@@ -30,6 +33,9 @@
 #include <console.h>
 #endif
 
+#ifdef HAVE_TERMIOS_H
+#include <termios.h>
+#else
 #ifdef HAVE_TERMIO_H
 #ifdef HAVE_WX
 #include <termios.h>
@@ -41,6 +47,7 @@
 #include <sgtty.h>
 #endif
 #endif
+#endif
 
 #undef TRUE
 #undef FALSE
@@ -78,6 +85,9 @@ char cm_arr[40];
 char so_arr[40];
 char se_arr[40];
 
+#ifdef HAVE_TERMIOS_H
+struct termios tty_cooked, tty_cbreak;
+#else
 #ifdef HAVE_TERMIO_H
 struct termio tty_cooked, tty_cbreak;
 #else
@@ -85,6 +95,7 @@ struct termio tty_cooked, tty_cbreak;
 struct sgttyb tty_cooked, tty_cbreak;
 #endif
 #endif
+#endif
 
 int interactive, tty_charmode;
 
@@ -92,7 +103,7 @@ extern char **environ, *tgoto(), *tgetstr();
 
 char *termcap_ptr;
 
-int termcap_putter(char ch) {
+int termcap_putter(int ch) {
     *termcap_ptr++ = ch;
     return 0;
 }
@@ -132,6 +143,13 @@ void term_init(void) {
 #endif /* WIN32 */
 #else
     if (interactive) {
+#ifdef HAVE_TERMIOS_H
+	tcgetattr(0, &tty_cooked);
+	tty_cbreak = tty_cooked;
+	tty_cbreak.c_cc[VMIN] = '\01';
+	tty_cbreak.c_cc[VTIME] = '\0';
+	tty_cbreak.c_lflag &= ~(ECHO|ICANON);
+#else
 #ifdef HAVE_TERMIO_H
 	ioctl(0,TCGETA,(char *)(&tty_cooked));
 	tty_cbreak = tty_cooked;
@@ -144,6 +162,7 @@ void term_init(void) {
 	tty_cbreak.sg_flags |= CBREAK;
 	tty_cbreak.sg_flags &= ~ECHO;
 #endif
+#endif
     }
     tty_charmode = 0;
     tgetent(bp, getenv("TERM"));
@@ -188,11 +207,15 @@ void term_init(void) {
 void charmode_on() {
 #ifdef unix
     if ((readstream == stdin) && interactive && !tty_charmode) {
+#ifdef HAVE_TERMIOS_H
+	tcsetattr(0, TCSANOW, &tty_cbreak);
+#else /* !HAVE_TERMIOS_H */
 #ifdef HAVE_TERMIO_H
 	ioctl(0,TCSETA,(char *)(&tty_cbreak));
 #else /* !HAVE_TERMIO_H */
 	ioctl(0,TIOCSETP,(char *)(&tty_cbreak));
 #endif /* HAVE_TERMIO_H */
+#endif /* HAVE_TERMIOS_H */
 	tty_charmode++;
     }
 #endif /* unix */
@@ -204,11 +227,15 @@ void charmode_on() {
 void charmode_off() {
 #ifdef unix
     if (tty_charmode) {
+#ifdef HAVE_TERMIOS_H
+	tcsetattr(0, TCSANOW, &tty_cooked);
+#else /* !HAVE_TERMIOS_H */
 #ifdef HAVE_TERMIO_H
 	ioctl(0,TCSETA,(char *)(&tty_cooked));
 #else /* !HAVE_TERMIO_H */
 	ioctl(0,TIOCSETP,(char *)(&tty_cooked));
 #endif /* HAVE_TERMIO_H */
+#endif /* HAVE_TERMIOS_H */
 	tty_charmode = 0;
     }
 #endif /* unix */
