Commit f29179e1 authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa

Do not render the value if the result is an error.

1999-02-19  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/clipboard.c (paste_cell): Do not render the value if the
	result is an error.

	* src/cell.c (cell_copy): Do not copy the value of a cell when the
	value is NULL (due to the cell having an error).

	* src/expr.c (eval_expr): Evaluate binary operations in parts to
	keep the correct error message on an operation if possible.
	(eval_expr): Propagate errors.

	* src/item-edit.c (item_edit_draw): Sync the before-cursor and
	after-cursor Y-display text cordinate.

	* src/expr.c (eval_funcall): Add type checking for the simple
	functions.

	* doc/C/Makefile.am (install-data-local): use topsrcdir here (fix
	from Ian Campbell <ijc25@cam.ac.uk>

	* src/fn-math.c (gnumeric_not): Implement NOT.
parent e1ca7a3c
1999-02-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/clipboard.c (paste_cell): Do not render the value if the
result is an error.
* src/cell.c (cell_copy): Do not copy the value of a cell when the
value is NULL (due to the cell having an error).
* src/expr.c (eval_expr): Evaluate binary operations in parts to
keep the correct error message on an operation if possible.
(eval_expr): Propagate errors.
* src/item-edit.c (item_edit_draw): Sync the before-cursor and
after-cursor Y-display text cordinate.
* src/expr.c (eval_funcall): Add type checking for the simple
functions.
* doc/C/Makefile.am (install-data-local): use topsrcdir here (fix
from Ian Campbell <ijc25@cam.ac.uk>
* src/fn-math.c (gnumeric_not): Implement NOT.
* src/number-match.c (format_create_regexp): Allow upper case
format codes.
......
1999-02-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/clipboard.c (paste_cell): Do not render the value if the
result is an error.
* src/cell.c (cell_copy): Do not copy the value of a cell when the
value is NULL (due to the cell having an error).
* src/expr.c (eval_expr): Evaluate binary operations in parts to
keep the correct error message on an operation if possible.
(eval_expr): Propagate errors.
* src/item-edit.c (item_edit_draw): Sync the before-cursor and
after-cursor Y-display text cordinate.
* src/expr.c (eval_funcall): Add type checking for the simple
functions.
* doc/C/Makefile.am (install-data-local): use topsrcdir here (fix
from Ian Campbell <ijc25@cam.ac.uk>
* src/fn-math.c (gnumeric_not): Implement NOT.
* src/number-match.c (format_create_regexp): Allow upper case
format codes.
......
1999-02-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/clipboard.c (paste_cell): Do not render the value if the
result is an error.
* src/cell.c (cell_copy): Do not copy the value of a cell when the
value is NULL (due to the cell having an error).
* src/expr.c (eval_expr): Evaluate binary operations in parts to
keep the correct error message on an operation if possible.
(eval_expr): Propagate errors.
* src/item-edit.c (item_edit_draw): Sync the before-cursor and
after-cursor Y-display text cordinate.
* src/expr.c (eval_funcall): Add type checking for the simple
functions.
* doc/C/Makefile.am (install-data-local): use topsrcdir here (fix
from Ian Campbell <ijc25@cam.ac.uk>
* src/fn-math.c (gnumeric_not): Implement NOT.
* src/number-match.c (format_create_regexp): Allow upper case
format codes.
......
1999-02-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/clipboard.c (paste_cell): Do not render the value if the
result is an error.
* src/cell.c (cell_copy): Do not copy the value of a cell when the
value is NULL (due to the cell having an error).
* src/expr.c (eval_expr): Evaluate binary operations in parts to
keep the correct error message on an operation if possible.
(eval_expr): Propagate errors.
* src/item-edit.c (item_edit_draw): Sync the before-cursor and
after-cursor Y-display text cordinate.
* src/expr.c (eval_funcall): Add type checking for the simple
functions.
* doc/C/Makefile.am (install-data-local): use topsrcdir here (fix
from Ian Campbell <ijc25@cam.ac.uk>
* src/fn-math.c (gnumeric_not): Implement NOT.
* src/number-match.c (format_create_regexp): Allow upper case
format codes.
......
......@@ -66,7 +66,7 @@ dist-hook:
-cp images/*.gif images/*.jpg $(distdir)/images
install-data-local: gnumeric.html
$(srcdir)/../mkinstalldirs $(gnumeric_helpdir)/images
$(topsrcdir)/mkinstalldirs $(gnumeric_helpdir)/images
-for file in $(srcdir)/gnumeric/*.html $(srcdir)/gnumeric/*.css; do \
basefile=`basename $$file`; \
$(INSTALL_DATA) $(srcdir)/$$file $(gnumeric_helpdir)/$$basefile; \
......
......@@ -137,7 +137,7 @@ static char *help_and = {
"ignored. If no logical values are provided, then the error '#VALUE!' "
"is returned. "
"\n"
"@SEEALSO=OR")
"@SEEALSO=OR, NOT")
};
static int
......@@ -854,6 +854,27 @@ gnumeric_max (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, c
return closure.result;
}
static char *help_not = {
N_("@FUNCTION=NOT\n"
"@SYNTAX=NOT(number)\n"
"@DESCRIPTION="
"Implements the logical NOT function: the result is TRUE if the "
"number is zero; othewise the result is FALSE.\n\n"
"@SEEALSO=AND, OR")
};
static Value *
gnumeric_not (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
int b;
b = value_get_as_int (argv [0]);
return value_int (!b);
}
static char *help_or = {
N_("@FUNCTION=OR\n"
"@SYNTAX=OR(b1, b2, ...)\n"
......@@ -868,7 +889,7 @@ static char *help_or = {
"ignored. If no logical values are provided, then the error '#VALUE!'"
"is returned.\n"
"@SEEALSO=AND")
"@SEEALSO=AND, NOT")
};
static int
......@@ -1194,6 +1215,7 @@ FunctionDefinition math_functions [] = {
{ "log10", "f", "number", &help_log10, NULL, gnumeric_log10 },
{ "min", 0, "", &help_min, gnumeric_min, NULL },
{ "max", 0, "", &help_max, gnumeric_max, NULL },
{ "not", "f", "number", &help_not, NULL, gnumeric_not },
{ "or", 0, "", &help_or, gnumeric_or, NULL },
{ "radians", "f", "number", &help_radians, NULL, gnumeric_radians },
{ "sin", "f", "number", &help_sin, NULL, gnumeric_sin },
......
......@@ -713,7 +713,13 @@ cell_copy (Cell *cell)
string_ref (new_cell->text);
new_cell->style = style_duplicate (new_cell->style);
new_cell->value = value_duplicate (new_cell->value);
/*
* The cell->value can be NULL if the cell contains
* an error
*/
if (new_cell->value)
new_cell->value = value_duplicate (new_cell->value);
new_cell->comment = NULL;
if (cell->comment)
......
......@@ -61,7 +61,8 @@ paste_cell (Sheet *dest_sheet, Cell *new_cell, int target_col, int target_row, i
cell_make_value (new_cell);
}
cell_render_value (new_cell);
if (new_cell->value)
cell_render_value (new_cell);
sheet_redraw_cell_region (dest_sheet,
target_col, target_row,
......
......@@ -448,6 +448,16 @@ eval_cell_value (Sheet *sheet, Value *value)
return res;
}
static void
free_values (Value **values, int top)
{
int i;
for (i = 0; i < top; i++)
value_release (values [i]);
g_free (values);
}
static Value *
eval_funcall (Sheet *sheet, ExprTree *tree, int eval_col, int eval_row, char **error_string)
{
......@@ -472,7 +482,7 @@ eval_funcall (Sheet *sheet, ExprTree *tree, int eval_col, int eval_row, char **e
Value **values;
int fn_argc;
char *arg_type = fd->args;
fn_argc = strlen (fd->args);
if (fn_argc != argc){
......@@ -488,6 +498,23 @@ eval_funcall (Sheet *sheet, ExprTree *tree, int eval_col, int eval_row, char **e
v = eval_expr (sheet, t, eval_col, eval_row, error_string);
if (v == NULL)
goto free_list;
switch (*arg_type){
case 'f':
if (v->type == VALUE_INTEGER ||
v->type == VALUE_FLOAT)
break;
free_values (values, arg);
*error_string = _("Type mismatch");
return NULL;
case 's':
if (v->type != VALUE_STRING){
free_values (values, arg);
*error_string = _("Type mismatch");
return NULL;
}
}
values [arg] = v;
}
......@@ -748,17 +775,18 @@ eval_expr (void *asheet, ExprTree *tree, int eval_col, int eval_row, char **erro
case OPER_EXP:
a = eval_expr (sheet, tree->u.binary.value_a,
eval_col, eval_row, error_string);
if (!a)
return NULL;
b = eval_expr (sheet, tree->u.binary.value_b,
eval_col, eval_row, error_string);
if (!(a && b)){
if (a)
value_release (a);
if (b)
value_release (b);
if (!b){
value_release (a);
return NULL;
}
if (!VALUE_IS_NUMBER (a) || !VALUE_IS_NUMBER (b)){
value_release (a);
value_release (b);
......@@ -907,6 +935,10 @@ eval_expr (void *asheet, ExprTree *tree, int eval_col, int eval_row, char **erro
if (cell->value)
return eval_cell_value (sheet, cell->value);
else {
*error_string = cell->text->str;
return NULL;
}
}
res = g_new (Value, 1);
......
......@@ -137,7 +137,7 @@ static char *help_and = {
"ignored. If no logical values are provided, then the error '#VALUE!' "
"is returned. "
"\n"
"@SEEALSO=OR")
"@SEEALSO=OR, NOT")
};
static int
......@@ -854,6 +854,27 @@ gnumeric_max (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, c
return closure.result;
}
static char *help_not = {
N_("@FUNCTION=NOT\n"
"@SYNTAX=NOT(number)\n"
"@DESCRIPTION="
"Implements the logical NOT function: the result is TRUE if the "
"number is zero; othewise the result is FALSE.\n\n"
"@SEEALSO=AND, OR")
};
static Value *
gnumeric_not (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
int b;
b = value_get_as_int (argv [0]);
return value_int (!b);
}
static char *help_or = {
N_("@FUNCTION=OR\n"
"@SYNTAX=OR(b1, b2, ...)\n"
......@@ -868,7 +889,7 @@ static char *help_or = {
"ignored. If no logical values are provided, then the error '#VALUE!'"
"is returned.\n"
"@SEEALSO=AND")
"@SEEALSO=AND, NOT")
};
static int
......@@ -1194,6 +1215,7 @@ FunctionDefinition math_functions [] = {
{ "log10", "f", "number", &help_log10, NULL, gnumeric_log10 },
{ "min", 0, "", &help_min, gnumeric_min, NULL },
{ "max", 0, "", &help_max, gnumeric_max, NULL },
{ "not", "f", "number", &help_not, NULL, gnumeric_not },
{ "or", 0, "", &help_or, gnumeric_or, NULL },
{ "radians", "f", "number", &help_radians, NULL, gnumeric_radians },
{ "sin", "f", "number", &help_sin, NULL, gnumeric_sin },
......
......@@ -137,7 +137,7 @@ static char *help_and = {
"ignored. If no logical values are provided, then the error '#VALUE!' "
"is returned. "
"\n"
"@SEEALSO=OR")
"@SEEALSO=OR, NOT")
};
static int
......@@ -854,6 +854,27 @@ gnumeric_max (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, c
return closure.result;
}
static char *help_not = {
N_("@FUNCTION=NOT\n"
"@SYNTAX=NOT(number)\n"
"@DESCRIPTION="
"Implements the logical NOT function: the result is TRUE if the "
"number is zero; othewise the result is FALSE.\n\n"
"@SEEALSO=AND, OR")
};
static Value *
gnumeric_not (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
int b;
b = value_get_as_int (argv [0]);
return value_int (!b);
}
static char *help_or = {
N_("@FUNCTION=OR\n"
"@SYNTAX=OR(b1, b2, ...)\n"
......@@ -868,7 +889,7 @@ static char *help_or = {
"ignored. If no logical values are provided, then the error '#VALUE!'"
"is returned.\n"
"@SEEALSO=AND")
"@SEEALSO=AND, NOT")
};
static int
......@@ -1194,6 +1215,7 @@ FunctionDefinition math_functions [] = {
{ "log10", "f", "number", &help_log10, NULL, gnumeric_log10 },
{ "min", 0, "", &help_min, gnumeric_min, NULL },
{ "max", 0, "", &help_max, gnumeric_max, NULL },
{ "not", "f", "number", &help_not, NULL, gnumeric_not },
{ "or", 0, "", &help_or, gnumeric_or, NULL },
{ "radians", "f", "number", &help_radians, NULL, gnumeric_radians },
{ "sin", "f", "number", &help_sin, NULL, gnumeric_sin },
......
......@@ -93,7 +93,7 @@ item_edit_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
dy + hd - (font->ascent + font->descent));
gdk_draw_text (drawable, font, canvas->style->black_gc,
dx + first_part_len,
dy + hd - font->descent,
dy + hd - font->descent - 1,
text + cursor_pos, text_len - cursor_pos);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment