diff options
author | Sami Kerola | 2011-04-10 16:24:21 +0200 |
---|---|---|
committer | Karel Zak | 2011-04-14 17:07:26 +0200 |
commit | fe16e1251327902bfd18ae287328d4ef9eeb9c24 (patch) | |
tree | 6fcc5224cb55b11c883ccca889a89abd7095a08c /term-utils/mesg.c | |
parent | agetty: coding style - fix identation (diff) | |
download | kernel-qcow2-util-linux-fe16e1251327902bfd18ae287328d4ef9eeb9c24.tar.gz kernel-qcow2-util-linux-fe16e1251327902bfd18ae287328d4ef9eeb9c24.tar.xz kernel-qcow2-util-linux-fe16e1251327902bfd18ae287328d4ef9eeb9c24.zip |
mesg: use long options, also --help and --version added
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'term-utils/mesg.c')
-rw-r--r-- | term-utils/mesg.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/term-utils/mesg.c b/term-utils/mesg.c index 6176aabfb..33f19413c 100644 --- a/term-utils/mesg.c +++ b/term-utils/mesg.c @@ -53,6 +53,7 @@ #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> +#include <getopt.h> #include "nls.h" #include "c.h" @@ -62,6 +63,18 @@ #define IS_NOT_ALLOWED 1 /* Receiving messages is not allowed. */ #define MESG_EXIT_FAILURE 2 /* An error occurred. */ +static void __attribute__ ((__noreturn__)) usage(FILE * out) +{ + fprintf(out, _("\nUsage:\n" + " %s [options] [y | n]\n"), program_invocation_short_name); + fprintf(out, + _("\nOptions:\n" + " -V, --version output version information and exit\n" + " -h, --help output help screen and exit\n")); + + exit(out == stderr ? MESG_EXIT_FAILURE : EXIT_SUCCESS); +} + int main(int argc, char *argv[]) { struct stat sb; @@ -72,11 +85,22 @@ int main(int argc, char *argv[]) bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - while ((ch = getopt(argc, argv, "")) != -1) + static const struct option longopts[] = { + { "version", no_argument, 0, 'V' }, + { "help", no_argument, 0, 'h' }, + { NULL, 0, 0, 0 } + }; + + while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) switch (ch) { - case '?': + case 'V': + printf(_("%s from %s\n"), program_invocation_short_name, + PACKAGE_STRING); + exit(EXIT_SUCCESS); + case 'h': + usage(stdout); default: - goto usage; + usage(stderr); } argc -= optind; @@ -110,9 +134,8 @@ int main(int argc, char *argv[]) if (chmod(tty, sb.st_mode & ~(S_IWGRP|S_IWOTH)) < 0) err(MESG_EXIT_FAILURE, _("change %s mode failed"), tty); return IS_NOT_ALLOWED; + default: + warnx(_("invalid argument: %c"), *argv[0]); + usage(stderr); } - -usage: - fprintf(stderr, _("Usage: %s [y | n]"), program_invocation_short_name); - return MESG_EXIT_FAILURE; } |