]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
wall: use long options
authorSami Kerola <kerolasa@iki.fi>
Wed, 6 Apr 2011 19:31:01 +0000 (21:31 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 12 Apr 2011 09:12:17 +0000 (11:12 +0200)
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>
term-utils/wall.c

index d15068e969c411e4eac8f5d627e2b0b3d015e63e..eb47db3750c69420f2b3de82cb5d4ef7b493c33c 100644 (file)
@@ -57,6 +57,7 @@
 #include <time.h>
 #include <unistd.h>
 #include <utmp.h>
+#include <getopt.h>
 
 #include "nls.h"
 #include "xalloc.h"
 
 /* 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);