This machine mirrors various open-source projects.
20 Gbit/s uplink.
If there are any issues or you want another project mirrored, please contact
mirror-service -=AT=- netcologne DOT de !
00001 // $Id: lisp_reader.cxx,v 1.5 2002/12/28 00:19:53 grumbel Exp $ 00002 // 00003 // Construo - A wire-frame construction game 00004 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de> 00005 // 00006 // This program is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU General Public License 00008 // as published by the Free Software Foundation; either version 2 00009 // of the License, or (at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 #include "construo_error.hxx" 00021 #include "lisp_reader.hxx" 00022 00023 LispReader::LispReader (lisp_object_t* l) 00024 : lst (l) 00025 { 00026 //std::cout << "LispReader: " << std::flush; 00027 //lisp_dump(lst, stdout); 00028 //std::cout << std::endl; 00029 } 00030 00031 lisp_object_t* 00032 LispReader::search_for(const char* name) 00033 { 00034 //std::cout << "LispReader::search_for(" << name << ")" << std::endl; 00035 lisp_object_t* cursor = lst; 00036 00037 while(!lisp_nil_p(cursor)) 00038 { 00039 lisp_object_t* cur = lisp_car(cursor); 00040 00041 if (!lisp_cons_p(cur) || !lisp_symbol_p (lisp_car(cur))) 00042 { 00043 lisp_dump(cur, stdout); 00044 throw ConstruoError (std::string("LispReader: Read error in search_for ") + name); 00045 } 00046 else 00047 { 00048 if (strcmp(lisp_symbol(lisp_car(cur)), name) == 0) 00049 { 00050 return lisp_cdr(cur); 00051 } 00052 } 00053 00054 cursor = lisp_cdr (cursor); 00055 } 00056 return 0; 00057 } 00058 00059 bool 00060 LispReader::read_vector (const char* name, Vector2d* vec) 00061 { 00062 lisp_object_t* obj = search_for (name); 00063 if (obj) 00064 { 00065 vec->x = lisp_real(lisp_car(obj)); 00066 vec->y = lisp_real(lisp_car(lisp_cdr(obj))); 00067 return true; 00068 } 00069 return false; 00070 } 00071 00072 bool 00073 LispReader::read_int (const char* name, int* i) 00074 { 00075 lisp_object_t* obj = search_for (name); 00076 if (obj) 00077 { 00078 *i = lisp_integer(lisp_car(obj)); 00079 return true; 00080 } 00081 return false; 00082 } 00083 00084 bool 00085 LispReader::read_float (const char* name, float* f) 00086 { 00087 lisp_object_t* obj = search_for (name); 00088 if (obj) 00089 { 00090 *f = lisp_real(lisp_car(obj)); 00091 return true; 00092 } 00093 return false; 00094 } 00095 00096 bool 00097 LispReader::read_bool (const char* name, bool* b) 00098 { 00099 lisp_object_t* obj = search_for (name); 00100 if (obj) 00101 { 00102 *b = lisp_boolean(lisp_car(obj)); 00103 return true; 00104 } 00105 return false; 00106 } 00107 00108 /* EOF */