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
|
/*************************************************************************
*
* 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 ENVH
#define ENVH
#include <lang/token.h>
mstring Random(int n);
const int OP_PARSE=8;
const mstring para_def="\n";
////////////////////////////////////////////////////////////////////
struct Lang {
volatile int running;
opmap ops;
tokmap toks;
Lang();
virtual ~Lang() {}
};
struct req_env {
Lang* glob;
tokmap toks;
mstring uri;
int lang;
volatile int* running;
int is_running() const { return glob->running&&(!running||*running); }
req_env(Lang& g,tokmap& p) : glob(&g),toks(p),uri(),lang(0),running(0) {}
virtual ~req_env() {}
};
////////////////////////////////////////////////////////////////////
struct Env : public op_env {
typedef mrvec<expr_t*> xpile;
typedef tokmap::iterator iterator;
typedef tokmap::const_iterator const_iterator;
Env(opmap& op,req_env& r,unsigned m):
op_env(op),req(&r),toks(&r.toks),up(0),mod(m),
loc(),db(0),dbat(0),pwd(r.uri),para(para_def),args(0) {}
Env(Env& p,tokmap& tok,const sref& cwd):
op_env(p),req(p.req),toks(&tok),up(p.up),mod(p.mod),
loc(p.loc),db(0),dbat(0),pwd(cwd),para(p.para),args(0) {}
Env(Env& p,unsigned m,const sref& cwd):
op_env(p),req(p.req),toks(p.toks),up(p.up),mod(m),
loc(p.loc),db(0),dbat(0),pwd(cwd),para(p.para),args(0) {}
Env(Env& p):
op_env(p),req(p.req),toks(p.toks),up(p.up),mod(p.mod),
loc(p.loc),db(p.db),dbat(p.dbat),pwd(p.pwd),para(p.para),args(0) {}
Env(Env& p,dbmap& dbm):
op_env(p),req(p.req),toks(p.toks),up(p.up),mod(p.mod),
loc(p.loc),db(&dbm),dbat(0),pwd(p.pwd),para(p.para),args(0) {}
Env(Env& p,opmap& op):
op_env(op),req(p.req),toks(p.toks),up(p.up),mod(p.mod),
loc(p.loc),db(p.db),dbat(p.dbat),pwd(p.pwd),para(p.para),args(0) {}
~Env() { clear_args(); }
int is_clear(const tok_t* tok) const { return tok&&tok->is_clear(mod); }
unsigned tight() const { return tok_t::tight(mod); }
int check_arg(const runnable_t& ftok) const;
int is_arg(const sref& t) const { return cset_digit.test(t.front()); }
int xsize() const { return xarg.size(); }
int rsize() const { return rarg.size(); }
void xpush(const sref& in) throw(merror_t);
void rpush(const sref& in) throw(merror_t);
void clear_args();
void parg(mstream& out,int n) throw(merror_t);
void parg(mstring& buf,int n) throw(merror_t);
mstring parg(int n) throw(merror_t);
const sref& operator[](int m) const throw(merror_t);
expr_t* arg(int m) throw(merror_t);
const sref glob(const sref& t) const throw(merror_t);
int glob_find(const sref& t) const;
void glob_list(rpile& list,const sref& t) const;
void glob_adb(const sref& fx,const sref& t) throw(merror_t);
const sref aloc(const sref& t,const sref& v) throw(merror_t);
const sref sloc(const sref& t,const sref& v) throw(merror_t);
const sref gloc(const sref& t) const throw(merror_t);
int gloc_find(const sref& t) const;
void gloc_list(rpile& list,const sref& t) const;
void gloc_adb(const sref& fx,const sref& t) throw(merror_t);
int onarg(int m) const;
int onglob(const sref& s) const;
int onloc(const sref& s) const;
void parse(mstream& out,const sref& in) throw(merror_t);
void expr(mstream& out,const sref& in) throw(merror_t);
void parse(mstream& out,expr_t* x) throw(merror_t);
void eval(mstream& out,const sref& in,int child) throw(merror_t);
void eval(mstream& out,expr_t* x,int child) throw(merror_t);
void eval(mstream& out,runnable_t* ftok,int child) throw(merror_t);
int split(sref& first,sref& rest) throw(merror_t);
void term(mstream& out,expr_t* x) throw(merror_t);
mstring URI(const sref& raw);
Env *up;
req_env* req;
tokmap* toks;
int mod,dbat;
tokmap loc;
dbmap* db;
mstring pwd,para,epilog;
int args;
xpile xarg,rarg;
};
/////////////////////////////////////////////////////////////////////
struct latex_env : public Env {
latex_env(Env& p);
int split(sref& first,sref& rest) throw(merror_t);
void term(mstream& out,expr_t* x) throw(merror_t);
};
/////////////////////////////////////////////////////////////////////
#endif
|