DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ibtisam Tariq <ibtisam.tariq@emumba.com>
To: maxime.coquelin@redhat.com, chenbo.xia@intel.com,
	cristian.dumitrescu@intel.com, jasvinder.singh@intel.com,
	john.mcnamara@intel.com, reshma.pattan@intel.com,
	konstantin.ananyev@intel.com, marko.kovacevic@intel.com
Cc: dev@dpdk.org, Ibtisam Tariq <ibtisam.tariq@emumba.com>,
	sergio.gonzalez.monroy@intel.com, phil.yang@arm.com
Subject: [dpdk-dev] [PATCH 3/7] examples/packet_ordering: enhance getopt_long usage
Date: Tue, 24 Nov 2020 12:32:45 +0000	[thread overview]
Message-ID: <20201124123249.14451-3-ibtisam.tariq@emumba.com> (raw)
In-Reply-To: <20201124123249.14451-1-ibtisam.tariq@emumba.com>

Instead of using getopt_long return value, strcmp was used to
compare the input parameters with the struct option array. This
patch get rid of all those strcmp by directly binding each longopt
with an int enum. This is to improve readability and consistency in
all examples.

Bugzilla ID: 238
Cc: sergio.gonzalez.monroy@intel.com
Cc: phil.yang@arm.com

Reported-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Ibtisam Tariq <ibtisam.tariq@emumba.com>
---
v3:
* None.

v2:
* Remove extra indentations.
* Remove extra block brackets in switch statement.
* Change enum names to start with OPT_ and remove KEYWORD from enum names.

v1:
* enhance getopt_long usage.
---
 examples/packet_ordering/main.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/examples/packet_ordering/main.c b/examples/packet_ordering/main.c
index 4bea1982d..32e58c9cd 100644
--- a/examples/packet_ordering/main.c
+++ b/examples/packet_ordering/main.c
@@ -29,6 +29,13 @@
 /* Macros for printing using RTE_LOG */
 #define RTE_LOGTYPE_REORDERAPP          RTE_LOGTYPE_USER1
 
+enum {
+#define OPT_DISABLE_REORDER "disable-reorder"
+	OPT_DISABLE_REORDER_NUM = 256,
+#define OPT_INSIGHT_WORKER "insight-worker"
+	OPT_INSIGHT_WORKER_NUM,
+};
+
 unsigned int portmask;
 unsigned int disable_reorder;
 unsigned int insight_worker;
@@ -157,9 +164,9 @@ parse_args(int argc, char **argv)
 	char **argvopt;
 	char *prgname = argv[0];
 	static struct option lgopts[] = {
-		{"disable-reorder", 0, 0, 0},
-		{"insight-worker", 0, 0, 0},
-		{NULL, 0, 0, 0}
+		{OPT_DISABLE_REORDER, 0, NULL, OPT_DISABLE_REORDER_NUM},
+		{OPT_INSIGHT_WORKER,  0, NULL, OPT_INSIGHT_WORKER_NUM },
+		{NULL,                0, 0,    0                      }
 	};
 
 	argvopt = argv;
@@ -176,18 +183,18 @@ parse_args(int argc, char **argv)
 				return -1;
 			}
 			break;
+
 		/* long options */
-		case 0:
-			if (!strcmp(lgopts[option_index].name, "disable-reorder")) {
-				printf("reorder disabled\n");
-				disable_reorder = 1;
-			}
-			if (!strcmp(lgopts[option_index].name,
-						"insight-worker")) {
-				printf("print all worker statistics\n");
-				insight_worker = 1;
-			}
+		case OPT_DISABLE_REORDER_NUM:
+			printf("reorder disabled\n");
+			disable_reorder = 1;
+			break;
+
+		case OPT_INSIGHT_WORKER_NUM:
+			printf("print all worker statistics\n");
+			insight_worker = 1;
 			break;
+
 		default:
 			print_usage(prgname);
 			return -1;
-- 
2.17.1


  parent reply	other threads:[~2020-11-24 12:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-24 12:32 [dpdk-dev] [PATCH 1/7] examples/fips_validation: " Ibtisam Tariq
2020-11-24 12:32 ` [dpdk-dev] [PATCH 2/7] examples/l3fwd-acl: " Ibtisam Tariq
2020-11-24 12:32 ` Ibtisam Tariq [this message]
2020-11-24 12:32 ` [dpdk-dev] [PATCH 4/7] examples/performance-thread/l3fwd-thread: " Ibtisam Tariq
2020-11-24 12:32 ` [dpdk-dev] [PATCH 5/7] examples/qos_sched: " Ibtisam Tariq
2020-11-24 12:32 ` [dpdk-dev] [PATCH 6/7] examples/vhost: " Ibtisam Tariq
2020-12-07 10:51   ` David Marchand
2020-12-31  7:00     ` Ibtisam Tariq
2020-11-24 12:32 ` [dpdk-dev] [PATCH 7/7] examples/vhost_crypto: " Ibtisam Tariq
2020-12-07 10:50 ` [dpdk-dev] [PATCH 1/7] examples/fips_validation: " David Marchand
  -- strict thread matches above, loose matches on Subject: below --
2020-11-11  8:15 Ibtisam Tariq
2020-11-11  8:15 ` [dpdk-dev] [PATCH 3/7] examples/packet_ordering: " Ibtisam Tariq

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=20201124123249.14451-3-ibtisam.tariq@emumba.com \
    --to=ibtisam.tariq@emumba.com \
    --cc=chenbo.xia@intel.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    --cc=jasvinder.singh@intel.com \
    --cc=john.mcnamara@intel.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=marko.kovacevic@intel.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=phil.yang@arm.com \
    --cc=reshma.pattan@intel.com \
    --cc=sergio.gonzalez.monroy@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).