summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/array.h4
-rw-r--r--usr.bin/tmux/cfg.c29
-rw-r--r--usr.bin/tmux/cmd-new-session.c14
-rw-r--r--usr.bin/tmux/cmd-source-file.c24
-rw-r--r--usr.bin/tmux/server.c24
-rw-r--r--usr.bin/tmux/tmux.h12
6 files changed, 53 insertions, 54 deletions
diff --git a/usr.bin/tmux/array.h b/usr.bin/tmux/array.h
index 1bd4de21dcf..d400acc4145 100644
--- a/usr.bin/tmux/array.h
+++ b/usr.bin/tmux/array.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: array.h,v 1.3 2009/10/29 08:59:17 nicm Exp $ */
+/* $OpenBSD: array.h,v 1.4 2010/02/06 23:22:27 nicm Exp $ */
/*
* Copyright (c) 2006 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -19,6 +19,8 @@
#ifndef ARRAY_H
#define ARRAY_H
+#define ARRAY_INITIALIZER { NULL, 0, 0 }
+
#define ARRAY_DECL(n, c) \
struct n { \
c *list; \
diff --git a/usr.bin/tmux/cfg.c b/usr.bin/tmux/cfg.c
index a89f8d9e9cd..a078719c642 100644
--- a/usr.bin/tmux/cfg.c
+++ b/usr.bin/tmux/cfg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cfg.c,v 1.9 2010/02/06 17:15:33 nicm Exp $ */
+/* $OpenBSD: cfg.c,v 1.10 2010/02/06 23:22:27 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -33,10 +33,9 @@
void printflike2 cfg_print(struct cmd_ctx *, const char *, ...);
void printflike2 cfg_error(struct cmd_ctx *, const char *, ...);
-char *cfg_cause;
-int cfg_finished;
-char **cfg_causes;
-u_int cfg_ncauses;
+char *cfg_cause;
+int cfg_finished;
+struct causelist cfg_causes = ARRAY_INITIALIZER;
/* ARGSUSED */
void printflike2
@@ -55,8 +54,8 @@ cfg_error(unused struct cmd_ctx *ctx, const char *fmt, ...)
va_end(ap);
}
-void printflike3
-cfg_add_cause(u_int *ncauses, char ***causes, const char *fmt, ...)
+void printflike2
+cfg_add_cause(struct causelist *causes, const char *fmt, ...)
{
char *cause;
va_list ap;
@@ -65,8 +64,7 @@ cfg_add_cause(u_int *ncauses, char ***causes, const char *fmt, ...)
xvasprintf(&cause, fmt, ap);
va_end(ap);
- *causes = xrealloc(*causes, *ncauses + 1, sizeof **causes);
- (*causes)[(*ncauses)++] = cause;
+ ARRAY_ADD(causes, cause);
}
/*
@@ -74,8 +72,7 @@ cfg_add_cause(u_int *ncauses, char ***causes, const char *fmt, ...)
* causes. Note that causes and ncauses must be initialised by the caller!
*/
int
-load_cfg(
- const char *path, struct cmd_ctx *ctxin, u_int *ncauses, char ***causes)
+load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
{
FILE *f;
u_int n;
@@ -85,7 +82,7 @@ load_cfg(
struct cmd_ctx ctx;
if ((f = fopen(path, "rb")) == NULL) {
- cfg_add_cause(ncauses, causes, "%s: %s", path, strerror(errno));
+ cfg_add_cause(causes, "%s: %s", path, strerror(errno));
return (-1);
}
n = 0;
@@ -105,8 +102,7 @@ load_cfg(
if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
if (cause == NULL)
continue;
- cfg_add_cause(
- ncauses, causes, "%s: %u: %s", path, n, cause);
+ cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
xfree(cause);
continue;
}
@@ -132,8 +128,7 @@ load_cfg(
cmd_list_exec(cmdlist, &ctx);
cmd_list_free(cmdlist);
if (cfg_cause != NULL) {
- cfg_add_cause(
- ncauses, causes, "%s: %d: %s", path, n, cfg_cause);
+ cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause);
xfree(cfg_cause);
continue;
}
@@ -142,7 +137,7 @@ load_cfg(
xfree(line);
fclose(f);
- if (*ncauses != 0)
+ if (ARRAY_LENGTH(causes) != 0)
return (-1);
return (0);
}
diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c
index 660072645a6..5582849d8d0 100644
--- a/usr.bin/tmux/cmd-new-session.c
+++ b/usr.bin/tmux/cmd-new-session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-session.c,v 1.26 2010/02/06 17:15:33 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.27 2010/02/06 23:22:27 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -285,15 +285,15 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
* If there are still configuration file errors to display, put the new
* session's current window into more mode and display them now.
*/
- if (cfg_finished && cfg_ncauses != 0) {
+ if (cfg_finished && !ARRAY_EMPTY(&cfg_causes)) {
wp = s->curw->window->active;
window_pane_set_mode(wp, &window_more_mode);
- for (i = 0; i < cfg_ncauses; i++) {
- window_more_add(wp, "%s", cfg_causes[i]);
- xfree(cfg_causes[i]);
+ for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
+ cause = ARRAY_ITEM(&cfg_causes, i);
+ window_more_add(wp, "%s", cause);
+ xfree(cause);
}
- xfree(cfg_causes);
- cfg_ncauses = 0;
+ ARRAY_FREE(&cfg_causes);
}
return (!detached); /* 1 means don't tell command client to exit */
diff --git a/usr.bin/tmux/cmd-source-file.c b/usr.bin/tmux/cmd-source-file.c
index ac2b0d67a25..3e06962ad21 100644
--- a/usr.bin/tmux/cmd-source-file.c
+++ b/usr.bin/tmux/cmd-source-file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-source-file.c,v 1.8 2010/02/06 17:15:33 nicm Exp $ */
+/* $OpenBSD: cmd-source-file.c,v 1.9 2010/02/06 23:22:27 nicm Exp $ */
/*
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
@@ -89,18 +89,18 @@ int
cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_source_file_data *data = self->data;
- char **causes;
- u_int i, ncauses;
-
- causes = NULL;
- ncauses = 0;
-
- if (load_cfg(data->path, ctx, &ncauses, &causes) != 0) {
- for (i = 0; i < ncauses; i++) {
- ctx->print(ctx, "%s", causes[i]);
- xfree(causes[i]);
+ struct causelist causes;
+ char *cause;
+ u_int i;
+
+ ARRAY_INIT(&causes);
+ if (load_cfg(data->path, ctx, &causes) != 0) {
+ for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
+ cause = ARRAY_ITEM(&causes, i);
+ ctx->print(ctx, "%s", cause);
+ xfree(cause);
}
- xfree(causes);
+ ARRAY_FREE(&causes);
}
return (0);
diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c
index 48d06644bac..fcd1cd4b0ae 100644
--- a/usr.bin/tmux/server.c
+++ b/usr.bin/tmux/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.82 2010/02/06 17:15:33 nicm Exp $ */
+/* $OpenBSD: server.c,v 1.83 2010/02/06 23:22:27 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -115,7 +115,7 @@ server_start(char *path)
{
struct window_pane *wp;
int pair[2], retval;
- char rpathbuf[MAXPATHLEN];
+ char rpathbuf[MAXPATHLEN], *cause;
struct timeval tv;
u_int i;
@@ -169,27 +169,27 @@ server_start(char *path)
retval = 0;
if (access(SYSTEM_CFG, R_OK) == 0)
- load_cfg(SYSTEM_CFG, NULL, &cfg_ncauses, &cfg_causes);
+ load_cfg(SYSTEM_CFG, NULL, &cfg_causes);
else if (errno != ENOENT) {
- cfg_add_cause(&cfg_ncauses, &cfg_causes,
- "%s: %s", strerror(errno), SYSTEM_CFG);
+ cfg_add_cause(
+ &cfg_causes, "%s: %s", strerror(errno), SYSTEM_CFG);
}
if (cfg_file != NULL)
- load_cfg(cfg_file, NULL, &cfg_ncauses, &cfg_causes);
+ load_cfg(cfg_file, NULL, &cfg_causes);
/*
* If there is a session already, put the current window and pane into
* more mode.
*/
- if (!ARRAY_EMPTY(&sessions) && cfg_ncauses != 0) {
+ if (!ARRAY_EMPTY(&sessions) && !ARRAY_EMPTY(&cfg_causes)) {
wp = ARRAY_FIRST(&sessions)->curw->window->active;
window_pane_set_mode(wp, &window_more_mode);
- for (i = 0; i < cfg_ncauses; i++) {
- window_more_add(wp, "%s", cfg_causes[i]);
- xfree(cfg_causes[i]);
+ for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
+ cause = ARRAY_ITEM(&cfg_causes, i);
+ window_more_add(wp, "%s", cause);
+ xfree(cause);
}
- xfree(cfg_causes);
- cfg_ncauses = 0;
+ ARRAY_FREE(&cfg_causes);
}
cfg_finished = 1;
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 8be009b0ed0..3766e45adf2 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.205 2010/02/06 22:55:31 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.206 2010/02/06 23:22:27 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1244,6 +1244,9 @@ struct set_option_entry {
const char **choices;
};
+/* List of configuration causes. */
+ARRAY_DECL(causelist, char *);
+
/* tmux.c */
extern struct options global_options;
extern struct options global_s_options;
@@ -1262,10 +1265,9 @@ int areshell(const char *);
/* cfg.c */
extern int cfg_finished;
-extern char **cfg_causes;
-extern u_int cfg_ncauses;
-void printflike3 cfg_add_cause(u_int *, char ***, const char *, ...);
-int load_cfg(const char *, struct cmd_ctx *, u_int *, char ***);
+struct causelist cfg_causes;
+void printflike2 cfg_add_cause(struct causelist *, const char *, ...);
+int load_cfg(const char *, struct cmd_ctx *, struct causelist *);
/* mode-key.c */
extern const struct mode_key_table mode_key_tables[];