Commit 27c1c882 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Improvements after VALUE_ERROR.

1999-07-30  Morten Welinder  <terra@diku.dk>

	* src/cell.c (cell_cleanout): New function.
	(cell_set_formula): Don't bother with CELL_ERROR.  Set value field
 	in all cases.
	(cell_set_array_formula): Set cell values.
	(cell_set_value_simple): Simplify using cell_cleanout.
	(cell_set_text_simple): Ditto.
	(cell_set_formula_tree_simple): Ditto.
	(cell_destroy): Ditto.
	(cell_get_text): Simplify.
	(cell_get_content): Ditto.

	* src/eval.c (cell_eval): Reorganise slightly.

	* src/expr.c (eval_expr_real): value should no longer be null.

	* src/cell.h (CELL_ERROR): Obsolete.
parent 2de2515d
1999-07-29 Morten Welinder <terra@diku.dk>
1999-07-30 Morten Welinder <terra@diku.dk>
* src/cell.c (cell_cleanout): New function.
(cell_set_formula): Don't bother with CELL_ERROR. Set value field
in all cases.
(cell_set_array_formula): Set cell values.
(cell_set_value_simple): Simplify using cell_cleanout.
(cell_set_text_simple): Ditto.
(cell_set_formula_tree_simple): Ditto.
(cell_destroy): Ditto.
(cell_get_text): Simplify.
(cell_get_content): Ditto.
* src/eval.c (cell_eval): Reorganise slightly.
* src/expr.c (eval_expr_real): value should no longer be null.
* src/cell.h (CELL_ERROR): Obsolete.
* src/print-info.h (hf_formats): Make extern.
......
1999-07-29 Morten Welinder <terra@diku.dk>
1999-07-30 Morten Welinder <terra@diku.dk>
* src/cell.c (cell_cleanout): New function.
(cell_set_formula): Don't bother with CELL_ERROR. Set value field
in all cases.
(cell_set_array_formula): Set cell values.
(cell_set_value_simple): Simplify using cell_cleanout.
(cell_set_text_simple): Ditto.
(cell_set_formula_tree_simple): Ditto.
(cell_destroy): Ditto.
(cell_get_text): Simplify.
(cell_get_content): Ditto.
* src/eval.c (cell_eval): Reorganise slightly.
* src/expr.c (eval_expr_real): value should no longer be null.
* src/cell.h (CELL_ERROR): Obsolete.
* src/print-info.h (hf_formats): Make extern.
......
......@@ -47,6 +47,28 @@ cell_modified (Cell *cell)
}
/* Empty a cell's value, entered_text, and parsed_node. */
static void
cell_cleanout (Cell *cell)
{
if (cell->parsed_node){
sheet_cell_formula_unlink (cell);
expr_tree_unref (cell->parsed_node);
cell->parsed_node = NULL;
}
if (cell->value) {
value_release (cell->value);
cell->value = NULL;
}
if (cell->entered_text) {
string_unref (cell->entered_text);
cell->entered_text = NULL;
}
}
void
cell_set_formula (Cell *cell, const char *text)
{
......@@ -63,20 +85,16 @@ cell_set_formula (Cell *cell, const char *text)
parse_pos_cell (&pp, cell),
&desired_format,
&error_msg);
cell_cleanout (cell);
if (new_expr == NULL){
cell->parsed_node = NULL;
cell->flags |= CELL_ERROR;
cell_set_rendered_text (cell, error_msg);
if (cell->value)
value_release (cell->value);
cell->value = NULL;
cell->entered_text = string_get (text);
/* FIXME: Supply a proper position? */
cell->value = value_new_error (NULL, error_msg);
return;
}
if (cell->flags & CELL_ERROR)
cell->flags &= ~CELL_ERROR;
if (desired_format &&
strcmp (cell->style->format->format, "General") == 0){
style_format_unref (cell->style->format);
......@@ -105,6 +123,8 @@ cell_set_formula (Cell *cell, const char *text)
new_expr->u.array.corner.func.expr);
} else {
cell->parsed_node = new_expr;
/* Until the value is recomputed, we put in this value. */
cell->value = value_new_error (NULL, _("Circular reference"));
cell_formula_changed (cell);
}
}
......@@ -597,20 +617,7 @@ cell_set_value_simple (Cell *cell, Value *v)
g_return_if_fail (v);
cell_modified (cell);
if (cell->entered_text)
string_unref (cell->entered_text);
cell->entered_text = NULL;
if (cell->value)
value_release (cell->value);
if (cell->parsed_node){
sheet_cell_formula_unlink (cell);
expr_tree_unref (cell->parsed_node);
cell->parsed_node = NULL;
}
cell_cleanout (cell);
cell->value = v;
cell_render_value (cell);
......@@ -655,22 +662,7 @@ cell_set_text_simple (Cell *cell, const char *text)
g_return_if_fail (text != NULL);
cell_modified (cell);
if (cell->entered_text)
string_unref (cell->entered_text);
cell->entered_text = string_get (text);
if (cell->value){
value_release (cell->value);
cell->value = NULL;
}
if (cell->parsed_node){
sheet_cell_formula_unlink (cell);
expr_tree_unref (cell->parsed_node);
cell->parsed_node = NULL;
}
cell_cleanout (cell);
if (text [0] == '=' && text [1] != 0){
cell_set_formula (cell, text);
......@@ -681,16 +673,12 @@ cell_set_text_simple (Cell *cell, const char *text)
l = strtol (text, &end, 10);
if (text != end && (l == (int)l)) {
/* Allow and ignore spaces at the end of integers. */
while (*end == ' ')
end++;
if (*end == 0) {
cell->value = value_new_int (l);
set = 1;
} else { /* chomp whitespace to end on integers */
while (*end == ' ')
end++;
if (*end == 0) {
cell->value = value_new_int (l);
set = 1;
}
}
}
......@@ -780,16 +768,15 @@ cell_set_formula_tree_simple (Cell *cell, ExprTree *formula)
g_return_if_fail (cell != NULL);
g_return_if_fail (formula != NULL);
cell_modified (cell);
/* Ref before unref. Repeat after me. */
expr_tree_ref (formula);
if (cell->parsed_node){
sheet_cell_formula_unlink (cell);
expr_tree_unref (cell->parsed_node);
}
cell_modified (cell);
cell_cleanout (cell);
cell->parsed_node = formula;
/* Until the value is recomputed, we put in this value. */
cell->value = value_new_error (NULL, _("Circular reference"));
cell_formula_changed (cell);
}
......@@ -904,10 +891,6 @@ cell_copy (const Cell *cell)
if (new_cell->render_color)
style_color_ref (new_cell->render_color);
/*
* The cell->value can be NULL if the cell contains
* an error
*/
if (new_cell->value)
new_cell->value = value_duplicate (new_cell->value);
......@@ -931,10 +914,7 @@ cell_destroy (Cell *cell)
}
cell_modified (cell);
if (cell->parsed_node)
expr_tree_unref (cell->parsed_node);
cell->parsed_node = (void *)0xdeadbeef;
cell_cleanout (cell);
if (cell->render_color)
style_color_unref (cell->render_color);
......@@ -946,17 +926,9 @@ cell_destroy (Cell *cell)
string_unref (cell->text);
cell->text = (void *)0xdeadbeef;
if (cell->entered_text)
string_unref (cell->entered_text);
cell->entered_text = (void *)0xdeadbeef;
style_destroy (cell->style);
cell->style = (void *)0xdeadbeef;
if (cell->value)
value_release (cell->value);
cell->value = (void *)0xdeadbeef;
g_free (cell);
}
......@@ -1184,6 +1156,7 @@ cell_make_value (Cell *cell)
g_return_if_fail (cell != NULL);
g_return_if_fail (cell->parsed_node != NULL);
/* FIXME: does this work at all? -- MW */
cell_modified (cell);
}
......@@ -1208,11 +1181,7 @@ cell_get_horizontal_align (const Cell *cell)
int
cell_is_number (const Cell *cell)
{
if (cell->value)
if (cell->value->type == VALUE_FLOAT || cell->value->type == VALUE_INTEGER)
return TRUE;
return FALSE;
return cell->value && VALUE_IS_NUMBER (cell->value);
}
static inline int
......@@ -1506,13 +1475,11 @@ cell_calc_dimensions (Cell *cell)
char *
cell_get_text (Cell *cell)
{
char *str;
ParsePosition pp;
g_return_val_if_fail (cell != NULL, NULL);
if (cell->parsed_node && cell->sheet){
char *func, *ret;
ParsePosition pp;
func = expr_decode_tree (cell->parsed_node,
parse_pos_cell (&pp, cell));
......@@ -1522,15 +1489,10 @@ cell_get_text (Cell *cell)
return ret;
}
/*
* If a value is set, return that text formatted
*/
if (cell->value)
str = format_value (cell->style->format, cell->value, NULL);
if (cell->entered_text)
return g_strdup (cell->entered_text->str);
else
str = g_strdup (cell->entered_text->str);
return str;
return format_value (cell->style->format, cell->value, NULL);
}
......@@ -1547,13 +1509,11 @@ cell_get_text (Cell *cell)
char *
cell_get_content (Cell *cell)
{
char *str;
ParsePosition pp;
g_return_val_if_fail (cell != NULL, NULL);
if (cell->parsed_node){
char *func, *ret;
ParsePosition pp;
func = expr_decode_tree (cell->parsed_node,
parse_pos_cell (&pp, cell));
......@@ -1566,12 +1526,10 @@ cell_get_content (Cell *cell)
/*
* Return the value without parsing.
*/
if (cell->value)
str = value_get_as_string (cell->value);
if (cell->entered_text)
return g_strdup (cell->entered_text->str);
else
str = g_strdup (cell->entered_text->str);
return str;
return value_get_as_string (cell->value);
}
char *
......
......@@ -34,7 +34,7 @@ struct _ColRowInfo {
#define ROW_INTERNAL_HEIGHT(row) ((row)->pixels - ((row)->margin_b + (row)->margin_a))
/* Cell has a computation error */
#define CELL_ERROR 1
/* #define CELL_ERROR 1 */
/* Cell container a comment */
#define CELL_HAS_COMMENT 2
......@@ -69,7 +69,8 @@ struct _Cell {
ColRowInfo *col;
ColRowInfo *row;
/* Text as entered by the user */
/* Text as entered by the user. This is only used for cells
with parse errors. */
String *entered_text;
/* Type of the content and the actual parsed content */
......
......@@ -51,22 +51,13 @@ cell_eval (Cell *cell)
}
#endif
if (cell->value){
if (cell->value)
value_release (cell->value);
cell->value = NULL;
}
if (v == NULL)
v = value_new_error (&s.pos, "Internal error");
cell->value = v;
if (v == NULL){
cell_set_rendered_text (cell, _("INTERNAL ERROR"));
cell->flags |= CELL_ERROR;
} else {
cell_render_value (cell);
if (v->type == VALUE_ERROR)
cell->flags |= CELL_ERROR;
else
cell->flags &= ~CELL_ERROR;
}
cell_render_value (cell);
cell_calc_dimensions (cell);
......
......@@ -51,22 +51,13 @@ cell_eval (Cell *cell)
}
#endif
if (cell->value){
if (cell->value)
value_release (cell->value);
cell->value = NULL;
}
if (v == NULL)
v = value_new_error (&s.pos, "Internal error");
cell->value = v;
if (v == NULL){
cell_set_rendered_text (cell, _("INTERNAL ERROR"));
cell->flags |= CELL_ERROR;
} else {
cell_render_value (cell);
if (v->type == VALUE_ERROR)
cell->flags |= CELL_ERROR;
else
cell->flags &= ~CELL_ERROR;
}
cell_render_value (cell);
cell_calc_dimensions (cell);
......
......@@ -1013,10 +1013,7 @@ eval_expr_real (FunctionEvalInfo *s, ExprTree const *tree)
cell_eval (cell);
}
if (cell->value)
return value_duplicate (cell->value);
return value_new_error (&s->pos, (cell->text) ? cell->text->str
: _("Reference to newborn cell"));
return value_duplicate (cell->value);
}
case OPER_CONSTANT:
......
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