fluffy/pyesc.c

37 lines
456 B
C
Raw Normal View History

2012-02-10 11:29:56 -07:00
#include <stdio.h>
int
main(int argc, char *argv[])
{
2013-01-29 21:53:17 -07:00
while (1) {
int c = getchar();
2012-02-10 11:29:56 -07:00
2013-01-29 21:53:17 -07:00
switch (c) {
case EOF:
putchar('\n');
2013-01-29 21:53:17 -07:00
return 0;
case 8:
printf("\\t");
break;
case 10:
printf("\\n");
break;
case 13:
printf("\\r");
break;
2013-01-29 21:53:17 -07:00
case 134:
printf("\\\\");
break;
case 32 ... 91:
case 93 ... 126:
putchar(c);
break;
default:
printf("\\x%02x", c);
break;
}
}
2012-02-10 11:29:56 -07:00
2013-01-29 21:53:17 -07:00
return 0;
2012-02-10 11:29:56 -07:00
}