From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9CD35A2EDB for ; Sat, 7 Sep 2019 00:35:20 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 07CF21F4FD; Sat, 7 Sep 2019 00:34:16 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 309481F402 for ; Sat, 7 Sep 2019 00:33:57 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Sep 2019 15:33:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,474,1559545200"; d="scan'208";a="208372454" Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain) ([10.166.188.58]) by fmsmga004.fm.intel.com with ESMTP; 06 Sep 2019 15:33:55 -0700 From: Pallavi Kadam To: dev@dpdk.org, thomas@monjalon.net Cc: Harini.Ramakrishnan@microsoft.com, ranjit.menon@intel.com, keith.wiles@intel.com, bruce.richardson@intel.com, antara.ganesh.kolar@intel.com, pallavi.kadam@intel.com Date: Fri, 6 Sep 2019 15:09:57 -0700 Message-Id: <20190906220957.7892-10-pallavi.kadam@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20190906220957.7892-1-pallavi.kadam@intel.com> References: <20190906220957.7892-1-pallavi.kadam@intel.com> Subject: [dpdk-dev] [PATCH 9/9] eal: add minimum viable code to support parsing X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" Adding specific logic for eal.c to support parsing on Windows. Signed-off-by: Pallavi Kadam Signed-off-by: Antara Ganesh Kolar Reviewed-by: Ranjit Menon Reviewed-by: Keith Wiles --- lib/librte_eal/windows/eal/eal.c | 119 +++++++++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 7 deletions(-) diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c index ffe5b8552..8deb6c83a 100644 --- a/lib/librte_eal/windows/eal/eal.c +++ b/lib/librte_eal/windows/eal/eal.c @@ -13,8 +13,12 @@ #include #include #include +#include #include + /* Allow the application to print its usage message too if set */ +static rte_usage_hook_t rte_application_usage_hook; + /* define fd variable here, because file needs to be kept open for the * duration of the program, as we hold a write lock on it in the primary proc */ @@ -73,21 +77,122 @@ enum rte_proc_type_t return ptype; } +/* display usage */ +static void +eal_usage(const char *prgname) +{ + printf("\nUsage: %s ", prgname); + eal_common_usage(); + /* Allow the application to print its usage message too + *if hook is set + */ + if (rte_application_usage_hook) { + printf("===== Application Usage =====\n\n"); + rte_application_usage_hook(prgname); + } +} + /* Parse the arguments for --log-level only */ static void -eal_log_level_parse(__rte_unused int argc, __rte_unused char **argv) +eal_log_level_parse(int argc, char **argv) { - /* TODO */ - /* This is a stub, not the expected result */ + int opt; + char **argvopt; + int option_index; + + argvopt = argv; + + eal_reset_internal_config(&internal_config); + + while ((opt = getopt_long(argc, argvopt, eal_short_options, + eal_long_options, &option_index)) != EOF) { + + int ret; + + /* getopt is not happy, stop right now */ + if (opt == '?') + break; + + ret = (opt == OPT_LOG_LEVEL_NUM) ? + eal_parse_common_option(opt, optarg, + &internal_config) : 0; + + /* common parser is not happy */ + if (ret < 0) + break; + } + + optind = 0; /* reset getopt lib */ } /* Parse the argument given in the command line of the application */ static int -eal_parse_args(__rte_unused int argc, __rte_unused char **argv) +eal_parse_args(int argc, char **argv) { - /* TODO */ - /* This is a stub, not the expected result */ - return 0; + int opt, ret; + char **argvopt; + int option_index; + char *prgname = argv[0]; + + argvopt = argv; + + while ((opt = getopt_long(argc, argvopt, eal_short_options, + eal_long_options, &option_index)) != EOF) { + + int ret; + + /* getopt is not happy, stop right now */ + if (opt == '?') { + eal_usage(prgname); + return -1; + } + + ret = eal_parse_common_option(opt, optarg, &internal_config); + /* common parser is not happy */ + if (ret < 0) { + eal_usage(prgname); + return -1; + } + /* common parser handled this option */ + if (ret == 0) + continue; + + switch (opt) { + case 'h': + eal_usage(prgname); + exit(EXIT_SUCCESS); + default: + if (opt < OPT_LONG_MIN_NUM && isprint(opt)) { + RTE_LOG(ERR, EAL, "Option %c is not supported " + "on Windows\n", opt); + } else if (opt >= OPT_LONG_MIN_NUM && + opt < OPT_LONG_MAX_NUM) { + RTE_LOG(ERR, EAL, "Option %s is not supported " + "on Windows\n", + eal_long_options[option_index].name); + } else { + RTE_LOG(ERR, EAL, "Option %d is not supported " + "on Windows\n", opt); + } + eal_usage(prgname); + return -1; + } + } + + if (eal_adjust_config(&internal_config) != 0) + return -1; + + /* sanity checks */ + if (eal_check_common_options(&internal_config) != 0) { + eal_usage(prgname); + return -1; + } + + if (optind >= 0) + argv[optind - 1] = prgname; + ret = optind - 1; + optind = 0; /* reset getopt lib */ + return ret; } static int -- 2.18.0.windows.1