Module Name:    src
Committed By:   blymn
Date:           Thu Sep 15 11:46:19 UTC 2011

Modified Files:
        src/tests/lib/libcurses/slave: command_table.h commands.c
            curses_commands.c curses_commands.h slave.c slave.h

Log Message:
- add support for getparyx and getyx calls
- allow a NULL pointer to be returned to the director
- add support for passing back a single chtype character
- fix some indentation
- fix a lot of curses command calls that were just plain wrong
- don't try to allocate storage for a NULL parameter, it doesn't need it


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libcurses/slave/command_table.h \
    src/tests/lib/libcurses/slave/curses_commands.h \
    src/tests/lib/libcurses/slave/slave.h
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libcurses/slave/commands.c
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libcurses/slave/curses_commands.c \
    src/tests/lib/libcurses/slave/slave.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libcurses/slave/command_table.h
diff -u src/tests/lib/libcurses/slave/command_table.h:1.2 src/tests/lib/libcurses/slave/command_table.h:1.3
--- src/tests/lib/libcurses/slave/command_table.h:1.2	Mon Apr 11 09:02:02 2011
+++ src/tests/lib/libcurses/slave/command_table.h	Thu Sep 15 11:46:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: command_table.h,v 1.2 2011/04/11 09:02:02 blymn Exp $	*/
+/*	$NetBSD: command_table.h,v 1.3 2011/09/15 11:46:19 blymn Exp $	*/
 
 /*-
  * Copyright 2009 Brett Lymn <[email protected]>
@@ -143,12 +143,14 @@
 	{"getbkgd", cmd_getbkgd},
 	{"getcury", cmd_getcury},
 	{"getcurx", cmd_getcurx},
+	{"getyx", cmd_getyx},
 	{"getbegy", cmd_getbegy},
 	{"getbegx", cmd_getbegx},
 	{"getmaxy", cmd_getmaxy},
 	{"getmaxx", cmd_getmaxx},
 	{"getpary", cmd_getpary},
 	{"getparx", cmd_getparx},
+	{"getparyx", cmd_getparyx},
 	{"gettmode", cmd_gettmode},
 	{"getwin", cmd_getwin},
 	{"halfdelay", cmd_halfdelay},
Index: src/tests/lib/libcurses/slave/curses_commands.h
diff -u src/tests/lib/libcurses/slave/curses_commands.h:1.2 src/tests/lib/libcurses/slave/curses_commands.h:1.3
--- src/tests/lib/libcurses/slave/curses_commands.h:1.2	Mon Apr 11 09:02:02 2011
+++ src/tests/lib/libcurses/slave/curses_commands.h	Thu Sep 15 11:46:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: curses_commands.h,v 1.2 2011/04/11 09:02:02 blymn Exp $	*/
+/*	$NetBSD: curses_commands.h,v 1.3 2011/09/15 11:46:19 blymn Exp $	*/
 
 /*-
  * Copyright 2009 Brett Lymn <[email protected]>
@@ -148,12 +148,14 @@
 void cmd_getbkgd(int, char **);
 void cmd_getcury(int, char **);
 void cmd_getcurx(int, char **);
+void cmd_getyx(int, char **);
 void cmd_getbegy(int, char **);
 void cmd_getbegx(int, char **);
 void cmd_getmaxy(int, char **);
 void cmd_getmaxx(int, char **);
 void cmd_getpary(int, char **);
 void cmd_getparx(int, char **);
+void cmd_getparyx(int, char **);
 void cmd_gettmode(int, char **);
 void cmd_getwin(int, char **);
 void cmd_halfdelay(int, char **);
Index: src/tests/lib/libcurses/slave/slave.h
diff -u src/tests/lib/libcurses/slave/slave.h:1.2 src/tests/lib/libcurses/slave/slave.h:1.3
--- src/tests/lib/libcurses/slave/slave.h:1.2	Sat Jun 11 18:03:18 2011
+++ src/tests/lib/libcurses/slave/slave.h	Thu Sep 15 11:46:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: slave.h,v 1.2 2011/06/11 18:03:18 christos Exp $	*/
+/*	$NetBSD: slave.h,v 1.3 2011/09/15 11:46:19 blymn Exp $	*/
 
 /*-
  * Copyright 2009 Brett Lymn <[email protected]>
@@ -40,6 +40,7 @@
 void report_count(int);
 void report_error(const char *);
 void report_int(int);
+void report_byte(chtype);
 void report_return(int);
 void report_nstr(chtype *);
 void report_status(const char *);

Index: src/tests/lib/libcurses/slave/commands.c
diff -u src/tests/lib/libcurses/slave/commands.c:1.3 src/tests/lib/libcurses/slave/commands.c:1.4
--- src/tests/lib/libcurses/slave/commands.c:1.3	Sat Jun 11 18:03:18 2011
+++ src/tests/lib/libcurses/slave/commands.c	Thu Sep 15 11:46:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: commands.c,v 1.3 2011/06/11 18:03:18 christos Exp $	*/
+/*	$NetBSD: commands.c,v 1.4 2011/09/15 11:46:19 blymn Exp $	*/
 
 /*-
  * Copyright 2009 Brett Lymn <[email protected]>
@@ -76,7 +76,10 @@
 {
 	char *string;
 
-	asprintf(&string, "%p", ptr);
+	if (ptr == NULL)
+		asprintf(&string, "NULL");
+	else
+		asprintf(&string, "%p", ptr);
 	report_status(string);
 	free(string);
 }
@@ -181,6 +184,19 @@
  * Report a string of chtype back to the director via the command pipe.
  */
 void
