home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / misc / xref_v1.1.lha / XRef / Tools / rexx / expungexref.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-09  |  3.1 KB  |  130 lines

  1. /*
  2. ** $PROJECT: rexxxref.library
  3. **
  4. ** $VER: expungexref.c 1.1 (08.01.95)
  5. **
  6. ** by
  7. **
  8. ** Stefan Ruppert , Windthorststraße 5 , 65439 Flörsheim , GERMANY
  9. **
  10. ** (C) Copyright 1995
  11. ** All Rights Reserved !
  12. **
  13. ** $HISTORY:
  14. **
  15. ** 08.01.95 : 001.001 : initial
  16. */
  17.  
  18. #include "rexxxref.h"
  19.  
  20. /*FS*/ /*"AutoDoc"*/
  21. /*GB*** rexxxref.library/ExpungeXRef *****************************************
  22. *
  23. *    NAME
  24. *        ExpungeXRef - expunge a/some xreffiles from memory
  25. *
  26. *    SYNOPSIS
  27. *        ExpungeXRef(CATEGORY,FILE,FORCE/S)
  28. *
  29. *    FUNCTION
  30. *        This is the Rexx-Function-Interface to the XR_ExpungeXRef() function
  31. *        of the xref.library.
  32. *
  33. *    INPUTS
  34. *        CATEGORY - category of xreffiles to expunge
  35. *        FILE     - expunge only the given file
  36. *        FORCE    - expunge also xreffiles, which are locked
  37. *
  38. *    RESULTS
  39. *        Set RC to RC_WARN, if no xreffiles was expunged. Otherwise
  40. *        set to RC_OK.
  41. *
  42. *    SEE ALSO
  43. *        LoadXRef() ,FindXRef() ,XR_ExpungeXRef()
  44. *
  45. ******************************************************************************
  46. *
  47. */
  48. /*FE*/
  49.  
  50. struct ExpungeXRefData
  51. {
  52.    struct RexxXRefBase *LibBase;
  53.    UBYTE Buffer[100];
  54. };
  55.  
  56. static RegCall ULONG expungexreffunc(REGA0 struct Hook *hook,REGA2 struct XRefFileNode *xref,REGA1 struct xrmExpunge *msg)
  57. {
  58.    if(msg->Msg = XRM_EXPUNGE)
  59.    {
  60.       struct ExpungeXRefData *exd = (struct ExpungeXRefData *) hook->h_Data;
  61.       struct RexxXRefBase *rxb = exd->LibBase;
  62.  
  63.       BOOL force  = (GetTagData(XREFA_Lock,XREF_LOCK,msg->exp_Attrs) == XREF_UNLOCK);
  64.       STRPTR name;
  65.       BOOL lock;
  66.  
  67.       if(GetXRefFileAttrs(xref,XREFA_Name,&name,
  68.                                XREFA_Lock,&lock,
  69.                                TAG_DONE) == 2 && !lock && force)
  70.       {
  71.          strncat(exd->Buffer,name,sizeof(exd->Buffer));
  72.          strncat(exd->Buffer," ",sizeof(exd->Buffer));
  73.       }
  74.       return(1);
  75.    }
  76.    return(0);
  77. }
  78.  
  79. ULONG expungexref(struct ARexxFunction *func,struct RexxMsg *rmsg,STRPTR *argstr,struct RexxXRefBase *rxb)
  80. {
  81.    ULONG rc  = RC_OK;
  82.  
  83.    if(!rmsg->rm_Args[LX_FILE])
  84.       rc = RXERR_REQUIRED_ARG_MISSING;
  85.    else
  86.    {
  87.       struct Hook hook = {NULL};
  88.       struct ExpungeXRefData exd;
  89.       struct TagItem tags[4];
  90.       UWORD tag = 2;
  91.  
  92.       exd.LibBase   = rxb;
  93.       exd.Buffer[0] = '\0';
  94.  
  95.       hook.h_Data  = &exd;
  96.       hook.h_Entry = (HOOKFUNC) expungexreffunc;
  97.  
  98.       tags[0].ti_Tag  = XREFA_XRefHook;
  99.       tags[0].ti_Data = (ULONG) &hook;
  100.  
  101.       if(rmsg->rm_Args[EX_FILE])
  102.       {
  103.          tags[1].ti_Tag  = XREFA_File;
  104.          tags[1].ti_Data = (ULONG) rmsg->rm_Args[EX_FILE];
  105.       } else
  106.       {
  107.          tags[1].ti_Tag  = XREFA_Category;
  108.          tags[1].ti_Data = (ULONG) rmsg->rm_Args[EX_CATEGORY];
  109.       }
  110.  
  111.       if(rmsg->rm_Args[EX_FORCE] && !Stricmp(rmsg->rm_Args[EX_FORCE],"FORCE"))
  112.       {
  113.          tags[tag].ti_Tag  = XREFA_Lock;
  114.          tags[tag].ti_Data = XREF_UNLOCK;
  115.          tag++;
  116.       }
  117.  
  118.       tags[tag].ti_Tag = TAG_END;
  119.  
  120.       if(XR_ExpungeXRef(tags))
  121.       {
  122.          if(!(*argstr = CreateArgstring(exd.Buffer,strlen(exd.Buffer))))
  123.             rc = RXERR_NO_FREE_STORE;
  124.       } else
  125.          rc = RC_WARN;
  126.    }
  127.    return(rc);
  128. }
  129.  
  130.