All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/6] ethtool: move option parsing related code into function
@ 2019-03-01  8:15 Jeff Kirsher
  2019-03-01  8:15 ` [PATCH v3 2/6] ethtool: move cmdline_coalesce out of do_scoalesce Jeff Kirsher
                   ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Jeff Kirsher @ 2019-03-01  8:15 UTC (permalink / raw)
  To: linville; +Cc: Nicholas Nunley, netdev

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>
---
 ethtool.c | 49 +++++++++++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 18 deletions(-)

diff --git a/ethtool.c b/ethtool.c
index fb4c088..917626f 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5268,6 +5268,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 *);
@@ -5287,24 +5310,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


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

end of thread, other threads:[~2019-03-14 18:45 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-01  8:15 [PATCH v3 1/6] ethtool: move option parsing related code into function Jeff Kirsher
2019-03-01  8:15 ` [PATCH v3 2/6] ethtool: move cmdline_coalesce out of do_scoalesce Jeff Kirsher
2019-03-01 13:50   ` Michal Kubecek
2019-03-01  8:15 ` [PATCH v3 3/6] ethtool: introduce new ioctl for per-queue settings Jeff Kirsher
2019-03-01 14:18   ` Michal Kubecek
2019-03-01 23:35     ` Nunley, Nicholas D
2019-03-01  8:15 ` [PATCH v3 4/6] ethtool: support per-queue sub command --show-coalesce Jeff Kirsher
2019-03-01 14:26   ` Michal Kubecek
2019-03-01  8:15 ` [PATCH v3 5/6] ethtool: support per-queue sub command --coalesce Jeff Kirsher
2019-03-01 14:28   ` Michal Kubecek
2019-03-01  8:15 ` [PATCH v3 6/6] ethtool: fix up dump_coalesce output to match actual option names Jeff Kirsher
2019-03-01 14:38   ` Michal Kubecek
2019-03-01 13:42 ` [PATCH v3 1/6] ethtool: move option parsing related code into function Michal Kubecek
2019-03-14 18:37 ` John W. Linville

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.