version 1.3, 2011/06/07 11:49:39
|
version 1.8, 2012/03/29 01:31:33
|
Line 12 terms:
|
Line 12 terms:
|
All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
|
|
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 | Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
|
|
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
Line 48 SUCH DAMAGE.
|
Line 48 SUCH DAMAGE.
|
|
|
/* |
/* |
* io_arrayInit() - Create and initialize dynamic array |
* io_arrayInit() - Create and initialize dynamic array |
|
* |
* @numItems = Number of Items |
* @numItems = Number of Items |
* return: NULL error, != NULL allocated memory for array |
* return: NULL error, != NULL allocated memory for array |
*/ |
*/ |
Line 69 io_arrayInit(int numItems)
|
Line 70 io_arrayInit(int numItems)
|
free(arr); |
free(arr); |
return NULL; |
return NULL; |
} else |
} else |
memset(arr->arr_data, 0, io_arraySize(arr) * sizeof(void*)); | io_arrayZero(arr); |
|
|
return arr; |
return arr; |
} |
} |
|
|
/* |
/* |
* 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 111 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; |
} |
} |
|
|
/* |
/* |
* 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 142 io_arrayTo(array_t * __restrict arr)
|
Line 145 io_arrayTo(array_t * __restrict arr)
|
/* |
/* |
* io_arrayFree() - Free all data in dynamic array items |
* io_arrayFree() - Free all data in dynamic array items |
* (WARNING! If assign static array dont use this!!!) |
* (WARNING! If assign static array dont use this!!!) |
|
* |
* @arr = Array |
* @arr = Array |
* return: none |
* return: none |
*/ |
*/ |
Line 150 io_arrayFree(array_t * __restrict arr)
|
Line 154 io_arrayFree(array_t * __restrict arr)
|
{ |
{ |
register int i; |
register int i; |
|
|
assert(arr); |
|
if (!arr) |
if (!arr) |
return; |
return; |
|
|
Line 163 io_arrayFree(array_t * __restrict arr)
|
Line 166 io_arrayFree(array_t * __restrict arr)
|
|
|
/* |
/* |
* io_arrayDestroy() - Free and destroy dynamic array |
* io_arrayDestroy() - Free and destroy dynamic array |
|
* |
* @parr = Array |
* @parr = Array |
* return: none |
* return: none |
*/ |
*/ |
inline void |
inline void |
io_arrayDestroy(array_t ** __restrict parr) |
io_arrayDestroy(array_t ** __restrict parr) |
{ |
{ |
assert(parr); | if (!parr || !*parr) |
if (!parr) | |
return; |
return; |
|
|
if ((*parr)->arr_data) |
if ((*parr)->arr_data) |
Line 181 io_arrayDestroy(array_t ** __restrict parr)
|
Line 184 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 error, 0 empty or >0 position of last used element |
*/ |
*/ |
Line 200 io_arrayLen(array_t * __restrict arr)
|
Line 204 io_arrayLen(array_t * __restrict arr)
|
|
|
/* |
/* |
* io_arrayGrow() - Grow/Shrink dynamic array, Use with care when it shrink!!! |
* io_arrayGrow() - Grow/Shrink dynamic array, Use with care when it shrink!!! |
|
* |
* @arr = Array |
* @arr = Array |
* @newNumItems = Number of Items |
* @newNumItems = Number of Items |
|
* @freeShrink = Free elements before shrink array |
* return: -1 error, 0 ok |
* return: -1 error, 0 ok |
*/ |
*/ |
int |
int |
io_arrayGrow(array_t * __restrict arr, int newNumItems) | io_arrayGrow(array_t * __restrict arr, int newNumItems, int freeShrink) |
{ |
{ |
void **data; |
void **data; |
int n = 0; |
int n = 0; |
/* register int i; */ | register int i; |
|
|
assert(arr); |
|
if (!arr) |
if (!arr) |
return -1; |
return -1; |
|
|
Line 219 io_arrayGrow(array_t * __restrict arr, int newNumItems
|
Line 224 io_arrayGrow(array_t * __restrict arr, int newNumItems
|
return 0; |
return 0; |
if (io_arraySize(arr) < newNumItems) { |
if (io_arraySize(arr) < newNumItems) { |
n = newNumItems - io_arraySize(arr); |
n = newNumItems - io_arraySize(arr); |
} /* else | } else if (freeShrink) |
for (i = newNumItems; i < arr->arr_num; i++) |
for (i = newNumItems; i < arr->arr_num; i++) |
if (arr->arr_data[i]) |
if (arr->arr_data[i]) |
free(arr->arr_data[i]); |
free(arr->arr_data[i]); |
*/ |
|
|
|
arr->arr_num = newNumItems; |
arr->arr_num = newNumItems; |
if (io_arraySize(arr)) { |
if (io_arraySize(arr)) { |
Line 246 io_arrayGrow(array_t * __restrict arr, int newNumItems
|
Line 250 io_arrayGrow(array_t * __restrict arr, int newNumItems
|
|
|
/* |
/* |
* io_arrayVacuum() - Vacuum dynamic array, empty elements will be deleted |
* io_arrayVacuum() - Vacuum dynamic array, empty elements will be deleted |
|
* |
* @arr = Array |
* @arr = Array |
* @fromWhere = 1 begin, 2 ALL empty elements |
* @fromWhere = 1 begin, 2 ALL empty elements |
* return: -1 error, 0 ok |
* return: -1 error, 0 ok |
Line 256 io_arrayVacuum(array_t * __restrict arr, int fromWhere
|
Line 261 io_arrayVacuum(array_t * __restrict arr, int fromWhere
|
register int i, j, num; |
register int i, j, num; |
int cx = 0; |
int cx = 0; |
|
|
assert(arr); |
|
if (!arr) |
if (!arr) |
return -1; |
return -1; |
else |
else |
Line 271 io_arrayVacuum(array_t * __restrict arr, int fromWhere
|
Line 275 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 297 io_arrayVacuum(array_t * __restrict arr, int fromWhere
|
Line 302 io_arrayVacuum(array_t * __restrict arr, int fromWhere
|
} |
} |
|
|
/* |
/* |
|
* io_arrayElem() - Always GET/PUT element into dynamic array, if not enough elements grow array |
|
* |
|
* @arr = Array |
|
* @n = Position |
|
* @data = Element, if set NULL GET element at position or !=NULL PUT element at position |
|
* return: -1 error or !=-1 return element at position |
|
*/ |
|
inline void * |
|
io_arrayElem(array_t * __restrict arr, int n, void *data) |
|
{ |
|
void *dat = NULL; |
|
|
|
if (!arr) |
|
return (void*) -1; |
|
|
|
if (n > io_arraySize(arr) && io_arrayGrow(arr, n + 1, 0)) |
|
return (void*) -1; |
|
|
|
dat = io_arrayGet(arr, n); |
|
if (data) |
|
io_arraySet(arr, n, data); |
|
|
|
return dat; |
|
} |
|
|
|
/* |
* io_arrayPush() - Push element into dynamic array like stack manner, place at first empty position |
* io_arrayPush() - Push element into dynamic array like stack manner, place at first empty position |
|
* |
* @arr = Array |
* @arr = Array |
* @data = Element, if set NULL return only first empty position |
* @data = Element, if set NULL return only first empty position |
* 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 |
Line 308 io_arrayPush(array_t * __restrict arr, void **data)
|
Line 340 io_arrayPush(array_t * __restrict arr, void **data)
|
register int i; |
register int i; |
int ret = -1; |
int ret = -1; |
|
|
assert(arr); | if (!arr) |
| return -1; |
|
|
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]) { |
Line 323 io_arrayPush(array_t * __restrict arr, void **data)
|
Line 356 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 |
*/ |
*/ |
Line 334 io_arrayPop(array_t * __restrict arr, void ** __restri
|
Line 368 io_arrayPop(array_t * __restrict arr, void ** __restri
|
register int i; |
register int i; |
int ret = -1; |
int ret = -1; |
|
|
assert(arr); | if (!arr) |
| return -1; |
|
|
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]) { |
Line 351 io_arrayPop(array_t * __restrict arr, void ** __restri
|
Line 386 io_arrayPop(array_t * __restrict arr, void ** __restri
|
|
|
/* |
/* |
* io_arrayConcat() Concat source array to destination array |
* io_arrayConcat() Concat source array to destination array |
|
* |
* @dest = Destination array |
* @dest = Destination array |
* @src = Source array |
* @src = Source array |
* return: -1 error; >0 new count of destination array |
* return: -1 error; >0 new count of destination array |
Line 366 io_arrayConcat(array_t * __restrict dest, array_t * __
|
Line 402 io_arrayConcat(array_t * __restrict dest, array_t * __
|
return -1; |
return -1; |
|
|
n = io_arraySize(dest); |
n = io_arraySize(dest); |
if (io_arrayGrow(dest, n + io_arraySize(src))) | if (io_arrayGrow(dest, n + io_arraySize(src), 0)) |
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*)); |
|
|
Line 374 io_arrayConcat(array_t * __restrict dest, array_t * __
|
Line 410 io_arrayConcat(array_t * __restrict dest, array_t * __
|
} |
} |
|
|
/* |
/* |
|
* io_arrayCopy() Copy source array to destination array |
|
* |
|
* @dest = Destination array, after use free with io_arrayDestroy() |
|
* @src = Source array |
|
* return: -1 error; >0 count of destination array |
|
*/ |
|
int |
|
io_arrayCopy(array_t ** __restrict dest, array_t * __restrict src) |
|
{ |
|
assert(dest); |
|
assert(src); |
|
if (!dest || !src) |
|
return -1; |
|
|
|
*dest = io_arrayInit(io_arraySize(src)); |
|
if (!*dest) |
|
return -1; |
|
|
|
memcpy((*dest)->arr_data, src->arr_data, io_arraySize(*dest) * sizeof(void*)); |
|
return io_arraySize(*dest); |
|
} |
|
|
|
/* |
* io_argsNum() Parse and calculate number of arguments |
* io_argsNum() Parse and calculate number of arguments |
|
* |
* @csArgs = Input arguments line |
* @csArgs = Input arguments line |
* @csDelim = Delimiter(s) for separate |
* @csDelim = Delimiter(s) for separate |
* return: 0 error format; -1 error:: can`t read; >0 ok, number of items |
* return: 0 error format; -1 error:: can`t read; >0 ok, number of items |
Line 397 io_argsNum(const char *csArgs, const char *csDelim)
|
Line 457 io_argsNum(const char *csArgs, const char *csDelim)
|
/* |
/* |
* io_arrayMake() Parse and make array from arguments ... (input string will be modified!!! |
* io_arrayMake() Parse and make array from arguments ... (input string will be modified!!! |
* and output array must be free with io_arrayDestroy() after use!) |
* and output array must be free with io_arrayDestroy() after use!) |
|
* |
* @psArgs = Input arguments line, after execute string is modified!!! |
* @psArgs = Input arguments line, after execute string is modified!!! |
* @nargs = Maximum requested count of arguments from input string psArgs, if 0 all psArgs |
* @nargs = Maximum requested count of arguments from input string psArgs, if 0 all psArgs |
* @csDelim = Delimiter(s) for separate |
* @csDelim = Delimiter(s) for separate |
Line 432 io_arrayMake(char * __restrict psArgs, int nargs, cons
|
Line 493 io_arrayMake(char * __restrict psArgs, int nargs, cons
|
|
|
/* |
/* |
* io_MakeAV() Parse and make attribute/value pair |
* io_MakeAV() Parse and make attribute/value pair |
|
* |
* @csArgs = Input argument line |
* @csArgs = Input argument line |
* @csDelim = Delimiter for separate |
* @csDelim = Delimiter for separate |
* @psAttr = Output Attribute |
* @psAttr = Output Attribute |