From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A9F4EA0A0E; Thu, 4 Feb 2021 08:34:51 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ECEE624058C; Thu, 4 Feb 2021 08:34:44 +0100 (CET) Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by mails.dpdk.org (Postfix) with ESMTP id 86F2124058E for ; Thu, 4 Feb 2021 08:34:43 +0100 (CET) Received: by mail-wr1-f45.google.com with SMTP id q7so2198912wre.13 for ; Wed, 03 Feb 2021 23:34:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YfN9QRUlm5CbXIMozeXmALaYryPmXJ5iUEf+HSPnZsg=; b=r/BTUAV9ZCwAec6+g0sePX1nu++x1R1itswX5UnVzOu4L3Rd8/pzT386UG4LvauubS ekdxGRhIQVvLng6WYpKEgdmsJdXJg3Exz8qBxYJBJQ06tYHMLmp9/1GCe0ID6oMTlex/ 92+KEQc3gfil5bHPH/vn4YU4iNrHbrAVOMnwwPmLKLaJSsd+81bWqbBpAq4ObfQJ8QXo dippbCXGURNzhaPRvGiudEh3BMViFFMGSvCEdutfHtrLt6WTRKiuPfXe5m0bwFOie4Tt bfJfzVqOuE1yRcksmFlNCVgOwrDwJ0cQQvpjL3b5DUPsqdPL48wYrg1shoRrYRbVHFRC JfVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YfN9QRUlm5CbXIMozeXmALaYryPmXJ5iUEf+HSPnZsg=; b=Aigdezg1/d+jMgUPtTFeXPEElLMR2RutEwaaMXWmGE/bIisriARAmOa8XlYj3xl8yv iB/lgsT4BXtSzWssyeTHamRlAIfD9YfwmpzyorgfP90A1H1kJ/OHtaczupEQcQsIWDNo tim5VXzNIq6peE80tqLKhvy0Fzw69dr0tE2Nd4L0qHJGDcJNxiCL0V/1MadcbqjVF8kz F8yQca2jqZIn0tHdOZaQw1yJHtFUP7mr+zciwjJzqEM5EPvguFKzS+it7LcMFkei8IO6 3ExJWXCOKiPNtqHxYo1pB8xmHNke1lGAmCU88/IYUOsiHc1HmolFknpPfv1FNugKkMB7 vP2Q== X-Gm-Message-State: AOAM530kdeVPqXojMIV/7/9xz3SSs6Ufd33fafDAelJZCfyioohTT9QN 3wEeLwzXMe1ql6ctBYfsyBcUTw== X-Google-Smtp-Source: ABdhPJzCd829sMHTV1DrYblSlDFpbjdYWU81/Q8Y5NAtuS3B126Wkk/ECf14iaotyIbKWnNdl4txJw== X-Received: by 2002:a5d:414f:: with SMTP id c15mr7705488wrq.42.1612424083317; Wed, 03 Feb 2021 23:34:43 -0800 (PST) Received: from localhost.localdomain ([39.33.143.135]) by smtp.gmail.com with ESMTPSA id j11sm7082604wrt.26.2021.02.03.23.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 23:34:42 -0800 (PST) From: Ibtisam Tariq 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 , sergio.gonzalez.monroy@intel.com, phil.yang@arm.com Date: Thu, 4 Feb 2021 07:34:16 +0000 Message-Id: <20210204073420.2421-3-ibtisam.tariq@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210204073420.2421-1-ibtisam.tariq@emumba.com> References: <20210204073420.2421-1-ibtisam.tariq@emumba.com> Subject: [dpdk-dev] [PATCH v4 3/7] examples/packet_ordering: enhance getopt_long usage X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Signed-off-by: Ibtisam Tariq --- v4: * None. 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..ff670747f 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