2020-01-11 22:45:22 -05:00
|
|
|
#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
|
2020-02-22 14:11:43 -05:00
|
|
|
* 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".
|
2020-01-11 22:45:22 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
int c = getchar();
|
|
|
|
while (c != EOF) {
|
|
|
|
if (c <= 0x20) {
|
|
|
|
putchar(0x20);
|
2020-02-22 14:11:43 -05:00
|
|
|
putchar(c|0x80);
|
2020-01-11 22:45:22 -05:00
|
|
|
} else {
|
|
|
|
putchar(c&0xff);
|
|
|
|
}
|
|
|
|
c = getchar();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|