callrxwn.c
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2014 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.oorexx.org/license.html */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /*********************************************************************/
39 /*
40 /* File Name: CALLRXWN - Windows application
41 /*
42 /* Description: Provides a sample call to the REXX
43 /* interpreter, passing in an environment name,
44 /* a file name, and a single argument string.
45 /*
46 /* A dialog box is created for the output.
47 /* Note that you must define a REXX standard
48 /* input and output exit handler for Windows
49 /* applications. Console applications are
50 /* not required to do this.
51 /*
52 /*
53 /* Entry Points: main - main entry point
54 /* RexxIOExit - REXX input and output exit
55 /*
56 /* Input: None
57 /*
58 /* Output: returns 0 in all cases.
59 /*
60 \*********************************************************************/
61 
62 #include <rexx.h> /* needed for RexxStart() */
63 #include <stdio.h> /* needed for printf() */
64 #include <string.h> /* needed for strlen() */
65 #include "callrxwn.h" /* prototypes, globals, const */
66 
67 /*********************************************************************\
68 *
69 * function: WinMain()
70 *
71 * input parameters: c.f. generic sample
72 *
73 \**********************************************************************/
74 int REXXENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
75  LPSTR lpCmdLine, int nCmdShow)
76 {
77 int ret;
78 
79  UNREFERENCED_PARAMETER( hPrevInstance );
80  UNREFERENCED_PARAMETER( lpCmdLine );
81  UNREFERENCED_PARAMETER( nCmdShow);
82  // create a dialog box for REXX STDIO
83  ret = (int)DialogBox (hInstance, MAKEINTRESOURCE(IDD_CALLREXX_DLG), NULL, (DLGPROC)MainDlgProc);
84  return ret;
85 }
86 
87 /**********************************************************************\
88 *
89 * function: MainDlgProc()
90 *
91 * input parameters: standard window procedure parameters.
92 *
93 * Description: at initialization time, call CallRexx routine to do
94 * rexxstart
95 *
96 \**********************************************************************/
97 LRESULT CALLBACK MainDlgProc(HWND hwnd, WORD msg, WPARAM wParam, LPARAM lParam)
98 {
99 
100  UNREFERENCED_PARAMETER(lParam);
101 
102 
103  switch (msg) {
104 
105  case WM_INITDIALOG: {
106  gHwnd=hwnd; // Save handle for exits
107  (VOID)CallRexx(hwnd); // call RexxStart
108  } break;
109 
110 
111  /******************************************************************\
112  * WM_SYSCOMMAND
113  *
114  * ignore all syscommand messages, except for SC_CLOSE.
115  * on this one, call EndDialog().
116  \******************************************************************/
117  case WM_SYSCOMMAND:
118  if (wParam == SC_CLOSE) {
119  EndDialog (hwnd, TRUE);
120  return TRUE;
121  } else
122  return FALSE;
123  break;
124 
125 
126  default: return FALSE;
127  } /* end switch(message) */
128  return 0;
129 }
130 
131 
132 /*********************************************************************\
133 * function: CallRexx()
134 *
135 * Description: Provides a sample call to the REXX
136 * interpreter, passing in an environment name,
137 * a file name, and a single argument string.
138 *
139 * input parameters:
140 * hwnd - parent of the list box with the info.
141 *
142 * output:
143 * returns 0
144 *
145 *
146 \*********************************************************************/
147 int CallRexx(HWND hwnd)
148 {
149 
150  RXSYSEXIT exitlist[9]; /* Exit list array */
151  CONSTRXSTRING arg; /* argument string for REXX */
152  RXSTRING rexxretval; /* return value from REXX */
153 
154  CHAR *str = "These words will be swapped"; /* text to swap */
155 
156  RexxReturnCode rc; /* return code from REXX */
157  SHORT rexxrc = 0; /* return code from function */
158  CHAR *chTextOut[]={
159  "This program will call the REXX interpreter to reverse ",
160  " the order of the words in a string. The interpreter ",
161  " is invoked with an initial environment name of 'FNC'",
162  " and a file name of 'BACKWARD.FNC'" ,
163  "" ,
164  "Below is the result of invoking the interpreter:" ,
165  "" ,
166  "The example is finished, close the" ,
167  "dialog when convenient." ,
168  ""
169  };
170  SHORT sIndex; /* index into output text */
171 
172  /* put info text on dialog */
173  for (sIndex=0; sIndex < 7; sIndex++) {
174  SendDlgItemMessage (hwnd, IDC_LISTBOX, LB_ADDSTRING, 0, (LPARAM)chTextOut[sIndex] );
175  }
176 
177  /* By setting the strlength of the output RXSTRING to zero, we */
178  /* force the interpreter to allocate memory and return it to us. */
179  /* We could provide a buffer for the interpreter to use instead. */
180  rexxretval.strlength = 0L; /* initialize return to empty */
181 
182  MAKERXSTRING(arg, str, strlen(str));/* create input argument */
183 
184  /* register exit handler */
185  rc = RexxRegisterExitExe("RexxIOExit",
186  (REXXPFN)&RexxIOExit, /* located at this address */
187  NULL);
188 
189  /* set up for RXSIO exit */
190  exitlist[0].sysexit_name = "RexxIOExit";
191  exitlist[0].sysexit_code = RXSIO;
192  exitlist[1].sysexit_code = RXENDLST;
193 
194  /* Here we call the interpreter. */
195  rc=RexxStart(1, /* number of arguments */
196  &arg, /* array of arguments */
197  "BACKWARD.FNC", /* name of REXX file */
198  0, /* No INSTORE used */
199  "FNC", /* Command env. name */
200  RXSUBROUTINE, /* Code for how invoked */
201  exitlist, /* No EXITs on this call */
202  &rexxrc, /* Rexx program output */
203  &rexxretval); /* Rexx program output */
204 
205  /* send rc info to dialog box */
206  wsprintf (chTxtBuffer," %s %d", "Interpreter Return Code:", rc);
207  SendDlgItemMessage (hwnd, IDC_LISTBOX, LB_ADDSTRING, 0, (LPARAM)chTxtBuffer);
208 
209  wsprintf (chTxtBuffer," %s %d", "Function Return Code: ", (int) rexxrc);
210  SendDlgItemMessage (hwnd, IDC_LISTBOX, LB_ADDSTRING, 0, (LPARAM)chTxtBuffer);
211 
212  wsprintf (chTxtBuffer," %s '%s'", "Original String: ", arg.strptr);
213  SendDlgItemMessage (hwnd, IDC_LISTBOX, LB_ADDSTRING, 0, (LPARAM)chTxtBuffer);
214 
215  wsprintf (chTxtBuffer," %s '%s'", "Backwards String: ", rexxretval.strptr);
216  SendDlgItemMessage (hwnd, IDC_LISTBOX, LB_ADDSTRING, 0, (LPARAM)chTxtBuffer);
217 
218  for (sIndex=6; sIndex < 10; sIndex++) {
219  SendDlgItemMessage (hwnd, IDC_LISTBOX, LB_ADDSTRING, 0, (LPARAM)chTextOut[sIndex] );
220  }
221 
222  RexxFreeMemory(rexxretval.strptr); /* Release storage */
223  /* given to us by REXX. */
224  /* remove the exit */
225  RexxDeregisterExit("RexxIOExit",NULL);
226 
227  return 0;
228  }
229 
230 /*********************************************************************\
231 * function: CallRexx()
232 *
233 * Description: This is our REXX Standard input and output handler
234 *
235 \*********************************************************************/
237  int ExitNumber, /* code defining exit function*/
238  int Subfunction, /* code defining exit subfunc */
239  PEXIT parmblock) /* func dependent control bloc*/
240 {
241  RXSIOSAY_PARM *sparm ;
242  RXSIOTRC_PARM *tparm ;
243 
244  switch (Subfunction) {
245  case RXSIOSAY: /* write line to standard */
246  /* output stream for SAY instr*/
247  sparm = ( RXSIOSAY_PARM * )parmblock ;
248  SendDlgItemMessage (gHwnd, IDC_LISTBOX, LB_ADDSTRING, 0, (LPARAM)sparm->rxsio_string.strptr);
249  break;
250  case RXSIOTRC: /* write line to standard */
251  /* error stream for trace or */
252  /* error messages */
253  tparm = ( RXSIOTRC_PARM * )parmblock ;
254  SendDlgItemMessage (gHwnd, IDC_LISTBOX, LB_ADDSTRING, 0, (LPARAM)tparm->rxsio_string.strptr);
255  break;
256  case RXSIOTRD: /* read line from standard */
257  /* input stream (PULL) */
258  case RXSIODTR: /* read line from standard */
259  default: /* input stream for */
260  break; /* interactive debug */
261  } /* endswitch */
262 
263  return RXEXIT_HANDLED; /* successfully handled */
264 
265 }
int REXXENTRY RexxStart(size_t argcount, PCONSTRXSTRING arglist, const char *programname, PRXSTRING instore, const char *envname, int calltype, PRXSYSEXIT exits, short *retcode, PRXSTRING result)
int CallRexx(HWND hwnd)
Definition: callrxwn.c:147
int REXXENTRY RexxIOExit(int ExitNumber, int Subfunction, PEXIT parmblock)
Definition: callrxwn.c:236
int REXXENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
Definition: callrxwn.c:74
LRESULT CALLBACK MainDlgProc(HWND hwnd, WORD msg, WPARAM wParam, LPARAM lParam)
Definition: callrxwn.c:97
CHAR chTxtBuffer[128]
Definition: callrxwn.h:48
#define IDD_CALLREXX_DLG
Definition: callrxwn.h:52
HWND gHwnd
Definition: callrxwn.h:45
#define IDC_LISTBOX
Definition: callrxwn.h:53
RexxReturnCode REXXENTRY RexxFreeMemory(void *)
RexxReturnCode REXXENTRY RexxDeregisterExit(CONSTANT_STRING, CONSTANT_STRING)
RexxReturnCode REXXENTRY RexxRegisterExitExe(CONSTANT_STRING, REXXPFN, CONSTANT_STRING)
#define MAKERXSTRING(r, p, l)
Definition: rexx.h:182
char * PEXIT
Definition: rexx.h:215
int RexxReturnCode
Definition: rexx.h:73
#define RXSUBROUTINE
Definition: rexxapidefs.h:65
#define RXENDLST
Definition: rexxapidefs.h:170
#define RXSIOSAY
Definition: rexxapidefs.h:181
#define RXSIO
Definition: rexxapidefs.h:180
#define RXSIOTRC
Definition: rexxapidefs.h:182
#define RXSIOTRD
Definition: rexxapidefs.h:183
#define RXSIODTR
Definition: rexxapidefs.h:184
#define RXEXIT_HANDLED
Definition: rexxapidefs.h:145
const char * strptr
Definition: rexx.h:163
CONSTANT_RXSTRING rxsio_string
Definition: rexx.h:746
CONSTANT_RXSTRING rxsio_string
Definition: rexx.h:753
size_t strlength
Definition: rexx.h:157
char * strptr
Definition: rexx.h:158
CONSTANT_STRING sysexit_name
Definition: rexx.h:191
int sysexit_code
Definition: rexx.h:192
void * REXXPFN
#define REXXENTRY