]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/demo_altkeys.c
ncurses 6.3 - patch 20221210
[ncurses.git] / test / demo_altkeys.c
index e968525e6907494f32dd07677dfd8d990c91f10c..ed36b4c15e635d3925ec7ccfad9bb62cf3ead21c 100644 (file)
@@ -27,7 +27,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: demo_altkeys.c,v 1.15 2022/04/16 18:26:57 tom Exp $
+ * $Id: demo_altkeys.c,v 1.16 2022/12/10 23:31:31 tom Exp $
  *
  * Demonstrate the define_key() function.
  * Thomas Dickey - 2005/10/22
@@ -71,8 +71,28 @@ log_last_line(WINDOW *win)
     }
 }
 
+static void
+usage(int ok)
+{
+    static const char *msg[] =
+    {
+       "Usage: demo_altkeys [options]"
+       ,""
+       ,USAGE_COMMON
+    };
+    size_t n;
+
+    for (n = 0; n < SIZEOF(msg); n++)
+       fprintf(stderr, "%s\n", msg[n]);
+
+    ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
+}
+/* *INDENT-OFF* */
+VERSION_COMMON()
+/* *INDENT-ON* */
+
 int
-main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
+main(int argc, char *argv[])
 {
     int n;
     int ch;
@@ -80,6 +100,19 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
     struct timeval previous;
 #endif
 
+    while ((ch = getopt(argc, argv, OPTS_COMMON)) != -1) {
+       switch (ch) {
+       case OPTS_VERSION:
+           show_version(argv);
+           ExitProgram(EXIT_SUCCESS);
+       default:
+           usage(ch == OPTS_USAGE);
+           /* NOTREACHED */
+       }
+    }
+    if (optind < argc)
+       usage(FALSE);
+
     unlink(MY_LOGFILE);
 
     setlocale(LC_ALL, "");