--- /dev/null
+// $Id$
+//
+// SuperTux - A Jump'n Run
+// Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#ifndef SUPERTUX_EXCEPTIONS_H
+#define SUPERTUX_EXCEPTIONS_H
+
+// Exceptions
+#include <exception>
+#include <string>
+
+class SuperTuxException : public std::exception
+{
+ public:
+ SuperTuxException(const char* _message, const char* _file = "", const unsigned int _line = 0)
+ : message(_message), file(_file), line(_line) { };
+ virtual ~SuperTuxException() throw() { };
+
+ const char* what() const throw() { return message; };
+ const char* what_file() const throw() { return file; };
+ const unsigned int what_line() const throw() { return line; };
+
+ private:
+ const char* message;
+ const char* file;
+ const unsigned int line;
+};
+
+#endif /*SUPERTUX_EXCEPTIONS_H*/
#include <iostream>
#include <string>
-#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
static void
_token_append (char c)
{
- assert(token_length < MAX_TOKEN_LENGTH);
+ if (token_length >= MAX_TOKEN_LENGTH)
+ throw LispReaderException("_token_append()", __FILE__, __LINE__);
token_string[token_length++] = c;
token_string[token_length] = '\0';
case LISP_STREAM_ANY:
return stream->v.any.next_char(stream->v.any.data);
}
- assert(0);
+
+ throw LispReaderException("_next_char()", __FILE__, __LINE__);
return EOF;
}
break;
default :
- assert(0);
+ throw LispReaderException("_unget_char()", __FILE__, __LINE__);
}
}
}
}
- assert(0);
+ throw LispReaderException("_scan()", __FILE__, __LINE__);
return TOKEN_ERROR;
}
int (*next_char) (void *data),
void (*unget_char) (char c, void *data))
{
- assert(next_char != 0 && unget_char != 0);
+ if (next_char == 0 || unget_char == 0)
+ throw LispReaderException("lisp_stream_init_any()", __FILE__, __LINE__);
stream->type = LISP_STREAM_ANY;
stream->v.any.data = data;
return lisp_make_boolean(0);
}
- assert(0);
+ throw LispReaderException("lisp_read()", __FILE__, __LINE__);
return &error_object;
}
static int
_match_pattern_var (lisp_object_t *pattern, lisp_object_t *obj, lisp_object_t **vars)
{
- assert(lisp_type(pattern) == LISP_TYPE_PATTERN_VAR);
+ if (lisp_type(pattern) != LISP_TYPE_PATTERN_VAR)
+ throw LispReaderException("_match_pattern_var", __FILE__, __LINE__);
switch (pattern->v.pattern.type)
{
for (sub = pattern->v.pattern.sub; sub != 0; sub = lisp_cdr(sub))
{
- assert(lisp_type(sub) == LISP_TYPE_CONS);
+ if (lisp_type(sub) != LISP_TYPE_CONS)
+ throw LispReaderException("_match_pattern_var()", __FILE__, __LINE__);
if (_match_pattern(lisp_car(sub), obj, vars))
matched = 1;
break;
default :
- assert(0);
+ throw LispReaderException("_match_pattern_var()", __FILE__, __LINE__);
}
if (vars != 0)
break;
default :
- assert(0);
+ throw LispReaderException("_match_pattern()", __FILE__, __LINE__);
}
return 0;
int
lisp_integer (lisp_object_t *obj)
{
- assert(obj->type == LISP_TYPE_INTEGER);
+ if (obj->type != LISP_TYPE_INTEGER)
+ throw LispReaderException("lisp_integer()", __FILE__, __LINE__);
return obj->v.integer;
}
char*
lisp_symbol (lisp_object_t *obj)
{
- assert(obj->type == LISP_TYPE_SYMBOL);
+ if (obj->type != LISP_TYPE_SYMBOL)
+ throw LispReaderException("lisp_symbol()", __FILE__, __LINE__);
return obj->v.string;
}
char*
lisp_string (lisp_object_t *obj)
{
- assert(obj->type == LISP_TYPE_STRING);
+ if (obj->type != LISP_TYPE_STRING)
+ throw LispReaderException("lisp_string()", __FILE__, __LINE__);
return obj->v.string;
}
int
lisp_boolean (lisp_object_t *obj)
{
- assert(obj->type == LISP_TYPE_BOOLEAN);
+ if (obj->type != LISP_TYPE_BOOLEAN)
+ throw LispReaderException("lisp_boolean()", __FILE__, __LINE__);
return obj->v.integer;
}
float
lisp_real (lisp_object_t *obj)
{
- assert(obj->type == LISP_TYPE_REAL || obj->type == LISP_TYPE_INTEGER);
+ if (obj->type != LISP_TYPE_REAL && obj->type != LISP_TYPE_INTEGER)
+ throw LispReaderException("lisp_real()", __FILE__, __LINE__);
if (obj->type == LISP_TYPE_INTEGER)
return obj->v.integer;
lisp_object_t*
lisp_car (lisp_object_t *obj)
{
- assert(obj->type == LISP_TYPE_CONS || obj->type == LISP_TYPE_PATTERN_CONS);
+ if (obj->type != LISP_TYPE_CONS && obj->type != LISP_TYPE_PATTERN_CONS)
+ throw LispReaderException("lisp_car()", __FILE__, __LINE__);
return obj->v.cons.car;
}
lisp_object_t*
lisp_cdr (lisp_object_t *obj)
{
- assert(obj->type == LISP_TYPE_CONS || obj->type == LISP_TYPE_PATTERN_CONS);
+ if (obj->type != LISP_TYPE_CONS && obj->type != LISP_TYPE_PATTERN_CONS)
+ throw LispReaderException("lisp_cdr()", __FILE__, __LINE__);
return obj->v.cons.cdr;
}
else if (x[i] == 'd')
obj = lisp_cdr(obj);
else
- assert(0);
+ throw LispReaderException("lisp_cxr()", __FILE__, __LINE__);
return obj;
}
while (obj != 0)
{
- assert(obj->type == LISP_TYPE_CONS || obj->type == LISP_TYPE_PATTERN_CONS);
+ if (obj->type != LISP_TYPE_CONS && obj->type != LISP_TYPE_PATTERN_CONS)
+ throw LispReaderException("lisp_list_length()", __FILE__, __LINE__);
++length;
obj = obj->v.cons.cdr;
{
while (index > 0)
{
- assert(obj != 0);
- assert(obj->type == LISP_TYPE_CONS || obj->type == LISP_TYPE_PATTERN_CONS);
+ if (obj == 0)
+ throw LispReaderException("lisp_list_nth_cdr()", __FILE__, __LINE__);
+ if (obj->type != LISP_TYPE_CONS && obj->type != LISP_TYPE_PATTERN_CONS)
+ throw LispReaderException("lisp_list_nth_cdr()", __FILE__, __LINE__);
--index;
obj = obj->v.cons.cdr;
{
obj = lisp_list_nth_cdr(obj, index);
- assert(obj != 0);
+ if (obj == 0)
+ throw LispReaderException("lisp_list_nth()", __FILE__, __LINE__);
return obj->v.cons.car;
}
break;
default :
- assert(0);
+ throw LispReaderException("lisp_dump()", __FILE__, __LINE__);
}
}
int buf_pos = 0;
int try_number = 1;
char* buf = static_cast<char*>(malloc(chunk_size));
- assert(buf);
+ if (!buf)
+ throw LispReaderException("lisp_read_from_gzfile()", __FILE__, __LINE__);
gzFile in = gzopen(filename, "r");
if (ret == -1)
{
free (buf);
- assert(!"Error while reading from file");
+ throw LispReaderException("Error while reading from file", __FILE__, __LINE__);
}
else if (ret == chunk_size) // buffer got full, eof not yet there so resize
{
buf_pos = chunk_size * try_number;
try_number += 1;
buf = static_cast<char*>(realloc(buf, chunk_size * try_number));
- assert(buf);
+
+ if (!buf)
+ throw LispReaderException("lisp_read_from_gzfile()", __FILE__, __LINE__);
}
else
{