FreeCalypso > hg > freecalypso-tools
comparison rvinterf/lowlevel/format.c @ 927:4e243402f453
rvinterf/lowlevel: use libprint for backslash-escape output
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Tue, 23 May 2023 03:59:42 +0000 |
| parents | 85d144f9fe56 |
| children | 65953c172f24 |
comparison
equal
deleted
inserted
replaced
| 926:6a0aa8d36d06 | 927:4e243402f453 |
|---|---|
| 17 static char fmtbuf[MAX_PKT_FROM_TARGET*8]; /* size it generously */ | 17 static char fmtbuf[MAX_PKT_FROM_TARGET*8]; /* size it generously */ |
| 18 | 18 |
| 19 void | 19 void |
| 20 print_rv_trace() | 20 print_rv_trace() |
| 21 { | 21 { |
| 22 int i, c; | 22 int i; |
| 23 char *dp; | 23 char *dp; |
| 24 | 24 |
| 25 dp = fmtbuf; | 25 dp = fmtbuf; |
| 26 strcpy(dp, "RV "); | 26 strcpy(dp, "RV "); |
| 27 dp += 3; | 27 dp += 3; |
| 31 dp += 2; | 31 dp += 2; |
| 32 } | 32 } |
| 33 /* severity level */ | 33 /* severity level */ |
| 34 sprintf(dp, " %d ", rxpkt[5]); | 34 sprintf(dp, " %d ", rxpkt[5]); |
| 35 dp = index(dp, '\0'); | 35 dp = index(dp, '\0'); |
| 36 for (i = 6; i < rxpkt_len; i++) { | 36 safe_print_trace(rxpkt + 6, rxpkt_len - 6, dp); |
| 37 c = rxpkt[i]; | |
| 38 switch (c) { | |
| 39 case '\\': | |
| 40 *dp++ = '\\'; | |
| 41 *dp++ = '\\'; | |
| 42 continue; | |
| 43 case '\r': | |
| 44 *dp++ = '\\'; | |
| 45 *dp++ = 'r'; | |
| 46 continue; | |
| 47 case '\n': | |
| 48 *dp++ = '\\'; | |
| 49 *dp++ = 'n'; | |
| 50 continue; | |
| 51 } | |
| 52 if (c >= ' ' && c <= '~') | |
| 53 *dp++ = c; | |
| 54 else if (c <= 7 && (i+1 == rxpkt_len || !isdigit(rxpkt[i+1]))) { | |
| 55 sprintf(dp, "\\%d", c); | |
| 56 dp += 2; | |
| 57 } else { | |
| 58 sprintf(dp, "\\x%02X", c); | |
| 59 dp += 4; | |
| 60 } | |
| 61 } | |
| 62 *dp = '\0'; | |
| 63 output_line(fmtbuf); | 37 output_line(fmtbuf); |
| 64 } | 38 } |
| 65 | 39 |
| 66 void | 40 void |
| 67 print_l1_trace() | 41 print_l1_trace() |
