termcap.c revision 17382
1139826Simp/* 253541Sshin * Copyright (c) 1994, Paul Richards. 353541Sshin * 453541Sshin * All rights reserved. 553541Sshin * 653541Sshin * This software may be used, modified, copied, distributed, and sold, in both 753541Sshin * source and binary form provided that the above copyright and these terms 853541Sshin * are retained, verbatim, as the first lines of this file. Under no 953541Sshin * circumstances is the author responsible for the proper functioning of this 1053541Sshin * software, nor does the author assume any responsibility for damages 1153541Sshin * incurred with its use. 1253541Sshin */ 1353541Sshin 1453541Sshin#include <stdio.h> 1553541Sshin#include <stdlib.h> 1653541Sshin#include <string.h> 1753541Sshin#include <unistd.h> 1853541Sshin#include <stdarg.h> 1953541Sshin#include <fcntl.h> 2053541Sshin#include <sys/errno.h> 2153541Sshin#include <sys/ioctl.h> 2253541Sshin#include <machine/console.h> 2353541Sshin 2453541Sshin#include "sysinstall.h" 2553541Sshin 2653541Sshin#define VTY_STATUS_LINE 24 2753541Sshin#define TTY_STATUS_LINE 23 28174510Sobrien 29174510Sobrienint 3053541Sshinset_termcap(void) 3153541Sshin{ 32139826Simp char *term; 3353541Sshin int stat; 3453541Sshin struct ttysize ts; 3553541Sshin 3653541Sshin OnVTY = FALSE; 3753541Sshin term = getenv("TERM"); 3853541Sshin stat = ioctl(STDERR_FILENO, GIO_COLOR, &ColorDisplay); 3953541Sshin 4053541Sshin if (getpid() != 1) { 4153541Sshin DebugFD = open("sysinstall.debug", O_WRONLY|O_CREAT|O_TRUNC, 0644); 4253541Sshin if (DebugFD < 0) 4353541Sshin DebugFD = open("/dev/null", O_RDWR, 0); 4453541Sshin } 4553541Sshin 4653541Sshin if (stat < 0) { 4753541Sshin if (!term) { 4853541Sshin if (setenv("TERM", "vt100", 1) < 0) 4953541Sshin return -1; 5053541Sshin if (setenv("TERMCAP", termcap_vt100, 1) < 0) 5153541Sshin return -1; 5253541Sshin } 5353541Sshin if (DebugFD == -1) 5453541Sshin DebugFD = dup(1); 5553541Sshin } 5653541Sshin else { 5753541Sshin int i, on; 5853541Sshin 5953541Sshin if (getpid() == 1) { 6053541Sshin DebugFD = open("/dev/ttyv1", O_WRONLY); 6153541Sshin on = 1; 6253541Sshin i = ioctl(DebugFD, TIOCCONS, (char *)&on); 63174510Sobrien msgDebug("ioctl(%d, TIOCCONS, NULL) = %d (%s)\n", DebugFD, i, !i ? "success" : strerror(errno)); 64174510Sobrien } 65174510Sobrien if (ColorDisplay) { 6662587Sitojun if (!term) { 6762587Sitojun if (setenv("TERM", "cons25", 1) < 0) 6862587Sitojun return -1; 6953541Sshin if (setenv("TERMCAP", termcap_cons25, 1) < 0) 7053541Sshin return -1; 7153541Sshin } 7253541Sshin } 7353541Sshin else { 7453541Sshin if (!term) { 7553541Sshin if (setenv("TERM", "cons25-m", 1) < 0) 76164033Srwatson return -1; 7753541Sshin if (setenv("TERMCAP", termcap_cons25_m, 1) < 0) 7853541Sshin return -1; 7953541Sshin } 8053541Sshin } 81181803Sbz OnVTY = TRUE; 8253541Sshin } 8353541Sshin if (ioctl(0, TIOCGSIZE, &ts) == -1) { 8453541Sshin msgDebug("Unable to get terminal size - errno %d\n", errno); 8553541Sshin ts.ts_lines = 0; 8653541Sshin } 87185571Sbz StatusLine = ts.ts_lines ? ts.ts_lines : (OnVTY ? VTY_STATUS_LINE : TTY_STATUS_LINE); 8853541Sshin return 0; 8953541Sshin} 9053541Sshin