aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-21 09:47:00 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-21 10:01:40 +0200
commit59b883431996e4d52d74d8926bc48243ec9dc8be (patch)
tree4e0cc821aff1d650d9d91f2005333c07b5096046
parent793f1e212bb08d2edba172cd32d0ef8cc43a1aeb (diff)
downloadvis-59b883431996e4d52d74d8926bc48243ec9dc8be.tar.gz
vis-59b883431996e4d52d74d8926bc48243ec9dc8be.tar.xz
vis: do not lazy allocate :-commands
The built in commands should always be available.
-rw-r--r--sam.c20
-rw-r--r--sam.h3
-rw-r--r--vis.c2
3 files changed, 15 insertions, 10 deletions
diff --git a/sam.c b/sam.c
index 2e71239..c52b2e1 100644
--- a/sam.c
+++ b/sam.c
@@ -163,6 +163,17 @@ static const CommandDef cmds[] = {
static const CommandDef cmddef_select =
{ { "s" }, 0, NULL, cmd_select };
+bool sam_init(Vis *vis) {
+ if (!(vis->cmds = map_new()))
+ return false;
+ bool ret = true;
+ for (const CommandDef *cmd = cmds; cmd && cmd->name[0]; cmd++) {
+ for (const char *const *name = cmd->name; *name; name++)
+ ret &= map_put(vis->cmds, *name, cmd);
+ }
+ return ret;
+}
+
const char *sam_error(enum SamError err) {
static const char *error_msg[] = {
[SAM_ERR_OK] = "Success",
@@ -474,15 +485,6 @@ static void command_free(Command *cmd) {
}
static const CommandDef *command_lookup(Vis *vis, const char *name) {
- if (!vis->cmds) {
- if (!(vis->cmds = map_new()))
- return NULL;
-
- for (const CommandDef *cmd = cmds; cmd && cmd->name[0]; cmd++) {
- for (const char *const *name = cmd->name; *name; name++)
- map_put(vis->cmds, *name, cmd);
- }
- }
return map_closest(vis->cmds, name);
}
diff --git a/sam.h b/sam.h
index 6521834..f44079a 100644
--- a/sam.h
+++ b/sam.h
@@ -17,7 +17,8 @@ enum SamError {
SAM_ERR_EXECUTE,
};
-enum SamError sam_cmd(Vis *vis, const char *cmd);
+bool sam_init(Vis*);
+enum SamError sam_cmd(Vis*, const char *cmd);
const char *sam_error(enum SamError);
#endif
diff --git a/vis.c b/vis.c
index 8f4155e..388bc41 100644
--- a/vis.c
+++ b/vis.c
@@ -364,6 +364,8 @@ Vis *vis_new(Ui *ui, VisEvent *event) {
goto err;
if (!(vis->keymap = map_new()))
goto err;
+ if (!sam_init(vis))
+ goto err;
vis->mode_prev = vis->mode = &vis_modes[VIS_MODE_NORMAL];
vis->event = event;
if (event && event->vis_init)