[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1450335186-3062-1-git-send-email-kan.liang@intel.com>
Date: Thu, 17 Dec 2015 06:53:02 +0000
From: kan.liang@...el.com
To: netdev@...r.kernel.org, davem@...emloft.net, bwh@...nel.org
Cc: jesse.brandeburg@...el.com, andi@...stfloor.org,
f.fainelli@...il.com, alexander.duyck@...il.com,
jeffrey.t.kirsher@...el.com, shannon.nelson@...el.com,
carolyn.wyborny@...el.com, donald.c.skidmore@...el.com,
mitch.a.williams@...el.com, ogerlitz@...lanox.com,
edumazet@...gle.com, jiri@...lanox.com, sfeldma@...il.com,
gospo@...ulusnetworks.com, sasha.levin@...cle.com,
dsahern@...il.com, tj@...nel.org, cascardo@...hat.com,
corbet@....net, ben@...adent.org.uk,
Kan Liang <kan.liang@...el.com>
Subject: [RFC 1/5] ethtool: move option parsing related codes into function
From: Kan Liang <kan.liang@...el.com>
Move option parsing code into find_option function.
No behavior changes.
Signed-off-by: Kan Liang <kan.liang@...el.com>
---
ethtool.c | 49 +++++++++++++++++++++++++++++++------------------
1 file changed, 31 insertions(+), 18 deletions(-)
diff --git a/ethtool.c b/ethtool.c
index 92c40b8..04c5015 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -4173,6 +4173,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 *);
@@ -4190,24 +4213,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();
--
1.7.11.7
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists