version 1.12.4.2, 2012/08/29 13:30:28
|
version 1.13.2.1, 2012/09/03 09:26:34
|
Line 655 io_findKeyVars(array_t * __restrict vars, u_short key)
|
Line 655 io_findKeyVars(array_t * __restrict vars, u_short key)
|
} |
} |
|
|
/* |
/* |
* io_hashVar() - Generate hash key for variable | * io_hashVar() - Generate hash key for variable from string or value |
* |
* |
* @v = variable |
* @v = variable |
|
* @key = key string for hash, if =NULL hash will built from variable |
* return: hash key |
* return: hash key |
*/ |
*/ |
u_short |
u_short |
io_hashVar(ait_val_t * __restrict v) | io_hashVar(ait_val_t * __restrict v, const char * __restrict key) |
{ |
{ |
void *p; |
void *p; |
u_short cksum; |
u_short cksum; |
Line 670 io_hashVar(ait_val_t * __restrict v)
|
Line 671 io_hashVar(ait_val_t * __restrict v)
|
if (!v) |
if (!v) |
return 0; |
return 0; |
|
|
switch (AIT_TYPE(v)) { | if (key) { |
case empty: | p = (void*) key; |
AIT_KEY(v) = 0; | l = (strlen(key) + 1) / 2; |
return 0; | } else { |
case string: | switch (AIT_TYPE(v)) { |
case buffer: | case empty: |
p = AIT_ADDR(v); | AIT_KEY(v) = 0; |
l = AIT_LEN(v) / 2; | return 0; |
break; | case string: |
case data: | case buffer: |
p = v->val_data; | p = AIT_ADDR(v); |
l = AIT_LEN(v) / 2; | l = AIT_LEN(v) / 2; |
break; | break; |
default: | case data: |
p = &AIT_RAW(v); | p = v->val_data; |
l = sizeof AIT_RAW(v) / 2; | l = AIT_LEN(v) / 2; |
break; | break; |
| default: |
| p = &AIT_RAW(v); |
| l = sizeof AIT_RAW(v) / 2; |
| break; |
| } |
} |
} |
|
|
cksum = crcFletcher16((u_short*) p, l); |
cksum = crcFletcher16((u_short*) p, l); |
|
|
if (AIT_BE(v)) |
if (AIT_BE(v)) |
Line 715 io_hashKeyVars(array_t * __restrict vars)
|
Line 722 io_hashKeyVars(array_t * __restrict vars)
|
return -1; |
return -1; |
|
|
for (i = 0; i < io_arraySize(vars); i++) |
for (i = 0; i < io_arraySize(vars); i++) |
io_hashVar(io_array(vars, i, ait_val_t*)); | io_hashVar(io_array(vars, i, ait_val_t*), NULL); |
|
|
return 0; |
return 0; |
} |
} |
Line 739 io_findKeyHash(array_t * __restrict vars, const char *
|
Line 746 io_findKeyHash(array_t * __restrict vars, const char *
|
return io_findKeyVars(vars, k); |
return io_findKeyVars(vars, k); |
} |
} |
|
|
|
/* |
|
* io_sprintfVar() - Builtin string variable from formatted input |
|
* |
|
* @v = variable |
|
* @fmt = format string |
|
* @... = argument(s) |
|
* return: -1 error or >0 copied bytes to variable |
|
*/ |
|
int |
|
io_sprintfVar(ait_val_t * __restrict v, const char *fmt, ...) |
|
{ |
|
int ret = 0; |
|
va_list lst; |
|
char *str = NULL; |
|
|
|
if (!v || !fmt) |
|
return -1; |
|
|
|
va_start(lst, fmt); |
|
ret = vasprintf(&str, fmt, lst); |
|
va_end(lst); |
|
|
|
if (str && ret > -1) { |
|
AIT_FREE_VAL(v); |
|
AIT_SET_STR(v, str); |
|
} else |
|
LOGERR; |
|
|
|
if (str) |
|
free(str); |
|
return ret; |
|
} |