chiark / gitweb /
bugfixes
authorian <ian>
Tue, 12 Oct 1999 23:16:18 +0000 (23:16 +0000)
committerian <ian>
Tue, 12 Oct 1999 23:16:18 +0000 (23:16 +0000)
client/adh-main.c
client/adh-opts.c
client/adh-query.c
client/adnshost.h

index 33b1f59b9b2431337d753b7ca9643f4c0cc1ecbf..121c195ded555e14153d7d10e2a0c5056b5a4343 100644 (file)
@@ -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] != '-' */
index 6af9e021b84502a944972689f3242563951cdc7f..e7704a1341ac8faf8c17d02227b4164acdee3477 100644 (file)
@@ -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();
index f2dd5c1b4b971ec9adc04e94e87ce8040d5ccd58..711b489d730028c31b92740abe9a30f12be9196a 100644 (file)
@@ -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);
index d512b4f184a397b6919bd204b9403b26076c592d..919a758adbf179b58d3ac2b69ca62878ae5b6242 100644 (file)
@@ -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 */