summaryrefslogtreecommitdiff
path: root/src/lang/help.cc
blob: 750a13ae6907e965f76abafc6638d3c3a29f9477 (plain)
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
/*************************************************************************
 *
 * 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 <lang/env.h>

TOK_IMPL(help) {
  out<<"HTC/1.2 - HyperText Compiler (H. Rydberg (C) 1998,1999,2000,2001)\n";
  out<<"\n";
  out<<"Try these commands:\n";
  out<<"\\help          - This message\n";
  out<<"\\ops           - List all operators\n";
  out<<"\\ops{op}       - Get info on operator\n";
  out<<"\\tok           - List all tokens\n";
  out<<"\\tok{tok}      - Get info on token\n";
  out<<"\\src{tok}      - View token source\n";
}

TOK_IMPL(ops) {
  mstring cmd; env.parg(cmd,-1);
  if(cmd.nempty()) {
    out<<cmd<<"\n";
    const op_t* p=env.ops->get(cmd);
    if(p) {
      if(p->pre1) out<<"Unary operator, precedence "<<p->pre1<<"\n";
      if(p->pre2) out<<"Binary operator, precedence "<<p->pre2<<"\n";
      out<<"\n";
      out<<p->desc;
    }
    else {
      out<<"(not found)\n";
    }
  }
  else {
    mstring line;
    line.convert("%-3s %-3s %s\n","P1","P2","NAME");
    out<<line;
    for(opmap::iterator p=env.ops->begin();p!=env.ops->end();p++) {
      line.convert("%-3d %-3d %s\n",(*p)->pre1,(*p)->pre2,(*p)->name.c_str());
      out<<line;
    }
  }
}

TOK_IMPL(tok) {
  mstring cmd; env.parg(cmd,-1);
  if(cmd.nempty()) {
    out<<cmd<<"\n";
    const tok_t* p=env.toks->get(cmd);
    if(p) {
      out<<"Mode: "<<Mode(*p)<<"\n";
      if(p->mod&tok_t::RESTRICT) out<<"public ";
      else if(p->mod&tok_t::NORMAL) out<<"normal ";
      else if(p->mod&tok_t::SYSONLY) out<<"system ";
      else if(p->mod&tok_t::INIT) out<<"init ";
      if(p->is_runnable()) {
        if(p->is_binary()) out<<"built-in ";
        out<<"function\n";
      }
      else {
        if(p->is_const()) out<<"constant"; else out<<"variable";
        if(p->is_reference()) out<<" reference";
        if(p->is_dbref()) out<<" database reference";
        out<<"\n";
      }
      out<<"Usage: ";
      if(p->is_runnable()) out<<*(func_t*)p; else out<<"\\"<<p->name;
      out<<"\n";
      if(p->is_runnable()) {
        mstring desc=Desc(*p);
        if(desc.nempty()) { out<<"\n"; out<<desc; }
      }
    }
    else {
      out<<"(not found)\n";
    }
  }
  else {
    mstring line;
    int n=0;
    for(tokmap* tok=env.toks;tok;tok=tok->up) {
      line.convert("%-12s %s %d\n","MODE","NAME LEVEL",n);
      out<<line;
      for(tokmap::iterator p=tok->begin();p!=tok->end();p++) {
        line.convert("%s %s\n",Mode(*(*p)).c_str(),(*p)->name.c_str());
        out<<line;
      }
      n--;
    }
  }
}

TOK_IMPL(src) {
  const tok_t* p=env.toks->get(env[0]);
  if(!p) out<<env[0]<<" (not found)\n";
  else {
    if(p->is_runnable()) {
      const func_t* ftok=(func_t*)p;
      out<<"{"<<ftok->name<<"}{"<<ftok->arg<<"}";
      if(p->is_binary()) out<<" (built-in function)\n";
      else out<<"{"<<ftok->x.expr<<"}\n";
    }
    else out<<env[0]<<" (not a function)\n";
  }
}

void envAddHelp(tokmap& T)
{
  TOK_ADD(help,"",tok_t::PRIVATE,
          "%Help message\n"
          "%Syntax: \\help\n"
          );
  TOK_ADD(ops,"?",tok_t::PRIVATE,
          "%Help on operators\n"
          "%Syntax: \\ops<opname>\n"
          );
  TOK_ADD(tok,"?",tok_t::PRIVATE,
          "%Help on tokens\n"
          "%Syntax: \\tok<tokname>\n"
          );
  TOK_ADD(src,"x",tok_t::SYSONLY,
          "%Source of token\n"
          "%Syntax: \\src{tokname}\n"
          );
}