mirror of
https://github.com/tmux/tmux.git
synced 2025-01-14 12:48:56 +00:00
Use the array.h code for the causes list.
This commit is contained in:
parent
bb53c20c18
commit
4651180503
2
array.h
2
array.h
@ -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; \
|
||||
|
27
cfg.c
27
cfg.c
@ -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);
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
struct causelist causes;
|
||||
char *cause;
|
||||
u_int i;
|
||||
|
||||
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]);
|
||||
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);
|
||||
|
22
server.c
22
server.c
@ -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;
|
||||
|
||||
|
10
tmux.h
10
tmux.h
@ -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[];
|
||||
|
Loading…
Reference in New Issue
Block a user