1 |
|
---|
2 | #define INCL_REXXSAA
|
---|
3 | #ifdef __EMX__
|
---|
4 | #include <os2emx.h>
|
---|
5 | #else
|
---|
6 | #include <os2.h>
|
---|
7 | #include <rexxsaa.h> /* needed for RexxStart() */
|
---|
8 | #endif
|
---|
9 | #include <string.h>
|
---|
10 | #include <stdio.h>
|
---|
11 | #include <stdlib.h>
|
---|
12 |
|
---|
13 | #if __cplusplus
|
---|
14 | extern "C" {
|
---|
15 | #endif
|
---|
16 |
|
---|
17 | #define INVALID_ROUTINE 40 /* Raise Rexx error */
|
---|
18 | #define VALID_ROUTINE 0 /* Successful completion */
|
---|
19 | #define MAX_VAR_LEN 270
|
---|
20 | typedef struct RxStemData {
|
---|
21 | SHVBLOCK shvb; /* Request block for RxVar */
|
---|
22 | CHAR varname[MAX_VAR_LEN]; /* Buffer for the variable */
|
---|
23 | /* name */
|
---|
24 | ULONG stemlen; /* Length of stem. */
|
---|
25 | } RXSTEMDATA;
|
---|
26 |
|
---|
27 | /*!**************************************************/
|
---|
28 | /* */
|
---|
29 | /* @@DESC */
|
---|
30 | /* */
|
---|
31 | /* To be written... */
|
---|
32 | /* */
|
---|
33 | /*!!*************************************************/
|
---|
34 | LONG RxGetLongFromStemWithoutNumber(RXSTRING args, char * chrTail, ULONG* ulError)
|
---|
35 | {
|
---|
36 | char text[20];
|
---|
37 | RXSTEMDATA ldp={0};
|
---|
38 |
|
---|
39 | *ulError=0;
|
---|
40 | /* Initialize data area */
|
---|
41 | strcpy(ldp.varname, args.strptr);
|
---|
42 | ldp.stemlen = args.strlength;
|
---|
43 | strupr(ldp.varname); /* uppercase the name */
|
---|
44 |
|
---|
45 | if (ldp.varname[ldp.stemlen-1] != '.')
|
---|
46 | ldp.varname[ldp.stemlen++] = '.';
|
---|
47 |
|
---|
48 | /* Add tail to stem */
|
---|
49 | strncat(ldp.varname+ldp.stemlen, chrTail, sizeof(ldp.varname)-ldp.stemlen);
|
---|
50 | ldp.varname[sizeof(ldp.varname)-1]=0;
|
---|
51 |
|
---|
52 | ldp.shvb.shvnext = NULL; /* Only one request block */
|
---|
53 | ldp.shvb.shvname.strptr = ldp.varname; /* Var name */
|
---|
54 | ldp.shvb.shvname.strlength = strlen(ldp.varname); /* RxString length */
|
---|
55 | ldp.shvb.shvnamelen = ldp.shvb.shvname.strlength;
|
---|
56 |
|
---|
57 | ldp.shvb.shvcode = RXSHV_SYFET; /* Get a value */
|
---|
58 | ldp.shvb.shvret = 0;
|
---|
59 |
|
---|
60 | /* The value field of the request block is empty so REXX will allocate memory for us
|
---|
61 | which holds the value. */
|
---|
62 |
|
---|
63 | /* Now get the value */
|
---|
64 | if (RexxVariablePool(&ldp.shvb) == RXSHV_BADN) {
|
---|
65 | *ulError=1;
|
---|
66 | return 0; /* error on non-zero */
|
---|
67 | }
|
---|
68 |
|
---|
69 | if(sizeof(text) > ldp.shvb.shvvalue.strlength) {
|
---|
70 | strncpy(text, ldp.shvb.shvvalue.strptr, ldp.shvb.shvvalue.strlength);
|
---|
71 | text[ldp.shvb.shvvalue.strlength]=0;
|
---|
72 | }
|
---|
73 | else
|
---|
74 | strncpy(text, ldp.shvb.shvvalue.strptr, sizeof(text));
|
---|
75 | text[sizeof(text)-1]=0;
|
---|
76 |
|
---|
77 | /* Free mem allocated for us by REXX */
|
---|
78 | DosFreeMem(ldp.shvb.shvvalue.strptr);
|
---|
79 |
|
---|
80 | return atol(text);
|
---|
81 | }
|
---|
82 |
|
---|
83 | /*!***********************************************************/
|
---|
84 | /* */
|
---|
85 | /* @@DESC */
|
---|
86 | /* */
|
---|
87 | /* This function returns a string from a stem. The caller */
|
---|
88 | /* must free the returned string with free() */
|
---|
89 | /* */
|
---|
90 | /*!!**********************************************************/
|
---|
91 | PSZ RxGetStringFromStemWithoutNumber(RXSTRING args, char *chrTail, ULONG* ulError)
|
---|
92 | {
|
---|
93 | RXSTEMDATA ldp={0};
|
---|
94 | char *pText;
|
---|
95 | *ulError=0;
|
---|
96 |
|
---|
97 | /* Initialize data area */
|
---|
98 | strcpy(ldp.varname, args.strptr);
|
---|
99 | ldp.stemlen = args.strlength;
|
---|
100 | strupr(ldp.varname); /* uppercase the name */
|
---|
101 |
|
---|
102 | if (ldp.varname[ldp.stemlen-1] != '.')
|
---|
103 | ldp.varname[ldp.stemlen++] = '.';
|
---|
104 |
|
---|
105 | /* Add tail to stem */
|
---|
106 | sprintf(ldp.varname+ldp.stemlen, "%s", chrTail);
|
---|
107 |
|
---|
108 | ldp.shvb.shvnext = NULL; /* Only one request block */
|
---|
109 | ldp.shvb.shvname.strptr = ldp.varname; /* Var name */
|
---|
110 | ldp.shvb.shvname.strlength = strlen(ldp.varname); /* RxString length */
|
---|
111 | ldp.shvb.shvnamelen = ldp.shvb.shvname.strlength;
|
---|
112 |
|
---|
113 | ldp.shvb.shvcode = RXSHV_SYFET; /* Get a value */
|
---|
114 | ldp.shvb.shvret = 0;
|
---|
115 |
|
---|
116 | /* The value field of the request block is empty so REXX will allocate memory for us
|
---|
117 | which holds the value. */
|
---|
118 |
|
---|
119 | /* Now get the value */
|
---|
120 | if (RexxVariablePool(&ldp.shvb) == RXSHV_BADN) {
|
---|
121 | *ulError=1;
|
---|
122 | return 0; /* error on non-zero */
|
---|
123 | }
|
---|
124 |
|
---|
125 | if((pText=(char*)malloc(ldp.shvb.shvvalue.strlength+1))!=NULLHANDLE)
|
---|
126 | {
|
---|
127 | strncpy(pText, ldp.shvb.shvvalue.strptr, ldp.shvb.shvvalue.strlength);
|
---|
128 | pText[ldp.shvb.shvvalue.strlength]=0;
|
---|
129 | }
|
---|
130 | /* Free mem allocated for us by REXX */
|
---|
131 | DosFreeMem(ldp.shvb.shvvalue.strptr);
|
---|
132 |
|
---|
133 | return pText;
|
---|
134 | }
|
---|
135 |
|
---|
136 | /*!***********************************************************/
|
---|
137 | /* */
|
---|
138 | /* @@DESC */
|
---|
139 | /* */
|
---|
140 | /* This function returns a long from a REXX var. */
|
---|
141 | /* */
|
---|
142 | /*!!**********************************************************/
|
---|
143 | LONG RxGetLongFromVar(char * chrVar, ULONG* ulError)
|
---|
144 | {
|
---|
145 | char text[20];
|
---|
146 | RXSTEMDATA ldp={0};
|
---|
147 |
|
---|
148 | *ulError=0;
|
---|
149 |
|
---|
150 | /* Initialize data area */
|
---|
151 | strcpy(ldp.varname, chrVar);
|
---|
152 | ldp.stemlen = strlen(chrVar);
|
---|
153 | strupr(ldp.varname); /* uppercase the name */
|
---|
154 |
|
---|
155 | ldp.varname[sizeof(ldp.varname)-1]=0;
|
---|
156 |
|
---|
157 | ldp.shvb.shvnext = NULL; /* Only one request block */
|
---|
158 | ldp.shvb.shvname.strptr = ldp.varname; /* Var name */
|
---|
159 | ldp.shvb.shvname.strlength = strlen(ldp.varname); /* RxString length */
|
---|
160 | ldp.shvb.shvnamelen = ldp.shvb.shvname.strlength;
|
---|
161 |
|
---|
162 | ldp.shvb.shvcode = RXSHV_SYFET; /* Get a value */
|
---|
163 | ldp.shvb.shvret = 0;
|
---|
164 |
|
---|
165 | /* The value field of the request block is empty so REXX will allocate memory for us
|
---|
166 | which holds the value. */
|
---|
167 |
|
---|
168 | /* Now get the value */
|
---|
169 | if (RexxVariablePool(&ldp.shvb) == RXSHV_BADN) {
|
---|
170 | *ulError=1;
|
---|
171 | return 0; /* error on non-zero */
|
---|
172 | }
|
---|
173 |
|
---|
174 | if(sizeof(text) > ldp.shvb.shvvalue.strlength) {
|
---|
175 | strncpy(text, ldp.shvb.shvvalue.strptr, ldp.shvb.shvvalue.strlength);
|
---|
176 | text[ldp.shvb.shvvalue.strlength]=0;
|
---|
177 | }
|
---|
178 | else
|
---|
179 | strncpy(text, ldp.shvb.shvvalue.strptr, sizeof(text));
|
---|
180 | text[sizeof(text)-1]=0;
|
---|
181 |
|
---|
182 | /* Free mem allocated for us by REXX */
|
---|
183 | DosFreeMem(ldp.shvb.shvvalue.strptr);
|
---|
184 |
|
---|
185 | return atol(text);
|
---|
186 | }
|
---|
187 |
|
---|
188 | /*!***********************************************************/
|
---|
189 | /* */
|
---|
190 | /* @@DESC */
|
---|
191 | /* */
|
---|
192 | /* To be written... */
|
---|
193 | /* */
|
---|
194 | /*!!**********************************************************/
|
---|
195 | LONG RxSetLongInRexxVar(char* chrVar, ULONG ulVal)
|
---|
196 | {
|
---|
197 | RXSTEMDATA ldp;
|
---|
198 | char valString[34];
|
---|
199 |
|
---|
200 | if(!chrVar || !strlen(chrVar))
|
---|
201 | return INVALID_ROUTINE; /* error on non-zero */
|
---|
202 |
|
---|
203 | memset(&ldp, 0, sizeof(ldp));
|
---|
204 | /* Initialize data area */
|
---|
205 | strcpy(ldp.varname, chrVar);
|
---|
206 | ldp.stemlen = strlen(chrVar);
|
---|
207 | strupr(ldp.varname); /* uppercase the name */
|
---|
208 |
|
---|
209 | ldp.shvb.shvnext = NULL; /* Only one request block */
|
---|
210 | ldp.shvb.shvname.strptr = ldp.varname; /* Var name */
|
---|
211 | ldp.shvb.shvname.strlength = strlen(ldp.varname); /* RxString length */
|
---|
212 | ldp.shvb.shvnamelen = ldp.shvb.shvname.strlength;
|
---|
213 | /* Set the value of the var */
|
---|
214 | ldp.shvb.shvvalue.strptr = _ultoa(ulVal, valString, 10); /* Make a string from the var */
|
---|
215 | ldp.shvb.shvvalue.strlength = strlen(valString);
|
---|
216 | ldp.shvb.shvvaluelen = ldp.shvb.shvvalue.strlength;
|
---|
217 | ldp.shvb.shvcode = RXSHV_SYSET;
|
---|
218 | ldp.shvb.shvret = 0;
|
---|
219 |
|
---|
220 | if (RexxVariablePool(&ldp.shvb) == RXSHV_BADN)
|
---|
221 | return INVALID_ROUTINE; /* error on non-zero */
|
---|
222 |
|
---|
223 | return VALID_ROUTINE;
|
---|
224 | }
|
---|
225 |
|
---|
226 | #if __cplusplus
|
---|
227 | }
|
---|
228 | #endif
|
---|
229 |
|
---|