|
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);
236 assert(ppos != NULL);
240 if ( ppos-> buf[ppos-> pos] == '\0' )
246 size_t len = (size_t) FREAD(ppos-> buf, sizeof(ppos-> buf) - 1, ppos-> fp);
248 if( len == 0 || len > sizeof(ppos-> buf) - 1 )
251 ppos-> buf[len] = '\0';
255 return ( unsigned char)ppos-> buf[ppos-> pos++];
259 #ifdef SPEC_LIKE_SPACE_HANDLING
272 assert(ppos != NULL);
283 if (((c == '\n') && (ppos-> lastsym == '\r')) || ((c == '\r') && (ppos-> lastsym == '\n')))
311 assert(ppos != NULL);
327 if ((c == '\n') || (c == '\r'))
329 } while((c == ' ') && (ppos-> lastsym == c));
346 assert(ppos != NULL);
360 assert(ppos != NULL);
386 assert(ppos != NULL);
390 if ( ! isalpha(c) && (c != '_') && (c != ':') )
392 xmlError(ppos, "Name starting with illegal charater");
397 while ( isalnum(c) || (c == '_') || (c == ':') || (c == '.') || (c == '-') )
399 if ( len + 1 >= size )
412 assert(name != NULL);
415 name[len++] = (char)c;
422 assert(name != NULL);
452 assert(ppos != NULL);
458 if ( (c != '"') && (c != '\'') )
460 xmlError(ppos, "Atribute value does not start with \" or \'");
480 assert(attr != NULL);
485 if ( (c == stop) || (c == EOF) )
488 attr[len++] = (char)c;
514 assert(ppos != NULL);
523 if ( (c == '>') && (state >= 2) )
526 state = (c == '-') ? state + 1 : 0;
530 xmlError(ppos, "Unexpected EOF in comment");
552 assert(ppos != NULL);
564 if ( (c == '>') && (state >= 2) )
582 assert(data != NULL);
585 data[len++] = (char)c;
587 assert(data != NULL);
593 assert(data != NULL);
595 data[len - 2] = '\0';
601 xmlError(ppos, "Unexpected EOF in CDATA");
614 assert(ppos != NULL);
621 while ( (c != EOF) && (c != '>') );
627 xmlError(ppos, "Unexpected EOF in PI");
651 typedef enum XmlSection XMLSECTION;
659 { "--", IS_COMMENT },
660 { "ATTLIST", IS_ATTLIST },
661 { "DOCTYPE", IS_DOCTYPE },
662 { "ELEMENT", IS_ELEMENT },
663 { "ENTITY", IS_ENTITY },
664 { "NOTATION", IS_NOTATION },
665 { "[CDATA[", IS_CDATA }
674 assert(ppos != NULL);
677 end = (int) ( sizeof(key) / sizeof(key[0])) - 1;
682 for(; (beg <= end) && (c != key[beg].name[k]); beg++)
684 for(; (end >= beg) && (c != key[end].name[k]); end--)
691 xmlError(ppos, "Unknown declaration");
693 while ( (c != EOF) && (c != '>') )
699 assert(beg < ( int)( sizeof(key) / sizeof(*key)));
701 switch(key[beg].what)
714 xmlError(ppos, "Can't create new node");
746 assert(ppos != NULL);
749 xmlError(ppos, "Missing name in endtag");
756 xmlError(ppos, "Missing '>' in endtag");
761 if ( strcmp(name, topPstack(ppos)->name) )
763 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");
1042 switch (ppos-> state)
1060 xmlError(ppos, "Internal Error, illegal state");
1069 const char* filename
1080 assert( filename != NULL );
1081 filenamelen = strlen(filename);
1087 if ( access(filename, R_OK) != 0 )
1089 strcat(myfilename, ".gz");
1094 if ( access(myfilename, R_OK) != 0 )
1095 strcpy(myfilename, filename);
1098 ppos. fp = FOPEN(myfilename, "r");
1115 xmlError(&ppos, "Can't create new node");
1121 xmlError(&ppos, "Can't create new attribute");
1136 if ( ! result && (node != NULL) )
1138 xmlErrmsg(&ppos, "Parsing error, processing stopped", TRUE, __FILE__, __LINE__);
1166 assert(name != NULL);
1185 assert(name != NULL);
1186 assert(value != NULL);
1206 a->next = n->attrlist;
1216 assert(parent != NULL);
1217 assert(child != NULL);
1219 child->parent = parent;
1220 child->prevsibl = parent->lastchild;
1221 child->nextsibl = NULL;
1222 parent->lastchild = child;
1224 if ( child->prevsibl != NULL )
1225 child->prevsibl->nextsibl = child;
1227 if ( parent->firstchild == NULL )
1228 parent->firstchild = child;
1245 assert(a->name != NULL);
1246 assert(a->value != NULL);
1259 assert(a->name != NULL);
1260 assert(a->value != NULL);
1280 n = node->lastchild;
1291 if ( node->data != NULL )
1295 assert(node->name != NULL);
1307 if ( n->data != NULL )
1311 assert(n->name != NULL);
1327 assert(root != NULL);
1329 for (n = root; n != NULL; n = n->nextsibl)
1335 for (a = n->attrlist; a != NULL; a = a->next)
1336 infoMessage( "Attr: %s = [%s]\n", a->name, a->value);
1338 if ( n->firstchild != NULL )
1355 assert(node != NULL);
1356 assert(name != NULL);
1358 for (a = node->attrlist; a != NULL; a = a->next)
1360 if ( ! strcmp(name, a->name) )
1366 infoMessage( "Error: Attribute %s in TAG <%s> not found\n",
1370 return (a == NULL) ? NULL : a->value;
1381 assert(node != NULL);
1382 assert(name != NULL);
1384 for (n = node; n != NULL; n = n->nextsibl)
1386 if ( ! strcmp(name, n->name) )
1399 assert(node != NULL);
1400 assert(name != NULL);
1414 assert(node != NULL);
1415 assert(name != NULL);
1417 if ( ! strcmp(name, node->name) )
1420 for (n = node->firstchild; n != NULL; n = n->nextsibl)
1428 if ( node->firstchild != NULL )
1434 if ( node->nextsibl != NULL )
1455 assert(node != NULL);
1456 assert(name != NULL);
1458 if ( ! strcmp(name, node->name) )
1461 if ( depth < maxdepth )
1463 for (n = node->firstchild; n != NULL; n = n->nextsibl)
1479 assert(node != NULL);
1481 return node->nextsibl;
1489 assert(node != NULL);
1491 return node->prevsibl;
1499 assert(node != NULL);
1501 return node->firstchild;
1509 assert(node != NULL);
1511 return node->lastchild;
1519 assert(node != NULL);
1529 assert(node != NULL);
1531 return node->lineno;
1539 assert(node != NULL);
1552 assert(node != NULL);
1553 assert(name != NULL);
1559 if ( ! strcmp(n->firstchild->name, "#PCDATA") )
1560 return n->firstchild->data;
|