chiark / gitweb /
Support --version in utility programs.
authorian <ian>
Sun, 17 Sep 2000 14:09:02 +0000 (14:09 +0000)
committerian <ian>
Sun, 17 Sep 2000 14:09:02 +0000 (14:09 +0000)
Makefile.in
README
README.html
changelog
client/adh-opts.c
client/adnshost.h
client/adnslogres.c
client/adnsresfilter.c
client/client.h [new file with mode: 0644]

index b920d4dbfc3240954e687622702d30366010aaab..869bfaf77e9c3aabb7c3561a65a78cf483e915d3 100644 (file)
 #  along with this program; if not, write to the Free Software Foundation,
 #  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 
+# Remember to change ADNS_VERSION_STRING in client/client.h too, and
+# possibly library soname (MAJOR and MINOR in settings.make.in).
 DISTVERSION=   pre-1.0-1
+
 srcdir=                @srcdir@
 VPATH=         @srcdir@
 
diff --git a/README b/README
index b812766c4e2308831a587fd7fd7faf9ee4f824d4..e98c114c5bcaf53e42bd29f86e5727048c22c8a0 100644 (file)
--- a/README
+++ b/README
@@ -147,7 +147,7 @@ References
    4. http://www.chiark.greenend.org.uk/~ian/adns/
    5. http://www.chiark.greenend.org.uk/~ian/adns/adns.tar.gz
    6. http://www.chiark.greenend.org.uk/~ian/adns/adns.h.txt
-   7. http://www.chiark.greenend.org.uk/~ian/adns/adnsresfilter.txt
+   7. http://www.chiark.greenend.org.uk/~ian/adns/adnshost.txt
    8. ftp://ftp.chiark.greenend.org.uk/users/ian/adns/
    9. http://www.chiark.greenend.org.uk/~ian/adns/ftp/
   10. http://www.chiark.greenend.org.uk/ucgi/~ijackson/cvsweb/adns/
index fc9ce4fad7d161411c644e39a464e12050ce1760..760c2780411168d5bc9c82bf54156d3cc5db7d19 100644 (file)
@@ -140,7 +140,7 @@ are:
     release</A> as a gzipped tarfile.
 <li><A href="http://www.chiark.greenend.org.uk/~ian/adns/adns.h.txt">adns.h</A>
     API header file with comments, and
-    <A href="http://www.chiark.greenend.org.uk/~ian/adns/adnsresfilter.txt">usage
+    <A href="http://www.chiark.greenend.org.uk/~ian/adns/adnshost.txt">usage
     message for adnshost</A> (currently there is no manual, sorry).
 <li>All versions released so far are also available via
     <A href="ftp://ftp.chiark.greenend.org.uk/users/ian/adns/">anonymous
index fb40fbc001374b3bee2ec61dabc24b77e151824a..c546adc2448323b5b7d290f794b9b933209f85f6 100644 (file)
--- a/changelog
+++ b/changelog
@@ -10,7 +10,7 @@ adns (1.0); urgency=medium
   * adnshost, adnslogres, adnsresfilter have options for config override. 
   * adnsresfilter has --debug option.
   * Improvements to adnslogres (incl. new -c option) from Tony Finch.
-  * adnslogres has --help option.
+  * adnslogres has --help option, all utilities support --version.
   * Documentation improved somewhat, including new GPL-vs-LGPL file.
 
   Changes for non-BETA release:
