]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/test_instr.c
ncurses 6.4 - patch 20240414
[ncurses.git] / test / test_instr.c
index 627db08e2f3a282710bcac09598411bc9c5fbc1f..c87bdd707212e4980797d49424de882d4cdf53e1 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2007,2010 Free Software Foundation, Inc.                   *
+ * Copyright 2020,2022 Thomas E. Dickey                                     *
+ * Copyright 2007-2010,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            *
@@ -26,7 +27,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: test_instr.c,v 1.5 2010/05/01 19:13:46 tom Exp $
+ * $Id: test_instr.c,v 1.12 2022/12/10 23:58:01 tom Exp $
  *
  * Author: Thomas E Dickey
  *
@@ -68,7 +69,7 @@ showmore(WINDOW *win, int line, char *buffer)
 }
 
 static int
-test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin)
+recursive_test(int level, char **argv, WINDOW *chrwin, WINDOW *strwin)
 {
     WINDOW *txtbox = 0;
     WINDOW *txtwin = 0;
@@ -85,6 +86,7 @@ test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin)
        return FALSE;
     }
 
+    *buffer = '\0';
     if (level > 1) {
        txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
        box(txtbox, 0, 0);
@@ -150,7 +152,7 @@ test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin)
                beep();
            break;
        case 'w':
-           test_inchs(level + 1, argv, chrwin, strwin);
+           recursive_test(level + 1, argv, chrwin, strwin);
            if (txtbox != 0) {
                touchwin(txtbox);
                wnoutrefresh(txtbox);
@@ -230,19 +232,49 @@ test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin)
     return TRUE;
 }
 
+static void
+usage(int ok)
+{
+    static const char *msg[] =
+    {
+       "Usage: test_instr [options] [file1 [...]]"
+       ,""
+       ,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, char *argv[])
 {
     WINDOW *chrbox;
     WINDOW *chrwin;
     WINDOW *strwin;
+    int ch;
+
+    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 */
+       }
+    }
 
     setlocale(LC_ALL, "");
 
-    if (argc < 2) {
-       fprintf(stderr, "usage: %s file\n", argv[0]);
-       return EXIT_FAILURE;
-    }
+    if (optind + 1 > argc)
+       usage(FALSE);
 
     initscr();
 
@@ -253,7 +285,7 @@ main(int argc, char *argv[])
     chrwin = derwin(chrbox, 2, COLS - 2, 1, 1);
     strwin = derwin(chrbox, 2, COLS - 2, 3, 1);
 
-    test_inchs(1, argv, chrwin, strwin);
+    recursive_test(optind, argv, chrwin, strwin);
 
     endwin();
     ExitProgram(EXIT_SUCCESS);