Commit 5c5f628f authored by Jody Goldberg's avatar Jody Goldberg

Minor reformating/reorg to improve readability

parent 07999d52
......@@ -8,6 +8,8 @@
records when we expect a cell.
(ms_excel_read_formula) : Clarify error message.
(biff_name_data_new) : Partial support for local vs global names.
(biff_name_data_get_name) : Reformat to improve readability.
(ms_excel_read_formula) : Ditto.
* ms-chart.c (ms_excel_biff_dimensions) : Don't print unless
we're debugging.
......
......@@ -216,11 +216,13 @@ biff_get_text (guint8 const *pos, guint32 length, guint32 *byte_length)
high_byte = (header & 0x1) != 0;
ext_str = (header & 0x4) != 0;
rich_str = (header & 0x8) != 0;
#if 0
if (rich_str || ext_str)
g_warning ("Panic: ahhh... sill string");
#endif
/* This can wait until the big unicode clean ;-) */
if (!already_warned) {
g_warning ("Fixme: eventualy we need to re-architecture string reading");
g_warning ("EXCEL: we need to re-architecture string reading to support unicode & rich text.");
already_warned = TRUE;
}
ptr+=1;
......@@ -674,44 +676,50 @@ biff_name_data_get_name (ExcelSheet *sheet, int idx)
a = sheet->wb->name_data;
if (a && 0 <= idx && idx < a->len && (bnd = g_ptr_array_index (a, idx))) {
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;
} 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);
if (a == NULL || idx < 0 || a->len <= idx ||
(bnd = g_ptr_array_index (a, idx)) == NULL) {
g_warning ("EXCEL : %x (of %x) UNKNOWN name\n", idx, a->len);
return expr_tree_new_constant(value_new_string("Unknown name"));
}
if (bnd->type == BNDStore && bnd->v.store.data) {
char *duff = "Some Error";
ExprTree *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;
} 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 > 1) {
ParsePosition ep;
printf ("Parsed name : '%s' = '%s'\n", bnd->name,
tree?expr_decode_tree (tree, parse_pos_init (
&ep, sheet->wb->gnum_wb, 0, 0)):"error");
}
#endif
else if (ms_excel_read_debug > 1) {
ParsePosition ep;
parse_pos_init (&ep, sheet->wb->gnum_wb, 0, 0);
printf ("Parsed name : '%s' = '%s'\n",
bnd->name, tree
? expr_decode_tree (tree, &ep)
: "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
{
g_warning ("EXCEL : %x (of %x) UNKNOWN name\n", idx, a->len);
return expr_tree_new_constant (value_new_string("Unknown name"));
}
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));
}
static void
......@@ -729,7 +737,6 @@ biff_name_data_destroy (BiffNameData *bnd)
g_free (bnd);
}
EXCEL_PALETTE_ENTRY const excel_default_palette[EXCEL_DEF_PAL_LEN] = {
/* These were generated by creating a sheet and
* modifying the 1st color cell and saving. This
......@@ -739,26 +746,26 @@ EXCEL_PALETTE_ENTRY const excel_default_palette[EXCEL_DEF_PAL_LEN] = {
* red and blue. It is too much effort to retype this.
* So I'll leave it in this odd format for now.
*/
{ 0,0,0 }, { 255,255,255 }, { 0,0,255 }, { 0,255,0 },
{ 255,0,0 }, { 0,255,255 }, { 255,0,255 }, { 255,255,0},
{ 0, 0, 0}, {255,255,255}, { 0, 0,255}, { 0,255, 0},
{255, 0, 0}, { 0,255,255}, {255, 0,255}, {255,255, 0},
{ 0,0,128 }, { 0,128,0 }, { 128,0,0 }, { 0,128,128 },
{ 128,0,128 }, { 128,128,0 }, { 192,192,192}, {128,128,128},
{ 0, 0,128}, { 0,128,0}, {128, 0, 0}, { 0,128,128},
{128, 0,128}, {128,128,0}, {192,192,192}, {128,128,128},
{ 255,153,153}, {102,51,153}, {204,255,255}, {255,255,204 },
{ 102,0,102 }, { 128,128,255 }, {204,102,0}, {255,204,204 },
{255,153,153}, {102, 51,153}, {204,255,255}, {255,255,204},
{102, 0,102}, {128,128,255}, {204,102, 0}, {255,204,204},
{ 128,0,0 }, { 255,0,255 }, { 0,255,255 }, { 255,255,0 },
{ 128,0,128 }, { 0,0,128 }, { 128,128,0 }, { 255,0,0 },
{128, 0, 0}, {255, 0,255}, { 0,255,255}, {255,255, 0},
{128, 0,128}, { 0, 0,128}, {128,128, 0}, {255, 0, 0},
{255,204,0}, {255,255,204}, {204,255,204}, { 153,255,255 },
{255,204,153}, {204,153,255}, {255,153,204}, {153,204,255},
{255,204, 0}, {255,255,204}, {204,255,204}, {153,255,255},
{255,204,153}, {204,153,255}, {255,153,204}, {153,204,255},
{255,102,51}, {204,204,51}, {0,204,153}, {0,204,255},
{0,153,255}, {0,102,255}, {153,102,102}, {150,150,150},
{255,102, 51}, {204,204, 51}, { 0,204,153}, { 0,204,255},
{ 0,153,255}, { 0,102,255}, {153,102,102}, {150,150,150},
{102,51,0}, {102,153,51}, {0,51,0}, {0,51,51},
{0,51,153}, {102,51,153}, {153,51,51}, {51,51,51}
{102, 51, 0}, {102,153, 51}, { 0, 51, 0}, { 0, 51, 51},
{ 0, 51,153}, {102, 51,153}, {153, 51, 51}, { 51, 51, 51}
};
static ExcelPalette *
......@@ -776,15 +783,15 @@ ms_excel_default_palette ()
#endif
pal = (ExcelPalette *) g_malloc (sizeof (ExcelPalette));
pal->length = entries;
pal->red = g_new (int, entries);
pal->red = g_new (int, entries);
pal->green = g_new (int, entries);
pal->blue = g_new (int, entries);
pal->blue = g_new (int, entries);
pal->gnum_cols = g_new (StyleColor *, entries);
while (--entries >= 0) {
pal->red[entries] = excel_default_palette[entries].r;
pal->green[entries] = excel_default_palette[entries].g;
pal->blue[entries] = excel_default_palette[entries].b;
pal->red[entries] = excel_default_palette[entries].r;
pal->green[entries] = excel_default_palette[entries].g;
pal->blue[entries] = excel_default_palette[entries].b;
pal->gnum_cols[entries] = NULL;
}
}
......@@ -1580,8 +1587,10 @@ ms_excel_read_formula (BiffQuery *q, ExcelSheet *sheet)
}
if (is_string) {
char *v = NULL;
if (ms_biff_query_next (q) && q->opcode == BIFF_STRING) {
guint16 code;
if (ms_biff_query_peek_next(q, &code) && code == BIFF_STRING) {
char *v;
ms_biff_query_next (q);
/*
* NOTE : the Excel developers kit docs are
* WRONG. There is an article that
......@@ -1589,20 +1598,22 @@ ms_excel_read_formula (BiffQuery *q, ExcelSheet *sheet)
* unicode format rather than the pure
* length version the docs describe.
*/
v = biff_get_text (q->data + 2,
MS_OLE_GET_GUINT16(q->data),
NULL);
}
if (v) {
val = value_new_string (v);
g_free (v);
v = biff_get_text (q->data + 2,
MS_OLE_GET_GUINT16(q->data),
NULL);
if (v) {
val = value_new_string (v);
g_free (v);
} else {
g_warning ("EXCEL : invalid STRING record");
val = value_new_string ("INVALID STRING");
}
} else {
/*
* Docs say that there should be a STRING
* record here
*/
g_warning ("Excel import error, "
"missing STRING record");
g_warning ("EXCEL : missing STRING record");
val = value_new_string ("MISSING STRING");
}
}
......@@ -1611,13 +1622,8 @@ ms_excel_read_formula (BiffQuery *q, ExcelSheet *sheet)
g_warning ("EXCEL : Invalid state. Missing Value?");
val = value_new_string ("MISSING Value");
}
if (cell->value != NULL) {
#if 0
/* We always give cells values nowadays. */
g_warning ("EXCEL : How does cell already have value?\n");
#endif
if (cell->value != NULL)
value_release (cell->value);
}
/* Set value */
cell->value = val;
......
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