From: Jasvinder Singh <jasvinder.singh@intel.com>
To: dev@dpdk.org
Cc: cristian.dumitrescu@intel.com
Subject: [dpdk-dev] [PATCH v2] ip_pipeline: configuration file parser cleanup
Date: Tue, 3 May 2016 14:58:38 +0100 [thread overview]
Message-ID: <1462283918-108334-1-git-send-email-jasvinder.singh@intel.com> (raw)
In-Reply-To: <1462190035-63125-1-git-send-email-jasvinder.singh@intel.com>
This patch updates the parsing routines related to packet queues
(pktq_in/out fields in the PIPELINE section) and message queues
(msgq_in/out fields of in the MSGQ Section) specified in ip_pipeline
configuration file.
In the updated routines, function "strtok_r()" is used for parsing the
string instead of manually checking the string termination, white
spaces, tabs etc., between the string tokens. Each call to strtok_r()
returns a pointer to a null-terminated string containing the next token.
If no more tokens are found, strtok_r() returns NULL. As a result of
using strtok_r(), the code size of the parsing routines is reduced
significantly.
Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
v2
- update the commit message
- change the local variable name from "token" to "name"
examples/ip_pipeline/config_parse.c | 169 ++++--------------------------------
1 file changed, 19 insertions(+), 150 deletions(-)
diff --git a/examples/ip_pipeline/config_parse.c b/examples/ip_pipeline/config_parse.c
index e166891..208f39a 100644
--- a/examples/ip_pipeline/config_parse.c
+++ b/examples/ip_pipeline/config_parse.c
@@ -1128,49 +1128,17 @@ parse_pipeline_pcap_sink(struct app_params *app,
static int
parse_pipeline_pktq_in(struct app_params *app,
struct app_pipeline_params *p,
- const char *value)
+ char *value)
{
- const char *next = value;
- char *end;
- char name[APP_PARAM_NAME_SIZE];
- size_t name_len;
- while (*next != '\0') {
+ while (1) {
enum app_pktq_in_type type;
int id;
- char *end_space;
- char *end_tab;
+ char *name = strtok_r(value, PARSE_DELIMITER, &value);
- next = skip_white_spaces(next);
- if (!next)
+ if (name == NULL)
break;
- end_space = strchr(next, ' ');
- end_tab = strchr(next, ' ');
-
- if (end_space && (!end_tab))
- end = end_space;
- else if ((!end_space) && end_tab)
- end = end_tab;
- else if (end_space && end_tab)
- end = RTE_MIN(end_space, end_tab);
- else
- end = NULL;
-
- if (!end)
- name_len = strlen(next);
- else
- name_len = end - next;
-
- if (name_len == 0 || name_len == sizeof(name))
- return -EINVAL;
-
- strncpy(name, next, name_len);
- name[name_len] = '\0';
- next += name_len;
- if (*next != '\0')
- next++;
-
if (validate_name(name, "RXQ", 2) == 0) {
type = APP_PKTQ_IN_HWQ;
id = APP_PARAM_ADD(app->hwq_in_params, name);
@@ -1200,48 +1168,16 @@ parse_pipeline_pktq_in(struct app_params *app,
static int
parse_pipeline_pktq_out(struct app_params *app,
struct app_pipeline_params *p,
- const char *value)
+ char *value)
{
- const char *next = value;
- char *end;
- char name[APP_PARAM_NAME_SIZE];
- size_t name_len;
-
- while (*next != '\0') {
- enum app_pktq_out_type type;
+ while (1) {
+ enum app_pktq_in_type type;
int id;
- char *end_space;
- char *end_tab;
+ char *name = strtok_r(value, PARSE_DELIMITER, &value);
- next = skip_white_spaces(next);
- if (!next)
+ if (name == NULL)
break;
- end_space = strchr(next, ' ');
- end_tab = strchr(next, ' ');
-
- if (end_space && (!end_tab))
- end = end_space;
- else if ((!end_space) && end_tab)
- end = end_tab;
- else if (end_space && end_tab)
- end = RTE_MIN(end_space, end_tab);
- else
- end = NULL;
-
- if (!end)
- name_len = strlen(next);
- else
- name_len = end - next;
-
- if (name_len == 0 || name_len == sizeof(name))
- return -EINVAL;
-
- strncpy(name, next, name_len);
- name[name_len] = '\0';
- next += name_len;
- if (*next != '\0')
- next++;
if (validate_name(name, "TXQ", 2) == 0) {
type = APP_PKTQ_OUT_HWQ;
id = APP_PARAM_ADD(app->hwq_out_params, name);
@@ -1271,48 +1207,15 @@ parse_pipeline_pktq_out(struct app_params *app,
static int
parse_pipeline_msgq_in(struct app_params *app,
struct app_pipeline_params *p,
- const char *value)
+ char *value)
{
- const char *next = value;
- char *end;
- char name[APP_PARAM_NAME_SIZE];
- size_t name_len;
- ssize_t idx;
-
- while (*next != '\0') {
- char *end_space;
- char *end_tab;
+ while (1) {
+ int idx;
+ char *name = strtok_r(value, PARSE_DELIMITER, &value);
- next = skip_white_spaces(next);
- if (!next)
+ if (name == NULL)
break;
- end_space = strchr(next, ' ');
- end_tab = strchr(next, ' ');
-
- if (end_space && (!end_tab))
- end = end_space;
- else if ((!end_space) && end_tab)
- end = end_tab;
- else if (end_space && end_tab)
- end = RTE_MIN(end_space, end_tab);
- else
- end = NULL;
-
- if (!end)
- name_len = strlen(next);
- else
- name_len = end - next;
-
- if (name_len == 0 || name_len == sizeof(name))
- return -EINVAL;
-
- strncpy(name, next, name_len);
- name[name_len] = '\0';
- next += name_len;
- if (*next != '\0')
- next++;
-
if (validate_name(name, "MSGQ", 1) != 0)
return -EINVAL;
@@ -1330,48 +1233,14 @@ parse_pipeline_msgq_in(struct app_params *app,
static int
parse_pipeline_msgq_out(struct app_params *app,
struct app_pipeline_params *p,
- const char *value)
+ char *value)
{
- const char *next = value;
- char *end;
- char name[APP_PARAM_NAME_SIZE];
- size_t name_len;
- ssize_t idx;
-
- while (*next != '\0') {
- char *end_space;
- char *end_tab;
+ while (1) {
+ int idx;
+ char *name = strtok_r(value, PARSE_DELIMITER, &value);
- next = skip_white_spaces(next);
- if (!next)
+ if (name == NULL)
break;
-
- end_space = strchr(next, ' ');
- end_tab = strchr(next, ' ');
-
- if (end_space && (!end_tab))
- end = end_space;
- else if ((!end_space) && end_tab)
- end = end_tab;
- else if (end_space && end_tab)
- end = RTE_MIN(end_space, end_tab);
- else
- end = NULL;
-
- if (!end)
- name_len = strlen(next);
- else
- name_len = end - next;
-
- if (name_len == 0 || name_len == sizeof(name))
- return -EINVAL;
-
- strncpy(name, next, name_len);
- name[name_len] = '\0';
- next += name_len;
- if (*next != '\0')
- next++;
-
if (validate_name(name, "MSGQ", 1) != 0)
return -EINVAL;
--
2.5.5
next prev parent reply other threads:[~2016-05-03 13:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-02 11:53 [dpdk-dev] [PATCH] " Jasvinder Singh
2016-05-03 9:43 ` Bruce Richardson
2016-05-03 13:58 ` Jasvinder Singh [this message]
2016-05-11 16:36 ` [dpdk-dev] [PATCH v3] " Jasvinder Singh
2016-05-30 14:33 ` [dpdk-dev] [PATCH v4] " Jasvinder Singh
2016-06-08 14:48 ` Thomas Monjalon
2016-06-08 16:24 ` Singh, Jasvinder
2016-06-08 16:30 ` [dpdk-dev] [PATCH v5] " Jasvinder Singh
2016-06-08 18:05 ` Thomas Monjalon
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=1462283918-108334-1-git-send-email-jasvinder.singh@intel.com \
--to=jasvinder.singh@intel.com \
--cc=cristian.dumitrescu@intel.com \
--cc=dev@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).