Annotation of XML/entities.c, revision 1.1
1.1 ! httpng 1: /*
! 2: * entities.c : implementation for the XML entities handking
! 3: */
! 4:
! 5: #include <stdio.h>
! 6: #include <malloc.h>
! 7: #include "entities.h"
! 8:
! 9: /*
! 10: * An unit of storage for an entity, contains the string, the value
! 11: * and the linkind data needed for the linking in the hash table.
! 12: */
! 13:
! 14: typedef struct xmlEntity {
! 15: struct xmlEntity *nextHash; /* Next entity in the hash table */
! 16: CHAR value; /* The entity CHAR equivalent */
! 17: const CHAR *id; /* The entity name */
! 18: } xmlEntity, *xmlEntityPtr;
! 19:
! 20: /*
! 21: * ALl entities are stored in an hash table associated to the document
! 22: */
! 23:
! 24: #define XML_NB_ENTITIES_HASH 256
! 25:
! 26: typedef struct xmlEntitiesHashTable {
! 27: int nb_entities; /* number of elements stored */
! 28: xmlEntityPtr table[XML_NB_ENTITIES_HASH]; /* the hash table itself */
! 29: } xmlEntitiesHashTable, *xmlEntitiesHashTablePtr;
! 30:
! 31: /*
! 32: * xmlCreateEntity : create a new entity record.
! 33: */
! 34: xmlEntityPtr xmlCreateEntity(CHAR value, const CHAR *id) {
! 35: xmlEntityPtr ret;
! 36:
! 37: ret = (xmlEntityPtr) malloc(sizeof(xmlEntity));
! 38: if (ret == NULL) {
! 39: fprintf(stderr, "xmlCreateEntity : malloc(%d) failed\n",
! 40: sizeof(xmlEntity));
! 41: }
! 42: ret->value = value;
! 43: ret->id = xmlStrdup(id);
! 44: ret->nextHash = NULL;
! 45: return(ret);
! 46: }
! 47:
! 48: /*
! 49: * xmlFreeEntity : clean-up an entity record.
! 50: */
! 51:
! 52: void xmlFreeEntity(xmlEntityPtr entity) {
! 53: if (entity == NULL) return;
! 54:
! 55: entity->value = (CHAR) -1;
! 56: if (entity->id != NULL)
! 57: free((char *) entity->id);
! 58: }
! 59:
! 60: /*
! 61: * xmlAddEntity : register a new entity for this document (DTD ???).
! 62: */
! 63: void xmlAddEntity(xmlDocPtr doc, CHAR value, const CHAR *id) {
! 64: }
! 65:
! 66: /*
! 67: * xmlGetEntity : do an entity lookup in the hash table and
! 68: * returns the corrsponding CHAR, if found, zero otherwise.
! 69: */
! 70: CHAR xmlGetEntity(xmlDocPtr doc, const CHAR *id) {
! 71: }
! 72:
! 73: /*
! 74: * xmlSubstituteEntities : do a global entities lookup on a input string
! 75: * and returns a duplicate after the entities substitution.
! 76: */
! 77: CHAR *xmlSubstituteEntities(xmlDocPtr doc, const CHAR *input) {
! 78: }
! 79:
! 80: /*
! 81: * xmlCreateEntitiesHashTable : create and initialize an enmpty hash table
! 82: */
! 83: xmlEntitiesHashTablePtr xmlCreateEntitiesHashTable(void) {
! 84: xmlEntitiesHashTablePtr ret;
! 85: int i;
! 86:
! 87: ret = (xmlEntitiesHashTablePtr)
! 88: malloc(sizeof(xmlEntitiesHashTable));
! 89: if (ret == NULL) {
! 90: fprintf(stderr, "xmlCreateEntitiesHashTable : malloc(%d) failed\n",
! 91: sizeof(xmlEntitiesHashTable));
! 92: return(NULL);
! 93: }
! 94: for (i = 0;i < XML_NB_ENTITIES_HASH;i++)
! 95: ret->table[i] = NULL;
! 96: return(ret);
! 97: }
! 98:
! 99: /*
! 100: * xmlFreeEntitiesHashTable : clean up and free an entities hash table.
! 101: */
! 102: void xmlFreeEntitiesHashTable(xmlEntitiesHashTablePtr table) {
! 103: xmlEntityPtr cur, next;
! 104: int i;
! 105:
! 106: if (table == NULL) return;
! 107:
! 108: for (i = 0;i < XML_NB_ENTITIES_HASH;i++) {
! 109: cur = table->table[i];
! 110: while (cur != NULL) {
! 111: next = cur->nextHash;
! 112: xmlFreeEntity(cur);
! 113: cur = next;
! 114: }
! 115: table->table[i] = (void *) 0xdeadbeef;
! 116: }
! 117: free(table);
! 118: }
! 119:
Webmaster