Rebuild autotool system
[construo.git] / lisp_reader.cxx
blob421619a501f4cf94f87e13642576e50a21eca505
1 // $Id: lisp_reader.cxx,v 1.5 2002/12/28 00:19:53 grumbel Exp $
2 //
3 // Construo - A wire-frame construction game
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "construo_error.hxx"
21 #include "lisp_reader.hxx"
22 #include <string.h>
24 LispReader::LispReader (lisp_object_t* l)
25 : lst (l)
27 //std::cout << "LispReader: " << std::flush;
28 //lisp_dump(lst, stdout);
29 //std::cout << std::endl;
32 lisp_object_t*
33 LispReader::search_for(const char* name)
35 //std::cout << "LispReader::search_for(" << name << ")" << std::endl;
36 lisp_object_t* cursor = lst;
38 while(!lisp_nil_p(cursor))
40 lisp_object_t* cur = lisp_car(cursor);
42 if (!lisp_cons_p(cur) || !lisp_symbol_p (lisp_car(cur)))
44 lisp_dump(cur, stdout);
45 throw ConstruoError (std::string("LispReader: Read error in search_for ") + name);
47 else
49 if (strcmp(lisp_symbol(lisp_car(cur)), name) == 0)
51 return lisp_cdr(cur);
55 cursor = lisp_cdr (cursor);
57 return 0;
60 bool
61 LispReader::read_vector (const char* name, Vector2d* vec)
63 lisp_object_t* obj = search_for (name);
64 if (obj)
66 vec->x = lisp_real(lisp_car(obj));
67 vec->y = lisp_real(lisp_car(lisp_cdr(obj)));
68 return true;
70 return false;
73 bool
74 LispReader::read_int (const char* name, int* i)
76 lisp_object_t* obj = search_for (name);
77 if (obj)
79 *i = lisp_integer(lisp_car(obj));
80 return true;
82 return false;
85 bool
86 LispReader::read_float (const char* name, float* f)
88 lisp_object_t* obj = search_for (name);
89 if (obj)
91 *f = lisp_real(lisp_car(obj));
92 return true;
94 return false;
97 bool
98 LispReader::read_bool (const char* name, bool* b)
100 lisp_object_t* obj = search_for (name);
101 if (obj)
103 *b = lisp_boolean(lisp_car(obj));
104 return true;
106 return false;
109 /* EOF */