Merge with 4.4-Lite version.

This commit is contained in:
mycroft 1994-09-20 04:52:02 +00:00
parent 7df690ffe6
commit fe5a9095e0
10 changed files with 611 additions and 325 deletions

View File

@ -1,5 +1,5 @@
# from: @(#)Makefile 5.4 (Berkeley) 6/5/91
# $Id: Makefile,v 1.6 1994/03/23 04:05:23 mycroft Exp $
# from: @(#)Makefile 8.1 (Berkeley) 5/31/93
# $Id: Makefile,v 1.7 1994/09/20 04:52:02 mycroft Exp $
PROG= stty
SRCS= cchar.c gfmt.c key.c modes.c print.c stty.c

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,16 +32,18 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)cchar.c 5.4 (Berkeley) 6/10/91";*/
static char rcsid[] = "$Id: cchar.c,v 1.7 1994/03/23 04:05:24 mycroft Exp $";
/*static char sccsid[] = "from: @(#)cchar.c 8.5 (Berkeley) 4/2/94";*/
static char *rcsid = "$Id: cchar.c,v 1.8 1994/09/20 04:52:03 mycroft Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <err.h>
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "stty.h"
#include "extern.h"
@ -53,45 +55,50 @@ static char rcsid[] = "$Id: cchar.c,v 1.7 1994/03/23 04:05:24 mycroft Exp $";
* command line.
*/
struct cchar cchars1[] = {
"discard", VDISCARD, CDISCARD,
"dsusp", VDSUSP, CDSUSP,
"eof", VEOF, CEOF,
"eol", VEOL, CEOL,
"eol2", VEOL2, CEOL,
"erase", VERASE, CERASE,
"intr", VINTR, CINTR,
"kill", VKILL, CKILL,
"lnext", VLNEXT, CLNEXT,
"min", VMIN, CMIN,
"quit", VQUIT, CQUIT,
"reprint", VREPRINT, CREPRINT,
"start", VSTART, CSTART,
"status", VSTATUS, CSTATUS,
"stop", VSTOP, CSTOP,
"susp", VSUSP, CSUSP,
"time", VTIME, CTIME,
"werase", VWERASE, CWERASE,
NULL,
{ "discard", VDISCARD, CDISCARD },
{ "dsusp", VDSUSP, CDSUSP },
{ "eof", VEOF, CEOF },
{ "eol", VEOL, CEOL },
{ "eol2", VEOL2, CEOL },
{ "erase", VERASE, CERASE },
{ "intr", VINTR, CINTR },
{ "kill", VKILL, CKILL },
{ "lnext", VLNEXT, CLNEXT },
{ "min", VMIN, CMIN },
{ "quit", VQUIT, CQUIT },
{ "reprint", VREPRINT, CREPRINT },
{ "start", VSTART, CSTART },
{ "status", VSTATUS, CSTATUS },
{ "stop", VSTOP, CSTOP },
{ "susp", VSUSP, CSUSP },
{ "time", VTIME, CTIME },
{ "werase", VWERASE, CWERASE },
{ NULL },
};
struct cchar cchars2[] = {
"brk", VEOL, CEOL,
"flush", VDISCARD, CDISCARD,
"rprnt", VREPRINT, CREPRINT,
"xoff", VSTOP, CSTOP,
"xon", VSTART, CSTART,
NULL,
{ "brk", VEOL, CEOL },
{ "flush", VDISCARD, CDISCARD },
{ "rprnt", VREPRINT, CREPRINT },
{ NULL },
};
static int
c_cchar(a, b)
const void *a, *b;
{
return (strcmp(((struct cchar *)a)->name, ((struct cchar *)b)->name));
}
int
csearch(argvp, ip)
char ***argvp;
struct info *ip;
{
register struct cchar *cp;
struct cchar tmp;
struct cchar *cp, tmp;
long val;
char *arg, *ep, *name;
static int c_cchar __P((const void *, const void *));
name = **argvp;
@ -101,7 +108,7 @@ csearch(argvp, ip)
c_cchar)) && !(cp = (struct cchar *)bsearch(&tmp, cchars1,
sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar),
c_cchar)))
return(0);
return (0);
arg = *++*argvp;
if (!arg) {
@ -135,12 +142,5 @@ csearch(argvp, ip)
else
ip->t.c_cc[cp->sub] = arg[0];
ip->set = 1;
return(1);
}
static
c_cchar(a, b)
const void *a, *b;
{
return(strcmp(((struct cchar *)a)->name, ((struct cchar *)b)->name));
return (1);
}

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -30,11 +30,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)extern.h 5.4 (Berkeley) 6/10/91
* $Id: extern.h,v 1.5 1994/03/23 04:05:26 mycroft Exp $
* from: @(#)extern.h 8.1 (Berkeley) 5/31/93
* $Id: extern.h,v 1.6 1994/09/20 04:52:04 mycroft Exp $
*/
__BEGIN_DECLS
int c_cchars __P((const void *, const void *));
int c_modes __P((const void *, const void *));
int csearch __P((char ***, struct info *));
@ -46,6 +45,5 @@ int msearch __P((char ***, struct info *));
void optlist __P((void));
void print __P((struct termios *, struct winsize *, int, enum FMT));
void usage __P((void));
__END_DECLS
extern struct cchar cchars1[], cchars2[];

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,18 +32,28 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)gfmt.c 5.4 (Berkeley) 6/10/91";*/
static char rcsid[] = "$Id: gfmt.c,v 1.7 1994/03/23 05:05:30 mycroft Exp $";
/*static char sccsid[] = "from: @(#)gfmt.c 8.6 (Berkeley) 4/2/94";*/
static char *rcsid = "$Id: gfmt.c,v 1.8 1994/09/20 04:52:05 mycroft Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <err.h>
#include <stdio.h>
#include <string.h>
#include "stty.h"
#include "extern.h"
static void gerr __P((char *));
static void
gerr(s)
char *s;
{
if (s)
errx(1, "illegal gfmt1 option -- %s", s);
else
errx(1, "illegal gfmt1 option");
}
void
gprint(tp, wp, ldisc)
@ -51,7 +61,7 @@ gprint(tp, wp, ldisc)
struct winsize *wp;
int ldisc;
{
register struct cchar *cp;
struct cchar *cp;
(void)printf("gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:",
tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag);
@ -62,24 +72,25 @@ gprint(tp, wp, ldisc)
void
gread(tp, s)
register struct termios *tp;
struct termios *tp;
char *s;
{
register char *ep, *p;
register struct cchar *cp;
struct cchar *cp;
char *ep, *p;
long tmp;
#define CHK(s) (*p == s[0] && !strcmp(p, s))
if (!(s = index(s, ':')))
if ((s = strchr(s, ':')) == NULL)
gerr(NULL);
for (++s; s;) {
for (++s; s != NULL;) {
p = strsep(&s, ":\0");
if (!p || !*p)
break;
if (!(ep = index(p, '=')))
if (!(ep = strchr(p, '=')))
gerr(p);
*ep++ = '\0';
(void)sscanf(ep, "%lx", &tmp);
#define CHK(s) (*p == s[0] && !strcmp(p, s))
if (CHK("cflag")) {
tp->c_cflag = tmp;
continue;
@ -106,25 +117,14 @@ gread(tp, s)
tp->c_ospeed = tmp;
continue;
}
for (cp = cchars1; cp->name; ++cp) {
for (cp = cchars1; cp->name != NULL; ++cp)
if (CHK(cp->name)) {
if (cp->sub == VMIN || cp->sub == VTIME)
(void)sscanf(ep, "%ld", &tmp);
tp->c_cc[cp->sub] = tmp;
break;
}
}
if (!cp->name)
if (cp->name == NULL)
gerr(p);
}
}
static void
gerr(s)
char *s;
{
if (s)
errx(1, "illegal gfmt1 option -- %s", s);
else
errx(1, "illegal gfmt1 option");
}

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,16 +32,18 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)key.c 5.3 (Berkeley) 6/10/91";*/
static char rcsid[] = "$Id: key.c,v 1.8 1994/03/23 04:05:29 mycroft Exp $";
/*static char sccsid[] = "from: @(#)key.c 8.3 (Berkeley) 4/2/94";*/
static char *rcsid = "$Id: key.c,v 1.9 1994/09/20 04:52:06 mycroft Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <err.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "stty.h"
#include "extern.h"
@ -70,35 +72,42 @@ static struct key {
#define F_OFFOK 0x02 /* can turn off */
int flags;
} keys[] = {
"all", f_all, 0,
"cbreak", f_cbreak, F_OFFOK,
"cols", f_columns, F_NEEDARG,
"columns", f_columns, F_NEEDARG,
"cooked", f_sane, 0,
"dec", f_dec, 0,
"everything", f_everything, 0,
"extproc", f_extproc, F_OFFOK,
"ispeed", f_ispeed, F_NEEDARG,
"new", f_tty, 0,
"nl", f_nl, F_OFFOK,
"old", f_tty, 0,
"ospeed", f_ospeed, F_NEEDARG,
"raw", f_raw, F_OFFOK,
"rows", f_rows, F_NEEDARG,
"sane", f_sane, 0,
"size", f_size, 0,
"speed", f_speed, 0,
"tty", f_tty, 0,
{ "all", f_all, 0 },
{ "cbreak", f_cbreak, F_OFFOK },
{ "cols", f_columns, F_NEEDARG },
{ "columns", f_columns, F_NEEDARG },
{ "cooked", f_sane, 0 },
{ "dec", f_dec, 0 },
{ "everything", f_everything, 0 },
{ "extproc", f_extproc, F_OFFOK },
{ "ispeed", f_ispeed, F_NEEDARG },
{ "new", f_tty, 0 },
{ "nl", f_nl, F_OFFOK },
{ "old", f_tty, 0 },
{ "ospeed", f_ospeed, F_NEEDARG },
{ "raw", f_raw, F_OFFOK },
{ "rows", f_rows, F_NEEDARG },
{ "sane", f_sane, 0 },
{ "size", f_size, 0 },
{ "speed", f_speed, 0 },
{ "tty", f_tty, 0 },
};
static int
c_key(a, b)
const void *a, *b;
{
return (strcmp(((struct key *)a)->name, ((struct key *)b)->name));
}
int
ksearch(argvp, ip)
char ***argvp;
struct info *ip;
{
register struct key *kp;
register char *name;
struct key tmp;
static int c_key __P((const void *, const void *));
char *name;
struct key *kp, tmp;
name = **argvp;
if (*name == '-') {
@ -110,7 +119,7 @@ ksearch(argvp, ip)
tmp.name = name;
if (!(kp = (struct key *)bsearch(&tmp, keys,
sizeof(keys)/sizeof(struct key), sizeof(struct key), c_key)))
return(0);
return (0);
if (!(kp->flags & F_OFFOK) && ip->off) {
warnx("illegal option -- %s", name);
usage();
@ -120,14 +129,7 @@ ksearch(argvp, ip)
usage();
}
kp->f(ip);
return(1);
}
static
c_key(a, b)
const void *a, *b;
{
return(strcmp(((struct key *)a)->name, ((struct key *)b)->name));
return (1);
}
void
@ -141,6 +143,7 @@ void
f_cbreak(ip)
struct info *ip;
{
if (ip->off)
f_sane(ip);
else {
@ -156,6 +159,7 @@ void
f_columns(ip)
struct info *ip;
{
ip->win.ws_col = atoi(ip->arg);
ip->wset = 1;
}
@ -164,6 +168,7 @@ void
f_dec(ip)
struct info *ip;
{
ip->t.c_cc[VERASE] = (u_char)0177;
ip->t.c_cc[VKILL] = CTRL('u');
ip->t.c_cc[VINTR] = CTRL('c');
@ -177,6 +182,7 @@ void
f_everything(ip)
struct info *ip;
{
print(&ip->t, &ip->win, ip->ldisc, BSD);
}
@ -184,13 +190,12 @@ void
f_extproc(ip)
struct info *ip;
{
int tmp;
if (ip->set) {
tmp = 1;
int tmp = 1;
(void)ioctl(ip->fd, TIOCEXT, &tmp);
} else {
tmp = 0;
int tmp = 0;
(void)ioctl(ip->fd, TIOCEXT, &tmp);
}
}
@ -199,6 +204,7 @@ void
f_ispeed(ip)
struct info *ip;
{
cfsetispeed(&ip->t, atoi(ip->arg));
ip->set = 1;
}
@ -207,6 +213,7 @@ void
f_nl(ip)
struct info *ip;
{
if (ip->off) {
ip->t.c_iflag |= ICRNL;
ip->t.c_oflag |= ONLCR;
@ -221,6 +228,7 @@ void
f_ospeed(ip)
struct info *ip;
{
cfsetospeed(&ip->t, atoi(ip->arg));
ip->set = 1;
}
@ -229,6 +237,7 @@ void
f_raw(ip)
struct info *ip;
{
if (ip->off)
f_sane(ip);
else {
@ -243,6 +252,7 @@ void
f_rows(ip)
struct info *ip;
{
ip->win.ws_row = atoi(ip->arg);
ip->wset = 1;
}
@ -251,6 +261,7 @@ void
f_sane(ip)
struct info *ip;
{
ip->t.c_cflag = TTYDEF_CFLAG | (ip->t.c_cflag & (CLOCAL|CRTSCTS));
ip->t.c_iflag = TTYDEF_IFLAG;
ip->t.c_iflag |= ICRNL;
@ -265,6 +276,7 @@ void
f_size(ip)
struct info *ip;
{
(void)printf("%d %d\n", ip->win.ws_row, ip->win.ws_col);
}
@ -272,6 +284,7 @@ void
f_speed(ip)
struct info *ip;
{
(void)printf("%d\n", cfgetospeed(&ip->t));
}

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,8 +32,8 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)modes.c 5.4 (Berkeley) 6/10/91";*/
static char rcsid[] = "$Id: modes.c,v 1.6 1994/04/12 06:08:48 cgd Exp $";
/*static char sccsid[] = "from: @(#)modes.c 8.3 (Berkeley) 4/2/94";*/
static char *rcsid = "$Id: modes.c,v 1.7 1994/09/20 04:52:07 mycroft Exp $";
#endif /* not lint */
#include <sys/types.h>
@ -52,150 +52,150 @@ struct modes {
* options, i.e. "foo" must immediately precede "-foo".
*/
struct modes cmodes[] = {
"cs5", CS5, CSIZE,
"cs6", CS6, CSIZE,
"cs7", CS7, CSIZE,
"cs8", CS8, CSIZE,
"cstopb", CSTOPB, 0,
"-cstopb", 0, CSTOPB,
"cread", CREAD, 0,
"-cread", 0, CREAD,
"parenb", PARENB, 0,
"-parenb", 0, PARENB,
"parodd", PARODD, 0,
"-parodd", 0, PARODD,
"parity", PARENB | CS7, PARODD | CSIZE,
"-parity", CS8, PARODD | PARENB | CSIZE,
"evenp", PARENB | CS7, PARODD | CSIZE,
"-evenp", CS8, PARODD | PARENB | CSIZE,
"oddp", PARENB | CS7 | PARODD, CSIZE,
"-oddp", CS8, PARODD | PARENB | CSIZE,
"pass8", CS8, PARODD | PARENB | CSIZE,
"hupcl", HUPCL, 0,
"-hupcl", 0, HUPCL,
"hup", HUPCL, 0,
"-hup", 0, HUPCL,
"clocal", CLOCAL, 0,
"-clocal", 0, CLOCAL,
"crtscts", CRTSCTS, 0,
"-crtscts", 0, CRTSCTS,
"mdmbuf", MDMBUF, 0,
"-mdmbuf", 0, MDMBUF,
NULL
{ "cs5", CS5, CSIZE },
{ "cs6", CS6, CSIZE },
{ "cs7", CS7, CSIZE },
{ "cs8", CS8, CSIZE },
{ "cstopb", CSTOPB, 0 },
{ "-cstopb", 0, CSTOPB },
{ "cread", CREAD, 0 },
{ "-cread", 0, CREAD },
{ "parenb", PARENB, 0 },
{ "-parenb", 0, PARENB },
{ "parodd", PARODD, 0 },
{ "-parodd", 0, PARODD },
{ "parity", PARENB | CS7, PARODD | CSIZE },
{ "-parity", CS8, PARODD | PARENB | CSIZE },
{ "evenp", PARENB | CS7, PARODD | CSIZE },
{ "-evenp", CS8, PARODD | PARENB | CSIZE },
{ "oddp", PARENB | CS7 | PARODD, CSIZE },
{ "-oddp", CS8, PARODD | PARENB | CSIZE },
{ "pass8", CS8, PARODD | PARENB | CSIZE },
{ "-pass8", PARENB | CS7, PARODD | CSIZE },
{ "hupcl", HUPCL, 0 },
{ "-hupcl", 0, HUPCL },
{ "hup", HUPCL, 0 },
{ "-hup", 0, HUPCL },
{ "clocal", CLOCAL, 0 },
{ "-clocal", 0, CLOCAL },
{ "crtscts", CRTSCTS, 0 },
{ "-crtscts", 0, CRTSCTS },
{ "mdmbuf", MDMBUF, 0 },
{ "-mdmbuf", 0, MDMBUF },
{ NULL },
};
struct modes imodes[] = {
"ignbrk", IGNBRK, 0,
"-ignbrk", 0, IGNBRK,
"brkint", BRKINT, 0,
"-brkint", 0, BRKINT,
"ignpar", IGNPAR, 0,
"-ignpar", 0, IGNPAR,
"parmrk", PARMRK, 0,
"-parmrk", 0, PARMRK,
"inpck", INPCK, 0,
"-inpck", 0, INPCK,
"istrip", ISTRIP, 0,
"-istrip", 0, ISTRIP,
"inlcr", INLCR, 0,
"-inlcr", 0, INLCR,
"igncr", IGNCR, 0,
"-igncr", 0, IGNCR,
"icrnl", ICRNL, 0,
"-icrnl", 0, ICRNL,
"ixon", IXON, 0,
"-ixon", 0, IXON,
"flow", IXON, 0,
"-flow", 0, IXON,
"ixoff", IXOFF, 0,
"-ixoff", 0, IXOFF,
"tandem", IXOFF, 0,
"-tandem", 0, IXOFF,
"ixany", IXANY, 0,
"-ixany", 0, IXANY,
"decctlq", 0, IXANY,
"-decctlq", IXANY, 0,
"imaxbel", IMAXBEL, 0,
"-imaxbel", 0, IMAXBEL,
NULL
{ "ignbrk", IGNBRK, 0 },
{ "-ignbrk", 0, IGNBRK },
{ "brkint", BRKINT, 0 },
{ "-brkint", 0, BRKINT },
{ "ignpar", IGNPAR, 0 },
{ "-ignpar", 0, IGNPAR },
{ "parmrk", PARMRK, 0 },
{ "-parmrk", 0, PARMRK },
{ "inpck", INPCK, 0 },
{ "-inpck", 0, INPCK },
{ "istrip", ISTRIP, 0 },
{ "-istrip", 0, ISTRIP },
{ "inlcr", INLCR, 0 },
{ "-inlcr", 0, INLCR },
{ "igncr", IGNCR, 0 },
{ "-igncr", 0, IGNCR },
{ "icrnl", ICRNL, 0 },
{ "-icrnl", 0, ICRNL },
{ "ixon", IXON, 0 },
{ "-ixon", 0, IXON },
{ "flow", IXON, 0 },
{ "-flow", 0, IXON },
{ "ixoff", IXOFF, 0 },
{ "-ixoff", 0, IXOFF },
{ "tandem", IXOFF, 0 },
{ "-tandem", 0, IXOFF },
{ "ixany", IXANY, 0 },
{ "-ixany", 0, IXANY },
{ "decctlq", 0, IXANY },
{ "-decctlq", IXANY, 0 },
{ "imaxbel", IMAXBEL, 0 },
{ "-imaxbel", 0, IMAXBEL },
{ NULL },
};
struct modes lmodes[] = {
"echo", ECHO, 0,
"-echo", 0, ECHO,
"echoe", ECHOE, 0,
"-echoe", 0, ECHOE,
"crterase", ECHOE, 0,
"-crterase", 0, ECHOE,
"crtbs", ECHOE, 0, /* crtbs not supported, close enough */
"-crtbs", 0, ECHOE,
"echok", ECHOK, 0,
"-echok", 0, ECHOK,
"echoke", ECHOKE, 0,
"-echoke", 0, ECHOKE,
"crtkill", ECHOKE, 0,
"-crtkill", 0, ECHOKE,
"altwerase", ALTWERASE, 0,
"-altwerase", 0, ALTWERASE,
"iexten", IEXTEN, 0,
"-iexten", 0, IEXTEN,
"echonl", ECHONL, 0,
"-echonl", 0, ECHONL,
"echoctl", ECHOCTL, 0,
"-echoctl", 0, ECHOCTL,
"ctlecho", ECHOCTL, 0,
"-ctlecho", 0, ECHOCTL,
"echoprt", ECHOPRT, 0,
"-echoprt", 0, ECHOPRT,
"prterase", ECHOPRT, 0,
"-prterase", 0, ECHOPRT,
"isig", ISIG, 0,
"-isig", 0, ISIG,
"icanon", ICANON, 0,
"-icanon", 0, ICANON,
"noflsh", NOFLSH, 0,
"-noflsh", 0, NOFLSH,
"tostop", TOSTOP, 0,
"-tostop", 0, TOSTOP,
"flusho", FLUSHO, 0,
"-flusho", 0, FLUSHO,
"pendin", PENDIN, 0,
"-pendin", 0, PENDIN,
"crt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT,
"-crt", ECHOK, ECHOE|ECHOKE|ECHOCTL,
"newcrt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT,
"-newcrt", ECHOK, ECHOE|ECHOKE|ECHOCTL,
"nokerninfo", NOKERNINFO, 0,
"-nokerninfo", 0, NOKERNINFO,
"kerninfo", 0, NOKERNINFO,
"-kerninfo", NOKERNINFO, 0,
NULL
{ "echo", ECHO, 0 },
{ "-echo", 0, ECHO },
{ "echoe", ECHOE, 0 },
{ "-echoe", 0, ECHOE },
{ "crterase", ECHOE, 0 },
{ "-crterase", 0, ECHOE },
{ "crtbs", ECHOE, 0 }, /* crtbs not supported, close enough */
{ "-crtbs", 0, ECHOE },
{ "echok", ECHOK, 0 },
{ "-echok", 0, ECHOK },
{ "echoke", ECHOKE, 0 },
{ "-echoke", 0, ECHOKE },
{ "crtkill", ECHOKE, 0 },
{ "-crtkill", 0, ECHOKE },
{ "altwerase", ALTWERASE, 0 },
{ "-altwerase", 0, ALTWERASE },
{ "iexten", IEXTEN, 0 },
{ "-iexten", 0, IEXTEN },
{ "echonl", ECHONL, 0 },
{ "-echonl", 0, ECHONL },
{ "echoctl", ECHOCTL, 0 },
{ "-echoctl", 0, ECHOCTL },
{ "ctlecho", ECHOCTL, 0 },
{ "-ctlecho", 0, ECHOCTL },
{ "echoprt", ECHOPRT, 0 },
{ "-echoprt", 0, ECHOPRT },
{ "prterase", ECHOPRT, 0 },
{ "-prterase", 0, ECHOPRT },
{ "isig", ISIG, 0 },
{ "-isig", 0, ISIG },
{ "icanon", ICANON, 0 },
{ "-icanon", 0, ICANON },
{ "noflsh", NOFLSH, 0 },
{ "-noflsh", 0, NOFLSH },
{ "tostop", TOSTOP, 0 },
{ "-tostop", 0, TOSTOP },
{ "flusho", FLUSHO, 0 },
{ "-flusho", 0, FLUSHO },
{ "pendin", PENDIN, 0 },
{ "-pendin", 0, PENDIN },
{ "crt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
{ "-crt", ECHOK, ECHOE|ECHOKE|ECHOCTL },
{ "newcrt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
{ "-newcrt", ECHOK, ECHOE|ECHOKE|ECHOCTL },
{ "nokerninfo", NOKERNINFO, 0 },
{ "-nokerninfo",0, NOKERNINFO },
{ "kerninfo", 0, NOKERNINFO },
{ "-kerninfo", NOKERNINFO, 0 },
{ NULL },
};
struct modes omodes[] = {
"opost", OPOST, 0,
"-opost", 0, OPOST,
"litout", 0, OPOST,
"-litout", OPOST, 0,
"onlcr", ONLCR, 0,
"-onlcr", 0, ONLCR,
"tabs", 0, OXTABS, /* "preserve" tabs */
"-tabs", OXTABS, 0,
"xtabs", OXTABS, 0,
"-xtabs", 0, OXTABS,
"oxtabs", OXTABS, 0,
"-oxtabs", 0, OXTABS,
NULL
{ "opost", OPOST, 0 },
{ "-opost", 0, OPOST },
{ "litout", 0, OPOST },
{ "-litout", OPOST, 0 },
{ "onlcr", ONLCR, 0 },
{ "-onlcr", 0, ONLCR },
{ "tabs", 0, OXTABS }, /* "preserve" tabs */
{ "-tabs", OXTABS, 0 },
{ "oxtabs", OXTABS, 0 },
{ "-oxtabs", 0, OXTABS },
{ NULL },
};
#define CHK(s) (*name == s[0] && !strcmp(name, s))
int
msearch(argvp, ip)
char ***argvp;
struct info *ip;
{
register struct modes *mp;
register char *name;
struct modes *mp;
char *name;
name = **argvp;
@ -204,28 +204,28 @@ msearch(argvp, ip)
ip->t.c_cflag &= ~mp->unset;
ip->t.c_cflag |= mp->set;
ip->set = 1;
return(1);
return (1);
}
for (mp = imodes; mp->name; ++mp)
if (CHK(mp->name)) {
ip->t.c_iflag &= ~mp->unset;
ip->t.c_iflag |= mp->set;
ip->set = 1;
return(1);
return (1);
}
for (mp = lmodes; mp->name; ++mp)
if (CHK(mp->name)) {
ip->t.c_lflag &= ~mp->unset;
ip->t.c_lflag |= mp->set;
ip->set = 1;
return(1);
return (1);
}
for (mp = omodes; mp->name; ++mp)
if (CHK(mp->name)) {
ip->t.c_oflag &= ~mp->unset;
ip->t.c_oflag |= mp->set;
ip->set = 1;
return(1);
return (1);
}
return(0);
return (0);
}

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,14 +32,16 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)print.c 5.4 (Berkeley) 6/10/91";*/
static char rcsid[] = "$Id: print.c,v 1.8 1994/04/12 06:08:51 cgd Exp $";
/*static char sccsid[] = "from: @(#)print.c 8.6 (Berkeley) 4/16/94";*/
static char *rcsid = "$Id: print.c,v 1.9 1994/09/20 04:52:09 mycroft Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "stty.h"
#include "extern.h"
@ -54,11 +56,10 @@ print(tp, wp, ldisc, fmt)
int ldisc;
enum FMT fmt;
{
register struct cchar *p;
register long tmp;
register int cnt;
register u_char *cc;
int ispeed, ospeed;
struct cchar *p;
long tmp;
u_char *cc;
int cnt, ispeed, ospeed;
char buf1[100], buf2[100];
cnt = 0;
@ -208,6 +209,7 @@ static void
binit(lb)
char *lb;
{
if (col) {
(void)printf("\n");
col = 0;
@ -219,6 +221,7 @@ static void
bput(s)
char *s;
{
if (col == 0) {
col = printf("%s: %s", label, s);
return;
@ -240,7 +243,7 @@ ccval(p, c)
char *bp;
if (c == _POSIX_VDISABLE)
return("<undef>");
return ("<undef>");
if (p->sub == VMIN || p->sub == VTIME) {
(void)snprintf(buf, sizeof(buf), "%d", c);
@ -263,5 +266,5 @@ ccval(p, c)
else
*bp++ = c;
*bp = '\0';
return(buf);
return (buf);
}

View File

@ -1,5 +1,5 @@
.\" Copyright (c) 1990 The Regents of the University of California.
.\" All rights reserved.
.\" Copyright (c) 1990, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" the Institute of Electrical and Electronics Engineers, Inc.
@ -32,26 +32,26 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" from: @(#)stty.1 6.13 (Berkeley) 6/27/91
.\" $Id: stty.1,v 1.5 1993/08/01 07:47:49 mycroft Exp $
.\" from: @(#)stty.1 8.4 (Berkeley) 4/18/94
.\" $Id: stty.1,v 1.6 1994/09/20 04:52:11 mycroft Exp $
.\"
.Dd June 27, 1991
.Dd April 18, 1994
.Dt STTY 1
.Os
.Sh NAME
.Nm stty
.Nd Set the options for a terminal device interface.
.Nd set the options for a terminal device interface
.Sh SYNOPSIS
.Nm stty
.Op Fl a | Fl e | Fl g
.Op Fl f Ar file
.Op operands
.Sh DESCRIPTION
The
The
.Nm stty
utility sets or reports on terminal
characteristics for the device that is its standard input.
If no options or operands are specified, it reports the settings of a set
If no options or operands are specified, it reports the settings of a subset
of characteristics as well as additional ones if they differ from their
default values.
Otherwise it modifies
@ -62,26 +62,39 @@ exclusive on some terminal types.
The following options are available:
.Bl -tag -width Ds
.It Fl a
Display all the current settings for the terminal to standard output
in the
Display all the current settings for the terminal to standard output
as per
.St -p1003.2 .
.It Fl e
Display all the current settings for the terminal to standard output
Display all the current settings for the terminal to standard output
in the traditional
.Tn BSD
``all'' and ``everything'' formats.
.It Fl f
Display the current settings for the terminal named by
.Ar file .
Open and use the terminal named by
.Ar file
rather than using standard input. The file is opened
using the
.Dv O_NONBLOCK
flag of
.Fn open ,
making it possible to
set or display settings on a terminal that might otherwise
block on the open.
.It Fl g
Display all the current settings for the terminal to standard output
Display all the current settings for the terminal to standard output
in a form that may be used as an argument to a subsequent invocation of
.Nm stty
to restore the current terminal state.
to restore the current terminal state as per
.St -p1003.2 .
.El
.Pp
The following arguments are available to set the terminal
characteristics:
.Ss Control Modes:
.Pp
Control mode flags affect hardware characteristics associated with the
terminal. This corresponds to the c_cflag in the termios structure.
.Bl -tag -width Fl
.It Cm parenb Pq Fl parenb
Enable (disable) parity generation
@ -112,6 +125,13 @@ If
the output baud rate is set to
zero, modem control is
no longer asserted.
.It Cm speed Ar number
This sets both
.Cm ispeed
and
.Cm ospeed
to
.Ar number .
.It Cm hupcl Pq Fl hupcl
Stop asserting modem control
(do not stop asserting modem control) on last close.
@ -125,6 +145,12 @@ Enable (disable) the receiver.
.It Cm clocal Pq Fl clocal
Assume a line without (with) modem
control.
.It Cm crtscts Pq Fl crtscts
Enable RTS/CTS flow control.
.El
.Ss Input Modes:
This corresponds to the c_iflag in the termios structure.
.Bl -tag -width Fl
.It Cm ignbrk Pq Fl ignbrk
Ignore (do not ignore) break on
input.
@ -170,7 +196,10 @@ stopped when the system receives
.Dv STOP
and started when the system
receives
.Dv START .
.Dv START ,
or if
.Cm ixany
is set, any character restarts output.
.It Cm ixoff Pq Fl ixoff
Request that the system send (not
send)
@ -178,10 +207,60 @@ send)
characters when
the input queue is nearly
empty/full.
.It Cm ixany Pq Fl ixany
Allow any character (allow only
.Dv START )
to restart output.
.It Cm imaxbel Pq Fl imaxbel
The system imposes a limit of
.Dv MAX_INPUT
(currently 255) characters in the input queue. If
.Cm imaxbel
is set and the input queue limit has been reached,
subsequent input causes the system to send an ASCII BEL
character to the output queue (the terminal beeps at you). Otherwise,
if
.Cm imaxbel
is unset and the input queue is full, the next input character causes
the entire input and output queues to be discarded.
.El
.Ss Output Modes:
This corresponds to the c_oflag of the termios structure.
.Bl -tag -width Fl
.It Cm opost Pq Fl opost
Post-process output (do not
post-process output; ignore all other
output modes).
.It Cm onlcr Pq Fl onlcr
Map (do not map)
.Dv NL
to
.DV CR-NL
on output.
.It Cm oxtabs Pq Fl oxtabs
Expand (do not expand) tabs to spaces on output.
.El
.Ss Local Modes:
.Pp
Local mode flags (lflags) affect various and sundry characteristics of terminal
processing.
Historically the term "local" pertained to new job control features
implemented by Jim Kulp on a
.Tn Pdp 11/70
at
.Tn IIASA .
Later the driver ran on the first
.Tn VAX
at Evans Hall, UC Berkeley, where the job control details
were greatly modified but the structure definitions and names
remained essentially unchanged.
The second interpretation of the 'l' in lflag
is ``line discipline flag'' which corresponds to the
.Ar c_lflag
of the
.Ar termios
structure.
.Bl -tag -width Fl
.It Cm isig Pq Fl isig
Enable (disable) the checking of
characters against the special control
@ -216,54 +295,97 @@ Echo (do not echo)
after
.Dv KILL
character.
.It Cm echoke Pq Fl echoke
The
.Dv KILL
character shall (shall
not) visually erase the
the current line from the
display, if possible.
.It Cm echonl Pq Fl echonl
Echo (do not echo)
.Dv NL ,
even if echo
is disabled.
.It Cm echoctl Pq Fl echoctl
If
.Cm echoctl
is set, echo control characters as ^X. Otherwise control characters
echo as themselves.
.It Cm echoprt Pq Fl echoprt
For printing terminals. If set, echo erased characters backwards within ``\\''
and ``/''. Otherwise, disable this feature.
.It Cm noflsh Pq Fl noflsh
Disable (enable) flush after
.Dv INTR , QUIT , SUSP .
.It Cm control-character Ar string
Set control-character to string.
.It Cm tostop Pq Fl tostop
Send (do not send)
.Dv SIGTTOU
for background output. This causes background jobs to stop if they attempt
terminal output.
.It Cm altwerase Pq Fl altwerase
Use (do not use) an alternate word erase algorithm when processing
.Dv WERASE
characters.
This alternate algorithm considers sequences of
alphanumeric/underscores as words.
It also skips the first preceding character in its classification
(as a convenience since the one preceding character could have been
erased with simply an
.Dv ERASE
character.)
.It Cm mdmbuf Pq Fl mdmbuf
If set, flow control output based on condition of Carrier Detect. Otherwise
writes return an error if Carrier Detect is low (and Carrier is not being
ignored with the
.Dv CLOCAL
flag.)
.It Cm flusho Pq Fl flusho
Indicates output is (is not) being discarded.
.It Cm pendin Pq Fl pendin
Indicates input is (is not) pending after a switch from non-canonical
to canonical mode and will be re-input when a read becomes pending
or more input arrives.
.El
.Ss Control Characters:
.Bl -tag -width Fl
.It Ar control-character Ar string
Set
.Ar control-character
to
.Ar string .
If string is a single character,
the control character is set to
that character.
If string is the
two character sequence "^-" or the
string "undef" the control character
is set to
.Pf { Dv _POSIX_VDISABLE Ns }
if
it is in effect for the device; if
.Pf { Dv _POSIX_VDISABLE Ns }
is not in effect
for the device, it is an
error.
is disabled (i.e. set to
.Pf { Dv _POSIX_VDISABLE Ns } . )
.Pp
Recognized control-characters:
.Bd -ragged -offset indent
.Bl -column character Subscript
.It control- Ta Tn POSIX.1
.It control-
.It character Subscript Description
.It _________ _________ _______________
.It eof Ta Tn VEOF EOF No character
.It eol Ta Tn VEOL EOL No character
.It eol2 Ta Tn VEOL2 EOL2 No character
.It erase Ta Tn VERASE ERASE No character
.It werase Ta Tn VWERASE WERASE No character
.It intr Ta Tn VINTR INTR No character
.It kill Ta Tn VKILL KILL No character
.It quit Ta Tn VQUIT QUIT No character
.It susp Ta Tn VSUSP SUSP No character
.It start Ta Tn VSTART START No character
.It stop Ta Tn VSTOP STOP No character
.It dsusp Ta Tn VDSUSP DSUSP No character
.It lnext Ta Tn VLNEXT LNEXT No character
.It reprint Ta Tn VREPRINT REPRINT No character
.It status Ta Tn VSTATUS STATUS No character
.El
.Ed
.It Cm saved settings
Set the current terminal
characteristics to the saved settings
produced by the
.Fl g
option.
.It Cm min Ar number
.It Cm time Ar number
Set the value of min or time to
@ -274,6 +396,16 @@ and
are used in
Non-Canonical mode input processing
(-icanon).
.El
.Ss Combination Modes:
.Pp
.Bl -tag -width Fl
.It Ar saved settings
Set the current terminal
characteristics to the saved settings
produced by the
.Fl g
option.
.It Cm evenp No or Cm parity
Enable parenb and cs7; disable
parodd.
@ -281,7 +413,7 @@ parodd.
Enable parenb, cs7, and parodd.
.It Fl parity , evenp , oddp
Disable parenb, and set cs8.
.It Cm nl Pq Fl nl
.It Cm \&nl Pq Fl \&nl
Enable (disable) icrnl.
In addition
-nl unsets inlcr and igncr.
@ -297,16 +429,153 @@ Resets all modes to reasonable values for interactive terminal use.
.It Cm tty
Set the line discipline to the standard terminal line discipline
.Dv TTYDISC .
.It Cm crt Pq Fl crt
Set (disable) all modes suitable for a CRT display device.
.It Cm kerninfo Pq Fl kerninfo
Enable (disable) the system generated status line associated with
processing a
.Dv STATUS
character (usually set to ^T). The status line consists of the
system load average, the current command name, its process ID, the
event the process is waiting on (or the status of the process), the user
and system times, percent cpu, and current memory usage.
.It Cm columns Ar number
The terminal size is recorded as having
.Ar number
columns.
.It Cm cols Ar number
is an alias for
.Cm columns.
.It Cm rows Ar number
The terminal size is recorded as having
.Ar number
rows.
.It Cm dec
Set modes suitable for users of Digital Equipment Corporation systems (
.Dv ERASE ,
.Dv KILL ,
and
.Dv INTR
characters are set to ^?, ^U, and ^C;
.Dv ixany
is disabled, and
.Dv crt
is enabled.)
.It Cm extproc Pq Fl extproc
If set, this flag indicates that some amount of terminal processing is being
performed by either the terminal hardware or by the remote side connected
to a pty.
.It Cm raw Pq Fl raw
If set, change the modes of the terminal so that no input or output processing
is performed. If unset, change the modes of the terminal to some reasonable
state that performs input and output processing. Note that since the
terminal driver no longer has a single
.Dv RAW
bit, it is not possible to intuit what flags were set prior to setting
.Cm raw .
This means that unsetting
.Cm raw
may not put back all the setting that were previously in effect.
To set the terminal into a raw state and then accurately restore it, the following
shell code is recommended:
.nf
save_state=$(stty -g)
stty raw
\&...
stty "$save_state"
.fi
.It Cm size
The size of the terminal is printed as two numbers on a single line,
first rows, then columns.
.El
.Ss Compatibility Modes:
.Pp
These modes remain for compatibility with the previous version of
the stty command.
.Bl -tag -width Fl
.It Cm all
Reports all the terminal modes as with
.Cm stty Fl a
except that the control characters are printed in a columnar format.
.It Cm everything
Same as
.Cm all .
.It Cm cooked
Same as
.Cm sane .
.It Cm cbreak
If set, enables
.Cm brkint , ixon , imaxbel , opost ,
.Cm isig , iexten ,
and
.Cm Fl icanon .
If unset, same as
.Cm sane .
.It Cm new
Same as
.Cm tty .
.It Cm old
Same as
.Cm tty .
.It Cm newcrt Pq Fl newcrt
Same as
.Cm crt .
.It Cm pass8
The converse of
.Cm parity .
.It Cm tandem Pq Fl tandem
Same as
.Cm ixoff .
.It Cm decctlq Pq Fl decctlq
The converse of
.Cm ixany .
.It Cm crterase Pq Fl crterase
Same as
.Cm echoe .
.It Cm crtbs Pq Fl crtbs
Same as
.Cm echoe .
.It Cm crtkill Pq Fl crtkill
Same as
.Cm echoke .
.It Cm ctlecho Pq Fl ctlecho
Same as
.Cm echoctl .
.It Cm prterase Pq Fl prterase
Same as
.Cm echoprt .
.It Cm litout Pq Fl litout
The converse of
.Cm opost .
.It Cm tabs Pq Fl tabs
The converse of
.Cm tabs .
.It Cm brk Ar value
Same as the control character
.Cm eol .
.It Cm flush Ar value
Same as the control character
.Cm discard .
.It Cm rprnt Ar value
Same as the control character
.Cm reprint .
.El
.Pp
The
.Nm stty
utility exits with a value of 0 if successful, and >0 if an error occurs.
.Sh SEE ALSO
.Xr stty 4
.Xr termios 4
.Sh STANDARDS
The
.Nm stty
function is expected to be
.St -p1003.2
compatible.
compatible. The flags
.Fl e
and
.Fl f
are
extensions to the standard.

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 1989, 1991 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1989, 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,39 +32,34 @@
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1989, 1991 The Regents of the University of California.\n\
All rights reserved.\n";
static char copyright[] =
"@(#) Copyright (c) 1989, 1991, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
/*static char sccsid[] = "from: @(#)stty.c 5.28 (Berkeley) 6/5/91";*/
static char rcsid[] = "$Id: stty.c,v 1.9 1994/03/23 04:05:33 mycroft Exp $";
/*static char sccsid[] = "from: @(#)stty.c 8.3 (Berkeley) 4/2/94";*/
static char *rcsid = "$Id: stty.c,v 1.10 1994/09/20 04:52:12 mycroft Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <err.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "stty.h"
#include "extern.h"
void
usage()
{
fprintf(stderr, "usage: stty: [-eg] [-f file] [options]\n");
exit(1);
}
int
main(argc, argv)
int argc;
char **argv;
char *argv[];
{
struct info i;
enum FMT fmt;
@ -74,9 +69,9 @@ main(argc, argv)
i.fd = STDIN_FILENO;
opterr = 0;
while (argv[optind] &&
strspn(argv[optind], "-aefg") == strlen(argv[optind]) &&
(ch = getopt(argc, argv, "aef:g")) != EOF)
while (optind < argc &&
strspn(argv[optind], "-aefg") == strlen(argv[optind]) &&
(ch = getopt(argc, argv, "aef:g")) != -1)
switch(ch) {
case 'a': /* undocumented: POSIX compatibility */
fmt = POSIX;
@ -156,3 +151,11 @@ args: argc -= optind;
warn("TIOCSWINSZ");
exit(0);
}
void
usage()
{
(void)fprintf(stderr, "usage: stty: [-a|-e|-g] [-f file] [options]\n");
exit (1);
}

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -30,8 +30,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)stty.h 5.3 (Berkeley) 6/10/91
* $Id: stty.h,v 1.4 1993/06/01 14:42:18 cgd Exp $
* from: @(#)stty.h 8.1 (Berkeley) 5/31/93
* $Id: stty.h,v 1.5 1994/09/20 04:52:12 mycroft Exp $
*/
#include <sys/ioctl.h>