2001-02-14 18:47:33 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/* stty -- change and print terminal line settings
|
|
|
|
Copyright (C) 1990-1999 Free Software Foundation, Inc.
|
|
|
|
|
2006-01-22 22:55:11 +00:00
|
|
|
Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
|
|
|
*/
|
2001-02-14 18:47:33 +00:00
|
|
|
/* Usage: stty [-ag] [-F device] [setting...]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-a Write all current settings to stdout in human-readable form.
|
|
|
|
-g Write all current settings to stdout in stty-readable form.
|
|
|
|
-F Open and use the specified device instead of stdin
|
|
|
|
|
|
|
|
If no args are given, write to stdout the baud rate and settings that
|
|
|
|
have been changed from their defaults. Mode reading and changes
|
|
|
|
are done on the specified device, or stdin if none was specified.
|
|
|
|
|
|
|
|
David MacKenzie <djm@gnu.ai.mit.edu>
|
|
|
|
|
2001-07-12 20:26:32 +00:00
|
|
|
Special for busybox ported by Vladimir Oleynik <dzo@simtreas.ru> 2001
|
2001-02-14 18:47:33 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2006-06-07 20:17:41 +00:00
|
|
|
#include "busybox.h"
|
2001-02-14 18:47:33 +00:00
|
|
|
|
|
|
|
#ifndef _POSIX_VDISABLE
|
|
|
|
# define _POSIX_VDISABLE ((unsigned char) 0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define Control(c) ((c) & 0x1f)
|
2006-09-19 14:17:10 +00:00
|
|
|
/* Canonical values for control characters */
|
2001-02-14 18:47:33 +00:00
|
|
|
#ifndef CINTR
|
2006-09-19 14:17:10 +00:00
|
|
|
# define CINTR Control('c')
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifndef CQUIT
|
|
|
|
# define CQUIT 28
|
|
|
|
#endif
|
|
|
|
#ifndef CERASE
|
|
|
|
# define CERASE 127
|
|
|
|
#endif
|
|
|
|
#ifndef CKILL
|
2006-09-19 14:17:10 +00:00
|
|
|
# define CKILL Control('u')
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifndef CEOF
|
2006-09-19 14:17:10 +00:00
|
|
|
# define CEOF Control('d')
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifndef CEOL
|
|
|
|
# define CEOL _POSIX_VDISABLE
|
|
|
|
#endif
|
|
|
|
#ifndef CSTART
|
2006-09-19 14:17:10 +00:00
|
|
|
# define CSTART Control('q')
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifndef CSTOP
|
2006-09-19 14:17:10 +00:00
|
|
|
# define CSTOP Control('s')
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifndef CSUSP
|
2006-09-19 14:17:10 +00:00
|
|
|
# define CSUSP Control('z')
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#if defined(VEOL2) && !defined(CEOL2)
|
|
|
|
# define CEOL2 _POSIX_VDISABLE
|
|
|
|
#endif
|
2006-09-19 14:17:10 +00:00
|
|
|
/* ISC renamed swtch to susp for termios, but we'll accept either name */
|
2001-02-14 18:47:33 +00:00
|
|
|
#if defined(VSUSP) && !defined(VSWTCH)
|
|
|
|
# define VSWTCH VSUSP
|
|
|
|
# define CSWTCH CSUSP
|
|
|
|
#endif
|
|
|
|
#if defined(VSWTCH) && !defined(CSWTCH)
|
|
|
|
# define CSWTCH _POSIX_VDISABLE
|
|
|
|
#endif
|
|
|
|
|
2006-09-19 15:12:12 +00:00
|
|
|
/* SunOS 5.3 loses (^Z doesn't work) if 'swtch' is the same as 'susp'.
|
|
|
|
So the default is to disable 'swtch.' */
|
2001-02-14 18:47:33 +00:00
|
|
|
#if defined (__sparc__) && defined (__svr4__)
|
|
|
|
# undef CSWTCH
|
|
|
|
# define CSWTCH _POSIX_VDISABLE
|
|
|
|
#endif
|
|
|
|
|
2001-03-02 20:00:54 +00:00
|
|
|
#if defined(VWERSE) && !defined (VWERASE) /* AIX-3.2.5 */
|
2001-02-14 18:47:33 +00:00
|
|
|
# define VWERASE VWERSE
|
|
|
|
#endif
|
|
|
|
#if defined(VDSUSP) && !defined (CDSUSP)
|
2006-09-19 14:17:10 +00:00
|
|
|
# define CDSUSP Control('y')
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
2001-03-02 20:00:54 +00:00
|
|
|
#if !defined(VREPRINT) && defined(VRPRNT) /* Irix 4.0.5 */
|
2001-02-14 18:47:33 +00:00
|
|
|
# define VREPRINT VRPRNT
|
|
|
|
#endif
|
|
|
|
#if defined(VREPRINT) && !defined(CRPRNT)
|
2006-09-19 14:17:10 +00:00
|
|
|
# define CRPRNT Control('r')
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#if defined(VWERASE) && !defined(CWERASE)
|
2006-09-19 14:17:10 +00:00
|
|
|
# define CWERASE Control('w')
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#if defined(VLNEXT) && !defined(CLNEXT)
|
2006-09-19 14:17:10 +00:00
|
|
|
# define CLNEXT Control('v')
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#if defined(VDISCARD) && !defined(VFLUSHO)
|
|
|
|
# define VFLUSHO VDISCARD
|
|
|
|
#endif
|
2001-03-02 20:00:54 +00:00
|
|
|
#if defined(VFLUSH) && !defined(VFLUSHO) /* Ultrix 4.2 */
|
2001-02-14 18:47:33 +00:00
|
|
|
# define VFLUSHO VFLUSH
|
|
|
|
#endif
|
2001-03-02 20:00:54 +00:00
|
|
|
#if defined(CTLECH) && !defined(ECHOCTL) /* Ultrix 4.3 */
|
2001-02-14 18:47:33 +00:00
|
|
|
# define ECHOCTL CTLECH
|
|
|
|
#endif
|
2001-03-02 20:00:54 +00:00
|
|
|
#if defined(TCTLECH) && !defined(ECHOCTL) /* Ultrix 4.2 */
|
2001-02-14 18:47:33 +00:00
|
|
|
# define ECHOCTL TCTLECH
|
|
|
|
#endif
|
2001-03-02 20:00:54 +00:00
|
|
|
#if defined(CRTKIL) && !defined(ECHOKE) /* Ultrix 4.2 and 4.3 */
|
2001-02-14 18:47:33 +00:00
|
|
|
# define ECHOKE CRTKIL
|
|
|
|
#endif
|
|
|
|
#if defined(VFLUSHO) && !defined(CFLUSHO)
|
2006-09-19 14:17:10 +00:00
|
|
|
# define CFLUSHO Control('o')
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#if defined(VSTATUS) && !defined(CSTATUS)
|
2006-09-19 14:17:10 +00:00
|
|
|
# define CSTATUS Control('t')
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
|
2006-09-19 14:17:10 +00:00
|
|
|
/* Which speeds to set */
|
2001-02-14 18:47:33 +00:00
|
|
|
enum speed_setting {
|
|
|
|
input_speed, output_speed, both_speeds
|
|
|
|
};
|
|
|
|
|
2006-09-19 15:12:12 +00:00
|
|
|
/* Which member(s) of 'struct termios' a mode uses */
|
2006-09-19 14:24:23 +00:00
|
|
|
enum {
|
2003-03-19 09:13:01 +00:00
|
|
|
/* Do NOT change the order or values, as mode_type_flag()
|
2006-09-19 14:17:10 +00:00
|
|
|
* depends on them */
|
2001-02-14 18:47:33 +00:00
|
|
|
control, input, output, local, combination
|
|
|
|
};
|
|
|
|
|
2001-03-02 20:00:54 +00:00
|
|
|
static const char evenp [] = "evenp";
|
|
|
|
static const char raw [] = "raw";
|
|
|
|
static const char stty_min [] = "min";
|
|
|
|
static const char stty_time [] = "time";
|
2001-02-14 18:47:33 +00:00
|
|
|
static const char stty_swtch[] = "swtch";
|
2001-03-02 20:00:54 +00:00
|
|
|
static const char stty_eol [] = "eol";
|
|
|
|
static const char stty_eof [] = "eof";
|
|
|
|
static const char parity [] = "parity";
|
|
|
|
static const char stty_oddp [] = "oddp";
|
|
|
|
static const char stty_nl [] = "nl";
|
|
|
|
static const char stty_ek [] = "ek";
|
|
|
|
static const char stty_sane [] = "sane";
|
|
|
|
static const char cbreak [] = "cbreak";
|
2001-02-14 18:47:33 +00:00
|
|
|
static const char stty_pass8[] = "pass8";
|
2001-03-02 20:00:54 +00:00
|
|
|
static const char litout [] = "litout";
|
|
|
|
static const char cooked [] = "cooked";
|
|
|
|
static const char decctlq [] = "decctlq";
|
|
|
|
static const char stty_tabs [] = "tabs";
|
2001-02-14 18:47:33 +00:00
|
|
|
static const char stty_lcase[] = "lcase";
|
|
|
|
static const char stty_LCASE[] = "LCASE";
|
2001-03-02 20:00:54 +00:00
|
|
|
static const char stty_crt [] = "crt";
|
|
|
|
static const char stty_dec [] = "dec";
|
2001-02-14 18:47:33 +00:00
|
|
|
|
2006-09-19 15:12:12 +00:00
|
|
|
/* Flags for 'struct mode_info' */
|
|
|
|
#define SANE_SET 1 /* Set in 'sane' mode */
|
|
|
|
#define SANE_UNSET 2 /* Unset in 'sane' mode */
|
|
|
|
#define REV 4 /* Can be turned off by prepending '-' */
|
2006-09-19 14:17:10 +00:00
|
|
|
#define OMIT 8 /* Don't display value */
|
2001-02-14 18:47:33 +00:00
|
|
|
|
2006-09-19 14:17:10 +00:00
|
|
|
/* Each mode */
|
2001-02-14 18:47:33 +00:00
|
|
|
struct mode_info {
|
2006-09-19 14:17:10 +00:00
|
|
|
const char *name; /* Name given on command line */
|
|
|
|
char type; /* Which structure element to change */
|
|
|
|
char flags; /* Setting and display options */
|
2006-09-19 15:12:12 +00:00
|
|
|
unsigned short mask; /* Other bits to turn off for this mode */
|
2006-09-19 14:17:10 +00:00
|
|
|
unsigned long bits; /* Bits to set for this mode */
|
2001-02-14 18:47:33 +00:00
|
|
|
};
|
|
|
|
|
2003-03-19 09:13:01 +00:00
|
|
|
#define MI_ENTRY(N,T,F,B,M) { N, T, F, M, B }
|
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
static const struct mode_info mode_info[] = {
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("parenb", control, REV, PARENB, 0 ),
|
|
|
|
MI_ENTRY("parodd", control, REV, PARODD, 0 ),
|
|
|
|
MI_ENTRY("cs5", control, 0, CS5, CSIZE),
|
|
|
|
MI_ENTRY("cs6", control, 0, CS6, CSIZE),
|
|
|
|
MI_ENTRY("cs7", control, 0, CS7, CSIZE),
|
|
|
|
MI_ENTRY("cs8", control, 0, CS8, CSIZE),
|
|
|
|
MI_ENTRY("hupcl", control, REV, HUPCL, 0 ),
|
|
|
|
MI_ENTRY("hup", control, REV | OMIT, HUPCL, 0 ),
|
|
|
|
MI_ENTRY("cstopb", control, REV, CSTOPB, 0 ),
|
|
|
|
MI_ENTRY("cread", control, SANE_SET | REV, CREAD, 0 ),
|
|
|
|
MI_ENTRY("clocal", control, REV, CLOCAL, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#ifdef CRTSCTS
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("crtscts", control, REV, CRTSCTS, 0 ),
|
|
|
|
#endif
|
|
|
|
MI_ENTRY("ignbrk", input, SANE_UNSET | REV, IGNBRK, 0 ),
|
|
|
|
MI_ENTRY("brkint", input, SANE_SET | REV, BRKINT, 0 ),
|
|
|
|
MI_ENTRY("ignpar", input, REV, IGNPAR, 0 ),
|
|
|
|
MI_ENTRY("parmrk", input, REV, PARMRK, 0 ),
|
|
|
|
MI_ENTRY("inpck", input, REV, INPCK, 0 ),
|
|
|
|
MI_ENTRY("istrip", input, REV, ISTRIP, 0 ),
|
|
|
|
MI_ENTRY("inlcr", input, SANE_UNSET | REV, INLCR, 0 ),
|
|
|
|
MI_ENTRY("igncr", input, SANE_UNSET | REV, IGNCR, 0 ),
|
|
|
|
MI_ENTRY("icrnl", input, SANE_SET | REV, ICRNL, 0 ),
|
|
|
|
MI_ENTRY("ixon", input, REV, IXON, 0 ),
|
|
|
|
MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 ),
|
|
|
|
MI_ENTRY("tandem", input, REV | OMIT, IXOFF, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#ifdef IUCLC
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef IXANY
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("ixany", input, SANE_UNSET | REV, IXANY, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef IMAXBEL
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("imaxbel", input, SANE_SET | REV, IMAXBEL, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("opost", output, SANE_SET | REV, OPOST, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#ifdef OLCUC
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("olcuc", output, SANE_UNSET | REV, OLCUC, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OCRNL
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("ocrnl", output, SANE_UNSET | REV, OCRNL, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ONLCR
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("onlcr", output, SANE_SET | REV, ONLCR, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ONOCR
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("onocr", output, SANE_UNSET | REV, ONOCR, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ONLRET
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("onlret", output, SANE_UNSET | REV, ONLRET, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OFILL
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("ofill", output, SANE_UNSET | REV, OFILL, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OFDEL
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("ofdel", output, SANE_UNSET | REV, OFDEL, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef NLDLY
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("nl1", output, SANE_UNSET, NL1, NLDLY),
|
|
|
|
MI_ENTRY("nl0", output, SANE_SET, NL0, NLDLY),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CRDLY
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("cr3", output, SANE_UNSET, CR3, CRDLY),
|
|
|
|
MI_ENTRY("cr2", output, SANE_UNSET, CR2, CRDLY),
|
|
|
|
MI_ENTRY("cr1", output, SANE_UNSET, CR1, CRDLY),
|
|
|
|
MI_ENTRY("cr0", output, SANE_SET, CR0, CRDLY),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
2001-03-02 20:00:54 +00:00
|
|
|
|
2001-02-14 18:47:33 +00:00
|
|
|
#ifdef TABDLY
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("tab3", output, SANE_UNSET, TAB3, TABDLY),
|
|
|
|
MI_ENTRY("tab2", output, SANE_UNSET, TAB2, TABDLY),
|
|
|
|
MI_ENTRY("tab1", output, SANE_UNSET, TAB1, TABDLY),
|
|
|
|
MI_ENTRY("tab0", output, SANE_SET, TAB0, TABDLY),
|
2001-02-14 18:47:33 +00:00
|
|
|
#else
|
|
|
|
# ifdef OXTABS
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("tab3", output, SANE_UNSET, OXTABS, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
# endif
|
|
|
|
#endif
|
2001-03-02 20:00:54 +00:00
|
|
|
|
2001-02-14 18:47:33 +00:00
|
|
|
#ifdef BSDLY
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("bs1", output, SANE_UNSET, BS1, BSDLY),
|
|
|
|
MI_ENTRY("bs0", output, SANE_SET, BS0, BSDLY),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VTDLY
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("vt1", output, SANE_UNSET, VT1, VTDLY),
|
|
|
|
MI_ENTRY("vt0", output, SANE_SET, VT0, VTDLY),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef FFDLY
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("ff1", output, SANE_UNSET, FF1, FFDLY),
|
|
|
|
MI_ENTRY("ff0", output, SANE_SET, FF0, FFDLY),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("isig", local, SANE_SET | REV, ISIG, 0 ),
|
|
|
|
MI_ENTRY("icanon", local, SANE_SET | REV, ICANON, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#ifdef IEXTEN
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 ),
|
|
|
|
#endif
|
|
|
|
MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ),
|
|
|
|
MI_ENTRY("echoe", local, SANE_SET | REV, ECHOE, 0 ),
|
|
|
|
MI_ENTRY("crterase", local, REV | OMIT, ECHOE, 0 ),
|
|
|
|
MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ),
|
|
|
|
MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 ),
|
|
|
|
MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#ifdef XCASE
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("xcase", local, SANE_UNSET | REV, XCASE, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef TOSTOP
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("tostop", local, SANE_UNSET | REV, TOSTOP, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ECHOPRT
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 ),
|
|
|
|
MI_ENTRY("prterase", local, REV | OMIT, ECHOPRT, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ECHOCTL
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 ),
|
|
|
|
MI_ENTRY("ctlecho", local, REV | OMIT, ECHOCTL, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ECHOKE
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 ),
|
|
|
|
MI_ENTRY("crtkill", local, REV | OMIT, ECHOKE, 0 ),
|
|
|
|
#endif
|
|
|
|
MI_ENTRY(evenp, combination, REV | OMIT, 0, 0 ),
|
|
|
|
MI_ENTRY(parity, combination, REV | OMIT, 0, 0 ),
|
|
|
|
MI_ENTRY(stty_oddp, combination, REV | OMIT, 0, 0 ),
|
|
|
|
MI_ENTRY(stty_nl, combination, REV | OMIT, 0, 0 ),
|
|
|
|
MI_ENTRY(stty_ek, combination, OMIT, 0, 0 ),
|
|
|
|
MI_ENTRY(stty_sane, combination, OMIT, 0, 0 ),
|
|
|
|
MI_ENTRY(cooked, combination, REV | OMIT, 0, 0 ),
|
|
|
|
MI_ENTRY(raw, combination, REV | OMIT, 0, 0 ),
|
|
|
|
MI_ENTRY(stty_pass8, combination, REV | OMIT, 0, 0 ),
|
|
|
|
MI_ENTRY(litout, combination, REV | OMIT, 0, 0 ),
|
|
|
|
MI_ENTRY(cbreak, combination, REV | OMIT, 0, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#ifdef IXANY
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY(decctlq, combination, REV | OMIT, 0, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
2006-09-19 14:17:10 +00:00
|
|
|
#if defined(TABDLY) || defined(OXTABS)
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY(stty_tabs, combination, REV | OMIT, 0, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#if defined(XCASE) && defined(IUCLC) && defined(OLCUC)
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY(stty_lcase, combination, REV | OMIT, 0, 0 ),
|
|
|
|
MI_ENTRY(stty_LCASE, combination, REV | OMIT, 0, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
2003-03-19 09:13:01 +00:00
|
|
|
MI_ENTRY(stty_crt, combination, OMIT, 0, 0 ),
|
|
|
|
MI_ENTRY(stty_dec, combination, OMIT, 0, 0 ),
|
2001-02-14 18:47:33 +00:00
|
|
|
};
|
|
|
|
|
2006-03-10 19:22:06 +00:00
|
|
|
enum {
|
2006-09-19 14:17:10 +00:00
|
|
|
NUM_mode_info = (sizeof(mode_info) / sizeof(mode_info[0]))
|
2006-03-10 19:22:06 +00:00
|
|
|
};
|
2001-02-14 18:47:33 +00:00
|
|
|
|
2006-09-19 14:17:10 +00:00
|
|
|
/* Control character settings */
|
2001-02-14 18:47:33 +00:00
|
|
|
struct control_info {
|
2006-09-19 14:17:10 +00:00
|
|
|
const char *name; /* Name given on command line */
|
2006-09-19 15:12:12 +00:00
|
|
|
unsigned char saneval; /* Value to set for 'stty sane' */
|
2006-09-19 14:17:10 +00:00
|
|
|
unsigned char offset; /* Offset in c_cc */
|
2001-02-14 18:47:33 +00:00
|
|
|
};
|
|
|
|
|
2006-09-19 14:17:10 +00:00
|
|
|
/* Control characters */
|
2001-02-14 18:47:33 +00:00
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
static const struct control_info control_info[] = {
|
2001-03-02 20:00:54 +00:00
|
|
|
{"intr", CINTR, VINTR},
|
|
|
|
{"quit", CQUIT, VQUIT},
|
|
|
|
{"erase", CERASE, VERASE},
|
|
|
|
{"kill", CKILL, VKILL},
|
|
|
|
{stty_eof, CEOF, VEOF},
|
|
|
|
{stty_eol, CEOL, VEOL},
|
2001-02-14 18:47:33 +00:00
|
|
|
#ifdef VEOL2
|
2001-03-02 20:00:54 +00:00
|
|
|
{"eol2", CEOL2, VEOL2},
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VSWTCH
|
2001-03-02 20:00:54 +00:00
|
|
|
{stty_swtch, CSWTCH, VSWTCH},
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
2001-03-02 20:00:54 +00:00
|
|
|
{"start", CSTART, VSTART},
|
|
|
|
{"stop", CSTOP, VSTOP},
|
|
|
|
{"susp", CSUSP, VSUSP},
|
2001-02-14 18:47:33 +00:00
|
|
|
#ifdef VDSUSP
|
2001-03-02 20:00:54 +00:00
|
|
|
{"dsusp", CDSUSP, VDSUSP},
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VREPRINT
|
2001-03-02 20:00:54 +00:00
|
|
|
{"rprnt", CRPRNT, VREPRINT},
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VWERASE
|
2001-03-02 20:00:54 +00:00
|
|
|
{"werase", CWERASE, VWERASE},
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VLNEXT
|
2001-03-02 20:00:54 +00:00
|
|
|
{"lnext", CLNEXT, VLNEXT},
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VFLUSHO
|
2001-03-02 20:00:54 +00:00
|
|
|
{"flush", CFLUSHO, VFLUSHO},
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VSTATUS
|
2001-03-02 20:00:54 +00:00
|
|
|
{"status", CSTATUS, VSTATUS},
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
2006-09-19 14:17:10 +00:00
|
|
|
/* These must be last because of the display routines */
|
2001-03-02 20:00:54 +00:00
|
|
|
{stty_min, 1, VMIN},
|
|
|
|
{stty_time, 0, VTIME},
|
2001-02-14 18:47:33 +00:00
|
|
|
};
|
|
|
|
|
2006-03-10 19:22:06 +00:00
|
|
|
enum {
|
2006-09-19 14:17:10 +00:00
|
|
|
NUM_control_info = (sizeof(control_info) / sizeof(control_info[0]))
|
2006-03-10 19:22:06 +00:00
|
|
|
};
|
2001-02-14 18:47:33 +00:00
|
|
|
|
2006-09-19 14:17:10 +00:00
|
|
|
/* The width of the screen, for output wrapping */
|
2006-10-08 12:49:22 +00:00
|
|
|
static unsigned max_col = 80; /* default */
|
2006-09-19 14:17:10 +00:00
|
|
|
/* Current position, to know when to wrap */
|
2006-10-08 12:49:22 +00:00
|
|
|
static unsigned current_col;
|
2006-09-19 14:31:44 +00:00
|
|
|
static const char *device_name = bb_msg_standard_input;
|
2001-02-14 18:47:33 +00:00
|
|
|
|
2006-09-19 14:31:44 +00:00
|
|
|
/* Return a string that is the printable representation of character CH */
|
2006-09-19 15:12:12 +00:00
|
|
|
/* Adapted from 'cat' by Torbjorn Granlund */
|
2006-09-19 14:31:44 +00:00
|
|
|
static const char *visible(unsigned int ch)
|
|
|
|
{
|
|
|
|
static char buf[10];
|
|
|
|
char *bpout = buf;
|
2003-06-20 09:01:58 +00:00
|
|
|
|
2006-09-19 14:31:44 +00:00
|
|
|
if (ch == _POSIX_VDISABLE)
|
|
|
|
return "<undef>";
|
|
|
|
|
|
|
|
if (ch >= 128) {
|
|
|
|
ch -= 128;
|
|
|
|
*bpout++ = 'M';
|
|
|
|
*bpout++ = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch < 32) {
|
|
|
|
*bpout++ = '^';
|
|
|
|
*bpout++ = ch + 64;
|
|
|
|
} else if (ch < 127) {
|
|
|
|
*bpout++ = ch;
|
|
|
|
} else {
|
|
|
|
*bpout++ = '^';
|
|
|
|
*bpout++ = '?';
|
|
|
|
}
|
|
|
|
|
|
|
|
*bpout = '\0';
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static tcflag_t *mode_type_flag(unsigned type, const struct termios *mode)
|
|
|
|
{
|
|
|
|
static const unsigned char tcflag_offsets[] = {
|
|
|
|
offsetof(struct termios, c_cflag), /* control */
|
|
|
|
offsetof(struct termios, c_iflag), /* input */
|
|
|
|
offsetof(struct termios, c_oflag), /* output */
|
|
|
|
offsetof(struct termios, c_lflag), /* local */
|
|
|
|
};
|
|
|
|
|
|
|
|
if (type <= local) {
|
|
|
|
return (tcflag_t*) (((char*)mode) + tcflag_offsets[type]);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static speed_t string_to_baud_or_die(const char *arg)
|
|
|
|
{
|
2006-10-08 12:49:22 +00:00
|
|
|
return tty_value_to_baud(xatou(arg));
|
2006-09-19 14:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_speed_or_die(enum speed_setting type, const char *arg,
|
|
|
|
struct termios *mode)
|
|
|
|
{
|
|
|
|
speed_t baud;
|
|
|
|
|
|
|
|
baud = string_to_baud_or_die(arg);
|
|
|
|
|
|
|
|
if (type != output_speed) { /* either input or both */
|
|
|
|
cfsetispeed(mode, baud);
|
|
|
|
}
|
|
|
|
if (type != input_speed) { /* either output or both */
|
|
|
|
cfsetospeed(mode, baud);
|
|
|
|
}
|
|
|
|
}
|
2003-06-20 09:01:58 +00:00
|
|
|
|
2006-09-19 14:24:23 +00:00
|
|
|
static ATTRIBUTE_NORETURN void perror_on_device_and_die(const char *fmt)
|
2003-06-20 09:01:58 +00:00
|
|
|
{
|
|
|
|
bb_perror_msg_and_die(fmt, device_name);
|
|
|
|
}
|
|
|
|
|
2006-09-19 14:24:23 +00:00
|
|
|
static void perror_on_device(const char *fmt)
|
|
|
|
{
|
|
|
|
bb_perror_msg(fmt, device_name);
|
|
|
|
}
|
|
|
|
|
2006-09-19 14:19:42 +00:00
|
|
|
/* No, inline won't be as efficient (gcc 3.4.3) */
|
|
|
|
#define streq(a,b) (!strcmp((a),(b)))
|
2001-02-14 18:47:33 +00:00
|
|
|
|
|
|
|
/* Print format string MESSAGE and optional args.
|
|
|
|
Wrap to next line first if it won't fit.
|
2006-09-19 14:17:10 +00:00
|
|
|
Print a space first unless MESSAGE will start a new line */
|
2001-02-14 18:47:33 +00:00
|
|
|
static void wrapf(const char *message, ...)
|
|
|
|
{
|
2006-09-19 14:19:42 +00:00
|
|
|
char buf[128];
|
2001-02-14 18:47:33 +00:00
|
|
|
va_list args;
|
|
|
|
int buflen;
|
|
|
|
|
|
|
|
va_start(args, message);
|
2006-09-19 14:19:42 +00:00
|
|
|
vsnprintf(buf, sizeof(buf), message, args);
|
2001-02-14 18:47:33 +00:00
|
|
|
va_end(args);
|
|
|
|
buflen = strlen(buf);
|
2006-09-19 14:19:42 +00:00
|
|
|
if (!buflen) return;
|
|
|
|
|
2001-02-14 18:47:33 +00:00
|
|
|
if (current_col > 0) {
|
|
|
|
current_col++;
|
2006-09-19 15:12:12 +00:00
|
|
|
if (buf[0] != '\n') {
|
|
|
|
if (current_col + buflen >= max_col) {
|
|
|
|
putchar('\n');
|
|
|
|
current_col = 0;
|
|
|
|
} else
|
|
|
|
putchar(' ');
|
|
|
|
}
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
|
|
|
fputs(buf, stdout);
|
|
|
|
current_col += buflen;
|
2006-09-19 14:19:42 +00:00
|
|
|
if (buf[buflen-1] == '\n')
|
|
|
|
current_col = 0;
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 14:31:44 +00:00
|
|
|
#ifdef TIOCGWINSZ
|
|
|
|
|
2006-09-19 15:12:12 +00:00
|
|
|
static int get_win_size(int fd, struct winsize *win)
|
2006-09-19 14:31:44 +00:00
|
|
|
{
|
2006-09-19 15:12:12 +00:00
|
|
|
return ioctl(fd, TIOCGWINSZ, (char *) win);
|
2006-09-19 14:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_window_size(int rows, int cols)
|
|
|
|
{
|
|
|
|
struct winsize win;
|
|
|
|
|
2006-09-19 15:12:12 +00:00
|
|
|
if (get_win_size(STDIN_FILENO, &win)) {
|
2006-09-19 14:31:44 +00:00
|
|
|
if (errno != EINVAL) {
|
|
|
|
perror_on_device("%s");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memset(&win, 0, sizeof(win));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rows >= 0)
|
|
|
|
win.ws_row = rows;
|
|
|
|
if (cols >= 0)
|
|
|
|
win.ws_col = cols;
|
|
|
|
|
|
|
|
# ifdef TIOCSSIZE
|
|
|
|
/* Alexander Dupuy <dupuy@cs.columbia.edu> wrote:
|
|
|
|
The following code deals with a bug in the SunOS 4.x (and 3.x?) kernel.
|
|
|
|
This comment from sys/ttold.h describes Sun's twisted logic - a better
|
|
|
|
test would have been (ts_lines > 64k || ts_cols > 64k || ts_cols == 0).
|
|
|
|
At any rate, the problem is gone in Solaris 2.x */
|
|
|
|
|
|
|
|
if (win.ws_row == 0 || win.ws_col == 0) {
|
|
|
|
struct ttysize ttysz;
|
|
|
|
|
|
|
|
ttysz.ts_lines = win.ws_row;
|
|
|
|
ttysz.ts_cols = win.ws_col;
|
|
|
|
|
|
|
|
win.ws_row = win.ws_col = 1;
|
|
|
|
|
|
|
|
if ((ioctl(STDIN_FILENO, TIOCSWINSZ, (char *) &win) != 0)
|
|
|
|
|| (ioctl(STDIN_FILENO, TIOCSSIZE, (char *) &ttysz) != 0)) {
|
|
|
|
perror_on_device("%s");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
if (ioctl(STDIN_FILENO, TIOCSWINSZ, (char *) &win))
|
|
|
|
perror_on_device("%s");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void display_window_size(int fancy)
|
|
|
|
{
|
|
|
|
const char *fmt_str = "%s\0%s: no size information for this device";
|
|
|
|
struct winsize win;
|
|
|
|
|
2006-09-19 15:12:12 +00:00
|
|
|
if (get_win_size(STDIN_FILENO, &win)) {
|
2006-09-19 14:31:44 +00:00
|
|
|
if ((errno != EINVAL) || ((fmt_str += 2), !fancy)) {
|
|
|
|
perror_on_device(fmt_str);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
wrapf(fancy ? "rows %d; columns %d;" : "%d %d\n",
|
|
|
|
win.ws_row, win.ws_col);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* !TIOCGWINSZ */
|
|
|
|
|
|
|
|
static inline void display_window_size(int fancy) {}
|
|
|
|
|
|
|
|
#endif /* !TIOCGWINSZ */
|
|
|
|
|
2006-10-08 12:49:22 +00:00
|
|
|
static int screen_columns_or_die(void)
|
2006-09-19 14:31:44 +00:00
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
#ifdef TIOCGWINSZ
|
|
|
|
struct winsize win;
|
|
|
|
|
|
|
|
/* 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 */
|
2006-09-19 15:12:12 +00:00
|
|
|
if (get_win_size(STDOUT_FILENO, &win) == 0 && win.ws_col > 0)
|
2006-09-19 14:31:44 +00:00
|
|
|
return win.ws_col;
|
|
|
|
#endif
|
|
|
|
|
2006-10-08 12:49:22 +00:00
|
|
|
s = getenv("COLUMNS");
|
|
|
|
if (s)
|
|
|
|
return xatoi_u(s);
|
|
|
|
return 80;
|
2006-09-19 14:31:44 +00:00
|
|
|
}
|
|
|
|
|
2001-02-14 18:47:33 +00:00
|
|
|
static const struct suffix_mult stty_suffixes[] = {
|
2001-03-02 20:00:54 +00:00
|
|
|
{"b", 512 },
|
|
|
|
{"k", 1024},
|
|
|
|
{"B", 1024},
|
|
|
|
{NULL, 0 }
|
2001-02-14 18:47:33 +00:00
|
|
|
};
|
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
static const struct mode_info *find_mode(const char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < NUM_mode_info; ++i)
|
2006-09-19 14:17:10 +00:00
|
|
|
if (streq(name, mode_info[i].name))
|
2006-09-19 14:16:28 +00:00
|
|
|
return &mode_info[i];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct control_info *find_control(const char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < NUM_control_info; ++i)
|
2006-09-19 14:17:10 +00:00
|
|
|
if (streq(name, control_info[i].name))
|
2006-09-19 14:16:28 +00:00
|
|
|
return &control_info[i];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
|
|
|
param_need_arg = 0x80,
|
|
|
|
param_line = 1 | 0x80,
|
|
|
|
param_rows = 2 | 0x80,
|
|
|
|
param_cols = 3 | 0x80,
|
|
|
|
param_size = 4,
|
2006-09-19 14:31:44 +00:00
|
|
|
param_speed = 5,
|
|
|
|
param_ispeed = 6 | 0x80,
|
|
|
|
param_ospeed = 7 | 0x80,
|
2006-09-19 14:16:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int find_param(const char *name)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_C_LINE
|
2006-09-19 14:17:10 +00:00
|
|
|
if (streq(name, "line")) return param_line;
|
2006-09-19 14:16:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef TIOCGWINSZ
|
2006-09-19 14:17:10 +00:00
|
|
|
if (streq(name, "rows")) return param_rows;
|
|
|
|
if (streq(name, "cols")) return param_cols;
|
|
|
|
if (streq(name, "columns")) return param_cols;
|
|
|
|
if (streq(name, "size")) return param_size;
|
|
|
|
#endif
|
2006-09-19 14:31:44 +00:00
|
|
|
if (streq(name, "speed")) return param_speed;
|
2006-09-19 14:17:10 +00:00
|
|
|
if (streq(name, "ispeed")) return param_ispeed;
|
|
|
|
if (streq(name, "ospeed")) return param_ospeed;
|
2006-09-19 14:16:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-19 14:31:44 +00:00
|
|
|
static int recover_mode(const char *arg, struct termios *mode);
|
|
|
|
static void set_mode(const struct mode_info *info,
|
|
|
|
int reversed, struct termios *mode);
|
|
|
|
static void display_all(const struct termios *mode);
|
|
|
|
static void display_changed(const struct termios *mode);
|
|
|
|
static void display_recoverable(const struct termios *mode);
|
|
|
|
static void display_speed(const struct termios *mode, int fancy);
|
|
|
|
static void sane_mode(struct termios *mode);
|
|
|
|
static void set_control_char_or_die(const struct control_info *info,
|
|
|
|
const char *arg, struct termios *mode);
|
|
|
|
|
2006-03-06 20:47:33 +00:00
|
|
|
int stty_main(int argc, char **argv)
|
2001-02-14 18:47:33 +00:00
|
|
|
{
|
|
|
|
struct termios mode;
|
2006-09-19 14:17:10 +00:00
|
|
|
void (*output_func)(const struct termios *);
|
2006-09-19 14:16:28 +00:00
|
|
|
const char *file_name = NULL;
|
|
|
|
int require_set_attr;
|
|
|
|
int speed_was_set;
|
|
|
|
int verbose_output;
|
|
|
|
int recoverable_output;
|
|
|
|
int noargs;
|
|
|
|
int k;
|
2001-02-14 18:47:33 +00:00
|
|
|
|
2003-03-19 09:13:01 +00:00
|
|
|
output_func = display_changed;
|
2006-09-19 14:16:28 +00:00
|
|
|
noargs = 1;
|
|
|
|
speed_was_set = 0;
|
|
|
|
require_set_attr = 0;
|
2001-02-14 18:47:33 +00:00
|
|
|
verbose_output = 0;
|
|
|
|
recoverable_output = 0;
|
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
/* First pass: only parse/verify command line params */
|
|
|
|
k = 0;
|
|
|
|
while (argv[++k]) {
|
|
|
|
const struct mode_info *mp;
|
|
|
|
const struct control_info *cp;
|
|
|
|
const char *arg = argv[k];
|
|
|
|
const char *argnext = argv[k+1];
|
|
|
|
int param;
|
|
|
|
|
|
|
|
if (arg[0] == '-') {
|
|
|
|
int i;
|
|
|
|
mp = find_mode(arg+1);
|
|
|
|
if (mp) {
|
|
|
|
if (!(mp->flags & REV))
|
|
|
|
bb_error_msg_and_die("invalid argument '%s'", arg);
|
|
|
|
noargs = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* It is an option - parse it */
|
|
|
|
i = 0;
|
|
|
|
while (arg[++i]) {
|
|
|
|
switch (arg[i]) {
|
|
|
|
case 'a':
|
|
|
|
verbose_output = 1;
|
|
|
|
output_func = display_all;
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
recoverable_output = 1;
|
|
|
|
output_func = display_recoverable;
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
if (file_name)
|
|
|
|
bb_error_msg_and_die("only one device may be specified");
|
|
|
|
file_name = &arg[i+1]; /* "-Fdevice" ? */
|
|
|
|
if (!file_name[0]) { /* nope, "-F device" */
|
|
|
|
int p = k+1; /* argv[p] is argnext */
|
|
|
|
file_name = argnext;
|
|
|
|
if (!file_name)
|
|
|
|
bb_error_msg_and_die(bb_msg_requires_arg, "-F");
|
|
|
|
/* remove -F param from arg[vc] */
|
|
|
|
--argc;
|
2006-09-19 15:12:12 +00:00
|
|
|
while (argv[p]) { argv[p] = argv[p+1]; ++p; }
|
2006-09-19 14:16:28 +00:00
|
|
|
}
|
|
|
|
goto end_option;
|
|
|
|
default:
|
|
|
|
bb_error_msg_and_die("invalid argument '%s'", arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end_option:
|
|
|
|
continue;
|
|
|
|
}
|
2001-02-14 18:47:33 +00:00
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
mp = find_mode(arg);
|
|
|
|
if (mp) {
|
|
|
|
noargs = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2001-02-14 18:47:33 +00:00
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
cp = find_control(arg);
|
|
|
|
if (cp) {
|
|
|
|
if (!argnext)
|
|
|
|
bb_error_msg_and_die(bb_msg_requires_arg, arg);
|
2006-09-19 14:24:23 +00:00
|
|
|
/* called for the side effect of xfunc death only */
|
|
|
|
set_control_char_or_die(cp, argnext, &mode);
|
2001-02-14 18:47:33 +00:00
|
|
|
noargs = 0;
|
2006-09-19 14:16:28 +00:00
|
|
|
++k;
|
|
|
|
continue;
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
param = find_param(arg);
|
|
|
|
if (param & param_need_arg) {
|
|
|
|
if (!argnext)
|
|
|
|
bb_error_msg_and_die(bb_msg_requires_arg, arg);
|
|
|
|
++k;
|
|
|
|
}
|
2001-02-14 18:47:33 +00:00
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
switch (param) {
|
|
|
|
#ifdef HAVE_C_LINE
|
|
|
|
case param_line:
|
2006-09-19 14:19:42 +00:00
|
|
|
# ifndef TIOCGWINSZ
|
2006-10-08 12:49:22 +00:00
|
|
|
xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes);
|
2006-09-19 14:16:28 +00:00
|
|
|
break;
|
2006-09-19 14:19:42 +00:00
|
|
|
# endif /* else fall-through */
|
2006-09-19 14:16:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef TIOCGWINSZ
|
|
|
|
case param_rows:
|
|
|
|
case param_cols:
|
2006-10-08 12:49:22 +00:00
|
|
|
xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes);
|
2006-09-19 14:16:28 +00:00
|
|
|
break;
|
|
|
|
case param_size:
|
|
|
|
#endif
|
2006-09-19 14:31:44 +00:00
|
|
|
case param_speed:
|
|
|
|
break;
|
2006-09-19 14:16:28 +00:00
|
|
|
case param_ispeed:
|
2006-09-19 14:31:44 +00:00
|
|
|
/* called for the side effect of xfunc death only */
|
|
|
|
set_speed_or_die(input_speed, argnext, &mode);
|
|
|
|
break;
|
2006-09-19 14:16:28 +00:00
|
|
|
case param_ospeed:
|
2006-09-19 14:31:44 +00:00
|
|
|
/* called for the side effect of xfunc death only */
|
|
|
|
set_speed_or_die(output_speed, argnext, &mode);
|
2006-09-19 14:16:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (recover_mode(arg, &mode) == 1) break;
|
2006-09-19 14:31:44 +00:00
|
|
|
if (string_to_baud_or_die(arg) != (speed_t) -1) break;
|
2006-09-19 14:16:28 +00:00
|
|
|
bb_error_msg_and_die("invalid argument '%s'", arg);
|
|
|
|
}
|
2001-02-14 18:47:33 +00:00
|
|
|
noargs = 0;
|
2006-09-19 14:16:28 +00:00
|
|
|
}
|
2001-02-14 18:47:33 +00:00
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
/* Specifying both -a and -g is an error */
|
|
|
|
if (verbose_output && recoverable_output)
|
|
|
|
bb_error_msg_and_die("verbose and stty-readable output styles are mutually exclusive");
|
|
|
|
/* Specifying -a or -g with non-options is an error */
|
|
|
|
if (!noargs && (verbose_output || recoverable_output))
|
|
|
|
bb_error_msg_and_die("modes may not be set when specifying an output style");
|
2001-02-14 18:47:33 +00:00
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
/* Now it is safe to start doing things */
|
2001-02-14 18:47:33 +00:00
|
|
|
if (file_name) {
|
2006-09-19 14:16:28 +00:00
|
|
|
int fd, fdflags;
|
2001-02-14 18:47:33 +00:00
|
|
|
device_name = file_name;
|
2006-09-19 14:16:28 +00:00
|
|
|
fd = xopen(device_name, O_RDONLY | O_NONBLOCK);
|
2006-09-19 15:12:12 +00:00
|
|
|
if (fd != STDIN_FILENO) {
|
|
|
|
dup2(fd, STDIN_FILENO);
|
2006-09-19 14:16:28 +00:00
|
|
|
close(fd);
|
|
|
|
}
|
2006-09-08 17:31:55 +00:00
|
|
|
fdflags = fcntl(STDIN_FILENO, F_GETFL);
|
|
|
|
if (fdflags == -1 || fcntl(STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
|
2006-09-29 21:30:43 +00:00
|
|
|
perror_on_device_and_die("%s: cannot reset non-blocking mode");
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize to all zeroes so there is no risk memcmp will report a
|
2006-09-19 14:17:10 +00:00
|
|
|
spurious difference in an uninitialized portion of the structure */
|
2001-02-14 18:47:33 +00:00
|
|
|
memset(&mode, 0, sizeof(mode));
|
2006-01-30 12:23:46 +00:00
|
|
|
if (tcgetattr(STDIN_FILENO, &mode))
|
2006-09-19 14:24:23 +00:00
|
|
|
perror_on_device_and_die("%s");
|
2001-02-14 18:47:33 +00:00
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
if (verbose_output || recoverable_output || noargs) {
|
2006-10-08 12:49:22 +00:00
|
|
|
max_col = screen_columns_or_die();
|
2006-01-30 12:23:46 +00:00
|
|
|
output_func(&mode);
|
2001-02-14 18:47:33 +00:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
/* Second pass: perform actions */
|
2002-06-06 11:35:29 +00:00
|
|
|
k = 0;
|
2006-09-19 14:16:28 +00:00
|
|
|
while (argv[++k]) {
|
|
|
|
const struct mode_info *mp;
|
|
|
|
const struct control_info *cp;
|
|
|
|
const char *arg = argv[k];
|
|
|
|
const char *argnext = argv[k+1];
|
|
|
|
int param;
|
|
|
|
|
|
|
|
if (arg[0] == '-') {
|
|
|
|
mp = find_mode(arg+1);
|
|
|
|
if (mp) {
|
|
|
|
set_mode(mp, 1 /* reversed */, &mode);
|
2002-06-06 11:35:29 +00:00
|
|
|
}
|
2006-09-19 14:16:28 +00:00
|
|
|
/* It is an option - already parsed. Skip it */
|
|
|
|
continue;
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
2001-03-02 20:00:54 +00:00
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
mp = find_mode(arg);
|
|
|
|
if (mp) {
|
|
|
|
set_mode(mp, 0 /* non-reversed */, &mode);
|
|
|
|
continue;
|
|
|
|
}
|
2001-03-02 20:00:54 +00:00
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
cp = find_control(arg);
|
|
|
|
if (cp) {
|
|
|
|
++k;
|
2006-09-19 14:24:23 +00:00
|
|
|
set_control_char_or_die(cp, argnext, &mode);
|
2006-09-19 14:16:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
param = find_param(arg);
|
|
|
|
if (param & param_need_arg) {
|
|
|
|
++k;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (param) {
|
2001-02-14 18:47:33 +00:00
|
|
|
#ifdef HAVE_C_LINE
|
2006-09-19 14:16:28 +00:00
|
|
|
case param_line:
|
2006-10-08 12:49:22 +00:00
|
|
|
mode.c_line = xatoul_sfx(argnext, stty_suffixes);
|
2006-09-19 14:16:28 +00:00
|
|
|
require_set_attr = 1;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef TIOCGWINSZ
|
|
|
|
case param_cols:
|
2006-10-08 12:49:22 +00:00
|
|
|
set_window_size(-1, xatoul_sfx(argnext, stty_suffixes));
|
2006-09-19 14:16:28 +00:00
|
|
|
break;
|
|
|
|
case param_size:
|
|
|
|
display_window_size(0);
|
|
|
|
break;
|
|
|
|
case param_rows:
|
2006-10-08 12:49:22 +00:00
|
|
|
set_window_size(xatoul_sfx(argnext, stty_suffixes), -1);
|
2006-09-19 14:16:28 +00:00
|
|
|
break;
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
2006-09-19 14:31:44 +00:00
|
|
|
case param_speed:
|
|
|
|
display_speed(&mode, 0);
|
|
|
|
break;
|
2006-09-19 14:16:28 +00:00
|
|
|
case param_ispeed:
|
2006-09-19 14:31:44 +00:00
|
|
|
set_speed_or_die(input_speed, argnext, &mode);
|
2006-09-19 14:16:28 +00:00
|
|
|
speed_was_set = 1;
|
|
|
|
require_set_attr = 1;
|
|
|
|
break;
|
|
|
|
case param_ospeed:
|
2006-09-19 14:31:44 +00:00
|
|
|
set_speed_or_die(output_speed, argnext, &mode);
|
2006-09-19 14:16:28 +00:00
|
|
|
speed_was_set = 1;
|
|
|
|
require_set_attr = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (recover_mode(arg, &mode) == 1)
|
2001-03-02 20:00:54 +00:00
|
|
|
require_set_attr = 1;
|
2006-09-19 14:31:44 +00:00
|
|
|
else /* true: if (string_to_baud_or_die(arg) != (speed_t) -1) */ {
|
|
|
|
set_speed_or_die(both_speeds, arg, &mode);
|
2001-02-14 18:47:33 +00:00
|
|
|
speed_was_set = 1;
|
|
|
|
require_set_attr = 1;
|
2006-09-19 14:16:28 +00:00
|
|
|
} /* else - impossible (caught in the first pass):
|
|
|
|
bb_error_msg_and_die("invalid argument '%s'", arg); */
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (require_set_attr) {
|
|
|
|
struct termios new_mode;
|
|
|
|
|
2006-01-30 12:23:46 +00:00
|
|
|
if (tcsetattr(STDIN_FILENO, TCSADRAIN, &mode))
|
2006-09-19 14:24:23 +00:00
|
|
|
perror_on_device_and_die("%s");
|
2001-02-14 18:47:33 +00:00
|
|
|
|
|
|
|
/* POSIX (according to Zlotnick's book) tcsetattr returns zero if
|
|
|
|
it performs *any* of the requested operations. This means it
|
2006-09-19 15:12:12 +00:00
|
|
|
can report 'success' when it has actually failed to perform
|
2001-02-14 18:47:33 +00:00
|
|
|
some proper subset of the requested operations. To detect
|
|
|
|
this partial failure, get the current terminal attributes and
|
2006-09-19 14:17:10 +00:00
|
|
|
compare them to the requested ones */
|
2001-02-14 18:47:33 +00:00
|
|
|
|
|
|
|
/* Initialize to all zeroes so there is no risk memcmp will report a
|
2006-09-19 14:17:10 +00:00
|
|
|
spurious difference in an uninitialized portion of the structure */
|
2001-02-14 18:47:33 +00:00
|
|
|
memset(&new_mode, 0, sizeof(new_mode));
|
2006-01-30 12:23:46 +00:00
|
|
|
if (tcgetattr(STDIN_FILENO, &new_mode))
|
2006-09-19 14:24:23 +00:00
|
|
|
perror_on_device_and_die("%s");
|
2001-02-14 18:47:33 +00:00
|
|
|
|
|
|
|
if (memcmp(&mode, &new_mode, sizeof(mode)) != 0) {
|
|
|
|
#ifdef CIBAUD
|
|
|
|
/* SunOS 4.1.3 (at least) has the problem that after this sequence,
|
|
|
|
tcgetattr (&m1); tcsetattr (&m1); tcgetattr (&m2);
|
|
|
|
sometimes (m1 != m2). The only difference is in the four bits
|
|
|
|
of the c_cflag field corresponding to the baud rate. To save
|
|
|
|
Sun users a little confusion, don't report an error if this
|
|
|
|
happens. But suppress the error only if we haven't tried to
|
|
|
|
set the baud rate explicitly -- otherwise we'd never give an
|
2006-09-19 14:17:10 +00:00
|
|
|
error for a true failure to set the baud rate */
|
2001-02-14 18:47:33 +00:00
|
|
|
|
|
|
|
new_mode.c_cflag &= (~CIBAUD);
|
|
|
|
if (speed_was_set || memcmp(&mode, &new_mode, sizeof(mode)) != 0)
|
|
|
|
#endif
|
2006-11-18 22:04:09 +00:00
|
|
|
perror_on_device_and_die("%s: cannot perform all requested operations");
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-09-19 14:20:22 +00:00
|
|
|
/* Save set_mode from #ifdef forest plague */
|
|
|
|
#ifndef ONLCR
|
|
|
|
#define ONLCR 0
|
|
|
|
#endif
|
|
|
|
#ifndef OCRNL
|
|
|
|
#define OCRNL 0
|
|
|
|
#endif
|
|
|
|
#ifndef ONLRET
|
|
|
|
#define ONLRET 0
|
|
|
|
#endif
|
|
|
|
#ifndef XCASE
|
|
|
|
#define XCASE 0
|
|
|
|
#endif
|
|
|
|
#ifndef IXANY
|
|
|
|
#define IXANY 0
|
|
|
|
#endif
|
|
|
|
#ifndef TABDLY
|
|
|
|
#define TABDLY 0
|
|
|
|
#endif
|
|
|
|
#ifndef OXTABS
|
|
|
|
#define OXTABS 0
|
|
|
|
#endif
|
|
|
|
#ifndef IUCLC
|
|
|
|
#define IUCLC 0
|
|
|
|
#endif
|
|
|
|
#ifndef OLCUC
|
|
|
|
#define OLCUC 0
|
|
|
|
#endif
|
|
|
|
#ifndef ECHOCTL
|
|
|
|
#define ECHOCTL 0
|
|
|
|
#endif
|
|
|
|
#ifndef ECHOKE
|
|
|
|
#define ECHOKE 0
|
|
|
|
#endif
|
2001-02-14 18:47:33 +00:00
|
|
|
|
2006-09-19 14:31:44 +00:00
|
|
|
static void set_mode(const struct mode_info *info, int reversed,
|
|
|
|
struct termios *mode)
|
2001-02-14 18:47:33 +00:00
|
|
|
{
|
|
|
|
tcflag_t *bitsp;
|
|
|
|
|
2006-09-19 14:24:23 +00:00
|
|
|
bitsp = mode_type_flag(info->type, mode);
|
|
|
|
|
|
|
|
if (bitsp) {
|
|
|
|
if (reversed)
|
|
|
|
*bitsp = *bitsp & ~((unsigned long)info->mask) & ~info->bits;
|
|
|
|
else
|
|
|
|
*bitsp = (*bitsp & ~((unsigned long)info->mask)) | info->bits;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Combination mode */
|
|
|
|
if (info->name == evenp || info->name == parity) {
|
|
|
|
if (reversed)
|
|
|
|
mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;
|
|
|
|
else
|
|
|
|
mode->c_cflag = (mode->c_cflag & ~PARODD & ~CSIZE) | PARENB | CS7;
|
|
|
|
} else if (info->name == stty_oddp) {
|
|
|
|
if (reversed)
|
|
|
|
mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;
|
|
|
|
else
|
|
|
|
mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARODD | PARENB;
|
|
|
|
} else if (info->name == stty_nl) {
|
|
|
|
if (reversed) {
|
|
|
|
mode->c_iflag = (mode->c_iflag | ICRNL) & ~INLCR & ~IGNCR;
|
|
|
|
mode->c_oflag = (mode->c_oflag | ONLCR) & ~OCRNL & ~ONLRET;
|
|
|
|
} else {
|
|
|
|
mode->c_iflag = mode->c_iflag & ~ICRNL;
|
|
|
|
if (ONLCR) mode->c_oflag = mode->c_oflag & ~ONLCR;
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
2006-09-19 14:24:23 +00:00
|
|
|
} else if (info->name == stty_ek) {
|
|
|
|
mode->c_cc[VERASE] = CERASE;
|
|
|
|
mode->c_cc[VKILL] = CKILL;
|
|
|
|
} else if (info->name == stty_sane) {
|
|
|
|
sane_mode(mode);
|
|
|
|
}
|
|
|
|
else if (info->name == cbreak) {
|
|
|
|
if (reversed)
|
|
|
|
mode->c_lflag |= ICANON;
|
|
|
|
else
|
|
|
|
mode->c_lflag &= ~ICANON;
|
|
|
|
} else if (info->name == stty_pass8) {
|
|
|
|
if (reversed) {
|
|
|
|
mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARENB;
|
|
|
|
mode->c_iflag |= ISTRIP;
|
|
|
|
} else {
|
|
|
|
mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;
|
|
|
|
mode->c_iflag &= ~ISTRIP;
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
2006-09-19 14:24:23 +00:00
|
|
|
} else if (info->name == litout) {
|
|
|
|
if (reversed) {
|
|
|
|
mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARENB;
|
|
|
|
mode->c_iflag |= ISTRIP;
|
|
|
|
mode->c_oflag |= OPOST;
|
|
|
|
} else {
|
|
|
|
mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;
|
|
|
|
mode->c_iflag &= ~ISTRIP;
|
|
|
|
mode->c_oflag &= ~OPOST;
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
2006-09-19 14:24:23 +00:00
|
|
|
} else if (info->name == raw || info->name == cooked) {
|
|
|
|
if ((info->name[0] == 'r' && reversed)
|
|
|
|
|| (info->name[0] == 'c' && !reversed)) {
|
|
|
|
/* Cooked mode */
|
|
|
|
mode->c_iflag |= BRKINT | IGNPAR | ISTRIP | ICRNL | IXON;
|
|
|
|
mode->c_oflag |= OPOST;
|
|
|
|
mode->c_lflag |= ISIG | ICANON;
|
|
|
|
#if VMIN == VEOF
|
|
|
|
mode->c_cc[VEOF] = CEOF;
|
|
|
|
#endif
|
|
|
|
#if VTIME == VEOL
|
|
|
|
mode->c_cc[VEOL] = CEOL;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
/* Raw mode */
|
|
|
|
mode->c_iflag = 0;
|
|
|
|
mode->c_oflag &= ~OPOST;
|
|
|
|
mode->c_lflag &= ~(ISIG | ICANON | XCASE);
|
|
|
|
mode->c_cc[VMIN] = 1;
|
|
|
|
mode->c_cc[VTIME] = 0;
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
2006-09-19 14:24:23 +00:00
|
|
|
}
|
|
|
|
else if (IXANY && info->name == decctlq) {
|
|
|
|
if (reversed)
|
|
|
|
mode->c_iflag |= IXANY;
|
|
|
|
else
|
|
|
|
mode->c_iflag &= ~IXANY;
|
|
|
|
}
|
|
|
|
else if (TABDLY && info->name == stty_tabs) {
|
|
|
|
if (reversed)
|
|
|
|
mode->c_oflag = (mode->c_oflag & ~TABDLY) | TAB3;
|
|
|
|
else
|
|
|
|
mode->c_oflag = (mode->c_oflag & ~TABDLY) | TAB0;
|
|
|
|
}
|
|
|
|
else if (OXTABS && info->name == stty_tabs) {
|
|
|
|
if (reversed)
|
|
|
|
mode->c_oflag |= OXTABS;
|
|
|
|
else
|
|
|
|
mode->c_oflag &= ~OXTABS;
|
|
|
|
}
|
|
|
|
else if (XCASE && IUCLC && OLCUC
|
|
|
|
&& (info->name == stty_lcase || info->name == stty_LCASE)) {
|
|
|
|
if (reversed) {
|
|
|
|
mode->c_lflag &= ~XCASE;
|
|
|
|
mode->c_iflag &= ~IUCLC;
|
|
|
|
mode->c_oflag &= ~OLCUC;
|
|
|
|
} else {
|
|
|
|
mode->c_lflag |= XCASE;
|
|
|
|
mode->c_iflag |= IUCLC;
|
|
|
|
mode->c_oflag |= OLCUC;
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
2006-09-19 14:24:23 +00:00
|
|
|
}
|
|
|
|
else if (info->name == stty_crt) {
|
|
|
|
mode->c_lflag |= ECHOE | ECHOCTL | ECHOKE;
|
|
|
|
}
|
|
|
|
else if (info->name == stty_dec) {
|
|
|
|
mode->c_cc[VINTR] = 3; /* ^C */
|
|
|
|
mode->c_cc[VERASE] = 127; /* DEL */
|
|
|
|
mode->c_cc[VKILL] = 21; /* ^U */
|
|
|
|
mode->c_lflag |= ECHOE | ECHOCTL | ECHOKE;
|
|
|
|
if (IXANY) mode->c_iflag &= ~IXANY;
|
|
|
|
}
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 14:31:44 +00:00
|
|
|
static void set_control_char_or_die(const struct control_info *info,
|
|
|
|
const char *arg, struct termios *mode)
|
2001-02-14 18:47:33 +00:00
|
|
|
{
|
|
|
|
unsigned char value;
|
|
|
|
|
|
|
|
if (info->name == stty_min || info->name == stty_time)
|
2006-10-08 12:49:22 +00:00
|
|
|
value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes);
|
2001-02-14 18:47:33 +00:00
|
|
|
else if (arg[0] == '\0' || arg[1] == '\0')
|
|
|
|
value = arg[0];
|
2006-09-19 14:17:10 +00:00
|
|
|
else if (streq(arg, "^-") || streq(arg, "undef"))
|
2001-02-14 18:47:33 +00:00
|
|
|
value = _POSIX_VDISABLE;
|
2006-09-19 14:24:23 +00:00
|
|
|
else if (arg[0] == '^') { /* Ignore any trailing junk (^Cjunk) */
|
2006-09-19 14:31:44 +00:00
|
|
|
value = arg[1] & 0x1f; /* Non-letters get weird results */
|
2001-02-14 18:47:33 +00:00
|
|
|
if (arg[1] == '?')
|
|
|
|
value = 127;
|
|
|
|
} else
|
2006-10-08 12:49:22 +00:00
|
|
|
value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes);
|
2001-02-14 18:47:33 +00:00
|
|
|
mode->c_cc[info->offset] = value;
|
|
|
|
}
|
|
|
|
|
2006-09-19 14:17:10 +00:00
|
|
|
static void display_changed(const struct termios *mode)
|
2001-02-14 18:47:33 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
tcflag_t *bitsp;
|
|
|
|
unsigned long mask;
|
2006-09-19 14:24:23 +00:00
|
|
|
int prev_type = control;
|
2001-02-14 18:47:33 +00:00
|
|
|
|
|
|
|
display_speed(mode, 1);
|
|
|
|
#ifdef HAVE_C_LINE
|
2006-09-19 14:19:42 +00:00
|
|
|
wrapf("line = %d;\n", mode->c_line);
|
|
|
|
#else
|
|
|
|
wrapf("\n");
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for (i = 0; control_info[i].name != stty_min; ++i) {
|
|
|
|
if (mode->c_cc[control_info[i].offset] == control_info[i].saneval)
|
|
|
|
continue;
|
2006-09-19 14:17:10 +00:00
|
|
|
/* If swtch is the same as susp, don't print both */
|
2001-02-14 18:47:33 +00:00
|
|
|
#if VSWTCH == VSUSP
|
|
|
|
if (control_info[i].name == stty_swtch)
|
|
|
|
continue;
|
|
|
|
#endif
|
2006-09-19 14:17:10 +00:00
|
|
|
/* If eof uses the same slot as min, only print whichever applies */
|
2001-02-14 18:47:33 +00:00
|
|
|
#if VEOF == VMIN
|
|
|
|
if ((mode->c_lflag & ICANON) == 0
|
|
|
|
&& (control_info[i].name == stty_eof
|
|
|
|
|| control_info[i].name == stty_eol)) continue;
|
|
|
|
#endif
|
|
|
|
wrapf("%s = %s;", control_info[i].name,
|
|
|
|
visible(mode->c_cc[control_info[i].offset]));
|
|
|
|
}
|
|
|
|
if ((mode->c_lflag & ICANON) == 0) {
|
2006-09-19 14:19:42 +00:00
|
|
|
wrapf("min = %d; time = %d;", (int) mode->c_cc[VMIN],
|
2001-02-14 18:47:33 +00:00
|
|
|
(int) mode->c_cc[VTIME]);
|
2006-09-19 14:19:42 +00:00
|
|
|
}
|
|
|
|
if (current_col) wrapf("\n");
|
2001-02-14 18:47:33 +00:00
|
|
|
|
|
|
|
for (i = 0; i < NUM_mode_info; ++i) {
|
|
|
|
if (mode_info[i].flags & OMIT)
|
|
|
|
continue;
|
2006-09-19 14:24:23 +00:00
|
|
|
if (mode_info[i].type != prev_type) {
|
2006-09-19 14:19:42 +00:00
|
|
|
if (current_col) wrapf("\n");
|
2006-09-19 14:24:23 +00:00
|
|
|
prev_type = mode_info[i].type;
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 14:24:23 +00:00
|
|
|
bitsp = mode_type_flag(mode_info[i].type, mode);
|
2001-02-14 18:47:33 +00:00
|
|
|
mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits;
|
|
|
|
if ((*bitsp & mask) == mode_info[i].bits) {
|
|
|
|
if (mode_info[i].flags & SANE_UNSET) {
|
|
|
|
wrapf("%s", mode_info[i].name);
|
|
|
|
}
|
2006-09-19 14:17:10 +00:00
|
|
|
} else if ((mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV)) {
|
2001-02-14 18:47:33 +00:00
|
|
|
wrapf("-%s", mode_info[i].name);
|
|
|
|
}
|
|
|
|
}
|
2006-09-19 14:19:42 +00:00
|
|
|
if (current_col) wrapf("\n");
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 14:31:44 +00:00
|
|
|
static void display_all(const struct termios *mode)
|
2001-02-14 18:47:33 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
tcflag_t *bitsp;
|
|
|
|
unsigned long mask;
|
2006-09-19 14:24:23 +00:00
|
|
|
int prev_type = control;
|
2001-02-14 18:47:33 +00:00
|
|
|
|
|
|
|
display_speed(mode, 1);
|
2006-01-30 12:23:46 +00:00
|
|
|
display_window_size(1);
|
2001-02-14 18:47:33 +00:00
|
|
|
#ifdef HAVE_C_LINE
|
2006-09-19 14:19:42 +00:00
|
|
|
wrapf("line = %d;\n", mode->c_line);
|
|
|
|
#else
|
|
|
|
wrapf("\n");
|
2001-02-14 18:47:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for (i = 0; control_info[i].name != stty_min; ++i) {
|
2006-09-19 14:17:10 +00:00
|
|
|
/* If swtch is the same as susp, don't print both */
|
2001-02-14 18:47:33 +00:00
|
|
|
#if VSWTCH == VSUSP
|
|
|
|
if (control_info[i].name == stty_swtch)
|
|
|
|
continue;
|
|
|
|
#endif
|
2006-09-19 14:17:10 +00:00
|
|
|
/* If eof uses the same slot as min, only print whichever applies */
|
2001-02-14 18:47:33 +00:00
|
|
|
#if VEOF == VMIN
|
|
|
|
if ((mode->c_lflag & ICANON) == 0
|
|
|
|
&& (control_info[i].name == stty_eof
|
|
|
|
|| control_info[i].name == stty_eol)) continue;
|
|
|
|
#endif
|
|
|
|
wrapf("%s = %s;", control_info[i].name,
|
|
|
|
visible(mode->c_cc[control_info[i].offset]));
|
|
|
|
}
|
|
|
|
#if VEOF == VMIN
|
|
|
|
if ((mode->c_lflag & ICANON) == 0)
|
|
|
|
#endif
|
|
|
|
wrapf("min = %d; time = %d;", mode->c_cc[VMIN], mode->c_cc[VTIME]);
|
2006-09-19 14:19:42 +00:00
|
|
|
if (current_col) wrapf("\n");
|
2001-02-14 18:47:33 +00:00
|
|
|
|
|
|
|
for (i = 0; i < NUM_mode_info; ++i) {
|
|
|
|
if (mode_info[i].flags & OMIT)
|
|
|
|
continue;
|
2006-09-19 14:24:23 +00:00
|
|
|
if (mode_info[i].type != prev_type) {
|
|
|
|
wrapf("\n");
|
|
|
|
prev_type = mode_info[i].type;
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 14:24:23 +00:00
|
|
|
bitsp = mode_type_flag(mode_info[i].type, mode);
|
2001-02-14 18:47:33 +00:00
|
|
|
mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits;
|
|
|
|
if ((*bitsp & mask) == mode_info[i].bits)
|
|
|
|
wrapf("%s", mode_info[i].name);
|
|
|
|
else if (mode_info[i].flags & REV)
|
|
|
|
wrapf("-%s", mode_info[i].name);
|
|
|
|
}
|
2006-09-19 14:19:42 +00:00
|
|
|
if (current_col) wrapf("\n");
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 14:17:10 +00:00
|
|
|
static void display_speed(const struct termios *mode, int fancy)
|
2001-02-14 18:47:33 +00:00
|
|
|
{
|
2006-09-19 14:24:23 +00:00
|
|
|
//01234567 8 9
|
2006-09-19 14:19:42 +00:00
|
|
|
const char *fmt_str = "%lu %lu\n\0ispeed %lu baud; ospeed %lu baud;";
|
2003-03-19 09:13:01 +00:00
|
|
|
unsigned long ispeed, ospeed;
|
|
|
|
|
|
|
|
ospeed = ispeed = cfgetispeed(mode);
|
|
|
|
if (ispeed == 0 || ispeed == (ospeed = cfgetospeed(mode))) {
|
2006-01-30 12:23:46 +00:00
|
|
|
ispeed = ospeed; /* in case ispeed was 0 */
|
2006-09-19 14:24:23 +00:00
|
|
|
//0123 4 5 6 7 8 9
|
2006-09-19 14:19:42 +00:00
|
|
|
fmt_str = "%lu\n\0\0\0\0\0speed %lu baud;";
|
2003-03-19 09:13:01 +00:00
|
|
|
}
|
2006-09-19 14:19:42 +00:00
|
|
|
if (fancy) fmt_str += 9;
|
2006-06-18 23:59:03 +00:00
|
|
|
wrapf(fmt_str, tty_baud_to_value(ispeed), tty_baud_to_value(ospeed));
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 14:17:10 +00:00
|
|
|
static void display_recoverable(const struct termios *mode)
|
2001-02-14 18:47:33 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
printf("%lx:%lx:%lx:%lx",
|
|
|
|
(unsigned long) mode->c_iflag, (unsigned long) mode->c_oflag,
|
|
|
|
(unsigned long) mode->c_cflag, (unsigned long) mode->c_lflag);
|
|
|
|
for (i = 0; i < NCCS; ++i)
|
|
|
|
printf(":%x", (unsigned int) mode->c_cc[i]);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
2006-09-19 14:16:28 +00:00
|
|
|
static int recover_mode(const char *arg, struct termios *mode)
|
2001-02-14 18:47:33 +00:00
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
unsigned int chr;
|
|
|
|
unsigned long iflag, oflag, cflag, lflag;
|
|
|
|
|
|
|
|
/* Scan into temporaries since it is too much trouble to figure out
|
2006-09-19 15:12:12 +00:00
|
|
|
the right format for 'tcflag_t' */
|
2001-02-14 18:47:33 +00:00
|
|
|
if (sscanf(arg, "%lx:%lx:%lx:%lx%n",
|
|
|
|
&iflag, &oflag, &cflag, &lflag, &n) != 4)
|
|
|
|
return 0;
|
|
|
|
mode->c_iflag = iflag;
|
|
|
|
mode->c_oflag = oflag;
|
|
|
|
mode->c_cflag = cflag;
|
|
|
|
mode->c_lflag = lflag;
|
|
|
|
arg += n;
|
|
|
|
for (i = 0; i < NCCS; ++i) {
|
|
|
|
if (sscanf(arg, ":%x%n", &chr, &n) != 1)
|
|
|
|
return 0;
|
|
|
|
mode->c_cc[i] = chr;
|
|
|
|
arg += n;
|
|
|
|
}
|
|
|
|
|
2006-09-19 14:17:10 +00:00
|
|
|
/* Fail if there are too many fields */
|
2001-02-14 18:47:33 +00:00
|
|
|
if (*arg != '\0')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sane_mode(struct termios *mode)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
tcflag_t *bitsp;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_control_info; ++i) {
|
|
|
|
#if VMIN == VEOF
|
|
|
|
if (control_info[i].name == stty_min)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
mode->c_cc[control_info[i].offset] = control_info[i].saneval;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_mode_info; ++i) {
|
|
|
|
if (mode_info[i].flags & SANE_SET) {
|
2006-09-19 14:24:23 +00:00
|
|
|
bitsp = mode_type_flag(mode_info[i].type, mode);
|
2003-03-19 09:13:01 +00:00
|
|
|
*bitsp = (*bitsp & ~((unsigned long)mode_info[i].mask))
|
|
|
|
| mode_info[i].bits;
|
2001-02-14 18:47:33 +00:00
|
|
|
} else if (mode_info[i].flags & SANE_UNSET) {
|
2006-09-19 14:24:23 +00:00
|
|
|
bitsp = mode_type_flag(mode_info[i].type, mode);
|
2003-03-19 09:13:01 +00:00
|
|
|
*bitsp = *bitsp & ~((unsigned long)mode_info[i].mask)
|
|
|
|
& ~mode_info[i].bits;
|
2001-02-14 18:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|