comparison loadtools/ttypassthru.c @ 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 e2e80a09338e
children
comparison
equal deleted inserted replaced
123:595631eee4bc 124:dfd3110d84e3
16 extern int errno; 16 extern int errno;
17 17
18 extern int target_fd; 18 extern int target_fd;
19 19
20 static struct termios saved_termios, my_termios; 20 static struct termios saved_termios, my_termios;
21
22 static void
23 safe_output(buf, cc)
24 u_char *buf;
25 {
26 int i, c;
27
28 for (i = 0; i < cc; i++) {
29 c = buf[i];
30 if (c == '\r' || c == '\n' || c == '\t' || c == '\b') {
31 putchar(c);
32 continue;
33 }
34 if (c & 0x80) {
35 putchar('M');
36 putchar('-');
37 c &= 0x7F;
38 }
39 if (c < 0x20) {
40 putchar('^');
41 putchar(c + '@');
42 } else if (c == 0x7F) {
43 putchar('^');
44 putchar('?');
45 } else
46 putchar(c);
47 }
48 fflush(stdout);
49 }
21 50
22 static void 51 static void
23 loop() 52 loop()
24 { 53 {
25 char buf[BUFSIZ]; 54 char buf[BUFSIZ];
53 if (cc <= 0) { 82 if (cc <= 0) {
54 tcsetattr(0, TCSAFLUSH, &saved_termios); 83 tcsetattr(0, TCSAFLUSH, &saved_termios);
55 fprintf(stderr, "EOF/error on target tty\n"); 84 fprintf(stderr, "EOF/error on target tty\n");
56 exit(1); 85 exit(1);
57 } 86 }
58 write(1, buf, cc); 87 safe_output(buf, cc);
59 } 88 }
60 } 89 }
61 } 90 }
62 91
63 tty_passthru() 92 tty_passthru()