home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / OS2UTIL.ZIP / CAT.C < prev    next >
Text File  |  1990-05-21  |  1KB  |  66 lines

  1. #define INCL_SUB
  2. #include <os2.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. main(int argc, char **argv);
  7.  
  8. main(argc, argv)
  9. int argc;
  10. char *argv[];
  11. {
  12.      register i;
  13.      FILE *fp;
  14.      char ch, f, drv[3], path[68], fn[80], *p;
  15.  
  16.      HDIR hdir;
  17.      USHORT usSearchCount;
  18.      FILEFINDBUF findbuf;
  19.  
  20.      for (i=1; i<argc; i++)
  21.      {
  22.      hdir        = 0xFFFF;
  23.      usSearchCount    = 1;
  24.  
  25.      if (p = strrchr(argv[i], '\\'))
  26.      {
  27.         f       = *(p+1);
  28.         *(p+1) = NULL;
  29.         strcpy(path, argv[i]);
  30.         *(p+1) = f;
  31.         drv[0] = NULL;
  32.      }
  33.      else
  34.      {
  35.         path[0] = NULL;
  36.  
  37.         if (strchr(argv[i], ':'))
  38.         {
  39.            strncpy(drv, argv[i], 2);
  40.            drv[2] = NULL;
  41.         }
  42.         else
  43.            drv[0] = NULL;
  44.      }
  45.  
  46.      if (!DosFindFirst(argv[i], &hdir, 0x00, &findbuf,
  47.          sizeof(findbuf), &usSearchCount, 0L))
  48.          do {
  49.           sprintf(fn, "%s%s%s", drv, path, strlwr(findbuf.achName));
  50.           if ( (fp=fopen(fn, "r")) == NULL)
  51.              printf("cat: %s not found.\n", fn);
  52.           else
  53.           {
  54.              while ( (ch = (char)fgetc(fp)) != EOF)
  55.               putchar(ch);
  56.              fclose(fp);
  57.           }
  58.          } while (!DosFindNext(hdir, &findbuf, sizeof(findbuf), &usSearchCount));
  59.      else
  60.         printf("cat: %s not found.\n", argv[i]);
  61.      }
  62.  
  63.      return 0;
  64. }
  65. 
  66.