From: Ben Hutchings <bhutchings@solarflare.com>
To: netdev@vger.kernel.org
Subject: [PATCH ethtool 3/5] ethtool: Allow for long options with no short option and without a device name
Date: Mon, 21 Feb 2011 19:18:36 +0000 [thread overview]
Message-ID: <1298315916.2608.71.camel@bwh-desktop> (raw)
In-Reply-To: <1298315809.2608.68.camel@bwh-desktop>
Change loop conditions to check for a long option string.
Generalise check for whether option requires a device name.
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
---
ethtool.c | 23 ++++++++++++++---------
1 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/ethtool.c b/ethtool.c
index d28f1b2..8246bda 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -287,12 +287,16 @@ static void show_usage(void)
fprintf(stdout,
"Usage:\n"
"ethtool DEVNAME\tDisplay standard information about device\n");
- for (i = 0; args[i].srt; i++) {
- fprintf(stdout, " ethtool %s|%s %s\t%s\n%s",
- args[i].srt, args[i].lng,
- strstr(args[i].srt, "-h") ? "\t" : "DEVNAME",
- args[i].help,
- args[i].opthelp ? args[i].opthelp : "");
+ for (i = 0; args[i].lng; i++) {
+ fputs(" ethtool ", stdout);
+ if (args[i].srt)
+ fprintf(stdout, "%s|", args[i].srt);
+ fprintf(stdout, "%s %s\t%s\n",
+ args[i].lng,
+ args[i].Mode < 0 ? "\t" : "DEVNAME",
+ args[i].help);
+ if (args[i].opthelp)
+ fputs(args[i].opthelp, stdout);
}
}
@@ -801,8 +805,9 @@ static void parse_cmdline(int argc, char **argp)
for (i = 1; i < argc; i++) {
switch (i) {
case 1:
- for (k = 0; args[k].srt; k++)
- if (!strcmp(argp[i], args[k].srt) ||
+ for (k = 0; args[k].lng; k++)
+ if ((args[k].srt &&
+ !strcmp(argp[i], args[k].srt)) ||
!strcmp(argp[i], args[k].lng)) {
mode = args[k].Mode;
break;
@@ -810,7 +815,7 @@ static void parse_cmdline(int argc, char **argp)
if (mode == MODE_HELP) {
show_usage();
exit(0);
- } else if (!args[k].srt && argp[i][0] == '-') {
+ } else if (!args[k].lng && argp[i][0] == '-') {
exit_bad_args();
} else {
devname = argp[i];
--
1.7.3.4
--
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
next prev parent reply other threads:[~2011-02-21 19:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-21 19:16 [PATCH ethtool 0/5] Add --version option and fix some bugs in show_usage() Ben Hutchings
2011-02-21 19:17 ` [PATCH ethtool 1/5] ethtool: Split show_usage() into two functions Ben Hutchings
2011-02-21 19:18 ` [PATCH ethtool 2/5] ethtool: Report an error if given an unrecognised option Ben Hutchings
2011-02-21 19:18 ` Ben Hutchings [this message]
2011-02-21 19:18 ` [PATCH ethtool 4/5] ethtool: Indent the no-options usage line consistently with the others Ben Hutchings
2011-02-21 19:19 ` [PATCH ethtool 5/5] ethtool: Add --version option Ben Hutchings
2011-02-22 6:16 ` Stephen Hemminger
2011-02-22 12:37 ` Ben Hutchings
2011-02-22 13:05 ` Eric Dumazet
2011-02-22 21:35 ` Jeff Garzik
2011-02-22 21:49 ` Ben Hutchings
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=1298315916.2608.71.camel@bwh-desktop \
--to=bhutchings@solarflare.com \
--cc=netdev@vger.kernel.org \
/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