From 931b7e89b025a354af81008fc7f799903ea16bee Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 30 Jun 2015 18:44:29 +0000 Subject: keep cmdq sorted --- conf.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'conf.c') diff --git a/conf.c b/conf.c index 54e6791..6648acd 100644 --- a/conf.c +++ b/conf.c @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: conf.c,v 1.188 2015/06/30 18:42:50 okan Exp $ + * $OpenBSD: conf.c,v 1.189 2015/06/30 18:44:29 okan Exp $ */ #include @@ -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); } -- cgit v1.2.3-2-gb3c3