From mboxrd@z Thu Jan 1 00:00:00 1970 From: bugzilla@dpdk.org Subject: [Bug 238] [tree-wide] enhance getopt_long usage Date: Tue, 02 Apr 2019 07:38:39 +0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable To: dev@dpdk.org Return-path: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" https://bugs.dpdk.org/show_bug.cgi?id=3D238 Bug ID: 238 Summary: [tree-wide] enhance getopt_long usage Product: DPDK Version: unspecified Hardware: All OS: All Status: CONFIRMED Severity: enhancement Priority: Low Component: other Assignee: dev@dpdk.org Reporter: david.marchand@redhat.com Target Milestone: future We have quite a couple of the following pattern in the apps and examples (quoting examples/fips_validation/main.c as a bad example): struct option lgopts[] =3D { {REQ_FILE_PATH_KEYWORD, required_argument, 0, 0}, {RSP_FILE_PATH_KEYWORD, required_argument, 0, 0}, {FOLDER_KEYWORD, no_argument, 0, 0}, {CRYPTODEV_KEYWORD, required_argument, 0, 0}, {CRYPTODEV_ID_KEYWORD, required_argument, 0, 0}, {CRYPTODEV_ST_KEYWORD, no_argument, 0, 0}, {CRYPTODEV_BK_ID_KEYWORD, required_argument, 0, 0}, {CRYPTODEV_BK_DIR_KEY, required_argument, 0, 0}, {NULL, 0, 0, 0} }; while ((opt =3D getopt_long(argc, argvopt, "s:", lgopts, &option_index)) !=3D EOF) { switch (opt) { case 0: if (strcmp(lgopts[option_index].name, REQ_FILE_PATH_KEYWORD) =3D=3D 0) env.req_path =3D optarg; else if (strcmp(lgopts[option_index].name, RSP_FILE_PATH_KEYWORD) =3D=3D 0) env.rsp_path =3D optarg; else if (strcmp(lgopts[option_index].name, FOLDER_KEYWORD) =3D=3D 0) env.is_path_folder =3D 1; else if (strcmp(lgopts[option_index].name, ... We can get rid of all those strcmp by directly binding each longopt with an= int enum. eal has been using this convention for quite some time, see: https://git.dpdk.org/dpdk/tree/lib/librte_eal/common/eal_options.h?h=3Dv19.= 02 https://git.dpdk.org/dpdk/tree/lib/librte_eal/common/eal_common_options.c?h= =3Dv19.02 --=20 You are receiving this mail because: You are the assignee for the bug.=