2001-02-15 00:17:33 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2017-10-05 18:49:25 +05:30
|
|
|
/*
|
|
|
|
* stty -- change and print terminal line settings
|
2017-10-05 18:10:24 +05:30
|
|
|
* Copyright (C) 1990-1999 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
|
|
|
*/
|
2019-02-27 21:15:39 +05:30
|
|
|
/* David MacKenzie <djm@gnu.ai.mit.edu>
|
2017-10-05 18:10:24 +05:30
|
|
|
*
|
|
|
|
* Special for busybox ported by Vladimir Oleynik <dzo@simtreas.ru> 2001
|
|
|
|
*/
|
2016-11-23 19:16:56 +05:30
|
|
|
//config:config STTY
|
2018-12-28 07:50:17 +05:30
|
|
|
//config: bool "stty (8.9 kb)"
|
2016-11-23 19:16:56 +05:30
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: stty is used to change and print terminal line settings.
|
2016-11-23 19:16:56 +05:30
|
|
|
|
2017-08-04 23:37:19 +05:30
|
|
|
//applet:IF_STTY(APPLET_NOEXEC(stty, stty, BB_DIR_BIN, BB_SUID_DROP, stty))
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2016-11-23 19:16:56 +05:30
|
|
|
//kbuild:lib-$(CONFIG_STTY) += stty.o
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2011-03-31 18:13:25 +05:30
|
|
|
//usage:#define stty_trivial_usage
|
|
|
|
//usage: "[-a|g] [-F DEVICE] [SETTING]..."
|
|
|
|
//usage:#define stty_full_usage "\n\n"
|
|
|
|
//usage: "Without arguments, prints baud rate, line discipline,\n"
|
|
|
|
//usage: "and deviations from stty sane\n"
|
|
|
|
//usage: "\n -F DEVICE Open device instead of stdin"
|
|
|
|
//usage: "\n -a Print all current settings in human-readable form"
|
|
|
|
//usage: "\n -g Print in stty-readable form"
|
|
|
|
//usage: "\n [SETTING] See manpage"
|
|
|
|
|
2019-02-27 21:15:39 +05:30
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2007-05-27 00:30:18 +05:30
|
|
|
#include "libbb.h"
|
2016-04-21 19:56:30 +05:30
|
|
|
#include "common_bufsiz.h"
|
2001-02-15 00:17:33 +05:30
|
|
|
|
|
|
|
#ifndef _POSIX_VDISABLE
|
|
|
|
# define _POSIX_VDISABLE ((unsigned char) 0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define Control(c) ((c) & 0x1f)
|
2006-09-19 19:47:10 +05:30
|
|
|
/* Canonical values for control characters */
|
2001-02-15 00:17:33 +05:30
|
|
|
#ifndef CINTR
|
2006-09-19 19:47:10 +05:30
|
|
|
# define CINTR Control('c')
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
|
|
|
#ifndef CQUIT
|
|
|
|
# define CQUIT 28
|
|
|
|
#endif
|
|
|
|
#ifndef CERASE
|
|
|
|
# define CERASE 127
|
|
|
|
#endif
|
|
|
|
#ifndef CKILL
|
2006-09-19 19:47:10 +05:30
|
|
|
# define CKILL Control('u')
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
|
|
|
#ifndef CEOF
|
2006-09-19 19:47:10 +05:30
|
|
|
# define CEOF Control('d')
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
|
|
|
#ifndef CEOL
|
|
|
|
# define CEOL _POSIX_VDISABLE
|
|
|
|
#endif
|
|
|
|
#ifndef CSTART
|
2006-09-19 19:47:10 +05:30
|
|
|
# define CSTART Control('q')
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
|
|
|
#ifndef CSTOP
|
2006-09-19 19:47:10 +05:30
|
|
|
# define CSTOP Control('s')
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
|
|
|
#ifndef CSUSP
|
2006-09-19 19:47:10 +05:30
|
|
|
# define CSUSP Control('z')
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
|
|
|
#if defined(VEOL2) && !defined(CEOL2)
|
|
|
|
# define CEOL2 _POSIX_VDISABLE
|
|
|
|
#endif
|
2011-01-24 21:06:15 +05:30
|
|
|
/* glibc-2.12.1 uses only VSWTC name */
|
|
|
|
#if defined(VSWTC) && !defined(VSWTCH)
|
|
|
|
# define VSWTCH VSWTC
|
|
|
|
#endif
|
2006-09-19 19:47:10 +05:30
|
|
|
/* ISC renamed swtch to susp for termios, but we'll accept either name */
|
2001-02-15 00:17:33 +05:30
|
|
|
#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 20:42:12 +05:30
|
|
|
/* SunOS 5.3 loses (^Z doesn't work) if 'swtch' is the same as 'susp'.
|
|
|
|
So the default is to disable 'swtch.' */
|
2007-04-10 21:12:06 +05:30
|
|
|
#if defined(__sparc__) && defined(__svr4__)
|
2001-02-15 00:17:33 +05:30
|
|
|
# undef CSWTCH
|
|
|
|
# define CSWTCH _POSIX_VDISABLE
|
|
|
|
#endif
|
|
|
|
|
2007-04-10 21:12:06 +05:30
|
|
|
#if defined(VWERSE) && !defined(VWERASE) /* AIX-3.2.5 */
|
2001-02-15 00:17:33 +05:30
|
|
|
# define VWERASE VWERSE
|
|
|
|
#endif
|
2007-04-10 21:12:06 +05:30
|
|
|
#if defined(VDSUSP) && !defined(CDSUSP)
|
2006-09-19 19:47:10 +05:30
|
|
|
# define CDSUSP Control('y')
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2001-03-03 01:30:54 +05:30
|
|
|
#if !defined(VREPRINT) && defined(VRPRNT) /* Irix 4.0.5 */
|
2001-02-15 00:17:33 +05:30
|
|
|
# define VREPRINT VRPRNT
|
|
|
|
#endif
|
|
|
|
#if defined(VREPRINT) && !defined(CRPRNT)
|
2006-09-19 19:47:10 +05:30
|
|
|
# define CRPRNT Control('r')
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
|
|
|
#if defined(VWERASE) && !defined(CWERASE)
|
2006-09-19 19:47:10 +05:30
|
|
|
# define CWERASE Control('w')
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
|
|
|
#if defined(VLNEXT) && !defined(CLNEXT)
|
2006-09-19 19:47:10 +05:30
|
|
|
# define CLNEXT Control('v')
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
|
|
|
#if defined(VDISCARD) && !defined(VFLUSHO)
|
|
|
|
# define VFLUSHO VDISCARD
|
|
|
|
#endif
|
2001-03-03 01:30:54 +05:30
|
|
|
#if defined(VFLUSH) && !defined(VFLUSHO) /* Ultrix 4.2 */
|
2001-02-15 00:17:33 +05:30
|
|
|
# define VFLUSHO VFLUSH
|
|
|
|
#endif
|
2001-03-03 01:30:54 +05:30
|
|
|
#if defined(CTLECH) && !defined(ECHOCTL) /* Ultrix 4.3 */
|
2001-02-15 00:17:33 +05:30
|
|
|
# define ECHOCTL CTLECH
|
|
|
|
#endif
|
2001-03-03 01:30:54 +05:30
|
|
|
#if defined(TCTLECH) && !defined(ECHOCTL) /* Ultrix 4.2 */
|
2001-02-15 00:17:33 +05:30
|
|
|
# define ECHOCTL TCTLECH
|
|
|
|
#endif
|
2001-03-03 01:30:54 +05:30
|
|
|
#if defined(CRTKIL) && !defined(ECHOKE) /* Ultrix 4.2 and 4.3 */
|
2001-02-15 00:17:33 +05:30
|
|
|
# define ECHOKE CRTKIL
|
|
|
|
#endif
|
|
|
|
#if defined(VFLUSHO) && !defined(CFLUSHO)
|
2006-09-19 19:47:10 +05:30
|
|
|
# define CFLUSHO Control('o')
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
|
|
|
#if defined(VSTATUS) && !defined(CSTATUS)
|
2006-09-19 19:47:10 +05:30
|
|
|
# define CSTATUS Control('t')
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
|
|
|
|
2010-07-30 09:31:37 +05:30
|
|
|
/* Save us from #ifdef forest plague */
|
|
|
|
#ifndef BSDLY
|
|
|
|
# define BSDLY 0
|
|
|
|
#endif
|
|
|
|
#ifndef CIBAUD
|
|
|
|
# define CIBAUD 0
|
|
|
|
#endif
|
|
|
|
#ifndef CRDLY
|
|
|
|
# define CRDLY 0
|
|
|
|
#endif
|
2017-09-18 15:46:47 +05:30
|
|
|
#ifndef CMSPAR
|
|
|
|
# define CMSPAR 0
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#ifndef CRTSCTS
|
|
|
|
# define CRTSCTS 0
|
|
|
|
#endif
|
|
|
|
#ifndef ECHOCTL
|
|
|
|
# define ECHOCTL 0
|
|
|
|
#endif
|
|
|
|
#ifndef ECHOKE
|
|
|
|
# define ECHOKE 0
|
|
|
|
#endif
|
|
|
|
#ifndef ECHOPRT
|
|
|
|
# define ECHOPRT 0
|
|
|
|
#endif
|
|
|
|
#ifndef FFDLY
|
|
|
|
# define FFDLY 0
|
|
|
|
#endif
|
|
|
|
#ifndef IEXTEN
|
|
|
|
# define IEXTEN 0
|
|
|
|
#endif
|
|
|
|
#ifndef IMAXBEL
|
|
|
|
# define IMAXBEL 0
|
|
|
|
#endif
|
|
|
|
#ifndef IUCLC
|
|
|
|
# define IUCLC 0
|
|
|
|
#endif
|
|
|
|
#ifndef IXANY
|
|
|
|
# define IXANY 0
|
|
|
|
#endif
|
|
|
|
#ifndef NLDLY
|
|
|
|
# define NLDLY 0
|
|
|
|
#endif
|
|
|
|
#ifndef OCRNL
|
|
|
|
# define OCRNL 0
|
|
|
|
#endif
|
|
|
|
#ifndef OFDEL
|
|
|
|
# define OFDEL 0
|
|
|
|
#endif
|
|
|
|
#ifndef OFILL
|
|
|
|
# define OFILL 0
|
|
|
|
#endif
|
|
|
|
#ifndef OLCUC
|
|
|
|
# define OLCUC 0
|
|
|
|
#endif
|
|
|
|
#ifndef ONLCR
|
|
|
|
# define ONLCR 0
|
|
|
|
#endif
|
|
|
|
#ifndef ONLRET
|
|
|
|
# define ONLRET 0
|
|
|
|
#endif
|
|
|
|
#ifndef ONOCR
|
|
|
|
# define ONOCR 0
|
|
|
|
#endif
|
|
|
|
#ifndef OXTABS
|
|
|
|
# define OXTABS 0
|
|
|
|
#endif
|
|
|
|
#ifndef TABDLY
|
|
|
|
# define TABDLY 0
|
|
|
|
#endif
|
|
|
|
#ifndef TAB1
|
|
|
|
# define TAB1 0
|
|
|
|
#endif
|
|
|
|
#ifndef TAB2
|
|
|
|
# define TAB2 0
|
|
|
|
#endif
|
|
|
|
#ifndef TOSTOP
|
|
|
|
# define TOSTOP 0
|
|
|
|
#endif
|
|
|
|
#ifndef VDSUSP
|
|
|
|
# define VDSUSP 0
|
|
|
|
#endif
|
|
|
|
#ifndef VEOL2
|
|
|
|
# define VEOL2 0
|
|
|
|
#endif
|
|
|
|
#ifndef VFLUSHO
|
|
|
|
# define VFLUSHO 0
|
|
|
|
#endif
|
|
|
|
#ifndef VLNEXT
|
|
|
|
# define VLNEXT 0
|
|
|
|
#endif
|
|
|
|
#ifndef VREPRINT
|
|
|
|
# define VREPRINT 0
|
|
|
|
#endif
|
|
|
|
#ifndef VSTATUS
|
|
|
|
# define VSTATUS 0
|
|
|
|
#endif
|
|
|
|
#ifndef VSWTCH
|
|
|
|
# define VSWTCH 0
|
|
|
|
#endif
|
|
|
|
#ifndef VTDLY
|
|
|
|
# define VTDLY 0
|
|
|
|
#endif
|
|
|
|
#ifndef VWERASE
|
|
|
|
# define VWERASE 0
|
|
|
|
#endif
|
|
|
|
#ifndef XCASE
|
|
|
|
# define XCASE 0
|
|
|
|
#endif
|
2011-01-24 21:06:15 +05:30
|
|
|
#ifndef IUTF8
|
|
|
|
# define IUTF8 0
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
|
2006-09-19 19:47:10 +05:30
|
|
|
/* Which speeds to set */
|
2001-02-15 00:17:33 +05:30
|
|
|
enum speed_setting {
|
|
|
|
input_speed, output_speed, both_speeds
|
|
|
|
};
|
|
|
|
|
2006-09-19 20:42:12 +05:30
|
|
|
/* Which member(s) of 'struct termios' a mode uses */
|
2006-09-19 19:54:23 +05:30
|
|
|
enum {
|
2001-02-15 00:17:33 +05:30
|
|
|
control, input, output, local, combination
|
|
|
|
};
|
2013-05-17 21:36:49 +05:30
|
|
|
static tcflag_t *get_ptr_to_tcflag(unsigned type, const struct termios *mode)
|
|
|
|
{
|
|
|
|
static const uint8_t tcflag_offsets[] ALIGN1 = {
|
|
|
|
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;
|
|
|
|
}
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2006-09-19 20:42:12 +05:30
|
|
|
/* 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 19:47:10 +05:30
|
|
|
#define OMIT 8 /* Don't display value */
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-11-24 10:02:49 +05:30
|
|
|
|
|
|
|
/* Each mode.
|
|
|
|
* This structure should be kept as small as humanly possible.
|
|
|
|
*/
|
2001-02-15 00:17:33 +05:30
|
|
|
struct mode_info {
|
2007-11-24 10:02:49 +05:30
|
|
|
const uint8_t type; /* Which structure element to change */
|
|
|
|
const uint8_t flags; /* Setting and display options */
|
|
|
|
/* only these values are ever used, so... */
|
|
|
|
#if (CSIZE | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY) < 0x100
|
|
|
|
const uint8_t mask;
|
|
|
|
#elif (CSIZE | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY) < 0x10000
|
|
|
|
const uint16_t mask;
|
|
|
|
#else
|
2007-01-18 01:14:24 +05:30
|
|
|
const tcflag_t mask; /* Other bits to turn off for this mode */
|
2007-11-24 10:02:49 +05:30
|
|
|
#endif
|
|
|
|
/* was using short here, but ppc32 was unhappy */
|
2007-01-18 01:14:24 +05:30
|
|
|
const tcflag_t bits; /* Bits to set for this mode */
|
2001-02-15 00:17:33 +05:30
|
|
|
};
|
|
|
|
|
2007-10-11 21:32:36 +05:30
|
|
|
enum {
|
2007-11-24 10:02:49 +05:30
|
|
|
/* Must match mode_name[] and mode_info[] order! */
|
2007-10-11 21:32:36 +05:30
|
|
|
IDX_evenp = 0,
|
|
|
|
IDX_parity,
|
|
|
|
IDX_oddp,
|
|
|
|
IDX_nl,
|
|
|
|
IDX_ek,
|
|
|
|
IDX_sane,
|
|
|
|
IDX_cooked,
|
|
|
|
IDX_raw,
|
|
|
|
IDX_pass8,
|
|
|
|
IDX_litout,
|
|
|
|
IDX_cbreak,
|
|
|
|
IDX_crt,
|
|
|
|
IDX_dec,
|
2010-07-30 09:31:37 +05:30
|
|
|
#if IXANY
|
2007-10-11 21:32:36 +05:30
|
|
|
IDX_decctlq,
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if TABDLY || OXTABS
|
2007-10-11 21:32:36 +05:30
|
|
|
IDX_tabs,
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if XCASE && IUCLC && OLCUC
|
2007-10-11 21:32:36 +05:30
|
|
|
IDX_lcase,
|
|
|
|
IDX_LCASE,
|
|
|
|
#endif
|
|
|
|
};
|
2007-01-01 23:48:04 +05:30
|
|
|
|
2007-11-24 10:02:49 +05:30
|
|
|
#define MI_ENTRY(N,T,F,B,M) N "\0"
|
|
|
|
|
|
|
|
/* Mode names given on command line */
|
2016-04-22 21:39:21 +05:30
|
|
|
static const char mode_name[] ALIGN1 =
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("parity", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("nl", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("ek", combination, OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("sane", combination, OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("cooked", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("raw", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("pass8", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("litout", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("crt", combination, OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("dec", combination, OMIT, 0, 0 )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if IXANY
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("decctlq", combination, REV | OMIT, 0, 0 )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if TABDLY || OXTABS
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("tabs", combination, REV | OMIT, 0, 0 )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if XCASE && IUCLC && OLCUC
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("lcase", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("LCASE", combination, REV | OMIT, 0, 0 )
|
|
|
|
#endif
|
|
|
|
MI_ENTRY("parenb", control, REV, PARENB, 0 )
|
|
|
|
MI_ENTRY("parodd", control, REV, PARODD, 0 )
|
2017-09-18 15:46:47 +05:30
|
|
|
#if CMSPAR
|
|
|
|
MI_ENTRY("cmspar", control, REV, CMSPAR, 0 )
|
|
|
|
#endif
|
2007-11-24 10:02:49 +05:30
|
|
|
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 )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if CRTSCTS
|
2007-11-24 10:02:49 +05:30
|
|
|
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 )
|
2011-01-26 16:28:37 +05:30
|
|
|
MI_ENTRY("tandem", input, OMIT | REV, IXOFF, 0 )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if IUCLC
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if IXANY
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("ixany", input, SANE_UNSET | REV, IXANY, 0 )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if IMAXBEL
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("imaxbel", input, SANE_SET | REV, IMAXBEL, 0 )
|
2011-01-24 21:06:15 +05:30
|
|
|
#endif
|
|
|
|
#if IUTF8
|
|
|
|
MI_ENTRY("iutf8", input, SANE_UNSET | REV, IUTF8, 0 )
|
2007-11-24 10:02:49 +05:30
|
|
|
#endif
|
|
|
|
MI_ENTRY("opost", output, SANE_SET | REV, OPOST, 0 )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if OLCUC
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("olcuc", output, SANE_UNSET | REV, OLCUC, 0 )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if OCRNL
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("ocrnl", output, SANE_UNSET | REV, OCRNL, 0 )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if ONLCR
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("onlcr", output, SANE_SET | REV, ONLCR, 0 )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if ONOCR
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("onocr", output, SANE_UNSET | REV, ONOCR, 0 )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if ONLRET
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("onlret", output, SANE_UNSET | REV, ONLRET, 0 )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if OFILL
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("ofill", output, SANE_UNSET | REV, OFILL, 0 )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if OFDEL
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("ofdel", output, SANE_UNSET | REV, OFDEL, 0 )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if NLDLY
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("nl1", output, SANE_UNSET, NL1, NLDLY)
|
|
|
|
MI_ENTRY("nl0", output, SANE_SET, NL0, NLDLY)
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if CRDLY
|
2007-11-24 10:02:49 +05:30
|
|
|
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)
|
|
|
|
#endif
|
|
|
|
|
2010-07-30 09:31:37 +05:30
|
|
|
#if TABDLY
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("tab3", output, SANE_UNSET, TAB3, TABDLY)
|
2010-07-30 09:31:37 +05:30
|
|
|
# if TAB2
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("tab2", output, SANE_UNSET, TAB2, TABDLY)
|
2010-07-30 09:31:37 +05:30
|
|
|
# endif
|
|
|
|
# if TAB1
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("tab1", output, SANE_UNSET, TAB1, TABDLY)
|
2010-07-30 09:31:37 +05:30
|
|
|
# endif
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("tab0", output, SANE_SET, TAB0, TABDLY)
|
|
|
|
#else
|
2010-07-30 09:31:37 +05:30
|
|
|
# if OXTABS
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("tab3", output, SANE_UNSET, OXTABS, 0 )
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2010-07-30 09:31:37 +05:30
|
|
|
#if BSDLY
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("bs1", output, SANE_UNSET, BS1, BSDLY)
|
|
|
|
MI_ENTRY("bs0", output, SANE_SET, BS0, BSDLY)
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VTDLY
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("vt1", output, SANE_UNSET, VT1, VTDLY)
|
|
|
|
MI_ENTRY("vt0", output, SANE_SET, VT0, VTDLY)
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if FFDLY
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("ff1", output, SANE_UNSET, FF1, FFDLY)
|
|
|
|
MI_ENTRY("ff0", output, SANE_SET, FF0, FFDLY)
|
|
|
|
#endif
|
|
|
|
MI_ENTRY("isig", local, SANE_SET | REV, ISIG, 0 )
|
|
|
|
MI_ENTRY("icanon", local, SANE_SET | REV, ICANON, 0 )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if IEXTEN
|
2007-11-24 10:02:49 +05:30
|
|
|
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 )
|
2011-01-26 16:28:37 +05:30
|
|
|
MI_ENTRY("crterase", local, OMIT | REV, ECHOE, 0 )
|
2007-11-24 10:02:49 +05:30
|
|
|
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 )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if XCASE
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("xcase", local, SANE_UNSET | REV, XCASE, 0 )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if TOSTOP
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("tostop", local, SANE_UNSET | REV, TOSTOP, 0 )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if ECHOPRT
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 )
|
2011-01-26 16:28:37 +05:30
|
|
|
MI_ENTRY("prterase", local, OMIT | REV, ECHOPRT, 0 )
|
2007-11-24 10:02:49 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if ECHOCTL
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 )
|
2011-01-26 16:28:37 +05:30
|
|
|
MI_ENTRY("ctlecho", local, OMIT | REV, ECHOCTL, 0 )
|
2007-11-24 10:02:49 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if ECHOKE
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 )
|
2011-01-26 16:28:37 +05:30
|
|
|
MI_ENTRY("crtkill", local, OMIT | REV, ECHOKE, 0 )
|
2017-09-18 15:46:47 +05:30
|
|
|
#endif
|
|
|
|
MI_ENTRY("flusho", local, SANE_UNSET | REV, FLUSHO, 0 )
|
|
|
|
#ifdef EXTPROC
|
|
|
|
MI_ENTRY("extproc", local, SANE_UNSET | REV, EXTPROC, 0 )
|
2007-11-24 10:02:49 +05:30
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
|
|
|
#undef MI_ENTRY
|
|
|
|
#define MI_ENTRY(N,T,F,B,M) { T, F, M, B },
|
2003-03-19 14:43:01 +05:30
|
|
|
|
2006-09-19 19:46:28 +05:30
|
|
|
static const struct mode_info mode_info[] = {
|
2007-11-24 10:02:49 +05:30
|
|
|
/* This should be verbatim cut-n-paste copy of the above MI_ENTRYs */
|
|
|
|
MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("parity", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("nl", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("ek", combination, OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("sane", combination, OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("cooked", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("raw", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("pass8", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("litout", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("crt", combination, OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("dec", combination, OMIT, 0, 0 )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if IXANY
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("decctlq", combination, REV | OMIT, 0, 0 )
|
2007-10-11 21:32:36 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if TABDLY || OXTABS
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("tabs", combination, REV | OMIT, 0, 0 )
|
2007-10-11 21:32:36 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if XCASE && IUCLC && OLCUC
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("lcase", combination, REV | OMIT, 0, 0 )
|
|
|
|
MI_ENTRY("LCASE", combination, REV | OMIT, 0, 0 )
|
|
|
|
#endif
|
|
|
|
MI_ENTRY("parenb", control, REV, PARENB, 0 )
|
|
|
|
MI_ENTRY("parodd", control, REV, PARODD, 0 )
|
2017-09-18 15:46:47 +05:30
|
|
|
#if CMSPAR
|
|
|
|
MI_ENTRY("cmspar", control, REV, CMSPAR, 0 )
|
|
|
|
#endif
|
2007-11-24 10:02:49 +05:30
|
|
|
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 )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if CRTSCTS
|
2007-11-24 10:02:49 +05:30
|
|
|
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 )
|
2011-01-26 16:28:37 +05:30
|
|
|
MI_ENTRY("tandem", input, OMIT | REV, IXOFF, 0 )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if IUCLC
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if IXANY
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("ixany", input, SANE_UNSET | REV, IXANY, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if IMAXBEL
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("imaxbel", input, SANE_SET | REV, IMAXBEL, 0 )
|
2011-01-24 21:06:15 +05:30
|
|
|
#endif
|
|
|
|
#if IUTF8
|
|
|
|
MI_ENTRY("iutf8", input, SANE_UNSET | REV, IUTF8, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("opost", output, SANE_SET | REV, OPOST, 0 )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if OLCUC
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("olcuc", output, SANE_UNSET | REV, OLCUC, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if OCRNL
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("ocrnl", output, SANE_UNSET | REV, OCRNL, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if ONLCR
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("onlcr", output, SANE_SET | REV, ONLCR, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if ONOCR
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("onocr", output, SANE_UNSET | REV, ONOCR, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if ONLRET
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("onlret", output, SANE_UNSET | REV, ONLRET, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if OFILL
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("ofill", output, SANE_UNSET | REV, OFILL, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if OFDEL
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("ofdel", output, SANE_UNSET | REV, OFDEL, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if NLDLY
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("nl1", output, SANE_UNSET, NL1, NLDLY)
|
|
|
|
MI_ENTRY("nl0", output, SANE_SET, NL0, NLDLY)
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if CRDLY
|
2007-11-24 10:02:49 +05:30
|
|
|
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-15 00:17:33 +05:30
|
|
|
#endif
|
2001-03-03 01:30:54 +05:30
|
|
|
|
2010-07-30 09:31:37 +05:30
|
|
|
#if TABDLY
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("tab3", output, SANE_UNSET, TAB3, TABDLY)
|
2010-07-30 09:31:37 +05:30
|
|
|
# if TAB2
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("tab2", output, SANE_UNSET, TAB2, TABDLY)
|
2010-07-30 09:31:37 +05:30
|
|
|
# endif
|
|
|
|
# if TAB1
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("tab1", output, SANE_UNSET, TAB1, TABDLY)
|
2010-07-30 09:31:37 +05:30
|
|
|
# endif
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("tab0", output, SANE_SET, TAB0, TABDLY)
|
2001-02-15 00:17:33 +05:30
|
|
|
#else
|
2010-07-30 09:31:37 +05:30
|
|
|
# if OXTABS
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("tab3", output, SANE_UNSET, OXTABS, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
# endif
|
|
|
|
#endif
|
2001-03-03 01:30:54 +05:30
|
|
|
|
2010-07-30 09:31:37 +05:30
|
|
|
#if BSDLY
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("bs1", output, SANE_UNSET, BS1, BSDLY)
|
|
|
|
MI_ENTRY("bs0", output, SANE_SET, BS0, BSDLY)
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VTDLY
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("vt1", output, SANE_UNSET, VT1, VTDLY)
|
|
|
|
MI_ENTRY("vt0", output, SANE_SET, VT0, VTDLY)
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if FFDLY
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("ff1", output, SANE_UNSET, FF1, FFDLY)
|
|
|
|
MI_ENTRY("ff0", output, SANE_SET, FF0, FFDLY)
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("isig", local, SANE_SET | REV, ISIG, 0 )
|
|
|
|
MI_ENTRY("icanon", local, SANE_SET | REV, ICANON, 0 )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if IEXTEN
|
2007-11-24 10:02:49 +05:30
|
|
|
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 )
|
2011-01-26 16:28:37 +05:30
|
|
|
MI_ENTRY("crterase", local, OMIT | REV, ECHOE, 0 )
|
2007-11-24 10:02:49 +05:30
|
|
|
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 )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if XCASE
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("xcase", local, SANE_UNSET | REV, XCASE, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if TOSTOP
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("tostop", local, SANE_UNSET | REV, TOSTOP, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if ECHOPRT
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 )
|
2011-01-26 16:28:37 +05:30
|
|
|
MI_ENTRY("prterase", local, OMIT | REV, ECHOPRT, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if ECHOCTL
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 )
|
2011-01-26 16:28:37 +05:30
|
|
|
MI_ENTRY("ctlecho", local, OMIT | REV, ECHOCTL, 0 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if ECHOKE
|
2007-11-24 10:02:49 +05:30
|
|
|
MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 )
|
2011-01-26 16:28:37 +05:30
|
|
|
MI_ENTRY("crtkill", local, OMIT | REV, ECHOKE, 0 )
|
2017-09-18 15:46:47 +05:30
|
|
|
#endif
|
|
|
|
MI_ENTRY("flusho", local, SANE_UNSET | REV, FLUSHO, 0 )
|
|
|
|
#ifdef EXTPROC
|
|
|
|
MI_ENTRY("extproc", local, SANE_UNSET | REV, EXTPROC, 0 )
|
2003-03-19 14:43:01 +05:30
|
|
|
#endif
|
2001-02-15 00:17:33 +05:30
|
|
|
};
|
|
|
|
|
2006-03-11 00:52:06 +05:30
|
|
|
enum {
|
2007-06-25 16:25:35 +05:30
|
|
|
NUM_mode_info = ARRAY_SIZE(mode_info)
|
2006-03-11 00:52:06 +05:30
|
|
|
};
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-11-24 10:02:49 +05:30
|
|
|
|
2007-10-11 21:32:36 +05:30
|
|
|
/* Control characters */
|
2001-02-15 00:17:33 +05:30
|
|
|
struct control_info {
|
2007-11-24 10:02:49 +05:30
|
|
|
const uint8_t saneval; /* Value to set for 'stty sane' */
|
|
|
|
const uint8_t offset; /* Offset in c_cc */
|
2001-02-15 00:17:33 +05:30
|
|
|
};
|
|
|
|
|
2007-10-11 21:32:36 +05:30
|
|
|
enum {
|
2007-11-24 10:02:49 +05:30
|
|
|
/* Must match control_name[] and control_info[] order! */
|
2007-10-11 21:32:36 +05:30
|
|
|
CIDX_intr = 0,
|
|
|
|
CIDX_quit,
|
|
|
|
CIDX_erase,
|
|
|
|
CIDX_kill,
|
|
|
|
CIDX_eof,
|
|
|
|
CIDX_eol,
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VEOL2
|
2007-10-11 21:32:36 +05:30
|
|
|
CIDX_eol2,
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VSWTCH
|
2007-10-11 21:32:36 +05:30
|
|
|
CIDX_swtch,
|
|
|
|
#endif
|
|
|
|
CIDX_start,
|
|
|
|
CIDX_stop,
|
|
|
|
CIDX_susp,
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VDSUSP
|
2007-10-11 21:32:36 +05:30
|
|
|
CIDX_dsusp,
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VREPRINT
|
2007-10-11 21:32:36 +05:30
|
|
|
CIDX_rprnt,
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VWERASE
|
2007-10-11 21:32:36 +05:30
|
|
|
CIDX_werase,
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VLNEXT
|
2007-10-11 21:32:36 +05:30
|
|
|
CIDX_lnext,
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VFLUSHO
|
2007-10-11 21:32:36 +05:30
|
|
|
CIDX_flush,
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VSTATUS
|
2007-10-11 21:32:36 +05:30
|
|
|
CIDX_status,
|
|
|
|
#endif
|
|
|
|
CIDX_min,
|
|
|
|
CIDX_time,
|
|
|
|
};
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-11-24 10:02:49 +05:30
|
|
|
#define CI_ENTRY(n,s,o) n "\0"
|
|
|
|
|
|
|
|
/* Name given on command line */
|
2016-04-22 21:39:21 +05:30
|
|
|
static const char control_name[] ALIGN1 =
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("intr", CINTR, VINTR )
|
|
|
|
CI_ENTRY("quit", CQUIT, VQUIT )
|
|
|
|
CI_ENTRY("erase", CERASE, VERASE )
|
|
|
|
CI_ENTRY("kill", CKILL, VKILL )
|
|
|
|
CI_ENTRY("eof", CEOF, VEOF )
|
|
|
|
CI_ENTRY("eol", CEOL, VEOL )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VEOL2
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("eol2", CEOL2, VEOL2 )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VSWTCH
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("swtch", CSWTCH, VSWTCH )
|
|
|
|
#endif
|
|
|
|
CI_ENTRY("start", CSTART, VSTART )
|
|
|
|
CI_ENTRY("stop", CSTOP, VSTOP )
|
|
|
|
CI_ENTRY("susp", CSUSP, VSUSP )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VDSUSP
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("dsusp", CDSUSP, VDSUSP )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VREPRINT
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("rprnt", CRPRNT, VREPRINT)
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VWERASE
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("werase", CWERASE, VWERASE )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VLNEXT
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("lnext", CLNEXT, VLNEXT )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VFLUSHO
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("flush", CFLUSHO, VFLUSHO )
|
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VSTATUS
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("status", CSTATUS, VSTATUS )
|
|
|
|
#endif
|
|
|
|
/* These must be last because of the display routines */
|
|
|
|
CI_ENTRY("min", 1, VMIN )
|
|
|
|
CI_ENTRY("time", 0, VTIME )
|
|
|
|
;
|
|
|
|
|
|
|
|
#undef CI_ENTRY
|
|
|
|
#define CI_ENTRY(n,s,o) { s, o },
|
|
|
|
|
2016-04-22 21:39:21 +05:30
|
|
|
static const struct control_info control_info[] ALIGN2 = {
|
2007-11-24 10:02:49 +05:30
|
|
|
/* This should be verbatim cut-n-paste copy of the above CI_ENTRYs */
|
|
|
|
CI_ENTRY("intr", CINTR, VINTR )
|
|
|
|
CI_ENTRY("quit", CQUIT, VQUIT )
|
|
|
|
CI_ENTRY("erase", CERASE, VERASE )
|
|
|
|
CI_ENTRY("kill", CKILL, VKILL )
|
|
|
|
CI_ENTRY("eof", CEOF, VEOF )
|
|
|
|
CI_ENTRY("eol", CEOL, VEOL )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VEOL2
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("eol2", CEOL2, VEOL2 )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VSWTCH
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("swtch", CSWTCH, VSWTCH )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("start", CSTART, VSTART )
|
|
|
|
CI_ENTRY("stop", CSTOP, VSTOP )
|
|
|
|
CI_ENTRY("susp", CSUSP, VSUSP )
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VDSUSP
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("dsusp", CDSUSP, VDSUSP )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VREPRINT
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("rprnt", CRPRNT, VREPRINT)
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VWERASE
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("werase", CWERASE, VWERASE )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VLNEXT
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("lnext", CLNEXT, VLNEXT )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VFLUSHO
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("flush", CFLUSHO, VFLUSHO )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2010-07-30 09:31:37 +05:30
|
|
|
#if VSTATUS
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("status", CSTATUS, VSTATUS )
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2006-09-19 19:47:10 +05:30
|
|
|
/* These must be last because of the display routines */
|
2007-11-24 10:02:49 +05:30
|
|
|
CI_ENTRY("min", 1, VMIN )
|
|
|
|
CI_ENTRY("time", 0, VTIME )
|
2001-02-15 00:17:33 +05:30
|
|
|
};
|
|
|
|
|
2006-03-11 00:52:06 +05:30
|
|
|
enum {
|
2007-06-25 16:25:35 +05:30
|
|
|
NUM_control_info = ARRAY_SIZE(control_info)
|
2006-03-11 00:52:06 +05:30
|
|
|
};
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-04-04 19:29:49 +05:30
|
|
|
|
|
|
|
struct globals {
|
2009-12-11 19:30:17 +05:30
|
|
|
const char *device_name;
|
2007-11-24 10:02:49 +05:30
|
|
|
/* The width of the screen, for output wrapping */
|
2009-12-11 19:30:17 +05:30
|
|
|
unsigned max_col;
|
2007-04-04 19:29:49 +05:30
|
|
|
/* Current position, to know when to wrap */
|
|
|
|
unsigned current_col;
|
2010-02-04 19:30:15 +05:30
|
|
|
} FIX_ALIASING;
|
2016-04-21 19:56:30 +05:30
|
|
|
#define G (*(struct globals*)bb_common_bufsiz1)
|
2008-06-25 15:23:17 +05:30
|
|
|
#define INIT_G() do { \
|
2017-08-07 00:53:03 +05:30
|
|
|
setup_common_bufsiz(); \
|
2008-06-25 15:23:17 +05:30
|
|
|
G.device_name = bb_msg_standard_input; \
|
|
|
|
G.max_col = 80; \
|
2017-08-07 00:25:56 +05:30
|
|
|
G.current_col = 0; /* we are noexec, must clear */ \
|
2008-06-25 15:23:17 +05:30
|
|
|
} while (0)
|
2007-04-04 19:29:49 +05:30
|
|
|
|
2009-04-19 06:57:20 +05:30
|
|
|
static void set_speed_or_die(enum speed_setting type, const char *arg,
|
|
|
|
struct termios *mode)
|
2006-09-19 20:01:44 +05:30
|
|
|
{
|
|
|
|
speed_t baud;
|
|
|
|
|
2007-01-18 01:14:59 +05:30
|
|
|
baud = tty_value_to_baud(xatou(arg));
|
2006-09-19 20:01:44 +05:30
|
|
|
|
|
|
|
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 14:31:58 +05:30
|
|
|
|
2008-07-05 14:48:54 +05:30
|
|
|
static NORETURN void perror_on_device_and_die(const char *fmt)
|
2003-06-20 14:31:58 +05:30
|
|
|
{
|
2007-11-24 10:02:49 +05:30
|
|
|
bb_perror_msg_and_die(fmt, G.device_name);
|
2003-06-20 14:31:58 +05:30
|
|
|
}
|
|
|
|
|
2006-09-19 19:54:23 +05:30
|
|
|
static void perror_on_device(const char *fmt)
|
|
|
|
{
|
2007-11-24 10:02:49 +05:30
|
|
|
bb_perror_msg(fmt, G.device_name);
|
2006-09-19 19:54:23 +05:30
|
|
|
}
|
|
|
|
|
2001-02-15 00:17:33 +05:30
|
|
|
/* Print format string MESSAGE and optional args.
|
|
|
|
Wrap to next line first if it won't fit.
|
2006-09-19 19:47:10 +05:30
|
|
|
Print a space first unless MESSAGE will start a new line */
|
2001-02-15 00:17:33 +05:30
|
|
|
static void wrapf(const char *message, ...)
|
|
|
|
{
|
2006-09-19 19:49:42 +05:30
|
|
|
char buf[128];
|
2001-02-15 00:17:33 +05:30
|
|
|
va_list args;
|
2008-05-13 07:57:31 +05:30
|
|
|
unsigned buflen;
|
2001-02-15 00:17:33 +05:30
|
|
|
|
|
|
|
va_start(args, message);
|
2007-01-18 01:16:33 +05:30
|
|
|
buflen = vsnprintf(buf, sizeof(buf), message, args);
|
2001-02-15 00:17:33 +05:30
|
|
|
va_end(args);
|
2007-01-18 14:11:22 +05:30
|
|
|
/* We seem to be called only with suitable lengths, but check if
|
|
|
|
somebody failed to adhere to this assumption just to be sure. */
|
|
|
|
if (!buflen || buflen >= sizeof(buf)) return;
|
2006-09-19 19:49:42 +05:30
|
|
|
|
2007-04-04 19:29:49 +05:30
|
|
|
if (G.current_col > 0) {
|
|
|
|
G.current_col++;
|
2006-09-19 20:42:12 +05:30
|
|
|
if (buf[0] != '\n') {
|
2007-11-24 10:02:49 +05:30
|
|
|
if (G.current_col + buflen >= G.max_col) {
|
2007-04-04 19:29:49 +05:30
|
|
|
G.current_col = 0;
|
2017-09-18 15:46:47 +05:30
|
|
|
bb_putchar('\n');
|
|
|
|
} else {
|
2007-09-27 15:50:47 +05:30
|
|
|
bb_putchar(' ');
|
2017-09-18 15:46:47 +05:30
|
|
|
}
|
2006-09-19 20:42:12 +05:30
|
|
|
}
|
2001-02-15 00:17:33 +05:30
|
|
|
}
|
|
|
|
fputs(buf, stdout);
|
2007-04-04 19:29:49 +05:30
|
|
|
G.current_col += buflen;
|
2006-09-19 19:49:42 +05:30
|
|
|
if (buf[buflen-1] == '\n')
|
2007-04-04 19:29:49 +05:30
|
|
|
G.current_col = 0;
|
2001-02-15 00:17:33 +05:30
|
|
|
}
|
|
|
|
|
2009-12-11 19:30:17 +05:30
|
|
|
static void newline(void)
|
|
|
|
{
|
|
|
|
if (G.current_col != 0)
|
|
|
|
wrapf("\n");
|
|
|
|
}
|
|
|
|
|
2010-07-30 09:31:37 +05:30
|
|
|
#ifdef TIOCGWINSZ
|
2009-12-11 19:30:17 +05:30
|
|
|
static void set_window_size(int rows, int cols)
|
2006-09-19 20:01:44 +05:30
|
|
|
{
|
2007-11-24 10:02:49 +05:30
|
|
|
struct winsize win = { 0, 0, 0, 0 };
|
2006-09-19 20:01:44 +05:30
|
|
|
|
2007-01-18 01:15:36 +05:30
|
|
|
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &win)) {
|
2006-09-19 20:01:44 +05:30
|
|
|
if (errno != EINVAL) {
|
2007-01-18 01:15:36 +05:30
|
|
|
goto bail;
|
2006-09-19 20:01:44 +05:30
|
|
|
}
|
|
|
|
memset(&win, 0, sizeof(win));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rows >= 0)
|
|
|
|
win.ws_row = rows;
|
|
|
|
if (cols >= 0)
|
|
|
|
win.ws_col = cols;
|
|
|
|
|
|
|
|
if (ioctl(STDIN_FILENO, TIOCSWINSZ, (char *) &win))
|
2007-01-18 01:15:36 +05:30
|
|
|
bail:
|
2006-09-19 20:01:44 +05:30
|
|
|
perror_on_device("%s");
|
|
|
|
}
|
2010-07-30 09:31:37 +05:30
|
|
|
#endif
|
2006-09-19 20:01:44 +05:30
|
|
|
|
2009-12-11 19:30:17 +05:30
|
|
|
static void display_window_size(int fancy)
|
2006-09-19 20:01:44 +05:30
|
|
|
{
|
|
|
|
const char *fmt_str = "%s\0%s: no size information for this device";
|
2007-01-18 01:15:36 +05:30
|
|
|
unsigned width, height;
|
2006-09-19 20:01:44 +05:30
|
|
|
|
2007-01-18 01:15:36 +05:30
|
|
|
if (get_terminal_width_height(STDIN_FILENO, &width, &height)) {
|
2006-09-19 20:01:44 +05:30
|
|
|
if ((errno != EINVAL) || ((fmt_str += 2), !fancy)) {
|
|
|
|
perror_on_device(fmt_str);
|
|
|
|
}
|
|
|
|
} else {
|
2009-12-11 19:30:17 +05:30
|
|
|
wrapf(fancy ? "rows %u; columns %u;" : "%u %u\n",
|
2007-01-18 01:15:36 +05:30
|
|
|
height, width);
|
2006-09-19 20:01:44 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-15 00:17:33 +05:30
|
|
|
static const struct suffix_mult stty_suffixes[] = {
|
2007-07-27 20:36:25 +05:30
|
|
|
{ "b", 512 },
|
|
|
|
{ "k", 1024 },
|
|
|
|
{ "B", 1024 },
|
2009-09-06 16:17:55 +05:30
|
|
|
{ "", 0 }
|
2001-02-15 00:17:33 +05:30
|
|
|
};
|
|
|
|
|
2006-09-19 19:46:28 +05:30
|
|
|
static const struct mode_info *find_mode(const char *name)
|
|
|
|
{
|
2008-01-28 04:54:31 +05:30
|
|
|
int i = index_in_strings(mode_name, name);
|
|
|
|
return i >= 0 ? &mode_info[i] : NULL;
|
2006-09-19 19:46:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static const struct control_info *find_control(const char *name)
|
|
|
|
{
|
2008-01-28 04:54:31 +05:30
|
|
|
int i = index_in_strings(control_name, name);
|
|
|
|
return i >= 0 ? &control_info[i] : NULL;
|
2006-09-19 19:46:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
|
|
|
param_need_arg = 0x80,
|
2007-04-20 01:25:54 +05:30
|
|
|
param_line = 1 | 0x80,
|
|
|
|
param_rows = 2 | 0x80,
|
|
|
|
param_cols = 3 | 0x80,
|
|
|
|
param_columns = 4 | 0x80,
|
|
|
|
param_size = 5,
|
|
|
|
param_speed = 6,
|
|
|
|
param_ispeed = 7 | 0x80,
|
|
|
|
param_ospeed = 8 | 0x80,
|
2006-09-19 19:46:28 +05:30
|
|
|
};
|
|
|
|
|
2009-04-19 06:57:20 +05:30
|
|
|
static int find_param(const char *name)
|
2006-09-19 19:46:28 +05:30
|
|
|
{
|
2007-08-13 02:28:27 +05:30
|
|
|
static const char params[] ALIGN1 =
|
2007-07-24 21:24:42 +05:30
|
|
|
"line\0" /* 1 */
|
|
|
|
"rows\0" /* 2 */
|
|
|
|
"cols\0" /* 3 */
|
|
|
|
"columns\0" /* 4 */
|
|
|
|
"size\0" /* 5 */
|
|
|
|
"speed\0" /* 6 */
|
|
|
|
"ispeed\0"
|
|
|
|
"ospeed\0";
|
|
|
|
int i = index_in_strings(params, name) + 1;
|
2007-04-04 19:29:49 +05:30
|
|
|
if (i == 0)
|
2007-02-04 16:43:57 +05:30
|
|
|
return 0;
|
2007-04-20 01:25:54 +05:30
|
|
|
if (i != 5 && i != 6)
|
2007-02-04 16:43:57 +05:30
|
|
|
i |= 0x80;
|
2007-01-18 01:15:14 +05:30
|
|
|
return i;
|
2006-09-19 19:46:28 +05:30
|
|
|
}
|
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
static int recover_mode(const char *arg, struct termios *mode)
|
2001-02-15 00:17:33 +05:30
|
|
|
{
|
2007-01-13 02:32:04 +05:30
|
|
|
int i, n;
|
2007-04-08 21:37:02 +05:30
|
|
|
unsigned chr;
|
2007-01-13 02:32:04 +05:30
|
|
|
unsigned long iflag, oflag, cflag, lflag;
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
/* Scan into temporaries since it is too much trouble to figure out
|
|
|
|
the right format for 'tcflag_t' */
|
|
|
|
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;
|
2001-02-15 00:17:33 +05:30
|
|
|
}
|
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
/* Fail if there are too many fields */
|
|
|
|
if (*arg != '\0')
|
|
|
|
return 0;
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
return 1;
|
|
|
|
}
|
2006-09-19 19:46:28 +05:30
|
|
|
|
2007-01-18 01:16:12 +05:30
|
|
|
static void display_recoverable(const struct termios *mode,
|
2008-07-05 14:48:54 +05:30
|
|
|
int UNUSED_PARAM dummy)
|
2007-01-13 02:32:04 +05:30
|
|
|
{
|
|
|
|
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]);
|
2007-09-27 15:50:47 +05:30
|
|
|
bb_putchar('\n');
|
2007-01-13 02:32:04 +05:30
|
|
|
}
|
2001-03-03 01:30:54 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
static void display_speed(const struct termios *mode, int fancy)
|
|
|
|
{
|
2009-12-11 19:30:17 +05:30
|
|
|
//____________________ 01234567 8 9
|
2007-01-13 02:32:04 +05:30
|
|
|
const char *fmt_str = "%lu %lu\n\0ispeed %lu baud; ospeed %lu baud;";
|
|
|
|
unsigned long ispeed, ospeed;
|
2001-03-03 01:30:54 +05:30
|
|
|
|
2011-01-24 23:00:35 +05:30
|
|
|
ispeed = cfgetispeed(mode);
|
|
|
|
ospeed = cfgetospeed(mode);
|
|
|
|
if (ispeed == 0 || ispeed == ospeed) {
|
2007-01-13 02:32:04 +05:30
|
|
|
ispeed = ospeed; /* in case ispeed was 0 */
|
2009-12-11 19:30:17 +05:30
|
|
|
//________ 0123 4 5 6 7 8 9
|
2007-01-13 02:32:04 +05:30
|
|
|
fmt_str = "%lu\n\0\0\0\0\0speed %lu baud;";
|
|
|
|
}
|
|
|
|
if (fancy) fmt_str += 9;
|
|
|
|
wrapf(fmt_str, tty_baud_to_value(ispeed), tty_baud_to_value(ospeed));
|
|
|
|
}
|
2006-09-19 19:46:28 +05:30
|
|
|
|
2009-12-11 19:30:17 +05:30
|
|
|
static void do_display(const struct termios *mode, int all)
|
2007-01-13 02:32:04 +05:30
|
|
|
{
|
|
|
|
int i;
|
|
|
|
tcflag_t *bitsp;
|
|
|
|
unsigned long mask;
|
|
|
|
int prev_type = control;
|
2006-09-19 19:46:28 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
display_speed(mode, 1);
|
2007-01-18 01:16:12 +05:30
|
|
|
if (all)
|
|
|
|
display_window_size(1);
|
2011-01-24 23:00:35 +05:30
|
|
|
#ifdef __linux__
|
2009-12-11 19:30:17 +05:30
|
|
|
wrapf("line = %u;\n", mode->c_line);
|
2007-01-13 02:32:04 +05:30
|
|
|
#else
|
2009-12-11 19:30:17 +05:30
|
|
|
newline();
|
2006-09-19 19:46:28 +05:30
|
|
|
#endif
|
2007-01-13 02:32:04 +05:30
|
|
|
|
2007-10-11 21:32:36 +05:30
|
|
|
for (i = 0; i != CIDX_min; ++i) {
|
2013-07-30 09:59:42 +05:30
|
|
|
char ch;
|
2017-08-07 00:25:56 +05:30
|
|
|
char buf10[10];
|
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
/* If swtch is the same as susp, don't print both */
|
|
|
|
#if VSWTCH == VSUSP
|
2007-10-11 21:32:36 +05:30
|
|
|
if (i == CIDX_swtch)
|
2007-01-13 02:32:04 +05:30
|
|
|
continue;
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2007-01-13 02:32:04 +05:30
|
|
|
/* If eof uses the same slot as min, only print whichever applies */
|
|
|
|
#if VEOF == VMIN
|
2009-12-11 19:30:17 +05:30
|
|
|
if (!(mode->c_lflag & ICANON)
|
2007-10-11 21:32:36 +05:30
|
|
|
&& (i == CIDX_eof || i == CIDX_eol)
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-01-13 02:32:04 +05:30
|
|
|
#endif
|
2013-07-30 09:59:42 +05:30
|
|
|
ch = mode->c_cc[control_info[i].offset];
|
|
|
|
if (ch == _POSIX_VDISABLE)
|
2017-08-07 00:25:56 +05:30
|
|
|
strcpy(buf10, "<undef>");
|
2013-07-30 09:59:42 +05:30
|
|
|
else
|
2017-08-07 00:25:56 +05:30
|
|
|
visible(ch, buf10, 0);
|
|
|
|
wrapf("%s = %s;", nth_string(control_name, i), buf10);
|
2001-02-15 00:17:33 +05:30
|
|
|
}
|
2007-01-13 02:32:04 +05:30
|
|
|
#if VEOF == VMIN
|
|
|
|
if ((mode->c_lflag & ICANON) == 0)
|
|
|
|
#endif
|
2009-12-11 19:30:17 +05:30
|
|
|
wrapf("min = %u; time = %u;", mode->c_cc[VMIN], mode->c_cc[VTIME]);
|
|
|
|
newline();
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
for (i = 0; i < NUM_mode_info; ++i) {
|
|
|
|
if (mode_info[i].flags & OMIT)
|
|
|
|
continue;
|
|
|
|
if (mode_info[i].type != prev_type) {
|
2009-12-11 19:30:17 +05:30
|
|
|
newline();
|
2007-01-13 02:32:04 +05:30
|
|
|
prev_type = mode_info[i].type;
|
|
|
|
}
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2013-05-17 21:36:49 +05:30
|
|
|
bitsp = get_ptr_to_tcflag(mode_info[i].type, mode);
|
2007-01-13 02:32:04 +05:30
|
|
|
mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits;
|
2007-01-18 01:16:12 +05:30
|
|
|
if ((*bitsp & mask) == mode_info[i].bits) {
|
|
|
|
if (all || (mode_info[i].flags & SANE_UNSET))
|
2007-11-24 10:02:49 +05:30
|
|
|
wrapf("-%s"+1, nth_string(mode_name, i));
|
2007-01-18 01:16:12 +05:30
|
|
|
} else {
|
2007-11-24 10:02:49 +05:30
|
|
|
if ((all && mode_info[i].flags & REV)
|
|
|
|
|| (!all && (mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV))
|
|
|
|
) {
|
|
|
|
wrapf("-%s", nth_string(mode_name, i));
|
|
|
|
}
|
2007-01-18 01:16:12 +05:30
|
|
|
}
|
2007-01-13 02:32:04 +05:30
|
|
|
}
|
2009-12-11 19:30:17 +05:30
|
|
|
newline();
|
2007-01-13 02:32:04 +05:30
|
|
|
}
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
static void sane_mode(struct termios *mode)
|
|
|
|
{
|
|
|
|
int i;
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
for (i = 0; i < NUM_control_info; ++i) {
|
|
|
|
#if VMIN == VEOF
|
2007-10-11 21:32:36 +05:30
|
|
|
if (i == CIDX_min)
|
2007-01-13 02:32:04 +05:30
|
|
|
break;
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2007-01-13 02:32:04 +05:30
|
|
|
mode->c_cc[control_info[i].offset] = control_info[i].saneval;
|
2001-02-15 00:17:33 +05:30
|
|
|
}
|
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
for (i = 0; i < NUM_mode_info; ++i) {
|
2013-05-17 21:36:49 +05:30
|
|
|
tcflag_t val;
|
|
|
|
tcflag_t *bitsp = get_ptr_to_tcflag(mode_info[i].type, mode);
|
|
|
|
|
|
|
|
if (!bitsp)
|
|
|
|
continue;
|
|
|
|
val = *bitsp & ~((unsigned long)mode_info[i].mask);
|
2007-01-13 02:32:04 +05:30
|
|
|
if (mode_info[i].flags & SANE_SET) {
|
2013-05-17 21:36:49 +05:30
|
|
|
*bitsp = val | mode_info[i].bits;
|
|
|
|
} else
|
|
|
|
if (mode_info[i].flags & SANE_UNSET) {
|
|
|
|
*bitsp = val & ~mode_info[i].bits;
|
2007-01-13 02:32:04 +05:30
|
|
|
}
|
|
|
|
}
|
2001-02-15 00:17:33 +05:30
|
|
|
}
|
|
|
|
|
2006-09-19 20:01:44 +05:30
|
|
|
static void set_mode(const struct mode_info *info, int reversed,
|
|
|
|
struct termios *mode)
|
2001-02-15 00:17:33 +05:30
|
|
|
{
|
|
|
|
tcflag_t *bitsp;
|
|
|
|
|
2013-05-17 21:36:49 +05:30
|
|
|
bitsp = get_ptr_to_tcflag(info->type, mode);
|
2006-09-19 19:54:23 +05:30
|
|
|
|
|
|
|
if (bitsp) {
|
2013-05-17 21:36:49 +05:30
|
|
|
tcflag_t val = *bitsp & ~info->mask;
|
2006-09-19 19:54:23 +05:30
|
|
|
if (reversed)
|
2013-05-17 21:36:49 +05:30
|
|
|
*bitsp = val & ~info->bits;
|
2006-09-19 19:54:23 +05:30
|
|
|
else
|
2013-05-17 21:36:49 +05:30
|
|
|
*bitsp = val | info->bits;
|
2006-09-19 19:54:23 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-17 21:36:49 +05:30
|
|
|
/* !bitsp - it's a "combination" mode */
|
2007-10-11 21:32:36 +05:30
|
|
|
if (info == &mode_info[IDX_evenp] || info == &mode_info[IDX_parity]) {
|
2006-09-19 19:54:23 +05:30
|
|
|
if (reversed)
|
|
|
|
mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;
|
|
|
|
else
|
2010-10-28 22:27:19 +05:30
|
|
|
mode->c_cflag = (mode->c_cflag & ~PARODD & ~CSIZE) | PARENB | CS7;
|
2007-10-11 21:32:36 +05:30
|
|
|
} else if (info == &mode_info[IDX_oddp]) {
|
2006-09-19 19:54:23 +05:30
|
|
|
if (reversed)
|
|
|
|
mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;
|
|
|
|
else
|
2010-10-28 22:27:19 +05:30
|
|
|
mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARODD | PARENB;
|
2007-10-11 21:32:36 +05:30
|
|
|
} else if (info == &mode_info[IDX_nl]) {
|
2006-09-19 19:54:23 +05:30
|
|
|
if (reversed) {
|
|
|
|
mode->c_iflag = (mode->c_iflag | ICRNL) & ~INLCR & ~IGNCR;
|
2010-10-28 22:27:19 +05:30
|
|
|
mode->c_oflag = (mode->c_oflag | ONLCR) & ~OCRNL & ~ONLRET;
|
2006-09-19 19:54:23 +05:30
|
|
|
} else {
|
|
|
|
mode->c_iflag = mode->c_iflag & ~ICRNL;
|
|
|
|
if (ONLCR) mode->c_oflag = mode->c_oflag & ~ONLCR;
|
2001-02-15 00:17:33 +05:30
|
|
|
}
|
2007-10-11 21:32:36 +05:30
|
|
|
} else if (info == &mode_info[IDX_ek]) {
|
2006-09-19 19:54:23 +05:30
|
|
|
mode->c_cc[VERASE] = CERASE;
|
|
|
|
mode->c_cc[VKILL] = CKILL;
|
2007-10-11 21:32:36 +05:30
|
|
|
} else if (info == &mode_info[IDX_sane]) {
|
2006-09-19 19:54:23 +05:30
|
|
|
sane_mode(mode);
|
2007-10-11 21:32:36 +05:30
|
|
|
} else if (info == &mode_info[IDX_cbreak]) {
|
2006-09-19 19:54:23 +05:30
|
|
|
if (reversed)
|
|
|
|
mode->c_lflag |= ICANON;
|
|
|
|
else
|
|
|
|
mode->c_lflag &= ~ICANON;
|
2007-10-11 21:32:36 +05:30
|
|
|
} else if (info == &mode_info[IDX_pass8]) {
|
2006-09-19 19:54:23 +05:30
|
|
|
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-15 00:17:33 +05:30
|
|
|
}
|
2007-10-11 21:32:36 +05:30
|
|
|
} else if (info == &mode_info[IDX_litout]) {
|
2006-09-19 19:54:23 +05:30
|
|
|
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-15 00:17:33 +05:30
|
|
|
}
|
2007-10-11 21:32:36 +05:30
|
|
|
} else if (info == &mode_info[IDX_raw] || info == &mode_info[IDX_cooked]) {
|
2007-11-24 10:02:49 +05:30
|
|
|
if ((info == &mode_info[IDX_raw] && reversed)
|
|
|
|
|| (info == &mode_info[IDX_cooked] && !reversed)
|
2007-10-11 21:32:36 +05:30
|
|
|
) {
|
2006-09-19 19:54:23 +05:30
|
|
|
/* 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-15 00:17:33 +05:30
|
|
|
}
|
2006-09-19 19:54:23 +05:30
|
|
|
}
|
2010-07-30 09:31:37 +05:30
|
|
|
#if IXANY
|
|
|
|
else if (info == &mode_info[IDX_decctlq]) {
|
2006-09-19 19:54:23 +05:30
|
|
|
if (reversed)
|
|
|
|
mode->c_iflag |= IXANY;
|
|
|
|
else
|
|
|
|
mode->c_iflag &= ~IXANY;
|
|
|
|
}
|
2010-07-30 09:31:37 +05:30
|
|
|
#endif
|
|
|
|
#if TABDLY
|
|
|
|
else if (info == &mode_info[IDX_tabs]) {
|
2006-09-19 19:54:23 +05:30
|
|
|
if (reversed)
|
|
|
|
mode->c_oflag = (mode->c_oflag & ~TABDLY) | TAB3;
|
|
|
|
else
|
|
|
|
mode->c_oflag = (mode->c_oflag & ~TABDLY) | TAB0;
|
|
|
|
}
|
2010-07-30 09:31:37 +05:30
|
|
|
#endif
|
|
|
|
#if OXTABS
|
|
|
|
else if (info == &mode_info[IDX_tabs]) {
|
2006-09-19 19:54:23 +05:30
|
|
|
if (reversed)
|
|
|
|
mode->c_oflag |= OXTABS;
|
|
|
|
else
|
|
|
|
mode->c_oflag &= ~OXTABS;
|
2010-07-30 09:31:37 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if XCASE && IUCLC && OLCUC
|
|
|
|
else if (info==&mode_info[IDX_lcase] || info==&mode_info[IDX_LCASE]) {
|
2006-09-19 19:54:23 +05:30
|
|
|
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-15 00:17:33 +05:30
|
|
|
}
|
2010-07-30 09:31:37 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else if (info == &mode_info[IDX_crt]) {
|
2006-09-19 19:54:23 +05:30
|
|
|
mode->c_lflag |= ECHOE | ECHOCTL | ECHOKE;
|
2007-10-11 21:32:36 +05:30
|
|
|
} else if (info == &mode_info[IDX_dec]) {
|
2006-09-19 19:54:23 +05:30
|
|
|
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-15 00:17:33 +05:30
|
|
|
}
|
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
static void set_control_char_or_die(const struct control_info *info,
|
|
|
|
const char *arg, struct termios *mode)
|
|
|
|
{
|
|
|
|
unsigned char value;
|
|
|
|
|
2007-10-11 21:32:36 +05:30
|
|
|
if (info == &control_info[CIDX_min] || info == &control_info[CIDX_time])
|
2007-01-13 02:32:04 +05:30
|
|
|
value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes);
|
|
|
|
else if (arg[0] == '\0' || arg[1] == '\0')
|
|
|
|
value = arg[0];
|
2009-12-11 19:30:17 +05:30
|
|
|
else if (strcmp(arg, "^-") == 0 || strcmp(arg, "undef") == 0)
|
2007-01-13 02:32:04 +05:30
|
|
|
value = _POSIX_VDISABLE;
|
|
|
|
else if (arg[0] == '^') { /* Ignore any trailing junk (^Cjunk) */
|
|
|
|
value = arg[1] & 0x1f; /* Non-letters get weird results */
|
|
|
|
if (arg[1] == '?')
|
|
|
|
value = 127;
|
|
|
|
} else
|
|
|
|
value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes);
|
|
|
|
mode->c_cc[info->offset] = value;
|
|
|
|
}
|
|
|
|
|
2007-11-24 10:02:49 +05:30
|
|
|
#define STTY_require_set_attr (1 << 0)
|
|
|
|
#define STTY_speed_was_set (1 << 1)
|
|
|
|
#define STTY_verbose_output (1 << 2)
|
|
|
|
#define STTY_recoverable_output (1 << 3)
|
|
|
|
#define STTY_noargs (1 << 4)
|
|
|
|
|
2007-10-11 15:35:36 +05:30
|
|
|
int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2009-11-28 19:48:53 +05:30
|
|
|
int stty_main(int argc UNUSED_PARAM, char **argv)
|
2007-01-13 02:32:04 +05:30
|
|
|
{
|
|
|
|
struct termios mode;
|
2009-12-11 19:30:17 +05:30
|
|
|
void (*output_func)(const struct termios *, int);
|
2007-01-13 02:32:04 +05:30
|
|
|
const char *file_name = NULL;
|
2007-01-18 01:16:12 +05:30
|
|
|
int display_all = 0;
|
2007-01-18 06:23:35 +05:30
|
|
|
int stty_state;
|
|
|
|
int k;
|
|
|
|
|
2007-11-24 10:02:49 +05:30
|
|
|
INIT_G();
|
|
|
|
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state = STTY_noargs;
|
2007-01-18 01:16:12 +05:30
|
|
|
output_func = do_display;
|
2007-01-13 02:32:04 +05:30
|
|
|
|
|
|
|
/* 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))
|
2007-01-18 01:12:30 +05:30
|
|
|
goto invalid_argument;
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state &= ~STTY_noargs;
|
2007-01-13 02:32:04 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* It is an option - parse it */
|
|
|
|
i = 0;
|
|
|
|
while (arg[++i]) {
|
|
|
|
switch (arg[i]) {
|
|
|
|
case 'a':
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state |= STTY_verbose_output;
|
2007-01-18 01:16:12 +05:30
|
|
|
output_func = do_display;
|
|
|
|
display_all = 1;
|
2007-01-13 02:32:04 +05:30
|
|
|
break;
|
|
|
|
case 'g':
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state |= STTY_recoverable_output;
|
2007-01-13 02:32:04 +05:30
|
|
|
output_func = display_recoverable;
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
if (file_name)
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("only one device may be specified");
|
2007-01-13 02:32:04 +05:30
|
|
|
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] */
|
2009-11-28 19:48:53 +05:30
|
|
|
while (argv[p]) {
|
|
|
|
argv[p] = argv[p+1];
|
|
|
|
++p;
|
|
|
|
}
|
2007-01-13 02:32:04 +05:30
|
|
|
}
|
|
|
|
goto end_option;
|
|
|
|
default:
|
2007-01-18 01:12:30 +05:30
|
|
|
goto invalid_argument;
|
2007-01-13 02:32:04 +05:30
|
|
|
}
|
|
|
|
}
|
2007-04-08 21:37:02 +05:30
|
|
|
end_option:
|
2007-01-13 02:32:04 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
mp = find_mode(arg);
|
|
|
|
if (mp) {
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state &= ~STTY_noargs;
|
2007-01-13 02:32:04 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
cp = find_control(arg);
|
|
|
|
if (cp) {
|
|
|
|
if (!argnext)
|
|
|
|
bb_error_msg_and_die(bb_msg_requires_arg, arg);
|
|
|
|
/* called for the side effect of xfunc death only */
|
|
|
|
set_control_char_or_die(cp, argnext, &mode);
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state &= ~STTY_noargs;
|
2007-01-13 02:32:04 +05:30
|
|
|
++k;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
param = find_param(arg);
|
|
|
|
if (param & param_need_arg) {
|
|
|
|
if (!argnext)
|
|
|
|
bb_error_msg_and_die(bb_msg_requires_arg, arg);
|
|
|
|
++k;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (param) {
|
2011-01-24 23:00:35 +05:30
|
|
|
#ifdef __linux__
|
2007-01-13 02:32:04 +05:30
|
|
|
case param_line:
|
|
|
|
# ifndef TIOCGWINSZ
|
|
|
|
xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes);
|
|
|
|
break;
|
|
|
|
# endif /* else fall-through */
|
|
|
|
#endif
|
|
|
|
#ifdef TIOCGWINSZ
|
|
|
|
case param_rows:
|
|
|
|
case param_cols:
|
2007-04-20 01:25:54 +05:30
|
|
|
case param_columns:
|
2007-01-13 02:32:04 +05:30
|
|
|
xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes);
|
|
|
|
break;
|
|
|
|
case param_size:
|
|
|
|
#endif
|
|
|
|
case param_speed:
|
|
|
|
break;
|
|
|
|
case param_ispeed:
|
|
|
|
/* called for the side effect of xfunc death only */
|
|
|
|
set_speed_or_die(input_speed, argnext, &mode);
|
|
|
|
break;
|
|
|
|
case param_ospeed:
|
|
|
|
/* called for the side effect of xfunc death only */
|
|
|
|
set_speed_or_die(output_speed, argnext, &mode);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (recover_mode(arg, &mode) == 1) break;
|
2007-01-18 01:14:59 +05:30
|
|
|
if (tty_value_to_baud(xatou(arg)) != (speed_t) -1) break;
|
2007-04-08 21:37:02 +05:30
|
|
|
invalid_argument:
|
2007-01-13 02:32:04 +05:30
|
|
|
bb_error_msg_and_die("invalid argument '%s'", arg);
|
|
|
|
}
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state &= ~STTY_noargs;
|
2007-01-13 02:32:04 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/* Specifying both -a and -g is an error */
|
2007-01-18 06:23:35 +05:30
|
|
|
if ((stty_state & (STTY_verbose_output | STTY_recoverable_output)) ==
|
2011-10-21 23:15:13 +05:30
|
|
|
(STTY_verbose_output | STTY_recoverable_output)
|
|
|
|
) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("-a and -g are mutually exclusive");
|
2011-10-21 23:15:13 +05:30
|
|
|
}
|
2007-01-13 02:32:04 +05:30
|
|
|
/* Specifying -a or -g with non-options is an error */
|
2011-10-21 23:15:13 +05:30
|
|
|
if ((stty_state & (STTY_verbose_output | STTY_recoverable_output))
|
|
|
|
&& !(stty_state & STTY_noargs)
|
2009-12-11 19:30:17 +05:30
|
|
|
) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("modes may not be set when -a or -g is used");
|
2009-12-11 19:30:17 +05:30
|
|
|
}
|
2007-01-13 02:32:04 +05:30
|
|
|
|
|
|
|
/* Now it is safe to start doing things */
|
|
|
|
if (file_name) {
|
2007-11-24 10:02:49 +05:30
|
|
|
G.device_name = file_name;
|
2009-11-12 01:35:42 +05:30
|
|
|
xmove_fd(xopen_nonblocking(G.device_name), STDIN_FILENO);
|
|
|
|
ndelay_off(STDIN_FILENO);
|
2001-02-15 00:17:33 +05:30
|
|
|
}
|
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
/* Initialize to all zeroes so there is no risk memcmp will report a
|
|
|
|
spurious difference in an uninitialized portion of the structure */
|
|
|
|
memset(&mode, 0, sizeof(mode));
|
|
|
|
if (tcgetattr(STDIN_FILENO, &mode))
|
|
|
|
perror_on_device_and_die("%s");
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-18 06:23:35 +05:30
|
|
|
if (stty_state & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) {
|
2015-10-23 05:14:22 +05:30
|
|
|
G.max_col = get_terminal_width(STDOUT_FILENO);
|
2007-01-18 01:16:12 +05:30
|
|
|
output_func(&mode, display_all);
|
2007-01-13 02:32:04 +05:30
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
/* Second pass: perform actions */
|
|
|
|
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] == '-') {
|
|
|
|
mp = find_mode(arg+1);
|
|
|
|
if (mp) {
|
|
|
|
set_mode(mp, 1 /* reversed */, &mode);
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state |= STTY_require_set_attr;
|
2007-01-13 02:32:04 +05:30
|
|
|
}
|
|
|
|
/* It is an option - already parsed. Skip it */
|
2001-02-15 00:17:33 +05:30
|
|
|
continue;
|
2007-01-13 02:32:04 +05:30
|
|
|
}
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
mp = find_mode(arg);
|
|
|
|
if (mp) {
|
|
|
|
set_mode(mp, 0 /* non-reversed */, &mode);
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state |= STTY_require_set_attr;
|
2001-02-15 00:17:33 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
cp = find_control(arg);
|
|
|
|
if (cp) {
|
|
|
|
++k;
|
|
|
|
set_control_char_or_die(cp, argnext, &mode);
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state |= STTY_require_set_attr;
|
2007-01-13 02:32:04 +05:30
|
|
|
continue;
|
|
|
|
}
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
param = find_param(arg);
|
|
|
|
if (param & param_need_arg) {
|
|
|
|
++k;
|
|
|
|
}
|
2003-03-19 14:43:01 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
switch (param) {
|
2011-01-24 23:00:35 +05:30
|
|
|
#ifdef __linux__
|
2007-01-13 02:32:04 +05:30
|
|
|
case param_line:
|
|
|
|
mode.c_line = xatoul_sfx(argnext, stty_suffixes);
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state |= STTY_require_set_attr;
|
2007-01-13 02:32:04 +05:30
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef TIOCGWINSZ
|
|
|
|
case param_cols:
|
2009-12-11 18:47:02 +05:30
|
|
|
case param_columns:
|
2007-01-13 02:32:04 +05:30
|
|
|
set_window_size(-1, xatoul_sfx(argnext, stty_suffixes));
|
|
|
|
break;
|
|
|
|
case param_size:
|
|
|
|
display_window_size(0);
|
|
|
|
break;
|
|
|
|
case param_rows:
|
|
|
|
set_window_size(xatoul_sfx(argnext, stty_suffixes), -1);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case param_speed:
|
|
|
|
display_speed(&mode, 0);
|
|
|
|
break;
|
|
|
|
case param_ispeed:
|
|
|
|
set_speed_or_die(input_speed, argnext, &mode);
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state |= (STTY_require_set_attr | STTY_speed_was_set);
|
2007-01-13 02:32:04 +05:30
|
|
|
break;
|
|
|
|
case param_ospeed:
|
|
|
|
set_speed_or_die(output_speed, argnext, &mode);
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state |= (STTY_require_set_attr | STTY_speed_was_set);
|
2007-01-13 02:32:04 +05:30
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (recover_mode(arg, &mode) == 1)
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state |= STTY_require_set_attr;
|
2007-01-18 01:14:59 +05:30
|
|
|
else /* true: if (tty_value_to_baud(xatou(arg)) != (speed_t) -1) */{
|
2007-01-13 02:32:04 +05:30
|
|
|
set_speed_or_die(both_speeds, arg, &mode);
|
2007-01-18 06:23:35 +05:30
|
|
|
stty_state |= (STTY_require_set_attr | STTY_speed_was_set);
|
2007-01-13 02:32:04 +05:30
|
|
|
} /* else - impossible (caught in the first pass):
|
|
|
|
bb_error_msg_and_die("invalid argument '%s'", arg); */
|
|
|
|
}
|
2003-03-19 14:43:01 +05:30
|
|
|
}
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-18 06:23:35 +05:30
|
|
|
if (stty_state & STTY_require_set_attr) {
|
2007-01-13 02:32:04 +05:30
|
|
|
struct termios new_mode;
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
if (tcsetattr(STDIN_FILENO, TCSADRAIN, &mode))
|
|
|
|
perror_on_device_and_die("%s");
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
/* POSIX (according to Zlotnick's book) tcsetattr returns zero if
|
|
|
|
it performs *any* of the requested operations. This means it
|
|
|
|
can report 'success' when it has actually failed to perform
|
|
|
|
some proper subset of the requested operations. To detect
|
|
|
|
this partial failure, get the current terminal attributes and
|
|
|
|
compare them to the requested ones */
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
/* Initialize to all zeroes so there is no risk memcmp will report a
|
|
|
|
spurious difference in an uninitialized portion of the structure */
|
|
|
|
memset(&new_mode, 0, sizeof(new_mode));
|
|
|
|
if (tcgetattr(STDIN_FILENO, &new_mode))
|
|
|
|
perror_on_device_and_die("%s");
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
if (memcmp(&mode, &new_mode, sizeof(mode)) != 0) {
|
2013-05-17 23:38:12 +05:30
|
|
|
/*
|
|
|
|
* I think the below chunk is not necessary on Linux.
|
|
|
|
* If you are deleting it, also delete STTY_speed_was_set bit -
|
|
|
|
* it is only ever checked here.
|
|
|
|
*/
|
|
|
|
#if 0 /* was "if CIBAUD" */
|
2007-01-13 02:32:04 +05:30
|
|
|
/* 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
|
|
|
|
error for a true failure to set the baud rate */
|
2001-02-15 00:17:33 +05:30
|
|
|
|
2007-01-13 02:32:04 +05:30
|
|
|
new_mode.c_cflag &= (~CIBAUD);
|
2007-01-18 06:23:35 +05:30
|
|
|
if ((stty_state & STTY_speed_was_set)
|
|
|
|
|| memcmp(&mode, &new_mode, sizeof(mode)) != 0)
|
2001-02-15 00:17:33 +05:30
|
|
|
#endif
|
2007-01-13 02:32:04 +05:30
|
|
|
perror_on_device_and_die("%s: cannot perform all requested operations");
|
2001-02-15 00:17:33 +05:30
|
|
|
}
|
|
|
|
}
|
2007-01-13 02:32:04 +05:30
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2001-02-15 00:17:33 +05:30
|
|
|
}
|