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