+report_byte(chtype c)
+{
+	chtype string[2];
+
+	string[0] = c;
+	string[1] = A_NORMAL | '\0';
+	report_nstr(string);
+}
+
+/*
+ * Report a string of chtype back to the director via the command pipe.
+ */
+void
 report_nstr(chtype *string)
 {
 	int len, type;
@@ -193,6 +209,9 @@
 		len++;
 	}
 
+	len++; /* add in the termination chtype */
+	len *= sizeof(chtype);
+
 	type = ret_byte;
 	if (write(slvpipe[WRITE_PIPE], &type, sizeof(int)) < 0)
 		err(1, "%s: command pipe write for status type failed",

Index: src/tests/lib/libcurses/slave/curses_commands.c
diff -u src/tests/lib/libcurses/slave/curses_commands.c:1.5 src/tests/lib/libcurses/slave/curses_commands.c:1.6
--- src/tests/lib/libcurses/slave/curses_commands.c:1.5	Mon Aug 29 12:46:03 2011
+++ src/tests/lib/libcurses/slave/curses_commands.c	Thu Sep 15 11:46:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: curses_commands.c,v 1.5 2011/08/29 12:46:03 christos Exp $	*/
+/*	$NetBSD: curses_commands.c,v 1.6 2011/09/15 11:46:19 blymn Exp $	*/
 
 /*-
  * Copyright 2009 Brett Lymn <[email protected]>
@@ -209,13 +209,13 @@
 
 	if (sscanf(args[0], "%d", &attrib) == 0) {
 		report_count(1);
-	report_error("BAD ARGUMENT");
+		report_error("BAD ARGUMENT");
 		return;
 	}
 
 	if (sscanf(args[1], "%hd", &pair) == 0) {
 		report_count(1);
-	report_error("BAD ARGUMENT");
+		report_error("BAD ARGUMENT");
 		return;
 	}
 
@@ -525,7 +525,7 @@
 
 
 	report_count(1);
-	report_int(inch());
+	report_byte(inch());
 }
 
 
@@ -563,7 +563,7 @@
 {
 	chtype string[256];
 
-	if (check_arg_count(nargs, 1) == 1)
+	if (check_arg_count(nargs, 0) == 1)
 		return;
 
 	/* XXX call2 */
@@ -596,7 +596,7 @@
 
 	/* XXX call2 */
 	report_count(2);
-	report_return(innstr(string, limit));
+	report_int(innstr(string, limit));
 	report_status(string);
 	free(string);
 }
