home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / OS2MNX1.ZIP / CAT2.C < prev    next >
Text File  |  1989-12-26  |  2KB  |  54 lines

  1. /* $Header: D:/RCS/RCS/cat2.c 1.1 89/12/24 07:55:37 RCA Exp $
  2.  * $Log
  3.  */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. void filecopy(FILE *);
  7.  
  8. main(argc, argv)    /* cat: concatenate files */
  9. int argc;
  10. char *argv[];
  11.  
  12. {
  13.     FILE *fp, *fopen();
  14.  
  15.     if (argc == 1)
  16.       {
  17.       printf ("\n █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█");
  18.       printf ("\n █ CAT2     (Concatenate)                  $Author: RCA $   █");
  19.       printf ("\n █          $Date: 89/12/24 07:55:37 $     $Revision: 1.1 $ █");
  20.       printf ("\n █ Usage:   CAT2  file1 file2 [ ... file(n)] > outfile      █");
  21.       printf ("\n █ Purpose: This command concatenates two or more files and █");
  22.       printf ("\n █          then copies them to standard output. Can be     █");
  23.       printf ("\n █          used to append CRLF's to UNIX files.            █");
  24.       printf ("\n █ OS:      Works under OS/2 or DOS.                        █");
  25.       printf ("\n █ Credits: From Kernighan & Ritchie, p. 154.               █");
  26.       printf ("\n █▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█\n");
  27.       exit(1);
  28.       }
  29.   
  30. /*    if (argc == 1) \\ no args; copy standard input */
  31. /*       filecopy(stdin);                            */
  32.       else
  33.      while (--argc > 0)
  34.         if ((fp = fopen(*++argv, "r")) == NULL) {
  35.         fprintf(stderr,
  36.             "cat: can't open %s\n", *argv);
  37.         exit(1);
  38.         } else {
  39.         filecopy(fp);
  40.         fclose(fp);
  41.         }
  42.     exit(0);
  43. }
  44.  
  45. void filecopy(fp)    /* copy file fp to standard output */
  46. FILE *fp;
  47. {
  48.     int c;
  49.  
  50.     while ((c = getc(fp)) != EOF)
  51.     putc(c, stdout);
  52. }
  53. 
  54.