home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.1 / Libraries / DOS / pattern.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  2.1 KB  |  101 lines

  1. #include <exec/types.h>
  2. #include <exec/execbase.h>
  3. #include <dos/dos.h>
  4. #include <dos/dosextens.h>
  5. #include <dos/dosasl.h>
  6. #include <clib/dos_protos.h>
  7.  
  8.  
  9. struct AnchorPath MyAp;
  10.  
  11. #define SAME 0
  12.  
  13. int
  14. main(argc,argv)
  15.     int    argc;
  16.     char    *argv[];
  17. {
  18.     LONG    retval = RETURN_ERROR;
  19.     LONG    all = FALSE;
  20.     char    dirname[256];
  21.  
  22.     if (argc < 2 || argc > 3)
  23.     {
  24. usage:        printf("Usage: %s <pattern> [all]\n",argv[0]);
  25.         return retval;
  26.     }
  27.  
  28.     if (argc == 3)
  29.     {
  30.         if (stricmp(argv[2],"all") == SAME)
  31.             all = TRUE;
  32.         else
  33.             goto usage;
  34.     }
  35.  
  36.     printf("Searching directory tree for pattern %s\n",argv[1]);
  37.  
  38.     /* Initialize the AnchorPath structure    */
  39.     MyAp.ap_BreakBits = SIGBREAKF_CTRL_C; /* Break on these bits    */
  40.  
  41.     for (retval = MatchFirst(argv[1],&MyAp);
  42.          retval == 0;
  43.          retval = MatchNext(&MyAp))
  44.     {
  45.         if (MyAp.ap_Flags & APF_DirChanged)
  46.         {
  47.             printf("Changed directories...\n");
  48.         }
  49.  
  50.         if (NameFromLock(MyAp.ap_Current->an_Lock,dirname,
  51.                  sizeof(dirname)) == FALSE)
  52.         {
  53.             PrintFault(IoErr(),"Error on NameFromLock");
  54.             break;
  55.         }
  56.         if (AddPart(dirname,&(MyAp.ap_Info.fib_FileName[0]),
  57.                 sizeof(dirname)) == FALSE)
  58.         {
  59.             PrintFault(IoErr(),"Error on AddPart");
  60.             break;
  61.         }
  62.  
  63.     /* This code section deals with ALL and directory ascent/descent */
  64.         if (MyAp.ap_Info.fib_DirEntryType > 0)
  65.         {
  66.             if (MyAp.ap_Flags & APF_DIDDIR)
  67.             {
  68.             printf("Ascending from directory %s\n",dirname);
  69.  
  70.             } else if (all) {
  71.  
  72.             printf("Entering directory %s\n",dirname);
  73.  
  74.             /* make it enter the directory */
  75.             MyAp.ap_Flags |= APF_DODIR;
  76.  
  77.             } else {
  78.             printf("The next dir is  ... %s\n",dirname);
  79.             }
  80.  
  81.             /* clear the completed directory flag */
  82.             MyAp.ap_Flags &= ~APF_DIDDIR;
  83.  
  84.         } else {
  85.             /* Here is code for handling each particular file */
  86.             printf("The next file is ... %s\n",dirname);
  87.         }
  88.     }
  89.  
  90.     /* This absolutely, positively must be called, all of the time. */
  91.     MatchEnd(&MyAp);
  92.  
  93.     /* Check for error, if so, print error message */
  94.     if (retval != ERROR_NO_MORE_ENTRIES)
  95.     {
  96.     printf("%s failed because Error code %ld\n",argv[0],retval);
  97.     PrintFault(retval,NULL);
  98.     }
  99. }
  100.  
  101.