summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2014-10-27 22:23:48 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2014-10-27 22:23:48 +0000
commitc0fb64c897c3c76aa02cc8f70b033d7e18d58370 (patch)
tree29670e2df3a23a01962652d390b1290bbbe2cab7 /usr.bin
parent7e1fafc115d0775035d15a8368847644806a572d (diff)
Move cfg_causes local into cfg.c and remove struct causelist.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/cfg.c36
-rw-r--r--usr.bin/tmux/cmd-queue.c11
-rw-r--r--usr.bin/tmux/cmd-source-file.c24
-rw-r--r--usr.bin/tmux/server.c21
-rw-r--r--usr.bin/tmux/tmux.h8
5 files changed, 51 insertions, 49 deletions
diff --git a/usr.bin/tmux/cfg.c b/usr.bin/tmux/cfg.c
index b31125912ed..514c88690c3 100644
--- a/usr.bin/tmux/cfg.c
+++ b/usr.bin/tmux/cfg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cfg.c,v 1.32 2014/06/25 19:17:27 tobias Exp $ */
+/* $OpenBSD: cfg.c,v 1.33 2014/10/27 22:23:47 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -30,7 +30,7 @@
struct cmd_q *cfg_cmd_q;
int cfg_finished;
int cfg_references;
-struct causelist cfg_causes;
+ARRAY_DECL (, char *) cfg_causes = ARRAY_INITIALIZER;
struct client *cfg_client;
int
@@ -40,7 +40,7 @@ load_cfg(const char *path, struct cmd_q *cmdq, char **cause)
char delim[3] = { '\\', '\\', '\0' };
u_int found;
size_t line = 0;
- char *buf, *cause1, *msg, *p;
+ char *buf, *cause1, *p;
struct cmd_list *cmdlist;
log_debug("loading %s", path);
@@ -67,8 +67,7 @@ load_cfg(const char *path, struct cmd_q *cmdq, char **cause)
free(buf);
if (cause1 == NULL)
continue;
- xasprintf(&msg, "%s:%zu: %s", path, line, cause1);
- ARRAY_ADD(&cfg_causes, msg);
+ cfg_add_cause("%s:%zu: %s", path, line, cause1);
free(cause1);
continue;
}
@@ -114,6 +113,33 @@ cfg_default_done(unused struct cmd_q *cmdq)
}
void
+cfg_add_cause(const char* fmt, ...)
+{
+ va_list ap;
+ char* msg;
+
+ va_start(ap, fmt);
+ xvasprintf(&msg, fmt, ap);
+ va_end (ap);
+
+ ARRAY_ADD(&cfg_causes, 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);
+ }
+ ARRAY_FREE(&cfg_causes);
+}
+
+void
cfg_show_causes(struct session *s)
{
struct window_pane *wp;
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c
index 5c331e6c678..f9e7a076e69 100644
--- a/usr.bin/tmux/cmd-queue.c
+++ b/usr.bin/tmux/cmd-queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-queue.c,v 1.19 2014/10/21 22:06:46 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.20 2014/10/27 22:23:47 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -93,17 +93,16 @@ cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
struct client *c = cmdq->client;
struct cmd *cmd = cmdq->cmd;
va_list ap;
- char *msg, *cause;
+ char *msg;
size_t msglen;
va_start(ap, fmt);
msglen = xvasprintf(&msg, fmt, ap);
va_end(ap);
- if (c == NULL) {
- xasprintf(&cause, "%s:%u: %s", cmd->file, cmd->line, msg);
- ARRAY_ADD(&cfg_causes, cause);
- } else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
+ if (c == NULL)
+ cfg_add_cause("%s:%u: %s", cmd->file, cmd->line, msg);
+ else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
evbuffer_add(c->stderr_data, msg, msglen);
evbuffer_add(c->stderr_data, "\n", 1);
diff --git a/usr.bin/tmux/cmd-source-file.c b/usr.bin/tmux/cmd-source-file.c
index e36f63545e6..121539836c9 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.20 2014/10/20 22:29:25 nicm Exp $ */
+/* $OpenBSD: cmd-source-file.c,v 1.21 2014/10/27 22:23:47 nicm Exp $ */
/*
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
@@ -28,7 +28,6 @@
enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_q *);
-void cmd_source_file_show(struct cmd_q *);
void cmd_source_file_done(struct cmd_q *);
const struct cmd_entry cmd_source_file_entry = {
@@ -59,11 +58,12 @@ cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq)
free(cause);
return (CMD_RETURN_ERROR);
}
- ARRAY_ADD(&cfg_causes, cause);
+ cfg_add_cause("%s", cause);
+ free(cause);
/* FALLTHROUGH */
case 0:
if (cfg_references == 0)
- cmd_source_file_show(cmdq);
+ cfg_print_causes(cmdq);
cmdq_free(cmdq1);
return (CMD_RETURN_NORMAL);
}
@@ -76,20 +76,6 @@ cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq)
}
void
-cmd_source_file_show(struct cmd_q *cmdq)
-{
- u_int i;
- char *cause;
-
- for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
- cause = ARRAY_ITEM(&cfg_causes, i);
- cmdq_print(cmdq, "%s", cause);
- free(cause);
- }
- ARRAY_FREE(&cfg_causes);
-}
-
-void
cmd_source_file_done(struct cmd_q *cmdq1)
{
struct cmd_q *cmdq = cmdq1->data;
@@ -105,6 +91,6 @@ cmd_source_file_done(struct cmd_q *cmdq1)
return;
if (cfg_references == 0)
- cmd_source_file_show(cmdq);
+ cfg_print_causes(cmdq);
cmdq_continue(cmdq);
}
diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c
index 51f443873da..7208e124a03 100644
--- a/usr.bin/tmux/server.c
+++ b/usr.bin/tmux/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.116 2014/09/01 21:58:41 nicm Exp $ */
+/* $OpenBSD: server.c,v 1.117 2014/10/27 22:23:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -165,25 +165,18 @@ server_start(int lockfd, char *lockfile)
cfg_cmd_q->emptyfn = cfg_default_done;
cfg_finished = 0;
cfg_references = 1;
- ARRAY_INIT(&cfg_causes);
cfg_client = ARRAY_FIRST(&clients);
if (cfg_client != NULL)
cfg_client->references++;
if (access(TMUX_CONF, R_OK) == 0) {
- if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1) {
- xasprintf(&cause, "%s: %s", TMUX_CONF, cause);
- ARRAY_ADD(&cfg_causes, cause);
- }
- } else if (errno != ENOENT) {
- xasprintf(&cause, "%s: %s", TMUX_CONF, strerror(errno));
- ARRAY_ADD(&cfg_causes, cause);
- }
+ if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1)
+ cfg_add_cause("%s: %s", TMUX_CONF, cause);
+ } else if (errno != ENOENT)
+ cfg_add_cause("%s: %s", TMUX_CONF, strerror(errno));
if (cfg_file != NULL) {
- if (load_cfg(cfg_file, cfg_cmd_q, &cause) == -1) {
- xasprintf(&cause, "%s: %s", cfg_file, cause);
- ARRAY_ADD(&cfg_causes, cause);
- }
+ if (load_cfg(cfg_file, cfg_cmd_q, &cause) == -1)
+ cfg_add_cause("%s: %s", cfg_file, cause);
}
cmdq_continue(cfg_cmd_q);
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index a04290a5558..035bc104ba1 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.478 2014/10/22 23:11:41 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.479 2014/10/27 22:23:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -381,9 +381,6 @@ struct tty_term_code_entry {
const char *name;
};
-/* List of error causes. */
-ARRAY_DECL(causelist, char *);
-
/* Message codes. */
enum msgtype {
MSG_VERSION = 12,
@@ -1500,10 +1497,11 @@ __dead void shell_exec(const char *, const char *);
extern struct cmd_q *cfg_cmd_q;
extern int cfg_finished;
extern int cfg_references;
-extern struct causelist cfg_causes;
extern struct client *cfg_client;
int load_cfg(const char *, struct cmd_q *, char **);
void cfg_default_done(struct cmd_q *);
+void cfg_add_cause(const char *, ...);
+void cfg_print_causes(struct cmd_q *);
void cfg_show_causes(struct session *);
/* format.c */