diff options
| author | Julian Blake Kongslie | 2022-05-29 16:37:06 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-05-29 16:37:06 -0700 |
| commit | 016d38f42584cf2e54de279e4948a9168028aff2 (patch) | |
| tree | 517df817d165aedf8b9e8877d2e8c2450a2c182e /tool/con.c | |
| parent | Add extremely sus speedy-download tool which might have made Mike's FTDI (diff) | |
| download | multipdp8-016d38f42584cf2e54de279e4948a9168028aff2.tar.xz | |
Tweak con script to do CRLF translation on received stream.
Diffstat (limited to '')
| -rw-r--r-- | tool/con.c | 33 |
1 files changed, 23 insertions, 10 deletions
| @@ -1,4 +1,5 @@ | |||
| 1 | /* con device */ | 1 | /* con device */ |
| 2 | /* vim: set noexpandtab sw=8 : */ | ||
| 2 | 3 | ||
| 3 | #include <signal.h> | 4 | #include <signal.h> |
| 4 | #include <stdio.h> | 5 | #include <stdio.h> |
| @@ -14,24 +15,27 @@ void | |||
| 14 | host(int fd) | 15 | host(int fd) |
| 15 | { | 16 | { |
| 16 | int cc; | 17 | int cc; |
| 17 | char buf[128]; | 18 | char buf; |
| 19 | #ifndef HEX | ||
| 20 | char last = '\r'; | ||
| 21 | #endif | ||
| 18 | 22 | ||
| 19 | for (;;) { | 23 | for (;;) { |
| 20 | cc = read(fd, buf, sizeof buf); | 24 | cc = read(fd, &buf, 1); |
| 21 | #ifdef HEX | ||
| 22 | if (cc < 0) | 25 | if (cc < 0) |
| 23 | break; | 26 | break; |
| 24 | for (int i = 0; i < cc; ++i) { | 27 | if (cc) { |
| 28 | #ifdef HEX | ||
| 25 | char hex[3]; | 29 | char hex[3]; |
| 26 | sprintf(hex, "%02X", (unsigned char) buf[i]); | 30 | sprintf(hex, "%02X", (unsigned char) buf); |
| 27 | write(1, hex, 2); | 31 | write(1, hex, 2); |
| 28 | } | ||
| 29 | #else | 32 | #else |
| 30 | if (cc > 0) | 33 | if (buf == '\n' && last != '\r') |
| 31 | write(1, buf, cc); | 34 | write(1, "\r", 1); |
| 32 | else if (cc < 0) | 35 | write(1, &buf, 1); |
| 33 | break; | 36 | last = buf; |
| 34 | #endif | 37 | #endif |
| 38 | } | ||
| 35 | } | 39 | } |
| 36 | } | 40 | } |
| 37 | 41 | ||
| @@ -57,6 +61,15 @@ user(int fd) | |||
| 57 | if (c == '.') | 61 | if (c == '.') |
| 58 | return; | 62 | return; |
| 59 | } | 63 | } |
| 64 | #ifdef HEX | ||
| 65 | char hex[5]; | ||
| 66 | sprintf(hex, "<%02X>", (unsigned char) c); | ||
| 67 | write(1, hex, 4); | ||
| 68 | #endif | ||
| 69 | #ifdef SEND_CRLF | ||
| 70 | if (c == '\n' && last != '\r') | ||
| 71 | write(fd, "\r", 1); | ||
| 72 | #endif | ||
| 60 | write(fd, &c, 1); | 73 | write(fd, &c, 1); |
| 61 | last = c; | 74 | last = c; |
| 62 | } | 75 | } |
