mesg: new --verbose option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
ea87bbf679
commit
849c6ea3f7
|
@ -71,6 +71,9 @@ Permits messages to be displayed.
|
||||||
.TP
|
.TP
|
||||||
Available options:
|
Available options:
|
||||||
.TP
|
.TP
|
||||||
|
.B \-v, \-\-verbose
|
||||||
|
Explain what is being done.
|
||||||
|
.TP
|
||||||
.B \-V, \-\-verbose
|
.B \-V, \-\-verbose
|
||||||
Output version information and exit.
|
Output version information and exit.
|
||||||
.TP
|
.TP
|
||||||
|
|
|
@ -69,6 +69,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
|
||||||
" %s [options] [y | n]\n"), program_invocation_short_name);
|
" %s [options] [y | n]\n"), program_invocation_short_name);
|
||||||
fprintf(out,
|
fprintf(out,
|
||||||
_("\nOptions:\n"
|
_("\nOptions:\n"
|
||||||
|
" -v, --verbose explain what is being done\n"
|
||||||
" -V, --version output version information and exit\n"
|
" -V, --version output version information and exit\n"
|
||||||
" -h, --help output help screen and exit\n"));
|
" -h, --help output help screen and exit\n"));
|
||||||
|
|
||||||
|
@ -79,20 +80,24 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char *tty;
|
char *tty;
|
||||||
int ch;
|
int ch, verbose = FALSE;
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||||
textdomain(PACKAGE);
|
textdomain(PACKAGE);
|
||||||
|
|
||||||
static const struct option longopts[] = {
|
static const struct option longopts[] = {
|
||||||
|
{ "verbose", no_argument, 0, 'v' },
|
||||||
{ "version", no_argument, 0, 'V' },
|
{ "version", no_argument, 0, 'V' },
|
||||||
{ "help", no_argument, 0, 'h' },
|
{ "help", no_argument, 0, 'h' },
|
||||||
{ NULL, 0, 0, 0 }
|
{ NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
|
while ((ch = getopt_long(argc, argv, "vVh", longopts, NULL)) != -1)
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
|
case 'v':
|
||||||
|
verbose = TRUE;
|
||||||
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
printf(_("%s from %s\n"), program_invocation_short_name,
|
printf(_("%s from %s\n"), program_invocation_short_name,
|
||||||
PACKAGE_STRING);
|
PACKAGE_STRING);
|
||||||
|
@ -129,10 +134,14 @@ int main(int argc, char *argv[])
|
||||||
if (chmod(tty, sb.st_mode | S_IWGRP | S_IWOTH) < 0)
|
if (chmod(tty, sb.st_mode | S_IWGRP | S_IWOTH) < 0)
|
||||||
#endif
|
#endif
|
||||||
err(MESG_EXIT_FAILURE, _("change %s mode failed"), tty);
|
err(MESG_EXIT_FAILURE, _("change %s mode failed"), tty);
|
||||||
|
if (verbose)
|
||||||
|
puts(_("write access to your terminal is allowed"));
|
||||||
return IS_ALLOWED;
|
return IS_ALLOWED;
|
||||||
case 'n':
|
case 'n':
|
||||||
if (chmod(tty, sb.st_mode & ~(S_IWGRP|S_IWOTH)) < 0)
|
if (chmod(tty, sb.st_mode & ~(S_IWGRP|S_IWOTH)) < 0)
|
||||||
err(MESG_EXIT_FAILURE, _("change %s mode failed"), tty);
|
err(MESG_EXIT_FAILURE, _("change %s mode failed"), tty);
|
||||||
|
if (verbose)
|
||||||
|
puts(_("write access to your terminal is denied"));
|
||||||
return IS_NOT_ALLOWED;
|
return IS_NOT_ALLOWED;
|
||||||
default:
|
default:
|
||||||
warnx(_("invalid argument: %c"), *argv[0]);
|
warnx(_("invalid argument: %c"), *argv[0]);
|
||||||
|
|
Loading…
Reference in New Issue