From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 05/10] spp_pcap: refactor func for splitting cmd tokens
Date: Fri, 31 May 2019 17:52:37 +0900 [thread overview]
Message-ID: <1559292762-27042-6-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <1559292762-27042-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp>
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Refactor function for splitting pcap command into tokens in which the
name of vars are misunderstandable.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/pcap/cmd_parser.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/src/pcap/cmd_parser.c b/src/pcap/cmd_parser.c
index 577e952..cf1f2b9 100644
--- a/src/pcap/cmd_parser.c
+++ b/src/pcap/cmd_parser.c
@@ -36,22 +36,29 @@ set_string_value_parse_error(struct sppwk_parse_err_msg *wk_err_msg,
return set_parse_error(wk_err_msg, SPPWK_PARSE_INVALID_VALUE, err_msg);
}
-/* Split command line parameter with spaces */
+/* Split tokens of pcap command with delimiter. */
+/* TODO(yasufum) consider this func can be moved to shared. */
static int
-parse_parameter_value(char *string, int max, int *nof_tokens, char *tokens[])
+split_cmd_tokens(char *tokens_str, int max_tokens, int *nof_tokens,
+ char *tokens[])
{
- int cnt = 0;
const char *delim = " ";
char *token = NULL;
- char *saveptr = NULL;
+ char *t_ptr = NULL;
+ int cnt = 0;
- token = strtok_r(string, delim, &saveptr);
+ token = strtok_r(tokens_str, delim, &t_ptr);
while (token != NULL) {
- if (cnt >= max)
+ if (cnt >= max_tokens) {
+ RTE_LOG(ERR, PCAP_PARSER,
+ "Invalid num of tokens in %s."
+ "It should be less than %d.\n",
+ tokens_str, max_tokens);
return SPPWK_RET_NG;
+ }
tokens[cnt] = token;
cnt++;
- token = strtok_r(NULL, delim, &saveptr);
+ token = strtok_r(NULL, delim, &t_ptr);
}
*nof_tokens = cnt;
@@ -104,7 +111,7 @@ parse_pcap_cmd(struct spp_command_request *request,
memset(tmp_str, 0x00, sizeof(tmp_str));
strcpy(tmp_str, request_str);
- ret = parse_parameter_value(tmp_str, SPPWK_MAX_PARAMS,
+ ret = split_cmd_tokens(tmp_str, SPPWK_MAX_PARAMS,
&nof_tokens, tokens);
if (ret < SPPWK_RET_OK) {
RTE_LOG(ERR, PCAP_PARSER, "Parameter number over limit."
--
2.17.1
next prev parent reply other threads:[~2019-05-31 8:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-31 8:52 [spp] [PATCH 00/10] Refactor cmd parser in spp_pcap ogawa.yasufumi
2019-05-31 8:52 ` [spp] [PATCH 01/10] spp_pcap: rename enum spp_command_type ogawa.yasufumi
2019-05-31 8:52 ` [spp] [PATCH 02/10] spp_pcap: rename struct spp_command ogawa.yasufumi
2019-05-31 8:52 ` [spp] [PATCH 03/10] spp_pcap: revise command response codes ogawa.yasufumi
2019-05-31 8:52 ` [spp] [PATCH 04/10] spp_pcap: revise parser functions ogawa.yasufumi
2019-05-31 8:52 ` ogawa.yasufumi [this message]
2019-05-31 8:52 ` [spp] [PATCH 06/10] spp_pcap: revise log msgs in parser func ogawa.yasufumi
2019-05-31 8:52 ` [spp] [PATCH 07/10] spp_pcap: remove unused string list ogawa.yasufumi
2019-05-31 8:52 ` [spp] [PATCH 08/10] spp_pcap: refactor comments of spp_pcap ogawa.yasufumi
2019-05-31 8:52 ` [spp] [PATCH 09/10] spp_pcap: rename spp_get_core_status ogawa.yasufumi
2019-05-31 8:52 ` [spp] [PATCH 10/10] spp_pcap: revise name of vars for parser error ogawa.yasufumi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1559292762-27042-6-git-send-email-ogawa.yasufumi@lab.ntt.co.jp \
--to=ogawa.yasufumi@lab.ntt.co.jp \
--cc=ferruh.yigit@intel.com \
--cc=spp@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).