allprint.c 902 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 "../cmd/lex/ldefs.h"
  10. //#include <ldefs.h>
  11. #include <stdio.h>
  12. extern FILE* yyout;
  13. int
  14. printable(int c)
  15. {
  16. return 040 < c && c < 0177;
  17. }
  18. void
  19. allprint(int c)
  20. {
  21. switch(c) {
  22. case '\n':
  23. fprintf(yyout,"\\n");
  24. break;
  25. case '\t':
  26. fprintf(yyout,"\\t");
  27. break;
  28. case '\b':
  29. fprintf(yyout,"\\b");
  30. break;
  31. case ' ':
  32. fprintf(yyout,"\\\bb");
  33. break;
  34. default:
  35. if(!printable(c))
  36. fprintf(yyout,"\\%-3o",c);
  37. else
  38. c = putc(c,yyout);
  39. USED(c);
  40. break;
  41. }
  42. return;
  43. }