clients/, disobedience/: Add `-u' option to override user config file.
[disorder] / disobedience / settings.c
index 8355712..18af6c1 100644 (file)
@@ -2,20 +2,18 @@
  * This file is part of Disobedience
  * Copyright (C) 2007, 2008 Richard Kettlewell
  *
- * This program is free software; you can redistribute it and/or modify
+ * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 /** @file disobedience/settings.c
  * @brief Disobedience settings
@@ -152,11 +150,15 @@ void init_styles(void) {
 }
 
 void save_settings(void) {
-  char *dir, *path, *tmp;
+  const char *dir;
+  char *path, *tmp;
   FILE *fp = 0;
   size_t n, m, c;
 
-  byte_xasprintf(&dir, "%s/.disorder", getenv("HOME"));
+  if(!(dir = profile_directory())) {
+    fpopup_msg(GTK_MESSAGE_ERROR, "failed to find home directory");
+    goto done;
+  }
   byte_xasprintf(&path, "%s/disobedience", dir);
   byte_xasprintf(&tmp, "%s.tmp", path);
   mkdir(dir, 02700);                    /* make sure directory exists */
@@ -208,8 +210,9 @@ void load_settings(void) {
   int nvec;
   size_t n, m, c;
 
-  byte_xasprintf(&path, "%s/.disorder/disobedience", getenv("HOME"));
-  if(!(fp = fopen(path, "r"))) {
+  if(!(path = profile_filename("disobedience")))
+    fpopup_msg(GTK_MESSAGE_ERROR, "failed to find home directory");
+  else if(!(fp = fopen(path, "r"))) {
     if(errno != ENOENT)
       fpopup_msg(GTK_MESSAGE_ERROR, "error opening %s: %s",
                  path, strerror(errno));
@@ -221,25 +224,25 @@ void load_settings(void) {
       if(!strcmp(vec[0], "color")) {
         GdkColor *color;
         if(nvec != 7) {
-          error(0, "%s: malformed '%s' command", path, vec[0]);
+          disorder_error(0, "%s: malformed '%s' command", path, vec[0]);
           continue;
         }
         for(n = 0; n < NSTYLES && strcmp(styles[n].name, vec[1]); ++n)
           ;
         if(n >= NSTYLES) {
-          error(0, "%s: unknown style '%s'", path, vec[1]);
+          disorder_error(0, "%s: unknown style '%s'", path, vec[1]);
           continue;
         }
         for(m = 0; m < NSTATES && strcmp(states[m], vec[2]); ++m)
           ;
         if(m >= NSTATES) {
-          error(0, "%s: unknown state '%s'", path, vec[2]);
+          disorder_error(0, "%s: unknown state '%s'", path, vec[2]);
           continue;
         }
         for(c = 0; c < NCOLORS && strcmp(colors[c].name, vec[3]); ++c)
           ;
         if(c >= NCOLORS) {
-          error(0, "%s: unknown color '%s'", path, vec[3]);
+          disorder_error(0, "%s: unknown color '%s'", path, vec[3]);
           continue;
         }
         color = (GdkColor *)((char *)styles[n].style + colors[c].offset) + m;
@@ -248,13 +251,13 @@ void load_settings(void) {
         color->blue = strtoul(vec[6], 0, 0);
       } else if(!strcmp(vec[0], "browser")) {
         if(nvec != 2) {
-          error(0, "%s: malformed '%s' command", path, vec[0]);
+          disorder_error(0, "%s: malformed '%s' command", path, vec[0]);
           continue;
         }
         browser = vec[1];
       } else
         /* mention errors but otherwise ignore them */
-        error(0, "%s: unknown command '%s'", path, vec[0]);
+        disorder_error(0, "%s: unknown command '%s'", path, vec[0]);
     }
     if(ferror(fp)) {
       fpopup_msg(GTK_MESSAGE_ERROR, "error reading %s: %s",