Commit c47d0d1a authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

fix handling of 26 & 27. The docs are confusing. The cached data is


2002-09-26  Jody Goldberg <jody@gnome.org>

	* ms-formula-read.c (ms_excel_parse_formula) : fix handling of 26 & 27.
	  The docs are confusing.  The cached data is appended not to the the
	  subexpression but to the entire string.  While we're here add a stub
	  for tables.
parent 0fe3e64c
2002-09-26 Jody Goldberg <jody@gnome.org>
* ms-formula-read.c (ms_excel_parse_formula) : fix handling of 26 & 27.
The docs are confusing. The cached data is appended not to the the
subexpression but to the entire string. While we're here add a stub
for tables.
2002-09-26 Jody Goldberg <jody@gnome.org>
* ms-formula-read.c (ms_excel_parse_formula) : supply handling of
......
......@@ -529,6 +529,23 @@ ms_excel_init_margins (ExcelSheet *esheet)
print_info_set_margins (pi, short_points, short_points, points, points);
}
static void
excel_shared_formula_free (XLSharedFormula *sf)
{
if (sf != NULL) {
g_free (sf->data);
g_free (sf);
}
}
static void
excel_data_table_free (XLDataTable *dt)
{
if (dt != NULL) {
g_free (dt->data);
g_free (dt);
}
}
static ExcelSheet *
ms_excel_sheet_new (ExcelWorkbook *wb, char const *sheet_name)
{
......@@ -546,12 +563,15 @@ ms_excel_sheet_new (ExcelWorkbook *wb, char const *sheet_name)
if (sheet == NULL)
sheet = sheet_new (wb->gnum_wb, sheet_name);
esheet->wb = wb;
esheet->gnum_sheet = sheet;
esheet->freeze_panes = FALSE;
esheet->shared_formulae =
g_hash_table_new ((GHashFunc)&cellpos_hash,
(GCompareFunc)&cellpos_cmp);
esheet->wb = wb;
esheet->gnum_sheet = sheet;
esheet->freeze_panes = FALSE;
esheet->shared_formulae = g_hash_table_new_full (
(GHashFunc)&cellpos_hash, (GCompareFunc)&cellpos_cmp,
NULL, (GDestroyNotify) &excel_shared_formula_free);
esheet->tables = g_hash_table_new_full (
(GHashFunc)&cellpos_hash, (GCompareFunc)&cellpos_cmp,
NULL, (GDestroyNotify) &excel_data_table_free);
ms_excel_init_margins (esheet);
ms_container_init (&esheet->container, &vtbl, &wb->container);
......@@ -1971,16 +1991,6 @@ ms_excel_sheet_insert (ExcelSheet *esheet, int xfidx,
}
}
static gboolean
biff_shared_formula_destroy (gpointer key, BiffSharedFormula *sf,
gpointer userdata)
{
if (sf != NULL)
g_free (sf->data);
g_free (sf);
return TRUE;
}
static GnmExpr const *
ms_excel_formula_shared (BiffQuery *q, ExcelSheet *esheet, Cell *cell)
{
......@@ -1989,7 +1999,7 @@ ms_excel_formula_shared (BiffQuery *q, ExcelSheet *esheet, Cell *cell)
gboolean is_array;
GnmExpr const *expr;
guint8 const *data;
BiffSharedFormula *sf;
XLSharedFormula *sf;
if (!ms_biff_query_peek_next (q, &opcode) ||
((0xff & opcode) != BIFF_SHRFMLA && (0xff & opcode) != BIFF_ARRAY)) {
......@@ -2012,7 +2022,7 @@ ms_excel_formula_shared (BiffQuery *q, ExcelSheet *esheet, Cell *cell)
esheet->wb, esheet, r.start.col, r.start.row,
data, data_len, !is_array, NULL);
sf = g_new (BiffSharedFormula, 1);
sf = g_new (XLSharedFormula, 1);
/* WARNING: Do NOT use the upper left corner as the hashkey.
* For some bizzare reason XL appears to sometimes not
......@@ -2030,7 +2040,6 @@ ms_excel_formula_shared (BiffQuery *q, ExcelSheet *esheet, Cell *cell)
d (1, printf ("Shared formula, extent %s\n", range_name (&r)););
/* Whack in the hash for later */
g_hash_table_insert (esheet->shared_formulae, &sf->key, sf);
g_return_val_if_fail (expr != NULL, FALSE);
......@@ -2240,7 +2249,7 @@ ms_excel_read_formula (BiffQuery *q, ExcelSheet *esheet)
cell_queue_recalc (cell);
}
BiffSharedFormula *
XLSharedFormula *
ms_excel_sheet_shared_formula (ExcelSheet const *esheet,
CellPos const *key)
{
......@@ -2251,6 +2260,17 @@ ms_excel_sheet_shared_formula (ExcelSheet const *esheet,
return g_hash_table_lookup (esheet->shared_formulae, key);
}
XLDataTable *
ms_excel_sheet_data_table (ExcelSheet const *esheet,
CellPos const *key)
{
g_return_val_if_fail (esheet != NULL, NULL);
d (5, printf ("FIND DATA TABLE: %s\n", cellpos_as_string (key)););
return g_hash_table_lookup (esheet->tables, key);
}
static void
ms_excel_sheet_insert_val (ExcelSheet *esheet, int xfidx,
int col, int row, Value *v)
......@@ -2334,12 +2354,13 @@ ms_excel_sheet_destroy (ExcelSheet *esheet, gboolean destroy_gnumeric_sheet)
if (esheet == NULL)
return;
if (esheet->shared_formulae != NULL) {
g_hash_table_foreach_remove (esheet->shared_formulae,
(GHRFunc)biff_shared_formula_destroy,
esheet);
g_hash_table_destroy (esheet->shared_formulae);
esheet->shared_formulae = NULL;
}
if (esheet->tables != NULL) {
g_hash_table_destroy (esheet->tables);
esheet->tables = NULL;
}
if (destroy_gnumeric_sheet && esheet->gnum_sheet != NULL) {
sheet_destroy (esheet->gnum_sheet);
......@@ -2359,6 +2380,7 @@ ms_wb_parse_expr (MSContainer *container, guint8 const *data, int length)
dummy_sheet.wb = (ExcelWorkbook *)container;
dummy_sheet.gnum_sheet = NULL;
dummy_sheet.shared_formulae = NULL;
dummy_sheet.tables = NULL;
return ms_sheet_parse_expr_internal (&dummy_sheet, data, length);
}
......
......@@ -22,7 +22,7 @@ typedef struct _ExcelSheet
Sheet *gnum_sheet;
struct _ExcelWorkbook *wb;
GHashTable *shared_formulae;
GHashTable *shared_formulae, *tables;
gboolean freeze_panes : 1;
} ExcelSheet;
......@@ -42,11 +42,19 @@ typedef struct {
guint8 *data;
guint32 data_len;
gboolean is_array;
} BiffSharedFormula;
} XLSharedFormula;
typedef struct {
CellPos key;
guint8 *data;
guint32 data_len;
} XLDataTable;
/* Use the upper left corner as the key to a collection of shared formulas */
BiffSharedFormula *ms_excel_sheet_shared_formula (ExcelSheet const *sheet,
XLSharedFormula *ms_excel_sheet_shared_formula (ExcelSheet const *sheet,
CellPos const *key);
XLDataTable *ms_excel_sheet_data_table (ExcelSheet const *esheet,
CellPos const *key);
typedef struct _ExcelPalette
{
......
......@@ -544,9 +544,8 @@ static GnmExpr const *
parse_list_pop (GnmExprList **list)
{
/* Get the head */
GnmExprList *tmp = g_slist_nth (*list, 0);
if (tmp != NULL)
{
GnmExprList *tmp = *list;
if (tmp != NULL) {
GnmExpr const *ans = tmp->data;
*list = g_slist_remove (*list, ans);
d (5, printf ("Pop 0x%x\n", (int)ans););
......@@ -691,16 +690,15 @@ static GnmExprOp const binary_ops [] = {
GNM_EXPR_OP_DIV, /* 0x06, ptgDiv */
GNM_EXPR_OP_EXP, /* 0x07, ptgPower */
GNM_EXPR_OP_CAT, /* 0x08, ptgConcat */
GNM_EXPR_OP_LT, /* 0x09, ptgLT */
GNM_EXPR_OP_LT, /* 0x09, ptgLT */
GNM_EXPR_OP_LTE, /* 0x0a, ptgLTE */
GNM_EXPR_OP_EQUAL, /* 0x0b, ptgEQ */
GNM_EXPR_OP_GTE, /* 0x0c, ptgGTE */
GNM_EXPR_OP_GT, /* 0x0d, ptgGT */
GNM_EXPR_OP_GT, /* 0x0d, ptgGT */
GNM_EXPR_OP_NOT_EQUAL, /* 0x0e, ptgNE */
/* FIXME: These need implementing ... */
GNM_EXPR_OP_INTERSECT, /* 0x0f, ptgIsect : Intersection */
GNM_EXPR_OP_ADD, /* 0x10, ptgUnion : Union */
0, /* handled elsewhere 0x10, ptgUnion : Union */
GNM_EXPR_OP_RANGE_CTOR /* 0x11, ptgRange : Range */
};
......@@ -763,7 +761,7 @@ ms_excel_parse_formula (ExcelWorkbook const *ewb,
switch (ptgbase) {
case FORMULA_PTG_EXPR: {
GnmExpr const *expr;
BiffSharedFormula *sf;
XLSharedFormula *sf;
CellPos top_left;
top_left.row = GSF_LE_GET_GUINT16 (cur+0);
......@@ -804,6 +802,10 @@ ms_excel_parse_formula (ExcelWorkbook const *ewb,
break;
}
case FORMULA_PTG_TBL :
ptg_length = 4;
break;
case FORMULA_PTG_ADD : case FORMULA_PTG_SUB :
case FORMULA_PTG_MULT : case FORMULA_PTG_DIV :
case FORMULA_PTG_EXP :
......@@ -812,7 +814,7 @@ ms_excel_parse_formula (ExcelWorkbook const *ewb,
case FORMULA_PTG_EQUAL :
case FORMULA_PTG_GTE : case FORMULA_PTG_GT :
case FORMULA_PTG_NOT_EQUAL :
case FORMULA_PTG_INTERSECT : case FORMULA_PTG_UNION :
case FORMULA_PTG_INTERSECT :
case FORMULA_PTG_RANGE : {
GnmExpr const *r = parse_list_pop (&stack);
GnmExpr const *l = parse_list_pop (&stack);
......@@ -823,6 +825,24 @@ ms_excel_parse_formula (ExcelWorkbook const *ewb,
break;
}
case FORMULA_PTG_UNION : {
GnmExpr const *r = parse_list_pop (&stack);
GnmExpr const *l = parse_list_pop (&stack);
/* not exactly legal, but should be reasonable
* XL has union operator we have sets.
*/
if (l->any.oper != GNM_EXPR_OP_SET) {
GnmExprList *args = gnm_expr_list_prepend (NULL, r);
args = gnm_expr_list_prepend (args, l);
parse_list_push (&stack, gnm_expr_new_set (args));
} else {
gnm_expr_list_append (l->set.set, r);
parse_list_push (&stack, l);
}
break;
}
case FORMULA_PTG_U_PLUS :
case FORMULA_PTG_U_MINUS :
case FORMULA_PTG_PERCENT :
......@@ -1292,17 +1312,6 @@ ms_excel_parse_formula (ExcelWorkbook const *ewb,
}
case FORMULA_PTG_MEM_AREA :
/* read the sub expression */
ptg_length = GSF_LE_GET_GUINT16 (cur+4),
parse_list_push (&stack, ms_excel_parse_formula (
ewb, esheet, fn_col, fn_row, cur+6, ptg_length,
shared, array_element));
/* ignore the cached rectangles */
ptg_length += 6 /* 4 reserved 2 len */ + 2 + /* ref count */
6 * GSF_LE_GET_GUINT16 (cur + ptg_length);
break;
case FORMULA_PTG_MEM_ERR :
/* ignore this, we handle at run time */
ptg_length = 6;
......@@ -1313,7 +1322,6 @@ ms_excel_parse_formula (ExcelWorkbook const *ewb,
ptg_length = 2;
break;
case FORMULA_PTG_NAME_X : { /* FIXME: Not using sheet_idx at all ... */
GnmExpr const *tree;
guint16 extn_name_idx; /* 1 based */
......
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