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

  1. /*
  2. ** $PROJECT: rexxxref.library
  3. **
  4. ** $VER: rexxcmdparser.c 1.4 (08.01.95)
  5. **
  6. ** by
  7. **
  8. ** Stefan Ruppert , Windthorststraße 5 , 65439 Flörsheim , GERMANY
  9. **
  10. ** (C) Copyright 1994,1995
  11. ** All Rights Reserved !
  12. **
  13. ** $HISTORY:
  14. **
  15. ** 08.01.95 : 001.004 : changed to rexxxref.library
  16. ** 30.11.94 : 001.003 : added LoadXRef() and ExpungeXRef()
  17. ** 26.11.94 : 001.002 : now FindXRef() works
  18. ** 28.05.94 : 001.001 : initial
  19. */
  20.  
  21. /* ------------------------------- include -------------------------------- */
  22.  
  23. #include "rexxxref.h"
  24.  
  25. /* ------------------------------- AutoDoc -------------------------------- */
  26.  
  27. /*FS*/ /*"AutoDoc"*/
  28. /*GB*** rexxxref.library/--rexxhost-- ****************************************
  29. *
  30. *    HOST INTERFACE
  31. *        rexxxref.library provides an ARexx function host interface that
  32. *        enables ARexx programs to take advantage of the features of the
  33. *        XRef-System.
  34. *
  35. *        The function host library vector is located at offset -30 from the
  36. *        library. This is the value you provide to ARexx in the AddLib()
  37. *        function call.
  38. *
  39. *    FUNCTIONS
  40. *        FindXRef(STRING/A,CATEGORY,LIMIT/N,NOPATTERN/S,NOCASE/S,STEM)
  41. *        LoadXRef(FILE/A,XREFPRI/N,LOCK/S,INDEX/S)
  42. *        ExpungeXRef(CATEGORY,FILE,FORCE/S)
  43. *
  44. *    EXAMPLES
  45. *        \* xref.library ARexx example *\
  46. *        OPTIONS RESULTS
  47. *
  48. *        IF ~SHOW('L','xref.library') THEN
  49. *            CALL ADDLIB('xref.library',0,-30)
  50. *
  51. *        \* load explicitly the sys_autodoc.xref *\
  52. *        IF LoadXRef('sys_autodoc.xref',10,,'INDEX') THEN
  53. *           Say "sys_autodoc.xref loaded with priority 10 !"
  54. *        ELSE
  55. *           Say "Can't load sys_autodoc.xref"
  56. *
  57. *        IF FindXRef('#?Window#?',,10,,,,) THEN
  58. *            DO i = 1 TO xref.count
  59. *                Say "XRef     : " xref.i.Name
  60. *                Say "Type     : " xref.i.Type
  61. *                Say "NodeName : " xref.i.NodeName
  62. *                Say "File     : " xref.i.File
  63. *                Say "Path     : " xref.i.Path
  64. *                Say "Line     : " xref.i.Line
  65. *            END
  66. *        ELSE
  67. *            Say "FindXRef() error : " ERRORTEXT(RC)
  68. *        EXIT
  69. *
  70. *    SEE ALSO
  71. *        ParseXRef() ,XR_LoadXRef() ,XR_ExpungeXRef()
  72. *
  73. ******************************************************************************
  74. *
  75. */
  76. /*FE*/
  77.  
  78. /* --------------------- My ARexx function structure ---------------------- */
  79.  
  80. struct ARexxFunction
  81. {
  82.    STRPTR af_Name;
  83.    ULONG (*af_Function)(const struct ARexxFunction *func,struct RexxMsg *rmsg,STRPTR *argstr,struct RexxXRefBase *rxb);
  84.    UWORD af_Args;
  85. };
  86.  
  87. /* ---------------------- ARexx Function definition ----------------------- */
  88.  
  89. static const struct ARexxFunction rexxfunc[] = {
  90.    {"FINDXREF"    ,findxref    ,FX_MAX},
  91.    {"LOADXREF"    ,loadxref    ,LX_MAX},
  92.    {"EXPUNGEXREF" ,expungexref ,EX_MAX},
  93.    {NULL,NULL,0}};
  94.  
  95. /* ------------------------ ARexx Function Server ------------------------- */
  96.  
  97. LibCall ULONG RexxCmdParser(REGA0 struct RexxMsg *rmsg,REGA6 struct RexxXRefBase *rxb)
  98. {
  99.    if(rmsg && rmsg->rm_Args[0])
  100.    {
  101.       const struct ARexxFunction *func = rexxfunc;
  102.  
  103.       while(func->af_Function)
  104.       {
  105.          if(!Stricmp(rmsg->rm_Args[0],func->af_Name))
  106.          {
  107.             UBYTE buf[20];
  108.             STRPTR argstr = NULL;
  109.             ULONG rc;
  110.  
  111.             DB(("ARexx Function :\n"));
  112.             D({
  113.                   ULONG i;
  114.                   bug("%s(",rmsg->rm_Args[0]);
  115.                   for(i = 1 ; i < func->af_Args ; i++)
  116.                      if(rmsg->rm_Args[i])
  117.                         bug("\"%s\",",rmsg->rm_Args[i]);
  118.                   bug("\"%s\")\n",rmsg->rm_Args[i]);
  119.               });
  120.  
  121.             rc = func->af_Function(func,rmsg,&argstr,rxb);
  122.  
  123.             if(rc == RC_OK && !argstr)
  124.                if(!(argstr = CreateArgstring("0",1)))
  125.                   rc = RXERR_NO_FREE_STORE;
  126.  
  127.             DB(("rc : %ld\n",rc));
  128.  
  129.             /* set RC variable */
  130.             sprintf(buf,"%ld",rc);
  131.             SetRexxVar((struct Message *) rmsg,"RC",buf,strlen(buf));
  132.  
  133.             putreg(REG_A0,(LONG) argstr);
  134.  
  135.             return(rc);
  136.          }
  137.          func++;
  138.       }
  139.    }
  140.    return(1);
  141. }
  142.  
  143.