Commit c78f0825 authored by Morten Welinder's avatar Morten Welinder

Introducing boolean value type -- currently simply an int.

parent c94ae897
Sun Jun 13 14:16:16 1999 Morten Welinder <welinder@rentec.com>
* src/fn-information.c (gnumeric_isblank): Return boolean.
(gnumeric_iseven): Ditto.
(gnumeric_islogical): Ditto.
(gnumeric_isnontext): Ditto.
(gnumeric_isnumber): Ditto.
(gnumeric_isodd): Ditto.
(gnumeric_isref): Ditto.
(gnumeric_istext): Ditto.
(gnumeric_n): Ditto.
1999-06-13 Morten Welinder <terra@diku.dk>
* src/expr.c (value_new_bool): New function.
(eval_expr): Return boolean Values.
* src/fn-logical.c (callback_function_and): Simplify.
(callback_function_or): Ditto.
(gnumeric_and): Simplify and return boolean Values.
(gnumeric_not): Ditto.
(gnumeric_if): Fix error case. Simplify.
* src/cell.c (cell_comment_destroy): Free realized_list.
* fn-*.c: Use new standard error variables.
......
Sun Jun 13 14:16:16 1999 Morten Welinder <welinder@rentec.com>
* src/fn-information.c (gnumeric_isblank): Return boolean.
(gnumeric_iseven): Ditto.
(gnumeric_islogical): Ditto.
(gnumeric_isnontext): Ditto.
(gnumeric_isnumber): Ditto.
(gnumeric_isodd): Ditto.
(gnumeric_isref): Ditto.
(gnumeric_istext): Ditto.
(gnumeric_n): Ditto.
1999-06-13 Morten Welinder <terra@diku.dk>
* src/expr.c (value_new_bool): New function.
(eval_expr): Return boolean Values.
* src/fn-logical.c (callback_function_and): Simplify.
(callback_function_or): Ditto.
(gnumeric_and): Simplify and return boolean Values.
(gnumeric_not): Ditto.
(gnumeric_if): Fix error case. Simplify.
* src/cell.c (cell_comment_destroy): Free realized_list.
* fn-*.c: Use new standard error variables.
......
Sun Jun 13 14:16:16 1999 Morten Welinder <welinder@rentec.com>
* src/fn-information.c (gnumeric_isblank): Return boolean.
(gnumeric_iseven): Ditto.
(gnumeric_islogical): Ditto.
(gnumeric_isnontext): Ditto.
(gnumeric_isnumber): Ditto.
(gnumeric_isodd): Ditto.
(gnumeric_isref): Ditto.
(gnumeric_istext): Ditto.
(gnumeric_n): Ditto.
1999-06-13 Morten Welinder <terra@diku.dk>
* src/expr.c (value_new_bool): New function.
(eval_expr): Return boolean Values.
* src/fn-logical.c (callback_function_and): Simplify.
(callback_function_or): Ditto.
(gnumeric_and): Simplify and return boolean Values.
(gnumeric_not): Ditto.
(gnumeric_if): Fix error case. Simplify.
* src/cell.c (cell_comment_destroy): Free realized_list.
* fn-*.c: Use new standard error variables.
......
Sun Jun 13 14:16:16 1999 Morten Welinder <welinder@rentec.com>
* src/fn-information.c (gnumeric_isblank): Return boolean.
(gnumeric_iseven): Ditto.
(gnumeric_islogical): Ditto.
(gnumeric_isnontext): Ditto.
(gnumeric_isnumber): Ditto.
(gnumeric_isodd): Ditto.
(gnumeric_isref): Ditto.
(gnumeric_istext): Ditto.
(gnumeric_n): Ditto.
1999-06-13 Morten Welinder <terra@diku.dk>
* src/expr.c (value_new_bool): New function.
(eval_expr): Return boolean Values.
* src/fn-logical.c (callback_function_and): Simplify.
(callback_function_or): Ditto.
(gnumeric_and): Simplify and return boolean Values.
(gnumeric_not): Ditto.
(gnumeric_if): Fix error case. Simplify.
* src/cell.c (cell_comment_destroy): Free realized_list.
* fn-*.c: Use new standard error variables.
......
......@@ -220,7 +220,7 @@ gnumeric_isblank (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -242,7 +242,7 @@ gnumeric_iseven (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -264,7 +264,7 @@ gnumeric_islogical (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -286,7 +286,7 @@ gnumeric_isnontext (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -306,7 +306,7 @@ gnumeric_isnumber (struct FunctionDefinition *n,
{
/* FIXME FIXME FIXME */
/* Do I need to run strtod on a string too ?? */
return value_new_int (VALUE_IS_NUMBER (argv [0]));
return value_new_bool (VALUE_IS_NUMBER (argv [0]));
}
......@@ -328,7 +328,7 @@ gnumeric_isodd (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -350,7 +350,7 @@ gnumeric_isref (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -372,7 +372,7 @@ gnumeric_istext (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -394,7 +394,7 @@ gnumeric_n (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......
......@@ -24,7 +24,7 @@ static char *help_and = {
"b1, trough bN are expressions that should evaluate to TRUE or FALSE. "
"If an integer or floating point value is provided zero is considered "
"FALSE and anything else is TRUE.\n"
"If the values contain strings or empty cells those values are "
"ignored. If no logical values are provided, then the error '#VALUE!' "
"is returned. "
......@@ -36,51 +36,35 @@ static int
callback_function_and (Sheet *sheet, Value *value,
char **error_string, void *closure)
{
Value *result = closure;
switch (value->type){
case VALUE_INTEGER:
if (value->v.v_int == 0){
result->v.v_int = 0;
return FALSE;
} else
result->v.v_int = 1;
break;
case VALUE_FLOAT:
if (value->v.v_float == 0.0){
result->v.v_int = 0;
return FALSE;
} else
result->v.v_int = 1;
default:
/* ignore strings */
break;
int *result = closure;
int err;
if (!value_get_as_bool (value, &err) && !err) {
*result = 0;
return FALSE;
}
*result = 1;
return TRUE;
}
static Value *
gnumeric_and (Sheet *sheet, GList *expr_node_list,
int eval_col, int eval_row, char **error_string)
{
Value *result;
result = value_new_int (-1);
int result = -1;
function_iterate_argument_values (sheet, callback_function_and,
result, expr_node_list,
&result, expr_node_list,
eval_col, eval_row, error_string);
/* See if there was any value worth using */
if (result->v.v_int == -1){
value_release (result);
if (result == -1){
*error_string = gnumeric_err_VALUE;
return NULL;
}
return result;
return value_new_bool (result);
}
......@@ -99,11 +83,8 @@ static Value *
gnumeric_not (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
int b;
b = value_get_as_int (argv [0]);
return value_new_int (!b);
/* FIXME: We should probably use value_get_as_bool. */
return value_new_bool (!value_get_as_int (argv [0]));
}
static char *help_or = {
......@@ -127,29 +108,15 @@ static int
callback_function_or (Sheet *sheet, Value *value,
char **error_string, void *closure)
{
Value *result = closure;
switch (value->type){
case VALUE_INTEGER:
if (value->v.v_int != 0){
result->v.v_int = 1;
return FALSE;
} else
result->v.v_int = 0;
break;
case VALUE_FLOAT:
if (value->v.v_float != 0.0){
result->v.v_int = 1;
return FALSE;
} else
result->v.v_int = 0;
default:
/* ignore strings */
break;
int *result = closure;
int err;
if (value_get_as_bool (value, &err) && !err) {
*result = 1;
return FALSE;
}
*result = 0;
return TRUE;
}
......@@ -157,21 +124,18 @@ static Value *
gnumeric_or (Sheet *sheet, GList *expr_node_list,
int eval_col, int eval_row, char **error_string)
{
Value *result;
result = value_new_int (-1);
int result = -1;
function_iterate_argument_values (sheet, callback_function_or,
result, expr_node_list,
&result, expr_node_list,
eval_col, eval_row, error_string);
/* See if there was any value worth using */
if (result->v.v_int == -1){
value_release (result);
if (result == -1){
*error_string = gnumeric_err_VALUE;
return NULL;
}
return result;
return value_new_bool (result);
}
static char *help_if = {
......@@ -195,7 +159,7 @@ gnumeric_if (Sheet *sheet, GList *expr_node_list,
ExprTree *expr;
Value *value;
int err, ret, args;
/* Type checking */
args = g_list_length (expr_node_list);
if (args < 1 || args > 3){
......@@ -212,20 +176,23 @@ gnumeric_if (Sheet *sheet, GList *expr_node_list,
/* Choose which expression we will evaluate */
ret = value_get_as_bool (value, &err);
value_release (value);
if (err)
if (err) {
/* FIXME: please verify error code. */
*error_string = gnumeric_err_VALUE;
return NULL;
}
if (ret){
if (expr_node_list->next)
expr = (ExprTree *) expr_node_list->next->data;
else
return value_new_int (1);
return value_new_bool (TRUE);
} else {
if (expr_node_list->next &&
if (expr_node_list->next &&
expr_node_list->next->next)
expr = (ExprTree *) expr_node_list->next->next->data;
else
return value_new_int (0);
return value_new_bool (FALSE);
}
/* Return the result */
......
......@@ -302,6 +302,14 @@ value_new_int (int i)
return v;
}
Value *
value_new_bool (gboolean b)
{
/* Currently our booleans are really just ints. This will have to
change if we want Excel's ISLOGICAL. */
return value_new_int (b ? 1 : 0);
}
Value *
value_new_string (const char *str)
{
......@@ -999,27 +1007,27 @@ eval_expr (Sheet *sheet, ExprTree *tree, int eval_col, int eval_row, char **erro
switch (tree->oper){
case OPER_EQUAL:
res = value_new_int (comp == IS_EQUAL);
res = value_new_bool (comp == IS_EQUAL);
break;
case OPER_GT:
res = value_new_int (comp == IS_GREATER);
res = value_new_bool (comp == IS_GREATER);
break;
case OPER_LT:
res = value_new_int (comp == IS_LESS);
res = value_new_bool (comp == IS_LESS);
break;
case OPER_LTE:
res = value_new_int (comp == IS_EQUAL || comp == IS_LESS);
res = value_new_bool (comp == IS_EQUAL || comp == IS_LESS);
break;
case OPER_GTE:
res = value_new_int (comp == IS_EQUAL || comp == IS_GREATER);
res = value_new_bool (comp == IS_EQUAL || comp == IS_GREATER);
break;
case OPER_NOT_EQUAL:
res = value_new_int (comp != IS_EQUAL);
res = value_new_bool (comp != IS_EQUAL);
break;
default:
......
......@@ -191,6 +191,7 @@ Value *eval_expr (Sheet *sheet, ExprTree *tree,
extern Value *value_zero;
Value *value_new_float (float_t f);
Value *value_new_int (int i);
Value *value_new_bool (gboolean b);
Value *value_new_string (const char *str);
Value *value_new_cellrange (const CellRef *a, const CellRef *b);
......
......@@ -220,7 +220,7 @@ gnumeric_isblank (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -242,7 +242,7 @@ gnumeric_iseven (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -264,7 +264,7 @@ gnumeric_islogical (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -286,7 +286,7 @@ gnumeric_isnontext (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -306,7 +306,7 @@ gnumeric_isnumber (struct FunctionDefinition *n,
{
/* FIXME FIXME FIXME */
/* Do I need to run strtod on a string too ?? */
return value_new_int (VALUE_IS_NUMBER (argv [0]));
return value_new_bool (VALUE_IS_NUMBER (argv [0]));
}
......@@ -328,7 +328,7 @@ gnumeric_isodd (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -350,7 +350,7 @@ gnumeric_isref (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -372,7 +372,7 @@ gnumeric_istext (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -394,7 +394,7 @@ gnumeric_n (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......
......@@ -24,7 +24,7 @@ static char *help_and = {
"b1, trough bN are expressions that should evaluate to TRUE or FALSE. "
"If an integer or floating point value is provided zero is considered "
"FALSE and anything else is TRUE.\n"
"If the values contain strings or empty cells those values are "
"ignored. If no logical values are provided, then the error '#VALUE!' "
"is returned. "
......@@ -36,51 +36,35 @@ static int
callback_function_and (Sheet *sheet, Value *value,
char **error_string, void *closure)
{
Value *result = closure;
switch (value->type){
case VALUE_INTEGER:
if (value->v.v_int == 0){
result->v.v_int = 0;
return FALSE;
} else
result->v.v_int = 1;
break;
case VALUE_FLOAT:
if (value->v.v_float == 0.0){
result->v.v_int = 0;
return FALSE;
} else
result->v.v_int = 1;
default:
/* ignore strings */
break;
int *result = closure;
int err;
if (!value_get_as_bool (value, &err) && !err) {
*result = 0;
return FALSE;
}
*result = 1;
return TRUE;
}
static Value *
gnumeric_and (Sheet *sheet, GList *expr_node_list,
int eval_col, int eval_row, char **error_string)
{
Value *result;
result = value_new_int (-1);
int result = -1;
function_iterate_argument_values (sheet, callback_function_and,
result, expr_node_list,
&result, expr_node_list,
eval_col, eval_row, error_string);
/* See if there was any value worth using */
if (result->v.v_int == -1){
value_release (result);
if (result == -1){
*error_string = gnumeric_err_VALUE;
return NULL;
}
return result;
return value_new_bool (result);
}
......@@ -99,11 +83,8 @@ static Value *
gnumeric_not (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
int b;
b = value_get_as_int (argv [0]);
return value_new_int (!b);
/* FIXME: We should probably use value_get_as_bool. */
return value_new_bool (!value_get_as_int (argv [0]));
}
static char *help_or = {
......@@ -127,29 +108,15 @@ static int
callback_function_or (Sheet *sheet, Value *value,
char **error_string, void *closure)
{
Value *result = closure;
switch (value->type){
case VALUE_INTEGER:
if (value->v.v_int != 0){
result->v.v_int = 1;
return FALSE;
} else
result->v.v_int = 0;
break;
case VALUE_FLOAT:
if (value->v.v_float != 0.0){
result->v.v_int = 1;
return FALSE;
} else
result->v.v_int = 0;
default:
/* ignore strings */
break;
int *result = closure;
int err;
if (value_get_as_bool (value, &err) && !err) {
*result = 1;
return FALSE;
}
*result = 0;
return TRUE;
}
......@@ -157,21 +124,18 @@ static Value *
gnumeric_or (Sheet *sheet, GList *expr_node_list,
int eval_col, int eval_row, char **error_string)
{
Value *result;
result = value_new_int (-1);
int result = -1;
function_iterate_argument_values (sheet, callback_function_or,
result, expr_node_list,
&result, expr_node_list,
eval_col, eval_row, error_string);
/* See if there was any value worth using */
if (result->v.v_int == -1){
value_release (result);
if (result == -1){
*error_string = gnumeric_err_VALUE;
return NULL;
}
return result;
return value_new_bool (result);
}
static char *help_if = {
......@@ -195,7 +159,7 @@ gnumeric_if (Sheet *sheet, GList *expr_node_list,
ExprTree *expr;
Value *value;
int err, ret, args;
/* Type checking */
args = g_list_length (expr_node_list);
if (args < 1 || args > 3){
......@@ -212,20 +176,23 @@ gnumeric_if (Sheet *sheet, GList *expr_node_list,
/* Choose which expression we will evaluate */
ret = value_get_as_bool (value, &err);
value_release (value);
if (err)
if (err) {
/* FIXME: please verify error code. */
*error_string = gnumeric_err_VALUE;
return NULL;
}
if (ret){
if (expr_node_list->next)
expr = (ExprTree *) expr_node_list->next->data;
else
return value_new_int (1);
return value_new_bool (TRUE);
} else {
if (expr_node_list->next &&
if (expr_node_list->next &&
expr_node_list->next->next)
expr = (ExprTree *) expr_node_list->next->next->data;
else
return value_new_int (0);
return value_new_bool (FALSE);
}
/* Return the result */
......
......@@ -220,7 +220,7 @@ gnumeric_isblank (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -242,7 +242,7 @@ gnumeric_iseven (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -264,7 +264,7 @@ gnumeric_islogical (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -286,7 +286,7 @@ gnumeric_isnontext (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -306,7 +306,7 @@ gnumeric_isnumber (struct FunctionDefinition *n,
{
/* FIXME FIXME FIXME */
/* Do I need to run strtod on a string too ?? */
return value_new_int (VALUE_IS_NUMBER (argv [0]));
return value_new_bool (VALUE_IS_NUMBER (argv [0]));
}
......@@ -328,7 +328,7 @@ gnumeric_isodd (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -350,7 +350,7 @@ gnumeric_isref (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -372,7 +372,7 @@ gnumeric_istext (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);
}
......@@ -394,7 +394,7 @@ gnumeric_n (struct FunctionDefinition *n,
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
return value_new_bool (result);