home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.2 / Libraries / DOS / pattern.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  1.7 KB  |  80 lines

  1. /*
  2.  * Copyright (C) 1990 Commodore-Amiga, Inc.
  3.  * All rights reserved
  4.  */
  5.  
  6. /* Example of DOS pattern matching calls.
  7.  * Compiled with Lattice C 5.05: lc -cfist -v -L pattern.c
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/execbase.h>
  12. #include <dos/dos.h>
  13. #include <dos/dosextens.h>
  14. #include <dos/dosasl.h>
  15. #include <clib/dos_protos.h>
  16.  
  17. #include <stdio.h>
  18.  
  19. struct AnchorPath MyAp;
  20.  
  21. int main(int, char **);
  22.  
  23. int
  24. main(argc,argv)
  25.     int    argc;
  26.     char    *argv[];
  27. {
  28.     LONG    retval = RETURN_ERROR;
  29.  
  30.     if (argc != 2 )
  31.     {
  32.         printf("Usage: %s <pattern>\n",argv[0]);
  33.         return retval;
  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.  
  46.     /* This code section deals with ALL and directory ascent/descent */
  47.         if (MyAp.ap_Info.fib_DirEntryType > 0)
  48.         {
  49.             if (MyAp.ap_Flags & APF_DIDDIR)
  50.             printf("Ascending from directory %s\n",
  51.                 &(MyAp.ap_Info.fib_FileName));
  52.             else {
  53.             printf("Entering directory %s\n",
  54.                 &(MyAp.ap_Info.fib_FileName));
  55.  
  56.             /* make it enter the directory */
  57.             MyAp.ap_Flags |= APF_DODIR;
  58.             }
  59.             /* clear the completed directory flag */
  60.             MyAp.ap_Flags &= ~APF_DIDDIR;
  61.  
  62.         } else {
  63.             /* Here is code for handling each particular file */
  64.             printf("The next file is ... %s\n",
  65.                &(MyAp.ap_Info.fib_FileName));
  66.         }
  67.     }
  68.  
  69.     /* This absolutely, positively must be called, all of the time. */
  70.     MatchEnd(&MyAp);
  71.  
  72.     /* Check for error, if so, print error message */
  73.     if (retval != ERROR_NO_MORE_ENTRIES)
  74.     {
  75.     printf("%s failed because Error code %ld\n",argv[0],retval);
  76.     PrintFault(retval,NULL);
  77.     }
  78. }
  79.  
  80.