SCIP Doxygen Documentation
 
Loading...
Searching...
No Matches
xmlparse.c File Reference
#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_NODEtopPstack (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_NODExmlProcess (const char *filename)
 
XML_NODExmlNewNode (const char *name, int lineno)
 
XML_ATTRxmlNewAttr (const char *name, const char *value)
 
void xmlAddAttr (XML_NODE *n, XML_ATTR *a)
 
void xmlAppendChild (XML_NODE *parent, XML_NODE *child)
 
static void xmlFreeAttr (XML_ATTR *attr)
 
void xmlFreeNode (XML_NODE *node)
 
void xmlShowNode (const XML_NODE *root)
 
const char * xmlGetAttrval (const XML_NODE *node, const char *name)
 
const XML_NODExmlFirstNode (const XML_NODE *node, const char *name)
 
const XML_NODExmlNextNode (const XML_NODE *node, const char *name)
 
const XML_NODExmlFindNode (const XML_NODE *node, const char *name)
 
const XML_NODExmlFindNodeMaxdepth (const XML_NODE *node, const char *name, int depth, int maxdepth)
 
const XML_NODExmlNextSibl (const XML_NODE *node)
 
const XML_NODExmlPrevSibl (const XML_NODE *node)
 
const XML_NODExmlFirstChild (const XML_NODE *node)
 
const XML_NODExmlLastChild (const XML_NODE *node)
 
const char * xmlGetName (const XML_NODE *node)
 
int xmlGetLine (const XML_NODE *node)
 
const char * xmlGetData (const XML_NODE *node)
 
const char * xmlFindPcdata (const XML_NODE *node, const char *name)
 

Macro Definition Documentation

◆ NAME_EXT_SIZE

#define NAME_EXT_SIZE   128

Definition at line 64 of file xmlparse.c.

Referenced by getName().

◆ ATTR_EXT_SIZE

#define ATTR_EXT_SIZE   4096

Definition at line 65 of file xmlparse.c.

Referenced by getAttrval().

◆ DATA_EXT_SIZE

#define DATA_EXT_SIZE   4096

Definition at line 66 of file xmlparse.c.

Referenced by doCdata(), and procPcdata().

◆ LINE_BUF_SIZE

#define LINE_BUF_SIZE   8192

Definition at line 67 of file xmlparse.c.

Referenced by mygetc().

◆ xmlError

#define xmlError ( a,
b )
Value:
xmlErrmsg(a, b, FALSE, __FILE__, __LINE__)
SCIP_VAR * a
SCIP_VAR ** b
#define FALSE
Definition def.h:94
static void xmlErrmsg(PPOS *ppos, const char *msg, XML_Bool msg_only, const char *file, int line)
Definition xmlparse.c:110

Definition at line 69 of file xmlparse.c.

Referenced by doCdata(), doComment(), getAttrval(), getName(), handleDecl(), handleEndtag(), handlePi(), handleStarttag(), popPstack(), procBefore(), procInTag(), procPcdata(), xmlParse(), and xmlProcess().

Typedef Documentation

◆ PSTACK

typedef struct parse_stack_struct PSTACK

Definition at line 73 of file xmlparse.c.

◆ PPOS

typedef struct parse_pos_struct PPOS

Definition at line 74 of file xmlparse.c.

◆ PSTATE

typedef enum parse_state_enum PSTATE

Definition at line 85 of file xmlparse.c.

Enumeration Type Documentation

◆ 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.

Function Documentation

◆ xmlErrmsg()

static void xmlErrmsg ( PPOS * ppos,
const char * msg,
XML_Bool msg_only,
const char * file,
int line )
static

output error message with corresponding line and position

Definition at line 110 of file xmlparse.c.

References assert(), parse_pos_struct::buf, parse_pos_struct::filename, parse_pos_struct::lineno, NULL, parse_pos_struct::pos, and XML_Bool.

Referenced by xmlProcess().

◆ pushPstack()

