# HG changeset patch # User Mychaela Falconia # Date 1684811450 0 # Node ID d452188587b4f703ecf408d4c1d19ab87bd5c7d2 # Parent 804aaac0b53d4e5cbb3ef258e3b3da654b8d2c91 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. diff -r 804aaac0b53d -r d452188587b4 rvinterf/lowlevel/format.c --- 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';