index fa5cceb7b072aa6894db2f2f5a50cfcda765878f..9805e5e8492440ef01ee7e21c9dd0494ed7d329d 100644 (file)
@@ -64,6 +64,8 @@ static const struct optioninfo global_options[]= {
   { ot_desconly, "other global options:" },
   { ot_funcarg,          "Configuration to use instead of /etc/resolv.conf",
     0, "config",           0,0, of_config, "<config-text>" },
+  { ot_func,             "Print version number",
+    0, "version",          0,0, of_version },
   { ot_func,             "Print usage information",
     0, "help",             0,0, of_help },
 
@@ -269,6 +271,10 @@ static void printusage(void) {
   if (ferror(stdout)) sysfail("write usage message",errno);
 }
 
+void of_version(const struct optioninfo *oi, const char *arg, const char *arg2) {
+  VERSION_PRINT_QUIT("adnshost");
+}
+
 void of_help(const struct optioninfo *oi, const char *arg, const char *arg2) {
   printusage();
   if (fclose(stdout)) sysfail("finish writing output",errno);
index d88c2a1a63610a843c846aa2ebfd8aee44cff6b5..a8da4ff1a7181771ba3bd0b14b2a81eef78a850d 100644 (file)
@@ -46,6 +46,7 @@
 #include "config.h"
 #include "adns.h"
 #include "dlist.h"
+#include "client.h"
 
 #ifdef ADNS_REGRESS_TEST
 # include "hredirect.h"
@@ -84,7 +85,7 @@ extern int ov_tcp, ov_cname, ov_format;
 extern char *ov_id;
 extern struct perqueryflags_remember ov_pqfr;
 
-extern optfunc of_config, of_help, of_type, of_ptr, of_reverse;
+extern optfunc of_config, of_version, of_help, of_type, of_ptr, of_reverse;
 extern optfunc of_asynch_id, of_cancel_id;
 
 const struct optioninfo *opt_findl(const char *opt);
@@ -116,8 +117,6 @@ void outerr(void) NONRETURNING;
 void *xmalloc(size_t sz);
 char *xstrsave(const char *str);
 
-void quitnow(int rc) NONRETURNING;
-
 extern int rcode;
 extern const char *config_text; /* 0 => use defaults */
 
index a91127b128b62acdea5654ad918407c0ab0fdf45..2f13fb02fbca246ff6143f2c003c13f6a2d7aa9d 100644 (file)
@@ -46,6 +46,7 @@ static const char * const cvsid =
 
 #include "config.h"
 #include "adns.h"
+#include "client.h"
 
 #ifdef ADNS_REGRESS_TEST
 # include "hredirect.h"
@@ -219,8 +220,13 @@ static void proclog(FILE *inf, FILE *outf, int maxpending, int opts) {
 }
 
 static void printhelp(FILE *file) {
-  fprintf(file, "usage: %s [-d] [-p] [-c concurrency] [-C config] [logfile]\n",
-         progname);
+  fputs("usage: adnslogres [<options>] [<logfile>]\n"
+       "       adnslogres --version|--help\n"
+       "options: -c <concurrency>  set max number of outstanding queries\n"
+       "         -p                use poll(2) instead of select(2)\n"
+       "         -d                turn on debugging\n"
+       "         -C <config>       use instead of contents of resolv.conf\n",
+       stdout);
 }
 
 static void usage(void) {
@@ -233,8 +239,14 @@ int main(int argc, char *argv[]) {
   extern char *optarg;
   FILE *inf;
 
-  if (argv[1] && !strcmp(argv[1],"--help")) {
-    printhelp(stdout);
+  if (argv[1] && !strncmp(argv[1],"--",2)) {
+    if (!strcmp(argv[1],"--help")) {
+      printhelp(stdout);
+    } else if (!strcmp(argv[1],"--version")) {
+      fputs(VERSION_MESSAGE("adnslogres"),stdout);
+    } else {
+      usage();
+    }
     if (ferror(stdout) || fclose(stdout)) { perror("stdout"); exit(1); }
     exit(0);
   }
index 3a3cacf96d6997aca88385d844cfe8869417027e..aec3889bacb8a9d9122be6ec63fbbba4f35e7f51 100644 (file)
@@ -41,6 +41,7 @@
 #include "adns.h"
 #include "dlist.h"
 #include "tvarith.h"
+#include "client.h"
 
 #ifdef ADNS_REGRESS_TEST
 # include "hredirect.h"
@@ -92,8 +93,7 @@ static int nonblock(int fd, int isnonblock) {
   return 0;
 }
 
-static void quit(int exitstatus) NONRETURNING;
-static void quit(int exitstatus) {
+void quitnow(int exitstatus) {
   nonblock(0,0);
   nonblock(1,0);
   exit(exitstatus);
@@ -102,7 +102,7 @@ static void quit(int exitstatus) {
 static void sysfail(const char *what) NONRETURNING;
 static void sysfail(const char *what) {
   fprintf(stderr,"adnsresfilter: system call failed: %s: %s\n",what,strerror(errno));
-  quit(2);
+  quitnow(2);
 }
 
 static void *xmalloc(size_t sz) {
@@ -116,7 +116,7 @@ static void outputerr(void) { sysfail("write to stdout"); }
 
 static void usage(void) {
   if (printf("usage: adnsresfilter [<options ...>]\n"
-            "       adnsresfilter  -h|--help\n"
+            "       adnsresfilter  -h|--help | --version\n"
             "options: -t<milliseconds>|--timeout <milliseconds>\n"
             "         -w|--wait        (always wait for queries to time out or fail)\n"
             "         -b|--brackets    (require [...] around IP addresses)\n"
@@ -134,13 +134,13 @@ static void usageerr(const char *why) NONRETURNING;
 static void usageerr(const char *why) {
   fprintf(stderr,"adnsresfilter: bad usage: %s\n",why);
   usage();
-  quit(1);
+  quitnow(1);
 }
 
 static void adnsfail(const char *what, int e) NONRETURNING;
 static void adnsfail(const char *what, int e) {
   fprintf(stderr,"adnsresfilter: adns call failed: %s: %s\n",what,strerror(e));
-  quit(2);
+  quitnow(2);
 }
 
 static void settimeout(const char *arg) {
@@ -174,7 +174,9 @@ static void parseargs(const char *const *argv) {
       } else if (!strcmp(arg,"--debug")) {
        initflags |= adns_if_debug;
       } else if (!strcmp(arg,"--help")) {
-       usage(); quit(0);
+       usage(); quitnow(0);
+      } else if (!strcmp(arg,"--version")) {
+       VERSION_PRINT_QUIT("adnsresfilter"); quitnow(0);
       } else {
        usageerr("unknown long option");
       }
@@ -202,7 +204,7 @@ static void parseargs(const char *const *argv) {
          break;
        case 'h':
          usage();
-         quit(0);
+         quitnow(0);
        default:
          usageerr("unknown short option");
        }
diff --git a/client/client.h b/client/client.h
new file mode 100644 (file)
index 0000000..2e74b12
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * clients.h
+ * - useful declarations and definitions for adns client programs
+ */
+/*
+ *  This file is
+ *    Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk>
+ *
+ *  It is part of adns, which is
+ *    Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk>
+ *    Copyright (C) 1999-2000 Tony Finch <dot@dotat.at>
+ *  
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *  
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *  
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software Foundation,
+ *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+ */
+
+#ifndef CLIENT_H_INCLUDED
+#define CLIENT_H_INCLUDED
+
+#define ADNS_VERSION_STRING "1.0"
+
+#define COPYRIGHT_MESSAGE \
+ "Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk>\n" \
+ "Copyright (C) 1999-2000 Tony Finch <dot@dotat.at>\n" \
+ "This is free software; see the source for copying conditions.  There is NO\n" \
+ "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
+
+#define VERSION_MESSAGE(program) \
+ program " (GNU adns) " ADNS_VERSION_STRING "\n\n" COPYRIGHT_MESSAGE
+
+#define VERSION_PRINT_QUIT(program)                               \
+  if (fputs(VERSION_MESSAGE(program),stdout) == EOF ||            \
+      fclose(stdout)) {                                           \
+    perror(program ": write version message");                    \
+    quitnow(-1);                                                  \
+  }                                                               \
+  quitnow(0);
+
+void quitnow(int rc) NONRETURNING;
+
+#endif