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);
186 assert(ppos->
top != NULL);
203 assert(ppos != NULL);
205 if ( ppos->
top == NULL )
228 assert(ppos != NULL);
230 while ( ppos->
top != NULL )
240 assert(ppos != NULL);
241 assert(ppos->
fp != 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)
713 if ( (data =
doCdata(ppos)) == NULL )
719 xmlError(ppos,
"Can't create new node");
751 assert(ppos != NULL);
753 if ( (name =
getName(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");
925 if ( (c !=
'=') || ((value =
getAttrval(ppos)) == NULL) )
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;
1019 xmlError(ppos,
"Can't create new node");
1046 switch (ppos->
state)
1064 xmlError(ppos,
"Internal Error, illegal state");
1073 const char* filename
1084 assert( filename != NULL );
1085 filenamelen = strlen(filename);
1091 if ( access(filename, R_OK) != 0 )
1093 strcat(myfilename,
".gz");
1098 if ( access(myfilename, R_OK) != 0 )
1099 strcpy(myfilename, filename);
1102 ppos.
fp =
FOPEN(myfilename,
"r");
1103 if ( ppos.
fp == NULL )
1119 xmlError(&ppos,
"Can't create new node");
1125 xmlError(&ppos,
"Can't create new attribute");
1140 if ( ! result && (node != NULL) )
1142 xmlErrmsg(&ppos,
"Parsing error, processing stopped",
TRUE, __FILE__, __LINE__);
1170 assert(name != NULL);
1189 assert(name != NULL);
1190 assert(value != NULL);
1210 a->next = n->attrlist;
1220 assert(parent != NULL);
1221 assert(child != NULL);
1223 child->parent = parent;
1224 child->prevsibl = parent->lastchild;
1225 child->nextsibl = NULL;
1226 parent->lastchild = child;
1228 if ( child->prevsibl != NULL )
1229 child->prevsibl->nextsibl = child;
1231 if ( parent->firstchild == NULL )
1232 parent->firstchild = child;
1251 assert(a->name != NULL);
1252 assert(a->value != NULL);
1274 n = node->lastchild;
1285 if ( node->data != NULL )
1289 assert(node->name != NULL);
1303 assert(root != NULL);
1305 for (n = root; n != NULL; n = n->nextsibl)
1309 infoMessage(
"Data: %s\n", (n->data != NULL) ? n->data :
"***");
1311 for (a = n->attrlist; a != NULL; a = a->next)
1312 infoMessage(
"Attr: %s = [%s]\n", a->name, a->value);
1314 if ( n->firstchild != NULL )
1331 assert(node != NULL);
1332 assert(name != NULL);
1334 for (a = node->attrlist; a != NULL; a = a->next)
1336 if ( ! strcmp(name, a->name) )
1342 infoMessage(
"Error: Attribute %s in TAG <%s> not found\n", name, node->name);
1345 return (a == NULL) ? NULL : a->value;
1356 assert(node != NULL);
1357 assert(name != NULL);
1359 for (n = node; n != NULL; n = n->nextsibl)
1361 if ( ! strcmp(name, n->name) )
1374 assert(node != NULL);
1375 assert(name != NULL);
1377 return (node->nextsibl == NULL) ? NULL :
xmlFirstNode(node->nextsibl, name);
1389 assert(node != NULL);
1390 assert(name != NULL);
1392 if ( ! strcmp(name, node->name) )
1395 for (n = node->firstchild; n != NULL; n = n->nextsibl)
1416 assert(node != NULL);
1417 assert(name != NULL);
1419 if ( ! strcmp(name, node->name) )
1422 if ( depth < maxdepth )
1424 for (n = node->firstchild; n != NULL; n = n->nextsibl)
1440 assert(node != NULL);
1442 return node->nextsibl;
1450 assert(node != NULL);
1452 return node->prevsibl;
1460 assert(node != NULL);
1462 return node->firstchild;
1470 assert(node != NULL);
1472 return node->lastchild;
1480 assert(node != NULL);
1490 assert(node != NULL);
1492 return node->lineno;
1500 assert(node != NULL);
1513 assert(node != NULL);
1514 assert(name != NULL);
1520 if ( ! strcmp(n->firstchild->name,
"#PCDATA") )
1521 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