diff options
Diffstat (limited to 'test/demo_terminfo.c')
| -rw-r--r-- | test/demo_terminfo.c | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/test/demo_terminfo.c b/test/demo_terminfo.c index 5e78015c36e0..f5b2967739ee 100644 --- a/test/demo_terminfo.c +++ b/test/demo_terminfo.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019-2022,2023 Thomas E. Dickey * + * Copyright 2019-2024,2025 Thomas E. Dickey * * Copyright 2009-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_terminfo.c,v 1.57 2023/05/27 20:13:10 tom Exp $ + * $Id: demo_terminfo.c,v 1.64 2025/07/05 15:11:35 tom Exp $ * * A simple demo of the terminfo interface. */ @@ -98,9 +98,12 @@ static long total_s_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; } @@ -141,17 +144,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; } @@ -165,7 +168,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 @@ -176,7 +179,7 @@ dumpit(NCURSES_CONST char *cap, const char *show) const char *str; int num; - if ((str = tigetstr(cap)) != 0 && (str != (char *) -1)) { + if ((str = tigetstr(cap)) != NULL && (str != (char *) -1)) { total_values++; total_s_values++; if (!q_opt) { @@ -253,7 +256,7 @@ dumpit(NCURSES_CONST char *cap, const char *show) #define LegalItem(c,n) (n) static void -brute_force(const char *name) +brute_force(NCURSES_CONST char *name) { #define MAX_FORCE 5 /* omit "colors", since CPU-time is a problem */ static const char legal[] = "\ @@ -324,7 +327,7 @@ abcdefghijklmnopqrstuvwxyz_"; #endif static void -demo_terminfo(char *name) +demo_terminfo(NCURSES_CONST char *name) { unsigned n; NCURSES_CONST char *cap; @@ -339,7 +342,7 @@ demo_terminfo(char *name) if (b_opt) { for (n = 0;; ++n) { cap = my_boolcodes[n]; - if (cap == 0) + if (cap == NULL) break; dumpit(cap, fullname(bool, n)); } @@ -348,7 +351,7 @@ demo_terminfo(char *name) if (n_opt) { for (n = 0;; ++n) { cap = my_numcodes[n]; - if (cap == 0) + if (cap == NULL) break; dumpit(cap, fullname(num, n)); } @@ -357,17 +360,17 @@ demo_terminfo(char *name) if (s_opt) { for (n = 0;; ++n) { cap = my_strcodes[n]; - if (cap == 0) + if (cap == NULL) break; dumpit(cap, fullname(str, n)); } } #ifdef NCURSES_VERSION - if (x_opt && (my_blob == 0)) { + if (x_opt && (my_blob == NULL)) { if (y_opt) { #if NCURSES_XNAMES - TERMTYPE *term = (TERMTYPE *) cur_term; - if (term != 0 + const TERMTYPE *term = (TERMTYPE *) cur_term; + if (term != NULL && ((NUM_BOOLEANS(term) != BOOLCOUNT) || (NUM_NUMBERS(term) != NUMCOUNT) || (NUM_STRINGS(term) != STRCOUNT))) { @@ -455,16 +458,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); @@ -704,11 +707,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); @@ -732,11 +735,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; @@ -750,7 +753,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"); } } @@ -786,11 +789,11 @@ 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" - ," -f print full names" + ," -f print full terminfo names" ," -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" #ifdef NCURSES_VERSION ," -x print extended capabilities" @@ -813,9 +816,9 @@ main(int argc, char *argv[]) int ch; int n; int repeat; - char *name; + NCURSES_CONST char *name; int r_opt = 1; - char *input_name = 0; + const char *input_name = NULL; while ((ch = getopt(argc, argv, OPTS_COMMON "abd:e:fi:nqr:sxy")) != -1) { switch (ch) { @@ -861,11 +864,8 @@ main(int argc, char *argv[]) x_opt = TRUE; break; #endif - case OPTS_VERSION: - show_version(argv); - ExitProgram(EXIT_SUCCESS); default: - usage(ch == OPTS_USAGE); + CASE_COMMON; /* NOTREACHED */ } } @@ -888,15 +888,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 @@ -915,10 +915,10 @@ main(int argc, char *argv[]) for (n = optind; n < argc; ++n) { demo_terminfo(argv[n]); } - } else if ((name = getenv("TERM")) != 0) { + } else if ((name = getenv("TERM")) != NULL) { demo_terminfo(name); } else { - static char dumb[] = "dumb"; + static NCURSES_CONST char dumb[] = "dumb"; demo_terminfo(dumb); } } @@ -933,8 +933,8 @@ main(int argc, char *argv[]) #if NO_LEAKS free_dblist(); - if (input_name != 0) { - if (my_blob != 0) { + if (input_name != NULL) { + if (my_blob != NULL) { free(my_blob); free(my_boolcodes); free(my_numcodes); |
