From 6641601a9dd7f34deeaa978899b3730b27635afb Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Sun, 4 Dec 2022 01:13:58 +0000 Subject: [PATCH] ncurses 6.3 - patch 20221203 + add -h usage and -V version options to the test-programs which use getopt. + use "command -v" rather than "type" in Ada95/gen/Makefile.in to fix a portability issue (patch by Nicolas Boulenguez). + update ncurses-howto, more documentation fixes along with corrections to example programs. --- Ada95/gen/Makefile.in | 4 +- NEWS | 10 +- VERSION | 2 +- dist.mk | 4 +- doc/html/NCURSES-Programming-HOWTO.html | 803 +++++++++++------------- package/debian-mingw/changelog | 4 +- package/debian-mingw64/changelog | 4 +- package/debian/changelog | 4 +- package/mingw-ncurses.nsi | 4 +- package/mingw-ncurses.spec | 2 +- package/ncurses.spec | 2 +- package/ncursest.spec | 2 +- test/back_ground.c | 26 +- test/background.c | 26 +- test/cardfile.c | 25 +- test/color_content.c | 31 +- test/combine.c | 41 +- test/demo_forms.c | 34 +- test/demo_menus.c | 32 +- test/demo_new_pair.c | 41 +- test/demo_panels.c | 34 +- test/demo_tabs.c | 43 +- test/demo_termcap.c | 60 +- test/demo_terminfo.c | 62 +- test/ditto.c | 148 +++-- test/dots.c | 21 +- test/dots_curses.c | 21 +- test/dots_mvcur.c | 21 +- test/dots_termcap.c | 21 +- test/dots_xcurses.c | 19 +- test/echochar.c | 35 +- test/extended_color.c | 29 +- test/filter.c | 30 +- test/firework.c | 22 +- test/gdc.c | 40 +- test/hanoi.c | 23 +- test/hashtest.c | 46 +- test/ins_wide.c | 29 +- test/inserts.c | 31 +- test/key_names.c | 36 +- test/keynames.c | 36 +- test/knight.c | 23 +- test/list_keys.c | 44 +- test/ncurses.c | 54 +- test/padview.c | 27 +- test/pair_content.c | 31 +- test/picsmap.c | 52 +- test/rain.c | 19 +- test/redraw.c | 27 +- test/savescreen.c | 35 +- test/sp_tinfo.c | 34 +- test/tclock.c | 19 +- test/test.priv.h | 40 +- test/test_add_wchstr.c | 31 +- test/test_addchstr.c | 33 +- test/test_addstr.c | 31 +- test/test_addwstr.c | 31 +- test/test_arrays.c | 49 +- test/test_mouse.c | 54 +- test/test_setupterm.c | 44 +- test/test_sgr.c | 44 +- test/test_termattrs.c | 29 +- test/test_tparm.c | 48 +- test/test_vid_puts.c | 27 +- test/test_vidputs.c | 29 +- test/view.c | 27 +- test/worm.c | 25 +- test/xmas.c | 17 +- 68 files changed, 1628 insertions(+), 1204 deletions(-) diff --git a/Ada95/gen/Makefile.in b/Ada95/gen/Makefile.in index c263581c..05331374 100644 --- a/Ada95/gen/Makefile.in +++ b/Ada95/gen/Makefile.in @@ -30,7 +30,7 @@ # Author: Juergen Pfeifer, 1996 # and: Thomas E. Dickey, 1997 # -# $Id: Makefile.in,v 1.100 2022/01/15 18:20:17 tom Exp $ +# $Id: Makefile.in,v 1.101 2022/12/03 19:45:12 Nicolas.Boulenguez Exp $ # .SUFFIXES: @@ -103,7 +103,7 @@ PROG_GENERATE = ./generate$x GENERATE = $(PROG_GENERATE) '@USE_ARG_SUFFIX@' DEL_ADAMODE = sed -e '/^\-\-\ \ \-\*\-\ ada\ \-\*\-.*/d' -GNATHTML = `type -p gnathtml || type -p gnathtml.pl 2>/dev/null` +GNATHTML = `command -v gnathtml || command -v gnathtml.pl` ################################################################################ ALIB = @cf_ada_package@ diff --git a/NEWS b/NEWS index 1638dc9e..499ee67b 100644 --- a/NEWS +++ b/NEWS @@ -26,7 +26,7 @@ -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------- --- $Id: NEWS,v 1.3882 2022/11/26 23:50:16 tom Exp $ +-- $Id: NEWS,v 1.3885 2022/12/03 23:58:35 tom Exp $ ------------------------------------------------------------------------------- This is a log of changes that ncurses has gone through since Zeyd started @@ -46,6 +46,14 @@ See the AUTHORS file for the corresponding full names. Changes through 1.9.9e did not credit all contributions; it is not possible to add this information. +20221203 + + add -h usage and -V version options to the test-programs which use + getopt. + + use "command -v" rather than "type" in Ada95/gen/Makefile.in to fix + a portability issue (patch by Nicolas Boulenguez). + + update ncurses-howto, more documentation fixes along with corrections + to example programs. + 20221126 + fix an error in pathname of explain.txt (cf: 20200201). + fix an error in "@" command in test/ncurses.c F-menu (cf: 20190121). diff --git a/VERSION b/VERSION index a2a8606b..3f2f107f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5:0:10 6.3 20221126 +5:0:10 6.3 20221203 diff --git a/dist.mk b/dist.mk index 46c90fad..800d188e 100644 --- a/dist.mk +++ b/dist.mk @@ -26,7 +26,7 @@ # use or other dealings in this Software without prior written # # authorization. # ############################################################################## -# $Id: dist.mk,v 1.1514 2022/11/26 11:55:42 tom Exp $ +# $Id: dist.mk,v 1.1515 2022/12/03 11:17:39 tom Exp $ # Makefile for creating ncurses distributions. # # This only needs to be used directly as a makefile by developers, but @@ -38,7 +38,7 @@ SHELL = /bin/sh # These define the major/minor/patch versions of ncurses. NCURSES_MAJOR = 6 NCURSES_MINOR = 3 -NCURSES_PATCH = 20221126 +NCURSES_PATCH = 20221203 # We don't append the patch to the version, since this only applies to releases VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR) diff --git a/doc/html/NCURSES-Programming-HOWTO.html b/doc/html/NCURSES-Programming-HOWTO.html index 99591d58..2296cdab 100644 --- a/doc/html/NCURSES-Programming-HOWTO.html +++ b/doc/html/NCURSES-Programming-HOWTO.html @@ -36,6 +36,17 @@ + + Revision 2.0 + 2022-12-03 + Revised by: dickey + + + + Fixes for the sample + programs, Correct documentation errata. + + Revision 1.9 2005-06-20 @@ -168,7 +179,7 @@
- +

This document is intended to be an "All in One" guide for programming with ncurses and its sister libraries. We @@ -288,7 +299,7 @@

6.1. addch() class of functions
-
6.2. mvaddch(), waddch() and +
6.2. mvaddch(), waddch() and mvwaddch()
6.3. printw() class of @@ -646,7 +657,7 @@ cables. The terminals could be configured by sending a series of bytes. All the capabilities (such as moving the cursor to a new location, erasing part of the screen, scrolling the - screen, changing modes etc.) of terminals could be accessed + screen, changing modes, etc.) of terminals could be accessed through these series of bytes. These control seeuqnces are usually called escape sequences, because they start with an escape(0x1B) character. Even today, with proper emulation, we @@ -656,9 +667,7 @@

Suppose you wanted to print a line in color. Try typing this on your console.

-
-echo "^[[0;31;40mIn Color"
-
+
echo "^[[0;31;40mIn Color"

The first character is an escape character, which looks like two characters ^ and [. To be able to print it, you have to press CTRL+V and then the ESC key. All the others are @@ -666,9 +675,7 @@ echo "^[[0;31;40mIn Color" string "In Color" in red. It stays that way and to revert back to the original mode type this.

-
-echo "^[[0;37;40m"
-
+
echo "^[[0;37;40m"

Now, what do these magic characters mean? Difficult to comprehend? They might even be different for different terminals. So the designers of UNIX invented a mechanism @@ -690,14 +697,14 @@ echo "^[[0;37;40m"

You might be wondering, what the import of all this technical gibberish is. In the above scenario, every application program is supposed to query the terminfo and - perform the necessary stuff (sending control characters + perform the necessary stuff (sending control characters, etc.). It soon became difficult to manage this complexity and this gave birth to 'CURSES'. Curses is a pun on the name "cursor optimization". The Curses library forms a wrapper over working with raw terminal codes, and provides highly flexible and efficient API (Application Programming Interface). It provides functions to move the cursor, - create windows, produce colors, play with mouse etc. The + create windows, produce colors, play with mouse, etc. The application programs need not worry about the underlying terminal capabilities.

@@ -711,9 +718,9 @@ echo "^[[0;37;40m"

A detailed history of NCURSES can be found in the NEWS file from the source distribution. The current package is - maintained by Thomas Dickey. You can contact the maintainers - at Thomas Dickey. You can contact the + maintainers at bug-ncurses@gnu.org.

@@ -726,7 +733,7 @@ echo "^[[0;37;40m"

NCURSES not only creates a wrapper over terminal capabilities, but also gives a robust framework to create nice looking UI (User Interface)s in text mode. It provides - functions to create windows etc. Its sister libraries + functions to create windows, etc. Its sister libraries panel, menu and form provide an extension to the basic curses library. These libraries usually come along with curses. One can create applications that contain multiple @@ -764,34 +771,32 @@ echo "^[[0;37;40m" "ftp://ftp.gnu.org/pub/gnu/ncurses/ncurses.tar.gz" target= "_top">ftp://ftp.gnu.org/pub/gnu/ncurses/ncurses.tar.gz or any of the ftp sites mentioned in http://www.gnu.org/order/ftp.html.

+ "https://www.gnu.org/order/ftp.html" target= + "_top">https://www.gnu.org/order/ftp.html.

Read the README and INSTALL files for details on to how to install it. It usually involves the following operations.

-
-    tar zxvf ncurses<version>.tar.gz  # unzip and untar the archive
+        
    tar zxvf ncurses<version>.tar.gz  # unzip and untar the archive
     cd ncurses<version>               # cd to the directory
     ./configure                             # configure the build according to your 
                                             # environment
     make                                    # make it
     su root                                 # become root
-    make install                            # install it
-
+ make install # install it

Using the RPM

NCURSES RPM can be found and downloaded from http://rpmfind.net . - The RPM can be installed with the following command after + "https://rpmfind.net" target="_top">https://rpmfind.net + . The RPM can be installed with the following command after becoming root.

-
-    rpm -i <downloaded rpm>
-
+
    rpm -i <downloaded rpm>
@@ -816,12 +821,11 @@ echo "^[[0;37;40m"

All the programs in the document are available in zipped form here. Unzip and untar it. The directory structure looks like this.

-
-ncurses
+        
ncurses
    |
    |----> JustForFun     -- just for fun programs
    |----> basics         -- basic programs
@@ -835,13 +839,12 @@ ncurses
    |                            by Anuradha Ratnaweera)
    |----> Makefile       -- the top level Makefile
    |----> README         -- the top level README file. contains instructions
-   |----> COPYING        -- copyright notice
-
+ |----> COPYING -- copyright notice

The individual directories contain the following files.

-
-Description of files in each directory
+        
Description of files in each directory
 --------------------------------------
 JustForFun
     |
@@ -882,7 +885,7 @@ JustForFun
   menus 
     |
     |----> menu_attrib.c     -- Usage of menu attributes
-    |----> menu_item_data.c  -- Usage of item_name() etc.. functions
+    |----> menu_item_data.c  -- Usage of item_name(), etc. functions
     |----> menu_multi_column.c    -- Creates multi columnar menus
     |----> menu_scroll.c     -- Demonstrates scrolling capability of menus
     |----> menu_simple.c     -- A simple menu accessed by arrow keys
@@ -900,8 +903,7 @@ JustForFun
     |----> panel_simple.c    -- A simple panel example
 
   perl
-    |----> 01-10.pl          -- Perl equivalents of first ten example programs
-
+ |----> 01-10.pl -- Perl equivalents of first ten example programs

There is a top level Makefile included in the main directory. It builds all the files and puts the ready-to-use exes in demo/exe directory. You can also do @@ -914,9 +916,9 @@ JustForFun

If you prefer browsing individual programs, point your browser to http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/ncurses_programs/

+ "_top">https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/ncurses_programs/

All the programs are released under the same license that is used by ncurses (MIT-style). This gives you the @@ -931,7 +933,7 @@ JustForFun

1.6. Other Formats of the document

-

This howto is also availabe in various other formats on +

This howto is also available in various other formats on the tldp.org site. Here are the links to other formats of this document.

@@ -945,25 +947,25 @@ JustForFun @@ -978,8 +980,8 @@ JustForFun

If above links are broken or if you want to experiment with sgml read on.

-
-
    Get both the source and the tar,gzipped programs, available at
+          

    Get both the source and the tar,gzipped programs, available at
         http://cvsview.tldp.org/index.cgi/LDP/howto/docbook/
         NCURSES-HOWTO/NCURSES-Programming-HOWTO.sgml
         http://cvsview.tldp.org/index.cgi/LDP/howto/docbook/
@@ -1000,12 +1002,11 @@ JustForFun
         NCURSES-ONE-BIG-FILE.html
     for ps, you would use
         htmldoc --size universal -t ps --firstpage p1 -f <output file name.ps>
-        NCURSES-ONE-BIG-FILE.html
-
+ NCURSES-ONE-BIG-FILE.html

See LDP Author guide for more details. If all else - failes, mail me at ppadala@gmail.com

@@ -1135,21 +1136,19 @@ JustForFun ncurses.h in your programs. To link the program with ncurses the flag -lncurses should be added.

-
-    #include <ncurses.h>
+        
    #include <ncurses.h>
     .
     .
     .
 
-    compile and link: gcc <program file> -lncurses
-
+ compile and link: gcc <program file> -lncurses

Example 1. The Hello World !!! Program

-
-#include <ncurses.h>
+          
#include <curses.h>
 
 int main()
 {       
@@ -1160,8 +1159,7 @@ int main()
         endwin();                       /* End curses mode                */
 
         return 0;
-}
-
+}
@@ -1273,7 +1271,7 @@ int main() initscr() has to be called. There are functions which can be called after this initialization to customize our curses session. We may ask the curses system to set the terminal in - raw mode or initialize color or initialize the mouse etc.. + raw mode or initialize color or initialize the mouse, etc. Let's discuss some of the functions that are normally called immediately after initscr();

@@ -1317,7 +1315,7 @@ int main() "LITERAL">noecho() switches off echoing. The reason you might want to do this is to gain more control over echoing or to suppress unnecessary echoing while taking - input from the user through the getch() etc. functions. + input from the user through the getch(), etc. functions. Most of the interactive programs call noecho() at initialization and do the echoing of characters in a controlled manner. It gives the @@ -1333,7 +1331,7 @@ int main() keypad()

This is my favorite initialization function. It enables - the reading of function keys like F1, F2, arrow keys etc. + the reading of function keys like F1, F2, arrow keys, etc. Almost every interactive program enables this, as arrow keys are a major part of any User Interface. Do keypad(stdscr, TRUE) to enable this feature @@ -1387,8 +1385,8 @@ int main() example

-
-#include <ncurses.h>
+          
#include <curses.h>
 
 int main()
 {       int ch;
@@ -1405,7 +1403,7 @@ int main()
         if(ch == KEY_F(1))              /* Without keypad enabled this will */
                 printw("F1 Key pressed");/*  not get to us either       */
                                         /* Without noecho() some ugly escape
-                                         * charachters might have been printed
+                                         * characters might have been printed
                                          * on screen                    */
         else
         {       printw("The pressed key is ");
@@ -1418,8 +1416,7 @@ int main()
         endwin();                       /* End curses mode                */
 
         return 0;
-}
-
+}

This program is self-explanatory. But I used functions @@ -1453,17 +1450,15 @@ int main() creates a default window named stdscr which represents your 80x25 (or the size of window in which you are running) screen. If you are - doing simple tasks like printing few strings, reading input + doing simple tasks like printing few strings, reading input, etc., you can safely use this single window for all of your purposes. You can also create windows and call functions which explicitly work on the specified window.

For example, if you call

-
-    printw("Hi There !!!");
-    refresh();
-
+
    printw("Hi There !!!");
+    refresh();

It prints the string on stdscr at the present cursor position. Similarly the call to refresh(), works on stdscr only.

@@ -1472,22 +1467,19 @@ int main() you have to call a function with a 'w' added to the usual function.

-
-    wprintw(win, "Hi There !!!");
-    wrefresh(win);
-
+
    wprintw(win, "Hi There !!!");
+    wrefresh(win);

As you will see in the rest of the document, naming of functions follow the same convention. For each function there usually are three more functions.

-
-    printw(string);        /* Print on stdscr at present cursor position */
+      
    printw(string);        /* Print on stdscr at present cursor position */
     mvprintw(y, x, string);/* Move to (y, x) then print string     */
     wprintw(win, string);  /* Print on window win at present cursor position */
                            /* in the window */
     mvwprintw(win, y, x, string);   /* Move to (y, x) relative to window */
-                                    /* co-ordinates and then print         */
-
+ /* co-ordinates and then print */

Usually the w-less functions are macros which expand to corresponding w-function with stdscr as the window parameter.

@@ -1554,9 +1546,8 @@ int main() char) bold and underlined, you would call addch() as below.

