version 1.8, 2012/03/29 01:31:33
|
version 1.8.2.1, 2012/04/10 15:27:33
|
Line 63 io_arrayInit(int numItems)
|
Line 63 io_arrayInit(int numItems)
|
return NULL; |
return NULL; |
} |
} |
|
|
|
arr->arr_last = -1; |
arr->arr_num = numItems; |
arr->arr_num = numItems; |
arr->arr_data = calloc(io_arraySize(arr), sizeof(void*)); |
arr->arr_data = calloc(io_arraySize(arr), sizeof(void*)); |
if (!arr->arr_data) { |
if (!arr->arr_data) { |
Line 110 io_arrayFrom(const char *** __restrict pargv, int argc
|
Line 111 io_arrayFrom(const char *** __restrict pargv, int argc
|
LOGERR; |
LOGERR; |
free(arr); |
free(arr); |
return NULL; |
return NULL; |
} else | } else { |
memcpy(arr->arr_data, *pargv, io_arraySize(arr) * sizeof(void*)); |
memcpy(arr->arr_data, *pargv, io_arraySize(arr) * sizeof(void*)); |
|
arr->arr_last = io_arraySize(arr) - 1; |
|
} |
|
|
return arr; |
return arr; |
} |
} |
Line 162 io_arrayFree(array_t * __restrict arr)
|
Line 165 io_arrayFree(array_t * __restrict arr)
|
free(arr->arr_data[i]); |
free(arr->arr_data[i]); |
arr->arr_data[i] = NULL; |
arr->arr_data[i] = NULL; |
} |
} |
|
|
|
arr->arr_last = -1; |
} |
} |
|
|
/* |
/* |
Line 186 io_arrayDestroy(array_t ** __restrict parr)
|
Line 191 io_arrayDestroy(array_t ** __restrict parr)
|
* io_arrayLen() - Get last used element in dynamic array (array Length) |
* io_arrayLen() - Get last used element in dynamic array (array Length) |
* |
* |
* @arr = Array |
* @arr = Array |
* return: -1 error, 0 empty or >0 position of last used element | * return: -1 empty or >-1 position of last used element |
*/ |
*/ |
inline int |
inline int |
io_arrayLen(array_t * __restrict arr) |
io_arrayLen(array_t * __restrict arr) |
Line 199 io_arrayLen(array_t * __restrict arr)
|
Line 204 io_arrayLen(array_t * __restrict arr)
|
|
|
for (i = io_arraySize(arr); i && !arr->arr_data[i - 1]; i--); |
for (i = io_arraySize(arr); i && !arr->arr_data[i - 1]; i--); |
|
|
return i; | return --i; |
} |
} |
|
|
/* |
/* |
Line 239 io_arrayGrow(array_t * __restrict arr, int newNumItems
|
Line 244 io_arrayGrow(array_t * __restrict arr, int newNumItems
|
arr->arr_data = data; |
arr->arr_data = data; |
|
|
memset(arr->arr_data + (io_arraySize(arr) - n), 0, n * sizeof(void*)); |
memset(arr->arr_data + (io_arraySize(arr) - n), 0, n * sizeof(void*)); |
|
arr->arr_last = io_arrayLen(arr); |
} else { |
} else { |
if (arr->arr_data) |
if (arr->arr_data) |
free(arr->arr_data); |
free(arr->arr_data); |
arr->arr_data = NULL; |
arr->arr_data = NULL; |
|
arr->arr_last = -1; |
} |
} |
|
|
return 0; |
return 0; |
Line 298 io_arrayVacuum(array_t * __restrict arr, int fromWhere
|
Line 305 io_arrayVacuum(array_t * __restrict arr, int fromWhere
|
} |
} |
} |
} |
|
|
|
arr->arr_last = io_arrayLen(arr); |
return cx; |
return cx; |
} |
} |
|
|
Line 317 io_arrayElem(array_t * __restrict arr, int n, void *da
|
Line 325 io_arrayElem(array_t * __restrict arr, int n, void *da
|
if (!arr) |
if (!arr) |
return (void*) -1; |
return (void*) -1; |
|
|
if (n > io_arraySize(arr) && io_arrayGrow(arr, n + 1, 0)) | if (n >= io_arraySize(arr) && io_arrayGrow(arr, n + 1, 0)) |
return (void*) -1; |
return (void*) -1; |
|
|
dat = io_arrayGet(arr, n); |
dat = io_arrayGet(arr, n); |
Line 332 io_arrayElem(array_t * __restrict arr, int n, void *da
|
Line 340 io_arrayElem(array_t * __restrict arr, int n, void *da
|
* |
* |
* @arr = Array |
* @arr = Array |
* @data = Element, if set NULL return only first empty position |
* @data = Element, if set NULL return only first empty position |
|
* @mayGrow = Array may to grow, if not enough room for new element |
* return: -1 not found empty position, array is full!, >-1 return position of stored element into array |
* return: -1 not found empty position, array is full!, >-1 return position of stored element into array |
*/ |
*/ |
inline int |
inline int |
io_arrayPush(array_t * __restrict arr, void **data) | io_arrayPush(array_t * __restrict arr, void **data, int mayGrow) |
{ |
{ |
|
#if 0 |
register int i; |
register int i; |
|
#endif |
int ret = -1; |
int ret = -1; |
|
|
if (!arr) |
if (!arr) |
return -1; |
return -1; |
|
else |
|
ret = io_arrayLast(arr) + 1; |
|
if (!mayGrow && ret >= io_arraySize(arr)) |
|
return -1; |
|
if (mayGrow && ret >= io_arraySize(arr) && |
|
io_arrayGrow(arr, ret + 1, 0)) |
|
return -1; |
|
|
|
#if 0 |
for (i = 0; i < io_arraySize(arr); i++) |
for (i = 0; i < io_arraySize(arr); i++) |
if (!arr->arr_data[i]) { |
if (!arr->arr_data[i]) { |
if (data) |
if (data) |
Line 350 io_arrayPush(array_t * __restrict arr, void **data)
|
Line 369 io_arrayPush(array_t * __restrict arr, void **data)
|
ret = i; |
ret = i; |
break; |
break; |
} |
} |
|
#endif |
|
arr->arr_data[++arr->arr_last] = *data; |
|
|
return ret; |
return ret; |
} |
} |
Line 365 io_arrayPush(array_t * __restrict arr, void **data)
|
Line 386 io_arrayPush(array_t * __restrict arr, void **data)
|
inline int |
inline int |
io_arrayPop(array_t * __restrict arr, void ** __restrict data, int delAfter) |
io_arrayPop(array_t * __restrict arr, void ** __restrict data, int delAfter) |
{ |
{ |
|
#if 0 |
register int i; |
register int i; |
|
#endif |
int ret = -1; |
int ret = -1; |
|
|
if (!arr) |
if (!arr) |
return -1; |
return -1; |
|
|
|
#if 0 |
for (i = io_arraySize(arr) - 1; i >= 0; i--) |
for (i = io_arraySize(arr) - 1; i >= 0; i--) |
if (arr->arr_data[i]) { |
if (arr->arr_data[i]) { |
if (data) |
if (data) |
Line 380 io_arrayPop(array_t * __restrict arr, void ** __restri
|
Line 404 io_arrayPop(array_t * __restrict arr, void ** __restri
|
ret = i; |
ret = i; |
break; |
break; |
} |
} |
|
#endif |
|
ret = io_arrayLast(arr); |
|
|
|
if (data) |
|
*data = arr->arr_data[ret]; |
|
if (delAfter) |
|
arr->arr_data[arr->arr_last--] = NULL; |
|
|
return ret; |
return ret; |
} |
} |
|
|
Line 406 io_arrayConcat(array_t * __restrict dest, array_t * __
|
Line 437 io_arrayConcat(array_t * __restrict dest, array_t * __
|
return -1; |
return -1; |
memcpy(dest->arr_data + n, src->arr_data, io_arraySize(src) * sizeof(void*)); |
memcpy(dest->arr_data + n, src->arr_data, io_arraySize(src) * sizeof(void*)); |
|
|
|
dest->arr_last = io_arrayLen(dest); |
return io_arraySize(dest); |
return io_arraySize(dest); |
} |
} |
|
|
Line 427 io_arrayCopy(array_t ** __restrict dest, array_t * __r
|
Line 459 io_arrayCopy(array_t ** __restrict dest, array_t * __r
|
*dest = io_arrayInit(io_arraySize(src)); |
*dest = io_arrayInit(io_arraySize(src)); |
if (!*dest) |
if (!*dest) |
return -1; |
return -1; |
|
else |
|
(*dest)->arr_last = src->arr_last; |
|
|
memcpy((*dest)->arr_data, src->arr_data, io_arraySize(*dest) * sizeof(void*)); |
memcpy((*dest)->arr_data, src->arr_data, io_arraySize(*dest) * sizeof(void*)); |
return io_arraySize(*dest); |
return io_arraySize(*dest); |