From: Christian Franke <Christian.Franke@t-online.de>
To: cygwin-patches@cygwin.com
Subject: [PATCH] Cygwin: utils: chattr: Improve option parsing.
Date: Wed, 19 May 2021 17:46:31 +0200 [thread overview]
Message-ID: <d515bfba-ce77-40c0-0c3e-67895675f753@t-online.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 668 bytes --]
This possibly improves the usability of chattr for some typical use cases:
Command : Old : New behavior
================================================
chattr -h : help : help
chattr -h FILE : help : chattr -- -h -- FILE
chattr -hs FILE : help : chattr -- -h -s -- FILE
chattr -sh FILE : fail : chattr -- -s -h -- FILE
chattr -ar FILE : fail : chattr -- -a -r -- FILE
Unrelated: there a two trivial block-copied-but-not-changed issues:
$ egrep 'ACL|--r' chattr.c
"Get POSIX ACL information\n"
" -R, --recursive recursively list attributes of directories
and their \n"
Regards,
Christian
[-- Attachment #2: 0001-Cygwin-utils-chattr-Improve-option-parsing.patch --]
[-- Type: text/plain, Size: 1370 bytes --]
From 865a5a50501f3fd0cf5ed28500d3e6e45a6456de Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Wed, 19 May 2021 16:24:47 +0200
Subject: [PATCH] Cygwin: utils: chattr: Improve option parsing.
Interpret '-h' as '--help' only if last argument.
Allow multiple characters in first '-mode' argument.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
---
winsup/utils/chattr.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/winsup/utils/chattr.c b/winsup/utils/chattr.c
index 98f693aab..f6ce340b4 100644
--- a/winsup/utils/chattr.c
+++ b/winsup/utils/chattr.c
@@ -271,7 +271,7 @@ int
main (int argc, char **argv)
{
int c, ret = 0;
- int lastoptind = 0;
+ int lastoptind = 1;
char *opt;
opterr = 0;
@@ -295,15 +295,16 @@ main (int argc, char **argv)
print_version ();
return 0;
break;
+ case 'h':
+ /* Print help if -h is last argument or --help is used,
+ otherwise interpret -h as 'remove hidden attribute'. */
+ if (optind >= argc || (optind > lastoptind && argv[optind-1][1] == '-'))
+ usage (stdout);
+ /*FALLTHRU*/
default:
if (optind > lastoptind)
- {
- --optind;
- goto next;
- }
- /*FALLTHRU*/
- case 'h':
- usage (c == 'h' ? stdout : stderr);
+ --optind;
+ goto next;
}
}
next:
--
2.31.1
next reply other threads:[~2021-05-19 15:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-19 15:46 Christian Franke [this message]
2021-05-19 17:47 ` Corinna Vinschen
2021-05-20 10:01 ` Christian Franke
2021-05-20 17:57 ` Corinna Vinschen
2021-05-20 19:48 ` Christian Franke
2021-05-20 20:19 ` Corinna Vinschen
2021-05-20 20:40 ` Corinna Vinschen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d515bfba-ce77-40c0-0c3e-67895675f753@t-online.de \
--to=christian.franke@t-online.de \
--cc=cygwin-patches@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).