home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / telecom / 133 / c / de1st.c next >
Encoding:
C/C++ Source or Header  |  1987-04-17  |  4.1 KB  |  84 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /* Module:     de1st.c - Replace 1st Word control flags with spaces         */
  4. /*                                                                          */
  5. /* Programmer: George R. Woodside                                           */
  6. /*                                                                          */
  7. /* Date:       January 22, 1987                                             */
  8. /*                                                                          */
  9. /****************************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <ctype.h>
  13.  
  14. main(argc,argv)
  15. int     argc;
  16. char    *argv[];
  17.  
  18. {
  19.   register int i;
  20.   FILE  *fp;
  21.  
  22.   if (argc > 1)                         /* if multiple arguments,           */
  23.     {
  24.       for (i = 1; i < argc; i++)        /* then do each one                 */
  25.         {
  26.           if( (fp = fopen(argv[i],"r") ) == NULL) /* if error opening file, */
  27.             {
  28.               printf("de1st: Unable to open %s \n",argv[i]);
  29.               continue;
  30.             }
  31.           else                          /* if file opened OK,               */
  32.             {
  33.               decnt(fp);                /* de-control it                    */
  34.             }                           /* end file opened OK               */
  35.         }                               /* end for one argument             */
  36.     }                                   /* end for all arguments            */
  37.     else                                /* if no arguments,                 */
  38.       decnt(stdin);                     /* dump standard in                 */
  39. }                                       /* end main                         */
  40.  
  41. /****************************************************************************/
  42. /* decnt - de-control character a file.                                     */
  43. /****************************************************************************/
  44. decnt(fp)
  45. FILE *fp;                               /* file to dump                     */
  46.  
  47. {
  48.  
  49.   register  int  c;
  50.  
  51.   while( (c = getc(fp) ) != EOF)        /* read the whole file              */
  52.     {
  53.       c = c & 0x7f;                     /* insure no high bits on           */
  54.       if(isprint(c))                    /* if a printable character,        */
  55.         putchar(c);                     /* copy it                          */
  56.       else                              /* but if a control,                */
  57.         {                               /* check it out                     */
  58.           switch (c)                    /* all controls are checked         */
  59.             {
  60.               case '\n':                /* newlines are ok                  */
  61.                 putchar(c);             /* copy it                          */
  62.                 break;                  /* and call it ok                   */
  63.  
  64.               case '\r':                /* returns are ok                   */
  65.                 putchar(c);             /* copy it                          */
  66.                 break;                  /* and call it ok                   */
  67.  
  68.               case '\014':              /* form feed ok for page break      */
  69.                 putchar(c);             /* copy it                          */
  70.                 break;                  /* and call it ok                   */
  71.  
  72.               case '\t':                /* tabs are ok                      */
  73.                 putchar(c);             /* copy it                          */
  74.                 break;                  /* and call it ok                   */
  75.  
  76.               default:
  77.                 putchar(' ');           /* anything else is a space         */
  78.                 break;
  79.  
  80.             }                           /* end switch                       */
  81.         }                               /* end control character            */
  82.     }                                   /* end of file                      */
  83. }                                       /* end decnt                        */
  84.