summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2014-10-27 22:23:47 +0000
committernicm <nicm>2014-10-27 22:23:47 +0000
commitb496b1fe11b99614e407d02edb1a21905f384929 (patch)
tree04f86af517474a5486ba8767bc2cdc8c5e102d26
parent428b51e03187f13ccaf1451fb89d53848facab6d (diff)
Move cfg_causes local into cfg.c and remove struct causelist.
-rw-r--r--cfg.c34
-rw-r--r--cmd-queue.c9
-rw-r--r--cmd-source-file.c22
-rw-r--r--server.c19
-rw-r--r--tmux.h6
5 files changed, 46 insertions, 44 deletions
diff --git a/cfg.c b/cfg.c
index 7502cee7..23828923 100644
--- a/cfg.c
+++ b/cfg.c
@@ -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/cmd-queue.c b/cmd-queue.c
index 0ddf90f7..a98fa9b6 100644
--- a/cmd-queue.c
+++ b/cmd-queue.c
@@ -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/cmd-source-file.c b/cmd-source-file.c
index 8610d807..e5710a0c 100644
--- a/cmd-source-file.c
+++ b/cmd-source-file.c
@@ -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/server.c b/server.c
index acf5aaf6..db261306 100644
--- a/server.c
+++ b/server.c
@@ -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/tmux.h b/tmux.h
index adba24d2..d310c7af 100644
--- a/tmux.h
+++ b/tmux.h
@@ -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 */