1 /****************************************************************************
2 * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 ****************************************************************************/
35 * tset.c - terminal initialization utility
37 * This code was mostly swiped from 4.4BSD tset, with some obsolescent
38 * cruft removed and substantial portions rewritten. A Regents of the
39 * University of California copyright applies to some portions of the
40 * code, and is reproduced below:
43 * Copyright (c) 1980, 1991, 1993
44 * The Regents of the University of California. All rights reserved.
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
56 * This product includes software developed by the University of
57 * California, Berkeley and its contributors.
58 * 4. Neither the name of the University nor the names of its contributors
59 * may be used to endorse or promote products derived from this software
60 * without specific prior written permission.
62 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
75 #define __INTERNAL_CAPS_VISIBLE /* we need to see has_hardware_tabs */
76 #include <progs.priv.h>
83 #if HAVE_GETTTYNAM && HAVE_TTYENT_H
87 char *ttyname(int fd);
90 /* this is just to stifle a missing-prototype warning */
92 # include <sys/ioctl.h>
96 /* they neglected to define struct winsize in termios.h -- it's only
98 #include <sys/stream.h>
102 #include <curses.h> /* for bool typedef */
103 #include <dump_entry.h>
104 #include <transform.h>
106 MODULE_ID("$Id: tset.c,v 0.47 2000/10/08 01:01:08 tom Exp $")
108 extern char **environ;
111 #define CTRL(x) ((x) & 0x1f)
113 const char *_nc_progname = "tset";
115 static TTY mode, oldmode;
117 static bool isreset = FALSE; /* invoked as reset */
118 static int terasechar = -1; /* new erase character */
119 static int intrchar = -1; /* new interrupt character */
120 static int tkillchar = -1; /* new kill character */
121 static int tlines, tcolumns; /* window size */
123 #define LOWERCASE(c) ((isalpha(c) && isupper(c)) ? tolower(c) : (c))
126 CaselessCmp(const char *a, const char *b)
127 { /* strcasecmp isn't portable */
129 int cmp = LOWERCASE(*a) - LOWERCASE(*b);
134 return LOWERCASE(*a) - LOWERCASE(*b);
138 err(const char *fmt,...)
142 (void) fprintf(stderr, "tset: ");
143 (void) vfprintf(stderr, fmt, ap);
145 (void) fprintf(stderr, "\n");
151 failed(const char *msg)
154 perror(strncat(strcpy(temp, "tset: "), msg, sizeof(temp) - 10));
162 register int fd, nr, nw;
165 if ((fd = open(file, O_RDONLY, 0)) < 0)
168 while ((nr = read(fd, buf, sizeof(buf))) > 0)
169 if ((nw = write(STDERR_FILENO, buf, (size_t) nr)) == -1)
170 failed("write to stderr");
179 return putc(c, stderr);
182 /* Prompt the user for a terminal type. */
184 askuser(const char *dflt)
186 static char answer[256];
189 /* We can get recalled; if so, don't continue uselessly. */
190 if (feof(stdin) || ferror(stdin)) {
191 (void) fprintf(stderr, "\n");
196 (void) fprintf(stderr, "Terminal type? [%s] ", dflt);
198 (void) fprintf(stderr, "Terminal type? ");
199 (void) fflush(stderr);
201 if (fgets(answer, sizeof(answer), stdin) == 0) {
203 (void) fprintf(stderr, "\n");
209 if ((p = strchr(answer, '\n')) != 0)
218 /**************************************************************************
220 * Mapping logic begins here
222 **************************************************************************/
224 /* Baud rate conditionals for mapping. */
233 struct map *next; /* Linked list of maps. */
234 const char *porttype; /* Port type, or "" for any. */
235 const char *type; /* Terminal type to select. */
236 int conditional; /* Baud rate conditionals bitmask. */
237 int speed; /* Baud rate to compare against. */
240 static MAP *cur, *maplist;
242 typedef struct speeds {
247 static const SPEEDS speeds[] =
264 /* sgttyb may define up to this point */
307 tbaudrate(char *rate)
312 /* The baudrate number can be preceded by a 'B', which is ignored. */
316 for (sp = speeds; sp->string; ++sp) {
317 if (!CaselessCmp(rate, sp->string)) {
323 err("unknown baud rate %s", rate);
329 * [port-type][test baudrate]:terminal-type
330 * The baud rate tests are: >, <, @, =, !
333 add_mapping(const char *port, char *arg)
341 mapp = malloc(sizeof(MAP));
342 if (copy == 0 || mapp == 0)
346 cur = maplist = mapp;
352 mapp->porttype = arg;
353 mapp->conditional = 0;
355 arg = strpbrk(arg, "><@=!:");
357 if (arg == 0) { /* [?]term */
358 mapp->type = mapp->porttype;
363 if (arg == mapp->porttype) /* [><@=! baud]:term */
364 termp = mapp->porttype = 0;
368 for (;; ++arg) { /* Optional conditionals. */
371 if (mapp->conditional & GT)
373 mapp->conditional |= LT;
376 if (mapp->conditional & LT)
378 mapp->conditional |= GT;
381 case '=': /* Not documented. */
382 mapp->conditional |= EQ;
385 mapp->conditional |= NOT;
394 if (mapp->conditional)
397 } else { /* Optional baudrate. */
398 arg = strchr(p = arg, ':');
402 mapp->speed = tbaudrate(p);
405 if (arg == (char *) 0) /* Non-optional type. */
410 /* Terminate porttype, if specified. */
414 /* If a NOT conditional, reverse the test. */
415 if (mapp->conditional & NOT)
416 mapp->conditional = ~mapp->conditional & (EQ | GT | LT);
418 /* If user specified a port with an option flag, set it. */
421 badmopt:err("illegal -m option format: %s", copy);
422 mapp->porttype = port;
425 (void) printf("port: %s\n", mapp->porttype ? mapp->porttype : "ANY");
426 (void) printf("type: %s\n", mapp->type);
427 (void) printf("conditional: ");
429 if (mapp->conditional & GT) {
433 if (mapp->conditional & EQ) {
434 (void) printf("%sEQ", p);
437 if (mapp->conditional & LT)
438 (void) printf("%sLT", p);
439 (void) printf("\nspeed: %d\n", mapp->speed);
444 * Return the type of terminal to use for a port of type 'type', as specified
445 * by the first applicable mapping in 'map'. If no mappings apply, return
449 mapped(const char *type)
454 for (mapp = maplist; mapp; mapp = mapp->next)
455 if (mapp->porttype == 0 || !strcmp(mapp->porttype, type)) {
456 switch (mapp->conditional) {
457 case 0: /* No test specified. */
461 match = (ospeed == mapp->speed);
464 match = (ospeed >= mapp->speed);
467 match = (ospeed > mapp->speed);
470 match = (ospeed <= mapp->speed);
473 match = (ospeed < mapp->speed);
481 /* No match found; return given type. */
485 /**************************************************************************
489 **************************************************************************/
492 * Figure out what kind of terminal we're dealing with, and then read in
496 get_termcap_entry(char *userarg)
513 /* Try the environment. */
514 if ((ttype = getenv("TERM")) != 0)
517 if ((ttypath = ttyname(STDERR_FILENO)) != 0) {
518 p = _nc_basename(ttypath);
521 * We have the 4.3BSD library call getttynam(3); that means
522 * there's an /etc/ttys to look up device-to-type mappings in.
523 * Try ttyname(3); check for dialup or other mapping.
525 if ((t = getttynam(p))) {
530 if ((fp = fopen("/etc/ttytype", "r")) != 0
531 || (fp = fopen("/etc/ttys", "r")) != 0) {
535 while (fgets(buffer, sizeof(buffer) - 1, fp) != 0) {
536 for (s = buffer, t = d = 0; *s; s++) {
541 else if (d == 0 && s != buffer && s[-1] == '\0')
544 if (t != 0 && d != 0 && !strcmp(d, p)) {
552 #endif /* HAVE_GETTTYNAM */
555 /* If still undefined, use "unknown". */
558 map:ttype = mapped(ttype);
561 * If not a path, remove TERMCAP from the environment so we get a
562 * real entry from /etc/termcap. This prevents us from being fooled
563 * by out of date stuff in the environment.
565 found:if ((p = getenv("TERMCAP")) != 0 && *p != '/') {
566 /* 'unsetenv("TERMCAP")' is not portable.
567 * The 'environ' array is better.
570 for (n = 0; environ[n] != 0; n++) {
571 if (!strncmp("TERMCAP=", environ[n], 8)) {
572 while ((environ[n] = environ[n + 1]) != 0) {
581 * ttype now contains a pointer to the type of the terminal.
582 * If the first character is '?', ask the user.
584 if (ttype[0] == '?') {
585 if (ttype[1] != '\0')
586 ttype = askuser(ttype + 1);
590 /* Find the terminfo entry. If it doesn't exist, ask the user. */
591 while ((rval = setupterm((NCURSES_CONST char *) ttype, STDOUT_FILENO,
594 (void) fprintf(stderr, "tset: unknown terminal type %s\n",
598 (void) fprintf(stderr,
599 "tset: can't initialize terminal type %s (error %d)\n",
603 ttype = askuser(ttype);
606 tgetflag("am"); /* force lib_termcap.o to be linked for 'ospeed' */
611 /**************************************************************************
615 **************************************************************************/
617 /* some BSD systems have these built in, some systems are missing
618 * one or more definitions. The safest solution is to override.
631 /* control-character defaults */
632 #define CEOF CTRL('D')
633 #define CERASE CTRL('H')
634 #define CINTR 127 /* ^? */
635 #define CKILL CTRL('U')
636 #define CLNEXT CTRL('v')
637 #define CRPRNT CTRL('r')
638 #define CQUIT CTRL('\\')
639 #define CSTART CTRL('Q')
640 #define CSTOP CTRL('S')
641 #define CSUSP CTRL('Z')
643 #define CHK(val, dft) ((int)val <= 0 ? dft : val)
645 static bool set_tabs(void);
648 * Reset the terminal mode bits to a sensible state. Very useful after
649 * a child program dies in raw mode.
655 tcgetattr(STDERR_FILENO, &mode);
657 stty(STDERR_FILENO, &mode);
661 #if defined(VDISCARD) && defined(CDISCARD)
662 mode.c_cc[VDISCARD] = CHK(mode.c_cc[VDISCARD], CDISCARD);
664 mode.c_cc[VEOF] = CHK(mode.c_cc[VEOF], CEOF);
665 mode.c_cc[VERASE] = CHK(mode.c_cc[VERASE], CERASE);
666 #if defined(VFLUSH) && defined(CFLUSH)
667 mode.c_cc[VFLUSH] = CHK(mode.c_cc[VFLUSH], CFLUSH);
669 mode.c_cc[VINTR] = CHK(mode.c_cc[VINTR], CINTR);
670 mode.c_cc[VKILL] = CHK(mode.c_cc[VKILL], CKILL);
671 #if defined(VLNEXT) && defined(CLNEXT)
672 mode.c_cc[VLNEXT] = CHK(mode.c_cc[VLNEXT], CLNEXT);
674 mode.c_cc[VQUIT] = CHK(mode.c_cc[VQUIT], CQUIT);
675 #if defined(VREPRINT) && defined(CRPRNT)
676 mode.c_cc[VREPRINT] = CHK(mode.c_cc[VREPRINT], CRPRNT);
678 #if defined(VSTART) && defined(CSTART)
679 mode.c_cc[VSTART] = CHK(mode.c_cc[VSTART], CSTART);
681 #if defined(VSTOP) && defined(CSTOP)
682 mode.c_cc[VSTOP] = CHK(mode.c_cc[VSTOP], CSTOP);
684 #if defined(VSUSP) && defined(CSUSP)
685 mode.c_cc[VSUSP] = CHK(mode.c_cc[VSUSP], CSUSP);
687 #if defined(VWERASE) && defined(CWERASE)
688 mode.c_cc[VWERASE] = CHK(mode.c_cc[VWERASE], CWERASE);
691 mode.c_iflag &= ~(IGNBRK | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
700 mode.c_iflag |= (BRKINT | IGNPAR | ICRNL | IXON
726 | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY
730 mode.c_oflag |= (OPOST
736 mode.c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD | CLOCAL);
737 mode.c_cflag |= (CS8 | CREAD);
738 mode.c_lflag &= ~(ECHONL | NOFLSH
750 mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOK
761 tcsetattr(STDERR_FILENO, TCSADRAIN, &mode);
763 stty(STDERR_FILENO, &mode);
768 * Returns a "good" value for the erase character. This is loosely based on
778 && key_backspace != 0
779 && strlen(key_backspace) == 1)
780 result = key_backspace[0];
789 * Update the values of the erase, interrupt, and kill characters in 'mode'.
791 * SVr4 tset (e.g., Solaris 2.5) only modifies the intr, quit or erase
792 * characters if they're unset, or if we specify them as options. This differs
793 * from BSD 4.4 tset, which always sets erase.
796 set_control_chars(void)
799 if (mode.c_cc[VERASE] == 0 || terasechar >= 0)
800 mode.c_cc[VERASE] = terasechar >= 0 ? terasechar : default_erase();
802 if (mode.c_cc[VINTR] == 0 || intrchar >= 0)
803 mode.c_cc[VINTR] = intrchar >= 0 ? intrchar : CINTR;
805 if (mode.c_cc[VKILL] == 0 || tkillchar >= 0)
806 mode.c_cc[VKILL] = tkillchar >= 0 ? tkillchar : CKILL;
811 * Set up various conversions in 'mode', including parity, tabs, returns,
812 * echo, and case, according to the termcap entry. If the program we're
813 * running was named with a leading upper-case character, map external
814 * uppercase to internal lowercase.
817 set_conversions(void)
821 * Conversion logic for some *really* ancient terminal glitches,
822 * not supported in terminfo. Left here for succeeding generations
825 if (tgetflag("UC")) {
827 mode.c_iflag |= IUCLC;
828 mode.c_oflag |= OLCUC;
830 } else if (tgetflag("LC")) {
832 mode.c_iflag &= ~IUCLC;
833 mode.c_oflag &= ~OLCUC;
836 mode.c_iflag &= ~(PARMRK | INPCK);
837 mode.c_lflag |= ICANON;
838 if (tgetflag("EP")) {
839 mode.c_cflag |= PARENB;
840 mode.c_cflag &= ~PARODD;
842 if (tgetflag("OP")) {
843 mode.c_cflag |= PARENB;
844 mode.c_cflag |= PARODD;
846 #endif /* __OBSOLETE__ */
850 mode.c_oflag |= ONLCR;
852 mode.c_iflag |= ICRNL;
853 mode.c_lflag |= ECHO;
855 mode.c_oflag |= OXTABS;
858 /* test used to be tgetflag("NL") */
859 if (newline != (char *) 0 && newline[0] == '\n' && !newline[1]) {
860 /* Newline, not linefeed. */
862 mode.c_oflag &= ~ONLCR;
864 mode.c_iflag &= ~ICRNL;
867 if (tgetflag("HD")) /* Half duplex. */
868 mode.c_lflag &= ~ECHO;
869 #endif /* __OBSOLETE__ */
871 /* test used to be tgetflag("pt") */
872 if (has_hardware_tabs) /* Print tabs. */
873 mode.c_oflag &= ~OXTABS;
875 mode.c_lflag |= (ECHOE | ECHOK);
879 /* Output startup string. */
887 if (pad_char != (char *) 0) /* Get/set pad character. */
889 #endif /* OBSOLETE */
892 if (oldmode.c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) {
893 oldmode.c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET);
894 tcsetattr(STDERR_FILENO, TCSADRAIN, &oldmode);
900 if ((p = reset_1string) != 0) {
904 if ((p = reset_2string) != 0) {
908 /* What about rf, rs3, as per terminfo man page? */
909 /* also might be nice to send rmacs, rmul, rmm */
910 if ((p = reset_file) != 0
911 || (p = init_file) != 0) {
918 (void) putc('\r', stderr);
919 (void) fflush(stderr);
920 (void) napms(1000); /* Settle the terminal. */
925 * Set the hardware tabs on the terminal, using the ct (clear all tabs),
926 * st (set one tab) and ch (horizontal cursor addressing) capabilities.
927 * This is done before if and is, so they can patch in case we blow this.
928 * Return TRUE if we set any tab stops, FALSE if not.
933 if (set_tab && clear_all_tabs) {
936 (void) putc('\r', stderr); /* Force to left margin. */
937 tputs(clear_all_tabs, 0, outc);
939 for (c = 8; c < tcolumns; c += 8) {
940 /* Get to the right column. In BSD tset, this
941 * used to try a bunch of half-clever things
942 * with cup and hpa, for an average saving of
943 * somewhat less than two character times per
944 * tab stop, less that .01 sec at 2400cps. We
945 * lost all this cruft because it seemed to be
946 * introducing some odd bugs.
947 * ----------12345678----------- */
948 (void) fputs(" ", stderr);
949 tputs(set_tab, 0, outc);
957 /**************************************************************************
961 **************************************************************************/
964 * Tell the user if a control key has been changed from the default value.
968 report(const char *name, int which, unsigned def)
970 unsigned older, newer;
973 newer = mode.c_cc[which];
974 older = oldmode.c_cc[which];
976 if (older == newer && older == def)
979 (void) fprintf(stderr, "%s %s ", name, older == newer ? "is" : "set to");
982 * Check 'delete' before 'backspace', since the key_backspace value
986 (void) fprintf(stderr, "delete.\n");
987 else if ((p = key_backspace) != 0
988 && newer == (unsigned char) p[0]
990 (void) fprintf(stderr, "backspace.\n");
991 else if (newer < 040) {
993 (void) fprintf(stderr, "control-%c (^%c).\n", newer, newer);
995 (void) fprintf(stderr, "%c.\n", newer);
1000 * Convert the obsolete argument forms into something that getopt can handle.
1001 * This means that -e, -i and -k get default arguments supplied for them.
1004 obsolete(char **argv)
1006 for (; *argv; ++argv) {
1007 char *parm = argv[0];
1009 if (parm[0] == '-' && parm[1] == '\0') {
1010 argv[0] = strdup("-q");
1014 if ((parm[0] != '-')
1015 || (argv[1] && argv[1][0] != '-')
1016 || (parm[1] != 'e' && parm[1] != 'i' && parm[1] != 'k')
1017 || (parm[2] != '\0'))
1019 switch (argv[0][1]) {
1021 argv[0] = strdup("-e^H");
1024 argv[0] = strdup("-i^C");
1027 argv[0] = strdup("-k^U");
1034 usage(const char *pname)
1036 (void) fprintf(stderr,
1037 "usage: %s [-IQVrs] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]\n", pname);
1044 return (optarg[0] == '^' && optarg[1] != '\0')
1045 ? ((optarg[1] == '?') ? '\177' : CTRL(optarg[1]))
1050 main(int argc, char **argv)
1052 #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ)
1055 int ch, noinit, noset, quiet, Sflag, sflag, showterm;
1059 if (GET_TTY(STDERR_FILENO, &mode) < 0)
1060 failed("standard error");
1063 ospeed = cfgetospeed(&mode);
1065 ospeed = mode.sg_ospeed;
1068 p = _nc_basename(*argv);
1069 if (!strcmp(p, PROG_RESET)) {
1075 noinit = noset = quiet = Sflag = sflag = showterm = 0;
1076 while ((ch = getopt(argc, argv, "a:d:e:Ii:k:m:np:qQSrsV")) != EOF) {
1078 case 'q': /* display term only */
1081 case 'a': /* OBSOLETE: map identifier to type */
1082 add_mapping("arpanet", optarg);
1084 case 'd': /* OBSOLETE: map identifier to type */
1085 add_mapping("dialup", optarg);
1087 case 'e': /* erase character */
1088 terasechar = arg_to_char();
1090 case 'I': /* no initialization strings */
1093 case 'i': /* interrupt character */
1094 intrchar = arg_to_char();
1096 case 'k': /* kill character */
1097 tkillchar = arg_to_char();
1099 case 'm': /* map identifier to type */
1100 add_mapping(0, optarg);
1102 case 'n': /* OBSOLETE: set new tty driver */
1104 case 'p': /* OBSOLETE: map identifier to type */
1105 add_mapping("plugboard", optarg);
1107 case 'Q': /* don't output control key settings */
1110 case 'S': /* OBSOLETE: output TERM & TERMCAP */
1113 case 'r': /* display term on stderr */
1116 case 's': /* output TERM set command */
1120 puts(curses_version());
1121 return EXIT_SUCCESS;
1133 ttype = get_termcap_entry(*argv);
1139 #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ)
1140 /* Set window size */
1141 (void) ioctl(STDERR_FILENO, TIOCGWINSZ, &win);
1142 if (win.ws_row == 0 && win.ws_col == 0 &&
1143 tlines > 0 && tcolumns > 0) {
1144 win.ws_row = tlines;
1145 win.ws_col = tcolumns;
1146 (void) ioctl(STDERR_FILENO, TIOCSWINSZ, &win);
1149 set_control_chars();
1155 /* Set the modes if they've changed. */
1156 if (memcmp(&mode, &oldmode, sizeof(mode))) {
1158 tcsetattr(STDERR_FILENO, TCSADRAIN, &mode);
1160 stty(STDERR_FILENO, &mode);
1165 /* Get the terminal name from the entry. */
1166 ttype = _nc_first_name(cur_term->type.term_names);
1169 (void) printf("%s\n", ttype);
1172 (void) fprintf(stderr, "Terminal type is %s.\n", ttype);
1174 * If erase, kill and interrupt characters could have been
1175 * modified and not -Q, display the changes.
1179 report("Erase", VERASE, CERASE);
1180 report("Kill", VKILL, CINTR);
1181 report("Interrupt", VINTR, CKILL);
1187 err("The -S option is not supported under terminfo.");
1191 * Figure out what shell we're using. A hack, we look for an
1192 * environmental variable SHELL ending in "csh".
1194 if ((p = getenv("SHELL")) != 0
1195 && !strcmp(p + strlen(p) - 3, "csh"))
1196 p = "set noglob;\nsetenv TERM %s;\nunset noglob;\n";
1199 (void) printf(p, ttype);
1202 return EXIT_SUCCESS;
1205 /* tset.c ends here */