Hash :
39a1f9a3
Author :
Date :
1999-01-17T19:11:59
Speed, conformance testing, more parsing, general improvements, Daniel.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
/*
* valid.c : part of the code use to do the DTD handling and the validity
* checking
*
* See Copyright for the status of this software.
*
* Daniel.Veillard@w3.org
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "valid.h"
#include "parser.h"
/****************************************************************
* *
* Util functions for data allocation/deallocation *
* *
****************************************************************/
/**
* xmlNewElementContent:
* @name: the subelement name or NULL
* @type: the type of element content decl
*
* Allocate an element content structure.
*
* return values: NULL if not, othervise the new element content structure
*/
xmlElementContentPtr
xmlNewElementContent(CHAR *name, int type) {
xmlElementContentPtr ret;
switch(type) {
case XML_ELEMENT_CONTENT_ELEMENT:
if (name == NULL) {
fprintf(stderr, "xmlNewElementContent : name == NULL !\n");
}
break;
case XML_ELEMENT_CONTENT_PCDATA:
case XML_ELEMENT_CONTENT_SEQ:
case XML_ELEMENT_CONTENT_OR:
if (name != NULL) {
fprintf(stderr, "xmlNewElementContent : name != NULL !\n");
}
break;
default:
fprintf(stderr, "xmlNewElementContent: unknown type %d\n", type);
exit(1);
}
ret = (xmlElementContentPtr) malloc(sizeof(xmlElementContent));
if (ret == NULL) {
fprintf(stderr, "xmlNewElementContent : out of memory!\n");
return(NULL);
}
ret->type = type;
ret->ocur = XML_ELEMENT_CONTENT_ONCE;
ret->name = xmlStrdup(name);
return(ret);
}
/**
* xmlNewElementContent:
* @name: the subelement name or NULL
* @type: the type of element content decl
*
* Free an element content structure. This is a recursive call !
*/
void
xmlFreeElementContent(xmlElementContentPtr cur) {
/* TODO !!! */
}
/****************************************************************
* *
* Registration of DTD declarations *
* *
****************************************************************/
/**
* xmlAddElementDecl:
* @name: the entity name
*
* Register a new element declaration
*
* return values: NULL if not, othervise the entity
*/
xmlElementPtr
xmlAddElementDecl(xmlDtdPtr dtd, char *name, int type,
xmlElementContentPtr content) {
xmlElementPtr ret;
if (dtd == NULL) {
fprintf(stderr, "xmlAddElementDecl: dtd == NULL\n");
return(NULL);
}
if (name == NULL) {
fprintf(stderr, "xmlAddElementDecl: name == NULL\n");
return(NULL);
}
switch (type) {
case XML_ELEMENT_TYPE_EMPTY:
if (content != NULL) {
fprintf(stderr,
"xmlAddElementDecl: content != NULL for EMPTY\n");
return(NULL);
}
break;
case XML_ELEMENT_TYPE_ANY:
if (content != NULL) {
fprintf(stderr,
"xmlAddElementDecl: content != NULL for ANY\n");
return(NULL);
}
break;
case XML_ELEMENT_TYPE_MIXED:
if (content == NULL) {
fprintf(stderr,
"xmlAddElementDecl: content == NULL for MIXED\n");
return(NULL);
}
break;
case XML_ELEMENT_TYPE_ELEMENT:
if (content == NULL) {
fprintf(stderr,
"xmlAddElementDecl: content == NULL for ELEMENT\n");
return(NULL);
}
break;
default:
fprintf(stderr, "xmlAddElementDecl: unknown type %d\n", type);
return(NULL);
}
/*
* Validity Check:
* Search the DTD for previous declarations of the ELEMENT
*/
/* TODO */
/*
* Create and fill the structure.
*/
ret = (xmlElementPtr) malloc(sizeof(xmlElement));
if (ret == NULL) {
fprintf(stderr, "xmlAddElementDecl: out of memory\n");
return(NULL);
}
ret->type = type;
ret->name = xmlStrdup(name);
ret->content = content;
/*
* Insert the structure in the DTD Element table
*/
/* TODO */
return(ret);
}