38 #include <sys/types.h> 40 #if defined(_WIN32) || defined(_WIN64) 41 #define R_OK _A_RDONLY 42 #define access _access 55 #define NAME_EXT_SIZE 128 56 #define ATTR_EXT_SIZE 4096 57 #define DATA_EXT_SIZE 4096 58 #define LINE_BUF_SIZE 8192 60 #define xmlError(a, b) xmlErrmsg(a, b, FALSE, __FILE__, __LINE__) 111 assert( ppos !=
NULL );
115 ret = fprintf(stderr,
"%s(%d) Error in file %s line %d\n", file, line, ppos->
filename, ppos->
lineno);
118 ret = fprintf(stderr,
"%s", ppos->
buf);
121 if ( strchr(ppos->
buf,
'\n') ==
NULL )
125 retc = fputc(
'\n', stderr);
129 ret = fprintf(stderr,
"%*s\n", ppos->
pos,
"^");
132 ret = fprintf(stderr,
"%s\n\n", msg);
139 (void) fprintf(stderr,
"%s(%d) Error in file %s line %d\n", file, line, ppos->
filename, ppos->
lineno);
141 (void) fprintf(stderr,
"%s", ppos->
buf);
143 if ( strchr(ppos->
buf,
'\n') ==
NULL )
145 (void) fputc(
'\n', stderr);
148 (void) fprintf(stderr,
"%*s\n", ppos->
pos,
"^");
150 (void) fprintf(stderr,
"%s\n\n", msg);
167 assert(ppos !=
NULL);
168 assert(node !=
NULL);
187 assert(ppos !=
NULL);
205 assert(ppos !=
NULL);
230 assert(ppos !=
NULL);
242 assert(ppos !=
NULL);
246 if ( ppos->
buf[ppos->
pos] ==
'\0' )
248 #ifdef SCIP_DISABLED_CODE 253 size_t len = (size_t)
FREAD(ppos->
buf,
sizeof(ppos->
buf) - 1, ppos->
fp);
255 if( len == 0 || len >
sizeof(ppos->
buf) - 1 )
258 ppos->
buf[len] =
'\0';
262 return (
unsigned char)ppos->
buf[ppos->
pos++];
266 #ifdef SPEC_LIKE_SPACE_HANDLING 279 assert(ppos !=
NULL);
290 if (((c ==
'\n') && (ppos->
lastsym ==
'\r')) || ((c ==
'\r') && (ppos->
lastsym ==
'\n')))
318 assert(ppos !=
NULL);
334 if ((c ==
'\n') || (c ==
'\r'))
336 }
while((c ==
' ') && (ppos->
lastsym == c));
353 assert(ppos !=
NULL);
367 assert(ppos !=
NULL);
393 assert(ppos !=
NULL);
397 if ( ! isalpha(c) && (c !=
'_') && (c !=
':') )
399 xmlError(ppos,
"Name starting with illegal charater");
404 while ( isalnum(c) || (c ==
'_') || (c ==
':') || (c ==
'.') || (c ==
'-') )
406 if ( len + 1 >= size )
419 assert(name !=
NULL);
422 name[len++] = (char)c;
429 assert(name !=
NULL);
459 assert(ppos !=
NULL);
465 if ( (c !=
'"') && (c !=
'\'') )
467 xmlError(ppos,
"Atribute value does not start with \" or \'");
487 assert(attr !=
NULL);
492 if ( (c == stop) || (c == EOF) )
495 attr[len++] = (char)c;
521 assert(ppos !=
NULL);
530 if ( (c ==
'>') && (state >= 2) )
533 state = (c ==
'-') ? state + 1 : 0;
537 xmlError(ppos,
"Unexpected EOF in comment");
559 assert(ppos !=
NULL);
571 if ( (c ==
'>') && (state >= 2) )
589 assert(data !=
NULL);
592 data[len++] = (char)c;
594 assert(data !=
NULL);
600 assert(data !=
NULL);
602 data[len - 2] =
'\0';
608 xmlError(ppos,
"Unexpected EOF in CDATA");
621 assert(ppos !=
NULL);
628 while ( (c != EOF) && (c !=
'>') );
634 xmlError(ppos,
"Unexpected EOF in PI");
658 typedef enum XmlSection XMLSECTION;
666 {
"--", IS_COMMENT },
667 {
"ATTLIST", IS_ATTLIST },
668 {
"DOCTYPE", IS_DOCTYPE },
669 {
"ELEMENT", IS_ELEMENT },
670 {
"ENTITY", IS_ENTITY },
671 {
"NOTATION", IS_NOTATION },
672 {
"[CDATA[", IS_CDATA }
681 assert(ppos !=
NULL);
684 end = (int) (
sizeof(
key) /
sizeof(
key[0])) - 1;
689 for(; (beg <= end) && (c !=
key[beg].name[k]); beg++)
691 for(; (end >= beg) && (c !=
key[end].name[k]); end--)
699 xmlError(ppos,
"Unknown declaration");
701 while ( (c != EOF) && (c !=
'>') )
707 assert(beg < (
int)(
sizeof(
key) /
sizeof(*
key)));
710 switch(
key[beg].what)
723 xmlError(ppos,
"Can't create new node");
755 assert(ppos !=
NULL);
758 xmlError(ppos,
"Missing name in endtag");
765 xmlError(ppos,
"Missing '>' in endtag");
770 if ( strcmp(name,
topPstack(ppos)->name) )
772 xmlError(ppos,
"Name of endtag does not match starttag");
797 assert(ppos !=
NULL);
802 xmlError(ppos,
"Missing name in tagstart");
810 xmlError(ppos,
"Can't create new node");
834 assert(ppos !=
NULL);
883 assert(ppos !=
NULL);
888 if ( (c ==
'/') || (c ==
'>') || (c == EOF) )
898 xmlError(ppos,
"Unexpected EOF while in a tag");
911 xmlError(ppos,
"Expected tag end marker '>'");
922 xmlError(ppos,
"No name for attribute");
931 xmlError(ppos,
"Missing attribute value");
940 xmlError(ppos,
"Can't create new attribute");
966 assert(ppos !=
NULL);
969 #ifndef SPEC_LIKE_SPACE_HANDLING 976 while ( (c != EOF) && (c !=
'<') )
978 if ( len + 1 >= size )
991 assert(data !=
NULL);
992 assert(size > len + 1);
994 data[len++] = (char)c;
1023 xmlError(ppos,
"Can't create new node");
1050 switch (ppos->
state)
1068 xmlError(ppos,
"Internal Error, illegal state");
1077 const char* filename
1088 assert( filename !=
NULL );
1089 filenamelen = strlen(filename);
1094 #ifdef SCIP_WITH_ZLIB 1095 if ( access(filename, R_OK) != 0 )
1097 strcat(myfilename,
".gz");
1102 if ( access(myfilename, R_OK) != 0 )
1103 (void)
SCIPstrncpy(myfilename, filename, (
int)filenamelen + 5);
1106 ppos.
fp =
FOPEN(myfilename,
"r");
1123 xmlError(&ppos,
"Can't create new node");
1129 xmlError(&ppos,
"Can't create new attribute");
1144 if ( ! result && (node !=
NULL) )
1146 xmlErrmsg(&ppos,
"Parsing error, processing stopped",
TRUE, __FILE__, __LINE__);
1174 assert(name !=
NULL);
1193 assert(name !=
NULL);
1194 assert(value !=
NULL);
1214 a->next = n->attrlist;
1224 assert(parent !=
NULL);
1225 assert(child !=
NULL);
1227 child->parent = parent;
1228 child->prevsibl = parent->lastchild;
1229 child->nextsibl =
NULL;
1230 parent->lastchild = child;
1232 if ( child->prevsibl !=
NULL )
1233 child->prevsibl->nextsibl = child;
1235 if ( parent->firstchild ==
NULL )
1236 parent->firstchild = child;
1255 assert(a->name !=
NULL);
1256 assert(a->value !=
NULL);
1278 n = node->lastchild;
1289 if ( node->data !=
NULL )
1293 assert(node->name !=
NULL);
1307 assert(root !=
NULL);
1309 for (n = root; n !=
NULL; n = n->nextsibl)
1315 for (a = n->attrlist; a !=
NULL; a = a->next)
1316 infoMessage(
"Attr: %s = [%s]\n", a->name, a->value);
1318 if ( n->firstchild !=
NULL )
1335 assert(node !=
NULL);
1336 assert(name !=
NULL);
1338 for (a = node->attrlist; a !=
NULL; a = a->next)
1340 if ( ! strcmp(name, a->name) )
1346 infoMessage(
"Error: Attribute %s in TAG <%s> not found\n", name, node->name);
1349 return (a ==
NULL) ?
NULL : a->value;
1360 assert(node !=
NULL);
1361 assert(name !=
NULL);
1363 for (n = node; n !=
NULL; n = n->nextsibl)
1365 if ( ! strcmp(name, n->name) )
1378 assert(node !=
NULL);
1379 assert(name !=
NULL);
1393 assert(node !=
NULL);
1394 assert(name !=
NULL);
1396 if ( ! strcmp(name, node->name) )
1399 for (n = node->firstchild; n !=
NULL; n = n->nextsibl)
1420 assert(node !=
NULL);
1421 assert(name !=
NULL);
1423 if ( ! strcmp(name, node->name) )
1426 if ( depth < maxdepth )
1428 for (n = node->firstchild; n !=
NULL; n = n->nextsibl)
1444 assert(node !=
NULL);
1446 return node->nextsibl;
1454 assert(node !=
NULL);
1456 return node->prevsibl;
1464 assert(node !=
NULL);
1466 return node->firstchild;
1474 assert(node !=
NULL);
1476 return node->lastchild;
1484 assert(node !=
NULL);
1494 assert(node !=
NULL);
1496 return node->lineno;
1504 assert(node !=
NULL);
1517 assert(node !=
NULL);
1518 assert(name !=
NULL);
1524 if ( ! strcmp(n->firstchild->name,
"#PCDATA") )
1525 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)
int SCIPstrncpy(char *t, const char *s, int size)
#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