X-Git-Url: http://pileus.org/git/?p=wmpus;a=blobdiff_plain;f=conf.c;h=407165546c72e4c83c8234672753aef4bac011f7;hp=6a13c4489a83dd561e7b65a980c97f65e8e0621a;hb=6676472c287a8163d53b2ba14ca8ec39bf7443eb;hpb=ed3dbd05944250855712283a1c10419bf15f7c12 diff --git a/conf.c b/conf.c index 6a13c44..4071655 100644 --- a/conf.c +++ b/conf.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Andy Spencer + * Copyright (c) 2011-2012, Andy Spencer * * 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,13 +72,13 @@ 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); + //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); + //printf("set_num: %s = %d\n", key, num); } tsearch(entry, &conf, conf_cmp); } @@ -103,7 +103,7 @@ static void load_file(const char *path) char key[256]={}, val[256]={}, fullkey[256]={}; FILE *fd = fopen(path, "rt"); if (!fd) return; - printf("load_file: %s\n", path); + //printf("load_file: %s\n", path); while (fgets(line, sizeof(line), fd)) { /* Find special characters */ char *lbrace = strchr( line , '['); @@ -127,7 +127,7 @@ static void load_file(const char *path) section, strtrim(key)); if (!strchr(fullkey, ' ')) { conf_set_str(fullkey, val); - printf(" [%s] = [%s]\n", fullkey, val); + //printf(" [%s] = [%s]\n", fullkey, val); } } else if (section[0] && equal) { @@ -147,7 +147,7 @@ static void load_file(const char *path) conf_set_int(fullkey, 0); else conf_set_str(fullkey, trim); - printf(" [%s] = [%s]\n", fullkey, trim); + //printf(" [%s] = [%s]\n", fullkey, trim); } } } @@ -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(); }