netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] ethtool: move option parsing related codes into function
@ 2016-05-15  7:14 kan.liang
  2016-05-15  7:14 ` [PATCH 2/5] ethtool: move cmdline_coalesce out of do_scoalesce kan.liang
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: kan.liang @ 2016-05-15  7:14 UTC (permalink / raw)
  To: bwh; +Cc: netdev, davem, nicolas.dichtel, ben, jesse.brandeburg, andi,
	Kan Liang

From: Kan Liang <kan.liang@intel.com>

Move option parsing code into find_option function.
No behavior changes.

Signed-off-by: Kan Liang <kan.liang@intel.com>
---
 ethtool.c | 49 +++++++++++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 18 deletions(-)

diff --git a/ethtool.c b/ethtool.c
index 0cd0d4f..bd0583c 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -4223,6 +4223,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 *);
@@ -4240,24 +4263,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.5.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [PATCH 1/5] ethtool: move option parsing related codes into function
@ 2016-03-14  9:30 kan.liang
  2016-03-14  9:30 ` [PATCH 4/5] ethtool: support per queue sub command --show-coalesce kan.liang
  0 siblings, 1 reply; 7+ messages in thread
From: kan.liang @ 2016-03-14  9:30 UTC (permalink / raw)
  To: bwh; +Cc: davem, nicolas.dichtel, ben, jesse.brandeburg, andi, netdev,
	Kan Liang

From: Kan Liang <kan.liang@intel.com>

Move option parsing code into find_option function.
No behavior changes.

Signed-off-by: Kan Liang <kan.liang@intel.com>
---
 ethtool.c | 49 +++++++++++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 18 deletions(-)

diff --git a/ethtool.c b/ethtool.c
index 0cd0d4f..bd0583c 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -4223,6 +4223,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 *);
@@ -4240,24 +4263,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.5.0

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

end of thread, other threads:[~2016-06-26 15:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-15  7:14 [PATCH 1/5] ethtool: move option parsing related codes into function kan.liang
2016-05-15  7:14 ` [PATCH 2/5] ethtool: move cmdline_coalesce out of do_scoalesce kan.liang
2016-06-26 15:05   ` Ben Hutchings
2016-05-15  7:14 ` [PATCH 3/5] ethtool: introduce new ioctl for per queue setting kan.liang
2016-05-15  7:14 ` [PATCH 4/5] ethtool: support per queue sub command --show-coalesce kan.liang
2016-05-15  7:14 ` [PATCH 5/5] ethtool: support per queue sub command --coalesce kan.liang
  -- strict thread matches above, loose matches on Subject: below --
2016-03-14  9:30 [PATCH 1/5] ethtool: move option parsing related codes into function kan.liang
2016-03-14  9:30 ` [PATCH 4/5] ethtool: support per queue sub command --show-coalesce kan.liang

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