-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathdialect.cpp
More file actions
48 lines (37 loc) · 1.09 KB
/
Copy pathdialect.cpp
File metadata and controls
48 lines (37 loc) · 1.09 KB
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
#include "dialect.h"
#include "exceptions.h"
#include <stdlib.h>
#include <string.h>
static int cmd_cmp(const void *pa, const void *pb) {
const cmdinfo *a = (const cmdinfo *)pa;
const cmdinfo *b = (const cmdinfo *)pb;
return strcmp(a->lookup_key, b->lookup_key);
}
static const cmdinfo *find_cmd(const struct cmdinfo *tbl, int cnt, const char *name) {
cmdinfo key;
key.lookup_key = name;
return (const cmdinfo *)bsearch((void *)&key, (void *)tbl, cnt, sizeof key, cmd_cmp);
}
static int count_cmds(const struct cmdinfo *tbl) {
int i = 0;
while (tbl[i].lookup_key)
i++;
return i;
}
Dialect::Dialect(const cmdinfo *cmds_, const std::string &n) : cmdcnt(count_cmds(cmds_)), cmds(cmds_), name(n) {
}
const cmdinfo *Dialect::find_command(const char *name) const {
return find_cmd(cmds, cmdcnt, name);
}
int Dialect::cmd_index(const cmdinfo *ci) const {
assert(ci >= cmds && ci < cmds + cmdcnt);
return (ci - cmds);
}
std::map<std::string, boost::shared_ptr<Dialect> > dialects;
void registerDelegates() {
registerAutoDelegates();
}
void freeDelegates() {
dialects.clear();
}
/* vim: set noet: */