47 #include <sys/types.h> 49 #if defined(_WIN32) || defined(_WIN64) 50 #define R_OK _A_RDONLY 51 #define access _access 64 #define NAME_EXT_SIZE 128 65 #define ATTR_EXT_SIZE 4096 66 #define DATA_EXT_SIZE 4096 67 #define LINE_BUF_SIZE 8192 69 #define xmlError(a, b) xmlErrmsg(a, b, FALSE, __FILE__, __LINE__) 120 assert( ppos !=
NULL );
124 ret = fprintf(stderr,
"%s(%d) Error in file %s line %d\n", file, line, ppos->
filename, ppos->
lineno);
127 ret = fprintf(stderr,
"%s", ppos->
buf);
130 if ( strchr(ppos->
buf,
'\n') ==
NULL )
134 retc = fputc(
'\n', stderr);
138 ret = fprintf(stderr,
"%*s\n", ppos->
pos,
"^");
141 ret = fprintf(stderr,
"%s\n\n", msg);
148 (void) fprintf(stderr,
"%s(%d) Error in file %s line %d\n", file, line, ppos->
filename, ppos->
lineno);
150 (void) fprintf(stderr,
"%s", ppos->
buf);
152 if ( strchr(ppos->
buf,
'\n') ==
NULL )
154 (void) fputc(
'\n', stderr);
157 (void) fprintf(stderr,
"%*s\n", ppos->
pos,
"^");
159 (void) fprintf(stderr,
"%s\n\n", msg);
176 assert(ppos !=
NULL);
177 assert(node !=
NULL);
196 assert(ppos !=
NULL);
214 assert(ppos !=
NULL);
239 assert(ppos !=
NULL);
251 assert(ppos !=
NULL);
255 if ( ppos->
buf[ppos->
pos] ==
'\0' )
257 #ifdef SCIP_DISABLED_CODE 262 size_t len = (size_t)
FREAD(ppos->
buf,
sizeof(ppos->
buf) - 1, ppos->
fp);
264 if( len == 0 || len >
sizeof(ppos->
buf) - 1 )
267 ppos->
buf[len] =
'\0';
271 return (
unsigned char)ppos->
buf[ppos->
pos++];
275 #ifdef SPEC_LIKE_SPACE_HANDLING 288 assert(ppos !=
NULL);
299 if (((c ==
'\n') && (ppos->
lastsym ==
'\r')) || ((c ==
'\r') && (ppos->
lastsym ==
'\n')))
327 assert(ppos !=
NULL);
343 if ((c ==
'\n') || (c ==
'\r'))
345 }
while((c ==
' ') && (ppos->
lastsym == c));
362 assert(ppos !=
NULL);
376 assert(ppos !=
NULL);
402 assert(ppos !=
NULL);
406 if ( ! isalpha(c) && (c !=
'_') && (c !=
':') )
408 xmlError(ppos,
"Name starting with illegal charater");
413 while ( isalnum(c) || (c ==
'_') || (c ==
':') || (c ==
'.') || (c ==
'-') )
415 if ( len + 1 >= size )
428 assert(name !=
NULL);
431 name[len++] = (char)c;
438 assert(name !=
NULL);
468 assert(ppos !=
NULL);
474 if ( (c !=
'"') && (c !=
'\'') )
476 xmlError(ppos,
"Atribute value does not start with \" or \'");
496 assert(attr !=
NULL);
501 if ( (c == stop) || (c == EOF) )
504 attr[len++] = (char)c;
530 assert(ppos !=
NULL);
539 if ( (c ==
'>') && (state >= 2) )
542 state = (c ==
'-') ? state + 1 : 0;
546 xmlError(ppos,
"Unexpected EOF in comment");
568 assert(ppos !=
NULL);
580 if ( (c ==
'>') && (state >= 2) )
598 assert(data !=
NULL);
601 data[len++] = (char)c;
603 assert(data !=
NULL);
609 assert(data !=
NULL);
611 data[len - 2] =
'\0';
617 xmlError(ppos,
"Unexpected EOF in CDATA");
630 assert(ppos !=
NULL);
637 while ( (c != EOF) && (c !=
'>') );
643 xmlError(ppos,
"Unexpected EOF in PI");
667 typedef enum XmlSection XMLSECTION;
675 {
"--", IS_COMMENT },
676 {
"ATTLIST", IS_ATTLIST },
677 {
"DOCTYPE", IS_DOCTYPE },
678 {
"ELEMENT", IS_ELEMENT },
679 {
"ENTITY", IS_ENTITY },
680 {
"NOTATION", IS_NOTATION },
681 {
"[CDATA[", IS_CDATA }
690 assert(ppos !=
NULL);
693 end = (int) (
sizeof(key) /
sizeof(key[0])) - 1;
698 for(; (beg <= end) && (c != key[beg].name[k]); beg++)
700 for(; (end >= beg) && (c != key[end].name[k]); end--)
708 xmlError(ppos,
"Unknown declaration");
710 while ( (c != EOF) && (c !=
'>') )
716 assert(beg < (
int)(
sizeof(key) /
sizeof(*key)));
719 switch(key[beg].what)
732 xmlError(ppos,
"Can't create new node");
764 assert(ppos !=
NULL);
767 xmlError(ppos,
"Missing name in endtag");
774 xmlError(ppos,
"Missing '>' in endtag");
779 if ( strcmp(name,
topPstack(ppos)->name) )
781 xmlError(ppos,
"Name of endtag does not match starttag");
806 assert(ppos !=
NULL);
811 xmlError(ppos,
"Missing name in tagstart");
819 xmlError(ppos,
"Can't create new node");
843 assert(ppos !=
NULL);
892 assert(ppos !=
NULL);
897 if ( (c ==
'/') || (c ==
'>') || (c == EOF) )
907 xmlError(ppos,
"Unexpected EOF while in a tag");
920 xmlError(ppos,
"Expected tag end marker '>'");
931 xmlError(ppos,
"No name for attribute");
940 xmlError(ppos,
"Missing attribute value");
949 xmlError(ppos,
"Can't create new attribute");
975 assert(ppos !=
NULL);
978 #ifndef SPEC_LIKE_SPACE_HANDLING 985 while ( (c != EOF) && (c !=
'<') )
987 if ( len + 1 >= size )
1000 assert(data !=
NULL);
1001 assert(size > len + 1);
1003 data[len++] = (char)c;
1032 xmlError(ppos,
"Can't create new node");
1059 switch (ppos->
state)
1077 xmlError(ppos,
"Internal Error, illegal state");
1086 const char* filename
1097 assert( filename !=
NULL );
1098 filenamelen = strlen(filename);
1103 #ifdef SCIP_WITH_ZLIB 1104 if ( access(filename, R_OK) != 0 )
1106 strcat(myfilename,
".gz");
1111 if ( access(myfilename, R_OK) != 0 )
1112 (void)
SCIPstrncpy(myfilename, filename, (
int)filenamelen + 5);
1115 ppos.
fp =
FOPEN(myfilename,
"r");
1132 xmlError(&ppos,
"Can't create new node");
1138 xmlError(&ppos,
"Can't create new attribute");
1153 if ( ! result && (node !=
NULL) )
1155 xmlErrmsg(&ppos,
"Parsing error, processing stopped",
TRUE, __FILE__, __LINE__);
1183 assert(name !=
NULL);
1202 assert(name !=
NULL);
1203 assert(value !=
NULL);
1223 a->next = n->attrlist;
1233 assert(parent !=
NULL);
1234 assert(child !=
NULL);
1236 child->parent = parent;
1237 child->prevsibl = parent->lastchild;
1238 child->nextsibl =
NULL;
1239 parent->lastchild = child;
1241 if ( child->prevsibl !=
NULL )
1242 child->prevsibl->nextsibl = child;
1244 if ( parent->firstchild ==
NULL )
1245 parent->firstchild = child;
1264 assert(a->name !=
NULL);
1265 assert(a->value !=
NULL);
1287 n = node->lastchild;
1298 if ( node->data !=
NULL )
1302 assert(node->name !=
NULL);
1316 assert(root !=
NULL);
1318 for (n = root; n !=
NULL; n = n->nextsibl)
1324 for (a = n->attrlist; a !=
NULL; a = a->next)
1325 infoMessage(
"Attr: %s = [%s]\n", a->name, a->value);
1327 if ( n->firstchild !=
NULL )
1344 assert(node !=
NULL);
1345 assert(name !=
NULL);
1347 for (a = node->attrlist; a !=
NULL; a = a->next)
1349 if ( ! strcmp(name, a->name) )
1355 infoMessage(
"Error: Attribute %s in TAG <%s> not found\n", name, node->name);
1358 return (a ==
NULL) ?
NULL : a->value;
1369 assert(node !=
NULL);
1370 assert(name !=
NULL);
1372 for (n = node; n !=
NULL; n = n->nextsibl)
1374 if ( ! strcmp(name, n->name) )
1387 assert(node !=
NULL);
1388 assert(name !=
NULL);
1402 assert(node !=
NULL);
1403 assert(name !=
NULL);
1405 if ( ! strcmp(name, node->name) )
1408 for (n = node->firstchild; n !=
NULL; n = n->nextsibl)
1429 assert(node !=
NULL);
1430 assert(name !=
NULL);
1432 if ( ! strcmp(name, node->name) )
1435 if ( depth < maxdepth )
1437 for (n = node->firstchild; n !=
NULL; n = n->nextsibl)
1453 assert(node !=
NULL);
1455 return node->nextsibl;
1463 assert(node !=
NULL);
1465 return node->prevsibl;
1473 assert(node !=
NULL);
1475 return node->firstchild;
1483 assert(node !=
NULL);
1485 return node->lastchild;
1493 assert(node !=
NULL);
1503 assert(node !=
NULL);
1505 return node->lineno;
1513 assert(node !=
NULL);
1526 assert(node !=
NULL);
1527 assert(name !=
NULL);
1533 if ( ! strcmp(n->firstchild->name,
"#PCDATA") )
1534 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)
int SCIPstrncpy(char *t, const char *s, int size)
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)
internal miscellaneous methods
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