diff options
Diffstat (limited to 'src/lang/env.h')
| -rw-r--r-- | src/lang/env.h | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/src/lang/env.h b/src/lang/env.h new file mode 100644 index 0000000..1313d18 --- /dev/null +++ b/src/lang/env.h | |||
| @@ -0,0 +1,156 @@ | |||
| 1 | /************************************************************************* | ||
| 2 | * | ||
| 3 | * HTCd - Copyright (C) 1998-2006 Henrik Rydberg | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 18 | */ | ||
| 19 | |||
| 20 | #ifndef ENVH | ||
| 21 | #define ENVH | ||
| 22 | |||
| 23 | #include <lang/token.h> | ||
| 24 | |||
| 25 | mstring Random(int n); | ||
| 26 | |||
| 27 | const int OP_PARSE=8; | ||
| 28 | const mstring para_def="\n"; | ||
| 29 | |||
| 30 | //////////////////////////////////////////////////////////////////// | ||
| 31 | |||
| 32 | struct Lang { | ||
| 33 | volatile int running; | ||
| 34 | opmap ops; | ||
| 35 | tokmap toks; | ||
| 36 | Lang(); | ||
| 37 | virtual ~Lang() {} | ||
| 38 | }; | ||
| 39 | |||
| 40 | struct req_env { | ||
| 41 | Lang* glob; | ||
| 42 | tokmap toks; | ||
| 43 | mstring uri; | ||
| 44 | int lang; | ||
| 45 | volatile int* running; | ||
| 46 | |||
| 47 | int is_running() const { return glob->running&&(!running||*running); } | ||
| 48 | |||
| 49 | req_env(Lang& g,tokmap& p) : glob(&g),toks(p),uri(),lang(0),running(0) {} | ||
| 50 | virtual ~req_env() {} | ||
| 51 | }; | ||
| 52 | |||
| 53 | //////////////////////////////////////////////////////////////////// | ||
| 54 | |||
| 55 | struct Env : public op_env { | ||
| 56 | typedef mrvec<expr_t*> xpile; | ||
| 57 | typedef tokmap::iterator iterator; | ||
| 58 | typedef tokmap::const_iterator const_iterator; | ||
| 59 | |||
| 60 | Env(opmap& op,req_env& r,unsigned m): | ||
| 61 | op_env(op),req(&r),toks(&r.toks),up(0),mod(m), | ||
| 62 | loc(),db(0),dbat(0),pwd(r.uri),para(para_def),args(0) {} | ||
| 63 | |||
| 64 | Env(Env& p,tokmap& tok,const sref& cwd): | ||
| 65 | op_env(p),req(p.req),toks(&tok),up(p.up),mod(p.mod), | ||
| 66 | loc(p.loc),db(0),dbat(0),pwd(cwd),para(p.para),args(0) {} | ||
| 67 | Env(Env& p,unsigned m,const sref& cwd): | ||
| 68 | op_env(p),req(p.req),toks(p.toks),up(p.up),mod(m), | ||
| 69 | loc(p.loc),db(0),dbat(0),pwd(cwd),para(p.para),args(0) {} | ||
| 70 | |||
| 71 | Env(Env& p): | ||
| 72 | op_env(p),req(p.req),toks(p.toks),up(p.up),mod(p.mod), | ||
| 73 | loc(p.loc),db(p.db),dbat(p.dbat),pwd(p.pwd),para(p.para),args(0) {} | ||
| 74 | Env(Env& p,dbmap& dbm): | ||
| 75 | op_env(p),req(p.req),toks(p.toks),up(p.up),mod(p.mod), | ||
| 76 | loc(p.loc),db(&dbm),dbat(0),pwd(p.pwd),para(p.para),args(0) {} | ||
| 77 | Env(Env& p,opmap& op): | ||
| 78 | op_env(op),req(p.req),toks(p.toks),up(p.up),mod(p.mod), | ||
| 79 | loc(p.loc),db(p.db),dbat(p.dbat),pwd(p.pwd),para(p.para),args(0) {} | ||
| 80 | |||
| 81 | ~Env() { clear_args(); } | ||
| 82 | |||
| 83 | int is_clear(const tok_t* tok) const { return tok&&tok->is_clear(mod); } | ||
| 84 | unsigned tight() const { return tok_t::tight(mod); } | ||
| 85 | |||
| 86 | int check_arg(const runnable_t& ftok) const; | ||
| 87 | int is_arg(const sref& t) const { return cset_digit.test(t.front()); } | ||
| 88 | |||
| 89 | int xsize() const { return xarg.size(); } | ||
| 90 | int rsize() const { return rarg.size(); } | ||
| 91 | |||
| 92 | void xpush(const sref& in) throw(merror_t); | ||
| 93 | void rpush(const sref& in) throw(merror_t); | ||
| 94 | void clear_args(); | ||
| 95 | |||
| 96 | void parg(mstream& out,int n) throw(merror_t); | ||
| 97 | void parg(mstring& buf,int n) throw(merror_t); | ||
| 98 | mstring parg(int n) throw(merror_t); | ||
| 99 | |||
| 100 | const sref& operator[](int m) const throw(merror_t); | ||
| 101 | expr_t* arg(int m) throw(merror_t); | ||
| 102 | |||
| 103 | const sref glob(const sref& t) const throw(merror_t); | ||
| 104 | |||
| 105 | int glob_find(const sref& t) const; | ||
| 106 | void glob_list(rpile& list,const sref& t) const; | ||
| 107 | void glob_adb(const sref& fx,const sref& t) throw(merror_t); | ||
| 108 | |||
| 109 | const sref aloc(const sref& t,const sref& v) throw(merror_t); | ||
| 110 | const sref sloc(const sref& t,const sref& v) throw(merror_t); | ||
| 111 | const sref gloc(const sref& t) const throw(merror_t); | ||
| 112 | |||
| 113 | int gloc_find(const sref& t) const; | ||
| 114 | void gloc_list(rpile& list,const sref& t) const; | ||
| 115 | void gloc_adb(const sref& fx,const sref& t) throw(merror_t); | ||
| 116 | |||
| 117 | int onarg(int m) const; | ||
| 118 | int onglob(const sref& s) const; | ||
| 119 | int onloc(const sref& s) const; | ||
| 120 | |||
| 121 | void parse(mstream& out,const sref& in) throw(merror_t); | ||
| 122 | void expr(mstream& out,const sref& in) throw(merror_t); | ||
| 123 | void parse(mstream& out,expr_t* x) throw(merror_t); | ||
| 124 | |||
| 125 | void eval(mstream& out,const sref& in,int child) throw(merror_t); | ||
| 126 | void eval(mstream& out,expr_t* x,int child) throw(merror_t); | ||
| 127 | void eval(mstream& out,runnable_t* ftok,int child) throw(merror_t); | ||
| 128 | |||
| 129 | int split(sref& first,sref& rest) throw(merror_t); | ||
| 130 | void term(mstream& out,expr_t* x) throw(merror_t); | ||
| 131 | |||
| 132 | mstring URI(const sref& raw); | ||
| 133 | |||
| 134 | Env *up; | ||
| 135 | req_env* req; | ||
| 136 | tokmap* toks; | ||
| 137 | int mod,dbat; | ||
| 138 | tokmap loc; | ||
| 139 | dbmap* db; | ||
| 140 | mstring pwd,para,epilog; | ||
| 141 | int args; | ||
| 142 | xpile xarg,rarg; | ||
| 143 | }; | ||
| 144 | |||
| 145 | ///////////////////////////////////////////////////////////////////// | ||
| 146 | |||
| 147 | struct latex_env : public Env { | ||
| 148 | latex_env(Env& p); | ||
| 149 | |||
| 150 | int split(sref& first,sref& rest) throw(merror_t); | ||
| 151 | void term(mstream& out,expr_t* x) throw(merror_t); | ||
| 152 | }; | ||
| 153 | |||
| 154 | ///////////////////////////////////////////////////////////////////// | ||
| 155 | |||
| 156 | #endif | ||
