#include "global.h"
#include "aitcfg.h"
cfg_root_t cfg;
char cfgname[MAXPATHLEN], section[STRSIZ];
static void
Usage(const char *prog)
{
printf( " -= CFGPROG =- ELWIX config tool ver.%s\n"
"(C)`25 by Michael Pounov <misho@elwix.org>\n"
"==========================================\n"
" Syntax: %s [-options] <config> [attribute] [value]\n\n"
"\t-s <section>\tScope of attribute\n"
"\t-w\t\tSet and write attribute\n"
"\t-v\t\tVerbose, more -v more verbosity\n"
"\t-h\t\tHelp, this help screen!\n",
PACKAGE_VERSION, prog);
}
int
Get(const char *prog, int argc, char **argv)
{
EVERBS(1) printf("Get value for %s in scope %s from config %s\n",
*argv ? *argv : "*", section, prog);
return 0;
}
int
Set(const char *prog, int argc, char **argv)
{
if (argc < 2) {
printf("Error:: missing attribute and value arguments!\n");
return 1;
}
EVERBS(1) printf("Set value %s for %s in scope %s from config %s\n",
argv[1], argv[0], section, prog);
return 0;
}
int
main(int argc, char **argv)
{
int ch;
int (*run)(const char*, int, char**) = Get;
const char *prog;
char *str;
if (!argv || !*argv)
prog = "cfgprog";
else if (!(prog = strrchr(*argv, '/')))
prog = *argv;
else
prog++;
while ((ch = getopt(argc, argv, "hvws:")) != -1)
switch (ch) {
case 'w':
run = Set;
break;
case 's':
strlcpy(section, optarg, sizeof section);
break;
case 'v':
e_incVerbose;
break;
default:
Usage(prog);
return 1;
}
argc -= optind;
argv += optind;
if (!strcmp(prog, "cfg_set"))
run = Set;
else if (!strcmp(prog, "cfg_get"))
run = Get;
if (!argc) {
printf("Error:: missing config name!\n");
Usage(prog);
return 1;
} else {
strlcpy(cfgname, *argv, sizeof cfgname);
argc--;
argv++;
}
if (argc && *argv && (str = strchr(*argv, '/'))) {
*str++ = 0;
strlcpy(section, *argv, sizeof section);
*argv = str;
}
return run(prog, argc, argv);
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>