static XML_Bool pushPstack ( PPOS * ppos,
XML_NODE * node )
static

Push new element on the parse stack.

TRUE if it worked, FAILURE otherwise.

Definition at line 169 of file xmlparse.c.

References ALLOC_FALSE, assert(), BMSallocMemory, debugMessage, parse_stack_struct::next, parse_stack_struct::node, NULL, parse_pos_struct::top, TRUE, and XML_Bool.

Referenced by handleStarttag(), and xmlProcess().

◆ topPstack()

static XML_NODE * topPstack ( const PPOS * ppos)
static

returns top element on stack (which has to be present)

Definition at line 192 of file xmlparse.c.

References assert(), parse_stack_struct::node, NULL, and parse_pos_struct::top.

Referenced by handleDecl(), handleEndtag(), handleStarttag(), procInTag(), and procPcdata().

◆ popPstack()

static XML_Bool popPstack ( PPOS * ppos)
static

remove top element from stack and deletes it

TRUE if ok, FALSE otherwise

Parameters
pposinput stream position

Definition at line 207 of file xmlparse.c.

References assert(), BMSfreeMemory, debugMessage, FALSE, parse_stack_struct::next, parse_stack_struct::node, NULL, result, parse_pos_struct::top, TRUE, XML_Bool, and xmlError.

Referenced by clearPstack(), handleEndtag(), and procInTag().

◆ clearPstack()

static void clearPstack ( PPOS * ppos)
static

remove complete stack

Definition at line 235 of file xmlparse.c.

References assert(), NULL, popPstack(), and parse_pos_struct::top.

Referenced by xmlProcess().

◆ mygetc()

static int mygetc ( PPOS * ppos)
static

Returns the next character from the input buffer and fills the buffer if it is empty (similar to fgetc()).

Definition at line 247 of file xmlparse.c.

References assert(), parse_pos_struct::buf, FGETS, parse_pos_struct::fp, FREAD, LINE_BUF_SIZE, NULL, and parse_pos_struct::pos.

Referenced by getsymbol().

◆ getsymbol()

static int getsymbol ( PPOS * ppos)
static

Read input from fp_in (variant).

Here we convert all LF or CR into SPACE and return maximally one SPACE after the other.

Note
This function counts lines differently. On systems that have only one '\r' as line feed (MAC) it does not count correctly.

Definition at line 321 of file xmlparse.c.

References assert(), c, debugMessage, parse_pos_struct::lastsym, parse_pos_struct::lineno, mygetc(), parse_pos_struct::nextsym, and NULL.

Referenced by doCdata(), doComment(), getAttrval(), getName(), handleDecl(), handlePi(), procBefore(), procInTag(), procPcdata(), and skipSpace().

◆ ungetsymbol()

static void ungetsymbol ( PPOS * ppos,
int c )
static

Reinserts a character into the input stream

Definition at line 357 of file xmlparse.c.

References assert(), c, parse_pos_struct::nextsym, and NULL.

Referenced by getName(), procBefore(), procInTag(), and procPcdata().

◆ skipSpace()

static int skipSpace ( PPOS * ppos)
static

Skip all spaces and return the next non-space character or EOF

Definition at line 370 of file xmlparse.c.

References assert(), c, getsymbol(), and NULL.

Referenced by getAttrval(), handleEndtag(), procBefore(), procInTag(), and procPcdata().

◆ getName()

static char * getName ( PPOS * ppos)
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 393 of file xmlparse.c.

References ALLOC_ABORT, assert(), BMSallocMemoryArray, BMSfreeMemoryArray, BMSreallocMemoryArray, c, getsymbol(), NAME_EXT_SIZE, NULL, ungetsymbol(), and xmlError.

Referenced by handleEndtag(), handleStarttag(), and procInTag().

◆ getAttrval()

static char * getAttrval ( PPOS * ppos)
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 458 of file xmlparse.c.

