--- libaitcfg/src/cfgprog.c 2025/01/30 12:28:41 1.1.2.1 +++ libaitcfg/src/cfgprog.c 2025/01/30 14:09:54 1.1.2.2 @@ -2,8 +2,101 @@ #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 \n" + "==========================================\n" + " Syntax: %s [-options] [attribute] [value]\n\n" + "\t-s
\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 -main(int argc, char **argv) +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); }