keep cmdq sorted

This commit is contained in:
okan 2015-06-30 18:44:29 +00:00
parent 6b8b856217
commit c87953eb64

10
conf.c
View File

@ -40,7 +40,7 @@ static void conf_unbind_mouse(struct conf *, struct binding *);
int
conf_cmd_add(struct conf *c, const char *name, const char *path)
{
struct cmd *cmd;
struct cmd *cmd, *prev;
cmd = xmalloc(sizeof(*cmd));
@ -54,6 +54,14 @@ conf_cmd_add(struct conf *c, const char *name, const char *path)
conf_cmd_remove(c, name);
TAILQ_INSERT_TAIL(&c->cmdq, cmd, entry);
/* keep queue sorted by name */
while ((prev = TAILQ_PREV(cmd, cmd_q, entry)) &&
(strcmp(prev->name, cmd->name) > 0)) {
TAILQ_REMOVE(&c->cmdq, cmd, entry);
TAILQ_INSERT_BEFORE(prev, cmd, entry);
}
return(1);
}