aboutsummaryrefslogtreecommitdiff
path: root/test/test_sgr.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_sgr.c')
-rw-r--r--test/test_sgr.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/test/test_sgr.c b/test/test_sgr.c
index 8763dca3cd34..6120344eabb6 100644
--- a/test/test_sgr.c
+++ b/test/test_sgr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2019-2022,2023 Thomas E. Dickey *
+ * Copyright 2019-2024,2025 Thomas E. Dickey *
* Copyright 2015-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -30,7 +30,7 @@
/*
* Author: Thomas E. Dickey
*
- * $Id: test_sgr.c,v 1.22 2023/05/27 20:13:10 tom Exp $
+ * $Id: test_sgr.c,v 1.28 2025/07/05 15:11:35 tom Exp $
*
* A simple demo of the sgr/sgr0 terminal capabilities.
*/
@@ -63,9 +63,12 @@ static long total_values;
static char *
make_dbitem(const char *const p, const char *const q)
{
- size_t need = strlen(e_opt) + 2 + (size_t) (p - q);
+ size_t diff = (size_t) (p - q);
+ size_t need = strlen(e_opt) + 2 + diff;
char *result = malloc(need);
- _nc_SPRINTF(result, _nc_SLIMIT(need) "%s=%.*s", e_opt, (int) (p - q), q);
+ if (result != NULL) {
+ _nc_SPRINTF(result, _nc_SLIMIT(need) "%s=%.*s", e_opt, (int) diff, q);
+ }
return result;
}
@@ -106,10 +109,10 @@ make_dblist(void)
static char *
next_dbitem(void)
{
- char *result = 0;
+ char *result = NULL;
if (db_list) {
- if ((result = db_list[db_item]) == 0) {
+ if ((result = db_list[db_item]) == NULL) {
db_item = 0;
result = db_list[0];
} else {
@@ -129,7 +132,7 @@ free_dblist(void)
for (n = 0; db_list[n]; ++n)
free(db_list[n]);
free(db_list);
- db_list = 0;
+ db_list = NULL;
}
}
#endif
@@ -142,10 +145,10 @@ free_dblist(void)
#define MASK_REV (1 << 2)
static void
-dumpit(unsigned bits, unsigned ignore, const char *sgr, const char *sgr0)
+dumpit(unsigned bits, unsigned ignore, NCURSES_CONST char *sgr, NCURSES_CONST char *sgr0)
{
- static const char sample[] = "abcdefghijklm";
- static char params[] = "SURBDBIPA";
+ static NCURSES_CONST char sample[] = "abcdefghijklm";
+ static NCURSES_CONST char params[] = "SURBDBIPA";
unsigned n;
printf("%4u ", bits);
@@ -177,12 +180,11 @@ one_bit(unsigned a, unsigned b)
static void
brute_force(const char *name)
{
- unsigned count;
- char *my_sgr;
- char *my_sgr0;
- char *my_bold;
- char *my_revs;
- char *my_smso;
+ NCURSES_CONST char *my_sgr;
+ NCURSES_CONST char *my_sgr0;
+ NCURSES_CONST char *my_bold;
+ NCURSES_CONST char *my_revs;
+ NCURSES_CONST char *my_smso;
char *my_name = strdup(name);
if (db_list) {
@@ -219,6 +221,7 @@ brute_force(const char *name)
unsigned ignore = 0;
unsigned reason = 0;
unsigned repeat = 0;
+ unsigned count;
for (count = 0; count < MAXSGR; ++count) {
values[count] = tparm(my_sgr,
BITS2P(1),
@@ -230,20 +233,20 @@ brute_force(const char *name)
BITS2P(7),
BITS2P(8),
BITS2P(9));
- if (values[count] != 0) {
+ if (values[count] != NULL) {
values[count] = strdup(values[count]);
}
}
for (count = 0; count < MAXSGR; ++count) {
- if (values[count] != 0) {
+ if (values[count] != NULL) {
for (j = count + 1; j < MAXSGR; ++j) {
- if (values[j] == 0)
+ if (values[j] == NULL)
continue;
if (strcmp(values[count], values[j]))
continue;
if (one_bit(count, j)) {
free(values[j]);
- values[j] = 0;
+ values[j] = NULL;
}
}
}
@@ -253,7 +256,7 @@ brute_force(const char *name)
for (count = 0; count < MAXSGR; ++count) {
if ((count & mask) != 0)
continue;
- if (values[count] != 0 && values[count + mask] != 0) {
+ if (values[count] != NULL && values[count + mask] != NULL) {
mask = 0;
break;
}
@@ -272,14 +275,14 @@ brute_force(const char *name)
}
}
for (count = 0; count < MAXSGR; ++count) {
- if (values[count] != 0) {
+ if (values[count] != NULL) {
bool found = FALSE;
if ((repeat & MASK_SMSO) != 0
&& (count & MASK_SMSO) != 0) {
found = TRUE;
} else {
for (j = 0; j < count; ++j) {
- if (values[j] != 0 && !strcmp(values[j], values[count])) {
+ if (values[j] != NULL && !strcmp(values[j], values[count])) {
if ((repeat & MASK_SMSO) != 0
&& (j & MASK_SMSO) != 0
&& (count & reason) != 0) {
@@ -334,7 +337,7 @@ int
main(int argc, char *argv[])
{
int ch;
- char *name;
+ const char *name;
while ((ch = getopt(argc, argv, OPTS_COMMON "d:e:nq")) != -1) {
switch (ch) {
@@ -350,11 +353,8 @@ main(int argc, char *argv[])
case 'q':
q_opt = TRUE;
break;
- case OPTS_VERSION:
- show_version(argv);
- ExitProgram(EXIT_SUCCESS);
default:
- usage(ch == OPTS_USAGE);
+ CASE_COMMON;
/* NOTREACHED */
}
}
@@ -366,10 +366,10 @@ main(int argc, char *argv[])
for (n = optind; n < argc; ++n) {
brute_force(argv[n]);
}
- } else if ((name = getenv("TERM")) != 0) {
+ } else if ((name = getenv("TERM")) != NULL) {
brute_force(name);
} else {
- static char dumb[] = "dumb";
+ static const char dumb[] = "dumb";
brute_force(dumb);
}