From: kan.liang@intel.com
To: bwh@kernel.org
Cc: davem@davemloft.net, nicolas.dichtel@6wind.com,
ben@decadent.org.uk, jesse.brandeburg@intel.com,
andi@firstfloor.org, netdev@vger.kernel.org,
Kan Liang <kan.liang@intel.com>
Subject: [PATCH 1/5] ethtool: move option parsing related codes into function
Date: Mon, 14 Mar 2016 02:30:03 -0700 [thread overview]
Message-ID: <1457947807-4804-1-git-send-email-kan.liang@intel.com> (raw)
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
next reply other threads:[~2016-03-14 16:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-14 9:30 kan.liang [this message]
2016-03-14 9:30 ` [PATCH 2/5] ethtool: move cmdline_coalesce out of do_scoalesce kan.liang
2016-03-14 9:30 ` [PATCH 3/5] ethtool: introduce new ioctl for per queue setting kan.liang
2016-03-14 9:30 ` [PATCH 4/5] ethtool: support per queue sub command --show-coalesce kan.liang
2016-03-14 9:30 ` [PATCH 5/5] ethtool: support per queue sub command --coalesce kan.liang
-- strict thread matches above, loose matches on Subject: below --
2016-05-15 7:14 [PATCH 1/5] ethtool: move option parsing related codes into function kan.liang
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=1457947807-4804-1-git-send-email-kan.liang@intel.com \
--to=kan.liang@intel.com \
--cc=andi@firstfloor.org \
--cc=ben@decadent.org.uk \
--cc=bwh@kernel.org \
--cc=davem@davemloft.net \
--cc=jesse.brandeburg@intel.com \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.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;
as well as URLs for NNTP newsgroup(s).