Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libcurses/slave tests/libcurses: remove redundant ...



details:   https://anonhg.NetBSD.org/src/rev/55073e7fa7d6
branches:  trunk
changeset: 983913:55073e7fa7d6
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jun 13 18:11:44 2021 +0000

description:
tests/libcurses: remove redundant argument numbers

Since all arguments are processed in increasing order, there is no need
to add the redundant argument numbers.  Most of the curses functions
have less than 5 arguments, which makes it easy enough to count the ARG
macros.

Changes to curses_commands.c:

* replace ^(\tARG_\w+\()\d(?:, |) with $1
* replace (define ARG_\w+\()i,\s with $1
* replace args\[i\] with *args++
* replace \(i\) with ()
* replace \(void\)0 with args++

The wrong argument count in cmd_mvwget_wch is still detected by
lint.lua, as it was before.  There is no test yet that covers this
function.

diffstat:

 tests/lib/libcurses/slave/curses_commands.c |  1502 +++++++++++++-------------
 tests/lib/libcurses/slave/lint.lua          |    19 +-
 2 files changed, 758 insertions(+), 763 deletions(-)

diffs (truncated from 3763 to 300 lines):

diff -r cea096367d62 -r 55073e7fa7d6 tests/lib/libcurses/slave/curses_commands.c
--- a/tests/lib/libcurses/slave/curses_commands.c       Sun Jun 13 17:02:14 2021 +0000
+++ b/tests/lib/libcurses/slave/curses_commands.c       Sun Jun 13 18:11:44 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: curses_commands.c,v 1.25 2021/04/04 09:49:13 rin Exp $ */
+/*     $NetBSD: curses_commands.c,v 1.26 2021/06/13 18:11:44 rillig Exp $      */
 
 /*-
  * Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -102,68 +102,68 @@
        if (check_arg_count(nargs, n) == 1)                             \
                return
 
-#define ARG_SHORT(i, arg) \
+#define ARG_SHORT(arg) \
        short arg;                                                      \
-       if (set_short(args[i], &arg) != 0)                              \
+       if (set_short(*args++, &arg) != 0)                              \
                return
 
-#define ARG_INT(i, arg) \
+#define ARG_INT(arg) \
        int arg;                                                        \
-       if (set_int(args[i], &arg) != 0)                                \
+       if (set_int(*args++, &arg) != 0)                                \
                return
 
-#define ARG_UINT(i, arg) \
+#define ARG_UINT(arg) \
        unsigned int arg;                                               \
-       if (set_uint(args[i], &arg) != 0)                               \
+       if (set_uint(*args++, &arg) != 0)                               \
                return
 
-#define ARG_CHTYPE(i, arg) \
-       chtype arg = ((const chtype *)args[i])[0]
-
-#define ARG_WCHAR(i, arg) \
-       wchar_t arg = ((const wchar_t *)args[i])[0]
-
-#define ARG_STRING(i, arg) \
-       const char *arg = args[i]
+#define ARG_CHTYPE(arg) \
+       chtype arg = ((const chtype *)*args++)[0]
+
+#define ARG_WCHAR(arg) \
+       wchar_t arg = ((const wchar_t *)*args++)[0]
+
+#define ARG_STRING(arg) \
+       const char *arg = *args++
 
 /* Only used for legacy interfaces that are missing the 'const'. */
-#define ARG_MODIFIABLE_STRING(i, arg) \
-       char *arg = args[i]
-
-#define ARG_CHTYPE_STRING(i, arg) \
-       const chtype *arg = (const chtype *)args[i]
-
-#define ARG_CCHAR_STRING(i, arg) \
-       const cchar_t *arg = (const cchar_t *)args[i]
-
-#define ARG_WCHAR_STRING(i, arg) \
-       wchar_t *arg = (wchar_t *)args[i]
-
-#define ARG_WINDOW(i, arg) \
+#define ARG_MODIFIABLE_STRING(arg) \
+       char *arg = *args++
+
+#define ARG_CHTYPE_STRING(arg) \
+       const chtype *arg = (const chtype *)*args++
+
+#define ARG_CCHAR_STRING(arg) \
+       const cchar_t *arg = (const cchar_t *)*args++
+
+#define ARG_WCHAR_STRING(arg) \
+       wchar_t *arg = (wchar_t *)*args++
+
+#define ARG_WINDOW(arg) \
        WINDOW *arg;                                                    \
-       if (set_win(args[i], &arg) != 0)                                \
+       if (set_win(*args++, &arg) != 0)                                \
                return
 
-#define ARG_SCREEN(i, arg) \
+#define ARG_SCREEN(arg) \
        SCREEN *arg;                                                    \
-       if (set_scrn(args[i], &arg) != 0)                               \
+       if (set_scrn(*args++, &arg) != 0)                               \
                return
 
 /*
  * Required by the API, intended for future extensions, but this
  * implementation does not support the extension.
  */
-#define ARG_NULL(i) \
-       (void)0
-
-#define ARG_IGNORE(i) \
-       (void)0
+#define ARG_NULL() \
+       args++
+
+#define ARG_IGNORE() \
+       args++
 
 void
 cmd_DRAIN(int nargs, char **args)
 {
        ARGC(1);
-       ARG_WINDOW(0, win);
+       ARG_WINDOW(win);
 
        while (wgetch(win) != ERR);
        report_count(1);
@@ -174,8 +174,8 @@
 cmd_addbytes(int nargs, char **args)
 {
        ARGC(2);
-       ARG_STRING(0, str);
-       ARG_INT(1, count);
+       ARG_STRING(str);
+       ARG_INT(count);
 
        report_count(1);
        report_return(addbytes(str, count));
@@ -186,7 +186,7 @@
 cmd_addch(int nargs, char **args)
 {
        ARGC(1);
-       ARG_CHTYPE(0, ch);
+       ARG_CHTYPE(ch);
 
        report_count(1);
        report_return(addch(ch));
@@ -197,8 +197,8 @@
 cmd_addchnstr(int nargs, char **args)
 {
        ARGC(2);
-       ARG_CHTYPE_STRING(0, chstr);
-       ARG_INT(1, count);
+       ARG_CHTYPE_STRING(chstr);
+       ARG_INT(count);
 
        report_count(1);
        report_return(addchnstr(chstr, count));
@@ -209,7 +209,7 @@
 cmd_addchstr(int nargs, char **args)
 {
        ARGC(1);
-       ARG_CHTYPE_STRING(0, chstr);
+       ARG_CHTYPE_STRING(chstr);
 
        report_count(1);
        report_return(addchstr(chstr));
@@ -220,8 +220,8 @@
 cmd_addnstr(int nargs, char **args)
 {
        ARGC(2);
-       ARG_STRING(0, str);
-       ARG_INT(1, count);
+       ARG_STRING(str);
+       ARG_INT(count);
 
        report_count(1);
        report_return(addnstr(str, count));
@@ -232,7 +232,7 @@
 cmd_addstr(int nargs, char **args)
 {
        ARGC(1);
-       ARG_STRING(0, str);
+       ARG_STRING(str);
 
        report_count(1);
        report_return(addstr(str));
@@ -261,7 +261,7 @@
 cmd_attr_off(int nargs, char **args)
 {
        ARGC(1);
-       ARG_INT(0, attrib);
+       ARG_INT(attrib);
 
        report_count(1);
        report_return(attr_off(attrib, NULL));
@@ -272,7 +272,7 @@
 cmd_attr_on(int nargs, char **args)
 {
        ARGC(1);
-       ARG_INT(0, attrib);
+       ARG_INT(attrib);
 
        report_count(1);
        report_return(attr_on(attrib, NULL));
@@ -283,8 +283,8 @@
 cmd_attr_set(int nargs, char **args)
 {
        ARGC(2);
-       ARG_INT(0, attrib);
-       ARG_SHORT(1, pair);
+       ARG_INT(attrib);
+       ARG_SHORT(pair);
 
        report_count(1);
        report_return(attr_set(attrib, pair, NULL));
@@ -295,7 +295,7 @@
 cmd_attroff(int nargs, char **args)
 {
        ARGC(1);
-       ARG_INT(0, attrib);
+       ARG_INT(attrib);
 
        report_count(1);
        report_return(attroff(attrib));
@@ -306,7 +306,7 @@
 cmd_attron(int nargs, char **args)
 {
        ARGC(1);
-       ARG_INT(0, attrib);
+       ARG_INT(attrib);
 
        report_count(1);
        report_return(attron(attrib));
@@ -317,7 +317,7 @@
 cmd_attrset(int nargs, char **args)
 {
        ARGC(1);
-       ARG_INT(0, attrib);
+       ARG_INT(attrib);
 
        report_count(1);
        report_return(attrset(attrib));
@@ -328,7 +328,7 @@
 cmd_bkgd(int nargs, char **args)
 {
        ARGC(1);
-       ARG_CHTYPE(0, ch);
+       ARG_CHTYPE(ch);
 
        report_count(1);
        report_return(bkgd(ch));
@@ -339,7 +339,7 @@
 cmd_bkgdset(int nargs, char **args)
 {
        ARGC(1);
-       ARG_CHTYPE(0, ch);
+       ARG_CHTYPE(ch);
 
        bkgdset(ch);            /* returns void */
        report_count(1);
@@ -351,14 +351,14 @@
 cmd_border(int nargs, char **args)
 {
        ARGC(8);
-       ARG_INT(0, ls);
-       ARG_INT(1, rs);
-       ARG_INT(2, ts);
-       ARG_INT(3, bs);
-       ARG_INT(4, tl);
-       ARG_INT(5, tr);
-       ARG_INT(6, bl);
-       ARG_INT(7, br);
+       ARG_INT(ls);
+       ARG_INT(rs);
+       ARG_INT(ts);
+       ARG_INT(bs);
+       ARG_INT(tl);
+       ARG_INT(tr);
+       ARG_INT(bl);
+       ARG_INT(br);
 
        report_count(1);
        report_return(border(ls, rs, ts, bs, tl, tr, bl, br));
@@ -399,8 +399,8 @@
 cmd_color_set(int nargs, char **args)
 {
        ARGC(2);
-       ARG_SHORT(0, colour_pair);
-       ARG_NULL(1);
+       ARG_SHORT(colour_pair);
+       ARG_NULL();
 
        report_count(1);
        report_return(color_set(colour_pair, NULL));
@@ -431,7 +431,7 @@
 cmd_echochar(int nargs, char **args)
 {
        ARGC(1);
-       ARG_CHTYPE(0, ch);
+       ARG_CHTYPE(ch);
 
        /* XXX causes refresh */
        report_count(1);
@@ -466,7 +466,7 @@
        char *string;
 
        ARGC(1);
-       ARG_INT(0, limit);
+       ARG_INT(limit);
 
        if ((string = malloc(limit + 1)) == NULL) {
                report_count(1);



Home | Main Index | Thread Index | Old Index