changeset 924:d452188587b4

rvinterf: begin change to backslash escape output format Right now throughout the rvinterf suite, any time we emit output that is expected to be ASCII, but may contain non-printable garbage, we use 'cat -v' form of garbage character representation. Unfortunately, this transformation is lossy (can't be reversed 100% reliably in the user's wetware), hence we would like to migrate to C-style backslash escapes, including doubling of any already-present backslashes - this escape mechanism is lossless. Begin this change by converting the output of RV and L1 traces in rvinterf and rvtdump.
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 23 May 2023 03:10:50 +0000
parents 804aaac0b53d
children 85d144f9fe56
files rvinterf/lowlevel/format.c
diffstat 1 files changed, 42 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/lowlevel/format.c	Mon Jan 02 01:06:03 2023 +0000
+++ b/rvinterf/lowlevel/format.c	Tue May 23 03:10:50 2023 +0000
@@ -34,19 +34,29 @@
 	dp = index(dp, '\0');
 	for (i = 6; i < rxpkt_len; i++) {
 		c = rxpkt[i];
-		if (c & 0x80) {
-			*dp++ = 'M';
-			*dp++ = '-';
-			c &= 0x7F;
+		switch (c) {
+		case '\\':
+			*dp++ = '\\';
+			*dp++ = '\\';
+			continue;
+		case '\r':
+			*dp++ = '\\';
+			*dp++ = 'r';
+			continue;
+		case '\n':
+			*dp++ = '\\';
+			*dp++ = 'n';
+			continue;
 		}
-		if (c < 0x20) {
-			*dp++ = '^';
-			*dp++ = c + '@';
-		} else if (c == 0x7F) {
-			*dp++ = '^';
-			*dp++ = '?';
-		} else
+		if (c >= ' ' && c <= '~')
 			*dp++ = c;
+		else if (c <= 7 && (i+1 == rxpkt_len || !isdigit(rxpkt[i+1]))) {
+			sprintf(dp, "\\%d", c);
+			dp += 2;
+		} else {
+			sprintf(dp, "\\x%02X", c);
+			dp += 4;
+		}
 	}
 	*dp = '\0';
 	output_line(fmtbuf);
@@ -76,19 +86,29 @@
 			continue;
 		}
 		c = rxpkt[i];
-		if (c & 0x80) {
-			*dp++ = 'M';
-			*dp++ = '-';
-			c &= 0x7F;
+		switch (c) {
+		case '\\':
+			*dp++ = '\\';
+			*dp++ = '\\';
+			continue;
+		case '\r':
+			*dp++ = '\\';
+			*dp++ = 'r';
+			continue;
+		case '\n':
+			*dp++ = '\\';
+			*dp++ = 'n';
+			continue;
 		}
-		if (c < 0x20) {
-			*dp++ = '^';
-			*dp++ = c + '@';
-		} else if (c == 0x7F) {
-			*dp++ = '^';
-			*dp++ = '?';
-		} else
+		if (c >= ' ' && c <= '~')
 			*dp++ = c;
+		else if (c <= 7 && (i+1 == rxpkt_len || !isdigit(rxpkt[i+1]))) {
+			sprintf(dp, "\\%d", c);
+			dp += 2;
+		} else {
+			sprintf(dp, "\\x%02X", c);
+			dp += 4;
+		}
 	}
 	/* will get here only if no newline sequence at the end */
 	*dp = '\0';