- valid.c: applied small patch from Gary Pennington, reindented

some part of the code.
Daniel
This commit is contained in:
Daniel Veillard 2001-05-04 15:21:12 +00:00
parent 3bbbe6fa2a
commit 377219233f
2 changed files with 148 additions and 141 deletions

View File

@ -1,3 +1,8 @@
Fri May 4 17:19:39 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* valid.c: applied small patch from Gary Pennington, reindented
some part of the code.
Thu May 3 13:10:43 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* configure.in doc/xml.html doc/html/*: preparing for 2.3.8

282
valid.c
View File

@ -1901,11 +1901,11 @@ xmlCreateRefTable(void) {
*/
static void
xmlFreeRef(xmlLinkPtr lk) {
xmlRefPtr ref = (xmlRefPtr)xmlLinkGetData(lk);
if (ref == NULL) return;
if (ref->value != NULL)
xmlFree((xmlChar *)ref->value);
xmlFree(ref);
xmlRefPtr ref = (xmlRefPtr)xmlLinkGetData(lk);
if (ref == NULL) return;
if (ref->value != NULL)
xmlFree((xmlChar *)ref->value);
xmlFree(ref);
}
/**
@ -1916,8 +1916,8 @@ xmlFreeRef(xmlLinkPtr lk) {
*/
static void
xmlFreeRefList(xmlListPtr list_ref) {
if (list_ref == NULL) return;
xmlListDelete(list_ref);
if (list_ref == NULL) return;
xmlListDelete(list_ref);
}
/**
@ -1930,15 +1930,15 @@ xmlFreeRefList(xmlListPtr list_ref) {
static int
xmlWalkRemoveRef(const void *data, const void *user)
{
xmlAttrPtr attr0 = ((xmlRefPtr)data)->attr;
xmlAttrPtr attr1 = ((xmlRemoveMemoPtr)user)->ap;
xmlListPtr ref_list = ((xmlRemoveMemoPtr)user)->l;
xmlAttrPtr attr0 = ((xmlRefPtr)data)->attr;
xmlAttrPtr attr1 = ((xmlRemoveMemoPtr)user)->ap;
xmlListPtr ref_list = ((xmlRemoveMemoPtr)user)->l;
if (attr0 == attr1) { /* Matched: remove and terminate walk */
xmlListRemoveFirst(ref_list, (void *)data);
return 0;
}
return 1;
if (attr0 == attr1) { /* Matched: remove and terminate walk */
xmlListRemoveFirst(ref_list, (void *)data);
return 0;
}
return 1;
}
/**
@ -1955,73 +1955,73 @@ xmlWalkRemoveRef(const void *data, const void *user)
xmlRefPtr
xmlAddRef(xmlValidCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlDocPtr doc, const xmlChar *value,
xmlAttrPtr attr) {
xmlRefPtr ret;
xmlRefTablePtr table;
xmlListPtr ref_list;
xmlRefPtr ret;
xmlRefTablePtr table;
xmlListPtr ref_list;
if (doc == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddRefDecl: doc == NULL\n");
return(NULL);
}
if (value == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddRefDecl: value == NULL\n");
return(NULL);
}
if (attr == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddRefDecl: attr == NULL\n");
return(NULL);
}
if (doc == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddRefDecl: doc == NULL\n");
return(NULL);
}
if (value == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddRefDecl: value == NULL\n");
return(NULL);
}
if (attr == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddRefDecl: attr == NULL\n");
return(NULL);
}
/*
/*
* Create the Ref table if needed.
*/
table = (xmlRefTablePtr) doc->refs;
if (table == NULL)
doc->refs = table = xmlCreateRefTable();
if (table == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddRef: Table creation failed!\n");
return(NULL);
}
table = (xmlRefTablePtr) doc->refs;
if (table == NULL)
doc->refs = table = xmlCreateRefTable();
if (table == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddRef: Table creation failed!\n");
return(NULL);
}
ret = (xmlRefPtr) xmlMalloc(sizeof(xmlRef));
if (ret == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddRef: out of memory\n");
return(NULL);
}
ret = (xmlRefPtr) xmlMalloc(sizeof(xmlRef));
if (ret == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddRef: out of memory\n");
return(NULL);
}
/*
/*
* fill the structure.
*/
ret->value = xmlStrdup(value);
ret->attr = attr;
ret->value = xmlStrdup(value);
ret->attr = attr;
/* To add a reference :-
* References are maintained as a list of references,
* Lookup the entry, if no entry create new nodelist
* Add the owning node to the NodeList
* Return the ref
*/
/* To add a reference :-
* References are maintained as a list of references,
* Lookup the entry, if no entry create new nodelist
* Add the owning node to the NodeList
* Return the ref
*/
if(NULL == (ref_list = xmlHashLookup(table, value))) {
if(NULL == (ref_list = xmlListCreate(xmlFreeRef, NULL))) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddRef: Reference list creation failed!\n");
return(NULL);
}
if (xmlHashAddEntry(table, value, ref_list) < 0) {
xmlListDelete(ref_list);
xmlGenericError(xmlGenericErrorContext,
"xmlAddRef: Reference list insertion failed!\n");
return(NULL);
}
}
xmlListInsert(ref_list, ret);
return(ret);
if (NULL == (ref_list = xmlHashLookup(table, value))) {
if (NULL == (ref_list = xmlListCreate(xmlFreeRef, NULL))) {
xmlGenericError(xmlGenericErrorContext,
"xmlAddRef: Reference list creation failed!\n");
return(NULL);
}
if (xmlHashAddEntry(table, value, ref_list) < 0) {
xmlListDelete(ref_list);
xmlGenericError(xmlGenericErrorContext,
"xmlAddRef: Reference list insertion failed!\n");
return(NULL);
}
}
xmlListInsert(ref_list, ret);
return(ret);
}
/**
@ -2032,7 +2032,7 @@ xmlAddRef(xmlValidCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlDocPtr doc, const xmlChar *v
*/
void
xmlFreeRefTable(xmlRefTablePtr table) {
xmlHashFree(table, (xmlHashDeallocator) xmlFreeRefList);
xmlHashFree(table, (xmlHashDeallocator) xmlFreeRefList);
}
/**
@ -2049,23 +2049,25 @@ xmlFreeRefTable(xmlRefTablePtr table) {
*/
int
xmlIsRef(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) {
if ((doc->intSubset == NULL) && (doc->extSubset == NULL)) {
return(0);
} else if (doc->type == XML_HTML_DOCUMENT_NODE) {
/* TODO @@@ */
return(0);
} else {
xmlAttributePtr attrDecl;
if ((doc->intSubset == NULL) && (doc->extSubset == NULL)) {
return(0);
} else if (doc->type == XML_HTML_DOCUMENT_NODE) {
/* TODO @@@ */
return(0);
} else {
xmlAttributePtr attrDecl;
attrDecl = xmlGetDtdAttrDesc(doc->intSubset, elem->name, attr->name);
if ((attrDecl == NULL) && (doc->extSubset != NULL))
attrDecl = xmlGetDtdAttrDesc(doc->extSubset, elem->name,
attr->name);
attrDecl = xmlGetDtdAttrDesc(doc->intSubset, elem->name, attr->name);
if ((attrDecl == NULL) && (doc->extSubset != NULL))
attrDecl = xmlGetDtdAttrDesc(doc->extSubset,
elem->name, attr->name);
if ((attrDecl != NULL) && (attrDecl->atype == XML_ATTRIBUTE_IDREF))
return(1);
}
return(0);
if ((attrDecl != NULL) &&
(attrDecl->atype == XML_ATTRIBUTE_IDREF ||
attrDecl->atype == XML_ATTRIBUTE_IDREFS))
return(1);
}
return(0);
}
/**
@ -2079,50 +2081,50 @@ xmlIsRef(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) {
*/
int
xmlRemoveRef(xmlDocPtr doc, xmlAttrPtr attr) {
xmlListPtr ref_list;
xmlRefTablePtr table;
xmlChar *ID;
xmlRemoveMemo target;
xmlListPtr ref_list;
xmlRefTablePtr table;
xmlChar *ID;
xmlRemoveMemo target;
if (doc == NULL) return(-1);
if (attr == NULL) return(-1);
table = (xmlRefTablePtr) doc->refs;
if (table == NULL)
return(-1);
if (doc == NULL) return(-1);
if (attr == NULL) return(-1);
table = (xmlRefTablePtr) doc->refs;
if (table == NULL)
return(-1);
if (attr == NULL)
return(-1);
ID = xmlNodeListGetString(doc, attr->children, 1);
if (ID == NULL)
return(-1);
ref_list = xmlHashLookup(table, ID);
if (attr == NULL)
return(-1);
ID = xmlNodeListGetString(doc, attr->children, 1);
if (ID == NULL)
return(-1);
ref_list = xmlHashLookup(table, ID);
if(ref_list == NULL) {
xmlFree(ID);
return (-1);
}
/* At this point, ref_list refers to a list of references which
* have the same key as the supplied attr. Our list of references
* is ordered by reference address and we don't have that information
* here to use when removing. We'll have to walk the list and
* check for a matching attribute, when we find one stop the walk
* and remove the entry.
* The list is ordered by reference, so that means we don't have the
* key. Passing the list and the reference to the walker means we
* will have enough data to be able to remove the entry.
*/
target.l = ref_list;
target.ap = attr;
if(ref_list == NULL) {
xmlFree(ID);
return (-1);
}
/* At this point, ref_list refers to a list of references which
* have the same key as the supplied attr. Our list of references
* is ordered by reference address and we don't have that information
* here to use when removing. We'll have to walk the list and
* check for a matching attribute, when we find one stop the walk
* and remove the entry.
* The list is ordered by reference, so that means we don't have the
* key. Passing the list and the reference to the walker means we
* will have enough data to be able to remove the entry.
*/
target.l = ref_list;
target.ap = attr;
/* Remove the supplied attr from our list */
xmlListWalk(ref_list, xmlWalkRemoveRef, &target);
/* Remove the supplied attr from our list */
xmlListWalk(ref_list, xmlWalkRemoveRef, &target);
/*If the list is empty then remove the list entry in the hash */
if (xmlListEmpty(ref_list))
xmlHashUpdateEntry(table, ID, NULL, (xmlHashDeallocator)
xmlFreeRefList);
xmlFree(ID);
return(0);
/*If the list is empty then remove the list entry in the hash */
if (xmlListEmpty(ref_list))
xmlHashUpdateEntry(table, ID, NULL, (xmlHashDeallocator)
xmlFreeRefList);
xmlFree(ID);
return(0);
}
/**
@ -2136,23 +2138,23 @@ xmlRemoveRef(xmlDocPtr doc, xmlAttrPtr attr) {
*/
xmlListPtr
xmlGetRefs(xmlDocPtr doc, const xmlChar *ID) {
xmlRefTablePtr table;
xmlRefTablePtr table;
if (doc == NULL) {
xmlGenericError(xmlGenericErrorContext, "xmlGetRef: doc == NULL\n");
return(NULL);
}
if (doc == NULL) {
xmlGenericError(xmlGenericErrorContext, "xmlGetRef: doc == NULL\n");
return(NULL);
}
if (ID == NULL) {
xmlGenericError(xmlGenericErrorContext, "xmlGetRef: ID == NULL\n");
return(NULL);
}
if (ID == NULL) {
xmlGenericError(xmlGenericErrorContext, "xmlGetRef: ID == NULL\n");
return(NULL);
}
table = (xmlRefTablePtr) doc->refs;
if (table == NULL)
return(NULL);
table = (xmlRefTablePtr) doc->refs;
if (table == NULL)
return(NULL);
return (xmlHashLookup(table, ID));
return (xmlHashLookup(table, ID));
}
/************************************************************************