rexxasp2.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 /* rexxasp2.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 40 /* Raise Rexx error */
59 #define VALID_ROUTINE 0 /* Successful completion */
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 
66 /*********************************************************************/
67 /* AspiFncTable */
68 /* Array of names of the REXXASPI functions. */
69 /* This list is used for registration and deregistration. */
70 /*********************************************************************/
71 static const char *AspiFncTable[] =
72  {
73  "AspiDeregFunc2",
74  "Aspi_Fill_REXX_Variable_Pool"
75  };
76 
77 
78 /*************************************************************************
79 * Function: AspiLoadFuncs2 *
80 * *
81 * Syntax: call AspiLoadFuncs2 *
82 * *
83 * Params: none *
84 * *
85 * Return: null string *
86 *************************************************************************/
87 
89  const char *name, /* Function name */
90  size_t numargs, /* Number of arguments */
91  CONSTRXSTRING args[], /* Argument array */
92  const char * queuename, /* Current queue */
93  PRXSTRING retstr ) /* Return RXSTRING */
94 {
95  int entries; /* Num of entries */
96  int j; /* Counter */
97 
98 
99  entries = sizeof(AspiFncTable)/sizeof(const char *);
100 
101  for (j = 0; j < entries; j++)
102  {
104  }
105  return VALID_ROUTINE;
106 }
107 
108 
109 /*************************************************************************
110 * Function: AspiDeregFunc2 *
111 * *
112 * Syntax: call AspiDeregFuncs2 *
113 * *
114 * Params: none *
115 * *
116 * Return: null string *
117 *************************************************************************/
118 
120  const char *name, /* Function name */
121  size_t numargs, /* Number of arguments */
122  CONSTRXSTRING args[], /* Argument array */
123  const char * queuename, /* Current queue */
124  PRXSTRING retstr ) /* Return RXSTRING */
125 {
126  int entries; /* Num of entries */
127  int j; /* Counter */
128 
129  retstr->strlength = 0; /* set return value */
130 
131  if (numargs > 0)
132  return INVALID_ROUTINE;
133 
134 
135  entries = sizeof(AspiFncTable)/sizeof(const char *);
136 
137  for (j = 0; j < entries; j++)
138  {
140  }
141  return VALID_ROUTINE;
142 }
143 
144 
145 
146 /*************************************************************************
147 * Function: AspiRead *
148 * *
149 * Syntax: call Aspi_Fill_REXX_Variable_Pool *
150 * *
151 * Params: outbuf - variable that will be filled with data *
152 * Return: 0 - success, 1 - failure *
153 *************************************************************************/
154 
156  const char *name, /* Function name */
157  size_t numargs, /* Number of arguments */
158  CONSTRXSTRING args[], /* Argument array */
159  const char * queuename, /* Current queue */
160  PRXSTRING retstr ) /* Return RXSTRING */
161 {
162  char *outbuf = NULL;
163  char *ptr;
164  int i;
165  SHVBLOCK shvb;
166 
167  /* we expect 1 argument */
168 
169  if (numargs != 1 ) /* validate arg count */
170  {
171  strcpy(retstr->strptr, "Aspi_Fill_REXX_Variable_Pool expects 1 Arguments");
172  retstr->strlength = strlen(retstr->strptr);
173  return VALID_ROUTINE;
174  }
175 
176  /* preset the return value */
177 
178  strcpy(retstr->strptr, "0");
179  retstr->strlength = strlen(retstr->strptr);
180 
181  outbuf = (char *) malloc(300);
182  if (outbuf == NULL)
183  {
184  strcpy(retstr->strptr, "Aspi_Fill_REXX_Variable_Pool received a allocation fault");
185  retstr->strlength = strlen(retstr->strptr);
186  return VALID_ROUTINE;
187  }
188 
189  ptr = outbuf;
190  for (i=0; i<300; i++)
191  {
192  *ptr = i % 256;
193  ptr++;
194  }
195 
196 /* copying the buffer to the Rexx Variable Pool ****************/
197 
198  shvb.shvnext = NULL;
199  shvb.shvname.strptr = args[0].strptr;
200  shvb.shvname.strlength = strlen(args[0].strptr);
201  shvb.shvnamelen = shvb.shvname.strlength;
202  shvb.shvvalue.strptr = outbuf;
203  shvb.shvvalue.strlength = 300;
204  shvb.shvvaluelen = 300;
205  shvb.shvcode = RXSHV_SYSET;
206  shvb.shvret = 0;
207  if (RexxVariablePool(&shvb) == RXSHV_BADN)
208  {
209  free(outbuf);
210  strcpy(retstr->strptr, "1");
211  return INVALID_ROUTINE;
212  }
213 
214  free(outbuf);
215  return VALID_ROUTINE;
216 }
217 
218 
219 #ifdef __cplusplus
220 }
221 #endif
222 
223 
224 
RexxReturnCode RexxEntry RexxVariablePool(PSHVBLOCK pshvblock)
RexxReturnCode REXXENTRY RexxDeregisterFunction(CONSTANT_STRING)
RexxReturnCode REXXENTRY RexxRegisterFunctionDll(CONSTANT_STRING, CONSTANT_STRING, CONSTANT_STRING)
int RexxReturnCode
Definition: rexx.h:73
#define RXSHV_BADN
Definition: rexxapidefs.h:116
#define RXSHV_SYSET
Definition: rexxapidefs.h:100
RexxReturnCode REXXENTRY AspiDeregFunc2(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
Definition: rexxasp2.c:119
RexxReturnCode REXXENTRY Aspi_Fill_REXX_Variable_Pool(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
Definition: rexxasp2.c:155
#define VALID_ROUTINE
Definition: rexxasp2.c:59
RexxReturnCode REXXENTRY AspiLoadFuncs2(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
Definition: rexxasp2.c:88
static const char * AspiFncTable[]
Definition: rexxasp2.c:71
#define INVALID_ROUTINE
Definition: rexxasp2.c:58
const char * strptr
Definition: rexx.h:163
size_t strlength
Definition: rexx.h:157
char * strptr
Definition: rexx.h:158
size_t shvvaluelen
Definition: rexx.h:209
CONSTANT_RXSTRING shvname
Definition: rexx.h:206
unsigned char shvret
Definition: rexx.h:211
unsigned char shvcode
Definition: rexx.h:210
RXSTRING shvvalue
Definition: rexx.h:207
size_t shvnamelen
Definition: rexx.h:208
struct _SHVBLOCK * shvnext
Definition: rexx.h:205
#define REXXENTRY