Move cfg_causes local into cfg.c and remove struct causelist.

This commit is contained in:
nicm 2014-10-27 22:23:47 +00:00
parent 428b51e031
commit b496b1fe11
5 changed files with 46 additions and 44 deletions

34
cfg.c
View File

@ -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;
}
@ -113,6 +112,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)
{

View File

@ -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);

View File

@ -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);
}
@ -75,20 +75,6 @@ cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_WAIT);
}
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)
{
@ -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);
}

View File

@ -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);

6
tmux.h
View File

@ -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 */