home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / newc_dev / delinf11.lha / DelInfo next >
Text File  |  1993-03-31  |  5KB  |  213 lines

  1. /* ---- DRev header ---- DO NOT EDIT! Please ---
  2. **
  3. **    Program           :   DelInfo
  4. **    Copyright         :   © 1993 by Paolo Dell'Aquila
  5. **    Author            :   Paolo Dell'Aquila
  6. **    Creation Date     :   12.11.92
  7. **    Current version   :   1.1
  8. **    Compiled with     :   SAS 6.0
  9. **
  10. **    REVISION HISTORY
  11. **
  12. **    Date       Ver     Author                Comment
  13. **    ---------  -----   -------------------   --------------------------
  14. **    31.03.93    1.1    Paolo Dell'Aquila      Now use AllocDosObject and needs
  15. **                                              no more RETURN after 'y' or 'n'.
  16. **    31.03.93    1.0    Paolo Dell'Aquila      Born in the CPU (I was)
  17. **
  18. */
  19.  
  20. #include <exec/types.h>
  21. #include <exec/ports.h>
  22. #include <exec/memory.h>
  23. #include <dos/dos.h>
  24. #include <dos/dosextens.h>
  25. #include <dos/exall.h>
  26. #include <clib/dos_protos.h>
  27. #include "proto/exec.h"
  28. #include "string.h"
  29.  
  30. #include "proto/dos.h"
  31.  
  32. #define VERSION 1
  33. #define REVISION 1
  34. #define DATE "31.03.93"
  35. #define VERS "DelInfo 1.1"
  36. #define VSTRING "DelInfo 1.1 (31.03.93)\n\r"
  37. char versiontag[]="$VER: DelInfo 1.1 (31.03.93)";
  38.  
  39. #define        TEMPLATE "DIR,I=INTER/S,S=SUBDIR/S"
  40. #define        DIR            0
  41. #define        INTER        1
  42. #define        SUBDIR        2
  43. #define        OPT_COUNT    3
  44.  
  45. LONG opts[OPT_COUNT];        /* C guarantees this will be all 0's! */
  46.  
  47. BOOL        SubDir=FALSE;
  48. BOOL        Inter=FALSE;
  49.  
  50. #define BUFFSIZE 1024
  51.  
  52. extern int printf(const char *, ...);
  53. extern int rawcon(int);
  54.  
  55. void DelInfo        (register TEXT *);
  56.  
  57. struct DosLibrary *DOSBase;
  58.  
  59.  
  60.  long stdout;
  61.  long stdin;
  62. __asm __saveds  main(register __d0 int len,register __a0 char *arg)
  63. {
  64.     TEXT dir[255];
  65.     struct RDArgs     *argsptr;
  66.     char             **sptr;
  67.  
  68.     if (!(DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",0)))
  69.         return -1;
  70.     stdout=Output();
  71.     stdin=Input();
  72.     argsptr=ReadArgs(TEMPLATE, opts, NULL);
  73.     if (argsptr == NULL)
  74.     {
  75.         PrintFault(IoErr(), NULL);    /* prints the appropriate err message */
  76.     }
  77.     else
  78.     {
  79.         GetCurrentDirName(dir,255);
  80.         sptr=(char **)(opts[DIR]);
  81.         if(sptr)
  82.         {
  83.             AddPart(dir,(STRPTR)(LONG *)sptr,255);
  84.         }
  85.         if(opts[SUBDIR])    SubDir=TRUE;
  86.         if(opts[INTER])        Inter=TRUE;
  87.         FreeArgs(argsptr);
  88.         printf("\n%s - Copyright © 1993 by Paolino Dell'Aquila (Fido 2:332/505.10)\n\n",VERS);
  89.         DelInfo(dir);
  90. //        printf("\n");
  91.     }
  92.     return 5;
  93. }
  94.  
  95. void DelInfo(register TEXT *dir)
  96. {
  97.  
  98.     BPTR obj_lock;
  99.     LONG res2,more;
  100.     struct ExAllData *Buffer,*ead;
  101.     struct ExAllControl *control;
  102.     LONG rc = RETURN_ERROR;
  103.  
  104. //    TEXT                            buf[256];
  105.     STRPTR                             s;
  106.     ULONG                             temp;
  107.     char                            c;
  108.     TEXT                            file[256];
  109.     TEXT                            buf2[ 2 ];
  110.  
  111.     SHORT    len=0;
  112.  
  113.     control=(struct ExAllControl *) AllocDosObject(DOS_EXALLCONTROL,NULL);
  114.     Buffer=(struct ExAllData *) AllocMem(BUFFSIZE,MEMF_PUBLIC|MEMF_CLEAR);
  115.  
  116.     if (!control || !Buffer)    goto cleanup;     // always check allocations!
  117.  
  118.     /* lock the directory */
  119.     if (obj_lock = Lock(dir,SHARED_LOCK))
  120.     {
  121.         control->eac_LastKey = 0;    /* paranoia */
  122.  
  123.         do     /* while more */
  124.         {
  125.             more = ExAll(obj_lock,Buffer,BUFFSIZE,ED_TYPE,control);
  126.             res2 = IoErr();
  127.             if (!more && res2 != ERROR_NO_MORE_ENTRIES)
  128.             {
  129.                 printf("Abnormal exit, error = %ld\n",res2);
  130.                 break;
  131.             }
  132.  
  133.             if (control->eac_Entries)
  134.             {
  135.                 ead = Buffer;
  136.                 do 
  137.                 {
  138.                     stccpy(file,dir,255);
  139.                     temp=SetSignal(0,0);
  140.                     if (temp & SIGBREAKF_CTRL_C) goto cleanup;
  141.  
  142.                     if(ead->ed_Type >0)        // e' una dir
  143.                     {
  144.                         if(SubDir)
  145.                         {
  146.                             stccpy(file,dir,255);
  147.                             AddPart(file,ead->ed_Name,255);
  148.                             DelInfo(file);
  149.                         }
  150.  
  151.                     }
  152.                     else
  153.                     {
  154.                         AddPart(file,ead->ed_Name,256);
  155.                         if((len=strlen(ead->ed_Name)) >5)
  156.                         {
  157.                             s=&(ead->ed_Name[strlen(ead->ed_Name)-5]);
  158.                             if(!(strnicmp(".info",s,5)))
  159.                             {
  160.                                 if(Inter)
  161.                                 {
  162.                                     printf("  ---> Delete %s [y/N] ?  ",file);
  163.                                     Flush(stdout);
  164.                                     rawcon(1);
  165.                                     c=FGetC(stdin);
  166.                                     rawcon(0);
  167.                                     if(c=='y')
  168.                                     {
  169.                                         if(!DeleteFile(file))
  170.                                             printf("  *** Problem deleting %s\n",file);
  171.                                     }
  172.  
  173.                                     buf2[ 0 ] = c;
  174.                                     buf2[1]='\0';
  175.                                     printf("%s\n",buf2);
  176.  
  177.                                 }
  178.                                 else
  179.                                 {
  180.                                     if(DeleteFile(file))
  181.                                         printf("  ---> Delete %s\n",file);
  182.                                     else printf("  *** Problem deleting %s\n",file);
  183.                                 }
  184.                             }
  185.                         }
  186.                     }    
  187.                     ead = ead->ed_Next;
  188.                 } while (ead);
  189.             }
  190.  
  191.             rc = RETURN_OK;    /* success */
  192.  
  193.         } while (more);
  194.  
  195.         UnLock(obj_lock);
  196.  
  197.     } 
  198.     else printf("Couldn't find %s\n",dir);
  199.  
  200.  
  201. cleanup:
  202.     if (Buffer)  FreeMem(Buffer,BUFFSIZE);
  203.     if (control) FreeDosObject(DOS_EXALLCONTROL,control);
  204.  
  205. }
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.