Commit 4fb728ac authored by Morten Welinder's avatar Morten Welinder

Improve do_expr_decode_tree to avoid extra ()s.

parent 9bf8eb01
1999-05-16 Morten Welinder <terra@diku.dk>
* src/expr.c (evaluate_level): Deleted.
(bigger_prec): Deleted.
(do_expr_decode_tree): Handle left/right associativity.
* src/cell.c (cell_set_text_simple): Simplify value parsing.
* src/dialog-goal-seek.c (test_cell_with_value): Cast to double,
not float.
1999-05-16 Michael Meeks <michael@imaginator.com>
* src/workbook.c (cb_assemble_selection): Add 'char *sel'
......@@ -42,7 +53,6 @@
regression testing. It is in Excel format so it tests the Excel
plugin's functionality in the same time too.
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/file.c (file_format_register_save): Changed to append
......@@ -56,7 +66,6 @@
* src/parser.y (value_dump): Fixed array problem.
Added const to parameter.
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/parser.c (value_dump): Updated Arrays, to use Value *
......@@ -86,7 +95,6 @@
* src/func.c (constants_init): Added a 'value_zero' constant
to kill leak in out-of-range / NULL cell cases in value_get_at_x_y
1999-05-14 Jukka-Pekka Iivonen <iivonen@iki.fi>
......@@ -4030,7 +4038,6 @@ Sun Aug 30 17:19:02 EDT 1998 Daniel Veillard <Daniel.Veillard@w3.org>
StyleFormat structure is actually released. resources allocated
in format_compile should be disposed here
* src/sheet.c (sheet_cursor_set): New function. Use this instead
of the view-specific routine (gnumeric_cursor_set).
......@@ -4553,7 +4560,6 @@ Sun Jul 26 17:39:53 EDT 1998 Daniel Veillard <Daniel.Veillard@w3.org>
* src/utils.c (cell_name): New routine. Renders a cell name.
* src/sheet.h (IS_SHEET): Added a signature to Sheet strucutres
and a signature to test with.
......
1999-05-16 Morten Welinder <terra@diku.dk>
* src/expr.c (evaluate_level): Deleted.
(bigger_prec): Deleted.
(do_expr_decode_tree): Handle left/right associativity.
* src/cell.c (cell_set_text_simple): Simplify value parsing.
* src/dialog-goal-seek.c (test_cell_with_value): Cast to double,
not float.
1999-05-16 Michael Meeks <michael@imaginator.com>
* src/workbook.c (cb_assemble_selection): Add 'char *sel'
......@@ -42,7 +53,6 @@
regression testing. It is in Excel format so it tests the Excel
plugin's functionality in the same time too.
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/file.c (file_format_register_save): Changed to append
......@@ -56,7 +66,6 @@
* src/parser.y (value_dump): Fixed array problem.
Added const to parameter.
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/parser.c (value_dump): Updated Arrays, to use Value *
......@@ -86,7 +95,6 @@
* src/func.c (constants_init): Added a 'value_zero' constant
to kill leak in out-of-range / NULL cell cases in value_get_at_x_y
1999-05-14 Jukka-Pekka Iivonen <iivonen@iki.fi>
......@@ -4030,7 +4038,6 @@ Sun Aug 30 17:19:02 EDT 1998 Daniel Veillard <Daniel.Veillard@w3.org>
StyleFormat structure is actually released. resources allocated
in format_compile should be disposed here
* src/sheet.c (sheet_cursor_set): New function. Use this instead
of the view-specific routine (gnumeric_cursor_set).
......@@ -4553,7 +4560,6 @@ Sun Jul 26 17:39:53 EDT 1998 Daniel Veillard <Daniel.Veillard@w3.org>
* src/utils.c (cell_name): New routine. Renders a cell name.
* src/sheet.h (IS_SHEET): Added a signature to Sheet strucutres
and a signature to test with.
......
1999-05-16 Morten Welinder <terra@diku.dk>
* src/expr.c (evaluate_level): Deleted.
(bigger_prec): Deleted.
(do_expr_decode_tree): Handle left/right associativity.
* src/cell.c (cell_set_text_simple): Simplify value parsing.
* src/dialog-goal-seek.c (test_cell_with_value): Cast to double,
not float.
1999-05-16 Michael Meeks <michael@imaginator.com>
* src/workbook.c (cb_assemble_selection): Add 'char *sel'
......@@ -42,7 +53,6 @@
regression testing. It is in Excel format so it tests the Excel
plugin's functionality in the same time too.
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/file.c (file_format_register_save): Changed to append
......@@ -56,7 +66,6 @@
* src/parser.y (value_dump): Fixed array problem.
Added const to parameter.
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/parser.c (value_dump): Updated Arrays, to use Value *
......@@ -86,7 +95,6 @@
* src/func.c (constants_init): Added a 'value_zero' constant
to kill leak in out-of-range / NULL cell cases in value_get_at_x_y
1999-05-14 Jukka-Pekka Iivonen <iivonen@iki.fi>
......@@ -4030,7 +4038,6 @@ Sun Aug 30 17:19:02 EDT 1998 Daniel Veillard <Daniel.Veillard@w3.org>
StyleFormat structure is actually released. resources allocated
in format_compile should be disposed here
* src/sheet.c (sheet_cursor_set): New function. Use this instead
of the view-specific routine (gnumeric_cursor_set).
......@@ -4553,7 +4560,6 @@ Sun Jul 26 17:39:53 EDT 1998 Daniel Veillard <Daniel.Veillard@w3.org>
* src/utils.c (cell_name): New routine. Renders a cell name.
* src/sheet.h (IS_SHEET): Added a signature to Sheet strucutres
and a signature to test with.
......
1999-05-16 Morten Welinder <terra@diku.dk>
* src/expr.c (evaluate_level): Deleted.
(bigger_prec): Deleted.
(do_expr_decode_tree): Handle left/right associativity.
* src/cell.c (cell_set_text_simple): Simplify value parsing.
* src/dialog-goal-seek.c (test_cell_with_value): Cast to double,
not float.
1999-05-16 Michael Meeks <michael@imaginator.com>
* src/workbook.c (cb_assemble_selection): Add 'char *sel'
......@@ -42,7 +53,6 @@
regression testing. It is in Excel format so it tests the Excel
plugin's functionality in the same time too.
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/file.c (file_format_register_save): Changed to append
......@@ -56,7 +66,6 @@
* src/parser.y (value_dump): Fixed array problem.
Added const to parameter.
1999-05-15 Michael Meeks <michael@imaginator.com>
* src/parser.c (value_dump): Updated Arrays, to use Value *
......@@ -86,7 +95,6 @@
* src/func.c (constants_init): Added a 'value_zero' constant
to kill leak in out-of-range / NULL cell cases in value_get_at_x_y
1999-05-14 Jukka-Pekka Iivonen <iivonen@iki.fi>
......@@ -4030,7 +4038,6 @@ Sun Aug 30 17:19:02 EDT 1998 Daniel Veillard <Daniel.Veillard@w3.org>
StyleFormat structure is actually released. resources allocated
in format_compile should be disposed here
* src/sheet.c (sheet_cursor_set): New function. Use this instead
of the view-specific routine (gnumeric_cursor_set).
......@@ -4553,7 +4560,6 @@ Sun Jul 26 17:39:53 EDT 1998 Daniel Veillard <Daniel.Veillard@w3.org>
* src/utils.c (cell_name): New routine. Renders a cell name.
* src/sheet.h (IS_SHEET): Added a signature to Sheet strucutres
and a signature to test with.
......
1998-05-11 Morten Welinder <terra@diku.dk>
* stat.c, stat.h: Remove old junk.
1998-10-07 Richard Hestilow <hestgray@ionet.net>
* stat.c: Changed all g_new's to g_malloc's to get rid of compiler
......
......@@ -11,16 +11,7 @@ can_unload (PluginData *pd)
{
return TRUE;
}
int
init_plugin (PluginData *pd)
{
pd->can_unload = can_unload;
pd->cleanup_plugin = cleanup_plugin;
pd->title = g_strdup (_("OLD Statistics Plugin, not required anymore"));
return 0;
}
static void
cleanup_plugin (PluginData *pd)
......@@ -28,6 +19,12 @@ cleanup_plugin (PluginData *pd)
g_free (pd->title);
}
int
init_plugin (PluginData *pd)
{
pd->can_unload = can_unload;
pd->cleanup_plugin = cleanup_plugin;
pd->title = g_strdup (_("OLD Statistics Plugin, not required anymore"));
return 0;
}
......@@ -7,22 +7,6 @@
#include "../../src/func.h"
#include "../../src/plugin.h"
float stat_undivided_variance(void *sheet, GList *expr_node_list,
int eval_col, int eval_row,
char **error_string);
static Value *stat_stdev (void *sheet, GList *expr_node_list, int eval_col,
int eval_row, char **error_string);
static Value *stat_variance(void *sheet, GList *expr_node_list, int eval_col,
int eval_row, char **error_string);
static Value *stat_nvariance(void *sheet, GList *expr_node_list, int eval_col,
int eval_row, char **error_string);
int callback_var(Sheet *sheet, Value *value,
char **error_string, void *closure);
static void cleanup_plugin(PluginData *pd);
int init_plugin(PluginData *pd);
#endif /* GNUMERIC_STAT_H */
......@@ -14,6 +14,7 @@
#include "color.h"
#include "cursors.h"
#include "utils.h"
#include <ctype.h>
static int redraws_frozen = 0;
static int redraws_deep_frozen = 0;
......@@ -640,69 +641,30 @@ cell_set_text_simple (Cell *cell, const char *text)
if (text [0] == '=' && text [1] != 0){
cell_set_formula (cell, text);
} else {
Value *v = g_new (Value, 1);
int is_text, is_float, maybe_float, has_digits;
int seen_exp;
const char *p;
char *end;
long l;
lconv = localeconv ();
is_text = is_float = maybe_float = has_digits = FALSE;
seen_exp = FALSE;
for (p = text; *p && !is_text; p++){
switch (*p){
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
has_digits = TRUE;
break;
case '-':
if (p == text)
break;
if (seen_exp)
is_text = TRUE;
/* falldown */
case 'E': case 'e': case '+': case ':': case '.': case ',':
if (*p == 'e' || *p == 'E') {
seen_exp = TRUE;
/* Lookahead */
if (*(p+1) == '-')
p++;
}
if (*p == ',' || *p == '.')
if (*lconv->decimal_point != *p){
is_text = TRUE;
break;
}
maybe_float = TRUE;
break;
/* Skip spaces, just in case. */
p = text;
while (isspace (*p)) p++;
default:
is_text = TRUE;
}
}
if (has_digits && maybe_float)
is_float = TRUE;
if (has_digits && !is_text){
if (is_float){
v->type = VALUE_FLOAT;
float_get_from_range (text, text+strlen(text),
&v->v.v_float);
l = strtol (p, &end, 10);
if (p != end && *end == 0) {
/* It is an int. FIXME: long/int confusion here. */
cell->value = value_new_int (l);
} else {
double d;
d = strtod (p, &end);
if (p != end && *end == 0) {
/* It is a floating point number. */
cell->value = value_new_float ((float_t)d);
} else {
v->type = VALUE_INTEGER;
int_get_from_range (text, text+strlen (text),
&v->v.v_int);
/* It is text. */
cell->value = value_new_string (text);
}
} else {
v->type = VALUE_STRING;
v->v.str = string_get (text);
}
cell->value = v;
cell_render_value (cell);
}
}
......
......@@ -21,11 +21,11 @@
#define MAX_CELL_NAME_LEN 20
static int test_cell_with_value (Cell *set_cell, Cell *change_cell,
float_t x, float_t *value)
static int
test_cell_with_value (Cell *set_cell, Cell *change_cell, float_t x, float_t *value)
{
char buf[256];
sprintf(buf, "%f", (float) x);
sprintf(buf, "%f", (double) x);
cell_set_text(change_cell, buf);
cell_eval(set_cell);
......
......@@ -21,11 +21,11 @@
#define MAX_CELL_NAME_LEN 20
static int test_cell_with_value (Cell *set_cell, Cell *change_cell,
float_t x, float_t *value)
static int
test_cell_with_value (Cell *set_cell, Cell *change_cell, float_t x, float_t *value)
{
char buf[256];
sprintf(buf, "%f", (float) x);
sprintf(buf, "%f", (double) x);
cell_set_text(change_cell, buf);
cell_eval(set_cell);
......
......@@ -411,19 +411,19 @@ value_get_as_int (const Value *v)
case VALUE_CELLRANGE:
g_warning ("Getting range as a double: what to do?");
return 0.0;
return 0;
case VALUE_INTEGER:
return v->v.v_int;
case VALUE_ARRAY:
return 0.0;
return 0;
case VALUE_FLOAT:
return (int) v->v.v_float;
default:
g_warning ("value_get_as_int unknown type\n");
break;
return 0;
}
return 0.0;
}
......@@ -1282,60 +1282,61 @@ cell_get_abs_col_row (const CellRef *cell_ref, int eval_col, int eval_row, int *
*row = cell_ref->row;
}
static int
evaluate_level (Operation x)
{
if (x == OPER_EXP)
return 3;
if ((x==OPER_MULT) || (x==OPER_DIV))
return 2;
if ((x==OPER_ADD) || (x==OPER_SUB) || (x==OPER_CONCAT))
return 1;
return 0;
}
static int
bigger_prec (Operation parent, Operation this)
{
int parent_level, this_level;
parent_level = evaluate_level (parent);
this_level = evaluate_level (this);
return parent_level >= this_level;
}
/*
* Converts a parsed tree into its string representation
* assuming that we are evaluating at col, row (This is
* only used during copying to "render" a new text
* representation for a copied cell.
* assuming that we are evaluating at col, row
*
* This routine is pretty simple: it walks the ExprTree and
* create a string representation.
* creates a string representation.
*
* FIXME: strings containing quotes will come out wrong.
* FIXME: negative constants should pretend to have OPER_NEG's precedence.
*/
static char *
do_expr_decode_tree (ExprTree *tree, Sheet *sheet, int col, int row, Operation parent_op)
do_expr_decode_tree (ExprTree *tree, Sheet *sheet, int col, int row, int paren_level)
{
static const char *operation_names [] = {
"=", ">", "<", ">=", "<=", "<>",
"+", "-", "*", "/", "^", "&",
NULL, NULL, NULL, "-"
static struct {
const char *name;
int prec; /* Precedences -- should match parser.y */
int assoc_left, assoc_right; /* 0: no, 1: yes. */
} operations [] = {
{ "=", 1, 1, 0 },
{ ">", 1, 1, 0 },
{ "<", 1, 1, 0 },
{ ">=", 1, 1, 0 },
{ "<=", 1, 1, 0 },
{ "<>", 1, 1, 0 },
{ "+", 3, 1, 0 },
{ "-", 3, 1, 0 },
{ "*", 4, 1, 0 },
{ "/", 4, 1, 0 },
{ "^", 6, 0, 1 },
{ "&", 2, 1, 0 },
{ NULL, 0, 0, 0 },
{ NULL, 0, 0, 0 },
{ NULL, 0, 0, 0 },
{ "-", 5, 0, 0 }
};
int op;
switch (tree->oper){
op = tree->oper;
switch (op){
case OPER_ANY_BINARY: {
char *a, *b, *res;
char const *op;
char const *opname;
int prec;
prec = operations[op].prec;
a = do_expr_decode_tree (tree->u.binary.value_a, sheet, col, row, tree->oper);
b = do_expr_decode_tree (tree->u.binary.value_b, sheet, col, row, tree->oper);
op = operation_names [tree->oper];
a = do_expr_decode_tree (tree->u.binary.value_a, sheet, col, row, prec - operations[op].assoc_left);
b = do_expr_decode_tree (tree->u.binary.value_b, sheet, col, row, prec - operations[op].assoc_right);
opname = operations[op].name;
if (bigger_prec (parent_op, tree->oper))
res = g_strconcat ("(", a, op, b, ")", NULL);
if (prec <= paren_level)
res = g_strconcat ("(", a, opname, b, ")", NULL);
else
res = g_strconcat (a, op, b, NULL);
res = g_strconcat (a, opname, b, NULL);
g_free (a);
g_free (b);
......@@ -1344,9 +1345,17 @@ do_expr_decode_tree (ExprTree *tree, Sheet *sheet, int col, int row, Operation p
case OPER_ANY_UNARY: {
char *res, *a;
char const *opname;
int prec;
a = do_expr_decode_tree (tree->u.value, sheet, col, row, tree->oper);
res = g_strconcat (operation_names[tree->oper], a, NULL);
prec = operations[op].prec;
a = do_expr_decode_tree (tree->u.value, sheet, col, row, operations[op].prec);
opname = operations[op].name;
if (prec <= paren_level)
res = g_strconcat ("(", opname, a, ")", NULL);
else
res = g_strconcat (opname, a, NULL);
g_free (a);
return res;
}
......@@ -1370,7 +1379,7 @@ do_expr_decode_tree (ExprTree *tree, Sheet *sheet, int col, int row, Operation p
for (l = arg_list; l; l = l->next, i++){
ExprTree *t = l->data;
args [i] = do_expr_decode_tree (t, sheet, col, row, OPER_CONSTANT);
args [i] = do_expr_decode_tree (t, sheet, col, row, 0);
len += strlen (args [i]) + 1;
}
len++;
......@@ -1384,8 +1393,7 @@ do_expr_decode_tree (ExprTree *tree, Sheet *sheet, int col, int row, Operation p
strcat (sum, ",");
}
res = g_strconcat (
fd->name, "(", sum, ")", NULL);
res = g_strconcat (fd->name, "(", sum, ")", NULL);
g_free (sum);
for (i = 0; i < argc; i++)
......@@ -1439,7 +1447,7 @@ expr_decode_tree (ExprTree *tree, Sheet *sheet, int col, int row)
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (IS_SHEET (sheet), NULL);
return do_expr_decode_tree (tree, sheet, col, row, OPER_CONSTANT);
return do_expr_decode_tree (tree, sheet, col, row, 0);
}
static ExprTree *
......
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