commit 3cf0b9aa7ea814a2e50246c2a3ef91d842d94505
parent 0ffb5eafed724886ae346e18ea9338ebc1e3e5ee
Author: Christoph Lohmann <20h@r-36.net>
Date: Sun, 11 Oct 2015 12:13:16 +0200
Allow environment variables for the configuration parameters.
Diffstat:
5 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/arg.h b/arg.h
@@ -51,5 +51,7 @@ extern char *argv0;
(&argv[0][1]) :\
(argc--, argv++, argv[0])))
+#define LNGARG() &argv[0][0]
+
#endif
diff --git a/cfg.c b/cfg.c
@@ -14,6 +14,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
+#include <ctype.h>
#include "ind.h"
#include "arg.h"
@@ -131,7 +132,21 @@ char *
config_getstr(config_t *cfg, char *key)
{
llistelem_t *selitem;
- char *rstr;
+ char *rstr, *envval, *ukey;
+ int i;
+
+ /*
+ * The environment is:
+ * RP${KEY}
+ */
+ ukey = smprintf("RP%s", key);
+ for (i = 2; i < strlen(ukey); i++)
+ ukey[i] = (char)toupper(ukey[i]);
+
+ envval = getenv(ukey);
+ free(ukey);
+ if (envval != NULL)
+ return memdups(envval);
if (cfg == NULL)
return NULL;
@@ -143,9 +158,6 @@ config_getstr(config_t *cfg, char *key)
rstr = NULL;
}
- if (cfg == NULL)
- config_free(cfg);
-
return rstr;
}
diff --git a/config.mk b/config.mk
@@ -14,7 +14,7 @@ INCS = -I. -I/usr/include
LIBS = -L/usr/lib -lc -lssl -lcrypto -lz -ldl
# flags
-CPPFLAGS = -DVERSION=\"${VERSION}\" -D_XOPEN_SOURCE=600 -D_DEFAULT_SOURCE -D_GNU_SOURCE
+CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -D_XOPEN_SOURCE -D_GNU_SOURCE
CFLAGS = -g -std=gnu99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
LDFLAGS = -g ${LIBS}
#LDFLAGS = -s ${LIBS}
diff --git a/mime.c b/mime.c
@@ -191,7 +191,7 @@ mime_decodeheaderext(char *value)
ast[0] = '\0';
slen = strlen(str);
- if (slen == NULL) {
+ if (slen == 0) {
free(work);
free(ret);
return memdupz("", 1);
diff --git a/view.c b/view.c
@@ -347,7 +347,7 @@ viewmain(int argc, char *argv[])
if (selected == NULL) {
selected = config_checkgetstr(cfg, "selected");
} else {
- selected = memdup(selected, strlen(selected)+1);
+ selected = memdups(selected);
}
}
if (cfg->name != NULL) {