X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fdemo_termcap.c;fp=test%2Fdemo_termcap.c;h=19fd7deaa0a1b47672b0dbcb4328a0aee4f892f1;hp=347fc5bd4775433e71cf429b4e09ba7c184b4821;hb=6641601a9dd7f34deeaa978899b3730b27635afb;hpb=205ea499dbbceba5201d997fbd8b6b1f7f29bd50 diff --git a/test/demo_termcap.c b/test/demo_termcap.c index 347fc5bd..19fd7dea 100644 --- a/test/demo_termcap.c +++ b/test/demo_termcap.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019-2020,2021 Thomas E. Dickey * + * Copyright 2019-2021,2022 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.60 2021/03/20 16:05:49 tom Exp $ + * $Id: demo_termcap.c,v 1.63 2022/12/04 00:40:11 tom Exp $ * * A simple demo of the termcap interface. */ @@ -738,40 +738,45 @@ free_code_list(char **list) #endif /* USE_CODE_LISTS */ static void -usage(void) +usage(int ok) { static const char *msg[] = { - "Usage: demo_termcap [options] [terminal]", - "", - "If no options are given, print all (boolean, numeric, string)", - "capabilities for the given terminal, using short names.", - "", - "Options:", - " -a try all names, print capabilities found", - " -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.", - " -n print numeric-capabilities", - " -q quiet (prints only counts)", - " -r COUNT repeat for given count", - " -s print string-capabilities", - " -v print termcap-variables", + "Usage: demo_termcap [options] [terminal]" + ,"" + ,"If no options are given, print all (boolean, numeric, string)" + ,"capabilities for the given terminal, using short names." + ,"" + ,USAGE_COMMON + ,"Options:" + ," -a try all names, print capabilities found" + ," -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." + ," -n print numeric-capabilities" + ," -q quiet (prints only counts)" + ," -r COUNT repeat for given count" + ," -s print string-capabilities" + ," -v print termcap-variables" #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 ch; int n; char *name; bool a_opt = FALSE; @@ -783,8 +788,8 @@ main(int argc, char *argv[]) int repeat; int r_opt = 1; - while ((n = getopt(argc, argv, "abd:e:i:nqr:svxy")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "abd:e:i:nqr:svxy")) != -1) { + switch (ch) { case 'a': a_opt = TRUE; break; @@ -808,7 +813,7 @@ main(int argc, char *argv[]) break; case 'r': if ((r_opt = atoi(optarg)) <= 0) - usage(); + usage(FALSE); break; case 's': s_opt = TRUE; @@ -829,9 +834,12 @@ main(int argc, char *argv[]) break; #endif #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } }