summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cfg.c25
-rw-r--r--cmd-command-prompt.c19
-rw-r--r--cmd-confirm-before.c19
-rw-r--r--cmd-display-panes.c23
-rw-r--r--cmd-queue.c19
-rw-r--r--cmd-source-file.c14
-rw-r--r--menu.c25
-rw-r--r--server-client.c15
-rw-r--r--server.c15
-rw-r--r--tmux.h5
10 files changed, 74 insertions, 105 deletions
diff --git a/cfg.c b/cfg.c
index 86b4c82f..f4942b22 100644
--- a/cfg.c
+++ b/cfg.c
@@ -81,7 +81,7 @@ void
start_cfg(void)
{
const char *home;
- int quiet = 0;
+ int flags = 0;
struct client *c;
/*
@@ -102,14 +102,14 @@ start_cfg(void)
}
if (cfg_file == NULL)
- load_cfg(TMUX_CONF, NULL, NULL, 1);
+ load_cfg(TMUX_CONF, NULL, NULL, CFG_QUIET, NULL);
if (cfg_file == NULL && (home = find_home()) != NULL) {
xasprintf(&cfg_file, "%s/.tmux.conf", home);
- quiet = 1;
+ flags = CFG_QUIET;
}
if (cfg_file != NULL)
- load_cfg(cfg_file, NULL, NULL, quiet);
+ load_cfg(cfg_file, NULL, NULL, flags, NULL);
cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL));
}
@@ -238,7 +238,8 @@ cfg_handle_directive(const char *p, const char *path, size_t line,
}
int
-load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
+load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
+ struct cmdq_item **new_item)
{
FILE *f;
const char delim[3] = { '\\', '\\', '\0' };
@@ -246,7 +247,7 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
size_t line = 0;
char *buf, *cause1, *p, *q;
struct cmd_list *cmdlist;
- struct cmdq_item *new_item;
+ struct cmdq_item *new_item0;
struct cfg_cond *cond, *cond1;
struct cfg_conds conds;
struct cmd_find_state *fs = NULL;
@@ -261,7 +262,7 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
log_debug("loading %s", path);
if ((f = fopen(path, "rb")) == NULL) {
- if (errno == ENOENT && quiet)
+ if (errno == ENOENT && (flags & CFG_QUIET))
return (0);
cfg_add_cause("%s: %s", path, strerror(errno));
return (-1);
@@ -300,12 +301,12 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
}
free(buf);
- new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
+ new_item0 = cmdq_get_command(cmdlist, NULL, NULL, 0);
if (item != NULL) {
- cmdq_insert_after(item, new_item);
- item = new_item;
+ cmdq_insert_after(item, new_item0);
+ item = new_item0;
} else
- cmdq_append(c, new_item);
+ cmdq_append(c, new_item0);
cmd_list_free(cmdlist);
found++;
@@ -318,6 +319,8 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
free(cond);
}
+ if (new_item != NULL)
+ *new_item = item;
return (found);
}
diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c
index d7159ad0..a3cc22c8 100644
--- a/cmd-command-prompt.c
+++ b/cmd-command-prompt.c
@@ -129,17 +129,6 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_NORMAL);
}
-static enum cmd_retval
-cmd_command_prompt_error(struct cmdq_item *item, void *data)
-{
- char *error = data;
-
- cmdq_error(item, "%s", error);
- free(error);
-
- return (CMD_RETURN_NORMAL);
-}
-
static int
cmd_command_prompt_callback(struct client *c, void *data, const char *s,
int done)
@@ -177,11 +166,11 @@ cmd_command_prompt_callback(struct client *c, void *data, const char *s,
cmdlist = cmd_string_parse(new_template, NULL, 0, &cause);
if (cmdlist == NULL) {
- if (cause != NULL) {
- new_item = cmdq_get_callback(cmd_command_prompt_error,
- cause);
- } else
+ if (cause != NULL)
+ new_item = cmdq_get_error(cause);
+ else
new_item = NULL;
+ free(cause);
} else {
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
cmd_list_free(cmdlist);
diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c
index 7036d34b..4017a6f9 100644
--- a/cmd-confirm-before.c
+++ b/cmd-confirm-before.c
@@ -82,17 +82,6 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_NORMAL);
}
-static enum cmd_retval
-cmd_confirm_before_error(struct cmdq_item *item, void *data)
-{
- char *error = data;
-
- cmdq_error(item, "%s", error);
- free(error);
-
- return (CMD_RETURN_NORMAL);
-}
-
static int
cmd_confirm_before_callback(struct client *c, void *data, const char *s,
__unused int done)
@@ -112,11 +101,11 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s,
cmdlist = cmd_string_parse(cdata->cmd, NULL, 0, &cause);
if (cmdlist == NULL) {
- if (cause != NULL) {
- new_item = cmdq_get_callback(cmd_confirm_before_error,
- cause);
- } else
+ if (cause != NULL)
+ new_item = cmdq_get_error(cause);
+ else
new_item = NULL;
+ free(cause);
} else {
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
cmd_list_free(cmdlist);
diff --git a/cmd-display-panes.c b/cmd-display-panes.c
index 8940b429..6e331ae1 100644
--- a/cmd-display-panes.c
+++ b/cmd-display-panes.c
@@ -182,17 +182,6 @@ cmd_display_panes_draw(struct client *c, struct screen_redraw_ctx *ctx)
}
}
-static enum cmd_retval
-cmd_display_panes_error(struct cmdq_item *item, void *data)
-{
- char *error = data;
-
- cmdq_error(item, "%s", error);
- free(error);
-
- return (CMD_RETURN_NORMAL);
-}
-
static void
cmd_display_panes_free(struct client *c)
{
@@ -226,11 +215,13 @@ cmd_display_panes_key(struct client *c, struct key_event *event)
cmd = cmd_template_replace(cdata->command, expanded, 1);
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
- if (cmdlist == NULL && cause != NULL)
- new_item = cmdq_get_callback(cmd_display_panes_error, cause);
- else if (cmdlist == NULL)
- new_item = NULL;
- else {
+ if (cmdlist == NULL) {
+ if (cause != NULL)
+ new_item = cmdq_get_error(cause);
+ else
+ new_item = NULL;
+ free(cause);
+ } else {
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
cmd_list_free(cmdlist);
}
diff --git a/cmd-queue.c b/cmd-queue.c
index 93b9788e..68bedae8 100644
--- a/cmd-queue.c
+++ b/cmd-queue.c
@@ -329,6 +329,25 @@ cmdq_get_callback1(const char *name, cmdq_cb cb, void *data)
return (item);
}
+/* Generic error callback. */
+static enum cmd_retval
+cmdq_error_callback(struct cmdq_item *item, void *data)
+{
+ char *error = data;
+
+ cmdq_error(item, "%s", error);
+ free(error);
+
+ return (CMD_RETURN_NORMAL);
+}
+
+/* Get an error callback for the command queue. */
+struct cmdq_item *
+cmdq_get_error(const char *error)
+{
+ return (cmdq_get_callback(cmdq_error_callback, xstrdup(error)));
+}
+
/* Fire callback on callback queue. */
static enum cmd_retval
cmdq_fire_callback(struct cmdq_item *item)
diff --git a/cmd-source-file.c b/cmd-source-file.c
index aeb11c42..5a3be6f9 100644
--- a/cmd-source-file.c
+++ b/cmd-source-file.c
@@ -48,15 +48,18 @@ static enum cmd_retval
cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- int quiet = args_has(args, 'q');
+ int flags = 0;
struct client *c = item->client;
- struct cmdq_item *new_item;
+ struct cmdq_item *new_item, *after;
enum cmd_retval retval;
char *pattern, *tmp;
const char *path = args->argv[0];
glob_t g;
u_int i;
+ if (args_has(args, 'q'))
+ flags |= CFG_QUIET;
+
if (*path == '/')
pattern = xstrdup(path);
else {
@@ -68,7 +71,7 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
retval = CMD_RETURN_NORMAL;
if (glob(pattern, 0, NULL, &g) != 0) {
- if (!quiet || errno != ENOENT) {
+ if (errno != ENOENT || (~flags & CFG_QUIET)) {
cmdq_error(item, "%s: %s", path, strerror(errno));
retval = CMD_RETURN_ERROR;
}
@@ -77,9 +80,12 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
}
free(pattern);
+ after = item;
for (i = 0; i < (u_int)g.gl_pathc; i++) {
- if (load_cfg(g.gl_pathv[i], c, item, quiet) < 0)
+ if (load_cfg(g.gl_pathv[i], c, after, flags, &new_item) < 0)
retval = CMD_RETURN_ERROR;
+ else if (new_item != NULL)
+ after = new_item;
}
if (cfg_finished) {
new_item = cmdq_get_callback(cmd_source_file_done, NULL);
diff --git a/menu.c b/menu.c
index 945b62c4..395e1455 100644
--- a/menu.c
+++ b/menu.c
@@ -191,17 +191,6 @@ menu_free_cb(struct client *c)
free(md);
}
-static enum cmd_retval
-menu_error_cb(struct cmdq_item *item, void *data)
-{
- char *error = data;
-
- cmdq_error(item, "%s", error);
- free(error);
-
- return (CMD_RETURN_NORMAL);
-}
-
static int
menu_key_cb(struct client *c, struct key_event *event)
{
@@ -284,12 +273,14 @@ chosen:
return (1);
}
cmdlist = cmd_string_parse(item->command, NULL, 0, &cause);
- if (cmdlist == NULL && cause != NULL)
- new_item = cmdq_get_callback(menu_error_cb, cause);
- else if (cmdlist == NULL)
- new_item = NULL;
- else {
- new_item = cmdq_get_command(cmdlist, &md->fs, NULL, 0);
+ if (cmdlist == NULL) {
+ if (cause != NULL)
+ new_item = cmdq_get_error(cause);
+ else
+ new_item = NULL;
+ free(cause);
+ } else {
+ new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
cmd_list_free(cmdlist);
}
if (new_item != NULL) {
diff --git a/server-client.c b/server-client.c
index b61c1fa9..47c513fc 100644
--- a/server-client.c
+++ b/server-client.c
@@ -1778,18 +1778,6 @@ server_client_command_done(struct cmdq_item *item, __unused void *data)
return (CMD_RETURN_NORMAL);
}
-/* Show an error message. */
-static enum cmd_retval
-server_client_command_error(struct cmdq_item *item, void *data)
-{
- char *error = data;
-
- cmdq_error(item, "%s", error);
- free(error);
-
- return (CMD_RETURN_NORMAL);
-}
-
/* Handle command message. */
static void
server_client_dispatch_command(struct client *c, struct imsg *imsg)
@@ -1837,7 +1825,8 @@ server_client_dispatch_command(struct client *c, struct imsg *imsg)
return;
error:
- cmdq_append(c, cmdq_get_callback(server_client_command_error, cause));
+ cmdq_append(c, cmdq_get_error(cause));
+ free(cause);
if (cmdlist != NULL)
cmd_list_free(cmdlist);
diff --git a/server.c b/server.c
index 41bc492e..af966501 100644
--- a/server.c
+++ b/server.c
@@ -143,18 +143,6 @@ fail:
return (-1);
}
-/* Server error callback. */
-static enum cmd_retval
-server_start_error(struct cmdq_item *item, void *data)
-{
- char *error = data;
-
- cmdq_error(item, "%s", error);
- free(error);
-
- return (CMD_RETURN_NORMAL);
-}
-
/* Fork new server. */
int
server_start(struct tmuxproc *client, struct event_base *base, int lockfd,
@@ -216,7 +204,8 @@ server_start(struct tmuxproc *client, struct event_base *base, int lockfd,
}
if (cause != NULL) {
- cmdq_append(c, cmdq_get_callback(server_start_error, cause));
+ cmdq_append(c, cmdq_get_error(cause));
+ free(cause);
c->flags |= CLIENT_EXIT;
}
diff --git a/tmux.h b/tmux.h
index c3cf11a3..f80409aa 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1673,8 +1673,10 @@ void proc_toggle_log(struct tmuxproc *);
/* cfg.c */
extern int cfg_finished;
extern struct client *cfg_client;
+#define CFG_QUIET 0x1
void start_cfg(void);
-int load_cfg(const char *, struct client *, struct cmdq_item *, int);
+int load_cfg(const char *, struct client *, struct cmdq_item *, int,
+ struct cmdq_item **);
void set_cfg_file(const char *);
void printflike(1, 2) cfg_add_cause(const char *, ...);
void cfg_print_causes(struct cmdq_item *);
@@ -1985,6 +1987,7 @@ struct cmdq_item *cmdq_get_command(struct cmd_list *, struct cmd_find_state *,
struct mouse_event *, int);
#define cmdq_get_callback(cb, data) cmdq_get_callback1(#cb, cb, data)
struct cmdq_item *cmdq_get_callback1(const char *, cmdq_cb, void *);
+struct cmdq_item *cmdq_get_error(const char *);
void cmdq_insert_after(struct cmdq_item *, struct cmdq_item *);
void cmdq_append(struct client *, struct cmdq_item *);
void cmdq_insert_hook(struct session *, struct cmdq_item *,