├── bin ├── 2dracer │ ├── vehical.class │ ├── 31.png │ ├── 32.png │ ├── 33.png │ ├── 34.png │ ├── rocket.png │ ├── missile.png │ ├── background.png │ ├── test_file │ └── game.ini └── pyengine_test.py ├── src ├── point.h ├── mem_manager │ ├── llist.h.gch │ ├── pyobjs.h │ ├── string_node.h │ ├── image_node.h │ └── llist.h ├── objects │ ├── vehical.cc │ ├── vehical.h │ ├── object.h │ └── object.cc ├── pyengine │ ├── pyengine.h │ └── pyengine.cc ├── sdl │ ├── timer.h │ ├── event.h │ ├── graphics.h │ ├── event.cc │ ├── sdl_dm.h │ ├── timer.cc │ ├── graphics.cc │ └── sdl_dm.cc ├── tests │ ├── makefile │ └── pyengine_test.cc ├── helpers │ ├── file_helper.h │ ├── string_tokenizer.h │ ├── config_loader.cc │ ├── string_helper.h │ ├── sdl_helper.h │ ├── config_loader.h │ ├── string_helper.cc │ ├── file_helper.cc │ └── string_tokenizer.cc ├── map.h ├── map.cc ├── resources.h ├── tester.cc ├── main.cc └── ini_parser │ ├── dictionary.h │ ├── iniparser.h │ ├── dictionary.c │ └── iniparser.c ├── makefile └── tags /bin/2dracer/vehical.class: -------------------------------------------------------------------------------- 1 | top_speed = 100 2 | speed>=top_speed?true:false 3 | -------------------------------------------------------------------------------- /bin/2dracer/31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmahmood/game_engine/master/bin/2dracer/31.png -------------------------------------------------------------------------------- /bin/2dracer/32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmahmood/game_engine/master/bin/2dracer/32.png -------------------------------------------------------------------------------- /bin/2dracer/33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmahmood/game_engine/master/bin/2dracer/33.png -------------------------------------------------------------------------------- /bin/2dracer/34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmahmood/game_engine/master/bin/2dracer/34.png -------------------------------------------------------------------------------- /bin/2dracer/rocket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmahmood/game_engine/master/bin/2dracer/rocket.png -------------------------------------------------------------------------------- /bin/2dracer/missile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmahmood/game_engine/master/bin/2dracer/missile.png -------------------------------------------------------------------------------- /src/point.h: -------------------------------------------------------------------------------- 1 | #ifndef POINT_H_ 2 | 3 | #define POINT_H_ 4 | 5 | 6 | #endif /* POINT_H_ */ 7 | 8 | 9 | -------------------------------------------------------------------------------- /bin/2dracer/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmahmood/game_engine/master/bin/2dracer/background.png -------------------------------------------------------------------------------- /src/mem_manager/llist.h.gch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmahmood/game_engine/master/src/mem_manager/llist.h.gch -------------------------------------------------------------------------------- /bin/2dracer/test_file: -------------------------------------------------------------------------------- 1 | First Map! 2 | 10 10 3 | @ 4 | ########## 5 | ########## 6 | ####x##### 7 | ####x##### 8 | ####x##### 9 | ####x##### 10 | ####x##### 11 | ####x##### 12 | ####x##### 13 | ####x##### 14 | -------------------------------------------------------------------------------- /src/objects/vehical.cc: -------------------------------------------------------------------------------- 1 | #include "vehical.h" 2 | #include 3 | 4 | void Vehical::move(Direction dir) 5 | { 6 | move_int(dir); 7 | } 8 | 9 | int Vehical::get_top_speed() 10 | { 11 | return top_speed; 12 | } 13 | 14 | void Vehical::set_top_speed(int ts) 15 | { 16 | top_speed = ts; 17 | } 18 | -------------------------------------------------------------------------------- /src/objects/vehical.h: -------------------------------------------------------------------------------- 1 | #ifndef VEHICAL_H_ 2 | #define VEHICAL_H_ 3 | 4 | #include "object.h" 5 | 6 | class Vehical : public Object 7 | { 8 | private: 9 | int top_speed; 10 | 11 | public: 12 | void set_top_speed(int); 13 | void move(Direction); 14 | int get_top_speed(); 15 | }; 16 | 17 | 18 | #endif /* SRC/OBJECTS/VEHICAL_H_ */ 19 | 20 | -------------------------------------------------------------------------------- /src/pyengine/pyengine.h: -------------------------------------------------------------------------------- 1 | #ifndef PYENGINE_H_ 2 | 3 | #define PYENGINE_H_ 4 | 5 | #include 6 | 7 | class PyEngine 8 | { 9 | public: 10 | PyEngine (char **, int); 11 | virtual ~PyEngine(); 12 | 13 | PyObject* load_module(PyObject *); 14 | PyObject* call_method(PyObject *,PyObject *); 15 | void check_error(); 16 | 17 | private: 18 | 19 | }; 20 | 21 | #endif /* SRC/PYENGINE/PYENGINE_H_ */ 22 | 23 | -------------------------------------------------------------------------------- /src/sdl/timer.h: -------------------------------------------------------------------------------- 1 | #ifndef TIME_H_ 2 | 3 | #define TIME_H_ 4 | 5 | class Timer 6 | { 7 | private: 8 | int start_ticks; 9 | int paused_ticks; 10 | bool paused; 11 | bool started; 12 | 13 | public: 14 | Timer(); 15 | void start(); 16 | void stop(); 17 | void pause(); 18 | void unpause(); 19 | int get_ticks(); 20 | bool is_started(); 21 | bool is_paused(); 22 | }; 23 | 24 | #endif /* TIME_H_ */ 25 | 26 | -------------------------------------------------------------------------------- /src/sdl/event.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENT_H_ 2 | 3 | #define EVENT_H_ 4 | 5 | #include "../resources.h" 6 | 7 | #define MAX_KEYS 512 8 | 9 | class Event 10 | { 11 | protected: 12 | Fx listeners[MAX_KEYS]; 13 | bool events_set[MAX_KEYS]; 14 | void call_function(void(*)()); 15 | 16 | public: 17 | Event(); 18 | void add_listener(int, Fx); 19 | bool get_key_state(int); 20 | void get_key_pressed(); 21 | }; 22 | 23 | 24 | 25 | #endif /* SRC/SDL/EVENT_H_ */ 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/tests/makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CFLAGS=-c -Wall -g 3 | LDFLAGS=-g -Wall 4 | SDLFLAG=`sdl-config --cflags --libs` -lSDL_image 5 | PYFLAGS=-l python2.5 6 | EXECUTABLE=../../bin/test 7 | 8 | python_c: pyengine test_pyengine 9 | $(CC) ../../obj/pyengine.o $(LDFLAGS) $(PYFLAGS) -o$(EXECUTABLE) 10 | 11 | test_pyengine: 12 | $(CC) -c pyengine_test.cc -o ../../obj/test_pyengine.o 13 | 14 | pyengine: 15 | $(CC) $(CFLAGS) $(PYFLAGS) -c ../pyengine/pyengine.cc -o ../../obj/pyengine.o 16 | -------------------------------------------------------------------------------- /bin/pyengine_test.py: -------------------------------------------------------------------------------- 1 | def print_test_data(): 2 | print ("Hello world") 3 | 4 | def print_arg(arg): 5 | print (arg) 6 | 7 | def return_result(x, y): 8 | return x * y 9 | 10 | class Test_class: 11 | def __init(self): 12 | print ("Welcome to test class! make your self at home!") 13 | 14 | def method_test_data(self): 15 | print("Test data"); 16 | 17 | def method_arg(self, arg): 18 | print(arg); 19 | 20 | def method_return_result(self, x,y): 21 | return x + y 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/sdl/graphics.h: -------------------------------------------------------------------------------- 1 | class Graphics 2 | { 3 | public: 4 | Graphics ( ); 5 | virtual ~Graphics(); 6 | 7 | bool copy_img_to(SDL_Surface*, SDL_Rect, Point); 8 | bool draw_image(SDL_Surface *image, int x=0, int y=0); 9 | void fill_rect(Uint32, SDL_Rect*); 10 | void fill_rect(Uint32, Rectangle*); 11 | void fill_surface(Uint32); 12 | void put_pixel(int , int , Uint32 ); 13 | Uint8 get_pixel(int , int ); 14 | Uint32 get_colorkey(int , int , int ); 15 | 16 | 17 | private: 18 | 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /bin/2dracer/game.ini: -------------------------------------------------------------------------------- 1 | [game] 2 | name=2D Racer 3 | actor_count=2 4 | 5 | [actor1] 6 | id=100 7 | life=100 8 | damage=10 9 | start_x=100 10 | start_y=100 11 | image=missile.png 12 | width=64 13 | height=86 14 | top_speed=20 15 | speed=0 16 | mass=5 17 | level=0 18 | max_level=5 19 | class=1 20 | 21 | [actor2] 22 | id=101 23 | life=100 24 | damage=0 25 | start_x=300 26 | start_y=300 27 | image=31.png 28 | width=64 29 | height=64 30 | top_speed=0 31 | speed=0 32 | mass=5 33 | level=0 34 | max_level=5 35 | class=0 36 | -------------------------------------------------------------------------------- /src/helpers/file_helper.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE_HELPER_H_ 2 | 3 | #define FILE_HELPER_H_ 4 | #include 5 | 6 | class File_helper 7 | { 8 | public: 9 | File_helper (); 10 | virtual ~File_helper(); 11 | 12 | bool read_file(char *); 13 | long get_file_size(char *); 14 | 15 | char *get_last_read_data(); 16 | long get_last_file_size(); 17 | 18 | void clean_up(); 19 | private: 20 | long get_file_size(FILE *); 21 | 22 | char *last_read_data; 23 | size_t file_size; 24 | }; 25 | #endif /* SRC/FILE_HELPER_H_ */ 26 | 27 | -------------------------------------------------------------------------------- /src/helpers/string_tokenizer.h: -------------------------------------------------------------------------------- 1 | #ifndef STRING_TOKENIZER_H_ 2 | 3 | #define STRING_TOKENIZER_H_ 4 | #include "string_helper.h" 5 | 6 | class String_tokenizer 7 | { 8 | public: 9 | String_tokenizer ( ); 10 | virtual ~String_tokenizer(); 11 | int split(char*, char); 12 | char *get(int); 13 | char *get_token(int); 14 | void clean_up(); 15 | int get_token_count(); 16 | 17 | private: 18 | int token_count; 19 | char *tokenized_str; 20 | int *token_positions; 21 | 22 | }; 23 | 24 | 25 | 26 | #endif /* SRC/STRING_TOKENIZER_H_ */ 27 | 28 | -------------------------------------------------------------------------------- /src/helpers/config_loader.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: config_loader.cc 5 | * 6 | * Description: Defination 7 | * 8 | * Version: 1.0 9 | * Created: 01/20/2009 01:17:23 PM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Tarin Mahmood (tmn), mrlinux045@gmail.com 14 | * Company: tmnSoft 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/helpers/string_helper.h: -------------------------------------------------------------------------------- 1 | #ifndef STRING_HELPER_H_ 2 | 3 | #define STRING_HELPER_H_ 4 | 5 | 6 | #include 7 | #include 8 | #include "../mem_manager/llist.h" 9 | #include "../mem_manager/string_node.h" 10 | 11 | class String_helper 12 | { 13 | public: 14 | static bool copy_string(char *&dest, const char *src); 15 | static void trim(char *, char); 16 | static void trim_left(char *, char); 17 | static void trim_right(char *, char); 18 | static char* search(char *, char, char); 19 | static void add_string(LinkedList&, int , char*); 20 | }; 21 | 22 | #endif /* SRC/STRING_HELPER_H_ */ 23 | 24 | -------------------------------------------------------------------------------- /src/tests/pyengine_test.cc: -------------------------------------------------------------------------------- 1 | #include "../mem_manager/llist.h" 2 | #include "../mem_manager/pyobjs.h" 3 | 4 | 5 | bool test_engine(char **argv, int argc) 6 | { 7 | LinkedListpyobj_list; 8 | 9 | PyObject *t = pyobj_list.add(PyString_FromString("pyengine_test"), 1000); 10 | PyEngine py_engine(argv, argc); 11 | 12 | pyobj_list.add(py_engine.load_module(t), 1002); 13 | pyobj_list.add(PyString_FromString("print_test_data"), 1003); 14 | 15 | py_engine.call_method(pyobj_list.get(1003)); 16 | } 17 | 18 | int main (int argc, char const* argv[]) 19 | { 20 | printf("Test started!\n"); 21 | test_engine(argv, argc); 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/map.h: -------------------------------------------------------------------------------- 1 | #ifndef MAP_H_ 2 | 3 | #define MAP_H_ 4 | 5 | #include "helpers/string_helper.h" 6 | #include "helpers/file_helper.h" 7 | #include "helpers/string_tokenizer.h" 8 | #include "point.h" 9 | 10 | class Map 11 | { 12 | public: 13 | Map (); 14 | bool load_map(char *map_file); 15 | void clean_up(); 16 | void display_map_info(); 17 | bool is_valid_position(Point); 18 | ~Map(); 19 | 20 | private: 21 | File_helper file_helper; 22 | String_helper string_helper; 23 | 24 | char *map; 25 | 26 | char *map_title; 27 | 28 | int map_width; 29 | int map_height; 30 | 31 | Point start_point; 32 | Point end_point; 33 | }; 34 | 35 | #endif /* MAP_H_ */ 36 | 37 | -------------------------------------------------------------------------------- /src/pyengine/pyengine.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pyengine.h" 3 | 4 | PyEngine::PyEngine(char **argv, int argc) 5 | { 6 | Py_SetProgramName(argv[0]); 7 | Py_Initialize(); 8 | PySys_SetArgv(argc, argv); 9 | check_error(); 10 | 11 | } 12 | 13 | void PyEngine::check_error() 14 | { 15 | if (PyErr_Occurred()) 16 | { 17 | PyErr_Print(); 18 | } 19 | } 20 | 21 | PyEngine::~PyEngine() 22 | { 23 | Py_Finalize(); 24 | } 25 | 26 | PyObject* PyEngine::load_module(PyObject *module_name) 27 | { 28 | return PyImport_Import(module_name); 29 | } 30 | 31 | PyObject* call_method(PyObject *method, PyObject *args=NULL) 32 | { 33 | return PyObject_CallObject(method, args); 34 | } 35 | -------------------------------------------------------------------------------- /src/helpers/sdl_helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: sdl_helper.h 5 | * 6 | * Description: SDL helper class defination 7 | * 8 | * Version: 1.0 9 | * Created: 01/01/2009 01:50:49 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Tarin Mahmood (tmn), mrlinux045@gmail.com 14 | * Company: tmnSoft 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | class SDL_Helper 20 | { 21 | public: 22 | SDL_Helper ( ); 23 | virtual ~SDL_Helper(); 24 | 25 | private: 26 | 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /src/helpers/config_loader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: config_loader.h 5 | * 6 | * Description: Loads configurations 7 | * 8 | * Version: 1.0 9 | * Created: 01/20/2009 01:17:11 PM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Tarin Mahmood (tmn), mrlinux045@gmail.com 14 | * Company: tmnSoft 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | class Config_loader 20 | { 21 | private: 22 | void set_config_file(char *); 23 | void init_configuraion(); 24 | 25 | public: 26 | }; 27 | -------------------------------------------------------------------------------- /src/mem_manager/pyobjs.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class PyObject_node 4 | { 5 | public: 6 | PyObject_node *next; 7 | PyObject_node *prev; 8 | 9 | int index; 10 | bool empty; 11 | 12 | PyObject_node ( ) 13 | { 14 | empty = true; 15 | 16 | } 17 | virtual ~PyObject_node() 18 | { 19 | if(empty) 20 | { 21 | return; 22 | } 23 | Py_DECREF(data); 24 | if(data!=NULL) 25 | { 26 | Py_XDECREF(data); 27 | } 28 | } 29 | 30 | void set_data(PyObject *obj) 31 | { 32 | if(!empty) 33 | { 34 | Py_DECREF(data); 35 | } 36 | 37 | data = obj; 38 | empty = false; 39 | } 40 | 41 | PyObject* get_data() 42 | { 43 | return data; 44 | } 45 | 46 | bool equals(PyObject *target) 47 | { 48 | return(target == data); 49 | } 50 | 51 | 52 | private: 53 | PyObject *data; 54 | }; 55 | 56 | -------------------------------------------------------------------------------- /src/sdl/event.cc: -------------------------------------------------------------------------------- 1 | #include "../resources.h" 2 | 3 | Event::Event() 4 | { 5 | for( int i = 0; i < MAX_KEYS; i += 1) 6 | { 7 | events_set[i] = false; 8 | } 9 | } 10 | 11 | void Event::call_function(void (*func_name)()) 12 | { 13 | func_name(); 14 | 15 | } 16 | 17 | void Event::add_listener(int key_code, Fx func) 18 | { 19 | listeners[key_code] = func; 20 | events_set[key_code] = true; 21 | } 22 | 23 | void Event::get_key_pressed() 24 | { 25 | SDL_Event event; 26 | int sym; 27 | SDL_WaitEvent(&event); 28 | switch (event.type) 29 | { 30 | case SDL_KEYDOWN: 31 | case SDL_KEYUP: 32 | sym = event.key.keysym.sym; 33 | if(events_set[sym]) 34 | { 35 | call_function(listeners[sym]); 36 | } 37 | break; 38 | 39 | case SDL_QUIT: 40 | call_function(listeners[event.type]); 41 | break; 42 | } 43 | } 44 | 45 | bool Event::get_key_state(int key_code) 46 | { 47 | Uint8 *key_state = SDL_GetKeyState(NULL); 48 | return key_state[key_code]; 49 | } 50 | -------------------------------------------------------------------------------- /src/mem_manager/string_node.h: -------------------------------------------------------------------------------- 1 | #ifndef STRING_NODE_H_ 2 | 3 | #define STRING_NODE_H_ 4 | 5 | //char test[][5] = {"123", "234"}; 6 | 7 | class String_node 8 | { 9 | char* data; 10 | public: 11 | String_node *next; 12 | String_node *prev; 13 | int index; 14 | bool empty; 15 | 16 | String_node() 17 | { 18 | data = NULL; 19 | empty = false; 20 | } 21 | 22 | void set_data(char *d=NULL) 23 | { 24 | if(!empty) 25 | { 26 | delete data; 27 | } 28 | int len; 29 | if(d==NULL) 30 | { 31 | empty = true; 32 | len = 10; 33 | } 34 | else 35 | { 36 | len = strlen(d); 37 | } 38 | 39 | data = new char[len]; 40 | strcpy(data, d); 41 | 42 | } 43 | 44 | char *get_data() 45 | { 46 | return data; 47 | } 48 | 49 | ~String_node() 50 | { 51 | printf(">%s\n", data); 52 | delete data; 53 | } 54 | 55 | bool equals(char *d) 56 | { 57 | return strcmp(d, data) == 0; 58 | } 59 | }; 60 | 61 | 62 | 63 | 64 | #endif /* STRING_NODE_H_ */ 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/sdl/sdl_dm.h: -------------------------------------------------------------------------------- 1 | #ifndef SDL_DM_H_ 2 | 3 | #define SDL_DM_H_ 4 | 5 | #include "../resources.h" 6 | 7 | class SDL_DM 8 | { 9 | private: 10 | SDL_Surface *Display; 11 | int scr_width; 12 | int scr_height; 13 | int wbit; 14 | int wflag; 15 | Uint32 background_color; 16 | bool initialized; 17 | 18 | public: 19 | SDL_DM(); 20 | ~SDL_DM(); 21 | 22 | bool is_initialized(); 23 | 24 | void set_screen_size(int, int); 25 | void set_display_flags(int); 26 | void set_display_color_bit(int); 27 | 28 | bool init_dm(); 29 | void close_display_manager(); 30 | void redraw(); 31 | 32 | bool copy_img_to(SDL_Surface*, SDL_Rect, Point); 33 | bool draw_image(SDL_Surface *image, int x=0, int y=0); 34 | void fill_rect(Uint32, SDL_Rect*); 35 | void fill_rect(Uint32, Rectangle*); 36 | void fill_surface(Uint32); 37 | void put_pixel(int , int , Uint32 ); 38 | Uint8 get_pixel(int , int ); 39 | 40 | long get_ticks(); 41 | SDL_PixelFormat *get_display_format (); 42 | Uint32 get_colorkey(int , int , int ); 43 | }; 44 | 45 | #endif /* SDL_DM_H_ */ 46 | 47 | -------------------------------------------------------------------------------- /src/objects/object.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECT_H_ 2 | #define OBJECT_H_ 3 | #include "../resources.h" 4 | 5 | class Object 6 | { 7 | public: 8 | 9 | virtual void set_life(int); 10 | virtual void set_size(int,int); 11 | virtual void set_damage(int); 12 | virtual void set_level(int); 13 | virtual void set_obj_id(int); 14 | virtual void set_position(int, int); 15 | virtual void set_speed(int); 16 | virtual void set_direction(Direction); 17 | 18 | int get_life(); 19 | int get_width(); 20 | int get_height(); 21 | int get_damage(); 22 | int get_level(); 23 | int get_obj_id(); 24 | int get_pos_x(); 25 | int get_pos_y(); 26 | int get_current_speed(); 27 | Direction get_direction(); 28 | 29 | virtual void move(Direction dir, int amount=0); 30 | Rectangle get_rectangle (); 31 | 32 | protected: 33 | int obj_id; 34 | int life; 35 | int width; 36 | int height; 37 | int damage; 38 | int level; 39 | Direction current_dir; 40 | 41 | int speed; 42 | 43 | int pos_x; 44 | int pos_y; 45 | 46 | void move_int (Direction); 47 | }; 48 | 49 | #endif /* SRC/OBJECTS/OBJECT_H_ */ 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/sdl/timer.cc: -------------------------------------------------------------------------------- 1 | #include "timer.h" 2 | #include 3 | 4 | Timer::Timer() 5 | { 6 | start_ticks = 0; 7 | paused_ticks = 0; 8 | paused = false; 9 | started = false; 10 | } 11 | 12 | void Timer::start() 13 | { 14 | started = true; 15 | paused = false; 16 | start_ticks = SDL_GetTicks(); 17 | } 18 | 19 | void Timer::stop() 20 | { 21 | started = false; 22 | paused = false; 23 | } 24 | 25 | void Timer::pause() 26 | { 27 | if( started && !paused ) 28 | { 29 | paused = true; 30 | paused_ticks = SDL_GetTicks() - start_ticks; 31 | } 32 | } 33 | 34 | void Timer::unpause() 35 | { 36 | if( paused == true ) 37 | { 38 | paused = false; 39 | start_ticks = SDL_GetTicks() - paused_ticks; 40 | paused_ticks = 0; 41 | } 42 | } 43 | 44 | int Timer::get_ticks() 45 | { 46 | if( started == true ) 47 | { 48 | if( paused == true ) 49 | { 50 | return paused_ticks; 51 | } 52 | else 53 | { 54 | return SDL_GetTicks() - start_ticks; 55 | } 56 | } 57 | return 0; 58 | } 59 | 60 | bool Timer::is_started() 61 | { 62 | return started; 63 | } 64 | 65 | bool Timer::is_paused() 66 | { 67 | return paused; 68 | } 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/mem_manager/image_node.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: image.h 5 | * 6 | * Description: image class to use as node in LinkedList 7 | * 8 | * Version: 1.0 9 | * Created: 01/01/2009 02:04:08 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Tarin Mahmood (tmn), mrlinux045@gmail.com 14 | * Company: tmnSoft 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | 20 | #include 21 | #include "../mem_manager/llist.h" 22 | 23 | class Image_node 24 | { 25 | SDL_Surface *data; 26 | public: 27 | Image_node *next; 28 | Image_node *prev; 29 | int index; 30 | 31 | void set_data(SDL_Surface *d) 32 | { 33 | data = d; 34 | } 35 | 36 | SDL_Surface* get_data() 37 | { 38 | return data; 39 | } 40 | 41 | ~Image_node() 42 | { 43 | if(data!=NULL) 44 | { 45 | printf("Deleting Image %d: ", index); 46 | delete data; 47 | printf("DONE\n"); 48 | } 49 | } 50 | 51 | bool equals(SDL_Surface* tdata) 52 | { 53 | return tdata == data; 54 | } 55 | 56 | }; 57 | 58 | -------------------------------------------------------------------------------- /src/map.cc: -------------------------------------------------------------------------------- 1 | #include "map.h" 2 | 3 | Map::Map() 4 | { 5 | map = NULL; 6 | map_title = NULL; 7 | } 8 | 9 | Map::~Map() 10 | { 11 | clean_up(); 12 | } 13 | 14 | void Map::clean_up() 15 | { 16 | if(map_title != NULL) 17 | { 18 | delete map_title; 19 | } 20 | 21 | if (map != NULL) 22 | { 23 | delete map; 24 | } 25 | } 26 | 27 | bool Map::load_map(char *map_file) 28 | { 29 | clean_up(); 30 | 31 | String_tokenizer stokenizer; 32 | char *map_info; 33 | char *map_data; 34 | char *map_size; 35 | 36 | if (!file_helper.read_file(map_file)) 37 | { 38 | return false; 39 | } 40 | 41 | map_data = file_helper.get_last_read_data(); 42 | stokenizer.split(map_data, '@'); 43 | 44 | map = stokenizer.get(1); 45 | map_info = stokenizer.get(0); 46 | 47 | string_helper.trim(map_info , '\n'); 48 | string_helper.trim(map , '\n'); 49 | 50 | 51 | stokenizer.split(map_info, '\n'); 52 | 53 | map_title = stokenizer.get(0); 54 | map_size = stokenizer.get(1); 55 | 56 | sscanf(map_size, "%d %d", &map_width, &map_height); 57 | 58 | delete map_info; 59 | delete map_data; 60 | delete map_size; 61 | return true; 62 | } 63 | 64 | bool Map::is_valid_position(Point p) 65 | { 66 | int x = p.x; 67 | int y = p.y; 68 | 69 | if(x>map_width || x <0) 70 | { 71 | return false; 72 | } 73 | 74 | if(y>map_height || y<0) 75 | { 76 | return false; 77 | } 78 | 79 | return true; 80 | } 81 | 82 | void Map::display_map_info() 83 | { 84 | printf("map title : %s\n", map_title); 85 | printf("map size : %d %d\n", map_width, map_height); 86 | map[map_width * 2 + 5] = 'W'; 87 | printf("map :\n[%s]\n", map); 88 | } 89 | -------------------------------------------------------------------------------- /src/helpers/string_helper.cc: -------------------------------------------------------------------------------- 1 | #include "../resources.h" 2 | #include "string_helper.h" 3 | 4 | bool String_helper::copy_string(char *&dest, const char *src) 5 | { 6 | try 7 | { 8 | int len = strlen(src); 9 | dest = new char[len]; 10 | strcpy(dest, src); 11 | return true; 12 | } 13 | catch(...) 14 | { 15 | if(dest !=NULL) 16 | { 17 | delete dest; 18 | } 19 | return false; 20 | } 21 | } 22 | char *String_helper::search(char *src, char search_key, char direction = 'f') 23 | { 24 | if(direction == 'f') 25 | { 26 | return strchr(src, search_key); 27 | } 28 | else 29 | { 30 | return strrchr(src, search_key); 31 | } 32 | } 33 | 34 | void String_helper::trim_right(char *string, char trim_char) 35 | { 36 | int i = strlen(string)-1; 37 | 38 | while( string[i] == trim_char) 39 | { 40 | i--; 41 | } 42 | string[i+1] = '\0'; 43 | } 44 | 45 | void String_helper::trim_left(char *src, char trim_char) 46 | { 47 | char *result = src; 48 | char *orig_str; 49 | 50 | orig_str = &result[0]; 51 | 52 | while(result[0] == trim_char) 53 | { 54 | result = &result[1]; 55 | } 56 | strcpy(src, result); 57 | } 58 | 59 | void String_helper::trim(char *src, char trim_char) 60 | { 61 | trim_right(src, trim_char); 62 | trim_left(src, trim_char); 63 | } 64 | 65 | void String_helper::add_string(LinkedList&list, int target, char *src2) 66 | { 67 | char *tmp = new char[strlen(list.get(target)) + strlen(src2) + 1]; 68 | if(tmp == NULL) 69 | { 70 | throw MEMORY_ALLOCATION_ERROR; 71 | } 72 | sprintf(tmp, "%s%s", list.get(target), src2); 73 | list.update(target, tmp); 74 | delete tmp; 75 | } 76 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CFLAGS=-c -Wall -g 3 | LDFLAGS=-g -Wall 4 | SDLFLAG=`sdl-config --cflags --libs` -lSDL_image 5 | PYFLAGS=-l python2.5 6 | EXECUTABLE=bin/game_engine.a 7 | 8 | game_engine: main string_helper string_tokenizer file_helper sdl object vehical timer ini_parser dictionary pyengine events 9 | g++ obj/main.o obj/string_helper.o obj/string_tokenizer.o obj/file_helper.o obj/sdl_dm.o obj/object.o obj/vehical.o obj/timer.o obj/ini_parser.o obj/dictionary.o obj/pyengine.o obj/event.o $(SDLFLAG) $(LDFLAGS) $(PYFLAGS) -o$(EXECUTABLE) 10 | 11 | main: 12 | g++ $(CFLAGS) -c src/main.cc -oobj/main.o 13 | 14 | string_helper: 15 | g++ $(CFLAGS) -c src/helpers/string_helper.cc -o obj/string_helper.o 16 | 17 | string_tokenizer: 18 | g++ $(CFLAGS) -c src/helpers/string_tokenizer.cc -o obj/string_tokenizer.o 19 | 20 | file_helper: 21 | g++ $(CFLAGS) -c src/helpers/file_helper.cc -o obj/file_helper.o 22 | 23 | sdl: 24 | g++ $(CFLAGS) $(SDLFLAG) -c src/sdl/sdl_dm.cc -o obj/sdl_dm.o 25 | 26 | vehical: 27 | g++ $(CFLAGS) $(SDLFLAG) -c src/objects/vehical.cc -o obj/vehical.o 28 | 29 | object: 30 | g++ $(CFLAGS) $(SDLFLAG) -c src/objects/object.cc -o obj/object.o 31 | 32 | timer: 33 | g++ $(CFLAGS) $(SDLFLAG) -c src/sdl/timer.cc -o obj/timer.o 34 | 35 | ini_parser: 36 | g++ $(CFLAGS) $(SDLFLAG) -c src/ini_parser/iniparser.c -o obj/ini_parser.o 37 | 38 | dictionary: 39 | g++ $(CFLAGS) $(SDLFLAG) -c src/ini_parser/dictionary.c -o obj/dictionary.o 40 | 41 | pyengine: 42 | g++ $(CFLAGS) $(PYFLAGS) -c src/pyengine/pyengine.cc -o obj/pyengine.o 43 | 44 | events: 45 | g++ $(CFLAGS) $(SDLFLAG) -c src/sdl/event.cc -o obj/event.o 46 | 47 | clean: 48 | rm obj/*.o 49 | rm $(EXECUTABLE) 50 | 51 | -------------------------------------------------------------------------------- /src/helpers/file_helper.cc: -------------------------------------------------------------------------------- 1 | #include "file_helper.h" 2 | #include 3 | 4 | File_helper::File_helper() 5 | { 6 | last_read_data = NULL; 7 | } 8 | 9 | File_helper::~File_helper() 10 | { 11 | clean_up(); 12 | } 13 | 14 | void File_helper::clean_up() 15 | { 16 | if (last_read_data!=NULL) 17 | { 18 | delete last_read_data; 19 | } 20 | } 21 | 22 | long File_helper::get_file_size(char *fname) 23 | { 24 | FILE *fp = fopen(fname, "r"); 25 | if(!fp) 26 | { 27 | return -1; 28 | } 29 | 30 | fseek (fp , 0 , SEEK_END); 31 | long size = ftell (fp); 32 | fclose(fp); 33 | return size; 34 | } 35 | 36 | long File_helper::get_file_size(FILE *fp) 37 | { 38 | fseek (fp , 0 , SEEK_END); 39 | long size = ftell (fp); 40 | rewind (fp); 41 | return size; 42 | } 43 | 44 | bool File_helper::read_file(char *fname=NULL) 45 | { 46 | clean_up(); 47 | 48 | FILE *fp = fopen(fname, "r"); 49 | if(fp == NULL) 50 | { 51 | return false; 52 | } 53 | 54 | file_size = get_file_size(fp); 55 | 56 | try 57 | { 58 | if (last_read_data != NULL) 59 | { 60 | delete last_read_data; 61 | } 62 | } 63 | catch (...) 64 | { 65 | printf("NEED FIX: PROBLEM HERE\n"); 66 | last_read_data = NULL; 67 | } 68 | 69 | last_read_data = new char[file_size * sizeof(char)]; 70 | size_t result = fread (last_read_data, 1, file_size, fp); 71 | 72 | if(result != file_size) 73 | { 74 | return false; 75 | } 76 | 77 | fclose(fp); 78 | return true; 79 | } 80 | 81 | char *File_helper::get_last_read_data() 82 | { 83 | if(last_read_data == NULL) 84 | { 85 | return NULL; 86 | } 87 | return last_read_data; 88 | } 89 | 90 | long File_helper::get_last_file_size() 91 | { 92 | return file_size; 93 | } 94 | -------------------------------------------------------------------------------- /src/resources.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: resources.h 5 | * 6 | * Description: All the required images are defined here 7 | * 8 | * Version: 1.0 9 | * Created: 01/16/2009 03:19:24 PM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: Tarin Mahmood (tmn), mrlinux045@gmail.com 14 | * Company: tmnSoft 15 | * 16 | * ===================================================================================== 17 | */ 18 | 19 | #ifndef RESOURCES_H_ 20 | #define RESOURCES_H_ 21 | 22 | #define DISPLAY_INIT_FAILED 100 23 | #define STRING_COPY_EXCEPTION 101 24 | #define MEMORY_ALLOCATION_ERROR 102 25 | #define ALL_GOOD 0 26 | 27 | #define MISSILE_IMAGE 1003 28 | 29 | #define S_EXIT 1000 30 | 31 | typedef void (*Fx)(); 32 | 33 | #define Image SDL_Surface* 34 | 35 | enum Direction 36 | { 37 | Left, Right, Up, Down 38 | }; 39 | 40 | struct Rectangle 41 | { 42 | int x; 43 | int y; 44 | int width; 45 | int height; 46 | }; 47 | 48 | struct Point 49 | { 50 | int x; 51 | int y; 52 | }; 53 | 54 | #include 55 | #include 56 | #include 57 | 58 | #include "sdl/sdl_dm.h" 59 | #include "sdl/event.h" 60 | 61 | #include "objects/vehical.h" 62 | #include "helpers/file_helper.h" 63 | #include "helpers/string_tokenizer.h" 64 | #include "ini_parser/iniparser.h" 65 | #include "ini_parser/dictionary.h" 66 | 67 | #include "mem_manager/llist.h" 68 | #include "mem_manager/image_node.h" 69 | #include "mem_manager/string_node.h" 70 | #include "sdl/timer.h" 71 | #include "mem_manager/pyobjs.h" 72 | 73 | 74 | #endif /* SRC/RESOURCES_H_ */ 75 | 76 | 77 | -------------------------------------------------------------------------------- /src/tester.cc: -------------------------------------------------------------------------------- 1 | int test_SDL() 2 | { 3 | SDL_DM sdm; 4 | sdm.set_screen_size(640, 480); 5 | sdm.init_dm(); 6 | char x; 7 | scanf("%c", &x); 8 | return 0; 9 | } 10 | 11 | void test_tokenizer(char *test, char split_by=' ') 12 | { 13 | String_tokenizer st; 14 | int count = st.split(test, split_by); 15 | printf("%s\n", test); 16 | printf ("%d\n", count); 17 | 18 | for( int i = 0; i < count; i++) 19 | { 20 | char *text = st.get(i); 21 | printf("[%s]\n", text); 22 | delete text; 23 | } 24 | 25 | } 26 | 27 | void test_file_helper() 28 | { 29 | File_helper fh; 30 | fh.read_file((char*)"test_file"); 31 | char *data = fh.get_last_read_data(); 32 | long size = fh.get_last_file_size(); 33 | printf ("%ld\n%s\n", size, data); 34 | test_tokenizer(data, '@'); 35 | delete data; 36 | } 37 | 38 | void test_map() 39 | { 40 | Map map; 41 | map.load_map((char*)"test_file"); 42 | map.display_map_info(); 43 | } 44 | 45 | void test_tokenizer_w_data() 46 | { 47 | test_tokenizer((char*)"This is a test"); 48 | test_tokenizer((char*)"This is a test"); 49 | test_tokenizer((char*)" This is a test"); 50 | } 51 | 52 | void test_string_trimmer() 53 | { 54 | String_helper st; 55 | char test[] = " this is a test string! "; 56 | char *res; 57 | 58 | st.copy_string(res, test); 59 | 60 | st.trim_left(res ,' '); 61 | printf("[%s]\n", test); 62 | printf("[%s]\n", res); 63 | 64 | st.copy_string(res, test); 65 | 66 | st.trim_right(res ,' '); 67 | printf("[%s]\n", test); 68 | printf("[%s]\n", res); 69 | 70 | st.copy_string(res, test); 71 | printf("[%s]\n", test); 72 | st.trim(res, ' '); 73 | printf("[%s]\n", res); 74 | delete res; 75 | 76 | } 77 | 78 | int start_test (int argc, char const* argv[]) 79 | { 80 | //test_tokenizer_w_data(); 81 | //test_file_helper(); 82 | //test_map(); 83 | //test_string_trimmer(); 84 | test_SDL(); 85 | 86 | return 0; 87 | } 88 | 89 | -------------------------------------------------------------------------------- /src/helpers/string_tokenizer.cc: -------------------------------------------------------------------------------- 1 | #include "string_helper.h" 2 | #include "string_tokenizer.h" 3 | #include 4 | 5 | String_tokenizer::String_tokenizer() 6 | { 7 | token_count = 0; 8 | tokenized_str = NULL; 9 | token_positions = NULL; 10 | } 11 | 12 | String_tokenizer::~String_tokenizer() 13 | { 14 | clean_up(); 15 | } 16 | 17 | void String_tokenizer::clean_up() 18 | { 19 | if (tokenized_str != NULL) 20 | { 21 | delete tokenized_str; 22 | } 23 | 24 | if(token_positions != NULL) 25 | { 26 | delete token_positions; 27 | } 28 | } 29 | 30 | int String_tokenizer::split(char *string, char split_by=' ') 31 | { 32 | clean_up(); 33 | 34 | String_helper::copy_string(tokenized_str, string); 35 | 36 | int *tpos = new int[strlen(string)]; 37 | 38 | token_count = 0; 39 | tpos[0] = 0; 40 | 41 | int len = strlen(tokenized_str); 42 | int last_found = -1; 43 | 44 | for(int i = 0; i<=len; i++) 45 | { 46 | if(tokenized_str[i]==split_by || tokenized_str[i]=='\0') 47 | { 48 | tokenized_str[i]='\0'; 49 | if (last_found + 1 == i) 50 | { 51 | tpos[token_count] = i+1; 52 | last_found = i; 53 | continue; 54 | } 55 | 56 | last_found = i; 57 | token_count++; 58 | tpos[token_count] = i+1; 59 | } 60 | } 61 | 62 | token_positions = new int[token_count]; 63 | for (int i=0;itoken_count) 81 | { 82 | return NULL; 83 | } 84 | char *ret_value ; 85 | char *target = &tokenized_str[token_positions[token_no]]; 86 | String_helper::copy_string(ret_value, target); 87 | return ret_value; 88 | } 89 | 90 | char *String_tokenizer::get_token(int token_no) 91 | { 92 | if(token_no > token_count) 93 | { 94 | return NULL; 95 | } 96 | return &tokenized_str[token_positions[token_no]]; 97 | } 98 | 99 | -------------------------------------------------------------------------------- /src/sdl/graphics.cc: -------------------------------------------------------------------------------- 1 | 2 | bool Graphics::draw_image(SDL_Surface *image, int x, int y) 3 | { 4 | SDL_Rect DestR, SrcR; 5 | if (!image) 6 | { 7 | return false; 8 | } 9 | 10 | SrcR.x = 0; 11 | SrcR.y = 0; 12 | SrcR.w = image->w; 13 | SrcR.h = image->h; 14 | 15 | DestR.x = x; 16 | DestR.y = y; 17 | DestR.w = image->w; 18 | DestR.h = image->h; 19 | 20 | SDL_BlitSurface(image, &SrcR, Display, &DestR); 21 | return true; 22 | 23 | } 24 | 25 | bool Graphics::copy_img_to( SDL_Surface *image, SDL_Rect src, Point destp) 26 | { 27 | if (!image) 28 | { 29 | return false; 30 | } 31 | 32 | SDL_Rect dest; 33 | dest.x = destp.x; 34 | dest.y = destp.y; 35 | dest.w = image->w; 36 | dest.h = image->h; 37 | 38 | SDL_BlitSurface(image, &src, Display, &dest); 39 | return true; 40 | } 41 | 42 | 43 | void Graphics::fill_surface (Uint32 colorkey) 44 | { 45 | SDL_FillRect(Display, NULL, colorkey); 46 | } 47 | 48 | void Graphics::fill_rect (Uint32 colorkey, SDL_Rect *rect) 49 | { 50 | SDL_FillRect(Display, rect, colorkey); 51 | } 52 | 53 | void Graphics::fill_rect (Uint32 colorkey, Rectangle *rect) 54 | { 55 | SDL_Rect sr; 56 | sr.x = rect->x; 57 | sr.y = rect->y; 58 | sr.w = rect->width; 59 | sr.h = rect->height; 60 | 61 | SDL_FillRect(Display, &sr, colorkey); 62 | } 63 | 64 | Uint32 Graphics::get_colorkey(int r, int g, int b) 65 | { 66 | return SDL_MapRGB(get_display_format(), r, g , b); 67 | } 68 | 69 | void Graphics::put_pixel(int x, int y, Uint32 pixel) 70 | { 71 | int bpp = Display->format->BytesPerPixel; 72 | Uint8 *p = (Uint8 *)Display->pixels + y * Display->pitch + x * bpp; 73 | 74 | switch(bpp) 75 | { 76 | case 1: 77 | *p = pixel; 78 | break; 79 | 80 | case 2: 81 | *(Uint16 *)p = pixel; 82 | break; 83 | 84 | case 3: 85 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) 86 | { 87 | p[0] = (pixel >> 16) & 0xff; 88 | p[1] = (pixel >> 8) & 0xff; 89 | p[2] = pixel & 0xff; 90 | } 91 | else 92 | { 93 | p[0] = pixel & 0xff; 94 | p[1] = (pixel >> 8) & 0xff; 95 | p[2] = (pixel >> 16) & 0xff; 96 | } 97 | break; 98 | 99 | case 4: 100 | *(Uint32 *)p = pixel; 101 | break; 102 | } 103 | } 104 | 105 | 106 | -------------------------------------------------------------------------------- /src/objects/object.cc: -------------------------------------------------------------------------------- 1 | #include "../resources.h" 2 | #include "object.h" 3 | #include 4 | 5 | void Object::move(Direction dir, int amount) 6 | { 7 | if(amount !=0) 8 | { 9 | int old_speed = speed; 10 | speed = amount; 11 | move_int(dir); 12 | speed = old_speed; 13 | return; 14 | } 15 | 16 | move_int(dir); 17 | } 18 | 19 | void Object::set_position(int x, int y) 20 | { 21 | pos_x = x; 22 | pos_y = y; 23 | } 24 | 25 | void Object::set_speed(int spd) 26 | { 27 | speed = spd; 28 | } 29 | 30 | int Object::get_current_speed() 31 | { 32 | return speed; 33 | } 34 | 35 | Rectangle Object::get_rectangle() 36 | { 37 | Rectangle t; 38 | t.x = pos_x; 39 | t.y = pos_y; 40 | t.width= width; 41 | t.height= height; 42 | return t; 43 | } 44 | 45 | void Object::move_int(Direction dir) 46 | { 47 | switch(dir) 48 | { 49 | case Left: 50 | printf("Left %d\n", speed); 51 | pos_x-=speed; 52 | break; 53 | 54 | case Right: 55 | printf("Right %d\n", speed); 56 | pos_x+=speed; 57 | break; 58 | 59 | case Up: 60 | printf("Top %d\n", speed); 61 | pos_y-=speed; 62 | break; 63 | 64 | case Down: 65 | printf("Down %d\n", speed); 66 | pos_y+=speed; 67 | break; 68 | } 69 | } 70 | 71 | void Object::set_life(int val) 72 | { 73 | life = val; 74 | } 75 | 76 | void Object::set_size(int w,int h) 77 | { 78 | width = w; 79 | height = h; 80 | } 81 | 82 | void Object::set_damage(int val) 83 | { 84 | damage = val; 85 | } 86 | 87 | void Object::set_level(int val) 88 | { 89 | level = val; 90 | } 91 | 92 | void Object::set_obj_id(int id) 93 | { 94 | obj_id = id; 95 | } 96 | 97 | void Object::set_direction(Direction dir) 98 | { 99 | speed = 0; 100 | current_dir = dir; 101 | } 102 | 103 | Direction Object::get_direction() 104 | { 105 | return current_dir; 106 | } 107 | 108 | int Object::get_life() 109 | { 110 | return life; 111 | } 112 | 113 | int Object::get_width() 114 | { 115 | return width; 116 | } 117 | 118 | int Object::get_height() 119 | { 120 | return height; 121 | } 122 | 123 | int Object::get_damage() 124 | { 125 | return damage; 126 | } 127 | 128 | int Object::get_level() 129 | { 130 | return level; 131 | } 132 | 133 | int Object::get_obj_id() 134 | { 135 | return obj_id; 136 | } 137 | 138 | int Object::get_pos_x() 139 | { 140 | return pos_x; 141 | } 142 | 143 | int Object::get_pos_y() 144 | { 145 | return pos_y; 146 | } 147 | 148 | -------------------------------------------------------------------------------- /src/main.cc: -------------------------------------------------------------------------------- 1 | #include "resources.h" 2 | 3 | SDL_DM sdm; 4 | 5 | int app_status; 6 | int system_status = ALL_GOOD; 7 | dictionary *game_ini; 8 | 9 | int actor_count; 10 | int name_index; 11 | 12 | void init_game(); 13 | void init_system(char*); 14 | void game_loop(); 15 | bool start_sdl(); 16 | void cleanup(); 17 | void sdl_event(); 18 | 19 | void clear_objects(); 20 | void on_escape(); 21 | void on_up(); 22 | void on_down(); 23 | void on_right(); 24 | void on_left(); 25 | 26 | LinkedListimage_list; 27 | LinkedListstring_list; 28 | LinkedListpyobj_list; 29 | 30 | Event events; 31 | Object vc; 32 | Timer main_timer; 33 | 34 | int main (int argc, char *argv[]) 35 | { 36 | if(argc < 2) 37 | { 38 | printf("Argument missing\n"); 39 | exit(1); 40 | } 41 | 42 | init_system(argv[1]); 43 | game_loop(); 44 | 45 | return EXIT_SUCCESS; 46 | } 47 | 48 | void init_system(char *game_name) 49 | { 50 | if(!start_sdl()) 51 | { 52 | exit(DISPLAY_INIT_FAILED); 53 | } 54 | atexit(cleanup); 55 | clear_objects(); 56 | 57 | String_helper::trim_right(game_name, '/'); 58 | 59 | string_list.add(game_name); 60 | init_game(); 61 | printf("Starting game loop\n"); 62 | } 63 | 64 | void init_game() 65 | { 66 | events.add_listener(SDLK_ESCAPE, on_escape); 67 | events.add_listener(SDL_QUIT, on_escape); 68 | events.add_listener(SDLK_UP, on_up); 69 | events.add_listener(SDLK_DOWN, on_down); 70 | events.add_listener(SDLK_LEFT, on_left); 71 | events.add_listener(SDLK_RIGHT, on_right); 72 | 73 | vc.set_size(64,64); 74 | vc.set_position(10,10); 75 | vc.set_speed(10); 76 | vc.set_obj_id(MISSILE_IMAGE); 77 | } 78 | 79 | void clear_objects() 80 | { 81 | Uint32 colorkey = SDL_MapRGB(sdm.get_display_format(), 0, 0, 0); 82 | 83 | Rectangle tr = vc.get_rectangle(); 84 | sdm.fill_rect(colorkey, &tr); 85 | } 86 | 87 | bool start_sdl() 88 | { 89 | sdm.set_screen_size(800, 800); 90 | return sdm.init_dm(); 91 | } 92 | 93 | void game_loop() 94 | { 95 | Uint32 colorkey = sdm.get_colorkey(233, 233, 233); 96 | try 97 | { 98 | while(app_status!=S_EXIT) 99 | { 100 | clear_objects(); 101 | events.get_key_pressed(); 102 | Rectangle tr = vc.get_rectangle(); 103 | sdm.fill_rect(colorkey, &tr); 104 | sdm.redraw(); 105 | } 106 | } 107 | catch(int x) 108 | { 109 | printf("Exception cought %d\n", x); 110 | } 111 | } 112 | 113 | 114 | void cleanup() 115 | { 116 | sdm.close_display_manager(); 117 | } 118 | 119 | void on_escape() 120 | { 121 | printf("Good bye!\n"); 122 | app_status = S_EXIT; 123 | } 124 | 125 | void on_up() 126 | { 127 | if(main_timer.is_started()) 128 | { 129 | main_timer.stop(); 130 | vc.set_direction(Up); 131 | return; 132 | } 133 | main_timer.start(); 134 | } 135 | 136 | void on_down() 137 | { 138 | if(main_timer.is_started()) 139 | { 140 | main_timer.stop(); 141 | vc.set_direction(Down); 142 | return; 143 | } 144 | main_timer.start(); 145 | 146 | } 147 | 148 | void on_right() 149 | { 150 | if(main_timer.is_started()) 151 | { 152 | main_timer.stop(); 153 | vc.set_direction(Right); 154 | return; 155 | } 156 | main_timer.start(); 157 | } 158 | 159 | void on_left() 160 | { 161 | if(main_timer.is_started()) 162 | { 163 | main_timer.stop(); 164 | vc.set_direction(Left); 165 | return; 166 | } 167 | main_timer.start(); 168 | } 169 | -------------------------------------------------------------------------------- /src/sdl/sdl_dm.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../point.h" 3 | #include"sdl_dm.h" 4 | 5 | SDL_DM::SDL_DM () 6 | { 7 | // default configuration 8 | scr_width = 300; 9 | scr_height = 300; 10 | wbit = 24; 11 | wflag = SDL_HWSURFACE|SDL_DOUBLEBUF; 12 | initialized = false; 13 | } 14 | 15 | SDL_DM::~SDL_DM() 16 | { 17 | close_display_manager(); 18 | } 19 | 20 | void SDL_DM::close_display_manager() 21 | { 22 | if(initialized) 23 | { 24 | if(Display!=NULL) 25 | { 26 | SDL_FreeSurface(Display); 27 | } 28 | SDL_Quit(); 29 | initialized = false; 30 | } 31 | } 32 | 33 | bool SDL_DM::is_initialized() 34 | { 35 | return initialized; 36 | } 37 | 38 | void SDL_DM::set_screen_size(int sw, int sh) 39 | { 40 | scr_width = sw; 41 | scr_height = sh; 42 | } 43 | 44 | void SDL_DM::set_display_flags(int flag) 45 | { 46 | wflag = flag; 47 | } 48 | 49 | void SDL_DM::set_display_color_bit(int bit) 50 | { 51 | wbit = bit; 52 | } 53 | 54 | bool SDL_DM::init_dm () 55 | { 56 | int sdl_status = SDL_Init(SDL_INIT_VIDEO); 57 | 58 | if(sdl_status<0) 59 | { 60 | return false; 61 | } 62 | 63 | Display = SDL_SetVideoMode(scr_width, scr_height, wbit, wflag); 64 | 65 | if (!Display) 66 | { 67 | return false; 68 | } 69 | 70 | initialized = true; 71 | 72 | SDL_WM_SetCaption("A SDL Window","Icon"); 73 | return true; 74 | } 75 | 76 | SDL_PixelFormat* SDL_DM::get_display_format () 77 | { 78 | return Display->format; 79 | } 80 | 81 | long SDL_DM::get_ticks () 82 | { 83 | return SDL_GetTicks(); 84 | } 85 | 86 | Uint8 SDL_DM::get_pixel (int x, int y) 87 | { 88 | int bpp = Display->format->BytesPerPixel; 89 | 90 | Uint8 *p = (Uint8 *)Display->pixels 91 | + y * Display->pitch 92 | + x * bpp; 93 | 94 | switch(bpp) 95 | { 96 | case 1: 97 | return *p; 98 | 99 | case 2: 100 | return *(Uint16 *)p; 101 | 102 | case 3: 103 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) 104 | { 105 | return p[0]<<16|p[1]<<8|p[2]; 106 | } 107 | else 108 | { 109 | return p[0]|p[1]<<8|p[2]<<16; 110 | } 111 | 112 | case 4: 113 | return *(Uint32 *)p; 114 | 115 | default: 116 | return 0; 117 | } 118 | } 119 | 120 | 121 | void SDL_DM::put_pixel(int x, int y, Uint32 pixel) 122 | { 123 | int bpp = Display->format->BytesPerPixel; 124 | Uint8 *p = (Uint8 *)Display->pixels + y * Display->pitch + x * bpp; 125 | 126 | switch(bpp) 127 | { 128 | case 1: 129 | *p = pixel; 130 | break; 131 | 132 | case 2: 133 | *(Uint16 *)p = pixel; 134 | break; 135 | 136 | case 3: 137 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) 138 | { 139 | p[0] = (pixel >> 16) & 0xff; 140 | p[1] = (pixel >> 8) & 0xff; 141 | p[2] = pixel & 0xff; 142 | } 143 | else 144 | { 145 | p[0] = pixel & 0xff; 146 | p[1] = (pixel >> 8) & 0xff; 147 | p[2] = (pixel >> 16) & 0xff; 148 | } 149 | break; 150 | 151 | case 4: 152 | *(Uint32 *)p = pixel; 153 | break; 154 | } 155 | } 156 | 157 | bool SDL_DM::draw_image(SDL_Surface *image, int x, int y) 158 | { 159 | SDL_Rect DestR, SrcR; 160 | if (!image) 161 | { 162 | return false; 163 | } 164 | 165 | SrcR.x = 0; 166 | SrcR.y = 0; 167 | SrcR.w = image->w; 168 | SrcR.h = image->h; 169 | 170 | DestR.x = x; 171 | DestR.y = y; 172 | DestR.w = image->w; 173 | DestR.h = image->h; 174 | 175 | SDL_BlitSurface(image, &SrcR, Display, &DestR); 176 | return true; 177 | 178 | } 179 | 180 | bool SDL_DM::copy_img_to( SDL_Surface *image, SDL_Rect src, Point destp) 181 | { 182 | if (!image) 183 | { 184 | return false; 185 | } 186 | 187 | SDL_Rect dest; 188 | dest.x = destp.x; 189 | dest.y = destp.y; 190 | dest.w = image->w; 191 | dest.h = image->h; 192 | 193 | SDL_BlitSurface(image, &src, Display, &dest); 194 | return true; 195 | } 196 | 197 | void SDL_DM::redraw () 198 | { 199 | SDL_Flip(Display); 200 | } 201 | 202 | void SDL_DM::fill_surface (Uint32 colorkey) 203 | { 204 | SDL_FillRect(Display, NULL, colorkey); 205 | } 206 | 207 | void SDL_DM::fill_rect (Uint32 colorkey, SDL_Rect *rect) 208 | { 209 | SDL_FillRect(Display, rect, colorkey); 210 | } 211 | 212 | void SDL_DM::fill_rect (Uint32 colorkey, Rectangle *rect) 213 | { 214 | SDL_Rect sr; 215 | sr.x = rect->x; 216 | sr.y = rect->y; 217 | sr.w = rect->width; 218 | sr.h = rect->height; 219 | 220 | SDL_FillRect(Display, &sr, colorkey); 221 | } 222 | 223 | Uint32 SDL_DM::get_colorkey(int r, int g, int b) 224 | { 225 | return SDL_MapRGB(get_display_format(), r, g , b); 226 | } 227 | -------------------------------------------------------------------------------- /src/mem_manager/llist.h: -------------------------------------------------------------------------------- 1 | #ifndef LLIST_H_ 2 | 3 | #define LLIST_H_ 4 | 5 | #include 6 | #include 7 | 8 | #define NOT_INITIALIZED 10001 9 | #define ILLIGAL_OFFSET 10002 10 | 11 | // exception class for linked list 12 | 13 | class Linked_list_exception 14 | { 15 | public: 16 | virtual const char* message(int code) const throw() 17 | { 18 | switch(code) 19 | { 20 | case NOT_INITIALIZED: 21 | return "List not initialized yet"; 22 | 23 | case ILLIGAL_OFFSET: 24 | return "Invalid index given"; 25 | 26 | default: 27 | return "Unknown error"; 28 | } 29 | } 30 | }; 31 | 32 | template 33 | class LinkedList 34 | { 35 | private: 36 | 37 | Node *current; 38 | Node *head; 39 | Node *last; 40 | int index; 41 | int count; 42 | Linked_list_exception err_handler; 43 | 44 | public: 45 | LinkedList ( ) 46 | { 47 | index = 0; 48 | head = NULL; 49 | current = NULL; 50 | last = NULL; 51 | } 52 | 53 | virtual ~LinkedList() 54 | { 55 | clear(); 56 | } 57 | 58 | void clear() 59 | { 60 | current = head; 61 | Node *n; 62 | while(1) 63 | { 64 | if(current == NULL) 65 | { 66 | break; 67 | } 68 | n = current; 69 | current = n->next; 70 | delete n; 71 | } 72 | } 73 | 74 | void remove(int index) 75 | { 76 | if(get(index) == NULL) 77 | { 78 | return; 79 | } 80 | 81 | Node *n; 82 | if(current == head) 83 | { 84 | n = head; 85 | head = current->next; 86 | head->prev = NULL; 87 | } 88 | else if(current == last) 89 | { 90 | n = last; 91 | last = current->prev; 92 | last->next = NULL; 93 | 94 | } 95 | else 96 | { 97 | n = current; 98 | current->prev->next = current->next; 99 | current->next->prev = current->prev; 100 | } 101 | 102 | delete n; 103 | count--; 104 | } 105 | 106 | int add(T data, int index=-1) 107 | { 108 | 109 | Node *new_node = init_new_node(); 110 | new_node->set_data(data); 111 | add_new_node( new_node ); 112 | 113 | if(index>=0) 114 | { 115 | new_node->index = index; 116 | } 117 | 118 | return new_node->index; 119 | } 120 | 121 | int move(T data, int index=-1) 122 | { 123 | int indx = add(data, index); 124 | delete data; 125 | return indx; 126 | } 127 | 128 | 129 | void add_empty(int index) 130 | { 131 | T tmp = (T)NULL; 132 | add(tmp, index); 133 | } 134 | 135 | bool update(int index, T data) 136 | { 137 | if(get(index)==NULL) 138 | { 139 | return false; 140 | } 141 | 142 | current->set_data(data); 143 | return true; 144 | } 145 | 146 | private: 147 | void add_new_node(Node *new_node) 148 | { 149 | if(head == NULL) 150 | { 151 | head = new_node; 152 | current = new_node; 153 | last = new_node; 154 | } 155 | else 156 | { 157 | last->next = new_node; 158 | new_node->prev = last; 159 | last = new_node; 160 | } 161 | 162 | if(index >= 0) 163 | { 164 | new_node->index = index; 165 | } 166 | count++; 167 | } 168 | 169 | Node *init_new_node() 170 | { 171 | Node *new_node = new Node; 172 | new_node->next = NULL; 173 | new_node->prev = NULL; 174 | new_node->index = index++; 175 | count++; 176 | return new_node; 177 | } 178 | 179 | public: 180 | bool find(T data) 181 | { 182 | for( reset(); is_valid(); next()) 183 | { 184 | if (current->equals(data)) 185 | { 186 | return true; 187 | } 188 | } 189 | return false; 190 | } 191 | 192 | T get(int index) 193 | { 194 | reset(); 195 | while(is_valid()) 196 | { 197 | if(current->index == index) 198 | { 199 | return current->get_data(); 200 | } 201 | next(); 202 | } 203 | return NULL; 204 | } 205 | 206 | bool is_valid() 207 | { 208 | if(current == NULL) 209 | { 210 | reset(); 211 | return false; 212 | } 213 | return true; 214 | } 215 | 216 | bool next() 217 | { 218 | if (current==NULL) 219 | { 220 | return false; 221 | } 222 | current = current->next; 223 | return true; 224 | } 225 | 226 | bool previous() 227 | { 228 | if (current==NULL) 229 | { 230 | return false; 231 | } 232 | current = current->prev; 233 | return true; 234 | } 235 | 236 | void rewind() 237 | { 238 | current = head; 239 | } 240 | 241 | void reset() 242 | { 243 | current = head; 244 | } 245 | 246 | void forward() 247 | { 248 | current = last; 249 | } 250 | 251 | bool current_equals(T d) 252 | { 253 | if(current->equals(d)) 254 | { 255 | return true; 256 | } 257 | return false; 258 | } 259 | 260 | T get_current() 261 | { 262 | if(current == NULL) 263 | { 264 | reset(); 265 | throw NOT_INITIALIZED; 266 | } 267 | return current->get_data(); 268 | } 269 | 270 | int get_current_index() 271 | { 272 | if(current == NULL) 273 | { 274 | throw ILLIGAL_OFFSET; 275 | } 276 | return current->index; 277 | } 278 | 279 | int get_count() 280 | { 281 | return count; 282 | } 283 | 284 | }; 285 | 286 | 287 | #endif /* SRC/MEM_MANAGER/LLIST_H_ */ 288 | -------------------------------------------------------------------------------- /src/ini_parser/dictionary.h: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------------------*/ 3 | /** 4 | @file dictionary.h 5 | @author N. Devillard 6 | @date Sep 2007 7 | @version $Revision: 1.12 $ 8 | @brief Implements a dictionary for string variables. 9 | 10 | This module implements a simple dictionary object, i.e. a list 11 | of string/string associations. This object is useful to store e.g. 12 | informations retrieved from a configuration file (ini files). 13 | */ 14 | /*--------------------------------------------------------------------------*/ 15 | 16 | /* 17 | $Id: dictionary.h,v 1.12 2007-11-23 21:37:00 ndevilla Exp $ 18 | $Author: ndevilla $ 19 | $Date: 2007-11-23 21:37:00 $ 20 | $Revision: 1.12 $ 21 | */ 22 | 23 | #ifndef _DICTIONARY_H_ 24 | #define _DICTIONARY_H_ 25 | 26 | /*--------------------------------------------------------------------------- 27 | Includes 28 | ---------------------------------------------------------------------------*/ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | /*--------------------------------------------------------------------------- 36 | New types 37 | ---------------------------------------------------------------------------*/ 38 | 39 | 40 | /*-------------------------------------------------------------------------*/ 41 | /** 42 | @brief Dictionary object 43 | 44 | This object contains a list of string/string associations. Each 45 | association is identified by a unique string key. Looking up values 46 | in the dictionary is speeded up by the use of a (hopefully collision-free) 47 | hash function. 48 | */ 49 | /*-------------------------------------------------------------------------*/ 50 | typedef struct _dictionary_ { 51 | int n ; /** Number of entries in dictionary */ 52 | int size ; /** Storage size */ 53 | char ** val ; /** List of string values */ 54 | char ** key ; /** List of string keys */ 55 | unsigned * hash ; /** List of hash values for keys */ 56 | } dictionary ; 57 | 58 | 59 | /*--------------------------------------------------------------------------- 60 | Function prototypes 61 | ---------------------------------------------------------------------------*/ 62 | 63 | /*-------------------------------------------------------------------------*/ 64 | /** 65 | @brief Compute the hash key for a string. 66 | @param key Character string to use for key. 67 | @return 1 unsigned int on at least 32 bits. 68 | 69 | This hash function has been taken from an Article in Dr Dobbs Journal. 70 | This is normally a collision-free function, distributing keys evenly. 71 | The key is stored anyway in the struct so that collision can be avoided 72 | by comparing the key itself in last resort. 73 | */ 74 | /*--------------------------------------------------------------------------*/ 75 | unsigned dictionary_hash(char * key); 76 | 77 | /*-------------------------------------------------------------------------*/ 78 | /** 79 | @brief Create a new dictionary object. 80 | @param size Optional initial size of the dictionary. 81 | @return 1 newly allocated dictionary objet. 82 | 83 | This function allocates a new dictionary object of given size and returns 84 | it. If you do not know in advance (roughly) the number of entries in the 85 | dictionary, give size=0. 86 | */ 87 | /*--------------------------------------------------------------------------*/ 88 | dictionary * dictionary_new(int size); 89 | 90 | /*-------------------------------------------------------------------------*/ 91 | /** 92 | @brief Delete a dictionary object 93 | @param d dictionary object to deallocate. 94 | @return void 95 | 96 | Deallocate a dictionary object and all memory associated to it. 97 | */ 98 | /*--------------------------------------------------------------------------*/ 99 | void dictionary_del(dictionary * vd); 100 | 101 | /*-------------------------------------------------------------------------*/ 102 | /** 103 | @brief Get a value from a dictionary. 104 | @param d dictionary object to search. 105 | @param key Key to look for in the dictionary. 106 | @param def Default value to return if key not found. 107 | @return 1 pointer to internally allocated character string. 108 | 109 | This function locates a key in a dictionary and returns a pointer to its 110 | value, or the passed 'def' pointer if no such key can be found in 111 | dictionary. The returned character pointer points to data internal to the 112 | dictionary object, you should not try to free it or modify it. 113 | */ 114 | /*--------------------------------------------------------------------------*/ 115 | char * dictionary_get(dictionary * d, char * key, char * def); 116 | 117 | 118 | /*-------------------------------------------------------------------------*/ 119 | /** 120 | @brief Set a value in a dictionary. 121 | @param d dictionary object to modify. 122 | @param key Key to modify or add. 123 | @param val Value to add. 124 | @return int 0 if Ok, anything else otherwise 125 | 126 | If the given key is found in the dictionary, the associated value is 127 | replaced by the provided one. If the key cannot be found in the 128 | dictionary, it is added to it. 129 | 130 | It is Ok to provide a NULL value for val, but NULL values for the dictionary 131 | or the key are considered as errors: the function will return immediately 132 | in such a case. 133 | 134 | Notice that if you dictionary_set a variable to NULL, a call to 135 | dictionary_get will return a NULL value: the variable will be found, and 136 | its value (NULL) is returned. In other words, setting the variable 137 | content to NULL is equivalent to deleting the variable from the 138 | dictionary. It is not possible (in this implementation) to have a key in 139 | the dictionary without value. 140 | 141 | This function returns non-zero in case of failure. 142 | */ 143 | /*--------------------------------------------------------------------------*/ 144 | int dictionary_set(dictionary * vd, char * key, char * val); 145 | 146 | /*-------------------------------------------------------------------------*/ 147 | /** 148 | @brief Delete a key in a dictionary 149 | @param d dictionary object to modify. 150 | @param key Key to remove. 151 | @return void 152 | 153 | This function deletes a key in a dictionary. Nothing is done if the 154 | key cannot be found. 155 | */ 156 | /*--------------------------------------------------------------------------*/ 157 | void dictionary_unset(dictionary * d, char * key); 158 | 159 | 160 | /*-------------------------------------------------------------------------*/ 161 | /** 162 | @brief Dump a dictionary to an opened file pointer. 163 | @param d Dictionary to dump 164 | @param f Opened file pointer. 165 | @return void 166 | 167 | Dumps a dictionary onto an opened file pointer. Key pairs are printed out 168 | as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as 169 | output file pointers. 170 | */ 171 | /*--------------------------------------------------------------------------*/ 172 | void dictionary_dump(dictionary * d, FILE * out); 173 | 174 | #endif 175 | -------------------------------------------------------------------------------- /src/ini_parser/iniparser.h: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------------------*/ 3 | /** 4 | @file iniparser.h 5 | @author N. Devillard 6 | @date Sep 2007 7 | @version 3.0 8 | @brief Parser for ini files. 9 | */ 10 | /*--------------------------------------------------------------------------*/ 11 | 12 | /* 13 | $Id: iniparser.h,v 1.24 2007-11-23 21:38:19 ndevilla Exp $ 14 | $Revision: 1.24 $ 15 | */ 16 | 17 | #ifndef _INIPARSER_H_ 18 | #define _INIPARSER_H_ 19 | 20 | /*--------------------------------------------------------------------------- 21 | Includes 22 | ---------------------------------------------------------------------------*/ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | /* 29 | * The following #include is necessary on many Unixes but not Linux. 30 | * It is not needed for Windows platforms. 31 | * Uncomment it if needed. 32 | */ 33 | /* #include */ 34 | 35 | #include "dictionary.h" 36 | 37 | /*--------------------------------------------------------------------------- 38 | Macros 39 | ---------------------------------------------------------------------------*/ 40 | /** For backwards compatibility only */ 41 | #define iniparser_getstr(d, k) iniparser_getstring(d, k, NULL) 42 | #define iniparser_setstr iniparser_setstring 43 | 44 | /*-------------------------------------------------------------------------*/ 45 | /** 46 | @brief Get number of sections in a dictionary 47 | @param d Dictionary to examine 48 | @return int Number of sections found in dictionary 49 | 50 | This function returns the number of sections found in a dictionary. 51 | The test to recognize sections is done on the string stored in the 52 | dictionary: a section name is given as "section" whereas a key is 53 | stored as "section:key", thus the test looks for entries that do not 54 | contain a colon. 55 | 56 | This clearly fails in the case a section name contains a colon, but 57 | this should simply be avoided. 58 | 59 | This function returns -1 in case of error. 60 | */ 61 | /*--------------------------------------------------------------------------*/ 62 | 63 | int iniparser_getnsec(dictionary * d); 64 | 65 | 66 | /*-------------------------------------------------------------------------*/ 67 | /** 68 | @brief Get name for section n in a dictionary. 69 | @param d Dictionary to examine 70 | @param n Section number (from 0 to nsec-1). 71 | @return Pointer to char string 72 | 73 | This function locates the n-th section in a dictionary and returns 74 | its name as a pointer to a string statically allocated inside the 75 | dictionary. Do not free or modify the returned string! 76 | 77 | This function returns NULL in case of error. 78 | */ 79 | /*--------------------------------------------------------------------------*/ 80 | 81 | char * iniparser_getsecname(dictionary * d, int n); 82 | 83 | 84 | /*-------------------------------------------------------------------------*/ 85 | /** 86 | @brief Save a dictionary to a loadable ini file 87 | @param d Dictionary to dump 88 | @param f Opened file pointer to dump to 89 | @return void 90 | 91 | This function dumps a given dictionary into a loadable ini file. 92 | It is Ok to specify @c stderr or @c stdout as output files. 93 | */ 94 | /*--------------------------------------------------------------------------*/ 95 | 96 | void iniparser_dump_ini(dictionary * d, FILE * f); 97 | 98 | /*-------------------------------------------------------------------------*/ 99 | /** 100 | @brief Dump a dictionary to an opened file pointer. 101 | @param d Dictionary to dump. 102 | @param f Opened file pointer to dump to. 103 | @return void 104 | 105 | This function prints out the contents of a dictionary, one element by 106 | line, onto the provided file pointer. It is OK to specify @c stderr 107 | or @c stdout as output files. This function is meant for debugging 108 | purposes mostly. 109 | */ 110 | /*--------------------------------------------------------------------------*/ 111 | void iniparser_dump(dictionary * d, FILE * f); 112 | 113 | /*-------------------------------------------------------------------------*/ 114 | /** 115 | @brief Get the string associated to a key 116 | @param d Dictionary to search 117 | @param key Key string to look for 118 | @param def Default value to return if key not found. 119 | @return pointer to statically allocated character string 120 | 121 | This function queries a dictionary for a key. A key as read from an 122 | ini file is given as "section:key". If the key cannot be found, 123 | the pointer passed as 'def' is returned. 124 | The returned char pointer is pointing to a string allocated in 125 | the dictionary, do not free or modify it. 126 | */ 127 | /*--------------------------------------------------------------------------*/ 128 | char * iniparser_getstring(dictionary * d, const char * key, char * def); 129 | 130 | /*-------------------------------------------------------------------------*/ 131 | /** 132 | @brief Get the string associated to a key, convert to an int 133 | @param d Dictionary to search 134 | @param key Key string to look for 135 | @param notfound Value to return in case of error 136 | @return integer 137 | 138 | This function queries a dictionary for a key. A key as read from an 139 | ini file is given as "section:key". If the key cannot be found, 140 | the notfound value is returned. 141 | 142 | Supported values for integers include the usual C notation 143 | so decimal, octal (starting with 0) and hexadecimal (starting with 0x) 144 | are supported. Examples: 145 | 146 | - "42" -> 42 147 | - "042" -> 34 (octal -> decimal) 148 | - "0x42" -> 66 (hexa -> decimal) 149 | 150 | Warning: the conversion may overflow in various ways. Conversion is 151 | totally outsourced to strtol(), see the associated man page for overflow 152 | handling. 153 | 154 | Credits: Thanks to A. Becker for suggesting strtol() 155 | */ 156 | /*--------------------------------------------------------------------------*/ 157 | int iniparser_getint(dictionary * d, const char * key, int notfound); 158 | 159 | /*-------------------------------------------------------------------------*/ 160 | /** 161 | @brief Get the string associated to a key, convert to a double 162 | @param d Dictionary to search 163 | @param key Key string to look for 164 | @param notfound Value to return in case of error 165 | @return double 166 | 167 | This function queries a dictionary for a key. A key as read from an 168 | ini file is given as "section:key". If the key cannot be found, 169 | the notfound value is returned. 170 | */ 171 | /*--------------------------------------------------------------------------*/ 172 | double iniparser_getdouble(dictionary * d, char * key, double notfound); 173 | 174 | /*-------------------------------------------------------------------------*/ 175 | /** 176 | @brief Get the string associated to a key, convert to a boolean 177 | @param d Dictionary to search 178 | @param key Key string to look for 179 | @param notfound Value to return in case of error 180 | @return integer 181 | 182 | This function queries a dictionary for a key. A key as read from an 183 | ini file is given as "section:key". If the key cannot be found, 184 | the notfound value is returned. 185 | 186 | A true boolean is found if one of the following is matched: 187 | 188 | - A string starting with 'y' 189 | - A string starting with 'Y' 190 | - A string starting with 't' 191 | - A string starting with 'T' 192 | - A string starting with '1' 193 | 194 | A false boolean is found if one of the following is matched: 195 | 196 | - A string starting with 'n' 197 | - A string starting with 'N' 198 | - A string starting with 'f' 199 | - A string starting with 'F' 200 | - A string starting with '0' 201 | 202 | The notfound value returned if no boolean is identified, does not 203 | necessarily have to be 0 or 1. 204 | */ 205 | /*--------------------------------------------------------------------------*/ 206 | int iniparser_getboolean(dictionary * d, const char * key, int notfound); 207 | 208 | 209 | /*-------------------------------------------------------------------------*/ 210 | /** 211 | @brief Set an entry in a dictionary. 212 | @param ini Dictionary to modify. 213 | @param entry Entry to modify (entry name) 214 | @param val New value to associate to the entry. 215 | @return int 0 if Ok, -1 otherwise. 216 | 217 | If the given entry can be found in the dictionary, it is modified to 218 | contain the provided value. If it cannot be found, -1 is returned. 219 | It is Ok to set val to NULL. 220 | */ 221 | /*--------------------------------------------------------------------------*/ 222 | int iniparser_setstring(dictionary * ini, char * entry, char * val); 223 | 224 | 225 | /*-------------------------------------------------------------------------*/ 226 | /** 227 | @brief Delete an entry in a dictionary 228 | @param ini Dictionary to modify 229 | @param entry Entry to delete (entry name) 230 | @return void 231 | 232 | If the given entry can be found, it is deleted from the dictionary. 233 | */ 234 | /*--------------------------------------------------------------------------*/ 235 | void iniparser_unset(dictionary * ini, char * entry); 236 | 237 | /*-------------------------------------------------------------------------*/ 238 | /** 239 | @brief Finds out if a given entry exists in a dictionary 240 | @param ini Dictionary to search 241 | @param entry Name of the entry to look for 242 | @return integer 1 if entry exists, 0 otherwise 243 | 244 | Finds out if a given entry exists in the dictionary. Since sections 245 | are stored as keys with NULL associated values, this is the only way 246 | of querying for the presence of sections in a dictionary. 247 | */ 248 | /*--------------------------------------------------------------------------*/ 249 | int iniparser_find_entry(dictionary * ini, char * entry) ; 250 | 251 | /*-------------------------------------------------------------------------*/ 252 | /** 253 | @brief Parse an ini file and return an allocated dictionary object 254 | @param ininame Name of the ini file to read. 255 | @return Pointer to newly allocated dictionary 256 | 257 | This is the parser for ini files. This function is called, providing 258 | the name of the file to be read. It returns a dictionary object that 259 | should not be accessed directly, but through accessor functions 260 | instead. 261 | 262 | The returned dictionary must be freed using iniparser_freedict(). 263 | */ 264 | /*--------------------------------------------------------------------------*/ 265 | dictionary * iniparser_load(const char * ininame); 266 | 267 | /*-------------------------------------------------------------------------*/ 268 | /** 269 | @brief Free all memory associated to an ini dictionary 270 | @param d Dictionary to free 271 | @return void 272 | 273 | Free all memory associated to an ini dictionary. 274 | It is mandatory to call this function before the dictionary object 275 | gets out of the current context. 276 | */ 277 | /*--------------------------------------------------------------------------*/ 278 | void iniparser_freedict(dictionary * d); 279 | 280 | #endif 281 | -------------------------------------------------------------------------------- /src/ini_parser/dictionary.c: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------*/ 2 | /** 3 | @file dictionary.c 4 | @author N. Devillard 5 | @date Sep 2007 6 | @version $Revision: 1.27 $ 7 | @brief Implements a dictionary for string variables. 8 | 9 | This module implements a simple dictionary object, i.e. a list 10 | of string/string associations. This object is useful to store e.g. 11 | informations retrieved from a configuration file (ini files). 12 | */ 13 | /*--------------------------------------------------------------------------*/ 14 | 15 | /* 16 | $Id: dictionary.c,v 1.27 2007-11-23 21:39:18 ndevilla Exp $ 17 | $Revision: 1.27 $ 18 | */ 19 | /*--------------------------------------------------------------------------- 20 | Includes 21 | ---------------------------------------------------------------------------*/ 22 | #include "dictionary.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | /** Maximum value size for integers and doubles. */ 30 | #define MAXVALSZ 1024 31 | 32 | /** Minimal allocated number of entries in a dictionary */ 33 | #define DICTMINSZ 128 34 | 35 | /** Invalid key token */ 36 | #define DICT_INVALID_KEY ((char*)-1) 37 | 38 | /*--------------------------------------------------------------------------- 39 | Private functions 40 | ---------------------------------------------------------------------------*/ 41 | 42 | /* Doubles the allocated size associated to a pointer */ 43 | /* 'size' is the current allocated size. */ 44 | static void * mem_double(void * ptr, int size) 45 | { 46 | void * newptr ; 47 | 48 | newptr = calloc(2*size, 1); 49 | if (newptr==NULL) { 50 | return NULL ; 51 | } 52 | memcpy(newptr, ptr, size); 53 | free(ptr); 54 | return newptr ; 55 | } 56 | 57 | /*-------------------------------------------------------------------------*/ 58 | /** 59 | @brief Duplicate a string 60 | @param s String to duplicate 61 | @return Pointer to a newly allocated string, to be freed with free() 62 | 63 | This is a replacement for strdup(). This implementation is provided 64 | for systems that do not have it. 65 | */ 66 | /*--------------------------------------------------------------------------*/ 67 | static char * xstrdup(char * s) 68 | { 69 | char * t ; 70 | if (!s) 71 | return NULL ; 72 | t = (char*)malloc(strlen(s)+1) ; 73 | if (t) { 74 | strcpy(t,s); 75 | } 76 | return t ; 77 | } 78 | 79 | /*--------------------------------------------------------------------------- 80 | Function codes 81 | ---------------------------------------------------------------------------*/ 82 | /*-------------------------------------------------------------------------*/ 83 | /** 84 | @brief Compute the hash key for a string. 85 | @param key Character string to use for key. 86 | @return 1 unsigned int on at least 32 bits. 87 | 88 | This hash function has been taken from an Article in Dr Dobbs Journal. 89 | This is normally a collision-free function, distributing keys evenly. 90 | The key is stored anyway in the struct so that collision can be avoided 91 | by comparing the key itself in last resort. 92 | */ 93 | /*--------------------------------------------------------------------------*/ 94 | unsigned dictionary_hash(char * key) 95 | { 96 | int len ; 97 | unsigned hash ; 98 | int i ; 99 | 100 | len = strlen(key); 101 | for (hash=0, i=0 ; i>6) ; 105 | } 106 | hash += (hash <<3); 107 | hash ^= (hash >>11); 108 | hash += (hash <<15); 109 | return hash ; 110 | } 111 | 112 | /*-------------------------------------------------------------------------*/ 113 | /** 114 | @brief Create a new dictionary object. 115 | @param size Optional initial size of the dictionary. 116 | @return 1 newly allocated dictionary objet. 117 | 118 | This function allocates a new dictionary object of given size and returns 119 | it. If you do not know in advance (roughly) the number of entries in the 120 | dictionary, give size=0. 121 | */ 122 | /*--------------------------------------------------------------------------*/ 123 | dictionary * dictionary_new(int size) 124 | { 125 | dictionary * d ; 126 | 127 | /* If no size was specified, allocate space for DICTMINSZ */ 128 | if (sizesize = size ; 134 | d->val = (char **)calloc(size, sizeof(char*)); 135 | d->key = (char **)calloc(size, sizeof(char*)); 136 | d->hash = (unsigned int *)calloc(size, sizeof(unsigned)); 137 | return d ; 138 | } 139 | 140 | /*-------------------------------------------------------------------------*/ 141 | /** 142 | @brief Delete a dictionary object 143 | @param d dictionary object to deallocate. 144 | @return void 145 | 146 | Deallocate a dictionary object and all memory associated to it. 147 | */ 148 | /*--------------------------------------------------------------------------*/ 149 | void dictionary_del(dictionary * d) 150 | { 151 | int i ; 152 | 153 | if (d==NULL) return ; 154 | for (i=0 ; isize ; i++) { 155 | if (d->key[i]!=NULL) 156 | free(d->key[i]); 157 | if (d->val[i]!=NULL) 158 | free(d->val[i]); 159 | } 160 | free(d->val); 161 | free(d->key); 162 | free(d->hash); 163 | free(d); 164 | return ; 165 | } 166 | 167 | /*-------------------------------------------------------------------------*/ 168 | /** 169 | @brief Get a value from a dictionary. 170 | @param d dictionary object to search. 171 | @param key Key to look for in the dictionary. 172 | @param def Default value to return if key not found. 173 | @return 1 pointer to internally allocated character string. 174 | 175 | This function locates a key in a dictionary and returns a pointer to its 176 | value, or the passed 'def' pointer if no such key can be found in 177 | dictionary. The returned character pointer points to data internal to the 178 | dictionary object, you should not try to free it or modify it. 179 | */ 180 | /*--------------------------------------------------------------------------*/ 181 | char * dictionary_get(dictionary * d, char * key, char * def) 182 | { 183 | unsigned hash ; 184 | int i ; 185 | 186 | hash = dictionary_hash(key); 187 | for (i=0 ; isize ; i++) { 188 | if (d->key[i]==NULL) 189 | continue ; 190 | /* Compare hash */ 191 | if (hash==d->hash[i]) { 192 | /* Compare string, to avoid hash collisions */ 193 | if (!strcmp(key, d->key[i])) { 194 | return d->val[i] ; 195 | } 196 | } 197 | } 198 | return def ; 199 | } 200 | 201 | /*-------------------------------------------------------------------------*/ 202 | /** 203 | @brief Set a value in a dictionary. 204 | @param d dictionary object to modify. 205 | @param key Key to modify or add. 206 | @param val Value to add. 207 | @return int 0 if Ok, anything else otherwise 208 | 209 | If the given key is found in the dictionary, the associated value is 210 | replaced by the provided one. If the key cannot be found in the 211 | dictionary, it is added to it. 212 | 213 | It is Ok to provide a NULL value for val, but NULL values for the dictionary 214 | or the key are considered as errors: the function will return immediately 215 | in such a case. 216 | 217 | Notice that if you dictionary_set a variable to NULL, a call to 218 | dictionary_get will return a NULL value: the variable will be found, and 219 | its value (NULL) is returned. In other words, setting the variable 220 | content to NULL is equivalent to deleting the variable from the 221 | dictionary. It is not possible (in this implementation) to have a key in 222 | the dictionary without value. 223 | 224 | This function returns non-zero in case of failure. 225 | */ 226 | /*--------------------------------------------------------------------------*/ 227 | int dictionary_set(dictionary * d, char * key, char * val) 228 | { 229 | int i ; 230 | unsigned hash ; 231 | 232 | if (d==NULL || key==NULL) return -1 ; 233 | 234 | /* Compute hash for this key */ 235 | hash = dictionary_hash(key) ; 236 | /* Find if value is already in dictionary */ 237 | if (d->n>0) { 238 | for (i=0 ; isize ; i++) { 239 | if (d->key[i]==NULL) 240 | continue ; 241 | if (hash==d->hash[i]) { /* Same hash value */ 242 | if (!strcmp(key, d->key[i])) { /* Same key */ 243 | /* Found a value: modify and return */ 244 | if (d->val[i]!=NULL) 245 | free(d->val[i]); 246 | d->val[i] = val ? xstrdup(val) : NULL ; 247 | /* Value has been modified: return */ 248 | return 0 ; 249 | } 250 | } 251 | } 252 | } 253 | /* Add a new value */ 254 | /* See if dictionary needs to grow */ 255 | if (d->n==d->size) { 256 | 257 | /* Reached maximum size: reallocate dictionary */ 258 | d->val = (char **)mem_double(d->val, d->size * sizeof(char*)) ; 259 | d->key = (char **)mem_double(d->key, d->size * sizeof(char*)) ; 260 | d->hash = (unsigned int *)mem_double(d->hash, d->size * sizeof(unsigned)) ; 261 | if ((d->val==NULL) || (d->key==NULL) || (d->hash==NULL)) { 262 | /* Cannot grow dictionary */ 263 | return -1 ; 264 | } 265 | /* Double size */ 266 | d->size *= 2 ; 267 | } 268 | 269 | /* Insert key in the first empty slot */ 270 | for (i=0 ; isize ; i++) { 271 | if (d->key[i]==NULL) { 272 | /* Add key here */ 273 | break ; 274 | } 275 | } 276 | /* Copy key */ 277 | d->key[i] = xstrdup(key); 278 | d->val[i] = val ? xstrdup(val) : NULL ; 279 | d->hash[i] = hash; 280 | d->n ++ ; 281 | return 0 ; 282 | } 283 | 284 | /*-------------------------------------------------------------------------*/ 285 | /** 286 | @brief Delete a key in a dictionary 287 | @param d dictionary object to modify. 288 | @param key Key to remove. 289 | @return void 290 | 291 | This function deletes a key in a dictionary. Nothing is done if the 292 | key cannot be found. 293 | */ 294 | /*--------------------------------------------------------------------------*/ 295 | void dictionary_unset(dictionary * d, char * key) 296 | { 297 | unsigned hash ; 298 | int i ; 299 | 300 | if (key == NULL) { 301 | return; 302 | } 303 | 304 | hash = dictionary_hash(key); 305 | for (i=0 ; isize ; i++) { 306 | if (d->key[i]==NULL) 307 | continue ; 308 | /* Compare hash */ 309 | if (hash==d->hash[i]) { 310 | /* Compare string, to avoid hash collisions */ 311 | if (!strcmp(key, d->key[i])) { 312 | /* Found key */ 313 | break ; 314 | } 315 | } 316 | } 317 | if (i>=d->size) 318 | /* Key not found */ 319 | return ; 320 | 321 | free(d->key[i]); 322 | d->key[i] = NULL ; 323 | if (d->val[i]!=NULL) { 324 | free(d->val[i]); 325 | d->val[i] = NULL ; 326 | } 327 | d->hash[i] = 0 ; 328 | d->n -- ; 329 | return ; 330 | } 331 | 332 | /*-------------------------------------------------------------------------*/ 333 | /** 334 | @brief Dump a dictionary to an opened file pointer. 335 | @param d Dictionary to dump 336 | @param f Opened file pointer. 337 | @return void 338 | 339 | Dumps a dictionary onto an opened file pointer. Key pairs are printed out 340 | as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as 341 | output file pointers. 342 | */ 343 | /*--------------------------------------------------------------------------*/ 344 | void dictionary_dump(dictionary * d, FILE * out) 345 | { 346 | int i ; 347 | 348 | if (d==NULL || out==NULL) return ; 349 | if (d->n<1) { 350 | fprintf(out, "empty dictionary\n"); 351 | return ; 352 | } 353 | for (i=0 ; isize ; i++) { 354 | if (d->key[i]) { 355 | fprintf(out, "%20s\t[%s]\n", 356 | d->key[i], 357 | d->val[i] ? d->val[i] : "UNDEF"); 358 | } 359 | } 360 | return ; 361 | } 362 | 363 | 364 | /* Test code */ 365 | #ifdef TESTDIC 366 | #define NVALS 20000 367 | int main(int argc, char *argv[]) 368 | { 369 | dictionary * d ; 370 | char * val ; 371 | int i ; 372 | char cval[90] ; 373 | 374 | /* Allocate dictionary */ 375 | printf("allocating...\n"); 376 | d = dictionary_new(0); 377 | 378 | /* Set values in dictionary */ 379 | printf("setting %d values...\n", NVALS); 380 | for (i=0 ; in != 0) { 398 | printf("error deleting values\n"); 399 | } 400 | printf("deallocating...\n"); 401 | dictionary_del(d); 402 | return 0 ; 403 | } 404 | #endif 405 | /* vim: set ts=4 et sw=4 tw=75 */ 406 | -------------------------------------------------------------------------------- /src/ini_parser/iniparser.c: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------------------*/ 3 | /** 4 | @file iniparser.c 5 | @author N. Devillard 6 | @date Sep 2007 7 | @version 3.0 8 | @brief Parser for ini files. 9 | */ 10 | /*--------------------------------------------------------------------------*/ 11 | /* 12 | $Id: iniparser.c,v 2.18 2008-01-03 18:35:39 ndevilla Exp $ 13 | $Revision: 2.18 $ 14 | $Date: 2008-01-03 18:35:39 $ 15 | */ 16 | /*---------------------------- Includes ------------------------------------*/ 17 | #include 18 | #include "iniparser.h" 19 | 20 | /*---------------------------- Defines -------------------------------------*/ 21 | #define ASCIILINESZ (1024) 22 | #define INI_INVALID_KEY ((char*)-1) 23 | 24 | /*--------------------------------------------------------------------------- 25 | Private to this module 26 | ---------------------------------------------------------------------------*/ 27 | /** 28 | * This enum stores the status for each parsed line (internal use only). 29 | */ 30 | typedef enum _line_status_ { 31 | LINE_UNPROCESSED, 32 | LINE_ERROR, 33 | LINE_EMPTY, 34 | LINE_COMMENT, 35 | LINE_SECTION, 36 | LINE_VALUE 37 | } line_status ; 38 | 39 | /*-------------------------------------------------------------------------*/ 40 | /** 41 | @brief Convert a string to lowercase. 42 | @param s String to convert. 43 | @return ptr to statically allocated string. 44 | 45 | This function returns a pointer to a statically allocated string 46 | containing a lowercased version of the input string. Do not free 47 | or modify the returned string! Since the returned string is statically 48 | allocated, it will be modified at each function call (not re-entrant). 49 | */ 50 | /*--------------------------------------------------------------------------*/ 51 | static char * strlwc(const char * s) 52 | { 53 | static char l[ASCIILINESZ+1]; 54 | int i ; 55 | 56 | if (s==NULL) return NULL ; 57 | memset(l, 0, ASCIILINESZ+1); 58 | i=0 ; 59 | while (s[i] && i l) { 93 | if (!isspace((int)*(last-1))) 94 | break ; 95 | last -- ; 96 | } 97 | *last = (char)0; 98 | return (char*)l ; 99 | } 100 | 101 | /*-------------------------------------------------------------------------*/ 102 | /** 103 | @brief Get number of sections in a dictionary 104 | @param d Dictionary to examine 105 | @return int Number of sections found in dictionary 106 | 107 | This function returns the number of sections found in a dictionary. 108 | The test to recognize sections is done on the string stored in the 109 | dictionary: a section name is given as "section" whereas a key is 110 | stored as "section:key", thus the test looks for entries that do not 111 | contain a colon. 112 | 113 | This clearly fails in the case a section name contains a colon, but 114 | this should simply be avoided. 115 | 116 | This function returns -1 in case of error. 117 | */ 118 | /*--------------------------------------------------------------------------*/ 119 | int iniparser_getnsec(dictionary * d) 120 | { 121 | int i ; 122 | int nsec ; 123 | 124 | if (d==NULL) return -1 ; 125 | nsec=0 ; 126 | for (i=0 ; isize ; i++) { 127 | if (d->key[i]==NULL) 128 | continue ; 129 | if (strchr(d->key[i], ':')==NULL) { 130 | nsec ++ ; 131 | } 132 | } 133 | return nsec ; 134 | } 135 | 136 | /*-------------------------------------------------------------------------*/ 137 | /** 138 | @brief Get name for section n in a dictionary. 139 | @param d Dictionary to examine 140 | @param n Section number (from 0 to nsec-1). 141 | @return Pointer to char string 142 | 143 | This function locates the n-th section in a dictionary and returns 144 | its name as a pointer to a string statically allocated inside the 145 | dictionary. Do not free or modify the returned string! 146 | 147 | This function returns NULL in case of error. 148 | */ 149 | /*--------------------------------------------------------------------------*/ 150 | char * iniparser_getsecname(dictionary * d, int n) 151 | { 152 | int i ; 153 | int foundsec ; 154 | 155 | if (d==NULL || n<0) return NULL ; 156 | foundsec=0 ; 157 | for (i=0 ; isize ; i++) { 158 | if (d->key[i]==NULL) 159 | continue ; 160 | if (strchr(d->key[i], ':')==NULL) { 161 | foundsec++ ; 162 | if (foundsec>n) 163 | break ; 164 | } 165 | } 166 | if (foundsec<=n) { 167 | return NULL ; 168 | } 169 | return d->key[i] ; 170 | } 171 | 172 | /*-------------------------------------------------------------------------*/ 173 | /** 174 | @brief Dump a dictionary to an opened file pointer. 175 | @param d Dictionary to dump. 176 | @param f Opened file pointer to dump to. 177 | @return void 178 | 179 | This function prints out the contents of a dictionary, one element by 180 | line, onto the provided file pointer. It is OK to specify @c stderr 181 | or @c stdout as output files. This function is meant for debugging 182 | purposes mostly. 183 | */ 184 | /*--------------------------------------------------------------------------*/ 185 | void iniparser_dump(dictionary * d, FILE * f) 186 | { 187 | int i ; 188 | 189 | if (d==NULL || f==NULL) return ; 190 | for (i=0 ; isize ; i++) { 191 | if (d->key[i]==NULL) 192 | continue ; 193 | if (d->val[i]!=NULL) { 194 | fprintf(f, "[%s]=[%s]\n", d->key[i], d->val[i]); 195 | } else { 196 | fprintf(f, "[%s]=UNDEF\n", d->key[i]); 197 | } 198 | } 199 | return ; 200 | } 201 | 202 | /*-------------------------------------------------------------------------*/ 203 | /** 204 | @brief Save a dictionary to a loadable ini file 205 | @param d Dictionary to dump 206 | @param f Opened file pointer to dump to 207 | @return void 208 | 209 | This function dumps a given dictionary into a loadable ini file. 210 | It is Ok to specify @c stderr or @c stdout as output files. 211 | */ 212 | /*--------------------------------------------------------------------------*/ 213 | void iniparser_dump_ini(dictionary * d, FILE * f) 214 | { 215 | int i, j ; 216 | char keym[ASCIILINESZ+1]; 217 | int nsec ; 218 | char * secname ; 219 | int seclen ; 220 | 221 | if (d==NULL || f==NULL) return ; 222 | 223 | nsec = iniparser_getnsec(d); 224 | if (nsec<1) { 225 | /* No section in file: dump all keys as they are */ 226 | for (i=0 ; isize ; i++) { 227 | if (d->key[i]==NULL) 228 | continue ; 229 | fprintf(f, "%s = %s\n", d->key[i], d->val[i]); 230 | } 231 | return ; 232 | } 233 | for (i=0 ; isize ; j++) { 239 | if (d->key[j]==NULL) 240 | continue ; 241 | if (!strncmp(d->key[j], keym, seclen+1)) { 242 | fprintf(f, 243 | "%-30s = %s\n", 244 | d->key[j]+seclen+1, 245 | d->val[j] ? d->val[j] : ""); 246 | } 247 | } 248 | } 249 | fprintf(f, "\n"); 250 | return ; 251 | } 252 | 253 | /*-------------------------------------------------------------------------*/ 254 | /** 255 | @brief Get the string associated to a key 256 | @param d Dictionary to search 257 | @param key Key string to look for 258 | @param def Default value to return if key not found. 259 | @return pointer to statically allocated character string 260 | 261 | This function queries a dictionary for a key. A key as read from an 262 | ini file is given as "section:key". If the key cannot be found, 263 | the pointer passed as 'def' is returned. 264 | The returned char pointer is pointing to a string allocated in 265 | the dictionary, do not free or modify it. 266 | */ 267 | /*--------------------------------------------------------------------------*/ 268 | char * iniparser_getstring(dictionary * d, const char * key, char * def) 269 | { 270 | char * lc_key ; 271 | char * sval ; 272 | 273 | if (d==NULL || key==NULL) 274 | return def ; 275 | 276 | lc_key = strlwc(key); 277 | sval = dictionary_get(d, lc_key, def); 278 | return sval ; 279 | } 280 | 281 | /*-------------------------------------------------------------------------*/ 282 | /** 283 | @brief Get the string associated to a key, convert to an int 284 | @param d Dictionary to search 285 | @param key Key string to look for 286 | @param notfound Value to return in case of error 287 | @return integer 288 | 289 | This function queries a dictionary for a key. A key as read from an 290 | ini file is given as "section:key". If the key cannot be found, 291 | the notfound value is returned. 292 | 293 | Supported values for integers include the usual C notation 294 | so decimal, octal (starting with 0) and hexadecimal (starting with 0x) 295 | are supported. Examples: 296 | 297 | "42" -> 42 298 | "042" -> 34 (octal -> decimal) 299 | "0x42" -> 66 (hexa -> decimal) 300 | 301 | Warning: the conversion may overflow in various ways. Conversion is 302 | totally outsourced to strtol(), see the associated man page for overflow 303 | handling. 304 | 305 | Credits: Thanks to A. Becker for suggesting strtol() 306 | */ 307 | /*--------------------------------------------------------------------------*/ 308 | int iniparser_getint(dictionary * d, const char * key, int notfound) 309 | { 310 | char * str ; 311 | 312 | str = iniparser_getstring(d, key, INI_INVALID_KEY); 313 | if (str==INI_INVALID_KEY) return notfound ; 314 | return (int)strtol(str, NULL, 0); 315 | } 316 | 317 | /*-------------------------------------------------------------------------*/ 318 | /** 319 | @brief Get the string associated to a key, convert to a double 320 | @param d Dictionary to search 321 | @param key Key string to look for 322 | @param notfound Value to return in case of error 323 | @return double 324 | 325 | This function queries a dictionary for a key. A key as read from an 326 | ini file is given as "section:key". If the key cannot be found, 327 | the notfound value is returned. 328 | */ 329 | /*--------------------------------------------------------------------------*/ 330 | double iniparser_getdouble(dictionary * d, char * key, double notfound) 331 | { 332 | char * str ; 333 | 334 | str = iniparser_getstring(d, key, INI_INVALID_KEY); 335 | if (str==INI_INVALID_KEY) return notfound ; 336 | return atof(str); 337 | } 338 | 339 | /*-------------------------------------------------------------------------*/ 340 | /** 341 | @brief Get the string associated to a key, convert to a boolean 342 | @param d Dictionary to search 343 | @param key Key string to look for 344 | @param notfound Value to return in case of error 345 | @return integer 346 | 347 | This function queries a dictionary for a key. A key as read from an 348 | ini file is given as "section:key". If the key cannot be found, 349 | the notfound value is returned. 350 | 351 | A true boolean is found if one of the following is matched: 352 | 353 | - A string starting with 'y' 354 | - A string starting with 'Y' 355 | - A string starting with 't' 356 | - A string starting with 'T' 357 | - A string starting with '1' 358 | 359 | A false boolean is found if one of the following is matched: 360 | 361 | - A string starting with 'n' 362 | - A string starting with 'N' 363 | - A string starting with 'f' 364 | - A string starting with 'F' 365 | - A string starting with '0' 366 | 367 | The notfound value returned if no boolean is identified, does not 368 | necessarily have to be 0 or 1. 369 | */ 370 | /*--------------------------------------------------------------------------*/ 371 | int iniparser_getboolean(dictionary * d, const char * key, int notfound) 372 | { 373 | char * c ; 374 | int ret ; 375 | 376 | c = iniparser_getstring(d, key, INI_INVALID_KEY); 377 | if (c==INI_INVALID_KEY) return notfound ; 378 | if (c[0]=='y' || c[0]=='Y' || c[0]=='1' || c[0]=='t' || c[0]=='T') { 379 | ret = 1 ; 380 | } else if (c[0]=='n' || c[0]=='N' || c[0]=='0' || c[0]=='f' || c[0]=='F') { 381 | ret = 0 ; 382 | } else { 383 | ret = notfound ; 384 | } 385 | return ret; 386 | } 387 | 388 | /*-------------------------------------------------------------------------*/ 389 | /** 390 | @brief Finds out if a given entry exists in a dictionary 391 | @param ini Dictionary to search 392 | @param entry Name of the entry to look for 393 | @return integer 1 if entry exists, 0 otherwise 394 | 395 | Finds out if a given entry exists in the dictionary. Since sections 396 | are stored as keys with NULL associated values, this is the only way 397 | of querying for the presence of sections in a dictionary. 398 | */ 399 | /*--------------------------------------------------------------------------*/ 400 | int iniparser_find_entry( 401 | dictionary * ini, 402 | char * entry 403 | ) 404 | { 405 | int found=0 ; 406 | if (iniparser_getstring(ini, entry, INI_INVALID_KEY)!=INI_INVALID_KEY) { 407 | found = 1 ; 408 | } 409 | return found ; 410 | } 411 | 412 | /*-------------------------------------------------------------------------*/ 413 | /** 414 | @brief Set an entry in a dictionary. 415 | @param ini Dictionary to modify. 416 | @param entry Entry to modify (entry name) 417 | @param val New value to associate to the entry. 418 | @return int 0 if Ok, -1 otherwise. 419 | 420 | If the given entry can be found in the dictionary, it is modified to 421 | contain the provided value. If it cannot be found, -1 is returned. 422 | It is Ok to set val to NULL. 423 | */ 424 | /*--------------------------------------------------------------------------*/ 425 | int iniparser_set(dictionary * ini, char * entry, char * val) 426 | { 427 | return dictionary_set(ini, strlwc(entry), val) ; 428 | } 429 | 430 | /*-------------------------------------------------------------------------*/ 431 | /** 432 | @brief Delete an entry in a dictionary 433 | @param ini Dictionary to modify 434 | @param entry Entry to delete (entry name) 435 | @return void 436 | 437 | If the given entry can be found, it is deleted from the dictionary. 438 | */ 439 | /*--------------------------------------------------------------------------*/ 440 | void iniparser_unset(dictionary * ini, char * entry) 441 | { 442 | dictionary_unset(ini, strlwc(entry)); 443 | } 444 | 445 | /*-------------------------------------------------------------------------*/ 446 | /** 447 | @brief Load a single line from an INI file 448 | @param input_line Input line, may be concatenated multi-line input 449 | @param section Output space to store section 450 | @param key Output space to store key 451 | @param value Output space to store value 452 | @return line_status value 453 | */ 454 | /*--------------------------------------------------------------------------*/ 455 | static line_status iniparser_line( 456 | char * input_line, 457 | char * section, 458 | char * key, 459 | char * value) 460 | { 461 | line_status sta ; 462 | char line[ASCIILINESZ+1]; 463 | int len ; 464 | 465 | strcpy(line, strstrip(input_line)); 466 | len = (int)strlen(line); 467 | 468 | sta = LINE_UNPROCESSED ; 469 | if (len<1) { 470 | /* Empty line */ 471 | sta = LINE_EMPTY ; 472 | } else if (line[0]=='#') { 473 | /* Comment line */ 474 | sta = LINE_COMMENT ; 475 | } else if (line[0]=='[' && line[len-1]==']') { 476 | /* Section name */ 477 | sscanf(line, "[%[^]]", section); 478 | strcpy(section, strstrip(section)); 479 | strcpy(section, strlwc(section)); 480 | sta = LINE_SECTION ; 481 | } else if (sscanf (line, "%[^=] = \"%[^\"]\"", key, value) == 2 482 | || sscanf (line, "%[^=] = '%[^\']'", key, value) == 2 483 | || sscanf (line, "%[^=] = %[^;#]", key, value) == 2) { 484 | /* Usual key=value, with or without comments */ 485 | strcpy(key, strstrip(key)); 486 | strcpy(key, strlwc(key)); 487 | strcpy(value, strstrip(value)); 488 | /* 489 | * sscanf cannot handle '' or "" as empty values 490 | * this is done here 491 | */ 492 | if (!strcmp(value, "\"\"") || (!strcmp(value, "''"))) { 493 | value[0]=0 ; 494 | } 495 | sta = LINE_VALUE ; 496 | } else if (sscanf(line, "%[^=] = %[;#]", key, value)==2 497 | || sscanf(line, "%[^=] %[=]", key, value) == 2) { 498 | /* 499 | * Special cases: 500 | * key= 501 | * key=; 502 | * key=# 503 | */ 504 | strcpy(key, strstrip(key)); 505 | strcpy(key, strlwc(key)); 506 | value[0]=0 ; 507 | sta = LINE_VALUE ; 508 | } else { 509 | /* Generate syntax error */ 510 | sta = LINE_ERROR ; 511 | } 512 | return sta ; 513 | } 514 | 515 | /*-------------------------------------------------------------------------*/ 516 | /** 517 | @brief Parse an ini file and return an allocated dictionary object 518 | @param ininame Name of the ini file to read. 519 | @return Pointer to newly allocated dictionary 520 | 521 | This is the parser for ini files. This function is called, providing 522 | the name of the file to be read. It returns a dictionary object that 523 | should not be accessed directly, but through accessor functions 524 | instead. 525 | 526 | The returned dictionary must be freed using iniparser_freedict(). 527 | */ 528 | /*--------------------------------------------------------------------------*/ 529 | dictionary * iniparser_load(const char * ininame) 530 | { 531 | FILE * in ; 532 | 533 | char line [ASCIILINESZ+1] ; 534 | char section [ASCIILINESZ+1] ; 535 | char key [ASCIILINESZ+1] ; 536 | char tmp [ASCIILINESZ+1] ; 537 | char val [ASCIILINESZ+1] ; 538 | 539 | int last=0 ; 540 | int len ; 541 | int lineno=0 ; 542 | int errs=0; 543 | 544 | dictionary * dict ; 545 | 546 | if ((in=fopen(ininame, "r"))==NULL) { 547 | fprintf(stderr, "iniparser: cannot open %s\n", ininame); 548 | return NULL ; 549 | } 550 | 551 | dict = dictionary_new(0) ; 552 | if (!dict) { 553 | fclose(in); 554 | return NULL ; 555 | } 556 | 557 | memset(line, 0, ASCIILINESZ); 558 | memset(section, 0, ASCIILINESZ); 559 | memset(key, 0, ASCIILINESZ); 560 | memset(val, 0, ASCIILINESZ); 561 | last=0 ; 562 | 563 | while (fgets(line+last, ASCIILINESZ-last, in)!=NULL) { 564 | lineno++ ; 565 | len = (int)strlen(line)-1; 566 | /* Safety check against buffer overflows */ 567 | if (line[len]!='\n') { 568 | fprintf(stderr, 569 | "iniparser: input line too long in %s (%d)\n", 570 | ininame, 571 | lineno); 572 | dictionary_del(dict); 573 | fclose(in); 574 | return NULL ; 575 | } 576 | /* Get rid of \n and spaces at end of line */ 577 | while ((len>=0) && 578 | ((line[len]=='\n') || (isspace(line[len])))) { 579 | line[len]=0 ; 580 | len-- ; 581 | } 582 | /* Detect multi-line */ 583 | if (line[len]=='\\') { 584 | /* Multi-line value */ 585 | last=len ; 586 | continue ; 587 | } else { 588 | last=0 ; 589 | } 590 | switch (iniparser_line(line, section, key, val)) { 591 | case LINE_EMPTY: 592 | case LINE_COMMENT: 593 | break ; 594 | 595 | case LINE_SECTION: 596 | errs = dictionary_set(dict, section, NULL); 597 | break ; 598 | 599 | case LINE_VALUE: 600 | sprintf(tmp, "%s:%s", section, key); 601 | errs = dictionary_set(dict, tmp, val) ; 602 | break ; 603 | 604 | case LINE_ERROR: 605 | fprintf(stderr, "iniparser: syntax error in %s (%d):\n", 606 | ininame, 607 | lineno); 608 | fprintf(stderr, "-> %s\n", line); 609 | errs++ ; 610 | break; 611 | 612 | default: 613 | break ; 614 | } 615 | memset(line, 0, ASCIILINESZ); 616 | last=0; 617 | if (errs<0) { 618 | fprintf(stderr, "iniparser: memory allocation failure\n"); 619 | break ; 620 | } 621 | } 622 | if (errs) { 623 | dictionary_del(dict); 624 | dict = NULL ; 625 | } 626 | fclose(in); 627 | return dict ; 628 | } 629 | 630 | /*-------------------------------------------------------------------------*/ 631 | /** 632 | @brief Free all memory associated to an ini dictionary 633 | @param d Dictionary to free 634 | @return void 635 | 636 | Free all memory associated to an ini dictionary. 637 | It is mandatory to call this function before the dictionary object 638 | gets out of the current context. 639 | */ 640 | /*--------------------------------------------------------------------------*/ 641 | void iniparser_freedict(dictionary * d) 642 | { 643 | dictionary_del(d); 644 | } 645 | 646 | /* vim: set ts=4 et sw=4 tw=75 */ 647 | -------------------------------------------------------------------------------- /tags: -------------------------------------------------------------------------------- 1 | !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ 2 | !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ 3 | !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ 4 | !_TAG_PROGRAM_NAME Exuberant Ctags // 5 | !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ 6 | !_TAG_PROGRAM_VERSION 5.7 // 7 | ALL_GOOD src/resources.h 25;" d 8 | ASCIILINESZ src/ini_parser/iniparser.c 21;" d file: 9 | Config_loader src/helpers/config_loader.h /^class Config_loader$/;" c 10 | DICTMINSZ src/ini_parser/dictionary.c 33;" d file: 11 | DICT_INVALID_KEY src/ini_parser/dictionary.c 36;" d file: 12 | DISPLAY_INIT_FAILED src/resources.h 22;" d 13 | Direction src/resources.h /^enum Direction$/;" g 14 | Display src/sdl/sdl_dm.h /^ SDL_Surface *Display;$/;" m class:SDL_DM 15 | Down src/resources.h /^ Left, Right, Up, Down$/;" e enum:Direction 16 | EVENT_MANAGEMENT_H_ src/sdl/event_management.h 21;" d 17 | FILE_HELPER_H_ src/helpers/file_helper.h 3;" d 18 | File_helper src/helpers/file_helper.cc /^File_helper::File_helper()$/;" f class:File_helper 19 | File_helper src/helpers/file_helper.h /^class File_helper$/;" c 20 | ILLIGAL_OFFSET src/mem_manager/llist.h 9;" d 21 | INI_INVALID_KEY src/ini_parser/iniparser.c 22;" d file: 22 | Image_node src/sdl/image.h /^class Image_node$/;" c 23 | Int_node src/mem_manager/int_node.h /^class Int_node$/;" c 24 | LINE_COMMENT src/ini_parser/iniparser.c /^ LINE_COMMENT,$/;" e enum:_line_status_ file: 25 | LINE_EMPTY src/ini_parser/iniparser.c /^ LINE_EMPTY,$/;" e enum:_line_status_ file: 26 | LINE_ERROR src/ini_parser/iniparser.c /^ LINE_ERROR,$/;" e enum:_line_status_ file: 27 | LINE_SECTION src/ini_parser/iniparser.c /^ LINE_SECTION,$/;" e enum:_line_status_ file: 28 | LINE_UNPROCESSED src/ini_parser/iniparser.c /^ LINE_UNPROCESSED,$/;" e enum:_line_status_ file: 29 | LINE_VALUE src/ini_parser/iniparser.c /^ LINE_VALUE$/;" e enum:_line_status_ file: 30 | LLIST_H_ src/mem_manager/llist.h 3;" d 31 | Left src/resources.h /^ Left, Right, Up, Down$/;" e enum:Direction 32 | LinkedList src/mem_manager/llist.h /^ LinkedList ( )$/;" f class:LinkedList 33 | LinkedList src/mem_manager/llist.h /^class LinkedList$/;" c 34 | Linked_list_exception src/mem_manager/llist.h /^class Linked_list_exception$/;" c 35 | MAP_H_ src/map.h 3;" d 36 | MAXVALSZ src/ini_parser/dictionary.c 30;" d file: 37 | MEMORY_ALLOCATION_ERROR src/resources.h 24;" d 38 | MISSILE_IMAGE src/resources.h 27;" d 39 | Map src/map.cc /^Map::Map()$/;" f class:Map 40 | Map src/map.h /^class Map$/;" c 41 | NOT_INITIALIZED src/mem_manager/llist.h 8;" d 42 | NVALS src/ini_parser/dictionary.c 366;" d file: 43 | OBJECT_H_ src/objects/object.h 3;" d 44 | Object src/objects/object.h /^class Object$/;" c 45 | POINT_H_ src/point.h 3;" d 46 | Point src/point.h /^struct Point$/;" s 47 | RESOURCES_H_ src/resources.h 20;" d 48 | Rectangle src/sdl/sdl_dm.h 11;" d 49 | Right src/resources.h /^ Left, Right, Up, Down$/;" e enum:Direction 50 | SDL_DM src/sdl/sdl_dm.cc /^SDL_DM::SDL_DM ()$/;" f class:SDL_DM 51 | SDL_DM src/sdl/sdl_dm.h /^class SDL_DM$/;" c 52 | SDL_DM_H_ src/sdl/sdl_dm.h 3;" d 53 | SDL_Helper src/helpers/sdl_helper.h /^class SDL_Helper$/;" c 54 | STRING_COPY_EXCEPTION src/resources.h 23;" d 55 | STRING_HELPER_H_ src/helpers/string_helper.h 3;" d 56 | STRING_NODE_H_ src/mem_manager/string_node.h 3;" d 57 | STRING_TOKENIZER_H_ src/helpers/string_tokenizer.h 3;" d 58 | S_EXIT src/resources.h 29;" d 59 | String_helper src/helpers/string_helper.h /^class String_helper$/;" c 60 | String_node src/mem_manager/string_node.h /^ String_node()$/;" f class:String_node 61 | String_node src/mem_manager/string_node.h /^class String_node$/;" c 62 | String_tokenizer src/helpers/string_tokenizer.cc /^String_tokenizer::String_tokenizer()$/;" f class:String_tokenizer 63 | String_tokenizer src/helpers/string_tokenizer.h /^class String_tokenizer$/;" c 64 | Surface src/sdl/sdl_dm.h 8;" d 65 | TIME_H_ src/sdl/timer.h 3;" d 66 | Timer src/sdl/timer.cc /^Timer::Timer()$/;" f class:Timer 67 | Timer src/sdl/timer.h /^class Timer$/;" c 68 | Up src/resources.h /^ Left, Right, Up, Down$/;" e enum:Direction 69 | Vehical src/objects/vehical.h /^class Vehical : public Object$/;" c 70 | _DICTIONARY_H_ src/ini_parser/dictionary.h 24;" d 71 | _INIPARSER_H_ src/ini_parser/iniparser.h 18;" d 72 | _dictionary_ src/ini_parser/dictionary.h /^typedef struct _dictionary_ {$/;" s 73 | _line_status_ src/ini_parser/iniparser.c /^typedef enum _line_status_ {$/;" g file: 74 | add src/mem_manager/llist.h /^ int add(T data, int index=-1)$/;" f class:LinkedList 75 | add_empty src/mem_manager/llist.h /^ void add_empty(int index)$/;" f class:LinkedList 76 | add_new_node src/mem_manager/llist.h /^ void add_new_node(Node *new_node)$/;" f class:LinkedList 77 | add_string src/helpers/string_helper.cc /^void String_helper::add_string(LinkedList&list, int target, char *src2)$/;" f class:String_helper 78 | app_status src/main.cc /^int app_status;$/;" v 79 | background_color src/sdl/sdl_dm.h /^ Uint32 background_color;$/;" m class:SDL_DM 80 | clean_up src/helpers/file_helper.cc /^void File_helper::clean_up()$/;" f class:File_helper 81 | clean_up src/helpers/string_tokenizer.cc /^void String_tokenizer::clean_up()$/;" f class:String_tokenizer 82 | clean_up src/map.cc /^void Map::clean_up()$/;" f class:Map 83 | cleanup src/main.cc /^void cleanup()$/;" f 84 | clear src/mem_manager/llist.h /^ void clear()$/;" f class:LinkedList 85 | clear_screen src/main.cc /^void clear_screen()$/;" f 86 | close_display_manager src/sdl/sdl_dm.cc /^void SDL_DM::close_display_manager()$/;" f class:SDL_DM 87 | copy_img_to src/sdl/sdl_dm.cc /^bool SDL_DM::copy_img_to( SDL_Surface *image, Rectangle src, Point destp)$/;" f class:SDL_DM 88 | copy_string src/helpers/string_helper.cc /^bool String_helper::copy_string(char *&dest, const char *src)$/;" f class:String_helper 89 | count src/mem_manager/llist.h /^ int count;$/;" m class:LinkedList 90 | current src/mem_manager/llist.h /^ Node *current;$/;" m class:LinkedList 91 | current_dir src/objects/object.h /^ Direction current_dir;$/;" m class:Object 92 | current_equals src/mem_manager/llist.h /^ bool current_equals(T d)$/;" f class:LinkedList 93 | damage src/objects/object.h /^ int damage;$/;" m class:Object 94 | data src/mem_manager/int_node.h /^ int data;$/;" m class:Int_node 95 | data src/mem_manager/string_node.h /^ char* data;$/;" m class:String_node 96 | data src/sdl/image.h /^ SDL_Surface *data;$/;" m class:Image_node 97 | dictionary src/ini_parser/dictionary.h /^} dictionary ;$/;" t typeref:struct:_dictionary_ 98 | dictionary_del src/ini_parser/dictionary.c /^void dictionary_del(dictionary * d)$/;" f 99 | dictionary_dump src/ini_parser/dictionary.c /^void dictionary_dump(dictionary * d, FILE * out)$/;" f 100 | dictionary_get src/ini_parser/dictionary.c /^char * dictionary_get(dictionary * d, char * key, char * def)$/;" f 101 | dictionary_hash src/ini_parser/dictionary.c /^unsigned dictionary_hash(char * key)$/;" f 102 | dictionary_new src/ini_parser/dictionary.c /^dictionary * dictionary_new(int size)$/;" f 103 | dictionary_set src/ini_parser/dictionary.c /^int dictionary_set(dictionary * d, char * key, char * val)$/;" f 104 | dictionary_unset src/ini_parser/dictionary.c /^void dictionary_unset(dictionary * d, char * key)$/;" f 105 | display_map_info src/map.cc /^void Map::display_map_info()$/;" f class:Map 106 | draw_image src/sdl/sdl_dm.cc /^bool SDL_DM::draw_image(SDL_Surface *image, int x, int y)$/;" f class:SDL_DM 107 | empty src/mem_manager/string_node.h /^ bool empty;$/;" m class:String_node 108 | end_point src/map.h /^ Point end_point;$/;" m class:Map 109 | equals src/mem_manager/int_node.h /^ bool equals(int d)$/;" f class:Int_node 110 | equals src/mem_manager/string_node.h /^ bool equals(char *d)$/;" f class:String_node 111 | equals src/sdl/image.h /^ bool equals(SDL_Surface* tdata)$/;" f class:Image_node 112 | err_handler src/mem_manager/llist.h /^ Linked_list_exception err_handler;$/;" m class:LinkedList 113 | file_helper src/map.h /^ File_helper file_helper;$/;" m class:Map 114 | file_size src/helpers/file_helper.h /^ size_t file_size;$/;" m class:File_helper 115 | fill_rect src/sdl/sdl_dm.cc /^void SDL_DM::fill_rect (Uint32 colorkey, SDL_Rect *rect)$/;" f class:SDL_DM 116 | fill_surface src/sdl/sdl_dm.cc /^void SDL_DM::fill_surface (Uint32 colorkey)$/;" f class:SDL_DM 117 | find src/mem_manager/llist.h /^ bool find(T data)$/;" f class:LinkedList 118 | forward src/mem_manager/llist.h /^ void forward()$/;" f class:LinkedList 119 | game_ini src/main.cc /^dictionary *game_ini;$/;" v 120 | game_loop src/main.cc /^void game_loop()$/;" f 121 | get src/helpers/string_tokenizer.cc /^char *String_tokenizer::get(int token_no)$/;" f class:String_tokenizer 122 | get src/mem_manager/llist.h /^ T get(int index)$/;" f class:LinkedList 123 | get_colorkey src/sdl/sdl_dm.cc /^Uint32 SDL_DM::get_colorkey(int r, int g, int b)$/;" f class:SDL_DM 124 | get_count src/mem_manager/llist.h /^ int get_count()$/;" f class:LinkedList 125 | get_current src/mem_manager/llist.h /^ T get_current()$/;" f class:LinkedList 126 | get_current_index src/mem_manager/llist.h /^ int get_current_index()$/;" f class:LinkedList 127 | get_current_speed src/objects/object.cc /^int Object::get_current_speed()$/;" f class:Object 128 | get_damage src/objects/object.cc /^int Object::get_damage()$/;" f class:Object 129 | get_data src/mem_manager/int_node.h /^ int get_data()$/;" f class:Int_node 130 | get_data src/mem_manager/string_node.h /^ char *get_data()$/;" f class:String_node 131 | get_data src/sdl/image.h /^ SDL_Surface* get_data()$/;" f class:Image_node 132 | get_display_format src/sdl/sdl_dm.cc /^SDL_PixelFormat* SDL_DM::get_display_format () $/;" f class:SDL_DM 133 | get_file_size src/helpers/file_helper.cc /^long File_helper::get_file_size(FILE *fp)$/;" f class:File_helper 134 | get_file_size src/helpers/file_helper.cc /^long File_helper::get_file_size(char *fname)$/;" f class:File_helper 135 | get_height src/objects/object.cc /^int Object::get_height()$/;" f class:Object 136 | get_key_down src/main.cc /^void get_key_down()$/;" f 137 | get_keyboard_event src/main.cc /^void get_keyboard_event(SDL_Event Event)$/;" f 138 | get_last_file_size src/helpers/file_helper.cc /^long File_helper::get_last_file_size()$/;" f class:File_helper 139 | get_last_read_data src/helpers/file_helper.cc /^char *File_helper::get_last_read_data()$/;" f class:File_helper 140 | get_level src/objects/object.cc /^int Object::get_level()$/;" f class:Object 141 | get_life src/objects/object.cc /^int Object::get_life()$/;" f class:Object 142 | get_obj_id src/objects/object.cc /^int Object::get_obj_id()$/;" f class:Object 143 | get_pixel src/sdl/sdl_dm.cc /^Uint8 SDL_DM::get_pixel (int x, int y)$/;" f class:SDL_DM 144 | get_pos_x src/objects/object.cc /^int Object::get_pos_x()$/;" f class:Object 145 | get_pos_y src/objects/object.cc /^int Object::get_pos_y()$/;" f class:Object 146 | get_ticks src/sdl/sdl_dm.cc /^long SDL_DM::get_ticks () $/;" f class:SDL_DM 147 | get_ticks src/sdl/timer.cc /^int Timer::get_ticks()$/;" f class:Timer 148 | get_token src/helpers/string_tokenizer.cc /^char *String_tokenizer::get_token(int token_no)$/;" f class:String_tokenizer 149 | get_token_count src/helpers/string_tokenizer.cc /^int String_tokenizer::get_token_count()$/;" f class:String_tokenizer 150 | get_top_speed src/objects/vehical.cc /^int Vehical::get_top_speed()$/;" f class:Vehical 151 | get_width src/objects/object.cc /^int Object::get_width()$/;" f class:Object 152 | hash src/ini_parser/dictionary.h /^ unsigned * hash ; \/** List of hash values for keys *\/$/;" m struct:_dictionary_ 153 | head src/mem_manager/llist.h /^ Node *head;$/;" m class:LinkedList 154 | height src/objects/object.h /^ int height;$/;" m class:Object 155 | image_list src/main.cc /^LinkedListimage_list;$/;" v 156 | index src/mem_manager/int_node.h /^ int index;$/;" m class:Int_node 157 | index src/mem_manager/llist.h /^ int index;$/;" m class:LinkedList 158 | index src/mem_manager/string_node.h /^ int index;$/;" m class:String_node 159 | index src/sdl/image.h /^ int index;$/;" m class:Image_node 160 | iniparser_dump src/ini_parser/iniparser.c /^void iniparser_dump(dictionary * d, FILE * f)$/;" f 161 | iniparser_dump_ini src/ini_parser/iniparser.c /^void iniparser_dump_ini(dictionary * d, FILE * f)$/;" f 162 | iniparser_find_entry src/ini_parser/iniparser.c /^int iniparser_find_entry($/;" f 163 | iniparser_freedict src/ini_parser/iniparser.c /^void iniparser_freedict(dictionary * d)$/;" f 164 | iniparser_getboolean src/ini_parser/iniparser.c /^int iniparser_getboolean(dictionary * d, const char * key, int notfound)$/;" f 165 | iniparser_getdouble src/ini_parser/iniparser.c /^double iniparser_getdouble(dictionary * d, char * key, double notfound)$/;" f 166 | iniparser_getint src/ini_parser/iniparser.c /^int iniparser_getint(dictionary * d, const char * key, int notfound)$/;" f 167 | iniparser_getnsec src/ini_parser/iniparser.c /^int iniparser_getnsec(dictionary * d)$/;" f 168 | iniparser_getsecname src/ini_parser/iniparser.c /^char * iniparser_getsecname(dictionary * d, int n)$/;" f 169 | iniparser_getstr src/ini_parser/iniparser.h 41;" d 170 | iniparser_getstring src/ini_parser/iniparser.c /^char * iniparser_getstring(dictionary * d, const char * key, char * def)$/;" f 171 | iniparser_line src/ini_parser/iniparser.c /^static line_status iniparser_line($/;" f file: 172 | iniparser_load src/ini_parser/iniparser.c /^dictionary * iniparser_load(const char * ininame)$/;" f 173 | iniparser_set src/ini_parser/iniparser.c /^int iniparser_set(dictionary * ini, char * entry, char * val)$/;" f 174 | iniparser_setstr src/ini_parser/iniparser.h 42;" d 175 | iniparser_unset src/ini_parser/iniparser.c /^void iniparser_unset(dictionary * ini, char * entry)$/;" f 176 | init_dm src/sdl/sdl_dm.cc /^bool SDL_DM::init_dm ()$/;" f class:SDL_DM 177 | init_game src/main.cc /^void init_game()$/;" f 178 | init_new_node src/mem_manager/llist.h /^ Node *init_new_node()$/;" f class:LinkedList 179 | init_system src/main.cc /^void init_system(char *game_name)$/;" f 180 | initialized src/sdl/sdl_dm.h /^ bool initialized;$/;" m class:SDL_DM 181 | is_initialized src/sdl/sdl_dm.cc /^bool SDL_DM::is_initialized()$/;" f class:SDL_DM 182 | is_paused src/sdl/timer.cc /^bool Timer::is_paused()$/;" f class:Timer 183 | is_started src/sdl/timer.cc /^bool Timer::is_started()$/;" f class:Timer 184 | is_valid src/mem_manager/llist.h /^ bool is_valid()$/;" f class:LinkedList 185 | is_valid_position src/map.cc /^bool Map::is_valid_position(Point p)$/;" f class:Map 186 | key src/ini_parser/dictionary.h /^ char ** key ; \/** List of string keys *\/$/;" m struct:_dictionary_ 187 | last src/mem_manager/llist.h /^ Node *last;$/;" m class:LinkedList 188 | last_read_data src/helpers/file_helper.h /^ char *last_read_data;$/;" m class:File_helper 189 | level src/objects/object.h /^ int level;$/;" m class:Object 190 | life src/objects/object.h /^ int life;$/;" m class:Object 191 | line_status src/ini_parser/iniparser.c /^} line_status ;$/;" t typeref:enum:_line_status_ file: 192 | load_image src/sdl/sdl_dm.h 9;" d 193 | load_map src/map.cc /^bool Map::load_map(char *map_file)$/;" f class:Map 194 | main src/ini_parser/dictionary.c /^int main(int argc, char *argv[])$/;" f 195 | main src/main.cc /^int main (int argc, char *argv[])$/;" f 196 | map src/map.h /^ char *map;$/;" m class:Map 197 | map_height src/map.h /^ int map_height;$/;" m class:Map 198 | map_title src/map.h /^ char *map_title;$/;" m class:Map 199 | map_width src/map.h /^ int map_width;$/;" m class:Map 200 | mem_double src/ini_parser/dictionary.c /^static void * mem_double(void * ptr, int size)$/;" f file: 201 | message src/mem_manager/llist.h /^ virtual const char* message(int code) const throw()$/;" f class:Linked_list_exception 202 | move src/objects/object.cc /^void Object::move(Direction dir)$/;" f class:Object 203 | move src/objects/vehical.cc /^void Vehical::move(Direction dir)$/;" f class:Vehical 204 | move_down src/main.cc /^void move_down()$/;" f 205 | move_int src/objects/object.cc /^void Object::move_int(Direction dir)$/;" f class:Object 206 | move_left src/main.cc /^void move_left()$/;" f 207 | move_right src/main.cc /^void move_right()$/;" f 208 | move_up src/main.cc /^void move_up()$/;" f 209 | n src/ini_parser/dictionary.h /^ int n ; \/** Number of entries in dictionary *\/$/;" m struct:_dictionary_ 210 | next src/mem_manager/int_node.h /^ Int_node *next;$/;" m class:Int_node 211 | next src/mem_manager/llist.h /^ bool next()$/;" f class:LinkedList 212 | next src/mem_manager/string_node.h /^ String_node *next;$/;" m class:String_node 213 | next src/sdl/image.h /^ Image_node *next;$/;" m class:Image_node 214 | obj_id src/objects/object.h /^ int obj_id;$/;" m class:Object 215 | on_key_down src/sdl/event_management.cc /^void on_key_down()$/;" f 216 | pause src/sdl/timer.cc /^void Timer::pause()$/;" f class:Timer 217 | paused src/sdl/timer.h /^ bool paused;$/;" m class:Timer 218 | paused_ticks src/sdl/timer.h /^ int paused_ticks;$/;" m class:Timer 219 | pos_x src/objects/object.h /^ int pos_x;$/;" m class:Object 220 | pos_y src/objects/object.h /^ int pos_y;$/;" m class:Object 221 | prev src/mem_manager/int_node.h /^ Int_node *prev;$/;" m class:Int_node 222 | prev src/mem_manager/string_node.h /^ String_node *prev;$/;" m class:String_node 223 | prev src/sdl/image.h /^ Image_node *prev;$/;" m class:Image_node 224 | previous src/mem_manager/llist.h /^ bool previous()$/;" f class:LinkedList 225 | put_pixel src/sdl/sdl_dm.cc /^void SDL_DM::put_pixel(int x, int y, Uint32 pixel)$/;" f class:SDL_DM 226 | read_file src/helpers/file_helper.cc /^bool File_helper::read_file(char *fname=NULL)$/;" f class:File_helper 227 | redraw src/sdl/sdl_dm.cc /^void SDL_DM::redraw ()$/;" f class:SDL_DM 228 | remove src/mem_manager/llist.h /^ void remove(int index)$/;" f class:LinkedList 229 | reset src/mem_manager/llist.h /^ void reset()$/;" f class:LinkedList 230 | rewind src/mem_manager/llist.h /^ void rewind()$/;" f class:LinkedList 231 | scr_height src/sdl/sdl_dm.h /^ int scr_height;$/;" m class:SDL_DM 232 | scr_width src/sdl/sdl_dm.h /^ int scr_width;$/;" m class:SDL_DM 233 | sdl_event src/main.cc /^void sdl_event()$/;" f 234 | sdl_event src/sdl/event_management.cc /^void sdl_event()$/;" f 235 | sdm src/main.cc /^SDL_DM sdm;$/;" v 236 | search src/helpers/string_helper.cc /^char *String_helper::search(char *src, char search_key, char direction = 'f')$/;" f class:String_helper 237 | set_damage src/objects/object.cc /^void Object::set_damage(int val)$/;" f class:Object 238 | set_data src/mem_manager/int_node.h /^ void set_data(int d)$/;" f class:Int_node 239 | set_data src/mem_manager/string_node.h /^ void set_data(char *d=NULL)$/;" f class:String_node 240 | set_data src/sdl/image.h /^ void set_data(SDL_Surface *d)$/;" f class:Image_node 241 | set_display_color_bit src/sdl/sdl_dm.cc /^void SDL_DM::set_display_color_bit(int bit)$/;" f class:SDL_DM 242 | set_display_flags src/sdl/sdl_dm.cc /^void SDL_DM::set_display_flags(int flag)$/;" f class:SDL_DM 243 | set_level src/objects/object.cc /^void Object::set_level(int val)$/;" f class:Object 244 | set_life src/objects/object.cc /^void Object::set_life(int val)$/;" f class:Object 245 | set_obj_id src/objects/object.cc /^void Object::set_obj_id(int id)$/;" f class:Object 246 | set_position src/objects/object.cc /^void Object::set_position(int x, int y)$/;" f class:Object 247 | set_screen_size src/sdl/sdl_dm.cc /^void SDL_DM::set_screen_size(int sw, int sh)$/;" f class:SDL_DM 248 | set_size src/objects/object.cc /^void Object::set_size(int w,int h)$/;" f class:Object 249 | set_speed src/objects/object.cc /^void Object::set_speed(int spd)$/;" f class:Object 250 | set_top_speed src/objects/vehical.cc /^void Vehical::set_top_speed(int ts)$/;" f class:Vehical 251 | size src/ini_parser/dictionary.h /^ int size ; \/** Storage size *\/$/;" m struct:_dictionary_ 252 | speed src/objects/object.h /^ int speed;$/;" m class:Object 253 | split src/helpers/string_tokenizer.cc /^int String_tokenizer::split(char *string, char split_by=' ')$/;" f class:String_tokenizer 254 | start src/sdl/timer.cc /^void Timer::start()$/;" f class:Timer 255 | start_point src/map.h /^ Point start_point;$/;" m class:Map 256 | start_sdl src/main.cc /^bool start_sdl()$/;" f 257 | start_test src/tester.cc /^int start_test (int argc, char const* argv[])$/;" f 258 | start_ticks src/sdl/timer.h /^ int start_ticks;$/;" m class:Timer 259 | started src/sdl/timer.h /^ bool started;$/;" m class:Timer 260 | stop src/sdl/timer.cc /^void Timer::stop()$/;" f class:Timer 261 | string_helper src/map.h /^ String_helper string_helper;$/;" m class:Map 262 | string_list src/main.cc /^LinkedListstring_list;$/;" v 263 | strlwc src/ini_parser/iniparser.c /^static char * strlwc(const char * s)$/;" f file: 264 | strstrip src/ini_parser/iniparser.c /^static char * strstrip(char * s)$/;" f file: 265 | system_status src/main.cc /^int system_status = ALL_GOOD;$/;" v 266 | test_SDL src/tester.cc /^int test_SDL()$/;" f 267 | test_file_helper src/tester.cc /^void test_file_helper()$/;" f 268 | test_map src/tester.cc /^void test_map()$/;" f 269 | test_string_trimmer src/tester.cc /^void test_string_trimmer()$/;" f 270 | test_tokenizer src/tester.cc /^void test_tokenizer(char *test, char split_by=' ')$/;" f 271 | test_tokenizer_w_data src/tester.cc /^void test_tokenizer_w_data()$/;" f 272 | token_count src/helpers/string_tokenizer.h /^ int token_count;$/;" m class:String_tokenizer 273 | token_positions src/helpers/string_tokenizer.h /^ int *token_positions;$/;" m class:String_tokenizer 274 | tokenized_str src/helpers/string_tokenizer.h /^ char *tokenized_str;$/;" m class:String_tokenizer 275 | top_speed src/objects/vehical.h /^ int top_speed;$/;" m class:Vehical 276 | trim src/helpers/string_helper.cc /^void String_helper::trim(char *src, char trim_char)$/;" f class:String_helper 277 | trim_left src/helpers/string_helper.cc /^void String_helper::trim_left(char *src, char trim_char)$/;" f class:String_helper 278 | trim_right src/helpers/string_helper.cc /^void String_helper::trim_right(char *string, char trim_char)$/;" f class:String_helper 279 | unload_image src/sdl/sdl_dm.h 10;" d 280 | unpause src/sdl/timer.cc /^void Timer::unpause()$/;" f class:Timer 281 | update src/mem_manager/llist.h /^ bool update(int index, T data)$/;" f class:LinkedList 282 | val src/ini_parser/dictionary.h /^ char ** val ; \/** List of string values *\/$/;" m struct:_dictionary_ 283 | vc src/main.cc /^Vehical vc;$/;" v 284 | wbit src/sdl/sdl_dm.h /^ int wbit;$/;" m class:SDL_DM 285 | wflag src/sdl/sdl_dm.h /^ int wflag;$/;" m class:SDL_DM 286 | width src/objects/object.h /^ int width;$/;" m class:Object 287 | x src/point.h /^ int x;$/;" m struct:Point 288 | xstrdup src/ini_parser/dictionary.c /^static char * xstrdup(char * s)$/;" f file: 289 | y src/point.h /^ int y;$/;" m struct:Point 290 | ~File_helper src/helpers/file_helper.cc /^File_helper::~File_helper()$/;" f class:File_helper 291 | ~Image_node src/sdl/image.h /^ ~Image_node()$/;" f class:Image_node 292 | ~Int_node src/mem_manager/int_node.h /^ ~Int_node()$/;" f class:Int_node 293 | ~LinkedList src/mem_manager/llist.h /^ virtual ~LinkedList()$/;" f class:LinkedList 294 | ~Map src/map.cc /^Map::~Map()$/;" f class:Map 295 | ~SDL_DM src/sdl/sdl_dm.cc /^SDL_DM::~SDL_DM()$/;" f class:SDL_DM 296 | ~String_node src/mem_manager/string_node.h /^ ~String_node()$/;" f class:String_node 297 | ~String_tokenizer src/helpers/string_tokenizer.cc /^String_tokenizer::~String_tokenizer()$/;" f class:String_tokenizer 298 | --------------------------------------------------------------------------------