From: Olivier Matz <olivier.matz@6wind.com>
To: dev@dpdk.org, bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com
Subject: [dpdk-dev] [PATCH 2/2] l2fwd: rework long options parsing
Date: Tue, 22 Nov 2016 14:52:16 +0100 [thread overview]
Message-ID: <1479822736-32399-3-git-send-email-olivier.matz@6wind.com> (raw)
In-Reply-To: <1479822736-32399-1-git-send-email-olivier.matz@6wind.com>
Do the same than in l3fwd to avoid strcmp() for long options.
For l2fwd, there is no long option that take advantage of this new
mechanism as --mac-updating and --no-mac-updating are directly setting a
flag without needing an entry in the switch/case.
So this patch just prepares the framework in case a new long option is
added in the future.
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
examples/l2fwd/main.c | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c
index b2f5851..97d6454 100644
--- a/examples/l2fwd/main.c
+++ b/examples/l2fwd/main.c
@@ -392,6 +392,29 @@ l2fwd_parse_timer_period(const char *q_arg)
return n;
}
+static const char short_options[] =
+ "p:" /* portmask */
+ "q:" /* number of queues */
+ "T:" /* timer period */
+ ;
+
+#define CMD_LINE_OPT_MAC_UPDATING "mac-updating"
+#define CMD_LINE_OPT_NO_MAC_UPDATING "no-mac-updating"
+
+enum {
+ /* long options mapped to a short option */
+
+ /* first long only option value must be >= 256, so that we won't
+ * conflict with short options */
+ CMD_LINE_OPT_MIN_NUM = 256,
+};
+
+static const struct option lgopts[] = {
+ { CMD_LINE_OPT_MAC_UPDATING, no_argument, &mac_updating, 1},
+ { CMD_LINE_OPT_NO_MAC_UPDATING, no_argument, &mac_updating, 0},
+ {NULL, 0, 0, 0}
+};
+
/* Parse the argument given in the command line of the application */
static int
l2fwd_parse_args(int argc, char **argv)
@@ -400,15 +423,10 @@ l2fwd_parse_args(int argc, char **argv)
char **argvopt;
int option_index;
char *prgname = argv[0];
- static struct option lgopts[] = {
- { "mac-updating", no_argument, &mac_updating, 1},
- { "no-mac-updating", no_argument, &mac_updating, 0},
- {NULL, 0, 0, 0}
- };
argvopt = argv;
- while ((opt = getopt_long(argc, argvopt, "p:q:T:",
+ while ((opt = getopt_long(argc, argvopt, short_options,
lgopts, &option_index)) != EOF) {
switch (opt) {
--
2.8.1
next prev parent reply other threads:[~2016-11-22 13:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-22 13:52 [dpdk-dev] [PATCH 0/2] l2fwd/l3fwd: " Olivier Matz
2016-11-22 13:52 ` [dpdk-dev] [PATCH 1/2] l3fwd: " Olivier Matz
2016-11-22 13:52 ` Olivier Matz [this message]
2016-11-22 13:59 ` [dpdk-dev] [PATCH 0/2] l2fwd/l3fwd: " Olivier Matz
2017-01-17 17:11 ` Thomas Monjalon
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=1479822736-32399-3-git-send-email-olivier.matz@6wind.com \
--to=olivier.matz@6wind.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=pablo.de.lara.guarch@intel.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).