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: reduce boilerplat...



details:   https://anonhg.NetBSD.org/src/rev/35f35b09b8f3
branches:  trunk
changeset: 952305:35f35b09b8f3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Feb 12 12:58:52 2021 +0000

description:
tests/libcurses: reduce boilerplate in function dispatcher

No functional change.  The generated code for GCC 9.3 on NetBSD 9.99.80
x86_64 is exactly the same as before.

diffstat:

 tests/lib/libcurses/slave/curses_commands.c |  1891 +++++++-------------------
 1 files changed, 547 insertions(+), 1344 deletions(-)

diffs (truncated from 3535 to 300 lines):

diff -r 233bc6d79198 -r 35f35b09b8f3 tests/lib/libcurses/slave/curses_commands.c
--- a/tests/lib/libcurses/slave/curses_commands.c       Fri Feb 12 12:26:09 2021 +0000
+++ b/tests/lib/libcurses/slave/curses_commands.c       Fri Feb 12 12:58:52 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: curses_commands.c,v 1.14 2021/02/12 08:55:32 rillig Exp $      */
+/*     $NetBSD: curses_commands.c,v 1.15 2021/02/12 12:58:52 rillig Exp $      */
 
 /*-
  * Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -103,11 +103,25 @@
        if (check_arg_count(nargs, n) == 1)                             \
                return
 
+#define ARG_SHORT(i, arg) \
+       short arg;                                                      \
+       if (set_short(args[i], &arg) != 0)                              \
+               return
+
 #define ARG_INT(i, arg) \
        int arg;                                                        \
        if (set_int(args[i], &arg) != 0)                                \
                return
 
+#define ARG_CHTYPE_STRING(i, arg) \
+       chtype *arg = (chtype *)args[i]
+
+#define ARG_CCHAR_STRING(i, arg) \
+       cchar_t *arg = (cchar_t *)args[i]
+
+#define ARG_WCHAR_STRING(i, arg) \
+       wchar_t *arg = (wchar_t *)args[i]
+
 #define ARG_WINDOW(i, arg) \
        WINDOW *arg;                                                    \
        if (set_win(args[i], &arg) != 0)                                \
@@ -128,6 +142,7 @@
 cmd_addbytes(int nargs, char **args)
 {
        ARGC(2);
+       /* TODO: arg 0 */
        ARG_INT(1, count);
 
        report_count(1);
@@ -138,11 +153,9 @@
 void
 cmd_addch(int nargs, char **args)
 {
-       chtype *ch;
-
        ARGC(1);
-
-       ch = (chtype *) args[0];
+       ARG_CHTYPE_STRING(0, ch);
+
        report_count(1);
        report_return(addch(ch[0]));
 }
