summary refs log tree commit diff
path: root/clients/cli/utils.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2015-07-14 19:38:58 +0200
committerMichael Biebl <biebl@debian.org>2015-07-14 19:38:58 +0200
commit50a58f0fabd8a34c1b6108a107e08abe3c1ccd24 (patch)
tree6790165f39daee79e2b6c6617483320613493367 /clients/cli/utils.c
parentf408e27bccfacf347605a8d98649975a68f38a17 (diff)
Imported Upstream version 1.0.4 upstream/1.0.4
Diffstat (limited to 'clients/cli/utils.c')
-rw-r--r--clients/cli/utils.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/clients/cli/utils.c b/clients/cli/utils.c
index 60cf9f93..dfd002ed 100644
--- a/clients/cli/utils.c
+++ b/clients/cli/utils.c
@@ -454,17 +454,34 @@ nmc_get_user_input (const char *ask_str)
  * Split string in 'line' according to 'delim' to (argument) array.
  */
 int
-nmc_string_to_arg_array (const char *line, const char *delim, char ***argv, int *argc)
+nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote,
+                         char ***argv, int *argc)
 {
-	int i = 0;
 	char **arr;
 
-	arr = g_strsplit_set (line ? line : "", delim ? delim : " \t", 0);
-	while (arr && arr[i])
-		i++;
+	arr = nmc_strsplit_set (line ? line : "", delim ? delim : " \t", 0);
+
+	if (unquote) {
+		int i = 0;
+		char *s;
+		size_t l;
+		const char *quotes = "\"'";
+
+		while (arr && arr[i]) {
+			s = arr[i];
+			l = strlen (s);
+			if (l >= 2) {
+				if (strchr (quotes, s[0]) && s[l-1] == s[0]) {
+					memmove (s, s+1, l-2);
+					s[l-2] = '\0';
+				}
+			}
+			i++;
+		}
+	}
 
-	*argc = i;
 	*argv = arr;
+	*argc = g_strv_length (arr);
 
 	return 0;
 }
@@ -544,20 +561,22 @@ nmc_util_strv_to_slist (char **strv)
  * Returns: a newly allocated string. Caller must free it with g_free().
  */
 char *
-nmc_util_strv_for_display (const char **strv)
+nmc_util_strv_for_display (const char **strv, gboolean brackets)
 {
 	GString *result;
 	guint i = 0;
 
 	result = g_string_sized_new (150);
-	g_string_append_c (result, '[');
+	if (brackets)
+		g_string_append_c (result, '[');
 	while (strv && strv[i]) {
 		if (result->len > 1)
 			g_string_append (result, ", ");
 		g_string_append (result, strv[i]);
 		i++;
 	}
-	g_string_append_c (result, ']');
+	if (brackets)
+		g_string_append_c (result, ']');
 
 	return g_string_free (result, FALSE);
 }