diff options
author | FWoltermann@gmail.com <FWoltermann@gmail.com@076cb2c4-205e-83fd-5cf3-1be9aa105544> | 2011-12-08 14:53:40 +0000 |
---|---|---|
committer | FWoltermann@gmail.com <FWoltermann@gmail.com@076cb2c4-205e-83fd-5cf3-1be9aa105544> | 2011-12-08 14:53:40 +0000 |
commit | e33e19d0587146859d48a134ec9fd94e7b7ba5cd (patch) | |
tree | 69d048c8801858d2756ab3a487090a7a1b74bf14 /Parser/Reader.cpp | |
download | starshatter-e33e19d0587146859d48a134ec9fd94e7b7ba5cd.zip starshatter-e33e19d0587146859d48a134ec9fd94e7b7ba5cd.tar.gz starshatter-e33e19d0587146859d48a134ec9fd94e7b7ba5cd.tar.bz2 |
Initial upload
Diffstat (limited to 'Parser/Reader.cpp')
-rw-r--r-- | Parser/Reader.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/Parser/Reader.cpp b/Parser/Reader.cpp new file mode 100644 index 0000000..14b1126 --- /dev/null +++ b/Parser/Reader.cpp @@ -0,0 +1,114 @@ +/* Project STARS
+ John DiCamillo Software Consulting
+ Copyright © 1997-2000. All Rights Reserved.
+
+ SUBSYSTEM: obelisk
+ FILE: reader.cpp
+ AUTHOR: John DiCamillo
+
+
+ OVERVIEW
+ ========
+ Implementation of the Reader class
+*/
+
+#include "MemDebug.h"
+#include "reader.h"
+#include <stdio.h>
+#include <fstream.h>
+#include <ctype.h>
+
+
+void Print(const char* fmt, ...);
+
+// +-------------------------------------------------------------------+
+
+Text
+ConsoleReader::more()
+{
+ // loop until the user types something
+ do {
+ printPrimaryPrompt();
+ fillInputBuffer();
+ } while (! *p);
+
+ return Text(p);
+}
+
+void
+ConsoleReader::printPrimaryPrompt()
+{
+ printf("- ");
+}
+
+void
+ConsoleReader::fillInputBuffer()
+{
+ fgets(buffer, 980, stdin);
+ p = buffer;
+ while (isspace(*p)) p++;
+}
+
+// +-------------------------------------------------------------------+
+
+FileReader::FileReader(const char* fname)
+ : filename(fname), done(0)
+{ }
+
+Text
+FileReader::more()
+{
+ if (done) return Text();
+
+ ifstream fin;
+ fin.open(filename, ios::in | ios::nocreate);
+
+ if (!fin) {
+ Print("ERROR(Parse): Could not open file '%s'\n", filename);
+ return Text();
+ }
+
+ Text result;
+ char buf[1000], newline;
+
+ while (fin.get(buf, 1000)) {
+ result.append(buf);
+ fin.get(newline);
+ result.append(newline);
+ }
+
+ done = 1;
+ return result;
+}
+
+// +-------------------------------------------------------------------+
+
+BlockReader::BlockReader(const char* block)
+ : data((char*) block), done(0), length(0)
+{ }
+
+BlockReader::BlockReader(const char* block, int len)
+ : data((char*) block), done(0), length(len)
+{ }
+
+Text
+BlockReader::more()
+{
+ if (done) return Text();
+
+ if (length) {
+ Text result(data, length);
+ done = 1;
+ return result;
+ }
+ else if (data) {
+ Text result(data);
+ done = 1;
+ return result;
+ }
+
+ done = 1;
+ return Text();
+}
+
+
|