--- libaitio/src/Attic/array.c 2012/05/23 11:49:35 1.9.6.1 +++ libaitio/src/Attic/array.c 2012/07/30 10:55:51 1.10.6.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: array.c,v 1.9.6.1 2012/05/23 11:49:35 misho Exp $ +* $Id: array.c,v 1.10.6.2 2012/07/30 10:55:51 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -57,7 +57,7 @@ io_arrayInit(int numItems) { array_t *arr = NULL; - arr = xmalloc(sizeof(array_t)); + arr = io_malloc(sizeof(array_t)); if (!arr) { LOGERR; return NULL; @@ -65,10 +65,10 @@ io_arrayInit(int numItems) arr->arr_last = -1; arr->arr_num = numItems; - arr->arr_data = xcalloc(io_arraySize(arr), sizeof(void*)); + arr->arr_data = io_calloc(io_arraySize(arr), sizeof(void*)); if (!arr->arr_data) { LOGERR; - xfree(arr); + io_free(arr); return NULL; } else io_arrayZero(arr); @@ -99,17 +99,17 @@ io_arrayFrom(const char *** __restrict pargv, int argc else for (a = *pargv; *a; a++, num++); - arr = xmalloc(sizeof(array_t)); + arr = io_malloc(sizeof(array_t)); if (!arr) { LOGERR; return NULL; } arr->arr_num = num; - arr->arr_data = xcalloc(io_arraySize(arr), sizeof(void*)); + arr->arr_data = io_calloc(io_arraySize(arr), sizeof(void*)); if (!arr->arr_data) { LOGERR; - xfree(arr); + io_free(arr); return NULL; } else { memcpy(arr->arr_data, *pargv, io_arraySize(arr) * sizeof(void*)); @@ -134,7 +134,7 @@ io_arrayTo(array_t * __restrict arr) if (!arr || !io_arraySize(arr)) return NULL; - args = (char **) xcalloc(io_arraySize(arr) + 1, sizeof(char*)); + args = (char **) io_calloc(io_arraySize(arr) + 1, sizeof(char*)); if (!args) { LOGERR; return NULL; @@ -162,7 +162,7 @@ io_arrayFree(array_t * __restrict arr) for (i = 0; i < io_arraySize(arr); i++) if (arr->arr_data[i]) { - xfree(arr->arr_data[i]); + io_free(arr->arr_data[i]); arr->arr_data[i] = NULL; } @@ -182,8 +182,8 @@ io_arrayDestroy(array_t ** __restrict parr) return; if ((*parr)->arr_data) - xfree((*parr)->arr_data); - xfree(*parr); + io_free((*parr)->arr_data); + io_free(*parr); *parr = NULL; } @@ -232,11 +232,11 @@ io_arrayGrow(array_t * __restrict arr, int newNumItems } else if (freeShrink) for (i = newNumItems; i < arr->arr_num; i++) if (arr->arr_data[i]) - xfree(arr->arr_data[i]); + io_free(arr->arr_data[i]); arr->arr_num = newNumItems; if (io_arraySize(arr)) { - data = xrealloc(arr->arr_data, io_arraySize(arr) * sizeof(void*)); + data = io_realloc(arr->arr_data, io_arraySize(arr) * sizeof(void*)); if (!data) { LOGERR; return -1; @@ -247,7 +247,7 @@ io_arrayGrow(array_t * __restrict arr, int newNumItems arr->arr_last = io_arrayLen(arr); } else { if (arr->arr_data) - xfree(arr->arr_data); + io_free(arr->arr_data); arr->arr_data = NULL; arr->arr_last = -1; } @@ -549,7 +549,7 @@ io_MakeAV(const char * __restrict csArgs, const char * return -1; else memset(psValue, 0, valLen); - psBuf = xstrdup(csArgs); + psBuf = io_strdup(csArgs); if (!psBuf) { LOGERR; return -1; @@ -567,7 +567,43 @@ io_MakeAV(const char * __restrict csArgs, const char * strlcpy(psValue, pos, valLen); } - xfree(psBuf); + io_free(psBuf); return ret; } +/* + * io_MakeAV2() Parse and make attribute/value pair over input string + * + * @csArgs = Input argument line, will be modified! + * @csDelim = Delimiter for separate + * @psAttr = Output Attribute + * @psValue = Output Value, if ==NULL this element not present value or not wanted for return + * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items +*/ +int +io_MakeAV2(char * __restrict psArgs, const char *csDelim, + char * __restrict psAttr, char * __restrict psValue) +{ + register int ret = 0; + char *pos; + + if (!psArgs || !csDelim) + return -1; + + pos = strpbrk(psArgs, csDelim); + if (pos) + *pos++ = 0; + ret++; + if (psAttr) + psAttr = psArgs; + + if (psValue) { + if (pos && *pos) { + ret++; + psValue = pos; + } else + psValue = NULL; + } + + return ret; +}