44*/
55
66/*
7- * Copyright (c) 2007-2015 The OpenRC Authors.
7+ * Copyright (c) 2007-2024 The OpenRC Authors.
88 * See the Authors file at the top-level directory of this distribution and
99 * https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS
1010 *
2626#include <string.h>
2727#include <strings.h>
2828#include <syslog.h>
29- #ifdef HAVE_TERMCAP
30- # include <termcap.h>
31- #endif
3229#include <unistd.h>
3330
3431#include "einfo.h"
@@ -97,12 +94,6 @@ static char *goto_column = NULL;
9794static const char * term = NULL ;
9895static bool term_is_cons25 = false;
9996
100- /* Termcap buffers and pointers
101- * Static buffers suck hard, but some termcap implementations require them */
102- #ifdef HAVE_TERMCAP
103- static char termcapbuf [2048 ];
104- static char tcapbuf [512 ];
105- #else
10697/* No curses support, so we hardcode a list of colour capable terms
10798 * Only terminals without "color" in the name need to be explicitly listed */
10899static const char * const color_terms [] = {
@@ -144,7 +135,6 @@ static const char *const color_terms[] = {
144135 "xterm-debian" ,
145136 NULL
146137};
147- #endif
148138
149139#ifndef HAVE_STRLCPY
150140static size_t
@@ -236,7 +226,6 @@ is_verbose(void)
236226}
237227
238228/* Fake tgoto call - very crapy, but works for our needs */
239- #ifndef HAVE_TERMCAP
240229static char *
241230tgoto (const char * cap , int col , int line )
242231{
@@ -299,7 +288,6 @@ tgoto(const char *cap, int col, int line)
299288 * p = '\0' ;
300289 return buf ;
301290}
302- #endif
303291
304292static bool
305293colour_terminal (FILE * EINFO_RESTRICT f )
@@ -312,9 +300,6 @@ colour_terminal(FILE * EINFO_RESTRICT f)
312300 const char * bold ;
313301 char tmp [100 ];
314302 unsigned int i = 0 ;
315- #ifdef HAVE_TERMCAP
316- char * bp ;
317- #endif
318303
319304 if (f && !isatty (fileno (f )))
320305 return false;
@@ -336,65 +321,33 @@ colour_terminal(FILE * EINFO_RESTRICT f)
336321 if (strcmp (term , "cons25" ) == 0 )
337322 term_is_cons25 = true;
338323
339- #ifdef HAVE_TERMCAP
340- /* Check termcap to see if we can do colour or not */
341- if (tgetent (termcapbuf , term ) == 1 ) {
342- bp = tcapbuf ;
343- _af = tgetstr ("AF" , & bp );
344- _ce = tgetstr ("ce" , & bp );
345- _ch = tgetstr ("ch" , & bp );
346- /* Our ch use also works with RI .... for now */
347- if (!_ch )
348- _ch = tgetstr ("RI" , & bp );
349- _md = tgetstr ("md" , & bp );
350- _me = tgetstr ("me" , & bp );
351- _up = tgetstr ("up" , & bp );
352- }
324+ if (strstr (term , "color" ))
325+ in_colour = 1 ;
353326
354- /* Cheat here as vanilla BSD has the whole termcap info in /usr
355- * which is not available to us when we boot */
356- if (term_is_cons25 || strcmp (term , "wsvt25" ) == 0 ) {
357- #else
358- if (strstr (term , "color" ))
327+ while (color_terms [i ] && in_colour != 1 ) {
328+ if (strcmp (color_terms [i ], term ) == 0 ) {
359329 in_colour = 1 ;
360-
361- while (color_terms [i ] && in_colour != 1 ) {
362- if (strcmp (color_terms [i ], term ) == 0 ) {
363- in_colour = 1 ;
364- }
365- i ++ ;
366- }
367-
368- if (in_colour != 1 ) {
369- in_colour = 0 ;
370- return false;
371330 }
372- #endif
373- if (!_af )
374- _af = AF ;
375- if (!_ce )
376- _ce = CE ;
377- if (!_ch )
378- _ch = CH ;
379- if (!_md )
380- _md = MD ;
381- if (!_me )
382- _me = ME ;
383- if (!_up )
384- _up = UP ;
385- #ifdef HAVE_TERMCAP
331+ i ++ ;
386332 }
387333
388- if (! _af || ! _ce || ! _me || ! _md || ! _up ) {
334+ if (in_colour != 1 ) {
389335 in_colour = 0 ;
390336 return false;
391337 }
392338
393- /* Many termcap databases don't have ch or RI even though they
394- * do work */
339+ if (!_af )
340+ _af = AF ;
341+ if (!_ce )
342+ _ce = CE ;
395343 if (!_ch )
396344 _ch = CH ;
397- #endif
345+ if (!_md )
346+ _md = MD ;
347+ if (!_me )
348+ _me = ME ;
349+ if (!_up )
350+ _up = UP ;
398351
399352 /* Now setup our colours */
400353 p = ebuffer ;
0 commit comments