summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexandre Bacquart <tek512@gmail.com>2010-11-17 13:32:50 (GMT)
committerAlexandre Bacquart <tek512@gmail.com>2010-11-17 13:32:50 (GMT)
commit9ef09cb0b1e3016de667f18c3dce97ad70bbb1d1 (patch)
tree68c22065847d2bc38cd26c4c29e973405efb1a26 /src
parent44fb1f071d53cc99c2c92d9f85b659bfd012f9cf (diff)
downloadmxe-9ef09cb0b1e3016de667f18c3dce97ad70bbb1d1.zip
mxe-9ef09cb0b1e3016de667f18c3dce97ad70bbb1d1.tar.gz
mxe-9ef09cb0b1e3016de667f18c3dce97ad70bbb1d1.tar.bz2
new package: tinyxml
Diffstat (limited to 'src')
-rw-r--r--src/tinyxml-test.cpp128
-rw-r--r--src/tinyxml.mk39
2 files changed, 167 insertions, 0 deletions
diff --git a/src/tinyxml-test.cpp b/src/tinyxml-test.cpp
new file mode 100644
index 0000000..9140eff
--- /dev/null
+++ b/src/tinyxml-test.cpp
@@ -0,0 +1,128 @@
+/* This file is part of mingw-cross-env. */
+/* See doc/index.html for further information. */
+
+#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);
+ }
+
+ string fpn(argv[1]);
+ TiXmlDocument doc(fpn);
+ if (!doc.LoadFile()) {
+ cerr << "failed to load " << fpn << endl;
+ exit(1);
+ }
+
+ dump_to_stdout(&doc);
+
+ return 0;
+}
+//=============================================================================
diff --git a/src/tinyxml.mk b/src/tinyxml.mk
new file mode 100644
index 0000000..8cbe7ff
--- /dev/null
+++ b/src/tinyxml.mk
@@ -0,0 +1,39 @@
+# This file is part of mingw-cross-env.
+# See doc/index.html for further information.
+
+# tinyxml
+PKG := tinyxml
+$(PKG)_IGNORE :=
+$(PKG)_VERSION := 2_6_1
+$(PKG)_CHECKSUM := 2ff9c177a6c0bef10cbd27700b71826801c12987
+$(PKG)_SUBDIR := tinyxml
+$(PKG)_FILE := tinyxml_$($(PKG)_VERSION).tar.gz
+$(PKG)_WEBSITE := http://sourceforge.net/projects/tinyxml/
+$(PKG)_URL := http://$(SOURCEFORGE_MIRROR)/project/tinyxml/tinyxml/$(subst _,.,$($(PKG)_VERSION))/$($(PKG)_FILE)
+$(PKG)_DEPS := gcc
+
+define $(PKG)_UPDATE
+ $(call SOURCEFORGE_FILES,http://sourceforge.net/projects/tinyxml/files/tinyxml/) | \
+ $(SED) -n 's,.*tinyxml_\([0-9][^>]*\)\.tar.*,\1,p' | \
+ tail -1
+endef
+
+define $(PKG)_BUILD
+ cd '$(1)' && \
+ $(TARGET)-g++ -c -O3 -Wall -Wno-unknown-pragmas -Wno-format -D TIXML_USE_STL -o tinyxml.o tinyxml.cpp && \
+ $(TARGET)-g++ -c -O3 -Wall -Wno-unknown-pragmas -Wno-format -D TIXML_USE_STL -o tinyxmlparser.o tinyxmlparser.cpp && \
+ $(TARGET)-g++ -c -O3 -Wall -Wno-unknown-pragmas -Wno-format -D TIXML_USE_STL -o tinyxmlerror.o tinyxmlerror.cpp && \
+ $(TARGET)-g++ -c -O3 -Wall -Wno-unknown-pragmas -Wno-format -D TIXML_USE_STL -o tinystr.o tinystr.cpp && \
+ $(TARGET)-g++ -c -O3 -Wall -Wno-unknown-pragmas -Wno-format -D TIXML_USE_STL -o tinyxmlerror.o tinyxmlerror.cpp && \
+ $(TARGET)-ar cr libtinyxml.a tinystr.o tinyxmlerror.o tinyxml.o tinyxmlparser.o
+ $(TARGET)-ranlib '$(1)/libtinyxml.a'
+ $(INSTALL) -d '$(PREFIX)/$(TARGET)/lib'
+ $(INSTALL) -m644 '$(1)/libtinyxml.a' '$(PREFIX)/$(TARGET)/lib/libtinyxml.a'
+ $(INSTALL) -d '$(PREFIX)/$(TARGET)/include'
+ $(INSTALL) -m644 '$(1)/tinyxml.h' '$(1)/tinystr.h' '$(PREFIX)/$(TARGET)/include/'
+
+ '$(TARGET)-g++' \
+ -W -Wall -D TIXML_USE_STL -Werror -ansi -pedantic \
+ '$(2).cpp' -o '$(PREFIX)/$(TARGET)/bin/test-tinyxml.exe' \
+ -I'$(PREFIX)/$(TARGET)/include/' -ltinyxml
+endef