#include #include #include #include "conflib.h" extern const char *__progname; static int multiple = 0; static int paths = 0; static int test = 0; static int verbose = 0; static void *conf; static volatile void usage(void) { fprintf(stderr,"Usage: %s tag [args]\n",__progname); exit(1); } static void handleargs(int ac, char **av, int early) { int skip; int errs; skip = 0; errs = 0; for (ac--,av++;ac;ac--,av++) { if (skip > 0) { skip --; continue; } if (**av != '-') { if (! early) conf_read(conf,*av,0); continue; } if (0) { needarg:; fprintf(stderr,"%s: %s needs a following argument\n",__progname,*av); errs ++; continue; } #define WANTARG() do { if (++skip >= ac) goto needarg; } while (0) if (!strcmp(*av,"-config")) { WANTARG(); if (! early) conf_read(conf,av[skip],0); continue; } if (!strcmp(*av,"-configline") || !strcmp(*av,"-set")) { WANTARG(); if (early) conf_line(conf,av[skip],0); continue; } #undef WANTARG fprintf(stderr,"%s: unrecognized option `%s'\n",__progname,*av); errs ++; } if (errs) usage(); } static const char *src(const char *from) { return(from?from:"command line"); } int main(int, char **); int main(int ac, char **av) { const char *val; const char *from; const char **vals; const char **fromv; int n; int i; conf = conf_newstate(); while (1) { ac --; av ++; if (ac < 1) usage(); if (!strcmp(*av,"-m")) { multiple = 1; continue; } if (!strcmp(av[0],"-p")) { paths = 1; continue; } if (!strcmp(av[0],"-t")) { test = 1; continue; } if (!strcmp(av[0],"-v")) { verbose = 1; continue; } break; } handleargs(ac,av,1); handleargs(ac,av,0); conf_check_env(conf,"MDB_CONFIG_DB",0); if (multiple) { if (test) { n = conf_values(conf,av[0],0,0,0); exit(n); } else if (paths) { n = conf_paths(conf,av[0],0,0,0); vals = malloc(n*sizeof(const char *)); fromv = malloc(n*sizeof(const char *)); conf_paths(conf,av[0],vals,fromv,n); } else { n = conf_values(conf,av[0],0,0,0); vals = malloc(n*sizeof(const char *)); fromv = malloc(n*sizeof(const char *)); conf_values(conf,av[0],vals,fromv,n); } for (i=0;i