summaryrefslogtreecommitdiff
path: root/src/stty.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-11-24 17:03:24 +0000
committerJim Meyering <jim@meyering.net>1996-11-24 17:03:24 +0000
commita992c841ae21bafa88c5862c8be9e8ac9c4d8b65 (patch)
tree67be5d2b2230de891f8a2f9c0a89ccb1be70b5f7 /src/stty.c
parent9299cf1e78a85f9e874193f82980aa00faf7bffd (diff)
downloadcoreutils-a992c841ae21bafa88c5862c8be9e8ac9c4d8b65.tar.xz
Big patch from Karl Heuer. FIXME: fill in details
Diffstat (limited to 'src/stty.c')
-rw-r--r--src/stty.c83
1 files changed, 57 insertions, 26 deletions
diff --git a/src/stty.c b/src/stty.c
index 243343dae..60bbbfded 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -27,6 +27,10 @@
David MacKenzie <djm@gnu.ai.mit.edu> */
+#ifdef TERMIOS_NEEDS_XOPEN_SOURCE
+# define _XOPEN_SOURCE
+#endif
+
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
@@ -38,6 +42,11 @@
# include <sys/stream.h>
# include <sys/ptem.h>
#endif
+#ifdef GWINSZ_IN_SYS_PTY
+# include <sys/ioctl.h>
+# include <sys/tty.h>
+# include <sys/pty.h>
+#endif
#include <getopt.h>
#if PROTOTYPES
# include <stdarg.h>
@@ -88,6 +97,11 @@
#if defined(VEOL2) && !defined(CEOL2)
# define CEOL2 _POSIX_VDISABLE
#endif
+/* ISC renamed swtch to susp for termios, but we'll accept either name. */
+#if defined(VSUSP) && !defined(VSWTCH)
+# define VSWTCH VSUSP
+# define CSWTCH CSUSP
+#endif
#if defined(VSWTCH) && !defined(CSWTCH)
# define CSWTCH _POSIX_VDISABLE
#endif
@@ -1178,27 +1192,12 @@ set_speed (enum speed_setting type, const char *arg, struct termios *mode)
#ifdef TIOCGWINSZ
-/* Get window size information. First try getting the information
- associated with standard output and if that fails, try standard input.
- Return zero for success, nonzero if both ioctl's failed. */
-
-static int
-get_win_size (struct winsize *win)
-{
- int err;
-
- err = ioctl (1, TIOCGWINSZ, (char *) win);
- if (err != 0)
- err = ioctl (0, TIOCGWINSZ, (char *) win);
- return err;
-}
-
static void
set_window_size (int rows, int cols)
{
struct winsize win;
- if (get_win_size (&win))
+ if (ioctl (0, TIOCGWINSZ, (char *) &win))
{
if (errno != EINVAL)
error (1, errno, _("standard input"));
@@ -1260,10 +1259,12 @@ display_window_size (int fancy)
{
struct winsize win;
- if (get_win_size (&win))
+ if (ioctl (0, TIOCGWINSZ, (char *) &win))
{
if (errno != EINVAL)
error (1, errno, _("standard input"));
+ if (!fancy)
+ error (1, 0, _("no size information for this device"));
}
else
{
@@ -1281,16 +1282,16 @@ screen_columns (void)
#ifdef TIOCGWINSZ
struct winsize win;
- if (get_win_size (&win))
- {
- /* With Solaris 2.[123], this ioctl fails and errno is set to
- EINVAL for telnet (but not rlogin) sessions. */
- if (errno != EINVAL)
- error (1, errno, _("standard input"));
- }
- else if (win.ws_col > 0)
+ /* With Solaris 2.[123], this ioctl fails and errno is set to
+ EINVAL for telnet (but not rlogin) sessions.
+ On ISC 3.0, it fails for the console and the serial port
+ (but it works for ptys).
+ It can also fail on any system when stdout isn't a tty.
+ In case of any failure, just use the default. */
+ if (ioctl (1, TIOCGWINSZ, (char *) &win) == 0 && win.ws_col > 0)
return win.ws_col;
#endif
+ /* FIXME: use xstrtol */
if (getenv ("COLUMNS"))
return atoi (getenv ("COLUMNS"));
return 80;
@@ -1361,6 +1362,19 @@ display_changed (struct termios *mode)
{
if (mode->c_cc[control_info[i].offset] == control_info[i].saneval)
continue;
+ /* If swtch is the same as susp, don't print both. */
+#if VSWTCH == VSUSP
+ if (strcmp (control_info[i].name, "swtch") == 0)
+ continue;
+#endif
+ /* If eof uses the same slot as min, only print whichever applies. */
+#if VEOF == VMIN
+ if ((mode->c_lflag & ICANON) == 0
+ && (strcmp (control_info[i].name, "eof") == 0
+ || strcmp(control_info[i].name, "eol") == 0))
+ continue;
+#endif
+
empty_line = 0;
wrapf ("%s = %s;", control_info[i].name,
visible (mode->c_cc[control_info[i].offset]));
@@ -1431,10 +1445,27 @@ display_all (struct termios *mode)
for (i = 0; strcmp (control_info[i].name, "min"); ++i)
{
+ /* If swtch is the same as susp, don't print both. */
+#if VSWTCH == VSUSP
+ if (strcmp (control_info[i].name, "swtch") == 0)
+ continue;
+#endif
+ /* If eof uses the same slot as min, only print whichever applies. */
+#if VEOF == VMIN
+ if ((mode->c_lflag & ICANON) == 0
+ && (strcmp (control_info[i].name, "eof") == 0
+ || strcmp(control_info[i].name, "eol") == 0))
+ continue;
+#endif
wrapf ("%s = %s;", control_info[i].name,
visible (mode->c_cc[control_info[i].offset]));
}
- wrapf ("min = %d; time = %d;\n", mode->c_cc[VMIN], mode->c_cc[VTIME]);
+#if VEOF == VMIN
+ if ((mode->c_lflag & ICANON) == 0)
+#endif
+ wrapf ("min = %d; time = %d;", mode->c_cc[VMIN], mode->c_cc[VTIME]);
+ if (current_col != 0)
+ putchar ('\n');
current_col = 0;
for (i = 0; mode_info[i].name != NULL; ++i)