DEADSOFTWARE

Testing odcread against a bunch of existing .odc files
[odcread.git] / odcread.cc
index 4ba36802c058412591472bd9fb6c4af470c6a41f..858028e6babf5e252ede8ade0c0f71d2946ceb4e 100644 (file)
@@ -1,6 +1,7 @@
 #include <iostream>
 #include <fstream>
 #include <string>
+#include <stack>
 
 #include <oberon.h>
 #include <reader.h>
@@ -52,40 +53,41 @@ namespace odc {
 
        class MyVisitor : public Visitor {
                private:
-               std::vector<Context*> d_context;
+               std::stack<Context*> d_context;
 
                void terminateContext() {
-                       Context *c = *(d_context.end() - 1);
-                       d_context.erase(d_context.end() - 1);
-                       if (d_context.size() == 0) {
+                       Context *c = d_context.top();
+                       d_context.pop();
+                       if (d_context.empty()) {
                                std::cout << c->getPlainText() << std::endl;
                        } else {
                                std::string text = c->getPlainText();
-                               (*(d_context.end() - 1))->addPiece(text);
+                               d_context.top()->addPiece(text);
                        }
                        delete c;
                }
                
                public:
                virtual void partStart() {
-                       d_context.push_back(new PartContext());
+                       d_context.push(new PartContext());
                }
                virtual void partEnd() {
                        terminateContext();
                }
                virtual void foldLeft(bool collapsed) {
-                       d_context.push_back(new FoldContext(collapsed));
+                       d_context.push(new FoldContext(collapsed));
                }
                virtual void foldRight() {
                        terminateContext();
                }
                virtual void textShortPiece(const ShortPiece *piece) {
                        std::string text = piece->getText();
-                       (*(d_context.end() - 1))->addPiece(text);
+                       d_context.top()->addPiece(text);
                }
                virtual void textLongPiece(const LongPiece *piece) {
-                       std::string text = piece->getText();
-                       (*(d_context.end() - 1))->addPiece(text);
+                       throw "Long Piece not handled";
+                       //std::string text = piece->getText();
+                       //d_context.top()->addPiece(text);
                }
        };
 
@@ -111,12 +113,27 @@ int main(int argc, char *argv[]) {
                return 1;
        }
        std::ifstream in(argv[1], std::ios::in | std::ios::binary);
-       odc::Store* s = odc::importDocument(in);
+
+       odc::Store* s;
+       try {
+               s = odc::importDocument(in);
+       } catch (int trap) {
+               std::cerr << "Exception in parsing file: BlackBox trap no. " << trap << std::endl;
+               return 2;
+       } catch (const char * exception) {
+               std::cerr << "Exception in parsing file: " << exception << std::endl;
+               return 2;
+       }
 //     std::cout << s->toPlainText() << std::endl;
 //     std::cout << std::endl << std::endl;
 
-       odc::MyVisitor visitor;
-       s->accept(visitor);
+       try {
+               odc::MyVisitor visitor;
+               s->accept(visitor);
+       } catch (const char * exception) {
+               std::cerr << "Exception in processing document: " << exception << std::endl;
+               return 3;
+       }
 //     std::cout << s->toString() << std::endl;
 //     std::cout << in.tellg() << " " << in.eof() << std::endl;