summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/date.c23
-rw-r--r--src/env.c21
-rw-r--r--src/id.c21
-rw-r--r--src/logname.c21
-rw-r--r--src/pathchk.c22
-rw-r--r--src/pinky.c24
-rw-r--r--src/printenv.c21
-rw-r--r--src/seq.c24
-rw-r--r--src/sleep.c21
-rw-r--r--src/su.c21
-rw-r--r--src/tee.c22
-rw-r--r--src/tty.c21
-rw-r--r--src/uname.c21
-rw-r--r--src/uptime.c21
-rw-r--r--src/users.c21
-rw-r--r--src/who.c24
-rw-r--r--src/whoami.c21
17 files changed, 74 insertions, 296 deletions
diff --git a/src/date.c b/src/date.c
index e6429fa46..b38c5f036 100644
--- a/src/date.c
+++ b/src/date.c
@@ -24,9 +24,10 @@
#include "system.h"
#include "closeout.h"
-#include "getline.h"
#include "error.h"
#include "getdate.h"
+#include "getline.h"
+#include "long-options.h"
#include "posixtm.h"
#ifndef STDC_HEADERS
@@ -44,12 +45,6 @@ static void show_date PARAMS ((const char *format, time_t when));
/* The name this program was run with, for error messages. */
char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
/* If non-zero, display time in RFC-822 format for mail or news. */
static int rfc_format = 0;
@@ -60,14 +55,12 @@ static struct option const long_options[] =
{
{"date", required_argument, NULL, 'd'},
{"file", required_argument, NULL, 'f'},
- {"help", no_argument, &show_help, 1},
{"reference", required_argument, NULL, 'r'},
{"rfc-822", no_argument, NULL, 'R'},
{"set", required_argument, NULL, 's'},
{"uct", no_argument, NULL, 'u'},
{"utc", no_argument, NULL, 'u'},
{"universal", no_argument, NULL, 'u'},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -287,6 +280,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "date", GNU_PACKAGE, VERSION,
+ "David MacKenzie", usage);
+
while ((optc = getopt_long (argc, argv, "d:f:r:Rs:u", long_options, NULL))
!= -1)
switch (optc)
@@ -316,15 +312,6 @@ main (int argc, char **argv)
usage (1);
}
- if (show_version)
- {
- printf ("date (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
n_args = argc - optind;
option_specified_date = ((datestr ? 1 : 0)
diff --git a/src/env.c b/src/env.c
index 8f677359c..a0d81191d 100644
--- a/src/env.c
+++ b/src/env.c
@@ -85,6 +85,7 @@
#include "system.h"
#include "error.h"
+#include "long-options.h"
int putenv ();
@@ -93,18 +94,10 @@ extern char **environ;
/* The name by which this program was run. */
char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
static struct option const longopts[] =
{
- {"help", no_argument, &show_help, 1},
{"ignore-environment", no_argument, NULL, 'i'},
{"unset", required_argument, NULL, 'u'},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -146,6 +139,9 @@ main (register int argc, register char **argv, char **envp)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "env", GNU_PACKAGE, VERSION,
+ "Richard Mlynarik and David MacKenzie", usage);
+
while ((optc = getopt_long (argc, argv, "+iu:", longopts, NULL)) != -1)
{
switch (optc)
@@ -162,15 +158,6 @@ main (register int argc, register char **argv, char **envp)
}
}
- if (show_version)
- {
- printf ("env (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
if (optind != argc && !strcmp (argv[optind], "-"))
ignore_environment = 1;
diff --git a/src/id.c b/src/id.c
index b9a404cd3..24c72497c 100644
--- a/src/id.c
+++ b/src/id.c
@@ -28,6 +28,7 @@
#include "system.h"
#include "error.h"
+#include "long-options.h"
#ifndef _POSIX_VERSION
struct passwd *getpwuid ();
@@ -70,21 +71,13 @@ static gid_t rgid, egid;
/* The number of errors encountered so far. */
static int problems = 0;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
static struct option const longopts[] =
{
{"group", no_argument, NULL, 'g'},
{"groups", no_argument, NULL, 'G'},
- {"help", no_argument, &show_help, 1},
{"name", no_argument, NULL, 'n'},
{"real", no_argument, NULL, 'r'},
{"user", no_argument, NULL, 'u'},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -126,6 +119,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "id", GNU_PACKAGE, VERSION,
+ "Arnold Robbins and David MacKenzie", usage);
+
while ((optc = getopt_long (argc, argv, "agnruG", longopts, NULL)) != -1)
{
switch (optc)
@@ -155,15 +151,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("id (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
if (just_user + just_group + just_group_list > 1)
error (1, 0, _("cannot print only user and only group"));
diff --git a/src/logname.c b/src/logname.c
index b9b3f60fa..913cf53d2 100644
--- a/src/logname.c
+++ b/src/logname.c
@@ -21,20 +21,13 @@
#include <getopt.h>
#include "system.h"
+#include "long-options.h"
/* The name this program was run with. */
char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
static struct option const long_options[] =
{
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
@@ -69,6 +62,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "logname", GNU_PACKAGE, VERSION,
+ "FIXME: unknown", usage);
+
while ((c = getopt_long (argc, argv, "", long_options, NULL)) != -1)
{
switch (c)
@@ -81,15 +77,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("logname (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
if (argc - optind != 0)
usage (1);
diff --git a/src/pathchk.c b/src/pathchk.c
index 2fc24dd69..ad285706a 100644
--- a/src/pathchk.c
+++ b/src/pathchk.c
@@ -45,6 +45,7 @@
#include "system.h"
#include "error.h"
+#include "long-options.h"
#ifdef _POSIX_VERSION
# ifndef PATH_MAX
@@ -96,17 +97,8 @@ static int validate_path PARAMS ((char *path, int portability));
/* The name this program was run with. */
char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
static struct option const longopts[] =
{
- {"help", no_argument, &show_help, 1},
- {"portability", no_argument, NULL, 'p'},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -143,6 +135,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "pathchk", GNU_PACKAGE, VERSION,
+ "David MacKenzie and Jim Meyering", usage);
+
while ((optc = getopt_long (argc, argv, "p", longopts, NULL)) != -1)
{
switch (optc)
@@ -159,15 +154,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("pathchk (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
if (optind == argc)
{
error (0, 0, _("too few arguments"));
diff --git a/src/pinky.c b/src/pinky.c
index 0f0327ea5..31c75ea7b 100644
--- a/src/pinky.c
+++ b/src/pinky.c
@@ -24,6 +24,7 @@
#include "system.h"
#include "error.h"
+#include "long-options.h"
#include "readutmp.h"
#ifndef MAXHOSTNAMELEN
@@ -40,12 +41,6 @@ char *ttyname ();
/* The name this program was run with. */
const char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
/* If nonzero, display the hours:minutes since each user has touched
the keyboard, or blank if within the last minute, or days followed
by a 'd' if not within the last day. */
@@ -77,8 +72,6 @@ static int include_where = 1;
static struct option const longopts[] =
{
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -433,7 +426,7 @@ The utmp file will be %s.\n\
}
int
-main (int argc, char *const argv[])
+main (int argc, char **argv)
{
int optc, longind;
@@ -442,6 +435,10 @@ main (int argc, char *const argv[])
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "pinky", GNU_PACKAGE, VERSION,
+ "Joseph Arceneaux, David MacKenzie, and Kaveh Ghazi",
+ usage);
+
while ((optc = getopt_long (argc, argv, "sfwiqbhlp", longopts, &longind))
!= -1)
{
@@ -498,15 +495,6 @@ main (int argc, char *const argv[])
}
}
- if (show_version)
- {
- printf ("pinky (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
if (do_short_format)
short_pinky (UTMP_FILE, argc - optind, argv + optind);
else
diff --git a/src/printenv.c b/src/printenv.c
index 3ac1f25ad..6496392ee 100644
--- a/src/printenv.c
+++ b/src/printenv.c
@@ -35,20 +35,13 @@
#include "system.h"
#include "closeout.h"
#include "error.h"
+#include "long-options.h"
/* The name this program was run with. */
char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
static struct option const long_options[] =
{
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
@@ -88,6 +81,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "printenv", GNU_PACKAGE, VERSION,
+ "David MacKenzie and Richard Mlynarik", usage);
+
while ((c = getopt_long (argc, argv, "", long_options, NULL)) != -1)
{
switch (c)
@@ -100,15 +96,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("printenv (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
if (optind == argc)
{
for (env = environ; *env != NULL; ++env)
diff --git a/src/seq.c b/src/seq.c
index b1c10f4ee..5dd9a3b26 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -25,6 +25,7 @@
#include "system.h"
#include "error.h"
+#include "long-options.h"
#include "xstrtod.h"
static double scan_double_arg PARAMS ((const char *arg));
@@ -52,12 +53,6 @@ static char *separator;
/* FIXME: make this an option. */
static char *terminator = "\n";
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
/* The increment. */
static double step;
@@ -68,9 +63,7 @@ static struct option const long_options[] =
{
{ "equal-width", no_argument, NULL, 'w'},
{ "format", required_argument, NULL, 'f'},
- { "help", no_argument, &show_help, 1},
{ "separator", required_argument, NULL, 's'},
- { "version", no_argument, &show_version, 1},
{ NULL, 0, NULL, 0}
};
@@ -119,6 +112,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "seq", GNU_PACKAGE, VERSION,
+ "Ulrich Drepper", usage);
+
equal_width = 0;
format_str = NULL;
separator = "\n";
@@ -162,18 +158,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("seq (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- {
- usage (0);
- /* NOTREACHED */
- }
-
if (optind >= argc)
{
error (0, 0, _("too few arguments"));
diff --git a/src/sleep.c b/src/sleep.c
index 74c142632..3f1ca5f74 100644
--- a/src/sleep.c
+++ b/src/sleep.c
@@ -22,22 +22,15 @@
#include "system.h"
#include "error.h"
+#include "long-options.h"
static long argdecode PARAMS ((const char *s));
/* The name by which this program was run. */
char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
static struct option const long_options[] =
{
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
@@ -73,6 +66,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "sleep", GNU_PACKAGE, VERSION,
+ "FIXME: unknown", usage);
+
while ((c = getopt_long (argc, argv, "", long_options, NULL)) != -1)
{
switch (c)
@@ -85,15 +81,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("sleep (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
if (argc == 1)
{
error (0, 0, _("too few arguments"));
diff --git a/src/su.c b/src/su.c
index f1a8bb92d..3d32a57b7 100644
--- a/src/su.c
+++ b/src/su.c
@@ -82,6 +82,7 @@
#define getusershell _getusershell_sys_proto_
#include "system.h"
+#include "long-options.h"
#undef getusershell
@@ -152,12 +153,6 @@ extern char **environ;
/* The name this program was run with. */
char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
/* If nonzero, pass the `-f' option to the subshell. */
static int fast_startup;
@@ -171,11 +166,9 @@ static struct option const longopts[] =
{
{"command", required_argument, 0, 'c'},
{"fast", no_argument, NULL, 'f'},
- {"help", no_argument, &show_help, 1},
{"login", no_argument, NULL, 'l'},
{"preserve-environment", no_argument, &change_environment, 0},
{"shell", required_argument, 0, 's'},
- {"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
@@ -467,6 +460,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "su", GNU_PACKAGE, VERSION,
+ "David MacKenzie", usage);
+
fast_startup = 0;
simulate_login = 0;
change_environment = 1;
@@ -504,15 +500,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("su (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
if (optind < argc && !strcmp (argv[optind], "-"))
{
simulate_login = 1;
diff --git a/src/tee.c b/src/tee.c
index b4b355368..f0d3aad0e 100644
--- a/src/tee.c
+++ b/src/tee.c
@@ -26,6 +26,7 @@
#include "system.h"
#include "closeout.h"
#include "error.h"
+#include "long-options.h"
int full_write ();
@@ -40,18 +41,10 @@ static int ignore_interrupts;
/* The name that this program was run with. */
char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
static struct option const long_options[] =
{
{"append", no_argument, NULL, 'a'},
- {"help", no_argument, &show_help, 1},
{"ignore-interrupts", no_argument, NULL, 'i'},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -88,6 +81,10 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "tee", GNU_PACKAGE, VERSION,
+ "Mike Parker, Richard M. Stallman, and David MacKenzie",
+ usage);
+
append = 0;
ignore_interrupts = 0;
@@ -111,15 +108,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("tee (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
if (ignore_interrupts)
{
#ifdef _POSIX_SOURCE
diff --git a/src/tty.c b/src/tty.c
index 056cb935d..088a22565 100644
--- a/src/tty.c
+++ b/src/tty.c
@@ -30,6 +30,7 @@
#include "system.h"
#include "closeout.h"
#include "error.h"
+#include "long-options.h"
/* The name under which this program was run. */
char *program_name;
@@ -37,18 +38,10 @@ char *program_name;
/* If nonzero, return an exit status but produce no output. */
static int silent;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
static struct option const longopts[] =
{
- {"help", no_argument, &show_help, 1},
{"silent", no_argument, NULL, 's'},
{"quiet", no_argument, NULL, 's'},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -84,6 +77,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "tty", GNU_PACKAGE, VERSION,
+ "David MacKenzie", usage);
+
silent = 0;
while ((optc = getopt_long (argc, argv, "s", longopts, NULL)) != -1)
@@ -102,15 +98,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("tty (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
if (optind != argc)
usage (2);
diff --git a/src/uname.c b/src/uname.c
index 62b9e5f27..f2499b8e2 100644
--- a/src/uname.c
+++ b/src/uname.c
@@ -40,6 +40,7 @@
#include "system.h"
#include "error.h"
+#include "long-options.h"
static void print_element PARAMS ((unsigned int mask, char *element));
@@ -68,21 +69,13 @@ static unsigned char toprint;
/* The name this program was run with, for error messages. */
char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
static struct option const long_options[] =
{
- {"help", no_argument, &show_help, 1},
{"machine", no_argument, NULL, 'm'},
{"nodename", no_argument, NULL, 'n'},
{"release", no_argument, NULL, 'r'},
{"sysname", no_argument, NULL, 's'},
{"processor", no_argument, NULL, 'p'},
- {"version", no_argument, &show_version, 1},
{"all", no_argument, NULL, 'a'},
{NULL, 0, NULL, 0}
};
@@ -125,6 +118,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "uname", GNU_PACKAGE, VERSION,
+ "David MacKenzie", usage);
+
toprint = 0;
while ((c = getopt_long (argc, argv, "snrvpma", long_options, NULL)) != -1)
@@ -168,15 +164,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("uname (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
if (optind != argc)
usage (1);
diff --git a/src/uptime.c b/src/uptime.c
index 993f3fbfd..e7e7cb5ab 100644
--- a/src/uptime.c
+++ b/src/uptime.c
@@ -22,22 +22,15 @@
#include <stdio.h>
#include "error.h"
+#include "long-options.h"
#include "readutmp.h"
#include "system.h"
/* The name this program was run with. */
char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
static struct option const longopts[] =
{
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -190,6 +183,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "uptime", GNU_PACKAGE, VERSION,
+ "Joseph Arceneaux and David MacKenzie", usage);
+
while ((optc = getopt_long (argc, argv, "", longopts, &longind)) != -1)
{
switch (optc)
@@ -202,15 +198,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("uptime (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
switch (argc - optind)
{
case 0: /* uptime */
diff --git a/src/users.c b/src/users.c
index e580583d4..09fff715c 100644
--- a/src/users.c
+++ b/src/users.c
@@ -22,22 +22,15 @@
#include <stdio.h>
#include "error.h"
+#include "long-options.h"
#include "readutmp.h"
#include "system.h"
/* The name this program was run with. */
char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
static struct option const longopts[] =
{
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -136,6 +129,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "users", GNU_PACKAGE, VERSION,
+ "Joseph Arceneaux and David MacKenzie", usage);
+
while ((optc = getopt_long (argc, argv, "", longopts, &longind)) != -1)
{
switch (optc)
@@ -148,15 +144,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("users (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
switch (argc - optind)
{
case 0: /* users */
diff --git a/src/who.c b/src/who.c
index e93943504..557fe21f9 100644
--- a/src/who.c
+++ b/src/who.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include "error.h"
+#include "long-options.h"
#include "readutmp.h"
#include "system.h"
@@ -46,12 +47,6 @@ char *ttyname ();
/* The name this program was run with. */
char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
/* If nonzero, attempt to canonicalize hostnames via a DNS lookup. */
static int do_lookup;
@@ -81,8 +76,6 @@ static struct option const longopts[] =
{"message", no_argument, NULL, 'T'},
{"mesg", no_argument, NULL, 'T'},
{"writable", no_argument, NULL, 'T'},
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -390,7 +383,11 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
- while ((optc = getopt_long (argc, argv, "ilmqsuwHT", longopts, &longind)) != -1)
+ parse_long_options (argc, argv, "who", GNU_PACKAGE, VERSION,
+ "Joseph Arceneaux and David MacKenzie", usage);
+
+ while ((optc = getopt_long (argc, argv, "ilmqsuwHT", longopts, &longind))
+ != -1)
{
switch (optc)
{
@@ -431,15 +428,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("who (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
switch (argc - optind)
{
case 0: /* who */
diff --git a/src/whoami.c b/src/whoami.c
index 2ecf9d8c7..3c021ab19 100644
--- a/src/whoami.c
+++ b/src/whoami.c
@@ -25,20 +25,13 @@
#include <getopt.h>
#include "system.h"
+#include "long-options.h"
/* The name this program was run with. */
char *program_name;
-/* If nonzero, display usage information and exit. */
-static int show_help;
-
-/* If nonzero, print the version on standard output and exit. */
-static int show_version;
-
static struct option const long_options[] =
{
- {"help", no_argument, &show_help, 1},
- {"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
@@ -74,6 +67,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ parse_long_options (argc, argv, "whoami", GNU_PACKAGE, VERSION,
+ "Richard Mlynarik", usage);
+
while ((c = getopt_long (argc, argv, "", long_options, NULL)) != -1)
{
switch (c)
@@ -86,15 +82,6 @@ main (int argc, char **argv)
}
}
- if (show_version)
- {
- printf ("whoami (%s) %s\n", GNU_PACKAGE, VERSION);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
if (optind != argc)
usage (1);