@@ -152,6 +165,7 @@
 cmd_addchnstr(int nargs, char **args)
 {
        ARGC(2);
+       /* TODO: arg 0 */
        ARG_INT(1, count);
 
        report_count(1);
@@ -163,6 +177,7 @@
 cmd_addchstr(int nargs, char **args)
 {
        ARGC(1);
+       /* TODO: arg 0 */
 
        report_count(1);
        report_return(addchstr((chtype *) args[0]));
@@ -173,6 +188,7 @@
 cmd_addnstr(int nargs, char **args)
 {
        ARGC(2);
+       /* TODO: arg 0 */
        ARG_INT(1, count);
 
        report_count(1);
@@ -184,6 +200,7 @@
 cmd_addstr(int nargs, char **args)
 {
        ARGC(1);
+       /* TODO: arg 0 */
 
        report_count(1);
        report_return(addstr(args[0]));
@@ -234,14 +251,9 @@
 void
 cmd_attr_set(int nargs, char **args)
 {
-       int attrib;
-       short pair;
-
        ARGC(2);
-
-       if ((set_int(args[0], &attrib) != 0) ||
-           (set_short(args[1], &pair) != 0))
-               return;
+       ARG_INT(0, attrib);
+       ARG_SHORT(1, pair);
 
        report_count(1);
        report_return(attr_set(attrib, pair, NULL));
@@ -284,11 +296,9 @@
 void
 cmd_bkgd(int nargs, char **args)
 {
-       chtype *ch;
-
        ARGC(1);
-
-       ch = (chtype *) args[0];
+       ARG_CHTYPE_STRING(0, ch);
+
        report_count(1);
        report_return(bkgd(ch[0]));
 }
@@ -297,11 +307,8 @@
 void
 cmd_bkgdset(int nargs, char **args)
 {
-       chtype *ch;
-
        ARGC(1);
-
-       ch = (chtype *) args[0];
+       ARG_CHTYPE_STRING(0, ch);
 
        bkgdset(ch[0]);         /* returns void */
        report_count(1);
@@ -312,19 +319,15 @@
 void
 cmd_border(int nargs, char **args)
 {
-       int ls, rs, ts, bs, tl, tr, bl, br;
-
        ARGC(8);
-
-       if ((set_int(args[0], &ls) != 0) ||
-           (set_int(args[1], &rs) != 0) ||
-           (set_int(args[2], &ts) != 0) ||
-           (set_int(args[3], &bs) != 0) ||
-           (set_int(args[4], &tl) != 0) ||
-           (set_int(args[5], &tr) != 0) ||
-           (set_int(args[6], &bl) != 0) ||
-           (set_int(args[7], &br) != 0))
-               return;
+       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);
 
        report_count(1);
        report_return(border(ls, rs, ts, bs, tl, tr, bl, br));
@@ -364,13 +367,9 @@
 void
 cmd_color_set(int nargs, char **args)
 {
-       short colour_pair;
-
        ARGC(2);
-
-       if (set_short(args[0], &colour_pair) != 0)
-               return;
-       /* XXX: args[1] is unused */
+       ARG_SHORT(0, colour_pair);
+       /* TODO: arg 1 */
 
        report_count(1);
        report_return(color_set(colour_pair, NULL));
@@ -400,10 +399,9 @@
 void
 cmd_echochar(int nargs, char **args)
 {
-       chtype *ch;
        ARGC(1);
-
-       ch = (chtype *) args[0];
+       ARG_CHTYPE_STRING(0, ch);
+
        /* XXX causes refresh */
        report_count(1);
        report_return(echochar(ch[0]));
@@ -535,10 +533,9 @@
 void
 cmd_insch(int nargs, char **args)
 {
-       chtype *ch;
        ARGC(1);
-
-       ch = (chtype *) args[0];
+       ARG_CHTYPE_STRING(0, ch);
+
        report_count(1);
        report_return(insch(ch[0]));
 }
@@ -582,13 +579,9 @@
 void
 cmd_move(int nargs, char **args)
 {
-       int y, x;
-
        ARGC(2);
-
-       if ((set_int(args[0], &y) != 0) ||
-           (set_int(args[1], &x) != 0))
-               return;
+       ARG_INT(0, y);
+       ARG_INT(1, x);
 
        report_count(1);
        report_return(move(y, x));
@@ -619,13 +612,9 @@
 void
 cmd_setscrreg(int nargs, char **args)
 {
-       int top, bottom;
-
        ARGC(2);
-
-       if ((set_int(args[0], &top) != 0) ||
-           (set_int(args[1], &bottom) != 0))
-               return;
+       ARG_INT(0, top);
+       ARG_INT(1, bottom);
 
        report_count(1);
        report_return(setscrreg(top, bottom));
@@ -687,14 +676,10 @@
 void
 cmd_waddbytes(int nargs, char **args)
 {
-       WINDOW *win;
-       int count;
-
        ARGC(3);
-
-       if ((set_win(args[0], &win) != 0) ||
-           (set_int(args[2], &count) != 0))
-               return;
+       ARG_WINDOW(0, win);
+       /* TODO: arg 1 */
+       ARG_INT(2, count);
 
        report_count(1);
        report_return(waddbytes(win, args[1], count));
@@ -706,6 +691,7 @@
 {
        ARGC(2);
        ARG_WINDOW(0, win);
+       /* TODO: arg 1 */
 
        report_count(1);
        report_return(waddstr(win, args[1]));
@@ -715,14 +701,11 @@
 void
 cmd_mvaddbytes(int nargs, char **args)
 {
-       int y, x, count;
-
        ARGC(4);
-
-       if ((set_int(args[0], &y) != 0) ||
-           (set_int(args[1], &x) != 0) ||
-           (set_int(args[3], &count) != 0))
-               return;
+       ARG_INT(0, y);
+       ARG_INT(1, x);
+       /* TODO: arg 2 */
+       ARG_INT(3, count);
 
        report_count(1);
        report_return(mvaddbytes(y, x, args[2], count));
@@ -732,15 +715,10 @@
 void
 cmd_mvaddch(int nargs, char **args)
 {
-       int y, x;
-       chtype *ch;
-
        ARGC(3);
-
-       if ((set_int(args[0], &y) != 0) ||
-           (set_int(args[1], &x) != 0))
-               return;
-       ch = (chtype *) args[2];
+       ARG_INT(0, y);
+       ARG_INT(1, x);
+       ARG_CHTYPE_STRING(2, ch);
 
        report_count(1);
        report_return(mvaddch(y, x, ch[0]));
@@ -750,14 +728,11 @@



Home | Main Index | Thread Index | Old Index