1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
/*************************************************************************
*
* HTCd - Copyright (C) 1998-2006 Henrik Rydberg
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef TOKENH
#define TOKENH
#include <ops/express.h>
#include <hdb/db.h>
#define TOK_ARGS (mstream& out,Env& env)
#define TOK_IMPL(func) static void impl_##func TOK_ARGS throw(merror_t)
#define TOK_ADD(func,a,mod,help) \
T.add(new binary_t(uscore2dot(#func),sref(help),mod,sref(a),impl_##func),0,1)
mstring uscore2dot(const char* s);
class Env;
typedef void (*s_func_t)TOK_ARGS;
class tok_t {
public:
static const unsigned CONSTANT,RESTRICT,NORMAL,SYSONLY,INIT;
static const unsigned RUNNABLE,FUNCTION,BINARY;
static const unsigned REFERENCE,DBREF,CRON;
static const unsigned PRIVATE,PUBLIC,XMODES;
static inline unsigned tight(unsigned xmod) {
// INIT is ignored here simply because no mode can
// read variables in INIT mode... defaults to public.
return (xmod&SYSONLY)?SYSONLY:(xmod&NORMAL)?PRIVATE:PUBLIC;
}
mstring name,body;
unsigned mod;
int is_clear(int xmod) const { return (mod&xmod)!=0; }
int is_replaceable(const tok_t& t) const { return (mod&t.mod)==t.mod; }
int is_const() const { return (mod&CONSTANT)!=0; }
int is_runnable() const { return (mod&RUNNABLE)!=0; }
int is_func() const { return (mod&FUNCTION)!=0; }
int is_cron() const { return (mod&CRON)!=0; }
int is_binary() const { return (mod&BINARY)!=0; }
int is_reference() const { return (mod&REFERENCE)!=0; }
int is_dbref() const { return (mod&DBREF)!=0; }
tok_t(const sref& s,const sref& b,unsigned m) : name(s),body(b),mod(m) {}
virtual ~tok_t();
static void* operator new(size_t n);
static void operator delete(void* p);
private:
static uniheap<32> tree;
};
///////////////////////////////////////////////////////////////////
class reference_t : public tok_t {
public:
mstring data;
reference_t(const sref& s,const sref& b,unsigned m):
tok_t(s,b,m|REFERENCE|CONSTANT) {}
static void* operator new(size_t n);
static void operator delete(void* p);
private:
static uniheap<44> tree;
};
///////////////////////////////////////////////////////////////////
class dbref_t : public tok_t {
public:
dbmap db;
dbref_t(const sref& s,const sref& b,unsigned m):
tok_t(s,b,m|DBREF|CONSTANT) {}
static void* operator new(size_t n);
static void operator delete(void* p);
private:
static uniheap<96> tree;
};
///////////////////////////////////////////////////////////////////
class runnable_t : public tok_t {
public:
mstring arg;
runnable_t(const sref& s,const sref& b,unsigned m,const sref& a):
tok_t(s,b,m|RUNNABLE|CONSTANT),arg(a) {}
static void* operator new(size_t n);
static void operator delete(void* p);
private:
static uniheap<44> tree;
};
///////////////////////////////////////////////////////////////////
class func_t : public runnable_t {
public:
expr_t x;
func_t(const sref& s,const sref& b,unsigned m,const sref& a):
runnable_t(s,b,m|FUNCTION,a) { x=body; }
static void* operator new(size_t n);
static void operator delete(void* p);
private:
static uniheap<80> tree;
};
///////////////////////////////////////////////////////////////////
class cron_t : public func_t {
public:
int last,interval;
cron_t(const sref& s,const sref& b,unsigned m,int i):
func_t(s,b,m|CRON,ms_empty),last(0),interval(i) {}
static void* operator new(size_t n);
static void operator delete(void* p);
private:
static uniheap<88> tree;
};
///////////////////////////////////////////////////////////////////
class binary_t : public runnable_t {
public:
s_func_t func;
binary_t(const sref& s,const sref& b,unsigned m,const sref& a,s_func_t f):
runnable_t(s,b,m|BINARY,a),func(f) {}
static void* operator new(size_t n);
static void operator delete(void* p);
private:
static uniheap<48> tree;
};
///////////////////////////////////////////////////////////////////
mstream& operator<<(mstream&,const runnable_t& ftok);
mstring Mode(const tok_t& tok);
mstring Desc(const tok_t& tok);
///////////////////////////////////////////////////////////////////
struct tokmap {
typedef tok_t* val_t;
typedef mrvec<val_t> map_t;
typedef map_t::iterator iterator;
typedef map_t::const_iterator const_iterator;
struct comp_t {
sref key;
comp_t(const sref& skey) : key(skey) {}
bool operator()(val_t a,val_t b) const {
return (a?((const sref&)a->name):key)<(b?((const sref&)b->name):key);
}
};
tokmap* up;
map_t list;
tokmap() : up(0),list() {}
tokmap(tokmap& p) : up(&p),list() {}
~tokmap() { clear(); }
iterator begin() { return list.begin(); }
const_iterator begin() const { return list.begin(); }
iterator end() { return list.end(); }
const_iterator end() const { return list.end(); }
void clear();
iterator erase(iterator p) { delete *p; return list.erase(p); }
tok_t* get_this(const sref& t);
const tok_t* get_this(const sref& t) const;
const tok_t* get(const sref& t) const;
tok_t* get(const sref& t);
tok_t* set(tok_t* tok,int replace,int force) throw(merror_t);
tok_t* add(tok_t* tok,int replace,int force) throw(merror_t);
};
///////////////////////////////////////////////////////////////////
int is_tokname(const sref& s);
int is_arglist(const sref& s);
tok_t* Cond(tokmap& map,const sref& s,const sref& b,unsigned m) throw(merror_t);
tok_t* Global(tokmap& map,const sref& s,const sref& b,unsigned m,int rpl=0) throw(merror_t);
tok_t* Const(tokmap& map,const sref& s,const sref& b,unsigned m,int rpl=0) throw(merror_t);
func_t* Func(tokmap& map,const sref& s,const sref& b,
unsigned m,const sref& a,int rpl=0) throw(merror_t);
cron_t* Cron(tokmap& map,const sref& s,const sref& b,
unsigned m,int i,int rpl=0) throw(merror_t);
binary_t* Binary(tokmap& map,const sref& s,const sref& b,
unsigned m,const sref& a,s_func_t f,int rpl=0) throw(merror_t);
reference_t* Reference(tokmap& map,const sref& s,const sref& b,
unsigned m,int rpl=0) throw(merror_t);
dbref_t* DBRef(tokmap& map,const sref& s,
const sref& b,unsigned m,int rpl=0) throw(merror_t);
void ClearToken(tokmap& map,const sref& s) throw(merror_t);
///////////////////////////////////////////////////////////////////
const int XPUBLIC=tok_t::RESTRICT;
const int XPRIVATE=XPUBLIC|tok_t::NORMAL;
const int XSYSTEM=XPRIVATE|tok_t::SYSONLY;
const int XINIT=tok_t::INIT;
#endif
|