#include <blockmemshell/memory.h>#include "xml.h"#include "xmldef.h"#include "scip/misc.h"#include <sys/types.h>#include <stdio.h>#include <stdlib.h>#include <assert.h>#include <ctype.h>#include <string.h>Go to the source code of this file.
Data Structures | |
| struct | parse_stack_struct |
| struct | parse_pos_struct |
Macros | |
| #define | NAME_EXT_SIZE 128 |
| #define | ATTR_EXT_SIZE 4096 |
| #define | DATA_EXT_SIZE 4096 |
| #define | LINE_BUF_SIZE 8192 |
| #define | xmlError(a, b) |
Functions | |
| static void | xmlErrmsg (PPOS *ppos, const char *msg, XML_Bool msg_only, const char *file, int line) |
| static XML_Bool | pushPstack (PPOS *ppos, XML_NODE *node) |
| static XML_NODE * | topPstack (const PPOS *ppos) |
| static XML_Bool | popPstack (PPOS *ppos) |
| static void | clearPstack (PPOS *ppos) |
| static int | mygetc (PPOS *ppos) |
| static int | getsymbol (PPOS *ppos) |
| static void | ungetsymbol (PPOS *ppos, int c) |
| static int | skipSpace (PPOS *ppos) |
| static char * | getName (PPOS *ppos) |
| static char * | getAttrval (PPOS *ppos) |
| static XML_Bool | doComment (PPOS *ppos) |
| static char * | doCdata (PPOS *ppos) |
| static void | handlePi (PPOS *ppos) |
| static void | handleDecl (PPOS *ppos) |
| static void | handleEndtag (PPOS *ppos) |
| static void | handleStarttag (PPOS *ppos) |
| static void | procBefore (PPOS *ppos) |
| static void | procInTag (PPOS *ppos) |
| static void | procPcdata (PPOS *ppos) |
| static XML_Bool | xmlParse (PPOS *ppos) |
| XML_NODE * | SCIPxmlProcess (const char *filename) |
| XML_NODE * | SCIPxmlNewNode (const char *name, int lineno) |
| XML_ATTR * | SCIPxmlNewAttr (const char *name, const char *value) |
| void | SCIPxmlAddAttr (XML_NODE *n, XML_ATTR *a) |
| void | SCIPxmlAppendChild (XML_NODE *parent, XML_NODE *child) |
| static void | xmlFreeAttr (XML_ATTR *attr) |
| void | SCIPxmlFreeNode (XML_NODE *node) |
| void | SCIPxmlShowNode (const XML_NODE *root) |
| const char * | SCIPxmlGetAttrval (const XML_NODE *node, const char *name) |
| const XML_NODE * | SCIPxmlFirstNode (const XML_NODE *node, const char *name) |
| const XML_NODE * | SCIPxmlNextNode (const XML_NODE *node, const char *name) |
| const XML_NODE * | SCIPxmlFindNode (const XML_NODE *node, const char *name) |
| const XML_NODE * | SCIPxmlFindNodeMaxdepth (const XML_NODE *node, const char *name, int depth, int maxdepth) |
| const XML_NODE * | SCIPxmlNextSibl (const XML_NODE *node) |
| const XML_NODE * | SCIPxmlPrevSibl (const XML_NODE *node) |
| const XML_NODE * | SCIPxmlFirstChild (const XML_NODE *node) |
| const XML_NODE * | SCIPxmlLastChild (const XML_NODE *node) |
| const char * | SCIPxmlGetName (const XML_NODE *node) |
| int | SCIPxmlGetLine (const XML_NODE *node) |
| const char * | SCIPxmlGetData (const XML_NODE *node) |
| const char * | SCIPxmlFindPcdata (const XML_NODE *node, const char *name) |
| #define NAME_EXT_SIZE 128 |
Definition at line 64 of file xmlparse.c.
Referenced by getName().
| #define ATTR_EXT_SIZE 4096 |
Definition at line 65 of file xmlparse.c.
Referenced by getAttrval().
| #define DATA_EXT_SIZE 4096 |
Definition at line 66 of file xmlparse.c.
Referenced by doCdata(), and procPcdata().
| #define LINE_BUF_SIZE 8192 |
Definition at line 67 of file xmlparse.c.
Referenced by mygetc().
Definition at line 69 of file xmlparse.c.
Referenced by doCdata(), doComment(), getAttrval(), getName(), handleDecl(), handleEndtag(), handlePi(), handleStarttag(), popPstack(), procBefore(), procInTag(), procPcdata(), SCIPxmlProcess(), and xmlParse().
| typedef struct parse_stack_struct PSTACK |
Definition at line 73 of file xmlparse.c.
| typedef struct parse_pos_struct PPOS |
Definition at line 74 of file xmlparse.c.
| typedef enum parse_state_enum PSTATE |
Definition at line 85 of file xmlparse.c.
| enum parse_state_enum |
state of the parser
| Enumerator | |
|---|---|
| XML_STATE_ERROR | |
| XML_STATE_BEFORE | |
| XML_STATE_IN_TAG | |
| XML_STATE_PCDATA | |
| XML_STATE_EOF | |
Definition at line 77 of file xmlparse.c.
|
static |
output error message with corresponding line and position
Definition at line 111 of file xmlparse.c.
References assert(), parse_pos_struct::buf, parse_pos_struct::filename, parse_pos_struct::lineno, NULL, parse_pos_struct::pos, XML_Bool, and xmlErrmsg().
Referenced by SCIPxmlProcess(), and xmlErrmsg().
Push new element on the parse stack.
TRUE if it worked, FAILURE otherwise.
Definition at line 170 of file xmlparse.c.
References ALLOC_FALSE, assert(), BMSallocMemory, debugMessage, parse_stack_struct::next, parse_stack_struct::node, NULL, pushPstack(), parse_pos_struct::top, TRUE, and XML_Bool.
Referenced by handleStarttag(), pushPstack(), and SCIPxmlProcess().
returns top element on stack (which has to be present)
Definition at line 194 of file xmlparse.c.
References assert(), parse_stack_struct::node, NULL, parse_pos_struct::top, and topPstack().
Referenced by handleDecl(), handleEndtag(), handleStarttag(), procInTag(), procPcdata(), and topPstack().
remove top element from stack and deletes it
TRUE if ok, FALSE otherwise
| ppos | input stream position |
Definition at line 209 of file xmlparse.c.
References assert(), BMSfreeMemory, debugMessage, FALSE, parse_stack_struct::next, parse_stack_struct::node, NULL, popPstack(), result, parse_pos_struct::top, TRUE, XML_Bool, and xmlError.
Referenced by clearPstack(), handleEndtag(), popPstack(), and procInTag().
|
static |
remove complete stack
Definition at line 237 of file xmlparse.c.
References assert(), clearPstack(), NULL, popPstack(), and parse_pos_struct::top.
Referenced by clearPstack(), and SCIPxmlProcess().
|
static |
Returns the next character from the input buffer and fills the buffer if it is empty (similar to fgetc()).
Definition at line 249 of file xmlparse.c.
References assert(), parse_pos_struct::buf, FGETS, parse_pos_struct::fp, FREAD, LINE_BUF_SIZE, mygetc(), NULL, and parse_pos_struct::pos.
Referenced by getsymbol(), and mygetc().
|
static |
Read input from fp_in (variant).
Here we convert all LF or CR into SPACE and return maximally one SPACE after the other.
Definition at line 323 of file xmlparse.c.
References assert(), c, debugMessage, getsymbol(), parse_pos_struct::lastsym, parse_pos_struct::lineno, mygetc(), parse_pos_struct::nextsym, and NULL.
Referenced by doCdata(), doComment(), getAttrval(), getName(), getsymbol(), handleDecl(), handlePi(), procBefore(), procInTag(), procPcdata(), and skipSpace().
|
static |
Reinserts a character into the input stream
Definition at line 359 of file xmlparse.c.
References assert(), c, parse_pos_struct::nextsym, NULL, and ungetsymbol().
Referenced by getName(), procBefore(), procInTag(), procPcdata(), and ungetsymbol().
|
static |
Skip all spaces and return the next non-space character or EOF
Definition at line 372 of file xmlparse.c.
References assert(), c, getsymbol(), NULL, and skipSpace().
Referenced by getAttrval(), handleEndtag(), procBefore(), procInTag(), procPcdata(), and skipSpace().
|
static |
Get name of a TAG or attribute from the input stream.
Either it returns a pointer to allocated memory which contains the name or it returns NULL if there is some error.
Definition at line 395 of file xmlparse.c.
References ALLOC_ABORT, assert(), BMSallocMemoryArray, BMSfreeMemoryArray, BMSreallocMemoryArray, c, getName(), getsymbol(), NAME_EXT_SIZE, NULL, ungetsymbol(), and xmlError.
Referenced by getName(), handleEndtag(), handleStarttag(), and procInTag().
|
static |
Read the value of an attribute from the input stream.
The value has to be between two " or ' (the other character is then valid as well). The function returns a pointer to allocated memory containing the value or it returns NULL in case of an error.
Definition at line 460 of file xmlparse.c.
References ALLOC_ABORT, assert(), ATTR_EXT_SIZE, BMSallocMemoryArray, BMSfreeMemoryArray, BMSreallocMemoryArray, c, getAttrval(), getsymbol(), NULL, skipSpace(), and xmlError.
Referenced by getAttrval(), and procInTag().
Skip comment
Return FALSE if an error occurs.
Definition at line 524 of file xmlparse.c.
References assert(), c, doComment(), FALSE, getsymbol(), NULL, result, TRUE, XML_Bool, and xmlError.
Referenced by doComment(), and handleDecl().
|
static |
Handles a CDATA section.
Returns a pointer to allocated memory containing the data of this section or NULL in case of an error.
Definition at line 560 of file xmlparse.c.
References ALLOC_ABORT, assert(), BMSallocMemoryArray, BMSfreeMemoryArray, BMSreallocMemoryArray, c, DATA_EXT_SIZE, doCdata(), getsymbol(), NULL, and xmlError.
Referenced by doCdata(), and handleDecl().
|
static |
Handle processing instructions (skipping)
Definition at line 626 of file xmlparse.c.
References assert(), c, getsymbol(), handlePi(), NULL, parse_pos_struct::state, XML_STATE_BEFORE, XML_STATE_ERROR, XML_STATE_PCDATA, and xmlError.
Referenced by handlePi(), and procBefore().
|
static |
Handles declarations that start with a <!.
This includes comments. Does currenlty not work very well, because of DTDs.
Definition at line 655 of file xmlparse.c.
References assert(), BMSduplicateMemoryArray, BMSfreeMemoryArray, c, doCdata(), doComment(), getsymbol(), handleDecl(), parse_pos_struct::lineno, NULL, SCIPxmlAppendChild(), SCIPxmlNewNode(), parse_pos_struct::state, topPstack(), XML_STATE_BEFORE, XML_STATE_ERROR, and xmlError.
Referenced by handleDecl(), and procBefore().
|
static |
Handle end tag
Definition at line 759 of file xmlparse.c.
References assert(), BMSfreeMemoryArray, c, getName(), handleEndtag(), NULL, popPstack(), skipSpace(), parse_pos_struct::state, topPstack(), XML_STATE_ERROR, XML_STATE_PCDATA, and xmlError.
Referenced by handleEndtag(), and procBefore().
|
static |
Handle start tag
Definition at line 801 of file xmlparse.c.
References assert(), BMSfreeMemoryArray, getName(), handleStarttag(), parse_pos_struct::lineno, NULL, pushPstack(), SCIPxmlAppendChild(), SCIPxmlNewNode(), parse_pos_struct::state, topPstack(), XML_STATE_ERROR, XML_STATE_IN_TAG, and xmlError.
Referenced by handleStarttag(), and procBefore().
|
static |
Checks for next tag
| ppos | input stream position |
Definition at line 839 of file xmlparse.c.
References assert(), c, getsymbol(), handleDecl(), handleEndtag(), handlePi(), handleStarttag(), NULL, procBefore(), skipSpace(), parse_pos_struct::state, ungetsymbol(), XML_STATE_BEFORE, XML_STATE_ERROR, and xmlError.
Referenced by procBefore(), and xmlParse().
|
static |
Process tag
| ppos | input stream position |
Definition at line 884 of file xmlparse.c.
References assert(), BMSfreeMemoryArray, c, FALSE, getAttrval(), getName(), getsymbol(), NULL, popPstack(), procInTag(), SCIPxmlAddAttr(), SCIPxmlNewAttr(), skipSpace(), parse_pos_struct::state, topPstack(), TRUE, ungetsymbol(), XML_Bool, XML_STATE_ERROR, XML_STATE_IN_TAG, XML_STATE_PCDATA, and xmlError.
Referenced by procInTag(), and xmlParse().
|
static |
| ppos | input stream position |
Definition at line 967 of file xmlparse.c.
References ALLOC_ABORT, assert(), BMSallocMemoryArray, BMSduplicateMemoryArray, BMSfreeMemoryArray, BMSreallocMemoryArray, c, DATA_EXT_SIZE, getsymbol(), parse_pos_struct::lineno, NULL, procPcdata(), SCIPxmlAppendChild(), SCIPxmlNewNode(), skipSpace(), parse_pos_struct::state, topPstack(), ungetsymbol(), XML_STATE_BEFORE, XML_STATE_EOF, XML_STATE_ERROR, XML_STATE_PCDATA, and xmlError.
Referenced by procPcdata(), and xmlParse().
Parse input stream
| ppos | input stream position |
Definition at line 1051 of file xmlparse.c.
References debugMessage, FALSE, procBefore(), procInTag(), procPcdata(), parse_pos_struct::state, TRUE, XML_Bool, XML_STATE_BEFORE, XML_STATE_EOF, XML_STATE_ERROR, XML_STATE_IN_TAG, XML_STATE_PCDATA, xmlError, and xmlParse().
Referenced by SCIPxmlProcess(), and xmlParse().
| XML_NODE * SCIPxmlProcess | ( | const char * | filename | ) |
Parse file
| filename | XML file name |
Definition at line 1089 of file xmlparse.c.
References assert(), BMSallocMemoryArray, BMScopyMemoryArray, BMSfreeMemoryArray, parse_pos_struct::buf, clearPstack(), FALSE, FCLOSE, parse_pos_struct::filename, FOPEN, parse_pos_struct::fp, parse_pos_struct::lastsym, parse_pos_struct::lineno, parse_pos_struct::nextsym, NULL, parse_pos_struct::pos, pushPstack(), result, SCIPstrncpy(), SCIPxmlAddAttr(), SCIPxmlFreeNode(), SCIPxmlNewAttr(), SCIPxmlNewNode(), SCIPxmlProcess(), parse_pos_struct::state, parse_pos_struct::top, TRUE, XML_Bool, XML_STATE_BEFORE, xmlErrmsg(), xmlError, and xmlParse().
Referenced by readXmlSolFile(), SCIP_DECL_READERREAD(), and SCIPxmlProcess().
| XML_NODE * SCIPxmlNewNode | ( | const char * | name, |
| int | lineno ) |
create new node
Definition at line 1172 of file xmlparse.c.
References assert(), BMSallocMemory, BMSclearMemory, BMSduplicateMemoryArray, NULL, and SCIPxmlNewNode().
Referenced by handleDecl(), handleStarttag(), procPcdata(), SCIPxmlNewNode(), and SCIPxmlProcess().
| XML_ATTR * SCIPxmlNewAttr | ( | const char * | name, |
| const char * | value ) |
create new attribute
Definition at line 1191 of file xmlparse.c.
References a, assert(), BMSallocMemory, BMSclearMemory, BMSduplicateMemoryArray, SCIP_Var::name, NULL, and SCIPxmlNewAttr().
Referenced by procInTag(), SCIPxmlNewAttr(), and SCIPxmlProcess().
add attribute
Definition at line 1211 of file xmlparse.c.
References a, assert(), NULL, and SCIPxmlAddAttr().
Referenced by procInTag(), SCIPxmlAddAttr(), and SCIPxmlProcess().
append child node
Definition at line 1224 of file xmlparse.c.
References assert(), NULL, and SCIPxmlAppendChild().
Referenced by handleDecl(), handleStarttag(), procPcdata(), and SCIPxmlAppendChild().
|
static |
free attribute
Definition at line 1246 of file xmlparse.c.
References a, assert(), b, BMSfreeMemory, BMSfreeMemoryArray, SCIP_Var::name, NULL, and xmlFreeAttr().
Referenced by SCIPxmlFreeNode(), and xmlFreeAttr().
| void SCIPxmlFreeNode | ( | XML_NODE * | node | ) |
free node
Definition at line 1271 of file xmlparse.c.
References assert(), BMSfreeMemory, BMSfreeMemoryArray, NULL, SCIPxmlFreeNode(), and xmlFreeAttr().
Referenced by readXmlSolFile(), SCIP_DECL_READERREAD(), SCIPxmlFreeNode(), and SCIPxmlProcess().
| void SCIPxmlShowNode | ( | const XML_NODE * | root | ) |
output node
Definition at line 1305 of file xmlparse.c.
References a, assert(), infoMessage, SCIP_Var::name, NULL, and SCIPxmlShowNode().
Referenced by SCIP_DECL_READERREAD(), and SCIPxmlShowNode().
| const char * SCIPxmlGetAttrval | ( | const XML_NODE * | node, |
| const char * | name ) |
get attribute value
Definition at line 1333 of file xmlparse.c.
References a, assert(), infoMessage, SCIP_Var::name, NULL, and SCIPxmlGetAttrval().
Referenced by readConstraints(), readExpression(), readLinearCoefs(), readMultIncr(), readNConstraints(), readNonlinearExprs(), readObjective(), readQuadraticCoefs(), readSOScons(), readVariables(), readXmlSolFile(), and SCIPxmlGetAttrval().
return first node
Definition at line 1358 of file xmlparse.c.
References assert(), NULL, and SCIPxmlFirstNode().
Referenced by SCIPxmlFirstNode(), and SCIPxmlNextNode().
return next node
Definition at line 1378 of file xmlparse.c.
References assert(), NULL, SCIPxmlFirstNode(), and SCIPxmlNextNode().
Referenced by SCIPxmlNextNode().
find node
Definition at line 1390 of file xmlparse.c.
References assert(), NULL, r, and SCIPxmlFindNode().
Referenced by SCIPxmlFindNode(), and SCIPxmlFindPcdata().
| const XML_NODE * SCIPxmlFindNodeMaxdepth | ( | const XML_NODE * | node, |
| const char * | name, | ||
| int | depth, | ||
| int | maxdepth ) |
find node with bound on the depth
| node | current node - use start node to begin |
| name | name of tag to search for |
| depth | current depth - start with 0 for root |
| maxdepth | maximal depth |
Definition at line 1415 of file xmlparse.c.
References assert(), depth, maxdepth, NULL, r, and SCIPxmlFindNodeMaxdepth().
Referenced by readConstraints(), readLinearCoefs(), readNConstraints(), readNonlinearExprs(), readObjective(), readQuadraticCoefs(), readSOScons(), readVariables(), readXmlSolFile(), SCIP_DECL_READERREAD(), and SCIPxmlFindNodeMaxdepth().
return next sibling
Definition at line 1445 of file xmlparse.c.
References assert(), NULL, and SCIPxmlNextSibl().
Referenced by readConstraints(), readExpression(), readLinearCoefs(), readNonlinearExprs(), readObjective(), readQuadraticCoefs(), readSOScons(), readVariables(), readXmlSolFile(), and SCIPxmlNextSibl().
return previous sibling
Definition at line 1455 of file xmlparse.c.
References assert(), NULL, and SCIPxmlPrevSibl().
Referenced by SCIPxmlPrevSibl().
return first child
Definition at line 1465 of file xmlparse.c.
References assert(), NULL, and SCIPxmlFirstChild().
Referenced by readConstraints(), readExpression(), readLinearCoefs(), readNonlinearExprs(), readObjective(), readQuadraticCoefs(), readSOScons(), readVariables(), readXmlSolFile(), SCIP_DECL_READERREAD(), and SCIPxmlFirstChild().
return last child
Definition at line 1475 of file xmlparse.c.
References assert(), NULL, and SCIPxmlLastChild().
Referenced by SCIPxmlLastChild().
| const char * SCIPxmlGetName | ( | const XML_NODE * | node | ) |
return name of node
Definition at line 1485 of file xmlparse.c.
References assert(), NULL, and SCIPxmlGetName().
Referenced by readExpression(), readLinearCoefs(), readNonlinearExprs(), readQuadraticCoefs(), readSOScons(), and SCIPxmlGetName().
| int SCIPxmlGetLine | ( | const XML_NODE * | node | ) |
get line number
Definition at line 1495 of file xmlparse.c.
References assert(), NULL, and SCIPxmlGetLine().
Referenced by SCIPxmlGetLine().
| const char * SCIPxmlGetData | ( | const XML_NODE * | node | ) |
get data
Definition at line 1505 of file xmlparse.c.
References assert(), NULL, and SCIPxmlGetData().
Referenced by readLinearCoefs(), readObjective(), SCIP_DECL_READERREAD(), and SCIPxmlGetData().
| const char * SCIPxmlFindPcdata | ( | const XML_NODE * | node, |
| const char * | name ) |
find PCDATA
Definition at line 1515 of file xmlparse.c.
References assert(), NULL, SCIPxmlFindNode(), and SCIPxmlFindPcdata().
Referenced by SCIPxmlFindPcdata().