home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxdlg11.zip / rx3.c < prev    next >
Text File  |  1995-03-03  |  3KB  |  132 lines

  1. /* RX.C (RX.EXE)
  2.  *
  3.  * This is a Presentation Manager program that launches a REXX script and allows it to open and use a PM window
  4.  * with PM controls in order to obtain user input (as opposed to "pull"ing from a command line prompt). It takes 1 arg
  5.  * from OS/2; the name of the REXX script to launch. It uses Rexx Dialog to implement the REXX/PM interface.
  6.  */
  7.  
  8. #define INCL_WINSYS
  9. #define INCL_WINWINDOWMGR
  10.  
  11. #include <os2.h>
  12. #include "rx.h"
  13.  
  14.  
  15.  
  16. /* Functions for REXX commands */
  17. VOID EXPENTRY Add2(VOID);
  18. VOID EXPENTRY Subtract2(VOID);
  19.  
  20.  
  21.  
  22. /* Globals */
  23. HMQ hmq;
  24. PFUNC cmdFuncs[] = { Add2, Subtract2 };
  25. UCHAR cmdArray[] = {3, 'A', 'D', 'D', 8, 'S', 'U', 'B', 'T', 'R', 'A', 'C', 'T', 0 };
  26.  
  27.  
  28.  
  29. /********************************** main() ********************************
  30.  * 1. Initializes PM environment: obtains anchor block handle and creates msg queue
  31.  *    that all of the Rexx Dialog windows use.
  32.  * 2. Initializes REXXSPEC for adding 2 REXX commands: APPADD, APPSUBTRACT
  33.  * 3. Calls RexxSet() routine (init RXDLG.DLL stuff)
  34.  * 4. Executes REXX script
  35.  * 5. Frees resources
  36.  * 6. Ends program
  37.  *
  38.  * Return: 0 if successful execution, non-zero if error
  39.  *************************************************************************/
  40. int main(int argc, char *argv[], char *envp[])
  41. {
  42.     register ULONG id;
  43.  
  44.     /* Obtain and initialize PM Message Queue for this process */
  45.     if(!(RexxSpec.Hab = WinInitialize(0)))
  46.     {
  47. badinit:
  48.     DosBeep(60, 120);
  49.     return(ERRAPP);
  50.     }
  51.  
  52.     if(!(hmq = WinCreateMsgQueue(RexxSpec.Hab, 0)))
  53.     {
  54.     WinTerminate(RexxSpec.Hab);
  55.     goto badinit;
  56.     }
  57.  
  58.     /* Is there a REXX script name specified? */
  59.     if (argc>1)
  60.     {
  61.     /* Setup this app's REXX commands */
  62.     RexxSpec.Cmds = &cmdArray[0];
  63.     RexxSpec.Handlers = &cmdFuncs[0];
  64.     RexxSpec.Prefix = "APP";
  65.  
  66.     /* Install REXX support */
  67.     if((id = RexxSet()))
  68.     {
  69.         DlgErrMsg(id, id+ERRAPP);
  70.     }
  71.     else
  72.     {
  73.         /* Execute REXX script (if it exists) */
  74.         RexxRunScript(argv[1]);
  75.  
  76.         /* Uninstall REXX support */
  77.         RexxFree();
  78.     }
  79.     }
  80.     /* Print usage */
  81.     else
  82.     {
  83.     DlgMsgStr("Usage: RX3 [Rexx script filename]", 0, 0);
  84.     }
  85.  
  86.     /* Free resources */
  87.     WinDestroyMsgQueue(hmq);
  88.     WinTerminate(RexxSpec.Hab);
  89.  
  90.     /* Return error code */
  91.     return(RexxSpec.ErrNum);
  92. }
  93.  
  94.  
  95.  
  96. VOID EXPENTRY Add2(VOID)
  97. {
  98.     LONG num1, num2;
  99.  
  100.     /* Get first number */
  101.     num1 = DlgAsciiToNum(RexxSpec.FromStr, &RexxSpec.FromStr, 0);
  102.  
  103.     /* Get second number */
  104.     num2 = DlgAsciiToNum(RexxSpec.FromStr, 0, 0);
  105.  
  106.     /* Add numbers and return it to the script */
  107.     RexxSetNumVar("SUM", num1+num2);
  108. }
  109.  
  110. VOID EXPENTRY Subtract2(VOID)
  111. {
  112.     LONG num1, num2;
  113.  
  114.     /* Get first number */
  115.     num1 = DlgAsciiToNum(RexxSpec.FromStr, &RexxSpec.FromStr, 0);
  116.  
  117.     /* Get second number */
  118.     num2 = DlgAsciiToNum(RexxSpec.FromStr, 0, 0);
  119.  
  120.     /* Check if num1 < num2.  If so, then return an error. We arbitrarily
  121.        choose an error number of ERRAPP+DISPLAYLEVEL, and a display level
  122.        of DISPLAYLEVEL (defined in RX.H) */
  123.     if (num1 < num2)
  124.     {
  125.     DlgMsgStr("Second number smaller than first", ERRAPP+DISPLAYLEVEL, DISPLAYLEVEL);
  126.     return;
  127.     }
  128.  
  129.     /* Subtract numbers and return it to the script in the variable "ANSWER.0" */
  130.     RexxSetNumVar("ANSWER.0", num1-num2);
  131. }
  132.