termcap.c revision 8770
18097Sjkh/*
28097Sjkh * Copyright (c) 1994, Paul Richards.
38097Sjkh *
48097Sjkh * All rights reserved.
58097Sjkh *
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
328302Sjkh    OnVTY = OnSerial = FALSE;
338601Sjkh    if (getpid() != 1)
348601Sjkh	DebugFD = open("sysinstall.debug", O_WRONLY|O_CREAT|O_TRUNC, 0644);
358770Sjkh    else {
368770Sjkh	int i, on;
378770Sjkh
388770Sjkh	DebugFD = open("/dev/ttyv1", O_WRONLY);
398770Sjkh	on = 1;
408770Sjkh	i = ioctl(DebugFD, TIOCCONS, (char *)&on);
418770Sjkh	msgDebug("ioctl(%d, TIOCCONS, NULL) = %d (%s)\n", DebugFD, i, !i ? "success" : strerror(errno));
428735Sjkh	RunningAsInit = TRUE;
438770Sjkh	OnVTY = TRUE;
448770Sjkh    }
458097Sjkh    term = getenv("TERM");
468601Sjkh    stat = ioctl(STDERR_FILENO, GIO_COLOR, &ColorDisplay);
478601Sjkh    if (stat < 0) {
488601Sjkh	if (!term) {
498097Sjkh	    if (setenv("TERM", "vt100", 1) < 0)
508097Sjkh		return -1;
518097Sjkh	    if (setenv("TERMCAP", termcap_vt100, 1) < 0)
528097Sjkh		return -1;
538601Sjkh	}
548601Sjkh	if (DebugFD == -1)
558097Sjkh	    DebugFD = dup(1);
568601Sjkh	OnSerial = TRUE;
578097Sjkh    }
588302Sjkh    else {
598601Sjkh	if (ColorDisplay) {
608601Sjkh	    if (!term) {
618601Sjkh		if (setenv("TERM", "cons25", 1) < 0)
628601Sjkh		    return -1;
638601Sjkh		if (setenv("TERMCAP", termcap_cons25, 1) < 0)
648601Sjkh		    return -1;
658601Sjkh	    }
668601Sjkh	}
678601Sjkh	else {
688601Sjkh	    if (!term) {
698601Sjkh		if (setenv("TERM", "cons25-m", 1) < 0)
708601Sjkh		    return -1;
718601Sjkh		if (setenv("TERMCAP", termcap_cons25_m, 1) < 0)
728601Sjkh		    return -1;
738601Sjkh	    }
748601Sjkh	}
758601Sjkh	OnVTY = TRUE;
768302Sjkh    }
778097Sjkh    return 0;
788097Sjkh}
79