1 /****************************************************************************
2 * Copyright (c) 1998-2007,2008 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 * and: Thomas E. Dickey 1996-on *
33 ****************************************************************************/
36 * tset.c - terminal initialization utility
38 * This code was mostly swiped from 4.4BSD tset, with some obsolescent
39 * cruft removed and substantial portions rewritten. A Regents of the
40 * University of California copyright applies to some portions of the
41 * code, and is reproduced below:
44 * Copyright (c) 1980, 1991, 1993
45 * The Regents of the University of California. All rights reserved.
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. All advertising materials mentioning features or use of this software
56 * must display the following acknowledgement:
57 * This product includes software developed by the University of
58 * California, Berkeley and its contributors.
59 * 4. Neither the name of the University nor the names of its contributors
60 * may be used to endorse or promote products derived from this software
61 * without specific prior written permission.
63 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
64 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
67 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
77 #define __INTERNAL_CAPS_VISIBLE /* we need to see has_hardware_tabs */
78 #include <progs.priv.h>
85 #if HAVE_GETTTYNAM && HAVE_TTYENT_H
89 char *ttyname(int fd);
92 /* this is just to stifle a missing-prototype warning */
94 # include <sys/ioctl.h>
98 /* they neglected to define struct winsize in termios.h -- it's only
100 #include <sys/stream.h>
101 #include <sys/ptem.h>
104 #include <dump_entry.h>
105 #include <transform.h>
107 MODULE_ID("$Id: tset.c,v 1.73 2008/08/04 12:47:05 tom Exp $")
109 extern char **environ;
112 #define CTRL(x) ((x) & 0x1f)
114 const char *_nc_progname = "tset";
116 static TTY mode, oldmode, original;
118 static bool opt_c; /* set control-chars */
119 static bool opt_w; /* set window-size */
121 static bool can_restore = FALSE;
122 static bool isreset = FALSE; /* invoked as reset */
123 static int terasechar = -1; /* new erase character */
124 static int intrchar = -1; /* new interrupt character */
125 static int tkillchar = -1; /* new kill character */
126 static int tlines, tcolumns; /* window size */
128 #define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c))
131 CaselessCmp(const char *a, const char *b)
132 { /* strcasecmp isn't portable */
134 int cmp = LOWERCASE(*a) - LOWERCASE(*b);
139 return LOWERCASE(*a) - LOWERCASE(*b);
146 SET_TTY(STDERR_FILENO, &original);
147 (void) fprintf(stderr, "\n");
149 ExitProgram(EXIT_FAILURE);
154 err(const char *fmt,...)
158 (void) fprintf(stderr, "%s: ", _nc_progname);
159 (void) vfprintf(stderr, fmt, ap);
166 failed(const char *msg)
169 unsigned len = strlen(_nc_progname) + 2;
171 if ((int) len < (int) sizeof(temp) - 12) {
172 strcpy(temp, _nc_progname);
175 strcpy(temp, "tset: ");
177 perror(strncat(temp, msg, sizeof(temp) - strlen(temp) - 2));
189 if ((fp = fopen(file, "r")) == 0)
192 while ((nr = fread(buf, sizeof(char), sizeof(buf), fp)) != 0)
193 if (fwrite(buf, sizeof(char), nr, stderr) != nr)
194 failed("write to stderr");
201 return putc(c, stderr);
204 /* Prompt the user for a terminal type. */
206 askuser(const char *dflt)
208 static char answer[256];
211 /* We can get recalled; if so, don't continue uselessly. */
213 if (feof(stdin) || ferror(stdin)) {
214 (void) fprintf(stderr, "\n");
220 (void) fprintf(stderr, "Terminal type? [%s] ", dflt);
222 (void) fprintf(stderr, "Terminal type? ");
223 (void) fflush(stderr);
225 if (fgets(answer, sizeof(answer), stdin) == 0) {
233 if ((p = strchr(answer, '\n')) != 0)
242 /**************************************************************************
244 * Mapping logic begins here
246 **************************************************************************/
248 /* Baud rate conditionals for mapping. */
257 struct map *next; /* Linked list of maps. */
258 const char *porttype; /* Port type, or "" for any. */
259 const char *type; /* Terminal type to select. */
260 int conditional; /* Baud rate conditionals bitmask. */
261 int speed; /* Baud rate to compare against. */
264 static MAP *cur, *maplist;
266 typedef struct speeds {
271 static const SPEEDS speeds[] =
288 /* sgttyb may define up to this point */
331 tbaudrate(char *rate)
336 /* The baudrate number can be preceded by a 'B', which is ignored. */
340 for (sp = speeds; sp->string; ++sp) {
341 if (!CaselessCmp(rate, sp->string)) {
347 err("unknown baud rate %s", rate);
353 * [port-type][test baudrate]:terminal-type
354 * The baud rate tests are: >, <, @, =, !
357 add_mapping(const char *port, char *arg)
365 mapp = (MAP *) malloc(sizeof(MAP));
366 if (copy == 0 || mapp == 0)
370 cur = maplist = mapp;
376 mapp->porttype = arg;
377 mapp->conditional = 0;
379 arg = strpbrk(arg, "><@=!:");
381 if (arg == 0) { /* [?]term */
382 mapp->type = mapp->porttype;
387 if (arg == mapp->porttype) /* [><@=! baud]:term */
388 termp = mapp->porttype = 0;
392 for (;; ++arg) { /* Optional conditionals. */
395 if (mapp->conditional & GT)
397 mapp->conditional |= LT;
400 if (mapp->conditional & LT)
402 mapp->conditional |= GT;
405 case '=': /* Not documented. */
406 mapp->conditional |= EQ;
409 mapp->conditional |= NOT;
418 if (mapp->conditional)
421 } else { /* Optional baudrate. */
422 arg = strchr(p = arg, ':');
426 mapp->speed = tbaudrate(p);
429 if (arg == (char *) 0) /* Non-optional type. */
434 /* Terminate porttype, if specified. */
438 /* If a NOT conditional, reverse the test. */
439 if (mapp->conditional & NOT)
440 mapp->conditional = ~mapp->conditional & (EQ | GT | LT);
442 /* If user specified a port with an option flag, set it. */
445 if (mapp->porttype) {
447 err("illegal -m option format: %s", copy);
449 mapp->porttype = port;
453 (void) printf("port: %s\n", mapp->porttype ? mapp->porttype : "ANY");
454 (void) printf("type: %s\n", mapp->type);
455 (void) printf("conditional: ");
457 if (mapp->conditional & GT) {
461 if (mapp->conditional & EQ) {
462 (void) printf("%sEQ", p);
465 if (mapp->conditional & LT)
466 (void) printf("%sLT", p);
467 (void) printf("\nspeed: %d\n", mapp->speed);
472 * Return the type of terminal to use for a port of type 'type', as specified
473 * by the first applicable mapping in 'map'. If no mappings apply, return
477 mapped(const char *type)
482 for (mapp = maplist; mapp; mapp = mapp->next)
483 if (mapp->porttype == 0 || !strcmp(mapp->porttype, type)) {
484 switch (mapp->conditional) {
485 case 0: /* No test specified. */
489 match = (ospeed == mapp->speed);
492 match = (ospeed >= mapp->speed);
495 match = (ospeed > mapp->speed);
498 match = (ospeed <= mapp->speed);
501 match = (ospeed < mapp->speed);
509 /* No match found; return given type. */
513 /**************************************************************************
517 **************************************************************************/
520 * Figure out what kind of terminal we're dealing with, and then read in
524 get_termcap_entry(char *userarg)
541 /* Try the environment. */
542 if ((ttype = getenv("TERM")) != 0)
545 if ((ttypath = ttyname(STDERR_FILENO)) != 0) {
546 p = _nc_basename(ttypath);
549 * We have the 4.3BSD library call getttynam(3); that means
550 * there's an /etc/ttys to look up device-to-type mappings in.
551 * Try ttyname(3); check for dialup or other mapping.
553 if ((t = getttynam(p))) {
558 if ((fp = fopen("/etc/ttytype", "r")) != 0
559 || (fp = fopen("/etc/ttys", "r")) != 0) {
563 while (fgets(buffer, sizeof(buffer) - 1, fp) != 0) {
564 for (s = buffer, t = d = 0; *s; s++) {
565 if (isspace(UChar(*s)))
569 else if (d == 0 && s != buffer && s[-1] == '\0')
572 if (t != 0 && d != 0 && !strcmp(d, p)) {
580 #endif /* HAVE_GETTTYNAM */
583 /* If still undefined, use "unknown". */
586 map:ttype = mapped(ttype);
589 * If not a path, remove TERMCAP from the environment so we get a
590 * real entry from /etc/termcap. This prevents us from being fooled
591 * by out of date stuff in the environment.
593 found:if ((p = getenv("TERMCAP")) != 0 && !_nc_is_abs_path(p)) {
594 /* 'unsetenv("TERMCAP")' is not portable.
595 * The 'environ' array is better.
598 for (n = 0; environ[n] != 0; n++) {
599 if (!strncmp("TERMCAP=", environ[n], 8)) {
600 while ((environ[n] = environ[n + 1]) != 0) {
609 * ttype now contains a pointer to the type of the terminal.
610 * If the first character is '?', ask the user.
612 if (ttype[0] == '?') {
613 if (ttype[1] != '\0')
614 ttype = askuser(ttype + 1);
618 /* Find the terminfo entry. If it doesn't exist, ask the user. */
619 while (setupterm((NCURSES_CONST char *) ttype, STDOUT_FILENO, &errret)
622 (void) fprintf(stderr, "%s: unknown terminal type %s\n",
623 _nc_progname, ttype);
626 (void) fprintf(stderr,
627 "%s: can't initialize terminal type %s (error %d)\n",
628 _nc_progname, ttype, errret);
631 ttype = askuser(ttype);
634 tgetflag("am"); /* force lib_termcap.o to be linked for 'ospeed' */
639 /**************************************************************************
643 **************************************************************************/
645 /* some BSD systems have these built in, some systems are missing
646 * one or more definitions. The safest solution is to override unless the
647 * commonly-altered ones are defined.
649 #if !(defined(CERASE) && defined(CINTR) && defined(CKILL) && defined(CQUIT))
662 /* control-character defaults */
664 #define CEOF CTRL('D')
667 #define CERASE CTRL('H')
670 #define CINTR 127 /* ^? */
673 #define CKILL CTRL('U')
676 #define CLNEXT CTRL('v')
679 #define CRPRNT CTRL('r')
682 #define CQUIT CTRL('\\')
685 #define CSTART CTRL('Q')
688 #define CSTOP CTRL('S')
691 #define CSUSP CTRL('Z')
694 #if defined(_POSIX_VDISABLE)
695 #define DISABLED(val) (((_POSIX_VDISABLE != -1) \
696 && ((val) == _POSIX_VDISABLE)) \
699 #define DISABLED(val) ((int)(val) <= 0)
702 #define CHK(val, dft) (DISABLED(val) ? dft : val)
704 static bool set_tabs(void);
707 * Reset the terminal mode bits to a sensible state. Very useful after
708 * a child program dies in raw mode.
714 tcgetattr(STDERR_FILENO, &mode);
716 stty(STDERR_FILENO, &mode);
720 #if defined(VDISCARD) && defined(CDISCARD)
721 mode.c_cc[VDISCARD] = CHK(mode.c_cc[VDISCARD], CDISCARD);
723 mode.c_cc[VEOF] = CHK(mode.c_cc[VEOF], CEOF);
724 mode.c_cc[VERASE] = CHK(mode.c_cc[VERASE], CERASE);
725 #if defined(VFLUSH) && defined(CFLUSH)
726 mode.c_cc[VFLUSH] = CHK(mode.c_cc[VFLUSH], CFLUSH);
728 mode.c_cc[VINTR] = CHK(mode.c_cc[VINTR], CINTR);
729 mode.c_cc[VKILL] = CHK(mode.c_cc[VKILL], CKILL);
730 #if defined(VLNEXT) && defined(CLNEXT)
731 mode.c_cc[VLNEXT] = CHK(mode.c_cc[VLNEXT], CLNEXT);
733 mode.c_cc[VQUIT] = CHK(mode.c_cc[VQUIT], CQUIT);
734 #if defined(VREPRINT) && defined(CRPRNT)
735 mode.c_cc[VREPRINT] = CHK(mode.c_cc[VREPRINT], CRPRNT);
737 #if defined(VSTART) && defined(CSTART)
738 mode.c_cc[VSTART] = CHK(mode.c_cc[VSTART], CSTART);
740 #if defined(VSTOP) && defined(CSTOP)
741 mode.c_cc[VSTOP] = CHK(mode.c_cc[VSTOP], CSTOP);
743 #if defined(VSUSP) && defined(CSUSP)
744 mode.c_cc[VSUSP] = CHK(mode.c_cc[VSUSP], CSUSP);
746 #if defined(VWERASE) && defined(CWERASE)
747 mode.c_cc[VWERASE] = CHK(mode.c_cc[VWERASE], CWERASE);
750 mode.c_iflag &= ~(IGNBRK | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
759 mode.c_iflag |= (BRKINT | IGNPAR | ICRNL | IXON
804 mode.c_oflag |= (OPOST
810 mode.c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD | CLOCAL);
811 mode.c_cflag |= (CS8 | CREAD);
812 mode.c_lflag &= ~(ECHONL | NOFLSH
824 mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOK
834 SET_TTY(STDERR_FILENO, &mode);
838 * Returns a "good" value for the erase character. This is loosely based on
848 && key_backspace != 0
849 && strlen(key_backspace) == 1)
850 result = key_backspace[0];
859 * Update the values of the erase, interrupt, and kill characters in 'mode'.
861 * SVr4 tset (e.g., Solaris 2.5) only modifies the intr, quit or erase
862 * characters if they're unset, or if we specify them as options. This differs
863 * from BSD 4.4 tset, which always sets erase.
866 set_control_chars(void)
869 if (DISABLED(mode.c_cc[VERASE]) || terasechar >= 0)
870 mode.c_cc[VERASE] = terasechar >= 0 ? terasechar : default_erase();
872 if (DISABLED(mode.c_cc[VINTR]) || intrchar >= 0)
873 mode.c_cc[VINTR] = intrchar >= 0 ? intrchar : CINTR;
875 if (DISABLED(mode.c_cc[VKILL]) || tkillchar >= 0)
876 mode.c_cc[VKILL] = tkillchar >= 0 ? tkillchar : CKILL;
881 * Set up various conversions in 'mode', including parity, tabs, returns,
882 * echo, and case, according to the termcap entry. If the program we're
883 * running was named with a leading upper-case character, map external
884 * uppercase to internal lowercase.
887 set_conversions(void)
891 * Conversion logic for some *really* ancient terminal glitches,
892 * not supported in terminfo. Left here for succeeding generations
895 if (tgetflag("UC")) {
897 mode.c_iflag |= IUCLC;
898 mode.c_oflag |= OLCUC;
900 } else if (tgetflag("LC")) {
902 mode.c_iflag &= ~IUCLC;
903 mode.c_oflag &= ~OLCUC;
906 mode.c_iflag &= ~(PARMRK | INPCK);
907 mode.c_lflag |= ICANON;
908 if (tgetflag("EP")) {
909 mode.c_cflag |= PARENB;
910 mode.c_cflag &= ~PARODD;
912 if (tgetflag("OP")) {
913 mode.c_cflag |= PARENB;
914 mode.c_cflag |= PARODD;
916 #endif /* __OBSOLETE__ */
920 mode.c_oflag |= ONLCR;
922 mode.c_iflag |= ICRNL;
923 mode.c_lflag |= ECHO;
925 mode.c_oflag |= OXTABS;
928 /* test used to be tgetflag("NL") */
929 if (newline != (char *) 0 && newline[0] == '\n' && !newline[1]) {
930 /* Newline, not linefeed. */
932 mode.c_oflag &= ~ONLCR;
934 mode.c_iflag &= ~ICRNL;
937 if (tgetflag("HD")) /* Half duplex. */
938 mode.c_lflag &= ~ECHO;
939 #endif /* __OBSOLETE__ */
941 /* test used to be tgetflag("pt") */
942 if (has_hardware_tabs) /* Print tabs. */
943 mode.c_oflag &= ~OXTABS;
945 mode.c_lflag |= (ECHOE | ECHOK);
949 /* Output startup string. */
957 if (pad_char != (char *) 0) /* Get/set pad character. */
959 #endif /* OBSOLETE */
962 if (oldmode.c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) {
963 oldmode.c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET);
964 SET_TTY(STDERR_FILENO, &oldmode);
970 if ((p = reset_1string) != 0) {
974 if ((p = reset_2string) != 0) {
978 /* What about rf, rs3, as per terminfo man page? */
979 /* also might be nice to send rmacs, rmul, rmm */
980 if ((p = reset_file) != 0
981 || (p = init_file) != 0) {
988 (void) putc('\r', stderr);
989 (void) fflush(stderr);
990 (void) napms(1000); /* Settle the terminal. */
995 * Set the hardware tabs on the terminal, using the ct (clear all tabs),
996 * st (set one tab) and ch (horizontal cursor addressing) capabilities.
997 * This is done before if and is, so they can patch in case we blow this.
998 * Return TRUE if we set any tab stops, FALSE if not.
1003 if (set_tab && clear_all_tabs) {
1006 (void) putc('\r', stderr); /* Force to left margin. */
1007 tputs(clear_all_tabs, 0, outc);
1009 for (c = 8; c < tcolumns; c += 8) {
1010 /* Get to the right column. In BSD tset, this
1011 * used to try a bunch of half-clever things
1012 * with cup and hpa, for an average saving of
1013 * somewhat less than two character times per
1014 * tab stop, less than .01 sec at 2400cps. We
1015 * lost all this cruft because it seemed to be
1016 * introducing some odd bugs.
1017 * -----------12345678----------- */
1018 (void) fputs(" ", stderr);
1019 tputs(set_tab, 0, outc);
1027 /**************************************************************************
1031 **************************************************************************/
1034 * Tell the user if a control key has been changed from the default value.
1038 report(const char *name, int which, unsigned def)
1040 unsigned older, newer;
1043 newer = mode.c_cc[which];
1044 older = oldmode.c_cc[which];
1046 if (older == newer && older == def)
1049 (void) fprintf(stderr, "%s %s ", name, older == newer ? "is" : "set to");
1051 if (DISABLED(newer))
1052 (void) fprintf(stderr, "undef.\n");
1054 * Check 'delete' before 'backspace', since the key_backspace value
1057 else if (newer == 0177)
1058 (void) fprintf(stderr, "delete.\n");
1059 else if ((p = key_backspace) != 0
1060 && newer == (unsigned char) p[0]
1062 (void) fprintf(stderr, "backspace.\n");
1063 else if (newer < 040) {
1065 (void) fprintf(stderr, "control-%c (^%c).\n", UChar(newer), UChar(newer));
1067 (void) fprintf(stderr, "%c.\n", UChar(newer));
1072 * Convert the obsolete argument forms into something that getopt can handle.
1073 * This means that -e, -i and -k get default arguments supplied for them.
1076 obsolete(char **argv)
1078 for (; *argv; ++argv) {
1079 char *parm = argv[0];
1081 if (parm[0] == '-' && parm[1] == '\0') {
1082 argv[0] = strdup("-q");
1086 if ((parm[0] != '-')
1087 || (argv[1] && argv[1][0] != '-')
1088 || (parm[1] != 'e' && parm[1] != 'i' && parm[1] != 'k')
1089 || (parm[2] != '\0'))
1091 switch (argv[0][1]) {
1093 argv[0] = strdup("-e^H");
1096 argv[0] = strdup("-i^C");
1099 argv[0] = strdup("-k^U");
1108 static const char *tbl[] =
1112 ," -c set control characters"
1113 ," -e ch erase character"
1114 ," -I no initialization strings"
1115 ," -i ch interrupt character"
1116 ," -k ch kill character"
1117 ," -m mapping map identifier to type"
1118 ," -Q do not output control key settings"
1119 ," -r display term on stderr"
1120 ," -s output TERM set command"
1121 ," -V print curses-version"
1122 ," -w set window-size"
1125 (void) fprintf(stderr, "Usage: %s [options] [terminal]\n", _nc_progname);
1126 for (n = 0; n < sizeof(tbl) / sizeof(tbl[0]); ++n)
1127 fprintf(stderr, "%s\n", tbl[n]);
1135 return (char) ((optarg[0] == '^' && optarg[1] != '\0')
1136 ? ((optarg[1] == '?') ? '\177' : CTRL(optarg[1]))
1141 main(int argc, char **argv)
1143 #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ)
1146 int ch, noinit, noset, quiet, Sflag, sflag, showterm;
1151 noinit = noset = quiet = Sflag = sflag = showterm = 0;
1152 while ((ch = getopt(argc, argv, "a:cd:e:Ii:k:m:np:qQSrsVw")) != -1) {
1154 case 'c': /* set control-chars */
1157 case 'a': /* OBSOLETE: map identifier to type */
1158 add_mapping("arpanet", optarg);
1160 case 'd': /* OBSOLETE: map identifier to type */
1161 add_mapping("dialup", optarg);
1163 case 'e': /* erase character */
1164 terasechar = arg_to_char();
1166 case 'I': /* no initialization strings */
1169 case 'i': /* interrupt character */
1170 intrchar = arg_to_char();
1172 case 'k': /* kill character */
1173 tkillchar = arg_to_char();
1175 case 'm': /* map identifier to type */
1176 add_mapping(0, optarg);
1178 case 'n': /* OBSOLETE: set new tty driver */
1180 case 'p': /* OBSOLETE: map identifier to type */
1181 add_mapping("plugboard", optarg);
1183 case 'Q': /* don't output control key settings */
1186 case 'q': /* display term only */
1189 case 'r': /* display term on stderr */
1192 case 'S': /* OBSOLETE: output TERM & TERMCAP */
1195 case 's': /* output TERM set command */
1198 case 'V': /* print curses-version */
1199 puts(curses_version());
1200 ExitProgram(EXIT_SUCCESS);
1201 case 'w': /* set window-size */
1210 _nc_progname = _nc_rootname(*argv);
1217 if (!opt_c && !opt_w)
1218 opt_c = opt_w = TRUE;
1220 if (GET_TTY(STDERR_FILENO, &mode) < 0)
1221 failed("standard error");
1223 original = oldmode = mode;
1225 ospeed = (NCURSES_OSPEED) cfgetospeed(&mode);
1227 ospeed = (NCURSES_OSPEED) mode.sg_ospeed;
1230 if (!strcmp(_nc_progname, PROG_RESET)) {
1235 ttype = get_termcap_entry(*argv);
1241 #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ)
1243 /* Set window size */
1244 (void) ioctl(STDERR_FILENO, TIOCGWINSZ, &win);
1245 if (win.ws_row == 0 && win.ws_col == 0 &&
1246 tlines > 0 && tcolumns > 0) {
1247 win.ws_row = tlines;
1248 win.ws_col = tcolumns;
1249 (void) ioctl(STDERR_FILENO, TIOCSWINSZ, &win);
1254 set_control_chars();
1260 /* Set the modes if they've changed. */
1261 if (memcmp(&mode, &oldmode, sizeof(mode))) {
1262 SET_TTY(STDERR_FILENO, &mode);
1267 /* Get the terminal name from the entry. */
1268 ttype = _nc_first_name(cur_term->type.term_names);
1271 (void) printf("%s\n", ttype);
1274 (void) fprintf(stderr, "Terminal type is %s.\n", ttype);
1276 * If erase, kill and interrupt characters could have been
1277 * modified and not -Q, display the changes.
1281 report("Erase", VERASE, CERASE);
1282 report("Kill", VKILL, CKILL);
1283 report("Interrupt", VINTR, CINTR);
1289 err("The -S option is not supported under terminfo.");
1296 * Figure out what shell we're using. A hack, we look for an
1297 * environmental variable SHELL ending in "csh".
1299 if ((var = getenv("SHELL")) != 0
1300 && ((len = (int) strlen(leaf = _nc_basename(var))) >= 3)
1301 && !strcmp(leaf + len - 3, "csh"))
1302 p = "set noglob;\nsetenv TERM %s;\nunset noglob;\n";
1305 (void) printf(p, ttype);
1308 ExitProgram(EXIT_SUCCESS);