]> Shamusworld >> Repos - architektonas/blobdiff - src/fileio.cpp
Initial work on bringing sanity to insane codebase.
[architektonas] / src / fileio.cpp
index b64e5bd200fa05ac1223dd337133abe522c19896..27ed4f3c3ccec27eacee2403c6bc0b891863c5f3 100644 (file)
 #include "fileio.h"
 
 //#include <stdio.h>
+#include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 #include <vector>
-#include "arc.h"
-#include "circle.h"
-#include "container.h"
-#include "dimension.h"
-#include "line.h"
+//#include "arc.h"
+//#include "circle.h"
+//#include "container.h"
+//#include "dimension.h"
+//#include "line.h"
+#include "structs.h"
 
 /*
 How to handle connected objects
@@ -101,6 +103,14 @@ perpendicular, or an arbitrary angle. How to encode that information? It's not
 intrinsic to either the Line or the Circle, but is a function of the
 relationship between them by virtue of their connection.
 
+
+OTHER CONSIDERATIONS:
+---------------------
+
+  - Need to figure out how to store the Layer list (should layer list be optional?)
+  - Need to figure out how to store the Block list and blocks
+
+
 */
 
 enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFLine, OTFCircle, OTFArc, OTFDimension,
@@ -116,7 +126,7 @@ enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFLine, OTFCircle, OTFArc,
           enumerates all objects within itself. */
 
        fprintf(file, "ARCHITEKTONAS DRAWING V1.0\n");
-#if 1
+#if 0
        object->Enumerate(file);
        fprintf(file, "END\n");
        return true;
@@ -140,7 +150,7 @@ enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFLine, OTFCircle, OTFArc,
           add objects to it until an "endContainer" marker is found. This will require a
           stack to maintain the current Container. */
 
-#if 1
+#if 0
        std::vector<Container *> containerStack;
        Container * currentTopContainer = drawing;//new Container(Vector(0, 0));
        Object * object;
@@ -159,7 +169,7 @@ enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFLine, OTFCircle, OTFArc,
 
                if (objectType == OTFEndOfFile)
                {
-printf("Load: container size = %li\n", drawing->objects.size());
+//printf("Load: container size = %li\n", drawing->objects.size());
                        return true;
                }
                else if (objectType == OTFContainer)
@@ -177,7 +187,7 @@ printf("Load: container size = %li\n", drawing->objects.size());
                else
                {
                        currentTopContainer->Add(object);
-printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.size(), currentTopContainer->objects.size());
+//printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.size(), currentTopContainer->objects.size());
                }
        }
 
@@ -190,10 +200,40 @@ printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.siz
 
 /*static*/ bool FileIO::GetObjectFromFile(FILE * file, Object * parent, Object ** object, int * objectType)
 {
+#if 0
        char buffer[256];
-       fscanf(file, "%s ", buffer);
+       int foundLayer = 0;
+       int num = fscanf(file, "%s", buffer);
        bool recognized = false;
-//printf("Load: buffer = \"%s\"\n", buffer);
+       *object = NULL;
+//printf("FileIO: fscanf returned %i, buffer = \"%s\"\n", num, buffer);
+
+// The following fugliness is for troubleshooting. Can remove later.
+       if ((strcmp(buffer, "END") != 0) && (strcmp(buffer, "ENDCONTAINER") != 0))
+{
+errno = 0;
+               num = fscanf(file, " %i ", &foundLayer);
+//printf("FileIO: fscanf returned %i, foundLayer = %i\n", num, foundLayer);
+if (errno)
+{
+       if (errno == EAGAIN)
+               printf("EAGAIN\n");
+       else if (errno == EBADF)
+               printf("EBADF\n");
+       else if (errno == EILSEQ)
+               printf("EILSEQ\n");
+       else if (errno == EINTR)
+               printf("EINTR\n");
+       else if (errno == EINVAL)
+               printf("EINVAL\n");
+       else if (errno == ENOMEM)
+               printf("ENOMEM\n");
+       else if (errno == ERANGE)
+               printf("ERANGE\n");
+       else
+               printf("errno = %i\n", errno);
+}
+}
 
        if (strcmp(buffer, "LINE") == 0)
        {
@@ -248,6 +288,12 @@ printf("Load: Adding object. Container size = %li (%li)\n", drawing->objects.siz
                *objectType = OTFEndOfFile;
        }
 
+       if (*object)
+               (*object)->layer = foundLayer;
+
        return recognized;
+#else
+       return false;
+#endif
 }