/*
- * 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
#include "conf.h"
/* Types */
-typedef enum { number, string } type_t;
-
typedef struct {
- type_t type;
+ enum {
+ NUMBER,
+ STRING,
+ } type;
char *key;
union {
int num;
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);
}
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);
}
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 , '[');
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) {
conf_set_int(fullkey, 0);
else
conf_set_str(fullkey, trim);
- printf(" [%s] = [%s]\n", fullkey, trim);
+ //printf(" [%s] = [%s]\n", fullkey, trim);
}
}
}
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;
}
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;
}
{
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();
}