Skip to content

Commit

Permalink
Trivial curses/termcap removal
Browse files Browse the repository at this point in the history
Remove the curses code and make the HAVE_TERMCAP-gated "fallbacks"
always present. This makes an ANSI terminal required for colors.

X-Gentoo-Bug: https://bugs.gentoo.org/904277
Closes: #619
  • Loading branch information
xxc3nsoredxx authored and williamh committed Apr 1, 2024
1 parent 7ac2080 commit 536794d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 79 deletions.
9 changes: 0 additions & 9 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,6 @@ else
cc_selinux_flags = []
endif

termcap = get_option('termcap')
if termcap != ''
termcap_dep = dependency(termcap)
termcap_flags = '-DHAVE_TERMCAP'
else
termcap_dep = []
termcap_flags = []
endif

if get_option('buildtype').startswith('debug')
cc_debug_flags = ['-DRC_DEBUG']
else
Expand Down
4 changes: 0 additions & 4 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,5 @@ option('shell', type : 'string', value : '/bin/sh',
description : 'Default posix compatible shell')
option('sysvinit', type : 'boolean', value : false,
description : 'enable SysVinit compatibility (linux only)')
option('termcap', type : 'combo',
choices :
[ '', 'ncurses', 'termcap' ],
description : 'the termcap library to use')
option('zsh-completions', type : 'boolean',
description : 'install zsh completions')
81 changes: 17 additions & 64 deletions src/libeinfo/libeinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/*
* Copyright (c) 2007-2015 The OpenRC Authors.
* Copyright (c) 2007-2024 The OpenRC Authors.
* See the Authors file at the top-level directory of this distribution and
* https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS
*
Expand All @@ -26,9 +26,6 @@
#include <string.h>
#include <strings.h>
#include <syslog.h>
#ifdef HAVE_TERMCAP
# include <termcap.h>
#endif
#include <unistd.h>

#include "einfo.h"
Expand Down Expand Up @@ -97,12 +94,6 @@ static char *goto_column = NULL;
static const char *term = NULL;
static bool term_is_cons25 = false;

/* Termcap buffers and pointers
* Static buffers suck hard, but some termcap implementations require them */
#ifdef HAVE_TERMCAP
static char termcapbuf[2048];
static char tcapbuf[512];
#else
/* No curses support, so we hardcode a list of colour capable terms
* Only terminals without "color" in the name need to be explicitly listed */
static const char *const color_terms[] = {
Expand Down Expand Up @@ -144,7 +135,6 @@ static const char *const color_terms[] = {
"xterm-debian",
NULL
};
#endif

#ifndef HAVE_STRLCPY
static size_t
Expand Down Expand Up @@ -236,7 +226,6 @@ is_verbose(void)
}

/* Fake tgoto call - very crapy, but works for our needs */
#ifndef HAVE_TERMCAP
static char *
tgoto(const char *cap, int col, int line)
{
Expand Down Expand Up @@ -299,7 +288,6 @@ tgoto(const char *cap, int col, int line)
*p = '\0';
return buf;
}
#endif

static bool
colour_terminal(FILE * EINFO_RESTRICT f)
Expand All @@ -312,9 +300,6 @@ colour_terminal(FILE * EINFO_RESTRICT f)
const char *bold;
char tmp[100];
unsigned int i = 0;
#ifdef HAVE_TERMCAP
char *bp;
#endif

if (f && !isatty(fileno(f)))
return false;
Expand All @@ -336,65 +321,33 @@ colour_terminal(FILE * EINFO_RESTRICT f)
if (strcmp(term, "cons25") == 0)
term_is_cons25 = true;

#ifdef HAVE_TERMCAP
/* Check termcap to see if we can do colour or not */
if (tgetent(termcapbuf, term) == 1) {
bp = tcapbuf;
_af = tgetstr("AF", &bp);
_ce = tgetstr("ce", &bp);
_ch = tgetstr("ch", &bp);
/* Our ch use also works with RI .... for now */
if (!_ch)
_ch = tgetstr("RI", &bp);
_md = tgetstr("md", &bp);
_me = tgetstr("me", &bp);
_up = tgetstr("up", &bp);
}
if (strstr(term, "color"))
in_colour = 1;

/* Cheat here as vanilla BSD has the whole termcap info in /usr
* which is not available to us when we boot */
if (term_is_cons25 || strcmp(term, "wsvt25") == 0) {
#else
if (strstr(term, "color"))
while (color_terms[i] && in_colour != 1) {
if (strcmp(color_terms[i], term) == 0) {
in_colour = 1;

while (color_terms[i] && in_colour != 1) {
if (strcmp(color_terms[i], term) == 0) {
in_colour = 1;
}
i++;
}

if (in_colour != 1) {
in_colour = 0;
return false;
}
#endif
if (!_af)
_af = AF;
if (!_ce)
_ce = CE;
if (!_ch)
_ch = CH;
if (!_md)
_md = MD;
if (!_me)
_me = ME;
if (!_up)
_up = UP;
#ifdef HAVE_TERMCAP
i++;
}

if (!_af || !_ce || !_me || !_md || !_up) {
if (in_colour != 1) {
in_colour = 0;
return false;
}

/* Many termcap databases don't have ch or RI even though they
* do work */
if (!_af)
_af = AF;
if (!_ce)
_ce = CE;
if (!_ch)
_ch = CH;
#endif
if (!_md)
_md = MD;
if (!_me)
_me = ME;
if (!_up)
_up = UP;

/* Now setup our colours */
p = ebuffer;
Expand Down
2 changes: 0 additions & 2 deletions src/libeinfo/meson.build
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
libeinfo_version = '1'

libeinfo = library('einfo', ['libeinfo.c'],
c_args : termcap_flags,
include_directories : incdir,
dependencies : termcap_dep,
link_depends : 'einfo.map',
version : libeinfo_version,
install : true,
Expand Down

0 comments on commit 536794d

Please sign in to comment.