-/* $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 <nicm@users.sourceforge.net>
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
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;
}