home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warptlk3.zip / TOOLKIT / SAMPLES / REXX / API / RXMACDLL / MACRO.C next >
C/C++ Source or Header  |  1995-08-24  |  13KB  |  234 lines

  1. /*********************************************************************/
  2. /*                                                                   */
  3. /*  File Name:          MACRO.C                                      */
  4. /*                                                                   */
  5. /*  Description:        Provides access to the macrospace interface  */
  6. /*                      functions for REXXSAA from REXX programs     */
  7. /*                      via the Available Function Table, which is   */
  8. /*                      composed of external functions for the REXX  */
  9. /*                      interpreter written in languages other than  */
  10. /*                      REXX.                                        */
  11. /*                                                                   */
  12. /*  Entry Points:       MacroLoad  - load a file or library          */
  13. /*                      MacroSave  - save macrospace to a library    */
  14. /*                      MacroErase - clear the macrospace            */
  15. /*                      MacroQuery - check for a function            */
  16. /*                                                                   */
  17. /*  Notes:              Each of the entry points to this library     */
  18. /*                      conforms to the external function interface  */
  19. /*                      format for REXXSAA, i.e., each function has  */
  20. /*                      five (5) parameters: the name the function   */
  21. /*                      was called as, the argument count, the list  */
  22. /*                      of argument strings, the current active      */
  23. /*                      external data queue, and the address of the  */
  24. /*                      RXSTRING structure to contain any return     */
  25. /*                      information.                                 */
  26. /*                                                                   */
  27. /*                      For each function, the returned value is set */
  28. /*                      to the return code from the macrospace API   */
  29. /*                      function call which it performs; therefore,  */
  30. /*                      to properly use these functions a program    */
  31. /*                      should compare the returned value with '0'   */
  32. /*                      to check for successful completion.          */
  33. /*                                                                   */
  34. /*  Return Codes:        0 == Function completed without error       */
  35. /*                      -1 == Illegal call to function               */
  36. /*                                                                   */
  37. /*  Usage Notes:        Since each function has its own entry point  */
  38. /*                      in the library, they can be registered in    */
  39. /*                      the Available Function Table by any name     */
  40. /*                      which is convenient for a program.  The      */
  41. /*                      function name parameter passed to each       */
  42. /*                      routine by the interpreter is ignored.       */
  43. /*                                                                   */
  44. /*********************************************************************/
  45.  
  46. #define INCL_RXMACRO              /* include macrospace info         */
  47. #define INCL_RXFUNC               /* include external function  info */
  48. #include <rexxsaa.h>              /* REXXSAA header information      */
  49. #include <string.h>
  50.  
  51.  
  52.  
  53.  
  54. /*********************************************************************/
  55. /* MacroLoad                                                         */
  56. /* This function will do one of two functions:                       */
  57. /*   When called with one argument:                                  */
  58. /*     The argument must be the name of a file created by            */
  59. /*     RexxSaveMacroSpace on the current release of OS/2.            */
  60. /*     All macros saved in the file will be loaded.                  */
  61. /*                                                                   */
  62. /*   When called with three arguments:                               */
  63. /*     The first argument must be the name of a REXX program file.   */
  64. /*     The second must be "BEFORE" or "AFTER" (upper/lower case does */
  65. /*       not matter)                                                 */
  66. /*     The third is the name that the REXX program will be called by.*/
  67. /*                                                                   */
  68. /* If called with a different number of arguments, it will raise an  */
  69. /*   error.                                                          */
  70. /*                                                                   */
  71. /* The return value of the function is the return code from          */
  72. /*   calling the RexxLoadMacroSpace or RexxAddMacro API.             */
  73. /*                                                                   */
  74. /*********************************************************************/
  75.  
  76. RexxFunctionHandler MacroLoad;
  77. RexxFunctionHandler MacroSave;
  78. RexxFunctionHandler MacroErase;
  79. RexxFunctionHandler MacroQuery;
  80.  
  81. /*$PE*/
  82. /*$FD.MacroLoad*/
  83.  
  84. ULONG APIENTRY MacroLoad(
  85.    PUCHAR    func,
  86.    ULONG     ac,
  87.    PRXSTRING av,
  88.    PSZ       que,
  89.    PRXSTRING ret)
  90.   {
  91.   APIRET rc = -1;                      /* return code from function  */
  92.   ULONG  srch_ord = -1;                /* search order position flag */
  93.                                        /*                            */
  94.   if (ac == 1) {                       /* 1 arg == library load      */
  95.     rc = RexxLoadMacroSpace(0L,        /* set return code from call  */
  96.                      (PSZ *)0,         /*   to RexxLoadMacroSpace    */
  97.                      av[0].strptr);    /*                            */
  98.     sprintf(ret->strptr, "%d", (int)rc);
  99.     ret->strlength=strlen(ret->strptr);/*                            */
  100.     rc = 0;                            /* no errors in call          */
  101.     }                                  /*                            */
  102.  
  103.   else if (ac == 3) {                  /* 3 args == function load    */
  104.     if (!stricmp(av[1].strptr,"BEFORE"))   /* set 'before' search    */
  105.       srch_ord = RXMACRO_SEARCH_BEFORE;/*                            */
  106.     else if(!stricmp(av[1].strptr,"AFTER"))/* set 'after' search     */
  107.       srch_ord = RXMACRO_SEARCH_AFTER; /*                            */
  108.  
  109.     rc = RexxAddMacro(av[2].strptr,    /* set return code from call  */
  110.                        av[0].strptr,   /*   to RexxAddMacro          */
  111.                        srch_ord),      /*                            */
  112.     sprintf(ret->strptr, "%d", (int)rc);
  113.     ret->strlength=strlen(ret->strptr);/*                            */
  114.     rc = 0;                            /* no errors in call          */
  115.     }                                  /*                            */
  116.  
  117.   /* We usually return 0 to indicate our processing was successful   */
  118.   /* and we have returned a valid result.  If we return non-zero,    */
  119.   /* then REXX will raise error 40, "invalid call to routine".       */
  120.   /* For all the functions in this program, we only raise an         */
  121.   /* error if we are called with an incorrect number of arguments.   */
  122.   return rc;                           /*                            */
  123.   }                                    /*                            */
  124.  
  125.  
  126. /*********************************************************************/
  127. /* MacroSave                                                         */
  128. /* This function must be called with one argument.                   */
  129. /*   The argument must be a valid OS/2 file name.                    */
  130. /*   This function will call RexxSaveMacroSpace to create a file     */
  131. /*   containing all the REXX programs currently loaded in the        */
  132. /*   macrospace.  NOTE:  This file may have to be re-created after   */
  133. /*   applying service or upgrading to a new release of OS/2.         */
  134. /*                                                                   */
  135. /* If called with a different number of arguments, it will raise an  */
  136. /*   error.                                                          */
  137. /*                                                                   */
  138. /* The return value of the function is the return code from          */
  139. /*   calling the RexxSaveMacroSpace API.                             */
  140. /*                                                                   */
  141. /*********************************************************************/
  142. /*$PE*/
  143. /*$FD.MacroSave*/
  144. ULONG APIENTRY MacroSave(
  145.    PUCHAR    func,
  146.    ULONG     ac,
  147.    PRXSTRING av,
  148.    PSZ       que,
  149.    PRXSTRING ret)
  150.   {
  151.   APIRET rc = -1;                      /* return code from function  */
  152.                                        /*                            */
  153.   if (ac == 1) {                       /* need only one arg          */
  154.     rc = RexxSaveMacroSpace(0,         /* set return code from call  */
  155.                      (PSZ *)0,         /*   to RexxSaveMacroSpace    */
  156.                      av[0].strptr);    /*                            */
  157.     sprintf(ret->strptr, "%d",(int)rc);/*                            */
  158.     ret->strlength=strlen(ret->strptr);/*                            */
  159.     rc = 0;                            /* no errors in call          */
  160.     }                                  /*                            */
  161.   return rc;                           /*                            */
  162.   }                                    /*                            */
  163.  
  164.  
  165. /*********************************************************************/
  166. /* MacroErase                                                        */
  167. /* This function must be called with no arguments.                   */
  168. /*   This function will call RexxClearMacroSpace to remove all REXX  */
  169. /*   macros from the macrospace.                                     */
  170. /*                                                                   */
  171. /* If called with any arguments, it will raise an error              */
  172. /*                                                                   */
  173. /* The return value of the function is the return code from          */
  174. /*   calling the RexxSaveMacroSpace API.                             */
  175. /*                                                                   */
  176. /*********************************************************************/
  177. /*$PE*/
  178. /*$FD.MacroErase*/
  179. ULONG APIENTRY MacroErase(
  180.    PUCHAR    func,
  181.    ULONG     ac,
  182.    PRXSTRING av,
  183.    PSZ       que,
  184.    PRXSTRING ret)
  185.   {
  186.   APIRET rc = -1;                      /* return code from function  */
  187.                                        /*                            */
  188.   if (ac == 0) {                       /* no args allowed in call    */
  189.     rc = RexxClearMacroSpace();        /* set return code from call  */
  190.     sprintf(ret->strptr, "%d", (int)rc);
  191.     rc = 0;                            /* no errors in call          */
  192.     }                                  /*                            */
  193.   return rc;                           /*                            */
  194.   }                                    /*                            */
  195.  
  196.  
  197. /*********************************************************************/
  198. /* MacroQuery                                                        */
  199. /* This function must be called with one argument.                   */
  200. /*   The argument gives the name of a macro that may be in the       */
  201. /*   macrospace.  This function will call RexxQueryMacro             */
  202. /*   to find out if the macro is present.  This function returns the */
  203. /*   return code of the RexxQueryMacro API.  This function does not  */
  204. /*   return the search order flag.                                   */
  205. /*                                                                   */
  206. /* If called with a different number of arguments, it will raise an  */
  207. /*   error.                                                          */
  208. /*                                                                   */
  209. /* The return value of the function is the return code from          */
  210. /*   calling the RexxQueryMacro API.                                 */
  211. /*                                                                   */
  212. /*********************************************************************/
  213. /*$PE*/
  214. /*$FD.MacroQuery*/
  215. ULONG APIENTRY MacroQuery(
  216.    PUCHAR    func,
  217.    ULONG     ac,
  218.    PRXSTRING av,
  219.    PSZ       que,
  220.    PRXSTRING ret)
  221.   {
  222.   APIRET rc = -1;                      /* return code from function  */
  223.   USHORT pos = 0;                      /* return of search position  */
  224.                                        /*                            */
  225.   if (ac == 1) {                       /* need only one arg          */
  226.     rc = RexxQueryMacro(av[0].strptr,&pos);/* set return code from   */
  227.                                        /*   call to RexxQueryMacro   */
  228.     sprintf(ret->strptr, "%d", (int) rc);
  229.     ret->strlength=strlen(ret->strptr);/*                            */
  230.     rc = 0;                            /* no errors in call          */
  231.     }                                  /*                            */
  232.   return rc;                           /*                            */
  233.   }                                    /*                            */
  234.