summary refs log tree commit diff
diff options
context:
space:
mode:
authorokan <okan>2012-12-18 00:14:41 +0000
committerokan <okan>2012-12-18 00:14:41 +0000
commitb848a2b236424a33d0fcf1f07e3b4473a56604ff (patch)
treef9f0e26c5276594a2afb01707b7a3536a1cb56dd
parent479e9f769c5a822da49ec60cd7ceb533e1739527 (diff)
downloadcwm-b848a2b236424a33d0fcf1f07e3b4473a56604ff.tar.gz
cwm-b848a2b236424a33d0fcf1f07e3b4473a56604ff.tar.xz
cwm-b848a2b236424a33d0fcf1f07e3b4473a56604ff.zip
simplify config file setup; with Tiago Cunha
-rw-r--r--calmwm.c21
-rw-r--r--calmwm.h1
-rw-r--r--conf.c31
3 files changed, 20 insertions, 33 deletions
diff --git a/calmwm.c b/calmwm.c
index 2c02342..25ac559 100644
--- a/calmwm.c
+++ b/calmwm.c
@@ -62,7 +62,7 @@ int
 main(int argc, char **argv)
 {
 	const char	*conf_file = NULL;
-	char		*display_name = NULL;
+	char		*conf_path, *display_name = NULL;
 	int		 ch;
 	struct passwd	*pw;
 
@@ -97,10 +97,25 @@ main(int argc, char **argv)
 			homedir = "/";
 	}
 
+	if (conf_file == NULL)
+		xasprintf(&conf_path, "%s/%s", homedir, CONFFILE);
+	else
+		conf_path = xstrdup(conf_file);
+
+	if (access(conf_path, R_OK) != 0) {
+		if (conf_file != NULL)
+			warn("%s", conf_file);
+		free(conf_path);
+		conf_path = NULL;
+	}
+
 	dpy_init(display_name);
 
-	bzero(&Conf, sizeof(Conf));
-	conf_setup(&Conf, conf_file);
+	conf_init(&Conf);
+	if (conf_path && (parse_config(conf_path, &Conf) == -1))
+		warnx("config file %s has errors, not loading", conf_path);
+	free(conf_path);
+
 	xu_getatoms();
 	x_setup();
 	xev_loop();
diff --git a/calmwm.h b/calmwm.h
index 256ce9e..3d44e9b 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -448,7 +448,6 @@ void			 conf_grab(struct conf *, struct keybinding *);
 void			 conf_grab_mouse(struct client_ctx *);
 void			 conf_init(struct conf *);
 void			 conf_mousebind(struct conf *, char *, char *);
-void			 conf_setup(struct conf *, const char *);
 void			 conf_ungrab(struct conf *, struct keybinding *);
 
 int			 font_ascent(struct screen_ctx *);
diff --git a/conf.c b/conf.c
index d1cbbf8..19a7a6d 100644
--- a/conf.c
+++ b/conf.c
@@ -166,7 +166,8 @@ conf_init(struct conf *c)
 {
 	int	i;
 
-	c->flags = 0;
+	bzero(c, sizeof(*c));
+
 	c->bwidth = CONF_BWIDTH;
 	c->mamount = CONF_MAMOUNT;
 	c->snapdist = CONF_SNAPDIST;
@@ -243,34 +244,6 @@ conf_clear(struct conf *c)
 }
 
 void
-conf_setup(struct conf *c, const char *conf_file)
-{
-	char		 conf_path[MAXPATHLEN];
-	struct stat	 sb;
-	int		 parse = 0;
-
-	conf_init(c);
-
-	if (conf_file == NULL) {
-		(void)snprintf(conf_path, sizeof(conf_path), "%s/%s",
-		    homedir, CONFFILE);
-
-		if (stat(conf_path, &sb) == 0 && (sb.st_mode & S_IFREG))
-			parse = 1;
-	} else {
-		if (stat(conf_file, &sb) == -1 || !(sb.st_mode & S_IFREG))
-			errx(1, "%s: %s", conf_file, strerror(errno));
-		else {
-			(void)strlcpy(conf_path, conf_file, sizeof(conf_path));
-			parse = 1;
-		}
-	}
-
-	if (parse && (parse_config(conf_path, c) == -1))
-		warnx("config file %s has errors, not loading", conf_path);
-}
-
-void
 conf_client(struct client_ctx *cc)
 {
 	struct winmatch	*wm;