From: nicm Date: Sat, 25 Apr 2015 18:47:01 +0000 (+0000) Subject: Use a char **,u_int pair for cfg_causes. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=60395c8f585bddad50cb99782268b2b7754bd64c;p=openbsd Use a char **,u_int pair for cfg_causes. --- diff --git a/usr.bin/tmux/cfg.c b/usr.bin/tmux/cfg.c index 4919b5efd4f..719429177d1 100644 --- a/usr.bin/tmux/cfg.c +++ b/usr.bin/tmux/cfg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cfg.c,v 1.34 2015/04/19 21:34:21 nicm Exp $ */ +/* $OpenBSD: cfg.c,v 1.35 2015/04/25 18:47:01 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -30,7 +30,8 @@ struct cmd_q *cfg_cmd_q; int cfg_finished; int cfg_references; -ARRAY_DECL (, char *) cfg_causes = ARRAY_INITIALIZER; +char** cfg_causes; +u_int cfg_ncauses; struct client *cfg_client; int @@ -122,40 +123,42 @@ cfg_add_cause(const char* fmt, ...) xvasprintf(&msg, fmt, ap); va_end (ap); - ARRAY_ADD(&cfg_causes, msg); + cfg_ncauses++; + cfg_causes = xreallocarray(cfg_causes, cfg_ncauses, sizeof *cfg_causes); + cfg_causes[cfg_ncauses - 1] = msg; } void cfg_print_causes(struct cmd_q *cmdq) { - char *cause; u_int i; - for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) { - cause = ARRAY_ITEM(&cfg_causes, i); - cmdq_print(cmdq, "%s", cause); - free(cause); + for (i = 0; i < cfg_ncauses; i++) { + cmdq_print(cmdq, "%s", cfg_causes[i]); + free(cfg_causes[i]); } - ARRAY_FREE(&cfg_causes); + + free(cfg_causes); + cfg_causes = NULL; } void cfg_show_causes(struct session *s) { struct window_pane *wp; - char *cause; u_int i; - if (s == NULL || ARRAY_EMPTY(&cfg_causes)) + if (s == NULL || cfg_ncauses == 0) return; wp = s->curw->window->active; window_pane_set_mode(wp, &window_copy_mode); window_copy_init_for_output(wp); - for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) { - cause = ARRAY_ITEM(&cfg_causes, i); - window_copy_add(wp, "%s", cause); - free(cause); + for (i = 0; i < cfg_ncauses; i++) { + window_copy_add(wp, "%s", cfg_causes[i]); + free(cfg_causes[i]); } - ARRAY_FREE(&cfg_causes); + + free(cfg_causes); + cfg_causes = NULL; }