allprint.c 870 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <libl.h>
  10. #include <stdio.h>
  11. extern FILE* yyout;
  12. int
  13. printable(int c)
  14. {
  15. return 040 < c && c < 0177;
  16. }
  17. void
  18. allprint(char c)
  19. {
  20. switch(c) {
  21. case '\n':
  22. fprintf(yyout,"\\n");
  23. break;
  24. case '\t':
  25. fprintf(yyout,"\\t");
  26. break;
  27. case '\b':
  28. fprintf(yyout,"\\b");
  29. break;
  30. case ' ':
  31. fprintf(yyout,"\\\bb");
  32. break;
  33. default:
  34. if(!printable(c))
  35. fprintf(yyout,"\\%-3o",c);
  36. else
  37. c = putc(c,yyout);
  38. USED(c);
  39. break;
  40. }
  41. return;
  42. }