| 1 |
pippijn |
1.4 |
/** |
| 2 |
|
|
* commandtree.h: Commandlist manipulation routines. |
| 3 |
|
|
* |
| 4 |
|
|
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
| 5 |
|
|
* Rights to this code are as documented in COPYING. |
| 6 |
|
|
* |
| 7 |
|
|
* |
| 8 |
|
|
* Portions of this file were derived from sources bearing the following license: |
| 9 |
pippijn |
1.1 |
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
| 10 |
|
|
* Copyright © 2005 William Pitcock, et al. |
| 11 |
pippijn |
1.2 |
* Rights to this code are as documented in doc/pod/license.pod. |
| 12 |
pippijn |
1.1 |
* |
| 13 |
pippijn |
1.5 |
* $Id: commandtree.h,v 1.4 2007-09-16 18:54:42 pippijn Exp $ |
| 14 |
pippijn |
1.1 |
*/ |
| 15 |
|
|
|
| 16 |
|
|
#ifndef COMMANDLIST_H |
| 17 |
|
|
#define COMMANDLIST_H |
| 18 |
|
|
|
| 19 |
|
|
#include <vector> |
| 20 |
|
|
|
| 21 |
pippijn |
1.5 |
#include <util/memory.h> |
| 22 |
pippijn |
1.1 |
|
| 23 |
|
|
struct command_t |
| 24 |
|
|
{ |
| 25 |
|
|
char const * const name; |
| 26 |
|
|
char const * const desc; |
| 27 |
|
|
char const *access; |
| 28 |
|
|
const int maxparc; |
| 29 |
|
|
void (*cmd) (sourceinfo_t *, const int parc, char *parv[]); |
| 30 |
|
|
|
| 31 |
|
|
void exec (service_t *svs, sourceinfo_t *si, int parc, char *parv[]) const; |
| 32 |
|
|
}; |
| 33 |
|
|
|
| 34 |
|
|
struct cmdvec : std::vector<command_t const *> |
| 35 |
|
|
{ |
| 36 |
|
|
typedef cmdvec::iterator iterator; |
| 37 |
|
|
|
| 38 |
|
|
command_t const *find (char const *command); |
| 39 |
|
|
}; |
| 40 |
|
|
|
| 41 |
|
|
E cmdvec null_cmdvec; |
| 42 |
|
|
|
| 43 |
|
|
/* struct for help command hash table */ |
| 44 |
|
|
struct helpentry_t : zero_initialised |
| 45 |
|
|
{ |
| 46 |
pippijn |
1.3 |
char const * const name; |
| 47 |
|
|
char const * const file; |
| 48 |
pippijn |
1.1 |
void (*func) (sourceinfo_t *si); |
| 49 |
pippijn |
1.3 |
|
| 50 |
|
|
helpentry_t (char const * const cmdname, char const * const filename, void (*function) (sourceinfo_t *si)) |
| 51 |
|
|
: name (cmdname), file (filename ? filename : 0), func (function ? function : 0) |
| 52 |
|
|
{ |
| 53 |
|
|
} |
| 54 |
pippijn |
1.1 |
}; |
| 55 |
|
|
|
| 56 |
|
|
typedef std::vector<helpentry_t *> helpvec; |
| 57 |
|
|
|
| 58 |
|
|
/* commandtree.c */ |
| 59 |
pippijn |
1.3 |
void operator << (cmdvec &commandlist, command_t const &cmd); |
| 60 |
pippijn |
1.1 |
void operator << (cmdvec &commandlist, command_t const *cmd[]); |
| 61 |
pippijn |
1.3 |
void operator >> (cmdvec &commandlist, command_t const &cmd); |
| 62 |
pippijn |
1.1 |
void operator >> (cmdvec &commandlist, command_t const *cmd[]); |
| 63 |
pippijn |
1.3 |
E void command_exec_split (service_t *svs, sourceinfo_t *si, char const * const cmd, char const * const text, cmdvec &commandlist); |
| 64 |
|
|
E void command_help (sourceinfo_t *si, cmdvec &commandlist); |
| 65 |
|
|
E void command_help_short (sourceinfo_t *si, cmdvec &commandlist, char const * const maincmds); |
| 66 |
pippijn |
1.1 |
|
| 67 |
|
|
/* help.c */ |
| 68 |
pippijn |
1.3 |
E void help_display (sourceinfo_t *si, char const * const command, helpvec &list); |
| 69 |
|
|
E void help_addentry (helpvec &list, char const * const topic, char const * const fname, void (*func) (sourceinfo_t *si)); |
| 70 |
|
|
E void help_delentry (helpvec &list, char const * const name); |
| 71 |
pippijn |
1.1 |
|
| 72 |
|
|
#endif |