home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_02 / 1002097a < prev    next >
Text File  |  1991-01-14  |  2KB  |  67 lines

  1.  
  2.  
  3. /*
  4.         A wildcard search main for the AMIGA workstation.
  5.         2 switches are presently supported:  /t for totals
  6.         and /s for subdirectories.
  7. */
  8.  
  9. #include <functions.h>          /* contains pragmas for system */
  10. #include <arpbase.h>            /* contains pragmas for ARP calls */
  11.  
  12. #define MAX_PATH 256
  13.  
  14. struct ArpBase *ArpBase;
  15. struct AnchorPath anchor;
  16. char pattern[128];
  17. int total;
  18.  
  19. void subfunc(char *path);
  20.  
  21. void main(int argc, char **argv)
  22. {
  23. if (argc < 2)
  24.         {
  25.         printf("\n\t%s <filespec> [/s/t]\n", argv[0]);
  26.         printf("\tFilespec can have DOS wildcards!\n"
  27.                 "\t/S switch includes subdirectories.\n"
  28.                 "\t/T switch gives a total.\n");
  29.         exit(0);
  30.         }
  31.  
  32. ArpBase = OpenLibrary("arp.library", 39);
  33. if (!ArpBase)
  34.         {
  35.         printf("ERROR: couldn't open ARP!!!\n");
  36.         exit(-1);
  37.         }
  38.  
  39. PreParse(BaseName(argv[1]), pattern);
  40. strcpy(BaseName(argv[1]), "*");
  41. anchor.ap_Flags = APF_DoWild;
  42. anchor.ap_StrLen = MAX_PATH;
  43.  
  44. if (!FindFirst(argv[1], &anchor))
  45.         do      {
  46.                 if (anchor.ap_Info.fib_DirEntryType > 0)
  47.                         {
  48.                          if (!(anchor.ap_Flags & APF_DidDir) &&
  49.                                                 argc > 2 && strstr(argv[2], "/S"))
  50.                                 anchor.ap_Flags |= APF_DoDir;
  51.                         anchor.ap_Flags &= ~APF_DidDir;
  52.                         }
  53.                 else
  54.                         if (PatternMatch(pattern,
  55.                                                         anchor.ap_Info.fib_FileName))
  56.                                 {
  57.                                 total++;
  58.                                 subfunc(anchor.ap_Buf);
  59.                                 }
  60.                 } while(!FindNext(&anchor));
  61.  
  62. if (argc > 2 && strstr(argv[2], "/T"))
  63.         printf("\tTOTAL = %d\n\n", total);
  64.  
  65. CloseLibrary(ArpBase);
  66. }
  67.