From 016d38f42584cf2e54de279e4948a9168028aff2 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sun, 29 May 2022 16:37:06 -0700 Subject: Tweak con script to do CRLF translation on received stream. --- tool/con.c | 33 +++++++++++++++++++++++---------- tool/download.tcl | 6 ++++-- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/tool/con.c b/tool/con.c index 8522786..92014e5 100644 --- a/tool/con.c +++ b/tool/con.c @@ -1,4 +1,5 @@ /* con device */ +/* vim: set noexpandtab sw=8 : */ #include #include @@ -14,24 +15,27 @@ void host(int fd) { int cc; - char buf[128]; + char buf; +#ifndef HEX + char last = '\r'; +#endif for (;;) { - cc = read(fd, buf, sizeof buf); -#ifdef HEX + cc = read(fd, &buf, 1); if (cc < 0) break; - for (int i = 0; i < cc; ++i) { + if (cc) { +#ifdef HEX char hex[3]; - sprintf(hex, "%02X", (unsigned char) buf[i]); + sprintf(hex, "%02X", (unsigned char) buf); write(1, hex, 2); - } #else - if (cc > 0) - write(1, buf, cc); - else if (cc < 0) - break; + if (buf == '\n' && last != '\r') + write(1, "\r", 1); + write(1, &buf, 1); + last = buf; #endif + } } } @@ -57,6 +61,15 @@ user(int fd) if (c == '.') return; } +#ifdef HEX + char hex[5]; + sprintf(hex, "<%02X>", (unsigned char) c); + write(1, hex, 4); +#endif +#ifdef SEND_CRLF + if (c == '\n' && last != '\r') + write(fd, "\r", 1); +#endif write(fd, &c, 1); last = c; } diff --git a/tool/download.tcl b/tool/download.tcl index c0dca55..96fc03b 100755 --- a/tool/download.tcl +++ b/tool/download.tcl @@ -14,11 +14,13 @@ if {$::argc > 1} { spawn tool/connect -send "@[format %x [expr $core * 32768 / $wordsperline]]\n" +set atline "@[format %x [expr $core * 32768 / $wordsperline]]" +send "$atline\n" +expect -ex "$atline\r\n" while {[gets stdin line] >= 0} { send "$line\n" - expect -ex "$line\n" + expect -ex "$line\r\n" } # It's likely we ended with a very large zero-memory operation. We want to see -- cgit v1.2.3