diff --git a/checkin_notes b/checkin_notes index 836b906bb4..0a8689c0fa 100644 --- a/checkin_notes +++ b/checkin_notes @@ -6730,3 +6730,16 @@ David 3 Oct 2011 html/user/ profile_menu.php + +David 3 Oct 2011 + - lib: move XML parse test program to its own file. + + Note: XML_PARSER::parse_str() doesn't currently work right + for something like xx. + It should return "xx". + TODO. + + lib/ + parse.cpp,h + parse_test.cpp (new) + Makefile.am diff --git a/lib/Makefile.am b/lib/Makefile.am index 24907f54a8..a7989d331c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -8,7 +8,7 @@ bin_PROGRAMS = # Stuff needed for server builds goes here. if ENABLE_SERVER -bin_PROGRAMS += crypt_prog +bin_PROGRAMS += crypt_prog parse_test endif # end of "if ENABLE_SERVER" @@ -221,4 +221,6 @@ msg_test_LDADD = $(LIBBOINC) crypt_prog_SOURCES = crypt_prog.cpp crypt_prog_CXXFLAGS = $(PTHREAD_CFLAGS) crypt_prog_LDADD = $(LIBBOINC_CRYPT_STATIC) $(LIBBOINC) $(SSL_LIBS) - +parse_test_SOURCES = parse_test.cpp +parse_test_CXXFLAGS = $(PTHREAD_CFLAGS) +parse_test_LDADD = $(LIBBOINC) diff --git a/lib/parse.cpp b/lib/parse.cpp index 5c85a32a6b..45ed5a1185 100644 --- a/lib/parse.cpp +++ b/lib/parse.cpp @@ -649,7 +649,9 @@ int XML_PARSER::get_aux(char* buf, int len, char* attr_buf, int attr_len) { } } -bool XML_PARSER::get(char* buf, int len, bool& _is_tag, char* attr_buf, int attr_len) { +bool XML_PARSER::get( + char* buf, int len, bool& _is_tag, char* attr_buf, int attr_len +) { switch (get_aux(buf, len, attr_buf, attr_len)) { case XML_PARSE_EOF: return true; case XML_PARSE_TAG: @@ -1006,66 +1008,3 @@ int XML_PARSER::copy_element(string& out) { out += end_tag; return 0; } - -// sample use is shown below - -#if 0 -void parse(FILE* f) { - bool flag; - MIOFILE mf; - XML_PARSER xp(&mf); - char name[256]; - int val; - double x; - - mf.init_file(f); - if (!xp.parse_start("blah")) { - printf("missing start tag\n"); - return; - } - while (!xp.get_tag()) { - if (!xp.is_tag) { - printf("unexpected text: %s\n", tag); - continue; - } - if (xp.match_tag("/blah")) { - printf("success\n"); - return; - } else if (xp.parse_str("str", name, sizeof(name))) { - printf("got str: %s\n", name); - } else if (xp.parse_int("int", val)) { - printf("got int: %d\n", val); - } else if (xp.parse_double("double", x)) { - printf("got double: %f\n", x); - } else if (xp.parse_bool("bool", flag)) { - printf("got bool: %d\n", flag); - } else { - printf("unparsed tag: %s\n", xp.parsed_tag); - xp.skip_unexpected(true, "xml test"); - } - } - printf("unexpected EOF\n"); -} - -int main() { - FILE* f = fopen("foo.xml", "r"); - parse(f); -} - -... and run it against, e.g.: - - - - - asdlfkj - fj - - blah - 6 - - 6.555 - 0 - - -#endif - diff --git a/lib/parse.h b/lib/parse.h index 85703600f6..b7b1442b7e 100644 --- a/lib/parse.h +++ b/lib/parse.h @@ -27,6 +27,8 @@ #include "str_util.h" #include "cl_boinc.h" +// see parse_test.cpp for example usage of XML_PARSER + class XML_PARSER { bool scan_nonws(int&); int scan_comment(); diff --git a/lib/parse_test.cpp b/lib/parse_test.cpp new file mode 100644 index 0000000000..18146c668f --- /dev/null +++ b/lib/parse_test.cpp @@ -0,0 +1,64 @@ +// test program for XML parser + +#include + +#include "parse.h" + +void parse(FILE* f) { + bool flag; + MIOFILE mf; + XML_PARSER xp(&mf); + char name[256]; + int val; + double x; + + mf.init_file(f); + if (!xp.parse_start("blah")) { + printf("missing start tag\n"); + return; + } + while (!xp.get_tag()) { + if (!xp.is_tag) { + printf("unexpected text: %s\n", xp.parsed_tag); + continue; + } + if (xp.match_tag("/blah")) { + printf("success\n"); + return; + } else if (xp.parse_str("str", name, sizeof(name))) { + printf("got str: %s\n", name); + } else if (xp.parse_int("int", val)) { + printf("got int: %d\n", val); + } else if (xp.parse_double("double", x)) { + printf("got double: %f\n", x); + } else if (xp.parse_bool("bool", flag)) { + printf("got bool: %d\n", flag); + } else { + printf("unparsed tag: %s\n", xp.parsed_tag); + xp.skip_unexpected(true, "xml test"); + } + } + printf("unexpected EOF\n"); +} + +int main() { + FILE* f = fopen("foo.xml", "r"); + parse(f); +} + +/* try it with something like: + + + + + asdlfkj + fj + + blah + 6 + + 6.555 + 0 + + +*/