From 0b6f56ccd83f0715e55855b4ddbdc7db897c4a7a Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 12 Oct 1999 23:16:18 +0000 Subject: [PATCH] bugfixes --- client/adh-main.c | 23 +++++++++++++++-------- client/adh-opts.c | 20 +++++++++++++++++--- client/adh-query.c | 4 ++-- client/adnshost.h | 2 +- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/client/adh-main.c b/client/adh-main.c index 33b1f59..121c195 100644 --- a/client/adh-main.c +++ b/client/adh-main.c @@ -83,25 +83,32 @@ int main(int argc, const char *const *argv) { adns_query qu; void *qun_v; adns_answer *answer; - int r, maxfd; + int r, maxfd, invert; fd_set readfds, writefds, exceptfds; while ((arg= *++argv)) { - if (arg[0] == '-') { - if (arg[1] == '-') { - oip= opt_findl(arg+2); + if (arg[0] == '-' || arg[0] == '+') { + if (arg[0] == '-' && arg[1] == '-') { + if (!strncmp(arg,"--no-",5)) { + invert= 1; + oip= opt_findl(arg+5); + } else { + invert= 0; + oip= opt_findl(arg+2); + } if (oip->type == ot_funcarg) { arg= *++argv; if (!arg) usageerr("option --%s requires a value argument",oip->lopt); } else { arg= 0; } - opt_do(oip,arg); - } else if (arg[1] == 0) { + opt_do(oip,arg,invert); + } else if (arg[0] == '-' && arg[1] == 0) { arg= *++argv; if (!arg) usageerr("option `-' must be followed by a domain"); domain_do_arg(arg); } else { /* arg[1] != '-', != '\0' */ + invert= (arg[0] == '+'); ++arg; while (*arg) { oip= opt_finds(&arg); @@ -110,11 +117,11 @@ int main(int argc, const char *const *argv) { arg= *++argv; if (!arg) usageerr("option -%s requires a value argument",oip->sopt); } + opt_do(oip,arg,invert); arg= ""; } else { - arg= 0; + opt_do(oip,0,invert); } - opt_do(oip,arg); } } } else { /* arg[0] != '-' */ diff --git a/client/adh-opts.c b/client/adh-opts.c index 6af9e02..e7704a1 100644 --- a/client/adh-opts.c +++ b/client/adh-opts.c @@ -297,14 +297,28 @@ static const struct optioninfo *find(const char **optp, const struct optioninfo *opt_findl(const char *opt) { return find(&opt,"--",oc_long); } const struct optioninfo *opt_finds(const char **optp) { return find(optp,"-",oc_short); } -void opt_do(const struct optioninfo *oip, const char *arg) { +static void noninvert(const struct optioninfo *oip) NONRETURNING; +static void noninvert(const struct optioninfo *oip) { + usageerr("option %s%s%s%s%s may not be inverted", + oip->sopt ? "-" : "", oip->sopt ? oip->sopt : "", + oip->lopt && oip->sopt ? " / " : "", + oip->lopt ? "--" : "", oip->lopt ? oip->lopt : ""); +} + +void opt_do(const struct optioninfo *oip, const char *arg, int invert) { switch (oip->type) { - case ot_flag: case ot_value: + case ot_flag: + assert(!arg); + *oip->storep= invert ? !oip->value : oip->value; + return; + case ot_value: assert(!arg); + if (invert) noninvert(oip); *oip->storep= oip->value; return; case ot_func: case ot_funcarg: - oip->func(oip,0); + if (invert) noninvert(oip); + oip->func(oip,arg); return; default: abort(); diff --git a/client/adh-query.c b/client/adh-query.c index f2dd5c1..711b489 100644 --- a/client/adh-query.c +++ b/client/adh-query.c @@ -159,11 +159,11 @@ void query_done(struct query_node *qun, adns_answer *answer) { st= answer->status; nrrs= answer->nrrs; if (ov_asynch) { - if (printf("%s %d", qun->id, nrrs) == EOF) outerr(); + if (printf("%s %d ", qun->id, nrrs) == EOF) outerr(); print_status(st,qun,answer); } else { if (st) { - if (fputs("; failed",stdout) == EOF) outerr(); + if (fputs("; failed ",stdout) == EOF) outerr(); print_status(st,qun,answer); } else if (answer->cname) { print_owner_ttl(qun,answer); diff --git a/client/adnshost.h b/client/adnshost.h index d512b4f..919a758 100644 --- a/client/adnshost.h +++ b/client/adnshost.h @@ -76,7 +76,7 @@ extern optfunc of_help, of_type, of_asynch_id, of_cancel_id; const struct optioninfo *opt_findl(const char *opt); const struct optioninfo *opt_finds(const char **optp); -void opt_do(const struct optioninfo *oip, const char *arg); +void opt_do(const struct optioninfo *oip, const char *arg, int invert); /* declarations related to query processing */ -- 2.30.2