rexxapi1.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 #include <string.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 
43 #include <windows.h>
44 
45 #include <rexx.h>
46 
47 /*********************************************************************/
48 /* Numeric Return calls */
49 /*********************************************************************/
50 
51 #define INVALID_ROUTINE 40 /* Raise Rexx error */
52 #define VALID_ROUTINE 0 /* Successful completion */
53 
54 
55 /*********************************************************************/
56 /* ApiFncTable */
57 /* Array of names of the REXXASP1 functions. */
58 /* This list is used for registration and deregistration. */
59 /*********************************************************************/
60 static PSZ ApiFncTable[] =
61  {
62  "Api_Output_From_C",
63  "Api_Output_From_REXX",
64  "Api_Exchange_Data",
65  "ApiDeregFunc"
66  };
67 
68 
69 /*************************************************************************
70 * Function: ApiLoadFuncs *
71 * *
72 * Syntax: call ApiLoadFuncs *
73 * *
74 * Params: none *
75 * *
76 * Return: null string *
77 *************************************************************************/
78 
80  PSZ name, /* Function name */
81  LONG numargs, /* Number of arguments */
82  RXSTRING args[], /* Argument array */
83  PSZ queuename, /* Current queue */
84  PRXSTRING retstr ) /* Return RXSTRING */
85 {
86  INT entries; /* Num of entries */
87  INT j; /* Counter */
88 
89 
90  entries = sizeof(ApiFncTable)/sizeof(PSZ);
91 
92  for (j = 0; j < entries; j++)
93  {
95  "REXXAPI1", ApiFncTable[j]);
96  }
97  return VALID_ROUTINE;
98 }
99 
100 
101 /*************************************************************************
102 * Function: ApiDeregFunc *
103 * *
104 * Syntax: call ApiDeregFuncs *
105 * *
106 * Params: none *
107 * *
108 * Return: null string *
109 *************************************************************************/
110 
112  PSZ name, /* Function name */
113  LONG numargs, /* Number of arguments */
114  RXSTRING args[], /* Argument array */
115  PSZ queuename, /* Current queue */
116  PRXSTRING retstr ) /* Return RXSTRING */
117 {
118  INT entries; /* Num of entries */
119  INT j; /* Counter */
120 
121  retstr->strlength = 0; /* set return value */
122 
123  if (numargs > 0)
124  return INVALID_ROUTINE;
125 
126 
127  entries = sizeof(ApiFncTable)/sizeof(PSZ);
128 
129  for (j = 0; j < entries; j++)
130  {
132  }
133  RexxDeregisterFunction("ApiLoadFuncs");
134  return VALID_ROUTINE;
135 }
136 
137 
138 
139 /*************************************************************************
140 * Function: Api_Output_From_C *
141 * *
142 * Syntax: call Api_Output_From_C *
143 * *
144 * Params: none *
145 * *
146 * Return: Version of this API support DLL *
147 *************************************************************************/
148 
150  PSZ name, /* Function name */
151  LONG numargs, /* Number of arguments */
152  RXSTRING args[], /* Argument array */
153  PSZ queuename, /* Current queue */
154  PRXSTRING retstr ) /* Return RXSTRING */
155 {
156 
157  if (numargs > 0)
158  {
159  strcpy(retstr->strptr, "Api_OutPut_From_C does not support any arguments");
160  retstr->strlength = strlen(retstr->strptr);
161  return VALID_ROUTINE;
162  }
163 
164  printf("This output was generated and displayed by the C-function Api_Output_From_C\n");
165  fflush(NULL);
166  return VALID_ROUTINE;
167 }
168 
169 
170 /*************************************************************************
171 * Function: Api_Output_From_REXX *
172 * *
173 * Syntax: call Api_Output_From_REXX *
174 * *
175 * Params: none *
176 * *
177 * Return: Version of this API support DLL *
178 *************************************************************************/
179 
181  PSZ name, /* Function name */
182  LONG numargs, /* Number of arguments */
183  RXSTRING args[], /* Argument array */
184  PSZ queuename, /* Current queue */
185  PRXSTRING retstr ) /* Return RXSTRING */
186 {
187  if (numargs > 0)
188  {
189  strcpy(retstr->strptr, "Api_OutPut_From_REXX does not support any arguments");
190  retstr->strlength = strlen(retstr->strptr);
191  return VALID_ROUTINE;
192  }
193 
194  strcpy(retstr->strptr, "This output was returned from the C-function Api_Output_From_REXX and is displayed by REXX");
195  retstr->strlength = strlen(retstr->strptr);
196  return VALID_ROUTINE;
197 }
198 
199 /*************************************************************************
200 * Function: Api_Exchange_Data *
201 * *
202 * Syntax: call Api_Exchange_Data startsect, numsects, outbuf *
203 * *
204 * Params: parm1 - numeric value given by REXX *
205 * parm2 - numeric value given by REXX *
206 * outbuf - variable given by REXX *
207 * *
208 * Return: 0 - success, 1 - failure *
209 *************************************************************************/
210 
212  PSZ name, /* Function name */
213  LONG numargs, /* Number of arguments */
214  RXSTRING args[], /* Argument array */
215  PSZ queuename, /* Current queue */
216  PRXSTRING retstr ) /* Return RXSTRING */
217 {
218  int parm1 = 0;
219  int parm2 = 0;
220  char outbuf[255];
221 
222  /* we expect 3 arguments */
223 
224  if (numargs != 3 )
225  {
226  strcpy(retstr->strptr, "Api_Exchange_Data function expects 3 arguments");
227  retstr->strlength = strlen(retstr->strptr);
228  return VALID_ROUTINE;
229  }
230 
231  strcpy(retstr->strptr, "\0");
232  retstr->strlength = strlen(retstr->strptr);
233 
234  /* read the values from the parameters */
235 
236  parm1 = atoi(args[0].strptr);
237  parm2 = atoi(args[1].strptr);
238  strcpy(outbuf, args[2].strptr);
239 
240  printf("Api_Exchange_Data function has received the following arguments: Argument 1: %d, Argument 2: %d, Argument 3 %s\n",
241  parm1, parm2, outbuf);
242  fflush(NULL);
243 
244  return VALID_ROUTINE;
245 
246 }
RexxReturnCode REXXENTRY RexxDeregisterFunction(CONSTANT_STRING)
RexxReturnCode REXXENTRY RexxRegisterFunctionDll(CONSTANT_STRING, CONSTANT_STRING, CONSTANT_STRING)
LONG REXXENTRY ApiLoadFuncs(PSZ name, LONG numargs, RXSTRING args[], PSZ queuename, PRXSTRING retstr)
Definition: rexxapi1.c:79
#define VALID_ROUTINE
Definition: rexxapi1.c:52
LONG REXXENTRY Api_Exchange_Data(PSZ name, LONG numargs, RXSTRING args[], PSZ queuename, PRXSTRING retstr)
Definition: rexxapi1.c:211
LONG REXXENTRY ApiDeregFunc(PSZ name, LONG numargs, RXSTRING args[], PSZ queuename, PRXSTRING retstr)
Definition: rexxapi1.c:111
#define INVALID_ROUTINE
Definition: rexxapi1.c:51
LONG REXXENTRY Api_Output_From_REXX(PSZ name, LONG numargs, RXSTRING args[], PSZ queuename, PRXSTRING retstr)
Definition: rexxapi1.c:180
LONG REXXENTRY Api_Output_From_C(PSZ name, LONG numargs, RXSTRING args[], PSZ queuename, PRXSTRING retstr)
Definition: rexxapi1.c:149
static PSZ ApiFncTable[]
Definition: rexxapi1.c:60
size_t strlength
Definition: rexx.h:157
char * strptr
Definition: rexx.h:158
#define REXXENTRY