/************************************************************************* * * 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 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 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