public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: utils: chattr: Improve option parsing.
@ 2021-05-19 15:46 Christian Franke
  2021-05-19 17:47 ` Corinna Vinschen
  0 siblings, 1 reply; 7+ messages in thread
From: Christian Franke @ 2021-05-19 15:46 UTC (permalink / raw)
  To: cygwin-patches

[-- 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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-05-20 20:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19 15:46 [PATCH] Cygwin: utils: chattr: Improve option parsing Christian Franke
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

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).