|
version 1.2.4.2, 2011/05/19 03:01:20
|
version 1.3.2.2, 2011/08/26 12:51:01
|
|
Line 76 io_arrayInit(int numItems)
|
Line 76 io_arrayInit(int numItems)
|
| |
|
| /* |
/* |
| * io_arrayFrom() - Create and fill array from array with pointers |
* io_arrayFrom() - Create and fill array from array with pointers |
| * @argv = Array with pointers | * @pargv = Array with pointers |
| * @argc = Number of Items, if 0 walk through argv and stop when reach NULL item |
* @argc = Number of Items, if 0 walk through argv and stop when reach NULL item |
| * return: NULL error, != NULL allocated memory for array | * return: NULL error, != NULL allocated new array |
| */ |
*/ |
| inline array_t * |
inline array_t * |
| io_arrayFrom(const char **argv, int argc) | io_arrayFrom(const char *** __restrict pargv, int argc) |
| { |
{ |
| array_t *arr = NULL; |
array_t *arr = NULL; |
| const char **a = NULL; |
const char **a = NULL; |
| register int num = 0; |
register int num = 0; |
| |
|
| assert(argv); | assert(pargv); |
| if (!argv || !*argv || argc < 0) | if (!pargv || !*pargv || argc < 0) |
| return NULL; |
return NULL; |
| |
|
| if (argc) |
if (argc) |
| num = argc; |
num = argc; |
| else |
else |
| for (a = argv; *a; a++, num++); | for (a = *pargv; *a; a++, num++); |
| |
|
| arr = malloc(sizeof(array_t)); |
arr = malloc(sizeof(array_t)); |
| if (!arr) { |
if (!arr) { |
|
Line 109 io_arrayFrom(const char **argv, int argc)
|
Line 109 io_arrayFrom(const char **argv, int argc)
|
| free(arr); |
free(arr); |
| return NULL; |
return NULL; |
| } else |
} else |
| memcpy(arr->arr_data, argv, io_arraySize(arr) * sizeof(void*)); | memcpy(arr->arr_data, *pargv, io_arraySize(arr) * sizeof(void*)); |
| |
|
| return arr; |
return arr; |
| } |
} |
|
Line 117 io_arrayFrom(const char **argv, int argc)
|
Line 117 io_arrayFrom(const char **argv, int argc)
|
| /* |
/* |
| * io_arrayTo() - Create and fill array with pointers from dynamic array |
* io_arrayTo() - Create and fill array with pointers from dynamic array |
| * @arr = Array |
* @arr = Array |
| * return: NULL error, != NULL allocated memory for array | * return: NULL error, != NULL allocated memory for array, NULL terminated |
| */ |
*/ |
| inline char ** |
inline char ** |
| io_arrayTo(array_t * __restrict arr) |
io_arrayTo(array_t * __restrict arr) |
|
Line 128 io_arrayTo(array_t * __restrict arr)
|
Line 128 io_arrayTo(array_t * __restrict arr)
|
| if (!arr || !io_arraySize(arr)) |
if (!arr || !io_arraySize(arr)) |
| return NULL; |
return NULL; |
| |
|
| args = (char **) calloc(io_arraySize(arr), sizeof(char*)); | args = (char **) calloc(io_arraySize(arr) + 1, sizeof(char*)); |
| if (!args) { |
if (!args) { |
| LOGERR; |
LOGERR; |
| return NULL; |
return NULL; |
| } else |
} else |
| memcpy(args, arr->arr_data, io_arraySize(arr) * sizeof(char*)); |
memcpy(args, arr->arr_data, io_arraySize(arr) * sizeof(char*)); |
| |
args[io_arraySize(arr)] = NULL; |
| |
|
| return args; |
return args; |
| } |
} |
|
Line 168 io_arrayFree(array_t * __restrict arr)
|
Line 169 io_arrayFree(array_t * __restrict arr)
|
| inline void |
inline void |
| io_arrayDestroy(array_t ** __restrict parr) |
io_arrayDestroy(array_t ** __restrict parr) |
| { |
{ |
| assert(parr); | assert(parr && *parr); |
| if (!parr) | if (!parr || !*parr) |
| return; |
return; |
| |
|
| if ((*parr)->arr_data) |
if ((*parr)->arr_data) |
|
Line 225 io_arrayGrow(array_t * __restrict arr, int newNumItems
|
Line 226 io_arrayGrow(array_t * __restrict arr, int newNumItems
|
| */ |
*/ |
| |
|
| arr->arr_num = newNumItems; |
arr->arr_num = newNumItems; |
| data = realloc(arr->arr_data, io_arraySize(arr) * sizeof(void*)); | if (io_arraySize(arr)) { |
| if (!data) { | data = realloc(arr->arr_data, io_arraySize(arr) * sizeof(void*)); |
| LOGERR; | if (!data) { |
| return -1; | LOGERR; |
| } else | return -1; |
| arr->arr_data = data; | } else |
| memset(arr->arr_data + (io_arraySize(arr) - n), 0, n * sizeof(void*)); | arr->arr_data = data; |
| |
|
| |
memset(arr->arr_data + (io_arraySize(arr) - n), 0, n * sizeof(void*)); |
| |
} else { |
| |
if (arr->arr_data) |
| |
free(arr->arr_data); |
| |
arr->arr_data = NULL; |
| |
} |
| |
|
| return 0; |
return 0; |
| } |
} |
| |
|
|
Line 263 io_arrayVacuum(array_t * __restrict arr, int fromWhere
|
Line 271 io_arrayVacuum(array_t * __restrict arr, int fromWhere
|
| */ |
*/ |
| if (fromWhere & VACUUM_LEFT) { |
if (fromWhere & VACUUM_LEFT) { |
| for (i = 0; i < num && !arr->arr_data[i]; i++); |
for (i = 0; i < num && !arr->arr_data[i]; i++); |
| |
if (i) { |
| |
memmove(arr->arr_data, arr->arr_data + i, (num - i) * sizeof(void*)); |
| |
memset(arr->arr_data + (num - i), 0, i * sizeof(void*)); |
| |
|
| memmove(arr->arr_data, arr->arr_data + i, (num - i) * sizeof(void*)); | num -= i; |
| memset(arr->arr_data + (num - i), 0, i * sizeof(void*)); | cx += i; |
| } |
| num -= i; | |
| cx += i; | |
| } |
} |
| if (fromWhere & VACUUM_BETWEEN) { |
if (fromWhere & VACUUM_BETWEEN) { |
| for (i = 0; i < num; i++) { |
for (i = 0; i < num; i++) { |
|
Line 316 io_arrayPush(array_t * __restrict arr, void **data)
|
Line 325 io_arrayPush(array_t * __restrict arr, void **data)
|
| /* |
/* |
| * io_arrayPop() - Pop element from dynamic array like stack manner, last used position |
* io_arrayPop() - Pop element from dynamic array like stack manner, last used position |
| * @arr = Array |
* @arr = Array |
| * @data = Element, if set NULL return only first empty position | * @data = Element, if set NULL return only last used position |
| * @delAfter = Delete after Pop element, !=0 delete element from array after return data |
* @delAfter = Delete after Pop element, !=0 delete element from array after return data |
| * return: -1 not found used position, array is empty!, >-1 return element position |
* return: -1 not found used position, array is empty!, >-1 return element position |
| */ |
*/ |