* Copyright (c) 1989, 1991 The Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1989, 1991 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)stty.c 5.24 (Berkeley) %G%";
static void usage
__P((void));
extern int opterr
, optind
;
extern struct cchar cchars1
[], cchars2
[];
extern struct modes cmodes
[], imodes
[], lmodes
[], omodes
[];
register struct modes
*mp
;
register struct cchar
*cp
;
while ((ch
= getopt(argc
, argv
, "aef:g")) != EOF
)
case 'a': /* undocumented: POSIX compatibility */
if ((ctl
= open(optarg
, O_RDONLY
| O_NONBLOCK
)) < 0)
if (ioctl(ctl
, TIOCGETD
, &ldisc
) < 0)
err("TIOCGETD: %s", strerror(errno
));
if (tcgetattr(ctl
, &t
) < 0)
err("tcgetattr: %s", strerror(errno
));
if (ioctl(ctl
, TIOCGWINSZ
, &win
) < 0)
warn("TIOCGWINSZ: %s\n", strerror(errno
));
checkredirect(); /* conversion aid */
print(&t
, &win
, ldisc
, fmt
);
#define CHK(s) (**argv == s[0] && !strcmp(*argv, s))
print(&t
, &win
, ldisc
, BSD
);
t
.c_iflag
| BRKINT
|IXON
|IMAXBEL
;
t
.c_lflag
|= ISIG
|IEXTEN
;
err("option requires an argument -- cols");
err("option requires an argument -- columns");
columns
: win
.ws_col
= atoi(*argv
);
t
.c_cc
[VERASE
] = (u_char
)0177;
t
.c_cc
[VKILL
] = CTRL('u');
t
.c_cc
[VINTR
] = CTRL('c');
t
.c_lflag
|= ECHOE
|ECHOKE
|ECHOCTL
;
print(&t
, &win
, ldisc
, BSD
);
ioctl(ctl
, TIOCEXT
, &tmp
);
ioctl(ctl
, TIOCEXT
, &tmp
);
err("option requires an argument -- ispeed");
cfsetispeed(&t
, atoi(*argv
));
err("option requires an argument -- ospeed");
cfsetospeed(&t
, atoi(*argv
));
t
.c_cflag
&= ~(CSIZE
|PARENB
);
err("option requires an argument -- rows");
win
.ws_row
= atoi(*argv
);
reset
: t
.c_cflag
= TTYDEF_CFLAG
| (t
.c_cflag
& CLOCAL
);
t
.c_iflag
= TTYDEF_IFLAG
;
/* preserve user-preference flags in lflag */
#define LKEEP (ECHOKE|ECHOE|ECHOK|ECHOPRT|ECHOCTL|ALTWERASE|TOSTOP|NOFLSH)
t
.c_lflag
= TTYDEF_LFLAG
| (t
.c_lflag
& LKEEP
);
t
.c_oflag
= TTYDEF_OFLAG
;
(void)printf("%d %d\n", win
.ws_row
, win
.ws_col
);
(void)printf("%d\n", cfgetospeed(&t
));
if (ioctl(0, TIOCSETD
, &tmp
) < 0)
err("TIOCSETD: %s", strerror(errno
));
for (mp
= cmodes
; mp
->name
; ++mp
)
for (mp
= imodes
; mp
->name
; ++mp
)
for (mp
= lmodes
; mp
->name
; ++mp
)
for (mp
= omodes
; mp
->name
; ++mp
)
for (cp
= cchars1
; cp
->name
; ++cp
) {
for (cp
= cchars2
; cp
->name
; ++cp
) {
err("option requires an argument -- %s",
if (CHK("undef") || CHK("<undef>"))
t
.c_cc
[cp
->sub
] = _POSIX_VDISABLE
;
((*argv
)[1] == '?') ? 0177 :
((*argv
)[1] == '-') ? _POSIX_VDISABLE
:
t
.c_cc
[cp
->sub
] = **argv
;
cfsetospeed(&t
, atoi(*argv
));
cfsetispeed(&t
, atoi(*argv
));
if (!strncmp(*argv
, "gfmt1", sizeof("gfmt1") - 1)) {
gread(&t
, *argv
+ sizeof("gfmt1") - 1);
err("illegal option -- %s", *argv
);
if (tcsetattr(ctl
, 0, &t
) < 0)
err("tcsetattr: %s", strerror(errno
));
if (ioctl(ctl
, TIOCSWINSZ
, &win
) < 0)
warn("TIOCSWINSZ: %s", strerror(errno
));
(void)fprintf(stderr
, "usage: stty: [-eg] [-f file] [options]\n");