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");
787 assert(ppos !=
NULL);
792 xmlError(ppos,
"Missing name in tagstart");
800 xmlError(ppos,
"Can't create new node");
824 assert(ppos !=
NULL);
873 assert(ppos !=
NULL);
878 if ( (c ==
'/') || (c ==
'>') || (c == EOF) )
888 xmlError(ppos,
"Unexpected EOF while in a tag");
901 xmlError(ppos,
"Expected tag end marker '>'");
912 xmlError(ppos,
"No name for attribute");
921 xmlError(ppos,
"Missing attribute value");
930 xmlError(ppos,
"Can't create new attribute");
956 assert(ppos !=
NULL);
959 #ifndef SPEC_LIKE_SPACE_HANDLING 966 while ( (c != EOF) && (c !=
'<') )
968 if ( len + 1 >= size )
981 assert(data !=
NULL);
982 assert(size > len + 1);
984 data[len++] = (char)c;
1016 xmlError(ppos,
"Can't create new node");
1043 switch (ppos->
state)
1061 xmlError(ppos,
"Internal Error, illegal state");
1070 const char* filename
1081 assert( filename !=
NULL );
1082 filenamelen = strlen(filename);
1088 if ( access(filename, R_OK) != 0 )
1090 strcat(myfilename,
".gz");
1095 if ( access(myfilename, R_OK) != 0 )
1096 strcpy(myfilename, filename);
1099 ppos.
fp =
FOPEN(myfilename,
"r");
1116 xmlError(&ppos,
"Can't create new node");
1122 xmlError(&ppos,
"Can't create new attribute");
1137 if ( ! result && (node !=
NULL) )
1139 xmlErrmsg(&ppos,
"Parsing error, processing stopped",
TRUE, __FILE__, __LINE__);
1167 assert(name !=
NULL);
1186 assert(name !=
NULL);
1187 assert(value !=
NULL);
1207 a->next = n->attrlist;
1217 assert(parent !=
NULL);
1218 assert(child !=
NULL);
1220 child->parent = parent;
1221 child->prevsibl = parent->lastchild;
1222 child->nextsibl =
NULL;
1223 parent->lastchild = child;
1225 if ( child->prevsibl !=
NULL )
1226 child->prevsibl->nextsibl = child;
1228 if ( parent->firstchild ==
NULL )
1229 parent->firstchild = child;
1248 assert(a->name !=
NULL);
1249 assert(a->value !=
NULL);
1271 n = node->lastchild;
1282 if ( node->data !=
NULL )
1286 assert(node->name !=
NULL);
1300 assert(root !=
NULL);
1302 for (n = root; n !=
NULL; n = n->nextsibl)
1308 for (a = n->attrlist; a !=
NULL; a = a->next)
1309 infoMessage(
"Attr: %s = [%s]\n", a->name, a->value);
1311 if ( n->firstchild !=
NULL )
1328 assert(node !=
NULL);
1329 assert(name !=
NULL);
1331 for (a = node->attrlist; a !=
NULL; a = a->next)
1333 if ( ! strcmp(name, a->name) )
1339 infoMessage(
"Error: Attribute %s in TAG <%s> not found\n", name, node->name);
1342 return (a ==
NULL) ?
NULL : a->value;
1353 assert(node !=
NULL);
1354 assert(name !=
NULL);
1356 for (n = node; n !=
NULL; n = n->nextsibl)
1358 if ( ! strcmp(name, n->name) )
1371 assert(node !=
NULL);
1372 assert(name !=
NULL);
1386 assert(node !=
NULL);
1387 assert(name !=
NULL);
1389 if ( ! strcmp(name, node->name) )
1392 for (n = node->firstchild; n !=
NULL; n = n->nextsibl)
1413 assert(node !=
NULL);
1414 assert(name !=
NULL);
1416 if ( ! strcmp(name, node->name) )
1419 if ( depth < maxdepth )
1421 for (n = node->firstchild; n !=
NULL; n = n->nextsibl)
1437 assert(node !=
NULL);
1439 return node->nextsibl;
1447 assert(node !=
NULL);
1449 return node->prevsibl;
1457 assert(node !=
NULL);
1459 return node->firstchild;
1467 assert(node !=
NULL);
1469 return node->lastchild;
1477 assert(node !=
NULL);
1487 assert(node !=
NULL);
1489 return node->lineno;
1497 assert(node !=
NULL);
1510 assert(node !=
NULL);
1511 assert(name !=
NULL);
1517 if ( ! strcmp(n->firstchild->name,
"#PCDATA") )
1518 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