mirror of
https://github.com/samba-team/samba.git
synced 2025-01-10 01:18:15 +03:00
r10516: Add seperator argument to str_list_{make,join}_shell()
(This used to be commit 0a5c9197f2
)
This commit is contained in:
parent
bb9c9ec69c
commit
01319b8462
@ -75,7 +75,7 @@ const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *
|
||||
Entries are seperated by spaces and can be enclosed by quotes.
|
||||
Does NOT support escaping
|
||||
*/
|
||||
const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string)
|
||||
const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const char *sep)
|
||||
{
|
||||
int num_elements = 0;
|
||||
const char **ret = NULL;
|
||||
@ -85,13 +85,16 @@ const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (sep == NULL)
|
||||
sep = " \t\n\r";
|
||||
|
||||
while (string && *string) {
|
||||
size_t len = strcspn(string, " ");
|
||||
size_t len = strcspn(string, sep);
|
||||
char *element;
|
||||
const char **ret2;
|
||||
|
||||
if (len == 0) {
|
||||
string += strspn(string, " ");
|
||||
string += strspn(string, sep);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -148,7 +151,7 @@ char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator)
|
||||
|
||||
/* join a list back to one (shell-like) string; entries
|
||||
* seperated by spaces, using quotes where necessary */
|
||||
char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list)
|
||||
char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep)
|
||||
{
|
||||
char *ret = NULL;
|
||||
int i;
|
||||
@ -163,9 +166,9 @@ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list)
|
||||
|
||||
for (i = 1; list[i]; i++) {
|
||||
if (strchr(list[i], ' ') || strlen(list[i]) == 0)
|
||||
ret = talloc_asprintf_append(ret, " \"%s\"", list[i]);
|
||||
ret = talloc_asprintf_append(ret, "%c\"%s\"", sep, list[i]);
|
||||
else
|
||||
ret = talloc_asprintf_append(ret, " %s", list[i]);
|
||||
ret = talloc_asprintf_append(ret, "%c%s", sep, list[i]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -38,9 +38,9 @@ static BOOL test_lists_shell(TALLOC_CTX *mem_ctx)
|
||||
const char **ret1, **ret2, *tmp;
|
||||
BOOL match = True;
|
||||
|
||||
ret1 = str_list_make_shell(mem_ctx, test_lists_shell_strings[i]);
|
||||
tmp = str_list_join_shell(mem_ctx, ret1);
|
||||
ret2 = str_list_make_shell(mem_ctx, tmp);
|
||||
ret1 = str_list_make_shell(mem_ctx, test_lists_shell_strings[i], " ");
|
||||
tmp = str_list_join_shell(mem_ctx, ret1, ' ');
|
||||
ret2 = str_list_make_shell(mem_ctx, tmp, " ");
|
||||
|
||||
if ((ret1 == NULL || ret2 == NULL) && ret2 != ret1) {
|
||||
match = False;
|
||||
|
Loading…
Reference in New Issue
Block a user