2 * Sherlock Library -- Shell Interface to Configuration Files
4 * (c) 2002 Martin Mares <mj@ucw.cz>
6 * Once we were using this beautiful Shell version, but it turned out
7 * that it doesn't work with nested config files:
9 * eval `sed <cf/sherlock '/^#/d;/^ *$/d;s/ \+$//;
10 * h;s@[^ ]*@@;x;s@[ ].*@@;y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/;G;s/\n//;
11 * /^\[SECTION\]/,/^\[/ {; /^[A-Z]/ { s/^\([^ ]\+\)[ ]*\(.*\)$/SH_\1="\2"/; p; }; };
14 * This software may be freely distributed and used according to the terms
15 * of the GNU Lesser General Public License.
25 static struct cfitem *items;
31 die("Usage: config [-C<configfile>] [-S<section>.<option>=<value>] <section> [@]<item>[=<default>] <item2> ... [*]");
35 report(struct cfitem *item, byte *value)
37 if (flags[item-items])
38 printf("CF_%s[${#CF_%s[*]}]='", item->name, item->name);
40 printf("CF_%s='", item->name);
44 die("Apostrophes are not supported in config of scripts");
51 int main(int argc, char **argv)
58 while (i < argc && argv[i][0] == '-')
63 c = items = alloca(sizeof(struct cfitem) * (argc-i+1));
72 if (!strcmp(argv[i], "*"))
73 items->type = CT_INCOMPLETE_SECTION;
76 char *e = strchr(argv[i], '=');
78 c->type = CT_FUNCTION;
85 printf("declare -a CF_%s ; CF_%s=()\n", c->name, c->name);
95 if (cf_getopt(start, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL) != -1)