1 | #include "rappture_interface.h" |
---|
2 | #include "RpFortranCommon.h" |
---|
3 | #include "RpDict.h" |
---|
4 | #include <string.h> |
---|
5 | |
---|
6 | /* |
---|
7 | // rappture-fortran api |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef COMPNAME_ADD1UNDERSCORE |
---|
11 | # define rp_init rp_init_ |
---|
12 | # define rp_lib rp_lib_ |
---|
13 | # define rp_lib_element_comp rp_lib_element_comp_ |
---|
14 | # define rp_lib_element_id rp_lib_element_id_ |
---|
15 | # define rp_lib_element_type rp_lib_element_type_ |
---|
16 | # define rp_lib_element_str rp_lib_element_str_ |
---|
17 | # define rp_lib_element_obj rp_lib_element_obj_ |
---|
18 | # define rp_lib_child_num rp_lib_child_num_ |
---|
19 | # define rp_lib_child_comp rp_lib_child_comp_ |
---|
20 | # define rp_lib_child_id rp_lib_child_id_ |
---|
21 | # define rp_lib_child_type rp_lib_child_type_ |
---|
22 | # define rp_lib_child_str rp_lib_child_str_ |
---|
23 | # define rp_lib_child_obj rp_lib_child_obj_ |
---|
24 | # define rp_lib_get rp_lib_get_ |
---|
25 | # define rp_lib_get_double rp_lib_get_double_ |
---|
26 | # define rp_lib_put_str rp_lib_put_str_ |
---|
27 | # define rp_lib_put_id_str rp_lib_put_id_str_ |
---|
28 | # define rp_lib_put_obj rp_lib_put_obj_ |
---|
29 | # define rp_lib_put_id_obj rp_lib_put_id_obj_ |
---|
30 | # define rp_lib_remove rp_lib_remove_ |
---|
31 | # define rp_lib_xml_len rp_lib_xml_len_ |
---|
32 | # define rp_lib_write_xml rp_lib_write_xml_ |
---|
33 | # define rp_lib_xml rp_lib_xml_ |
---|
34 | # define rp_quit rp_quit_ |
---|
35 | # define rp_result rp_result_ |
---|
36 | #elif defined(COMPNAME_ADD2UNDERSCORE) |
---|
37 | # define rp_init rp_init__ |
---|
38 | # define rp_lib rp_lib__ |
---|
39 | # define rp_lib_element_comp rp_lib_element_comp__ |
---|
40 | # define rp_lib_element_id rp_lib_element_id__ |
---|
41 | # define rp_lib_element_type rp_lib_element_type__ |
---|
42 | # define rp_lib_element_str rp_lib_element_str__ |
---|
43 | # define rp_lib_element_obj rp_lib_element_obj__ |
---|
44 | # define rp_lib_child_num rp_lib_child_num__ |
---|
45 | # define rp_lib_child_comp rp_lib_child_comp__ |
---|
46 | # define rp_lib_child_id rp_lib_child_id__ |
---|
47 | # define rp_lib_child_type rp_lib_child_type__ |
---|
48 | # define rp_lib_child_str rp_lib_child_str__ |
---|
49 | # define rp_lib_child_obj rp_lib_child_obj__ |
---|
50 | # define rp_lib_get rp_lib_get__ |
---|
51 | # define rp_lib_get_double rp_lib_get_double__ |
---|
52 | # define rp_lib_put_str rp_lib_put_str__ |
---|
53 | # define rp_lib_put_id_str rp_lib_put_id_str__ |
---|
54 | # define rp_lib_put_obj rp_lib_put_obj__ |
---|
55 | # define rp_lib_put_id_obj rp_lib_put_id_obj__ |
---|
56 | # define rp_lib_remove rp_lib_remove__ |
---|
57 | # define rp_lib_xml_len rp_lib_xml_len__ |
---|
58 | # define rp_lib_write_xml rp_lib_write_xml__ |
---|
59 | # define rp_lib_xml rp_lib_xml__ |
---|
60 | # define rp_quit rp_quit__ |
---|
61 | # define rp_result rp_result__ |
---|
62 | #elif defined(COMPNAME_NOCHANGE) |
---|
63 | # define rp_init rp_init |
---|
64 | # define rp_lib rp_lib |
---|
65 | # define rp_lib_element_comp rp_lib_element_comp |
---|
66 | # define rp_lib_element_id rp_lib_element_id |
---|
67 | # define rp_lib_element_type rp_lib_element_type |
---|
68 | # define rp_lib_element_str rp_lib_element_str |
---|
69 | # define rp_lib_element_obj rp_lib_element_obj |
---|
70 | # define rp_lib_child_num rp_lib_child_num |
---|
71 | # define rp_lib_child_comp rp_lib_child_comp |
---|
72 | # define rp_lib_child_id rp_lib_child_id |
---|
73 | # define rp_lib_child_type rp_lib_child_type |
---|
74 | # define rp_lib_child_str rp_lib_child_str |
---|
75 | # define rp_lib_child_obj rp_lib_child_obj |
---|
76 | # define rp_lib_get rp_lib_get |
---|
77 | # define rp_lib_get_double rp_lib_get_double |
---|
78 | # define rp_lib_put_str rp_lib_put_str |
---|
79 | # define rp_lib_put_id_str rp_lib_put_id_str |
---|
80 | # define rp_lib_put_obj rp_lib_put_obj |
---|
81 | # define rp_lib_put_id_obj rp_lib_put_id_obj |
---|
82 | # define rp_lib_remove rp_lib_remove |
---|
83 | # define rp_lib_xml_len rp_lib_xml_len |
---|
84 | # define rp_lib_write_xml rp_lib_write_xml |
---|
85 | # define rp_lib_xml rp_lib_xml |
---|
86 | # define rp_quit rp_quit |
---|
87 | # define rp_result rp_result |
---|
88 | #elif defined(COMPNAME_UPPERCASE) |
---|
89 | # define rp_init RP_INIT |
---|
90 | # define rp_lib RP_LIB |
---|
91 | # define rp_lib_element_comp RP_LIB_ELEMENT_COMP |
---|
92 | # define rp_lib_element_id RP_LIB_ELEMENT_ID |
---|
93 | # define rp_lib_element_type RP_LIB_ELEMENT_TYPE |
---|
94 | # define rp_lib_element_str RP_LIB_ELEMENT_STR |
---|
95 | # define rp_lib_element_obj RP_LIB_ELEMENT_OBJ |
---|
96 | # define rp_lib_child_num RP_LIB_CHILD_NUM |
---|
97 | # define rp_lib_child_comp RP_LIB_CHILD_COMP |
---|
98 | # define rp_lib_child_id RP_LIB_CHILD_ID |
---|
99 | # define rp_lib_child_type RP_LIB_CHILD_TYPE |
---|
100 | # define rp_lib_child_str RP_LIB_CHILD_STR |
---|
101 | # define rp_lib_child_obj RP_LIB_CHILD_OBJ |
---|
102 | # define rp_lib_get RP_LIB_GET |
---|
103 | # define rp_lib_get_double RP_LIB_GET_DOUBLE |
---|
104 | # define rp_lib_put_str RP_LIB_PUT_STR |
---|
105 | # define rp_lib_put_id_str RP_LIB_PUT_ID_STR |
---|
106 | # define rp_lib_put_obj RP_LIB_PUT_OBJ |
---|
107 | # define rp_lib_put_id_obj RP_LIB_PUT_ID_OBJ |
---|
108 | # define rp_lib_remove RP_LIB_REMOVE |
---|
109 | # define rp_lib_xml_len RP_LIB_XML_LEN |
---|
110 | # define rp_lib_write_xml RP_LIB_WRITE_XML |
---|
111 | # define rp_lib_xml RP_LIB_XML |
---|
112 | # define rp_quit RP_QUIT |
---|
113 | # define rp_result RP_RESULT |
---|
114 | #endif |
---|
115 | |
---|
116 | |
---|
117 | extern "C" |
---|
118 | void rp_init(); |
---|
119 | |
---|
120 | extern "C" |
---|
121 | int rp_lib(const char* filePath, int filePath_len); |
---|
122 | |
---|
123 | extern "C" |
---|
124 | void rp_lib_element_comp( int* handle, |
---|
125 | char* path, |
---|
126 | char* retText, |
---|
127 | int path_len, |
---|
128 | int retText_len ); |
---|
129 | |
---|
130 | extern "C" |
---|
131 | void rp_lib_element_id( int* handle, |
---|
132 | char* path, |
---|
133 | char* retText, |
---|
134 | int path_len, |
---|
135 | int retText_len ); |
---|
136 | |
---|
137 | extern "C" |
---|
138 | void rp_lib_element_type( int* handle, |
---|
139 | char* path, |
---|
140 | char* retText, |
---|
141 | int path_len, |
---|
142 | int retText_len ); |
---|
143 | |
---|
144 | extern "C" |
---|
145 | void rp_lib_element_str( int* handle, |
---|
146 | char* path, |
---|
147 | char* flavor, |
---|
148 | char* retText, |
---|
149 | int path_len, |
---|
150 | int flavor_len, |
---|
151 | int retText_len ); |
---|
152 | |
---|
153 | extern "C" |
---|
154 | int rp_lib_element_obj( int* handle, |
---|
155 | char* path, |
---|
156 | int path_len ); |
---|
157 | |
---|
158 | extern "C" |
---|
159 | int rp_lib_child_num( int* handle, |
---|
160 | char* path, |
---|
161 | int path_len); |
---|
162 | |
---|
163 | extern "C" |
---|
164 | int rp_lib_child_comp( int* handle, /* integer handle of library */ |
---|
165 | char* path, /* DOM path of requested object */ |
---|
166 | char* type, /* specific name of element */ |
---|
167 | int* childNum, /* child number for iteration */ |
---|
168 | char* retText, /* buffer to store return text */ |
---|
169 | int path_len, /* length of path */ |
---|
170 | int type_len, /* length of type */ |
---|
171 | int retText_len /* length of return text buffer */ |
---|
172 | ); |
---|
173 | |
---|
174 | extern "C" |
---|
175 | int rp_lib_child_id( int* handle, /* integer handle of library */ |
---|
176 | char* path, /* DOM path of requested object */ |
---|
177 | char* type, /* specific name of element */ |
---|
178 | int* childNum, /* child number for iteration */ |
---|
179 | char* retText, /* buffer to store return text */ |
---|
180 | int path_len, /* length of path */ |
---|
181 | int type_len, /* length of type */ |
---|
182 | int retText_len /* length of return text buffer */ |
---|
183 | ); |
---|
184 | |
---|
185 | extern "C" |
---|
186 | int rp_lib_child_type( int* handle, /* integer handle of library */ |
---|
187 | char* path, /* DOM path of requested object */ |
---|
188 | char* type, /* specific name of element */ |
---|
189 | int* childNum, /* child number for iteration */ |
---|
190 | char* retText, /* buffer to store return text */ |
---|
191 | int path_len, /* length of path */ |
---|
192 | int type_len, /* length of type */ |
---|
193 | int retText_len /* length of return text buffer */ |
---|
194 | ); |
---|
195 | |
---|
196 | extern "C" |
---|
197 | int rp_lib_child_str( int* handle, /* integer handle of library */ |
---|
198 | char* path, /* DOM path of requested object */ |
---|
199 | char* flavor, /* information you want returned*/ |
---|
200 | char* type, /* specific name of element */ |
---|
201 | int* childNum, /* child number for iteration */ |
---|
202 | char* retText, /* buffer to store return text */ |
---|
203 | int path_len, /* length of path */ |
---|
204 | int flavor_len, /* length of flavor */ |
---|
205 | int type_len, /* length of type */ |
---|
206 | int retText_len /* length of return text buffer */ |
---|
207 | ); |
---|
208 | |
---|
209 | extern "C" |
---|
210 | int rp_lib_child_obj( int* handle, |
---|
211 | char* path, |
---|
212 | char* type, |
---|
213 | int path_len, |
---|
214 | int type_len |
---|
215 | ); |
---|
216 | |
---|
217 | extern "C" |
---|
218 | void rp_lib_get( int* handle, |
---|
219 | char* path, |
---|
220 | char* retText, |
---|
221 | int path_len, |
---|
222 | int retText_len ); |
---|
223 | |
---|
224 | extern "C" |
---|
225 | double rp_lib_get_double( int* handle, |
---|
226 | char* path, |
---|
227 | int path_len); |
---|
228 | |
---|
229 | extern "C" |
---|
230 | void rp_lib_put_str( int* handle, |
---|
231 | char* path, |
---|
232 | char* value, |
---|
233 | int* append, |
---|
234 | int path_len, |
---|
235 | int value_len ); |
---|
236 | |
---|
237 | extern "C" |
---|
238 | void rp_lib_put_id_str( int* handle, |
---|
239 | char* path, |
---|
240 | char* value, |
---|
241 | char* id, |
---|
242 | int* append, |
---|
243 | int path_len, |
---|
244 | int value_len, |
---|
245 | int id_len ); |
---|
246 | |
---|
247 | extern "C" |
---|
248 | void rp_lib_put_obj( int* handle, |
---|
249 | char* path, |
---|
250 | int* valHandle, |
---|
251 | int* append, |
---|
252 | int path_len ); |
---|
253 | |
---|
254 | extern "C" |
---|
255 | void rp_lib_put_id_obj( int* handle, |
---|
256 | char* path, |
---|
257 | int* valHandle, |
---|
258 | char* id, |
---|
259 | int* append, |
---|
260 | int path_len, |
---|
261 | int id_len ); |
---|
262 | |
---|
263 | extern "C" |
---|
264 | int rp_lib_remove( int* handle, |
---|
265 | char* path, |
---|
266 | int path_len); |
---|
267 | |
---|
268 | extern "C" |
---|
269 | int rp_lib_xml_len( int* handle); |
---|
270 | |
---|
271 | extern "C" |
---|
272 | void rp_lib_xml( int* handle, |
---|
273 | char* retText, |
---|
274 | int retText_len); |
---|
275 | |
---|
276 | extern "C" |
---|
277 | int rp_lib_write_xml( int* handle, |
---|
278 | char* outFile, |
---|
279 | int outFile_len); |
---|
280 | extern "C" |
---|
281 | void rp_quit(); |
---|
282 | |
---|
283 | extern "C" |
---|
284 | void rp_result(int* handle); |
---|
285 | |
---|
286 | |
---|
287 | /**********************************************************/ |
---|
288 | |
---|
289 | /**********************************************************/ |
---|
290 | |
---|
291 | // private member functions |
---|
292 | int storeNode(PyObject* node); |
---|
293 | int objType( char* flavor); |
---|
294 | |
---|
295 | int storeObject(PyObject* objectName); |
---|
296 | PyObject* getObject(int objKey); |
---|
297 | // char* null_terminate(char* inStr, int len); |
---|
298 | |
---|
299 | // global vars |
---|
300 | // dictionary to hold the python objects that |
---|
301 | // cannot be sent to fortran |
---|
302 | |
---|
303 | #define DICT_TEMPLATE <int,PyObject*> |
---|
304 | RpDict DICT_TEMPLATE fortObjDict; |
---|
305 | int rapptureStarted = 0; |
---|
306 | |
---|
307 | void rp_init() { |
---|
308 | // |
---|
309 | PyObject* rpClass = NULL; |
---|
310 | int retVal = 0; |
---|
311 | |
---|
312 | // initialize the interpreter |
---|
313 | Py_Initialize(); |
---|
314 | rpClass = importRappture(); |
---|
315 | |
---|
316 | if (rpClass) { |
---|
317 | // store the handle in the dictionary |
---|
318 | retVal = storeObject(rpClass); |
---|
319 | rapptureStarted = 1; |
---|
320 | } |
---|
321 | } |
---|
322 | |
---|
323 | int rp_lib(const char* filePath, int filePath_len) |
---|
324 | { |
---|
325 | PyObject* lib = NULL; |
---|
326 | PyObject* rpClass = NULL; |
---|
327 | int handle = -1; |
---|
328 | char* inFilePath = NULL; |
---|
329 | |
---|
330 | if (!rapptureStarted) { |
---|
331 | rp_init(); |
---|
332 | } |
---|
333 | |
---|
334 | inFilePath = null_terminate((char*)filePath, filePath_len); |
---|
335 | |
---|
336 | // error checking to make sure inText is valid??? |
---|
337 | |
---|
338 | // grab the rappture class from the dictionary |
---|
339 | rpClass = getObject(0); |
---|
340 | |
---|
341 | if (rpClass) { |
---|
342 | |
---|
343 | |
---|
344 | // create a RapptureIO object and store in dictionary |
---|
345 | lib = createRapptureObj(rpClass, inFilePath); |
---|
346 | |
---|
347 | if (lib) { |
---|
348 | handle = storeObject(lib); |
---|
349 | } |
---|
350 | } |
---|
351 | |
---|
352 | if (inFilePath) { |
---|
353 | free(inFilePath); |
---|
354 | inFilePath = NULL; |
---|
355 | } |
---|
356 | |
---|
357 | return handle; |
---|
358 | } |
---|
359 | |
---|
360 | int rp_lib_element_obj(int* handle, /* integer handle of library */ |
---|
361 | char* path, /* null terminated path */ |
---|
362 | int path_len |
---|
363 | ) |
---|
364 | { |
---|
365 | int newObjHandle = -1; |
---|
366 | |
---|
367 | const char* flavor = "object"; |
---|
368 | char* inPath = NULL; |
---|
369 | |
---|
370 | PyObject* lib = NULL; |
---|
371 | PyObject* retObj = NULL; |
---|
372 | |
---|
373 | inPath = null_terminate(path,path_len); |
---|
374 | |
---|
375 | // error checking to make sure inText is valid??? |
---|
376 | |
---|
377 | if (fortObjDict.size() > 0) { |
---|
378 | if ((handle) && (*handle != 0)) { |
---|
379 | lib = getObject(*handle); |
---|
380 | if (lib) { |
---|
381 | retObj = (PyObject*) rpElement(lib, inPath, flavor); |
---|
382 | |
---|
383 | if (retObj) { |
---|
384 | |
---|
385 | newObjHandle = storeObject(retObj); |
---|
386 | // Py_DECREF(retObj); |
---|
387 | } |
---|
388 | } |
---|
389 | } |
---|
390 | } |
---|
391 | |
---|
392 | if (inPath) { |
---|
393 | free(inPath); |
---|
394 | inPath = NULL; |
---|
395 | } |
---|
396 | |
---|
397 | return newObjHandle; |
---|
398 | } |
---|
399 | |
---|
400 | void rp_lib_element_comp( int* handle, /* integer handle of library */ |
---|
401 | char* path, /* null terminated path */ |
---|
402 | char* retText, /* return buffer for fortran*/ |
---|
403 | int path_len, |
---|
404 | int retText_len /* length of return text buffer */ |
---|
405 | ) |
---|
406 | { |
---|
407 | char* inPath = NULL; |
---|
408 | |
---|
409 | inPath = null_terminate(path,path_len); |
---|
410 | if (path_len) { |
---|
411 | path_len = strlen(inPath) + 1; |
---|
412 | } |
---|
413 | else { |
---|
414 | path_len = 0; |
---|
415 | } |
---|
416 | |
---|
417 | // error checking to make sure inText is valid??? |
---|
418 | |
---|
419 | rp_lib_element_str(handle,inPath,"component",retText,path_len,10,retText_len); |
---|
420 | |
---|
421 | if (inPath) { |
---|
422 | free(inPath); |
---|
423 | inPath = NULL; |
---|
424 | } |
---|
425 | |
---|
426 | } |
---|
427 | |
---|
428 | void rp_lib_element_id( int* handle, /* integer handle of library */ |
---|
429 | char* path, /* null terminated path */ |
---|
430 | char* retText, /* return buffer for fortran*/ |
---|
431 | int path_len, |
---|
432 | int retText_len /* length of return text buffer */ |
---|
433 | ) |
---|
434 | { |
---|
435 | char* inPath = NULL; |
---|
436 | inPath = null_terminate(path,path_len); |
---|
437 | if (inPath) { |
---|
438 | path_len = strlen(inPath) + 1; |
---|
439 | } |
---|
440 | else { |
---|
441 | path_len = 0; |
---|
442 | } |
---|
443 | |
---|
444 | rp_lib_element_str(handle,inPath,"id",retText,path_len,3,retText_len); |
---|
445 | if (inPath) { |
---|
446 | free(inPath); |
---|
447 | inPath = NULL; |
---|
448 | } |
---|
449 | |
---|
450 | |
---|
451 | } |
---|
452 | |
---|
453 | void rp_lib_element_type( int* handle, /* integer handle of library */ |
---|
454 | char* path, /* null terminated path */ |
---|
455 | char* retText, /* return buffer for fortran*/ |
---|
456 | int path_len, |
---|
457 | int retText_len /* length of return text buffer */ |
---|
458 | ) |
---|
459 | { |
---|
460 | char* inPath = NULL; |
---|
461 | inPath = null_terminate(path,path_len); |
---|
462 | if (inPath) { |
---|
463 | path_len = strlen(inPath) + 1; |
---|
464 | } |
---|
465 | else { |
---|
466 | path_len = 0; |
---|
467 | } |
---|
468 | rp_lib_element_str(handle,path,"type",retText,path_len,5,retText_len); |
---|
469 | if (inPath) { |
---|
470 | free(inPath); |
---|
471 | inPath = NULL; |
---|
472 | } |
---|
473 | |
---|
474 | |
---|
475 | } |
---|
476 | |
---|
477 | void rp_lib_element_str( int* handle, /* integer handle of library */ |
---|
478 | char* path, /* null terminated path */ |
---|
479 | char* flavor, /* null terminated flavor */ |
---|
480 | char* retText, /* return buffer for fortran*/ |
---|
481 | int path_len, |
---|
482 | int flavor_len, |
---|
483 | int retText_len /* length of return text buffer */ |
---|
484 | ) |
---|
485 | { |
---|
486 | // int length_in = 0; |
---|
487 | // int length_out = 0; |
---|
488 | // int i = 0; |
---|
489 | const char* xmlText = NULL; |
---|
490 | |
---|
491 | PyObject* lib = NULL; |
---|
492 | |
---|
493 | char* retObj = NULL; |
---|
494 | |
---|
495 | char* inPath = NULL; |
---|
496 | char* inFlavor = NULL; |
---|
497 | |
---|
498 | inPath = null_terminate(path,path_len); |
---|
499 | inFlavor = null_terminate(flavor,flavor_len); |
---|
500 | |
---|
501 | if (rapptureStarted) { |
---|
502 | if ((handle) && (*handle != 0)) { |
---|
503 | lib = getObject(*handle); |
---|
504 | |
---|
505 | if (lib) { |
---|
506 | if(objType(inFlavor) == 1) { |
---|
507 | |
---|
508 | retObj = (char*) rpElement(lib, inPath, inFlavor); |
---|
509 | if (retObj) { |
---|
510 | xmlText = retObj; |
---|
511 | |
---|
512 | fortranify(xmlText, retText, retText_len); |
---|
513 | |
---|
514 | /* |
---|
515 | length_in = strlen(xmlText); |
---|
516 | length_out = retText_len; |
---|
517 | |
---|
518 | strncpy(retText, xmlText, length_out); |
---|
519 | |
---|
520 | // fortran-ify the string |
---|
521 | if (length_in < length_out) { |
---|
522 | for (i = length_in; i < length_out; i++) { |
---|
523 | retText[i] = ' '; |
---|
524 | } |
---|
525 | } |
---|
526 | *(retText+length_out-1) = ' '; |
---|
527 | */ |
---|
528 | |
---|
529 | free(retObj); |
---|
530 | retObj = NULL; |
---|
531 | } |
---|
532 | else { |
---|
533 | |
---|
534 | } |
---|
535 | } |
---|
536 | |
---|
537 | } |
---|
538 | } |
---|
539 | } |
---|
540 | |
---|
541 | if (inPath) { |
---|
542 | free(inPath); |
---|
543 | inPath = NULL; |
---|
544 | } |
---|
545 | |
---|
546 | if (inFlavor) { |
---|
547 | free(inFlavor); |
---|
548 | inFlavor = NULL; |
---|
549 | } |
---|
550 | |
---|
551 | } |
---|
552 | |
---|
553 | int rp_lib_child_num( int* handle, |
---|
554 | char* path, |
---|
555 | int path_len |
---|
556 | ) |
---|
557 | { |
---|
558 | int numChildren = 0; |
---|
559 | |
---|
560 | PyObject* lib = NULL; |
---|
561 | PyObject* list = NULL; |
---|
562 | char* inPath = NULL; |
---|
563 | |
---|
564 | inPath = null_terminate(path,path_len); |
---|
565 | |
---|
566 | if (rapptureStarted) { |
---|
567 | if ((handle) && (*handle != 0)) { |
---|
568 | lib = getObject(*handle); |
---|
569 | |
---|
570 | if (lib) { |
---|
571 | list = rpChildren_f(lib, inPath, "type"); |
---|
572 | if (list) { |
---|
573 | numChildren = PyList_Size(list); |
---|
574 | Py_DECREF(list); |
---|
575 | } |
---|
576 | else { |
---|
577 | |
---|
578 | } |
---|
579 | } |
---|
580 | } |
---|
581 | } |
---|
582 | |
---|
583 | if (inPath) { |
---|
584 | free(inPath); |
---|
585 | inPath = NULL; |
---|
586 | } |
---|
587 | |
---|
588 | return numChildren; |
---|
589 | |
---|
590 | } |
---|
591 | |
---|
592 | |
---|
593 | int rp_lib_child_comp ( int* handle, /* integer handle of library */ |
---|
594 | char* path, /* DOM path of requested object */ |
---|
595 | char* type, /* specific name of element */ |
---|
596 | int* childNum, /* child number for iteration */ |
---|
597 | char* retText, /* buffer to store return text */ |
---|
598 | int path_len, /* length of path */ |
---|
599 | int type_len, /* length of type */ |
---|
600 | int retText_len /* length of return text buffer */ |
---|
601 | ) |
---|
602 | { |
---|
603 | int retVal = 0; |
---|
604 | |
---|
605 | char* inPath = NULL; |
---|
606 | char* inType = NULL; |
---|
607 | |
---|
608 | inPath = null_terminate(path,path_len); |
---|
609 | inType = null_terminate(type,type_len); |
---|
610 | |
---|
611 | if (inPath) { |
---|
612 | path_len = strlen(inPath) + 1; |
---|
613 | } |
---|
614 | else { |
---|
615 | path_len = 0; |
---|
616 | } |
---|
617 | |
---|
618 | if (inType) { |
---|
619 | type_len = strlen(inType) + 1; |
---|
620 | } |
---|
621 | else { |
---|
622 | type_len = 0; |
---|
623 | } |
---|
624 | |
---|
625 | retVal = rp_lib_child_str( handle, |
---|
626 | inPath, |
---|
627 | "component", |
---|
628 | inType, |
---|
629 | childNum, |
---|
630 | retText, |
---|
631 | path_len, |
---|
632 | 10, |
---|
633 | type_len, |
---|
634 | retText_len |
---|
635 | ); |
---|
636 | |
---|
637 | if (inPath) { |
---|
638 | free(inPath); |
---|
639 | inPath = NULL; |
---|
640 | } |
---|
641 | |
---|
642 | if (inType) { |
---|
643 | free(inType); |
---|
644 | inType = NULL; |
---|
645 | } |
---|
646 | |
---|
647 | return retVal; |
---|
648 | } |
---|
649 | |
---|
650 | int rp_lib_child_id( int* handle, /* integer handle of library */ |
---|
651 | char* path, /* DOM path of requested object */ |
---|
652 | char* type, /* specific name of element */ |
---|
653 | int* childNum, /* child number for iteration */ |
---|
654 | char* retText, /* buffer to store return text */ |
---|
655 | int path_len, /* length of path */ |
---|
656 | int type_len, /* length of type */ |
---|
657 | int retText_len /* length of return text buffer */ |
---|
658 | ) |
---|
659 | { |
---|
660 | int retVal = 0; |
---|
661 | char* inPath = NULL; |
---|
662 | char* inType = NULL; |
---|
663 | |
---|
664 | inPath = null_terminate(path,path_len); |
---|
665 | inType = null_terminate(type,type_len); |
---|
666 | |
---|
667 | if (inPath) { |
---|
668 | path_len = strlen(inPath) + 1; |
---|
669 | } |
---|
670 | else { |
---|
671 | path_len = 0; |
---|
672 | } |
---|
673 | |
---|
674 | if (inType) { |
---|
675 | type_len = strlen(inType) + 1; |
---|
676 | } |
---|
677 | else { |
---|
678 | type_len = 0; |
---|
679 | } |
---|
680 | |
---|
681 | retVal = rp_lib_child_str( handle, |
---|
682 | inPath, |
---|
683 | "id", |
---|
684 | inType, |
---|
685 | childNum, |
---|
686 | retText, |
---|
687 | path_len, |
---|
688 | 3, |
---|
689 | type_len, |
---|
690 | retText_len |
---|
691 | ); |
---|
692 | |
---|
693 | if (inPath) { |
---|
694 | free(inPath); |
---|
695 | inPath = NULL; |
---|
696 | } |
---|
697 | |
---|
698 | if (inType) { |
---|
699 | free(inType); |
---|
700 | inType = NULL; |
---|
701 | } |
---|
702 | |
---|
703 | return retVal; |
---|
704 | } |
---|
705 | |
---|
706 | int rp_lib_child_type ( int* handle, /* integer handle of library */ |
---|
707 | char* path, /* DOM path of requested object */ |
---|
708 | char* type, /* specific name of element */ |
---|
709 | int* childNum, /* child number for iteration */ |
---|
710 | char* retText, /* buffer to store return text */ |
---|
711 | int path_len, /* length of path */ |
---|
712 | int type_len, /* length of type */ |
---|
713 | int retText_len /* length of return text buffer */ |
---|
714 | ) |
---|
715 | { |
---|
716 | int retVal = 0; |
---|
717 | char* inPath = NULL; |
---|
718 | char* inType = NULL; |
---|
719 | |
---|
720 | inPath = null_terminate(path,path_len); |
---|
721 | inType = null_terminate(type,type_len); |
---|
722 | |
---|
723 | if (inPath) { |
---|
724 | path_len = strlen(inPath) + 1; |
---|
725 | } |
---|
726 | else { |
---|
727 | path_len = 0; |
---|
728 | } |
---|
729 | |
---|
730 | if (inType) { |
---|
731 | type_len = strlen(inType) + 1; |
---|
732 | } |
---|
733 | else { |
---|
734 | type_len = 0; |
---|
735 | } |
---|
736 | |
---|
737 | retVal = rp_lib_child_str( handle, |
---|
738 | inPath, |
---|
739 | "type", |
---|
740 | inType, |
---|
741 | childNum, |
---|
742 | retText, |
---|
743 | path_len, |
---|
744 | 5, |
---|
745 | type_len, |
---|
746 | retText_len |
---|
747 | ); |
---|
748 | |
---|
749 | if (inPath) { |
---|
750 | free(inPath); |
---|
751 | inPath = NULL; |
---|
752 | } |
---|
753 | |
---|
754 | if (inType) { |
---|
755 | free(inType); |
---|
756 | inType = NULL; |
---|
757 | } |
---|
758 | |
---|
759 | return retVal; |
---|
760 | } |
---|
761 | |
---|
762 | int rp_lib_child_str ( int* handle, /* integer handle of library */ |
---|
763 | char* path, /* DOM path of requested object */ |
---|
764 | char* flavor, /* information you want returned*/ |
---|
765 | char* type, /* specific name of element */ |
---|
766 | int* childNum, /* child number for iteration */ |
---|
767 | char* retText, /* buffer to store return text */ |
---|
768 | int path_len, /* length of path */ |
---|
769 | int flavor_len, /* length of flavor */ |
---|
770 | int type_len, /* length of type */ |
---|
771 | int retText_len /* length of return text buffer */ |
---|
772 | ) |
---|
773 | { |
---|
774 | int retVal = 0; |
---|
775 | // int i = 0; |
---|
776 | // int length_in = 0; |
---|
777 | |
---|
778 | PyObject* lib = NULL; |
---|
779 | PyObject* list = NULL; |
---|
780 | PyObject* list_item = NULL; |
---|
781 | |
---|
782 | char* xmlChild = NULL; |
---|
783 | char* inPath = NULL; |
---|
784 | char* inType = NULL; |
---|
785 | char* inFlavor = NULL; |
---|
786 | |
---|
787 | inPath = null_terminate(path,path_len); |
---|
788 | inFlavor = null_terminate(flavor,flavor_len); |
---|
789 | inType = null_terminate(type,type_len); |
---|
790 | |
---|
791 | if (rapptureStarted) { |
---|
792 | if ((handle) && (*handle != 0)) { |
---|
793 | lib = getObject(*handle); |
---|
794 | if (lib) { |
---|
795 | if(objType(inFlavor) == 1) { |
---|
796 | |
---|
797 | list = rpChildren_f(lib, inPath, inFlavor); |
---|
798 | if (list) { |
---|
799 | retVal = PyList_Size(list); |
---|
800 | // check to make sure our node index is within bounds |
---|
801 | if (((*childNum)-1) < retVal) { |
---|
802 | // get the requested node |
---|
803 | list_item = PyList_GetItem(list,(*childNum)-1); |
---|
804 | // make node string, borrowed object |
---|
805 | xmlChild = PyString_AsString(list_item); |
---|
806 | Py_DECREF(list); |
---|
807 | // printf("xmlChild = :%s:\n",xmlChild); |
---|
808 | if (xmlChild) { |
---|
809 | fortranify(xmlChild, retText, retText_len); |
---|
810 | |
---|
811 | /* |
---|
812 | strncpy(retText, xmlChild, retText_len); |
---|
813 | length_in = strlen(xmlChild); |
---|
814 | |
---|
815 | // fortran-ify the string |
---|
816 | if (length_in < retText_len) { |
---|
817 | for (i = length_in; i < retText_len; i++) { |
---|
818 | retText[i] = ' '; |
---|
819 | } |
---|
820 | } |
---|
821 | // *(retText+retText_len-1) = ' '; |
---|
822 | */ |
---|
823 | } |
---|
824 | } |
---|
825 | } |
---|
826 | else { |
---|
827 | |
---|
828 | } |
---|
829 | } |
---|
830 | } |
---|
831 | } |
---|
832 | } |
---|
833 | |
---|
834 | if (inPath) { |
---|
835 | free(inPath); |
---|
836 | inPath = NULL; |
---|
837 | } |
---|
838 | |
---|
839 | if (inFlavor) { |
---|
840 | free(inFlavor); |
---|
841 | inFlavor = NULL; |
---|
842 | } |
---|
843 | |
---|
844 | if (inType) { |
---|
845 | free(inType); |
---|
846 | inType = NULL; |
---|
847 | } |
---|
848 | |
---|
849 | |
---|
850 | return retVal; |
---|
851 | } |
---|
852 | |
---|
853 | int rp_lib_child_obj ( int* handle, |
---|
854 | char* path, |
---|
855 | char* type, |
---|
856 | int path_len, |
---|
857 | int type_len |
---|
858 | ) |
---|
859 | { |
---|
860 | int newObjHandle = -1; |
---|
861 | |
---|
862 | PyObject* lib = NULL; |
---|
863 | PyObject* list = NULL; |
---|
864 | |
---|
865 | char* inPath = NULL; |
---|
866 | char* inType = NULL; |
---|
867 | |
---|
868 | inPath = null_terminate(path,path_len); |
---|
869 | inType = null_terminate(type,type_len); |
---|
870 | |
---|
871 | if (rapptureStarted) { |
---|
872 | if ((handle) && (*handle != 0)) { |
---|
873 | lib = getObject(*handle); |
---|
874 | |
---|
875 | if (lib) { |
---|
876 | list = rpChildren_f(lib, inPath, "object"); |
---|
877 | if (list) { |
---|
878 | // store the whole list, |
---|
879 | // need to make a way to read the nodes |
---|
880 | newObjHandle = storeObject(list); |
---|
881 | // Py_DECREF(list); |
---|
882 | } |
---|
883 | else { |
---|
884 | |
---|
885 | } |
---|
886 | } |
---|
887 | } |
---|
888 | } |
---|
889 | |
---|
890 | if (inPath) { |
---|
891 | free(inPath); |
---|
892 | inPath = NULL; |
---|
893 | } |
---|
894 | |
---|
895 | if (inType) { |
---|
896 | free(inType); |
---|
897 | inType = NULL; |
---|
898 | } |
---|
899 | |
---|
900 | return newObjHandle; |
---|
901 | |
---|
902 | } |
---|
903 | |
---|
904 | |
---|
905 | void rp_lib_get( int* handle, /* integer handle of library */ |
---|
906 | char* path, /* null terminated path */ |
---|
907 | char* retText, /* return text buffer for fortran*/ |
---|
908 | int path_len, |
---|
909 | int retText_len /* length of return text buffer */ |
---|
910 | ) |
---|
911 | { |
---|
912 | // int length_in = 0; |
---|
913 | // int length_out = 0; |
---|
914 | // int i = 0; |
---|
915 | const char* xmlText = NULL; |
---|
916 | |
---|
917 | PyObject* lib = NULL; |
---|
918 | |
---|
919 | char* inPath = NULL; |
---|
920 | |
---|
921 | inPath = null_terminate(path,path_len); |
---|
922 | |
---|
923 | if (rapptureStarted) { |
---|
924 | if ((handle) && (*handle != 0)) { |
---|
925 | lib = getObject(*handle); |
---|
926 | |
---|
927 | if (lib) { |
---|
928 | // retObj is a borrowed object |
---|
929 | // whose contents must not be modified |
---|
930 | xmlText = rpGet(lib, inPath); |
---|
931 | |
---|
932 | if (xmlText) { |
---|
933 | |
---|
934 | fortranify(xmlText, retText, retText_len); |
---|
935 | |
---|
936 | /* |
---|
937 | length_in = strlen(xmlText); |
---|
938 | length_out = retText_len; |
---|
939 | |
---|
940 | strncpy(retText, xmlText, length_out); |
---|
941 | |
---|
942 | // fortran-ify the string |
---|
943 | if (length_in < length_out) { |
---|
944 | for (i = length_in; i < length_out; i++) { |
---|
945 | retText[i] = ' '; |
---|
946 | } |
---|
947 | } |
---|
948 | *(retText+length_out-1) = ' '; |
---|
949 | */ |
---|
950 | } |
---|
951 | |
---|
952 | } |
---|
953 | } |
---|
954 | } |
---|
955 | |
---|
956 | if (inPath) { |
---|
957 | free(inPath); |
---|
958 | inPath = NULL; |
---|
959 | } |
---|
960 | |
---|
961 | } |
---|
962 | |
---|
963 | double rp_lib_get_double( int* handle, /* integer handle of library */ |
---|
964 | char* path, /* null terminated path */ |
---|
965 | int path_len |
---|
966 | ) |
---|
967 | { |
---|
968 | double retVal = 0.0; |
---|
969 | const char* xmlText = NULL; |
---|
970 | |
---|
971 | PyObject* lib = NULL; |
---|
972 | |
---|
973 | char* inPath = NULL; |
---|
974 | |
---|
975 | inPath = null_terminate(path,path_len); |
---|
976 | |
---|
977 | path_len = strlen(inPath) + 1; |
---|
978 | |
---|
979 | if (rapptureStarted) { |
---|
980 | if ((handle) && (*handle != 0)) { |
---|
981 | lib = getObject(*handle); |
---|
982 | |
---|
983 | if (lib) { |
---|
984 | // retObj is a borrowed object |
---|
985 | // whose contents must not be modified |
---|
986 | xmlText = rpGet(lib, inPath); |
---|
987 | |
---|
988 | if (xmlText) { |
---|
989 | retVal = atof(xmlText); |
---|
990 | } |
---|
991 | |
---|
992 | } |
---|
993 | } |
---|
994 | } |
---|
995 | |
---|
996 | if (inPath) { |
---|
997 | free(inPath); |
---|
998 | inPath = NULL; |
---|
999 | } |
---|
1000 | |
---|
1001 | return retVal; |
---|
1002 | } |
---|
1003 | |
---|
1004 | |
---|
1005 | void rp_lib_put_str( int* handle, |
---|
1006 | char* path, |
---|
1007 | char* value, |
---|
1008 | int* append, |
---|
1009 | int path_len, |
---|
1010 | int value_len |
---|
1011 | ) |
---|
1012 | { |
---|
1013 | char* inPath = NULL; |
---|
1014 | char* inValue = NULL; |
---|
1015 | |
---|
1016 | inPath = null_terminate(path,path_len); |
---|
1017 | inValue = null_terminate(value,value_len); |
---|
1018 | |
---|
1019 | |
---|
1020 | if (inPath) { |
---|
1021 | path_len = strlen(inPath) + 1; |
---|
1022 | } |
---|
1023 | else { |
---|
1024 | path_len = 0; |
---|
1025 | } |
---|
1026 | |
---|
1027 | if (inValue){ |
---|
1028 | value_len = strlen(inValue) + 1; |
---|
1029 | } |
---|
1030 | else { |
---|
1031 | value_len = 0; |
---|
1032 | } |
---|
1033 | |
---|
1034 | rp_lib_put_id_str(handle,inPath,inValue,NULL,append,path_len,value_len,0); |
---|
1035 | |
---|
1036 | if (inPath) { |
---|
1037 | free(inPath); |
---|
1038 | inPath = NULL; |
---|
1039 | } |
---|
1040 | |
---|
1041 | if (inValue) { |
---|
1042 | free(inValue); |
---|
1043 | inValue = NULL; |
---|
1044 | } |
---|
1045 | } |
---|
1046 | |
---|
1047 | |
---|
1048 | void rp_lib_put_id_str ( int* handle, |
---|
1049 | char* path, |
---|
1050 | char* value, |
---|
1051 | char* id, |
---|
1052 | int* append, |
---|
1053 | int path_len, |
---|
1054 | int value_len, |
---|
1055 | int id_len |
---|
1056 | ) |
---|
1057 | { |
---|
1058 | PyObject* lib = NULL; |
---|
1059 | |
---|
1060 | char* inPath = NULL; |
---|
1061 | char* inValue = NULL; |
---|
1062 | char* inId = NULL; |
---|
1063 | |
---|
1064 | inPath = null_terminate(path,path_len); |
---|
1065 | inValue = null_terminate(value,value_len); |
---|
1066 | inId = null_terminate(id,id_len); |
---|
1067 | |
---|
1068 | if (rapptureStarted) { |
---|
1069 | if ((handle) && (*handle != 0)) { |
---|
1070 | lib = getObject(*handle); |
---|
1071 | |
---|
1072 | if (lib) { |
---|
1073 | rpPut(lib, inPath, inValue, inId, *append); |
---|
1074 | } |
---|
1075 | } |
---|
1076 | } |
---|
1077 | |
---|
1078 | if (inPath) { |
---|
1079 | free(inPath); |
---|
1080 | inPath = NULL; |
---|
1081 | } |
---|
1082 | |
---|
1083 | if (inValue) { |
---|
1084 | free(inValue); |
---|
1085 | inValue = NULL; |
---|
1086 | } |
---|
1087 | |
---|
1088 | if (inId) { |
---|
1089 | free(inId); |
---|
1090 | inId = NULL; |
---|
1091 | } |
---|
1092 | |
---|
1093 | } |
---|
1094 | |
---|
1095 | void rp_lib_put_obj( int* handle, |
---|
1096 | char* path, |
---|
1097 | int* valHandle, |
---|
1098 | int* append, |
---|
1099 | int path_len |
---|
1100 | ) |
---|
1101 | { |
---|
1102 | char* inPath = NULL; |
---|
1103 | |
---|
1104 | inPath = null_terminate(path,path_len); |
---|
1105 | |
---|
1106 | if (inPath) { |
---|
1107 | path_len = strlen(inPath) + 1; |
---|
1108 | } |
---|
1109 | |
---|
1110 | rp_lib_put_id_obj(handle,inPath,valHandle,NULL,append,path_len,0); |
---|
1111 | |
---|
1112 | if (inPath) { |
---|
1113 | free(inPath); |
---|
1114 | inPath = NULL; |
---|
1115 | } |
---|
1116 | |
---|
1117 | } |
---|
1118 | |
---|
1119 | void rp_lib_put_id_obj ( int* handle, |
---|
1120 | char* path, |
---|
1121 | int* valHandle, |
---|
1122 | char* id, |
---|
1123 | int* append, |
---|
1124 | int path_len, |
---|
1125 | int id_len |
---|
1126 | ) |
---|
1127 | { |
---|
1128 | PyObject* lib = NULL; |
---|
1129 | PyObject* value = NULL; |
---|
1130 | |
---|
1131 | char* inPath = NULL; |
---|
1132 | char* inId = NULL; |
---|
1133 | |
---|
1134 | inPath = null_terminate(path,path_len); |
---|
1135 | inId = null_terminate(id,id_len); |
---|
1136 | |
---|
1137 | if (rapptureStarted) { |
---|
1138 | if ((handle) && (*handle != 0)) { |
---|
1139 | lib = getObject(*handle); |
---|
1140 | value = getObject(*valHandle); |
---|
1141 | |
---|
1142 | if (lib && value) { |
---|
1143 | // retObj is a borrowed object |
---|
1144 | // whose contents must not be modified |
---|
1145 | rpPutObj(lib, inPath, value, inId, *append); |
---|
1146 | } |
---|
1147 | } |
---|
1148 | } |
---|
1149 | |
---|
1150 | if (inPath) { |
---|
1151 | free(inPath); |
---|
1152 | inPath = NULL; |
---|
1153 | } |
---|
1154 | |
---|
1155 | if (inId) { |
---|
1156 | free(inId); |
---|
1157 | inId = NULL; |
---|
1158 | } |
---|
1159 | |
---|
1160 | } |
---|
1161 | |
---|
1162 | int rp_lib_remove (int* handle, char* path, int path_len) |
---|
1163 | { |
---|
1164 | int newObjHandle = -1; |
---|
1165 | |
---|
1166 | PyObject* lib = NULL; |
---|
1167 | PyObject* removedObj = NULL; |
---|
1168 | |
---|
1169 | char* inPath = NULL; |
---|
1170 | |
---|
1171 | inPath = null_terminate(path,path_len); |
---|
1172 | |
---|
1173 | if (rapptureStarted) { |
---|
1174 | if ((handle) && (*handle != 0)) { |
---|
1175 | lib = getObject(*handle); |
---|
1176 | |
---|
1177 | if (lib) { |
---|
1178 | removedObj = rpRemove(lib, inPath); |
---|
1179 | |
---|
1180 | if (removedObj) { |
---|
1181 | newObjHandle = storeObject(removedObj); |
---|
1182 | // Py_DECREF(removedObj); |
---|
1183 | } |
---|
1184 | |
---|
1185 | } |
---|
1186 | } |
---|
1187 | } |
---|
1188 | |
---|
1189 | if (inPath) { |
---|
1190 | free(inPath); |
---|
1191 | inPath = NULL; |
---|
1192 | } |
---|
1193 | |
---|
1194 | return newObjHandle; |
---|
1195 | } |
---|
1196 | |
---|
1197 | int rp_lib_xml_len (int* handle) |
---|
1198 | { |
---|
1199 | int length = -1; |
---|
1200 | char* xmlText = NULL; |
---|
1201 | |
---|
1202 | PyObject* lib = NULL; |
---|
1203 | |
---|
1204 | if (rapptureStarted) { |
---|
1205 | if ((handle) && (*handle != 0)) { |
---|
1206 | lib = getObject(*handle); |
---|
1207 | |
---|
1208 | if (lib) { |
---|
1209 | // dont modify xmlText, borrowed pointer |
---|
1210 | xmlText = rpXml(lib); |
---|
1211 | |
---|
1212 | if (xmlText) { |
---|
1213 | length = strlen(xmlText) + 1; |
---|
1214 | free(xmlText); |
---|
1215 | // printf("len = :%d:\n",length); |
---|
1216 | } |
---|
1217 | } |
---|
1218 | } |
---|
1219 | } |
---|
1220 | return length; |
---|
1221 | } |
---|
1222 | |
---|
1223 | void rp_lib_xml(int* handle, char* retText, int retText_len) |
---|
1224 | { |
---|
1225 | // int length_in = 0; |
---|
1226 | // int length_out = 0; |
---|
1227 | // int i = 0; |
---|
1228 | char* xmlText = NULL; |
---|
1229 | |
---|
1230 | PyObject* lib = NULL; |
---|
1231 | |
---|
1232 | if (rapptureStarted) { |
---|
1233 | if ((handle) && (*handle != 0)) { |
---|
1234 | lib = getObject(*handle); |
---|
1235 | |
---|
1236 | if (lib) { |
---|
1237 | xmlText = rpXml(lib); |
---|
1238 | |
---|
1239 | if (xmlText) { |
---|
1240 | |
---|
1241 | fortranify(xmlText, retText, retText_len); |
---|
1242 | |
---|
1243 | /* |
---|
1244 | length_in = strlen(xmlText); |
---|
1245 | length_out = retText_len; |
---|
1246 | |
---|
1247 | strncpy(retText, xmlText, length_out); |
---|
1248 | |
---|
1249 | // fortran-ify the string |
---|
1250 | if (length_in < length_out) { |
---|
1251 | for (i = length_in; i < length_out; i++) { |
---|
1252 | retText[i] = ' '; |
---|
1253 | } |
---|
1254 | } |
---|
1255 | *(retText+length_out-1) = ' '; |
---|
1256 | */ |
---|
1257 | |
---|
1258 | free(xmlText); |
---|
1259 | } |
---|
1260 | |
---|
1261 | } |
---|
1262 | } |
---|
1263 | } |
---|
1264 | } |
---|
1265 | |
---|
1266 | int rp_lib_write_xml(int* handle, char* outFile, int outFile_len) |
---|
1267 | { |
---|
1268 | int retVal = -1; |
---|
1269 | PyObject* lib = NULL; |
---|
1270 | FILE* outFH = NULL; |
---|
1271 | char* inOutFile = NULL; |
---|
1272 | char* xmlText = NULL; |
---|
1273 | |
---|
1274 | inOutFile = null_terminate(outFile, outFile_len); |
---|
1275 | |
---|
1276 | if (inOutFile && (inOutFile != "") ) { |
---|
1277 | outFH = fopen(inOutFile, "w"); |
---|
1278 | } |
---|
1279 | |
---|
1280 | if (outFH && rapptureStarted) { |
---|
1281 | if ((handle) && (*handle != 0)) { |
---|
1282 | lib = getObject(*handle); |
---|
1283 | |
---|
1284 | if (lib) { |
---|
1285 | xmlText = rpXml(lib); |
---|
1286 | if (xmlText) { |
---|
1287 | retVal = fputs(xmlText,outFH); |
---|
1288 | free(xmlText); |
---|
1289 | } |
---|
1290 | } |
---|
1291 | } |
---|
1292 | } |
---|
1293 | |
---|
1294 | if (outFH) { |
---|
1295 | fclose(outFH); |
---|
1296 | outFH = NULL; |
---|
1297 | } |
---|
1298 | |
---|
1299 | if (inOutFile) { |
---|
1300 | free(inOutFile); |
---|
1301 | inOutFile = NULL; |
---|
1302 | } |
---|
1303 | |
---|
1304 | return retVal; |
---|
1305 | } |
---|
1306 | |
---|
1307 | void rp_quit() |
---|
1308 | { |
---|
1309 | |
---|
1310 | // clean up python's memory |
---|
1311 | // shut down the python interpreter |
---|
1312 | // clean up the dictionary |
---|
1313 | |
---|
1314 | RpDictEntry DICT_TEMPLATE *hPtr; |
---|
1315 | // RpDictIterator DICT_TEMPLATE iter((RpDict&)*this); |
---|
1316 | RpDictIterator DICT_TEMPLATE iter(fortObjDict); |
---|
1317 | |
---|
1318 | hPtr = iter.first(); |
---|
1319 | |
---|
1320 | while (hPtr) { |
---|
1321 | Py_DECREF(*(hPtr->getValue())); |
---|
1322 | hPtr->erase(); |
---|
1323 | hPtr = iter.next(); |
---|
1324 | } |
---|
1325 | |
---|
1326 | if (fortObjDict.size()) { |
---|
1327 | // probably want to change the warning sometime |
---|
1328 | // printf("\nWARNING: internal dictionary is not empty..deleting\n"); |
---|
1329 | } |
---|
1330 | |
---|
1331 | rapptureStarted = 0; |
---|
1332 | // Py_Finalize(); |
---|
1333 | } |
---|
1334 | |
---|
1335 | void rp_result(int* handle) { |
---|
1336 | PyObject* lib = NULL; |
---|
1337 | |
---|
1338 | if (rapptureStarted && handle && *handle != 0) { |
---|
1339 | lib = getObject(*handle); |
---|
1340 | if (lib) { |
---|
1341 | rpResult(lib); |
---|
1342 | } |
---|
1343 | } |
---|
1344 | rp_quit(); |
---|
1345 | } |
---|
1346 | |
---|
1347 | int objType( char* flavor) |
---|
1348 | { |
---|
1349 | if (flavor == NULL) { |
---|
1350 | // return a PyObject* |
---|
1351 | return 0; |
---|
1352 | } |
---|
1353 | else if((*flavor == 'o')&&(strncmp(flavor,"object", 6)==0)){ |
---|
1354 | // return a PyObject* |
---|
1355 | return 0; |
---|
1356 | } |
---|
1357 | else if ( |
---|
1358 | ((*flavor == 't')&&(strncmp(flavor,"type", 4) == 0)) |
---|
1359 | ||((*flavor == 'i')&&(strncmp(flavor,"id", 2) == 0)) |
---|
1360 | ||((*flavor == 'c')&&(strncmp(flavor,"component", 9) == 0))) |
---|
1361 | { |
---|
1362 | // return a char* |
---|
1363 | // convert the result to c style strings |
---|
1364 | return 1; |
---|
1365 | } |
---|
1366 | else { |
---|
1367 | // unrecognized format |
---|
1368 | return -1; |
---|
1369 | } |
---|
1370 | } |
---|
1371 | |
---|
1372 | int storeObject(PyObject* objectName) { |
---|
1373 | |
---|
1374 | int retVal = -1; |
---|
1375 | int dictKey = fortObjDict.size(); |
---|
1376 | int newEntry = 0; |
---|
1377 | |
---|
1378 | if (objectName) { |
---|
1379 | // dictionary returns a reference to the inserted value |
---|
1380 | // no error checking to make sure it was successful in entering |
---|
1381 | // the new entry. |
---|
1382 | fortObjDict.set(dictKey,objectName, &newEntry); |
---|
1383 | } |
---|
1384 | |
---|
1385 | retVal = dictKey; |
---|
1386 | return retVal; |
---|
1387 | } |
---|
1388 | |
---|
1389 | PyObject* getObject(int objKey) { |
---|
1390 | |
---|
1391 | PyObject* retVal = *(fortObjDict.find(objKey).getValue()); |
---|
1392 | |
---|
1393 | if (retVal == *(fortObjDict.getNullEntry().getValue())) { |
---|
1394 | retVal = NULL; |
---|
1395 | } |
---|
1396 | |
---|
1397 | return retVal; |
---|
1398 | |
---|
1399 | } |
---|