1994-05-26 06:18:55 +00:00
|
|
|
/*-
|
|
|
|
* 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
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-08-24 00:26:12 +00:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)key.c 8.3 (Berkeley) 4/2/94";
|
|
|
|
#else
|
|
|
|
static const char rcsid[] =
|
1999-08-27 23:15:48 +00:00
|
|
|
"$FreeBSD$";
|
1997-08-24 00:26:12 +00:00
|
|
|
#endif
|
1994-05-26 06:18:55 +00:00
|
|
|
#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"
|
|
|
|
|
|
|
|
__BEGIN_DECLS
|
2002-02-02 06:50:57 +00:00
|
|
|
static int c_key(const void *, const void *);
|
|
|
|
void f_all(struct info *);
|
|
|
|
void f_cbreak(struct info *);
|
|
|
|
void f_columns(struct info *);
|
|
|
|
void f_dec(struct info *);
|
|
|
|
void f_ek(struct info *);
|
|
|
|
void f_everything(struct info *);
|
|
|
|
void f_extproc(struct info *);
|
|
|
|
void f_ispeed(struct info *);
|
|
|
|
void f_nl(struct info *);
|
|
|
|
void f_ospeed(struct info *);
|
|
|
|
void f_raw(struct info *);
|
|
|
|
void f_rows(struct info *);
|
|
|
|
void f_sane(struct info *);
|
|
|
|
void f_size(struct info *);
|
|
|
|
void f_speed(struct info *);
|
|
|
|
void f_tty(struct info *);
|
1994-05-26 06:18:55 +00:00
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
static struct key {
|
2001-05-18 11:04:19 +00:00
|
|
|
const char *name; /* name */
|
2002-02-02 06:50:57 +00:00
|
|
|
void (*f)(struct info *); /* function */
|
1994-05-26 06:18:55 +00:00
|
|
|
#define F_NEEDARG 0x01 /* needs an argument */
|
|
|
|
#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 },
|
2001-08-23 22:31:13 +00:00
|
|
|
{ "ek", f_ek, 0 },
|
1994-05-26 06:18:55 +00:00
|
|
|
{ "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
|
2002-02-02 06:50:57 +00:00
|
|
|
c_key(const void *a, const void *b)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
2001-05-18 11:04:19 +00:00
|
|
|
return (strcmp(((const struct key *)a)->name, ((const struct key *)b)->name));
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-02-02 06:50:57 +00:00
|
|
|
ksearch(char ***argvp, struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
struct key *kp, tmp;
|
|
|
|
|
|
|
|
name = **argvp;
|
|
|
|
if (*name == '-') {
|
|
|
|
ip->off = 1;
|
|
|
|
++name;
|
|
|
|
} else
|
|
|
|
ip->off = 0;
|
|
|
|
|
|
|
|
tmp.name = name;
|
|
|
|
if (!(kp = (struct key *)bsearch(&tmp, keys,
|
|
|
|
sizeof(keys)/sizeof(struct key), sizeof(struct key), c_key)))
|
|
|
|
return (0);
|
|
|
|
if (!(kp->flags & F_OFFOK) && ip->off) {
|
1997-08-24 00:26:12 +00:00
|
|
|
warnx("illegal option -- -%s", name);
|
1994-05-26 06:18:55 +00:00
|
|
|
usage();
|
|
|
|
}
|
|
|
|
if (kp->flags & F_NEEDARG && !(ip->arg = *++*argvp)) {
|
1997-08-24 00:26:12 +00:00
|
|
|
warnx("option requires an argument -- %s", name);
|
1994-05-26 06:18:55 +00:00
|
|
|
usage();
|
|
|
|
}
|
|
|
|
kp->f(ip);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_all(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
2000-04-30 17:04:26 +00:00
|
|
|
print(&ip->t, &ip->win, ip->ldisc, BSD);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_cbreak(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (ip->off)
|
|
|
|
f_sane(ip);
|
|
|
|
else {
|
|
|
|
ip->t.c_iflag |= BRKINT|IXON|IMAXBEL;
|
|
|
|
ip->t.c_oflag |= OPOST;
|
|
|
|
ip->t.c_lflag |= ISIG|IEXTEN;
|
|
|
|
ip->t.c_lflag &= ~ICANON;
|
|
|
|
ip->set = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_columns(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
ip->win.ws_col = atoi(ip->arg);
|
|
|
|
ip->wset = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_dec(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
ip->t.c_cc[VERASE] = (u_char)0177;
|
|
|
|
ip->t.c_cc[VKILL] = CTRL('u');
|
|
|
|
ip->t.c_cc[VINTR] = CTRL('c');
|
|
|
|
ip->t.c_lflag &= ~ECHOPRT;
|
|
|
|
ip->t.c_lflag |= ECHOE|ECHOKE|ECHOCTL;
|
|
|
|
ip->t.c_iflag &= ~IXANY;
|
|
|
|
ip->set = 1;
|
|
|
|
}
|
|
|
|
|
2001-08-23 22:31:13 +00:00
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_ek(struct info *ip)
|
2001-08-23 22:31:13 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
ip->t.c_cc[VERASE] = CERASE;
|
|
|
|
ip->t.c_cc[VKILL] = CKILL;
|
|
|
|
ip->set = 1;
|
|
|
|
}
|
|
|
|
|
1994-05-26 06:18:55 +00:00
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_everything(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
2000-04-30 17:04:26 +00:00
|
|
|
print(&ip->t, &ip->win, ip->ldisc, BSD);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_extproc(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
1996-12-14 06:16:51 +00:00
|
|
|
if (ip->off) {
|
|
|
|
int tmp = 0;
|
1994-05-26 06:18:55 +00:00
|
|
|
(void)ioctl(ip->fd, TIOCEXT, &tmp);
|
|
|
|
} else {
|
1996-12-14 06:16:51 +00:00
|
|
|
int tmp = 1;
|
1994-05-26 06:18:55 +00:00
|
|
|
(void)ioctl(ip->fd, TIOCEXT, &tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_ispeed(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
2001-05-18 11:04:19 +00:00
|
|
|
cfsetispeed(&ip->t, (speed_t)atoi(ip->arg));
|
1994-05-26 06:18:55 +00:00
|
|
|
ip->set = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_nl(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (ip->off) {
|
|
|
|
ip->t.c_iflag |= ICRNL;
|
|
|
|
ip->t.c_oflag |= ONLCR;
|
|
|
|
} else {
|
|
|
|
ip->t.c_iflag &= ~ICRNL;
|
|
|
|
ip->t.c_oflag &= ~ONLCR;
|
|
|
|
}
|
|
|
|
ip->set = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_ospeed(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
2001-05-18 11:04:19 +00:00
|
|
|
cfsetospeed(&ip->t, (speed_t)atoi(ip->arg));
|
1994-05-26 06:18:55 +00:00
|
|
|
ip->set = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_raw(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (ip->off)
|
|
|
|
f_sane(ip);
|
|
|
|
else {
|
|
|
|
cfmakeraw(&ip->t);
|
|
|
|
ip->t.c_cflag &= ~(CSIZE|PARENB);
|
|
|
|
ip->t.c_cflag |= CS8;
|
|
|
|
ip->set = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_rows(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
ip->win.ws_row = atoi(ip->arg);
|
|
|
|
ip->wset = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_sane(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
ip->t.c_cflag = TTYDEF_CFLAG | (ip->t.c_cflag & CLOCAL);
|
|
|
|
ip->t.c_iflag = TTYDEF_IFLAG;
|
|
|
|
ip->t.c_iflag |= ICRNL;
|
|
|
|
/* preserve user-preference flags in lflag */
|
|
|
|
#define LKEEP (ECHOKE|ECHOE|ECHOK|ECHOPRT|ECHOCTL|ALTWERASE|TOSTOP|NOFLSH)
|
|
|
|
ip->t.c_lflag = TTYDEF_LFLAG | (ip->t.c_lflag & LKEEP);
|
|
|
|
ip->t.c_oflag = TTYDEF_OFLAG;
|
|
|
|
ip->set = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_size(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
(void)printf("%d %d\n", ip->win.ws_row, ip->win.ws_col);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_speed(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
1998-06-28 18:08:54 +00:00
|
|
|
(void)printf("%lu\n", (u_long)cfgetospeed(&ip->t));
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-02 06:50:57 +00:00
|
|
|
f_tty(struct info *ip)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
|
|
|
|
tmp = TTYDISC;
|
1995-04-28 19:29:30 +00:00
|
|
|
if (ioctl(ip->fd, TIOCSETD, &tmp) < 0)
|
1994-05-26 06:18:55 +00:00
|
|
|
err(1, "TIOCSETD");
|
|
|
|
}
|