enable_opengl="no"])
fi
+AC_CHECK_LIB(z, gzopen,, AC_MSG_ERROR([*** zlib is missing]))
+
# FIXME: Evil
CXXFLAGS="$CXXFLAGS -DDATA_PREFIX='\"$datadir/supertux/\"' -DLINUX"
return lisp_obj;
}
+void mygzungetc(char c, void* file)
+{
+ gzungetc(c, file);
+}
+
+lisp_stream_t* lisp_stream_init_gzfile (lisp_stream_t *stream, gzFile file)
+{
+ return lisp_stream_init_any (stream, file, gzgetc, mygzungetc);
+}
+
+bool has_suffix(const char* data, const char* suffix)
+{
+ int suffix_len = strlen(suffix);
+ int data_len = strlen(data);
+
+ const char* data_suffix = (data + data_len - suffix_len);
+
+ if (data_suffix >= data)
+ {
+ return (strcmp(data_suffix, suffix) == 0);
+ }
+ else
+ {
+ return false;
+ }
+}
+
+lisp_object_t* lisp_read_from_file(const char* filename)
+{
+ lisp_stream_t stream;
+
+ if (has_suffix(filename, ".gz"))
+ {
+ 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;
+ }
+ else
+ {
+ lisp_object_t* obj = 0;
+ FILE* in = fopen(filename, "r");
+
+ if (in)
+ {
+ lisp_stream_init_file(&stream, in);
+ obj = lisp_read(&stream);
+ fclose(in);
+ }
+
+ return obj;
+ }
+}
+
+// EOF //
#define __LISPREADER_H__
#include <stdio.h>
+#include <zlib.h>
#include <string>
#include <vector>
} v;
};
+lisp_stream_t* lisp_stream_init_gzfile (lisp_stream_t *stream, gzFile file);
lisp_stream_t* lisp_stream_init_file (lisp_stream_t *stream, FILE *file);
lisp_stream_t* lisp_stream_init_string (lisp_stream_t *stream, char *buf);
lisp_stream_t* lisp_stream_init_any (lisp_stream_t *stream, void *data,
void (*unget_char) (char c, void *data));
lisp_object_t* lisp_read (lisp_stream_t *in);
+lisp_object_t* lisp_read_from_file(const char* filename);
void lisp_free (lisp_object_t *obj);
lisp_object_t* lisp_read_from_string (const char *buf);
TileManager::TileManager()
{
- lisp_stream_t stream;
- FILE* in = fopen(DATA_PREFIX "images/worldmap/antarctica.scm", "r");
- assert(in);
- lisp_stream_init_file (&stream, in);
- lisp_object_t* root_obj = lisp_read (&stream);
+ lisp_object_t* root_obj = lisp_read_from_file(DATA_PREFIX "images/worldmap/antarctica.scm");
+ assert(root_obj);
+
if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-worldmap-tiles") == 0)
{
lisp_object_t* cur = lisp_cdr(root_obj);
void
WorldMap::load_map()
{
- lisp_stream_t stream;
- FILE* in = fopen(DATA_PREFIX "levels/default/worldmap.scm", "r");
- assert(in);
- lisp_stream_init_file (&stream, in);
- lisp_object_t* root_obj = lisp_read (&stream);
+ lisp_object_t* root_obj = lisp_read_from_file(DATA_PREFIX "levels/default/worldmap.scm");
+ assert(root_obj);
if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-worldmap") == 0)
{
int y;
};
-struct Level
-{
- int x;
- int y;
- std::string name;
-};
-
struct Tile
{
texture_type sprite;
int width;
int height;
+ struct Level
+ {
+ int x;
+ int y;
+ std::string name;
+ };
+
typedef std::vector<Level> Levels;
Levels levels;