19 #include "lt-memory.h" 23 #define Realloc srealloc 75 "unspecified",
"no",
"yes" 78 static Char *Strndup(
const Char *old,
int len)
80 Char *
new =
Malloc((len+1) *
sizeof(Char));
85 memcpy(
new, old, len *
sizeof(Char));
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;
122 ElementDefinition elem, elem1;
124 NotationDefinition not, not1;
131 Free((Char *)dtd->name);
138 for(ent = dtd->entities; ent; ent = ent1)
144 for(ent = dtd->parameter_entities; ent; ent = ent1)
155 for(elem = dtd->elements; elem; elem = elem1)
164 for(not = dtd->notations; not; not = not1)
183 const char8 *systemid, NotationDefinition notation,
188 if(!(e =
Malloc(
sizeof(*e))))
190 if(name && !(name = Strndup(name, namelen))) {
202 e->publicid = publicid;
203 e->systemid = systemid;
204 e->notation = notation;
217 const Char *text, Entity
parent,
218 int line_offset,
int line1_char_offset,
219 int matches_parent_text)
223 if(!(e =
Malloc(
sizeof(*e))))
227 if(!(name = Strndup(name, namelen))) {
241 e->line_offset = line_offset;
242 e->line1_char_offset = line1_char_offset;
243 e->matches_parent_text = matches_parent_text;
255 Free((
void *)e->name);
256 Free((
void *)e->base_url);
257 Free((
void *)e->url);
262 Free((
void *)e->text);
265 Free((
void *)e->systemid);
266 Free((
void *)e->publicid);
267 Free((
void *)e->version_decl);
268 Free((
void *)e->ddb_filename);
342 e->next = dtd->parameter_entities;
343 dtd->parameter_entities = e;
347 e->next = dtd->entities;
359 for(e = dtd->predefined_entities; e; e = e->next)
360 if(
Strncmp(name, e->name, namelen) == 0 && e->name[namelen] == 0)
364 for(e = pe ? dtd->parameter_entities : dtd->entities; e; e=e->next)
365 if(
Strncmp(name, e->name, namelen) == 0 && e->name[namelen] == 0)
384 struct element_content *c;
386 if (!(entry = DeclareElement(dtd->doctype, name, namelen, 0,
391 e.doctype = dtd->doctype;
392 e.
name = (Char *)dtd->doctype->elements+entry->keyptr;
393 e.elsum = (NSL_ElementSummary_I *)(dtd->doctype->permanentBase+entry->eval);
397 if(!(c =
Malloc(
sizeof(*c))))
401 c->next = e.doctype->element_content;
402 e.doctype->element_content = c;
409 if(!(e =
Malloc(
sizeof(*e))) )
412 if(!(name = Strndup(name, namelen))) {
419 e->namelen = namelen;
421 e->content = content;
423 e->next = dtd->elements;
431 const Char *name,
int namelen)
437 if (!(entry = DeclareElement(dtd->doctype, name, namelen, 0, (ctVals)
CT_any))) {
440 e.doctype = dtd->doctype;
441 e.
name = (Char *)dtd->doctype->elements+entry->keyptr;
442 e.elsum = (NSL_ElementSummary_I *)(dtd->doctype->permanentBase+entry->eval);
444 e.elsum->omitStart |= 2;
449 if(!(e =
Malloc(
sizeof(*e))) )
452 if(!(name = Strndup(name, namelen))) {
463 e->next = dtd->elements;
474 struct element_content *c;
476 e->elsum->contentType = type;
477 e->elsum->omitStart &= ~2;
480 if(!(c =
Malloc(
sizeof(*c))))
483 c->content = content;
484 c->next = e->doctype->element_content;
485 e->doctype->element_content = c;
490 e->content = content;
502 NSL_ElementSummary_I *elsum;
507 entry = rsearch(name, namelen, dtd->doctype->elements);
511 elsum = (NSL_ElementSummary_I *)(dtd->doctype->permanentBase+entry->eval);
513 e.doctype = dtd->doctype;
514 e.
name = (Char *)dtd->doctype->elements+entry->keyptr;
520 e.
tentative = ((e.elsum->omitStart & 2) != 0);
524 ElementDefinition e, *p;
526 for(p = &dtd->elements, e = *p; e; p = &e->next, e = *p)
527 if(namelen == e->namelen && *name == *e->name &&
528 memcmp(name, e->name, namelen*
sizeof(Char)) == 0)
531 e->
next = dtd->elements;
545 AttributeDefinition a, a1;
553 Free((
void *)e->name);
562 for(a = e->attributes; a; a = a1)
588 Char *av = allowed_values ? allowed_values[0] : 0;
590 NSL_Doctype_I *doctype = element->doctype;
597 for(avp = allowed_values; *avp; avp++)
599 Free(allowed_values);
602 if (!(name = DeclareAttr(doctype, name, namelen,
603 (NSL_Attr_Declared_Value)type,
605 (NSL_ADefType)default_type, default_value,
606 &element->elsum, element->name))) {
610 return (AttributeDefinition)FindAttrSpec(element->elsum,
614 AttributeDefinition a;
616 if(!(a =
Malloc(
sizeof(*a))) )
619 if(!(name = Strndup(name, namelen))) {
627 a->allowed_values = allowed_values;
629 a->default_value = default_value;
630 a->next = element->attributes;
631 element->attributes = a;
641 if(!element->doctype)
644 if(!(name = AttrUniqueName(element->doctype, name, namelen)))
646 return (AttributeDefinition)FindAttrSpec(element->elsum,
650 AttributeDefinition a;
652 for(a = element->attributes; a; a = a->next)
653 if(namelen == a->namelen &&
654 memcmp(name, a->name, namelen *
sizeof(Char)) == 0)
662 AttributeDefinition previous)
668 return previous->next;
670 return element->attributes;
686 Free((
void *)a->name);
691 if(a->allowed_values)
692 Free(a->allowed_values[0]);
693 Free(a->allowed_values);
697 Free((
void *)a->default_value);
715 NotationDefinition n;
717 if(!(n =
Malloc(
sizeof(*n))) )
720 if(!(name = Strndup(name, namelen))) {
727 n->systemid = systemid;
728 n->publicid = publicid;
729 n->next = dtd->notations;
738 NotationDefinition n;
740 if(!(n =
Malloc(
sizeof(*n))) )
743 if(!(name = Strndup(name, namelen))) {
752 n->next = dtd->notations;
762 n->systemid = systemid;
763 n->publicid = publicid;
770 NotationDefinition n;
772 for(n = dtd->notations; n; n = n->next)
773 if(
Strncmp(name, n->name, namelen) == 0 && n->name[namelen] == 0)
786 Free((
void *)n->name);
790 Free((
void *)n->systemid);
791 Free((
void *)n->publicid);
Entity NewInternalEntityN(const Char *name, int namelen, const Char *text, Entity parent, int line_offset, int line1_char_offset, int matches_parent_text)
const char8 * StandaloneDeclarationName[SDD_enum_count]
Entity FindEntityN(Dtd dtd, const Char *name, int namelen, int pe)
void FreeAttributeDefinition(AttributeDefinition a)
void FreeNotationDefinition(NotationDefinition n)
void FreeElementDefinition(ElementDefinition e)
NotationDefinition FindNotationN(Dtd dtd, const Char *name, int namelen)
ElementDefinition FindElementN(Dtd dtd, const Char *name, int namelen)
const char8 * EntityBaseURL(Entity e)
void EntitySetBaseURL(Entity e, const char8 *url)
STD_API char8 *EXPRT url_merge(const char8 *url, const char8 *base, char8 **scheme, char8 **host, int *port, char8 **path)
enum attribute_type AttributeType
STD_API CharacterEncoding InternalCharacterEncoding
ElementDefinition TentativelyDefineElementN(Dtd dtd, const Char *name, int namelen)
AttributeDefinition FindAttributeN(ElementDefinition element, const Char *name, int namelen)
enum content_type ContentType
AttributeDefinition DefineAttributeN(ElementDefinition element, const Char *name, int namelen, AttributeType type, Char **allowed_values, DefaultType default_type, const Char *default_value)
struct element_definition * next
enum default_type DefaultType
const char8 * AttributeTypeName[AT_enum_count]
const char8 * DefaultTypeName[DT_enum_count]
Entity NewExternalEntityN(const Char *name, int namelen, const char8 *publicid, const char8 *systemid, NotationDefinition notation, Entity parent)
NotationDefinition RedefineNotation(NotationDefinition n, const char8 *publicid, const char8 *systemid)
const char8 * EntityURL(Entity e)
NotationDefinition DefineNotationN(Dtd dtd, const Char *name, int namelen, const char8 *publicid, const char8 *systemid)
Entity DefineEntity(Dtd dtd, Entity e, int pe)
NotationDefinition TentativelyDefineNotationN(Dtd dtd, const Char *name, int namelen)
const char8 * EntityDescription(Entity e)
void FreeEntity(Entity e)
STD_API char8 * strdup8(const char8 *s)
EST_Item * parent(const EST_Item *n)
return parent of n
ElementDefinition DefineElementN(Dtd dtd, const Char *name, int namelen, ContentType type, Char *content)
AttributeDefinition NextAttributeDefinition(ElementDefinition element, AttributeDefinition previous)
const char8 * ContentTypeName[CT_enum_count]
ElementDefinition RedefineElement(ElementDefinition e, ContentType type, Char *content)