References ALLOC_ABORT, assert(), ATTR_EXT_SIZE, BMSallocMemoryArray, BMSfreeMemoryArray, BMSreallocMemoryArray, c, getsymbol(), NULL, skipSpace(), and xmlError.

Referenced by procInTag().

◆ doComment()

static XML_Bool doComment ( PPOS * ppos)
static

Skip comment

Return FALSE if an error occurs.

Definition at line 522 of file xmlparse.c.

References assert(), c, FALSE, getsymbol(), NULL, result, TRUE, XML_Bool, and xmlError.

Referenced by handleDecl().

◆ doCdata()

static char * doCdata ( PPOS * ppos)
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 558 of file xmlparse.c.

References ALLOC_ABORT, assert(), BMSallocMemoryArray, BMSfreeMemoryArray, BMSreallocMemoryArray, c, DATA_EXT_SIZE, getsymbol(), NULL, and xmlError.

Referenced by handleDecl().

◆ handlePi()

static void handlePi ( PPOS * ppos)
static

Handle processing instructions (skipping)

Definition at line 624 of file xmlparse.c.

References assert(), c, getsymbol(), NULL, parse_pos_struct::state, XML_STATE_BEFORE, XML_STATE_ERROR, XML_STATE_PCDATA, and xmlError.

Referenced by procBefore().

◆ handleDecl()

static void handleDecl ( PPOS * ppos)
static

Handles declarations that start with a <!.

This includes comments. Does currenlty not work very well, because of DTDs.

Definition at line 653 of file xmlparse.c.

References assert(), BMSduplicateMemoryArray, BMSfreeMemoryArray, c, doCdata(), doComment(), getsymbol(), parse_pos_struct::lineno, NULL, parse_pos_struct::state, topPstack(), XML_STATE_BEFORE, XML_STATE_ERROR, xmlAppendChild(), xmlError, and xmlNewNode().

Referenced by procBefore().

◆ handleEndtag()

static void handleEndtag ( PPOS * ppos)
static

◆ handleStarttag()

static void handleStarttag ( PPOS * ppos)
static

◆ procBefore()

static void procBefore ( PPOS * ppos)
static

Checks for next tag

Parameters
pposinput stream position

Definition at line 837 of file xmlparse.c.

References assert(), c, getsymbol(), handleDecl(), handleEndtag(), handlePi(), handleStarttag(), NULL, skipSpace(), parse_pos_struct::state, ungetsymbol(), XML_STATE_BEFORE, XML_STATE_ERROR, and xmlError.

Referenced by xmlParse().

◆ procInTag()

static void procInTag ( PPOS * ppos)
static

◆ procPcdata()

◆ xmlParse()

static XML_Bool xmlParse ( PPOS * ppos)
static

Parse input stream

Parameters
pposinput stream position

Definition at line 1049 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, and xmlError.

Referenced by xmlProcess().

◆ xmlProcess()

◆ xmlNewNode()

XML_NODE * xmlNewNode ( const char * name,
int lineno )

create new node

Definition at line 1176 of file xmlparse.c.

References assert(), BMSallocMemory, BMSclearMemory, BMSduplicateMemoryArray, and NULL.

Referenced by handleDecl(), handleStarttag(), procPcdata(), and xmlProcess().

◆ xmlNewAttr()

XML_ATTR * xmlNewAttr ( const char * name,
const char * value )

create new attribute

Definition at line 1195 of file xmlparse.c.

References a, assert(), BMSallocMemory, BMSclearMemory, BMSduplicateMemoryArray, and NULL.

Referenced by procInTag(), and xmlProcess().

◆ xmlAddAttr()

void xmlAddAttr ( XML_NODE * n,
XML_ATTR * a )

add attribute

Definition at line 1215 of file xmlparse.c.

References a, assert(), and NULL.

Referenced by procInTag(), and xmlProcess().

◆ xmlAppendChild()

void xmlAppendChild ( XML_NODE * parent,
XML_NODE * child )

append child node

Definition at line 1228 of file xmlparse.c.

References assert(), and NULL.

