summaryrefslogtreecommitdiff
path: root/src/core/wee-string.c
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2014-01-31 12:56:26 +0100
committerSebastien Helleu <flashcode@flashtux.org>2014-02-09 12:55:40 +0100
commit6bc7c456d7899ab3d0020120c96ea53eded04b98 (patch)
tree674c713f6ac52fb89a375e6a1af7e8f5d92373b9 /src/core/wee-string.c
parenta703fc8c1771e5e8ef4ad08f8c82b6e18594ee10 (diff)
downloadweechat-6bc7c456d7899ab3d0020120c96ea53eded04b98.zip
core: add argument "num_items" in function string_split_shell
Diffstat (limited to 'src/core/wee-string.c')
-rw-r--r--src/core/wee-string.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index c19215c4a..cbd69738d 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -1387,7 +1387,7 @@ string_split_internal (const char *string, const char *separators, int keep_eol,
char *ptr, *ptr1, *ptr2;
const char *str_shared;
- if (num_items != NULL)
+ if (num_items)
*num_items = 0;
if (!string || !string[0] || !separators || !separators[0])
@@ -1402,7 +1402,7 @@ string_split_internal (const char *string, const char *separators, int keep_eol,
i = 1;
while ((ptr = strpbrk (ptr, separators)))
{
- while (ptr[0] && (strchr (separators, ptr[0]) != NULL))
+ while (ptr[0] && strchr (separators, ptr[0]))
{
ptr++;
}
@@ -1421,7 +1421,7 @@ string_split_internal (const char *string, const char *separators, int keep_eol,
for (i = 0; i < n_items; i++)
{
- while (ptr1[0] && (strchr (separators, ptr1[0]) != NULL))
+ while (ptr1[0] && strchr (separators, ptr1[0]))
{
ptr1++;
}
@@ -1522,7 +1522,7 @@ string_split_internal (const char *string, const char *separators, int keep_eol,
}
array[i] = NULL;
- if (num_items != NULL)
+ if (num_items)
*num_items = i;
free (string2);
@@ -1577,12 +1577,15 @@ string_split_shared (const char *string, const char *separators, int keep_eol,
*/
char **
-string_split_shell (const char *string)
+string_split_shell (const char *string, int *num_items)
{
int temp_len, num_args, add_char_to_temp, add_temp_to_args, quoted;
char *string2, *temp, **args, **args2, state, escapedstate;
char *ptr_string, *ptr_next, saved_char;
+ if (num_items)
+ *num_items = 0;
+
if (!string)
return NULL;
@@ -1748,6 +1751,9 @@ string_split_shell (const char *string)
free (string2);
free (temp);
+ if (num_items)
+ *num_items = num_args;
+
return args;
}
@@ -1845,7 +1851,7 @@ string_split_command (const char *command, char separator)
nb_substr = 1;
ptr = command;
- while ( (p = strchr(ptr, separator)) != NULL)
+ while ((p = strchr(ptr, separator)) != NULL)
{
nb_substr++;
ptr = ++p;