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 / exall.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  2.1 KB  |  101 lines

  1. /* an example of how to use ExAll */
  2.  
  3. #include <exec/types.h>
  4. #include <exec/ports.h>
  5. #include <exec/memory.h>
  6. #include <dos/dos.h>
  7. #include <dos/dosextens.h>
  8. #include <dos/exall.h>
  9. #include <clib/dos_protos.h>
  10.  
  11. /* normally you'ld include pragmas here */
  12.  
  13. #define BUFFSIZE 300
  14.  
  15. int
  16. main(argc,argv)
  17.     int argc;
  18.     char *argv[];
  19. {
  20.     BPTR obj_lock;
  21.     LONG res2,more;
  22.     struct ExAllData *Buffer,*ead;
  23.     struct ExAllControl *control;
  24.     LONG rc = RETURN_ERROR;
  25.     char pattern[256];
  26.  
  27.   /* ugly argument parsing */
  28.   if( argc >= 2 && argc <= 3) {
  29.  
  30.     /* control MUST be allocated by AllocDosObject! */
  31.     control=(struct ExAllControl *) AllocDosObject(DOS_EXALLCONTROL,NULL);
  32.     Buffer=(struct ExAllData *) AllocMem(BUFFSIZE,MEMF_PUBLIC|MEMF_CLEAR);
  33.  
  34.     /* always check allocations! */
  35.     if (!control || !Buffer)
  36.         goto cleanup;
  37.  
  38.     if (argc == 3)
  39.     {
  40.         /* parse the pattern for eac_MatchString */
  41.         if (ParsePatternNoCase(argv[2],pattern,sizeof(pattern)) == -1)
  42.         {
  43.             printf("ParsePatternNoCase buffer overflow!\n");
  44.             goto cleanup;
  45.         }
  46.         control->eac_MatchString = pattern;
  47.     }
  48.  
  49.     /* lock the directory */
  50.     if (obj_lock = Lock(argv[1],SHARED_LOCK)) {
  51.  
  52.       control->eac_LastKey = 0;    /* paranoia */
  53.  
  54.       do { /* while more */
  55.  
  56.         more = ExAll(obj_lock,Buffer,BUFFSIZE,ED_TYPE,control);
  57.         res2 = IoErr();
  58.         if (!more && res2 != ERROR_NO_MORE_ENTRIES)
  59.         {
  60.         VPrintf("Abnormal exit, error = %ld\n",&res2);
  61.         break;
  62.         }
  63.  
  64.         /* remember, VPrintf wants a pointer to arguments! */
  65.         VPrintf("Returned %ld entries:\n\n",&(control->eac_Entries));
  66.  
  67.         if (control->eac_Entries)
  68.         {
  69.         ead = Buffer;
  70.         do {
  71.             VPrintf("%s",(LONG *) &(ead->ed_Name));
  72.             if (ead->ed_Type > 0)
  73.                 PutStr(" (dir)\n");
  74.             else
  75.                 PutStr(" (file)\n");
  76.  
  77.             ead = ead->ed_Next;
  78.         } while (ead);
  79.         }
  80.  
  81.         rc = RETURN_OK;    /* success */
  82.  
  83.       } while (more);
  84.  
  85.       UnLock(obj_lock);
  86.  
  87.     } else VPrintf("Couldn't find %s\n",(LONG *) &(argv[1]));
  88.  
  89. cleanup:
  90.     if (Buffer)  FreeMem(Buffer,BUFFSIZE);
  91.     if (control) FreeDosObject(DOS_EXALLCONTROL,control);
  92.  
  93.     return(rc);
  94.  
  95.     } else {
  96.       VPrintf("Usage: %s dirname [pattern]\n",(LONG *) &(argv[0]));
  97.       return(rc);
  98.     }
  99. }
  100.  
  101.