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