Debian Codegraph @

src/lisp/lisp.cpp

raw symbols ◀ ▶ SCIP
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 #include <cstdio>
23
24 namespace lisp
25 {
26
27 Lisp::Lisp(LispType newtype)
28 : m_type(newtype)
29 {}
30
31 //-----------------------------------------------------------------------------
32
33 Lisp::~Lisp()
34 {
35 if(m_type == TYPE_SYMBOL || m_type == TYPE_STRING)
36 delete[] m_v.m_string;
37 if(m_type == TYPE_CONS)
38 {
39 delete m_v.m_cons.m_cdr;
40 delete m_v.m_cons.m_car;
41 }
42 }
43
44 //-----------------------------------------------------------------------------
45
46 const Lisp*
47 Lisp::getLisp(const char* name) const
48 {
49 const Lisp* P;
50
51 for(P = getCdr(); P != 0; P = P->getCdr())
52 {
53 const Lisp* CHILD = P->getCar();
54 // Also ignore if the child is not a CONS type, i.e.
55 // a TYPE_INTEGER is found, for which car is not defined!
56 if(!CHILD || CHILD->m_type!=TYPE_CONS)
57 continue;
58 if(!CHILD->getCar())
59 continue;
60 std::string CHILDName;
61 if(!CHILD->getCar()->get(CHILDName))
62 continue;
63 if(CHILDName == name)
64 return CHILD;
65 }
66
67 return 0;
68 }
69
70 //-----------------------------------------------------------------------------
71
72 //FIXME: is the boolean handled by this function? should the argument be
73 //removed?
74 void
75 Lisp::print(int ) const
76 {
77 if(m_type == TYPE_CONS)
78 {
79 printf("(");
80 if(m_v.m_cons.m_car)
81 m_v.m_cons.m_car->print();
82 if(m_v.m_cons.m_cdr)
83 {
84 printf(",");
85 if(m_v.m_cons.m_cdr)
86 m_v.m_cons.m_cdr->print();
87 }
88 printf(")");
89 }
90 if(m_type == TYPE_STRING)
91 {
92 printf("'%s' ", m_v.m_string);
93 }
94 if(m_type == TYPE_INTEGER)
95 {
96 printf("%d", m_v.m_integer);
97 }
98 if(m_type == TYPE_REAL)
99 {
100 printf("%f", m_v.m_real);
101 }
102 if(m_type == TYPE_SYMBOL)
103 {
104 printf("%s ", m_v.m_string);
105 }
106 }
107
108 } // end of namespace lisp