From 59b883431996e4d52d74d8926bc48243ec9dc8be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 21 Apr 2016 09:47:00 +0200 Subject: vis: do not lazy allocate :-commands The built in commands should always be available. --- sam.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'sam.c') 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); } -- cgit v1.2.3