mirror of
https://github.com/GNOME/libxml2.git
synced 2025-02-23 18:29:14 +08:00
- valid.c: applied small patch from Gary Pennington, reindented
some part of the code. Daniel
This commit is contained in:
parent
3bbbe6fa2a
commit
377219233f
@ -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>
|
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
|
* configure.in doc/xml.html doc/html/*: preparing for 2.3.8
|
||||||
|
284
valid.c
284
valid.c
@ -1901,11 +1901,11 @@ xmlCreateRefTable(void) {
|
|||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
xmlFreeRef(xmlLinkPtr lk) {
|
xmlFreeRef(xmlLinkPtr lk) {
|
||||||
xmlRefPtr ref = (xmlRefPtr)xmlLinkGetData(lk);
|
xmlRefPtr ref = (xmlRefPtr)xmlLinkGetData(lk);
|
||||||
if (ref == NULL) return;
|
if (ref == NULL) return;
|
||||||
if (ref->value != NULL)
|
if (ref->value != NULL)
|
||||||
xmlFree((xmlChar *)ref->value);
|
xmlFree((xmlChar *)ref->value);
|
||||||
xmlFree(ref);
|
xmlFree(ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1916,8 +1916,8 @@ xmlFreeRef(xmlLinkPtr lk) {
|
|||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
xmlFreeRefList(xmlListPtr list_ref) {
|
xmlFreeRefList(xmlListPtr list_ref) {
|
||||||
if (list_ref == NULL) return;
|
if (list_ref == NULL) return;
|
||||||
xmlListDelete(list_ref);
|
xmlListDelete(list_ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1930,15 +1930,15 @@ xmlFreeRefList(xmlListPtr list_ref) {
|
|||||||
static int
|
static int
|
||||||
xmlWalkRemoveRef(const void *data, const void *user)
|
xmlWalkRemoveRef(const void *data, const void *user)
|
||||||
{
|
{
|
||||||
xmlAttrPtr attr0 = ((xmlRefPtr)data)->attr;
|
xmlAttrPtr attr0 = ((xmlRefPtr)data)->attr;
|
||||||
xmlAttrPtr attr1 = ((xmlRemoveMemoPtr)user)->ap;
|
xmlAttrPtr attr1 = ((xmlRemoveMemoPtr)user)->ap;
|
||||||
xmlListPtr ref_list = ((xmlRemoveMemoPtr)user)->l;
|
xmlListPtr ref_list = ((xmlRemoveMemoPtr)user)->l;
|
||||||
|
|
||||||
if (attr0 == attr1) { /* Matched: remove and terminate walk */
|
if (attr0 == attr1) { /* Matched: remove and terminate walk */
|
||||||
xmlListRemoveFirst(ref_list, (void *)data);
|
xmlListRemoveFirst(ref_list, (void *)data);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1955,73 +1955,73 @@ xmlWalkRemoveRef(const void *data, const void *user)
|
|||||||
xmlRefPtr
|
xmlRefPtr
|
||||||
xmlAddRef(xmlValidCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlDocPtr doc, const xmlChar *value,
|
xmlAddRef(xmlValidCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlDocPtr doc, const xmlChar *value,
|
||||||
xmlAttrPtr attr) {
|
xmlAttrPtr attr) {
|
||||||
xmlRefPtr ret;
|
xmlRefPtr ret;
|
||||||
xmlRefTablePtr table;
|
xmlRefTablePtr table;
|
||||||
xmlListPtr ref_list;
|
xmlListPtr ref_list;
|
||||||
|
|
||||||
if (doc == NULL) {
|
if (doc == NULL) {
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
"xmlAddRefDecl: doc == NULL\n");
|
"xmlAddRefDecl: doc == NULL\n");
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
"xmlAddRefDecl: value == NULL\n");
|
"xmlAddRefDecl: value == NULL\n");
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
if (attr == NULL) {
|
if (attr == NULL) {
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
"xmlAddRefDecl: attr == NULL\n");
|
"xmlAddRefDecl: attr == NULL\n");
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the Ref table if needed.
|
* Create the Ref table if needed.
|
||||||
*/
|
*/
|
||||||
table = (xmlRefTablePtr) doc->refs;
|
table = (xmlRefTablePtr) doc->refs;
|
||||||
if (table == NULL)
|
if (table == NULL)
|
||||||
doc->refs = table = xmlCreateRefTable();
|
doc->refs = table = xmlCreateRefTable();
|
||||||
if (table == NULL) {
|
if (table == NULL) {
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
"xmlAddRef: Table creation failed!\n");
|
"xmlAddRef: Table creation failed!\n");
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = (xmlRefPtr) xmlMalloc(sizeof(xmlRef));
|
ret = (xmlRefPtr) xmlMalloc(sizeof(xmlRef));
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
"xmlAddRef: out of memory\n");
|
"xmlAddRef: out of memory\n");
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fill the structure.
|
* fill the structure.
|
||||||
*/
|
*/
|
||||||
ret->value = xmlStrdup(value);
|
ret->value = xmlStrdup(value);
|
||||||
ret->attr = attr;
|
ret->attr = attr;
|
||||||
|
|
||||||
/* To add a reference :-
|
/* To add a reference :-
|
||||||
* References are maintained as a list of references,
|
* References are maintained as a list of references,
|
||||||
* Lookup the entry, if no entry create new nodelist
|
* Lookup the entry, if no entry create new nodelist
|
||||||
* Add the owning node to the NodeList
|
* Add the owning node to the NodeList
|
||||||
* Return the ref
|
* Return the ref
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(NULL == (ref_list = xmlHashLookup(table, value))) {
|
if (NULL == (ref_list = xmlHashLookup(table, value))) {
|
||||||
if(NULL == (ref_list = xmlListCreate(xmlFreeRef, NULL))) {
|
if (NULL == (ref_list = xmlListCreate(xmlFreeRef, NULL))) {
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
"xmlAddRef: Reference list creation failed!\n");
|
"xmlAddRef: Reference list creation failed!\n");
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
if (xmlHashAddEntry(table, value, ref_list) < 0) {
|
if (xmlHashAddEntry(table, value, ref_list) < 0) {
|
||||||
xmlListDelete(ref_list);
|
xmlListDelete(ref_list);
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
"xmlAddRef: Reference list insertion failed!\n");
|
"xmlAddRef: Reference list insertion failed!\n");
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xmlListInsert(ref_list, ret);
|
xmlListInsert(ref_list, ret);
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2032,7 +2032,7 @@ xmlAddRef(xmlValidCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlDocPtr doc, const xmlChar *v
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
xmlFreeRefTable(xmlRefTablePtr table) {
|
xmlFreeRefTable(xmlRefTablePtr table) {
|
||||||
xmlHashFree(table, (xmlHashDeallocator) xmlFreeRefList);
|
xmlHashFree(table, (xmlHashDeallocator) xmlFreeRefList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2049,23 +2049,25 @@ xmlFreeRefTable(xmlRefTablePtr table) {
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xmlIsRef(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) {
|
xmlIsRef(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) {
|
||||||
if ((doc->intSubset == NULL) && (doc->extSubset == NULL)) {
|
if ((doc->intSubset == NULL) && (doc->extSubset == NULL)) {
|
||||||
return(0);
|
return(0);
|
||||||
} else if (doc->type == XML_HTML_DOCUMENT_NODE) {
|
} else if (doc->type == XML_HTML_DOCUMENT_NODE) {
|
||||||
/* TODO @@@ */
|
/* TODO @@@ */
|
||||||
return(0);
|
return(0);
|
||||||
} else {
|
} else {
|
||||||
xmlAttributePtr attrDecl;
|
xmlAttributePtr attrDecl;
|
||||||
|
|
||||||
attrDecl = xmlGetDtdAttrDesc(doc->intSubset, elem->name, attr->name);
|
attrDecl = xmlGetDtdAttrDesc(doc->intSubset, elem->name, attr->name);
|
||||||
if ((attrDecl == NULL) && (doc->extSubset != NULL))
|
if ((attrDecl == NULL) && (doc->extSubset != NULL))
|
||||||
attrDecl = xmlGetDtdAttrDesc(doc->extSubset, elem->name,
|
attrDecl = xmlGetDtdAttrDesc(doc->extSubset,
|
||||||
attr->name);
|
elem->name, attr->name);
|
||||||
|
|
||||||
if ((attrDecl != NULL) && (attrDecl->atype == XML_ATTRIBUTE_IDREF))
|
if ((attrDecl != NULL) &&
|
||||||
return(1);
|
(attrDecl->atype == XML_ATTRIBUTE_IDREF ||
|
||||||
}
|
attrDecl->atype == XML_ATTRIBUTE_IDREFS))
|
||||||
return(0);
|
return(1);
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2079,50 +2081,50 @@ xmlIsRef(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) {
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xmlRemoveRef(xmlDocPtr doc, xmlAttrPtr attr) {
|
xmlRemoveRef(xmlDocPtr doc, xmlAttrPtr attr) {
|
||||||
xmlListPtr ref_list;
|
xmlListPtr ref_list;
|
||||||
xmlRefTablePtr table;
|
xmlRefTablePtr table;
|
||||||
xmlChar *ID;
|
xmlChar *ID;
|
||||||
xmlRemoveMemo target;
|
xmlRemoveMemo target;
|
||||||
|
|
||||||
if (doc == NULL) return(-1);
|
if (doc == NULL) return(-1);
|
||||||
if (attr == NULL) return(-1);
|
if (attr == NULL) return(-1);
|
||||||
table = (xmlRefTablePtr) doc->refs;
|
table = (xmlRefTablePtr) doc->refs;
|
||||||
if (table == NULL)
|
if (table == NULL)
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
||||||
if (attr == NULL)
|
if (attr == NULL)
|
||||||
return(-1);
|
return(-1);
|
||||||
ID = xmlNodeListGetString(doc, attr->children, 1);
|
ID = xmlNodeListGetString(doc, attr->children, 1);
|
||||||
if (ID == NULL)
|
if (ID == NULL)
|
||||||
return(-1);
|
return(-1);
|
||||||
ref_list = xmlHashLookup(table, ID);
|
ref_list = xmlHashLookup(table, ID);
|
||||||
|
|
||||||
if(ref_list == NULL) {
|
if(ref_list == NULL) {
|
||||||
xmlFree(ID);
|
xmlFree(ID);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
/* At this point, ref_list refers to a list of references which
|
/* At this point, ref_list refers to a list of references which
|
||||||
* have the same key as the supplied attr. Our list of references
|
* have the same key as the supplied attr. Our list of references
|
||||||
* is ordered by reference address and we don't have that information
|
* 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
|
* 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
|
* check for a matching attribute, when we find one stop the walk
|
||||||
* and remove the entry.
|
* and remove the entry.
|
||||||
* The list is ordered by reference, so that means we don't have the
|
* 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
|
* key. Passing the list and the reference to the walker means we
|
||||||
* will have enough data to be able to remove the entry.
|
* will have enough data to be able to remove the entry.
|
||||||
*/
|
*/
|
||||||
target.l = ref_list;
|
target.l = ref_list;
|
||||||
target.ap = attr;
|
target.ap = attr;
|
||||||
|
|
||||||
/* Remove the supplied attr from our list */
|
/* Remove the supplied attr from our list */
|
||||||
xmlListWalk(ref_list, xmlWalkRemoveRef, &target);
|
xmlListWalk(ref_list, xmlWalkRemoveRef, &target);
|
||||||
|
|
||||||
/*If the list is empty then remove the list entry in the hash */
|
/*If the list is empty then remove the list entry in the hash */
|
||||||
if (xmlListEmpty(ref_list))
|
if (xmlListEmpty(ref_list))
|
||||||
xmlHashUpdateEntry(table, ID, NULL, (xmlHashDeallocator)
|
xmlHashUpdateEntry(table, ID, NULL, (xmlHashDeallocator)
|
||||||
xmlFreeRefList);
|
xmlFreeRefList);
|
||||||
xmlFree(ID);
|
xmlFree(ID);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2136,23 +2138,23 @@ xmlRemoveRef(xmlDocPtr doc, xmlAttrPtr attr) {
|
|||||||
*/
|
*/
|
||||||
xmlListPtr
|
xmlListPtr
|
||||||
xmlGetRefs(xmlDocPtr doc, const xmlChar *ID) {
|
xmlGetRefs(xmlDocPtr doc, const xmlChar *ID) {
|
||||||
xmlRefTablePtr table;
|
xmlRefTablePtr table;
|
||||||
|
|
||||||
if (doc == NULL) {
|
if (doc == NULL) {
|
||||||
xmlGenericError(xmlGenericErrorContext, "xmlGetRef: doc == NULL\n");
|
xmlGenericError(xmlGenericErrorContext, "xmlGetRef: doc == NULL\n");
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ID == NULL) {
|
if (ID == NULL) {
|
||||||
xmlGenericError(xmlGenericErrorContext, "xmlGetRef: ID == NULL\n");
|
xmlGenericError(xmlGenericErrorContext, "xmlGetRef: ID == NULL\n");
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
table = (xmlRefTablePtr) doc->refs;
|
table = (xmlRefTablePtr) doc->refs;
|
||||||
if (table == NULL)
|
if (table == NULL)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
return (xmlHashLookup(table, ID));
|
return (xmlHashLookup(table, ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
|
Loading…
Reference in New Issue
Block a user