handle builds on systems without termios.h

Windows doesn't have this, so add some build time checks.
master
Mike Frysinger 2017-02-21 17:04:48 -05:00 committed by Benno Schulenberg
parent cab33779ae
commit ca86045918
2 changed files with 18 additions and 1 deletions

View File

@ -57,7 +57,7 @@ AC_DEFINE_DIR([PKGDATADIR], [pkgdatadir], [Where data are placed to.])
dnl Checks for header files. dnl Checks for header files.
AC_CHECK_HEADERS(libintl.h limits.h pwd.h sys/param.h) AC_CHECK_HEADERS(libintl.h limits.h pwd.h termios.h sys/param.h)
dnl Checks for options. dnl Checks for options.

View File

@ -34,7 +34,9 @@
#ifdef ENABLE_UTF8 #ifdef ENABLE_UTF8
#include <langinfo.h> #include <langinfo.h>
#endif #endif
#ifdef HAVE_TERMIOS_H
#include <termios.h> #include <termios.h>
#endif
#include <getopt.h> #include <getopt.h>
#ifndef NANO_TINY #ifndef NANO_TINY
#include <sys/ioctl.h> #include <sys/ioctl.h>
@ -48,7 +50,12 @@ static int oldinterval = -1;
static bool no_rcfiles = FALSE; static bool no_rcfiles = FALSE;
/* Should we ignore all rcfiles? */ /* Should we ignore all rcfiles? */
#endif #endif
#ifdef HAVE_TERMIOS_H
static struct termios oldterm; static struct termios oldterm;
#else
# define tcsetattr(...)
# define tcgetattr(...)
#endif
/* The user's original terminal settings. */ /* The user's original terminal settings. */
static struct sigaction act; static struct sigaction act;
/* Used to set up all our fun signal handlers. */ /* Used to set up all our fun signal handlers. */
@ -1417,23 +1424,27 @@ void do_toggle_void(void)
* settings. */ * settings. */
void disable_extended_io(void) void disable_extended_io(void)
{ {
#ifdef HAVE_TERMIOS_H
struct termios term; struct termios term;
tcgetattr(0, &term); tcgetattr(0, &term);
term.c_lflag &= ~IEXTEN; term.c_lflag &= ~IEXTEN;
term.c_oflag &= ~OPOST; term.c_oflag &= ~OPOST;
tcsetattr(0, TCSANOW, &term); tcsetattr(0, TCSANOW, &term);
#endif
} }
/* Disable interpretation of the special control keys in our terminal /* Disable interpretation of the special control keys in our terminal
* settings. */ * settings. */
void disable_signals(void) void disable_signals(void)
{ {
#ifdef HAVE_TERMIOS_H
struct termios term; struct termios term;
tcgetattr(0, &term); tcgetattr(0, &term);
term.c_lflag &= ~ISIG; term.c_lflag &= ~ISIG;
tcsetattr(0, TCSANOW, &term); tcsetattr(0, TCSANOW, &term);
#endif
} }
#ifndef NANO_TINY #ifndef NANO_TINY
@ -1441,11 +1452,13 @@ void disable_signals(void)
* settings. */ * settings. */
void enable_signals(void) void enable_signals(void)
{ {
#ifdef HAVE_TERMIOS_H
struct termios term; struct termios term;
tcgetattr(0, &term); tcgetattr(0, &term);
term.c_lflag |= ISIG; term.c_lflag |= ISIG;
tcsetattr(0, TCSANOW, &term); tcsetattr(0, TCSANOW, &term);
#endif
} }
#endif #endif
@ -1453,22 +1466,26 @@ void enable_signals(void)
* settings. */ * settings. */
void disable_flow_control(void) void disable_flow_control(void)
{ {
#ifdef HAVE_TERMIOS_H
struct termios term; struct termios term;
tcgetattr(0, &term); tcgetattr(0, &term);
term.c_iflag &= ~IXON; term.c_iflag &= ~IXON;
tcsetattr(0, TCSANOW, &term); tcsetattr(0, TCSANOW, &term);
#endif
} }
/* Enable interpretation of the flow control characters in our terminal /* Enable interpretation of the flow control characters in our terminal
* settings. */ * settings. */
void enable_flow_control(void) void enable_flow_control(void)
{ {
#ifdef HAVE_TERMIOS_H
struct termios term; struct termios term;
tcgetattr(0, &term); tcgetattr(0, &term);
term.c_iflag |= IXON; term.c_iflag |= IXON;
tcsetattr(0, TCSANOW, &term); tcsetattr(0, TCSANOW, &term);
#endif
} }
/* Set up the terminal state. Put the terminal in raw mode (read one /* Set up the terminal state. Put the terminal in raw mode (read one