From patchwork Tue May 3 13:58:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 12361 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id EA76B37AA; Tue, 3 May 2016 15:52:24 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id AD26C2C72 for ; Tue, 3 May 2016 15:52:22 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 03 May 2016 06:52:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,572,1455004800"; d="scan'208";a="696111097" Received: from sie-lab-212-251.ir.intel.com (HELO silpixa00381635.ir.intel.com) ([10.237.212.251]) by FMSMGA003.fm.intel.com with ESMTP; 03 May 2016 06:52:20 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Tue, 3 May 2016 14:58:38 +0100 Message-Id: <1462283918-108334-1-git-send-email-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1462190035-63125-1-git-send-email-jasvinder.singh@intel.com> References: <1462190035-63125-1-git-send-email-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v2] ip_pipeline: configuration file parser cleanup X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Acked-by: Cristian Dumitrescu --- 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;