23#define Realloc srealloc
37const char8 *DefaultTypeName[DT_enum_count] = {
46const char8 *ContentTypeName[CT_enum_count] = {
55const char8 *AttributeTypeName[AT_enum_count] = {
74const char8 *StandaloneDeclarationName[SDD_enum_count] = {
75 "unspecified",
"no",
"yes"
97 if(!(d = Malloc(
sizeof(*d))))
101 d->internal_part = 0;
102 d->external_part = 0;
104 d->parameter_entities = 0;
105 d->predefined_entities = 0;
135 FreeEntity(
dtd->internal_part);
136 FreeEntity(
dtd->external_part);
158 FreeElementDefinition(
elem);
167 FreeNotationDefinition(
not);
182Entity NewExternalEntityN(
const Char *name,
int namelen,
const char8 *publicid,
188 if(!(
e = Malloc(
sizeof(*
e))))
190 if(name && !(name = Strndup(name, namelen)))
193 e->type = ET_external;
196 e->encoding = CE_unknown;
200 e->publicid = publicid;
201 e->systemid = systemid;
202 e->notation = notation;
205 e->encoding_decl = CE_unknown;
206 e->standalone_decl = SDD_unspecified;
214Entity NewInternalEntityN(
const Char *name,
int namelen,
216 int line_offset,
int line1_char_offset,
217 int matches_parent_text)
221 if(!(
e = Malloc(
sizeof(*
e))))
224 if(!(name = Strndup(name, namelen)))
227 e->type = ET_internal;
230 e->encoding = InternalCharacterEncoding;
235 e->line_offset = line_offset;
236 e->line1_char_offset = line1_char_offset;
237 e->matches_parent_text = matches_parent_text;
249 Free((
void *)
e->name);
250 Free((
void *)
e->base_url);
251 Free((
void *)
e->url);
256 Free((
void *)
e->text);
259 Free((
void *)
e->systemid);
260 Free((
void *)
e->publicid);
261 Free((
void *)
e->version_decl);
262 Free((
void *)
e->ddb_filename);
269const char8 *EntityURL(
Entity e)
276 if(
e->type == ET_internal)
280 const char8 *url = EntityURL(
e->parent);
282 e->url = strdup8(url);
286 e->url = url_merge(
e->systemid,
287 e->parent ? EntityBaseURL(
e->parent) : 0,
297const char8 *EntityDescription(
Entity e)
302 if(
e->type == ET_external)
306 return EntityDescription(
e->parent);
311void EntitySetBaseURL(
Entity e,
const char8 *url)
316const char8 *EntityBaseURL(
Entity e)
321 if(
e->type == ET_internal)
324 return EntityBaseURL(
e->parent);
336 e->next =
dtd->parameter_entities;
337 dtd->parameter_entities =
e;
341 e->next =
dtd->entities;
353 for(
e =
dtd->predefined_entities;
e;
e =
e->next)
354 if(Strncmp(name,
e->name, namelen) == 0 &&
e->name[namelen] == 0)
358 for(
e =
pe ?
dtd->parameter_entities :
dtd->entities;
e;
e=
e->next)
359 if(Strncmp(name,
e->name, namelen) == 0 &&
e->name[namelen] == 0)
373 ContentType type,
Char *content)
385 e.doctype =
dtd->doctype;
389 if(type == CT_element || type == CT_mixed)
391 if(!(c = Malloc(
sizeof(*c))))
394 c->content = content;
395 c->next =
e.doctype->element_content;
396 e.doctype->element_content = c;
403 if(!(
e = Malloc(
sizeof(*
e))) || !(name = Strndup(name, namelen)))
408 e->namelen = namelen;
410 e->content = content;
412 e->next =
dtd->elements;
420 const Char *name,
int namelen)
429 e.doctype =
dtd->doctype;
433 e.elsum->omitStart |= 2;
438 if(!(
e = Malloc(
sizeof(*
e))) || !(name = Strndup(name, namelen)))
443 e->namelen = namelen;
447 e->next =
dtd->elements;
460 e->elsum->contentType = type;
461 e->elsum->omitStart &= ~2;
462 if(type == CT_element)
464 if(!(c = Malloc(
sizeof(*c))))
467 c->content = content;
468 c->next =
e->doctype->element_content;
469 e->doctype->element_content = c;
474 e->content = content;
497 e.doctype =
dtd->doctype;
501 e.namelen = Strlen(
e.name);
504 e.tentative = ((
e.elsum->omitStart & 2) != 0);
510 for(p = &
dtd->elements,
e = *p;
e; p = &
e->next,
e = *p)
511 if(namelen ==
e->namelen && *name == *
e->name &&
515 e->next =
dtd->elements;
537 Free((
void *)
e->name);
546 for(a =
e->attributes; a; a =
a1)
549 FreeAttributeDefinition(a);
567 AttributeType type,
Char **allowed_values,
568 DefaultType default_type,
const Char *default_value)
572 Char *
av = allowed_values ? allowed_values[0] : 0;
583 Free(allowed_values);
590 &element->elsum, element->name))) {
600 if(!(a= Malloc(
sizeof(*a))) || !(name = Strndup(name, namelen)))
604 a->namelen = namelen;
606 a->allowed_values = allowed_values;
607 a->default_type = default_type;
608 a->default_value = default_value;
609 a->next = element->attributes;
610 element->attributes = a;
617 const Char *name,
int namelen)
620 if(!element->doctype)
631 for(a = element->attributes; a; a = a->next)
632 if(namelen == a->namelen &&
633 memcmp(name, a->name, namelen *
sizeof(
Char)) == 0)
649 return element->attributes;
665 Free((
void *)a->name);
670 if(a->allowed_values)
671 Free(a->allowed_values[0]);
672 Free(a->allowed_values);
676 Free((
void *)a->default_value);
692 const char8 *publicid,
const char8 *systemid)
696 if(!(n = Malloc(
sizeof(*n))) || !(name = Strndup(name, namelen)))
701 n->systemid = systemid;
702 n->publicid = publicid;
703 n->next =
dtd->notations;
710 const Char *name,
int namelen)
714 if(!(n = Malloc(
sizeof(*n))) || !(name = Strndup(name, namelen)))
721 n->next =
dtd->notations;
728 const char8 *publicid,
const char8 *systemid)
731 n->systemid = systemid;
732 n->publicid = publicid;
741 for(n =
dtd->notations; n; n = n->next)
742 if(Strncmp(name, n->name, namelen) == 0 && n->name[namelen] == 0)
755 Free((
void *)n->name);
759 Free((
void *)n->systemid);
760 Free((
void *)n->publicid);