2 #include "exceptions.h"
6 static int cmd_cmp(const void *pa
, const void *pb
) {
7 const cmdinfo
*a
= (const cmdinfo
*)pa
;
8 const cmdinfo
*b
= (const cmdinfo
*)pb
;
10 return strcmp(a
->lookup_key
, b
->lookup_key
);
13 static const cmdinfo
*find_cmd(const struct cmdinfo
*tbl
, int cnt
, const char *name
) {
15 key
.lookup_key
= name
;
16 return (const cmdinfo
*)bsearch((void *)&key
, (void *)tbl
, cnt
, sizeof key
, cmd_cmp
);
19 static int count_cmds(const struct cmdinfo
*tbl
) {
21 while (tbl
[i
].lookup_key
)
26 Dialect::Dialect(const cmdinfo
*cmds_
, const std::string
&n
) : cmdcnt(count_cmds(cmds_
)), cmds(cmds_
), name(n
) {
29 const cmdinfo
*Dialect::find_command(const char *name
) const {
30 const cmdinfo
*ci
= find_cmd(cmds
, cmdcnt
, name
);
32 throw parseException(std::string("Command not found: ") + name
);
36 int Dialect::cmd_index(const cmdinfo
*ci
) const {
37 assert(ci
>= cmds
&& ci
< cmds
+ cmdcnt
);
41 std::map
<std::string
, boost::shared_ptr
<Dialect
> > dialects
;
43 void registerDelegates() {
44 registerAutoDelegates();
47 void freeDelegates() {