-
-    addch(ch | A_BOLD | A_UNDERLINE);
-
+
    addch(ch | A_BOLD | A_UNDERLINE);
  • @@ -1574,7 +1565,7 @@ int main()

    Additionally, curses provides some special characters for character-based graphics. You can draw tables, horizontal or vertical lines, etc. You can - find all avaliable characters in the header file ncurses.h. Try looking for macros beginning with ACS_ in this file.

    @@ -1582,23 +1573,18 @@ int main()

    -

    6.2. +

    6.2. mvaddch(), waddch() and mvwaddch()

    mvaddch() is used to move the cursor to a given point, and then print. Thus, the calls:

    -
    -    move(row,col);    /* moves the cursor to rowth row and colth column */
    -    addch(ch);
    -
    can be replaced by +
        move(row,col);    /* moves the cursor to rowth row and colth column */
    +    addch(ch);
    can be replaced by -
    -    mvaddch(row,col,ch);
    -
    +
        mvaddch(row,col,ch);

    waddch() is similar to addch(), except that it adds a character into the given window. (Note that Example 3. A Simple printw example

    -
    -#include <ncurses.h>                   /* ncurses.h includes stdio.h */  
    +            
    #include <curses.h>
     #include <string.h> 
      
     int main()
     {
      char mesg[]="Just a string";           /* message to be appeared on the screen */
      int row,col;                           /* to store the number of rows and *
    -                                         * the number of colums of the screen */
    +                                         * the number of columns of the screen */
      initscr();                             /* start the curses mode */
      getmaxyx(stdscr,row,col);              /* get the number of rows and columns */
      mvprintw(row/2,(col-strlen(mesg))/2,"%s",mesg);
    @@ -1702,8 +1687,7 @@ int main()
      endwin();
     
      return 0;
    -}
    -
    +}

    Above program demonstrates how easy it is to use @@ -1879,9 +1863,8 @@ int main()

    Example 4. A Simple scanw example

    -
    -#include <ncurses.h>                   /* ncurses.h includes stdio.h */  
    +          
    #include <curses.h>
     #include <string.h> 
      
     int main()
    @@ -1889,7 +1872,7 @@ int main()
      char mesg[]="Enter a string: ";                /* message to be appeared on the screen */
      char str[80];
      int row,col;                           /* to store the number of rows and *
    -                                         * the number of colums of the screen */
    +                                         * the number of columns of the screen */
      initscr();                             /* start the curses mode */
      getmaxyx(stdscr,row,col);              /* get the number of rows and columns */
      mvprintw(row/2,(col-strlen(mesg))/2,"%s",mesg);
    @@ -1900,8 +1883,7 @@ int main()
      endwin();
     
      return 0;
    -}
    -
    +}
    @@ -1924,10 +1906,9 @@ int main()

    Example 5. A Simple Attributes example

    -
    -/* pager functionality by Joseph Spainhour" <spainhou@bellsouth.net> */
    -#include <ncurses.h>
    +        
    /* pager functionality by Joseph Spainhour" <spainhou@bellsouth.net> */
    +#include <curses.h>
     #include <stdlib.h>
     
     int main(int argc, char *argv[])
    @@ -1952,7 +1933,7 @@ int main(int argc, char *argv[])
       getmaxyx(stdscr, row, col);           /* find the boundaries of the screeen */
       while((ch = fgetc(fp)) != EOF)        /* read the file till we reach the end */
       {
    -    getyx(stdscr, y, x);                /* get the current curser position */
    +    getyx(stdscr, y, x);                /* get the current cursor position */
         if(y == (row - 1))                  /* are we are at the end of the screen */
         {
           printw("<-Press Any Key->");      /* tell the user to press a key */
    @@ -1964,7 +1945,7 @@ int main(int argc, char *argv[])
                                              * switch bold on */    
         {
           attron(A_BOLD);                   /* cut bold on */
    -      getyx(stdscr, y, x);              /* get the current curser position */
    +      getyx(stdscr, y, x);              /* get the current cursor position */
           move(y, x - 1);                   /* back up one space */
           printw("%c%c", '/', ch);          /* The actual printing is done here */
         }
    @@ -1979,8 +1960,7 @@ int main(int argc, char *argv[])
       endwin();                             /* End curses mode */
       fclose(fp);
       return 0;
    -}
    -
    +}

    Don't worry about all those initialization and other crap. @@ -2013,7 +1993,7 @@ int main(int argc, char *argv[])

    Let's get into more details of attributes. The functions attron(), attroff(), attrset() , and their sister functions attr_get() etc.. can be used to switch + "LITERAL">attr_get(), etc. can be used to switch attributes on/off , get attributes and produce a colorful display.

    @@ -2022,8 +2002,7 @@ int main(int argc, char *argv[]) following video attributes, which are defined in <curses.h> can be passed to these functions.

    -
    -    
    +        
        
         A_NORMAL        Normal display (no highlight)
         A_STANDOUT      Best highlighting mode of the terminal.
         A_UNDERLINE     Underlining
    @@ -2036,8 +2015,7 @@ int main(int argc, char *argv[])
         A_ALTCHARSET    Alternate character set
         A_CHARTEXT      Bit-mask to extract a character
         COLOR_PAIR(n)   Color-pair number n 
    -    
    -
    +

    The last one is the most colorful one :-) Colors are explained in the next sections.

    @@ -2046,9 +2024,8 @@ int main(int argc, char *argv[]) combined effect. If you wanted reverse video with blinking characters you can use

    -
    -    attron(A_REVERSE | A_BLINK);
    -
    +
        attron(A_REVERSE | A_BLINK);
    @@ -2096,8 +2073,8 @@ int main(int argc, char *argv[])

    8.4. attr_ functions

    -

    There are series of functions like attr_set(), attr_on - etc.. These are similar to above functions except that they +

    There are series of functions like attr_set(), attr_on, + etc. These are similar to above functions except that they take parameters of type attr_t.

    @@ -2130,9 +2107,8 @@ int main(int argc, char *argv[]) of line. If you want to change attributes of characters from current position to end of line, just use this.

    -
    -    chgat(-1, A_REVERSE, 0, NULL);
    -
    +
        chgat(-1, A_REVERSE, 0, NULL);

    This function is useful when changing attributes for characters that are already on the screen. Move to the character from which you want to change and change the @@ -2150,8 +2126,8 @@ int main(int argc, char *argv[])

    Example 6. Chgat() Usage example

    -
    -#include <ncurses.h>
    +          
    #include <curses.h>
     
     int main(int argc, char *argv[])
     {       initscr();                      /* Start curses mode            */
    @@ -2165,7 +2141,7 @@ int main(int argc, char *argv[])
              * Third parameter number of characters to update. -1 means till 
              * end of line
              * Forth parameter is the normal attribute you wanted to give 
    -         * to the charcter
    +         * to the character
              * Fifth is the color index. It is the index given during init_pair()
              * use 0 if you didn't want color
              * Sixth one is always NULL 
    @@ -2174,8 +2150,7 @@ int main(int argc, char *argv[])
             getch();
             endwin();                       /* End curses mode                */
             return 0;
    -}
    -
    +}

    This example also introduces us to the color world of @@ -2214,12 +2189,12 @@ int main(int argc, char *argv[]) thing on the screen actually. It allocates memory for a structure to manipulate the window and updates the structure with data regarding the window such as its size, - beginy, beginx etc. Hence in curses, a window is just an + beginy, beginx, etc. Hence in curses, a window is just an abstraction of an imaginary window, which can be manipulated independent of other parts of screen. The function newwin() returns a pointer to structure WINDOW, - which can be passed to window related functions like - wprintw() etc.. Finally the window can be destroyed with + which can be passed to window related functions such as + wprintw(), etc. Finally the window can be destroyed with delwin(). It will deallocate the memory associated with the window structure.

    @@ -2241,8 +2216,8 @@ int main(int argc, char *argv[])

    Example 7. Window Border example

    -
    -#include <ncurses.h>
    +          
    #include <curses.h>
     
     WINDOW *create_newwin(int height, int width, int starty, int startx);
     void destroy_win(WINDOW *local_win);
    @@ -2322,8 +2297,7 @@ void destroy_win(WINDOW *local_win)
              */
             wrefresh(local_win);
             delwin(local_win);
    -}
    -
    +}
    @@ -2359,21 +2333,18 @@ void destroy_win(WINDOW *local_win) the 4 corner points and the 4 lines. To put it clearly, if you have called wborder as below:

    -
    -    wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
    -
    -

    it produces some thing like

    +
        wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
    +

    it produces something like

    -
    -    +------------+
    +        
        +------------+
         |            |
         |            |
         |            |
         |            |
         |            |
         |            |
    -    +------------+
    -
    + +------------+
    @@ -2416,8 +2387,8 @@ void destroy_win(WINDOW *local_win)

    Example 8. More border functions

    -
    -#include <ncurses.h>
    +          
    #include <curses.h>
     
     typedef struct _win_border_struct {
             chtype  ls, rs, ts, bs, 
    @@ -2536,8 +2507,7 @@ void create_box(WIN *p_win, bool flag)
                                     
             refresh();
     
    -}
    -
    +}
    @@ -2560,8 +2530,10 @@ void create_box(WIN *p_win, bool flag)

    Example 9. A Simple Color example

    -
    -#include <ncurses.h>
    +          
    #include <stdlib.h>
    +#include <string.h>
    +#include <curses.h>
     
     void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string);
     int main(int argc, char *argv[])
    @@ -2600,8 +2572,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin
             mvwprintw(win, y, x, "%s", string);
             refresh();
     }
    -
    -
    +

    As you can see, to start using color, you should first @@ -2615,37 +2586,35 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin

    Curses initializes all the colors supported by terminal when start_color() is called. These can be accessed by the define constants like COLOR_BLACK - etc. Now to actually start using colors, you have to define - pairs. Colors are always used in pairs. That means you have - to use the function init_pair() to - define the foreground and background for the pair number - you give. After that that pair number can be used as a - normal attribute with COLOR_PAIR()function. This may seem to be - cumbersome at first. But this elegant solution allows us to - manage color pairs very easily. To appreciate it, you have - to look into the the source code of "dialog", a utility for - displaying dialog boxes from shell scripts. The developers - have defined foreground and background combinations for all - the colors they might need and initialized at the - beginning. This makes it very easy to set attributes just - by accessing a pair which we already have defined as a - constant.

    + , etc. Now to actually start using colors, you have to + define pairs. Colors are always used in pairs. That means + you have to use the function init_pair() to define the foreground and + background for the pair number you give. After that that + pair number can be used as a normal attribute with + COLOR_PAIR()function. This may + seem to be cumbersome at first. But this elegant solution + allows us to manage color pairs very easily. To appreciate + it, you have to look into the the source code of "dialog", + a utility for displaying dialog boxes from shell scripts. + The developers have defined foreground and background + combinations for all the colors they might need and + initialized at the beginning. This makes it very easy to + set attributes just by accessing a pair which we already + have defined as a constant.

    The following colors are defined in curses.h. You can use these as parameters for various color functions.

    -
    -        COLOR_BLACK   0
    +        
            COLOR_BLACK   0
             COLOR_RED     1
             COLOR_GREEN   2
             COLOR_YELLOW  3
             COLOR_BLUE    4
             COLOR_MAGENTA 5
             COLOR_CYAN    6
    -        COLOR_WHITE   7
    -
    + COLOR_WHITE 7
    @@ -2660,11 +2629,10 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin of red color by a minuscule. Then you can use this function as

    -
    -    init_color(COLOR_RED, 700, 0, 0);
    +        
        init_color(COLOR_RED, 700, 0, 0);
         /* param 1     : color name
    -     * param 2, 3, 4 : rgb content min = 0, max = 1000 */
    -
    + * param 2, 3, 4 : rgb content min = 0, max = 1000 */

    If your terminal cannot change the color definitions, the function returns ERR. The function can_change_color() can be used to find out @@ -2709,7 +2677,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin enabled to read keys when you are interested in reading individual key hits rather than complete lines of text (which usually end with a carriage return). keypad should - be enabled to get the Functions keys, arrow keys etc. See + be enabled to get the Functions keys, arrow keys, etc. See the initialization section for details.

    getch() returns an integer @@ -2724,11 +2692,9 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin

    For example, if you call getch() like this

    -
    -    int ch;
    +        
        int ch;
     
    -    ch = getch();
    -
    + ch = getch();

    getch() will wait for the user to press a key, (unless you specified a timeout) and when user presses a key, the corresponding integer is returned. Then you can check the @@ -2737,10 +2703,8 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin

    The following code piece will do that job.

    -
    -    if(ch == KEY_LEFT)
    -        printw("Left arrow is pressed\n");
    -
    +
        if(ch == KEY_LEFT)
    +        printw("Left arrow is pressed\n");

    Let's write a small program which creates a menu which can be navigated by up and down arrows.

    @@ -2756,9 +2720,8 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin

    Example 10. A Simple Key Usage example

    -
    -#include <stdio.h>
    -#include <ncurses.h>
    +          
    #include <curses.h>
     
     #define WIDTH 30
     #define HEIGHT 10 
    @@ -2813,7 +2776,7 @@ int main()
                                     choice = highlight;
                                     break;
                             default:
    -                                mvprintw(24, 0, "Charcter pressed is = %3d Hopefully it can be printed as '%c'", c, c);
    +                                mvprintw(24, 0, "Character pressed is = %3d Hopefully it can be printed as '%c'", c, c);
                                     refresh();
                                     break;
                     }
    @@ -2847,8 +2810,7 @@ void print_menu(WINDOW *menu_win, int highlight)
             }
             wrefresh(menu_win);
     }
    -
    -
    +
    @@ -2873,10 +2835,9 @@ void print_menu(WINDOW *menu_win, int highlight) receive have to be enabled with mousemask().

    -
    -    mousemask(  mmask_t newmask,    /* The events you want to listen to */
    -                mmask_t *oldmask)    /* The old events mask                */
    -
    +
        mousemask(  mmask_t newmask,    /* The events you want to listen to */
    +                mmask_t *oldmask)    /* The old events mask                */

    The first parameter to above function is a bit mask of events you would like to listen. By default, all the events are turned off. The bit mask The following are all the event masks:

    -
    -    Name            Description
    +        
        Name            Description
            ---------------------------------------------------------------------
            BUTTON1_PRESSED          mouse button 1 down
            BUTTON1_RELEASED         mouse button 1 up
    @@ -2912,8 +2872,7 @@ void print_menu(WINDOW *menu_win, int highlight)
            BUTTON_CTRL              control was down during button state change
            BUTTON_ALT               alt was down during button state change
            ALL_MOUSE_EVENTS         report all button state changes
    -       REPORT_MOUSE_POSITION    report mouse movement
    -
    + REPORT_MOUSE_POSITION report mouse movement
    @@ -2929,27 +2888,23 @@ void print_menu(WINDOW *menu_win, int highlight)

    The code approximately looks like this:

    -
    -    MEVENT event;
    +        
        MEVENT event;
     
         ch = getch();
         if(ch == KEY_MOUSE)
             if(getmouse(&event) == OK)
                 .    /* Do some thing with the event */
                 .
    -            .
    -
    + .

    getmouse() returns the event into the pointer given to it. It is a structure which contains

    -
    -    typedef struct
    +        
        typedef struct
         {
             short id;         /* ID to distinguish multiple devices */
             int x, y, z;      /* event coordinates */
             mmask_t bstate;   /* button state bits */
    -    }    
    -
    + }

    The bstate is the main variable we are interested in. It tells the button state of the mouse.

    @@ -2957,10 +2912,9 @@ void print_menu(WINDOW *menu_win, int highlight)

    Then with a code snippet like the following, we can find out what happened.

    -
    -    if(event.bstate & BUTTON1_PRESSED)
    -        printw("Left Button Pressed");
    -
    +
        if(event.bstate & BUTTON1_PRESSED)
    +        printw("Left Button Pressed");
    @@ -2978,8 +2932,9 @@ void print_menu(WINDOW *menu_win, int highlight)

    Example 11. Access the menu with mouse !!!

    -
    -#include <ncurses.h>
    +          
    #include <string.h>
    +#include <curses.h>
     
     #define WIDTH 30
     #define HEIGHT 10 
    @@ -3083,8 +3038,7 @@ void report_choice(int mouse_x, int mouse_y, int *p_choice)
                                     *p_choice = choice + 1; 
                             break;
                     }
    -}
    -
    +}
    @@ -3129,17 +3083,15 @@ void report_choice(int mouse_x, int mouse_y, int *p_choice) given to it. Since getyx() is a macro you don't have to pass the address of the variables. It can be called as

    -
    -    getyx(win, y, x);
    +        
        getyx(win, y, x);
         /* win: window pointer
          *   y, x: y, x co-ordinates will be put into this variables 
    -     */
    -
    + */

    The function getparyx() gets the beginning co-ordinates of the sub window relative to the main window. This is some times useful to update a sub window. When designing fancy stuff like writing multiple menus, it becomes difficult to - store the menu positions, their first option co-ordinates + store the menu positions, their first option co-ordinates, etc. A simple solution to this problem, is to create menus in sub windows and later find the starting co-ordinates of the menus by using getparyx().

    @@ -3209,11 +3161,9 @@ void report_choice(int mouse_x, int mouse_y, int *p_choice)

    This function can be used to make the cursor invisible. The parameter to this function should be

    -
    -    0 : invisible      or
    +        
        0 : invisible      or
         1 : normal    or
    -    2 : very visible.
    -
    + 2 : very visible.
    @@ -3240,8 +3190,9 @@ void report_choice(int mouse_x, int mouse_y, int *p_choice)

    Example 12. Temporarily Leaving Curses Mode

    -
    -#include <ncurses.h>
    +          
    #include <stdlib.h>
    +#include <curses.h>
     
     int main()
     {       
    @@ -3260,8 +3211,7 @@ int main()
             endwin();                       /* End curses mode                */
     
             return 0;
    -}
    -
    +}
    @@ -3277,16 +3227,16 @@ int main() box() use these characters. All these variables start with ACS meaning alternative character set. You might have noticed me using these - characters in some of the programs above. Here's an example - showing all the characters.

    + characters in some of the programs above. Here is an + example showing all the characters.

    Example 13. ACS Variables Example

    -
    -#include <ncurses.h>
    +          
    #include <curses.h>
     
     int main()
     {
    @@ -3329,8 +3279,7 @@ int main()
             endwin();
     
             return 0;
    -}
    -
    +}
    @@ -3362,7 +3311,7 @@ int main() create blotches, whenever you forget to refresh the windows in the proper order.

    -

    Don't despair. There's an elegant solution provided in +

    Don't despair. There is an elegant solution provided in panels library. In the words of developers of ncurses

    When your @@ -3395,7 +3344,7 @@ int main() to display them correctly. There is a function similar to refresh() which, when called , displays panels in the correct order. Functions are provided to hide or show - panels, move panels, change its size etc.. The overlapping + panels, move panels, change its size, etc. The overlapping problem is managed by the panels library during all the calls to these functions.

    @@ -3421,7 +3370,7 @@ int main()
  • Mainpulate the panels with show_panel(), - hide_panel(), move_panel() etc. Make use of helper + hide_panel(), move_panel(), etc. Make use of helper functions like panel_hidden() and panel_window(). Make use of user pointer to store custom data for a panel. Use the functions set_panel_userptr() and @@ -3451,21 +3400,19 @@ int main() flag -lpanel should be added along with -lncurses in that order.

    -
    -    #include <panel.h>
    +        
        #include <panel.h>
         .
         .
         .
     
    -    compile and link: gcc <program file> -lpanel -lncurses
    -
    + compile and link: gcc <program file> -lpanel -lncurses

    Example 14. Panel basics

    -
    -#include <panel.h>
    +          
    #include <panel.h>
     
     int main()
     {       WINDOW *my_wins[3];
    @@ -3502,8 +3449,7 @@ int main()
             getch();
             endwin();
     }
    -
    -
    +

    As you can see, above program follows a simple flow as @@ -3529,8 +3475,9 @@ int main()

    Example 15. Panel Window Browsing Example

    -
    -#include <panel.h>
    +          
    #include <string.h>
    +#include <panel.h>
     
     #define NLINES 10
     #define NCOLS 40
    @@ -3646,8 +3593,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin
             mvwprintw(win, y, x, "%s", string);
             wattroff(win, color);
             refresh();
    -}
    -
    +}
    @@ -3667,7 +3613,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin can be accessed using the function panel_userptr() which will return the user pointer for the panel given as argument. After finding the - next panel in the cycle It is brought to the top by the + next panel in the cycle, it is brought to the top by the function top_panel(). This function brings the panel given as argument to the top of the panel stack.

    @@ -3707,8 +3653,10 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin

    Example 16. Panel Moving and Resizing example

    -
    -#include <panel.h>
    +          
    #include <stdlib.h>
    +#include <string.h>
    +#include <panel.h>
     
     typedef struct _PANEL_DATA {
             int x, y, w, h;
    @@ -3941,8 +3889,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin
             mvwprintw(win, y, x, "%s", string);
             wattroff(win, color);
             refresh();
    -}
    -
    +}

    Concentrate on the main while loop. Once it finds out @@ -3999,8 +3946,9 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin

    Example 17. Panel Hiding and Showing example

    -
    -#include <panel.h>
    +          
    #include <string.h>
    +#include <panel.h>
     
     typedef struct _PANEL_DATA {
             int hide;       /* TRUE if panel is hidden */
    @@ -4040,7 +3988,7 @@ int main()
             my_panels[1] = new_panel(my_wins[1]);   /* Push 1, order: stdscr-0-1 */
             my_panels[2] = new_panel(my_wins[2]);   /* Push 2, order: stdscr-0-1-2 */
     
    -        /* Initialize panel datas saying that nothing is hidden */
    +        /* Initialize panel data saying that nothing is hidden */
             panel_datas[0].hide = FALSE;
             panel_datas[1].hide = FALSE;
             panel_datas[2].hide = FALSE;
    @@ -4155,8 +4103,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin
             mvwprintw(win, y, x, "%s", string);
             wattroff(win, color);
             refresh();
    -}
    -
    +}
    @@ -4184,7 +4131,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin

    The menus library provides a nice extension to basic curses, through which you can create menus. It provides a set of functions to create menus. But they have to be customized - to give a nicer look, with colors etc. Let's get into the + to give a nicer look, with colors, etc. Let's get into the details.

    A menu is a screen display that assists the user to choose @@ -4268,21 +4215,20 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin -lmenu should be added along with -lncurses in that order.

    -
    -    #include <menu.h>
    +        
        #include <menu.h>
         .
         .
         .
     
    -    compile and link: gcc <program file> -lmenu -lncurses
    -
    + compile and link: gcc <program file> -lmenu -lncurses

    Example 18. Menu Basics

    -
    -#include <curses.h>
    +          
    #include <stdlib.h>
    +#include <curses.h>
     #include <menu.h>
     
     #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
    @@ -4337,8 +4283,7 @@ int main()
             free_menu(my_menu);
             endwin();
     }
    -        
    -
    +

    This program demonstrates the basic concepts involved in @@ -4357,8 +4302,8 @@ int main()

    The menu_driver accepts following navigational requests.

    -
    -
     REQ_LEFT_ITEM         Move left to an item.
    +        
    
     REQ_LEFT_ITEM         Move left to an item.
          REQ_RIGHT_ITEM      Move right to an item.
          REQ_UP_ITEM         Move up to an item.
          REQ_DOWN_ITEM       Move down to an item.
    @@ -4374,8 +4319,7 @@ int main()
          REQ_CLEAR_PATTERN     Clear the menu pattern buffer.
          REQ_BACK_PATTERN      Delete the previous character from the pattern buffer.
          REQ_NEXT_MATCH     Move to the next item matching the pattern match.
    -     REQ_PREV_MATCH     Move to the previous item matching the pattern match.
    -
    + REQ_PREV_MATCH Move to the previous item matching the pattern match.

    Don't get overwhelmed by the number of options. We will see them slowly one after another. The options of interest in this example are REQ_UP_ITEM and REQ_DOWN_ITEM. These @@ -4487,9 +4431,9 @@ int main() mouse position an action is taken accordingly. The action to be taken is explained in the man page as,

    -
    -       If  the  second argument is the KEY_MOUSE special key, the
    +            
           If  the  second argument is the KEY_MOUSE special key, the
            associated mouse event is translated into one of the above
            pre-defined  requests.   Currently only clicks in the user
            window (e.g. inside the menu display area or  the  decora­
    @@ -4501,8 +4445,7 @@ int main()
            generated, if you doubleclick a REQ_SCR_DPAGE is generated
            and  if  you  tripleclick a REQ_LAST_ITEM is generated. If
            you click at an item inside the display area of the  menu,
    -       the menu cursor is positioned to that item.
    -
    + the menu cursor is positioned to that item.
  • @@ -4533,8 +4476,10 @@ int main()

    Example 19. Menu Windows Usage example

    -
    -#include <menu.h>
    +          
    #include <stdlib.h>
    +#include <string.h>
    +#include <menu.h>
     
     #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
     #define CTRLD   4
    @@ -4638,8 +4583,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin
             mvwprintw(win, y, x, "%s", string);
             wattroff(win, color);
             refresh();
    -}
    -
    +}

    This example creates a menu with a title, border, a @@ -4670,8 +4614,10 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin

    Example 20. Scrolling Menus example

    -
    -#include <curses.h>
    +          
    #include <stdlib.h>
    +#include <string.h>
    +#include <curses.h>
     #include <menu.h>
     
     #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
    @@ -4742,7 +4688,7 @@ int main()
             wrefresh(my_menu_win);
             
             attron(COLOR_PAIR(2));
    -        mvprintw(LINES - 2, 0, "Use PageUp and PageDown to scoll down or up a page of items");
    +        mvprintw(LINES - 2, 0, "Use PageUp and PageDown to scroll down or up a page of items");
             mvprintw(LINES - 1, 0, "Arrow Keys to navigate (F1 to Exit)");
             attroff(COLOR_PAIR(2));
             refresh();
    @@ -4794,8 +4740,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin
             mvwprintw(win, y, x, "%s", string);
             wattroff(win, color);
             refresh();
    -}
    -
    +}

    This program is self-explanatory. In this example the @@ -4831,8 +4776,9 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin

    Example 21. Milt Columnar Menus Example

    -
    -#include <curses.h>
    +          
    #include <stdlib.h>
    +#include <curses.h>
     #include <menu.h>
     
     #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
    @@ -4928,8 +4874,7 @@ int main()
             for(i = 0; i < n_choices; ++i)
                     free_item(my_items[i]);
             endwin();
    -}
    -
    +}

    Watch the function call to set_menu_format(). It @@ -4940,8 +4885,7 @@ int main() menu_opts() which can be used to manipulate menu options. The following menu options can be specified.

    -
    -       O_ONEVALUE
    +        
           O_ONEVALUE
                 Only one item can be selected for this menu.
     
            O_SHOWDESC
    @@ -4960,8 +4904,7 @@ int main()
     
            O_NONCYCLIC
                 Don't   wrap   around  next-item  and  previous-item,
    -            requests to the other end of the menu.
    -
    + requests to the other end of the menu.

    All options are on by default. You can switch specific attributes on or off with menu_opts_on() and menu_opts_off() functions. You can also use set_menu_opts() @@ -4987,8 +4930,10 @@ int main()

    Example 22. Multi Valued Menus example

    -
    -#include <curses.h>
    +          
    #include <stdlib.h>
    +#include <string.h>
    +#include <curses.h>
     #include <menu.h>
     
     #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
    @@ -5071,8 +5016,7 @@ int main()
             free_menu(my_menu);
             endwin();
     }
    -        
    -
    +

    Whew, A lot of new functions. Let's take them one after @@ -5125,8 +5069,9 @@ int main()

    Example 23. Menu Options example

    -
    -#include <menu.h>
    +          
    #include <stdlib.h>
    +#include <menu.h>
     
     #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
     #define CTRLD   4
    @@ -5205,8 +5150,7 @@ int main()
             free_menu(my_menu);
             endwin();
     }
    -        
    -
    +
    @@ -5228,8 +5172,9 @@ int main()

    Example 24. Menu User Pointer Usage

    -
    -#include <curses.h>
    +          
    #include <stdlib.h>
    +#include <curses.h>
     #include <menu.h>
     
     #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
    @@ -5315,8 +5260,7 @@ void func(char *name)
     {       move(20, 0);
             clrtoeol();
             mvprintw(20, 0, "Item selected is : %s", name);
    -}       
    -
    +}
    @@ -5334,7 +5278,7 @@ void func(char *name) plain ncurses. Forms library tries to provide a basic frame work to build and maintain forms with ease. It has lot of features(functions) which manage validation, dynamic - expansion of fields etc.. Let's see it in full flow.

    + expansion of fields, etc. Let's see it in full flow.

    A form is a collection of fields; each field can be either a label(static text) or a data-entry location. The forms also @@ -5351,13 +5295,13 @@ void func(char *name) the fields related to the form are created with new_field(). You can set options for the fields, so that they can be displayed with some fancy attributes, validated - before the field looses focus etc.. Then the fields are + before the field looses focus, etc. Then the fields are attached to form. After this, the form can be posted to display and is ready to receive inputs. On the similar lines to menu_driver(), the form is manipulated with form_driver(). We can send requests to form_driver to move focus to a certain field, move cursor to end of the field - etc.. After the user enters values in the fields and + etc. After the user enters values in the fields and validation done, form can be unposted and memory allocated can be freed.

    @@ -5425,21 +5369,19 @@ void func(char *name) -lform should be added along with -lncurses in that order.

    -
    -    #include <form.h>
    +        
        #include <form.h>
         .
         .
         .
     
    -    compile and link: gcc <program file> -lform -lncurses
    -
    + compile and link: gcc <program file> -lform -lncurses

    Example 25. Forms Basics

    -
    -#include <form.h>
    +          
    #include <form.h>
     
     int main()
     {       FIELD *field[3];
    @@ -5504,8 +5446,7 @@ int main()
     
             endwin();
             return 0;
    -}
    -
    +}

    Above example is pretty straight forward. It creates two @@ -5558,13 +5499,12 @@ int main() and number of additional buffers into the parameters given to it. It is a sort of inverse of new_field().

    -
    -int field_info(     FIELD *field,              /* field from which to fetch */
    +          
    int field_info(     FIELD *field,              /* field from which to fetch */
                         int *height, *int width,   /* field size */ 
                         int *top, int *left,       /* upper left corner */
                         int *offscreen,            /* number of offscreen rows */
    -                    int *nbuf);                /* number of working buffers */
    -
    + int *nbuf); /* number of working buffers */
    @@ -5576,10 +5516,9 @@ int field_info( FIELD *field, /* field from which to fetch */

    The location of the field can be moved to a different position with move_field().

    -
    -int move_field(    FIELD *field,              /* field to alter */
    -                   int top, int left);        /* new upper-left corner */
    -
    +
    int move_field(    FIELD *field,              /* field to alter */
    +                   int top, int left);        /* new upper-left corner */

    As usual, the changed position can be queried with field_infor().

    @@ -5593,11 +5532,10 @@ int move_field( FIELD *field, /* field to alter */

    The justification to be done for the field can be fixed using the function set_field_just().

    -
    -    int set_field_just(FIELD *field,          /* field to alter */
    +          
        int set_field_just(FIELD *field,          /* field to alter */
                    int justmode);         /* mode to set */
    -    int field_just(FIELD *field);          /* fetch justify mode of field */
    -
    + int field_just(FIELD *field); /* fetch justify mode of field */

    The justification mode valued accepted and returned by these functions are NO_JUSTIFICATION, JUSTIFY_RIGHT, JUSTIFY_LEFT, or JUSTIFY_CENTER.

    @@ -5621,8 +5559,8 @@ int move_field( FIELD *field, /* field to alter */ attributes and pad character for the field. The following list gives the usage of functions.

    -
    -
int set_field_fore(FIELD *field,        /* field to alter */
    +          
    
int set_field_fore(FIELD *field,        /* field to alter */
                        chtype attr);        /* attribute to set */ 
     
     chtype field_fore(FIELD *field);        /* field to query */
    @@ -5638,8 +5576,7 @@ int set_field_pad(FIELD *field,         /* field to alter */
                       int pad);             /* pad character to set */ 
     
     chtype field_pad(FIELD *field);         /* field to query */  
    -                                        /* returns present pad character */
    -
    + /* returns present pad character */

    Though above functions seem quite simple, using colors with set_field_fore() may be frustrating in the beginning. Let me first explain about foreground and @@ -5658,8 +5595,8 @@ chtype field_pad(FIELD *field); /* field to query */

    Example 26. Form Attributes example

    -
    -#include <form.h>
    +            
    #include <form.h>
     
     int main()
     {       FIELD *field[3];
    @@ -5733,8 +5670,7 @@ int main()
     
             endwin();
             return 0;
    -}
    -
    +}

    Play with the color pairs and try to understand the @@ -5755,8 +5691,8 @@ int main() processing. You can manipulate them with these functions:

    -
    -int set_field_opts(FIELD *field,          /* field to alter */
    +          
    int set_field_opts(FIELD *field,          /* field to alter */
                        int attr);             /* attribute to set */ 
     
     int field_opts_on(FIELD *field,           /* field to alter */
    @@ -5765,8 +5701,7 @@ int field_opts_on(FIELD *field,           /* field to alter */
     int field_opts_off(FIELD *field,          /* field to alter */
                       int attr);              /* attributes to turn off */ 
     
    -int field_opts(FIELD *field);             /* field to query */ 
    -
    +int field_opts(FIELD *field); /* field to query */

    The function set_field_opts() can be used to directly set attributes of a field or you can choose to switch a few attributes on and off with field_opts_on() and @@ -5897,8 +5832,8 @@ int field_opts(FIELD *field); /* field to query */

    Example 27. Field Options Usage example

    -
    -#include <form.h>
    +            
    #include <form.h>
     
     #define STARTX 15
     #define STARTY 4
    @@ -5973,8 +5908,7 @@ int main()
     
             endwin();
             return 0;
    -}
    -
    +}

    This example, though useless, shows the usage of @@ -5997,12 +5931,11 @@ int main() out whether it has been modified or not. The following functions can assist in those operations.

    -
    -int set_field_status(FIELD *field,      /* field to alter */
    +          
    int set_field_status(FIELD *field,      /* field to alter */
                        int status);         /* status to set */
     
    -int field_status(FIELD *field);         /* fetch status of field */
    -
    +int field_status(FIELD *field); /* fetch status of field */

    It is better to check the field's status only after after leaving the field, as data buffer might not have been updated yet as the validation is still due. To @@ -6026,13 +5959,12 @@ int field_status(FIELD *field); /* fetch status of field */ user. The following functions set and fetch user pointer.

    -
    -int set_field_userptr(FIELD *field,   
    +          
    int set_field_userptr(FIELD *field,   
                char *userptr);      /* the user pointer you wish to associate */
                                     /* with the field    */
     
    -char *field_userptr(FIELD *field);      /* fetch user pointer of the field */
    -
    +char *field_userptr(FIELD *field); /* fetch user pointer of the field */
    @@ -6053,29 +5985,26 @@ char *field_userptr(FIELD *field); /* fetch user pointer of the field */ O_STATIC should be turned off. This can be done with a

    -
    -    field_opts_off(field_pointer, O_STATIC);
    -
    +
        field_opts_off(field_pointer, O_STATIC);

    But it is usually not advisable to allow a field to grow infinitely. You can set a maximum limit to the growth of the field with

    -
    -int set_max_field(FIELD *field,    /* Field on which to operate */
    -                  int max_growth); /* maximum growth allowed for the field */
    -
    +
    int set_max_field(FIELD *field,    /* Field on which to operate */
    +                  int max_growth); /* maximum growth allowed for the field */

    The field info for a dynamically growable field can be retrieved by

    -
    -int dynamic_field_info( FIELD *field,     /* Field on which to operate */
    +          
    int dynamic_field_info( FIELD *field,     /* Field on which to operate */
                 int   *prows,     /* number of rows will be filled in this */
                 int   *pcols,     /* number of columns will be filled in this*/
                 int   *pmax)      /* maximum allowable growth will be filled */
    -                              /* in this */
    -
    Though field_info work as usual, it is advisable to use this -function to get the proper attributes of a dynamically growable -field. + /* in this */
    Though field_info +work as usual, it is advisable to use this function to get the +proper attributes of a dynamically growable field.

    Recall the library routine new_field; a new field created with height set to one will be defined to be a one line field. A new field created with height greater @@ -6198,8 +6127,9 @@ field.

    Example 28. Form Windows Example

    -
    -#include <form.h>
    +          
    #include <string.h>
    +#include <form.h>
     
     void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
     
    @@ -6310,8 +6240,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin
             mvwprintw(win, y, x, "%s", string);
             wattroff(win, color);
             refresh();
    -}
    -
    +}
    @@ -6332,15 +6261,14 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin

    Validation can be attached to a field with the following function.

    -
    -int set_field_type(FIELD *field,          /* field to alter */
    +        
    int set_field_type(FIELD *field,          /* field to alter */
                        FIELDTYPE *ftype,      /* type to associate */
    -                   ...);                  /* additional arguments*/
    -
    Once set, the validation type for a field can be queried with + ...); /* additional arguments*/
    Once +set, the validation type for a field can be queried with -
    -FIELDTYPE *field_type(FIELD *field);      /* field to query */
    -
    +
    FIELDTYPE *field_type(FIELD *field);      /* field to query */

    The form driver validates the data in a field only when data is entered by the end-user. Validation does not occur when

    @@ -6361,18 +6289,17 @@ FIELDTYPE *field_type(FIELD *field); /* field to query */ can also specify custom validation, though it is a bit tricky and cumbersome.

    -

    TYPE_ALPHA

    +

    TYPE_ALPHA

    This field type accepts alphabetic data; no blanks, no digits, no special characters (this is checked at character-entry time). It is set up with:

    -
    -int set_field_type(FIELD *field,          /* field to alter */
    +        
    int set_field_type(FIELD *field,          /* field to alter */
                        TYPE_ALPHA,            /* type to associate */
    -                   int width);            /* minimum width of field */
    -
    + int width); /* minimum width of field */

    The width argument sets a minimum width of data. The user has to enter at-least width number of characters before he can leave the field. Typically you'll want to set @@ -6380,39 +6307,37 @@ int set_field_type(FIELD *field, /* field to alter */ width, the validation check will always fail. A minimum width of zero makes field completion optional.

    -

    TYPE_ALNUM

    +

    TYPE_ALNUM

    This field type accepts alphabetic data and digits; no blanks, no special characters (this is checked at character-entry time). It is set up with:

    -
    -int set_field_type(FIELD *field,          /* field to alter */
    +        
    int set_field_type(FIELD *field,          /* field to alter */
                        TYPE_ALNUM,            /* type to associate */
    -                   int width);            /* minimum width of field */
    -
    + int width); /* minimum width of field */

    The width argument sets a minimum width of data. As with TYPE_ALPHA, typically you'll want to set this to the field width; if it is greater than the field width, the validation check will always fail. A minimum width of zero makes field completion optional.

    -

    TYPE_ENUM

    +

    TYPE_ENUM

    This type allows you to restrict a field's values to be among a specified set of string values (for example, the two-letter postal codes for U.S. states). It is set up with:

    -
    -int set_field_type(FIELD *field,          /* field to alter */
    +        
    int set_field_type(FIELD *field,          /* field to alter */
                        TYPE_ENUM,             /* type to associate */
                        char **valuelist;      /* list of possible values */
                        int checkcase;         /* case-sensitive? */
    -                   int checkunique);      /* must specify uniquely? */
    -
    + int checkunique); /* must specify uniquely? */

    The valuelist parameter must point at a NULL-terminated list of valid strings. The checkcase argument, if true, makes comparison with the string case-sensitive.

    @@ -6432,18 +6357,17 @@ int set_field_type(FIELD *field, /* field to alter */

    The REQ_NEXT_CHOICE and REQ_PREV_CHOICE input requests can be particularly useful with these fields.

    -

    TYPE_INTEGER

    +

    TYPE_INTEGER

    This field type accepts an integer. It is set up as follows:

    -
    -int set_field_type(FIELD *field,          /* field to alter */
    +        
    int set_field_type(FIELD *field,          /* field to alter */
                        TYPE_INTEGER,          /* type to associate */
                        int padding,           /* # places to zero-pad to */
    -                   int vmin, int vmax);   /* valid range */
    -
    + int vmin, int vmax); /* valid range */

    Valid characters consist of an optional leading minus and digits. The range check is performed on exit. If the range maximum is less than or equal to the minimum, the @@ -6456,18 +6380,17 @@ int set_field_type(FIELD *field, /* field to alter */

    A TYPE_INTEGER value buffer can conveniently be interpreted with the C library function atoi(3).

    -

    TYPE_NUMERIC

    +

    TYPE_NUMERIC

    This field type accepts a decimal number. It is set up as follows:

    -
    -int set_field_type(FIELD *field,          /* field to alter */
    +        
    int set_field_type(FIELD *field,          /* field to alter */
                        TYPE_NUMERIC,          /* type to associate */
                        int padding,           /* # places of precision */
    -                   int vmin, int vmax);   /* valid range */
    -
    + int vmin, int vmax); /* valid range */

    Valid characters consist of an optional leading minus and digits. possibly including a decimal point. The range check is performed on exit. If the range maximum is less @@ -6480,17 +6403,16 @@ int set_field_type(FIELD *field, /* field to alter */

    A TYPE_NUMERIC value buffer can conveniently be interpreted with the C library function atof(3).

    -

    TYPE_REGEXP

    +

    TYPE_REGEXP

    This field type accepts data matching a regular expression. It is set up as follows:

    -
    -int set_field_type(FIELD *field,          /* field to alter */
    +        
    int set_field_type(FIELD *field,          /* field to alter */
                        TYPE_REGEXP,           /* type to associate */
    -                   char *regexp);         /* expression to match */
    -
    + char *regexp); /* expression to match */

    The syntax for regular expressions is that of regcomp(3). The check for regular-expression match is performed on exit.

    @@ -6507,10 +6429,9 @@ int set_field_type(FIELD *field, /* field to alter */ important role in forms system. All types of requests to forms system should be funneled through form_driver().

    -
    -int form_driver(FORM *form,     /* form on which to operate     */
    -                int request)    /* form request code         */
    -
    +
    int form_driver(FORM *form,     /* form on which to operate     */
    +                int request)    /* form request code         */

    As you have seen some of the examples above, you have to be in a loop looking for user input and then decide whether it is a field data or a form request. The form requests are @@ -6533,10 +6454,9 @@ int form_driver(FORM *form, /* form on which to operate */ the form into pages. The function set_new_page() to set a new page at the field specified.

    -
    -int set_new_page(FIELD *field,/* Field at which page break to be set or unset */
    -         bool new_page_flag); /* should be TRUE to put a break */
    -
    +
    int set_new_page(FIELD *field,/* Field at which page break to be set or unset */
    +         bool new_page_flag); /* should be TRUE to put a break */

    The following requests allow you to move to different pages

    @@ -7107,8 +7027,8 @@ int set_new_page(FIELD *field,/* Field at which page break to be set or unset */

    The following is the list of widgets provided with cdk and their description.

    -
    -Widget Type           Quick Description
    +          
    Widget Type           Quick Description
     ===========================================================================
     Alphalist             Allows a user to select from a list of words, with
                           the ability to narrow the search list by typing in a
    @@ -7151,8 +7071,7 @@ Template              Creates a entry field with character sensitive
                           dates and phone numbers.
     Viewer                This is a file/information viewer. Very useful
                           when you need to display loads of information.
    -===========================================================================
    -
    +===========================================================================

    A few of the widgets are modified by Thomas Dickey in recent versions.

    @@ -7171,14 +7090,13 @@ Viewer This is a file/information viewer. Very useful

    If the string

    -
    -"</B/1>This line should have a yellow foreground and a blue
    -background.<!1>"
    -
    +
    "</B/1>This line should have a yellow foreground and a blue
    +background.<!1>"

    given as a parameter to newCDKLabel(), it prints the line with yellow foreground and blue background. There are other tags available for justifying string, embedding - special drawing characters etc.. Please refer to the man + special drawing characters, etc. Please refer to the man page cdk_display(3X) for details. The man page explains the usage with nice examples.

    @@ -7220,16 +7138,17 @@ background.<!1>"

    As he explains, dialog is a real gem in making professional-looking dialog boxes with ease. It creates a - variety of dialog boxes, menus, check lists etc.. It is + variety of dialog boxes, menus, check lists, etc. It is usually installed by default. If not, you can download it from Thomas Dickey's site.

    The above-mentioned article gives a very good overview - of its uses and capabilites. The man page has more details. - It can be used in variety of situations. One good example - is building of linux kernel in text mode. Linux kernel uses - a modified version of dialog tailored for its needs.

    + of its uses and capabilities. The man page has more + details. It can be used in variety of situations. One good + example is building of linux kernel in text mode. Linux + kernel uses a modified version of dialog tailored for its + needs.

    dialog was initially designed to be used with shell scripts. If you want to use its functionality in a c @@ -7297,21 +7216,19 @@ background.<!1>" "http://www.math.com/students/wonders/life/life.html" target="_top">Paul Callahan's words

    -
    -The Game of Life (or simply Life) is not a game in the conventional sense. There
    +        
    The Game of Life (or simply Life) is not a game in the conventional sense. There
     are no players, and no winning or losing. Once the "pieces" are placed in the
     starting position, the rules determine everything that happens later.
     Nevertheless, Life is full of surprises! In most cases, it is impossible to look
     at a starting position (or pattern) and see what will happen in the future. The
    -only way to find out is to follow the rules of the game.
    -
    +only way to find out is to follow the rules of the game.

    This program starts with a simple inverted U pattern and shows how wonderful life works. There is a lot of room for improvement in the program. You can let the user enter pattern of his choice or even take input from a file. You can also change rules and play with a lot of variations. - Search on google for interesting information on game of life.

    @@ -7329,7 +7246,7 @@ only way to find out is to follow the rules of the game.

    Magic Square, another wonder of math, is very simple to understand but very difficult to make. In a magic square sum of the numbers in each row, each column is equal. Even - diagnol sum can be equal. There are many variations which + diagonal sum can be equal. There are many variations which have special properties.

    This program creates a simple magic square of odd diff --git a/package/debian-mingw/changelog b/package/debian-mingw/changelog index 0aa5c537..e40862bd 100644 --- a/package/debian-mingw/changelog +++ b/package/debian-mingw/changelog @@ -1,8 +1,8 @@ -ncurses6 (6.3+20221126) unstable; urgency=low +ncurses6 (6.3+20221203) unstable; urgency=low * latest weekly patch - -- Thomas E. Dickey Sat, 26 Nov 2022 06:55:42 -0500 + -- Thomas E. Dickey Sat, 03 Dec 2022 06:17:39 -0500 ncurses6 (5.9+20131005) unstable; urgency=low diff --git a/package/debian-mingw64/changelog b/package/debian-mingw64/changelog index 0aa5c537..e40862bd 100644 --- a/package/debian-mingw64/changelog +++ b/package/debian-mingw64/changelog @@ -1,8 +1,8 @@ -ncurses6 (6.3+20221126) unstable; urgency=low +ncurses6 (6.3+20221203) unstable; urgency=low * latest weekly patch - -- Thomas E. Dickey Sat, 26 Nov 2022 06:55:42 -0500 + -- Thomas E. Dickey Sat, 03 Dec 2022 06:17:39 -0500 ncurses6 (5.9+20131005) unstable; urgency=low diff --git a/package/debian/changelog b/package/debian/changelog index 592417af..cdf2e8bb 100644 --- a/package/debian/changelog +++ b/package/debian/changelog @@ -1,8 +1,8 @@ -ncurses6 (6.3+20221126) unstable; urgency=low +ncurses6 (6.3+20221203) unstable; urgency=low * latest weekly patch - -- Thomas E. Dickey Sat, 26 Nov 2022 06:55:42 -0500 + -- Thomas E. Dickey Sat, 03 Dec 2022 06:17:39 -0500 ncurses6 (5.9+20120608) unstable; urgency=low diff --git a/package/mingw-ncurses.nsi b/package/mingw-ncurses.nsi index 7d2d5ab5..fe1570dc 100644 --- a/package/mingw-ncurses.nsi +++ b/package/mingw-ncurses.nsi @@ -1,4 +1,4 @@ -; $Id: mingw-ncurses.nsi,v 1.553 2022/11/26 11:55:42 tom Exp $ +; $Id: mingw-ncurses.nsi,v 1.554 2022/12/03 11:17:39 tom Exp $ ; TODO add examples ; TODO bump ABI to 6 @@ -10,7 +10,7 @@ !define VERSION_MAJOR "6" !define VERSION_MINOR "3" !define VERSION_YYYY "2022" -!define VERSION_MMDD "1126" +!define VERSION_MMDD "1203" !define VERSION_PATCH ${VERSION_YYYY}${VERSION_MMDD} !define MY_ABI "5" diff --git a/package/mingw-ncurses.spec b/package/mingw-ncurses.spec index 628c6137..f0a122ee 100644 --- a/package/mingw-ncurses.spec +++ b/package/mingw-ncurses.spec @@ -3,7 +3,7 @@ Summary: shared libraries for terminal handling Name: mingw32-ncurses6 Version: 6.3 -Release: 20221126 +Release: 20221203 License: X11 Group: Development/Libraries Source: ncurses-%{version}-%{release}.tgz diff --git a/package/ncurses.spec b/package/ncurses.spec index bc899a5a..01efb066 100644 --- a/package/ncurses.spec +++ b/package/ncurses.spec @@ -1,7 +1,7 @@ Summary: shared libraries for terminal handling Name: ncurses6 Version: 6.3 -Release: 20221126 +Release: 20221203 License: X11 Group: Development/Libraries Source: ncurses-%{version}-%{release}.tgz diff --git a/package/ncursest.spec b/package/ncursest.spec index 93906589..5c0e8896 100644 --- a/package/ncursest.spec +++ b/package/ncursest.spec @@ -1,7 +1,7 @@ Summary: Curses library with POSIX thread support. Name: ncursest6 Version: 6.3 -Release: 20221126 +Release: 20221203 License: X11 Group: Development/Libraries Source: ncurses-%{version}-%{release}.tgz diff --git a/test/back_ground.c b/test/back_ground.c index 10028246..295494b4 100644 --- a/test/back_ground.c +++ b/test/back_ground.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2021 Thomas E. Dickey * + * Copyright 2021,2022 Thomas E. Dickey * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: back_ground.c,v 1.5 2021/02/20 12:23:21 tom Exp $ + * $Id: back_ground.c,v 1.8 2022/12/04 00:38:34 tom Exp $ */ #include @@ -170,12 +170,13 @@ test_background(void) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: background [options]" ,"" + ,USAGE_COMMON ,"Options:" #if HAVE_ASSUME_DEFAULT_COLORS ," -a invoke assume_default_colors, repeat to use in init_pair" @@ -194,8 +195,11 @@ usage(void) 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 GCC_UNUSED, char *argv[]GCC_UNUSED) @@ -206,12 +210,12 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) #if HAVE_USE_DEFAULT_COLORS int d_option = 0; #endif - int n; + int ch; setlocale(LC_ALL, ""); - while ((n = getopt(argc, argv, "ab:df:l:wW:")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "ab:df:l:wW:")) != -1) { + switch (ch) { #if HAVE_ASSUME_DEFAULT_COLORS case 'a': ++a_option; @@ -230,7 +234,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) break; case 'l': if (!open_dump(optarg)) - usage(); + usage(FALSE); break; case 'w': wide_fill = L'\u2591'; @@ -238,8 +242,12 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) case 'W': wide_fill = decode_wchar(optarg); break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } #if HAVE_USE_DEFAULT_COLORS && HAVE_ASSUME_DEFAULT_COLORS diff --git a/test/background.c b/test/background.c index 649ffced..2811ea9c 100644 --- a/test/background.c +++ b/test/background.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2020,2021 Thomas E. Dickey * + * Copyright 2018-2021,2022 Thomas E. Dickey * * Copyright 2003-2014,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: background.c,v 1.20 2021/02/13 20:54:08 tom Exp $ + * $Id: background.c,v 1.23 2022/12/04 00:40:11 tom Exp $ */ #define NEED_COLOR_CODE 1 @@ -129,12 +129,13 @@ test_background(void) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: background [options]" ,"" + ,USAGE_COMMON ,"Options:" #if HAVE_ASSUME_DEFAULT_COLORS ," -a invoke assume_default_colors, repeat to use in init_pair" @@ -151,8 +152,11 @@ usage(void) 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 GCC_UNUSED, char *argv[]GCC_UNUSED) @@ -163,12 +167,12 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) #if HAVE_USE_DEFAULT_COLORS int d_option = 0; #endif - int n; + int ch; setlocale(LC_ALL, ""); - while ((n = getopt(argc, argv, "ab:df:l:")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "ab:df:l:")) != -1) { + switch (ch) { #if HAVE_ASSUME_DEFAULT_COLORS case 'a': ++a_option; @@ -187,10 +191,14 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) break; case 'l': if (!open_dump(optarg)) - usage(); + usage(FALSE); break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } #if HAVE_USE_DEFAULT_COLORS && HAVE_ASSUME_DEFAULT_COLORS diff --git a/test/cardfile.c b/test/cardfile.c index 78b659b3..092483b0 100644 --- a/test/cardfile.c +++ b/test/cardfile.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019-2020,2021 Thomas E. Dickey * + * Copyright 2019-2021,2022 Thomas E. Dickey * * Copyright 1999-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: cardfile.c,v 1.48 2021/03/20 18:23:14 tom Exp $ + * $Id: cardfile.c,v 1.51 2022/12/04 00:40:11 tom Exp $ * * File format: text beginning in column 1 is a title; other text is content. */ @@ -550,37 +550,45 @@ cardfile(char *fname) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: cardfile [options] file" ,"" + ,USAGE_COMMON ,"Options:" ," -c use color if terminal supports it" }; size_t 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 n; + int ch; setlocale(LC_ALL, ""); - while ((n = getopt(argc, argv, "c")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "c")) != -1) { + switch (ch) { case 'c': try_color = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } @@ -600,6 +608,7 @@ main(int argc, char *argv[]) } if (optind + 1 == argc) { + int n; for (n = 1; n < argc; n++) read_data(argv[n]); if (count_cards() == 0) diff --git a/test/color_content.c b/test/color_content.c index 99627546..f40988b8 100644 --- a/test/color_content.c +++ b/test/color_content.c @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: color_content.c,v 1.14 2022/05/21 20:00:04 tom Exp $ + * $Id: color_content.c,v 1.17 2022/12/04 00:40:11 tom Exp $ */ #define NEED_TIME_H @@ -224,12 +224,13 @@ seconds(struct timeval *mark) #endif static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: color_content [options]" ,"" + ,USAGE_COMMON ,"Options:" ," -f COLOR first color value to test (default: 0)" ," -i interactive, showing test-progress" @@ -245,26 +246,29 @@ usage(void) size_t 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 GCC_UNUSED, char *argv[]GCC_UNUSED) { - int i; + int ch; - while ((i = getopt(argc, argv, "f:il:npr:sx")) != -1) { - switch (i) { + while ((ch = getopt(argc, argv, OPTS_COMMON "f:il:npr:sx")) != -1) { + switch (ch) { case 'f': if ((f_opt = atoi(optarg)) <= 0) - usage(); + usage(FALSE); break; case 'i': i_opt = 1; break; case 'l': if ((l_opt = atoi(optarg)) <= 0) - usage(); + usage(FALSE); break; case 'n': n_opt = 1; @@ -274,7 +278,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) break; case 'r': if ((r_opt = atoi(optarg)) <= 0) - usage(); + usage(FALSE); break; case 's': s_opt = 1; @@ -284,17 +288,22 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) x_opt = 1; break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); if (r_opt <= 0) r_opt = 1; setup_test(); if (p_opt) { + int i; endwin(); for (i = 0; i < COLORS; ++i) { my_color_t r, g, b; diff --git a/test/combine.c b/test/combine.c index 7bc90974..d2c3caf9 100644 --- a/test/combine.c +++ b/test/combine.c @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: combine.c,v 1.19 2022/05/21 23:19:31 tom Exp $ + * $Id: combine.c,v 1.22 2022/12/04 00:40:11 tom Exp $ */ #include @@ -181,52 +181,59 @@ show_help(WINDOW *current) } static void -usage(void) +usage(int ok) { static const char *msg[] = { - "Usage: combine [options]", - "", - "Demonstrate combining-characters.", - "", - "Options:", - " -c use cchar_t data rather than wchar_t string", - " -l FILE log window-dumps to this file", - " -r draw even-numbered rows in reverse-video", + "Usage: combine [options]" + ,"" + ,USAGE_COMMON + ,"Demonstrate combining-characters." + ,"" + ,"Options:" + ," -c use cchar_t data rather than wchar_t string" + ," -l FILE log window-dumps to this file" + ," -r draw even-numbered rows in reverse-video" }; 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 GCC_UNUSED, char *argv[]GCC_UNUSED) { - int n; + int ch; int left_at = ' '; int over_it = 0; bool done = FALSE; bool log_option = FALSE; const char *dump_log = "combine.log"; - while ((n = getopt(argc, argv, "cl:r")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "cl:r")) != -1) { + switch (ch) { case 'c': c_opt = TRUE; break; case 'l': log_option = TRUE; if (!open_dump(optarg)) - usage(); + usage(FALSE); break; case 'r': r_opt = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } diff --git a/test/demo_forms.c b/test/demo_forms.c index ea0426d0..8e831255 100644 --- a/test/demo_forms.c +++ b/test/demo_forms.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2019,2020 Thomas E. Dickey * + * Copyright 2018-2020,2022 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.61 2022/12/04 00:40:11 tom Exp $ * * Demonstrate a variety of functions from the form library. * Thomas Dickey - 2003/4/26 @@ -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) { diff --git a/test/demo_menus.c b/test/demo_menus.c index e0e4852e..ab3880cb 100644 --- a/test/demo_menus.c +++ b/test/demo_menus.c @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: demo_menus.c,v 1.76 2022/05/15 13:54:48 tom Exp $ + * $Id: demo_menus.c,v 1.79 2022/12/04 00:40:11 tom Exp $ * * Demonstrate a variety of functions from the menu library. * Thomas Dickey - 2005/4/9 @@ -977,42 +977,46 @@ call_files(int code) } static void -usage(void) +usage(int ok) { static const char *const tbl[] = { "Usage: demo_menus [options] [menu-file]" ,"" + ,USAGE_COMMON ,"Options:" #if HAVE_RIPOFFLINE - ," -f rip-off footer line (can repeat)" - ," -h rip-off header line (can repeat)" + ," -F rip-off footer line (can repeat)" + ," -H rip-off header line (can repeat)" #endif #ifdef TRACE - ," -t mask specify default trace-level (may toggle with ^T)" + ," -t mask specify default trace-level (may toggle with ^T)" #endif }; size_t n; for (n = 0; n < SIZEOF(tbl); n++) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc, char *argv[]) { - int c; + int ch; setlocale(LC_ALL, ""); START_TRACE(); - while ((c = getopt(argc, argv, "fht:")) != -1) { - switch (c) { + while ((ch = getopt(argc, argv, OPTS_COMMON "FHt:")) != -1) { + switch (ch) { #if HAVE_RIPOFFLINE - case 'f': + case 'F': ripoffline(-1, rip_footer); break; - case 'h': + case 'H': ripoffline(1, rip_header); break; #endif /* HAVE_RIPOFFLINE */ @@ -1021,8 +1025,12 @@ main(int argc, char *argv[]) curses_trace((unsigned) strtoul(optarg, 0, 0)); break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } diff --git a/test/demo_new_pair.c b/test/demo_new_pair.c index ac0d9bf3..bc41d44d 100644 --- a/test/demo_new_pair.c +++ b/test/demo_new_pair.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2020,2021 Thomas E. Dickey * + * Copyright 2018-2021,2022 Thomas E. Dickey * * Copyright 2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: demo_new_pair.c,v 1.24 2021/02/21 01:24:06 tom Exp $ + * $Id: demo_new_pair.c,v 1.27 2022/12/04 00:40:11 tom Exp $ * * Demonstrate the alloc_pair() function. */ @@ -127,26 +127,27 @@ now(void) } static void -usage(void) +usage(int ok) { static const char *msg[] = { - "Usage: demo_new_pair [options]", - "", - "Repeatedly print using all possible color combinations.", - "", - "Options:", - " -g use getcchar to check setcchar", - " -i use init_pair rather than alloc_pair", - " -p start in paged-mode", - " -s start in single-step mode", - " -w print a wide-character cell", + "Usage: demo_new_pair [options]" + ,"" + ,"Repeatedly print using all possible color combinations." + ,"" + ,USAGE_COMMON + ,"Options:" + ," -g use getcchar to check setcchar" + ," -i use init_pair rather than alloc_pair" + ," -p start in paged-mode" + ," -s start in single-step mode" + ," -w print a wide-character cell" }; unsigned n; for (n = 0; n < SIZEOF(msg); ++n) { fprintf(stderr, "%s\n", msg[n]); } - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } #define use_pages() \ @@ -158,6 +159,9 @@ usage(void) #define update_modes() \ scrollok(stdscr, !paged_mode); \ nodelay(stdscr, !single_mode || paged_mode) +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc, char *argv[]) @@ -204,7 +208,7 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "gipsw")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "gipsw")) != -1) { switch (ch) { case 'g': check_set = TRUE; @@ -221,9 +225,12 @@ main(int argc, char *argv[]) case 'w': use_wide = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } diff --git a/test/demo_panels.c b/test/demo_panels.c index 005483e9..6c825891 100644 --- a/test/demo_panels.c +++ b/test/demo_panels.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2019,2020 Thomas E. Dickey * + * Copyright 2018-2020,2022 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_panels.c,v 1.45 2020/02/02 23:34:34 tom Exp $ + * $Id: demo_panels.c,v 1.48 2022/12/04 00:40:11 tom Exp $ * * Demonstrate a variety of functions from the panel library. */ @@ -741,39 +741,43 @@ demo_panels(InitPanel myInit, FillPanel myFill) } static void -usage(void) +usage(int ok) { static const char *const tbl[] = { "Usage: demo_panels [options]" ,"" + ,USAGE_COMMON ,"Options:" - ," -i file read commands from file" - ," -o file record commands in file" - ," -m do not use colors" + ," -i file read commands from file" + ," -o file record commands in file" + ," -m do not use colors" #if USE_WIDEC_SUPPORT - ," -w use wide-characters in panels and background" + ," -w use wide-characters in panels and background" #endif - ," -x do not enclose panels in boxes" + ," -x do not enclose panels in boxes" }; size_t n; for (n = 0; n < SIZEOF(tbl); n++) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc, char *argv[]) { - int c; + int ch; bool monochrome = FALSE; InitPanel myInit = init_panel; FillPanel myFill = fill_panel; setlocale(LC_ALL, ""); - while ((c = getopt(argc, argv, "i:o:mwx")) != -1) { - switch (c) { + while ((ch = getopt(argc, argv, OPTS_COMMON "i:o:mwx")) != -1) { + switch (ch) { case 'i': log_in = fopen(optarg, "r"); break; @@ -792,8 +796,12 @@ main(int argc, char *argv[]) case 'x': unboxed = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (unboxed) diff --git a/test/demo_tabs.c b/test/demo_tabs.c index 2fa79287..16c1ad57 100644 --- a/test/demo_tabs.c +++ b/test/demo_tabs.c @@ -29,7 +29,7 @@ /* * Author: Thomas E. Dickey * - * $Id: demo_tabs.c,v 1.7 2022/08/13 21:02:25 tom Exp $ + * $Id: demo_tabs.c,v 1.10 2022/12/04 00:40:11 tom Exp $ * * A simple demo of tabs in curses. */ @@ -38,44 +38,51 @@ #include static void -usage(void) +usage(int ok) { static const char *msg[] = { - "Usage: demo_tabs [options]", - "", - "Print a grid to test tab-stops with the curses interface", - "", - "Options:", - " -l COUNT total number of lines to show", - " -t NUM set TABSIZE variable to the given value", + "Usage: demo_tabs [options]" + ,"" + ,"Print a grid to test tab-stops with the curses interface" + ,"" + ,USAGE_COMMON + ,"Options:" + ," -l COUNT total number of lines to show" + ," -t NUM set TABSIZE variable to the given value" }; 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 tabstop; - int n, col, row, step; + int ch, col, row, step; int line_limit = -1; int curses_stops = -1; - while ((n = getopt(argc, argv, "l:t:")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "l:t:")) != -1) { + switch (ch) { case 'l': line_limit = atoi(optarg); break; case 't': curses_stops = atoi(optarg); break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } @@ -93,10 +100,10 @@ main(int argc, char *argv[]) move(row, 0); for (col = step = 0; col < COLS - 1; ++col) { if (row == 0) { - chtype ch = '-'; + chtype ct = '-'; if ((col % tabstop) == 0) - ch = '+'; - addch(ch); + ct = '+'; + addch(ct); } else if (col + 1 < row) { addch('*'); } else { 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 */ } } diff --git a/test/demo_terminfo.c b/test/demo_terminfo.c index 45cee391..5b24c607 100644 --- a/test/demo_terminfo.c +++ b/test/demo_terminfo.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019-2020,2021 Thomas E. Dickey * + * Copyright 2019-2021,2022 Thomas E. Dickey * * Copyright 2009-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_terminfo.c,v 1.52 2021/03/20 16:07:29 tom Exp $ + * $Id: demo_terminfo.c,v 1.55 2022/12/04 00:40:11 tom Exp $ * * A simple demo of the terminfo interface. */ @@ -768,49 +768,54 @@ free_code_list(char **list) #endif /* USE_CODE_LISTS */ static void -usage(void) +usage(int ok) { static const char *msg[] = { - "Usage: demo_terminfo [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", - " -f print full names", - " -i NAME terminal description to use as names for \"-a\" option", - " -n print numeric-capabilities", - " -q quiet (prints only counts)", - " -r COUNT repeat for given count", - " -s print string-capabilities", + "Usage: demo_terminfo [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" + ," -f print full names" + ," -i NAME terminal description to use as names for \"-a\" option" + ," -n print numeric-capabilities" + ," -q quiet (prints only counts)" + ," -r COUNT repeat for given count" + ," -s print string-capabilities" #ifdef NCURSES_VERSION - " -x print extended capabilities", - " -y direct-lookup names of extended capabilities", + ," -x print extended capabilities" + ," -y direct-lookup names of 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; int repeat; char *name; int r_opt = 1; char *input_name = 0; - while ((n = getopt(argc, argv, "abd:e:fi:nqr:sxy")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "abd:e:fi:nqr:sxy")) != -1) { + switch (ch) { case 'a': a_opt = TRUE; break; @@ -837,7 +842,7 @@ main(int argc, char *argv[]) break; case 'r': if ((r_opt = atoi(optarg)) <= 0) - usage(); + usage(FALSE); break; case 's': s_opt = TRUE; @@ -853,9 +858,12 @@ main(int argc, char *argv[]) x_opt = TRUE; break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } diff --git a/test/ditto.c b/test/ditto.c index fdc8611a..06b63553 100644 --- a/test/ditto.c +++ b/test/ditto.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2020,2021 Thomas E. Dickey * + * Copyright 2018-2021,2022 Thomas E. Dickey * * Copyright 1998-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 (1998-on) * - * $Id: ditto.c,v 1.52 2021/08/15 20:07:11 tom Exp $ + * $Id: ditto.c,v 1.55 2022/12/04 00:40:55 tom Exp $ * * The program illustrates how to set up multiple screens from a single * program. @@ -102,9 +102,6 @@ typedef struct { DITTO *ditto; /* data for all screens */ } DDATA; -static GCC_NORETURN void failed(const char *); -static GCC_NORETURN void usage(void); - static void failed(const char *s) { @@ -112,13 +109,6 @@ failed(const char *s) ExitProgram(EXIT_FAILURE); } -static void -usage(void) -{ - fprintf(stderr, "Usage: ditto [terminal1 ...]\n"); - ExitProgram(EXIT_FAILURE); -} - /* Add to the head of the fifo, checking for overflow. */ static void put_fifo(FIFO * fifo, int value) @@ -381,78 +371,106 @@ handle_screen(void *arg) } #endif -int -main(int argc, char *argv[]) +static void +usage(int ok) { - int j; - DITTO *data; + static const char *msg[] = + { + "Usage: ditto [terminal [terminal2 ...]]" + ,"" + ,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[]) { + int j; + int ch; + DITTO *data; #ifndef USE_PTHREADS - int count; + int count; #endif - if (argc <= 1) - usage(); + 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); - if ((data = typeCalloc(DITTO, (size_t) argc)) == 0) - failed("calloc data"); + if ((data = typeCalloc(DITTO, (size_t) argc)) == 0) + failed("calloc data"); - assert(data != 0); + assert(data != 0); - for (j = 0; j < argc; j++) { - open_screen(&data[j], argv, argc, j); - } + for (j = 0; j < argc; j++) { + open_screen(&data[j], argv, argc, j); + } #ifdef USE_PTHREADS - /* - * For multi-threaded operation, set up a reader for each of the screens. - * That uses blocking I/O rather than polling for input, so no calls to - * napms() are needed. - */ - for (j = 0; j < argc; j++) { - (void) pthread_create(&(data[j].thread), NULL, handle_screen, &data[j]); - } - pthread_join(data[1].thread, NULL); + /* + * For multi-threaded operation, set up a reader for each of the screens. + * That uses blocking I/O rather than polling for input, so no calls to + * napms() are needed. + */ + for (j = 0; j < argc; j++) { + (void) pthread_create(&(data[j].thread), NULL, handle_screen, + &data[j]); + } + pthread_join(data[1].thread, NULL); #else - /* - * Loop, reading characters from any of the inputs and writing to all - * of the screens. - */ - for (count = 0;; ++count) { - DDATA ddata; - int ch; - int which = (count % argc); + /* + * Loop, reading characters from any of the inputs and writing to all + * of the screens. + */ + for (count = 0;; ++count) { + DDATA ddata; + int which = (count % argc); - napms(20); + napms(20); - ddata.source = which; - ddata.ditto = data; + ddata.source = which; + ddata.ditto = data; - ch = USING_SCREEN(data[which].screen, read_screen, &ddata); - if (ch == CTRL('D')) { - break; - } else if (ch != ERR) { - show_ditto(data, argc, &ddata); + ch = USING_SCREEN(data[which].screen, read_screen, &ddata); + if (ch == CTRL('D')) { + break; + } else if (ch != ERR) { + show_ditto(data, argc, &ddata); + } } - } #endif - /* - * Cleanup and exit - */ - for (j = argc - 1; j >= 0; j--) { - USING_SCREEN(data[j].screen, close_screen, 0); - fprintf(data[j].output, "**Closed\r\n"); - /* - * Closing before a delscreen() helps ncurses determine that there - * is no valid output buffer, and can remove the setbuf() data. + * Cleanup and exit */ - fflush(data[j].output); - fclose(data[j].output); - delscreen(data[j].screen); + for (j = argc - 1; j >= 0; j--) { + USING_SCREEN(data[j].screen, close_screen, 0); + fprintf(data[j].output, "**Closed\r\n"); + + /* + * Closing before a delscreen() helps ncurses determine that there + * is no valid output buffer, and can remove the setbuf() data. + */ + fflush(data[j].output); + fclose(data[j].output); + delscreen(data[j].screen); + } + ExitProgram(EXIT_SUCCESS); } - ExitProgram(EXIT_SUCCESS); -} #else int main(void) diff --git a/test/dots.c b/test/dots.c index 94d90a13..8ec53f30 100644 --- a/test/dots.c +++ b/test/dots.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019,2020 Thomas E. Dickey * + * Copyright 2019-2020,2022 Thomas E. Dickey * * Copyright 1999-2013,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 1999 * - * $Id: dots.c,v 1.40 2020/05/29 23:04:02 tom Exp $ + * $Id: dots.c,v 1.43 2022/12/04 00:40:11 tom Exp $ * * A simple demo of the terminfo interface. */ @@ -111,12 +111,13 @@ get_number(NCURSES_CONST char *cap, int map) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: dots [options]" ,"" + ,USAGE_COMMON ,"Options:" ," -T TERM override $TERM" #if HAVE_USE_ENV @@ -132,8 +133,11 @@ usage(void) 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, @@ -150,7 +154,7 @@ main(int argc, size_t need; char *my_env; - while ((ch = getopt(argc, argv, "T:efm:r:s:")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "T:efm:r:s:")) != -1) { switch (ch) { case 'T': need = 6 + strlen(optarg); @@ -175,9 +179,12 @@ main(int argc, case 's': s_option = atoi(optarg); break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } diff --git a/test/dots_curses.c b/test/dots_curses.c index 95ddb931..2fb7a83c 100644 --- a/test/dots_curses.c +++ b/test/dots_curses.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2019,2020 Thomas E. Dickey * + * Copyright 2018-2020,2022 Thomas E. Dickey * * Copyright 2014,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: dots_curses.c,v 1.21 2020/08/29 16:22:03 juergen Exp $ + * $Id: dots_curses.c,v 1.24 2022/12/04 00:40:11 tom Exp $ * * A simple demo of the curses interface used for comparison with termcap. */ @@ -87,12 +87,13 @@ set_colors(int fg, int bg) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: dots_curses [options]" ,"" + ,USAGE_COMMON ,"Options:" ," -T TERM override $TERM" #if HAVE_USE_DEFAULT_COLORS @@ -110,8 +111,11 @@ usage(void) 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[]) @@ -129,7 +133,7 @@ main(int argc, char *argv[]) size_t need; char *my_env; - while ((ch = getopt(argc, argv, "T:dem:r:s:")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "T:dem:r:s:")) != -1) { switch (ch) { case 'T': need = 6 + strlen(optarg); @@ -156,9 +160,12 @@ main(int argc, char *argv[]) case 's': s_option = atoi(optarg); break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } diff --git a/test/dots_mvcur.c b/test/dots_mvcur.c index a032124c..26db2e11 100644 --- a/test/dots_mvcur.c +++ b/test/dots_mvcur.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019,2020 Thomas E. Dickey * + * Copyright 2019-2020,2022 Thomas E. Dickey * * Copyright 2007-2013,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 - 2007 * - * $Id: dots_mvcur.c,v 1.26 2020/05/29 23:04:02 tom Exp $ + * $Id: dots_mvcur.c,v 1.29 2022/12/04 00:40:11 tom Exp $ * * A simple demo of the terminfo interface, and mvcur. */ @@ -112,12 +112,13 @@ get_number(NCURSES_CONST char *cap, int map) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: dots_termcap [options]" ,"" + ,USAGE_COMMON ,"Options:" ," -T TERM override $TERM" #if HAVE_USE_ENV @@ -133,8 +134,11 @@ usage(void) 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 GCC_UNUSED, @@ -153,7 +157,7 @@ main(int argc GCC_UNUSED, size_t need; char *my_env; - while ((ch = getopt(argc, argv, "T:efm:r:s:")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "T:efm:r:s:")) != -1) { switch (ch) { case 'T': need = 6 + strlen(optarg); @@ -178,9 +182,12 @@ main(int argc GCC_UNUSED, case 's': s_option = atoi(optarg); break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } diff --git a/test/dots_termcap.c b/test/dots_termcap.c index 5e4c17d1..aa1d1988 100644 --- a/test/dots_termcap.c +++ b/test/dots_termcap.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2019,2020 Thomas E. Dickey * + * Copyright 2018-2020,2022 Thomas E. Dickey * * Copyright 2013-2014,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: dots_termcap.c,v 1.26 2020/09/05 17:58:47 juergen Exp $ + * $Id: dots_termcap.c,v 1.29 2022/12/04 00:40:11 tom Exp $ * * A simple demo of the termcap interface. */ @@ -180,12 +180,13 @@ get_number(NCURSES_CONST char *cap, const char *env) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: dots_termcap [options]" ,"" + ,USAGE_COMMON ,"Options:" ," -T TERM override $TERM" ," -e allow environment $LINES / $COLUMNS" @@ -198,8 +199,11 @@ usage(void) 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[]) @@ -220,7 +224,7 @@ main(int argc, char *argv[]) size_t need; char *my_env; - while ((ch = getopt(argc, argv, "T:em:r:s:")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "T:em:r:s:")) != -1) { switch (ch) { case 'T': need = 6 + strlen(optarg); @@ -240,9 +244,12 @@ main(int argc, char *argv[]) case 's': s_option = atoi(optarg); break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } diff --git a/test/dots_xcurses.c b/test/dots_xcurses.c index 3ccdea37..3244824a 100644 --- a/test/dots_xcurses.c +++ b/test/dots_xcurses.c @@ -30,7 +30,7 @@ /* * Author: Thomas E. Dickey * - * $Id: dots_xcurses.c,v 1.25 2022/04/16 18:27:24 tom Exp $ + * $Id: dots_xcurses.c,v 1.28 2022/12/04 00:40:11 tom Exp $ * * A simple demo of the wide-curses interface used for comparison with termcap. */ @@ -110,12 +110,13 @@ set_colors(int fg, int bg) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: dots_xcurses [options]" ,"" + ,USAGE_COMMON ,"Options:" ," -T TERM override $TERM" #if HAVE_USE_DEFAULT_COLORS @@ -136,8 +137,11 @@ usage(void) 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[]) @@ -155,7 +159,7 @@ main(int argc, char *argv[]) size_t need; char *my_env; - while ((ch = getopt(argc, argv, "T:dem:r:s:x")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "T:dem:r:s:x")) != -1) { switch (ch) { case 'T': need = 6 + strlen(optarg); @@ -187,9 +191,12 @@ main(int argc, char *argv[]) x_option = TRUE; break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } diff --git a/test/echochar.c b/test/echochar.c index ce7f03d3..0033f873 100644 --- a/test/echochar.c +++ b/test/echochar.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019,2020 Thomas E. Dickey * + * Copyright 2019-2020,2022 Thomas E. Dickey * * Copyright 2006-2014,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: echochar.c,v 1.21 2020/02/02 23:34:34 tom Exp $ + * $Id: echochar.c,v 1.24 2022/12/04 00:40:11 tom Exp $ * * Demonstrate the echochar function (compare to dots.c). * Thomas Dickey - 2006/11/4 @@ -78,6 +78,28 @@ set_color(char *my_pairs, int fg, int bg) } } +static void +usage(int ok) +{ + static const char *msg[] = + { + "Usage: echochar" + ,"" + ,USAGE_COMMON + ,"Options:" + ," -r use addch/refresh rather than echochar()" + }; + 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) @@ -91,14 +113,17 @@ main(int argc GCC_UNUSED, int last_fg = 0; int last_bg = 0; - while ((ch = getopt(argc, argv, "r")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "r")) != -1) { switch (ch) { case 'r': opt_r = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - fprintf(stderr, "Usage: echochar [-r]\n"); - ExitProgram(EXIT_FAILURE); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } diff --git a/test/extended_color.c b/test/extended_color.c index c83f8212..7f827bec 100644 --- a/test/extended_color.c +++ b/test/extended_color.c @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: extended_color.c,v 1.16 2022/04/16 18:27:24 tom Exp $ + * $Id: extended_color.c,v 1.19 2022/12/04 00:40:11 tom Exp $ */ #include @@ -139,38 +139,45 @@ show_rgb(SCREEN *sp) } static void -usage(void) +usage(int ok) { static const char *tbl[] = { - "Usage: extended_color", - "", - "Options:", - " -s use sp-funcs", - NULL + "Usage: extended_color" + ,"" + ,USAGE_COMMON + ,"Options:" + ," -s use sp-funcs" }; size_t n; for (n = 0; n < SIZEOF(tbl); ++n) { fprintf(stderr, "%s\n", tbl[n]); } - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) { + int ch; int i; SCREEN *sp; - while ((i = getopt(argc, argv, "s")) != -1) { - switch (i) { + while ((ch = getopt(argc, argv, OPTS_COMMON "s")) != -1) { + switch (ch) { #if USE_SP_FUNCS case 's': opt_s = TRUE; break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); /* NOTREACHED */ } } diff --git a/test/filter.c b/test/filter.c index 6cd9206b..b7444569 100644 --- a/test/filter.c +++ b/test/filter.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019,2020 Thomas E. Dickey * + * Copyright 2019-2020,2022 Thomas E. Dickey * * Copyright 1998-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 1998 * - * $Id: filter.c,v 1.35 2020/07/25 22:40:57 tom Exp $ + * $Id: filter.c,v 1.38 2022/12/04 00:40:11 tom Exp $ * * An example of the 'filter()' function in ncurses, this program prompts * for commands and executes them (like a command shell). It illustrates @@ -299,28 +299,32 @@ cancel_altscreen(void) #endif static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: filter [options]" ,"" + ,USAGE_COMMON ,"Options:" #ifdef NCURSES_VERSION - ," -a suppress xterm alternate-screen by amending smcup/rmcup" + ," -a suppress xterm alternate-screen by amending smcup/rmcup" #endif - ," -c show current time on prompt line with \"Command\"" + ," -c show current time on prompt line with \"Command\"" #if HAVE_USE_DEFAULT_COLORS - ," -d invoke use_default_colors" + ," -d invoke use_default_colors" #endif - ," -i use initscr() rather than newterm()" - ," -p poll for individual characters rather than using getnstr" + ," -i use initscr() rather than newterm()" + ," -p poll for individual characters rather than using getnstr" }; 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[]) @@ -340,7 +344,7 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "adcip")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "adcip")) != -1) { switch (ch) { #ifdef NCURSES_VERSION case 'a': @@ -361,8 +365,12 @@ main(int argc, char *argv[]) case 'p': p_option = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } diff --git a/test/firework.c b/test/firework.c index bfeadd7c..54e4036c 100644 --- a/test/firework.c +++ b/test/firework.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019,2020 Thomas E. Dickey * + * Copyright 2019-2020,2022 Thomas E. Dickey * * Copyright 1998-2014,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: firework.c,v 1.37 2020/02/02 23:34:34 tom Exp $ + * $Id: firework.c,v 1.40 2022/12/04 00:40:11 tom Exp $ */ #include @@ -138,12 +138,13 @@ explode(int row, int col) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: firework [options]" ,"" + ,USAGE_COMMON ,"Options:" #if HAVE_USE_DEFAULT_COLORS ," -d invoke use_default_colors, repeat to use in init_pair" @@ -154,8 +155,11 @@ usage(void) 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[]) @@ -170,19 +174,23 @@ main(int argc, char *argv[]) bool d_option = FALSE; #endif - while ((ch = getopt(argc, argv, "d")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "d")) != -1) { switch (ch) { #if HAVE_USE_DEFAULT_COLORS case 'd': d_option = TRUE; break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); InitAndCatch(initscr(), onsig); noecho(); diff --git a/test/gdc.c b/test/gdc.c index 59c95e17..7243c104 100644 --- a/test/gdc.c +++ b/test/gdc.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019,2020 Thomas E. Dickey * + * Copyright 2019-2020,2022 Thomas E. Dickey * * Copyright 1998-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -34,7 +34,7 @@ * modified 10-18-89 for curses (jrl) * 10-18-89 added signal handling * - * $Id: gdc.c,v 1.54 2020/02/02 23:34:34 tom Exp $ + * $Id: gdc.c,v 1.57 2022/12/04 00:40:11 tom Exp $ */ #include @@ -150,26 +150,27 @@ set(int t, int n) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: gdc [options] [count]" ,"" + ,USAGE_COMMON ,"Options:" #if HAVE_USE_DEFAULT_COLORS - ," -d invoke use_default_colors" + ," -d invoke use_default_colors" #endif - ," -n redirect input to /dev/null" - ," -s scroll each number into place, rather than flipping" - ," -t hh:mm:ss specify starting time (default is ``now'')" + ," -n redirect input to /dev/null" + ," -s scroll each number into place, rather than flipping" + ," -t TIME specify starting time as hh:mm:ss (default is ``now'')" ,"" ,"If you specify a count, gdc runs for that number of seconds" }; unsigned j; for (j = 0; j < SIZEOF(msg); j++) fprintf(stderr, "%s\n", msg[j]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } static time_t @@ -183,14 +184,14 @@ parse_time(const char *value) if (sscanf(value, "%d:%d:%d%c", &hh, &mm, &ss, &c) != 3) { if (sscanf(value, "%02d%02d%02d%c", &hh, &mm, &ss, &c) != 3) { - usage(); + usage(FALSE); } } if ((hh < 0) || (hh >= 24) || (mm < 0) || (mm >= 60) || (ss < 0) || (ss >= 60)) { - usage(); + usage(FALSE); } /* adjust so that the localtime in the main loop will give usable time */ @@ -204,10 +205,13 @@ parse_time(const char *value) if (tm->tm_hour != hh) { fprintf(stderr, "Cannot find local time for %s!\n", value); - usage(); + usage(FALSE); } return result; } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc, char *argv[]) @@ -215,7 +219,7 @@ main(int argc, char *argv[]) time_t now; struct tm *tm; long t, a; - int i, j, s, k; + int i, j, s, k, ch; int count = 0; FILE *ofp = stdout; FILE *ifp = stdin; @@ -228,8 +232,8 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); - while ((k = getopt(argc, argv, "dnst:")) != -1) { - switch (k) { + while ((ch = getopt(argc, argv, OPTS_COMMON "dnst:")) != -1) { + switch (ch) { #if HAVE_USE_DEFAULT_COLORS case 'd': d_option = TRUE; @@ -245,15 +249,19 @@ main(int argc, char *argv[]) case 't': starts = parse_time(optarg); break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) { count = atoi(argv[optind++]); assert(count >= 0); if (optind < argc) - usage(); + usage(FALSE); } InitAndCatch({ diff --git a/test/hanoi.c b/test/hanoi.c index 034878ab..6d92332f 100644 --- a/test/hanoi.c +++ b/test/hanoi.c @@ -42,7 +42,7 @@ * * Date: 05.Nov.90 * - * $Id: hanoi.c,v 1.44 2022/07/28 00:31:22 tom Exp $ + * $Id: hanoi.c,v 1.47 2022/12/04 00:40:11 tom Exp $ */ #include @@ -241,12 +241,13 @@ Solved(int NumTiles) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: hanoi [options] [[] [a]]" ,"" + ,USAGE_COMMON ,"Options:" #if HAVE_USE_DEFAULT_COLORS ," -d invoke use_default_colors" @@ -259,8 +260,11 @@ usage(void) 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) @@ -272,7 +276,7 @@ main(int argc, char **argv) #endif NTiles = DEFAULTTILES; - while ((ch = getopt(argc, argv, "dn:X")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "dn:X")) != -1) { switch (ch) { #if HAVE_USE_DEFAULT_COLORS case 'd': @@ -285,8 +289,11 @@ main(int argc, char **argv) case 'X': AutoFlag = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); /* NOTREACHED */ } } @@ -295,7 +302,7 @@ main(int argc, char **argv) switch (argc - optind) { case 2: if (strcmp(argv[optind + 1], "a")) { - usage(); + usage(FALSE); } AutoFlag = TRUE; /* FALLTHRU */ @@ -305,12 +312,12 @@ main(int argc, char **argv) case 0: break; default: - usage(); + usage(FALSE); } if (NTiles > MAXTILES || NTiles < MINTILES) { fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES); - usage(); + usage(FALSE); } initscr(); diff --git a/test/hashtest.c b/test/hashtest.c index 70d62287..be79c0e1 100644 --- a/test/hashtest.c +++ b/test/hashtest.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019,2020 Thomas E. Dickey * + * Copyright 2019-2020,2022 Thomas E. Dickey * * Copyright 1998-2013,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -31,7 +31,7 @@ * * Generate timing statistics for vertical-motion optimization. * - * $Id: hashtest.c,v 1.36 2020/02/02 23:34:34 tom Exp $ + * $Id: hashtest.c,v 1.39 2022/12/04 00:40:11 tom Exp $ */ #include @@ -150,49 +150,53 @@ run_test(bool optimized GCC_UNUSED) } static void -usage(void) +usage(int ok) { static const char *const tbl[] = { "Usage: hashtest [options]" ,"" + ,USAGE_COMMON ,"Options:" - ," -c continuous (don't reset between refresh's)" - ," -f num leave 'num' lines constant for footer" - ," -h num leave 'num' lines constant for header" - ," -l num repeat test 'num' times" - ," -n test the normal optimizer" - ," -o test the hashed optimizer" - ," -r reverse the loops" - ," -s single-step" - ," -x assume lower-right corner extension" + ," -c continuous (don't reset between refresh's)" + ," -F num leave 'num' lines constant for footer" + ," -H num leave 'num' lines constant for header" + ," -l num repeat test 'num' times" + ," -n test the normal optimizer" + ," -o test the hashed optimizer" + ," -r reverse the loops" + ," -s single-step" + ," -x assume lower-right corner extension" }; size_t n; for (n = 0; n < SIZEOF(tbl); n++) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc, char *argv[]) { - int c; + int ch; int test_loops = 1; int test_normal = FALSE; int test_optimize = FALSE; setlocale(LC_ALL, ""); - while ((c = getopt(argc, argv, "cf:h:l:norsx")) != -1) { - switch (c) { + while ((ch = getopt(argc, argv, OPTS_COMMON "cF:H:l:norsx")) != -1) { + switch (ch) { case 'c': continuous = TRUE; break; - case 'f': + case 'F': foot_lines = atoi(optarg); break; - case 'h': + case 'H': head_lines = atoi(optarg); break; case 'l': @@ -214,8 +218,12 @@ main(int argc, char *argv[]) case 'x': extend_corner = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (!test_normal && !test_optimize) { diff --git a/test/ins_wide.c b/test/ins_wide.c index c99b19d6..d76ae3ce 100644 --- a/test/ins_wide.c +++ b/test/ins_wide.c @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: ins_wide.c,v 1.26 2022/09/03 21:40:27 tom Exp $ + * $Id: ins_wide.c,v 1.29 2022/12/04 00:40:11 tom Exp $ * * Demonstrate the wins_wstr() and wins_wch functions. * Thomas Dickey - 2002/11/23 @@ -455,23 +455,27 @@ test_inserts(int level) } static void -usage(void) +usage(int ok) { static const char *tbl[] = { "Usage: ins_wide [options]" ,"" + ,USAGE_COMMON ,"Options:" - ," -f FILE read data from given file" - ," -n NUM limit string-inserts to NUM bytes on ^N replay" - ," -m perform wmove/move separately from insert-functions" - ," -w use window-parameter even when stdscr would be implied" + ," -f FILE read data from given file" + ," -n NUM limit string-inserts to NUM bytes on ^N replay" + ," -m perform wmove/move separately from insert-functions" + ," -w use window-parameter even when stdscr would be implied" }; unsigned n; for (n = 0; n < SIZEOF(tbl); ++n) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) @@ -480,7 +484,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "f:mn:w")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "f:mn:w")) != -1) { switch (ch) { case 'f': init_linedata(optarg); @@ -496,13 +500,16 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) case 'w': w_opt = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); test_inserts(0); endwin(); diff --git a/test/inserts.c b/test/inserts.c index 6d108cc3..33268d43 100644 --- a/test/inserts.c +++ b/test/inserts.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * Copyright 2020,2022 Thomas E. Dickey * * Copyright 2002-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: inserts.c,v 1.30 2020/02/02 23:34:34 tom Exp $ + * $Id: inserts.c,v 1.33 2022/12/04 00:40:11 tom Exp $ * * Demonstrate the winsstr() and winsch functions. * Thomas Dickey - 2002/10/19 @@ -384,23 +384,27 @@ test_inserts(int level) } static void -usage(void) +usage(int ok) { static const char *tbl[] = { "Usage: inserts [options]" ,"" + ,USAGE_COMMON ,"Options:" - ," -f FILE read data from given file" - ," -n NUM limit string-inserts to NUM bytes on ^N replay" - ," -m perform wmove/move separately from insert-functions" - ," -w use window-parameter even when stdscr would be implied" + ," -f FILE read data from given file" + ," -n NUM limit string-inserts to NUM bytes on ^N replay" + ," -m perform wmove/move separately from insert-functions" + ," -w use window-parameter even when stdscr would be implied" }; unsigned n; for (n = 0; n < SIZEOF(tbl); ++n) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) @@ -409,7 +413,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "f:mn:w")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "f:mn:w")) != -1) { switch (ch) { case 'f': init_linedata(optarg); @@ -425,13 +429,16 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) case 'w': w_opt = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); test_inserts(0); endwin(); diff --git a/test/key_names.c b/test/key_names.c index 69c95d63..fa7fdba6 100644 --- a/test/key_names.c +++ b/test/key_names.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * Copyright 2020,2022 Thomas E. Dickey * * Copyright 2007-2014,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: key_names.c,v 1.8 2020/02/02 23:34:34 tom Exp $ + * $Id: key_names.c,v 1.11 2022/12/04 00:40:11 tom Exp $ */ #include @@ -35,15 +35,32 @@ #if USE_WIDEC_SUPPORT static void -usage(void) +usage(int ok) { - fprintf(stderr, "Usage: key_names [-m] [-s]\n"); - ExitProgram(EXIT_FAILURE); + static const char *msg[] = + { + "Usage: key_names" + ,"" + ,USAGE_COMMON + ,"Options:" + ," -m call meta(TRUE) in initialization" + ," -s call newterm, etc., to complete initialization" + }; + 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[]) { + int ch; int n; bool do_setup = FALSE; @@ -51,16 +68,19 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); - while ((n = getopt(argc, argv, "ms")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "ms")) != -1) { + switch (ch) { case 'm': do_meta = TRUE; break; case 's': do_setup = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); /* NOTREACHED */ } } diff --git a/test/keynames.c b/test/keynames.c index 5a3d12a6..cae260f6 100644 --- a/test/keynames.c +++ b/test/keynames.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * Copyright 2020,2022 Thomas E. Dickey * * Copyright 1998-2006,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,37 +27,57 @@ * authorization. * ****************************************************************************/ /* - * $Id: keynames.c,v 1.10 2020/02/02 23:34:34 tom Exp $ + * $Id: keynames.c,v 1.13 2022/12/04 00:40:11 tom Exp $ */ #include static void -usage(void) +usage(int ok) { - fprintf(stderr, "Usage: keynames [-m] [-s]\n"); - ExitProgram(EXIT_FAILURE); + static const char *msg[] = + { + "Usage: keynames" + ,"" + ,USAGE_COMMON + ,"Options:" + ," -m call meta(TRUE) in initialization" + ," -s call newterm, etc., to complete initialization" + }; + 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[]) { + int ch; int n; bool do_setup = FALSE; bool do_meta = FALSE; setlocale(LC_ALL, ""); - while ((n = getopt(argc, argv, "ms")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "ms")) != -1) { + switch (ch) { case 'm': do_meta = TRUE; break; case 's': do_setup = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); /* NOTREACHED */ } } diff --git a/test/knight.c b/test/knight.c index 08ccf225..b15c4d23 100644 --- a/test/knight.c +++ b/test/knight.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2020,2021 Thomas E. Dickey * + * Copyright 2018-2021,2022 Thomas E. Dickey * * Copyright 1998-2013,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -34,7 +34,7 @@ * Eric S. Raymond July 22 1995. Mouse support * added September 20th 1995. * - * $Id: knight.c,v 1.49 2021/05/08 19:32:15 tom Exp $ + * $Id: knight.c,v 1.52 2022/12/04 00:40:11 tom Exp $ */ #include @@ -899,12 +899,13 @@ play(void) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: knight [options]" ,"" + ,USAGE_COMMON ,"Options:" #if HAVE_USE_DEFAULT_COLORS ," -d invoke use_default_colors" @@ -916,15 +917,18 @@ usage(void) 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; - while ((ch = getopt(argc, argv, "dn:")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "dn:")) != -1) { switch (ch) { #if HAVE_USE_DEFAULT_COLORS case 'd': @@ -935,17 +939,20 @@ main(int argc, char *argv[]) ch = atoi(optarg); if (ch < 3 || ch > 8) { fprintf(stderr, "board size %d is outside [3..8]\n", ch); - usage(); + usage(FALSE); } xlimit = ylimit = ch; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); init_program(); diff --git a/test/list_keys.c b/test/list_keys.c index e3077de4..8312a4b6 100644 --- a/test/list_keys.c +++ b/test/list_keys.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2020,2021 Thomas E. Dickey * + * Copyright 2018-2021,2022 Thomas E. Dickey * * Copyright 2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: list_keys.c,v 1.27 2021/03/27 23:41:21 tom Exp $ + * $Id: list_keys.c,v 1.30 2022/12/04 00:40:11 tom Exp $ * * Author: Thomas E Dickey * @@ -417,37 +417,41 @@ list_keys(TERMINAL **terms, int count) } static void -usage(void) +usage(int ok) { static const char *msg[] = { - "Usage: list_keys [options] [terminal [terminal2 [...]]]", - "", - "Print capabilities for terminal special keys.", - "", - "Options:", - " -f print full names", - " -m print modifier-column for shift/control keys", - " -t print result as CSV table", + "Usage: list_keys [options] [terminal [terminal2 [...]]]" + ,"" + ,"Print capabilities for terminal special keys." + ,"" + ,USAGE_COMMON + ,"Options:" + ," -f print full names" + ," -m print modifier-column for shift/control keys" + ," -t print result as CSV table" #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 n; + int ch; TERMINAL **terms = typeCalloc(TERMINAL *, argc + 1); - while ((n = getopt(argc, argv, "fmtx")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "fmtx")) != -1) { + switch (ch) { case 'f': f_opt = TRUE; break; @@ -462,9 +466,12 @@ main(int argc, char *argv[]) x_opt = TRUE; break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } @@ -475,6 +482,7 @@ main(int argc, char *argv[]) if (optind < argc) { int found = 0; int status; + int n; for (n = optind; n < argc; ++n) { setupterm((NCURSES_CONST char *) argv[n], 1, &status); if (status > 0 && cur_term != 0) { diff --git a/test/ncurses.c b/test/ncurses.c index b9d1831d..afa631ad 100644 --- a/test/ncurses.c +++ b/test/ncurses.c @@ -41,7 +41,7 @@ AUTHOR Author: Eric S. Raymond 1993 Thomas E. Dickey (beginning revision 1.27 in 1996). -$Id: ncurses.c,v 1.529 2022/11/26 23:16:04 tom Exp $ +$Id: ncurses.c,v 1.532 2022/12/04 00:40:11 tom Exp $ ***************************************************************************/ @@ -7639,48 +7639,49 @@ settings_test(bool recur GCC_UNUSED) ****************************************************************************/ static void -usage(void) +usage(int ok) { static const char *const tbl[] = { "Usage: ncurses [options]" ,"" + ,USAGE_COMMON ,"Options:" #ifdef NCURSES_VERSION - ," -a f,b set default-colors (assumed white-on-black)" - ," -d use default-colors if terminal supports them" + ," -a f,b set default-colors (assumed white-on-black)" + ," -d use default-colors if terminal supports them" #endif #if HAVE_USE_ENV - ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS" + ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS" #endif #if USE_SOFTKEYS - ," -e fmt specify format for soft-keys test (e)" + ," -e fmt specify format for soft-keys test (e)" #endif #if HAVE_RIPOFFLINE - ," -f rip-off footer line (can repeat)" - ," -h rip-off header line (can repeat)" + ," -F rip-off footer line (can repeat)" + ," -H rip-off header line (can repeat)" #endif - ," -m do not use colors" + ," -m do not use colors" #if HAVE_COLOR_CONTENT - ," -p file rgb values to use in 'd' rather than ncurses's builtin" + ," -p file rgb values to use in 'd' rather than ncurses's builtin" #endif #if USE_LIBPANEL - ," -s msec specify nominal time for panel-demo (default: 1, to hold)" + ," -s msec specify nominal time for panel-demo (default: 1, to hold)" #endif #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(_NC_WINDOWS) - ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment" + ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment" #endif #ifdef TRACE - ," -t mask specify default trace-level (may toggle with ^T)" + ," -t mask specify default trace-level (may toggle with ^T)" #endif #if HAVE_COLOR_CONTENT - ," -x use xterm-compatible control for reading color palette" + ," -x use xterm-compatible control for reading color palette" #endif }; size_t n; for (n = 0; n < SIZEOF(tbl); n++) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } static void @@ -7887,11 +7888,14 @@ main_menu(bool top) /*+------------------------------------------------------------------------- main(argc,argv) --------------------------------------------------------------------------*/ +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc, char *argv[]) { - int c; + int ch; int my_e_param = 1; #ifdef NCURSES_VERSION_PATCH #if HAVE_USE_DEFAULT_COLORS @@ -7911,8 +7915,8 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); - while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:x")) != -1) { - switch (c) { + while ((ch = getopt(argc, argv, OPTS_COMMON "a:dEe:FHmp:s:Tt:x")) != -1) { + switch (ch) { #ifdef NCURSES_VERSION_PATCH #if HAVE_USE_DEFAULT_COLORS #if HAVE_ASSUME_DEFAULT_COLORS @@ -7942,17 +7946,17 @@ main(int argc, char *argv[]) my_e_param = atoi(optarg); #ifdef NCURSES_VERSION if (my_e_param > 3) /* allow extended layouts */ - usage(); + usage(FALSE); #else if (my_e_param > 1) - usage(); + usage(FALSE); #endif break; #if HAVE_RIPOFFLINE - case 'f': + case 'F': ripoffline(-1, rip_footer); break; - case 'h': + case 'H': ripoffline(1, rip_header); break; #endif /* HAVE_RIPOFFLINE */ @@ -7984,8 +7988,12 @@ main(int argc, char *argv[]) xterm_colors = TRUE; break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } diff --git a/test/padview.c b/test/padview.c index 868dbfed..0defee34 100644 --- a/test/padview.c +++ b/test/padview.c @@ -29,7 +29,7 @@ /* * clone of view.c, using pads * - * $Id: padview.c,v 1.19 2022/05/15 14:36:23 tom Exp $ + * $Id: padview.c,v 1.22 2022/12/04 00:40:11 tom Exp $ */ #include @@ -56,8 +56,6 @@ static int num_lines; static bool n_option = FALSE; #endif -static GCC_NORETURN void usage(void); - static void failed(const char *msg) { @@ -250,12 +248,13 @@ read_file(const char *filename) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: view [options] file" ,"" + ,USAGE_COMMON ,"Options:" ," -c use color if terminal supports it" ," -i ignore INT, QUIT, TERM signals" @@ -271,8 +270,11 @@ usage(void) size_t 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[]) @@ -302,6 +304,7 @@ main(int argc, char *argv[]) 0 }; + int ch; int i; int my_delay = 0; WINDOW *my_pad; @@ -315,8 +318,8 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); - while ((i = getopt(argc, argv, "cinstT:")) != -1) { - switch (i) { + while ((ch = getopt(argc, argv, OPTS_COMMON "cinstT:")) != -1) { + switch (ch) { case 'c': try_color = TRUE; break; @@ -337,7 +340,7 @@ main(int argc, char *argv[]) char *next = 0; int tvalue = (int) strtol(optarg, &next, 0); if (tvalue < 0 || (next != 0 && *next != 0)) - usage(); + usage(FALSE); curses_trace((unsigned) tvalue); } break; @@ -345,12 +348,16 @@ main(int argc, char *argv[]) curses_trace(TRACE_CALLS); break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind + 1 != argc) - usage(); + usage(FALSE); InitAndCatch(initscr(), ignore_sigs ? SIG_IGN : finish); keypad(stdscr, TRUE); /* enable keyboard mapping */ diff --git a/test/pair_content.c b/test/pair_content.c index c0e0e71d..07651807 100644 --- a/test/pair_content.c +++ b/test/pair_content.c @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: pair_content.c,v 1.17 2022/05/28 20:15:06 tom Exp $ + * $Id: pair_content.c,v 1.20 2022/12/04 00:40:11 tom Exp $ */ #define NEED_TIME_H @@ -217,12 +217,13 @@ seconds(struct timeval *mark) #endif static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: pair_content [options]" ,"" + ,USAGE_COMMON ,"Options:" ," -f PAIR first color pair to test (default: 1)" ," -i interactive, showing test-progress" @@ -238,26 +239,29 @@ usage(void) size_t n; for (n = 0; n < SIZEOF(msg); n++) fprintf(stderr, "%s\n", msg[n]); - finish(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) { - int i; + int ch; - while ((i = getopt(argc, argv, "f:il:npr:sx")) != -1) { - switch (i) { + while ((ch = getopt(argc, argv, OPTS_COMMON "f:il:npr:sx")) != -1) { + switch (ch) { case 'f': if ((f_opt = atoi(optarg)) <= 0) - usage(); + usage(FALSE); break; case 'i': i_opt = 1; break; case 'l': if ((l_opt = atoi(optarg)) <= 0) - usage(); + usage(FALSE); break; case 'n': n_opt = 1; @@ -267,7 +271,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) break; case 'r': if ((r_opt = atoi(optarg)) <= 0) - usage(); + usage(FALSE); break; case 's': s_opt = 1; @@ -277,17 +281,22 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) x_opt = 1; break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); if (r_opt <= 0) r_opt = 1; setup_test(); if (p_opt) { + int i; endwin(); for (i = f_opt; i < l_opt; ++i) { my_color_t fg, bg; diff --git a/test/picsmap.c b/test/picsmap.c index bf8133a4..04bae985 100644 --- a/test/picsmap.c +++ b/test/picsmap.c @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: picsmap.c,v 1.145 2022/04/16 18:21:05 tom Exp $ + * $Id: picsmap.c,v 1.148 2022/12/04 00:40:11 tom Exp $ * * Author: Thomas E. Dickey * @@ -487,27 +487,28 @@ read_file(const char *filename) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: picsmap [options] [imagefile [...]]" ,"Read/display one or more xbm/xpm files (possibly use \"convert\")" ,"" + ,USAGE_COMMON ,"Options:" - ," -a ratio aspect-ratio correction for ImageMagick" + ," -a ratio aspect-ratio correction for ImageMagick" #if HAVE_USE_DEFAULT_COLORS - ," -d invoke use_default_colors" + ," -d invoke use_default_colors" #endif - ," -L add debugging information to logfile" - ," -l logfile write informational messages to logfile" - ," -p palette color-palette file (default \"$TERM.dat\")" - ," -q less verbose" - ," -r rgb-path xpm uses X rgb color-names (default \"" RGB_PATH "\")" - ," -s SECS pause for SECS seconds after display vs getch" + ," -L add debugging information to logfile" + ," -l FILE write informational messages to FILE" + ," -p FILE color-palette file (default \"$TERM.dat\")" + ," -q less verbose" + ," -r FILE xpm uses X rgb color-names in FILE (default \"" RGB_PATH "\")" + ," -s SECS pause for SECS seconds after display vs getch" #if USE_EXTENDED_COLORS - ," -x [pc] use extension (p=extended-pairs, c=extended-colors)" - ," Either/both extension may be given" + ," -x [pc] use extension (p=extended-pairs, c=extended-colors)" + ," Either/both extension may be given" #endif }; size_t n; @@ -517,7 +518,7 @@ usage(void) fflush(stdout); for (n = 0; n < SIZEOF(msg); n++) fprintf(stderr, "%s\n", msg[n]); - cleanup(EXIT_FAILURE); + cleanup(ok ? EXIT_SUCCESS : EXIT_FAILURE); } static void @@ -541,7 +542,7 @@ giveup(const char *fmt, ...) fflush(logfp); } - usage(); + usage(FALSE); } /* @@ -1723,24 +1724,27 @@ report_colors(PICS_HEAD * pics) } } } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc, char *argv[]) { - int n; + int ch; int opt_d = FALSE; char ignore_ch; const char *palette_path = 0; const char *rgb_path = RGB_PATH; - while ((n = getopt(argc, argv, "a:dLl:p:qr:s:x:")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "a:dLl:p:qr:s:x:")) != -1) { + switch (ch) { case 'a': if (sscanf(optarg, "%lf%c", &aspect_ratio, &ignore_ch) != 1 || aspect_ratio < 0.1 || aspect_ratio > 10.) { fprintf(stderr, "Expected a number in [0.1 to 10.]: %s\n", optarg); - usage(); + usage(FALSE); } break; #if HAVE_USE_DEFAULT_COLORS @@ -1780,21 +1784,25 @@ main(int argc, char *argv[]) use_extended_colors = TRUE; break; default: - usage(); + usage(FALSE); break; } } } break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) { char **rgb_data = read_file(rgb_path); + int n; if (rgb_data) rgb_table = parse_rgb(rgb_data); @@ -1827,7 +1835,7 @@ main(int argc, char *argv[]) free(rgb_table); free(all_colors); } else { - usage(); + usage(FALSE); } cleanup(EXIT_SUCCESS); diff --git a/test/rain.c b/test/rain.c index dde411b2..1b1d81a0 100644 --- a/test/rain.c +++ b/test/rain.c @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: rain.c,v 1.54 2022/07/23 22:47:38 tom Exp $ + * $Id: rain.c,v 1.57 2022/12/04 00:40:11 tom Exp $ */ #include #include @@ -302,12 +302,13 @@ get_input(void) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: rain [options]" ,"" + ,USAGE_COMMON ,"Options:" #if HAVE_USE_DEFAULT_COLORS ," -d invoke use_default_colors" @@ -318,8 +319,11 @@ usage(void) 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[]) @@ -345,20 +349,23 @@ main(int argc, char *argv[]) bool d_option = FALSE; #endif - while ((ch = getopt(argc, argv, "d")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "d")) != -1) { switch (ch) { #if HAVE_USE_DEFAULT_COLORS case 'd': d_option = TRUE; break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); setlocale(LC_ALL, ""); diff --git a/test/redraw.c b/test/redraw.c index b0840fb8..776efe97 100644 --- a/test/redraw.c +++ b/test/redraw.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020,2021 Thomas E. Dickey * + * Copyright 2020-2021,2022 Thomas E. Dickey * * Copyright 2006-2012,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: redraw.c,v 1.13 2021/06/17 21:26:02 tom Exp $ + * $Id: redraw.c,v 1.16 2022/12/04 00:40:11 tom Exp $ * * Demonstrate the redrawwin() and wredrawln() functions. * Thomas Dickey - 2006/11/4 @@ -189,21 +189,25 @@ test_redraw(WINDOW *win) } static void -usage(void) +usage(int ok) { static const char *tbl[] = { "Usage: redraw [options]" ,"" + ,USAGE_COMMON ,"Options:" - ," -e use stderr (default stdout)" - ," -n do not initialize terminal" + ," -e use stderr (default stdout)" + ," -n do not initialize terminal" }; unsigned n; for (n = 0; n < SIZEOF(tbl); ++n) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) @@ -212,7 +216,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) bool no_init = FALSE; FILE *my_fp = stdout; - while ((ch = getopt(argc, argv, "en")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "en")) != -1) { switch (ch) { case 'e': my_fp = stderr; @@ -220,13 +224,16 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) case 'n': no_init = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); if (no_init) { START_TRACE(); diff --git a/test/savescreen.c b/test/savescreen.c index 4c767a52..50e54540 100644 --- a/test/savescreen.c +++ b/test/savescreen.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2020,2021 Thomas E. Dickey * + * Copyright 2018-2021,2022 Thomas E. Dickey * * Copyright 2006-2017,2018 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: savescreen.c,v 1.58 2021/03/27 23:41:21 tom Exp $ + * $Id: savescreen.c,v 1.61 2022/12/04 00:40:11 tom Exp $ * * Demonstrate save/restore functions from the curses library. * Thomas Dickey - 2007/7/14 @@ -253,24 +253,28 @@ replay_help(void) } static void -usage(void) +usage(int ok) { static const char *msg[] = { - "Usage: savescreen [-r] files", - "", - "Options:", - " -f file fill/initialize screen using text from this file", - " -i use scr_init/scr_restore rather than scr_set", - " -k keep the restored dump-files rather than removing them", - " -r replay the screen-dump files" + "Usage: savescreen [-r] files" + ,"" + ,USAGE_COMMON + ,"Options:" + ," -f file fill/initialize screen using text from this file" + ," -i use scr_init/scr_restore rather than scr_set" + ," -k keep the restored dump-files rather than removing them" + ," -r replay the screen-dump files" }; 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[]) @@ -291,7 +295,7 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "f:ikr")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "f:ikr")) != -1) { switch (ch) { case 'f': fill_by = optarg; @@ -305,9 +309,12 @@ main(int argc, char *argv[]) case 'r': replaying = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } diff --git a/test/sp_tinfo.c b/test/sp_tinfo.c index 593a24b1..68c88e6e 100644 --- a/test/sp_tinfo.c +++ b/test/sp_tinfo.c @@ -28,7 +28,7 @@ ****************************************************************************/ /* - * $Id: sp_tinfo.c,v 1.24 2022/04/09 22:56:28 tom Exp $ + * $Id: sp_tinfo.c,v 1.27 2022/12/04 00:40:11 tom Exp $ * * TOTO: add option for non-sp-funcs interface */ @@ -283,41 +283,47 @@ cleanup(MYDATA * data) } static void -usage(void) +usage(int ok) { static const char *tbl[] = { - "Usage: sp_tinfo [output] [error]", - "", - "Options:", - " -n suppress call to new_prescr()", - " -t use termcap functions rather than terminfo", - NULL + "Usage: sp_tinfo [output] [error]" + ,"" + ,USAGE_COMMON + ,"Options:" + ," -n suppress call to new_prescr()" + ," -t use termcap functions rather than terminfo" }; size_t n; for (n = 0; n < SIZEOF(tbl); ++n) { fprintf(stderr, "%s\n", tbl[n]); } - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc, char *argv[]) { MYDATA *my_out; MYDATA *my_err; - int n; + int ch; - while ((n = getopt(argc, argv, "nt")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "nt")) != -1) { + switch (ch) { case 'n': opt_n = TRUE; break; case 't': opt_t = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); /* NOTREACHED */ } } @@ -325,7 +331,7 @@ main(int argc, char *argv[]) argc -= (optind - 1); if (argc > 3) - usage(); + usage(FALSE); my_out = initialize((argc > 1) ? argv[1] : "vt100", stdout); my_err = initialize((argc > 2) ? argv[2] : "ansi", stderr); diff --git a/test/tclock.c b/test/tclock.c index 23ceb6bf..0773b3b7 100644 --- a/test/tclock.c +++ b/test/tclock.c @@ -1,4 +1,4 @@ -/* $Id: tclock.c,v 1.43 2022/07/27 19:23:01 tom Exp $ */ +/* $Id: tclock.c,v 1.46 2022/12/04 00:40:11 tom Exp $ */ #define NEED_TIME_H #include @@ -107,12 +107,13 @@ dline(int pair, int from_x, int from_y, int x2, int y2, int ch) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: tclock [options]" ,"" + ,USAGE_COMMON ,"Options:" #if HAVE_USE_DEFAULT_COLORS ," -d invoke use_default_colors" @@ -123,8 +124,11 @@ usage(void) 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[]) @@ -151,20 +155,23 @@ main(int argc, char *argv[]) bool d_option = FALSE; #endif - while ((ch = getopt(argc, argv, "d")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "d")) != -1) { switch (ch) { #if HAVE_USE_DEFAULT_COLORS case 'd': d_option = TRUE; break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); setlocale(LC_ALL, ""); diff --git a/test/test.priv.h b/test/test.priv.h index a577da12..e94e5740 100644 --- a/test/test.priv.h +++ b/test/test.priv.h @@ -30,7 +30,7 @@ /**************************************************************************** * Author: Thomas E. Dickey 1996-on * ****************************************************************************/ -/* $Id: test.priv.h,v 1.204 2022/08/20 16:34:24 tom Exp $ */ +/* $Id: test.priv.h,v 1.206 2022/12/04 00:08:15 tom Exp $ */ #ifndef __TEST_PRIV_H #define __TEST_PRIV_H 1 @@ -715,6 +715,44 @@ extern int optind; #define HELP_KEY_1 '?' #define HELP_KEY_2 KEY_F(1) +/* our "standard" options for getopt, needed for help2man */ +#define OPTS_USAGE 'h' +#define OPTS_VERSION 'V' +#define OPTS_COMMON "hV" +#define USAGE_COMMON \ + "Common options:"\ +," -h show this message"\ +," -V show version of curses" + +#if HAVE_CURSES_VERSION +#define format_version(buffer) strcpy(buffer, curses_version()) +#elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH) +#define format_version(buffer) sprintf(buffer, "ncurses %d.%d.%d", \ + NCURSES_VERSION_MAJOR, \ + NCURSES_VERSION_MINOR, \ + NCURSES_VERSION_PATCH) +#else +#define format_version(buffer) strcpy(buffer, "ncurses-examples") +#endif + +#define VERSION_COMMON() \ +static char *version_common(char **argv) { \ + char *base = argv[0]; \ + char *leaf = strrchr(base, '/'); \ + char *result = malloc(strlen(base) + 80); \ + if (leaf++ == NULL) leaf = base; \ + sprintf(result, "%.20s: ", leaf); \ + format_version(result + strlen(result)); \ + return result; \ +} \ +static void show_version(char **argv) { \ + char *value = version_common(argv); \ + if (value != NULL) { \ + puts(value); \ + free(value); \ + } \ +} + /* from nc_string.h, to make this stand alone */ #if HAVE_BSD_STRING_H #include diff --git a/test/test_add_wchstr.c b/test/test_add_wchstr.c index b1605046..36fd335f 100644 --- a/test/test_add_wchstr.c +++ b/test/test_add_wchstr.c @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: test_add_wchstr.c,v 1.30 2022/09/03 21:40:27 tom Exp $ + * $Id: test_add_wchstr.c,v 1.33 2022/12/04 00:40:11 tom Exp $ * * Demonstrate the waddwchstr() and wadd_wch functions. * Thomas Dickey - 2009/9/12 @@ -542,24 +542,28 @@ recursive_test(int level) } static void -usage(void) +usage(int ok) { static const char *tbl[] = { "Usage: test_add_wchstr [options]" ,"" + ,USAGE_COMMON ,"Options:" - ," -f FILE read data from given file" - ," -n NUM limit string-adds to NUM bytes on ^N replay" - ," -m perform wmove/move separately from add-functions" - ," -p pass-thru control characters without using unctrl()" - ," -w use window-parameter even when stdscr would be implied" + ," -f FILE read data from given file" + ," -n NUM limit string-adds to NUM bytes on ^N replay" + ," -m perform wmove/move separately from add-functions" + ," -p pass-thru control characters without using unctrl()" + ," -w use window-parameter even when stdscr would be implied" }; unsigned n; for (n = 0; n < SIZEOF(tbl); ++n) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) @@ -568,7 +572,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "f:mn:pw")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "f:mn:pw")) != -1) { switch (ch) { case 'f': init_linedata(optarg); @@ -587,13 +591,16 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) case 'w': w_opt = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); recursive_test(0); endwin(); diff --git a/test/test_addchstr.c b/test/test_addchstr.c index 5b2df8ad..f81b3f0b 100644 --- a/test/test_addchstr.c +++ b/test/test_addchstr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * Copyright 2020,2022 Thomas E. Dickey * * Copyright 2009-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: test_addchstr.c,v 1.25 2020/02/02 23:34:34 tom Exp $ + * $Id: test_addchstr.c,v 1.28 2022/12/04 00:40:11 tom Exp $ * * Demonstrate the waddchstr() and waddch functions. * Thomas Dickey - 2009/9/12 @@ -460,24 +460,28 @@ recursive_test(int level) } static void -usage(void) +usage(int ok) { static const char *tbl[] = { "Usage: test_addchstr [options]" ,"" + ,USAGE_COMMON ,"Options:" - ," -f FILE read data from given file" - ," -n NUM limit string-adds to NUM bytes on ^N replay" - ," -m perform wmove/move separately from add-functions" - ," -p pass-thru control characters without using unctrl()" - ," -w use window-parameter even when stdscr would be implied" + ," -f FILE read data from given file" + ," -n NUM limit string-adds to NUM bytes on ^N replay" + ," -m perform wmove/move separately from add-functions" + ," -p pass-thru control characters without using unctrl()" + ," -w use window-parameter even when stdscr would be implied" }; unsigned n; for (n = 0; n < SIZEOF(tbl); ++n) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) @@ -486,7 +490,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "f:mn:pw")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "f:mn:pw")) != -1) { switch (ch) { case 'f': init_linedata(optarg); @@ -505,13 +509,16 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) case 'w': w_opt = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); recursive_test(0); endwin(); diff --git a/test/test_addstr.c b/test/test_addstr.c index 67e540a5..f4070fb3 100644 --- a/test/test_addstr.c +++ b/test/test_addstr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * Copyright 2020,2022 Thomas E. Dickey * * Copyright 2009-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: test_addstr.c,v 1.16 2020/02/02 23:34:34 tom Exp $ + * $Id: test_addstr.c,v 1.19 2022/12/04 00:40:11 tom Exp $ * * Demonstrate the waddstr() and waddch functions. * Thomas Dickey - 2009/9/12 @@ -375,23 +375,27 @@ recursive_test(int level) } static void -usage(void) +usage(int ok) { static const char *tbl[] = { "Usage: test_addstr [options]" ,"" + ,USAGE_COMMON ,"Options:" - ," -f FILE read data from given file" - ," -n NUM limit string-adds to NUM bytes on ^N replay" - ," -m perform wmove/move separately from add-functions" - ," -w use window-parameter even when stdscr would be implied" + ," -f FILE read data from given file" + ," -n NUM limit string-adds to NUM bytes on ^N replay" + ," -m perform wmove/move separately from add-functions" + ," -w use window-parameter even when stdscr would be implied" }; unsigned n; for (n = 0; n < SIZEOF(tbl); ++n) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) @@ -400,7 +404,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "f:mn:w")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "f:mn:w")) != -1) { switch (ch) { case 'f': init_linedata(optarg); @@ -416,13 +420,16 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) case 'w': w_opt = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); recursive_test(0); endwin(); diff --git a/test/test_addwstr.c b/test/test_addwstr.c index 22cacb91..e4e90579 100644 --- a/test/test_addwstr.c +++ b/test/test_addwstr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * Copyright 2020,2022 Thomas E. Dickey * * Copyright 2009-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: test_addwstr.c,v 1.17 2020/02/02 23:34:34 tom Exp $ + * $Id: test_addwstr.c,v 1.20 2022/12/04 00:40:11 tom Exp $ * * Demonstrate the waddwstr() and wadd_wch functions. * Thomas Dickey - 2009/9/12 @@ -467,23 +467,27 @@ recursive_test(int level) } static void -usage(void) +usage(int ok) { static const char *tbl[] = { "Usage: test_addwstr [options]" ,"" + ,USAGE_COMMON ,"Options:" - ," -f FILE read data from given file" - ," -n NUM limit string-adds to NUM bytes on ^N replay" - ," -m perform wmove/move separately from add-functions" - ," -w use window-parameter even when stdscr would be implied" + ," -f FILE read data from given file" + ," -n NUM limit string-adds to NUM bytes on ^N replay" + ," -m perform wmove/move separately from add-functions" + ," -w use window-parameter even when stdscr would be implied" }; unsigned n; for (n = 0; n < SIZEOF(tbl); ++n) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) @@ -492,7 +496,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "f:mn:w")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "f:mn:w")) != -1) { switch (ch) { case 'f': init_linedata(optarg); @@ -508,13 +512,16 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) case 'w': w_opt = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); recursive_test(0); endwin(); diff --git a/test/test_arrays.c b/test/test_arrays.c index 7ee25eab..ef276703 100644 --- a/test/test_arrays.c +++ b/test/test_arrays.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * 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 * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: test_arrays.c,v 1.9 2020/02/02 23:34:34 tom Exp $ + * $Id: test_arrays.c,v 1.12 2022/12/04 00:40:11 tom Exp $ * * Author: Thomas E Dickey * @@ -135,37 +135,41 @@ dump_table(void) } static void -usage(void) +usage(int ok) { static const char *msg[] = { - "Usage: test_arrays [options]", - "", - "If no options are given, print all (boolean, numeric, string)", - "capability names showing their index within the tables.", - "", - "Options:", - " -C print termcap names", - " -T print terminfo names", - " -c print termcap names", - " -f print full terminfo names", - " -n print short terminfo names", - " -t print the result as CSV table", + "Usage: test_arrays [options]" + ,"" + ,"If no options are given, print all (boolean, numeric, string)" + ,"capability names showing their index within the tables." + ,"" + ,USAGE_COMMON + ,"Options:" + ," -C print termcap names" + ," -T print terminfo names" + ," -c print termcap names" + ," -f print full terminfo names" + ," -n print short terminfo names" + ," -t print the result as CSV table" }; 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 n; + int ch; - while ((n = getopt(argc, argv, "CTcfnt")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "CTcfnt")) != -1) { + switch (ch) { case 'C': opt_C = TRUE; break; @@ -184,13 +188,16 @@ main(int argc, char *argv[]) case 't': opt_t = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); if (!(opt_T || opt_C)) { opt_T = opt_C = TRUE; diff --git a/test/test_mouse.c b/test/test_mouse.c index 1348877f..06c72e37 100644 --- a/test/test_mouse.c +++ b/test/test_mouse.c @@ -22,7 +22,7 @@ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************/ /* - * $Id: test_mouse.c,v 1.23 2022/08/20 18:12:16 tom Exp $ + * $Id: test_mouse.c,v 1.26 2022/12/04 00:40:11 tom Exp $ * * Author: Leonid S Usov * @@ -117,45 +117,46 @@ logw(const char *fmt, ...) } static void -usage(void) +usage(int ok) { static const char *msg[] = { - "Usage: test_mouse [options]", - "", - "Test mouse events. These examples for $TERM demonstrate xterm", - "features:", - " xterm", - " xterm-1002", - " xterm-1003", - "", - "Options:", - " -r show raw input stream, injecting a new line before every ESC", - " -i n set mouse interval to n; default is 0 (no double-clicks)", - " -h show this message", - " -T term use terminal description other than $TERM" + "Usage: test_mouse [options]" + ,"" + ,"Test mouse events. These examples for $TERM demonstrate xterm" + ,"features:" + ," xterm" + ," xterm-1002" + ," xterm-1003" + ,"" + ,USAGE_COMMON + ,"Options:" + ," -r show raw input stream, injecting a new line before every ESC" + ," -i n set mouse interval to n; default is 0 (no double-clicks)" + ," -T term use terminal description other than $TERM" }; unsigned n; for (n = 0; n < sizeof(msg) / sizeof(char *); ++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[]) { bool rawmode = FALSE; int interval = 0; - int c; + int ch; MEVENT event; char *my_environ = NULL; const char *term_format = "TERM=%s"; - while ((c = getopt(argc, argv, "hi:rT:")) != -1) { - switch (c) { - case 'h': - usage(); - ExitProgram(EXIT_SUCCESS); + while ((ch = getopt(argc, argv, OPTS_COMMON "i:rT:")) != -1) { + switch (ch) { case 'i': interval = atoi(optarg); break; @@ -167,13 +168,16 @@ main(int argc, char *argv[]) sprintf(my_environ, term_format, optarg); putenv(my_environ); break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - ExitProgram(EXIT_FAILURE); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) { - usage(); + usage(FALSE); ExitProgram(EXIT_FAILURE); } @@ -199,7 +203,7 @@ main(int argc, char *argv[]) logoffset = getcury(stdscr); while (1) { - c = getch(); + int c = getch(); switch (c) { case KEY_MOUSE: diff --git a/test/test_setupterm.c b/test/test_setupterm.c index 0dc7494b..360a25a3 100644 --- a/test/test_setupterm.c +++ b/test/test_setupterm.c @@ -30,7 +30,7 @@ /* * Author: Thomas E. Dickey * - * $Id: test_setupterm.c,v 1.12 2022/05/15 16:36:00 tom Exp $ + * $Id: test_setupterm.c,v 1.15 2022/12/04 00:40:11 tom Exp $ * * A simple demo of setupterm/restartterm. */ @@ -148,37 +148,42 @@ test_setupterm(NCURSES_CONST char *name) } static void -usage(void) +usage(int ok) { static const char *msg[] = { - "Usage: test_setupterm [options] [terminal]", - "", - "Demonstrate error-checking for setupterm and restartterm.", - "", - "Options:", - " -a automatic test for each success/error code", - " -f treat errors as fatal", - " -n set environment to disable terminfo database, assuming", - " the compiled-in paths for database also fail", + "Usage: test_setupterm [options] [terminal]" + ,"" + ,USAGE_COMMON + ,"Demonstrate error-checking for setupterm and restartterm." + ,"" + ,"Options:" + ," -a automatic test for each success/error code" + ," -f treat errors as fatal" + ," -n set environment to disable terminfo database, assuming" + ," the compiled-in paths for database also fail" #if HAVE_RESTARTTERM - " -r test restartterm rather than setupterm", + ," -r test restartterm rather than setupterm" #endif }; unsigned n; for (n = 0; n < SIZEOF(msg); ++n) { fprintf(stderr, "%s\n", msg[n]); } - finish(EXIT_FAILURE); + finish(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc, char *argv[]) { + int ch; int n; - while ((n = getopt(argc, argv, "afnr")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "afnr")) != -1) { + switch (ch) { case 'a': a_opt = TRUE; break; @@ -193,9 +198,12 @@ main(int argc, char *argv[]) r_opt = TRUE; break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } @@ -230,7 +238,7 @@ main(int argc, char *argv[]) static char predef[][9] = {"vt100", "dumb", "lpr", "unknown", "none-such"}; if (optind < argc) { - usage(); + usage(FALSE); } for (n = 0; n < 4; ++n) { test_setupterm(predef[n]); diff --git a/test/test_sgr.c b/test/test_sgr.c index 33564adb..385762a5 100644 --- a/test/test_sgr.c +++ b/test/test_sgr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019-2020,2021 Thomas E. Dickey * + * Copyright 2019-2021,2022 Thomas E. Dickey * * Copyright 2015-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: test_sgr.c,v 1.17 2021/03/27 22:43:36 tom Exp $ + * $Id: test_sgr.c,v 1.20 2022/12/04 00:40:11 tom Exp $ * * A simple demo of the sgr/sgr0 terminal capabilities. */ @@ -305,35 +305,39 @@ brute_force(const char *name) } static void -usage(void) +usage(int ok) { static const char *msg[] = { - "Usage: test_sgr [options] [terminal]", - "", - "Print all distinct combinations of sgr capability.", - "", - "Options:", - " -d LIST colon-separated list of databases to use", - " -e NAME environment variable to set with -d option", - " -n do not initialize terminal, to test error-checking", - " -q quiet (prints only counts)", + "Usage: test_sgr [options] [terminal]" + ,"" + ,"Print all distinct combinations of sgr capability." + ,"" + ,USAGE_COMMON + ,"Options:" + ," -d LIST colon-separated list of databases to use" + ," -e NAME environment variable to set with -d option" + ," -n do not initialize terminal, to test error-checking" + ," -q quiet (prints only counts)" }; 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 n; + int ch; char *name; - while ((n = getopt(argc, argv, "d:e:nq")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "d:e:nq")) != -1) { + switch (ch) { case 'd': d_opt = optarg; break; @@ -346,15 +350,19 @@ main(int argc, char *argv[]) case 'q': q_opt = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } make_dblist(); if (optind < argc) { + int n; for (n = optind; n < argc; ++n) { brute_force(argv[n]); } diff --git a/test/test_termattrs.c b/test/test_termattrs.c index 2464ddea..f5e95db1 100644 --- a/test/test_termattrs.c +++ b/test/test_termattrs.c @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: test_termattrs.c,v 1.4 2022/05/15 15:55:30 tom Exp $ + * $Id: test_termattrs.c,v 1.7 2022/12/04 00:40:11 tom Exp $ * * Demonstrate the termattrs and term_attrs functions. */ @@ -118,25 +118,29 @@ test_termattrs(unsigned long value) } static void -usage(void) +usage(int ok) { static const char *tbl[] = { "Usage: test_termattrs [options]" ,"" + ,USAGE_COMMON ,"Options:" - ," -e use stderr (default stdout)" - ," -n do not initialize terminal" - ," -s use setupterm rather than newterm" + ," -e use stderr (default stdout)" + ," -n do not initialize terminal" + ," -s use setupterm rather than newterm" #if USE_WIDEC_SUPPORT - ," -w use term_attrs rather than termattrs" + ," -w use term_attrs rather than termattrs" #endif }; unsigned n; for (n = 0; n < SIZEOF(tbl); ++n) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) @@ -150,7 +154,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) my_fp = stdout; - while ((ch = getopt(argc, argv, "ensw")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "ensw")) != -1) { switch (ch) { case 'e': my_fp = stderr; @@ -166,13 +170,16 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) w_opt = TRUE; break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); if (no_init) { START_TRACE(); diff --git a/test/test_tparm.c b/test/test_tparm.c index 1c976af7..dddec7c3 100644 --- a/test/test_tparm.c +++ b/test/test_tparm.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020,2021 Thomas E. Dickey * + * Copyright 2020-2021,2022 Thomas E. Dickey * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,7 +29,7 @@ /* * Author: Thomas E. Dickey * - * $Id: test_tparm.c,v 1.20 2021/03/20 15:58:32 tom Exp $ + * $Id: test_tparm.c,v 1.23 2022/12/04 00:40:11 tom Exp $ * * Exercise tparm, either for all possible capabilities with fixed parameters, * or one capability with all possible parameters. @@ -178,38 +178,43 @@ test_tparm(const char *name, const char *format, int *number) } static void -usage(void) +usage(int ok) { static const char *msg[] = { - "Usage: test_tparm [options] [capability] [value1 [value2 [...]]]", - "", - "Use tparm/tputs for all distinct combinations of given capability.", - "", - "Options:", - " -T TERM override $TERM; this may be a comma-separated list or \"-\"", - " to read a list from standard-input", - " -a test all combinations of parameters", - " [value1...] forms a vector of maximum parameter-values.", - " -p test capabilities with no parameters but having padding", - " -r NUM repeat tests NUM times", - " -v show values and results", + "Usage: test_tparm [options] [capability] [value1 [value2 [...]]]" + ,"" + ,"Use tparm/tputs for all distinct combinations of given capability." + ,"" + ,USAGE_COMMON + ,"Options:" + ," -T TERM override $TERM; this may be a comma-separated list or \"-\"" + ," to read a list from standard-input" + ," -a test all combinations of parameters" + ," [value1...] forms a vector of maximum parameter-values." + ," -p test capabilities with no parameters but having padding" + ," -r NUM repeat tests NUM times" + ," -v show values and results" }; unsigned n; for (n = 0; n < SIZEOF(msg); ++n) { fprintf(stderr, "%s\n", msg[n]); } - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } #define PLURAL(n) n, (n != 1) ? "s" : "" #define COLONS(n) (n >= 1) ? ":" : "" #define NUMFORM "%10ld" +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc, char *argv[]) { + int ch; int n; int r_run, t_run, n_run; char *old_term = getenv("TERM"); @@ -239,8 +244,8 @@ main(int argc, char *argv[]) if (all_caps == 0 || all_terms == 0 || num_parms == 0 || str_parms == 0) failed("no memory"); - while ((n = getopt(argc, argv, "T:apr:v")) != -1) { - switch (n) { + while ((ch = getopt(argc, argv, OPTS_COMMON "T:apr:v")) != -1) { + switch (ch) { case 'T': t_opt = optarg; break; @@ -256,9 +261,12 @@ main(int argc, char *argv[]) case 'v': ++v_opt; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } diff --git a/test/test_vid_puts.c b/test/test_vid_puts.c index 00bcb082..5a08d907 100644 --- a/test/test_vid_puts.c +++ b/test/test_vid_puts.c @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: test_vid_puts.c,v 1.13 2022/04/16 18:27:24 tom Exp $ + * $Id: test_vid_puts.c,v 1.16 2022/12/04 00:40:11 tom Exp $ * * Demonstrate the vid_puts and vid_attr functions. * Thomas Dickey - 2013/01/12 @@ -94,22 +94,26 @@ test_vid_puts(void) } static void -usage(void) +usage(int ok) { static const char *tbl[] = { "Usage: test_vid_puts [options]" ,"" + ,USAGE_COMMON ,"Options:" - ," -e use stderr (default stdout)" - ," -n do not initialize terminal" - ," -p use vid_puts (default vid_attr)" + ," -e use stderr (default stdout)" + ," -n do not initialize terminal" + ," -p use vid_puts (default vid_attr)" }; unsigned n; for (n = 0; n < SIZEOF(tbl); ++n) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) @@ -119,7 +123,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) my_fp = stdout; - while ((ch = getopt(argc, argv, "enp")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "enp")) != -1) { switch (ch) { case 'e': my_fp = stderr; @@ -130,13 +134,16 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) case 'p': p_opt = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); setlocale(LC_ALL, ""); if (no_init) { diff --git a/test/test_vidputs.c b/test/test_vidputs.c index 25b7714d..d7bbfcb2 100644 --- a/test/test_vidputs.c +++ b/test/test_vidputs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020,2021 Thomas E. Dickey * + * Copyright 2020-2021,2022 Thomas E. Dickey * * Copyright 2013-2014,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: test_vidputs.c,v 1.11 2021/04/25 00:10:43 tom Exp $ + * $Id: test_vidputs.c,v 1.14 2022/12/04 00:40:11 tom Exp $ * * Demonstrate the vidputs and vidattr functions. * Thomas Dickey - 2013/01/12 @@ -94,22 +94,26 @@ test_vidputs(void) } static void -usage(void) +usage(int ok) { static const char *tbl[] = { "Usage: test_vidputs [options]" ,"" + ,USAGE_COMMON ,"Options:" - ," -e use stderr (default stdout)" - ," -n do not initialize terminal" - ," -p use vidputs (default vidattr)" + ," -e use stderr (default stdout)" + ," -n do not initialize terminal" + ," -p use vidputs (default vidattr)" }; unsigned n; for (n = 0; n < SIZEOF(tbl); ++n) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) @@ -119,7 +123,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) my_fp = stdout; - while ((ch = getopt(argc, argv, "enp")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "enp")) != -1) { switch (ch) { case 'e': my_fp = stderr; @@ -130,13 +134,16 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) case 'p': p_opt = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - break; + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); if (no_init) { START_TRACE(); diff --git a/test/view.c b/test/view.c index b368f5b7..72e0cfbb 100644 --- a/test/view.c +++ b/test/view.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019-2020,2021 Thomas E. Dickey * + * Copyright 2019-2021,2022 Thomas E. Dickey * * Copyright 1998-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -52,7 +52,7 @@ * scroll operation worked, and the refresh() code only had to do a * partial repaint. * - * $Id: view.c,v 1.142 2021/06/12 23:16:31 tom Exp $ + * $Id: view.c,v 1.145 2022/12/04 00:40:11 tom Exp $ */ #include @@ -377,12 +377,13 @@ read_file(const char *filename) } static GCC_NORETURN void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: view [options] file" ,"" + ,USAGE_COMMON ,"Options:" ," -c use color if terminal supports it" ," -i ignore INT, QUIT, TERM signals" @@ -398,8 +399,11 @@ usage(void) size_t 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[]) @@ -429,6 +433,7 @@ main(int argc, char *argv[]) 0 }; + int ch; int i; int my_delay = 0; NCURSES_CH_T **olptr; @@ -441,8 +446,8 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); - while ((i = getopt(argc, argv, "cinstT:")) != -1) { - switch (i) { + while ((ch = getopt(argc, argv, OPTS_COMMON "cinstT:")) != -1) { + switch (ch) { case 'c': try_color = TRUE; break; @@ -463,7 +468,7 @@ main(int argc, char *argv[]) char *next = 0; int tvalue = (int) strtol(optarg, &next, 0); if (tvalue < 0 || (next != 0 && *next != 0)) - usage(); + usage(FALSE); curses_trace((unsigned) tvalue); } break; @@ -471,12 +476,16 @@ main(int argc, char *argv[]) curses_trace(TRACE_CALLS); break; #endif + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind + 1 != argc) - usage(); + usage(FALSE); InitAndCatch(initscr(), ignore_sigs ? SIG_IGN : finish); keypad(stdscr, TRUE); /* enable keyboard mapping */ diff --git a/test/worm.c b/test/worm.c index 2ce1c5ee..aca96c6f 100644 --- a/test/worm.c +++ b/test/worm.c @@ -53,7 +53,7 @@ traces will be dumped. The program stops and waits for one character of input at the beginning and end of the interval. - $Id: worm.c,v 1.85 2022/08/13 13:28:01 tom Exp $ + $Id: worm.c,v 1.88 2022/12/04 00:40:11 tom Exp $ */ #include @@ -447,12 +447,13 @@ update_refs(WINDOW *win, void *data) #endif static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: worm [options]" ,"" + ,USAGE_COMMON ,"Options:" #if HAVE_USE_DEFAULT_COLORS ," -d invoke use_default_colors" @@ -471,8 +472,11 @@ usage(void) 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[]) @@ -489,7 +493,7 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "dfl:n:tT:N")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "dfl:n:tT:N")) != -1) { switch (ch) { #if HAVE_USE_DEFAULT_COLORS case 'd': @@ -502,13 +506,13 @@ main(int argc, char *argv[]) case 'l': if ((length = atoi(optarg)) < 2 || length > MAX_LENGTH) { fprintf(stderr, "%s: Invalid length\n", *argv); - usage(); + usage(FALSE); } break; case 'n': if ((number = atoi(optarg)) < 1 || number > MAX_WORMS) { fprintf(stderr, "%s: Invalid number of worms\n", *argv); - usage(); + usage(FALSE); } break; case 't': @@ -517,19 +521,22 @@ main(int argc, char *argv[]) #ifdef TRACE case 'T': if (sscanf(optarg, "%d,%d", &trace_start, &trace_end) != 2) - usage(); + usage(FALSE); break; case 'N': _nc_optimize_enable ^= OPTIMIZE_ALL; /* declared by ncurses */ break; #endif /* TRACE */ + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); /* NOTREACHED */ } } if (optind < argc) - usage(); + usage(FALSE); signal(SIGINT, onsig); initscr(); diff --git a/test/xmas.c b/test/xmas.c index 678c9e17..9ba3a26c 100644 --- a/test/xmas.c +++ b/test/xmas.c @@ -92,7 +92,7 @@ /******************************************************************************/ /* - * $Id: xmas.c,v 1.36 2021/03/27 22:40:53 tom Exp $ + * $Id: xmas.c,v 1.39 2022/12/04 00:40:11 tom Exp $ */ #include @@ -646,12 +646,13 @@ done(int sig GCC_UNUSED) } static void -usage(void) +usage(int ok) { static const char *msg[] = { "Usage: xmas [options]" ,"" + ,USAGE_COMMON ,"Options:" #if HAVE_USE_DEFAULT_COLORS ," -d invoke use_default_colors" @@ -663,8 +664,11 @@ usage(void) 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[]) @@ -676,7 +680,7 @@ main(int argc, char *argv[]) #endif bool opt_q = FALSE; - while ((ch = getopt(argc, argv, "dq")) != -1) { + while ((ch = getopt(argc, argv, OPTS_COMMON "dq")) != -1) { switch (ch) { #if HAVE_USE_DEFAULT_COLORS case 'd': @@ -686,8 +690,11 @@ main(int argc, char *argv[]) case 'q': opt_q = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); /* NOTREACHED */ } } -- 2.45.0