From aa3ffb57294018bc66aabe1df8960643c397a449 Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 17 Sep 2000 14:09:02 +0000 Subject: [PATCH] Support --version in utility programs. --- Makefile.in | 3 +++ README | 2 +- README.html | 2 +- changelog | 2 +- client/adh-opts.c | 6 +++++ client/adnshost.h | 5 ++-- client/adnslogres.c | 20 ++++++++++++---- client/adnsresfilter.c | 18 ++++++++------- client/client.h | 52 ++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 client/client.h diff --git a/Makefile.in b/Makefile.in index b920d4d..869bfaf 100644 --- a/Makefile.in +++ b/Makefile.in @@ -21,7 +21,10 @@ # 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 b812766..e98c114 100644 --- 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/ diff --git a/README.html b/README.html index fc9ce4f..760c278 100644 --- a/README.html +++ b/README.html @@ -140,7 +140,7 @@ are: release as a gzipped tarfile.
  • adns.h API header file with comments, and - usage + usage message for adnshost (currently there is no manual, sorry).
  • All versions released so far are also available via anonymous diff --git a/changelog b/changelog index fb40fbc..c546adc 100644 --- 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: diff --git a/client/adh-opts.c b/client/adh-opts.c index fa5cceb..9805e5e 100644 --- a/client/adh-opts.c +++ b/client/adh-opts.c @@ -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, "" }, + { 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); diff --git a/client/adnshost.h b/client/adnshost.h index d88c2a1..a8da4ff 100644 --- a/client/adnshost.h +++ b/client/adnshost.h @@ -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 */ diff --git a/client/adnslogres.c b/client/adnslogres.c index a91127b..2f13fb0 100644 --- a/client/adnslogres.c +++ b/client/adnslogres.c @@ -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 [] []\n" + " adnslogres --version|--help\n" + "options: -c set max number of outstanding queries\n" + " -p use poll(2) instead of select(2)\n" + " -d turn on debugging\n" + " -C 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); } diff --git a/client/adnsresfilter.c b/client/adnsresfilter.c index 3a3cacf..aec3889 100644 --- a/client/adnsresfilter.c +++ b/client/adnsresfilter.c @@ -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 []\n" - " adnsresfilter -h|--help\n" + " adnsresfilter -h|--help | --version\n" "options: -t|--timeout \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 index 0000000..2e74b12 --- /dev/null +++ b/client/client.h @@ -0,0 +1,52 @@ +/* + * clients.h + * - useful declarations and definitions for adns client programs + */ +/* + * This file is + * Copyright (C) 1997-2000 Ian Jackson + * + * It is part of adns, which is + * Copyright (C) 1997-2000 Ian Jackson + * Copyright (C) 1999-2000 Tony Finch + * + * 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 \n" \ + "Copyright (C) 1999-2000 Tony Finch \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 -- 2.30.2