#include <stdio.h>
#include <string.h>
+static struct cfitem *items;
+static byte *flags;
+
static void
help(void)
{
- die("Usage: config [-C<configfile>] [-S<section>.<option>=<value>] <section> <item>[=<default>] <item2> ... [*]");
+ die("Usage: config [-C<configfile>] [-S<section>.<option>=<value>] <section> [@]<item>[=<default>] <item2> ... [*]");
+}
+
+static byte *
+report(struct cfitem *item, byte *value)
+{
+ if (flags[item-items])
+ printf("CF_%s[${#CF_%s[*]}]='", item->name, item->name);
+ else
+ printf("CF_%s='", item->name);
+ while (*value)
+ {
+ if (*value == '\'')
+ die("Apostrophes are not supported in config of scripts");
+ putchar(*value++);
+ }
+ puts("'");
+ return NULL;
}
int main(int argc, char **argv)
{
int i = 1;
int start;
- struct cfitem *items, *c;
- byte **vars;
+ struct cfitem *c;
log_init("config");
while (i < argc && argv[i][0] == '-')
help();
start = i;
c = items = alloca(sizeof(struct cfitem) * (argc-i+1));
- vars = alloca(sizeof(byte *) * argc);
+ flags = alloca(argc);
+ bzero(flags, argc);
c->name = argv[i];
c->type = CT_SECTION;
c->var = NULL;
items->type = CT_INCOMPLETE_SECTION;
else
{
- byte *e = strchr(argv[i], '=');
+ char *e = strchr(argv[i], '=');
+ c->name = argv[i];
+ c->type = CT_FUNCTION;
+ c->var = report;
if (e)
*e++ = 0;
- else
- e = "";
- c->name = argv[i];
- c->type = CT_STRING;
- c->var = &vars[i];
- *(byte **)c->var = e;
+ if (*c->name == '@')
+ {
+ c->name++;
+ printf("declare -a CF_%s ; CF_%s=()\n", c->name, c->name);
+ flags[c-items] = 1;
+ }
+ if (e)
+ report(c, e);
c++;
}
}
cf_register(items);
if (cf_getopt(start, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL) != -1)
help();
-
- c = items+1;
- while (c->type)
- {
- printf("CF_%s=\"%s\"\n", c->name, *(byte **)c->var);
- c++;
- }
-
return 0;
}