[3/8] examples/packet_ordering: enhance getopt_long usage

Message ID 20201029125339.30916-3-ibtisam.tariq@emumba.com (mailing list archive)
State Changes Requested, archived
Delegated to: David Marchand
Headers
Series [1/8] examples/fips_validation: enhance getopt_long usage |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ibtisam Tariq Oct. 29, 2020, 12:53 p.m. UTC
  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.

Bugzilla ID: 238
Fixes: 850f3733f8 ("examples/packet_ordering: new sample app")
Fixes: 016493307a ("examples/packet_ordering: add stats per worker thread")
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>
---
 examples/packet_ordering/main.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)
  

Patch

diff --git a/examples/packet_ordering/main.c b/examples/packet_ordering/main.c
index a79d77a32..ac41d1a88 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 OPTION_DISABLE_REORDER "disable-reorder"
+	OPTION_DISABLE_REORDER_NUM = 256,
+#define OPTION_INSIGHT_WORKER "insight-worker"
+	OPTION_INSIGHT_WORKER_NUM,
+};
+
 unsigned int portmask;
 unsigned int disable_reorder;
 unsigned int insight_worker;
@@ -157,8 +164,8 @@  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},
+		{OPTION_DISABLE_REORDER, 0, NULL, OPTION_DISABLE_REORDER_NUM},
+		{OPTION_INSIGHT_WORKER, 0, NULL, OPTION_INSIGHT_WORKER_NUM},
 		{NULL, 0, 0, 0}
 	};
 
@@ -177,17 +184,18 @@  parse_args(int argc, char **argv)
 			}
 			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 OPTION_DISABLE_REORDER_NUM:
+		{
+			printf("reorder disabled\n");
+			disable_reorder = 1;
 			break;
+		}
+		case OPTION_INSIGHT_WORKER_NUM:
+		{
+			printf("print all worker statistics\n");
+			insight_worker = 1;
+			break;
+		}
 		default:
 			print_usage(prgname);
 			return -1;