diff options
author | Volker Grabsch <vog@notjusthosting.com> | 2010-11-17 14:55:51 (GMT) |
---|---|---|
committer | Volker Grabsch <vog@notjusthosting.com> | 2010-11-17 14:55:51 (GMT) |
commit | 0dfe34bd930d3273bcb91efc46ec570987a39c08 (patch) | |
tree | e8cb11f3de6385f8275e7160c90413cfe0073812 | |
parent | 38e54d63dc17f68e419cb4478540a45302124f2e (diff) | |
download | mxe-0dfe34bd930d3273bcb91efc46ec570987a39c08.zip mxe-0dfe34bd930d3273bcb91efc46ec570987a39c08.tar.gz mxe-0dfe34bd930d3273bcb91efc46ec570987a39c08.tar.bz2 |
shortened test program for package tinyxml
-rw-r--r-- | src/tinyxml-test.cpp | 118 |
1 files changed, 6 insertions, 112 deletions
diff --git a/src/tinyxml-test.cpp b/src/tinyxml-test.cpp index 07387a7..4cf444f 100644 --- a/src/tinyxml-test.cpp +++ b/src/tinyxml-test.cpp @@ -4,125 +4,19 @@ #include <iostream> #include <tinyxml.h> -using namespace std; - -// ---------------------------------------------------------------------- -// STDOUT dump and indenting utility functions -// ---------------------------------------------------------------------- -const unsigned int NUM_INDENTS_PER_SPACE=2; - -const char * getIndent( unsigned int numIndents ) -{ - static const char * pINDENT=" + "; - static const unsigned int LENGTH=strlen( pINDENT ); - unsigned int n=numIndents*NUM_INDENTS_PER_SPACE; - if ( n > LENGTH ) n = LENGTH; - - return &pINDENT[ LENGTH-n ]; -} - -// same as getIndent but no "+" at the end -const char * getIndentAlt( unsigned int numIndents ) -{ - static const char * pINDENT=" "; - static const unsigned int LENGTH=strlen( pINDENT ); - unsigned int n=numIndents*NUM_INDENTS_PER_SPACE; - if ( n > LENGTH ) n = LENGTH; - - return &pINDENT[ LENGTH-n ]; -} - -int dump_attribs_to_stdout(TiXmlElement* pElement, unsigned int indent) -{ - if ( !pElement ) return 0; - - TiXmlAttribute* pAttrib=pElement->FirstAttribute(); - int i=0; - int ival; - double dval; - const char* pIndent=getIndent(indent); - printf("\n"); - while (pAttrib) - { - printf( "%s%s: value=[%s]", pIndent, pAttrib->Name(), pAttrib->Value()); - - if (pAttrib->QueryIntValue(&ival)==TIXML_SUCCESS) printf( " int=%d", ival); - if (pAttrib->QueryDoubleValue(&dval)==TIXML_SUCCESS) printf( " d=%1.1f", dval); - printf( "\n" ); - i++; - pAttrib=pAttrib->Next(); - } - return i; -} - -void dump_to_stdout(TiXmlNode* pParent, unsigned int indent = 0) -{ - if (!pParent) - return; - - TiXmlNode* pChild; - TiXmlText* pText; - int t = pParent->Type(); - printf("%s", getIndent(indent)); - int num; - - switch (t) { - case TiXmlNode::TINYXML_DOCUMENT: - printf("Document"); - break; - - case TiXmlNode::TINYXML_ELEMENT: - printf("Element [%s]", pParent->Value()); - num=dump_attribs_to_stdout(pParent->ToElement(), indent+1); - switch(num) { - case 0: printf(" (No attributes)"); break; - case 1: printf("%s1 attribute", getIndentAlt(indent)); break; - default: printf("%s%d attributes", getIndentAlt(indent), num); break; - } - break; - - case TiXmlNode::TINYXML_COMMENT: - printf("Comment: [%s]", pParent->Value()); - break; - - case TiXmlNode::TINYXML_UNKNOWN: - printf("Unknown" ); - break; - - case TiXmlNode::TINYXML_TEXT: - pText = pParent->ToText(); - printf("Text: [%s]", pText->Value() ); - break; - - case TiXmlNode::TINYXML_DECLARATION: - printf("Declaration" ); - break; - default: - break; - } - printf("\n"); - for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) - { - dump_to_stdout( pChild, indent+1 ); - } -} -//============================================================================= int main(int argc, char *argv[]) { - if (argc <= 1) { - cout << "Usage: tinyxml-test <xml-file>" << endl; - exit(1); + if (argc != 2) { + std::cerr << "Usage: tinyxml-test <xml-file>" << std::endl; + return 1; } + std::string fpn = argv[1]; - string fpn(argv[1]); TiXmlDocument doc(fpn); if (!doc.LoadFile()) { - cerr << "failed to load " << fpn << endl; - exit(1); + std::cerr << "failed to load " << fpn << std::endl; + return 1; } - dump_to_stdout(&doc); - return 0; } -//============================================================================= |