* Copyright (c) 1980, 1991 The Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1980, 1991 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)tset.c 5.19 (Berkeley) %G%";
void obsolete
__P((char *[]));
void report
__P((char *, int, u_int
));
struct termios mode
, oldmode
;
int dosetenv
; /* output TERMCAP strings */
int erasechar
; /* new erase character */
int intrchar
; /* new interrupt character */
int isreset
; /* invoked as reset */
int killchar
; /* new kill character */
int noinit
; /* don't output initialization string */
int noset
; /* only report term type */
int quiet
; /* don't display ctrl key settings */
int showterm
; /* display term on stderr */
int lines
, columns
; /* window size */
char savech
, *p
, *t
, *tcapbuf
, *ttype
;
if (tcgetattr(STDERR_FILENO
, &mode
) < 0)
err("standard error: %s", strerror(errno
));
ospeed
= cfgetospeed(&mode
);
if (p
= strrchr(*argv
, '/'))
usingupper
= isupper(*p
);
if (!strcasecmp(p
, "reset")) {
while ((ch
= getopt(argc
, argv
, "-a:d:e:Ii:k:m:np:Qrs")) != EOF
) {
case '-': /* OBSOLETE: display term only */
case 'a': /* OBSOLETE: map identifier to type */
add_mapping("arpanet", optarg
);
case 'd': /* OBSOLETE: map identifier to type */
add_mapping("dialup", optarg
);
case 'e': /* erase character */
erasechar
= optarg
[0] == '^' && optarg
[1] != '\0' ?
optarg
[1] == '?' ? '\177' : CTRL(optarg
[1]) :
case 'I': /* no initialization */
case 'i': /* interrupt character */
intrchar
= optarg
[0] == '^' && optarg
[1] != '\0' ?
optarg
[1] == '?' ? '\177' : CTRL(optarg
[1]) :
case 'k': /* kill character */
killchar
= optarg
[0] == '^' && optarg
[1] != '\0' ?
optarg
[1] == '?' ? '\177' : CTRL(optarg
[1]) :
case 'm': /* map identifier to type */
add_mapping(NULL
, optarg
);
case 'n': /* OBSOLETE: set new tty driver */
case 'p': /* OBSOLETE: map identifier to type */
add_mapping("plugboard", optarg
);
case 'r': /* display term on stderr */
case 's': /* print commands to set environment */
ttype
= get_termcap_entry(*argv
, &tcapbuf
);
(void)ioctl(STDERR_FILENO
, TIOCGWINSZ
, &win
);
if (win
.ws_row
== 0 && win
.ws_col
== 0 &&
lines
> 0 && columns
> 0) {
(void)ioctl(STDERR_FILENO
, TIOCSWINSZ
, &win
);
set_conversions(usingupper
);
/* Set the modes if they've changed. */
if (memcmp(&mode
, &oldmode
, sizeof(mode
)))
tcsetattr(STDERR_FILENO
, TCSADRAIN
, &mode
);
* The termcap file generally has a two-character name first in each
* entry followed by more descriptive names. If we ended up with the
* first one, we switch to the second one for setting or reporting
p
= strpbrk(tcapbuf
, "|:");
if (p
&& *p
!= ':' && !strncmp(ttype
, tcapbuf
, p
- tcapbuf
)) {
if (p
= strpbrk(p
, "|:")) {
if ((ttype
= strdup(t
)) == NULL
)
err("%s", strerror(errno
));
(void)printf("%s\n", ttype
);
(void)fprintf(stderr
, "Terminal type is %s.\n", ttype
);
* If erase, kill and interrupt characters could have been
* modified and not -Q, display the changes.
report("Erase", VERASE
, CERASE
);
report("Kill", VKILL
, CKILL
);
report("Interrupt", VINTR
, CINTR
);
* Figure out what shell we're using. A hack, we look for a $SHELL
csh
= (p
= getenv("SHELL")) && !strcmp(p
+ strlen(p
) - 3, "csh");
(void)printf("set noglob;\nsetenv TERM %s;\nsetenv TERMCAP '",
(void)printf("TERM=%s;\nTERMCAP='", ttype
);
(void)printf("';\nunset noglob;\n");
(void)printf("';\nexport TERMCAP TERM;\n");
* Tell the user if a control key has been changed from the default value.
old
= oldmode
.c_cc
[which
];
if (old
== new && old
== def
)
(void)fprintf(stderr
, "%s %s ", name
, old
== new ? "is" : "set to");
if (tgetstr("kb", &bp
) && new == buf
[0] && buf
[1] == '\0')
(void)fprintf(stderr
, "backspace.\n");
(void)fprintf(stderr
, "delete.\n");
(void)fprintf(stderr
, "control-%c (^%c).\n", new, new);
(void)fprintf(stderr
, "%c.\n", new);
* Convert the obsolete argument form into something that getopt can handle.
* This means that -e, -i and -k get default arguments supplied for them.
if (argv
[0][0] != '-' || argv
[1] && argv
[1][0] != '-' ||
argv
[0][1] != 'e' && argv
[0][1] != 'i' &&
argv
[0][1] != 'k' || argv
[0][2] != '\0')
"usage: tset [-IQrs] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]\n");