@@ -648,7 +648,7 @@
 {
 	char string[256];
 
-	if (check_arg_count(nargs, 1) == 1)
+	if (check_arg_count(nargs, 0) == 1)
 		return;
 
 	/* XXX call2 */
@@ -882,6 +882,7 @@
 cmd_mvaddch(int nargs, char **args)
 {
 	int y, x;
+	chtype *ch;
 
 	if (check_arg_count(nargs, 3) == 1)
 		return;
@@ -898,8 +899,9 @@
 		return;
 	}
 
+	ch = (chtype *) args[2];
 	report_count(1);
-	report_return(mvaddch(y, x, args[2][0]));
+	report_return(mvaddch(y, x, ch[0]));
 }
 
 
@@ -1791,7 +1793,7 @@
 		return;
 
 	report_count(1);
-	report_int(beep());
+	report_return(beep());
 }
 
 
@@ -2179,14 +2181,14 @@
 		return;
 
 	report_count(1);
-	report_return(erasechar());
+	report_int(erasechar());
 }
 
 
 void
 cmd_flash(int nargs, char **args)
 {
-	if (check_arg_count(nargs, 1) == 0)
+	if (check_arg_count(nargs, 0) == 1)
 		return;
 
 	report_count(1);
@@ -2280,7 +2282,7 @@
 	}
 
 	report_count(1);
-	report_int(getbkgd(win));
+	report_byte(getbkgd(win));
 }
 
 
@@ -2323,6 +2325,28 @@
 
 
 void
