~vdupras/collapseos

ref: ac3629b817115b1af75096856ee9499cfbbd3392 collapseos/tools/ttysafe.c -rw-r--r-- 671 bytes
ac3629b8Virgil Dupras Make BLK@* and BLK!* into ialiases 1 year, 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdlib.h>
#include <stdio.h>

/* Converts stdin to a content that is "tty safe", that is, that it doesn't
 * contain ASCII control characters that can mess up serial communication.
 * How it works is that it leaves any char > 0x20 intact, but any char <= 0x20
 * is replaced by two chars: 0x20, then char|0x80. A 0x20 char always indicate
 * "take the next char you'll receive and unset the 7th bit from it".
 */

int main(void)
{
    int c = getchar();
    while (c != EOF) {
        if (c <= 0x20) {
            putchar(0x20);
            putchar(c|0x80);
        } else {
            putchar(c&0xff);
        }
        c = getchar();
    }
    return 0;
}