termcap.c revision 8881
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/errno.h>
21#include <sys/ioctl.h>
22#include <machine/console.h>
23
24#include "sysinstall.h"
25
26int
27set_termcap(void)
28{
29    char           *term;
30    int		   stat;
31
32    OnVTY = OnSerial = FALSE;
33    if (getpid() != 1)
34	DebugFD = open("sysinstall.debug", O_WRONLY|O_CREAT|O_TRUNC, 0644);
35    else {
36	int i, on;
37
38	DebugFD = open("/dev/ttyv1", O_WRONLY);
39	on = 1;
40	i = ioctl(DebugFD, TIOCCONS, (char *)&on);
41	msgDebug("ioctl(%d, TIOCCONS, NULL) = %d (%s)\n", DebugFD, i, !i ? "success" : strerror(errno));
42	RunningAsInit = TRUE;
43	OnVTY = TRUE;
44    }
45    term = getenv("TERM");
46    stat = ioctl(STDERR_FILENO, GIO_COLOR, &ColorDisplay);
47    if (stat < 0) {
48	if (!term) {
49	    if (setenv("TERM", "vt100", 1) < 0)
50		return -1;
51	    if (setenv("TERMCAP", termcap_vt100, 1) < 0)
52		return -1;
53	}
54	if (DebugFD == -1)
55	    DebugFD = dup(1);
56	OnSerial = TRUE;
57    }
58    else {
59	if (ColorDisplay) {
60	    if (!term) {
61		if (setenv("TERM", "cons25", 1) < 0)
62		    return -1;
63		if (setenv("TERMCAP", termcap_cons25, 1) < 0)
64		    return -1;
65	    }
66	}
67	else {
68	    if (!term) {
69		if (setenv("TERM", "cons25-m", 1) < 0)
70		    return -1;
71		if (setenv("TERMCAP", termcap_cons25_m, 1) < 0)
72		    return -1;
73	    }
74	}
75	OnVTY = TRUE;
76    }
77    return 0;
78}
79