summaryrefslogtreecommitdiff
path: root/ncurses/tinfo/lib_termcap.c
diff options
context:
space:
mode:
Diffstat (limited to 'ncurses/tinfo/lib_termcap.c')
-rw-r--r--ncurses/tinfo/lib_termcap.c60
1 files changed, 31 insertions, 29 deletions
diff --git a/ncurses/tinfo/lib_termcap.c b/ncurses/tinfo/lib_termcap.c
index 2ece985914e9..331c92999a72 100644
--- a/ncurses/tinfo/lib_termcap.c
+++ b/ncurses/tinfo/lib_termcap.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2018-2020,2023 Thomas E. Dickey *
+ * Copyright 2018-2024,2025 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -49,10 +49,10 @@
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_termcap.c,v 1.89 2023/05/27 20:13:10 tom Exp $")
+MODULE_ID("$Id: lib_termcap.c,v 1.96 2025/12/27 12:33:34 tom Exp $")
-NCURSES_EXPORT_VAR(char *) UP = 0;
-NCURSES_EXPORT_VAR(char *) BC = 0;
+NCURSES_EXPORT_VAR(char *) UP = NULL;
+NCURSES_EXPORT_VAR(char *) BC = NULL;
#define MyCache _nc_globals.tgetent_cache
#define CacheInx _nc_globals.tgetent_index
@@ -94,8 +94,8 @@ NCURSES_SP_NAME(tgetent) (NCURSES_SP_DCLx char *bufp, const char *name)
int rc = ERR;
int n;
bool found_cache = FALSE;
-#ifdef USE_TERM_DRIVER
- TERMINAL *termp = 0;
+#if USE_TERM_DRIVER
+ TERMINAL *termp = NULL;
#endif
START_TRACE();
@@ -103,8 +103,8 @@ NCURSES_SP_NAME(tgetent) (NCURSES_SP_DCLx char *bufp, const char *name)
TINFO_SETUP_TERM(&termp, name, STDOUT_FILENO, &rc, TRUE);
-#ifdef USE_TERM_DRIVER
- if (termp == 0 ||
+#if USE_TERM_DRIVER
+ if (termp == NULL ||
!((TERMINAL_CONTROL_BLOCK *) termp)->drv->isTerminfo)
returnCode(rc);
#endif
@@ -125,18 +125,18 @@ NCURSES_SP_NAME(tgetent) (NCURSES_SP_DCLx char *bufp, const char *name)
bool same_result = (MyCache[n].last_used && MyCache[n].last_bufp == bufp);
if (same_result) {
CacheInx = n;
- if (FIX_SGR0 != 0) {
+ if (FIX_SGR0 != NULL) {
FreeAndNull(FIX_SGR0);
}
/*
* Also free the terminfo data that we loaded (much bigger leak).
*/
- if (LAST_TRM != 0 && LAST_TRM != TerminalOf(SP_PARM)) {
- TERMINAL *trm = LAST_TRM;
+ if (LAST_TRM != NULL && LAST_TRM != TerminalOf(SP_PARM)) {
+ const TERMINAL *trm = LAST_TRM;
NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx LAST_TRM);
for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx)
if (LAST_TRM == trm)
- LAST_TRM = 0;
+ LAST_TRM = NULL;
CacheInx = n;
}
found_cache = TRUE;
@@ -157,13 +157,13 @@ NCURSES_SP_NAME(tgetent) (NCURSES_SP_DCLx char *bufp, const char *name)
LAST_TRM = TerminalOf(SP_PARM);
LAST_SEQ = ++CacheSeq;
} else {
- LAST_TRM = 0;
+ LAST_TRM = NULL;
}
PC = 0;
- UP = 0;
- BC = 0;
- FIX_SGR0 = 0; /* don't free it - application may still use */
+ UP = NULL;
+ BC = NULL;
+ FIX_SGR0 = NULL; /* don't free it - application may still use */
if (rc == 1) {
@@ -180,19 +180,19 @@ NCURSES_SP_NAME(tgetent) (NCURSES_SP_DCLx char *bufp, const char *name)
BC = backspace_if_not_bs;
if ((FIX_SGR0 = _nc_trim_sgr0(&TerminalType(TerminalOf(SP_PARM))))
- != 0) {
+ != NULL) {
if (!strcmp(FIX_SGR0, exit_attribute_mode)) {
if (FIX_SGR0 != exit_attribute_mode) {
free(FIX_SGR0);
}
- FIX_SGR0 = 0;
+ FIX_SGR0 = NULL;
}
}
LAST_BUF = bufp;
LAST_USE = TRUE;
SetNoPadding(SP_PARM);
- (void) NCURSES_SP_NAME(baudrate) (NCURSES_SP_ARG); /* sets ospeed as a side-effect */
+ (void) NCURSES_SP_NAME(baudrate) (NCURSES_SP_ARG); /* sets ospeed as a side effect */
/* LINT_PREPRO
#if 0*/
@@ -246,7 +246,7 @@ NCURSES_SP_NAME(tgetflag) (NCURSES_SP_DCLx const char *id)
int j = -1;
entry_ptr = _nc_find_type_entry(id, BOOLEAN, TRUE);
- if (entry_ptr != 0) {
+ if (entry_ptr != NULL) {
j = entry_ptr->nte_index;
}
#if NCURSES_XNAMES
@@ -292,13 +292,15 @@ NCURSES_SP_NAME(tgetnum) (NCURSES_SP_DCLx const char *id)
int result = ABSENT_NUMERIC;
T((T_CALLED("tgetnum(%p, %s)"), (void *) SP_PARM, id));
+ assert(result < 0);
+
if (HasTInfoTerminal(SP_PARM) && ValidCap(id)) {
TERMTYPE2 *tp = &TerminalType(TerminalOf(SP_PARM));
struct name_table_entry const *entry_ptr;
int j = -1;
entry_ptr = _nc_find_type_entry(id, NUMBER, TRUE);
- if (entry_ptr != 0) {
+ if (entry_ptr != NULL) {
j = entry_ptr->nte_index;
}
#if NCURSES_XNAMES
@@ -350,7 +352,7 @@ NCURSES_SP_NAME(tgetstr) (NCURSES_SP_DCLx const char *id, char **area)
int j = -1;
entry_ptr = _nc_find_type_entry(id, STRING, TRUE);
- if (entry_ptr != 0) {
+ if (entry_ptr != NULL) {
j = entry_ptr->nte_index;
}
#if NCURSES_XNAMES
@@ -371,12 +373,12 @@ NCURSES_SP_NAME(tgetstr) (NCURSES_SP_DCLx const char *id, char **area)
/* setupterm forces canceled strings to null */
if (VALID_STRING(result)) {
if (result == exit_attribute_mode
- && FIX_SGR0 != 0) {
+ && FIX_SGR0 != NULL) {
result = FIX_SGR0;
TR(TRACE_DATABASE, ("altered to : %s", _nc_visbuf(result)));
}
- if (area != 0
- && *area != 0) {
+ if (area != NULL
+ && *area != NULL) {
_nc_STRCPY(*area, result, 1024);
result = *area;
*area += strlen(*area) + 1;
@@ -401,13 +403,13 @@ tgetstr(const char *id, char **area)
NCURSES_EXPORT(void)
_nc_tgetent_leak(const TERMINAL *const termp)
{
- if (termp != 0) {
+ if (termp != NULL) {
int num;
for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) {
if (LAST_TRM == termp) {
FreeAndNull(FIX_SGR0);
- if (LAST_TRM != 0) {
- LAST_TRM = 0;
+ if (LAST_TRM != NULL) {
+ LAST_TRM = NULL;
}
break;
}
@@ -420,7 +422,7 @@ _nc_tgetent_leaks(void)
{
int num;
for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) {
- if (LAST_TRM != 0) {
+ if (LAST_TRM != NULL) {
del_curterm(LAST_TRM);
_nc_tgetent_leak(LAST_TRM);
}