Commit 310538a8 authored by Michael Meeks's avatar Michael Meeks

start of sheet/name/global name scoping.

Various fixes.
parent 4fe16541
1999-09-26 Michael Meeks <michael@nuclecu.unam.mx>
* src/workbook.c (workbook_do_destroy): rename name clean.
* src/sheet.c (sheet_destroy): add name clean.
* configure.in: Add vital conditional for libole2.
* src/xml-io.c (xml_write_names): Write from a GList.
(xml_workbook_write): pass a GList. (xml_read_names): add sheet arg.
(xml_workbook_read): upd. name read. (xml_sheet_read): add sheet name
read. (xml_sheet_write): write names.
Clean several redundant forward references.
* src/main.c: make startup_files const.
* src/expr-name.c: Major API hack for scoped names.
(expr_name_add, expr_name_create, expr_name_lookup): add docs
+ scoped names. (expr_name_value): setup correct 'wb' for parsing.
* src/parser.y (try_symbol): Add comment + hard code to workbook
scope.
1999-09-26 Miguel de Icaza <miguel@gnu.org>
* src/sheet-object.c (sheet_set_mode_type): Protect Bonobo code
......
Gnumeric 0.38
Arturo:
* Split libole2 + test program.
* Large excel file support > 8Mb.
Michael:
* Start of sheet/workbook/global name scoping.
Gnumeric 0.36
Jody:
......
1999-09-26 Michael Meeks <michael@nuclecu.unam.mx>
* src/workbook.c (workbook_do_destroy): rename name clean.
* src/sheet.c (sheet_destroy): add name clean.
* configure.in: Add vital conditional for libole2.
* src/xml-io.c (xml_write_names): Write from a GList.
(xml_workbook_write): pass a GList. (xml_read_names): add sheet arg.
(xml_workbook_read): upd. name read. (xml_sheet_read): add sheet name
read. (xml_sheet_write): write names.
Clean several redundant forward references.
* src/main.c: make startup_files const.
* src/expr-name.c: Major API hack for scoped names.
(expr_name_add, expr_name_create, expr_name_lookup): add docs
+ scoped names. (expr_name_value): setup correct 'wb' for parsing.
* src/parser.y (try_symbol): Add comment + hard code to workbook
scope.
1999-09-26 Miguel de Icaza <miguel@gnu.org>
* src/sheet-object.c (sheet_set_mode_type): Protect Bonobo code
......
......@@ -157,6 +157,7 @@ if $try_bonobo; then
fi
fi
AM_CONDITIONAL(BONOBO, $have_bonobo)
AM_CONDITIONAL(LIBOLE2_PUBLIC_LIBRARY, false)
dnl ******************************
dnl GnomePrint checking
......
1999-09-26 Michael Meeks <michael@nuclecu.unam.mx>
* ms-excel-read.c (biff_name_data_new): add sheet scope.
(ms_excel_read_name): Use the 2nd 'copy' of idx since its the
only valid one. (biff_name_data_get_name): Create using scope.
1999-09-26 Michael Meeks <michael@nuclecu.unam.mx>
* Makefile.am: remove the 'ole' test program
......
......@@ -624,6 +624,7 @@ biff_format_data_destroy (gpointer key, BiffFormatData *d, gpointer userdata)
typedef struct {
char const *name;
gboolean sheet_scope;
enum { BNDStore, BNDName } type;
union {
ExprName *name;
......@@ -640,11 +641,13 @@ static void
biff_name_data_new (ExcelWorkbook *wb, char const *name,
guint16 const sheet_index,
guint8 const *formula, guint16 const len,
gboolean const external)
gboolean const external,
gboolean const sheet_scope)
{
BiffNameData *bnd = g_new (BiffNameData, 1);
bnd->name = name;
bnd->type = BNDStore;
bnd->name = name;
bnd->sheet_scope = sheet_scope;
bnd->type = BNDStore;
if (formula) {
bnd->v.store.data = g_malloc (len);
memcpy (bnd->v.store.data, formula, len);
......@@ -700,9 +703,14 @@ biff_name_data_get_name (ExcelSheet *sheet, int idx)
} 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->sheet_scope)
bnd->v.name = expr_name_add (NULL, sheet->gnum_sheet,
bnd->name,
tree, &duff);
else
bnd->v.name = expr_name_add (sheet->wb->gnum_wb, NULL,
bnd->name,
tree, &duff);
if (!bnd->v.name)
printf ("Error: '%s' on name '%s'\n", duff,
bnd->name);
......@@ -1915,10 +1923,7 @@ ms_excel_read_name (BiffQuery *q, ExcelSheet *sheet)
guint8 name_len = MS_OLE_GET_GUINT8 (q->data + 3);
guint16 name_def_len;
guint8 *name_def_data;
guint16 sheet_idx = MS_OLE_GET_GUINT16 (q->data + 6);
#if 0
guint16 ixals = MS_OLE_GET_GUINT16 (q->data + 8); /* dup */
#endif
guint16 sheet_idx = MS_OLE_GET_GUINT16 (q->data + 8);
guint8 menu_txt_len = MS_OLE_GET_GUINT8 (q->data + 10);
guint8 descr_txt_len = MS_OLE_GET_GUINT8 (q->data + 11);
guint8 help_txt_len = MS_OLE_GET_GUINT8 (q->data + 12);
......@@ -2010,7 +2015,7 @@ ms_excel_read_name (BiffQuery *q, ExcelSheet *sheet)
biff_name_data_new (sheet->wb, name, sheet_idx,
name_def_data, name_def_len,
FALSE);
FALSE, (sheet_idx != 0));
if (menu_txt)
g_free (menu_txt);
if (descr_txt)
......@@ -2042,7 +2047,7 @@ ms_excel_externname (BiffQuery *q, ExcelSheet *sheet)
MS_OLE_GET_GUINT8(q->data), NULL);
}
biff_name_data_new (sheet->wb, name, 0, defn, defnlen, TRUE);
biff_name_data_new (sheet->wb, name, 0, defn, defnlen, TRUE, FALSE);
}
/**
......
......@@ -88,7 +88,8 @@ fill_list (state_t *state)
state->selected = -1;
state->expr_names = names = expr_name_list (state->wb, FALSE);
/* FIXME: scoping issues here */
state->expr_names = names = expr_name_list (state->wb, NULL, FALSE);
while (names) {
ExprName *expr_name = names->data;
......@@ -165,11 +166,13 @@ grab_text_ok (state_t *state, gboolean update_list)
if (!name || (name[0] == '\0'))
return TRUE;
expr_name = expr_name_lookup (state->wb, name);
/* FIXME: we need to be able to select names scope ideally */
expr_name = expr_name_lookup (state->wb, NULL, name);
if (expr_name)
expr_name_remove (expr_name);
expr_name = expr_name_create (state->wb, name,
/* FIXME: and here */
expr_name = expr_name_create (state->wb, NULL, name,
value, &error);
if (expr_name == NULL) {
......
......@@ -14,11 +14,28 @@
#include "eval.h"
#include "expr-name.h"
/* We don't expect that many names ! */
/* We don't expect that many global names ! */
static GList *global_names = NULL;
/*
* FIXME: when we sort out the parser's scope problems
* we'll fix this.
*/
static Workbook *
get_real_wb (Workbook *wb, Sheet *sheet)
{
if (wb)
return wb;
if (sheet)
return sheet->workbook;
g_warning ("duff name scope");
return NULL;
}
ExprName *
expr_name_lookup (Workbook *wb, char const *name)
expr_name_lookup (Workbook *wb, Sheet *sheet, char const *name)
{
GList *p = global_names;
......@@ -31,6 +48,7 @@ expr_name_lookup (Workbook *wb, char const *name)
return expr_name;
p = g_list_next (p);
}
if (wb)
p = wb->names;
while (p) {
......@@ -40,12 +58,23 @@ expr_name_lookup (Workbook *wb, char const *name)
return expr_name;
p = g_list_next (p);
}
if (sheet)
p = sheet->names;
while (p) {
ExprName *expr_name = p->data;
g_return_val_if_fail (expr_name != NULL, 0);
if (g_strcasecmp (expr_name->name->str, name) == 0)
return expr_name;
p = g_list_next (p);
}
return NULL;
}
static ExprName *
add_real (Workbook *wb, const char *name, gboolean builtin,
ExprTree *expr_tree, void *expr_func)
add_real (Workbook *wb, Sheet *sheet, const char *name,
gboolean builtin, ExprTree *expr_tree, void *expr_func)
{
ExprName *expr_name;
......@@ -54,6 +83,7 @@ add_real (Workbook *wb, const char *name, gboolean builtin,
expr_name = g_new (ExprName,1);
expr_name->wb = wb;
expr_name->sheet = sheet;
expr_name->name = string_get (name);
g_return_val_if_fail (expr_name->name != NULL, NULL);
......@@ -117,21 +147,35 @@ name_refer_circular (const char *name, ExprTree *expr)
return FALSE;
}
/**
* expr_name_add:
* @wb:
* @sheet:
* @name:
* @expr:
* @error_msg:
*
* Parses a texual name in @value, and enters the value
* either as a workbook name if @sheet == NULL or a sheet
* name if @wb == NULL. If both wb & sheet == NULL then
* it must be a truly global name.
*
* Return value:
**/
ExprName *
expr_name_add (Workbook *wb, char const *name,
expr_name_add (Workbook *wb, Sheet *sheet, char const *name,
ExprTree *expr, char **error_msg)
{
ExprName *expr_name;
g_return_val_if_fail (wb != NULL, 0);
g_return_val_if_fail (name != NULL, 0);
g_return_val_if_fail (expr != NULL, 0);
if ((expr_name = expr_name_lookup (wb, name))) {
if ((expr_name = expr_name_lookup (wb, sheet, name))) {
*error_msg = _("already defined");
return NULL;
} else if (!wb) {
*error_msg = _("no workbook");
} else if (!wb && !sheet) {
*error_msg = _("no scope");
return NULL;
}
......@@ -140,44 +184,68 @@ expr_name_add (Workbook *wb, char const *name,
return NULL;
}
expr_name = add_real (wb, name, FALSE, expr, NULL);
expr_name = add_real (wb, sheet, name, FALSE, expr, NULL);
if (wb)
wb->names = g_list_append (wb->names, expr_name);
else if (sheet)
sheet->names = g_list_append (sheet->names, expr_name);
else
global_names = g_list_append (global_names, expr_name);
return expr_name;
}
/**
* expr_name_create:
* @wb:
* @sheet:
* @name:
* @value:
* @error_msg:
*
* Parses a texual name in @value, and enters the value
* either as a workbook name if @sheet == NULL or a sheet
* name if @wb == NULL.
*
* Return value: The created ExprName.
**/
ExprName *
expr_name_create (Workbook *wb, const char *name,
expr_name_create (Workbook *wb, Sheet *sheet, const char *name,
const char *value, char **error_msg)
{
ExprTree *tree;
ParsePosition pp;
tree = expr_parse_string (value,
parse_pos_init (&pp, wb, 0, 0),
parse_pos_init (&pp,
get_real_wb (wb, sheet),
0, 0),
NULL, error_msg);
if (!tree)
return NULL;
return expr_name_add (wb, name, tree, error_msg);
return expr_name_add (wb, sheet, name, tree, error_msg);
}
void
expr_name_remove (ExprName *expr_name)
{
Workbook *wb;
Sheet *sheet;
g_return_if_fail (expr_name != NULL);
if (expr_name->wb) {
printf ("Removing from workbook\n");
wb = expr_name->wb;
g_assert (g_list_find (wb->names, expr_name) != NULL);
wb->names = g_list_remove (wb->names, expr_name);
g_assert (g_list_find (wb->names, expr_name) == NULL);
} else if (expr_name->sheet) {
sheet = expr_name->sheet;
g_assert (g_list_find (sheet->names, expr_name) != NULL);
sheet->names = g_list_remove (sheet->names, expr_name);
g_assert (g_list_find (sheet->names, expr_name) == NULL);
} else {
printf ("Removing from globals\n");
/* FIXME -- this code is not right. */
......@@ -187,7 +255,7 @@ expr_name_remove (ExprName *expr_name)
g_assert (g_list_find (wb->names, expr_name) == NULL);
}
printf ("Removing : '%s'\n", expr_name->name->str);
/* printf ("Removing : '%s'\n", expr_name->name->str);*/
if (expr_name->name)
string_unref (expr_name->name);
expr_name->name = NULL;
......@@ -196,14 +264,32 @@ expr_name_remove (ExprName *expr_name)
expr_name->t.expr_tree)
expr_tree_unref (expr_name->t.expr_tree);
expr_name->wb = NULL;
expr_name->wb = NULL;
expr_name->sheet = NULL;
expr_name->t.expr_tree = NULL;
g_free (expr_name);
}
void
expr_name_clean (Workbook *wb)
expr_name_clean_sheet (Sheet *sheet)
{
GList *p = global_names;
GList *next ;
while (p) {
ExprName *expr_name = p->data;
g_return_if_fail (expr_name);
next = g_list_next (p);
if ((!sheet || expr_name->sheet == sheet))
expr_name_remove (expr_name);
p = next;
}
}
void
expr_name_clean_workbook (Workbook *wb)
{
GList *p = global_names;
GList *next ;
......@@ -220,7 +306,7 @@ expr_name_clean (Workbook *wb)
}
GList *
expr_name_list (Workbook *wb, gboolean builtins_too)
expr_name_list (Workbook *wb, Sheet *sheet, gboolean builtins_too)
{
GList *l;
g_return_val_if_fail (wb != NULL, NULL);
......@@ -242,7 +328,9 @@ expr_name_value (const ExprName *expr_name)
ParsePosition pp;
if (!expr_name->builtin) {
parse_pos_init (&pp, expr_name->wb, 0, 0);
parse_pos_init (&pp, get_real_wb (expr_name->wb,
expr_name->sheet),
0, 0);
val = expr_decode_tree (expr_name->t.expr_tree, &pp);
} else
val = g_strdup (_("Builtin"));
......@@ -313,7 +401,7 @@ expr_name_init (void)
/* Not in global function table though ! */
while (builtins[lp].name) {
ExprName *expr_name;
expr_name = add_real (NULL, builtins[lp].name, TRUE, NULL,
expr_name = add_real (NULL, NULL, builtins[lp].name, TRUE, NULL,
builtins[lp].fn);
global_names = g_list_append (global_names, expr_name);
lp++;
......
......@@ -13,24 +13,26 @@
void expr_name_init (void);
/* Attach a name to a workbook */
ExprName *expr_name_add (Workbook *wb, const char *name,
ExprName *expr_name_add (Workbook *wb, Sheet *sheet,
const char *name,
ExprTree *expr, char **error_msg);
/* Can only be used when we have a current sheet */
ExprName *expr_name_create (Workbook *wb, const char *name,
/* Convenience function to parse the name */
ExprName *expr_name_create (Workbook *wb, Sheet *sheet, const char *name,
const char *value, char **error_msg);
/* Lookup - use sparingly */
ExprName *expr_name_lookup (Workbook *wb, const char *name);
ExprName *expr_name_lookup (Workbook *wb, Sheet *sheet, const char *name);
/* Remove a name from a workbook */
/* Remove a name from its parent workbook / sheet */
void expr_name_remove (ExprName *exprn);
/* Remove a workbook's names */
void expr_name_clean (Workbook *wb);
/* Destroy the local scope's names */
void expr_name_clean_workbook (Workbook *wb);
void expr_name_clean_sheet (Sheet *sheet);
/* Get all a workbooks names */
GList *expr_name_list (Workbook *wb, gboolean builtins_too);
GList *expr_name_list (Workbook *wb, Sheet *sheet, gboolean builtins_too);
/* Evaluate the name's expression */
Value *eval_expr_name (FunctionEvalInfo *ei, const ExprName *exprn);
......
......@@ -162,6 +162,7 @@ struct _FunctionDefinition {
struct _ExprName {
String *name;
Workbook *wb;
Sheet *sheet;
gboolean builtin;
union {
ExprTree *expr_tree;
......
......@@ -34,8 +34,8 @@ extern int ms_excel_color_debug;
extern int ms_excel_chart_debug;
static char *dump_file_name = NULL;
static char **startup_files = NULL;
static char *startup_glade_file = NULL;
static const char **startup_files = NULL;
poptContext ctx;
......
......@@ -34,8 +34,8 @@ extern int ms_excel_color_debug;
extern int ms_excel_chart_debug;
static char *dump_file_name = NULL;
static char **startup_files = NULL;
static char *startup_glade_file = NULL;
static const char **startup_files = NULL;
poptContext ctx;
......
......@@ -462,7 +462,11 @@ try_symbol (char *string, gboolean try_cellref_and_number)
}
{ /* Name ? */
ExprName *name = expr_name_lookup (parser_wb,
/*
* FIXME: we need a good bit of work to get sheet
* scope names working well
*/
ExprName *name = expr_name_lookup (parser_wb, NULL,
string);
if (name)
return return_name (name);
......
......@@ -2386,6 +2386,8 @@ sheet_destroy (Sheet *sheet)
g_hash_table_foreach (sheet->cell_hash, cell_hash_free_key, NULL);
g_hash_table_destroy (sheet->cell_hash);
expr_name_clean_sheet (sheet);
if (sheet->dependency_hash)
g_hash_table_destroy (sheet->dependency_hash);
......
......@@ -120,6 +120,9 @@ struct _Sheet {
/* The list of cells that have a comment */
GList *comment_list;
/* User defined names */
GList *names;
double last_zoom_factor_used;
/*
......
......@@ -325,7 +325,7 @@ workbook_do_destroy (Workbook *wb)
symbol_table_destroy (wb->symbol_names);
expr_name_clean (wb);
expr_name_clean_workbook (wb);
workbook_do_destroy_private (wb);
......
......@@ -36,11 +36,6 @@ typedef struct {
xmlNodePtr style_node; /* The node where we insert the styles */
} parse_xml_context_t;
static Sheet *xml_sheet_read (parse_xml_context_t *ctxt, xmlNodePtr tree);
static xmlNodePtr xml_sheet_write (parse_xml_context_t *ctxt, Sheet *sheet);
static gboolean xml_workbook_read (Workbook *wb, parse_xml_context_t *ctxt, xmlNodePtr tree);
static xmlNodePtr xml_workbook_write (parse_xml_context_t *ctxt, Workbook *wb);
/*
* Internal stuff: xml helper functions.
*/
......@@ -715,14 +710,10 @@ xml_write_style (parse_xml_context_t *ctxt, Style *style, int style_idx)
}
static xmlNodePtr
xml_write_names (parse_xml_context_t *ctxt, Workbook *wb)
xml_write_names (parse_xml_context_t *ctxt, GList *names)
{
GList *names, *m;
xmlNodePtr cur;
g_return_val_if_fail (wb != NULL, NULL);
m = names = expr_name_list (wb, FALSE);
GList *m;
xmlNodePtr cur;
if (!names)
return NULL;
......@@ -748,16 +739,16 @@ xml_write_names (parse_xml_context_t *ctxt, Workbook *wb)
xmlAddChild (cur, tmp);
names = g_list_next (names);
}
g_list_free (m);
return cur;
}
static void
xml_read_names (parse_xml_context_t *ctxt, xmlNodePtr tree, Workbook *wb)
xml_read_names (parse_xml_context_t *ctxt, xmlNodePtr tree, Workbook *wb,
Sheet *sheet)
{
xmlNodePtr child;
g_return_if_fail (wb != NULL);
g_return_if_fail (ctxt != NULL);
g_return_if_fail (tree != NULL);
......@@ -781,7 +772,7 @@ xml_read_names (parse_xml_context_t *ctxt, xmlNodePtr tree, Workbook *wb)
g_return_if_fail (txt != NULL);
g_return_if_fail (!strcmp (bits->name, "value"));
if (!expr_name_create (wb, name, txt, &error))
if (!expr_name_create (wb, sheet, name, txt, &error))
g_warning (error);
g_free (txt);
......@@ -1672,6 +1663,10 @@ xml_sheet_write (parse_xml_context_t *ctxt, Sheet *sheet)
sprintf (str, "%f", sheet->last_zoom_factor_used);
xmlNewChild (cur, ctxt->ns, "Zoom", str);
child = xml_write_names (ctxt, sheet->names);
if (child)
xmlAddChild (cur, child);
/*
* Print Information
*/
......@@ -1875,6 +1870,10 @@ xml_sheet_read (parse_xml_context_t *ctxt, xmlNodePtr tree)
xml_read_cols_info (ctxt, ret, tree);
xml_read_rows_info (ctxt, ret, tree);
child = xml_search_child (tree, "Names");
if (child)
xml_read_names (ctxt, child, NULL, ret);
child = xml_search_child (tree, "Objects");
if (child != NULL){
objects = child->childs;
......@@ -1923,7 +1922,7 @@ xml_workbook_write (parse_xml_context_t *ctxt, Workbook *wb)
if (child)
xmlAddChild (cur, child);
child = xml_write_names (ctxt, wb);
child = xml_write_names (ctxt, wb->names);
if (child)
xmlAddChild (cur, child);
......@@ -2045,14 +2044,14 @@ xml_workbook_read (Workbook *wb, parse_xml_context_t *ctxt, xmlNodePtr tree)
*/
child = xml_search_child (tree, "Names");
if (child)
xml_read_names (ctxt, child, wb);
xml_read_names (ctxt, child, wb, NULL);
child = xml_search_child (tree, "Sheets");
/*
* Pass 2: read the contents
*/
c = child->childs;
while (c != NULL){
while (c != NULL) {
sheet = xml_sheet_read (ctxt, c);
c = c->next;
}
......
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