summaryrefslogtreecommitdiff
path: root/src/lang/help.cc
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2011-10-08 20:30:28 +0200
committerHenrik Rydberg <rydberg@euromail.se>2011-10-08 20:30:28 +0200
commit5df79c53745fde5d6c3340a2979b1429cd5892c1 (patch)
tree1a81af141708b826e9c61e8a04019994fcca8298 /src/lang/help.cc
Initial import of htcd system 1.0
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/lang/help.cc')
-rw-r--r--src/lang/help.cc140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/lang/help.cc b/src/lang/help.cc
new file mode 100644
index 0000000..750a13a
--- /dev/null
+++ b/src/lang/help.cc
@@ -0,0 +1,140 @@
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#include <lang/env.h>
21
22TOK_IMPL(help) {
23 out<<"HTC/1.2 - HyperText Compiler (H. Rydberg (C) 1998,1999,2000,2001)\n";
24 out<<"\n";
25 out<<"Try these commands:\n";
26 out<<"\\help - This message\n";
27 out<<"\\ops - List all operators\n";
28 out<<"\\ops{op} - Get info on operator\n";
29 out<<"\\tok - List all tokens\n";
30 out<<"\\tok{tok} - Get info on token\n";
31 out<<"\\src{tok} - View token source\n";
32}
33
34TOK_IMPL(ops) {
35 mstring cmd; env.parg(cmd,-1);
36 if(cmd.nempty()) {
37 out<<cmd<<"\n";
38 const op_t* p=env.ops->get(cmd);
39 if(p) {
40 if(p->pre1) out<<"Unary operator, precedence "<<p->pre1<<"\n";
41 if(p->pre2) out<<"Binary operator, precedence "<<p->pre2<<"\n";
42 out<<"\n";
43 out<<p->desc;
44 }
45 else {
46 out<<"(not found)\n";
47 }
48 }
49 else {
50 mstring line;
51 line.convert("%-3s %-3s %s\n","P1","P2","NAME");
52 out<<line;
53 for(opmap::iterator p=env.ops->begin();p!=env.ops->end();p++) {
54 line.convert("%-3d %-3d %s\n",(*p)->pre1,(*p)->pre2,(*p)->name.c_str());
55 out<<line;
56 }
57 }
58}
59
60TOK_IMPL(tok) {
61 mstring cmd; env.parg(cmd,-1);
62 if(cmd.nempty()) {
63 out<<cmd<<"\n";
64 const tok_t* p=env.toks->get(cmd);
65 if(p) {
66 out<<"Mode: "<<Mode(*p)<<"\n";
67 if(p->mod&tok_t::RESTRICT) out<<"public ";
68 else if(p->mod&tok_t::NORMAL) out<<"normal ";
69 else if(p->mod&tok_t::SYSONLY) out<<"system ";
70 else if(p->mod&tok_t::INIT) out<<"init ";
71 if(p->is_runnable()) {
72 if(p->is_binary()) out<<"built-in ";
73 out<<"function\n";
74 }
75 else {
76 if(p->is_const()) out<<"constant"; else out<<"variable";
77 if(p->is_reference()) out<<" reference";
78 if(p->is_dbref()) out<<" database reference";
79 out<<"\n";
80 }
81 out<<"Usage: ";
82 if(p->is_runnable()) out<<*(func_t*)p; else out<<"\\"<<p->name;
83 out<<"\n";
84 if(p->is_runnable()) {
85 mstring desc=Desc(*p);
86 if(desc.nempty()) { out<<"\n"; out<<desc; }
87 }
88 }
89 else {
90 out<<"(not found)\n";
91 }
92 }
93 else {
94 mstring line;
95 int n=0;
96 for(tokmap* tok=env.toks;tok;tok=tok->up) {
97 line.convert("%-12s %s %d\n","MODE","NAME LEVEL",n);
98 out<<line;
99 for(tokmap::iterator p=tok->begin();p!=tok->end();p++) {
100 line.convert("%s %s\n",Mode(*(*p)).c_str(),(*p)->name.c_str());
101 out<<line;
102 }
103 n--;
104 }
105 }
106}
107
108TOK_IMPL(src) {
109 const tok_t* p=env.toks->get(env[0]);
110 if(!p) out<<env[0]<<" (not found)\n";
111 else {
112 if(p->is_runnable()) {
113 const func_t* ftok=(func_t*)p;
114 out<<"{"<<ftok->name<<"}{"<<ftok->arg<<"}";
115 if(p->is_binary()) out<<" (built-in function)\n";
116 else out<<"{"<<ftok->x.expr<<"}\n";
117 }
118 else out<<env[0]<<" (not a function)\n";
119 }
120}
121
122void envAddHelp(tokmap& T)
123{
124 TOK_ADD(help,"",tok_t::PRIVATE,
125 "%Help message\n"
126 "%Syntax: \\help\n"
127 );
128 TOK_ADD(ops,"?",tok_t::PRIVATE,
129 "%Help on operators\n"
130 "%Syntax: \\ops<opname>\n"
131 );
132 TOK_ADD(tok,"?",tok_t::PRIVATE,
133 "%Help on tokens\n"
134 "%Syntax: \\tok<tokname>\n"
135 );
136 TOK_ADD(src,"x",tok_t::SYSONLY,
137 "%Source of token\n"
138 "%Syntax: \\src{tokname}\n"
139 );
140}