commit a6963a776475852f96f9e579bff9223b4779d380
parent 8baae4976cc9f03cd1c03e9c06c242de5ce137b2
Author: Christoph Lohmann <20h@r-36.net>
Date: Wed, 26 Nov 2014 19:27:19 +0100
Add a way to display the configuration name.
Diffstat:
cfg.c | | | 20 | +++++++++++++++++--- |
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/cfg.c b/cfg.c
@@ -39,7 +39,11 @@ config_init(char *cfgn)
cfg->path = memdup(path, strlen(path)+1);
free(path);
- cfg->name = memdup(cfgn, strlen(cfgn)+1);
+ if (cfg->name == NULL) {
+ cfg->name = memdup("default", 8);
+ } else {
+ cfg->name = memdup(cfgn, strlen(cfgn)+1);
+ }
return cfg;
}
@@ -171,7 +175,7 @@ void
configusage(void)
{
die("usage: %s [-hiqv] [-c cfg] [-e cfg|-l|key"
- " [value]]|-d key|-s regex]\n", argv0);
+ " [value]]|-d key|-s regex|-n]\n", argv0);
}
int
@@ -190,7 +194,8 @@ configmain(int argc, char *argv[])
DODELETE = 0x08,
DOSEARCH = 0x10,
DOINIT = 0x20,
- DODEFAULT = 0x40
+ DODEFAULT = 0x40,
+ DONAMECFG = 0x80
};
status = 0;
@@ -213,6 +218,9 @@ configmain(int argc, char *argv[])
case 'i':
status |= DOINIT;
break;
+ case 'n':
+ status |= DONAMECFG;
+ break;
case 'q':
status |= BEQUIET;
break;
@@ -245,6 +253,12 @@ configmain(int argc, char *argv[])
cfg = config_init(cfgn);
+ if (status & DONAMECFG) {
+ if (cfg->name != NULL)
+ printf("%s\n", cfg->name);
+ return 0;
+ }
+
if (status & DOLIST) {
if (config_len(cfg) > 0) {
llist_sort(cfg->values);