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--)
698 xmlError(ppos,
"Unknown declaration");
700 while ( (c != EOF) && (c !=
'>') )
706 assert(beg < (
int)(
sizeof(
key) /
sizeof(*
key)));
708 switch(
key[beg].what)
721 xmlError(ppos,
"Can't create new node");
753 assert(ppos !=
NULL);
756 xmlError(ppos,
"Missing name in endtag");
763 xmlError(ppos,
"Missing '>' in endtag");
768 if ( strcmp(name,
topPstack(ppos)->name) )
770 xmlError(ppos,
"Name of endtag does not match starttag");
795 assert(ppos !=
NULL);
800 xmlError(ppos,
"Missing name in tagstart");
808 xmlError(ppos,
"Can't create new node");
832 assert(ppos !=
NULL);
881 assert(ppos !=
NULL);
886 if ( (c ==
'/') || (c ==
'>') || (c == EOF) )
896 xmlError(ppos,
"Unexpected EOF while in a tag");
909 xmlError(ppos,
"Expected tag end marker '>'");
920 xmlError(ppos,
"No name for attribute");
929 xmlError(ppos,
"Missing attribute value");
938 xmlError(ppos,
"Can't create new attribute");
964 assert(ppos !=
NULL);
967 #ifndef SPEC_LIKE_SPACE_HANDLING 974 while ( (c != EOF) && (c !=
'<') )
976 if ( len + 1 >= size )
989 assert(data !=
NULL);
990 assert(size > len + 1);
992 data[len++] = (char)c;
1021 xmlError(ppos,
"Can't create new node");
1048 switch (ppos->
state)
1066 xmlError(ppos,
"Internal Error, illegal state");
1075 const char* filename
1086 assert( filename !=
NULL );
1087 filenamelen = strlen(filename);
1092 #ifdef SCIP_WITH_ZLIB 1093 if ( access(filename, R_OK) != 0 )
1095 strcat(myfilename,
".gz");
1100 if ( access(myfilename, R_OK) != 0 )
1101 (void)
SCIPstrncpy(myfilename, filename, (
int)filenamelen + 5);
1104 ppos.
fp =
FOPEN(myfilename,
"r");
1121 xmlError(&ppos,
"Can't create new node");
1127 xmlError(&ppos,
"Can't create new attribute");
1142 if ( ! result && (node !=
NULL) )
1144 xmlErrmsg(&ppos,
"Parsing error, processing stopped",
TRUE, __FILE__, __LINE__);
1172 assert(name !=
NULL);
1191 assert(name !=
NULL);
1192 assert(value !=
NULL);
1212 a->next = n->attrlist;
1222 assert(parent !=
NULL);
1223 assert(child !=
NULL);
1225 child->parent = parent;
1226 child->prevsibl = parent->lastchild;
1227 child->nextsibl =
NULL;
1228 parent->lastchild = child;
1230 if ( child->prevsibl !=
NULL )
1231 child->prevsibl->nextsibl = child;
1233 if ( parent->firstchild ==
NULL )
1234 parent->firstchild = child;
1253 assert(a->name !=
NULL);
1254 assert(a->value !=
NULL);
1276 n = node->lastchild;
1287 if ( node->data !=
NULL )
1291 assert(node->name !=
NULL);
1305 assert(root !=
NULL);
1307 for (n = root; n !=
NULL; n = n->nextsibl)
1313 for (a = n->attrlist; a !=
NULL; a = a->next)
1314 infoMessage(
"Attr: %s = [%s]\n", a->name, a->value);
1316 if ( n->firstchild !=
NULL )
1333 assert(node !=
NULL);
1334 assert(name !=
NULL);
1336 for (a = node->attrlist; a !=
NULL; a = a->next)
1338 if ( ! strcmp(name, a->name) )
1344 infoMessage(
"Error: Attribute %s in TAG <%s> not found\n", name, node->name);
1347 return (a ==
NULL) ?
NULL : a->value;
1358 assert(node !=
NULL);
1359 assert(name !=
NULL);
1361 for (n = node; n !=
NULL; n = n->nextsibl)
1363 if ( ! strcmp(name, n->name) )
1376 assert(node !=
NULL);
1377 assert(name !=
NULL);
1391 assert(node !=
NULL);
1392 assert(name !=
NULL);
1394 if ( ! strcmp(name, node->name) )
1397 for (n = node->firstchild; n !=
NULL; n = n->nextsibl)
1418 assert(node !=
NULL);
1419 assert(name !=
NULL);
1421 if ( ! strcmp(name, node->name) )
1424 if ( depth < maxdepth )
1426 for (n = node->firstchild; n !=
NULL; n = n->nextsibl)
1442 assert(node !=
NULL);
1444 return node->nextsibl;
1452 assert(node !=
NULL);
1454 return node->prevsibl;
1462 assert(node !=
NULL);
1464 return node->firstchild;
1472 assert(node !=
NULL);
1474 return node->lastchild;
1482 assert(node !=
NULL);
1492 assert(node !=
NULL);
1494 return node->lineno;
1502 assert(node !=
NULL);
1515 assert(node !=
NULL);
1516 assert(name !=
NULL);
1522 if ( ! strcmp(n->firstchild->name,
"#PCDATA") )
1523 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