re-implement ast_separate_app_args with clearer code and in a way that doesn't fail with certain combinations of array size and delimiter count

add doxygen docs for ast_separate_app_args


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5566 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kevin P. Fleming
2005-05-04 03:43:10 +00:00
parent 135f392c62
commit 523911c9b0
2 changed files with 33 additions and 9 deletions

29
app.c
View File

@@ -1069,16 +1069,29 @@ int ast_app_group_match_get_count(char *groupmatch, char *category)
int ast_separate_app_args(char *buf, char delim, char **array, int arraylen)
{
int x = 0;
memset(array, 0, arraylen * sizeof(char *));
if (!buf)
int x;
char *scan;
char delims[2];
if (!buf || !array || !arraylen)
return 0;
for (array[x] = buf ; x < arraylen && array[x]; x++) {
if ((array[x+1] = strchr(array[x], delim))) {
*array[x+1] = '\0';
array[x+1]++;
}
memset(array, 0, arraylen * sizeof(*array));
scan = buf;
delims[0] = delim;
delims[1] = '\0';
x = 0;
while (x < arraylen - 1) {
array[x] = strsep(&scan, delims);
x++;
if (!scan)
break;
}
array[x++] = scan;
return x;
}