Code and comment cleanups to the Karll array functions
There should be no behavioural change.
This commit is contained in:
152
source/array.c
152
source/array.c
@@ -417,14 +417,14 @@ m_s3cat(&result, space, array_info.item[array_info.index[index]]);
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_matchitem)
|
||||
{
|
||||
char *name;
|
||||
char *name = next_arg(input, &input);
|
||||
long index;
|
||||
an_array *array;
|
||||
long current_match;
|
||||
long best_match = 0;
|
||||
long match = -1;
|
||||
|
||||
if ((name = next_arg(input, &input)) && (array = get_array(name)))
|
||||
if (name && (array = get_array(name)))
|
||||
{
|
||||
match = -2;
|
||||
if (*input)
|
||||
@@ -446,14 +446,11 @@ BUILT_IN_FUNCTION(function_matchitem)
|
||||
BUILT_IN_FUNCTION(function_igetmatches)
|
||||
{
|
||||
char *result = NULL;
|
||||
char *name = NULL;
|
||||
char *name = next_arg(input, &input);
|
||||
long item;
|
||||
an_array *array;
|
||||
|
||||
if ((name = next_arg(input, &input)) &&
|
||||
(array = get_array(name)) && *input)
|
||||
{
|
||||
if (*input)
|
||||
if (name && (array = get_array(name)) && *input)
|
||||
{
|
||||
for (item = 0; item < array->size; item++)
|
||||
{
|
||||
@@ -461,7 +458,6 @@ BUILT_IN_FUNCTION(function_igetmatches)
|
||||
m_s3cat(&result, space, ltoa(find_index(array, item)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!result)
|
||||
RETURN_EMPTY;
|
||||
@@ -475,12 +471,12 @@ BUILT_IN_FUNCTION(function_igetmatches)
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_listarray)
|
||||
{
|
||||
char *name;
|
||||
an_array *array;
|
||||
long index;
|
||||
char *result = NULL;
|
||||
char *name = next_arg(input, &input);
|
||||
long index;
|
||||
an_array *array;
|
||||
|
||||
if ((name = next_arg(input, &input)) && (array = get_array(name)))
|
||||
if (name && (array = get_array(name)))
|
||||
{
|
||||
for (index = 0; index < array->size; index++)
|
||||
m_s3cat(&result, space, array->item[index]);
|
||||
@@ -497,14 +493,11 @@ BUILT_IN_FUNCTION(function_listarray)
|
||||
BUILT_IN_FUNCTION(function_getmatches)
|
||||
{
|
||||
char *result = NULL;
|
||||
char *name = NULL;
|
||||
char *name = next_arg(input, &input);
|
||||
long index;
|
||||
an_array *array;
|
||||
|
||||
if ((name = next_arg(input, &input)) &&
|
||||
(array = get_array(name)) && *input)
|
||||
{
|
||||
if (*input)
|
||||
if (name && (array = get_array(name)) && *input)
|
||||
{
|
||||
for (index = 0; index < array->size; index++)
|
||||
{
|
||||
@@ -512,9 +505,10 @@ BUILT_IN_FUNCTION(function_getmatches)
|
||||
m_s3cat(&result, space, ltoa(index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!result)
|
||||
RETURN_EMPTY;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -525,14 +519,14 @@ BUILT_IN_FUNCTION(function_getmatches)
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_rmatchitem)
|
||||
{
|
||||
char *name = NULL;
|
||||
char *name = next_arg(input, &input);
|
||||
long index;
|
||||
an_array *array;
|
||||
long current_match;
|
||||
long best_match = 0;
|
||||
long match = -1;
|
||||
|
||||
if ((name = next_arg(input, &input)) && (array = get_array(name)))
|
||||
if (name && (array = get_array(name)))
|
||||
{
|
||||
match = -2;
|
||||
if (*input)
|
||||
@@ -559,13 +553,11 @@ BUILT_IN_FUNCTION(function_rmatchitem)
|
||||
BUILT_IN_FUNCTION(function_getrmatches)
|
||||
{
|
||||
char *result = NULL;
|
||||
char *name = NULL;
|
||||
char *name = next_arg(input, &input);
|
||||
long index;
|
||||
an_array *array;
|
||||
|
||||
if ((name = next_arg(input, &input)) && (array = get_array(name)))
|
||||
{
|
||||
if (*input)
|
||||
if (name && (array = get_array(name)) && *input)
|
||||
{
|
||||
for (index = 0; index < array->size; index++)
|
||||
{
|
||||
@@ -573,7 +565,6 @@ BUILT_IN_FUNCTION(function_getrmatches)
|
||||
m_s3cat(&result, space, ltoa(index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!result)
|
||||
RETURN_EMPTY;
|
||||
@@ -581,16 +572,16 @@ BUILT_IN_FUNCTION(function_getrmatches)
|
||||
}
|
||||
|
||||
/*
|
||||
* function_numitems() returns the number of items in an array, or -1 if unable
|
||||
* function_numitems() returns the number of items in an array, or 0 if unable
|
||||
* to find the array
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_numitems)
|
||||
{
|
||||
char *name = NULL;
|
||||
char *name = next_arg(input, &input);
|
||||
an_array *array;
|
||||
long items = 0;
|
||||
|
||||
if ((name = next_arg(input, &input)) && (array = get_array(name)))
|
||||
if (name && (array = get_array(name)))
|
||||
items = array->size;
|
||||
|
||||
RETURN_INT(items);
|
||||
@@ -602,21 +593,18 @@ BUILT_IN_FUNCTION(function_numitems)
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_getitem)
|
||||
{
|
||||
char *name = NULL;
|
||||
char *itemstr = NULL;
|
||||
char *name = next_arg(input, &input);
|
||||
char *itemstr = next_arg(input, &input);
|
||||
long item;
|
||||
an_array *array;
|
||||
char *found = NULL;
|
||||
|
||||
if ((name = next_arg(input, &input)) && (array = get_array(name)))
|
||||
{
|
||||
if ((itemstr = next_arg(input, &input)))
|
||||
if (name && (array = get_array(name)) && itemstr)
|
||||
{
|
||||
item = my_atol(itemstr);
|
||||
if (item >= 0 && item < array->size)
|
||||
found = array->item[item];
|
||||
}
|
||||
}
|
||||
RETURN_STR(found);
|
||||
}
|
||||
|
||||
@@ -634,17 +622,15 @@ BUILT_IN_FUNCTION(function_getitem)
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_setitem)
|
||||
{
|
||||
char *name = NULL;
|
||||
char *itemstr = NULL;
|
||||
char *name = next_arg(input, &input);
|
||||
char *itemstr = next_arg(input, &input);
|
||||
long item;
|
||||
long index = 0;
|
||||
long oldindex;
|
||||
an_array *array;
|
||||
int result = -1;
|
||||
|
||||
if ((name = next_arg(input, &input)))
|
||||
{
|
||||
if (strlen(name) && (itemstr = next_arg(input, &input)))
|
||||
if (name && itemstr)
|
||||
{
|
||||
item = my_atol(itemstr);
|
||||
if (item >= 0)
|
||||
@@ -702,7 +688,6 @@ BUILT_IN_FUNCTION(function_setitem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
RETURN_INT(result);
|
||||
}
|
||||
|
||||
@@ -740,18 +725,15 @@ BUILT_IN_FUNCTION(function_numarrays)
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_finditem)
|
||||
{
|
||||
char *name = NULL;
|
||||
char *name = next_arg(input, &input);
|
||||
an_array *array;
|
||||
long item = -1;
|
||||
|
||||
if ((name = next_arg(input, &input)) && (array = get_array(name)))
|
||||
{
|
||||
if (*input)
|
||||
if (name && (array = get_array(name)) && *input)
|
||||
{
|
||||
item = find_item(*array, input);
|
||||
item = (item >= 0) ? array->index[item] : -2;
|
||||
}
|
||||
}
|
||||
RETURN_INT(item)
|
||||
}
|
||||
|
||||
@@ -762,18 +744,15 @@ BUILT_IN_FUNCTION(function_finditem)
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_ifinditem)
|
||||
{
|
||||
char *name = NULL;
|
||||
char *name = next_arg(input, &input);
|
||||
an_array *array;
|
||||
long item = -1;
|
||||
|
||||
if ((name = next_arg(input, &input)) && (array = get_array(name)))
|
||||
{
|
||||
if (*input)
|
||||
if (name && (array = get_array(name)) && *input)
|
||||
{
|
||||
if ((item = find_item(*array, input)) < 0)
|
||||
item = -2;
|
||||
}
|
||||
}
|
||||
RETURN_INT(item)
|
||||
}
|
||||
|
||||
@@ -784,21 +763,18 @@ BUILT_IN_FUNCTION(function_ifinditem)
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_igetitem)
|
||||
{
|
||||
char *name = NULL;
|
||||
char *itemstr = NULL;
|
||||
char *name = next_arg(input, &input);
|
||||
char *itemstr = next_arg(input, &input);
|
||||
long item;
|
||||
an_array *array;
|
||||
char *found = NULL;
|
||||
|
||||
if ((name = next_arg(input, &input)) && (array = get_array(name)))
|
||||
{
|
||||
if ((itemstr = next_arg(input, &input)))
|
||||
if (name && (array = get_array(name)) && itemstr)
|
||||
{
|
||||
item = my_atol(itemstr);
|
||||
if (item >= 0 && item < array->size)
|
||||
found = array->item[array->index[item]];
|
||||
}
|
||||
}
|
||||
RETURN_STR(found)
|
||||
}
|
||||
|
||||
@@ -809,16 +785,16 @@ BUILT_IN_FUNCTION(function_igetitem)
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_indextoitem)
|
||||
{
|
||||
char *name = NULL;
|
||||
char *itemstr = NULL;
|
||||
char *name = next_arg(input, &input);
|
||||
char *itemstr = next_arg(input, &input);
|
||||
long item;
|
||||
an_array *array;
|
||||
long found = -1;
|
||||
|
||||
if ((name = next_arg(input, &input)) && (array = get_array(name)))
|
||||
if (name && (array = get_array(name)))
|
||||
{
|
||||
found = -2;
|
||||
if ((itemstr = next_arg(input, &input)))
|
||||
if (itemstr)
|
||||
{
|
||||
item = my_atol(itemstr);
|
||||
if (item >= 0 && item < array->size)
|
||||
@@ -835,16 +811,16 @@ BUILT_IN_FUNCTION(function_indextoitem)
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_itemtoindex)
|
||||
{
|
||||
char *name;
|
||||
char *itemstr;
|
||||
char *name = next_arg(input, &input);
|
||||
char *itemstr = next_arg(input, &input);
|
||||
long item;
|
||||
an_array *array;
|
||||
long found = -1;
|
||||
|
||||
if ((name = next_arg(input, &input)) && (array = get_array(name)))
|
||||
if (name && (array = get_array(name)))
|
||||
{
|
||||
found = -2;
|
||||
if ((itemstr = next_arg(input, &input)))
|
||||
if (itemstr)
|
||||
{
|
||||
item = my_atol(itemstr);
|
||||
if (item >= 0 && item < array->size)
|
||||
@@ -862,8 +838,8 @@ BUILT_IN_FUNCTION(function_itemtoindex)
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_delitem)
|
||||
{
|
||||
char *name;
|
||||
char *itemstr;
|
||||
char *name = next_arg(input, &input);
|
||||
char *itemstr = next_arg(input, &input);
|
||||
char **strptr;
|
||||
long item;
|
||||
long cnt;
|
||||
@@ -871,14 +847,15 @@ BUILT_IN_FUNCTION(function_delitem)
|
||||
an_array *array;
|
||||
long found = -1;
|
||||
|
||||
if ((name = next_arg(input, &input)) && (array = get_array(name)))
|
||||
if (name && (array = get_array(name)))
|
||||
{
|
||||
found = -2;
|
||||
if ((itemstr = next_arg(input, &input)))
|
||||
if (itemstr)
|
||||
{
|
||||
item = my_atol(itemstr);
|
||||
if (item >= 0 && item < array->size)
|
||||
{
|
||||
found = 0;
|
||||
if (array->size == 1)
|
||||
delete_array(name);
|
||||
else
|
||||
@@ -895,7 +872,6 @@ BUILT_IN_FUNCTION(function_delitem)
|
||||
RESIZE(array->item, char *, array->size);
|
||||
RESIZE(array->index, long, array->size);
|
||||
}
|
||||
found = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -908,10 +884,10 @@ BUILT_IN_FUNCTION(function_delitem)
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_delarray)
|
||||
{
|
||||
char *name;
|
||||
char *name = next_arg(input, &input);
|
||||
long found = -1;
|
||||
|
||||
if ((name = next_arg(input, &input)) && (get_array(name)))
|
||||
if (name && get_array(name))
|
||||
{
|
||||
delete_array(name);
|
||||
found = 0;
|
||||
@@ -920,18 +896,16 @@ BUILT_IN_FUNCTION(function_delarray)
|
||||
}
|
||||
/*
|
||||
* function_ifindfirst() returns the first index of an exact match with the
|
||||
* search string, or returns -2 if unable to find the array, or -1 if unable
|
||||
* search string, or returns -1 if unable to find the array, or -2 if unable
|
||||
* to find any matches.
|
||||
*/
|
||||
BUILT_IN_FUNCTION(function_ifindfirst)
|
||||
{
|
||||
char *name;
|
||||
char *name = next_arg(input, &input);
|
||||
an_array *array;
|
||||
long item = -1;
|
||||
|
||||
if ((name = next_arg(input, &input)) && (array = get_array(name)))
|
||||
{
|
||||
if (*input)
|
||||
if (name && (array = get_array(name)) && *input)
|
||||
{
|
||||
if ((item = find_item(*array, input)) < 0)
|
||||
item = -2;
|
||||
@@ -942,7 +916,6 @@ BUILT_IN_FUNCTION(function_ifindfirst)
|
||||
item++;
|
||||
}
|
||||
}
|
||||
}
|
||||
RETURN_INT(item)
|
||||
}
|
||||
|
||||
@@ -951,20 +924,18 @@ BUILT_IN_FUNCTION(function_ifindfirst)
|
||||
* the elements within the array. This allows parsing using % and *
|
||||
* for wildcards. We return only the best match from the array, unlike
|
||||
* getmatch() which returns ALL the matching items.
|
||||
*
|
||||
* <shade> gettmatch(users % user@host *) would match the userhost mask in the
|
||||
* second word of the array
|
||||
*/
|
||||
|
||||
BUILT_IN_FUNCTION(function_gettmatch)
|
||||
{
|
||||
char *name;
|
||||
char *name = next_arg(input, &input);
|
||||
an_array *array;
|
||||
char *ret = NULL;
|
||||
#if 0
|
||||
<shade> gettmatch(users % user@host *) would match the userhost mask in the
|
||||
second word of the array
|
||||
#endif
|
||||
if ((name = next_arg(input, &input)) && (array = get_array(name)))
|
||||
{
|
||||
if (*input)
|
||||
|
||||
if (name && (array = get_array(name)) && *input)
|
||||
{
|
||||
int index, current_match;
|
||||
int best_match = 0;
|
||||
@@ -981,21 +952,17 @@ char *ret = NULL;
|
||||
ret = array->item[match];
|
||||
|
||||
}
|
||||
}
|
||||
RETURN_STR(ret);
|
||||
}
|
||||
|
||||
BUILT_IN_FUNCTION(function_igetrmatches)
|
||||
{
|
||||
char *result = (char *) 0;
|
||||
char *name = (char *) 0;
|
||||
char *result = NULL;
|
||||
char *name = next_arg(input, &input);
|
||||
long item;
|
||||
an_array *array;
|
||||
|
||||
if ((name = next_arg(input, &input)) &&
|
||||
(array = get_array(name)) && *input)
|
||||
{
|
||||
if (*input)
|
||||
if (name && (array = get_array(name)) && *input)
|
||||
{
|
||||
for (item = 0; item < array->size; item++)
|
||||
{
|
||||
@@ -1003,7 +970,6 @@ BUILT_IN_FUNCTION(function_igetrmatches)
|
||||
m_s3cat(&result, space, ltoa(find_index(array, item)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!result)
|
||||
RETURN_EMPTY;
|
||||
|
||||
Reference in New Issue
Block a user