rexxapi2.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 #include <rexx.h>
45 
46 /*********************************************************************/
47 /* Numeric Return calls */
48 /*********************************************************************/
49 
50 #define INVALID_ROUTINE 40 /* Raise Rexx error */
51 #define VALID_ROUTINE 0 /* Successful completion */
52 
53 
54 /*********************************************************************/
55 /* ApiFncTable */
56 /* Array of names of the REXXApi functions. */
57 /* This list is used for registration and deregistration. */
58 /*********************************************************************/
59 static PSZ ApiFncTable[] =
60  {
61  "Api_Exchange_Data",
62  "ApiDeregFunc",
63  "Api_Fill_REXX_Variable_Pool"
64  };
65 
66 
67 /*************************************************************************
68 * Function: ApiLoadFuncs *
69 * *
70 * Syntax: call ApiLoadFuncs *
71 * *
72 * Params: none *
73 * *
74 * Return: null string *
75 *************************************************************************/
76 
78  PSZ name, /* Function name */
79  LONG numargs, /* Number of arguments */
80  RXSTRING args[], /* Argument array */
81  PSZ queuename, /* Current queue */
82  PRXSTRING retstr ) /* Return RXSTRING */
83 {
84  INT entries; /* Num of entries */
85  INT j; /* Counter */
86 
87 
88  entries = sizeof(ApiFncTable)/sizeof(PSZ);
89 
90  for (j = 0; j < entries; j++)
91  {
93  "REXXAPI2", ApiFncTable[j]);
94  }
95  return VALID_ROUTINE;
96 }
97 
98 
99 /*************************************************************************
100 * Function: ApiDeregFunc *
101 * *
102 * Syntax: call ApiDeregFuncs *
103 * *
104 * Params: none *
105 * *
106 * Return: null string *
107 *************************************************************************/
108 
110  PSZ name, /* Function name */
111  LONG numargs, /* Number of arguments */
112  RXSTRING args[], /* Argument array */
113  PSZ queuename, /* Current queue */
114  PRXSTRING retstr ) /* Return RXSTRING */
115 {
116  INT entries; /* Num of entries */
117  INT j; /* Counter */
118 
119  retstr->strlength = 0; /* set return value */
120 
121  if (numargs > 0)
122  return INVALID_ROUTINE;
123 
124 
125  entries = sizeof(ApiFncTable)/sizeof(PSZ);
126 
127  for (j = 0; j < entries; j++)
128  {
130  }
131  return VALID_ROUTINE;
132  RexxDeregisterFunction("ApiLoadFuncs");
133 }
134 
135 
136 
137 /*************************************************************************
138 * Function: ApiRead *
139 * *
140 * Syntax: call Api_Fill_REXX_Variable_Pool *
141 * *
142 * Params: outbuf - variable that will be filled with data *
143 * Return: 0 - success, 1 - failure *
144 *************************************************************************/
145 
147  PSZ name, /* Function name */
148  LONG numargs, /* Number of arguments */
149  RXSTRING args[], /* Argument array */
150  PSZ queuename, /* Current queue */
151  PRXSTRING retstr ) /* Return RXSTRING */
152 {
153  char *outbuf = NULL;
154  char *ptr;
155  int i;
156  SHVBLOCK shvb;
157 
158  /* we expect 1 argument */
159 
160  if (numargs != 1 ) /* validate arg count */
161  {
162  strcpy(retstr->strptr, "Api_Fill_REXX_Variable_Pool expects 1 arguments");
163  retstr->strlength = strlen(retstr->strptr);
164  return VALID_ROUTINE;
165  }
166 
167  /* preset the return value */
168 
169  strcpy(retstr->strptr, "0");
170  retstr->strlength = 1;
171 
172  outbuf = malloc(300);
173  if (outbuf == NULL)
174  {
175  strcpy(retstr->strptr, "Memory allocation error in Api_Fill_REXX_Variable_Pool!");
176  retstr->strlength = strlen(retstr->strptr);
177  return VALID_ROUTINE;
178  }
179 
180  ptr = outbuf;
181  for (i=0; i<300; i++)
182  {
183  *ptr = i % 256;
184  ptr++;
185  }
186 
187 /* Create a new variable in the REXX Variable Pool ****************/
188 
189  shvb.shvnext = NULL;
190  shvb.shvname.strptr = args[0].strptr;
191  shvb.shvname.strlength = strlen(args[0].strptr);
192  shvb.shvnamelen = shvb.shvname.strlength;
193  shvb.shvvalue.strptr = outbuf;
194  shvb.shvvalue.strlength = 300;
195  shvb.shvvaluelen = 300;
196  shvb.shvcode = RXSHV_SYSET;
197  shvb.shvret = 0;
198  if (RexxVariablePool(&shvb) == RXSHV_BADN)
199  {
200  free(outbuf);
201  strcpy(retstr->strptr, "1");
202  return INVALID_ROUTINE;
203  }
204 
205  free(outbuf);
206  return VALID_ROUTINE;
207 }
RexxReturnCode RexxEntry RexxVariablePool(PSHVBLOCK pshvblock)
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: rexxapi2.c:77
#define VALID_ROUTINE
Definition: rexxapi2.c:51
LONG REXXENTRY Api_Fill_REXX_Variable_Pool(PSZ name, LONG numargs, RXSTRING args[], PSZ queuename, PRXSTRING retstr)
Definition: rexxapi2.c:146
LONG REXXENTRY ApiDeregFunc(PSZ name, LONG numargs, RXSTRING args[], PSZ queuename, PRXSTRING retstr)
Definition: rexxapi2.c:109
#define INVALID_ROUTINE
Definition: rexxapi2.c:50
static PSZ ApiFncTable[]
Definition: rexxapi2.c:59
#define RXSHV_BADN
Definition: rexxapidefs.h:116
#define RXSHV_SYSET
Definition: rexxapidefs.h:100
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