summaryrefslogtreecommitdiffstats
path: root/term-utils/wall.c
diff options
context:
space:
mode:
authorSami Kerola2011-04-06 21:31:01 +0200
committerKarel Zak2011-04-12 11:12:17 +0200
commit76cc41b7fb8cab196ef690d09bf8dab0232ddeac (patch)
treef37bf6103ef64fa83da3c91138a9d0a67f78ca5a /term-utils/wall.c
parentwall: remove global variables and support TMPDIR (diff)
downloadkernel-qcow2-util-linux-76cc41b7fb8cab196ef690d09bf8dab0232ddeac.tar.gz
kernel-qcow2-util-linux-76cc41b7fb8cab196ef690d09bf8dab0232ddeac.tar.xz
kernel-qcow2-util-linux-76cc41b7fb8cab196ef690d09bf8dab0232ddeac.zip
wall: use long options
Also --version & --help options added, and rewrote help output. Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'term-utils/wall.c')
-rw-r--r--term-utils/wall.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/term-utils/wall.c b/term-utils/wall.c
index d15068e96..eb47db375 100644
--- a/term-utils/wall.c
+++ b/term-utils/wall.c
@@ -57,6 +57,7 @@
#include <time.h>
#include <unistd.h>
#include <utmp.h>
+#include <getopt.h>
#include "nls.h"
#include "xalloc.h"
@@ -78,11 +79,19 @@
/* Function prototypes */
char *makemsg(char *fname, size_t *mbufsize, int print_banner);
+static void usage(FILE *out);
-static void __attribute__((__noreturn__)) usage(void)
+static void __attribute__((__noreturn__)) usage(FILE *out)
{
- errx(EXIT_FAILURE, _("usage: %s [-n] [file]\n"),
- program_invocation_short_name);
+ fprintf(out, _("Usage: %s [options] [file]\n"),
+ program_invocation_short_name);
+ fprintf(out, _(
+ "\nOptions:\n"
+ " -n, --nobanner do not print banner, works only for root\n"
+ " -V, --version output version information and exit\n"
+ " -h, --help display this help and exit\n\n"));
+
+ exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
int
@@ -101,21 +110,35 @@ main(int argc, char **argv) {
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- while ((ch = getopt(argc, argv, "n")) != -1) {
+ static const struct option longopts[] = {
+ { "nobanner", no_argument, 0, 'n' },
+ { "version", no_argument, 0, 'V' },
+ { "help", no_argument, 0, 'h' },
+ { NULL, 0, 0, 0 }
+ };
+
+ while ((ch = getopt_long(argc, argv, "nVh", longopts, NULL)) != -1) {
switch (ch) {
case 'n':
if (geteuid() == 0)
print_banner = FALSE;
+ else
+ warnx(_("--nobanner is available only for root"));
break;
- case '?':
+ case 'V':
+ printf(_("%s from %s\n"), program_invocation_short_name,
+ PACKAGE_STRING);
+ exit(EXIT_SUCCESS);
+ case 'h':
+ usage(stdout);
default:
- usage();
+ usage(stderr);
}
}
argc -= optind;
argv += optind;
if (argc > 1)
- usage();
+ usage(stderr);
mbuf = makemsg(*argv, &mbufsize, print_banner);