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 DB158436C8; Mon, 11 Dec 2023 10:54:30 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4DAD340EDF; Mon, 11 Dec 2023 10:54:27 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 38D1240ED3 for ; Mon, 11 Dec 2023 10:54:24 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SpcXW6hGdzZcmB; Mon, 11 Dec 2023 17:54:19 +0800 (CST) Received: from dggpeml500024.china.huawei.com (unknown [7.185.36.10]) by mail.maildlp.com (Postfix) with ESMTPS id 11B3A14040F; Mon, 11 Dec 2023 17:54:23 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 11 Dec 2023 17:54:22 +0800 From: Chengwen Feng To: , , , CC: Subject: [RFC v3 07/12] argparse: provide parsing known type API Date: Mon, 11 Dec 2023 09:51:05 +0000 Message-ID: <20231211095110.18946-8-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231211095110.18946-1-fengchengwen@huawei.com> References: <20231121122651.7078-1-fengchengwen@huawei.com> <20231211095110.18946-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500024.china.huawei.com (7.185.36.10) 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 Provide API which could parsing the value from the input string based on the value type. This API could used in user callback when parsing string by argparse or kvargs library. Signed-off-by: Chengwen Feng --- lib/argparse/rte_argparse.c | 19 +++++++++++++++++++ lib/argparse/rte_argparse.h | 19 +++++++++++++++++++ lib/argparse/version.map | 1 + 3 files changed, 39 insertions(+) diff --git a/lib/argparse/rte_argparse.c b/lib/argparse/rte_argparse.c index cc5493c6be..6b82f58eaf 100644 --- a/lib/argparse/rte_argparse.c +++ b/lib/argparse/rte_argparse.c @@ -600,3 +600,22 @@ rte_argparse_parse(struct rte_argparse *obj, int argc, char **argv) exit(ret); return ret; } + +int +rte_argparse_parse_type(const char *str, uint64_t val_type, void *val) +{ + uint32_t cmp_max = RTE_FIELD_GET64(ARG_ATTR_VAL_TYPE_MASK, RTE_ARGPARSE_ARG_VALUE_MAX); + struct rte_argparse_arg arg = { + .name_long = str, + .name_short = NULL, + .val_saver = val, + .val_set = NULL, + .flags = val_type, + }; + uint32_t value_type = arg_attr_val_type(&arg); + + if (value_type == 0 || value_type >= cmp_max) + return -EINVAL; + + return parse_arg_autosave(&arg, str); +} diff --git a/lib/argparse/rte_argparse.h b/lib/argparse/rte_argparse.h index 72eea7cf87..5e40431e5b 100644 --- a/lib/argparse/rte_argparse.h +++ b/lib/argparse/rte_argparse.h @@ -184,6 +184,25 @@ struct rte_argparse { __rte_experimental int rte_argparse_parse(struct rte_argparse *obj, int argc, char **argv); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Parse the value from the input string based on the value type. + * + * @param str + * Input string. + * @param val_type + * The value type, @see RTE_ARGPARSE_ARG_VALUE_INT or other type. + * @param val + * Saver for the value. + * + * @return + * 0 on success. Otherwise negative value is returned. + */ +__rte_experimental +int rte_argparse_parse_type(const char *str, uint64_t val_type, void *val); + #ifdef __cplusplus } #endif diff --git a/lib/argparse/version.map b/lib/argparse/version.map index 1c176f69e9..9b68464600 100644 --- a/lib/argparse/version.map +++ b/lib/argparse/version.map @@ -2,6 +2,7 @@ EXPERIMENTAL { global: rte_argparse_parse; + rte_argparse_parse_type; local: *; }; -- 2.17.1