core: add argument "num_items" in function string_split_shell

v2.8-utf8proc
Sebastien Helleu 2014-01-31 12:56:26 +01:00
parent a703fc8c17
commit 6bc7c456d7
3 changed files with 15 additions and 8 deletions

View File

@ -1542,7 +1542,8 @@ hook_process_child (struct t_hook *hook_process)
* if no arguments were found in hashtable, make an automatic split
* of command, like the shell does
*/
exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
exec_args = string_split_shell (HOOK_PROCESS(hook_process, command),
NULL);
}
if (exec_args)

View File

@ -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;

View File

@ -64,7 +64,7 @@ extern char **string_split (const char *string, const char *separators,
extern char **string_split_shared (const char *string, const char *separators,
int keep_eol, int num_items_max,
int *num_items);
extern char **string_split_shell (const char *string);
extern char **string_split_shell (const char *string, int *num_items);
extern void string_free_split (char **split_string);
extern void string_free_split_shared (char **split_string);
extern char *string_build_with_split_string (const char **split_string,