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

wicontrol patch



    Here is a small patch against sbin/wicontrol/wicontrol.c to handle 
weird non printable characters. Some wi cards have Ctl-XX or \n
characters into fields.

Thanks.

-- 
oc
--- wicontrol_orig.c	Fri Sep 24 14:37:24 2004
+++ wicontrol.c	Fri Oct  1 14:48:51 2004
@@ -60,6 +60,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <stdlib.h>
+#include <vis.h>
 #include <unistd.h>
 #include <errno.h>
 #include <err.h>
@@ -153,29 +154,23 @@
 void
 wi_printstr(struct wi_req *wreq)
 {
-	char			*ptr;
-	int			i, max;
+	char		*ptr = NULL, *visptr = NULL;
+	int			visrtrn;
 
 	if (wreq->wi_type == WI_RID_SERIALNO) {
 		ptr = (char *)&wreq->wi_val;
-		max = MIN(sizeof(wreq->wi_val) - 1, (wreq->wi_len - 1) * 2);
-		for (i = 0; i < max; i++) {
-			if (ptr[i] == '\0')
-				ptr[i] = ' ';
-		}
+		if ((visptr = malloc( 4 * strlen(ptr) + 1 )) == NULL)
+			err(1, NULL);
+		visrtrn = strvisx(visptr, ptr, strlen(ptr), VIS_WHITE | VIS_SAFE);
 	} else {
-		int len = letoh16(wreq->wi_val[0]);
-
 		ptr = (char *)&wreq->wi_val[1];
-		max = MIN(sizeof(wreq->wi_val) - 1, len);
-		for (i = 0; i < max; i++) {
-			if (ptr[i] == '\0')
-				ptr[i] = ' ';
-		}
+		if ((visptr = malloc( 4 * strlen(ptr) + 1 )) == NULL)
+			err(1, NULL);
+		visrtrn = strvisx(visptr, ptr, MIN(sizeof(wreq->wi_val) - 1,
+			letoh16(wreq->wi_val[0])), VIS_TAB | VIS_NL | VIS_SAFE);
 	}
-
-	ptr[i] = '\0';
-	printf("[ %s ]", ptr);
+	printf("[ %s ]", visptr);
+	free(visptr);
 }
 
 void