summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-10-12 01:52:24 +0000
committerJim Meyering <jim@meyering.net>1993-10-12 01:52:24 +0000
commit87fa23e6417d7d1938b72e872d779ae7225a5aa4 (patch)
tree0fcc68f9cdf7315d09d5836df0f261e3d6b8c13a /src
parentf12b53b2ce8f0bb0dd28a290f9b27490ef4599a9 (diff)
downloadcoreutils-87fa23e6417d7d1938b72e872d779ae7225a5aa4.tar.xz
merge with 1.8.1b
Diffstat (limited to 'src')
-rw-r--r--src/basename.c2
-rw-r--r--src/date.c2
-rw-r--r--src/dirname.c2
-rw-r--r--src/echo.c17
-rw-r--r--src/env.c2
-rw-r--r--src/expr.c54
-rw-r--r--src/id.c2
-rw-r--r--src/logname.c2
-rw-r--r--src/nice.c23
-rw-r--r--src/pathchk.c23
-rw-r--r--src/printf.c18
-rw-r--r--src/sleep.c46
-rw-r--r--src/stty.c55
-rw-r--r--src/su.c27
-rw-r--r--src/tee.c39
-rw-r--r--src/test.c15
-rw-r--r--src/tty.c35
-rw-r--r--src/uname.c33
-rw-r--r--src/who.c22
19 files changed, 336 insertions, 83 deletions
diff --git a/src/basename.c b/src/basename.c
index 01e3d4375..ec8cd5a4e 100644
--- a/src/basename.c
+++ b/src/basename.c
@@ -43,7 +43,7 @@ char *program_name;
/* If non-zero, display usage information and exit. */
static int show_help;
-/* If non-zero, print the version on standard error. */
+/* If non-zero, print the version on standard output and exit. */
static int show_version;
static struct option const long_options[] =
diff --git a/src/date.c b/src/date.c
index e97ef43d7..b80c47fe3 100644
--- a/src/date.c
+++ b/src/date.c
@@ -85,7 +85,7 @@ char *program_name;
/* If non-zero, display usage information and exit. */
static int show_help;
-/* If non-zero, print the version on standard error. */
+/* If non-zero, print the version on standard output and exit. */
static int show_version;
static struct option const long_options[] =
diff --git a/src/dirname.c b/src/dirname.c
index d6227db2f..a4209c89a 100644
--- a/src/dirname.c
+++ b/src/dirname.c
@@ -32,7 +32,7 @@ char *program_name;
/* If non-zero, display usage information and exit. */
static int show_help;
-/* If non-zero, print the version on standard error. */
+/* If non-zero, print the version on standard output and exit. */
static int show_version;
static struct option const long_options[] =
diff --git a/src/echo.c b/src/echo.c
index ddf3b1783..2e27abe63 100644
--- a/src/echo.c
+++ b/src/echo.c
@@ -57,6 +57,19 @@ on System V systems with the -E option.
# define VALID_ECHO_OPTIONS "n"
#endif /* !V9_ECHO */
+/* The name this program was run with. */
+char *program_name;
+
+void parse_long_options ();
+
+static void
+usage ()
+{
+ fprintf (stderr, "Usage: %s [{--help,--version}] [-ne] [string ...]\n",
+ program_name);
+ exit (1);
+}
+
/* Print the words in LIST to standard output. If the first word is
`-n', then don't print a trailing newline. We also support the
echo syntax from Version 9 unix systems. */
@@ -67,6 +80,10 @@ main (argc, argv)
{
int display_return = 1, do_v9 = 0;
+ program_name = argv[0];
+
+ parse_long_options (argc, argv, usage);
+
/* System V machines already have a /bin/sh with a v9 behaviour. We
use the identical behaviour for these machines so that the
existing system shell scripts won't barf. */
diff --git a/src/env.c b/src/env.c
index 283e88ad4..b08d48311 100644
--- a/src/env.c
+++ b/src/env.c
@@ -98,7 +98,7 @@ char *program_name;
/* If non-zero, display usage information and exit. */
static int show_help;
-/* If non-zero, print the version on standard error. */
+/* If non-zero, print the version on standard output and exit. */
static int show_version;
static struct option const longopts[] =
diff --git a/src/expr.c b/src/expr.c
index a9f376942..97f7b39d8 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -32,7 +32,6 @@
#include <ctype.h>
#include <sys/types.h>
#include <regex.h>
-#include <getopt.h>
#include "system.h"
#include "version.h"
@@ -81,6 +80,7 @@ void error ();
char *xstrdup ();
char *strstr ();
char *xmalloc ();
+void parse_long_options ();
static VALUE *docolon ();
static VALUE *eval ();
@@ -99,13 +99,6 @@ static void tostring ();
static void trace ();
#endif
-static struct option const long_options[] =
-{
- {"help", no_argument, 0, 'h'},
- {"version", no_argument, 0, 'v'},
- {0, 0, 0, 0}
-};
-
static void
usage ()
{
@@ -114,39 +107,6 @@ usage ()
exit (1);
}
-/* Process long options that precede all other command line arguments. */
-
-static void
-parse_long_options (argc, argv)
- int argc;
- char **argv;
-{
- int c;
-
- while ((c = getopt_long (argc, argv, "+", long_options, (int *) 0)) != EOF)
- {
- switch (c)
- {
- case 'h':
- usage ();
-
- case 'v':
- printf ("%s\n", version_string);
- exit (0);
-
- default:
- usage ();
- }
- }
-
- /* Restore optind in case it has advanced past a leading `--'. We can use a
- simple assignment here because all brances of the above switch statement
- exit. Otherwise, we'd have to be careful to decrement only when optind
- is larger than 1 and the last argument processed was `--'. */
-
- optind = 1;
-}
-
void
main (argc, argv)
int argc;
@@ -156,7 +116,7 @@ main (argc, argv)
program_name = argv[0];
- parse_long_options (argc, argv);
+ parse_long_options (argc, argv, usage);
if (argc == 1)
usage ();
@@ -465,7 +425,8 @@ eval7 ()
#endif
if (nomoreargs ())
error (2, 0, "syntax error");
- else if (nextarg ("("))
+
+ if (nextarg ("("))
{
args++;
v = eval ();
@@ -474,10 +435,11 @@ eval7 ()
args++;
return v;
}
- else if (nextarg (")"))
+
+ if (nextarg (")"))
error (2, 0, "syntax error");
- else
- return str_value (*args++);
+
+ return str_value (*args++);
}
/* Handle match, substr, index, and length keywords. */
diff --git a/src/id.c b/src/id.c
index 7d55d7105..bd18ed855 100644
--- a/src/id.c
+++ b/src/id.c
@@ -85,7 +85,7 @@ static int problems = 0;
/* If non-zero, display usage information and exit. */
static int show_help;
-/* If non-zero, print the version on standard error. */
+/* If non-zero, print the version on standard output and exit. */
static int show_version;
static struct option const longopts[] =
diff --git a/src/logname.c b/src/logname.c
index 19fea40cb..82c49feef 100644
--- a/src/logname.c
+++ b/src/logname.c
@@ -28,7 +28,7 @@ char *program_name;
/* If non-zero, display usage information and exit. */
static int show_help;
-/* If non-zero, print the version on standard error. */
+/* If non-zero, print the version on standard output and exit. */
static int show_version;
static struct option const long_options[] =
diff --git a/src/nice.c b/src/nice.c
index 51218d8e7..28e68d9f5 100644
--- a/src/nice.c
+++ b/src/nice.c
@@ -28,6 +28,12 @@
#include "version.h"
#include "system.h"
+#ifdef NICE_PRIORITY
+#define GET_PRIORITY() nice (0)
+#else
+#define GET_PRIORITY() getpriority (PRIO_PROCESS, 0)
+#endif
+
void error ();
static int isinteger ();
@@ -39,7 +45,7 @@ char *program_name;
/* If non-zero, display usage information and exit. */
static int show_help;
-/* If non-zero, print the version on standard error. */
+/* If non-zero, print the version on standard output and exit. */
static int show_version;
static struct option const longopts[] =
@@ -111,27 +117,18 @@ main (argc, argv)
usage ();
/* No command given; print the priority. */
errno = 0;
-#ifndef NICE_PRIORITY
- current_priority = getpriority (PRIO_PROCESS, 0);
-#else
- current_priority = nice (0);
-#endif
+ current_priority = GET_PRIORITY ();
if (current_priority == -1 && errno != 0)
error (1, errno, "cannot get priority");
printf ("%d\n", current_priority);
exit (0);
}
- errno = 0;
#ifndef NICE_PRIORITY
- current_priority = getpriority (PRIO_PROCESS, 0);
-#else
- current_priority = nice (0);
-#endif
+ errno = 0;
+ current_priority = GET_PRIORITY ();
if (current_priority == -1 && errno != 0)
error (1, errno, "cannot get priority");
-
-#ifndef NICE_PRIORITY
if (setpriority (PRIO_PROCESS, 0, current_priority + adjustment))
#else
if (nice (adjustment) == -1)
diff --git a/src/pathchk.c b/src/pathchk.c
index 7302e3859..e6da04ea2 100644
--- a/src/pathchk.c
+++ b/src/pathchk.c
@@ -41,6 +41,8 @@
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
+
+#include "version.h"
#include "system.h"
#ifdef _POSIX_VERSION
@@ -96,9 +98,17 @@ static void usage ();
/* The name this program was run with. */
char *program_name;
+/* If non-zero, display usage information and exit. */
+static int show_help;
+
+/* If non-zero, 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}
};
@@ -117,14 +127,27 @@ main (argc, argv)
{
switch (optc)
{
+ case 0:
+ break;
+
case 'p':
check_portability = 1;
break;
+
default:
usage ();
}
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (optind == argc)
usage ();
diff --git a/src/printf.c b/src/printf.c
index 0c0da37fe..e1bd4d3ab 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -46,7 +46,10 @@
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
+#include <getopt.h>
+
#include "system.h"
+#include "version.h"
#if !defined (isascii) || defined (STDC_HEADERS)
#undef isascii
@@ -68,6 +71,7 @@ unsigned long strtoul ();
char *xmalloc ();
void error ();
+void parse_long_options ();
static double xstrtod ();
static int print_esc ();
@@ -79,11 +83,19 @@ static void print_esc_char ();
static void print_esc_string ();
static void verify ();
+/* The value to return to the calling program. */
+static int exit_status;
+
/* The name this program was run with. */
char *program_name;
-/* The value to return to the calling program. */
-static int exit_status;
+static void
+usage ()
+{
+ fprintf (stderr, "Usage: %s [{--help,--version}] format [argument...]\n",
+ program_name);
+ exit (1);
+}
void
main (argc, argv)
@@ -96,6 +108,8 @@ main (argc, argv)
program_name = argv[0];
exit_status = 0;
+ parse_long_options (argc, argv, usage);
+
if (argc == 1)
{
fprintf (stderr, "Usage: %s format [argument...]\n", program_name);
diff --git a/src/sleep.c b/src/sleep.c
index 1551eeaa8..2858ff42f 100644
--- a/src/sleep.c
+++ b/src/sleep.c
@@ -17,6 +17,9 @@
#include <stdio.h>
#include <sys/types.h>
+#include <getopt.h>
+
+#include "version.h"
#include "system.h"
void error ();
@@ -26,6 +29,27 @@ static long argdecode ();
/* The name by which this program was run. */
char *program_name;
+/* If non-zero, display usage information and exit. */
+static int show_help;
+
+/* If non-zero, 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}
+};
+
+static void
+usage ()
+{
+ fprintf (stderr, "Usage: %s [{--help,--version}] number[smhd]...\n",
+ program_name);
+ exit (1);
+}
+
void
main (argc, argv)
int argc;
@@ -33,9 +57,31 @@ main (argc, argv)
{
int i;
unsigned seconds = 0;
+ int c;
program_name = argv[0];
+ while ((c = getopt_long (argc, argv, "", long_options, (int *) 0)) != EOF)
+ {
+ switch (c)
+ {
+ case 0:
+ break;
+
+ default:
+ usage ();
+ }
+ }
+
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (argc == 1)
{
fprintf (stderr, "Usage: %s number[smhd]...\n", argv[0]);
diff --git a/src/stty.c b/src/stty.c
index 1e0a59a3e..ea764ac33 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -45,7 +45,9 @@
#include <varargs.h>
#define VA_START(args, lastarg) va_start(args)
#endif
+
#include "system.h"
+#include "version.h"
#if defined(GWINSZ_BROKEN) /* Such as for SCO UNIX 3.2.2. */
#undef TIOCGWINSZ
@@ -365,10 +367,18 @@ static int max_col;
/* Current position, to know when to wrap. */
static int current_col;
+/* If non-zero, display usage information and exit. */
+static int show_help;
+
+/* If non-zero, print the version on standard output and exit. */
+static int show_version;
+
static struct option longopts[] =
{
{"all", no_argument, NULL, 'a'},
+ {"help", no_argument, &show_help, 1},
{"save", no_argument, NULL, 'g'},
+ {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -411,6 +421,15 @@ wrapf (message, va_alist)
current_col += buflen;
}
+static void
+usage ()
+{
+ fprintf (stderr,
+ "Usage: %s [{--help,--version}] [-ag] [--all] [--save] [setting...]\n",
+ program_name);
+ exit (1);
+}
+
void
main (argc, argv)
int argc;
@@ -425,14 +444,35 @@ main (argc, argv)
while ((optc = getopt_long (argc, argv, "ag", longopts, (int *) 0)) != EOF)
{
- if (optc == 'a')
- output_type = all;
- else if (optc == 'g')
- output_type = recoverable;
- else
- break;
+ switch (optc)
+ {
+ case 0:
+ break;
+
+ case 'a':
+ output_type = all;
+ break;
+
+ case 'g':
+ output_type = recoverable;
+ break;
+
+ default:
+ goto done;
+ }
+ }
+
+done:;
+
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
}
+ if (show_help)
+ usage ();
+
if (tcgetattr (0, &mode))
error (1, errno, "standard input");
@@ -853,6 +893,9 @@ mode_type_flag (type, mode)
case combination:
return NULL;
+
+ default:
+ abort ();
}
}
diff --git a/src/su.c b/src/su.c
index c94db90f0..7252a07e1 100644
--- a/src/su.c
+++ b/src/su.c
@@ -73,6 +73,7 @@
#include <getopt.h>
#include <sys/types.h>
#include <pwd.h>
+#include <grp.h>
#include "system.h"
#ifdef HAVE_SYSLOG_H
@@ -115,6 +116,8 @@ uid_t getuid ();
#include <shadow.h>
#endif
+#include "version.h"
+
/* The default PATH for simulated logins to non-superuser accounts. */
#define DEFAULT_LOGIN_PATH ":/usr/ucb:/bin:/usr/bin"
@@ -153,6 +156,12 @@ extern char **environ;
/* The name this program was run with. */
char *program_name;
+/* If non-zero, display usage information and exit. */
+static int show_help;
+
+/* If non-zero, 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;
@@ -166,9 +175,11 @@ static struct option const longopts[] =
{
{"command", required_argument, 0, 'c'},
{"fast", no_argument, &fast_startup, 1},
+ {"help", no_argument, &show_help, 1},
{"login", no_argument, &simulate_login, 1},
{"preserve-environment", no_argument, &change_environment, 0},
{"shell", required_argument, 0, 's'},
+ {"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
@@ -196,26 +207,42 @@ main (argc, argv)
{
case 0:
break;
+
case 'c':
command = optarg;
break;
+
case 'f':
fast_startup = 1;
break;
+
case 'l':
simulate_login = 1;
break;
+
case 'm':
case 'p':
change_environment = 0;
break;
+
case 's':
shell = optarg;
break;
+
default:
usage ();
}
}
+
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (optind < argc && !strcmp (argv[optind], "-"))
{
simulate_login = 1;
diff --git a/src/tee.c b/src/tee.c
index 941507fec..b107ee053 100644
--- a/src/tee.c
+++ b/src/tee.c
@@ -21,7 +21,9 @@
#include <sys/types.h>
#include <signal.h>
#include <getopt.h>
+
#include "system.h"
+#include "version.h"
char *xmalloc ();
void error ();
@@ -38,13 +40,31 @@ static int ignore_interrupts;
/* The name that this program was run with. */
char *program_name;
+/* If non-zero, display usage information and exit. */
+static int show_help;
+
+/* If non-zero, 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}
};
+static void
+usage ()
+{
+ fprintf (stderr, "\
+Usage: %s [{--help,--version}] [-ai] [--append]\n\
+ [--ignore-interrupts] [file...]\n",
+ program_name);
+ exit (1);
+}
+
void
main (argc, argv)
int argc;
@@ -62,20 +82,31 @@ main (argc, argv)
{
switch (optc)
{
+ case 0:
+ break;
+
case 'a':
append = 1;
break;
+
case 'i':
ignore_interrupts = 1;
break;
+
default:
- fprintf (stderr, "\
-Usage: %s [-ai] [--append] [--ignore-interrupts] [file...]\n",
- program_name);
- exit (1);
+ usage ();
}
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (ignore_interrupts)
{
#ifdef _POSIX_VERSION
diff --git a/src/test.c b/src/test.c
index b2cb92d22..d905c63e6 100644
--- a/src/test.c
+++ b/src/test.c
@@ -993,6 +993,18 @@ posixtest ()
return (value);
}
+#if defined (TEST_STANDALONE)
+void parse_long_options ();
+
+static void
+usage ()
+{
+ fprintf (stderr, "Usage: %s [{--help,--version}] [expr]\n",
+ program_name);
+ exit (1);
+}
+#endif /* TEST_STANDALONE */
+
/*
* [:
* '[' expr ']'
@@ -1026,6 +1038,8 @@ test_command (margc, margv)
if (margv[0] && strcmp (margv[0], "[") == 0)
{
+ parse_long_options (margc, margv, usage);
+
--margc;
if (margc < 2)
@@ -1041,6 +1055,7 @@ test_command (margc, margv)
if (pos >= argc)
test_exit (SHELL_BOOLEAN (FALSE));
+ parse_long_options (argc, argv, usage);
value = posixtest ();
if (pos != argc)
diff --git a/src/tty.c b/src/tty.c
index 79e1759e2..1839ae1b0 100644
--- a/src/tty.c
+++ b/src/tty.c
@@ -17,14 +17,19 @@
/* Displays "not a tty" if stdin is not a terminal.
Displays nothing if -s option is given.
- Exit status 0 if stdin is a tty, 1 if not, 2 if usage error.
+ Exit status 0 if stdin is a tty, 1 if not, 2 if usage error,
+ 3 if write error.
- Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
+ Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
+
#include "system.h"
+#include "version.h"
+
+void error ();
static void usage ();
@@ -34,10 +39,18 @@ char *program_name;
/* If nonzero, return an exit status but produce no output. */
static int silent;
+/* If non-zero, display usage information and exit. */
+static int show_help;
+
+/* If non-zero, 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}
};
@@ -56,14 +69,27 @@ main (argc, argv)
{
switch (optc)
{
+ case 0:
+ break;
+
case 's':
silent = 1;
break;
+
default:
usage ();
}
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (optind != argc)
usage ();
@@ -74,9 +100,12 @@ main (argc, argv)
puts (tty);
else
puts ("not a tty");
+
+ if (ferror (stdout) || fclose (stdout) == EOF)
+ error (3, errno, "standard output");
}
- exit (tty == NULL);
+ exit (isatty (0) ? 0 : 1);
}
static void
diff --git a/src/uname.c b/src/uname.c
index c247aecdd..366e1e34a 100644
--- a/src/uname.c
+++ b/src/uname.c
@@ -32,7 +32,9 @@
#include <sys/types.h>
#include <sys/utsname.h>
#include <getopt.h>
+
#include "system.h"
+#include "version.h"
void error ();
@@ -61,13 +63,20 @@ static unsigned char toprint;
/* The name this program was run with, for error messages. */
char *program_name;
+/* If non-zero, display usage information and exit. */
+static int show_help;
+
+/* If non-zero, print the version on standard output and exit. */
+static int show_version;
+
static struct option const long_options[] =
{
- {"sysname", no_argument, NULL, 's'},
+ {"help", no_argument, &show_help, 1},
+ {"machine", no_argument, NULL, 'm'},
{"nodename", no_argument, NULL, 'n'},
{"release", no_argument, NULL, 'r'},
- {"version", no_argument, NULL, 'v'},
- {"machine", no_argument, NULL, 'm'},
+ {"sysname", no_argument, NULL, 's'},
+ {"version", no_argument, &show_version, 1},
{"all", no_argument, NULL, 'a'},
{NULL, 0, NULL, 0}
};
@@ -88,30 +97,48 @@ main (argc, argv)
{
switch (c)
{
+ case 0:
+ break;
+
case 's':
toprint |= PRINT_SYSNAME;
break;
+
case 'n':
toprint |= PRINT_NODENAME;
break;
+
case 'r':
toprint |= PRINT_RELEASE;
break;
+
case 'v':
toprint |= PRINT_VERSION;
break;
+
case 'm':
toprint |= PRINT_MACHINE;
break;
+
case 'a':
toprint = PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
PRINT_VERSION | PRINT_MACHINE;
break;
+
default:
usage ();
}
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (optind != argc)
usage ();
diff --git a/src/who.c b/src/who.c
index 1edec4e67..15305a363 100644
--- a/src/who.c
+++ b/src/who.c
@@ -40,7 +40,9 @@
#ifndef _POSIX_SOURCE
#include <sys/param.h>
#endif
+
#include "system.h"
+#include "version.h"
#ifndef UTMP_FILE
#ifdef _PATH_UTMP /* 4.4BSD. */
@@ -75,6 +77,12 @@ static void who_am_i ();
/* The name this program was run with. */
char *program_name;
+/* If non-zero, display usage information and exit. */
+static int show_help;
+
+/* If non-zero, print the version on standard output and exit. */
+static int show_version;
+
/* If nonzero, display only a list of usernames and count of
the users logged on.
Ignored for `who am i'. */
@@ -95,10 +103,12 @@ static int include_mesg;
static struct option const longopts[] =
{
{"count", no_argument, NULL, 'q'},
+ {"help", no_argument, &show_help, 1},
{"idle", no_argument, NULL, 'u'},
{"heading", no_argument, NULL, 'H'},
{"message", no_argument, NULL, 'T'},
{"mesg", no_argument, NULL, 'T'},
+ {"version", no_argument, &show_version, 1},
{"writable", no_argument, NULL, 'T'},
{NULL, 0, NULL, 0}
};
@@ -118,6 +128,9 @@ main (argc, argv)
{
switch (optc)
{
+ case 0:
+ break;
+
case 'm':
my_line_only = 1;
break;
@@ -148,6 +161,15 @@ main (argc, argv)
}
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (chdir ("/dev"))
error (1, errno, "cannot change directory to /dev");