Serj Kalichev пре 10 месеци
родитељ
комит
9ff17b19cc
3 измењених фајлова са 29 додато и 15 уклоњено
  1. 1 0
      src/klish_plugin_sysrepo.h
  2. 24 14
      src/kly.c
  3. 4 1
      src/pline.c

+ 1 - 0
src/klish_plugin_sysrepo.h

@@ -330,6 +330,7 @@ bool_t klysc_node_ext(const struct lysc_node *node,
 bool_t klysc_node_ext_is_password(const struct lysc_node *node);
 const char *klysc_node_ext_completion(const struct lysc_node *node);
 const char *klysc_node_ext_default(const struct lysc_node *node);
+char *klyd_esc_value(const char *value);
 char *klyd_node_value(const struct lyd_node *node);
 const struct lysc_node *klysc_find_child(const struct lysc_node *node,
 	const char *name);

+ 24 - 14
src/kly.c

@@ -140,15 +140,35 @@ const char *klysc_node_ext_default(const struct lysc_node *node)
 }
 
 
+char *klyd_esc_value(const char *value)
+{
+	char *space = NULL;
+	char *escaped = NULL;
+	char *result = NULL;
+
+	if (!value)
+		return NULL;
+
+	escaped = faux_str_c_esc(value);
+	// String with space must have quotes
+	space = strchr(escaped, ' ');
+	if (space) {
+		result = faux_str_sprintf("\"%s\"", escaped);
+		faux_str_free(escaped);
+	} else {
+		result = escaped;
+	}
+
+	return result;
+}
+
+
 // Get value from data lyd node
 char *klyd_node_value(const struct lyd_node *node)
 {
 	const struct lysc_node *schema = NULL;
 	const struct lysc_type *type = NULL;
 	const char *origin_value = NULL;
-	char *space = NULL;
-	char *escaped = NULL;
-	char *result = NULL;
 
 	if (!node)
 		return NULL;
@@ -171,17 +191,7 @@ char *klyd_node_value(const struct lyd_node *node)
 		origin_value = value->ident->name;
 	}
 
-	escaped = faux_str_c_esc(origin_value);
-	// String with space must have quotes
-	space = strchr(origin_value, ' ');
-	if (space) {
-		result = faux_str_sprintf("\"%s\"", escaped);
-		faux_str_free(escaped);
-	} else {
-		result = escaped;
-	}
-
-	return result;
+	return klyd_esc_value(origin_value);
 }
 
 

+ 4 - 1
src/pline.c

@@ -1335,10 +1335,13 @@ void pline_print_completions(const pline_t *pline, bool_t help,
 					0, 0, &vals, &val_num);
 				for (i = 0; i < val_num; i++) {
 					char *tmp = sr_val_to_str(&vals[i]);
+					char *esc_tmp = NULL;
 					if (!tmp)
 						continue;
-					printf("%s\n", tmp);
+					esc_tmp = klyd_esc_value(tmp);
 					free(tmp);
+					printf("%s\n", esc_tmp);
+					free(esc_tmp);
 				}
 				sr_free_values(vals, val_num);
 			} else if (existing_nodes_only) {