*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
-static void conf_set(const char *key, int num, const char *str)
+static void entry_free(entry_t *entry)
+{
+ free(entry->key);
+ if (entry->type == STRING)
+ free(entry->str);
+ free(entry);
+}
+
+static void entry_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)
- free(entry->str);
- free(entry);
+ if ((entry = entry_get(key))) {
+ tdelete(entry, &conf, entry_cmp);
+ entry_free(entry);
char key[256]={}, val[256]={}, fullkey[256]={};
FILE *fd = fopen(path, "rt");
if (!fd) return;
char key[256]={}, val[256]={}, fullkey[256]={};
FILE *fd = fopen(path, "rt");
if (!fd) return;
while (fgets(line, sizeof(line), fd)) {
/* Find special characters */
char *lbrace = strchr( line , '[');
while (fgets(line, sizeof(line), fd)) {
/* Find special characters */
char *lbrace = strchr( line , '[');
section, strtrim(key));
if (!strchr(fullkey, ' ')) {
conf_set_str(fullkey, val);
section, strtrim(key));
if (!strchr(fullkey, ' ')) {
conf_set_str(fullkey, val);
conf_set_int(fullkey, 0);
else
conf_set_str(fullkey, trim);
conf_set_int(fullkey, 0);
else
conf_set_str(fullkey, trim);
/* Configuration file functions */
int conf_get_int(const char *key, int def)
{
/* Configuration file functions */
int conf_get_int(const char *key, int def)
{
- snprintf(conf_path, sizeof(conf_path),
- "%s/%s", getenv("HOME"), ".wmpus");
+ snprintf(conf_path, sizeof(conf_path), "%s/%s",
+ getenv("HOME") ?: getenv("HOMEPATH") ?: ".",
+ ".wmpus");