chiark / gitweb /
+ * TODO list updated somewhat.
[adns.git] / client / adh-opts.c
index 6af9e021b84502a944972689f3242563951cdc7f..772e474f3fe7e1054244641cece4f4fd0b7a648d 100644 (file)
@@ -5,10 +5,10 @@
  */
 /*
  *  This file is
- *    Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
+ *    Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk>
  *
  *  It is part of adns, which is
- *    Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
+ *    Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk>
  *    Copyright (C) 1999 Tony Finch <dot@dotat.at>
  *  
  *  This program is free software; you can redistribute it and/or modify
@@ -32,7 +32,7 @@ int ov_env=1, ov_pipe=0, ov_asynch=0;
 int ov_verbose= 0;
 adns_rrtype ov_type= adns_r_none;
 int ov_search=0, ov_qc_query=0, ov_qc_anshost=0, ov_qc_cname=1;
-int ov_tcp=0, ov_cname=0;
+int ov_tcp=0, ov_cname=0, ov_format=fmt_default;
 char *ov_id= 0;
 struct perqueryflags_remember ov_pqfr = { 1,1,1, tm_none };
 
@@ -44,6 +44,14 @@ static const struct optioninfo global_options[]= {
     "f", "pipe",           &ov_pipe, 1 },
   { ot_flag,             "Allow answers to be reordered",
     "a", "asynch",         &ov_asynch, 1 },
+  
+  { ot_desconly, "answer/error output format and destination (see below):" },
+  { ot_value,            "Answers to stdout, errors as messages to stderr (default)",
+    "Fs", "fmt-simple",    &ov_format, fmt_simple },
+  { ot_value,            "Answers and errors both to stdout in parseable format",
+    "Fi", "fmt-inline",    &ov_format, fmt_inline },
+  { ot_value,            "Fully-parseable output format (default for --asynch)",
+    "Fa", "fmt-asynch",    &ov_format, fmt_asynch },
                         
   { ot_desconly, "global verbosity level:" },
   { ot_value,            "Do not print anything to stderr",
@@ -65,7 +73,9 @@ static const struct optioninfo perquery_options[]= {
   { ot_funcarg,          "Query type (see below)",
     "t", "type",           0,0, &of_type, "type" },
   { ot_funcarg,          "Do reverse query (address -> name lookup)",
-    "i", "ptr",            0,0, &of_type, "addr" },
+    "i", "ptr",            0,0, &of_ptr, "addr" },
+  { ot_funcarg2,         "Lookup in in-addr-like `zone' (eg MAPS RBL)",
+    0, "reverse",          0,0, &of_reverse, "addr","zone" },
 
   { ot_desconly, "per-query binary options:" },
   { ot_flag,             "Use the search list",
@@ -104,7 +114,7 @@ static const struct optioninfo perquery_options[]= {
   { ot_desconly, "asynchronous/pipe mode options:" },
   { ot_funcarg,          "Set <id>, default is decimal sequence starting 0",
     0, "asynch-id",        0,0, &of_asynch_id, "id" },
-  { ot_funcarg,          "Cancel the query with id <id>",
+  { ot_funcarg,          "Cancel the query with id <id> (no error if not found)",
     0, "cancel-id",        0,0, &of_cancel_id, "id" },
 
   { ot_end }
@@ -184,6 +194,15 @@ static void printusage(void) {
                 oip->desc);
        }
        break;
+      case ot_funcarg2:
+       assert(!oip->sopt);
+       l= (maxlopt + maxsopt - 2 -
+           (strlen(oip->lopt) + strlen(oip->argdesc) + strlen(oip->argdesc2)));
+         printf(" --%s <%s> <%s>%*s%s\n",
+                oip->lopt, oip->argdesc, oip->argdesc2,
+                l>2 ? l : 2, "",
+                oip->desc);
+       break;
       case ot_desconly:
        printf("%s\n", oip->desc);
        break;
@@ -216,11 +235,12 @@ static void printusage(void) {
        "or if the <owner> domain refers to a CNAME and --show-cname is on\n"
        "   [<owner>] [<ttl>] CNAME <cname>\n"
        "   [<cname>] [<ttl>] <type> <data>\n"
-       "When a query fails you get a line like this (broken here for readability):\n"
+       "When a query fails you get an error message to stderr (with --fmt-simple).\n"
+       "Specify --fmt-inline for lines like this (broken here for readability):\n"
        "   ; failed <statustype> <statusnum> <statusabbrev> \\\n"
        "       [<owner>] [<ttl>] [<cname>] \"<status string>\"\n"
-       "\n"
-       "If you use --asynch each answer (success or failure) is preceded by a line\n"
+       "If you use --fmt-asynch, which is the default for --asynch,\n"
+       "each answer (success or failure) is preceded by a line\n"
        "   <id> <nrrs> <statustype> <statusnum> <statusabbrev> \\\n"
        "       [<owner>] [<ttl>] [<cname>] \"<status string>\"\n"
        "where <nrrs> is the number of RRs that follow and <cname> will be `$' or\n"
@@ -247,7 +267,7 @@ static void printusage(void) {
   if (ferror(stdout)) sysfail("write usage message",errno);
 }
 
-void of_help(const struct optioninfo *oi, const char *arg) {
+void of_help(const struct optioninfo *oi, const char *arg, const char *arg2) {
   printusage();
   if (fclose(stdout)) sysfail("finish writing output",errno);
   exit(0);
@@ -285,26 +305,43 @@ static const struct optioninfo *find(const char **optp,
                                     const char *prefix,
                                     comparer_type *comparer) {
   const struct optioninfo *oip;
+  const char *opt;
 
+  opt= *optp;
   oip= find1(optp,perquery_options,comparer);
   if (oip) return oip;
   oip= find1(optp,global_options,comparer);
-  if (!oip) usageerr("unknown option %s%s",prefix,*optp);
-  if (ads) usageerr("global option %s%s specified after query domain(s)",prefix,*optp);
+  if (!oip) usageerr("unknown option %s%s",prefix,opt);
+  if (ads) usageerr("global option %s%s specified after query domain(s)",prefix,opt);
   return oip;
 }
 
 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, int invert,
+           const char *arg, const char *arg2) {
   switch (oip->type) {
-  case ot_flag: case ot_value:
+  case ot_flag:
+    assert(!arg);
+    *oip->storep= !invert;
+    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);
+  case ot_func: case ot_funcarg: case ot_funcarg2:
+    if (invert) noninvert(oip);
+    oip->func(oip,arg,arg2);
     return;
   default:
     abort();