mirror of
https://github.com/sheumann/hush.git
synced 2025-03-11 18:30:22 +00:00
stty: style fixes
This commit is contained in:
parent
7eab79acc5
commit
9efb070dcb
193
coreutils/stty.c
193
coreutils/stty.c
@ -23,17 +23,14 @@
|
|||||||
|
|
||||||
#include "busybox.h"
|
#include "busybox.h"
|
||||||
|
|
||||||
#define STREQ(a, b) (strcmp ((a), (b)) == 0)
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef _POSIX_VDISABLE
|
#ifndef _POSIX_VDISABLE
|
||||||
# define _POSIX_VDISABLE ((unsigned char) 0)
|
# define _POSIX_VDISABLE ((unsigned char) 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define Control(c) ((c) & 0x1f)
|
#define Control(c) ((c) & 0x1f)
|
||||||
/* Canonical values for control characters. */
|
/* Canonical values for control characters */
|
||||||
#ifndef CINTR
|
#ifndef CINTR
|
||||||
# define CINTR Control ('c')
|
# define CINTR Control('c')
|
||||||
#endif
|
#endif
|
||||||
#ifndef CQUIT
|
#ifndef CQUIT
|
||||||
# define CQUIT 28
|
# define CQUIT 28
|
||||||
@ -42,27 +39,27 @@
|
|||||||
# define CERASE 127
|
# define CERASE 127
|
||||||
#endif
|
#endif
|
||||||
#ifndef CKILL
|
#ifndef CKILL
|
||||||
# define CKILL Control ('u')
|
# define CKILL Control('u')
|
||||||
#endif
|
#endif
|
||||||
#ifndef CEOF
|
#ifndef CEOF
|
||||||
# define CEOF Control ('d')
|
# define CEOF Control('d')
|
||||||
#endif
|
#endif
|
||||||
#ifndef CEOL
|
#ifndef CEOL
|
||||||
# define CEOL _POSIX_VDISABLE
|
# define CEOL _POSIX_VDISABLE
|
||||||
#endif
|
#endif
|
||||||
#ifndef CSTART
|
#ifndef CSTART
|
||||||
# define CSTART Control ('q')
|
# define CSTART Control('q')
|
||||||
#endif
|
#endif
|
||||||
#ifndef CSTOP
|
#ifndef CSTOP
|
||||||
# define CSTOP Control ('s')
|
# define CSTOP Control('s')
|
||||||
#endif
|
#endif
|
||||||
#ifndef CSUSP
|
#ifndef CSUSP
|
||||||
# define CSUSP Control ('z')
|
# define CSUSP Control('z')
|
||||||
#endif
|
#endif
|
||||||
#if defined(VEOL2) && !defined(CEOL2)
|
#if defined(VEOL2) && !defined(CEOL2)
|
||||||
# define CEOL2 _POSIX_VDISABLE
|
# define CEOL2 _POSIX_VDISABLE
|
||||||
#endif
|
#endif
|
||||||
/* ISC renamed swtch to susp for termios, but we'll accept either name. */
|
/* ISC renamed swtch to susp for termios, but we'll accept either name */
|
||||||
#if defined(VSUSP) && !defined(VSWTCH)
|
#if defined(VSUSP) && !defined(VSWTCH)
|
||||||
# define VSWTCH VSUSP
|
# define VSWTCH VSUSP
|
||||||
# define CSWTCH CSUSP
|
# define CSWTCH CSUSP
|
||||||
@ -82,19 +79,19 @@
|
|||||||
# define VWERASE VWERSE
|
# define VWERASE VWERSE
|
||||||
#endif
|
#endif
|
||||||
#if defined(VDSUSP) && !defined (CDSUSP)
|
#if defined(VDSUSP) && !defined (CDSUSP)
|
||||||
# define CDSUSP Control ('y')
|
# define CDSUSP Control('y')
|
||||||
#endif
|
#endif
|
||||||
#if !defined(VREPRINT) && defined(VRPRNT) /* Irix 4.0.5 */
|
#if !defined(VREPRINT) && defined(VRPRNT) /* Irix 4.0.5 */
|
||||||
# define VREPRINT VRPRNT
|
# define VREPRINT VRPRNT
|
||||||
#endif
|
#endif
|
||||||
#if defined(VREPRINT) && !defined(CRPRNT)
|
#if defined(VREPRINT) && !defined(CRPRNT)
|
||||||
# define CRPRNT Control ('r')
|
# define CRPRNT Control('r')
|
||||||
#endif
|
#endif
|
||||||
#if defined(VWERASE) && !defined(CWERASE)
|
#if defined(VWERASE) && !defined(CWERASE)
|
||||||
# define CWERASE Control ('w')
|
# define CWERASE Control('w')
|
||||||
#endif
|
#endif
|
||||||
#if defined(VLNEXT) && !defined(CLNEXT)
|
#if defined(VLNEXT) && !defined(CLNEXT)
|
||||||
# define CLNEXT Control ('v')
|
# define CLNEXT Control('v')
|
||||||
#endif
|
#endif
|
||||||
#if defined(VDISCARD) && !defined(VFLUSHO)
|
#if defined(VDISCARD) && !defined(VFLUSHO)
|
||||||
# define VFLUSHO VDISCARD
|
# define VFLUSHO VDISCARD
|
||||||
@ -112,25 +109,24 @@
|
|||||||
# define ECHOKE CRTKIL
|
# define ECHOKE CRTKIL
|
||||||
#endif
|
#endif
|
||||||
#if defined(VFLUSHO) && !defined(CFLUSHO)
|
#if defined(VFLUSHO) && !defined(CFLUSHO)
|
||||||
# define CFLUSHO Control ('o')
|
# define CFLUSHO Control('o')
|
||||||
#endif
|
#endif
|
||||||
#if defined(VSTATUS) && !defined(CSTATUS)
|
#if defined(VSTATUS) && !defined(CSTATUS)
|
||||||
# define CSTATUS Control ('t')
|
# define CSTATUS Control('t')
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Which speeds to set. */
|
/* Which speeds to set */
|
||||||
enum speed_setting {
|
enum speed_setting {
|
||||||
input_speed, output_speed, both_speeds
|
input_speed, output_speed, both_speeds
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Which member(s) of `struct termios' a mode uses. */
|
/* Which member(s) of `struct termios' a mode uses */
|
||||||
enum mode_type {
|
enum mode_type {
|
||||||
/* Do NOT change the order or values, as mode_type_flag()
|
/* Do NOT change the order or values, as mode_type_flag()
|
||||||
* depends on them. */
|
* depends on them */
|
||||||
control, input, output, local, combination
|
control, input, output, local, combination
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const char evenp [] = "evenp";
|
static const char evenp [] = "evenp";
|
||||||
static const char raw [] = "raw";
|
static const char raw [] = "raw";
|
||||||
static const char stty_min [] = "min";
|
static const char stty_min [] = "min";
|
||||||
@ -154,22 +150,22 @@ static const char stty_LCASE[] = "LCASE";
|
|||||||
static const char stty_crt [] = "crt";
|
static const char stty_crt [] = "crt";
|
||||||
static const char stty_dec [] = "dec";
|
static const char stty_dec [] = "dec";
|
||||||
|
|
||||||
|
/* 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 `-' */
|
||||||
|
#define OMIT 8 /* Don't display value */
|
||||||
|
|
||||||
/* Flags for `struct mode_info'. */
|
/* Each mode */
|
||||||
#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 `-'. */
|
|
||||||
#define OMIT 8 /* Don't display value. */
|
|
||||||
|
|
||||||
/* Each mode. */
|
|
||||||
struct mode_info {
|
struct mode_info {
|
||||||
const char *name; /* Name given on command line. */
|
const char *name; /* Name given on command line */
|
||||||
/* enum mode_type type; */
|
/* enum mode_type type; */
|
||||||
char type; /* Which structure element to change. */
|
char type; /* Which structure element to change */
|
||||||
char flags; /* Setting and display options. */
|
char flags; /* Setting and display options */
|
||||||
unsigned short mask; /* Other bits to turn off for this mode. */
|
unsigned short mask; /* Other bits to turn off for this mode */
|
||||||
unsigned long bits; /* Bits to set for this mode. */
|
unsigned long bits; /* Bits to set for this mode */
|
||||||
};
|
};
|
||||||
|
#define EMT(t) ((enum mode_type)(t))
|
||||||
|
|
||||||
#define MI_ENTRY(N,T,F,B,M) { N, T, F, M, B }
|
#define MI_ENTRY(N,T,F,B,M) { N, T, F, M, B }
|
||||||
|
|
||||||
@ -308,7 +304,7 @@ static const struct mode_info mode_info[] = {
|
|||||||
#ifdef IXANY
|
#ifdef IXANY
|
||||||
MI_ENTRY(decctlq, combination, REV | OMIT, 0, 0 ),
|
MI_ENTRY(decctlq, combination, REV | OMIT, 0, 0 ),
|
||||||
#endif
|
#endif
|
||||||
#if defined (TABDLY) || defined (OXTABS)
|
#if defined(TABDLY) || defined(OXTABS)
|
||||||
MI_ENTRY(stty_tabs, combination, REV | OMIT, 0, 0 ),
|
MI_ENTRY(stty_tabs, combination, REV | OMIT, 0, 0 ),
|
||||||
#endif
|
#endif
|
||||||
#if defined(XCASE) && defined(IUCLC) && defined(OLCUC)
|
#if defined(XCASE) && defined(IUCLC) && defined(OLCUC)
|
||||||
@ -320,18 +316,17 @@ static const struct mode_info mode_info[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NUM_mode_info =
|
NUM_mode_info = (sizeof(mode_info) / sizeof(mode_info[0]))
|
||||||
(sizeof(mode_info) / sizeof(struct mode_info))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Control character settings. */
|
/* Control character settings */
|
||||||
struct control_info {
|
struct control_info {
|
||||||
const char *name; /* Name given on command line. */
|
const char *name; /* Name given on command line */
|
||||||
unsigned char saneval; /* Value to set for `stty sane'. */
|
unsigned char saneval; /* Value to set for `stty sane' */
|
||||||
unsigned char offset; /* Offset in c_cc. */
|
unsigned char offset; /* Offset in c_cc */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Control characters. */
|
/* Control characters */
|
||||||
|
|
||||||
static const struct control_info control_info[] = {
|
static const struct control_info control_info[] = {
|
||||||
{"intr", CINTR, VINTR},
|
{"intr", CINTR, VINTR},
|
||||||
@ -367,17 +362,20 @@ static const struct control_info control_info[] = {
|
|||||||
#ifdef VSTATUS
|
#ifdef VSTATUS
|
||||||
{"status", CSTATUS, VSTATUS},
|
{"status", CSTATUS, VSTATUS},
|
||||||
#endif
|
#endif
|
||||||
/* These must be last because of the display routines. */
|
/* These must be last because of the display routines */
|
||||||
{stty_min, 1, VMIN},
|
{stty_min, 1, VMIN},
|
||||||
{stty_time, 0, VTIME},
|
{stty_time, 0, VTIME},
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NUM_control_info =
|
NUM_control_info = (sizeof(control_info) / sizeof(control_info[0]))
|
||||||
(sizeof(control_info) / sizeof(struct control_info))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define EMT(t) ((enum mode_type)(t))
|
/* The width of the screen, for output wrapping */
|
||||||
|
static int max_col;
|
||||||
|
|
||||||
|
/* Current position, to know when to wrap */
|
||||||
|
static int current_col;
|
||||||
|
|
||||||
static const char * visible(unsigned int ch);
|
static const char * visible(unsigned int ch);
|
||||||
static int recover_mode(const char *arg, struct termios *mode);
|
static int recover_mode(const char *arg, struct termios *mode);
|
||||||
@ -385,11 +383,11 @@ static int screen_columns(void);
|
|||||||
static void set_mode(const struct mode_info *info,
|
static void set_mode(const struct mode_info *info,
|
||||||
int reversed, struct termios *mode);
|
int reversed, struct termios *mode);
|
||||||
static speed_t string_to_baud(const char *arg);
|
static speed_t string_to_baud(const char *arg);
|
||||||
static tcflag_t* mode_type_flag(enum mode_type type, struct termios *mode);
|
static tcflag_t* mode_type_flag(enum mode_type type, const struct termios *mode);
|
||||||
static void display_all(struct termios *mode);
|
static void display_all(const struct termios *mode);
|
||||||
static void display_changed(struct termios *mode);
|
static void display_changed(const struct termios *mode);
|
||||||
static void display_recoverable(struct termios *mode);
|
static void display_recoverable(const struct termios *mode);
|
||||||
static void display_speed(struct termios *mode, int fancy);
|
static void display_speed(const struct termios *mode, int fancy);
|
||||||
static void display_window_size(int fancy);
|
static void display_window_size(int fancy);
|
||||||
static void sane_mode(struct termios *mode);
|
static void sane_mode(struct termios *mode);
|
||||||
static void set_control_char(const struct control_info *info,
|
static void set_control_char(const struct control_info *info,
|
||||||
@ -405,21 +403,19 @@ static ATTRIBUTE_NORETURN void perror_on_device(const char *fmt)
|
|||||||
bb_perror_msg_and_die(fmt, device_name);
|
bb_perror_msg_and_die(fmt, device_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ATTRIBUTE_ALWAYS_INLINE int streq(const char *a, const char *b)
|
||||||
/* The width of the screen, for output wrapping. */
|
{
|
||||||
static int max_col;
|
return strcmp(a, b) == 0;
|
||||||
|
}
|
||||||
/* Current position, to know when to wrap. */
|
|
||||||
static int current_col;
|
|
||||||
|
|
||||||
/* Print format string MESSAGE and optional args.
|
/* Print format string MESSAGE and optional args.
|
||||||
Wrap to next line first if it won't fit.
|
Wrap to next line first if it won't fit.
|
||||||
Print a space first unless MESSAGE will start a new line. */
|
Print a space first unless MESSAGE will start a new line */
|
||||||
|
|
||||||
static void wrapf(const char *message, ...)
|
static void wrapf(const char *message, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char buf[1024]; /* Plenty long for our needs. */
|
char buf[1024]; /* Plenty long for our needs */
|
||||||
int buflen;
|
int buflen;
|
||||||
|
|
||||||
va_start(args, message);
|
va_start(args, message);
|
||||||
@ -449,7 +445,7 @@ static const struct mode_info *find_mode(const char *name)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < NUM_mode_info; ++i)
|
for (i = 0; i < NUM_mode_info; ++i)
|
||||||
if (STREQ(name, mode_info[i].name))
|
if (streq(name, mode_info[i].name))
|
||||||
return &mode_info[i];
|
return &mode_info[i];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -458,7 +454,7 @@ static const struct control_info *find_control(const char *name)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < NUM_control_info; ++i)
|
for (i = 0; i < NUM_control_info; ++i)
|
||||||
if (STREQ(name, control_info[i].name))
|
if (streq(name, control_info[i].name))
|
||||||
return &control_info[i];
|
return &control_info[i];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -477,17 +473,17 @@ enum {
|
|||||||
static int find_param(const char *name)
|
static int find_param(const char *name)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_C_LINE
|
#ifdef HAVE_C_LINE
|
||||||
if (STREQ(name, "line")) return param_line;
|
if (streq(name, "line")) return param_line;
|
||||||
#endif
|
#endif
|
||||||
#ifdef TIOCGWINSZ
|
#ifdef TIOCGWINSZ
|
||||||
if (STREQ(name, "rows")) return param_rows;
|
if (streq(name, "rows")) return param_rows;
|
||||||
if (STREQ(name, "cols")) return param_cols;
|
if (streq(name, "cols")) return param_cols;
|
||||||
if (STREQ(name, "columns")) return param_cols;
|
if (streq(name, "columns")) return param_cols;
|
||||||
if (STREQ(name, "size")) return param_size;
|
if (streq(name, "size")) return param_size;
|
||||||
#endif
|
#endif
|
||||||
if (STREQ(name, "ispeed")) return param_ispeed;
|
if (streq(name, "ispeed")) return param_ispeed;
|
||||||
if (STREQ(name, "ospeed")) return param_ospeed;
|
if (streq(name, "ospeed")) return param_ospeed;
|
||||||
if (STREQ(name, "speed")) return param_speed;
|
if (streq(name, "speed")) return param_speed;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,7 +491,7 @@ static int find_param(const char *name)
|
|||||||
int stty_main(int argc, char **argv)
|
int stty_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct termios mode;
|
struct termios mode;
|
||||||
void (*output_func)(struct termios *);
|
void (*output_func)(const struct termios *);
|
||||||
const char *file_name = NULL;
|
const char *file_name = NULL;
|
||||||
int require_set_attr;
|
int require_set_attr;
|
||||||
int speed_was_set;
|
int speed_was_set;
|
||||||
@ -634,7 +630,7 @@ end_option:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize to all zeroes so there is no risk memcmp will report a
|
/* Initialize to all zeroes so there is no risk memcmp will report a
|
||||||
spurious difference in an uninitialized portion of the structure. */
|
spurious difference in an uninitialized portion of the structure */
|
||||||
memset(&mode, 0, sizeof(mode));
|
memset(&mode, 0, sizeof(mode));
|
||||||
if (tcgetattr(STDIN_FILENO, &mode))
|
if (tcgetattr(STDIN_FILENO, &mode))
|
||||||
perror_on_device("%s");
|
perror_on_device("%s");
|
||||||
@ -739,10 +735,10 @@ end_option:
|
|||||||
can report `success' when it has actually failed to perform
|
can report `success' when it has actually failed to perform
|
||||||
some proper subset of the requested operations. To detect
|
some proper subset of the requested operations. To detect
|
||||||
this partial failure, get the current terminal attributes and
|
this partial failure, get the current terminal attributes and
|
||||||
compare them to the requested ones. */
|
compare them to the requested ones */
|
||||||
|
|
||||||
/* Initialize to all zeroes so there is no risk memcmp will report a
|
/* Initialize to all zeroes so there is no risk memcmp will report a
|
||||||
spurious difference in an uninitialized portion of the structure. */
|
spurious difference in an uninitialized portion of the structure */
|
||||||
memset(&new_mode, 0, sizeof(new_mode));
|
memset(&new_mode, 0, sizeof(new_mode));
|
||||||
if (tcgetattr(STDIN_FILENO, &new_mode))
|
if (tcgetattr(STDIN_FILENO, &new_mode))
|
||||||
perror_on_device("%s");
|
perror_on_device("%s");
|
||||||
@ -756,7 +752,7 @@ end_option:
|
|||||||
Sun users a little confusion, don't report an error if this
|
Sun users a little confusion, don't report an error if this
|
||||||
happens. But suppress the error only if we haven't tried to
|
happens. But suppress the error only if we haven't tried to
|
||||||
set the baud rate explicitly -- otherwise we'd never give an
|
set the baud rate explicitly -- otherwise we'd never give an
|
||||||
error for a true failure to set the baud rate. */
|
error for a true failure to set the baud rate */
|
||||||
|
|
||||||
new_mode.c_cflag &= (~CIBAUD);
|
new_mode.c_cflag &= (~CIBAUD);
|
||||||
if (speed_was_set || memcmp(&mode, &new_mode, sizeof(mode)) != 0)
|
if (speed_was_set || memcmp(&mode, &new_mode, sizeof(mode)) != 0)
|
||||||
@ -768,7 +764,6 @@ end_option:
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return 0 if not applied because not reversible; otherwise return 1. */
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_mode(const struct mode_info *info, int reversed, struct termios *mode)
|
set_mode(const struct mode_info *info, int reversed, struct termios *mode)
|
||||||
@ -778,7 +773,7 @@ set_mode(const struct mode_info *info, int reversed, struct termios *mode)
|
|||||||
bitsp = mode_type_flag(EMT(info->type), mode);
|
bitsp = mode_type_flag(EMT(info->type), mode);
|
||||||
|
|
||||||
if (bitsp == NULL) {
|
if (bitsp == NULL) {
|
||||||
/* Combination mode. */
|
/* Combination mode */
|
||||||
if (info->name == evenp || info->name == parity) {
|
if (info->name == evenp || info->name == parity) {
|
||||||
if (reversed)
|
if (reversed)
|
||||||
mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;
|
mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;
|
||||||
@ -843,7 +838,7 @@ set_mode(const struct mode_info *info, int reversed, struct termios *mode)
|
|||||||
} else if (info->name == raw || info->name == cooked) {
|
} else if (info->name == raw || info->name == cooked) {
|
||||||
if ((info->name[0] == 'r' && reversed)
|
if ((info->name[0] == 'r' && reversed)
|
||||||
|| (info->name[0] == 'c' && !reversed)) {
|
|| (info->name[0] == 'c' && !reversed)) {
|
||||||
/* Cooked mode. */
|
/* Cooked mode */
|
||||||
mode->c_iflag |= BRKINT | IGNPAR | ISTRIP | ICRNL | IXON;
|
mode->c_iflag |= BRKINT | IGNPAR | ISTRIP | ICRNL | IXON;
|
||||||
mode->c_oflag |= OPOST;
|
mode->c_oflag |= OPOST;
|
||||||
mode->c_lflag |= ISIG | ICANON;
|
mode->c_lflag |= ISIG | ICANON;
|
||||||
@ -854,7 +849,7 @@ set_mode(const struct mode_info *info, int reversed, struct termios *mode)
|
|||||||
mode->c_cc[VEOL] = CEOL;
|
mode->c_cc[VEOL] = CEOL;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/* Raw mode. */
|
/* Raw mode */
|
||||||
mode->c_iflag = 0;
|
mode->c_iflag = 0;
|
||||||
mode->c_oflag &= ~OPOST;
|
mode->c_oflag &= ~OPOST;
|
||||||
mode->c_lflag &= ~(ISIG | ICANON
|
mode->c_lflag &= ~(ISIG | ICANON
|
||||||
@ -945,13 +940,13 @@ set_control_char(const struct control_info *info, const char *arg,
|
|||||||
value = bb_xparse_number(arg, stty_suffixes);
|
value = bb_xparse_number(arg, stty_suffixes);
|
||||||
else if (arg[0] == '\0' || arg[1] == '\0')
|
else if (arg[0] == '\0' || arg[1] == '\0')
|
||||||
value = arg[0];
|
value = arg[0];
|
||||||
else if (STREQ(arg, "^-") || STREQ(arg, "undef"))
|
else if (streq(arg, "^-") || streq(arg, "undef"))
|
||||||
value = _POSIX_VDISABLE;
|
value = _POSIX_VDISABLE;
|
||||||
else if (arg[0] == '^' && arg[1] != '\0') { /* Ignore any trailing junk. */
|
else if (arg[0] == '^' && arg[1] != '\0') { /* Ignore any trailing junk */
|
||||||
if (arg[1] == '?')
|
if (arg[1] == '?')
|
||||||
value = 127;
|
value = 127;
|
||||||
else
|
else
|
||||||
value = arg[1] & ~0140; /* Non-letters get weird results. */
|
value = arg[1] & ~0140; /* Non-letters get weird results */
|
||||||
} else
|
} else
|
||||||
value = bb_xparse_number(arg, stty_suffixes);
|
value = bb_xparse_number(arg, stty_suffixes);
|
||||||
mode->c_cc[info->offset] = value;
|
mode->c_cc[info->offset] = value;
|
||||||
@ -976,9 +971,7 @@ set_speed(enum speed_setting type, const char *arg, struct termios *mode)
|
|||||||
|
|
||||||
static int get_win_size(int fd, struct winsize *win)
|
static int get_win_size(int fd, struct winsize *win)
|
||||||
{
|
{
|
||||||
int err = ioctl(fd, TIOCGWINSZ, (char *) win);
|
return ioctl(fd, TIOCGWINSZ, (char *) win);
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1002,7 +995,7 @@ set_window_size(int rows, int cols)
|
|||||||
The following code deals with a bug in the SunOS 4.x (and 3.x?) kernel.
|
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
|
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).
|
test would have been (ts_lines > 64k || ts_cols > 64k || ts_cols == 0).
|
||||||
At any rate, the problem is gone in Solaris 2.x. */
|
At any rate, the problem is gone in Solaris 2.x */
|
||||||
|
|
||||||
if (win.ws_row == 0 || win.ws_col == 0) {
|
if (win.ws_row == 0 || win.ws_col == 0) {
|
||||||
struct ttysize ttysz;
|
struct ttysize ttysz;
|
||||||
@ -1055,7 +1048,7 @@ static int screen_columns(void)
|
|||||||
On ISC 3.0, it fails for the console and the serial port
|
On ISC 3.0, it fails for the console and the serial port
|
||||||
(but it works for ptys).
|
(but it works for ptys).
|
||||||
It can also fail on any system when stdout isn't a tty.
|
It can also fail on any system when stdout isn't a tty.
|
||||||
In case of any failure, just use the default. */
|
In case of any failure, just use the default */
|
||||||
if (get_win_size(STDOUT_FILENO, &win) == 0 && win.ws_col > 0)
|
if (get_win_size(STDOUT_FILENO, &win) == 0 && win.ws_col > 0)
|
||||||
return win.ws_col;
|
return win.ws_col;
|
||||||
#endif
|
#endif
|
||||||
@ -1067,7 +1060,7 @@ static int screen_columns(void)
|
|||||||
return columns;
|
return columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
static tcflag_t *mode_type_flag(enum mode_type type, struct termios *mode)
|
static tcflag_t *mode_type_flag(enum mode_type type, const struct termios *mode)
|
||||||
{
|
{
|
||||||
static const unsigned char tcflag_offsets[] = {
|
static const unsigned char tcflag_offsets[] = {
|
||||||
offsetof(struct termios, c_cflag), /* control */
|
offsetof(struct termios, c_cflag), /* control */
|
||||||
@ -1082,7 +1075,7 @@ static tcflag_t *mode_type_flag(enum mode_type type, struct termios *mode)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display_changed(struct termios *mode)
|
static void display_changed(const struct termios *mode)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int empty_line;
|
int empty_line;
|
||||||
@ -1101,12 +1094,12 @@ static void display_changed(struct termios *mode)
|
|||||||
for (i = 0; control_info[i].name != stty_min; ++i) {
|
for (i = 0; control_info[i].name != stty_min; ++i) {
|
||||||
if (mode->c_cc[control_info[i].offset] == control_info[i].saneval)
|
if (mode->c_cc[control_info[i].offset] == control_info[i].saneval)
|
||||||
continue;
|
continue;
|
||||||
/* If swtch is the same as susp, don't print both. */
|
/* If swtch is the same as susp, don't print both */
|
||||||
#if VSWTCH == VSUSP
|
#if VSWTCH == VSUSP
|
||||||
if (control_info[i].name == stty_swtch)
|
if (control_info[i].name == stty_swtch)
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
/* If eof uses the same slot as min, only print whichever applies. */
|
/* If eof uses the same slot as min, only print whichever applies */
|
||||||
#if VEOF == VMIN
|
#if VEOF == VMIN
|
||||||
if ((mode->c_lflag & ICANON) == 0
|
if ((mode->c_lflag & ICANON) == 0
|
||||||
&& (control_info[i].name == stty_eof
|
&& (control_info[i].name == stty_eof
|
||||||
@ -1144,9 +1137,7 @@ static void display_changed(struct termios *mode)
|
|||||||
wrapf("%s", mode_info[i].name);
|
wrapf("%s", mode_info[i].name);
|
||||||
empty_line = 0;
|
empty_line = 0;
|
||||||
}
|
}
|
||||||
}
|
} else if ((mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV)) {
|
||||||
else if ((mode_info[i].flags & (SANE_SET | REV)) ==
|
|
||||||
(SANE_SET | REV)) {
|
|
||||||
wrapf("-%s", mode_info[i].name);
|
wrapf("-%s", mode_info[i].name);
|
||||||
empty_line = 0;
|
empty_line = 0;
|
||||||
}
|
}
|
||||||
@ -1157,7 +1148,7 @@ static void display_changed(struct termios *mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
display_all(struct termios *mode)
|
display_all(const struct termios *mode)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
tcflag_t *bitsp;
|
tcflag_t *bitsp;
|
||||||
@ -1175,12 +1166,12 @@ display_all(struct termios *mode)
|
|||||||
current_col = 0;
|
current_col = 0;
|
||||||
|
|
||||||
for (i = 0; control_info[i].name != stty_min; ++i) {
|
for (i = 0; control_info[i].name != stty_min; ++i) {
|
||||||
/* If swtch is the same as susp, don't print both. */
|
/* If swtch is the same as susp, don't print both */
|
||||||
#if VSWTCH == VSUSP
|
#if VSWTCH == VSUSP
|
||||||
if (control_info[i].name == stty_swtch)
|
if (control_info[i].name == stty_swtch)
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
/* If eof uses the same slot as min, only print whichever applies. */
|
/* If eof uses the same slot as min, only print whichever applies */
|
||||||
#if VEOF == VMIN
|
#if VEOF == VMIN
|
||||||
if ((mode->c_lflag & ICANON) == 0
|
if ((mode->c_lflag & ICANON) == 0
|
||||||
&& (control_info[i].name == stty_eof
|
&& (control_info[i].name == stty_eof
|
||||||
@ -1217,7 +1208,7 @@ display_all(struct termios *mode)
|
|||||||
current_col = 0;
|
current_col = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display_speed(struct termios *mode, int fancy)
|
static void display_speed(const struct termios *mode, int fancy)
|
||||||
{
|
{
|
||||||
unsigned long ispeed, ospeed;
|
unsigned long ispeed, ospeed;
|
||||||
const char *fmt_str =
|
const char *fmt_str =
|
||||||
@ -1237,7 +1228,7 @@ static void display_speed(struct termios *mode, int fancy)
|
|||||||
current_col = 0;
|
current_col = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display_recoverable(struct termios *mode)
|
static void display_recoverable(const struct termios *mode)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -1256,7 +1247,7 @@ static int recover_mode(const char *arg, struct termios *mode)
|
|||||||
unsigned long iflag, oflag, cflag, lflag;
|
unsigned long iflag, oflag, cflag, lflag;
|
||||||
|
|
||||||
/* Scan into temporaries since it is too much trouble to figure out
|
/* Scan into temporaries since it is too much trouble to figure out
|
||||||
the right format for `tcflag_t'. */
|
the right format for `tcflag_t' */
|
||||||
if (sscanf(arg, "%lx:%lx:%lx:%lx%n",
|
if (sscanf(arg, "%lx:%lx:%lx:%lx%n",
|
||||||
&iflag, &oflag, &cflag, &lflag, &n) != 4)
|
&iflag, &oflag, &cflag, &lflag, &n) != 4)
|
||||||
return 0;
|
return 0;
|
||||||
@ -1272,7 +1263,7 @@ static int recover_mode(const char *arg, struct termios *mode)
|
|||||||
arg += n;
|
arg += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fail if there are too many fields. */
|
/* Fail if there are too many fields */
|
||||||
if (*arg != '\0')
|
if (*arg != '\0')
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -1310,8 +1301,8 @@ static void sane_mode(struct termios *mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return a string that is the printable representation of character CH. */
|
/* Return a string that is the printable representation of character CH */
|
||||||
/* Adapted from `cat' by Torbjorn Granlund. */
|
/* Adapted from `cat' by Torbjorn Granlund */
|
||||||
|
|
||||||
static const char *visible(unsigned int ch)
|
static const char *visible(unsigned int ch)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user