Referenced by handleDecl(), handleStarttag(), and procPcdata().

◆ xmlFreeAttr()

static void xmlFreeAttr ( XML_ATTR * attr)
static

free attribute

Definition at line 1250 of file xmlparse.c.

References a, assert(), b, BMSfreeMemory, BMSfreeMemoryArray, and NULL.

Referenced by xmlFreeNode().

◆ xmlFreeNode()

void xmlFreeNode ( XML_NODE * node)

◆ xmlShowNode()

void xmlShowNode ( const XML_NODE * root)

output node

Definition at line 1309 of file xmlparse.c.

References a, assert(), infoMessage, NULL, and xmlShowNode().

Referenced by SCIP_DECL_READERREAD(), and xmlShowNode().

◆ xmlGetAttrval()

const char * xmlGetAttrval ( const XML_NODE * node,
const char * name )

◆ xmlFirstNode()

const XML_NODE * xmlFirstNode ( const XML_NODE * node,
const char * name )

return first node

Definition at line 1362 of file xmlparse.c.

References assert(), and NULL.

Referenced by xmlNextNode().

◆ xmlNextNode()

const XML_NODE * xmlNextNode ( const XML_NODE * node,
const char * name )

return next node

Definition at line 1382 of file xmlparse.c.

References assert(), NULL, and xmlFirstNode().

◆ xmlFindNode()

const XML_NODE * xmlFindNode ( const XML_NODE * node,
const char * name )

find node

Definition at line 1394 of file xmlparse.c.

References assert(), NULL, r, and xmlFindNode().

Referenced by xmlFindNode(), and xmlFindPcdata().

◆ xmlFindNodeMaxdepth()

const XML_NODE * xmlFindNodeMaxdepth ( const XML_NODE * node,
const char * name,
int depth,
int maxdepth )

find node with bound on the depth

Parameters
nodecurrent node - use start node to begin
namename of tag to search for
depthcurrent depth - start with 0 for root
maxdepthmaximal depth

Definition at line 1419 of file xmlparse.c.

References assert(), depth, maxdepth, NULL, r, and xmlFindNodeMaxdepth().

Referenced by readConstraints(), readLinearCoefs(), readNConstraints(), readNonlinearExprs(), readObjective(), readQuadraticCoefs(), readSOScons(), readVariables(), readXmlSolFile(), SCIP_DECL_READERREAD(), and xmlFindNodeMaxdepth().

◆ xmlNextSibl()

const XML_NODE * xmlNextSibl ( const XML_NODE * node)

◆ xmlPrevSibl()

const XML_NODE * xmlPrevSibl ( const XML_NODE * node)

return previous sibling

Definition at line 1459 of file xmlparse.c.

References assert(), and NULL.

◆ xmlFirstChild()

const XML_NODE * xmlFirstChild ( const XML_NODE * node)

◆ xmlLastChild()

const XML_NODE * xmlLastChild ( const XML_NODE * node)

return last child

Definition at line 1479 of file xmlparse.c.

References assert(), and NULL.

◆ xmlGetName()

const char * xmlGetName ( const XML_NODE * node)

return name of node

Definition at line 1489 of file xmlparse.c.

References assert(), and NULL.

Referenced by readExpression(), readLinearCoefs(), readNonlinearExprs(), readQuadraticCoefs(), and readSOScons().

◆ xmlGetLine()

int xmlGetLine ( const XML_NODE * node)

get line number

Definition at line 1499 of file xmlparse.c.

References assert(), and NULL.

◆ xmlGetData()

const char * xmlGetData ( const XML_NODE * node)

get data

Definition at line 1509 of file xmlparse.c.

References assert(), and NULL.

Referenced by readLinearCoefs(), readObjective(), and SCIP_DECL_READERREAD().

◆ xmlFindPcdata()

const char * xmlFindPcdata ( const XML_NODE * node,
const char * name )

find PCDATA

Definition at line 1519 of file xmlparse.c.

References assert(), NULL, and xmlFindNode().