Annotation of libaitcfg/src/cfgprog.c, revision 1.1.2.2
1.1.2.1 misho 1: #include "global.h"
2: #include "aitcfg.h"
3:
4:
1.1.2.2 ! misho 5: cfg_root_t cfg;
! 6: char cfgname[MAXPATHLEN], section[STRSIZ];
! 7:
! 8:
! 9: static void
! 10: Usage(const char *prog)
! 11: {
! 12: printf( " -= CFGPROG =- ELWIX config tool ver.%s\n"
! 13: "(C)`25 by Michael Pounov <misho@elwix.org>\n"
! 14: "==========================================\n"
! 15: " Syntax: %s [-options] <config> [attribute] [value]\n\n"
! 16: "\t-s <section>\tScope of attribute\n"
! 17: "\t-w\t\tSet and write attribute\n"
! 18: "\t-v\t\tVerbose, more -v more verbosity\n"
! 19: "\t-h\t\tHelp, this help screen!\n",
! 20: PACKAGE_VERSION, prog);
! 21: }
! 22:
1.1.2.1 misho 23: int
1.1.2.2 ! misho 24: Get(const char *prog, int argc, char **argv)
1.1.2.1 misho 25: {
1.1.2.2 ! misho 26: EVERBS(1) printf("Get value for %s in scope %s from config %s\n",
! 27: *argv ? *argv : "*", section, prog);
! 28:
1.1.2.1 misho 29: return 0;
30: }
1.1.2.2 ! misho 31:
! 32: int
! 33: Set(const char *prog, int argc, char **argv)
! 34: {
! 35: if (argc < 2) {
! 36: printf("Error:: missing attribute and value arguments!\n");
! 37: return 1;
! 38: }
! 39:
! 40: EVERBS(1) printf("Set value %s for %s in scope %s from config %s\n",
! 41: argv[1], argv[0], section, prog);
! 42:
! 43: return 0;
! 44: }
! 45:
! 46:
! 47: int
! 48: main(int argc, char **argv)
! 49: {
! 50: int ch;
! 51: int (*run)(const char*, int, char**) = Get;
! 52: const char *prog;
! 53: char *str;
! 54:
! 55: if (!argv || !*argv)
! 56: prog = "cfgprog";
! 57: else if (!(prog = strrchr(*argv, '/')))
! 58: prog = *argv;
! 59: else
! 60: prog++;
! 61:
! 62: while ((ch = getopt(argc, argv, "hvws:")) != -1)
! 63: switch (ch) {
! 64: case 'w':
! 65: run = Set;
! 66: break;
! 67: case 's':
! 68: strlcpy(section, optarg, sizeof section);
! 69: break;
! 70: case 'v':
! 71: e_incVerbose;
! 72: break;
! 73: default:
! 74: Usage(prog);
! 75: return 1;
! 76: }
! 77: argc -= optind;
! 78: argv += optind;
! 79:
! 80: if (!strcmp(prog, "cfg_set"))
! 81: run = Set;
! 82: else if (!strcmp(prog, "cfg_get"))
! 83: run = Get;
! 84:
! 85: if (!argc) {
! 86: printf("Error:: missing config name!\n");
! 87: Usage(prog);
! 88: return 1;
! 89: } else {
! 90: strlcpy(cfgname, *argv, sizeof cfgname);
! 91: argc--;
! 92: argv++;
! 93: }
! 94:
! 95: if (argc && *argv && (str = strchr(*argv, '/'))) {
! 96: *str++ = 0;
! 97: strlcpy(section, *argv, sizeof section);
! 98: *argv = str;
! 99: }
! 100:
! 101: return run(prog, argc, argv);
! 102: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>