termcap.c revision 9202
18097Sjkh/*
28097Sjkh * Copyright (c) 1994, Paul Richards.
38881Srgrimes *
48097Sjkh * All rights reserved.
58881Srgrimes *
68097Sjkh * This software may be used, modified, copied, distributed, and sold, in both
78097Sjkh * source and binary form provided that the above copyright and these terms
88097Sjkh * are retained, verbatim, as the first lines of this file.  Under no
98097Sjkh * circumstances is the author responsible for the proper functioning of this
108097Sjkh * software, nor does the author assume any responsibility for damages
118097Sjkh * incurred with its use.
128097Sjkh */
138097Sjkh
148097Sjkh#include <stdio.h>
158097Sjkh#include <stdlib.h>
168097Sjkh#include <string.h>
178097Sjkh#include <unistd.h>
188097Sjkh#include <stdarg.h>
198097Sjkh#include <fcntl.h>
208756Sjkh#include <sys/errno.h>
218097Sjkh#include <sys/ioctl.h>
228097Sjkh#include <machine/console.h>
238097Sjkh
248097Sjkh#include "sysinstall.h"
258097Sjkh
268097Sjkhint
278097Sjkhset_termcap(void)
288097Sjkh{
298097Sjkh    char           *term;
308601Sjkh    int		   stat;
318097Sjkh
329202Srgrimes    OnVTY = RunningAsInit = FALSE;
339202Srgrimes
349202Srgrimes    term = getenv("TERM");
359202Srgrimes    stat = ioctl(STDERR_FILENO, GIO_COLOR, &ColorDisplay);
369202Srgrimes
378601Sjkh    if (getpid() != 1)
388601Sjkh	DebugFD = open("sysinstall.debug", O_WRONLY|O_CREAT|O_TRUNC, 0644);
399202Srgrimes    else
409202Srgrimes	RunningAsInit = TRUE;
418770Sjkh
428601Sjkh    if (stat < 0) {
438601Sjkh	if (!term) {
448097Sjkh	    if (setenv("TERM", "vt100", 1) < 0)
458097Sjkh		return -1;
468097Sjkh	    if (setenv("TERMCAP", termcap_vt100, 1) < 0)
478097Sjkh		return -1;
488601Sjkh	}
498601Sjkh	if (DebugFD == -1)
508097Sjkh	    DebugFD = dup(1);
518097Sjkh    }
528302Sjkh    else {
539202Srgrimes	int i, on;
549202Srgrimes
559202Srgrimes	DebugFD = open("/dev/ttyv1", O_WRONLY);
569202Srgrimes	on = 1;
579202Srgrimes	i = ioctl(DebugFD, TIOCCONS, (char *)&on);
589202Srgrimes	msgDebug("ioctl(%d, TIOCCONS, NULL) = %d (%s)\n", DebugFD, i, !i ? "success" : strerror(errno));
599202Srgrimes	OnVTY = TRUE;
608601Sjkh	if (ColorDisplay) {
618601Sjkh	    if (!term) {
628601Sjkh		if (setenv("TERM", "cons25", 1) < 0)
638601Sjkh		    return -1;
648601Sjkh		if (setenv("TERMCAP", termcap_cons25, 1) < 0)
658601Sjkh		    return -1;
668601Sjkh	    }
678601Sjkh	}
688601Sjkh	else {
698601Sjkh	    if (!term) {
708601Sjkh		if (setenv("TERM", "cons25-m", 1) < 0)
718601Sjkh		    return -1;
728601Sjkh		if (setenv("TERMCAP", termcap_cons25_m, 1) < 0)
738601Sjkh		    return -1;
748601Sjkh	    }
758601Sjkh	}
768302Sjkh    }
778097Sjkh    return 0;
788097Sjkh}
79