/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
*/
#include <stddef.h>
#ifdef COMPILED_FROM_DSP
#include "winconfig.h"
#elif defined(MACOS_CLASSIC)
#include "macconfig.h"
#elif defined(__amigaos__)
#include "amigaconfig.h"
#elif defined(__WATCOMC__)
#include "watcomconfig.h"
#else
#ifdef HAVE_EXPAT_CONFIG_H
#include <expat_config.h>
#endif
#endif /* ndef COMPILED_FROM_DSP */
#include "expat_external.h"
#include "internal.h"
#include "xmlrole.h"
#include "ascii.h"
/* Doesn't check:
that ,| are not mixed in a model group
content of literals
*/
static const char KW_ANY[] = {
static const char KW_ATTLIST[] = {
static const char KW_CDATA[] = {
static const char KW_DOCTYPE[] = {
static const char KW_ELEMENT[] = {
static const char KW_EMPTY[] = {
static const char KW_ENTITIES[] = {
'\0' };
static const char KW_ENTITY[] = {
static const char KW_FIXED[] = {
static const char KW_ID[] = {
static const char KW_IDREF[] = {
static const char KW_IDREFS[] = {
#ifdef XML_DTD
static const char KW_IGNORE[] = {
#endif
static const char KW_IMPLIED[] = {
#ifdef XML_DTD
static const char KW_INCLUDE[] = {
#endif
static const char KW_NDATA[] = {
static const char KW_NMTOKEN[] = {
static const char KW_NMTOKENS[] = {
'\0' };
static const char KW_NOTATION[] =
'\0' };
static const char KW_PCDATA[] = {
static const char KW_PUBLIC[] = {
static const char KW_REQUIRED[] = {
'\0' };
static const char KW_SYSTEM[] = {
#ifndef MIN_BYTES_PER_CHAR
#endif
#ifdef XML_DTD
? internalSubset \
: externalSubset1))
#else /* not XML_DTD */
#endif /* not XML_DTD */
int tok,
const char *ptr,
const char *end,
static PROLOG_HANDLER
#ifdef XML_DTD
#endif /* XML_DTD */
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_XML_DECL:
return XML_ROLE_XML_DECL;
case XML_TOK_PI:
return XML_ROLE_PI;
case XML_TOK_COMMENT:
return XML_ROLE_COMMENT;
case XML_TOK_BOM:
return XML_ROLE_NONE;
case XML_TOK_DECL_OPEN:
if (!XmlNameMatchesAscii(enc,
end,
break;
return XML_ROLE_DOCTYPE_NONE;
case XML_TOK_INSTANCE_START:
return XML_ROLE_INSTANCE_START;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_PI:
return XML_ROLE_PI;
case XML_TOK_COMMENT:
return XML_ROLE_COMMENT;
case XML_TOK_BOM:
return XML_ROLE_NONE;
case XML_TOK_DECL_OPEN:
if (!XmlNameMatchesAscii(enc,
end,
break;
return XML_ROLE_DOCTYPE_NONE;
case XML_TOK_INSTANCE_START:
return XML_ROLE_INSTANCE_START;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_PI:
return XML_ROLE_PI;
case XML_TOK_COMMENT:
return XML_ROLE_COMMENT;
case XML_TOK_INSTANCE_START:
return XML_ROLE_INSTANCE_START;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_DOCTYPE_NONE;
case XML_TOK_NAME:
case XML_TOK_PREFIXED_NAME:
return XML_ROLE_DOCTYPE_NAME;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_DOCTYPE_NONE;
case XML_TOK_OPEN_BRACKET:
return XML_ROLE_DOCTYPE_INTERNAL_SUBSET;
case XML_TOK_DECL_CLOSE:
return XML_ROLE_DOCTYPE_CLOSE;
case XML_TOK_NAME:
return XML_ROLE_DOCTYPE_NONE;
}
return XML_ROLE_DOCTYPE_NONE;
}
break;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_DOCTYPE_NONE;
case XML_TOK_LITERAL:
return XML_ROLE_DOCTYPE_PUBLIC_ID;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_DOCTYPE_NONE;
case XML_TOK_LITERAL:
return XML_ROLE_DOCTYPE_SYSTEM_ID;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_DOCTYPE_NONE;
case XML_TOK_OPEN_BRACKET:
return XML_ROLE_DOCTYPE_INTERNAL_SUBSET;
case XML_TOK_DECL_CLOSE:
return XML_ROLE_DOCTYPE_CLOSE;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_DOCTYPE_NONE;
case XML_TOK_DECL_CLOSE:
return XML_ROLE_DOCTYPE_CLOSE;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_DECL_OPEN:
if (XmlNameMatchesAscii(enc,
end,
KW_ENTITY)) {
return XML_ROLE_ENTITY_NONE;
}
if (XmlNameMatchesAscii(enc,
end,
KW_ATTLIST)) {
return XML_ROLE_ATTLIST_NONE;
}
if (XmlNameMatchesAscii(enc,
end,
KW_ELEMENT)) {
return XML_ROLE_ELEMENT_NONE;
}
if (XmlNameMatchesAscii(enc,
end,
KW_NOTATION)) {
return XML_ROLE_NOTATION_NONE;
}
break;
case XML_TOK_PI:
return XML_ROLE_PI;
case XML_TOK_COMMENT:
return XML_ROLE_COMMENT;
case XML_TOK_PARAM_ENTITY_REF:
return XML_ROLE_PARAM_ENTITY_REF;
case XML_TOK_CLOSE_BRACKET:
return XML_ROLE_DOCTYPE_NONE;
case XML_TOK_NONE:
return XML_ROLE_NONE;
}
}
#ifdef XML_DTD
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
if (tok == XML_TOK_XML_DECL)
return XML_ROLE_TEXT_DECL;
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_COND_SECT_OPEN:
return XML_ROLE_NONE;
case XML_TOK_COND_SECT_CLOSE:
if (state->includeLevel == 0)
break;
return XML_ROLE_NONE;
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_CLOSE_BRACKET:
break;
case XML_TOK_NONE:
if (state->includeLevel)
break;
return XML_ROLE_NONE;
default:
}
}
#endif /* XML_DTD */
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ENTITY_NONE;
case XML_TOK_PERCENT:
return XML_ROLE_ENTITY_NONE;
case XML_TOK_NAME:
return XML_ROLE_GENERAL_ENTITY_NAME;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ENTITY_NONE;
case XML_TOK_NAME:
return XML_ROLE_PARAM_ENTITY_NAME;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ENTITY_NONE;
case XML_TOK_NAME:
return XML_ROLE_ENTITY_NONE;
}
return XML_ROLE_ENTITY_NONE;
}
break;
case XML_TOK_LITERAL:
return XML_ROLE_ENTITY_VALUE;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ENTITY_NONE;
case XML_TOK_LITERAL:
return XML_ROLE_ENTITY_PUBLIC_ID;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ENTITY_NONE;
case XML_TOK_LITERAL:
return XML_ROLE_ENTITY_SYSTEM_ID;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ENTITY_NONE;
case XML_TOK_DECL_CLOSE:
return XML_ROLE_ENTITY_COMPLETE;
case XML_TOK_NAME:
return XML_ROLE_ENTITY_NONE;
}
break;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ENTITY_NONE;
case XML_TOK_NAME:
return XML_ROLE_ENTITY_NOTATION_NAME;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ENTITY_NONE;
case XML_TOK_NAME:
return XML_ROLE_ENTITY_NONE;
}
return XML_ROLE_ENTITY_NONE;
}
break;
case XML_TOK_LITERAL:
return XML_ROLE_ENTITY_VALUE;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ENTITY_NONE;
case XML_TOK_LITERAL:
return XML_ROLE_ENTITY_PUBLIC_ID;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ENTITY_NONE;
case XML_TOK_LITERAL:
return XML_ROLE_ENTITY_SYSTEM_ID;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ENTITY_NONE;
case XML_TOK_DECL_CLOSE:
return XML_ROLE_ENTITY_COMPLETE;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NOTATION_NONE;
case XML_TOK_NAME:
return XML_ROLE_NOTATION_NAME;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NOTATION_NONE;
case XML_TOK_NAME:
return XML_ROLE_NOTATION_NONE;
}
return XML_ROLE_NOTATION_NONE;
}
break;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NOTATION_NONE;
case XML_TOK_LITERAL:
return XML_ROLE_NOTATION_PUBLIC_ID;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NOTATION_NONE;
case XML_TOK_LITERAL:
return XML_ROLE_NOTATION_SYSTEM_ID;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NOTATION_NONE;
case XML_TOK_LITERAL:
return XML_ROLE_NOTATION_SYSTEM_ID;
case XML_TOK_DECL_CLOSE:
return XML_ROLE_NOTATION_NO_SYSTEM_ID;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ATTLIST_NONE;
case XML_TOK_NAME:
case XML_TOK_PREFIXED_NAME:
return XML_ROLE_ATTLIST_ELEMENT_NAME;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ATTLIST_NONE;
case XML_TOK_DECL_CLOSE:
return XML_ROLE_ATTLIST_NONE;
case XML_TOK_NAME:
case XML_TOK_PREFIXED_NAME:
return XML_ROLE_ATTRIBUTE_NAME;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ATTLIST_NONE;
case XML_TOK_NAME:
{
static const char * const types[] = {
};
int i;
return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i;
}
}
return XML_ROLE_ATTLIST_NONE;
}
break;
case XML_TOK_OPEN_PAREN:
return XML_ROLE_ATTLIST_NONE;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ATTLIST_NONE;
case XML_TOK_NMTOKEN:
case XML_TOK_NAME:
case XML_TOK_PREFIXED_NAME:
return XML_ROLE_ATTRIBUTE_ENUM_VALUE;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ATTLIST_NONE;
case XML_TOK_CLOSE_PAREN:
return XML_ROLE_ATTLIST_NONE;
case XML_TOK_OR:
return XML_ROLE_ATTLIST_NONE;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ATTLIST_NONE;
case XML_TOK_OPEN_PAREN:
return XML_ROLE_ATTLIST_NONE;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ATTLIST_NONE;
case XML_TOK_NAME:
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ATTLIST_NONE;
case XML_TOK_CLOSE_PAREN:
return XML_ROLE_ATTLIST_NONE;
case XML_TOK_OR:
return XML_ROLE_ATTLIST_NONE;
}
}
/* default value */
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ATTLIST_NONE;
case XML_TOK_POUND_NAME:
if (XmlNameMatchesAscii(enc,
end,
KW_IMPLIED)) {
return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE;
}
if (XmlNameMatchesAscii(enc,
end,
KW_REQUIRED)) {
}
if (XmlNameMatchesAscii(enc,
end,
KW_FIXED)) {
return XML_ROLE_ATTLIST_NONE;
}
break;
case XML_TOK_LITERAL:
return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ATTLIST_NONE;
case XML_TOK_LITERAL:
return XML_ROLE_FIXED_ATTRIBUTE_VALUE;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ELEMENT_NONE;
case XML_TOK_NAME:
case XML_TOK_PREFIXED_NAME:
return XML_ROLE_ELEMENT_NAME;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ELEMENT_NONE;
case XML_TOK_NAME:
return XML_ROLE_CONTENT_EMPTY;
}
return XML_ROLE_CONTENT_ANY;
}
break;
case XML_TOK_OPEN_PAREN:
return XML_ROLE_GROUP_OPEN;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ELEMENT_NONE;
case XML_TOK_POUND_NAME:
if (XmlNameMatchesAscii(enc,
end,
KW_PCDATA)) {
return XML_ROLE_CONTENT_PCDATA;
}
break;
case XML_TOK_OPEN_PAREN:
return XML_ROLE_GROUP_OPEN;
case XML_TOK_NAME:
case XML_TOK_PREFIXED_NAME:
return XML_ROLE_CONTENT_ELEMENT;
case XML_TOK_NAME_QUESTION:
return XML_ROLE_CONTENT_ELEMENT_OPT;
case XML_TOK_NAME_ASTERISK:
return XML_ROLE_CONTENT_ELEMENT_REP;
case XML_TOK_NAME_PLUS:
return XML_ROLE_CONTENT_ELEMENT_PLUS;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ELEMENT_NONE;
case XML_TOK_CLOSE_PAREN:
return XML_ROLE_GROUP_CLOSE;
return XML_ROLE_GROUP_CLOSE_REP;
case XML_TOK_OR:
return XML_ROLE_ELEMENT_NONE;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ELEMENT_NONE;
case XML_TOK_NAME:
case XML_TOK_PREFIXED_NAME:
return XML_ROLE_CONTENT_ELEMENT;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ELEMENT_NONE;
return XML_ROLE_GROUP_CLOSE_REP;
case XML_TOK_OR:
return XML_ROLE_ELEMENT_NONE;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ELEMENT_NONE;
case XML_TOK_OPEN_PAREN:
return XML_ROLE_GROUP_OPEN;
case XML_TOK_NAME:
case XML_TOK_PREFIXED_NAME:
return XML_ROLE_CONTENT_ELEMENT;
case XML_TOK_NAME_QUESTION:
return XML_ROLE_CONTENT_ELEMENT_OPT;
case XML_TOK_NAME_ASTERISK:
return XML_ROLE_CONTENT_ELEMENT_REP;
case XML_TOK_NAME_PLUS:
return XML_ROLE_CONTENT_ELEMENT_PLUS;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_ELEMENT_NONE;
case XML_TOK_CLOSE_PAREN:
}
return XML_ROLE_GROUP_CLOSE;
}
return XML_ROLE_GROUP_CLOSE_REP;
}
return XML_ROLE_GROUP_CLOSE_OPT;
case XML_TOK_CLOSE_PAREN_PLUS:
}
return XML_ROLE_GROUP_CLOSE_PLUS;
case XML_TOK_COMMA:
return XML_ROLE_GROUP_SEQUENCE;
case XML_TOK_OR:
return XML_ROLE_GROUP_CHOICE;
}
}
#ifdef XML_DTD
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_NAME:
return XML_ROLE_NONE;
}
return XML_ROLE_NONE;
}
break;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_OPEN_BRACKET:
return XML_ROLE_NONE;
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_OPEN_BRACKET:
return XML_ROLE_IGNORE_SECT;
}
}
#endif /* XML_DTD */
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
switch (tok) {
case XML_TOK_PROLOG_S:
case XML_TOK_DECL_CLOSE:
}
}
static int PTRCALL
int tok,
const char *ptr,
const char *end,
{
return XML_ROLE_NONE;
}
static int FASTCALL
{
#ifdef XML_DTD
return XML_ROLE_INNER_PARAM_ENTITY_REF;
#endif
return XML_ROLE_ERROR;
}
void
{
#ifdef XML_DTD
state->includeLevel = 0;
state->inEntityValue = 0;
#endif /* XML_DTD */
}
#ifdef XML_DTD
void
{
state->documentEntity = 0;
state->includeLevel = 0;
}
#endif /* XML_DTD */