Cygwin: utils: chattr: Improve option parsing, fix some messages.

Allow multiple characters also in first '-mode' argument.
Use '-H' instead of '-h' for '--help' to fix ambiguity with
hidden attribute.  Fix help and usage texts and documentation.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
This commit is contained in:
Christian Franke 2021-05-20 11:05:29 +02:00 committed by Corinna Vinschen
parent 0c0f3df224
commit cb674a4ad1
2 changed files with 19 additions and 23 deletions

View File

@ -27,18 +27,18 @@
<refsynopsisdiv> <refsynopsisdiv>
<screen> <screen>
chattr [-RVfhv] [+-=mode]... [file]... chattr [-RVfHv] [+-=mode]... [file]...
</screen> </screen>
</refsynopsisdiv> </refsynopsisdiv>
<refsect1 id="chattr-options"> <refsect1 id="chattr-options">
<title>Options</title> <title>Options</title>
<screen> <screen>
-R, --recursive recursively list attributes of directories and their -R, --recursive recursively apply the changes to directories and
contents their contents
-V, --verbose Be verbose during operation -V, --verbose Be verbose during operation
-f, --force suppress error messages -f, --force suppress error messages
-h, --help this help text -H, --help this help text
-v, --version display the program version -v, --version display the program version
</screen> </screen>
</refsect1> </refsect1>

View File

@ -28,12 +28,12 @@ struct option longopts[] = {
{ "recursive", no_argument, NULL, 'R' }, { "recursive", no_argument, NULL, 'R' },
{ "verbose", no_argument, NULL, 'V' }, { "verbose", no_argument, NULL, 'V' },
{ "force", no_argument, NULL, 'f' }, { "force", no_argument, NULL, 'f' },
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'H' },
{ "version", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'v' },
{ NULL, no_argument, NULL, 0} { NULL, no_argument, NULL, 0}
}; };
const char *opts = "+RVfhv"; const char *opts = "+RVfHv";
struct struct
{ {
@ -211,7 +211,7 @@ static void
print_version () print_version ()
{ {
printf ("%s (cygwin) %d.%d.%d\n" printf ("%s (cygwin) %d.%d.%d\n"
"Get POSIX ACL information\n" "Change file attributes\n"
"Copyright (C) 2018 - %s Cygwin Authors\n" "Copyright (C) 2018 - %s Cygwin Authors\n"
"This is free software; see the source for copying conditions. " "This is free software; see the source for copying conditions. "
"There is NO\n" "There is NO\n"
@ -227,7 +227,7 @@ print_version ()
static void __attribute__ ((__noreturn__)) static void __attribute__ ((__noreturn__))
usage (FILE *stream) usage (FILE *stream)
{ {
fprintf (stream, "Usage: %s [-RVfhv] [+-=mode]... [file]...\n", fprintf (stream, "Usage: %s [-RVfHv] [+-=mode]... [file]...\n",
program_invocation_short_name); program_invocation_short_name);
if (stream == stderr) if (stream == stderr)
fprintf (stream, "Try '%s --help' for more information\n", fprintf (stream, "Try '%s --help' for more information\n",
@ -236,11 +236,11 @@ usage (FILE *stream)
fprintf (stream, "\n" fprintf (stream, "\n"
"Change file attributes\n" "Change file attributes\n"
"\n" "\n"
" -R, --recursive recursively list attributes of directories and their \n" " -R, --recursive recursively apply the changes to directories and their\n"
" contents\n" " contents\n"
" -V, --verbose Be verbose during operation\n" " -V, --verbose Be verbose during operation\n"
" -f, --force suppress error messages\n" " -f, --force suppress error messages\n"
" -h, --help this help text\n" " -H, --help this help text\n"
" -v, --version display the program version\n" " -v, --version display the program version\n"
"\n" "\n"
"The format of 'mode' is {+-=}[acCehnrsSt]\n" "The format of 'mode' is {+-=}[acCehnrsSt]\n"
@ -271,7 +271,7 @@ int
main (int argc, char **argv) main (int argc, char **argv)
{ {
int c, ret = 0; int c, ret = 0;
int lastoptind = 0; int lastoptind = 1;
char *opt; char *opt;
opterr = 0; opterr = 0;
@ -281,15 +281,15 @@ main (int argc, char **argv)
{ {
case 'R': case 'R':
Ropt = 1; Ropt = 1;
lastoptind = optind;
break; break;
case 'V': case 'V':
Vopt = 1; Vopt = 1;
lastoptind = optind;
break; break;
case 'f': case 'f':
fopt = 1; fopt = 1;
lastoptind = optind; break;
case 'H':
usage (stdout);
break; break;
case 'v': case 'v':
print_version (); print_version ();
@ -297,14 +297,10 @@ main (int argc, char **argv)
break; break;
default: default:
if (optind > lastoptind) if (optind > lastoptind)
{
--optind; --optind;
goto next; goto next;
} }
/*FALLTHRU*/ lastoptind = optind;
case 'h':
usage (c == 'h' ? stdout : stderr);
}
} }
next: next:
while (optind < argc) while (optind < argc)