Netdev List
 help / color / mirror / Atom feed
From: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
To: linville@tuxdriver.com
Cc: Nicholas Nunley <nicholas.d.nunley@intel.com>,
	netdev@vger.kernel.org, nhorman@redhat.com, sassmann@redhat.com,
	Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Subject: [PATCH v2 1/6] ethtool: move option parsing related code into function
Date: Tue,  5 Feb 2019 16:01:01 -0800	[thread overview]
Message-ID: <20190206000106.24364-1-jeffrey.t.kirsher@intel.com> (raw)

From: Nicholas Nunley <nicholas.d.nunley@intel.com>

Move option parsing code into find_option function.

No behavior changes.

Based on patch by Kan Liang <kan.liang@intel.com>

Signed-off-by: Nicholas Nunley <nicholas.d.nunley@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---
 ethtool.c | 49 +++++++++++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 18 deletions(-)

diff --git a/ethtool.c b/ethtool.c
index 2f7e96b..8b7c224 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5265,6 +5265,29 @@ static int show_usage(struct cmd_context *ctx)
 	return 0;
 }
 
+static int find_option(int argc, char **argp)
+{
+	const char *opt;
+	size_t len;
+	int k;
+
+	for (k = 0; args[k].opts; k++) {
+		opt = args[k].opts;
+		for (;;) {
+			len = strcspn(opt, "|");
+			if (strncmp(*argp, opt, len) == 0 &&
+			    (*argp)[len] == 0)
+				return k;
+
+			if (opt[len] == 0)
+				break;
+			opt += len + 1;
+		}
+	}
+
+	return -1;
+}
+
 int main(int argc, char **argp)
 {
 	int (*func)(struct cmd_context *);
@@ -5284,24 +5307,14 @@ int main(int argc, char **argp)
 	 */
 	if (argc == 0)
 		exit_bad_args();
-	for (k = 0; args[k].opts; k++) {
-		const char *opt;
-		size_t len;
-		opt = args[k].opts;
-		for (;;) {
-			len = strcspn(opt, "|");
-			if (strncmp(*argp, opt, len) == 0 &&
-			    (*argp)[len] == 0) {
-				argp++;
-				argc--;
-				func = args[k].func;
-				want_device = args[k].want_device;
-				goto opt_found;
-			}
-			if (opt[len] == 0)
-				break;
-			opt += len + 1;
-		}
+
+	k = find_option(argc, argp);
+	if (k >= 0) {
+		argp++;
+		argc--;
+		func = args[k].func;
+		want_device = args[k].want_device;
+		goto opt_found;
 	}
 	if ((*argp)[0] == '-')
 		exit_bad_args();
-- 
2.20.1


             reply	other threads:[~2019-02-06  0:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-06  0:01 Jeff Kirsher [this message]
2019-02-06  0:01 ` [PATCH v2 2/6] ethtool: move cmdline_coalesce out of do_scoalesce Jeff Kirsher
2019-02-06  0:01 ` [PATCH v2 3/6] ethtool: introduce new ioctl for per-queue settings Jeff Kirsher
2019-02-06  9:18   ` Michal Kubecek
2019-02-07 23:37     ` Nunley, Nicholas D
2019-02-08  7:02       ` Michal Kubecek
2019-02-08 13:56         ` Willem de Bruijn
2019-02-06 10:32   ` Michal Kubecek
2019-02-07 23:41     ` Nunley, Nicholas D
2019-02-06 12:43   ` Michal Kubecek
2019-02-07 23:43     ` Nunley, Nicholas D
2019-02-06  0:01 ` [PATCH v2 4/6] ethtool: support per-queue sub command --show-coalesce Jeff Kirsher
2019-02-06 13:22   ` Michal Kubecek
2019-02-07 23:53     ` Nunley, Nicholas D
2019-02-08  7:10       ` Michal Kubecek
2019-02-06  0:01 ` [PATCH v2 5/6] ethtool: support per-queue sub command --coalesce Jeff Kirsher
2019-02-06  0:01 ` [PATCH v2 6/6] ethtool: fix up dump_coalesce output to match actual option names Jeff Kirsher
2019-02-06  9:56 ` [PATCH v2 1/6] ethtool: move option parsing related code into function Michal Kubecek

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=20190206000106.24364-1-jeffrey.t.kirsher@intel.com \
    --to=jeffrey.t.kirsher@intel.com \
    --cc=linville@tuxdriver.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@redhat.com \
    --cc=nicholas.d.nunley@intel.com \
    --cc=sassmann@redhat.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