JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
better fix from davec
[spectrwm.git] / spectrwm.c
index 2928f00..4d4c12a 100644 (file)
@@ -6,8 +6,8 @@
  * Copyright (c) 2010 Tuukka Kataja <stuge@xor.fi>
  * Copyright (c) 2011 Jason L. Wright <jason@thought.net>
  * Copyright (c) 2011-2012 Reginald Kennedy <rk@rejii.com>
- * Copyright (c) 2012 Lawrence Teo <lteo@lteo.net>
- * Copyright (c) 2012 Tiago Cunha <tcunha@gmx.com>
+ * Copyright (c) 2011-2012 Lawrence Teo <lteo@lteo.net>
+ * Copyright (c) 2011-2012 Tiago Cunha <tcunha@gmx.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -83,7 +83,7 @@
 #elif defined(__FreeBSD__)
 #include <sys/tree.h>
 #else
-#include <sys/tree.h>
+#include "tree.h"
 #endif
 
 #include <X11/cursorfont.h>
@@ -6971,17 +6971,40 @@ main(int argc, char *argv[])
        setup_spawn();
 
        /* load config */
-       snprintf(conf, sizeof conf, "%s/.%s", pwd->pw_dir, SWM_CONF_FILE);
-       if (stat(conf, &sb) != -1) {
-               if (S_ISREG(sb.st_mode))
-                       cfile = conf;
-       } else {
-               /* try global conf file */
-               snprintf(conf, sizeof conf, "/etc/%s", SWM_CONF_FILE);
-               if (!stat(conf, &sb))
-                       if (S_ISREG(sb.st_mode))
+       for (i = 0; ; i++) {
+               conf[0] = '\0';
+               switch (i) {
+               case 0:
+                       /* ~ */
+                       snprintf(conf, sizeof conf, "%s/.%s",
+                           pwd->pw_dir, SWM_CONF_FILE);
+                       break;
+               case 1:
+                       /* global */
+                       snprintf(conf, sizeof conf, "/etc/%s",
+                           SWM_CONF_FILE);
+                       break;
+               case 2:
+                       /* ~ compat */
+                       snprintf(conf, sizeof conf, "%s/.%s",
+                           pwd->pw_dir, SWM_CONF_FILE_OLD);
+                       break;
+               case 3:
+                       /* global compat */
+                       snprintf(conf, sizeof conf, "/etc/%s",
+                           SWM_CONF_FILE_OLD);
+                       break;
+               default:
+                       goto noconfig;
+               }
+
+               if (strlen(conf) && stat(conf, &sb) != -1)
+                       if (S_ISREG(sb.st_mode)) {
                                cfile = conf;
+                               break;
+                       }
        }
+noconfig:
 
        /* load conf (if any) and refresh font color in bar graphics contexts */
        if (cfile && conf_load(cfile, SWM_CONF_DEFAULT) == 0)