1 /***********************************************************************/
2 /* Open Visualization Data Explorer */
3 /* (C) Copyright IBM Corp. 1989,1999 */
4 /* ALL RIGHTS RESERVED */
5 /* This code licensed under the */
6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */
7 /***********************************************************************/
8
9 #include <dxconfig.h>
10
11
12 #include <stdio.h>
13 #include <dx/dx.h>
14 #include "config.h"
15 #include "nodeb.h"
16 #include "pmodflags.h"
17 #include "_macro.h"
18 #include "distp.h"
19 #include "remote.h"
20
21 extern Error _dxfByteSwap(void *dest, void *src, int ndata, Type t); /* from libdx/edfdata.c */
22
23 static char rbuffer[PTBUFSIZE];
24 static int SwapMsg;
25
readN(int fd,Pointer Buffer,int n,Type t)26 Error readN(int fd, Pointer Buffer, int n, Type t)
27 {
28 static int bytesleft = 0;
29 static char *ptr;
30 static int nbytes;
31
32 nbytes = n * DXTypeSize(t);
33
34 /* The 2 _dxf_ExReceiveBuffer calls here did not include SwapMsg. Prototyping
35 * revealed the coding error. However, now someone that knows needs to check
36 * out the calls with _dxfByteSwap.
37 */
38
39 if(nbytes > PTBUFSIZE-sizeof(int)) {
40 if(_dxf_ExReceiveBuffer(fd, Buffer, n, t, SwapMsg) < 0) {
41 DXUIMessage("ERROR", "Received bad parse tree");
42 return(ERROR);
43 }
44 else
45 return(OK);
46 }
47
48 if(bytesleft == 0) {
49 if(_dxf_ExReceiveBuffer(fd, rbuffer, PTBUFSIZE, TYPE_UBYTE, SwapMsg) < 0) {
50 DXUIMessage("ERROR", "Received bad parse tree");
51 return(ERROR);
52 }
53 bcopy(rbuffer, &bytesleft, sizeof(int));
54 if(SwapMsg)
55 _dxfByteSwap(&bytesleft, &bytesleft, 1, TYPE_INT);
56 bytesleft -= sizeof(int);
57 ptr = rbuffer + sizeof(int);
58 }
59
60 bcopy(ptr, Buffer, nbytes);
61 if(SwapMsg)
62 _dxfByteSwap(Buffer, Buffer, n, t);
63
64 bytesleft -= nbytes;
65 ptr += nbytes;
66 return(OK);
67 }
68
69 struct node *ExReadNode(int fd);
70
_dxf_ExReadTree(int fd,int swap)71 struct node *_dxf_ExReadTree(int fd, int swap)
72 {
73 node *pt;
74 SwapMsg = swap;
75 pt = ExReadNode(fd);
76 return(pt);
77 }
78
ExReadNodeList(int fd)79 struct node *ExReadNodeList(int fd)
80 {
81 int i, numattr;
82 struct node *hdr = NULL;
83 struct node *curr;
84
85 readN(fd, &numattr, 1, TYPE_INT);
86
87 if(numattr > 0) {
88 hdr = ExReadNode(fd);
89 LIST_CREATE(hdr);
90 }
91 for(i = 1; i < numattr; i++) {
92 curr = ExReadNode(fd);
93 LIST_APPEND(hdr, curr);
94 }
95 return(hdr);
96 }
97
98
ExReadNode(int fd)99 struct node *ExReadNode(int fd)
100 {
101 int len;
102 node *n;
103 int type_code;
104 _ntype type;
105 struct node *function;
106
107 readN(fd, &type_code, 1, TYPE_INT);
108 type = (_ntype) type_code;
109 n = _dxf_ExPCreateNode( type );
110 /* first print node attributes */
111 n->attr = ExReadNodeList(fd);
112 n->type = type;
113
114 switch (type)
115 {
116 case NT_MACRO: /* macro definition */
117 case NT_MODULE:
118 n->v.function.id = ExReadNodeList(fd);
119 /* read next 3 ints - flags, nin, nout */
120 readN(fd, &(n->v.function.flags), 3, TYPE_INT);
121 n->v.function.in = ExReadNodeList(fd);
122 readN(fd, &(n->v.function.varargs), 1, TYPE_INT);
123 n->v.function.out = ExReadNodeList(fd);
124 if(type == NT_MACRO)
125 n->v.function.def.stmt = ExReadNodeList(fd);
126 else {
127 if(n->v.function.flags & MODULE_OUTBOARD)
128 n->v.function.def.func = DXOutboard;
129 else {
130 function =(node *)_dxf_ExMacroSearch(n->v.function.id->v.id.id);
131 if(function)
132 n->v.function.def.func = function->v.function.def.func;
133 else
134 n->v.function.def.func = NULL;
135 }
136 }
137 /* read next 2 ints - prehidden, posthidden */
138 readN(fd, &(n->v.function.prehidden), 2, TYPE_INT);
139 #if 0
140 readN(fd, n->v.function.led, 4, TYPE_UBYTE);
141 #endif
142 readN(fd, &(n->v.function.index), 1, TYPE_INT);
143 break;
144 case NT_ASSIGNMENT:
145 n->v.assign.lval = ExReadNodeList(fd);
146 n->v.assign.rval = ExReadNodeList(fd);
147 break;
148 case NT_CALL:
149 n->v.call.id = ExReadNodeList(fd);
150 n->v.call.arg = ExReadNodeList(fd);
151 break;
152 case NT_PRINT:
153 readN(fd, &(n->v.print.type), 1, TYPE_INT);
154 n->v.print.val = ExReadNodeList(fd);
155 break;
156 case NT_ATTRIBUTE:
157 n->v.attr.id = ExReadNodeList(fd);
158 n->v.attr.val = ExReadNodeList(fd);
159 break;
160 case NT_ARGUMENT:
161 n->v.arg.id = ExReadNodeList(fd);
162 n->v.arg.val = ExReadNodeList(fd);
163 break;
164 case NT_LOGICAL:
165 case NT_ARITHMETIC:
166 readN(fd, &(n->v.expr.op), 1, TYPE_INT);
167 n->v.expr.lhs = ExReadNodeList(fd);
168 n->v.expr.rhs = ExReadNodeList(fd);
169 break;
170 case NT_CONSTANT:
171 /* the information in this structure is enough to */
172 /* reconstruct the array in obj. I will rebuild the */
173 /* array obj on the other side. */
174 readN(fd, &(n->v.constant.items), 1, TYPE_INT);
175 readN(fd, &(n->v.constant.type), 1, TYPE_INT);
176 n->v.constant.origin = n->v.constant.delta = NULL;
177 n->v.constant.obj = NULL;
178 if(n->v.constant.type != TYPE_UBYTE) {
179 int regular = 0;
180 readN(fd, ®ular, 1, TYPE_INT);
181 if(regular) {
182 if(n->v.constant.type == TYPE_FLOAT) {
183 n->v.constant.origin =
184 (float *)DXAllocateLocal(sizeof(float));
185 if(n->v.constant.origin == NULL)
186 _dxf_ExDie("Could not allocate memory for data");
187 n->v.constant.delta =
188 (float *)DXAllocateLocal(sizeof(float));
189 if(n->v.constant.delta == NULL)
190 _dxf_ExDie("Could not allocate memory for data");
191 readN(fd, n->v.constant.origin, 1, TYPE_FLOAT);
192 readN(fd, n->v.constant.delta, 1, TYPE_FLOAT);
193 }
194 if(n->v.constant.type == TYPE_INT) {
195 n->v.constant.origin =
196 (int *)DXAllocateLocal(sizeof(int));
197 if(n->v.constant.origin == NULL)
198 _dxf_ExDie("Could not allocate memory for data");
199 n->v.constant.delta =
200 (int *)DXAllocateLocal(sizeof(int));
201 if(n->v.constant.delta == NULL)
202 _dxf_ExDie("Could not allocate memory for data");
203 readN(fd, n->v.constant.origin, 1, TYPE_INT);
204 readN(fd, n->v.constant.delta, 1, TYPE_INT);
205 }
206 }
207 else {
208 readN(fd, &(n->v.constant.cat), 1, TYPE_INT);
209 readN(fd, &(n->v.constant.rank), 1, TYPE_INT);
210 if(n->v.constant.rank > 0) {
211 if(n->v.constant.rank <= LOCAL_SHAPE) {
212 n->v.constant.shape = n->v.constant.lshape;
213 n->v.constant.salloc = LOCAL_SHAPE;
214 }
215 else {
216 n->v.constant.shape =
217 (int *)DXAllocateLocal(
218 n->v.constant.rank*sizeof(int));
219 if(n->v.constant.shape == NULL)
220 _dxf_ExDie("Could not allocate memory");
221 n->v.constant.salloc = n->v.constant.rank;
222 }
223 }
224 readN(fd, n->v.constant.shape, n->v.constant.rank,
225 TYPE_INT);
226 }
227 }
228 if(!n->v.constant.origin) { /* not regular */
229 readN(fd, &len, 1, TYPE_INT);
230 n->v.constant.data = (Pointer *)DXAllocateLocal(len);
231 if(n->v.constant.data == NULL)
232 _dxf_ExDie("Could not allocate memory for data");
233 len /= DXTypeSize(n->v.constant.type);
234 readN(fd, n->v.constant.data, len, n->v.constant.type);
235 }
236 /* make an array object for this node */
237 _dxf_ExEvalConstant(n);
238 break;
239 case NT_ID:
240 readN(fd, &len, 1, TYPE_INT);
241 n->v.id.id = (char *)DXAllocateLocal(len);
242 if(n->v.id.id == NULL)
243 _dxf_ExDie("Could not allocate memory for name");
244 readN(fd, n->v.id.id, len, TYPE_UBYTE);
245 n->v.id.dflt = ExReadNodeList(fd);
246 break;
247 case NT_EXID:
248 readN(fd, &len, 1, TYPE_INT);
249 n->v.exid.id = (char *)DXAllocateLocal(len);
250 if(n->v.exid.id == NULL)
251 _dxf_ExDie("Could not allocate memory for name");
252 readN(fd, n->v.exid.id, len, TYPE_UBYTE);
253 break;
254 case NT_BACKGROUND:
255 readN(fd, &(n->v.background.type), 1, TYPE_INT);
256 readN(fd, &(n->v.background.handle), 1, TYPE_INT);
257 n->v.background.statement = ExReadNodeList(fd);
258 break;
259 case NT_PACKET:
260 readN(fd, &(n->v.packet.type), 1, TYPE_INT);
261 readN(fd, &(n->v.packet.number), 1, TYPE_INT);
262 n->v.packet.packet = ExReadNodeList(fd);
263 readN(fd, &(n->v.packet.size), 1, TYPE_INT);
264 #if 0
265 /* I don't think this is used anymore */
266 /* we'll have to worry about the type and size */
267 /* of data on the other side */
268 n->v.packet.data = (Pointer *)DXAllocateLocal(n->v.packet.size);
269 if(n->v.packet.data == NULL)
270 _dxf_ExDie("Could not allocate memory for data");
271 readN(fd, n->v.packet.data, n->v.packet.size, TYPE_UBYTE);
272 #endif
273 break;
274 case NT_DATA:
275 /* where and when is this type of node used? */
276 /* we could have a problem since we don't know */
277 /* the type of the data. (for lsb vs. msb) */
278 readN(fd, &(n->v.data.len), 1, TYPE_INT);
279 /* we'll have to worry about the type and size */
280 /* of data on the other side */
281 n->v.data.data = (Pointer *)DXAllocateLocal(n->v.data.len);
282 if(n->v.data.data == NULL)
283 _dxf_ExDie("Could not allocate memory for data");
284 readN(fd, n->v.data.data, n->v.data.len, TYPE_UBYTE);
285 break;
286 default:
287 DXSetError(ERROR_INTERNAL, "bad node type\n");
288 DXFree(n);
289 return(NULL);
290 }
291 return(n);
292 }
293
294
295