2 * Copyright (c) 1994, Paul Richards.
6 * This software may be used, modified, copied, distributed, and sold, in both
7 * source and binary form provided that the above copyright and these terms
8 * are retained, verbatim, as the first lines of this file. Under no
9 * circumstances is the author responsible for the proper functioning of this
10 * software, nor does the author assume any responsibility for damages
11 * incurred with its use.
13 * $FreeBSD: src/release/sysinstall/termcap.c,v 1.24.6.5 2002/07/02 22:35:25 jhb Exp $
14 * $DragonFly: src/release/sysinstall/Attic/termcap.c,v 1.2 2003/06/17 04:27:21 dillon Exp $
17 #include "sysinstall.h"
20 #include <sys/errno.h>
21 #include <sys/ioctl.h>
22 #include <machine/console.h>
24 #define VTY_STATUS_LINE 24
25 #define TTY_STATUS_LINE 23
28 prompt_term(char **termp, char **termcapp)
32 const char *term, *termcap;
33 } lookup[] = { { "ansi", termcap_ansi },
34 { "vt100", termcap_vt100 },
35 { "cons25", termcap_cons25 },
36 { "cons25-m", termcap_cons25_m },
37 { "xterm", termcap_xterm },
38 { "cons25w", termcap_cons25w } }; /* must be last */
44 printf("\nThese are the predefined terminal types available to\n");
45 printf("sysinstall when running stand-alone. Please choose the\n");
46 printf("closest match for your particular terminal.\n\n");
47 printf("1 ...................... Standard ANSI terminal.\n");
48 printf("2 ...................... VT100 or compatible terminal.\n");
49 printf("3 ...................... FreeBSD system console (color).\n");
50 printf("4 ...................... FreeBSD system console (monochrome).\n\n");
51 printf("5 ...................... xterm terminal emulator.\n\n");
52 printf("Your choice: (1-5) ");
54 fgets(str, 80, stdin);
57 *termp = (char *)lookup[i - 1].term;
58 *termcapp = (char *)lookup[i - 1].termcap;
62 printf("\007Invalid choice, please try again.\n\n");
66 printf("\nPlease set your TERM variable before running this program.\n");
67 printf("Defaulting to an ANSI compatible terminal - please press RETURN\n");
68 fgets(str, 80, stdin); /* Just to make it interactive */
69 *termp = (char *)"ansi";
70 *termcapp = (char *)termcap_ansi;
81 term = getenv("TERM");
82 stat = ioctl(STDERR_FILENO, GIO_COLOR, &ColorDisplay);
86 DebugFD = open("sysinstall.debug", O_WRONLY|O_CREAT|O_TRUNC, 0644);
90 DebugFD = open("/dev/null", O_RDWR, 0);
93 if (!OnVTY || (stat < 0)) {
97 prompt_term(&term, &termcap);
98 if (setenv("TERM", term, 1) < 0)
100 if (setenv("TERMCAP", termcap, 1) < 0)
104 DebugFD = open("/dev/null", O_RDWR, 0);
110 DebugFD = open("/dev/ttyv1", O_WRONLY);
113 i = ioctl(DebugFD, TIOCCONS, (char *)&on);
114 msgDebug("ioctl(%d, TIOCCONS, NULL) = %d (%s)\n",
115 DebugFD, i, !i ? "success" : strerror(errno));
121 if (setenv("TERM", "cons25w", 1) < 0)
123 if (setenv("TERMCAP", termcap_cons25w, 1) < 0)
129 if (setenv("TERM", "cons25", 1) < 0)
131 if (setenv("TERMCAP", termcap_cons25, 1) < 0)
137 if (setenv("TERM", "cons25-m", 1) < 0)
139 if (setenv("TERMCAP", termcap_cons25_m, 1) < 0)
145 if (ioctl(0, TIOCGSIZE, &ts) == -1) {
146 msgDebug("Unable to get terminal size - errno %d\n", errno);
149 StatusLine = ts.ts_lines ? ts.ts_lines - 1: (OnVTY ? VTY_STATUS_LINE : TTY_STATUS_LINE);