home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_03 / 1n03083a < prev    next >
Text File  |  1990-07-31  |  1KB  |  55 lines

  1.  
  2.  
  3. /*
  4.  * ANSIPRT.C - reads a file with ANSI carriage control characters from STDIN
  5.  *             and writes an expanded file to STDOUT.  Use redirection to
  6.  *             control input and output.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11.  
  12. char inline[1024];
  13.  
  14. main()
  15.    {
  16.    char *workptr;
  17.  
  18.    fgets(inline, sizeof(inline), stdin);
  19.  
  20.    while(!feof(stdin))
  21.       {
  22.       switch(inline[0])
  23.          {
  24.          case '1':   /* formfeed     */
  25.             fputc('\n',stdout);
  26.             fputc('\f',stdout);
  27.             break;
  28.          case '0':   /* double-space */
  29.             fputc('\n',stdout);
  30.             fputc('\n',stdout);
  31.             break;
  32.          case '-':   /* triple-space */
  33.             fputc('\n',stdout);
  34.             fputc('\n',stdout);
  35.             fputc('\n',stdout);
  36.             break;
  37.          case '+':   /* overwrite    */
  38.             fputc('\r',stdout);
  39.             break;
  40.          default:    /* single-space by default */
  41.             fputc('\n',stdout);
  42.             break;
  43.          }
  44.  
  45.       workptr = strchr(inline, '\n');  /* Convert LF to CR */
  46.       if(workptr != NULL)
  47.          *workptr = '\r';
  48.  
  49.       fputs(&inline[1], stdout);       /* skip first character */
  50.  
  51.       fgets(inline, sizeof(inline), stdin);
  52.       }
  53.    }
  54.  
  55.