--- libaitio/src/Attic/vars.c 2012/05/18 12:43:06 1.7.2.2 +++ libaitio/src/Attic/vars.c 2012/05/19 00:11:58 1.9 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: vars.c,v 1.7.2.2 2012/05/18 12:43:06 misho Exp $ +* $Id: vars.c,v 1.9 2012/05/19 00:11:58 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -499,24 +499,32 @@ io_allocVars(int varnum) * return: NULL error or !=NULL ait_val_t element */ inline ait_val_t * -io_getVars(array_t * __restrict vars, int n) +io_getVars(array_t ** __restrict vars, int n) { + register int i; ait_val_t *v; - if (!vars) { - if (!(vars = io_arrayInit(n + 1))) + if (!vars) + return NULL; + + if (!*vars) { + if (!(*vars = io_allocVars(n + 1))) return NULL; } else { - if (n >= io_arraySize(vars) && io_arrayGrow(vars, n + 1, 0)) - return NULL; + if (n >= (i = io_arraySize(*vars))) { + if (io_arrayGrow(*vars, n + 1, 0)) + return NULL; + for (; i < io_arraySize(*vars); i++) + if (!io_arrayGet(*vars, i)) { + if (!(v = io_allocVar())) + return NULL; + else + io_arraySet(*vars, n, v); + } + } } - if ((v = io_allocVar())) - return NULL; - else - io_arraySet(vars, n, v); - - return v; + return io_array(*vars, n, ait_val_t*); } /*