BOOTSTRAP (kexpr) functions
LIBRARY ROUTINE
kexpr_eval - evaluate an expression
LIBRARY CALL
KexprResult *kexpr_eval(
long id,
char *string,
KexprResult *result,
char *error)
INPUT
- id - the variable identifier. This specifies the
variable context to use. Use KEXPR_GLOBAL_ID
to use the global variable context.
- string - the string to be evaluated.
OUTPUT
- result - holds the result of the evaluation. If this
argument is NULL, a new KexprResult structure will
be allocated.
The result can be one of two types, KSTRING
or KDOUBLE. The result type is stored in
result->type. The result value is stored in
the string_value or double_value members of result.
Use the function kexpr_delete_result
to free a KexprResult structure. If the result is
a string, this function will allocate or
re-allocate space in the
KexprResult structure to hold it, if necessary.
- error - If an error occurs the error message is stored in
the error string and FALSE is returned. The
error string must be an array of at least
1024 characters. It is allocated by the calling
routine. If
the error string has not been allocated by the
calling routine (error is passed in as NULL) then the
error message is output with the kerror facility.
RETURN VALUE
TRUE (1) on success, FALSE (0) otherwise
DESCRIPTION
This routine evaluates an input expression and
stores the resulting value in a KexprResult structure.
Currently, the result can be one of two types, KSTRING
or KDOUBLE. The result type is stored in result->type.
The result value is stored in result->string_value
or result->double_value.
ADDITIONAL INFORMATION
none
EXAMPLES
res = kexpr_eval(KEXPR_GLOBAL_ID, "x = 25", NULL, NULL);
res = kexpr_eval(KEXPR_GLOBAL_ID, "ln(x)", res, myerror);
SIDE EFFECTS
Variable values may be changed by assignment statements.
RESTRICTIONS
none
MODIFICATION
none
FILES
$BOOTSTRAP/objects/library/kexpr/src/routines.c
SEE ALSO
kexpr(3)
COPYRIGHT
Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.