rohrpost

A commandline mail client to change the world as we see it.
git clone git://r-36.net/rohrpost
Log | Files | Refs | LICENSE

commit bba874fdbfc5e9958ec0ba44d48a7b2493c0b87b
parent 2e0382149c34a197505257418b5660ff98ea9686
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sun,  5 Jan 2014 14:52:04 +0100

Add configuration listing feature.

Diffstat:
cfg.c | 49+++++++++++++++++++++++++++++++++++++++++--------
cfg.h | 1+
config.mk | 2+-
3 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/cfg.c b/cfg.c @@ -13,6 +13,7 @@ #include <libgen.h> #include <sys/stat.h> #include <sys/types.h> +#include <dirent.h> #include "ind.h" #include "arg.h" @@ -71,6 +72,31 @@ config_default(char *cfgn) } void +config_list(void) +{ + char *path; + struct dirent **dirlist; + int ndir; + + path = path_mkrppath(NULL); + + ndir = scandir(path, &dirlist, NULL, alphasort); + free(path); + if (ndir < 0) + edie("scandir"); + for (--ndir; ndir >= 0; ndir--) { + if (!strcmp(dirlist[ndir]->d_name, ".")) + continue; + if (!strcmp(dirlist[ndir]->d_name, "..")) + continue; + if (!strcmp(dirlist[ndir]->d_name, "default")) + continue; + printf("%s\n", dirlist[ndir]->d_name); + } + free(dirlist); +} + +void config_stop(config_t *cfg) { char *path; @@ -163,7 +189,8 @@ configmain(int argc, char *argv[]) DOLIST = 0x04, DODELETE = 0x08, DOSEARCH = 0x10, - DOINIT = 0x20 + DOINIT = 0x20, + DODEFAULT = 0x40 }; status = 0; @@ -180,7 +207,8 @@ configmain(int argc, char *argv[]) status |= DODELETE; break; case 'e': - def = EARGF(configusage()); + def = ARGF(); + status |= DODEFAULT; break; case 'i': status |= DOINIT; @@ -201,13 +229,18 @@ configmain(int argc, char *argv[]) configusage(); } ARGEND; - if (def) { - config_default(def); - if (!(status & BEQUIET)) { - printf("Default configuration set to '%s'.\n", - def); + if (status & DODEFAULT) { + if (def) { + config_default(def); + if (!(status & BEQUIET)) { + printf("Default configuration set to '%s'.\n", + def); + } + return 0; + } else { + config_list(); + return 0; } - return 0; } cfg = config_init(cfgn); diff --git a/cfg.h b/cfg.h @@ -31,6 +31,7 @@ char *config_checkgetstr(config_t *cfg, char *key); config_t *config_init(char *cfgn); void config_stop(config_t *cfg); void config_default(char *cfgn); +void config_list(void); int configmain(int argc, char *argv[]); 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 +CPPFLAGS = -DVERSION=\"${VERSION}\" -D_XOPEN_SOURCE=600 -D_SVID_SOURCE CFLAGS = -g -std=gnu99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} LDFLAGS = -g ${LIBS} #LDFLAGS = -s ${LIBS}