linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
To: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: [PATCH 2/3] btrfs-progs: prop: simplify parse_args()
Date: Mon, 9 May 2016 16:49:19 +0900	[thread overview]
Message-ID: <573040FF.5060601@jp.fujitsu.com> (raw)
In-Reply-To: <57303A21.9070308@jp.fujitsu.com>

Since <object> parameter is mandatory for all subcommands,
'object' is always set by parse_args()'s callers.
In addition, on setting '*name' and '*value', if 'optind < argc'
is satisfied here, they are always set by parse_args()'s callers.

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>

---
 cmds-property.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/cmds-property.c b/cmds-property.c
index 48a8945..46be8f3 100644
--- a/cmds-property.c
+++ b/cmds-property.c
@@ -298,7 +298,7 @@ static void parse_args(int argc, char **argv,
 {
 	int ret;
 	char *type_str = NULL;
-	int max_nonopt_args = 0;
+	int max_nonopt_args = 1;

 	optind = 1;
 	while (1) {
@@ -315,8 +315,6 @@ static void parse_args(int argc, char **argv,
 		}
 	}

-	if (object)
-		max_nonopt_args++;
 	if (name)
 		max_nonopt_args++;
 	if (value)
@@ -345,14 +343,13 @@ static void parse_args(int argc, char **argv,
 		}
 	}

-	if (object && optind < argc)
-		*object = argv[optind++];
-	if (name && optind < argc)
+	*object = argv[optind++];
+	if (optind < argc)
 		*name = argv[optind++];
-	if (value && optind < argc)
+	if (optind < argc)
 		*value = argv[optind++];

-	if (!*types && object && *object) {
+	if (!*types) {
 		ret = autodetect_object_types(*object, types);
 		if (ret < 0) {
 			error("failed to detect object type: %s",
-- 
2.5.5

  reply	other threads:[~2016-05-09  7:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-09  7:20 [PATCH 1/3] btrfs-progs: prop: convert error messages to use error() Satoru Takeuchi
2016-05-09  7:49 ` Satoru Takeuchi [this message]
2016-05-09  7:52 ` [PATCH 3/3] btrfs-progs: prop: remove conditions which never be satisfied Satoru Takeuchi
2016-05-09 15:56 ` [PATCH 1/3] btrfs-progs: prop: convert error messages to use error() David Sterba

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=573040FF.5060601@jp.fujitsu.com \
    --to=takeuchi_satoru@jp.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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 NNTP newsgroup(s).