aboutsummaryrefslogtreecommitdiff
path: root/cfg.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2015-09-06 20:47:50 +0100
committerThomas Adam <thomas@xteddy.org>2015-09-06 20:47:50 +0100
commit76688d204071b76fd3388e46e944e4b917c09625 (patch)
treeb6c7920003106991bbb8db46a432e47b16429c94 /cfg.c
parent2ebef95994953e49ae84862a65f9ee649a72e200 (diff)
parentaceae73b9a401c0b124a3534079e9c0d998f0dbd (diff)
downloadrtmux-76688d204071b76fd3388e46e944e4b917c09625.tar.gz
rtmux-76688d204071b76fd3388e46e944e4b917c09625.tar.bz2
rtmux-76688d204071b76fd3388e46e944e4b917c09625.zip
Merge branch 'obsd-master'
Conflicts: cfg.c tmux.c
Diffstat (limited to 'cfg.c')
-rw-r--r--cfg.c60
1 files changed, 54 insertions, 6 deletions
diff --git a/cfg.c b/cfg.c
index 70c69027..ecb38fc0 100644
--- a/cfg.c
+++ b/cfg.c
@@ -23,15 +23,63 @@
#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;
+char *cfg_file;
+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
+set_cfg_file(const char *path)
+{
+ free(cfg_file);
+ cfg_file = xstrdup(path);
+}
+
+void
+start_cfg(void)
+{
+ char *cause = NULL;
+ const char *home;
+
+ 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 && (home = find_home()) != NULL) {
+ xasprintf(&cfg_file, "%s/.tmux.conf", home);
+ if (access(cfg_file, R_OK) != 0 && errno == ENOENT) {
+ free(cfg_file);
+ cfg_file = NULL;
+ }
+ }
+ 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)