[Refdb-cvs] CVS: refdb/src xmlhandler.c,1.22,1.23
Status: Beta
Brought to you by:
mhoenicka
From: Markus H. <mho...@us...> - 2004-05-17 23:54:44
|
Update of /cvsroot/refdb/refdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4491 Modified Files: xmlhandler.c Log Message: moved elstack functions to elstack.c and elstack.h Index: xmlhandler.c =================================================================== RCS file: /cvsroot/refdb/refdb/src/xmlhandler.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -U2 -r1.22 -r1.23 --- xmlhandler.c 28 Apr 2004 03:03:16 -0000 1.22 +++ xmlhandler.c 17 May 2004 23:54:34 -0000 1.23 @@ -36,4 +36,5 @@ #include "refdb.h" #include "refdbd.h" /* depends on backend.h */ +#include "elstack.h" #include "xmlhandler.h" #include "strfncs.h" @@ -54,5 +55,4 @@ /* forward declarations of local functions */ static char* concat_elnames(struct elstack* ptr_current_element, char* exclude_name, char* concat); -static char* get_ancestor_attr(struct elstack* ptr_current_element, char* ancestor_name, char* ancestor_attribute); @@ -326,5 +326,5 @@ /* first authorlist */ else if (strcmp((ptr_asdata->ptr_first)->elname, "AUTHORLIST") == 0) { - ptr_attr = get_ancestor_attr(ptr_asdata->ptr_first, "AUTHORLIST", "ROLE"); + ptr_attr = elstack_get_ancestor_attr(ptr_asdata->ptr_first, "AUTHORLIST", "ROLE"); if (strcmp(ptr_attr, "PRIMARY") == 0) { strcpy(concat, "AUTHORLIST"); @@ -357,5 +357,5 @@ /* second pubdate */ else if (strcmp((ptr_asdata->ptr_first)->elname, "PUBDATE") == 0) { - ptr_attr = get_ancestor_attr(ptr_asdata->ptr_first, "PUBDATE", "ROLE"); + ptr_attr = elstack_get_ancestor_attr(ptr_asdata->ptr_first, "PUBDATE", "ROLE"); if (strcmp(ptr_attr, "PRIMARY") == 0) { strcpy(concat, "PUBDATE"); @@ -385,5 +385,5 @@ /* third title */ else if (strcmp((ptr_asdata->ptr_first)->elname, "TITLE") == 0) { - ptr_attr = get_ancestor_attr(ptr_asdata->ptr_first, "TITLE", "ROLE"); + ptr_attr = elstack_get_ancestor_attr(ptr_asdata->ptr_first, "TITLE", "ROLE"); if (strcmp(ptr_attr, "PRIMARY") == 0) { strcpy(concat, "TITLE"); @@ -414,5 +414,5 @@ } else if (strcmp((ptr_asdata->ptr_first)->elname, "USERDEF") == 0) { - ptr_attr = get_ancestor_attr(ptr_asdata->ptr_first, "USERDEF", "ROLE"); + ptr_attr = elstack_get_ancestor_attr(ptr_asdata->ptr_first, "USERDEF", "ROLE"); if (strcmp(ptr_attr, "1") == 0) { strcpy(concat, "USERDEF1"); @@ -446,5 +446,5 @@ } else if (strcmp((ptr_asdata->ptr_first)->elname, "MISC") == 0) { - ptr_attr = get_ancestor_attr(ptr_asdata->ptr_first, "MISC", "ROLE"); + ptr_attr = elstack_get_ancestor_attr(ptr_asdata->ptr_first, "MISC", "ROLE"); if (strcmp(ptr_attr, "1") == 0) { strcpy(concat, "MISC1"); @@ -472,5 +472,5 @@ } else if (strcmp((ptr_asdata->ptr_first)->elname, "LINK") == 0) { - ptr_attr = get_ancestor_attr(ptr_asdata->ptr_first, "LINK", "ROLE"); + ptr_attr = elstack_get_ancestor_attr(ptr_asdata->ptr_first, "LINK", "ROLE"); if (strcmp(ptr_attr, "1") == 0) { strcpy(concat, "LINK1"); @@ -547,11 +547,11 @@ strcpy(table_name, "REFSTYLE"); - if (is_descendant_of(ptr_asdata->ptr_first, "PUBTYPE")) { - strcpy(pubtype, get_ancestor_attr(ptr_asdata->ptr_first, "PUBTYPE", "TYPE")); + if (elstack_is_descendant_of(ptr_asdata->ptr_first, "PUBTYPE")) { + strcpy(pubtype, elstack_get_ancestor_attr(ptr_asdata->ptr_first, "PUBTYPE", "TYPE")); } - else if (is_descendant_of(ptr_asdata->ptr_first, "INTEXTDEF")) { + else if (elstack_is_descendant_of(ptr_asdata->ptr_first, "INTEXTDEF")) { strcpy(pubtype, "INTEXT"); } - else if (is_descendant_of(ptr_asdata->ptr_first, "AUTHORONLY")) { + else if (elstack_is_descendant_of(ptr_asdata->ptr_first, "AUTHORONLY")) { strcpy(pubtype, "AUTHORONLY"); } @@ -572,13 +572,13 @@ /* elements with character data at various locations */ else if (strcmp((ptr_asdata->ptr_first)->elname, "RANGESEPARATOR") == 0) { - if (is_descendant_of(ptr_asdata->ptr_first, "PUBTYPE")) { + if (elstack_is_descendant_of(ptr_asdata->ptr_first, "PUBTYPE")) { strcpy(table_name, "REFSTYLE"); strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "PUBTYPE", concat)); - strcpy(pubtype, get_ancestor_attr(ptr_asdata->ptr_first, "PUBTYPE", "TYPE")); + strcpy(pubtype, elstack_get_ancestor_attr(ptr_asdata->ptr_first, "PUBTYPE", "TYPE")); n_chardata = 1; n_attrdata = 1; current_id = *(ptr_asdata->ptr_citstyle_id); } - else if (is_descendant_of(ptr_asdata->ptr_first, "INTEXTDEF")) { + else if (elstack_is_descendant_of(ptr_asdata->ptr_first, "INTEXTDEF")) { strcpy(table_name, "REFSTYLE"); strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "INTEXTDEF", concat)); @@ -588,5 +588,5 @@ current_id = *(ptr_asdata->ptr_citstyle_id); } - else if (is_descendant_of(ptr_asdata->ptr_first, "AUTHORONLY")) { + else if (elstack_is_descendant_of(ptr_asdata->ptr_first, "AUTHORONLY")) { strcpy(table_name, "REFSTYLE"); strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "AUTHORONLY", concat)); @@ -596,5 +596,5 @@ current_id = *(ptr_asdata->ptr_citstyle_id); } - else if (is_descendant_of(ptr_asdata->ptr_first, "YEARONLY")) { + else if (elstack_is_descendant_of(ptr_asdata->ptr_first, "YEARONLY")) { strcpy(table_name, "REFSTYLE"); strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "YEARONLY", concat)); @@ -633,15 +633,15 @@ } else { - if (is_descendant_of(ptr_asdata->ptr_first, "PUBTYPE")) { + if (elstack_is_descendant_of(ptr_asdata->ptr_first, "PUBTYPE")) { strcpy(table_name, "REFSTYLE"); strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "PUBTYPE", concat)); - strcpy(pubtype, get_ancestor_attr(ptr_asdata->ptr_first, "PUBTYPE", "TYPE")); + strcpy(pubtype, elstack_get_ancestor_attr(ptr_asdata->ptr_first, "PUBTYPE", "TYPE")); } - else if (is_descendant_of(ptr_asdata->ptr_first, "INTEXTDEF")) { + else if (elstack_is_descendant_of(ptr_asdata->ptr_first, "INTEXTDEF")) { strcpy(table_name, "REFSTYLE"); strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "INTEXTDEF", concat)); strcpy(pubtype, "INTEXT"); } - else if (is_descendant_of(ptr_asdata->ptr_first, "AUTHORONLY")) { + else if (elstack_is_descendant_of(ptr_asdata->ptr_first, "AUTHORONLY")) { strcpy(table_name, "REFSTYLE"); strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "AUTHORONLY", concat)); @@ -670,13 +670,13 @@ strcmp((ptr_asdata->ptr_first)->elname, "TWOSEPS") == 0) { strcpy(table_name, "REFSTYLE"); - if (is_descendant_of(ptr_asdata->ptr_first, "PUBTYPE")) { + if (elstack_is_descendant_of(ptr_asdata->ptr_first, "PUBTYPE")) { strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "PUBTYPE", concat)); - strcpy(pubtype, get_ancestor_attr(ptr_asdata->ptr_first, "PUBTYPE", "TYPE")); + strcpy(pubtype, elstack_get_ancestor_attr(ptr_asdata->ptr_first, "PUBTYPE", "TYPE")); } - else if (is_descendant_of(ptr_asdata->ptr_first, "INTEXTDEF")) { + else if (elstack_is_descendant_of(ptr_asdata->ptr_first, "INTEXTDEF")) { strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "INTEXTDEF", concat)); strcpy(pubtype, "INTEXT"); } - else if (is_descendant_of(ptr_asdata->ptr_first, "AUTHORONLY")) { + else if (elstack_is_descendant_of(ptr_asdata->ptr_first, "AUTHORONLY")) { strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "AUTHORONLY", concat)); strcpy(pubtype, "AUTHORONLY"); @@ -695,13 +695,13 @@ strcmp((ptr_asdata->ptr_first)->elname, "SECONDSEP") == 0) { strcpy(table_name, "REFSTYLE"); - if (is_descendant_of(ptr_asdata->ptr_first, "PUBTYPE")) { + if (elstack_is_descendant_of(ptr_asdata->ptr_first, "PUBTYPE")) { strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "PUBTYPE", concat)); - strcpy(pubtype, get_ancestor_attr(ptr_asdata->ptr_first, "PUBTYPE", "TYPE")); + strcpy(pubtype, elstack_get_ancestor_attr(ptr_asdata->ptr_first, "PUBTYPE", "TYPE")); } - else if (is_descendant_of(ptr_asdata->ptr_first, "INTEXTDEF")) { + else if (elstack_is_descendant_of(ptr_asdata->ptr_first, "INTEXTDEF")) { strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "INTEXTDEF", concat)); strcpy(pubtype, "INTEXT"); } - else if (is_descendant_of(ptr_asdata->ptr_first, "AUTHORONLY")) { + else if (elstack_is_descendant_of(ptr_asdata->ptr_first, "AUTHORONLY")) { strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "AUTHORONLY", concat)); strcpy(pubtype, "AUTHORONLY"); @@ -739,13 +739,13 @@ strcmp((ptr_asdata->ptr_first)->elname, "VOLUME") == 0) { strcpy(table_name, "REFSTYLE"); - if (is_descendant_of(ptr_asdata->ptr_first, "PUBTYPE")) { + if (elstack_is_descendant_of(ptr_asdata->ptr_first, "PUBTYPE")) { strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "PUBTYPE", concat)); - strcpy(pubtype, get_ancestor_attr(ptr_asdata->ptr_first, "PUBTYPE", "TYPE")); + strcpy(pubtype, elstack_get_ancestor_attr(ptr_asdata->ptr_first, "PUBTYPE", "TYPE")); } - else if (is_descendant_of(ptr_asdata->ptr_first, "INTEXTDEF")) { + else if (elstack_is_descendant_of(ptr_asdata->ptr_first, "INTEXTDEF")) { strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "INTEXTDEF", concat)); strcpy(pubtype, "INTEXT"); } - else if (is_descendant_of(ptr_asdata->ptr_first, "AUTHORONLY")) { + else if (elstack_is_descendant_of(ptr_asdata->ptr_first, "AUTHORONLY")) { strcpy(column_name, concat_elnames(ptr_asdata->ptr_first, "AUTHORONLY", concat)); strcpy(pubtype, "AUTHORONLY"); @@ -940,95 +940,4 @@ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - get_ancestor_attr(): returns the value of an attribute of an - ancestor of the current element - - static char* get_ancestor_attr returns the value of the requested attribute - or NULL if no such attribute is found - - struct elstack* ptr_current_element ptr to the current element on - the element stack - - char* ancestor_name name of the requested ancestor element - - char* ancestor_attribute name of the requested ancestor attribute - - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ -static char* get_ancestor_attr(struct elstack* ptr_current_element, char* ancestor_name, char* ancestor_attribute) { - struct elstack* ptr_el; - struct attrlist* ptr_attr; - - ptr_el = ptr_current_element; - - while (ptr_el != NULL) { - if (strcmp(ptr_el->elname, ancestor_name) == 0) { - ptr_attr = ptr_el->ptr_attr_first; - - while (ptr_attr != NULL) { - if (strcmp(ptr_attr->attribute_name, ancestor_attribute) == 0) { - return ptr_attr->attribute_value; - } - ptr_attr = ptr_attr->ptr_next; - } - } - ptr_el = ptr_el->ptr_next; - } - return NULL; -} - -/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - get_attr(): returns the value of an attribute of the current element - - char* get_attr returns the value of the requested attribute - or NULL if no such attribute is found - - struct elstack* ptr_current_element ptr to the current element on - the element stack - - char* attribute name of the requested attribute - - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ -char* get_attr(struct elstack* ptr_current_element, char* attribute) { - struct attrlist* ptr_attr; - - ptr_attr = ptr_current_element->ptr_attr_first; - - while (ptr_attr != NULL) { - if (strcmp(ptr_attr->attribute_name, attribute) == 0) { - return ptr_attr->attribute_value; - } - ptr_attr = ptr_attr->ptr_next; - } - - return NULL; -} - -/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - is_descendant_of(): tests whether the current element is the - descendant of a given element - - int is_descendant_of returns 1 if the current element is the - descendant of the given element, 0 if not - - struct elstack* ptr_current_element ptr to the current element on - the element stack - - char* ancestor_name name of the requested ancestor element - - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ -int is_descendant_of(struct elstack* ptr_current_element, char* ancestor_name) { - struct elstack* ptr_el; - - ptr_el = ptr_current_element; - - while (ptr_el != NULL) { - if (strcmp(ptr_el->elname, ancestor_name) == 0) { - return 1; - } - ptr_el = ptr_el->ptr_next; - } - return 0; -} - -/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ concat_elnames(): concatenates the names of all ancestors of the current element up to a given element which is not @@ -1074,5 +983,5 @@ /* we use short versions of these element names in order not to exceed the column name limit of PostgreSQL */ - ptr_attr = get_ancestor_attr(ptr_el, "AUTHORLIST", "ROLE"); + ptr_attr = elstack_get_ancestor_attr(ptr_el, "AUTHORLIST", "ROLE"); if (strcmp(ptr_attr, "PRIMARY") == 0) { strcpy(concat, "Q"); /* AUTHORLIST */ @@ -1089,5 +998,5 @@ } else if (strcmp(ptr_el->elname, "PUBDATE") == 0) { - ptr_attr = get_ancestor_attr(ptr_el, "PUBDATE", "ROLE"); + ptr_attr = elstack_get_ancestor_attr(ptr_el, "PUBDATE", "ROLE"); if (strcmp(ptr_attr, "PRIMARY") == 0) { strcpy(concat, "PUBDATE"); @@ -1101,5 +1010,5 @@ } else if (strcmp(ptr_el->elname, "TITLE") == 0) { - ptr_attr = get_ancestor_attr(ptr_el, "TITLE", "ROLE"); + ptr_attr = elstack_get_ancestor_attr(ptr_el, "TITLE", "ROLE"); if (strcmp(ptr_attr, "PRIMARY") == 0) { strcpy(concat, "TITLE"); @@ -1116,5 +1025,5 @@ } else if (strcmp(ptr_el->elname, "USERDEF") == 0) { - ptr_attr = get_ancestor_attr(ptr_el, "USERDEF", "ROLE"); + ptr_attr = elstack_get_ancestor_attr(ptr_el, "USERDEF", "ROLE"); if (strcmp(ptr_attr, "1") == 0) { strcpy(concat, "USERDEF1"); @@ -1134,5 +1043,5 @@ } else if (strcmp(ptr_el->elname, "MISC") == 0) { - ptr_attr = get_ancestor_attr(ptr_el, "MISC", "ROLE"); + ptr_attr = elstack_get_ancestor_attr(ptr_el, "MISC", "ROLE"); if (strcmp(ptr_attr, "1") == 0) { strcpy(concat, "MISC1"); @@ -1146,5 +1055,5 @@ } else if (strcmp(ptr_el->elname, "LINK") == 0) { - ptr_attr = get_ancestor_attr(ptr_el, "LINK", "ROLE"); + ptr_attr = elstack_get_ancestor_attr(ptr_el, "LINK", "ROLE"); if (strcmp(ptr_attr, "1") == 0) { strcpy(concat, "LINK1"); |