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