]> Pileus Git - wmpus/blobdiff - conf.c
Update copyright dates
[wmpus] / conf.c
diff --git a/conf.c b/conf.c
index 6a13c4489a83dd561e7b65a980c97f65e8e0621a..24bb54934a017e91c62f80a4ef6ae3f15ea94764 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Andy Spencer <andy753421@gmail.com>
+ * Copyright (c) 2011-2012, Andy Spencer <andy753421@gmail.com>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -23,7 +23,7 @@
 #include "conf.h"
 
 /* Types */
-typedef enum { number, string } type_t;
+typedef enum { NUMBER, STRING } type_t;
 
 typedef struct {
        type_t  type;
@@ -63,7 +63,7 @@ static void conf_set(const char *key, int num, const char *str)
        if ((entry = conf_get(key))) {
                tdelete(entry, &conf, conf_cmp);
                free(entry->key);
-               if (entry->type == string)
+               if (entry->type == STRING)
                        free(entry->str);
                free(entry);
        }
@@ -72,11 +72,11 @@ static void conf_set(const char *key, int num, const char *str)
        entry = new0(entry_t);
        entry->key = strdup(key);
        if (str) {
-               entry->type = string;
+               entry->type = STRING;
                entry->str  = strdup(str);
                printf("set_str: %s = %s\n", key, str);
        } else {
-               entry->type = number;
+               entry->type = NUMBER;
                entry->num  = num;
                printf("set_num: %s = %d\n", key, num);
        }
@@ -225,7 +225,7 @@ static void load_args(int argc, char **argv)
 int conf_get_int(const char *key, int def)
 {
        entry_t *entry = conf_get(key);
-       return entry && entry->type == number
+       return entry && entry->type == NUMBER
                ? entry->num : def;
 }
 
@@ -237,7 +237,7 @@ void conf_set_int(const char *key, int value)
 const char *conf_get_str(const char *key, const char *def)
 {
        entry_t *entry = conf_get(key);
-       return entry && entry->type == string
+       return entry && entry->type == STRING
                ? entry->str : def;
 }
 
@@ -256,8 +256,9 @@ void conf_init(int argc, char **argv)
 {
        conf_argc = argc;
        conf_argv = argv;
-       snprintf(conf_path, sizeof(conf_path),
-               "%s/%s", getenv("HOME"), ".wmpus");
+       snprintf(conf_path, sizeof(conf_path), "%s/%s",
+                       getenv("HOME") ?: getenv("HOMEPATH") ?: ".",
+                       ".wmpus");
        conf_reload();
 }