+cmd_getyx(int nargs, char **args)
+{
+	WINDOW *win;
+	int y, x;
+
+	if (check_arg_count(nargs, 1) == 1)
+		return;
+
+	if (sscanf(args[0], "%p", &win) == 0) {
+		report_count(1);
+		report_error("BAD ARGUMENT");
+		return;
+	}
+
+	getyx(win, y, x);
+	report_count(2);
+	report_int(y);
+	report_int(x);
+}
+
+
+void
 cmd_getbegy(int nargs, char **args)
 {
 	WINDOW *win;
@@ -2437,6 +2461,28 @@
 
 
 void
+cmd_getparyx(int nargs, char **args)
+{
+	WINDOW *win;
+	int y, x;
+
+	if (check_arg_count(nargs, 1) == 1)
+		return;
+
+	if (sscanf(args[0], "%p", &win) == 0) {
+		report_count(1);
+		report_error("BAD ARGUMENT");
+		return;
+	}
+
+	report_count(2);
+	getparyx(win, y, x);
+	report_int(y);
+	report_int(x);
+}
+
+
+void
 cmd_gettmode(int nargs, char **args)
 {
 	if (check_arg_count(nargs, 0) == 1)
@@ -2522,16 +2568,13 @@
 void
 cmd_hline(int nargs, char **args)
 {
-	int ch, count;
+	int count;
+	chtype *ch;
 
 	if (check_arg_count(nargs, 2) == 1)
 		return;
 
-	if (sscanf(args[0], "%d", &ch) == 0) {
-		report_count(1);
-		report_error("BAD ARGUMENT");
-		return;
-	}
+	ch = (chtype *) args[0];
 
 	if (sscanf(args[1], "%d", &count) == 0) {
 		report_count(1);
@@ -2540,7 +2583,7 @@
 	}
 
 	report_count(1);
-	report_return(hline(ch, count));
+	report_return(hline(ch[0], count));
 }
 
 
@@ -2811,7 +2854,7 @@
 void
 cmd_keyname(int nargs, char **args)
 {
-	int key;
+	unsigned int key;
 
 	if (check_arg_count(nargs, 1) == 1)
 		return;
@@ -3529,13 +3572,13 @@
 		return;
 	}
 
-	if (sscanf(args[0], "%d", &begin_y) == 0) {
+	if (sscanf(args[2], "%d", &begin_y) == 0) {
 		report_count(1);
 		report_error("BAD ARGUMENT");
 		return;
 	}
 
-	if (sscanf(args[1], "%d", &begin_x) == 0) {
+	if (sscanf(args[3], "%d", &begin_x) == 0) {
 		report_count(1);
 		report_error("BAD ARGUMENT");
 		return;
@@ -4485,7 +4528,7 @@
 cmd_waddch(int nargs, char **args)
 {
 	WINDOW *win;
-	int ch;
+	chtype *ch;
 
 	if (check_arg_count(nargs, 2) == 1)
 		return;
@@ -4496,14 +4539,10 @@
 		return;
 	}
 
-	if (sscanf(args[1], "%d", &ch) == 0) {
-		report_count(1);
-		report_error("BAD ARGUMENT");
-		return;
-	}
+	ch = (chtype *) args[1];
 
 	report_count(1);
-	report_return(waddch(win, ch));
+	report_return(waddch(win, ch[0]));
 }
 
 
@@ -5990,7 +6029,8 @@
 cmd_wchgat(int nargs, char **args)
 {
 	WINDOW *win;
-	int n, attr, colour;
+	int n, attr;
+	short colour;
 
 	if (check_arg_count(nargs, 4) == 1)
 		return;
@@ -6013,7 +6053,7 @@
 		return;
 	}
 
-	if (sscanf(args[3], "%d", &colour) == 0) {
+	if (sscanf(args[3], "%hd", &colour) == 0) {
 		report_count(1);
 		report_error("BAD ARGUMENT");
 		return;
@@ -6027,12 +6067,10 @@
 void
 cmd_mvchgat(int nargs, char **args)
 {
-	if (check_arg_count(nargs, 5) == 1)
-		return;
-
-	int y, x, n, attr, colour;
+	int y, x, n, attr;
+	short colour;
 
-	if (check_arg_count(nargs, 3) == 1)
+	if (check_arg_count(nargs, 6) == 1)
 		return;
 
 	if (sscanf(args[0], "%d", &y) == 0) {
@@ -6059,7 +6097,7 @@
 		return;
 	}
 
-	if (sscanf(args[4], "%d", &colour) == 0) {
+	if (sscanf(args[4], "%hd", &colour) == 0) {
 		report_count(1);
 		report_error("BAD ARGUMENT");
 		return;
@@ -6916,7 +6954,7 @@
 
 	if (sscanf(args[0], "%d", &w) == 0) {
 		report_count(1);
-	report_error("BAD ARGUMENT");
+		report_error("BAD ARGUMENT");
 		return;
 	}
 
Index: src/tests/lib/libcurses/slave/slave.c
diff -u src/tests/lib/libcurses/slave/slave.c:1.5 src/tests/lib/libcurses/slave/slave.c:1.6
--- src/tests/lib/libcurses/slave/slave.c:1.5	Fri Jun 17 02:15:28 2011
+++ src/tests/lib/libcurses/slave/slave.c	Thu Sep 15 11:46:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: slave.c,v 1.5 2011/06/17 02:15:28 christos Exp $	*/
+/*	$NetBSD: slave.c,v 1.6 2011/09/15 11:46:19 blymn Exp $	*/
 
 /*-
  * Copyright 2009 Brett Lymn <[email protected]>
@@ -84,7 +84,6 @@
 		if (read(cmdpipe[READ_PIPE], cmdbuf, len) < 0)
 			err(1, "slave command read failed");
 		cmdbuf[len] = '\0';
-
 		argslen = 0;
 		args = NULL;
 
@@ -103,12 +102,13 @@
 					    "failed");
 
 				args = tmpargs;
-				if (type != ret_null)
+				if (type != ret_null) {
 					args[argslen] = malloc(len + 1);
 
-				if (args[argslen] == NULL)
-					err(1, "slave alloc of %d bytes for"
-					    " args failed", len);
+					if (args[argslen] == NULL)
+						err(1, "slave alloc of %d bytes"
+						    " for args failed", len);
+				}
 
 				if (len == 0) {
 					if (type == ret_null)
@@ -141,7 +141,6 @@
 		}
 		while(len >= 0);
 
-
 		command_execute(cmdbuf, argslen, args);
 
 		if (args != NULL) {

Reply via email to