summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/cfg.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2015-09-01 10:01:57 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2015-09-01 10:01:57 +0000
commit3f731f511581db20a4b8b0d3091216360fb21229 (patch)
tree2cc06012c81075ce986e320677771764f99889e4 /usr.bin/tmux/cfg.c
parent139d1399389601b5d2f1a58a44198692bc417ad4 (diff)
Move initial conf load into cfg.c.
Diffstat (limited to 'usr.bin/tmux/cfg.c')
-rw-r--r--usr.bin/tmux/cfg.c45
1 files changed, 38 insertions, 7 deletions
diff --git a/usr.bin/tmux/cfg.c b/usr.bin/tmux/cfg.c
index 442c65a28fb..e4d8b721b45 100644
--- a/usr.bin/tmux/cfg.c
+++ b/usr.bin/tmux/cfg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cfg.c,v 1.39 2015/06/05 18:06:30 nicm Exp $ */
+/* $OpenBSD: cfg.c,v 1.40 2015/09/01 10:01:56 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -23,16 +23,47 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <util.h>
#include "tmux.h"
-struct cmd_q *cfg_cmd_q;
-int cfg_finished;
-int cfg_references;
-char **cfg_causes;
-u_int cfg_ncauses;
-struct client *cfg_client;
+struct cmd_q *cfg_cmd_q;
+int cfg_finished;
+int cfg_references;
+char **cfg_causes;
+u_int cfg_ncauses;
+struct client *cfg_client;
+
+void cfg_default_done(struct cmd_q *);
+
+void
+start_cfg(void)
+{
+ char *cause = NULL;
+
+ cfg_cmd_q = cmdq_new(NULL);
+ cfg_cmd_q->emptyfn = cfg_default_done;
+
+ cfg_finished = 0;
+ cfg_references = 1;
+
+ cfg_client = TAILQ_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)
+ 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 && load_cfg(cfg_file, cfg_cmd_q, &cause) == -1)
+ cfg_add_cause("%s: %s", cfg_file, cause);
+ free(cause);
+
+ cmdq_continue(cfg_cmd_q);
+}
int
load_cfg(const char *path, struct cmd_q *cmdq, char **cause)