]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/demo_forms.c
ncurses 6.4 - patch 20230902
[ncurses.git] / test / demo_forms.c
index ea0426d0fa00a8dc52c3c2a00eb9e02675fe723c..61c4cc7200a68a5210e5795fe221ed2fc5ffd8bc 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2018-2019,2020 Thomas E. Dickey                                *
+ * Copyright 2018-2022,2023 Thomas E. Dickey                                *
  * Copyright 2003-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -27,7 +27,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: demo_forms.c,v 1.58 2020/03/21 15:57:59 tom Exp $
+ * $Id: demo_forms.c,v 1.62 2023/05/27 20:13:10 tom Exp $
  *
  * Demonstrate a variety of functions from the form library.
  * Thomas Dickey - 2003/4/26
@@ -242,7 +242,7 @@ show_insert_mode(bool insert_mode)
 #define O_SELECTABLE (O_ACTIVE | O_VISIBLE)
 
 static FIELD *
-another_field(FORM *form, FIELD *field)
+another_field(FORM *form, const FIELD *const field)
 {
     FIELD **f = form_fields(form);
     FIELD *result = 0;
@@ -556,23 +556,28 @@ demo_forms(void)
 }
 
 static void
-usage(void)
+usage(int ok)
 {
     static const char *tbl[] =
     {
        "Usage: demo_forms [options] [data file]"
        ,""
-       ," -d        make fields dynamic"
-       ," -j value  justify (1=left, 2=center, 3=right)"
-       ," -m value  set maximum size of dynamic fields"
-       ," -o value  specify number of offscreen rows in new_field()"
-       ," -t value  specify text to fill fields initially"
+       ,USAGE_COMMON
+       ,"Options:"
+       ," -d       make fields dynamic"
+       ," -j NUM   justify (1=left, 2=center, 3=right)"
+       ," -m NUM   set maximum size of dynamic fields"
+       ," -o NUM   specify number of offscreen rows in new_field()"
+       ," -t NUM   specify text to fill fields initially"
     };
     unsigned int j;
     for (j = 0; j < SIZEOF(tbl); ++j)
        fprintf(stderr, "%s\n", tbl[j]);
-    exit(EXIT_FAILURE);
+    ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
+/* *INDENT-OFF* */
+VERSION_COMMON()
+/* *INDENT-ON* */
 
 int
 main(int argc, char *argv[])
@@ -581,7 +586,7 @@ main(int argc, char *argv[])
 
     setlocale(LC_ALL, "");
 
-    while ((ch = getopt(argc, argv, "dj:m:o:t:")) != -1) {
+    while ((ch = getopt(argc, argv, OPTS_COMMON "dj:m:o:t:")) != -1) {
        switch (ch) {
        case 'd':
            d_option = TRUE;
@@ -590,7 +595,7 @@ main(int argc, char *argv[])
            j_value = atoi(optarg);
            if (j_value < NO_JUSTIFICATION
                || j_value > JUSTIFY_RIGHT)
-               usage();
+               usage(FALSE);
            break;
        case 'm':
            m_value = atoi(optarg);
@@ -601,9 +606,12 @@ main(int argc, char *argv[])
        case 't':
            t_value = optarg;
            break;
+       case OPTS_VERSION:
+           show_version(argv);
+           ExitProgram(EXIT_SUCCESS);
        default:
-           usage();
-
+           usage(ch == OPTS_USAGE);
+           /* NOTREACHED */
        }
     }
     while (optind < argc) {