This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
--help and --version fixes
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: libc-alpha at sourceware dot org
- Date: Fri, 2 Jan 2009 19:40:13 +0000 (UTC)
- Subject: --help and --version fixes
This patch fixes various problems with --help and --version output
(compared to the GNU Coding Standards requirements) in tools
distributed with and installed by glibc.
* pcprofiledump didn't support --version.
* ldconfig --help didn't give bug-reporting information.
* sln didn't support --help or --version.
* memusagestat didn't support --version.
* nscd --help didn't give bug-reporting information.
* getconf didn't support --help, and its --version output went to
stderr instead of stdout.
* rpcgen and rpcinfo didn't support --help or --version.
* lddlibc4 didn't support --help or --version.
2009-01-02 Joseph Myers <joseph@codesourcery.com>
* debug/pcprofiledump.c (print_version,
argp_program_version_hook): New.
* elf/ldconfig.c (doc): Give bug reporting information.
* elf/sln.c (usage): New.
(main): Support --help and --version.
* malloc/memusagestat.c (print_version,
argp_program_version_hook): New.
* nscd/nscd.c (doc): Give bug reporting information.
* posix/getconf.c (main): Send --version output to stdout.
Support --help.
* sunrpc/rpc_main.c (usage, options_usage): Take STREAM and STATUS
arguments. All callers changed.
(print_version): New.
(parseargs): Support --help and --version.
* sunrpc/rpcinfo.c (usage): Take STREAM argument. All callers
changed.
(print_version): New.
(main): Use getopt_long. Support --help and --version.
* sysdeps/unix/sysv/linux/lddlibc4.c (main): Support --help and
--version.
Index: debug/pcprofiledump.c
===================================================================
RCS file: /cvs/glibc/libc/debug/pcprofiledump.c,v
retrieving revision 1.6
diff -u -r1.6 pcprofiledump.c
--- debug/pcprofiledump.c 21 Aug 2007 14:55:47 -0000 1.6
+++ debug/pcprofiledump.c 2 Jan 2009 18:38:49 -0000
@@ -66,6 +66,10 @@
/* Prototype for option handler. */
static error_t parse_opt (int key, char *arg, struct argp_state *state);
+/* Name and version of program. */
+static void print_version (FILE *stream, struct argp_state *state);
+void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
+
/* Data structure to communicate with argp functions. */
static struct argp argp =
{
@@ -209,3 +213,16 @@
}
return (char *) text;
}
+
+/* Print the version information. */
+static void
+print_version (FILE *stream, struct argp_state *state)
+{
+ fprintf (stream, "pcprofiledump (GNU %s) %s\n", PACKAGE, VERSION);
+ fprintf (stream, gettext ("\
+Copyright (C) %s Free Software Foundation, Inc.\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\
+"), "2009");
+ fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper");
+}
Index: elf/ldconfig.c
===================================================================
RCS file: /cvs/glibc/libc/elf/ldconfig.c,v
retrieving revision 1.64
diff -u -r1.64 ldconfig.c
--- elf/ldconfig.c 2 Jan 2009 08:46:29 -0000 1.64
+++ elf/ldconfig.c 2 Jan 2009 18:38:49 -0000
@@ -153,7 +153,9 @@
#include <dl-procinfo.c>
/* Short description of program. */
-static const char doc[] = N_("Configure Dynamic Linker Run Time Bindings.");
+static const char doc[] = N_("Configure Dynamic Linker Run Time Bindings.\v\
+For bug reporting instructions, please see:\n\
+<http://www.gnu.org/software/libc/bugs.html>.\n");
/* Prototype for option handler. */
static error_t parse_opt (int key, char *arg, struct argp_state *state);
Index: elf/sln.c
===================================================================
RCS file: /cvs/glibc/libc/elf/sln.c,v
retrieving revision 1.6
diff -u -r1.6 sln.c
--- elf/sln.c 6 Jul 2001 04:54:46 -0000 1.6
+++ elf/sln.c 2 Jan 2009 18:38:49 -0000
@@ -28,12 +28,15 @@
#include <string.h>
#include <limits.h>
+#include "../version.h"
+
#if !defined S_ISDIR && defined S_IFDIR
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
static int makesymlink (const char *src, const char *dest);
static int makesymlinks (const char *file);
+static void usage (void);
int
main (int argc, char **argv)
@@ -41,6 +44,13 @@
switch (argc)
{
case 2:
+ if (!strcmp (argv[1], "--version")) {
+ printf ("sln (GNU libc) %s\n", VERSION);
+ return 0;
+ } else if (!strcmp (argv[1], "--help")) {
+ usage ();
+ return 0;
+ }
return makesymlinks (argv [1]);
break;
@@ -49,12 +59,21 @@
break;
default:
- printf ("Usage: %s src dest|file\n", argv [0]);
+ usage ();
return 1;
break;
}
}
+static void
+usage (void)
+{
+ printf ("Usage: sln src dest|file\n\
+\n\
+For bug reporting instructions, please see:\n\
+<http://www.gnu.org/software/libc/bugs.html>.\n");
+}
+
static int
makesymlinks (file)
const char *file;
Index: malloc/memusagestat.c
===================================================================
RCS file: /cvs/glibc/libc/malloc/memusagestat.c,v
retrieving revision 1.11
diff -u -r1.11 memusagestat.c
--- malloc/memusagestat.c 16 Jul 2007 00:54:59 -0000 1.11
+++ malloc/memusagestat.c 2 Jan 2009 18:38:50 -0000
@@ -38,6 +38,8 @@
#include <gdfontl.h>
#include <gdfonts.h>
+#include "../version.h"
+#define PACKAGE _libc_intl_domainname
/* Default size of the generated image. */
#define XSIZE 800
@@ -73,6 +75,10 @@
/* Function to print some extra text in the help message. */
static char *more_help (int key, const char *text, void *input);
+/* Name and version of program. */
+static void print_version (FILE *stream, struct argp_state *state);
+void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
+
/* Data structure to communicate with argp functions. */
static struct argp argp =
{
@@ -535,3 +541,16 @@
}
return (char *) text;
}
+
+/* Print the version information. */
+static void
+print_version (FILE *stream, struct argp_state *state)
+{
+ fprintf (stream, "memusagestat (GNU %s) %s\n", PACKAGE, VERSION);
+ fprintf (stream, gettext ("\
+Copyright (C) %s Free Software Foundation, Inc.\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\
+"), "2009");
+ fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper");
+}
Index: nscd/nscd.c
===================================================================
RCS file: /cvs/glibc/libc/nscd/nscd.c,v
retrieving revision 1.61
diff -u -r1.61 nscd.c
--- nscd/nscd.c 2 Jan 2009 08:45:21 -0000 1.61
+++ nscd/nscd.c 2 Jan 2009 18:38:50 -0000
@@ -109,7 +109,9 @@
};
/* Short description of program. */
-static const char doc[] = N_("Name Service Cache Daemon.");
+static const char doc[] = N_("Name Service Cache Daemon.\v\
+For bug reporting instructions, please see:\n\
+<http://www.gnu.org/software/libc/bugs.html>.\n");
/* Prototype for option handler. */
static error_t parse_opt (int key, char *arg, struct argp_state *state);
Index: posix/getconf.c
===================================================================
RCS file: /cvs/glibc/libc/posix/getconf.c,v
retrieving revision 1.49
diff -u -r1.49 getconf.c
--- posix/getconf.c 2 Jan 2009 08:47:04 -0000 1.49
+++ posix/getconf.c 2 Jan 2009 18:38:50 -0000
@@ -1008,13 +1008,28 @@
if (argc > 1 && strcmp (argv[1], "--version") == 0)
{
- fprintf (stderr, "getconf (GNU %s) %s\n", PACKAGE, VERSION);
- fprintf (stderr, gettext ("\
+ printf ("getconf (GNU %s) %s\n", PACKAGE, VERSION);
+ printf (gettext ("\
Copyright (C) %s Free Software Foundation, Inc.\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\
"), "2009");
- fprintf (stderr, gettext ("Written by %s.\n"), "Roland McGrath");
+ printf (gettext ("Written by %s.\n"), "Roland McGrath");
+ return 0;
+ }
+
+ if (argc > 1 && strcmp (argv[1], "--help") == 0)
+ {
+ printf (gettext ("\
+Usage: getconf [-v SPEC] VAR\n\
+ or: getconf [-v SPEC] PATH_VAR PATH\n\
+\n\
+Get the configuration value for variable VAR, or for variable PATH_VAR\n\
+for path PATH. If SPEC is given, give values for compilation\n\
+environment SPEC.\n\
+\n\
+For bug reporting instructions, please see:\n\
+<http://www.gnu.org/software/libc/bugs.html>.\n"));
return 0;
}
Index: sunrpc/rpc_main.c
===================================================================
RCS file: /cvs/glibc/libc/sunrpc/rpc_main.c,v
retrieving revision 1.31
diff -u -r1.31 rpc_main.c
--- sunrpc/rpc_main.c 3 Nov 2008 07:47:39 -0000 1.31
+++ sunrpc/rpc_main.c 2 Jan 2009 18:38:51 -0000
@@ -52,6 +52,9 @@
#include "rpc_scan.h"
#include "proto.h"
+#include "../version.h"
+#define PACKAGE _libc_intl_domainname
+
#define EXTEND 1 /* alias for TRUE */
#define DONT_EXTEND 0 /* alias for FALSE */
@@ -132,8 +135,9 @@
static void putarg (int whereto, const char *cp);
static void checkfiles (const char *infile, const char *outfile);
static int parseargs (int argc, const char *argv[], struct commandline *cmd);
-static void usage (void) __attribute__ ((noreturn));
-static void options_usage (void) __attribute__ ((noreturn));
+static void usage (FILE *stream, int status) __attribute__ ((noreturn));
+static void options_usage (FILE *stream, int status) __attribute__ ((noreturn));
+static void print_version (void);
static void c_initialize (void);
static char *generate_guard (const char *pathname);
@@ -185,7 +189,7 @@
(void) memset ((char *) &cmd, 0, sizeof (struct commandline));
clear_args ();
if (!parseargs (argc, argv, &cmd))
- usage ();
+ usage (stderr, 1);
if (cmd.cflag || cmd.hflag || cmd.lflag || cmd.tflag || cmd.sflag ||
cmd.mflag || cmd.nflag || cmd.Ssflag || cmd.Scflag)
@@ -787,7 +791,7 @@
{
if (outfilename)
unlink (outfilename);
- usage ();
+ usage (stderr, 1);
}
write_rest ();
}
@@ -1218,6 +1222,10 @@
}
cmd->infile = argv[i];
}
+ else if (!strcmp (argv[i], "--help"))
+ usage (stdout, 0);
+ else if (!strcmp (argv[i], "--version"))
+ print_version ();
else
{
for (j = 1; argv[i][j] != 0; j++)
@@ -1442,46 +1450,56 @@
}
static void
-usage (void)
+usage (FILE *stream, int status)
{
- fprintf (stderr, _("usage: %s infile\n"), cmdname);
- fprintf (stderr, _("\t%s [-abkCLNTM][-Dname[=value]] [-i size] \
+ fprintf (stream, _("usage: %s infile\n"), cmdname);
+ fprintf (stream, _("\t%s [-abkCLNTM][-Dname[=value]] [-i size] \
[-I [-K seconds]] [-Y path] infile\n"), cmdname);
- fprintf (stderr, _("\t%s [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm] \
+ fprintf (stream, _("\t%s [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm] \
[-o outfile] [infile]\n"), cmdname);
- fprintf (stderr, _("\t%s [-s nettype]* [-o outfile] [infile]\n"), cmdname);
- fprintf (stderr, _("\t%s [-n netid]* [-o outfile] [infile]\n"), cmdname);
- options_usage ();
- exit (1);
+ fprintf (stream, _("\t%s [-s nettype]* [-o outfile] [infile]\n"), cmdname);
+ fprintf (stream, _("\t%s [-n netid]* [-o outfile] [infile]\n"), cmdname);
+ options_usage (stream, status);
+ exit (status);
}
static void
-options_usage (void)
-{
- f_print (stderr, "options:\n");
- f_print (stderr, "-a\t\tgenerate all files, including samples\n");
- f_print (stderr, "-b\t\tbackward compatibility mode (generates code for SunOS 4.1)\n");
- f_print (stderr, "-c\t\tgenerate XDR routines\n");
- f_print (stderr, "-C\t\tANSI C mode\n");
- f_print (stderr, "-Dname[=value]\tdefine a symbol (same as #define)\n");
- f_print (stderr, "-h\t\tgenerate header file\n");
- f_print (stderr, "-i size\t\tsize at which to start generating inline code\n");
- f_print (stderr, "-I\t\tgenerate code for inetd support in server (for SunOS 4.1)\n");
- f_print (stderr, "-K seconds\tserver exits after K seconds of inactivity\n");
- f_print (stderr, "-l\t\tgenerate client side stubs\n");
- f_print (stderr, "-L\t\tserver errors will be printed to syslog\n");
- f_print (stderr, "-m\t\tgenerate server side stubs\n");
- f_print (stderr, "-M\t\tgenerate MT-safe code\n");
- f_print (stderr, "-n netid\tgenerate server code that supports named netid\n");
- f_print (stderr, "-N\t\tsupports multiple arguments and call-by-value\n");
- f_print (stderr, "-o outfile\tname of the output file\n");
- f_print (stderr, "-s nettype\tgenerate server code that supports named nettype\n");
- f_print (stderr, "-Sc\t\tgenerate sample client code that uses remote procedures\n");
- f_print (stderr, "-Ss\t\tgenerate sample server code that defines remote procedures\n");
- f_print (stderr, "-Sm \t\tgenerate makefile template \n");
- f_print (stderr, "-t\t\tgenerate RPC dispatch table\n");
- f_print (stderr, "-T\t\tgenerate code to support RPC dispatch tables\n");
- f_print (stderr, "-Y path\t\tdirectory name to find C preprocessor (cpp)\n");
+options_usage (FILE *stream, int status)
+{
+ f_print (stream, "options:\n");
+ f_print (stream, "-a\t\tgenerate all files, including samples\n");
+ f_print (stream, "-b\t\tbackward compatibility mode (generates code for SunOS 4.1)\n");
+ f_print (stream, "-c\t\tgenerate XDR routines\n");
+ f_print (stream, "-C\t\tANSI C mode\n");
+ f_print (stream, "-Dname[=value]\tdefine a symbol (same as #define)\n");
+ f_print (stream, "-h\t\tgenerate header file\n");
+ f_print (stream, "-i size\t\tsize at which to start generating inline code\n");
+ f_print (stream, "-I\t\tgenerate code for inetd support in server (for SunOS 4.1)\n");
+ f_print (stream, "-K seconds\tserver exits after K seconds of inactivity\n");
+ f_print (stream, "-l\t\tgenerate client side stubs\n");
+ f_print (stream, "-L\t\tserver errors will be printed to syslog\n");
+ f_print (stream, "-m\t\tgenerate server side stubs\n");
+ f_print (stream, "-M\t\tgenerate MT-safe code\n");
+ f_print (stream, "-n netid\tgenerate server code that supports named netid\n");
+ f_print (stream, "-N\t\tsupports multiple arguments and call-by-value\n");
+ f_print (stream, "-o outfile\tname of the output file\n");
+ f_print (stream, "-s nettype\tgenerate server code that supports named nettype\n");
+ f_print (stream, "-Sc\t\tgenerate sample client code that uses remote procedures\n");
+ f_print (stream, "-Ss\t\tgenerate sample server code that defines remote procedures\n");
+ f_print (stream, "-Sm \t\tgenerate makefile template \n");
+ f_print (stream, "-t\t\tgenerate RPC dispatch table\n");
+ f_print (stream, "-T\t\tgenerate code to support RPC dispatch tables\n");
+ f_print (stream, "-Y path\t\tdirectory name to find C preprocessor (cpp)\n");
+
+ f_print (stream, "\n\
+For bug reporting instructions, please see:\n\
+<http://www.gnu.org/software/libc/bugs.html>.\n");
+ exit (status);
+}
- exit (1);
+static void
+print_version (void)
+{
+ printf ("rpcgen (GNU %s) %s\n", PACKAGE, VERSION);
+ exit (0);
}
Index: sunrpc/rpcinfo.c
===================================================================
RCS file: /cvs/glibc/libc/sunrpc/rpcinfo.c,v
retrieving revision 1.8
diff -u -r1.8 rpcinfo.c
--- sunrpc/rpcinfo.c 19 Sep 2001 03:05:41 -0000 1.8
+++ sunrpc/rpcinfo.c 2 Jan 2009 18:38:52 -0000
@@ -58,6 +58,9 @@
#include <locale.h>
#include <libintl.h>
+#include "../version.h"
+#define PACKAGE _libc_intl_domainname
+
#define MAXHOSTLEN 256
#define MIN_VERS ((u_long) 0)
@@ -70,7 +73,8 @@
static bool_t reply_proc (void *res, struct sockaddr_in *who);
static void brdcst (int argc, char **argv) __attribute__ ((noreturn));
static void deletereg (int argc, char **argv);
-static void usage (void);
+static void usage (FILE *stream);
+static void print_version (void);
static u_long getprognum (char *arg);
static u_long getvers (char *arg);
static void get_inet_address (struct sockaddr_in *addr, char *host);
@@ -92,6 +96,11 @@
int errflg;
int function;
u_short portnum;
+ static const struct option long_options[] = {
+ { "help", no_argument, NULL, 'H' },
+ { "version", no_argument, NULL, 'V' },
+ { NULL, 0, NULL, 0 }
+ };
setlocale (LC_ALL, "");
textdomain (_libc_intl_domainname);
@@ -99,7 +108,7 @@
function = NONE;
portnum = 0;
errflg = 0;
- while ((c = getopt (argc, argv, "ptubdn:")) != -1)
+ while ((c = getopt_long (argc, argv, "ptubdn:", long_options, NULL)) != -1)
{
switch (c)
{
@@ -143,6 +152,14 @@
function = DELETES;
break;
+ case 'H':
+ usage (stdout);
+ return 0;
+
+ case 'V':
+ print_version ();
+ return 0;
+
case '?':
errflg = 1;
}
@@ -150,7 +167,7 @@
if (errflg || function == NONE)
{
- usage ();
+ usage (stderr);
return 1;
}
@@ -160,7 +177,7 @@
case PMAPDUMP:
if (portnum != 0)
{
- usage ();
+ usage (stderr);
return 1;
}
pmapdump (argc - optind, argv + optind);
@@ -177,7 +194,7 @@
case BRDCST:
if (portnum != 0)
{
- usage ();
+ usage (stderr);
return 1;
}
brdcst (argc - optind, argv + optind);
@@ -208,7 +225,7 @@
if (argc < 2 || argc > 3)
{
- usage ();
+ usage (stderr);
exit (1);
}
prognum = getprognum (argv[1]);
@@ -363,7 +380,7 @@
if (argc < 2 || argc > 3)
{
- usage ();
+ usage (stderr);
exit (1);
}
prognum = getprognum (argv[1]);
@@ -532,7 +549,7 @@
if (argc > 1)
{
- usage ();
+ usage (stderr);
exit (1);
}
if (argc == 1)
@@ -624,7 +641,7 @@
if (argc != 2)
{
- usage ();
+ usage (stderr);
exit (1);
}
prognum = getprognum (argv[0]);
@@ -650,7 +667,7 @@
if (argc != 2)
{
- usage ();
+ usage (stderr);
exit (1);
}
if (getuid ())
@@ -669,15 +686,24 @@
}
static void
-usage ()
+usage (FILE *stream)
{
fputs (_("Usage: rpcinfo [ -n portnum ] -u host prognum [ versnum ]\n"),
- stderr);
+ stream);
fputs (_(" rpcinfo [ -n portnum ] -t host prognum [ versnum ]\n"),
- stderr);
- fputs (_(" rpcinfo -p [ host ]\n"), stderr);
- fputs (_(" rpcinfo -b prognum versnum\n"), stderr);
- fputs (_(" rpcinfo -d prognum versnum\n"), stderr);
+ stream);
+ fputs (_(" rpcinfo -p [ host ]\n"), stream);
+ fputs (_(" rpcinfo -b prognum versnum\n"), stream);
+ fputs (_(" rpcinfo -d prognum versnum\n"), stream);
+ fprintf (stream, _("\n\
+For bug reporting instructions, please see:\n\
+<http://www.gnu.org/software/libc/bugs.html>.\n"));
+}
+
+static void
+print_version (void)
+{
+ printf ("rpcinfo (GNU %s) %s\n", PACKAGE, VERSION);
}
static u_long
Index: sysdeps/unix/sysv/linux/lddlibc4.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/lddlibc4.c,v
retrieving revision 1.5
diff -u -r1.5 lddlibc4.c
--- sysdeps/unix/sysv/linux/lddlibc4.c 20 Sep 2005 07:46:19 -0000 1.5
+++ sysdeps/unix/sysv/linux/lddlibc4.c 2 Jan 2009 18:38:53 -0000
@@ -56,6 +56,25 @@
if (argc != 2)
return 1;
+ if (!strcmp (argv[1], "--help"))
+ {
+ printf (gettext ("Usage: lddlibc4 FILE\n\
+\n\
+For bug reporting instructions, please see:\n\
+<http://www.gnu.org/software/libc/bugs.html>.\n"));
+ return 0;
+ }
+ else if (!strcmp (argv[1], "--version"))
+ {
+ printf ("lddlibc4 (GNU %s) %s\n", PACKAGE, VERSION);
+ printf (gettext ("\
+Copyright (C) %s Free Software Foundation, Inc.\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\
+"), "2009");
+ return 0;
+ }
+
filename = argv[1];
/* First see whether this is really an a.out binary. */
--
Joseph S. Myers
joseph@codesourcery.com