/*    DeleteLink  (or NewDeleteLink ;-)  
 *        by
 *    Phil Dietz -- NCEMRSoft 1991
 *
 *    USAGE:    DeleteLink <file>
 *
 *    SUMMARY:  Deletes a soft link pointing to an unmounted file
 *              which Commodore's 'delete' SHOULD do, but doesn't.
 *              Note:  DeleteLink will delete ANY file so use with
 *                     extreme caution!
 *
 *    TIPS:     You know you have a bad soft link when:
 *              NewList6 shows 'link -> :UNKNOWN FILE:
 *          or     "       "   'link -> !some_file
 *
 *              The link is not bad, it's just that you can't delete
 *              the link whenver you want.  That's why deletelink is here.
 *
 *    REQUIREMENTS:  WB2.0 version 37
 *
 *    COMPILE:  lc -Lt -ccurfist -rr -ms -O -v -b1 DeleteLink.c
 */

#include <stdio.h>
#include <stdlib.h>
#include <exec/types.h>
#include <clib/exec_protos.h>
#include <pragmas/exec_pragmas.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <clib/dos_protos.h>
#include <pragmas/dos_pragmas.h>

extern struct DOSBase *DOSBase;

int main(int argc, char **argv)
   {
   struct FileInfoBlock __aligned fib;
   BPTR lock;

   if (!(struct DosLibrary *)OpenLibrary("dos.library", 37)) exit(1);
   if (argc<2) 
      {
      PutStr("Usage: DeleteLink <filename>\n");
      exit(1);
      }
   lock=Lock(argv[1], SHARED_LOCK);
   if(lock)
      {
      if(Examine(lock,&fib))
         {
         if(fib.fib_DirEntryType==3) {if (!(DeleteFile(argv[1]))) PutStr("Failed.\n");}
         else PutStr("Not a soft link.\n");
         }
      UnLock(lock);
      }
}
