comparison rvinterf/lowlevel/format.c @ 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 e7502631a0f9
children 85d144f9fe56
comparison
equal deleted inserted replaced
923:804aaac0b53d 924:d452188587b4
32 /* severity level */ 32 /* severity level */
33 sprintf(dp, " %d ", rxpkt[5]); 33 sprintf(dp, " %d ", rxpkt[5]);
34 dp = index(dp, '\0'); 34 dp = index(dp, '\0');
35 for (i = 6; i < rxpkt_len; i++) { 35 for (i = 6; i < rxpkt_len; i++) {
36 c = rxpkt[i]; 36 c = rxpkt[i];
37 if (c & 0x80) { 37 switch (c) {
38 *dp++ = 'M'; 38 case '\\':
39 *dp++ = '-'; 39 *dp++ = '\\';
40 c &= 0x7F; 40 *dp++ = '\\';
41 continue;
42 case '\r':
43 *dp++ = '\\';
44 *dp++ = 'r';
45 continue;
46 case '\n':
47 *dp++ = '\\';
48 *dp++ = 'n';
49 continue;
41 } 50 }
42 if (c < 0x20) { 51 if (c >= ' ' && c <= '~')
43 *dp++ = '^';
44 *dp++ = c + '@';
45 } else if (c == 0x7F) {
46 *dp++ = '^';
47 *dp++ = '?';
48 } else
49 *dp++ = c; 52 *dp++ = c;
53 else if (c <= 7 && (i+1 == rxpkt_len || !isdigit(rxpkt[i+1]))) {
54 sprintf(dp, "\\%d", c);
55 dp += 2;
56 } else {
57 sprintf(dp, "\\x%02X", c);
58 dp += 4;
59 }
50 } 60 }
51 *dp = '\0'; 61 *dp = '\0';
52 output_line(fmtbuf); 62 output_line(fmtbuf);
53 } 63 }
54 64
74 *dp++ = ' '; 84 *dp++ = ' ';
75 i++; 85 i++;
76 continue; 86 continue;
77 } 87 }
78 c = rxpkt[i]; 88 c = rxpkt[i];
79 if (c & 0x80) { 89 switch (c) {
80 *dp++ = 'M'; 90 case '\\':
81 *dp++ = '-'; 91 *dp++ = '\\';
82 c &= 0x7F; 92 *dp++ = '\\';
93 continue;
94 case '\r':
95 *dp++ = '\\';
96 *dp++ = 'r';
97 continue;
98 case '\n':
99 *dp++ = '\\';
100 *dp++ = 'n';
101 continue;
83 } 102 }
84 if (c < 0x20) { 103 if (c >= ' ' && c <= '~')
85 *dp++ = '^';
86 *dp++ = c + '@';
87 } else if (c == 0x7F) {
88 *dp++ = '^';
89 *dp++ = '?';
90 } else
91 *dp++ = c; 104 *dp++ = c;
105 else if (c <= 7 && (i+1 == rxpkt_len || !isdigit(rxpkt[i+1]))) {
106 sprintf(dp, "\\%d", c);
107 dp += 2;
108 } else {
109 sprintf(dp, "\\x%02X", c);
110 dp += 4;
111 }
92 } 112 }
93 /* will get here only if no newline sequence at the end */ 113 /* will get here only if no newline sequence at the end */
94 *dp = '\0'; 114 *dp = '\0';
95 output_line(fmtbuf); 115 output_line(fmtbuf);
96 } 116 }