From c17c4ebbab022de80a9f893115f2fd41e6a07c44 Mon Sep 17 00:00:00 2001
From: Mike Buland <eichlan@xagasoft.com>
Date: Tue, 8 May 2007 06:31:33 +0000
Subject: Added the TAF format structures and XML format structures, I'm making
 up TAF (textual archive format), but named it wrong, this seemed easier than
 redoing it all.

---
 src/tests/xml.cpp   |  15 ++++++++
 src/tsfdocument.cpp |   9 +++++
 src/tsfdocument.h   |  22 +++++++++++
 src/tsfnode.cpp     |   9 +++++
 src/tsfnode.h       |  21 ++++++++++
 src/tsfreader.cpp   |   9 +++++
 src/tsfreader.h     |  22 +++++++++++
 src/tsfwriter.cpp   |   9 +++++
 src/tsfwriter.h     |  22 +++++++++++
 src/xmldocument.cpp |   9 +++++
 src/xmldocument.h   |  22 +++++++++++
 src/xmlnode.cpp     |   9 +++++
 src/xmlnode.h       |  22 +++++++++++
 src/xmlreader.cpp   | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/xmlreader.h     |  70 ++++++++++++++++++++++++++++++++++
 src/xmlwriter.cpp   |   9 +++++
 src/xmlwriter.h     |  22 +++++++++++
 17 files changed, 409 insertions(+)
 create mode 100644 src/tests/xml.cpp
 create mode 100644 src/tsfdocument.cpp
 create mode 100644 src/tsfdocument.h
 create mode 100644 src/tsfnode.cpp
 create mode 100644 src/tsfnode.h
 create mode 100644 src/tsfreader.cpp
 create mode 100644 src/tsfreader.h
 create mode 100644 src/tsfwriter.cpp
 create mode 100644 src/tsfwriter.h
 create mode 100644 src/xmldocument.cpp
 create mode 100644 src/xmldocument.h
 create mode 100644 src/xmlnode.cpp
 create mode 100644 src/xmlnode.h
 create mode 100644 src/xmlreader.cpp
 create mode 100644 src/xmlreader.h
 create mode 100644 src/xmlwriter.cpp
 create mode 100644 src/xmlwriter.h

(limited to 'src')

