
/* cat - amiga program to concatenate files, requires ANSI C */

/* Released to the public domain by Karl Lehenbauer, 1-Feb-1990 */

#include <stdio.h>
#include <fcntl.h>

void catfile(const char *fname)
{
       FILE *fp;
       char s[1024];

       if ((fp = fopen(fname,"r")) == NULL)
       {
               perror(fname);
               return;
       }

       while (fgets(s, sizeof(s), fp) != NULL)
               fputs(s, stdout);

       if (ferror(fp))
               fprintf(stderr,"cat: error occured reading %s\n",fname);

       fclose(fp);
}

main(int argc, char *argv[])
{
       char *fname;
       int i;

       if (argc < 2)
       {
               fprintf(stderr,"usage: cat [>outfile] file [file..]\n");
               exit(1);
       }

       for (i = 1; i < argc; i++)
               while ((fname = scdir(argv[i])) != NULL)
                       catfile(fname);

       if (ferror(stdout))
       {
               fprintf(stderr,"cat: error occured while writing output file\n");
               exit(2);
       }

       exit(0);
}
