home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Recent / disk / misc / PurgeDelDir.lha / PurgeDelDir / PurgeDelDir.c < prev    next >
C/C++ Source or Header  |  2000-08-01  |  3KB  |  127 lines

  1. /***********************************************************/
  2. /*
  3. **   $VER: PurgeDelDir v1.4 by Giles Burdett
  4. **
  5. **   PurgeDelDir - Purge the .DelDir of a PFS formatted
  6. **   partition of all its entries.
  7. **
  8. **   See the ReadMe for usage information
  9. **
  10. **   PurgeDelDir has been designed and programmed
  11. **   by Giles Burdett in 2000
  12. **     - layabouts@the-giant-sofa.demon.co.uk
  13. **
  14. **   PFS is the Professional File System by
  15. **   GREat Effects Development
  16. **     - www.greed.nl
  17. **
  18. */
  19. /***********************************************************/
  20.  
  21.  
  22.  
  23.  
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <clib/dos_protos.h>
  28.  
  29.  
  30. UBYTE version_info[]="$VER: PurgeDelDir v1.4 by Giles Burdett";
  31.  
  32. //#define PDD_DEBUG       // Uncomment to debug
  33.  
  34.  
  35. #define DEFAULT_SLOT_NUMBER 32
  36. #define MAX_SLOT_NUMBER 992
  37. #define MAX_DIGITS 4
  38.  
  39. int main (int argc, char **argv)
  40. {
  41.     struct RDArgs *cmdline_args;
  42.     LONG arguments[]={0, 0};
  43.     BPTR fp;
  44.     // Default slot value in case user doesn't specify one
  45.     int slot=DEFAULT_SLOT_NUMBER;
  46.     LONG i;
  47.     unsigned char target[256];
  48.     char env_slot_value_string[MAX_DIGITS];
  49.     LONG user_slot=0;
  50.     BOOL user_slot_entered=FALSE;
  51.  
  52.     if ((cmdline_args=ReadArgs("Device/A,Slots/N", arguments, NULL))==NULL)
  53.     {
  54.         puts ("Error: Missing device/volume name");
  55.         return RETURN_FAIL;
  56.     }
  57.  
  58.     // Store arguments
  59.     strcpy (target, (STRPTR)arguments[0]);
  60.     if (arguments[1])
  61.     {
  62.         user_slot=*((LONG *)(arguments[1]));
  63.         user_slot_entered=TRUE;
  64.     }
  65.  
  66.     FreeArgs(cmdline_args);
  67.  
  68.     #ifdef PDD_DEBUG
  69.         printf("you typed: %s\n", target);
  70.     #endif
  71.     strcat (target, "deldirpurgefile");
  72.     #ifdef PDD_DEBUG
  73.         printf("The full path: %s\n");
  74.     #endif
  75.  
  76.     {
  77.         int len;
  78.         if ((len=GetVar("PurgeDelDir/slot_value", env_slot_value_string, MAX_DIGITS, GVF_GLOBAL_ONLY))>0)
  79.         {
  80.             // Reset to default if env var is a non-number string
  81.             if (!(slot=abs(atoi(env_slot_value_string))))
  82.                 slot=DEFAULT_SLOT_NUMBER;
  83.             #ifdef PDD_DEBUG
  84.                 printf ("env slots: %d\n", slot);
  85.             #endif
  86.         }
  87.     }
  88.     #ifdef PDD_DEBUG
  89.         printf ("arg[1]=%ld\n", arguments[1]);
  90.     #endif
  91.  
  92.     // Check if user wants to override default or env variable
  93.     if (user_slot_entered)
  94.     {
  95.         if (user_slot<1 || user_slot>MAX_SLOT_NUMBER)
  96.         {
  97.             puts ("Bad slot number - aborting DelDir flush...");
  98.             return RETURN_FAIL;
  99.         }
  100.         else
  101.             slot=user_slot;
  102.         #ifdef PDD_DEBUG
  103.             printf ("slots: %d\n", slot);
  104.         #endif
  105.     }
  106.  
  107.     #ifdef PDD_DEBUG
  108.         printf ("Final slot value = %d\n", slot);
  109.     #endif
  110.  
  111.     for (i=0; i<slot; i++)
  112.     {
  113.          // Need the extra brackets around the assignment otherwise
  114.          // the compiler gets horribly confused!
  115.          if (!(fp=Open (target, MODE_NEWFILE)))
  116.          {
  117.              PrintFault (IoErr(), "Failure");
  118.              return RETURN_FAIL;
  119.          }
  120.          Close (fp);
  121.          DeleteFile (target);
  122.     }
  123.     
  124.     return RETURN_OK;
  125. }
  126.  
  127.