4 configure libxml2 (default Linux libxml2.rpm doesn't cut it)
6 ./configure --prefix=/afs/info.uni-karlsruhe.de/user/<home>/src/C/xml --with-gnu-ld --with-pic --with-output --with-tree --with-reader --with-pattern --with-writer --with-push --with-valid --with-catalog --with-xpath--with-xptr --with-c14n --with-xinclude --with-schemas --with-regexps --with-debug --with-mem-debug
9 gcc -g read.c -I../include/libxml2 -L../lib -lxml2 -o read
15 static type_t *types = NULL;
16 static entity_t *entities = NULL;
17 static effs_t *effs = NULL;
19 static int _ent_id = 0;
20 /* static int _node_id = 0; */
23 getNodeModule (xmlNodePtr node)
25 char *mod_str = (char*) xmlGetProp (node, BAD_CAST "module");
27 if (NULL == mod_str) {
30 const char *res = strdup (mod_str);
37 getNodeProcName (xmlNodePtr node)
39 char *proc_str = (char*) xmlGetProp (node, BAD_CAST "procname");
43 return (strdup (proc_str));
47 getNodeId (xmlNodePtr node)
49 char *id_str = (char*) xmlGetProp (node, BAD_CAST "id");
58 getNodeRefId (xmlNodePtr node)
60 char *refid_str = (char*) xmlGetProp (node, BAD_CAST "refid");
63 refid = atoi (refid_str+1);
69 getNodeTypeId (xmlNodePtr node)
71 char *type_str = (char*) xmlGetProp (node, BAD_CAST "type");
74 type_id = atoi (type_str+1);
80 *getNodeTypeStr (xmlNodePtr node)
82 const char *type_str = (char*) xmlGetProp (node, BAD_CAST "type");
89 *getNodeEntityStr (xmlNodePtr node)
91 const char *ent_str = (char*) xmlGetProp (node, BAD_CAST "entity");
98 parseArg (xmlDocPtr doc, xmlNodePtr argelm)
105 CHECK_NAME (argelm, arg);
106 /* fprintf (stdout, "arg node \t0x%08x\n", (int) argelm); */
108 id = getNodeId (argelm);
109 /* fprintf (stdout, "arg->id = \"%d\"\n", id); */
110 num_str = (char*) xmlGetProp (argelm, BAD_CAST "number");
111 num = atoi (num_str);
112 /* fprintf (stdout, "arg->no = \"%d\"\n", no); */
123 *parseValref (xmlDocPtr doc, xmlNodePtr valelm)
127 CHECK_NAME (valelm, valref);
128 /* fprintf (stdout, "valref node \t0x%08x\n", (int) valelm); */
130 ref_id = getNodeRefId (valelm);
131 /* fprintf (stdout, "val->refid = \"%d\"\n", ref_id); */
133 valref = NEW (valref_t);
134 valref->kind = eff_valref;
135 valref->refid = ref_id;
141 *parseSelect (xmlDocPtr doc, xmlNodePtr selelm)
143 char *entity_str = (char*) xmlGetProp (selelm, BAD_CAST "entity");
144 const int entity_id = atoi (entity_str+1);
147 valref_t *valref = NULL;
148 select_t *sel = NEW (select_t);
149 sel->kind = eff_select;
151 CHECK_NAME (selelm, select);
152 /* fprintf (stdout, "select node \t0x%08x\n", (int) selelm); */
154 ent = getEntityById (entity_id);
156 child = selelm->xmlChildrenNode;
159 valref = parseValref (doc, child);
162 sel->valrefid = valref ? valref->refid : -1;
173 *parseLoad (xmlDocPtr doc, xmlNodePtr loadelm)
178 load_t *load = NEW (load_t);
179 load->kind = eff_load;
181 CHECK_NAME (loadelm, load);
182 /* fprintf (stdout, "load node \t0x%08x\n", (int) loadelm); */
183 id = getNodeId (loadelm);
185 child = loadelm->xmlChildrenNode;
187 sel = parseSelect (doc, child);
190 load->ptrrefid = sel->valrefid;
191 load->ent = sel->ent;
199 *parseStore (xmlDocPtr doc, xmlNodePtr storeelm)
204 store_t *store = NEW (store_t);
205 store->kind = eff_store;
207 CHECK_NAME (storeelm, store);
208 /* fprintf (stdout, "store node \t0x%08x\n", (int) storeelm); */
210 child = storeelm->xmlChildrenNode;
212 sel = parseSelect (doc, child);
216 valref = parseValref (doc, child);
218 store->ent = sel->ent;
219 store->ptrrefid = sel->valrefid;
220 store->valrefid = valref->refid;
229 *parseAlloc (xmlDocPtr doc, xmlNodePtr allocelm)
233 alloc_t *alloc = NEW (alloc_t); /* ...! */
234 alloc->kind = eff_alloc;
236 CHECK_NAME (allocelm, alloc);
237 /* fprintf (stdout, "alloc node \t0x%08x\n", (int) allocelm); */
238 id = getNodeId (allocelm);
239 /* fprintf (stdout, "alloc->id = \"%d\"\n", id); */
240 type_id = getNodeTypeId (allocelm);
241 /* fprintf (stdout, "alloc->type_id = \"%d\"\n", type_id); */
244 alloc->tp_id = type_id;
250 *parseCall (xmlDocPtr doc, xmlNodePtr callelm)
257 call_t *call = NEW (call_t);
258 call->kind = eff_call;
260 CHECK_NAME (callelm, call);
261 /* fprintf (stdout, "call node \t0x%08x\n", (int) callelm); */
262 id = getNodeId (callelm);
263 /* fprintf (stdout, "call->id = \"%d\"\n", id); */
265 child = callelm->xmlChildrenNode;
267 sel = parseSelect (doc, child);
269 arg = child = child->next;
273 while (NULL != child) {
280 call->valrefid = sel->valrefid;
281 call->ent = sel->ent;
282 call->n_args = n_args;
288 int *args = (int*) malloc (n_args * sizeof (int) );
291 while (NULL != arg) {
292 valref_t *valref = parseValref (doc, arg);
293 args [i ++] = valref->refid;
306 *parseJoin (xmlDocPtr doc, xmlNodePtr joinelm)
313 join_t *join = NEW (join_t);
314 join->kind = eff_join;
316 CHECK_NAME (joinelm, join);
317 /* fprintf (stdout, "join node \t0x%08x\n", (int) joinelm); */
318 id = getNodeId (joinelm);
319 /* fprintf (stdout, "join->id = \"%d\"\n", id); */
321 child = joinelm->xmlChildrenNode;
325 while (NULL != child) {
330 ins = (int*) malloc (n_ins * sizeof (int) );
333 child = joinelm->xmlChildrenNode;
335 while (NULL != child) {
336 valref_t *valref = parseValref (doc, child);
337 ins [i ++] = valref->refid;
350 *parseUnknown (xmlDocPtr doc, xmlNodePtr unknownelm)
353 unknown_t *unknown = NEW (unknown_t);
354 unknown->kind = eff_unknown;
356 CHECK_NAME (unknownelm, unknown);
357 /* fprintf (stdout, "unknown node \t0x%08x\n", (int) unknownelm); */
358 id = getNodeId (unknownelm);
366 *parseReturn (xmlDocPtr doc, xmlNodePtr retelm)
369 ret_t *ret = NEW (ret_t);
372 CHECK_NAME (retelm, ret);
373 /* fprintf (stdout, "ret node \t0x%08x\n", (int) retelm); */
375 child = retelm->xmlChildrenNode;
378 valref_t *valref = parseValref (doc, child);
379 ret->ret_id = valref->refid;
389 *parseRaise (xmlDocPtr doc, xmlNodePtr raiseelm)
394 raise_t *raise = NEW (raise_t);
395 raise->kind = eff_raise;
397 CHECK_NAME (raiseelm, raise);
398 /* fprintf (stdout, "raise node \t0x%08x\n", (int) raiseelm); */
400 tp_id = getNodeTypeId (raiseelm);
401 /* fprintf (stdout, "raise->type = \"%d\"\n", tp_id); */
403 child = raiseelm->xmlChildrenNode;
405 assert (NULL != child);
407 valref = parseValref (doc, child);
409 raise->valref = valref->refid;
410 raise->tp_id = tp_id;
421 /** parse a type node and insert it into the list */
423 parseType (xmlDocPtr doc, xmlNodePtr typeelm)
426 const int tp_id = getNodeId (typeelm);
427 /* fprintf (stdout, "type node \t0x%08x (%d)\n", (int) typeelm, tp_id); */
428 fprintf (stdout, "type = \"%s\"\n", getNodeTypeStr (typeelm));
430 type = (type_t*) malloc (sizeof (type_t));
432 type->name = (char*) strdup (getNodeTypeStr (typeelm));
438 if (_ent_id <= tp_id) {
443 /** parse an entity node and insert it into the list */
445 parseEntity (xmlDocPtr doc, xmlNodePtr entelm)
447 entity_t *ent = NEW (entity_t);
450 const int ent_id = getNodeId (entelm);
451 /* fprintf (stdout, "entity node \t0x%08x (%d)\n", (int) entelm, ent_id); */
452 fprintf (stdout, "ent = \"%s.%s\"\n",
453 getNodeTypeStr (entelm),
454 getNodeEntityStr (entelm));
457 ent->name = (char*) strdup (getNodeEntityStr (entelm));
458 ent->tp_name = (char*) strdup (getNodeTypeStr (entelm));
461 ent->prev = entities;
464 if (_ent_id <= ent_id) {
469 /** parse any effect, and turn it into an eff_t (TODO) */
471 parseEffect (xmlDocPtr doc, xmlNodePtr effelm)
473 xmlNodePtr cur = effelm->xmlChildrenNode;
474 char *procname = getNodeProcName (effelm);
475 effs_t *curr_effs = NULL;
479 fprintf (stdout, "effect for \"%s\"\n", procname);
481 while (NULL != cur) {
486 curr_effs = NEW (effs_t);
487 curr_effs->procname = procname;
488 curr_effs->n_effs = n_effs;
489 curr_effs->effs = (eff_t**) malloc (n_effs * sizeof (eff_t*));
491 while (NULL != cur) {
494 if (NODE_NAME (cur, arg)) {
495 eff = (eff_t*) parseArg (doc, cur);
496 } else if (NODE_NAME (cur, load)) {
497 eff = (eff_t*) parseLoad (doc, cur);
498 } else if (NODE_NAME (cur, store)) {
499 eff = (eff_t*) parseStore (doc, cur);
500 } else if (NODE_NAME (cur, alloc)) {
501 eff = (eff_t*) parseAlloc (doc, cur);
502 } else if (NODE_NAME (cur, call)) {
503 eff = (eff_t*) parseCall (doc, cur);
504 } else if (NODE_NAME (cur, join)) {
505 eff = (eff_t*) parseJoin (doc, cur);
506 } else if (NODE_NAME (cur, unknown)) {
507 eff = (eff_t*) parseUnknown (doc, cur);
508 } else if (NODE_NAME (cur, ret)) {
509 eff = (eff_t*) parseReturn (doc, cur);
510 } else if (NODE_NAME (cur, raise)) {
511 eff = (eff_t*) parseRaise (doc, cur);
512 } else if (NODE_NAME (cur, comment)) {
515 fprintf (stderr, "wrong element \"%s\"\n", BAD_CAST cur->name);
521 curr_effs->effs [i ++] = eff;
524 curr_effs->next = effs;
531 type_t *getTypeByName (const char *name)
533 type_t *curr = types;
535 while (NULL != curr) {
536 if (0 == strcmp (name, curr->name)) {
546 type_t *getTypeById (const int id)
548 type_t *curr = types;
550 while (NULL != curr) {
551 if (id == curr->id) {
561 entity_t *getEntityByNames (const char *name, const char *tp_name)
563 entity_t *curr = entities;
565 while (NULL != curr) {
566 if ((0 == strcmp (name, curr->name)) && (0 == strcmp (tp_name, curr->tp_name))) {
576 entity_t *getEntityById (const int id)
578 entity_t *curr = entities;
580 while (NULL != curr) {
581 if (id == curr->id) {
591 effs_t *getEffectByName (const char *procname)
593 effs_t *curr_effs = effs;
595 while (NULL != curr_effs) {
596 if (0 == strcmp (procname, curr_effs->procname)) {
600 curr_effs = curr_effs->next;
606 void read_extern (const char *filename)
608 /* xmlNsPtr ns = NULL; */ /* no namespace for us */
609 xmlDocPtr doc; /* whole document */
610 xmlNodePtr cur; /* current node */
611 /* i've got no idea what the VERSION cast is all about. voodoo
612 programming at its finest. */
613 LIBXML_TEST_VERSION xmlKeepBlanksDefault (0);
614 doc = xmlParseFile (filename);
615 CHECK (doc, "xmlParseFile");
617 cur = xmlDocGetRootElement (doc);
618 CHECK (cur, "xmlDocGetRootElement");
620 if (! NODE_NAME (cur, effects)) {
621 fprintf (stderr,"root node \"%s\" != \"effects\"\n", BAD_CAST cur->name);
628 const char *mod_str = getNodeModule (cur);
630 if (NULL != mod_str) {
631 fprintf (stdout, "effects for \"%s\"\n", mod_str);
633 fprintf (stdout, "effects \t0x%08x\n", (int) cur);
638 cur = cur->xmlChildrenNode;
639 while (cur != NULL) {
640 if (NODE_NAME (cur, type)) {
641 parseType (doc, cur);
642 } else if (NODE_NAME (cur, entity)) {
643 parseEntity (doc, cur);
644 } else if (NODE_NAME (cur, effect)) {
645 parseEffect (doc, cur);
646 } else if ((NODE_NAME (cur, comment))) {
649 fprintf (stderr, "wrong element \"%s\"\n", BAD_CAST cur->name);
657 void test_getEffectByName ()
659 /* test getEffectByName */
661 "store_unknown_proc",
668 "no_this_doesn't_really_exist",
675 while (NULL != names [i]) {
676 effs_t *the_eff = getEffectByName (names [i]);
679 fprintf (stdout, "Effect for \"%s\" is at 0x%08x\n",
680 names [i], (int) the_eff);
682 fprintf (stdout, "Effect for \"%s\" not found\n",
691 main (int argc, char **argv)
693 /* xmlNsPtr ns = NULL; */ /* no namespace for us */
694 xmlDocPtr doc; /* whole document */
695 xmlNodePtr cur; /* current node */
699 fprintf (stderr, "no filename\n");
703 /* i've got no idea what the VERSION cast is all about. voodoo
704 programming at its finest. */
705 LIBXML_TEST_VERSION xmlKeepBlanksDefault (0);
707 doc = xmlParseFile (name);
709 CHECK (doc, "xmlParseFile");
711 cur = xmlDocGetRootElement (doc);
712 CHECK (cur, "xmlDocGetRootElement");
714 if (! NODE_NAME (cur, effects)) {
715 fprintf (stderr,"root node \"%s\" != \"effects\"\n", BAD_CAST cur->name);
722 const char *mod_str = getNodeModule (cur);
724 if (NULL != mod_str) {
725 fprintf (stdout, "effects for \"%s\"\n", mod_str);
727 fprintf (stdout, "effects \t0x%08x\n", (int) cur);
732 cur = cur->xmlChildrenNode;
733 while (cur != NULL) {
734 if (NODE_NAME (cur, type)) {
735 parseType (doc, cur);
736 } else if (NODE_NAME (cur, entity)) {
737 parseEntity (doc, cur);
738 } else if (NODE_NAME (cur, effect)) {
739 parseEffect (doc, cur);
740 } else if ((NODE_NAME (cur, comment))) {
743 fprintf (stderr, "wrong element \"%s\"\n", BAD_CAST cur->name);
750 /* test getEffectByName */
753 "store_unknown_proc",
760 "no_this_doesn't_really_exist",
767 while (NULL != names [i]) {
768 effs_t *the_eff = getEffectByName (names [i]);
771 fprintf (stdout, "Effect for \"%s\" is at 0x%08x\n",
772 names [i], (int) the_eff);
774 fprintf (stdout, "Effect for \"%s\" not found\n",
787 * Revision 1.1 2004/10/11 09:31:06 liekweg
788 * First Import of XML reading procs --flo