summaryrefslogtreecommitdiff
path: root/test/demo_termcap.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/demo_termcap.c')
-rw-r--r--test/demo_termcap.c94
1 files changed, 47 insertions, 47 deletions
diff --git a/test/demo_termcap.c b/test/demo_termcap.c
index 6e2aba700679..c4689ae75244 100644
--- a/test/demo_termcap.c
+++ b/test/demo_termcap.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2019-2022,2023 Thomas E. Dickey *
+ * Copyright 2019-2024,2025 Thomas E. Dickey *
* Copyright 2005-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: demo_termcap.c,v 1.65 2023/05/27 20:13:10 tom Exp $
+ * $Id: demo_termcap.c,v 1.75 2025/07/05 15:11:35 tom Exp $
*
* A simple demo of the termcap interface.
*/
@@ -101,15 +101,18 @@ static long total_b_values;
static long total_n_values;
static long total_s_values;
-#define isCapName(c) (isgraph(c) && strchr("^=:\\", c) == 0)
+#define isCapName(c) (isgraph(c) && strchr("^=:\\", c) == NULL)
#define EachCapName(n) n = 33; n < 127; ++n
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;
}
@@ -150,17 +153,17 @@ 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 {
db_item++;
}
}
- if (result != 0)
+ if (result != NULL)
printf("** %s\n", result);
return result;
}
@@ -174,7 +177,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 /* NO_LEAKS */
@@ -256,10 +259,10 @@ dumpit(NCURSES_CONST char *cap)
* to hold all of the strings extracted from the terminal entry.
*/
char area[1024], *ap = area;
- char *str;
+ NCURSES_CONST char *str;
int num;
- if ((str = tgetstr(cap, &ap)) != 0) {
+ if ((str = tgetstr(cap, &ap)) != NULL) {
total_values++;
total_s_values++;
if (!q_opt) {
@@ -289,7 +292,7 @@ dumpit(NCURSES_CONST char *cap)
}
static void
-brute_force(const char *name)
+brute_force(NCURSES_CONST char *name)
{
char buffer[1024];
@@ -343,7 +346,7 @@ demo_termcap(NCURSES_CONST char *name)
if (b_opt) {
for (n = 0;; ++n) {
cap = my_boolcodes[n];
- if (cap == 0)
+ if (cap == NULL)
break;
dumpit(cap);
}
@@ -352,7 +355,7 @@ demo_termcap(NCURSES_CONST char *name)
if (n_opt) {
for (n = 0;; ++n) {
cap = my_numcodes[n];
- if (cap == 0)
+ if (cap == NULL)
break;
dumpit(cap);
}
@@ -361,16 +364,16 @@ demo_termcap(NCURSES_CONST char *name)
if (s_opt) {
for (n = 0;; ++n) {
cap = my_strcodes[n];
- if (cap == 0)
+ if (cap == NULL)
break;
dumpit(cap);
}
}
#ifdef NCURSES_VERSION
- if (x_opt && (my_blob == 0) && y_opt) {
+ if (x_opt && (my_blob == NULL) && y_opt) {
#if NCURSES_XNAMES
- TERMTYPE *term = (TERMTYPE *) cur_term;
- if (term != 0
+ NCURSES_CONST TERMTYPE *term = (TERMTYPE *) cur_term;
+ if (term != NULL
&& ((NUM_BOOLEANS(term) != BOOLCOUNT)
|| (NUM_NUMBERS(term) != NUMCOUNT)
|| (NUM_STRINGS(term) != STRCOUNT))) {
@@ -429,16 +432,16 @@ parse_description(const char *input_name)
* None of the arrays could be larger than the input-file, and since it
* is small, just allocate the maximum for simplicity.
*/
- if ((my_blob = malloc((size_t) sb.st_size + 1)) == 0 ||
- (my_boolcodes = typeCalloc(char *, sb.st_size)) == 0 ||
- (my_numcodes = typeCalloc(char *, sb.st_size)) == 0 ||
- (my_numvalues = typeCalloc(char *, sb.st_size)) == 0 ||
- (my_strcodes = typeCalloc(char *, sb.st_size)) == 0 ||
- (my_strvalues = typeCalloc(char *, sb.st_size)) == 0) {
+ if ((my_blob = malloc((size_t) sb.st_size + 1)) == NULL ||
+ (my_boolcodes = typeCalloc(char *, sb.st_size)) == NULL ||
+ (my_numcodes = typeCalloc(char *, sb.st_size)) == NULL ||
+ (my_numvalues = typeCalloc(char *, sb.st_size)) == NULL ||
+ (my_strcodes = typeCalloc(char *, sb.st_size)) == NULL ||
+ (my_strvalues = typeCalloc(char *, sb.st_size)) == NULL) {
failed("cannot allocate memory for input-file");
}
- if ((fp = fopen(input_name, "r")) == 0) {
+ if ((fp = fopen(input_name, "r")) == NULL) {
failed("cannot open input-file");
} else {
len = fread(my_blob, sizeof(char), (size_t) sb.st_size, fp);
@@ -674,11 +677,11 @@ parse_description(const char *input_name)
break;
}
}
- my_boolcodes[count_bools] = 0;
- my_numcodes[count_nums] = 0;
- my_numvalues[count_nums] = 0;
- my_strcodes[count_strs] = 0;
- my_strvalues[count_strs] = 0;
+ my_boolcodes[count_bools] = NULL;
+ my_numcodes[count_nums] = NULL;
+ my_numvalues[count_nums] = NULL;
+ my_strcodes[count_strs] = NULL;
+ my_strvalues[count_strs] = NULL;
#if 0
printf("bools:%d\n", (int) count_bools);
@@ -702,11 +705,11 @@ copy_code_list(NCURSES_CONST char *const *list)
int pass;
size_t count;
size_t length = 1;
- char **result = 0;
- char *unused = 0;
+ char **result = NULL;
+ char *unused = NULL;
for (pass = 0; pass < 2; ++pass) {
- for (count = 0; list[count] != 0; ++count) {
+ for (count = 0; list[count] != NULL; ++count) {
size_t chunk = strlen(list[count]) + 1;
if (pass == 0) {
length += chunk;
@@ -720,7 +723,7 @@ copy_code_list(NCURSES_CONST char *const *list)
char *blob = malloc(length);
result = typeCalloc(char *, count + 1);
unused = blob;
- if (blob == 0 || result == 0)
+ if (blob == NULL || result == NULL)
failed("copy_code_list failed");
}
}
@@ -756,10 +759,10 @@ usage(int ok)
," -b print boolean-capabilities"
," -d LIST colon-separated list of databases to use"
," -e NAME environment variable to set with -d option"
- ," -i NAME terminal description to use as names for \"-a\" option, etc."
+ ," -i NAME terminal description to use as names for \"-a\" option"
," -n print numeric-capabilities"
," -q quiet (prints only counts)"
- ," -r COUNT repeat for given count"
+ ," -r NUM repeat tests NUM times"
," -s print string-capabilities"
," -v print termcap-variables"
#ifdef NCURSES_VERSION
@@ -781,12 +784,12 @@ main(int argc, char *argv[])
{
int ch;
int n;
- char *name;
+ NCURSES_CONST char *name;
bool a_opt = FALSE;
#if defined(NCURSES_VERSION) || defined(HAVE_CURSES_DATA_OSPEED)
bool v_opt = FALSE;
#endif
- char *input_name = 0;
+ NCURSES_CONST char *input_name = NULL;
int repeat;
int r_opt = 1;
@@ -837,11 +840,8 @@ main(int argc, char *argv[])
break;
#endif
#endif
- case OPTS_VERSION:
- show_version(argv);
- ExitProgram(EXIT_SUCCESS);
default:
- usage(ch == OPTS_USAGE);
+ CASE_COMMON;
/* NOTREACHED */
}
}
@@ -864,15 +864,15 @@ 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 NCURSES_CONST char dumb[] = "dumb";
brute_force(dumb);
}
}
} else {
- if (input_name != 0) {
+ if (input_name != NULL) {
parse_description(input_name);
}
#if USE_CODE_LISTS
@@ -891,10 +891,10 @@ main(int argc, char *argv[])
for (n = optind; n < argc; ++n) {
demo_termcap(argv[n]);
}
- } else if ((name = getenv("TERM")) != 0) {
+ } else if ((name = getenv("TERM")) != NULL) {
demo_termcap(name);
} else {
- static char dumb[] = "dumb";
+ static NCURSES_CONST char dumb[] = "dumb";
demo_termcap(dumb);
}
}