]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/demo_defkey.c
ncurses 6.3 - patch 20221210
[ncurses.git] / test / demo_defkey.c
index 7835ee846484f50f4fe02280a919d3bb4ab42ac7..44d60dc936730f4c5e412c04ed0be79b9d97b76e 100644 (file)
@@ -27,7 +27,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: demo_defkey.c,v 1.32 2022/04/16 18:26:57 tom Exp $
+ * $Id: demo_defkey.c,v 1.33 2022/12/10 23:31:31 tom Exp $
  *
  * Demonstrate the define_key() function.
  * Thomas Dickey - 2002/11/23
@@ -214,14 +214,47 @@ remove_definition(WINDOW *win, int code)
     really_define_key(win, 0, code);
 }
 
+static void
+usage(int ok)
+{
+    static const char *msg[] =
+    {
+       "Usage: demo_defkey [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[])
 {
     char *fkeys[12];
     int n;
     int ch;
     WINDOW *win;
 
+    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, "");