| top | |
static int notStandaloneHandler(ptr userData) {
return 1;
}
| ^ | Definition continued at: 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34. | | | | | section top | |
static void startElement(ptr userData,const XML_Char *name,const XML_Char **att) {
pTclContext c = userData; XML_Parser p = c->parser;
int idoff = XML_GetIdAttributeIndex(p);
int speclen = XML_GetSpecifiedAttributeCount(p);
Obj defaulted = 0;
Obj *ppending; int npending;
Obj piece = 0;
piece = pairstr(piece,"%what","start",-1);
piece = pairobj(piece,"%name",normaliseNamespacedName(name));
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
piece = pairIndex(piece,c); pushIndex(c);
for (; *att; att+=2,idoff-=2,speclen-=2) {
if (idoff==0) piece = pairobj(piece,"%id",normaliseNamespacedName(*att));
if (speclen<=0) {
if (!defaulted) defaulted = incr(Tcl_NewObj());
Tcl_ListObjAppendElement(0,defaulted,normaliseNamespacedName(*att));
}
if (streq((chars)(att[0]),"http://www.w3.org/XML/1998/namespace~base") || streq((chars)(att[0]),"xml:base")) {
piece = pairstr(piece,"%base",att[1],-1);
}
if (speclen==0) piece = pairint(piece,"%specified",0);
if (!piece) piece = incr(Tcl_NewObj());
Tcl_ListObjAppendElement(0,piece,normaliseNamespacedName(att[0]));
Tcl_ListObjAppendElement(0,piece,Tcl_NewStringObj(att[1],-1));
}
if (defaulted) {
piece = pairobj(piece,"%defaulted",defaulted);
decr(defaulted);
}
if (c->pendingNamespace) {
if (Tcl_ListObjGetElements(0,c->pendingNamespace,&npending,&ppending)==TCL_OK) {
for (; npending>0; npending-=2,ppending+=2) {
int n; chars s = Tcl_GetStringFromObj(ppending[0],&n);
static char xmlns[] = "%%xmlns.%s";
chars S = nheap(n+sizeof xmlns,char);
sprintf(S,xmlns,s);
piece = pairobj(piece,S,ppending[1]);
dispose(S);
}
}
decr(c->pendingNamespace); c->pendingNamespace = 0;
}
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
}
static void endElement(ptr userData,const XML_Char *name) {
pTclContext c = userData; XML_Parser p = c->parser;
Obj piece = 0;
piece = pairstr(piece,"%what","end",-1);
piece = pairobj(piece,"%name",normaliseNamespacedName(name));
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
popIndex(c); piece = pairIndex(piece,c); incrIndex(c);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
}
| ^ | Definition continued at: 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34. | | | | | section top | |
static void characterData(ptr userData,const XML_Char *s,int n) {
pTclContext c = userData; XML_Parser p = c->parser;
int o,m,l; chars t = XML_GetInputContext(p,&o,&m),T; bool entity = false;
Obj piece = 0;
t += o; m -= o;
if (c->cdata==0 && *t=='&' && m>2) {
for (T=t,l=0; m>0 && !entity; m--,T++,l++) entity = *T==';';
}
piece = pairstr(piece,"%what","content",-1);
piece = pairstr(piece,"%data",s,n);
if (entity) piece = pairstr(piece,"%entity",t,l);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
piece = pairIndex(piece,c); incrIndex(c);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
}
| ^ | Definition continued at: 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34. | | | | | section top | |
static void processingInstruction(ptr userData,const XML_Char *target,const XML_Char *data) {
pTclContext c = userData; XML_Parser p = c->parser;
Obj piece = 0;
piece = pairstr(piece,"%what","pi",-1);
piece = pairstr(piece,"%target",target,-1);
piece = pairstr(piece,"%data",data,-1);
piece = pairIndex(piece,c); incrIndex(c);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
}
| ^ | | | | | | section top | |
static void comment(ptr userData,const XML_Char *data) {
pTclContext c = userData; XML_Parser p = c->parser;
Obj piece = 0;
piece = pairstr(piece,"%what","comment",-1);
piece = pairstr(piece,"%data",data,-1);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
piece = pairIndex(piece,c); incrIndex(c);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
}
| ^ | | | | | | section top | |
static void startCdataSection(ptr userData) {
pTclContext c = userData; XML_Parser p = c->parser;
Obj piece = 0;
piece = pairstr(piece,"%what","cdata-begin",-1);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
piece = pairIndex(piece,c); pushIndex(c);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
c->cdata += 1;
}
static void endCdataSection(ptr userData) {
pTclContext c = userData; XML_Parser p = c->parser;
Obj piece = 0;
piece = pairstr(piece,"%what","cdata-end",-1);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
popIndex(c); piece = pairIndex(piece,c); incrIndex(c);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
c->cdata -= 1;
}
| ^ | | | | | | section top | |
static void startNamespaceDecl(ptr userData,const XML_Char *prefix,const XML_Char *uri) {
pTclContext c = userData; XML_Parser p = c->parser;
Obj piece = 0;
piece = pairstr(piece,"%what","namespace-begin",-1);
piece = pairstr(piece,"%prefix",prefix?prefix:"",-1);
piece = pairstr(piece,"%uri",uri?uri:"",-1);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
piece = pairIndex(piece,c); incrIndex(c);
c->pendingNamespace = pairstr(c->pendingNamespace,prefix,uri,-1);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
}
static void endNamespaceDecl(ptr userData,const XML_Char *prefix) {
pTclContext c = userData; XML_Parser p = c->parser;
Obj piece = 0;
piece = pairstr(piece,"%what","namespace-end",-1);
piece = pairstr(piece,"%prefix",prefix?prefix:"",-1);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
piece = pairIndex(piece,c); incrIndex(c);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
}
| ^ | | | | | | section top | |
static void xmlDecl(ptr userData,const XML_Char *version,const XML_Char *encoding,int standalone) {
pTclContext c = userData; XML_Parser p = c->parser;
Obj piece = 0;
piece = pairstr(piece,"%what",version?"xml":"text",-1);
piece = pairstr(piece,"%version",version,-1);
piece = pairstr(piece,"%encoding",encoding,-1);
if (standalone>=0) piece = pairint(piece,"%standalone",standalone);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
piece = pairIndex(piece,c); incrIndex(c);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
}
| ^ | | | | | | section top | |
static void startDoctypeDecl(ptr userData,
const XML_Char *doctypeName,
const XML_Char *systemId,
const XML_Char *publicId,
int has_internal_subset)
{
pTclContext c = userData; XML_Parser p = c->parser;
Obj piece = 0;
piece = pairstr(piece,"%what","doctype-begin",-1);
piece = pairstr(piece,"%name",doctypeName,-1);
piece = pairstr(piece,"%system",systemId,-1);
piece = pairstr(piece,"%public",publicId,-1);
piece = pairint(piece,"%internal",has_internal_subset);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
piece = pairIndex(piece,c); pushIndex(c);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
}
static void endDoctypeDecl(ptr userData) {
pTclContext c = userData; XML_Parser p = c->parser;
Obj piece = 0;
piece = pairstr(piece,"%what","doctype-end",-1);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
popIndex(c); piece = pairIndex(piece,c); incrIndex(c);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
}
| ^ | | | | | | section top | |
typedef struct Fsm Fsm,*pFsm;
struct Fsm {
pFsm all,next,also;
chars trace,name;
bool epsilon,marked,cons,top;
int number;
};
static pFsm fsm(chars trace,chars name,pFsm next,pFsm also,pFsm *all) {
pFsm fsm = heap(Fsm);
fsm->all = (*all); (*all) = fsm;
fsm->trace = trace; fsm->name = name; fsm->next = next; fsm->also = also;
fsm->epsilon = false; fsm->marked = false; fsm->cons = false; fsm->top = true;
fsm->number = -1;
return fsm;
}
static void freeFsms(pFsm *all) {
while ((*all)) {
pFsm a = (*all)->all; dispose((*all)); (*all) = a;
}
}
static void join(chars trace,pFsm from,pFsm to,pFsm *all) {
pFsm p;
for (p=from; p; p=p->also) if (p->next==to) return;
if (from->next) {
from->also = fsm(trace,0,to,from->also,all);
from->also->top = false;
}else
from->next = to;
}
static void dumpfsm(chars label,pFsm *all) {
pFsm x,p; fprintf(stderr,"%s:\n",label);
for (x=(*all); x; x=x->all) {
if (!x->top) continue;
fprintf(stderr," %p %s\n",x,x->name?x->name:"#MISSING");
for (p=x; p; p=p->also) {
fprintf(stderr," %p (%s) %s%s%s",
p->next,p->trace,!p->next?"#null":p->next->name?p->next->name:"#MISSING",
p->epsilon?" epsilon":"",
p->cons?" cons":"");
if (p->number>=0) fprintf(stderr," number=%d",p->number);
fprintf(stderr,"\n");
}
}
}
static void epsilonMark(pFsm x,pFsm *all) {
pFsm p = x;
if (!x || x->marked) return;
while (p) {
if (p->epsilon) {
p = p->also;
}else if (p->next==x && !x->name) {
p->epsilon = true;
p = p->also;
}else if (p->next==0) {
p->epsilon = true;
p = p->also;
}else if (!p->next->name) {
pFsm q;
p->epsilon = true;
for (q=p->next; q; q=q->also) {
if (!q->epsilon) join("copy",x,q->next,all);
}
p = x;
}else {
p = p->also;
}
}
x->marked = true;
if (!x->name) x->name = "#MISSING";
for (p=x; p; p=p->also) {
if (!p->epsilon) {
epsilonMark(p->next,all);
}
}
}
static void fsmNumber(pFsm x,int *N,pFsm *all) {
if (!x || x->number>=0) {
;
}else if (x->next==0 && x->also==0) {
x->number = -1;
}else {
pFsm p; x->number = *N; *N += 1;
for (p=x; p; p=p->also) if (!p->epsilon) fsmNumber(p->next,N,all);
}
}
static void fsmConstruct(pFsm x,Obj L,pFsm *all) {
if (!x || x->cons) {
;
}else if (x->next==0 && x->also==0) {
x->cons = true;
}else {
pFsm p; Obj S = incr(Tcl_NewObj());
x->cons = true;
for (p=x; p; p=p->also) {
if (!p->epsilon) {
S = pairint(S,p->next->name,p->next->number);
}
}
Tcl_ListObjAppendElement(0,L,S); decr(S);
for (p=x; p; p=p->also) {
if (!p->epsilon) {
fsmConstruct(p->next,L,all);
}
}
}
}
static Obj xmlContent(XML_Content *model,Obj *display,pFsm *begin,pFsm *end,pFsm *all) {
if (model) {
Obj P[4],L; int i;
static chars type[] = {"","empty","any","mixed","name","choice","seq"};
static chars quant[] = {"none","opt","rep","plus"};
chars sep = ""; pFsm last;
P[0] = Tcl_NewStringObj(type[model->type],-1);
P[1] = Tcl_NewStringObj(quant[model->quant],-1);
P[2] = Tcl_NewStringObj(model->name?model->name:"",-1);
P[3] = 0;
L = Tcl_NewListObj(3,P);
*end = fsm("end",0,0,0,all);
switch (model->type) {
case XML_CTYPE_ANY:
*display = incr(Tcl_NewStringObj("ANY",-1));
*begin = fsm("#any","#ANY",*end,0,all);
join("any b->e",*begin,*end,all);
join("any e->b",*end,*begin,all);
break;
case XML_CTYPE_NAME:
*display = incr(Tcl_NewStringObj(model->name?model->name:"",-1));
*begin = fsm("name begin",0,fsm("name",model->name,*end,0,all),0,all);
break;
case XML_CTYPE_MIXED:
*display = incr(Tcl_NewStringObj("(#PCDATA"/*)*/,-1)); sep = "|";
*begin = fsm("mixedbegin",0,fsm("#pcdata","#PCDATA",*end,0,all),0,all);
break;
case XML_CTYPE_CHOICE:
case XML_CTYPE_SEQ:
*display = incr(Tcl_NewStringObj("("/*)*/,-1));
last = *begin = fsm("seqchoicebegin",0,0,0,all);
break;
default:
*display = incr(Tcl_NewStringObj("EMPTY",-1));
*begin = fsm("empty",0,*end,0,all);
break;
}
for (i=0; i<model->numchildren; i++) {
Obj C; pFsm b,e; Obj SL = xmlContent(&model->children[i],&C,&b,&e,all);
if (SL) Tcl_ListObjAppendElement(0,L,SL);
Tcl_AppendToObj(*display,sep,-1);
Tcl_AppendObjToObj(*display,C); decr(C);
switch (model->type) {
case XML_CTYPE_MIXED:
case XML_CTYPE_CHOICE:
sep = "|";
join("choice begin",*begin,b,all); join("choice end",e,*end,all);
break;
case XML_CTYPE_SEQ:
sep = ",";
join("sequence and",last,b,all); last = e;
break;
}
}
switch (model->type) {
case XML_CTYPE_MIXED:
Tcl_AppendToObj(*display,/*(*/")",-1);
if (model->numchildren>1) Tcl_AppendToObj(*display,"*",-1);
join("mixed b->e",*begin,*end,all);
join("mixed e->b",*end,*begin,all);
break;
case XML_CTYPE_CHOICE:
Tcl_AppendToObj(*display,/*(*/")",-1);
break;
case XML_CTYPE_SEQ:
Tcl_AppendToObj(*display,/*(*/")",-1);
join("sequence ->e",last,*end,all);
break;
}
switch (model->quant) {
case XML_CQUANT_OPT:
Tcl_AppendToObj(*display,"?",-1);
join("? b->e",*begin,*end,all);
break;
case XML_CQUANT_REP:
Tcl_AppendToObj(*display,"*",-1);
join("* b->e",*begin,*end,all);
join("* e->b",*end,*begin,all);
break;
case XML_CQUANT_PLUS:
Tcl_AppendToObj(*display,"+",-1);
join("+ e->b",*end,*begin,all);
break;
}
return L;
}else
return 0;
}
static void elementDecl(ptr userData,const XML_Char *name,XML_Content *model) {
pFsm all = 0;
pTclContext c = userData; XML_Parser p = c->parser;
Obj display,machine; pFsm begin,end; int N = 0;
Obj piece = 0;
c->anyElement = true;
piece = pairstr(piece,"%what","element",-1);
piece = pairstr(piece,"%name",name,-1);
piece = pairobj(piece,"%model",xmlContent(model,&display,&begin,&end,&all));
piece = pairobj(piece,"%display",display); decr(display);
begin = fsm("#begin","#BEGIN",begin,0,&all); join("end->#end",end,fsm("#end","#END",0,0,&all),&all);
epsilonMark(begin,&all);
machine = incr(Tcl_NewObj()); fsmNumber(begin,&N,&all);
fsmConstruct(begin,machine,&all); freeFsms(&all);
piece = pairobj(piece,"%fsm",machine); decr(machine);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
piece = pairIndex(piece,c); incrIndex(c);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
dispose(model);
}
| ^ | Definition continued at: 31, 32, 33, 34. | | | | | section top | |
static void attlist(ptr userData,const XML_Char *elname,
const XML_Char *attname,
const XML_Char *att_type,
const XML_Char *dflt,
int isrequired)
{
pTclContext c = userData; XML_Parser p = c->parser;
chars assigned = dflt?(isrequired?"#FIXED":""):(isrequired?"#REQUIRED":"#IMPLIED");
Obj display;
Obj piece = 0;
piece = pairstr(piece,"%what","attlist",-1);
piece = pairstr(piece,"%element",elname,-1);
piece = pairstr(piece,"%attname",attname,-1);
piece = pairstr(piece,"%type",att_type,-1);
piece = pairstr(piece,"%assigned",assigned,-1);
piece = pairstr(piece,"%default",dflt,-1);
piece = pairint(piece,"%required",isrequired);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
display = incr(Tcl_NewStringObj(att_type,-1));
if (dflt) {
chars d;
if (isrequired) {
Tcl_AppendToObj(display," #FIXED",-1);
}
Tcl_AppendToObj(display," '",-1);
for (d=dflt; *d; d++) {
if (*d=='\'') {
Tcl_AppendToObj(display,"'",-1);
}else {
Tcl_AppendToObj(display,d,1);
}
}
Tcl_AppendToObj(display,"'",-1);
}else if (!dflt && isrequired) {
Tcl_AppendToObj(display," #REQUIRED",-1);
}else if (!dflt && !isrequired) {
Tcl_AppendToObj(display," #IMPLIED",-1);
}
piece = pairobj(piece,"%display",display); decr(display);
piece = pairIndex(piece,c); incrIndex(c);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
}
| ^ | Definition continued at: 32, 33, 34. | | | | | section top | |
static void entity(ptr userData,
const XML_Char *entityName,
int is_parameter_entity,
const XML_Char *value,
int value_length,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId,
const XML_Char *notationName)
{
pTclContext c = userData; XML_Parser p = c->parser;
Obj piece = 0;
piece = pairstr(piece,"%what",
is_parameter_entity
? (value ? "parameterEntityInternal"
: "parameterEntityExternal")
: (value ? "entityInternal"
: notationName ? "entityExternalUnparsed"
: "entityExternalParsed")
,-1);
piece = pairstr(piece,"%name",entityName,-1);
piece = pairstr(piece,"%value",value,value_length);
piece = pairstr(piece,"%system",systemId,-1);
piece = pairstr(piece,"%public",publicId,-1);
piece = pairstr(piece,"%notation",notationName,-1);
piece = pairstr(piece,"%base",base,-1);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
piece = pairIndex(piece,c); incrIndex(c);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
}
| ^ | Definition continued at: 33, 34. | | | | | section top | |
static void notation(ptr userData,
const XML_Char *notationName,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId)
{
pTclContext c = userData; XML_Parser p = c->parser;
Obj piece = 0;
piece = pairstr(piece,"%what","notation",-1);
piece = pairstr(piece,"%system",systemId,-1);
piece = pairstr(piece,"%public",publicId,-1);
piece = pairstr(piece,"%notation",notationName,-1);
piece = pairstr(piece,"%base",base,-1);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(p));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(p));
piece = pairIndex(piece,c); incrIndex(c);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
}
| ^ | Definition continued at: 34. | | | | | section top | |
static int externalEntityRef(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId)
{
pTclContext c = XML_GetUserData(parser);
if (c->reader) {
int o,m,l; chars t = XML_GetInputContext(parser,&o,&m),T; bool entity = false;
Obj reader = incr(Tcl_DuplicateObj(c->reader)); int rc;
Obj piece = 0;
t += o; m -= o;
if (c->cdata==0 && *t=='&' && m>2) {
for (T=t,l=0; m>0 && !entity; m--,T++,l++) entity = *T==';';
}
c->refcount += 1;
c->parser = XML_ExternalEntityParserCreate(parser,context,
c->encoding?Tcl_GetStringFromObj(c->encoding,0):0);
c->token = createParserToken(c->parser,0);
reader = pairstr(reader,"%parser",c->token,-1);
reader = pairstr(reader,"%base",base,-1);
reader = pairstr(reader,"%system",systemId,-1);
reader = pairstr(reader,"%public",publicId,-1);
reader = pairobj(reader,"%encoding",c->encoding);
piece = pairstr(piece,"%what","entity-parser-begin",-1);
piece = pairstr(piece,"%base",base,-1);
piece = pairstr(piece,"%system",systemId,-1);
piece = pairstr(piece,"%public",publicId,-1);
piece = pairobj(piece,"%encoding",c->encoding);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(parser));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(parser));
piece = pairIndex(piece,c); pushIndex(c);
if (entity) piece = pairstr(piece,"%entity",t,l);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
rc = Tcl_EvalObjEx(c->intr,reader,TCL_EVAL_DIRECT|TCL_EVAL_GLOBAL);
if (Tcl_IsShared(c->result)) {
Obj t = incr(Tcl_DuplicateObj(c->result));
decr(c->result);
c->result = t;
}
decr(reader); deleteParser(c->token);
c->parser = parser;
c->subparserError = rc!=TCL_OK;
piece = pairstr(0,"%what","entity-parser-end",-1);
piece = pairint(piece,"%line",XML_GetCurrentLineNumber(parser));
piece = pairint(piece,"%col",XML_GetCurrentColumnNumber(parser));
popIndex(c); piece = pairIndex(piece,c); incrIndex(c);
Tcl_ListObjAppendElement(0,c->result,piece); decr(piece);
return rc==TCL_OK;
}else {
return 1;
}
}
| ^ | | |
| |