- change new XML parser to handle XML comments (<!-- ... -->)

client/
		log_flags.C
	lib/
		parse.C,h

svn path=/trunk/boinc/; revision=12894
This commit is contained in:
David Anderson 2007-06-11 21:30:26 +00:00
parent 49d435913e
commit 52c2fe8b33
4 changed files with 66 additions and 25 deletions

View File

@ -6066,3 +6066,11 @@ David 11 June 2007
client/
cs_statefile.C
David 11 June 2007
- change new XML parser to handle XML comments (<!-- ... -->)
client/
log_flags.C
lib/
parse.C,h

View File

@ -246,14 +246,15 @@ int CONFIG::parse(FILE* f) {
if (!strcmp(tag, "log_flags")) {
log_flags.parse(xp);
continue;
} else if (!strcmp(tag, "options")) {
parse_options(xp);
} else {
msg_printf(NULL, MSG_USER_ERROR, "Unparsed tag in %s: <%s>\n",
CONFIG_FILE, tag
);
xp.skip_unexpected(tag);
}
if (!strcmp(tag, "options")) {
parse_options(xp);
continue;
}
msg_printf(NULL, MSG_USER_ERROR, "Unparsed tag in %s: <%s>\n",
CONFIG_FILE, tag
);
xp.skip_unexpected(tag);
}
msg_printf(NULL, MSG_USER_ERROR, "Missing end tag in %s", CONFIG_FILE);
return ERR_XML_PARSE;

View File

@ -436,24 +436,52 @@ bool XML_PARSER::scan_nonws(int& first_char) {
}
}
int XML_PARSER::scan_comment() {
char buf[256];
char* p = buf;
while (1) {
int c = f->_getc();
if (c == EOF) return 2;
*p++ = c;
*p = 0;
if (strstr(buf, "-->")) {
return 1;
}
if (strlen(buf) > 32) {
strcpy(buf, buf+16);
p = buf;
}
}
}
// we just read a <; read until we find a >,
// and copy intervening text (except spaces) to buf.
// Return true iff reached EOF
// Return:
// 0 if got a tag
// 1 if got a comment (ignore)
// 2 if reached EOF
// TODO: parse attributes too
//
bool XML_PARSER::scan_tag(char* buf, int len) {
int XML_PARSER::scan_tag(char* buf, int len) {
int c;
while (1) {
char* buf_start = buf;
for (int i=0; ; i++) {
c = f->_getc();
if (c == EOF) return true;
if (c == EOF) return 2;
if (isspace(c)) continue;
if (c == '>') {
*buf = 0;
return false;
return 0;
}
if (--len > 0) {
*buf++ = c;
}
// check for comment start
//
if (i==2 && !strncmp(buf_start, "!--", 3)) {
return scan_comment();
}
}
}
@ -485,20 +513,23 @@ bool XML_PARSER::get(char* buf, int len, bool& is_tag) {
bool eof;
int c;
eof = scan_nonws(c);
if (eof) return true;
if (c == '<') {
eof = scan_tag(buf, len);
while (1) {
eof = scan_nonws(c);
if (eof) return true;
is_tag = true;
} else {
buf[0] = c;
eof = copy_until_tag(buf+1, len-1);
if (eof) return true;
is_tag = false;
if (c == '<') {
int retval = scan_tag(buf, len);
if (retval == 2) return true;
if (retval == 1) continue;
is_tag = true;
} else {
buf[0] = c;
eof = copy_until_tag(buf+1, len-1);
if (eof) return true;
is_tag = false;
}
strip_whitespace(buf);
return false;
}
strip_whitespace(buf);
return false;
}
// We just parsed "parsed_tag".

View File

@ -38,7 +38,8 @@
class XML_PARSER {
MIOFILE* f;
bool scan_nonws(int&);
bool scan_tag(char*, int);
int scan_comment();
int scan_tag(char*, int);
bool copy_until_tag(char*, int);
public:
XML_PARSER(MIOFILE*);