Debian Codegraph @

src/lisp/lisp.cpp

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 // $Id: lisp.cpp 1024 2007-04-30 14:25:32Z hiker $
2 //
3 // TuxKart - a fun racing game with go-kart
4 // Copyright (C) 2004 Matthias Braun <[email protected]>
5 // code in this file based on lispreader from Mark Probst
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "lisp.hpp"
21
22 namespace lisp
23 {
24
25 Lisp::Lisp(LispType newtype)
26 : m_type(newtype)
27 {}
28
29 //-----------------------------------------------------------------------------
30
31 Lisp::~Lisp()
32 {
33 if(m_type == TYPE_SYMBOL || m_type == TYPE_STRING)
34 delete[] m_v.m_string;
35 if(m_type == TYPE_CONS)
36 {
37 delete m_v.m_cons.m_cdr;
38 delete m_v.m_cons.m_car;
39 }
40 }
41
42 //-----------------------------------------------------------------------------
43
44 const Lisp*
45 Lisp::getLisp(const char* name) const
46 {
47 const Lisp* P;
48
49 for(P = getCdr(); P != 0; P = P->getCdr())
50 {
51 const Lisp* CHILD = P->getCar();
52 // Also ignore if the child is not a CONS type, i.e.
53 // a TYPE_INTEGER is found, for which car is not defined!
54 if(!CHILD || CHILD->m_type!=TYPE_CONS)
55 continue;
56 if(!CHILD->getCar())
57 continue;
58 std::string CHILDName;
59 if(!CHILD->getCar()->get(CHILDName))
60 continue;
61 if(CHILDName == name)
62 return CHILD;
63 }
64
65 return 0;
66 }
67
68 //-----------------------------------------------------------------------------
69
70 //FIXME: is the boolean handled by this function? should the argument be
71 //removed?
72 void
73 Lisp::print(int ) const
74 {
75 if(m_type == TYPE_CONS)
76 {
77 printf("(");
78 if(m_v.m_cons.m_car)
79 m_v.m_cons.m_car->print();
80 if(m_v.m_cons.m_cdr)
81 {
82 printf(",");
83 if(m_v.m_cons.m_cdr)
84 m_v.m_cons.m_cdr->print();
85 }
86 printf(")");
87 }
88 if(m_type == TYPE_STRING)
89 {
90 printf("'%s' ", m_v.m_string);
91 }
92 if(m_type == TYPE_INTEGER)
93 {
94 printf("%d", m_v.m_integer);
95 }
96 if(m_type == TYPE_REAL)
97 {
98 printf("%f", m_v.m_real);
99 }
100 if(m_type == TYPE_SYMBOL)
101 {
102 printf("%s ", m_v.m_string);
103 }
104 }
105
106 } // end of namespace lisp