termcap.c revision 8098
1/*
2 * Copyright (c) 1994, Paul Richards.
3 *
4 * All rights reserved.
5 *
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.
12 */
13
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17#include <unistd.h>
18#include <stdarg.h>
19#include <fcntl.h>
20#include <sys/ioctl.h>
21#include <machine/console.h>
22
23#include "sysinstall.h"
24
25int
26set_termcap(void)
27{
28    char           *term;
29    extern const char termcap_vt100[];
30    extern const char termcap_cons25[];
31    extern const char termcap_cons25_m[];
32
33    term = getenv("TERM");
34    if (term == NULL) {
35	int     color_display;
36
37	if (ioctl(STDERR_FILENO, GIO_COLOR, &color_display) < 0) {
38	    if (setenv("TERM", "vt100", 1) < 0)
39		return -1;
40	    if (setenv("TERMCAP", termcap_vt100, 1) < 0)
41		return -1;
42	    DebugFD = dup(1);
43	    OnSerial = TRUE;
44	} else if (color_display) {
45	    if (setenv("TERM", "cons25", 1) < 0)
46		return -1;
47	    if (setenv("TERMCAP", termcap_cons25, 1) < 0)
48		return -1;
49	    DebugFD = open("/dev/ttyv1",O_WRONLY);
50	} else {
51	    if (setenv("TERM", "cons25-m", 1) < 0)
52		return -1;
53	    if (setenv("TERMCAP", termcap_cons25_m, 1) < 0)
54		return -1;
55	    DebugFD = open("/dev/ttyv1",O_WRONLY);
56	}
57    } else {
58	DebugFD = open("sysinstall.debug",
59		       O_WRONLY|O_CREAT|O_TRUNC,0644);
60    }
61    return 0;
62}
63