tAllow environment variables for the configuration parameters. - rohrpost - A commandline mail client to change the world as we see it.
 (HTM) git clone git://r-36.net/rohrpost
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit 3cf0b9aa7ea814a2e50246c2a3ef91d842d94505
 (DIR) parent 0ffb5eafed724886ae346e18ea9338ebc1e3e5ee
 (HTM) Author: Christoph Lohmann <20h@r-36.net>
       Date:   Sun, 11 Oct 2015 12:13:16 +0200
       
       Allow environment variables for the configuration parameters.
       
       Diffstat:
         arg.h                               |       2 ++
         cfg.c                               |      20 ++++++++++++++++----
         config.mk                           |       2 +-
         mime.c                              |       2 +-
         view.c                              |       2 +-
       
       5 files changed, 21 insertions(+), 7 deletions(-)
       ---
 (DIR) diff --git a/arg.h b/arg.h
       t@@ -51,5 +51,7 @@ extern char *argv0;
                                                (&argv[0][1]) :\
                                                (argc--, argv++, argv[0])))
        
       +#define LNGARG()        &argv[0][0]
       +
        #endif
        
 (DIR) diff --git a/cfg.c b/cfg.c
       t@@ -14,6 +14,7 @@
        #include <sys/stat.h>
        #include <sys/types.h>
        #include <dirent.h>
       +#include <ctype.h>
        
        #include "ind.h"
        #include "arg.h"
       t@@ -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;
       t@@ -143,9 +158,6 @@ config_getstr(config_t *cfg, char *key)
                        rstr = NULL;
                }
        
       -        if (cfg == NULL)
       -                config_free(cfg);
       -
                return rstr;
        }
        
 (DIR) diff --git a/config.mk b/config.mk
       t@@ -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}
 (DIR) diff --git a/mime.c b/mime.c
       t@@ -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);
 (DIR) diff --git a/view.c b/view.c
       t@@ -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) {