[ofa-general] [PATCH] opensm/config: allow space separated strings as values

Sasha Khapyorsky sashak at voltaire.com
Sat Jun 14 05:54:12 PDT 2008


This slightly extends OpenSM config file format and allow using space
separated strings (quoted or not) as config values.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 opensm/opensm/osm_subnet.c |   31 ++++++++++++++++++++++++++++---
 1 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/opensm/opensm/osm_subnet.c b/opensm/opensm/osm_subnet.c
index 1bf3daf..a9081c9 100644
--- a/opensm/opensm/osm_subnet.c
+++ b/opensm/opensm/osm_subnet.c
@@ -49,6 +49,7 @@
 #include <stdarg.h>
 #include <limits.h>
 #include <errno.h>
+#include <ctype.h>
 #include <complib/cl_debug.h>
 #include <complib/cl_log.h>
 #include <opensm/osm_subnet.h>
@@ -606,6 +607,30 @@ opts_unpack_charp(IN char *p_req_key,
 
 /**********************************************************************
  **********************************************************************/
+static char *clean_val(char *val)
+{
+	char *p = val;
+	/* clean leading spaces */
+	while (isspace(*p))
+		p++;
+	val = p;
+	if (!*val)
+		return val;
+	/* clean trailing spaces */
+	p = val + strlen(val) - 1;
+	while (p > val && isspace(*p))
+		p--;
+	p[1] = '\0';
+	/* clean quotas */
+	if ((*val == '\"' && *p == '\"') || (*val == '\'' && *p == '\'')) {
+		val++;
+		p--;
+	}
+	return val;
+}
+
+/**********************************************************************
+ **********************************************************************/
 static void
 subn_parse_qos_options(IN const char *prefix,
 		       IN char *p_key,
@@ -1106,7 +1131,7 @@ int osm_subn_parse_conf_file(char *file_name, osm_subn_opt_t * const p_opts)
 {
 	char line[1024];
 	FILE *opts_file;
-	char *p_key, *p_val, *p_last;
+	char *p_key, *p_val;
 
 	opts_file = fopen(file_name, "r");
 	if (!opts_file) {
@@ -1124,11 +1149,11 @@ int osm_subn_parse_conf_file(char *file_name, osm_subn_opt_t * const p_opts)
 
 	while (fgets(line, 1023, opts_file) != NULL) {
 		/* get the first token */
-		p_key = strtok_r(line, " \t\n", &p_last);
+		p_key = strtok_r(line, " \t\n", &p_val);
 		if (!p_key)
 			continue;
 
-		p_val = strtok_r(NULL, " \t\n", &p_last);
+		p_val = clean_val(p_val);
 
 		opts_unpack_net64("guid", p_key, p_val, &p_opts->guid);
 
-- 
1.5.5.1.178.g1f811




More information about the general mailing list