/****************************************************************************
- * Copyright 2020,2021 Thomas E. Dickey *
+ * Copyright 2020-2021,2022 Thomas E. Dickey *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
/*
* Author: Thomas E. Dickey
*
- * $Id: test_tparm.c,v 1.17 2021/03/06 23:39:14 tom Exp $
+ * $Id: test_tparm.c,v 1.24 2022/12/10 23:23:27 tom Exp $
*
* Exercise tparm, either for all possible capabilities with fixed parameters,
* or one capability with all possible parameters.
#define USE_TINFO
#include <test.priv.h>
-static void failed(const char *) GCC_NORETURN;
+static GCC_NORETURN void failed(const char *);
static void
failed(const char *msg)
}
static void
-usage(void)
+usage(int ok)
{
static const char *msg[] =
{
- "Usage: test_tparm [options] [capability] [value1 [value2 [...]]]",
- "",
- "Use tparm/tputs for all distinct combinations of given capability.",
- "",
- "Options:",
- " -T TERM override $TERM; this may be a comma-separated list or \"-\"",
- " to read a list from standard-input",
- " -a test all combinations of parameters",
- " [value1...] forms a vector of maximum parameter-values.",
- " -p test capabilities with no parameters but having padding",
- " -r NUM repeat tests NUM times",
- " -v show values and results",
+ "Usage: test_tparm [options] [capability] [value1 [value2 [...]]]"
+ ,""
+ ,"Use tparm/tputs for all distinct combinations of given capability."
+ ,""
+ ,USAGE_COMMON
+ ,"Options:"
+ ," -T TERM override $TERM; this may be a comma-separated list or \"-\""
+ ," to read a list from standard-input"
+ ," -a test all combinations of parameters"
+ ," [value1...] forms a vector of maximum parameter-values."
+ ," -p test capabilities with no parameters but having padding"
+ ," -r NUM repeat tests NUM times"
+ ," -v show values and results"
};
unsigned n;
for (n = 0; n < SIZEOF(msg); ++n) {
fprintf(stderr, "%s\n", msg[n]);
}
- ExitProgram(EXIT_FAILURE);
+ ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
}
#define PLURAL(n) n, (n != 1) ? "s" : ""
#define COLONS(n) (n >= 1) ? ":" : ""
#define NUMFORM "%10ld"
+/* *INDENT-OFF* */
+VERSION_COMMON()
+/* *INDENT-ON* */
int
main(int argc, char *argv[])
{
+ int ch;
int n;
int r_run, t_run, n_run;
char *old_term = getenv("TERM");
if (all_caps == 0 || all_terms == 0 || num_parms == 0 || str_parms == 0)
failed("no memory");
- while ((n = getopt(argc, argv, "T:apr:v")) != -1) {
- switch (n) {
+ while ((ch = getopt(argc, argv, OPTS_COMMON "T:apr:v")) != -1) {
+ switch (ch) {
case 'T':
t_opt = optarg;
break;
case 'v':
++v_opt;
break;
+ case OPTS_VERSION:
+ show_version(argv);
+ ExitProgram(EXIT_SUCCESS);
default:
- usage();
- break;
+ usage(ch == OPTS_USAGE);
+ /* NOTREACHED */
}
}
r_opt = 1;
if (a_opt) {
- for (n = 0; n < use_parms; ++n)
+ for (n = 0; n < max_parms; ++n)
if (num_parms[n])
use_parms *= (num_parms[n] + 1);
}
all_terms[t_run]);
}
+ memset(all_parms, 0, sizeof(all_parms));
if (a_opt) {
/* for each combination of values */
- memset(all_parms, 0, sizeof(all_parms));
do {
for (n_run = 0; n_run < use_caps; ++n_run) {
test_tparm(cap_name[n_run], cap_data[n_run], all_parms);
#else /* !HAVE_TIGETSTR */
int
-main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
+main(void)
{
failed("This program requires the terminfo functions such as tigetstr");
}