diff --git a/src/tests/xml.cpp b/src/tests/xml.cpp
new file mode 100644
index 0000000..9ef6a7e
--- /dev/null
+++ b/src/tests/xml.cpp
@@ -0,0 +1,15 @@
+#include "bu/xmlreader.h"
+#include "bu/xmlnode.h"
+#include "bu/xmldocument.h"
+#include "bu/file.h"
+
+int main()
+{
+	Bu::File f("test.xml", "r");
+	Bu::XmlReader xr( f );
+
+	xr.read();
+
+	return 0;
+}
+
diff --git a/src/tsfdocument.cpp b/src/tsfdocument.cpp
new file mode 100644
index 0000000..582f1b1
--- /dev/null
+++ b/src/tsfdocument.cpp
@@ -0,0 +1,9 @@
+#include "tsfdocument.h"
+
+Bu::TsfDocument::TsfDocument()
+{
+}
+
+Bu::TsfDocument::~TsfDocument()
+{
+}
diff --git a/src/tsfdocument.h b/src/tsfdocument.h
new file mode 100644
index 0000000..e324459
--- /dev/null
+++ b/src/tsfdocument.h
@@ -0,0 +1,22 @@
+#ifndef TSF_DOCUMENT_H
+#define TSF_DOCUMENT_H
+
+#include <stdint.h>
+
+namespace Bu
+{
+	/**
+	 *
+	 */
+	class TsfDocument
+	{
+	public:
+		TsfDocument();
+		virtual ~TsfDocument();
+
+	private:
+
+	};
+}
+
+#endif
diff --git a/src/tsfnode.cpp b/src/tsfnode.cpp
new file mode 100644
index 0000000..19df4ed
--- /dev/null
+++ b/src/tsfnode.cpp
@@ -0,0 +1,9 @@
+#include "tsfnode.h"
+
+Bu::TsfNode::TsfNode()
+{
+}
+
+Bu::TsfNode::~TsfNode()
+{
+}
diff --git a/src/tsfnode.h b/src/tsfnode.h
new file mode 100644
index 0000000..f58b825
--- /dev/null
+++ b/src/tsfnode.h
@@ -0,0 +1,21 @@
+#ifndef TSF_NODE_H
+#define TSF_NODE_H
+
+#include <stdint.h>
+
+namespace Bu
+{
+	/**
+	 *
+	 */
+	class TsfNode
+	{
+	public:
+		TsfNode();
+		virtual ~TsfNode();
+
+	private:
+
+	};
+}
+#endif
diff --git a/src/tsfreader.cpp b/src/tsfreader.cpp
new file mode 100644
index 0000000..58f4f78
--- /dev/null
+++ b/src/tsfreader.cpp
@@ -0,0 +1,9 @@
+#include "tsfreader.h"
+
+Bu::TsfReader::TsfReader()
+{
+}
+
+Bu::TsfReader::~TsfReader()
+{
+}
diff --git a/src/tsfreader.h b/src/tsfreader.h
new file mode 100644
index 0000000..cc8400a
--- /dev/null
+++ b/src/tsfreader.h
@@ -0,0 +1,22 @@
+#ifndef TSF_READER_H
+#define TSF_READER_H
+
+#include <stdint.h>
+
+namespace Bu
+{
+	/**
+	 *
+	 */
+	class TsfReader
+	{
+	public:
+		TsfReader();
+		virtual ~TsfReader();
+
+	private:
+
+	};
+}
+
+#endif
diff --git a/src/tsfwriter.cpp b/src/tsfwriter.cpp
new file mode 100644
index 0000000..6592996
--- /dev/null
+++ b/src/tsfwriter.cpp
@@ -0,0 +1,9 @@
+#include "tsfwriter.h"
+
+Bu::TsfWriter::TsfWriter()
+{
+}
+
+Bu::TsfWriter::~TsfWriter()
+{
+}
diff --git a/src/tsfwriter.h b/src/tsfwriter.h
new file mode 100644
index 0000000..18f19d6
--- /dev/null
+++ b/src/tsfwriter.h
@@ -0,0 +1,22 @@
+#ifndef TSF_WRITER_H
+#define TSF_WRITER_H
+
+#include <stdint.h>
+
+namespace Bu
+{
+	/**
+	 *
+	 */
+	class TsfWriter
+	{
+	public:
+		TsfWriter();
+		virtual ~TsfWriter();
+
+	private:
+
+	};
+}
+
+#endif
diff --git a/src/xmldocument.cpp b/src/xmldocument.cpp
new file mode 100644
index 0000000..cb21826
--- /dev/null
+++ b/src/xmldocument.cpp
@@ -0,0 +1,9 @@
+#include "xmldocument.h"
+
+Bu::XmlDocument::XmlDocument()
+{
+}
+
+Bu::XmlDocument::~XmlDocument()
+{
+}
diff --git a/src/xmldocument.h b/src/xmldocument.h
new file mode 100644
index 0000000..e16e3ea
--- /dev/null
+++ b/src/xmldocument.h
@@ -0,0 +1,22 @@
+#ifndef XML_DOCUMENT_H
+#define XML_DOCUMENT_H
+
+#include <stdint.h>
+
+namespace Bu
+{
+	/**
+	 *
+	 */
+	class XmlDocument
+	{
+	public:
+		XmlDocument();
+		virtual ~XmlDocument();
+
+	private:
+
+	};
+}
+
+#endif
diff --git a/src/xmlnode.cpp b/src/xmlnode.cpp
new file mode 100644
index 0000000..58ef5c5
--- /dev/null
+++ b/src/xmlnode.cpp
@@ -0,0 +1,9 @@
+#include "xmlnode.h"
+
+Bu::XmlNode::XmlNode()
+{
+}
+
+Bu::XmlNode::~XmlNode()
+{
+}
diff --git a/src/xmlnode.h b/src/xmlnode.h
new file mode 100644
index 0000000..cd9961a
--- /dev/null
+++ b/src/xmlnode.h
@@ -0,0 +1,22 @@
+#ifndef XML_NODE_H
+#define XML_NODE_H
+
+#include <stdint.h>
+
+namespace Bu
+{
+	/**
+	 *
+	 */
+	class XmlNode
+	{
+	public:
+		XmlNode();
+		virtual ~XmlNode();
+
+	private:
+
+	};
+}
+
+#endif
diff --git a/src/xmlreader.cpp b/src/xmlreader.cpp
new file mode 100644
index 0000000..432ecc1
--- /dev/null
+++ b/src/xmlreader.cpp
@@ -0,0 +1,108 @@
+#include "xmlreader.h"
+
+Bu::XmlReader::XmlReader( Bu::Stream &sIn ) :
+	sIn( sIn )
+{
+}
+
+Bu::XmlReader::~XmlReader()
+{
+}
+
+const char *Bu::XmlReader::lookahead( int nAmnt )
+{
+	if( sBuf.getSize() >= nAmnt )
+		return sBuf.getStr();
+
+	int nNew = nAmnt - sBuf.getSize();
+	char *buf = new char[nNew];
+	sIn.read( buf, nNew );
+	sBuf.append( buf );
+
+	return sBuf.getStr();
+}
+
+void Bu::XmlReader::burn( int nAmnt )
+{
+	if( sBuf.getSize() < nAmnt )
+	{
+		lookahead( nAmnt );
+	}
+
+	sBuf.remove( nAmnt );
+}
+
+void Bu::XmlNode::checkString( const char *str, int nLen )
+{
+	if( !strncmp( str, lookahead( nLen ), nLen ) )
+	{
+		burn( nLen );
+		return;
+	}
+
+	throw Bu::ExceptionBase("Expected string '%s'", str );
+}
+
+Bu::XmlNode *Bu::XmlReader::read()
+{
+	prolog();
+}
+
+void Bu::XmlReader::prolog()
+{
+	XMLDecl();
+	Misc();
+}
+
+void Bu::XmlReader::XMLDecl()
+{
+	checkString("<?xml", 5 );
+	VersionInfo();
+	EncodingDecl();
+	SDDecl();
+	S();
+}
+
+void Bu::XmlReader::Misc()
+{
+}
+
+void Bu::XmlReader::S()
+{
+	for( int j = 0;; j++ )
+	{
+		char c = *lookahead( 1 );
+		if( c == 0x20 || c == 0x9 || c == 0xD || c == 0xA )
+			continue;
+		if( j == 0 )
+			printf("Error, expected whitespace!\n");
+		return;
+	}
+}
+
+void Bu::XmlReader::S()
+{
+	for(;;)
+	{
+		char c = *lookahead( 1 );
+		if( c == 0x20 || c == 0x9 || c == 0xD || c == 0xA )
+			continue;
+		return;
+	}
+}
+
+void Bu::XmlReader::VersionInfo()
+{
+	S();
+	checkString("version", 7 );
+	
+}
+
+void Bu::XmlReader::Eq()
+{
+	Sq();
+	checkString("=", 1 );
+	Sq();
+}
+
+
diff --git a/src/xmlreader.h b/src/xmlreader.h
new file mode 100644
index 0000000..19791c4
--- /dev/null
+++ b/src/xmlreader.h
@@ -0,0 +1,70 @@
+#ifndef XML_READER_H
+#define XML_READER_H
+
+#include <stdint.h>
+#include "bu/stream.h"
+#include "bu/fstring.h"
+#include "bu/xmlnode.h"
+
+namespace Bu
+{
+	/**
+	 *
+	 */
+	class XmlReader
+	{
+	public:
+		XmlReader( Bu::Stream &sIn );
+		virtual ~XmlReader();
+
+		XmlNode *read();
+
+	private:
+		Bu::Stream &sIn;
+		Bu::FString sBuf;
+
+	private: // Helpers
+		const char *lookahead( int nAmnt );
+		void burn( int nAmnt );
+		void checkString( const char *str, int nLen );
+
+	private: // States
+		/**
+		 * The headers, etc.
+		 */
+		void prolog();
+
+		/**
+		 * The xml decleration (version, encoding, etc).
+		 */
+		void XMLDecl();
+
+		/**
+		 * Misc things...?
+		 */
+		void Misc();
+
+		/**
+		 * Whitespace eater.
+		 */
+		void S();
+
+		/**
+		 * Optional whitespace eater.
+		 */
+		void Sq();
+
+		/**
+		 * XML Version spec
+		 */
+		void VersionInfo();
+
+		/**
+		 * Your basic equals sign with surrounding whitespace.
+		 */
+		void Eq();
+
+	};
+}
+
+#endif
diff --git a/src/xmlwriter.cpp b/src/xmlwriter.cpp
new file mode 100644
index 0000000..23a5175
--- /dev/null
+++ b/src/xmlwriter.cpp
@@ -0,0 +1,9 @@
+#include "xmlwriter.h"
+
+Bu::XmlWriter::XmlWriter()
+{
+}
+
+Bu::XmlWriter::~XmlWriter()
+{
+}
diff --git a/src/xmlwriter.h b/src/xmlwriter.h
new file mode 100644
index 0000000..796d6fb
--- /dev/null
+++ b/src/xmlwriter.h
@@ -0,0 +1,22 @@
+#ifndef XML_WRITER_H
+#define XML_WRITER_H
+
+#include <stdint.h>
+
+namespace Bu
+{
+	/**
+	 *
+	 */
+	class XmlWriter
+	{
+	public:
+		XmlWriter();
+		virtual ~XmlWriter();
+
+	private:
+
+	};
+}
+
+#endif
-- 
cgit v1.2.3