xref: /plan9/sys/src/liblex/allprint.c (revision 219b2ee8daee37f4aad58d63f21287faa8e4ffdc)
1 #include	<u.h>
2 #include	<libc.h>
3 #include	<stdio.h>
4 
5 extern	FILE*	yyout;
6 
7 int
8 printable(int c)
9 {
10 	return 040 < c && c < 0177;
11 }
12 
13 void
14 allprint(char c)
15 {
16 
17 	switch(c) {
18 	case '\n':
19 		fprintf(yyout,"\\n");
20 		break;
21 	case '\t':
22 		fprintf(yyout,"\\t");
23 		break;
24 	case '\b':
25 		fprintf(yyout,"\\b");
26 		break;
27 	case ' ':
28 		fprintf(yyout,"\\\bb");
29 		break;
30 	default:
31 		if(!printable(c))
32 			fprintf(yyout,"\\%-3o",c);
33 		else
34 			c = putc(c,yyout);
35 			USED(c);
36 		break;
37 	}
38 	return;
39 }
40