/****************************************************************************
- * Copyright (c) 2016-2018,2019 Free Software Foundation, Inc. *
+ * Copyright 2018-2021,2022 Thomas E. Dickey *
+ * Copyright 2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* authorization. *
****************************************************************************/
/*
- * $Id: list_keys.c,v 1.25 2019/08/24 23:11:01 tom Exp $
+ * $Id: list_keys.c,v 1.31 2022/12/10 23:23:27 tom Exp $
*
* Author: Thomas E Dickey
*
map |= (bit1 << 1) | (bit2 >> 1);
_nc_SPRINTF(result, _nc_SLIMIT(sizeof(result))
"%sF%d", modifiers[map][(unsigned) f_opt], 1 + key);
- } else if (sscanf(name, "k%[A-Z]%d%c", buffer, &value, &chr) == 2 &&
+ } else if (sscanf(name, "k%80[A-Z]%d%c", buffer, &value, &chr) == 2 &&
(value > 1 &&
value <= 8) &&
(!strcmp(buffer, "UP") ||
!strcmp(buffer, "PRV"))) {
_nc_SPRINTF(result, _nc_SLIMIT(sizeof(result))
"%sk%s", modifiers[value - 1][(unsigned) f_opt], buffer);
- } else if (sscanf(name, "k%[A-Z]%c", buffer, &chr) == 1 &&
+ } else if (sscanf(name, "k%80[A-Z]%c", buffer, &chr) == 1 &&
(!strcmp(buffer, "UP") ||
!strcmp(buffer, "DN"))) {
_nc_SPRINTF(result, _nc_SLIMIT(sizeof(result))
}
static void
-usage(void)
+usage(int ok)
{
static const char *msg[] =
{
- "Usage: list_keys [options] [terminal [terminal2 [...]]]",
- "",
- "Print capabilities for terminal special keys.",
- "",
- "Options:",
- " -f print full names",
- " -m print modifier-column for shift/control keys",
- " -t print result as CSV table",
+ "Usage: list_keys [options] [terminal [terminal2 [...]]]"
+ ,""
+ ,"Print capabilities for terminal special keys."
+ ,""
+ ,USAGE_COMMON
+ ,"Options:"
+ ," -f print full names"
+ ," -m print modifier-column for shift/control keys"
+ ," -t print result as CSV table"
#ifdef NCURSES_VERSION
- " -x print extended capabilities",
+ ," -x print extended capabilities"
#endif
};
unsigned n;
for (n = 0; n < SIZEOF(msg); ++n) {
fprintf(stderr, "%s\n", msg[n]);
}
- ExitProgram(EXIT_FAILURE);
+ ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
}
+/* *INDENT-OFF* */
+VERSION_COMMON()
+/* *INDENT-ON* */
int
main(int argc, char *argv[])
{
- int n;
+ int ch;
TERMINAL **terms = typeCalloc(TERMINAL *, argc + 1);
- while ((n = getopt(argc, argv, "fmtx")) != -1) {
- switch (n) {
+ while ((ch = getopt(argc, argv, OPTS_COMMON "fmtx")) != -1) {
+ switch (ch) {
case 'f':
f_opt = TRUE;
break;
x_opt = TRUE;
break;
#endif
+ case OPTS_VERSION:
+ show_version(argv);
+ ExitProgram(EXIT_SUCCESS);
default:
- usage();
- break;
+ usage(ch == OPTS_USAGE);
+ /* NOTREACHED */
}
}
if (optind < argc) {
int found = 0;
int status;
+ int n;
for (n = optind; n < argc; ++n) {
setupterm((NCURSES_CONST char *) argv[n], 1, &status);
if (status > 0 && cur_term != 0) {
#else
int
-main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
+main(void)
{
printf("This program requires the terminfo arrays\n");
ExitProgram(EXIT_FAILURE);
#endif
#else /* !HAVE_TIGETSTR */
int
-main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
+main(void)
{
printf("This program requires the terminfo functions such as tigetstr\n");
ExitProgram(EXIT_FAILURE);