version 1.34, 2009/11/11 23:49:01 |
version 1.35, 2010/01/12 23:22:14 |
|
|
/* $OpenBSD$ */ |
/* $OpenBSD$ */ |
|
|
/**************************************************************************** |
/**************************************************************************** |
* Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * |
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * |
* * |
* * |
* Permission is hereby granted, free of charge, to any person obtaining a * |
* Permission is hereby granted, free of charge, to any person obtaining a * |
* copy of this software and associated documentation files (the * |
* copy of this software and associated documentation files (the * |
|
|
/**************************************************************************** |
/**************************************************************************** |
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * |
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * |
* and: Eric S. Raymond <esr@snark.thyrsus.com> * |
* and: Eric S. Raymond <esr@snark.thyrsus.com> * |
|
* and: Thomas E. Dickey 1996-on * |
****************************************************************************/ |
****************************************************************************/ |
|
|
/* |
/* |
|
|
* SUCH DAMAGE. |
* SUCH DAMAGE. |
*/ |
*/ |
|
|
|
#define USE_LIBTINFO |
#define __INTERNAL_CAPS_VISIBLE /* we need to see has_hardware_tabs */ |
#define __INTERNAL_CAPS_VISIBLE /* we need to see has_hardware_tabs */ |
#include <progs.priv.h> |
#include <progs.priv.h> |
|
|
|
|
char *ttyname(int fd); |
char *ttyname(int fd); |
#endif |
#endif |
|
|
/* this is just to stifle a missing-prototype warning */ |
#if HAVE_SIZECHANGE |
#if defined(linux) || defined(__OpenBSD__) |
# if !defined(sun) || !TERMIOS |
# include <sys/ioctl.h> |
# if HAVE_SYS_IOCTL_H |
|
# include <sys/ioctl.h> |
|
# endif |
|
# endif |
#endif |
#endif |
|
|
#if NEED_PTEM_H |
#if NEED_PTEM_H |
/* they neglected to define struct winsize in termios.h -- it's only |
/* they neglected to define struct winsize in termios.h -- it's only |
in termio.h */ |
in termio.h */ |
#include <sys/stream.h> |
#include <sys/stream.h> |
#include <sys/ptem.h> |
#include <sys/ptem.h> |
#endif |
#endif |
|
|
#include <curses.h> /* for bool typedef */ |
|
#include <dump_entry.h> |
#include <dump_entry.h> |
#include <transform.h> |
#include <transform.h> |
|
|
MODULE_ID("$From: tset.c,v 0.49 2001/02/24 23:29:33 tom Exp $") |
MODULE_ID("$Id$") |
|
|
|
/* |
|
* SCO defines TIOCGSIZE and the corresponding struct. Other systems (SunOS, |
|
* Solaris, IRIX) define TIOCGWINSZ and struct winsize. |
|
*/ |
|
#ifdef TIOCGSIZE |
|
# define IOCTL_GET_WINSIZE TIOCGSIZE |
|
# define IOCTL_SET_WINSIZE TIOCSSIZE |
|
# define STRUCT_WINSIZE struct ttysize |
|
# define WINSIZE_ROWS(n) n.ts_lines |
|
# define WINSIZE_COLS(n) n.ts_cols |
|
#else |
|
# ifdef TIOCGWINSZ |
|
# define IOCTL_GET_WINSIZE TIOCGWINSZ |
|
# define IOCTL_SET_WINSIZE TIOCSWINSZ |
|
# define STRUCT_WINSIZE struct winsize |
|
# define WINSIZE_ROWS(n) n.ws_row |
|
# define WINSIZE_COLS(n) n.ws_col |
|
# endif |
|
#endif |
|
|
extern char **environ; |
extern char **environ; |
|
|
#undef CTRL |
#undef CTRL |
|
|
|
|
const char *_nc_progname = "tset"; |
const char *_nc_progname = "tset"; |
|
|
static TTY mode, oldmode; |
static TTY mode, oldmode, original; |
|
|
|
static bool opt_c; /* set control-chars */ |
|
static bool opt_w; /* set window-size */ |
|
|
|
static bool can_restore = FALSE; |
static bool isreset = FALSE; /* invoked as reset */ |
static bool isreset = FALSE; /* invoked as reset */ |
static int terasechar = -1; /* new erase character */ |
static int terasechar = -1; /* new erase character */ |
static int intrchar = -1; /* new interrupt character */ |
static int intrchar = -1; /* new interrupt character */ |
static int tkillchar = -1; /* new kill character */ |
static int tkillchar = -1; /* new kill character */ |
static int tlines, tcolumns; /* window size */ |
static int tlines, tcolumns; /* window size */ |
|
|
#define LOWERCASE(c) ((isalpha(CharOf(c)) && isupper(CharOf(c))) ? tolower(CharOf(c)) : (c)) |
#define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c)) |
|
|
static int |
static int |
CaselessCmp(const char *a, const char *b) |
CaselessCmp(const char *a, const char *b) |
|
|
} |
} |
|
|
static void |
static void |
|
exit_error(void) |
|
{ |
|
if (can_restore) |
|
SET_TTY(STDERR_FILENO, &original); |
|
(void) fprintf(stderr, "\n"); |
|
fflush(stderr); |
|
ExitProgram(EXIT_FAILURE); |
|
/* NOTREACHED */ |
|
} |
|
|
|
static void |
err(const char *fmt,...) |
err(const char *fmt,...) |
{ |
{ |
va_list ap; |
va_list ap; |
va_start(ap, fmt); |
va_start(ap, fmt); |
(void) fprintf(stderr, "tset: "); |
(void) fprintf(stderr, "%s: ", _nc_progname); |
(void) vfprintf(stderr, fmt, ap); |
(void) vfprintf(stderr, fmt, ap); |
va_end(ap); |
va_end(ap); |
(void) fprintf(stderr, "\n"); |
exit_error(); |
exit(EXIT_FAILURE); |
|
/* NOTREACHED */ |
/* NOTREACHED */ |
} |
} |
|
|
static void |
static void |
failed(const char *msg) |
failed(const char *msg) |
{ |
{ |
(void)fputs("tset: ", stderr); |
fprintf(stderr, "%s: ", _nc_progname); |
perror(msg); |
perror(msg); |
exit(EXIT_FAILURE); |
exit_error(); |
/* NOTREACHED */ |
/* NOTREACHED */ |
} |
} |
|
|
static void |
static void |
cat(char *file) |
cat(char *file) |
{ |
{ |
int fd, nr; |
FILE *fp; |
|
size_t nr; |
char buf[BUFSIZ]; |
char buf[BUFSIZ]; |
|
|
if ((fd = open(file, O_RDONLY, 0)) < 0) |
if ((fp = fopen(file, "r")) == 0) |
failed(file); |
failed(file); |
|
|
while ((nr = read(fd, buf, sizeof(buf))) > 0) |
while ((nr = fread(buf, sizeof(char), sizeof(buf), fp)) != 0) |
if (write(STDERR_FILENO, buf, (size_t) nr) == -1) |
if (fwrite(buf, sizeof(char), nr, stderr) != nr) |
failed("write to stderr"); |
failed("write to stderr"); |
if (nr != 0) |
fclose(fp); |
failed(file); |
|
(void) close(fd); |
|
} |
} |
|
|
static int |
static int |
|
|
static char answer[256]; |
static char answer[256]; |
|
|
/* We can get recalled; if so, don't continue uselessly. */ |
/* We can get recalled; if so, don't continue uselessly. */ |
|
clearerr(stdin); |
if (feof(stdin) || ferror(stdin)) { |
if (feof(stdin) || ferror(stdin)) { |
(void) fprintf(stderr, "\n"); |
(void) fprintf(stderr, "\n"); |
exit(EXIT_FAILURE); |
exit_error(); |
|
/* NOTREACHED */ |
} |
} |
for (;;) { |
for (;;) { |
if (dflt) |
if (dflt) |
|
|
|
|
if (fgets(answer, sizeof(answer), stdin) == NULL) { |
if (fgets(answer, sizeof(answer), stdin) == NULL) { |
if (dflt == 0) { |
if (dflt == 0) { |
(void) fprintf(stderr, "\n"); |
exit_error(); |
exit(EXIT_FAILURE); |
/* NOTREACHED */ |
} |
} |
return (dflt); |
return (dflt); |
} |
} |
|
|
char *base = 0; |
char *base = 0; |
|
|
copy = strdup(arg); |
copy = strdup(arg); |
mapp = malloc(sizeof(MAP)); |
mapp = (MAP *) malloc(sizeof(MAP)); |
if (copy == 0 || mapp == 0) |
if (copy == 0 || mapp == 0) |
failed("malloc"); |
failed("malloc"); |
mapp->next = 0; |
mapp->next = 0; |
|
|
mapp->conditional = ~mapp->conditional & (EQ | GT | LT); |
mapp->conditional = ~mapp->conditional & (EQ | GT | LT); |
|
|
/* If user specified a port with an option flag, set it. */ |
/* If user specified a port with an option flag, set it. */ |
done:if (port) { |
done: |
if (mapp->porttype) |
if (port) { |
badmopt:err("illegal -m option format: %s", copy); |
if (mapp->porttype) { |
|
badmopt: |
|
err("illegal -m option format: %s", copy); |
|
} |
mapp->porttype = port; |
mapp->porttype = port; |
} |
} |
free(copy); |
free(copy); |
|
|
|
|
while (fgets(buffer, sizeof(buffer), fp) != NULL) { |
while (fgets(buffer, sizeof(buffer), fp) != NULL) { |
for (s = buffer, t = d = 0; *s; s++) { |
for (s = buffer, t = d = 0; *s; s++) { |
if (isspace(CharOf(*s))) |
if (isspace(UChar(*s))) |
*s = '\0'; |
*s = '\0'; |
else if (t == 0) |
else if (t == 0) |
t = s; |
t = s; |
|
|
* real entry from /etc/termcap. This prevents us from being fooled |
* real entry from /etc/termcap. This prevents us from being fooled |
* by out of date stuff in the environment. |
* by out of date stuff in the environment. |
*/ |
*/ |
found:if ((p = getenv("TERMCAP")) != 0 && *p != '/') { |
found:if ((p = getenv("TERMCAP")) != 0 && !_nc_is_abs_path(p)) { |
/* 'unsetenv("TERMCAP")' is not portable. |
/* 'unsetenv("TERMCAP")' is not portable. |
* The 'environ' array is better. |
* The 'environ' array is better. |
*/ |
*/ |
|
|
while (setupterm((NCURSES_CONST char *) ttype, STDOUT_FILENO, &errret) |
while (setupterm((NCURSES_CONST char *) ttype, STDOUT_FILENO, &errret) |
!= OK) { |
!= OK) { |
if (errret == 0) { |
if (errret == 0) { |
(void) fprintf(stderr, "tset: unknown terminal type %s\n", |
(void) fprintf(stderr, "%s: unknown terminal type %s\n", |
ttype); |
_nc_progname, ttype); |
ttype = 0; |
ttype = 0; |
} else { |
} else { |
(void) fprintf(stderr, |
(void) fprintf(stderr, |
"tset: can't initialize terminal type %s (error %d)\n", |
"%s: can't initialize terminal type %s (error %d)\n", |
ttype, errret); |
_nc_progname, ttype, errret); |
ttype = 0; |
ttype = 0; |
} |
} |
ttype = askuser(ttype); |
ttype = askuser(ttype); |
|
|
**************************************************************************/ |
**************************************************************************/ |
|
|
/* some BSD systems have these built in, some systems are missing |
/* some BSD systems have these built in, some systems are missing |
* one or more definitions. The safest solution is to override. |
* one or more definitions. The safest solution is to override unless the |
|
* commonly-altered ones are defined. |
*/ |
*/ |
|
#if !(defined(CERASE) && defined(CINTR) && defined(CKILL) && defined(CQUIT)) |
#undef CEOF |
#undef CEOF |
#undef CERASE |
#undef CERASE |
#undef CINTR |
#undef CINTR |
|
|
#undef CSTART |
#undef CSTART |
#undef CSTOP |
#undef CSTOP |
#undef CSUSP |
#undef CSUSP |
|
#endif |
|
|
/* control-character defaults */ |
/* control-character defaults */ |
|
#ifndef CEOF |
#define CEOF CTRL('D') |
#define CEOF CTRL('D') |
|
#endif |
|
#ifndef CERASE |
#define CERASE CTRL('H') |
#define CERASE CTRL('H') |
|
#endif |
|
#ifndef CINTR |
#define CINTR 127 /* ^? */ |
#define CINTR 127 /* ^? */ |
|
#endif |
|
#ifndef CKILL |
#define CKILL CTRL('U') |
#define CKILL CTRL('U') |
|
#endif |
|
#ifndef CLNEXT |
#define CLNEXT CTRL('v') |
#define CLNEXT CTRL('v') |
|
#endif |
|
#ifndef CRPRNT |
#define CRPRNT CTRL('r') |
#define CRPRNT CTRL('r') |
|
#endif |
|
#ifndef CQUIT |
#define CQUIT CTRL('\\') |
#define CQUIT CTRL('\\') |
|
#endif |
|
#ifndef CSTART |
#define CSTART CTRL('Q') |
#define CSTART CTRL('Q') |
|
#endif |
|
#ifndef CSTOP |
#define CSTOP CTRL('S') |
#define CSTOP CTRL('S') |
|
#endif |
|
#ifndef CSUSP |
#define CSUSP CTRL('Z') |
#define CSUSP CTRL('Z') |
|
#endif |
|
|
#define CHK(val, dft) ((int)val <= 0 ? dft : val) |
#if defined(_POSIX_VDISABLE) |
|
#define DISABLED(val) (((_POSIX_VDISABLE != -1) \ |
|
&& ((val) == _POSIX_VDISABLE)) \ |
|
|| ((val) <= 0)) |
|
#else |
|
#define DISABLED(val) ((int)(val) <= 0) |
|
#endif |
|
|
|
#define CHK(val, dft) (DISABLED(val) ? dft : val) |
|
|
static bool set_tabs(void); |
static bool set_tabs(void); |
|
|
/* |
/* |
|
|
| OFDEL |
| OFDEL |
#endif |
#endif |
#ifdef NLDLY |
#ifdef NLDLY |
| NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY |
| NLDLY |
#endif |
#endif |
|
#ifdef CRDLY |
|
| CRDLY |
|
#endif |
|
#ifdef TABDLY |
|
| TABDLY |
|
#endif |
|
#ifdef BSDLY |
|
| BSDLY |
|
#endif |
|
#ifdef VTDLY |
|
| VTDLY |
|
#endif |
|
#ifdef FFDLY |
|
| FFDLY |
|
#endif |
); |
); |
|
|
mode.c_oflag |= (OPOST |
mode.c_oflag |= (OPOST |
|
|
); |
); |
#endif |
#endif |
|
|
#ifdef TERMIOS |
SET_TTY(STDERR_FILENO, &mode); |
tcsetattr(STDERR_FILENO, TCSADRAIN, &mode); |
|
#else |
|
stty(STDERR_FILENO, &mode); |
|
#endif |
|
} |
} |
|
|
/* |
/* |
|
|
set_control_chars(void) |
set_control_chars(void) |
{ |
{ |
#ifdef TERMIOS |
#ifdef TERMIOS |
if (mode.c_cc[VERASE] == 0 || terasechar >= 0) |
if (DISABLED(mode.c_cc[VERASE]) || terasechar >= 0) |
mode.c_cc[VERASE] = terasechar >= 0 ? terasechar : default_erase(); |
mode.c_cc[VERASE] = (terasechar >= 0) ? terasechar : default_erase(); |
|
|
if (mode.c_cc[VINTR] == 0 || intrchar >= 0) |
if (DISABLED(mode.c_cc[VINTR]) || intrchar >= 0) |
mode.c_cc[VINTR] = intrchar >= 0 ? intrchar : CINTR; |
mode.c_cc[VINTR] = (intrchar >= 0) ? intrchar : CINTR; |
|
|
if (mode.c_cc[VKILL] == 0 || tkillchar >= 0) |
if (DISABLED(mode.c_cc[VKILL]) || tkillchar >= 0) |
mode.c_cc[VKILL] = tkillchar >= 0 ? tkillchar : CKILL; |
mode.c_cc[VKILL] = (tkillchar >= 0) ? tkillchar : CKILL; |
#endif |
#endif |
} |
} |
|
|
|
|
#ifdef TAB3 |
#ifdef TAB3 |
if (oldmode.c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) { |
if (oldmode.c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) { |
oldmode.c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET); |
oldmode.c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET); |
tcsetattr(STDERR_FILENO, TCSADRAIN, &oldmode); |
SET_TTY(STDERR_FILENO, &oldmode); |
} |
} |
#endif |
#endif |
settle = set_tabs(); |
settle = set_tabs(); |
|
|
* used to try a bunch of half-clever things |
* used to try a bunch of half-clever things |
* with cup and hpa, for an average saving of |
* with cup and hpa, for an average saving of |
* somewhat less than two character times per |
* somewhat less than two character times per |
* tab stop, less that .01 sec at 2400cps. We |
* tab stop, less than .01 sec at 2400cps. We |
* lost all this cruft because it seemed to be |
* lost all this cruft because it seemed to be |
* introducing some odd bugs. |
* introducing some odd bugs. |
* ----------12345678----------- */ |
* -----------12345678----------- */ |
(void) fputs(" ", stderr); |
(void) fputs(" ", stderr); |
tputs(set_tab, 0, outc); |
tputs(set_tab, 0, outc); |
} |
} |
|
|
*/ |
*/ |
#ifdef TERMIOS |
#ifdef TERMIOS |
static void |
static void |
report(const char *name, int which, unsigned int def) |
report(const char *name, int which, unsigned def) |
{ |
{ |
unsigned int older, newer; |
unsigned older, newer; |
char *p; |
char *p; |
|
|
newer = mode.c_cc[which]; |
newer = mode.c_cc[which]; |
|
|
|
|
(void) fprintf(stderr, "%s %s ", name, older == newer ? "is" : "set to"); |
(void) fprintf(stderr, "%s %s ", name, older == newer ? "is" : "set to"); |
|
|
|
if (DISABLED(newer)) |
|
(void) fprintf(stderr, "undef.\n"); |
/* |
/* |
* Check 'delete' before 'backspace', since the key_backspace value |
* Check 'delete' before 'backspace', since the key_backspace value |
* is ambiguous. |
* is ambiguous. |
*/ |
*/ |
if (newer == 0177) |
else if (newer == 0177) |
(void) fprintf(stderr, "delete.\n"); |
(void) fprintf(stderr, "delete.\n"); |
else if ((p = key_backspace) != 0 |
else if ((p = key_backspace) != 0 |
&& newer == (unsigned char) p[0] |
&& newer == (unsigned char) p[0] |
|
|
(void) fprintf(stderr, "backspace.\n"); |
(void) fprintf(stderr, "backspace.\n"); |
else if (newer < 040) { |
else if (newer < 040) { |
newer ^= 0100; |
newer ^= 0100; |
(void) fprintf(stderr, "control-%c (^%c).\n", newer, newer); |
(void) fprintf(stderr, "control-%c (^%c).\n", UChar(newer), UChar(newer)); |
} else |
} else |
(void) fprintf(stderr, "%c.\n", newer); |
(void) fprintf(stderr, "%c.\n", UChar(newer)); |
} |
} |
#endif |
#endif |
|
|
|
|
} |
} |
|
|
static void |
static void |
usage(const char *pname) |
usage(void) |
{ |
{ |
(void) fprintf(stderr, "usage: %s [-IQqrSsV] [-] " |
static const char *tbl[] = |
"[-e ch] [-i ch] [-k ch] [-m mapping] [terminal]\n", |
{ |
pname); |
"" |
exit(EXIT_FAILURE); |
,"Options:" |
|
," -c set control characters" |
|
," -e ch erase character" |
|
," -I no initialization strings" |
|
," -i ch interrupt character" |
|
," -k ch kill character" |
|
," -m mapping map identifier to type" |
|
," -Q do not output control key settings" |
|
," -r display term on stderr" |
|
," -s output TERM set command" |
|
," -V print curses-version" |
|
," -w set window-size" |
|
}; |
|
unsigned n; |
|
(void) fprintf(stderr, "Usage: %s [-cIQqrSsVw] [-] " |
|
"[-e ch] [-i ch] [-k ch] [-m mapping] [terminal]\n", |
|
_nc_progname); |
|
for (n = 0; n < sizeof(tbl) / sizeof(tbl[0]); ++n) |
|
fprintf(stderr, "%s\n", tbl[n]); |
|
|
|
exit_error(); |
|
/* NOTREACHED */ |
} |
} |
|
|
static char |
static char |
arg_to_char(void) |
arg_to_char(void) |
{ |
{ |
return (optarg[0] == '^' && optarg[1] != '\0') |
return (char) ((optarg[0] == '^' && optarg[1] != '\0') |
? ((optarg[1] == '?') ? '\177' : CTRL(optarg[1])) |
? ((optarg[1] == '?') ? '\177' : CTRL(optarg[1])) |
: optarg[0]; |
: optarg[0]); |
} |
} |
|
|
int |
int |
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
#if defined(TIOCGWINSZ) && defined(TIOCSWINSZ) |
|
struct winsize win; |
|
#endif |
|
int ch, noinit, noset, quiet, Sflag, sflag, showterm; |
int ch, noinit, noset, quiet, Sflag, sflag, showterm; |
const char *p; |
const char *p; |
const char *ttype; |
const char *ttype; |
|
|
void wrtermcap (char *); |
void wrtermcap (char *); |
#endif /* __OpenBSD__ */ |
#endif /* __OpenBSD__ */ |
|
|
if (GET_TTY(STDERR_FILENO, &mode) < 0) |
|
failed("standard error"); |
|
oldmode = mode; |
|
#ifdef TERMIOS |
|
ospeed = cfgetospeed(&mode); |
|
#else |
|
ospeed = mode.sg_ospeed; |
|
#endif |
|
|
|
p = _nc_basename(*argv); |
|
if (!strcmp(p, PROG_RESET)) { |
|
isreset = TRUE; |
|
reset_mode(); |
|
} |
|
|
|
obsolete(argv); |
obsolete(argv); |
noinit = noset = quiet = Sflag = sflag = showterm = 0; |
noinit = noset = quiet = Sflag = sflag = showterm = 0; |
while ((ch = getopt(argc, argv, "a:d:e:Ii:k:m:np:qQSrsV")) != -1) { |
while ((ch = getopt(argc, argv, "a:cd:e:Ii:k:m:np:qQSrsVw")) != -1) { |
switch (ch) { |
switch (ch) { |
case 'q': /* display term only */ |
case 'c': /* set control-chars */ |
noset = 1; |
opt_c = TRUE; |
break; |
break; |
case 'a': /* OBSOLETE: map identifier to type */ |
case 'a': /* OBSOLETE: map identifier to type */ |
add_mapping("arpanet", optarg); |
add_mapping("arpanet", optarg); |
|
|
case 'Q': /* don't output control key settings */ |
case 'Q': /* don't output control key settings */ |
quiet = 1; |
quiet = 1; |
break; |
break; |
case 'S': /* OBSOLETE: output TERM & TERMCAP */ |
case 'q': /* display term only */ |
Sflag = 1; |
noset = 1; |
break; |
break; |
case 'r': /* display term on stderr */ |
case 'r': /* display term on stderr */ |
showterm = 1; |
showterm = 1; |
break; |
break; |
|
case 'S': /* OBSOLETE: output TERM & TERMCAP */ |
|
Sflag = 1; |
|
break; |
case 's': /* output TERM set command */ |
case 's': /* output TERM set command */ |
sflag = 1; |
sflag = 1; |
break; |
break; |
case 'V': |
case 'V': /* print curses-version */ |
puts(curses_version()); |
puts(curses_version()); |
return EXIT_SUCCESS; |
ExitProgram(EXIT_SUCCESS); |
|
case 'w': /* set window-size */ |
|
opt_w = TRUE; |
|
break; |
case '?': |
case '?': |
default: |
default: |
usage(*argv); |
usage(); |
} |
} |
} |
} |
|
|
|
_nc_progname = _nc_rootname(*argv); |
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
|
|
if (argc > 1) |
if (argc > 1) |
usage(*argv); |
usage(); |
|
|
|
if (!opt_c && !opt_w) |
|
opt_c = opt_w = TRUE; |
|
|
|
if (GET_TTY(STDERR_FILENO, &mode) < 0) |
|
failed("standard error"); |
|
can_restore = TRUE; |
|
original = oldmode = mode; |
|
#ifdef TERMIOS |
|
ospeed = (NCURSES_OSPEED) cfgetospeed(&mode); |
|
#else |
|
ospeed = (NCURSES_OSPEED) mode.sg_ospeed; |
|
#endif |
|
|
|
if (!strcmp(_nc_progname, PROG_RESET)) { |
|
isreset = TRUE; |
|
reset_mode(); |
|
} |
|
|
ttype = get_termcap_entry(*argv); |
ttype = get_termcap_entry(*argv); |
#ifdef __OpenBSD__ |
#ifdef __OpenBSD__ |
if (tcgetent(tcapbuf, ttype) < 0) |
if (tcgetent(tcapbuf, ttype) < 0) |
|
|
tcolumns = columns; |
tcolumns = columns; |
tlines = lines; |
tlines = lines; |
|
|
#if defined(TIOCGWINSZ) && defined(TIOCSWINSZ) |
#if HAVE_SIZECHANGE |
/* Set window size */ |
if (opt_w) { |
(void) ioctl(STDERR_FILENO, TIOCGWINSZ, &win); |
STRUCT_WINSIZE win; |
if (win.ws_row == 0 && win.ws_col == 0 && |
/* Set window size if not set already */ |
tlines > 0 && tcolumns > 0) { |
(void) ioctl(STDERR_FILENO, IOCTL_GET_WINSIZE, &win); |
win.ws_row = tlines; |
if (WINSIZE_ROWS(win) == 0 && |
win.ws_col = tcolumns; |
WINSIZE_COLS(win) == 0 && |
(void) ioctl(STDERR_FILENO, TIOCSWINSZ, &win); |
tlines > 0 && tcolumns > 0) { |
|
WINSIZE_ROWS(win) = tlines; |
|
WINSIZE_COLS(win) = tcolumns; |
|
(void) ioctl(STDERR_FILENO, IOCTL_SET_WINSIZE, &win); |
|
} |
} |
} |
#endif |
#endif |
set_control_chars(); |
if (opt_c) { |
set_conversions(); |
set_control_chars(); |
|
set_conversions(); |
|
|
if (!noinit) |
if (!noinit) |
set_init(); |
set_init(); |
|
|
/* Set the modes if they've changed. */ |
/* Set the modes if they've changed. */ |
if (memcmp(&mode, &oldmode, sizeof(mode))) { |
if (memcmp(&mode, &oldmode, sizeof(mode))) { |
#ifdef TERMIOS |
SET_TTY(STDERR_FILENO, &mode); |
tcsetattr(STDERR_FILENO, TCSADRAIN, &mode); |
} |
#else |
|
stty(STDERR_FILENO, &mode); |
|
#endif |
|
} |
} |
} |
} |
|
|
|
|
#ifdef TERMIOS |
#ifdef TERMIOS |
if (!quiet) { |
if (!quiet) { |
report("Erase", VERASE, CERASE); |
report("Erase", VERASE, CERASE); |
report("Kill", VKILL, CINTR); |
report("Kill", VKILL, CKILL); |
report("Interrupt", VINTR, CKILL); |
report("Interrupt", VINTR, CINTR); |
} |
} |
#endif |
#endif |
} |
} |
|
|
} else |
} else |
err("No termcap entry for %s, only terminfo.", ttype); |
err("No termcap entry for %s, only terminfo.", ttype); |
} |
} |
#else |
#else |
if (Sflag) |
if (Sflag) |
err("The -S option is not supported under terminfo."); |
err("The -S option is not supported under terminfo."); |
#endif /* __OpenBSD__ */ |
#endif /* __OpenBSD__ */ |
|
|
} |
} |
#else |
#else |
if (sflag) { |
if (sflag) { |
|
int len; |
|
char *var; |
|
char *leaf; |
/* |
/* |
* Figure out what shell we're using. A hack, we look for an |
* Figure out what shell we're using. A hack, we look for an |
* environmental variable SHELL ending in "csh". |
* environmental variable SHELL ending in "csh". |
*/ |
*/ |
if ((p = getenv("SHELL")) != 0 |
if ((var = getenv("SHELL")) != 0 |
&& !strcmp(p + strlen(p) - 3, "csh")) |
&& ((len = (int) strlen(leaf = _nc_basename(var))) >= 3) |
|
&& !strcmp(leaf + len - 3, "csh")) |
p = "set noglob;\nsetenv TERM %s;\nunset noglob;\n"; |
p = "set noglob;\nsetenv TERM %s;\nunset noglob;\n"; |
else |
else |
p = "TERM=%s;\n"; |
p = "TERM=%s;\n"; |
|
|
} |
} |
#endif /* __OpenBSD__ */ |
#endif /* __OpenBSD__ */ |
|
|
return EXIT_SUCCESS; |
ExitProgram(EXIT_SUCCESS); |
} |
} |
|
|
/* tset.c ends here */ |
|