version 1.12.4.2, 2012/08/29 13:30:28
|
version 1.13.2.3, 2012/09/17 13:44:22
|
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; |
|
} |
|
|
|
/* |
|
* io_setlikeVar() - Set variable like ... |
|
* |
|
* @v = variable |
|
* @t = type of data |
|
* @l = length of data |
|
* @... = data |
|
* return: -1 error or 0 ok |
|
*/ |
|
inline int |
|
io_setlikeVar(ait_val_t * __restrict v, ait_type_t t, u_int l, ...) |
|
{ |
|
va_list lst; |
|
|
|
if (!v) |
|
return -1; |
|
|
|
AIT_FREE_VAL(v); |
|
AIT_INIT_VAL2(v, t); |
|
AIT_LEN(v) = l; |
|
AIT_IN(v) = 1; |
|
|
|
va_start(lst, l); |
|
switch (AIT_TYPE(v)) { |
|
case ptr: |
|
case buffer: |
|
case string: |
|
AIT_ADDR(v) = va_arg(lst, void*); |
|
break; |
|
default: |
|
AIT_RAW(v) = va_arg(lst, uint64_t); |
|
break; |
|
} |
|
va_end(lst); |
|
|
|
return 0; |
|
} |
|
|
|
/* |
|
* io_cmpVar() - Compare two variables |
|
* |
|
* @a = 1st variable |
|
* @b = 2nd variable |
|
* return: 0 is equal or !=0 is different |
|
*/ |
|
inline int |
|
io_cmpVar(ait_val_t * __restrict a, ait_val_t * __restrict b) |
|
{ |
|
intptr_t ret; |
|
|
|
if (!(ret = (a - b))) |
|
return ret; |
|
if ((ret = AIT_TYPE(a) - AIT_TYPE(b))) |
|
return ret; |
|
if ((ret = AIT_LEN(a) - AIT_LEN(b))) |
|
return ret; |
|
|
|
switch (AIT_TYPE(a)) { |
|
case buffer: |
|
ret = memcmp(AIT_GET_BUF(a), AIT_GET_BUF(b), AIT_LEN(a)); |
|
break; |
|
case string: |
|
ret = strncmp(AIT_GET_STR(a), AIT_GET_STR(b), AIT_LEN(a)); |
|
break; |
|
case data: |
|
ret = memcmp(AIT_GET_DATA(a), AIT_GET_DATA(b), AIT_LEN(a)); |
|
break; |
|
case ptr: |
|
ret = AIT_ADDR(a) - AIT_ADDR(b); |
|
break; |
|
default: |
|
ret = AIT_RAW(a) - AIT_RAW(b); |
|
break; |
|
} |
|
|
|
return (int) ret; |
|
} |