Commit be513498 authored by Michael Meeks's avatar Michael Meeks

Wierd hack to expr.c and implement ADDRESS function.

parent 8caf856f
1999-04-15 Michael Meeks <michael@mejm2.dow.cam.ac.uk>
* src/parser.y (value_dump): Added CellRange support
include expr.h
1999-04-15 Michael Meeks <michael@edenproject.org>
* src/fn-lookup.c (gnumeric_offset): Implemented OFFSET.
* src/expr.c (value_cellrange): Created.
(eval_funcall): Major hack to allow auto-conversion
of cell references to cell ranges on the fly.
* src/expr.h: Added value_cellrange.
1999-04-15 Michael Meeks <michael@edenproject.org>
(gnumeric_choose): CHOOSE function implemented.
1999-04-14 Miguel de Icaza <miguel@nuclecu.unam.mx>
......
1999-04-15 Michael Meeks <michael@mejm2.dow.cam.ac.uk>
* src/parser.y (value_dump): Added CellRange support
include expr.h
1999-04-15 Michael Meeks <michael@edenproject.org>
* src/fn-lookup.c (gnumeric_offset): Implemented OFFSET.
* src/expr.c (value_cellrange): Created.
(eval_funcall): Major hack to allow auto-conversion
of cell references to cell ranges on the fly.
* src/expr.h: Added value_cellrange.
1999-04-15 Michael Meeks <michael@edenproject.org>
(gnumeric_choose): CHOOSE function implemented.
1999-04-14 Miguel de Icaza <miguel@nuclecu.unam.mx>
......
1999-04-15 Michael Meeks <michael@mejm2.dow.cam.ac.uk>
* src/parser.y (value_dump): Added CellRange support
include expr.h
1999-04-15 Michael Meeks <michael@edenproject.org>
* src/fn-lookup.c (gnumeric_offset): Implemented OFFSET.
* src/expr.c (value_cellrange): Created.
(eval_funcall): Major hack to allow auto-conversion
of cell references to cell ranges on the fly.
* src/expr.h: Added value_cellrange.
1999-04-15 Michael Meeks <michael@edenproject.org>
(gnumeric_choose): CHOOSE function implemented.
1999-04-14 Miguel de Icaza <miguel@nuclecu.unam.mx>
......
1999-04-15 Michael Meeks <michael@mejm2.dow.cam.ac.uk>
* src/parser.y (value_dump): Added CellRange support
include expr.h
1999-04-15 Michael Meeks <michael@edenproject.org>
* src/fn-lookup.c (gnumeric_offset): Implemented OFFSET.
* src/expr.c (value_cellrange): Created.
(eval_funcall): Major hack to allow auto-conversion
of cell references to cell ranges on the fly.
* src/expr.h: Added value_cellrange.
1999-04-15 Michael Meeks <michael@edenproject.org>
(gnumeric_choose): CHOOSE function implemented.
1999-04-14 Miguel de Icaza <miguel@nuclecu.unam.mx>
......
......@@ -349,6 +349,47 @@ gnumeric_columns (struct FunctionDefinition *i, Value *argv [], char **error_str
return value_int (value_area_get_width (argv [0]));
}
static char *help_offset = {
N_("@FUNCTION=OFFSET\n"
"@SYNTAX=OFFSET(range,row,col,height,width)\n"
"@DESCRIPTION="
"The OFFSET function returns a cell range."
"The cell range starts at offset (col,row) from range, "
"and is of height @height and width @width."
"\n"
"If range is neither a reference nor a range returns #VALUE!."
"\n"
"@SEEALSO=COLUMN,COLUMNS,ROWS")
};
static Value *
gnumeric_offset (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
CellRef a;
CellRef b;
int tw, th;
g_return_val_if_fail (argv[0]->type == VALUE_CELLRANGE, NULL);
memcpy (&a, &argv[0]->v.cell_range.cell_a, sizeof(CellRef));
a.row+=value_get_as_int(argv[1]);
a.col+=value_get_as_int(argv[2]);
memcpy (&b, &a, sizeof(CellRef));
tw = value_get_as_int(argv[3]);
th = value_get_as_int(argv[4]);
if (tw < 0 || th < 0) {
*error_string = _("#VALUE!");
return NULL;
} else if (a.row<0 || a.col < 0) {
*error_string = _("#REF!");
return NULL;
}
b.row+=tw;
b.col+=th;
return value_cellrange (&a, &b);
}
static char *help_row = {
N_("@FUNCTION=ROW\n"
"@SYNTAX=ROW([reference])\n"
......@@ -412,6 +453,7 @@ FunctionDefinition lookup_functions [] = {
{ "column", "?", "ref", &help_column, gnumeric_column, NULL },
{ "columns", "A", "ref", &help_column, NULL, gnumeric_columns },
{ "hlookup", "?Af|b","val,range,col_idx,approx", &help_hlookup, NULL, gnumeric_hlookup },
{ "offset", "rffff","ref,row,col,hight,width", &help_offset, NULL, gnumeric_offset },
{ "row", "?", "ref", &help_row, gnumeric_row, NULL },
{ "rows", "A", "ref", &help_rows, NULL, gnumeric_rows },
{ "vlookup", "?Af|b","val,range,col_idx,approx", &help_vlookup, NULL, gnumeric_vlookup },
......
......@@ -313,6 +313,16 @@ value_str (char *str)
return v;
}
Value *
value_cellrange (CellRef *a, CellRef *b)
{
Value *v = g_new (Value, 1);
v->type = VALUE_CELLRANGE;
memcpy (&v->v.cell_range.cell_a, a, sizeof(CellRef));
memcpy (&v->v.cell_range.cell_b, b, sizeof(CellRef));
return v;
}
/*
* Casts a value to float if it is integer, and returns
* a new Value * if required
......@@ -656,15 +666,28 @@ eval_funcall (Sheet *sheet, ExprTree *tree, int eval_col, int eval_row, char **e
ExprTree *t = (ExprTree *) l->data;
int type_mismatch = 0;
v = eval_expr (sheet, t, eval_col, eval_row, error_string);
if (v == NULL)
goto free_list;
if (*arg_type=='|')
arg_type++;
if ((*arg_type != 'A' && /* This is so a cell reference */
*arg_type != 'r') || /* can be converted to a cell range */
!t || (t->oper != OPER_VAR)) { /* without being evaluated */
if ((v = eval_expr (sheet, t, eval_col,
eval_row, error_string))==NULL)
goto free_list;
} else {
g_assert (t->oper == OPER_VAR);
v = value_cellrange (&t->u.ref,
&t->u.ref);
if (!v->v.cell_range.cell_a.sheet)
v->v.cell_range.cell_a.sheet = sheet;
if (!v->v.cell_range.cell_b.sheet)
v->v.cell_range.cell_b.sheet = sheet;
}
switch (*arg_type){
case 'f':
if (v->type != VALUE_INTEGER &&
v->type != VALUE_FLOAT)
type_mismatch = 1;
......
......@@ -173,6 +173,8 @@ const Value *value_area_get_at_x_y (Value *v, guint x, guint y);
Value *value_array_new (guint width, guint height);
void value_array_resize (Value *v, guint width, guint height);
void value_array_copy_to (Value *dest, const Value *src);
Value *value_cellrange (CellRef *a, CellRef *b);
void value_dump (Value *value);
char *value_string (const Value *value);
......
......@@ -349,6 +349,47 @@ gnumeric_columns (struct FunctionDefinition *i, Value *argv [], char **error_str
return value_int (value_area_get_width (argv [0]));
}
static char *help_offset = {
N_("@FUNCTION=OFFSET\n"
"@SYNTAX=OFFSET(range,row,col,height,width)\n"
"@DESCRIPTION="
"The OFFSET function returns a cell range."
"The cell range starts at offset (col,row) from range, "
"and is of height @height and width @width."
"\n"
"If range is neither a reference nor a range returns #VALUE!."
"\n"
"@SEEALSO=COLUMN,COLUMNS,ROWS")
};
static Value *
gnumeric_offset (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
CellRef a;
CellRef b;
int tw, th;
g_return_val_if_fail (argv[0]->type == VALUE_CELLRANGE, NULL);
memcpy (&a, &argv[0]->v.cell_range.cell_a, sizeof(CellRef));
a.row+=value_get_as_int(argv[1]);
a.col+=value_get_as_int(argv[2]);
memcpy (&b, &a, sizeof(CellRef));
tw = value_get_as_int(argv[3]);
th = value_get_as_int(argv[4]);
if (tw < 0 || th < 0) {
*error_string = _("#VALUE!");
return NULL;
} else if (a.row<0 || a.col < 0) {
*error_string = _("#REF!");
return NULL;
}
b.row+=tw;
b.col+=th;
return value_cellrange (&a, &b);
}
static char *help_row = {
N_("@FUNCTION=ROW\n"
"@SYNTAX=ROW([reference])\n"
......@@ -412,6 +453,7 @@ FunctionDefinition lookup_functions [] = {
{ "column", "?", "ref", &help_column, gnumeric_column, NULL },
{ "columns", "A", "ref", &help_column, NULL, gnumeric_columns },
{ "hlookup", "?Af|b","val,range,col_idx,approx", &help_hlookup, NULL, gnumeric_hlookup },
{ "offset", "rffff","ref,row,col,hight,width", &help_offset, NULL, gnumeric_offset },
{ "row", "?", "ref", &help_row, gnumeric_row, NULL },
{ "rows", "A", "ref", &help_rows, NULL, gnumeric_rows },
{ "vlookup", "?Af|b","val,range,col_idx,approx", &help_vlookup, NULL, gnumeric_vlookup },
......
......@@ -349,6 +349,47 @@ gnumeric_columns (struct FunctionDefinition *i, Value *argv [], char **error_str
return value_int (value_area_get_width (argv [0]));
}
static char *help_offset = {
N_("@FUNCTION=OFFSET\n"
"@SYNTAX=OFFSET(range,row,col,height,width)\n"
"@DESCRIPTION="
"The OFFSET function returns a cell range."
"The cell range starts at offset (col,row) from range, "
"and is of height @height and width @width."
"\n"
"If range is neither a reference nor a range returns #VALUE!."
"\n"
"@SEEALSO=COLUMN,COLUMNS,ROWS")
};
static Value *
gnumeric_offset (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
CellRef a;
CellRef b;
int tw, th;
g_return_val_if_fail (argv[0]->type == VALUE_CELLRANGE, NULL);
memcpy (&a, &argv[0]->v.cell_range.cell_a, sizeof(CellRef));
a.row+=value_get_as_int(argv[1]);
a.col+=value_get_as_int(argv[2]);
memcpy (&b, &a, sizeof(CellRef));
tw = value_get_as_int(argv[3]);
th = value_get_as_int(argv[4]);
if (tw < 0 || th < 0) {
*error_string = _("#VALUE!");
return NULL;
} else if (a.row<0 || a.col < 0) {
*error_string = _("#REF!");
return NULL;
}
b.row+=tw;
b.col+=th;
return value_cellrange (&a, &b);
}
static char *help_row = {
N_("@FUNCTION=ROW\n"
"@SYNTAX=ROW([reference])\n"
......@@ -412,6 +453,7 @@ FunctionDefinition lookup_functions [] = {
{ "column", "?", "ref", &help_column, gnumeric_column, NULL },
{ "columns", "A", "ref", &help_column, NULL, gnumeric_columns },
{ "hlookup", "?Af|b","val,range,col_idx,approx", &help_hlookup, NULL, gnumeric_hlookup },
{ "offset", "rffff","ref,row,col,hight,width", &help_offset, NULL, gnumeric_offset },
{ "row", "?", "ref", &help_row, gnumeric_row, NULL },
{ "rows", "A", "ref", &help_rows, NULL, gnumeric_rows },
{ "vlookup", "?Af|b","val,range,col_idx,approx", &help_vlookup, NULL, gnumeric_vlookup },
......
......@@ -650,6 +650,17 @@ value_dump (Value *value)
for (y = 0; y < value->v.array.y; y++)
value_dump (&value->v.array.vals [x][y]);
printf ("}\n");
break;
}
case VALUE_CELLRANGE: {
CellRef *c = &value->v.cell_range.cell_a;
printf ("CellRange\n");
printf ("%p: %d,%d rel? %d,%d\n", c->sheet, c->col, c->row,
c->col_relative, c->row_relative);
c = &value->v.cell_range.cell_b;
printf ("%p: %d,%d rel? %d,%d\n", c->sheet, c->col, c->row,
c->col_relative, c->row_relative);
break;
}
default:
printf ("Unhandled item type\n");
......
......@@ -10,6 +10,6 @@
#include "pixmaps/oval.xpm"
#include "pixmaps/bold.xpm"
#include "pixmaps/italic.xpm"
#include "pixmaps/graphic.xpm"
/* #include "pixmaps/graphic.xpm" */
#endif /* GNUMERIC_PIXMAPS_H */
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