home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BDSC / BDSC-3 / CAT.C < prev    next >
Text File  |  2000-06-30  |  896b  |  44 lines

  1. /*
  2.     Concatenate text files listed on command line onto the standard
  3.     output, or else  take standard input and send it to standard output.
  4.     For example,
  5.  
  6.         cat file1 file2 file3 >file4
  7.  
  8.     creates "file4" consisting of the concatenation of file1,file2, and
  9.     file3 (which must all be text files).
  10.  
  11.     Link by:
  12.         clink cat -f dio
  13. */
  14.  
  15. #include "bdscio.h"
  16. #include "dio.h"
  17.  
  18. #define STDERR 4
  19.  
  20. main(argc,argv)
  21. char **argv;
  22. {
  23.     int c;
  24.     int i;
  25.     char ibuf[BUFSIZ];
  26.  
  27.     dioinit(&argc,argv);
  28.  
  29.     if (argc == 1)
  30.         while ((c = getchar()) != EOF) putchar(c);
  31.     else
  32.         for (i = 1; i < argc; i++)
  33.         {
  34.             if (fopen(argv[i],ibuf) == ERROR)
  35.             {
  36.                 fprintf(STDERR,"\7Can't open %s\n",argv[i]);
  37.                 continue;
  38.             }
  39.             while ((c = getc(ibuf)) != EOF && c != CPMEOF)
  40.                 putchar(c);
  41.         }
  42.     dioflush();
  43. }
  44.