36 #include <sys/types.h> 38 #if defined(_WIN32) || defined(_WIN64) 39 #define R_OK _A_RDONLY 40 #define access _access 53 #define NAME_EXT_SIZE 128 54 #define ATTR_EXT_SIZE 4096 55 #define DATA_EXT_SIZE 4096 56 #define LINE_BUF_SIZE 8192 58 #define xmlError(a, b) xmlErrmsg(a, b, FALSE, __FILE__, __LINE__) 109 assert( ppos !=
NULL );
113 ret = fprintf(stderr,
"%s(%d) Error in file %s line %d\n", file, line, ppos->
filename, ppos->
lineno);
116 ret = fprintf(stderr,
"%s", ppos->
buf);
119 if ( strchr(ppos->
buf,
'\n') ==
NULL )
123 retc = fputc(
'\n', stderr);
127 ret = fprintf(stderr,
"%*s\n", ppos->
pos,
"^");
130 ret = fprintf(stderr,
"%s\n\n", msg);
137 (void) fprintf(stderr,
"%s(%d) Error in file %s line %d\n", file, line, ppos->
filename, ppos->
lineno);
139 (void) fprintf(stderr,
"%s", ppos->
buf);
141 if ( strchr(ppos->
buf,
'\n') ==
NULL )
143 (void) fputc(
'\n', stderr);
146 (void) fprintf(stderr,
"%*s\n", ppos->
pos,
"^");
148 (void) fprintf(stderr,
"%s\n\n", msg);
165 assert(ppos !=
NULL);
166 assert(node !=
NULL);
185 assert(ppos !=
NULL);
203 assert(ppos !=
NULL);
228 assert(ppos !=
NULL);
240 assert(ppos !=
NULL);
244 if ( ppos->
buf[ppos->
pos] ==
'\0' )
246 #ifdef SCIP_DISABLED_CODE 251 size_t len = (size_t)
FREAD(ppos->
buf,
sizeof(ppos->
buf) - 1, ppos->
fp);
253 if( len == 0 || len >
sizeof(ppos->
buf) - 1 )
256 ppos->
buf[len] =
'\0';
260 return (
unsigned char)ppos->
buf[ppos->
pos++];
264 #ifdef SPEC_LIKE_SPACE_HANDLING 277 assert(ppos !=
NULL);
288 if (((c ==
'\n') && (ppos->
lastsym ==
'\r')) || ((c ==
'\r') && (ppos->
lastsym ==
'\n')))
316 assert(ppos !=
NULL);
332 if ((c ==
'\n') || (c ==
'\r'))
334 }
while((c ==
' ') && (ppos->
lastsym == c));
351 assert(ppos !=
NULL);
365 assert(ppos !=
NULL);
391 assert(ppos !=
NULL);
395 if ( ! isalpha(c) && (c !=
'_') && (c !=
':') )
397 xmlError(ppos,
"Name starting with illegal charater");
402 while ( isalnum(c) || (c ==
'_') || (c ==
':') || (c ==
'.') || (c ==
'-') )
404 if ( len + 1 >= size )
417 assert(name !=
NULL);
420 name[len++] = (char)c;
427 assert(name !=
NULL);
457 assert(ppos !=
NULL);
463 if ( (c !=
'"') && (c !=
'\'') )
465 xmlError(ppos,
"Atribute value does not start with \" or \'");
485 assert(attr !=
NULL);
490 if ( (c == stop) || (c == EOF) )
493 attr[len++] = (char)c;
519 assert(ppos !=
NULL);
528 if ( (c ==
'>') && (state >= 2) )
531 state = (c ==
'-') ? state + 1 : 0;
535 xmlError(ppos,
"Unexpected EOF in comment");
557 assert(ppos !=
NULL);
569 if ( (c ==
'>') && (state >= 2) )
587 assert(data !=
NULL);
590 data[len++] = (char)c;
592 assert(data !=
NULL);
598 assert(data !=
NULL);
600 data[len - 2] =
'\0';
606 xmlError(ppos,
"Unexpected EOF in CDATA");
619 assert(ppos !=
NULL);
626 while ( (c != EOF) && (c !=
'>') );
632 xmlError(ppos,
"Unexpected EOF in PI");
656 typedef enum XmlSection XMLSECTION;
664 {
"--", IS_COMMENT },
665 {
"ATTLIST", IS_ATTLIST },
666 {
"DOCTYPE", IS_DOCTYPE },
667 {
"ELEMENT", IS_ELEMENT },
668 {
"ENTITY", IS_ENTITY },
669 {
"NOTATION", IS_NOTATION },
670 {
"[CDATA[", IS_CDATA }
679 assert(ppos !=
NULL);
682 end = (int) (
sizeof(key) /
sizeof(key[0])) - 1;
687 for(; (beg <= end) && (c != key[beg].name[k]); beg++)
689 for(; (end >= beg) && (c != key[end].name[k]); end--)
696 xmlError(ppos,
"Unknown declaration");
698 while ( (c != EOF) && (c !=
'>') )
704 assert(beg < (
int)(
sizeof(key) /
sizeof(*key)));
706 switch(key[beg].what)
719 xmlError(ppos,
"Can't create new node");
751 assert(ppos !=
NULL);
754 xmlError(ppos,
"Missing name in endtag");
761 xmlError(ppos,
"Missing '>' in endtag");
766 if ( strcmp(name,
topPstack(ppos)->name) )
768 xmlError(ppos,
"Name of endtag does not match starttag");
793 assert(ppos !=
NULL);
798 xmlError(ppos,
"Missing name in tagstart");
806 xmlError(ppos,
"Can't create new node");
830 assert(ppos !=
NULL);
879 assert(ppos !=
NULL);
884 if ( (c ==
'/') || (c ==
'>') || (c == EOF) )
894 xmlError(ppos,
"Unexpected EOF while in a tag");
907 xmlError(ppos,
"Expected tag end marker '>'");
918 xmlError(ppos,
"No name for attribute");
927 xmlError(ppos,
"Missing attribute value");
936 xmlError(ppos,
"Can't create new attribute");
962 assert(ppos !=
NULL);
965 #ifndef SPEC_LIKE_SPACE_HANDLING 972 while ( (c != EOF) && (c !=
'<') )
974 if ( len + 1 >= size )
987 assert(data !=
NULL);
988 assert(size > len + 1);
990 data[len++] = (char)c;
1022 xmlError(ppos,
"Can't create new node");
1049 switch (ppos->
state)
1067 xmlError(ppos,
"Internal Error, illegal state");
1076 const char* filename
1087 assert( filename !=
NULL );
1088 filenamelen = strlen(filename);
1094 if ( access(filename, R_OK) != 0 )
1096 strcat(myfilename,
".gz");
1101 if ( access(myfilename, R_OK) != 0 )
1102 strcpy(myfilename, filename);
1105 ppos.
fp =
FOPEN(myfilename,
"r");
1122 xmlError(&ppos,
"Can't create new node");
1128 xmlError(&ppos,
"Can't create new attribute");
1143 if ( ! result && (node !=
NULL) )
1145 xmlErrmsg(&ppos,
"Parsing error, processing stopped",
TRUE, __FILE__, __LINE__);
1173 assert(name !=
NULL);
1192 assert(name !=
NULL);
1193 assert(value !=
NULL);
1213 a->next = n->attrlist;
1223 assert(parent !=
NULL);
1224 assert(child !=
NULL);
1226 child->parent = parent;
1227 child->prevsibl = parent->lastchild;
1228 child->nextsibl =
NULL;
1229 parent->lastchild = child;
1231 if ( child->prevsibl !=
NULL )
1232 child->prevsibl->nextsibl = child;
1234 if ( parent->firstchild ==
NULL )
1235 parent->firstchild = child;
1254 assert(a->name !=
NULL);
1255 assert(a->value !=
NULL);
1277 n = node->lastchild;
1288 if ( node->data !=
NULL )
1292 assert(node->name !=
NULL);
1306 assert(root !=
NULL);
1308 for (n = root; n !=
NULL; n = n->nextsibl)
1314 for (a = n->attrlist; a !=
NULL; a = a->next)
1315 infoMessage(
"Attr: %s = [%s]\n", a->name, a->value);
1317 if ( n->firstchild !=
NULL )
1334 assert(node !=
NULL);
1335 assert(name !=
NULL);
1337 for (a = node->attrlist; a !=
NULL; a = a->next)
1339 if ( ! strcmp(name, a->name) )
1345 infoMessage(
"Error: Attribute %s in TAG <%s> not found\n", name, node->name);
1348 return (a ==
NULL) ?
NULL : a->value;
1359 assert(node !=
NULL);
1360 assert(name !=
NULL);
1362 for (n = node; n !=
NULL; n = n->nextsibl)
1364 if ( ! strcmp(name, n->name) )
1377 assert(node !=
NULL);
1378 assert(name !=
NULL);
1392 assert(node !=
NULL);
1393 assert(name !=
NULL);
1395 if ( ! strcmp(name, node->name) )
1398 for (n = node->firstchild; n !=
NULL; n = n->nextsibl)
1419 assert(node !=
NULL);
1420 assert(name !=
NULL);
1422 if ( ! strcmp(name, node->name) )
1425 if ( depth < maxdepth )
1427 for (n = node->firstchild; n !=
NULL; n = n->nextsibl)
1443 assert(node !=
NULL);
1445 return node->nextsibl;
1453 assert(node !=
NULL);
1455 return node->prevsibl;
1463 assert(node !=
NULL);
1465 return node->firstchild;
1473 assert(node !=
NULL);
1475 return node->lastchild;
1483 assert(node !=
NULL);
1493 assert(node !=
NULL);
1495 return node->lineno;
1503 assert(node !=
NULL);
1516 assert(node !=
NULL);
1517 assert(name !=
NULL);
1523 if ( ! strcmp(n->firstchild->name,
"#PCDATA") )
1524 return n->firstchild->data;
const XML_NODE * xmlFirstNode(const XML_NODE *node, const char *name)
static void handleDecl(PPOS *ppos)
const char * xmlFindPcdata(const XML_NODE *node, const char *name)
void xmlFreeNode(XML_NODE *node)
#define FREAD(buf, len, fp)
static int getsymbol(PPOS *ppos)
struct XML_ATTR_struct XML_ATTR
static char * doCdata(PPOS *ppos)
static void xmlFreeAttr(XML_ATTR *attr)
XML_NODE * xmlNewNode(const char *name, int lineno)
const char * xmlGetName(const XML_NODE *node)
#define BMSallocMemoryArray(ptr, num)
enum parse_state_enum PSTATE
XML_ATTR * xmlNewAttr(const char *name, const char *value)
#define BMSfreeMemory(ptr)
void xmlShowNode(const XML_NODE *root)
static void procInTag(PPOS *ppos)
const char * xmlGetData(const XML_NODE *node)
static void xmlErrmsg(PPOS *ppos, const char *msg, XML_Bool msg_only, const char *file, int line)
static void procPcdata(PPOS *ppos)
static int mygetc(PPOS *ppos)
static void ungetsymbol(PPOS *ppos, int c)
#define BMSfreeMemoryArray(ptr)
static XML_Bool popPstack(PPOS *ppos)
struct XML_NODE_struct XML_NODE
static XML_Bool doComment(PPOS *ppos)
const XML_NODE * xmlFindNode(const XML_NODE *node, const char *name)
const char * xmlGetAttrval(const XML_NODE *node, const char *name)
const XML_NODE * xmlNextNode(const XML_NODE *node, const char *name)
static XML_Bool xmlParse(PPOS *ppos)
#define BMSduplicateMemoryArray(ptr, source, num)
const XML_NODE * xmlFirstChild(const XML_NODE *node)
XML_NODE * xmlProcess(const char *filename)
static int skipSpace(PPOS *ppos)
static XML_NODE * topPstack(const PPOS *ppos)
static char * getAttrval(PPOS *ppos)
void xmlAddAttr(XML_NODE *n, XML_ATTR *a)
#define FGETS(buf, len, fp)
#define BMScopyMemoryArray(ptr, source, num)
#define FOPEN(file, mode)
#define BMSclearMemory(ptr)
static char * getName(PPOS *ppos)
const XML_NODE * xmlNextSibl(const XML_NODE *node)
static XML_Bool pushPstack(PPOS *ppos, XML_NODE *node)
#define BMSallocMemory(ptr)
#define BMSreallocMemoryArray(ptr, num)
declarations for XML parsing
const XML_NODE * xmlPrevSibl(const XML_NODE *node)
const XML_NODE * xmlLastChild(const XML_NODE *node)
const XML_NODE * xmlFindNodeMaxdepth(const XML_NODE *node, const char *name, int depth, int maxdepth)
static void handlePi(PPOS *ppos)
int xmlGetLine(const XML_NODE *node)
void xmlAppendChild(XML_NODE *parent, XML_NODE *child)
static void handleStarttag(PPOS *ppos)
static void procBefore(PPOS *ppos)
static void handleEndtag(PPOS *ppos)
static void clearPstack(PPOS *ppos)
memory allocation routines
definitions for XML parsing