1 /** 2 * @file lispreader.h 3 * @brief Parse configuration file 4 * @created 2007-06-15 5 * @date 2014-07-27 6 * @author Mark Probst 7 * @author Ingo Ruhnke <grumbel@gmx.de> 8 * @author Bruno Ethvignot <bruno at tlk dot biz> 9 */ 10 /* 11 * copyright (c) 1998-2000 Mark Probst 12 * copyright (c) 2002 Ingo Ruhnke <grumbel@gmx.de> 13 * copyright (c) 2007-2014 TLK Games all rights reserved 14 * $Id: lispreader.h 19 2014-07-27 18:03:48Z bruno.ethvignot@gmail.com $ 15 * 16 * Powermanga is free software; you can redistribute it and/or modify 17 * it under the terms of the GNU General Public License as published by 18 * the Free Software Foundation; either version 3 of the License, or 19 * (at your option) any later version. 20 * 21 * Powermanga is distributed in the hope that it will be useful, but 22 * WITHOUT ANY WARRANTY; without even the implied warranty of 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 * GNU General Public License for more details. 25 * 26 * You should have received a copy of the GNU General Public License 27 * along with this program; if not, write to the Free Software 28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 29 * MA 02110-1301, USA. 30 */ 31 #ifndef __LISPREADER__ 32 #define __LISPREADER__ 33 class lispreader; 34 #include "../include/tecnoballz.h" 35 36 typedef enum 37 { 38 LISP_TYPE_INTERNAL = -3, 39 LISP_TYPE_PARSE_ERROR = -2, 40 LISP_TYPE_EOF = -1, 41 LISP_TYPE_NIL = 0, 42 LISP_TYPE_SYMBOL, 43 LISP_TYPE_INTEGER, 44 LISP_TYPE_STRING, 45 LISP_TYPE_REAL, 46 LISP_TYPE_CONS, 47 LISP_TYPE_PATTERN_CONS, 48 LISP_TYPE_BOOLEAN, 49 LISP_TYPE_PATTERN_VAR 50 } LISP_TYPE_ENUM; 51 52 typedef struct 53 { 54 Sint32 type; 55 union 56 { 57 FILE *file; 58 struct 59 { 60 char *buf; 61 Sint32 pos; 62 } 63 string; 64 struct 65 { 66 void *data; 67 Sint32 (*next_char) (void *data); 68 void (*unget_char) (char c, void *data); 69 } 70 any; 71 } v; 72 } 73 lisp_stream_t; 74 75 typedef struct _lisp_object_t lisp_object_t; 76 struct _lisp_object_t 77 { 78 Sint32 type; 79 union 80 { 81 struct 82 { 83 struct _lisp_object_t *car; 84 struct _lisp_object_t *cdr; 85 } 86 cons; 87 char *string; 88 Sint32 integer; 89 float real; 90 struct 91 { 92 Sint32 type; 93 Sint32 index; 94 struct _lisp_object_t *sub; 95 } 96 pattern; 97 } v; 98 }; 99 100 class lispreader:public virtual tecnoballz 101 { 102 public: 103 lispreader (); 104 ~lispreader (); 105 bool read_int (const char *name, Sint32 * i); 106 bool read_bool (const char *name, bool * b); 107 bool lisp_read_string (const char *name, char **str); 108 bool read_string (const char *name, std::string* str); 109 lisp_object_t *lisp_read_file (std::string filename); 110 char *lisp_symbol (lisp_object_t * obj); 111 lisp_object_t *lisp_car (lisp_object_t * obj); 112 lisp_object_t *lisp_cdr (lisp_object_t * obj); 113 void lisp_free (lisp_object_t * obj); 114 private: 115 lisp_object_t *root_obj; 116 lisp_object_t* lst; 117 void _token_clear (void); 118 void token_append (char c); 119 void _token_append (char c); 120 Sint32 _next_char (lisp_stream_t * stream); 121 void _unget_char (char c, lisp_stream_t * stream); 122 Sint32 _scan (lisp_stream_t * stream); 123 lisp_object_t * lisp_object_alloc (Sint32 type); 124 lisp_stream_t * lisp_stream_init_string (lisp_stream_t * stream, char *buf); 125 lisp_object_t * lisp_make_integer (Sint32 value); 126 lisp_object_t * lisp_make_real (float value); 127 lisp_object_t * lisp_make_symbol (const char *value); 128 lisp_object_t * lisp_make_string (const char *value); 129 lisp_object_t * lisp_make_cons (lisp_object_t * car, lisp_object_t * cdr); 130 lisp_object_t * lisp_make_boolean (Sint32 value); 131 lisp_object_t * lisp_make_pattern_cons (lisp_object_t * car, lisp_object_t * cdr); 132 lisp_object_t *lisp_read (lisp_stream_t * in); 133 Sint32 lisp_type (lisp_object_t * obj); 134 Sint32 lisp_integer (lisp_object_t * obj); 135 char * lisp_string (lisp_object_t * obj); 136 Sint32 lisp_boolean (lisp_object_t * obj); 137 lisp_object_t * search_for (const char *name); 138 void lisp_dump (lisp_object_t * obj, FILE * out); 139 float lisp_real (lisp_object_t * obj); 140 141 142 143 144 145 146 }; 147 148 #endif 149