FreeCalypso > hg > freecalypso-sw
changeset 124:dfd3110d84e3
fc-[ix]ram: tty pass-thru mode made binary-safe
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Thu, 31 Oct 2013 06:56:31 +0000 |
parents | 595631eee4bc |
children | 17c1e2a38418 |
files | loadtools/ttypassthru.c |
diffstat | 1 files changed, 30 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/loadtools/ttypassthru.c Thu Oct 31 05:50:06 2013 +0000 +++ b/loadtools/ttypassthru.c Thu Oct 31 06:56:31 2013 +0000 @@ -20,6 +20,35 @@ static struct termios saved_termios, my_termios; static void +safe_output(buf, cc) + u_char *buf; +{ + int i, c; + + for (i = 0; i < cc; i++) { + c = buf[i]; + if (c == '\r' || c == '\n' || c == '\t' || c == '\b') { + putchar(c); + continue; + } + if (c & 0x80) { + putchar('M'); + putchar('-'); + c &= 0x7F; + } + if (c < 0x20) { + putchar('^'); + putchar(c + '@'); + } else if (c == 0x7F) { + putchar('^'); + putchar('?'); + } else + putchar(c); + } + fflush(stdout); +} + +static void loop() { char buf[BUFSIZ]; @@ -55,7 +84,7 @@ fprintf(stderr, "EOF/error on target tty\n"); exit(1); } - write(1, buf, cc); + safe_output(buf, cc); } } }