home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / p / ut-c.lbr / CAT.CZ / CAT.C
Encoding:
C/C++ Source or Header  |  1993-10-25  |  2.1 KB  |  77 lines

  1. /*  cat.c -- UTOOL. Concatenate files ver 2.  
  2.      author: David H. Wolen
  3.      last change: 6/12/83
  4.  
  5.      usage:
  6.           (1) copy console input to file (^z<cr> to stop)
  7.                cat >ofile
  8.           (2) concat inp files and write on output file
  9.                cat ifile1 ifile2 >ofile
  10.           (3) concat input files and pass to std input of prog2
  11.                cat ifile1 ifile2 |prog2
  12.           (4) clean up WordStar doc file
  13.                cat -w file.doc >ofile
  14.  
  15.      option:   -w  clean up WordStar doc files by zeroing
  16.                     hi bits and converting strange characters
  17.                     to blanks
  18.  
  19.      input:    files or STDIN
  20.      output:   STDOUT
  21.  
  22.  
  23.      linkage: a:clink cat -f dio -ca
  24. */
  25.  
  26. #include "a:bdscio.h"
  27. #include "a:dio.h"
  28. #define STDERR  4
  29.  
  30. main(argc,argv)
  31. int  argc;
  32. char *argv[];
  33. {
  34.      char ibuf[BUFSIZ], undoc(), *s;
  35.      int  c, isstdin, wsflg;
  36.  
  37.      dioinit(&argc,argv);
  38.      wsflg=FALSE;
  39.  
  40.      while(--argc > 0 && (*++argv)[0] == '-')
  41.           for(s=argv[0]+1; *s != '\0'; s++)
  42.                switch(*s)
  43.                     {case 'W':  wsflg=TRUE; break;
  44.                     default:  fprintf(STDERR,"cat: invalid option\n");
  45.                               exit(dioflush());
  46.                     }
  47.  
  48.      if(argc <= 0)
  49.           isstdin=TRUE;
  50.      else
  51.           isstdin=FALSE;
  52.  
  53.      if(isstdin)         /* std input */
  54.           while((c=getchar()) != EOF)
  55.                {if(wsflg)
  56.                     putchar(undoc(c));
  57.                else
  58.                     putchar(c);
  59.                }
  60.  
  61.      if(!isstdin)          /* files */
  62.           while(argc-- > 0)
  63.                {if(fopen(*argv++,ibuf)==ERROR)
  64.                     {fprintf(STDERR,"cat: can't open %s\n",*argv);
  65.                     exit(dioflush());
  66.                     }
  67.                while((c=getc(ibuf)) != EOF && c != CPMEOF)
  68.                     {if(wsflg)
  69.                          putchar(undoc(c));
  70.                     else
  71.                          putchar(c);
  72.                     }
  73.                }
  74.  
  75.      dioflush();
  76. }
  77.