Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
671B

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. /* Converts stdin to a content that is "tty safe", that is, that it doesn't
  4. * contain ASCII control characters that can mess up serial communication.
  5. * How it works is that it leaves any char > 0x20 intact, but any char <= 0x20
  6. * is replaced by two chars: 0x20, then char|0x80. A 0x20 char always indicate
  7. * "take the next char you'll receive and unset the 7th bit from it".
  8. */
  9. int main(void)
  10. {
  11. int c = getchar();
  12. while (c != EOF) {
  13. if (c <= 0x20) {
  14. putchar(0x20);
  15. putchar(c|0x80);
  16. } else {
  17. putchar(c&0xff);
  18. }
  19. c = getchar();
  20. }
  21. return 0;
  22. }