- removed st_abort() from lisp reader, client code should check the return value...
[supertux.git] / src / lispreader.cpp
index 7981189..9074633 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
+#include <iostream>
 #include <string>
 #include <assert.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
-
+#include "setup.h"
 #include "lispreader.h"
 
 #define TOKEN_ERROR                   -1
 static char token_string[MAX_TOKEN_LENGTH + 1] = "";
 static int token_length = 0;
 
-static lisp_object_t end_marker = { LISP_TYPE_EOF };
-static lisp_object_t error_object = { LISP_TYPE_PARSE_ERROR };
-static lisp_object_t close_paren_marker = { LISP_TYPE_PARSE_ERROR };
-static lisp_object_t dot_marker = { LISP_TYPE_PARSE_ERROR };
+static lisp_object_t end_marker = { LISP_TYPE_EOF, {{0, 0}} };
+static lisp_object_t error_object = { LISP_TYPE_PARSE_ERROR , {{0,0}}  };
+static lisp_object_t close_paren_marker = { LISP_TYPE_PARSE_ERROR , {{0,0}}  };
+static lisp_object_t dot_marker = { LISP_TYPE_PARSE_ERROR , {{0,0}} };
 
 static void
 _token_clear (void)
@@ -1041,6 +1042,8 @@ LispReader::read_int (const char* name, int* i)
   lisp_object_t* obj = search_for (name);
   if (obj)
     {
+      if (!lisp_integer_p(lisp_car(obj)))
+        st_abort("LispReader expected type integer at token: ", name);
       *i = lisp_integer(lisp_car(obj));
       return true;
     }
@@ -1066,6 +1069,8 @@ LispReader::read_float (const char* name, float* f)
   lisp_object_t* obj = search_for (name);
   if (obj)
     {
+      if (!lisp_real_p(lisp_car(obj)) && !lisp_integer_p(lisp_car(obj)))
+        st_abort("LispReader expected type real at token: ", name);
       *f = lisp_real(lisp_car(obj));
       return true;
     }
@@ -1080,6 +1085,8 @@ LispReader::read_string_vector (const char* name, std::vector<std::string>* vec)
     {
       while(!lisp_nil_p(obj))
         {
+          if (!lisp_string_p(lisp_car(obj)))
+            st_abort("LispReader expected type string at token: ", name);
           vec->push_back(lisp_string(lisp_car(obj)));
           obj = lisp_cdr(obj);
         }
@@ -1096,6 +1103,8 @@ LispReader::read_int_vector (const char* name, std::vector<int>* vec)
     {
       while(!lisp_nil_p(obj))
         {
+          if (!lisp_integer_p(lisp_car(obj)))
+            st_abort("LispReader expected type integer at token: ", name);
           vec->push_back(lisp_integer(lisp_car(obj)));
           obj = lisp_cdr(obj);
         }
@@ -1126,7 +1135,8 @@ LispReader::read_string (const char* name, std::string* str)
   lisp_object_t* obj = search_for (name);
   if (obj)
     {
-
+      if (!lisp_string_p(lisp_car(obj)))
+        st_abort("LispReader expected type string at token: ", name);
      *str = lisp_string(lisp_car(obj));
       return true;
     }
@@ -1139,6 +1149,8 @@ LispReader::read_bool (const char* name, bool* b)
   lisp_object_t* obj = search_for (name);
   if (obj)
     {
+      if (!lisp_boolean_p(lisp_car(obj)))
+        st_abort("LispReader expected type bool at token: ", name);
       *b = lisp_boolean(lisp_car(obj));
       return true;
     }
@@ -1305,18 +1317,6 @@ lisp_object_t* lisp_read_from_file(const std::string& filename)
   if (has_suffix(filename.c_str(), ".gz"))
     {
       return lisp_read_from_gzfile(filename.c_str());
-#if 0
-      lisp_object_t* obj = 0;
-      gzFile in = gzopen(filename, "r");
-
-      if (in)
-        {
-          lisp_stream_init_gzfile(&stream, in);
-          obj = lisp_read(&stream);
-          gzclose(in);
-        }
-        return obj;
-#endif
     }
   else
     {