home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 10dump / showit.c < prev   
Encoding:
C/C++ Source or Header  |  1988-08-11  |  839 b   |  42 lines

  1. /*
  2.  *    showit -- make non-printable characters in
  3.  *    the stream fp visible (or optionally strip them)
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <ctype.h>
  8. #include <local\std.h>
  9.  
  10. int
  11. showit(fp, strip, wp)
  12. FILE *fp;
  13. BOOLEAN strip;    /* strip non-ASCII codes */
  14. BOOLEAN wp;    /* filter typical word processing codes */
  15. {
  16.     int ch;
  17.     
  18.     clearerr(fp);
  19.     while ((ch = getc(fp)) != EOF)
  20.         if (isascii(ch) && (isprint(ch) || isspace(ch)))
  21.             switch (ch) {
  22.             case '\r':
  23.                 if (wp == TRUE) {
  24.                     if ((ch = getc(fp)) != '\n')
  25.                         ungetc(ch, fp);
  26.                     putchar('\r');
  27.                     putchar('\n');
  28.                 }
  29.                 else
  30.                     putchar(ch);
  31.                 break;
  32.             default:
  33.                 putchar(ch);
  34.                 break;
  35.             }
  36.         else if (strip == FALSE)
  37.             printf("\\%02X", ch);
  38.         else if (wp == TRUE && isprint(ch & ASCII))
  39.             putchar(ch & ASCII);
  40.     return (ferror(fp));
  41. }
  42.