# HG changeset patch # User Mychaela Falconia # Date 1684813666 0 # Node ID 6a0aa8d36d06348e4298e838839c8a8e22df71c7 # Parent 85d144f9fe569d9db3755f75396a42a6c7fe032e rvinterf backslash escape: introduce libprint The new helper function library named libprint is meant to replace the badly misnamed libg23, and will soon contain functions for printing all of the same kinds of GPF TST packets that are now handled in libg23. However, we are also moving safe_print_trace() from libasync to this new library, and changing it to emit our new backslash escape format. diff -r 85d144f9fe56 -r 6a0aa8d36d06 rvinterf/Makefile --- a/rvinterf/Makefile Tue May 23 03:21:02 2023 +0000 +++ b/rvinterf/Makefile Tue May 23 03:47:46 2023 +0000 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 PROGDIR=asyncshell ctracedec etmsync l1filter lowlevel rvtat tmsh -LIBDIR= libasync libg23 libinterf +LIBDIR= libasync libg23 libinterf libprint SUBDIR= ${PROGDIR} ${LIBDIR} INSTALL_PREFIX= /opt/freecalypso @@ -9,12 +9,12 @@ all: ${SUBDIR} -asyncshell: libasync libg23 libinterf +asyncshell: libasync libg23 libinterf libprint etmsync: libinterf l1filter: libinterf -lowlevel: libg23 +lowlevel: libg23 libprint rvtat: libinterf -tmsh: libasync libinterf +tmsh: libasync libinterf libprint ${SUBDIR}: FRC cd $@; ${MAKE} ${MFLAGS} CC=${CC} CFLAGS="${CFLAGS}" diff -r 85d144f9fe56 -r 6a0aa8d36d06 rvinterf/asyncshell/Makefile --- a/rvinterf/asyncshell/Makefile Tue May 23 03:21:02 2023 +0000 +++ b/rvinterf/asyncshell/Makefile Tue May 23 03:47:46 2023 +0000 @@ -5,7 +5,8 @@ OBJS= at.o battery.o help.o init.o keypress.o main.o oneshot.o parse.o \ pktsort.o poweroff.o rxctl.o sendarb.o sendsp.o tchcmd.o tchplay.o \ tchrec.o usercmd.o -LIBS= ../libasync/libasync.a ../libg23/libg23.a ../libinterf/libinterf.a +LIBS= ../libasync/libasync.a ../libg23/libg23.a ../libprint/libprint.a \ + ../libinterf/libinterf.a INSTALL_PREFIX= /opt/freecalypso diff -r 85d144f9fe56 -r 6a0aa8d36d06 rvinterf/libasync/rvtrace.c --- a/rvinterf/libasync/rvtrace.c Tue May 23 03:21:02 2023 +0000 +++ b/rvinterf/libasync/rvtrace.c Tue May 23 03:47:46 2023 +0000 @@ -15,34 +15,6 @@ extern int rvi_msg_len; void -safe_print_trace(src, srclen, dest) - u_char *src; - char *dest; -{ - int i, c; - char *dp; - - dp = dest; - for (i = 0; i < srclen; i++) { - c = src[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'; -} - -void handle_useid_0() { char buf[MAX_PKT_FROM_TARGET*4]; diff -r 85d144f9fe56 -r 6a0aa8d36d06 rvinterf/libprint/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/libprint/Makefile Tue May 23 03:47:46 2023 +0000 @@ -0,0 +1,13 @@ +CC= gcc +CFLAGS= -O2 +OBJS= back_esc.o +LIB= libprint.a + +all: ${LIB} + +${LIB}: ${OBJS} + ar rcu $@ ${OBJS} + ranlib $@ + +clean: + rm -f *.[oa] errs diff -r 85d144f9fe56 -r 6a0aa8d36d06 rvinterf/libprint/back_esc.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/libprint/back_esc.c Tue May 23 03:47:46 2023 +0000 @@ -0,0 +1,48 @@ +/* + * The function implemented in this module prints a potentially-dirty string + * into a buffer with C-style backslash escapes, including doubling of any + * already-present backslashes. The output buffer must be sized for up to + * 4x expansion, plus the terminating NUL. + */ + +#include +#include +#include + +void +safe_print_trace(src, srclen, dest) + u_char *src; + char *dest; +{ + int i, c; + char *dp; + + dp = dest; + for (i = 0; i < srclen; i++) { + c = src[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 == srclen || !isdigit(src[i+1]))) { + sprintf(dp, "\\%d", c); + dp += 2; + } else { + sprintf(dp, "\\x%02X", c); + dp += 4; + } + } + *dp = '\0'; +} diff -r 85d144f9fe56 -r 6a0aa8d36d06 rvinterf/tmsh/Makefile --- a/rvinterf/tmsh/Makefile Tue May 23 03:21:02 2023 +0000 +++ b/rvinterf/tmsh/Makefile Tue May 23 03:47:46 2023 +0000 @@ -5,7 +5,7 @@ OBJS= abb.o abbtm3.o audiocmd.o audioresp.o bsimcmd.o bsimresp.o etmbasic.o \ ffs2.o ffs2resp.o init.o l1cmd.o l1resp.o main.o misc.o omr.o omw.o \ oneshot.o pktsort.o rftablechk.o saverftab.o tmcore.o usercmd.o -LIBS= ../libasync/libasync.a ../libinterf/libinterf.a \ +LIBS= ../libasync/libasync.a ../libprint/libprint.a ../libinterf/libinterf.a \ ../../librftab/librftab.a INSTALL_PREFIX= /opt/freecalypso