From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/lang/basic.cc | 315 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 315 insertions(+) create mode 100644 src/lang/basic.cc (limited to 'src/lang/basic.cc') diff --git a/src/lang/basic.cc b/src/lang/basic.cc new file mode 100644 index 0000000..54d16a9 --- /dev/null +++ b/src/lang/basic.cc @@ -0,0 +1,315 @@ +/************************************************************************* + * + * 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 + */ + +#include + +/////////////////////////////////////////////////// + +TOK_IMPL(asis) { out<expr; } +TOK_IMPL(mute) {} +TOK_IMPL(comment) {} + +/////////////////////////////////////////////////// + +TOK_IMPL(cond) { + Cond(*env.toks,env[0],env[1],tok_t::PUBLIC); +} +TOK_IMPL(global) { + Global(*env.toks,env[0],env[1],tok_t::PUBLIC); +} +TOK_IMPL(const) { + Const(*env.toks,env[0],env[1],tok_t::PUBLIC); +} +TOK_IMPL(reconst) { + Const(*env.toks,env[0],env[1],tok_t::PUBLIC,1); +} + +/////////////////////////////////////////////////// + +TOK_IMPL(type) { + tok_t* p=env.toks->get(env[0]); + if(env.is_clear(p)) out<mod; +} +TOK_IMPL(desc) { + tok_t* p=env.toks->get(env[0]); + if(env.is_clear(p)) out<get(env[0]); + if(env.is_clear(p)&&p->is_func()) ((func_t*)p)->x.trav(out,12); +} +TOK_IMPL(clear) { + ClearToken(*env.toks,env[0]); +} + +////////////////////////////////////////////////////// + +TOK_IMPL(exist) { out<parg(out,atoi(env[0])-1); } +TOK_IMPL(args) { if(env.up) out<args; else out<<0; } + +/////////////////////////////////////////////////// + +TOK_IMPL(random) { + out<\n" + "%\n" + "%Generates a list of names, beginning with the partial name,\n" + "%from the same - not nescessarily the current - local stack.\n" + "%\n" + "%Generates all local variables in the current stack if no\n" + "%partial name is given.\n" + "%\n" + "%Generates a list of tables if @ is given.\n" + ); + TOK_ADD(globlist,"?",tok_t::PUBLIC, + "%List global variables\n" + "%Syntax: \\globlist\n" + "%\n" + "%Generates a list of names, beginning with the partial name,\n" + "%from the same - not nescessarily the current - global level.\n" + "%\n" + "%Generates all global variables on the current level if no\n" + "%partial name is given.\n" + ); + TOK_ADD(lrec,"xx?",tok_t::PUBLIC, + "%Create a local record\n" + "%Syntax: \\lrec{partial name}{name list}\n" + "%\n" + "%Creates a set of local variables, all beginning with the\n" + "%partial name, and initializes each variable to init.\n" + ); + + ////////////////////////////////////////////////////// + + TOK_ADD(arg,"x",tok_t::PUBLIC, + "%Show/Evaluate argument #n.\n" + "%Syntax: \\arg{n}\n" + "%\n" + "%Same as the command \\1, \\2 etc, except this\n" + "%may be used to index the arguments e.g. using local variables.\n" + ); + TOK_ADD(args,"",tok_t::PUBLIC, + "%Number of arguments in the current function\n" + "%Syntax: \\args\n" + "%\n" + "%Note that the optional argument will count as one variable,\n" + "%and may be accesed using either \\0 or \\arg{\\args}.\n" + ); + + ////////////////////////////////////////////////////// + + TOK_ADD(random,"x",tok_t::PRIVATE, + "%Get n random digits between 0 and 9 inclusive\n" + "%Syntax: \\random{n}\n" + ); + +} -- cgit v1.2.3