|
|
Go to the documentation of this file.
36 #include <sys/types.h>
47 #define NAME_EXT_SIZE 128
48 #define ATTR_EXT_SIZE 4096
49 #define DATA_EXT_SIZE 4096
50 #define LINE_BUF_SIZE 8192
52 #define xmlError(a, b) xmlErrmsg(a, b, FALSE, __FILE__, __LINE__)
103 assert( ppos != NULL );
107 ret = fprintf(stderr, "%s(%d) Error in file %s line %d\n", file, line, ppos-> filename, ppos-> lineno);
110 ret = fprintf(stderr, "%s", ppos-> buf);
113 if ( strchr(ppos-> buf, '\n') == NULL )
117 retc = fputc( '\n', stderr);
121 ret = fprintf(stderr, "%*s\n", ppos-> pos, "^");
124 ret = fprintf(stderr, "%s\n\n", msg);
131 (void) fprintf(stderr, "%s(%d) Error in file %s line %d\n", file, line, ppos-> filename, ppos-> lineno);
133 (void) fprintf(stderr, "%s", ppos-> buf);
135 if ( strchr(ppos-> buf, '\n') == NULL )
137 (void) fputc( '\n', stderr);
140 (void) fprintf(stderr, "%*s\n", ppos-> pos, "^");
142 (void) fprintf(stderr, "%s\n\n", msg);
159 assert(ppos != NULL);
160 assert(node != NULL);
179 assert(ppos != NULL);
197 assert(ppos != NULL);
222 assert(ppos != NULL);
234 assert(ppos != NULL);
238 if ( ppos-> buf[ppos-> pos] == '\0' )
240 #ifdef SCIP_DISABLED_CODE
245 size_t len = (size_t) FREAD(ppos-> buf, sizeof(ppos-> buf) - 1, ppos-> fp);
247 if( len == 0 || len > sizeof(ppos-> buf) - 1 )
250 ppos-> buf[len] = '\0';
254 return ( unsigned char)ppos-> buf[ppos-> pos++];
258 #ifdef SPEC_LIKE_SPACE_HANDLING
271 assert(ppos != NULL);
282 if (((c == '\n') && (ppos-> lastsym == '\r')) || ((c == '\r') && (ppos-> lastsym == '\n')))
310 assert(ppos != NULL);
326 if ((c == '\n') || (c == '\r'))
328 } while((c == ' ') && (ppos-> lastsym == c));
345 assert(ppos != NULL);
359 assert(ppos != NULL);
385 assert(ppos != NULL);
389 if ( ! isalpha(c) && (c != '_') && (c != ':') )
391 xmlError(ppos, "Name starting with illegal charater");
396 while ( isalnum(c) || (c == '_') || (c == ':') || (c == '.') || (c == '-') )
398 if ( len + 1 >= size )
411 assert(name != NULL);
414 name[len++] = (char)c;
421 assert(name != NULL);
451 assert(ppos != NULL);
457 if ( (c != '"') && (c != '\'') )
459 xmlError(ppos, "Atribute value does not start with \" or \'");
479 assert(attr != NULL);
484 if ( (c == stop) || (c == EOF) )
487 attr[len++] = (char)c;
513 assert(ppos != NULL);
522 if ( (c == '>') && (state >= 2) )
525 state = (c == '-') ? state + 1 : 0;
529 xmlError(ppos, "Unexpected EOF in comment");
551 assert(ppos != NULL);
563 if ( (c == '>') && (state >= 2) )
581 assert(data != NULL);
584 data[len++] = (char)c;
586 assert(data != NULL);
592 assert(data != NULL);
594 data[len - 2] = '\0';
600 xmlError(ppos, "Unexpected EOF in CDATA");
613 assert(ppos != NULL);
620 while ( (c != EOF) && (c != '>') );
626 xmlError(ppos, "Unexpected EOF in PI");
650 typedef enum XmlSection XMLSECTION;
658 { "--", IS_COMMENT },
659 { "ATTLIST", IS_ATTLIST },
660 { "DOCTYPE", IS_DOCTYPE },
661 { "ELEMENT", IS_ELEMENT },
662 { "ENTITY", IS_ENTITY },
663 { "NOTATION", IS_NOTATION },
664 { "[CDATA[", IS_CDATA }
673 assert(ppos != NULL);
676 end = (int) ( sizeof(key) / sizeof(key[0])) - 1;
681 for(; (beg <= end) && (c != key[beg].name[k]); beg++)
683 for(; (end >= beg) && (c != key[end].name[k]); end--)
690 xmlError(ppos, "Unknown declaration");
692 while ( (c != EOF) && (c != '>') )
698 assert(beg < ( int)( sizeof(key) / sizeof(*key)));
700 switch(key[beg].what)
713 xmlError(ppos, "Can't create new node");
745 assert(ppos != NULL);
748 xmlError(ppos, "Missing name in endtag");
755 xmlError(ppos, "Missing '>' in endtag");
760 if ( strcmp(name, topPstack(ppos)->name) )
762 xmlError(ppos, "Name of endtag does not match starttag");
786 assert(ppos != NULL);
791 xmlError(ppos, "Missing name in tagstart");
799 xmlError(ppos, "Can't create new node");
823 assert(ppos != NULL);
872 assert(ppos != NULL);
877 if ( (c == '/') || (c == '>') || (c == EOF) )
887 xmlError(ppos, "Unexpected EOF while in a tag");
900 xmlError(ppos, "Expected tag end marker '>'");
911 xmlError(ppos, "No name for attribute");
920 xmlError(ppos, "Missing attribute value");
929 xmlError(ppos, "Can't create new attribute");
955 assert(ppos != NULL);
958 #ifndef SPEC_LIKE_SPACE_HANDLING
965 while ( (c != EOF) && (c != '<') )
967 if ( len + 1 >= size )
980 assert(data != NULL);
981 assert(size > len + 1);
983 data[len++] = (char)c;
1015 xmlError(ppos, "Can't create new node");
1041 switch (ppos-> state)
1059 xmlError(ppos, "Internal Error, illegal state");
1068 const char* filename
1079 assert( filename != NULL );
1080 filenamelen = strlen(filename);
1086 if ( access(filename, R_OK) != 0 )
1088 strcat(myfilename, ".gz");
1093 if ( access(myfilename, R_OK) != 0 )
1094 strcpy(myfilename, filename);
1097 ppos. fp = FOPEN(myfilename, "r");
1114 xmlError(&ppos, "Can't create new node");
1120 xmlError(&ppos, "Can't create new attribute");
1135 if ( ! result && (node != NULL) )
1137 xmlErrmsg(&ppos, "Parsing error, processing stopped", TRUE, __FILE__, __LINE__);
1165 assert(name != NULL);
1184 assert(name != NULL);
1185 assert(value != NULL);
1205 a->next = n->attrlist;
1215 assert(parent != NULL);
1216 assert(child != NULL);
1218 child->parent = parent;
1219 child->prevsibl = parent->lastchild;
1220 child->nextsibl = NULL;
1221 parent->lastchild = child;
1223 if ( child->prevsibl != NULL )
1224 child->prevsibl->nextsibl = child;
1226 if ( parent->firstchild == NULL )
1227 parent->firstchild = child;
1246 assert(a->name != NULL);
1247 assert(a->value != NULL);
1269 n = node->lastchild;
1280 if ( node->data != NULL )
1284 assert(node->name != NULL);
1298 assert(root != NULL);
1300 for (n = root; n != NULL; n = n->nextsibl)
1306 for (a = n->attrlist; a != NULL; a = a->next)
1307 infoMessage( "Attr: %s = [%s]\n", a->name, a->value);
1309 if ( n->firstchild != NULL )
1326 assert(node != NULL);
1327 assert(name != NULL);
1329 for (a = node->attrlist; a != NULL; a = a->next)
1331 if ( ! strcmp(name, a->name) )
1337 infoMessage( "Error: Attribute %s in TAG <%s> not found\n", name, node->name);
1340 return (a == NULL) ? NULL : a->value;
1351 assert(node != NULL);
1352 assert(name != NULL);
1354 for (n = node; n != NULL; n = n->nextsibl)
1356 if ( ! strcmp(name, n->name) )
1369 assert(node != NULL);
1370 assert(name != NULL);
1384 assert(node != NULL);
1385 assert(name != NULL);
1387 if ( ! strcmp(name, node->name) )
1390 for (n = node->firstchild; n != NULL; n = n->nextsibl)
1411 assert(node != NULL);
1412 assert(name != NULL);
1414 if ( ! strcmp(name, node->name) )
1417 if ( depth < maxdepth )
1419 for (n = node->firstchild; n != NULL; n = n->nextsibl)
1435 assert(node != NULL);
1437 return node->nextsibl;
1445 assert(node != NULL);
1447 return node->prevsibl;
1455 assert(node != NULL);
1457 return node->firstchild;
1465 assert(node != NULL);
1467 return node->lastchild;
1475 assert(node != NULL);
1485 assert(node != NULL);
1487 return node->lineno;
1495 assert(node != NULL);
1508 assert(node != NULL);
1509 assert(name != NULL);
1515 if ( ! strcmp(n->firstchild->name, "#PCDATA") )
1516 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)
#define BMSfreeMemoryArray(ptr)
static XML_Bool popPstack(PPOS *ppos)
struct XML_NODE_struct XML_NODE
static XML_Bool doComment(PPOS *ppos)
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
|