37 #include <sys/types.h> 39 #if defined(_WIN32) || defined(_WIN64) 40 #define R_OK _A_RDONLY 41 #define access _access 54 #define NAME_EXT_SIZE 128 55 #define ATTR_EXT_SIZE 4096 56 #define DATA_EXT_SIZE 4096 57 #define LINE_BUF_SIZE 8192 59 #define xmlError(a, b) xmlErrmsg(a, b, FALSE, __FILE__, __LINE__) 110 assert( ppos !=
NULL );
114 ret = fprintf(stderr,
"%s(%d) Error in file %s line %d\n", file, line, ppos->
filename, ppos->
lineno);
117 ret = fprintf(stderr,
"%s", ppos->
buf);
120 if ( strchr(ppos->
buf,
'\n') ==
NULL )
124 retc = fputc(
'\n', stderr);
128 ret = fprintf(stderr,
"%*s\n", ppos->
pos,
"^");
131 ret = fprintf(stderr,
"%s\n\n", msg);
138 (void) fprintf(stderr,
"%s(%d) Error in file %s line %d\n", file, line, ppos->
filename, ppos->
lineno);
140 (void) fprintf(stderr,
"%s", ppos->
buf);
142 if ( strchr(ppos->
buf,
'\n') ==
NULL )
144 (void) fputc(
'\n', stderr);
147 (void) fprintf(stderr,
"%*s\n", ppos->
pos,
"^");
149 (void) fprintf(stderr,
"%s\n\n", msg);
166 assert(ppos !=
NULL);
167 assert(node !=
NULL);
186 assert(ppos !=
NULL);
204 assert(ppos !=
NULL);
229 assert(ppos !=
NULL);
241 assert(ppos !=
NULL);
245 if ( ppos->
buf[ppos->
pos] ==
'\0' )
247 #ifdef SCIP_DISABLED_CODE 252 size_t len = (size_t)
FREAD(ppos->
buf,
sizeof(ppos->
buf) - 1, ppos->
fp);
254 if( len == 0 || len >
sizeof(ppos->
buf) - 1 )
257 ppos->
buf[len] =
'\0';
261 return (
unsigned char)ppos->
buf[ppos->
pos++];
265 #ifdef SPEC_LIKE_SPACE_HANDLING 278 assert(ppos !=
NULL);
289 if (((c ==
'\n') && (ppos->
lastsym ==
'\r')) || ((c ==
'\r') && (ppos->
lastsym ==
'\n')))
317 assert(ppos !=
NULL);
333 if ((c ==
'\n') || (c ==
'\r'))
335 }
while((c ==
' ') && (ppos->
lastsym == c));
352 assert(ppos !=
NULL);
366 assert(ppos !=
NULL);
392 assert(ppos !=
NULL);
396 if ( ! isalpha(c) && (c !=
'_') && (c !=
':') )
398 xmlError(ppos,
"Name starting with illegal charater");
403 while ( isalnum(c) || (c ==
'_') || (c ==
':') || (c ==
'.') || (c ==
'-') )
405 if ( len + 1 >= size )
418 assert(name !=
NULL);
421 name[len++] = (char)c;
428 assert(name !=
NULL);
458 assert(ppos !=
NULL);
464 if ( (c !=
'"') && (c !=
'\'') )
466 xmlError(ppos,
"Atribute value does not start with \" or \'");
486 assert(attr !=
NULL);
491 if ( (c == stop) || (c == EOF) )
494 attr[len++] = (char)c;
520 assert(ppos !=
NULL);
529 if ( (c ==
'>') && (state >= 2) )
532 state = (c ==
'-') ? state + 1 : 0;
536 xmlError(ppos,
"Unexpected EOF in comment");
558 assert(ppos !=
NULL);
570 if ( (c ==
'>') && (state >= 2) )
588 assert(data !=
NULL);
591 data[len++] = (char)c;
593 assert(data !=
NULL);
599 assert(data !=
NULL);
601 data[len - 2] =
'\0';
607 xmlError(ppos,
"Unexpected EOF in CDATA");
620 assert(ppos !=
NULL);
627 while ( (c != EOF) && (c !=
'>') );
633 xmlError(ppos,
"Unexpected EOF in PI");
657 typedef enum XmlSection XMLSECTION;
665 {
"--", IS_COMMENT },
666 {
"ATTLIST", IS_ATTLIST },
667 {
"DOCTYPE", IS_DOCTYPE },
668 {
"ELEMENT", IS_ELEMENT },
669 {
"ENTITY", IS_ENTITY },
670 {
"NOTATION", IS_NOTATION },
671 {
"[CDATA[", IS_CDATA }
680 assert(ppos !=
NULL);
683 end = (int) (
sizeof(
key) /
sizeof(
key[0])) - 1;
688 for(; (beg <= end) && (c !=
key[beg].name[k]); beg++)
690 for(; (end >= beg) && (c !=
key[end].name[k]); end--)
697 xmlError(ppos,
"Unknown declaration");
699 while ( (c != EOF) && (c !=
'>') )
705 assert(beg < (
int)(
sizeof(
key) /
sizeof(*
key)));
707 switch(
key[beg].what)
720 xmlError(ppos,
"Can't create new node");
752 assert(ppos !=
NULL);
755 xmlError(ppos,
"Missing name in endtag");
762 xmlError(ppos,
"Missing '>' in endtag");
767 if ( strcmp(name,
topPstack(ppos)->name) )
769 xmlError(ppos,
"Name of endtag does not match starttag");
794 assert(ppos !=
NULL);
799 xmlError(ppos,
"Missing name in tagstart");
807 xmlError(ppos,
"Can't create new node");
831 assert(ppos !=
NULL);
880 assert(ppos !=
NULL);
885 if ( (c ==
'/') || (c ==
'>') || (c == EOF) )
895 xmlError(ppos,
"Unexpected EOF while in a tag");
908 xmlError(ppos,
"Expected tag end marker '>'");
919 xmlError(ppos,
"No name for attribute");
928 xmlError(ppos,
"Missing attribute value");
937 xmlError(ppos,
"Can't create new attribute");
963 assert(ppos !=
NULL);
966 #ifndef SPEC_LIKE_SPACE_HANDLING 973 while ( (c != EOF) && (c !=
'<') )
975 if ( len + 1 >= size )
988 assert(data !=
NULL);
989 assert(size > len + 1);
991 data[len++] = (char)c;
1020 xmlError(ppos,
"Can't create new node");
1047 switch (ppos->
state)
1065 xmlError(ppos,
"Internal Error, illegal state");
1074 const char* filename
1085 assert( filename !=
NULL );
1086 filenamelen = strlen(filename);
1091 #ifdef SCIP_WITH_ZLIB 1092 if ( access(filename, R_OK) != 0 )
1094 strcat(myfilename,
".gz");
1099 if ( access(myfilename, R_OK) != 0 )
1100 (void)
SCIPstrncpy(myfilename, filename, (
int)filenamelen + 5);
1103 ppos.
fp =
FOPEN(myfilename,
"r");
1120 xmlError(&ppos,
"Can't create new node");
1126 xmlError(&ppos,
"Can't create new attribute");
1141 if ( ! result && (node !=
NULL) )
1143 xmlErrmsg(&ppos,
"Parsing error, processing stopped",
TRUE, __FILE__, __LINE__);
1171 assert(name !=
NULL);
1190 assert(name !=
NULL);
1191 assert(value !=
NULL);
1211 a->next = n->attrlist;
1221 assert(parent !=
NULL);
1222 assert(child !=
NULL);
1224 child->parent = parent;
1225 child->prevsibl = parent->lastchild;
1226 child->nextsibl =
NULL;
1227 parent->lastchild = child;
1229 if ( child->prevsibl !=
NULL )
1230 child->prevsibl->nextsibl = child;
1232 if ( parent->firstchild ==
NULL )
1233 parent->firstchild = child;
1252 assert(a->name !=
NULL);
1253 assert(a->value !=
NULL);
1275 n = node->lastchild;
1286 if ( node->data !=
NULL )
1290 assert(node->name !=
NULL);
1304 assert(root !=
NULL);
1306 for (n = root; n !=
NULL; n = n->nextsibl)
1312 for (a = n->attrlist; a !=
NULL; a = a->next)
1313 infoMessage(
"Attr: %s = [%s]\n", a->name, a->value);
1315 if ( n->firstchild !=
NULL )
1332 assert(node !=
NULL);
1333 assert(name !=
NULL);
1335 for (a = node->attrlist; a !=
NULL; a = a->next)
1337 if ( ! strcmp(name, a->name) )
1343 infoMessage(
"Error: Attribute %s in TAG <%s> not found\n", name, node->name);
1346 return (a ==
NULL) ?
NULL : a->value;
1357 assert(node !=
NULL);
1358 assert(name !=
NULL);
1360 for (n = node; n !=
NULL; n = n->nextsibl)
1362 if ( ! strcmp(name, n->name) )
1375 assert(node !=
NULL);
1376 assert(name !=
NULL);
1390 assert(node !=
NULL);
1391 assert(name !=
NULL);
1393 if ( ! strcmp(name, node->name) )
1396 for (n = node->firstchild; n !=
NULL; n = n->nextsibl)
1417 assert(node !=
NULL);
1418 assert(name !=
NULL);
1420 if ( ! strcmp(name, node->name) )
1423 if ( depth < maxdepth )
1425 for (n = node->firstchild; n !=
NULL; n = n->nextsibl)
1441 assert(node !=
NULL);
1443 return node->nextsibl;
1451 assert(node !=
NULL);
1453 return node->prevsibl;
1461 assert(node !=
NULL);
1463 return node->firstchild;
1471 assert(node !=
NULL);
1473 return node->lastchild;
1481 assert(node !=
NULL);
1491 assert(node !=
NULL);
1493 return node->lineno;
1501 assert(node !=
NULL);
1514 assert(node !=
NULL);
1515 assert(name !=
NULL);
1521 if ( ! strcmp(n->firstchild->name,
"#PCDATA") )
1522 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