changeset 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 6a0aa8d36d06
children 65953c172f24
files rvinterf/lowlevel/Makefile rvinterf/lowlevel/format.c rvinterf/lowlevel/format_fc.c rvinterf/lowlevel/logsent.c
diffstat 4 files changed, 8 insertions(+), 95 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/lowlevel/Makefile	Tue May 23 03:47:46 2023 +0000
+++ b/rvinterf/lowlevel/Makefile	Tue May 23 03:59:42 2023 +0000
@@ -1,7 +1,7 @@
 CC=	gcc
 CFLAGS=	-O2
 PROGS=	rvtdump rvinterf tfc139
-LIBS=	../../libserial/libserial.a ../libg23/libg23.a
+LIBS=	../../libserial/libserial.a ../libg23/libg23.a ../libprint/libprint.a
 LIBPWON=../../libpwon/libpwon.a
 
 INSTALL_PREFIX=	/opt/freecalypso
--- a/rvinterf/lowlevel/format.c	Tue May 23 03:47:46 2023 +0000
+++ b/rvinterf/lowlevel/format.c	Tue May 23 03:59:42 2023 +0000
@@ -19,7 +19,7 @@
 void
 print_rv_trace()
 {
-	int i, c;
+	int i;
 	char *dp;
 
 	dp = fmtbuf;
@@ -33,33 +33,7 @@
 	/* severity level */
 	sprintf(dp, " %d ", rxpkt[5]);
 	dp = index(dp, '\0');
-	for (i = 6; i < rxpkt_len; i++) {
-		c = rxpkt[i];
-		switch (c) {
-		case '\\':
-			*dp++ = '\\';
-			*dp++ = '\\';
-			continue;
-		case '\r':
-			*dp++ = '\\';
-			*dp++ = 'r';
-			continue;
-		case '\n':
-			*dp++ = '\\';
-			*dp++ = 'n';
-			continue;
-		}
-		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';
+	safe_print_trace(rxpkt + 6, rxpkt_len - 6, dp);
 	output_line(fmtbuf);
 }
 
--- a/rvinterf/lowlevel/format_fc.c	Tue May 23 03:47:46 2023 +0000
+++ b/rvinterf/lowlevel/format_fc.c	Tue May 23 03:59:42 2023 +0000
@@ -18,58 +18,16 @@
 void
 print_ati_output()
 {
-	int i, c;
-	char *dp;
-
-	dp = fmtbuf;
-	strcpy(dp, "ATI: ");
-	dp += 5;
-	for (i = 1; i < rxpkt_len; i++) {
-		c = rxpkt[i];
-		if (c & 0x80) {
-			*dp++ = 'M';
-			*dp++ = '-';
-			c &= 0x7F;
-		}
-		if (c < 0x20) {
-			*dp++ = '^';
-			*dp++ = c + '@';
-		} else if (c == 0x7F) {
-			*dp++ = '^';
-			*dp++ = '?';
-		} else
-			*dp++ = c;
-	}
-	*dp = '\0';
+	strcpy(fmtbuf, "ATI: ");
+	safe_print_trace(rxpkt + 1, rxpkt_len - 1, fmtbuf + 5);
 	output_line(fmtbuf);
 }
 
 void
 print_fc_lld_msg()
 {
-	int i, c;
-	char *dp;
-
-	dp = fmtbuf;
-	strcpy(dp, "LLD: ");
-	dp += 5;
-	for (i = 1; i < rxpkt_len; i++) {
-		c = rxpkt[i];
-		if (c & 0x80) {
-			*dp++ = 'M';
-			*dp++ = '-';
-			c &= 0x7F;
-		}
-		if (c < 0x20) {
-			*dp++ = '^';
-			*dp++ = c + '@';
-		} else if (c == 0x7F) {
-			*dp++ = '^';
-			*dp++ = '?';
-		} else
-			*dp++ = c;
-	}
-	*dp = '\0';
+	strcpy(fmtbuf, "LLD: ");
+	safe_print_trace(rxpkt + 1, rxpkt_len - 1, fmtbuf + 5);
 	output_line(fmtbuf);
 }
 
--- a/rvinterf/lowlevel/logsent.c	Tue May 23 03:47:46 2023 +0000
+++ b/rvinterf/lowlevel/logsent.c	Tue May 23 03:59:42 2023 +0000
@@ -17,28 +17,9 @@
 	u_char *pkt;
 {
 	char buf[MAX_PKT_TO_TARGET*4+10];
-	int i, c;
-	char *dp;
 
 	strcpy(buf, "Sent to ATI: ");
-	dp = buf + 13;
-	for (i = 1; i < pktlen; i++) {
-		c = pkt[i];
-		if (c & 0x80) {
-			*dp++ = 'M';
-			*dp++ = '-';
-			c &= 0x7F;
-		}
-		if (c < 0x20) {
-			*dp++ = '^';
-			*dp++ = c + '@';
-		} else if (c == 0x7F) {
-			*dp++ = '^';
-			*dp++ = '?';
-		} else
-			*dp++ = c;
-	}
-	*dp = '\0';
+	safe_print_trace(pkt + 1, pktlen - 1, buf + 13);
 	output_line(buf);
 }