Commit ece60427 authored by Michael Meeks's avatar Michael Meeks

Name support ( needs a GUI ),

Hack the Gnumeric.idl file to get it to compile.
parent 5ddc4d73
......@@ -37,6 +37,7 @@ Michael
- Formulae should import into Excel.
- Text / numbers work nicely.
* Prettified 'sort' slightly.
* Implemented Name support.
Nick Lamb
......
1999-07-08 Michael Meeks <michael@edenproject.org>
* src/Gnumeric.idl: Removed : GNOME::Unknown from Workbook so
people can compile for now.
1999-07-07 Michael Meeks <michael@edenproject.org>
* src/expr.c (do_expr_decode_tree): Add vital translation stuff.
* src/parser.y (return_name): Created.
(try_symbol): Add name lookup.
* src/eval.c (add_tree_deps): Calculate name dependencies if at all
possible.
* src/main.c (gnumeric_main): Add expr_name_init.
* src/expr.c (expr_tree_new_name, do_expr_tree_unref),
(eval_expr, do_expr_decode_tree, do_expr_tree_invalidate_references),
(do_expr_tree_fixup_references, expr_dump_tree): Add OPER_NAME support
in every case just after OPER_FUNCALL.
* src/expr.h: Add ExprName struct, include and OPER_NAME.
* src/Makefile.am (GNUMERIC_BASE_SOURCES): Added expr_name.[ch]
1999-07-07 Miguel de Icaza <miguel@gnu.org>
* configure.in (EXTRA_GNOME_CFLAGS): Assemble all the flags we
......
1999-07-08 Michael Meeks <michael@edenproject.org>
* src/Gnumeric.idl: Removed : GNOME::Unknown from Workbook so
people can compile for now.
1999-07-07 Michael Meeks <michael@edenproject.org>
* src/expr.c (do_expr_decode_tree): Add vital translation stuff.
* src/parser.y (return_name): Created.
(try_symbol): Add name lookup.
* src/eval.c (add_tree_deps): Calculate name dependencies if at all
possible.
* src/main.c (gnumeric_main): Add expr_name_init.
* src/expr.c (expr_tree_new_name, do_expr_tree_unref),
(eval_expr, do_expr_decode_tree, do_expr_tree_invalidate_references),
(do_expr_tree_fixup_references, expr_dump_tree): Add OPER_NAME support
in every case just after OPER_FUNCALL.
* src/expr.h: Add ExprName struct, include and OPER_NAME.
* src/Makefile.am (GNUMERIC_BASE_SOURCES): Added expr_name.[ch]
1999-07-07 Miguel de Icaza <miguel@gnu.org>
* configure.in (EXTRA_GNOME_CFLAGS): Assemble all the flags we
......
1999-07-08 Michael Meeks <michael@edenproject.org>
* src/Gnumeric.idl: Removed : GNOME::Unknown from Workbook so
people can compile for now.
1999-07-07 Michael Meeks <michael@edenproject.org>
* src/expr.c (do_expr_decode_tree): Add vital translation stuff.
* src/parser.y (return_name): Created.
(try_symbol): Add name lookup.
* src/eval.c (add_tree_deps): Calculate name dependencies if at all
possible.
* src/main.c (gnumeric_main): Add expr_name_init.
* src/expr.c (expr_tree_new_name, do_expr_tree_unref),
(eval_expr, do_expr_decode_tree, do_expr_tree_invalidate_references),
(do_expr_tree_fixup_references, expr_dump_tree): Add OPER_NAME support
in every case just after OPER_FUNCALL.
* src/expr.h: Add ExprName struct, include and OPER_NAME.
* src/Makefile.am (GNUMERIC_BASE_SOURCES): Added expr_name.[ch]
1999-07-07 Miguel de Icaza <miguel@gnu.org>
* configure.in (EXTRA_GNOME_CFLAGS): Assemble all the flags we
......
1999-07-08 Michael Meeks <michael@edenproject.org>
* src/Gnumeric.idl: Removed : GNOME::Unknown from Workbook so
people can compile for now.
1999-07-07 Michael Meeks <michael@edenproject.org>
* src/expr.c (do_expr_decode_tree): Add vital translation stuff.
* src/parser.y (return_name): Created.
(try_symbol): Add name lookup.
* src/eval.c (add_tree_deps): Calculate name dependencies if at all
possible.
* src/main.c (gnumeric_main): Add expr_name_init.
* src/expr.c (expr_tree_new_name, do_expr_tree_unref),
(eval_expr, do_expr_decode_tree, do_expr_tree_invalidate_references),
(do_expr_tree_fixup_references, expr_dump_tree): Add OPER_NAME support
in every case just after OPER_FUNCALL.
* src/expr.h: Add ExprName struct, include and OPER_NAME.
* src/Makefile.am (GNUMERIC_BASE_SOURCES): Added expr_name.[ch]
1999-07-07 Miguel de Icaza <miguel@gnu.org>
* configure.in (EXTRA_GNOME_CFLAGS): Assemble all the flags we
......
1999-07-08 Michael Meeks <michael@edenproject.org>
* ms-formula-read.c (ms_excel_parse_formula): Add magic 0x17
for special undocumented 'Addin Name' support.
1999-07-07 Michael Meeks <michael@edenproject.org>
* ms-excel-read.c (ms_excel_read_name): Fix crucial bug
in name_def_data calc.
(ms_excel_read_name): Removed all 'internal_names' stuff.
1999-07-06 Michael Meeks <michael@edenproject.org>
* ms-formula-read.c (ms_excel_parse_formula): PTG_NAME:
......
......@@ -568,9 +568,14 @@ biff_format_data_destroy (gpointer key, BiffFormatData *d, gpointer userdata)
typedef struct {
char *name;
ExprTree *formula;
guint8 *data;
guint16 len;
enum { BNDStore, BNDName } type;
union {
ExprName *name;
struct {
guint8 *data;
guint16 len;
} store;
} v;
} BiffNameData;
static int externsheet = 0;
......@@ -581,18 +586,18 @@ biff_name_data_new (ExcelWorkbook *wb, char *name,
{
BiffNameData *bnd = g_new (BiffNameData, 1);
bnd->name = name;
bnd->formula = NULL; /* parse it late */
bnd->type = BNDStore;
if (formula) {
bnd->data = g_malloc (len);
memcpy (bnd->data, formula, len);
bnd->len = len;
bnd->v.store.data = g_malloc (len);
memcpy (bnd->v.store.data, formula, len);
bnd->v.store.len = len;
} else {
bnd->data = NULL;
bnd->len = 0;
bnd->v.store.data = NULL;
bnd->v.store.len = 0;
}
#ifndef NO_DEBUG_EXCEL
if (ms_excel_read_debug>1) {
if (ms_excel_read_debug > 1) {
printf ("EXTERNNAME : %x %x '%s'\n", externsheet,
wb->name_data->len, bnd->name);
}
......@@ -612,11 +617,39 @@ biff_name_data_get_name (ExcelSheet *sheet, guint16 idx)
a = sheet->wb->name_data;
if (a && idx < a->len && (bnd = g_ptr_array_index (a, idx))) {
/* if (!bnd->formula) .... wait for it.
bnd->formula = ms_excel_parse_formula (sheet->wb, sheet, bnd->data, 0, 0,
FALSE, bnd->len, NULL);
return bnd->formula;*/
return expr_tree_new_constant (value_new_string (bnd->name));
if (bnd->type == BNDStore && bnd->v.store.data) {
char *duff = "Some Error";
ExprTree *tree;
tree = ms_excel_parse_formula (sheet->wb, sheet, bnd->v.store.data, 0, 0,
FALSE, bnd->v.store.len, NULL);
if (!tree) { /* OK so it's a special 'AddIn' name */
bnd->type = BNDName;
g_free (bnd->v.store.data);
bnd->v.name = NULL;
printf ("Serious error parsing '%s'\n", bnd->name);
} else {
bnd->type = BNDName;
g_free (bnd->v.store.data);
bnd->v.name = expr_name_add (sheet->wb->gnum_wb, bnd->name,
tree, &duff);
if (!bnd->v.name)
printf ("Error: '%s' on name '%s'\n", duff,
bnd->name);
#ifndef NO_DEBUG_EXCEL
else if (ms_excel_read_debug > 0) {
EvalPosition ep;
printf ("Parsed name : '%s' = '%s'\n", bnd->name,
tree?expr_decode_tree (tree, eval_pos_init (
&ep, sheet->gnum_sheet, 0, 0)):"error");
}
#endif
}
}
if (bnd->type == BNDName && bnd->v.name)
return expr_tree_new_name (bnd->v.name);
else
return expr_tree_new_constant (value_new_string (bnd->name));
} else
return expr_tree_new_constant (value_new_string("Unknown name"));
}
......@@ -629,13 +662,10 @@ biff_name_data_destroy (BiffNameData *bnd)
if (bnd->name)
g_free (bnd->name);
bnd->name = NULL;
if (bnd->formula)
expr_tree_unref (bnd->formula);
bnd->formula = NULL;
if (bnd->data)
g_free (bnd->data);
bnd->data = NULL;
bnd->len = 0;
if (bnd->type == BNDStore) {
if (bnd->v.store.data)
g_free (bnd->v.store.data);
}
g_free (bnd);
}
......@@ -1663,7 +1693,6 @@ ms_excel_workbook_new (eBiff_version ver)
ans->name_data = g_ptr_array_new ();
ans->format_data = g_hash_table_new ((GHashFunc)biff_guint16_hash,
(GCompareFunc)biff_guint16_equal);
ans->internal_names = g_ptr_array_new ();
ans->palette = ms_excel_default_palette ();
ans->ver = ver;
ans->global_strings = NULL;
......@@ -1744,9 +1773,6 @@ ms_excel_workbook_destroy (ExcelWorkbook *wb)
wb);
g_hash_table_destroy (wb->format_data);
if (wb->internal_names)
g_ptr_array_free (wb->internal_names, TRUE);
if (wb->palette && wb->palette != ms_excel_default_palette ())
ms_excel_palette_destroy (wb->palette);
......@@ -1816,7 +1842,7 @@ ms_excel_read_name (BiffQuery *q, ExcelSheet *sheet)
#endif
guint8 name_len = BIFF_GET_GUINT8 (q->data + 3);
guint16 name_def_len = BIFF_GET_GUINT16 (q->data + 4);
guint8 *name_def_data = q->data + 15 + name_def_len;
guint8 *name_def_data = q->data + 15 + name_len;
#if 0
guint16 sheet_idx = BIFF_GET_GUINT16 (q->data + 6);
guint16 ixals = BIFF_GET_GUINT16 (q->data + 8); /* dup */
......@@ -1830,7 +1856,7 @@ ms_excel_read_name (BiffQuery *q, ExcelSheet *sheet)
/* g_assert (ixals==sheet_idx); */
ptr = q->data + 14;
if (name_len == 1 && *ptr <= 0x0c) {
if (0 && name_len == 1 && *ptr <= 0x0c) {
switch (*ptr)
{
case 0x00 : name = "Consolidate_Area"; break;
......@@ -1861,13 +1887,17 @@ ms_excel_read_name (BiffQuery *q, ExcelSheet *sheet)
ptr+= help_txt_len;
status_txt = biff_get_text (ptr, status_txt_len, NULL);
printf ("Name record : '%s', '%s', '%s', '%s', '%s'\n",
name ? name : "(null)",
menu_txt ? menu_txt : "(null)",
descr_txt ? descr_txt : "(null)",
help_txt ? help_txt : "(null)",
status_txt ? status_txt : "(null)");
dump (name_def_data, name_def_len);
#ifndef NO_DEBUG_EXCEL
if (ms_excel_read_debug > 0) {
printf ("Name record : '%s', '%s', '%s', '%s', '%s'\n",
name ? name : "(null)",
menu_txt ? menu_txt : "(null)",
descr_txt ? descr_txt : "(null)",
help_txt ? help_txt : "(null)",
status_txt ? status_txt : "(null)");
dump (name_def_data, name_def_len);
}
#endif
/* Unpack flags */
fn_grp_idx = (flags&0xfc0)>>6;
......@@ -1887,14 +1917,6 @@ ms_excel_read_name (BiffQuery *q, ExcelSheet *sheet)
printf (" BinData");
printf ("\n");
/* g_ptr_array_add (wb->internal_names, name); */
#ifndef NO_DEBUG_EXCEL
if (ms_excel_read_debug>1) {
printf ("NAME %d : %s\n", sheet->wb->internal_names->len, name);
}
#endif
biff_name_data_new (sheet->wb, name, name_def_data, name_def_len);
if (menu_txt)
g_free (menu_txt);
......@@ -1908,8 +1930,8 @@ ms_excel_read_name (BiffQuery *q, ExcelSheet *sheet)
/* S59D7E.HTM */
static void
ms_excel_externname(BiffQuery *q,
ExcelSheet *sheet)
ms_excel_externname (BiffQuery *q,
ExcelSheet *sheet)
{
char *externname;
guint8 *defn;
......
......@@ -654,7 +654,7 @@ make_function (PARSE_LIST **stack, int fn_idx, int numargs)
char const *f_name;
if (!tmp ||
tmp->oper != OPER_CONSTANT ||
tmp->u.constant->type != VALUE_STRING){
tmp->u.constant->type != VALUE_STRING) {
if (tmp) expr_tree_unref (tmp);
parse_list_free (&args);
parse_list_push (stack,
......@@ -665,8 +665,7 @@ make_function (PARSE_LIST **stack, int fn_idx, int numargs)
f_name = tmp->u.constant->v.str->str;
name = symbol_lookup (global_symbol_table, f_name);
if (!name)
{
if (!name) {
FunctionCategory *cat =
function_get_category (_("Unknown Function"));
/*
......@@ -1207,8 +1206,15 @@ ms_excel_parse_formula (ExcelWorkbook *wb, ExcelSheet *sheet, guint8 *mem,
case FORMULA_PTG_ERR:
{
const char *errtxt =
biff_get_error_text (BIFF_GET_GUINT8(cur));
guint8 err_num;
const char *errtxt;
err_num = BIFF_GET_GUINT8 (cur);
if (err_num == 0x17) { /* Magic 'Addin Name' error number */
parse_list_free (&stack);
return NULL; /* To tell name stuff */
}
errtxt = biff_get_error_text (err_num);
/* FIXME: we do not have errors as first-class values, so we
must build an expression that generates the error. */
parse_list_push (&stack, expr_tree_new_error (errtxt));
......
......@@ -188,7 +188,7 @@ module GNOME {
};
interface Workbook : GNOME::Unknown {
interface Workbook {
exception NameExists {};
Sheet sheet_new (in string name) raises (NameExists);
......
......@@ -91,6 +91,8 @@ GNUMERIC_BASE_SOURCES = \
eval.c \
expr.c \
expr.h \
expr-name.c \
expr-name.h \
file.c \
file.h \
formats.h \
......
......@@ -238,6 +238,13 @@ add_tree_deps (Cell *cell, ExprTree *tree)
add_tree_deps (cell, l->data);
return;
case OPER_NAME:
if (tree->u.name->builtin) {
/* FIXME: insufficiently flexible dependancy code (?) */
} else
add_tree_deps (cell, tree->u.name->t.exprt);
return;
case OPER_ARRAY:
if (tree->u.array.x != 0 || tree->u.array.y != 0){
/* Non-corner cells depend on the corner */
......
......@@ -238,6 +238,13 @@ add_tree_deps (Cell *cell, ExprTree *tree)
add_tree_deps (cell, l->data);
return;
case OPER_NAME:
if (tree->u.name->builtin) {
/* FIXME: insufficiently flexible dependancy code (?) */
} else
add_tree_deps (cell, tree->u.name->t.exprt);
return;
case OPER_ARRAY:
if (tree->u.array.x != 0 || tree->u.array.y != 0){
/* Non-corner cells depend on the corner */
......
......@@ -299,6 +299,21 @@ expr_parse_string (const char *expr, const EvalPosition *fp,
return NULL;
}
ExprTree *
expr_tree_new_name (const ExprName *name)
{
ExprTree *ans;
ans = g_new (ExprTree, 1);
if (!ans)
return NULL;
ans->ref_count = 1;
ans->oper = OPER_NAME;
ans->u.name = name;
return ans;
}
/*ExprTree *
expr_tree_new (void)
......@@ -423,6 +438,9 @@ do_expr_tree_unref (ExprTree *tree)
break;
}
case OPER_NAME:
break;
case OPER_ANY_BINARY:
do_expr_tree_unref (tree->u.binary.value_a);
do_expr_tree_unref (tree->u.binary.value_b);
......@@ -1602,6 +1620,9 @@ eval_expr (FunctionEvalInfo *s, ExprTree *tree)
case OPER_FUNCALL:
return eval_funcall (s, tree);
case OPER_NAME:
return eval_expr_name (s, tree->u.name);
case OPER_VAR: {
Sheet *cell_sheet;
CellRef *ref;
......@@ -1750,10 +1771,12 @@ do_expr_decode_tree (ExprTree *tree, const EvalPosition *fp, int paren_level)
{ "/", 4, 1, 0 },
{ "^", 6, 0, 1 },
{ "&", 2, 1, 0 },
{ NULL, 0, 0, 0 },
{ NULL, 0, 0, 0 },
{ NULL, 0, 0, 0 },
{ "-", 5, 0, 0 }
{ NULL, 0, 0, 0 }, /* Funcall */
{ NULL, 0, 0, 0 }, /* Name */
{ NULL, 0, 0, 0 }, /* Constant */
{ NULL, 0, 0, 0 }, /* Var */
{ "-", 5, 0, 0 },
{ NULL, 0, 0, 0 } /* Array */
};
int op;
Sheet *sheet = fp->sheet;
......@@ -1846,6 +1869,9 @@ do_expr_decode_tree (ExprTree *tree, const EvalPosition *fp, int paren_level)
return g_strconcat (fd->name, "()", NULL);
}
case OPER_NAME:
return g_strdup (tree->u.name->name->str);
case OPER_VAR: {
CellRef *cell_ref;
......@@ -2043,6 +2069,9 @@ do_expr_tree_invalidate_references (ExprTree *src, const struct expr_tree_frob_r
}
}
case OPER_NAME:
return NULL;
case OPER_VAR: {
CellRef cr = src->u.ref; /* Copy a structure, not a pointer. */
......@@ -2270,6 +2299,9 @@ do_expr_tree_fixup_references (ExprTree *src, const struct expr_tree_frob_refere
}
}
case OPER_NAME:
return NULL;
case OPER_VAR: {
CellRef cr = src->u.ref; /* Copy a structure, not a pointer. */
......@@ -2423,6 +2455,10 @@ expr_dump_tree (ExprTree *tree)
printf ("Function call: %s\n", s->str);
break;
case OPER_NAME:
printf ("Name : %s\n", tree->u.name->name->str);
break;
case OPER_ANY_BINARY:
expr_dump_tree (tree->u.binary.value_a);
expr_dump_tree (tree->u.binary.value_b);
......
......@@ -2,15 +2,21 @@
#define GNUMERIC_EXPR_H
/* Forward references for structures. */
typedef struct _Value Value;
typedef struct _Value Value;
typedef struct _ExprTree ExprTree;
typedef struct _CellRef CellRef;
typedef struct _CellRef CellRef;
typedef struct _ArrayRef ArrayRef;
typedef struct _ExprName ExprName;
typedef struct _EvalPosition EvalPosition;
typedef struct _ErrorMessage ErrorMessage;
typedef struct _FunctionEvalInfo FunctionEvalInfo;
#include "sheet.h"
#include "symbol.h"
#include "numbers.h"
#include "str.h"
#include "expr-name.h"
/* Some utility constants to make sure we all spell correctly */
/* TODO : These should really be const, but can't until error_string changes */
......@@ -22,6 +28,7 @@ extern char *gnumeric_err_NAME;
extern char *gnumeric_err_NUM;
extern char *gnumeric_err_NA;
/* Warning: if you add something here, see do_expr_decode_tree ! */
typedef enum {
OPER_EQUAL, /* Compare value equal */
OPER_GT, /* Compare value greather than */
......@@ -39,6 +46,8 @@ typedef enum {
OPER_FUNCALL, /* Function call invocation */
OPER_NAME, /* Name reference */
OPER_CONSTANT, /* Constant value */
OPER_VAR, /* Cell content lookup (variable) */
OPER_NEG, /* Sign inversion */
......@@ -116,12 +125,14 @@ struct _ExprTree {
Symbol *symbol;
GList *arg_list;
} function;
struct {
ExprTree *value_a;
ExprTree *value_b;
} binary;
const ExprName *name;
ExprTree *value;
CellRef ref;
......@@ -141,9 +152,7 @@ typedef enum {
/*
* Function parameter structures
*/
typedef struct _EvalPosition EvalPosition;
typedef struct _ErrorMessage ErrorMessage;
typedef struct _FunctionEvalInfo FunctionEvalInfo;
/* FIXME: Should be tastefuly concealed */
typedef struct _FunctionDefinition FunctionDefinition;
......@@ -230,6 +239,19 @@ struct _FunctionDefinition {
} fn;
};
/*
* Built in / definable sheet names.
*/
struct _ExprName {
String *name;
Workbook *wb;
gboolean builtin;
union {
ExprTree *expr_tree;
FunctionArgs *expr_func;
} t;
};
void cell_get_abs_col_row (const CellRef *cell_ref,
int eval_col, int eval_row,
int *col, int *row);
......@@ -248,6 +270,7 @@ ExprTree *expr_tree_new_constant (Value *v);
ExprTree *expr_tree_new_unary (Operation op, ExprTree *e);
ExprTree *expr_tree_new_binary (ExprTree *l, Operation op, ExprTree *r);
ExprTree *expr_tree_new_funcall (Symbol *sym, GList *args);
ExprTree *expr_tree_new_name (const ExprName *name);
ExprTree *expr_tree_new_var (const CellRef *cr);
ExprTree *expr_tree_new_error (const char *txt);
ExprTree *expr_tree_array_formula (int const x, int const y, int const rows,
......
......@@ -82,6 +82,7 @@ gnumeric_main (void *closure, int argc, char *argv [])
global_symbol_init ();
constants_init ();
functions_init ();
expr_name_init ();
plugins_init ();
/* The statically linked in file formats */
......
......@@ -82,6 +82,7 @@ gnumeric_main (void *closure, int argc, char *argv [])
global_symbol_init ();
constants_init ();
functions_init ();
expr_name_init ();
plugins_init ();
/* The statically linked in file formats */
......
......@@ -352,6 +352,19 @@ return_symbol (Symbol *sym)
return type;
}
static int
return_name (ExprName *exprn)
{
ExprTree *e = p_new (ExprTree);
e->ref_count = 1;
e->oper = OPER_NAME;
e->u.name = exprn;
yylval.tree = e;
return CONSTANT;
}
/**
* try_symbol:
* @string: the string to try.
......@@ -384,6 +397,13 @@ try_symbol (char *string, gboolean try_cellref)
return return_sheetref (sheet);
}
{ /* Name ? */
ExprName *name = expr_name_lookup (parser_sheet->workbook,
string);
if (name)
return return_name (name);
}
return make_string_return (string);
}
......
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