Commit 260f6e3b authored by Michael Meeks's avatar Michael Meeks

daniel's Excel Name export,

start of 'gb' autoconf bits.
parent e0758632
No preview for this file type
......@@ -14,6 +14,9 @@ Jody:
* 1st pass at borders.
* Improve edit popup.
Daniel:
* Excel Name export.
--------------------------------------------------------------------------
Gnumeric 0.39
......
No preview for this file type
......@@ -10,6 +10,7 @@
#undef HAVE_GTK_SELECTION_ADD_TARGET
#undef HAVE_GUILE
#undef ENABLE_BONOBO
#undef ENABLE_GB
#undef HAVE_IEEEFP_H
#undef ENABLE_GNOME
......
......@@ -171,8 +171,51 @@ if $try_bonobo; then
fi
fi
AM_CONDITIONAL(BONOBO, $have_bonobo)
dnl ******************************
dnl Kludge for Libole2 virtual link.
dnl ******************************
AM_CONDITIONAL(LIBOLE2_PUBLIC_LIBRARY, false)
dnl ******************************
dnl Check for GB
dnl ******************************
try_gb=true
gb=
gb_msg=no
have_gb=false
AC_ARG_WITH(gb,
[--{with,without}-gb Compile with Gb support or without it],
if test x$withval = xno; then
try_gb=false
fi
)
if $try_gb; then
AC_MSG_CHECKING(for Gb > 0.0)
if gnome-config --libs gb > /dev/null 2>&1; then
vers=`gnome-config --modversion gb`
case $vers
in
gb-0.[[0]]) gb_ok=false ;;
*) gb_ok=true ;;
esac
else
gb_ok=false
fi
if $gb_ok; then
AC_MSG_RESULT(found)
AC_DEFINE(ENABLE_GB)
have_gb=true
gb=gb
gb_msg=yes
else
AC_MSG_RESULT(not found)
fi
fi
AM_CONDITIONAL(GB, $have_gb)
dnl ******************************
dnl GnomePrint checking
dnl ******************************
......@@ -201,8 +244,8 @@ else
AC_MSG_ERROR(Did not find libGlade installed)
fi
EXTRA_GNOME_LIBS=`gnome-config --libs gnomeui print libglade $bonobo`
EXTRA_GNOME_CFLAGS=`gnome-config --cflags gnomeui print libglade $bonobo`
EXTRA_GNOME_LIBS=`gnome-config --libs gnomeui print libglade $bonobo $gb`
EXTRA_GNOME_CFLAGS=`gnome-config --cflags gnomeui print libglade $bonobo $gb`
AC_SUBST(EXTRA_GNOME_LIBS)
AC_SUBST(EXTRA_GNOME_CFLAGS)
......@@ -255,3 +298,4 @@ Configuration:
Bonobo Support: ${bonobo_msg}
"
dnl GB Support: ${gb_msg}
1999-10-30 Daniel Risacher <magnus@alum.mit.edu>
* ms-excel-read.c (biff_get_text): tiny fix to debugging code
(biff_name_data_new): actually return the new data
(biff_name_data_get_name): Moved code that adds names to the
workbook to ms_excel_read_name()
(ms_excel_read_name): Add name definitions to workbook when
definition is read, rather than when used.
Formatting.
* ms-formula-write.c (write_ref): minor change to comply with
spec for references.
(write_node): Handle OPER_NAME.
Formatting.
* ms-excel-write.c (write_names): New function. Writes name
definitions. Called from write_workbook().
Formatting.
* ms-excel-write.h: Added names to struct _ExcelWorkbook
1999-10-30 Michael Meeks <mmeeks@gnu.org>
* ms-excel-read.c (ms_excel_get_xf): kill const.
......
......@@ -153,7 +153,7 @@ biff_get_text (guint8 const *pos, guint32 length, guint32 *byte_length)
#ifndef NO_DEBUG_EXCEL
if (ms_excel_read_debug > 1) {
printf ("String :\n");
dump (pos, length);
dump (pos, length+1);
}
#endif
......@@ -598,7 +598,7 @@ typedef struct {
static int externsheet = 0;
static void
static BiffNameData*
biff_name_data_new (ExcelWorkbook *wb, char const *name,
guint16 const sheet_index,
guint8 const *formula, guint16 const len,
......@@ -629,6 +629,7 @@ biff_name_data_new (ExcelWorkbook *wb, char const *name,
dump (bnd->v.store.data, bnd->v.store.len);
#endif
g_ptr_array_add (wb->name_data, bnd);
return bnd;
}
ExprTree *
......@@ -649,44 +650,6 @@ biff_name_data_get_name (ExcelSheet *sheet, int idx)
}
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);
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);
#ifndef NO_DEBUG_EXCEL
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
......@@ -901,7 +864,7 @@ ms_excel_palette_destroy (ExcelPalette *pal)
g_free (pal->red);
g_free (pal->green);
g_free (pal->blue);
for (lp=0;lp<pal->length;lp++)
for (lp = 0; lp < pal->length; lp++)
if (pal->gnum_cols[lp])
style_color_unref (pal->gnum_cols[lp]);
g_free (pal->gnum_cols);
......@@ -1847,7 +1810,7 @@ ms_excel_workbook_detach (ExcelWorkbook *wb, ExcelSheet *ans)
if (!workbook_detach_sheet (wb->gnum_wb, ans->gnum_sheet, FALSE))
return FALSE;
}
for (idx=0;idx<wb->excel_sheets->len;idx++)
for (idx = 0; idx < wb->excel_sheets->len; idx++)
if (g_ptr_array_index (wb->excel_sheets, idx) == ans) {
g_ptr_array_index (wb->excel_sheets, idx) = NULL;
return TRUE;
......@@ -1876,21 +1839,21 @@ ms_excel_workbook_destroy (ExcelWorkbook *wb)
g_hash_table_destroy (wb->boundsheet_data_by_index);
g_hash_table_destroy (wb->boundsheet_data_by_stream);
if (wb->XF_cell_records)
for (lp=0;lp<wb->XF_cell_records->len;lp++)
for (lp = 0; lp < wb->XF_cell_records->len; lp++)
biff_xf_data_destroy (g_ptr_array_index (wb->XF_cell_records, lp));
g_ptr_array_free (wb->XF_cell_records, TRUE);
if (wb->name_data)
for (lp=0;lp<wb->name_data->len;lp++)
for (lp = 0; lp < wb->name_data->len; lp++)
biff_name_data_destroy (g_ptr_array_index (wb->name_data, lp));
g_ptr_array_free (wb->name_data, TRUE);
for (lp=0;lp<wb->blips->len;lp++)
for (lp = 0; lp < wb->blips->len; lp++)
ms_escher_blip_destroy (g_ptr_array_index(wb->blips, lp));
g_ptr_array_free (wb->blips, TRUE);
wb->blips = NULL;
for (lp=0;lp<wb->charts->len;lp++)
for (lp = 0; lp < wb->charts->len; lp++)
gnumeric_chart_destroy (g_ptr_array_index(wb->charts, lp));
g_ptr_array_free (wb->charts, TRUE);
wb->charts = NULL;
......@@ -1944,7 +1907,7 @@ biff_get_rk (guint8 const *ptr)
/* Think carefully about big/little endian issues before
changing this code. */
for (lp=0;lp<4;lp++) {
for (lp = 0; lp < 4; lp++) {
tmp[lp+4]=(lp>0)?ptr[lp]:(ptr[lp]&0xfc);
tmp[lp]=0;
}
......@@ -1982,6 +1945,7 @@ ms_excel_read_name (BiffQuery *q, ExcelSheet *sheet)
guint8 status_txt_len = MS_OLE_GET_GUINT8 (q->data + 13);
char *name, *menu_txt, *descr_txt, *help_txt, *status_txt;
guint8 const *ptr;
BiffNameData *bnd;
#if 0
dump_biff (q);
......@@ -2065,9 +2029,49 @@ ms_excel_read_name (BiffQuery *q, ExcelSheet *sheet)
}
#endif
biff_name_data_new (sheet->wb, name, sheet_idx,
name_def_data, name_def_len,
FALSE, (sheet_idx != 0));
bnd = biff_name_data_new (sheet->wb, name, sheet_idx,
name_def_data, name_def_len,
FALSE, (sheet_idx != 0));
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);
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);
#ifndef NO_DEBUG_EXCEL
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 (menu_txt)
g_free (menu_txt);
if (descr_txt)
......@@ -2314,7 +2318,7 @@ ms_excel_read_cell (BiffQuery *q, ExcelSheet *sheet)
/* NOTE : seems like this is inclusive firstcol, inclusive lastcol */
if (lastcol >= SHEET_MAX_COLS)
lastcol = SHEET_MAX_COLS-1;
for (lp = firstcol ; lp <= lastcol ; ++lp)
for (lp = firstcol; lp <= lastcol; ++lp)
sheet_col_set_width (sheet->gnum_sheet, lp,
width);
break;
......@@ -2548,6 +2552,8 @@ ms_excel_read_sheet (ExcelSheet *sheet, BiffQuery *q, ExcelWorkbook *wb)
#ifndef NO_DEBUG_EXCEL
if (ms_excel_read_debug > 1)
printf ("Blank sheet\n");
if (ms_excel_read_debug > 5)
printf ("BIFF_EOF\n");
#endif
if (ms_excel_workbook_detach (sheet->wb, sheet)) {
ms_excel_sheet_destroy (sheet);
......@@ -3164,7 +3170,7 @@ ms_excel_read_workbook (Workbook *workbook, MsOle *file)
wb->extern_sheets = g_new (BiffExternSheetData, numXTI+1);
for (cnt=0; cnt < numXTI; cnt++) {
for (cnt = 0; cnt < numXTI; cnt++) {
wb->extern_sheets[cnt].sup_idx = MS_OLE_GET_GUINT16(q->data + 2 + cnt*6 + 0);
wb->extern_sheets[cnt].first_tab = MS_OLE_GET_GUINT16(q->data + 2 + cnt*6 + 2);
wb->extern_sheets[cnt].last_tab = MS_OLE_GET_GUINT16(q->data + 2 + cnt*6 + 4);
......
......@@ -97,7 +97,7 @@ biff_put_text (BiffPut *bp, const char *txt, eBiff_version ver,
ms_biff_put_var_write (bp, data, off);
/* You got it coming */
for (lp=0; lp<len;lp++) {
for (lp = 0; lp < len; lp++) {
MS_OLE_SET_GUINT16 (data, txt[lp]);
ms_biff_put_var_write (bp, data, unicode?2:1);
}
......@@ -106,8 +106,8 @@ biff_put_text (BiffPut *bp, const char *txt, eBiff_version ver,
/* An attempt at efficiency */
/* chunks = len/BLK_LEN;
pos = 0;
for (lpc=0;lpc<chunks;lpc++) {
for (lp=0;lp<BLK_LEN;lp++,pos++)
for (lpc = 0; lpc < chunks; lpc++) {
for (lp = 0; lp < BLK_LEN; lp++, pos++)
data[lp] = txt[pos];
data[BLK_LEN] = '\0';
printf ("Writing chunk '%s'\n", data);
......@@ -115,7 +115,7 @@ biff_put_text (BiffPut *bp, const char *txt, eBiff_version ver,
}
len = len-pos;
if (len > 0) {
for (lp=0;lp<len;lp++,pos++)
for (lp = 0; lp < len; lp++, pos++)
data[lp] = txt[pos];
data[lp] = '\0';
printf ("Writing chunk '%s'\n", data);
......@@ -260,9 +260,6 @@ write_externsheets (BiffPut *bp, ExcelWorkbook *wb, ExcelSheet *ignore)
return;
}
if (num_sheets == 1) /* Not enough sheets for extern records */
return;
if (ignore) /* Strangely needed */
num_sheets--;
......@@ -417,7 +414,7 @@ int
ms_excel_write_get_sheet_idx (ExcelWorkbook *wb, Sheet *gnum_sheet)
{
guint lp;
for (lp=0;lp<wb->sheets->len;lp++) {
for (lp = 0; lp < wb->sheets->len; lp++) {
ExcelSheet *sheet = g_ptr_array_index (wb->sheets, lp);
g_return_val_if_fail (sheet, 0);
if (sheet->gnum_sheet == gnum_sheet)
......@@ -513,7 +510,7 @@ write_palette (BiffPut *bp, ExcelWorkbook *wb)
MS_OLE_SET_GUINT16 (data, EXCEL_DEF_PAL_LEN); /* Entries */
ms_biff_put_var_write (bp, data, 2);
for (i=0;i<EXCEL_DEF_PAL_LEN;i++) {
for (i = 0; i < EXCEL_DEF_PAL_LEN; i++) {
r = excel_default_palette[i].r;
g = excel_default_palette[i].g;
b = excel_default_palette[i].b;
......@@ -620,7 +617,7 @@ write_formats (BiffPut *bp, ExcelWorkbook *wb)
guint8 data[64];
int lp;
for (lp=0;lp<8;lp++) { /* FIXME: Magic minimum formats */
for (lp = 0; lp < 8; lp++) { /* FIXME: Magic minimum formats */
guint fidx = magic_num[lp];
char *fmt;
formats->StyleFormat_to_idx = g_hash_table_new (g_direct_hash,
......@@ -673,7 +670,7 @@ write_xf_record (BiffPut *bp, Style *style, eBiff_version ver, int hack)
guint8 data[256];
int lp;
for (lp=0;lp<250;lp++)
for (lp = 0; lp < 250; lp++)
data[lp] = 0;
if (ver >= eBiffV7)
......@@ -770,6 +767,52 @@ xf_free (XF *xf)
}
}
static void
write_names (BiffPut *bp, ExcelWorkbook *wb)
{
Workbook* gwb = wb->gnum_wb;
GList *names = gwb->names;
ExcelSheet *sheet;
/* excel crashes if this isn't here and the names have Ref3Ds */
if (names)
write_externsheets (bp, wb, NULL);
sheet = g_ptr_array_index(wb->sheets,0);
while (names) {
guint8 data[20];
guint32 len, name_len, i;
ExprName *expr_name = names->data;
char *text;
g_return_if_fail (expr_name != NULL);
for (i = 0; i < 20; i++) data[i] = 0;
text = expr_name->name->str;
ms_biff_put_var_next (bp, BIFF_NAME);
name_len = strlen(expr_name->name->str);
MS_OLE_SET_GUINT8 (data+3, name_len); /* name_len */
/* This code will only work for eBiffV7. */
ms_biff_put_var_write (bp, data, 14);
biff_put_text (bp, text, wb->ver, FALSE, AS_PER_VER);
ms_biff_put_var_seekto (bp, 14+name_len);
len = ms_excel_write_formula (bp, sheet,
expr_name->t.expr_tree,
0, 0);
g_assert (len <= 0xffff);
ms_biff_put_var_seekto (bp, 4);
MS_OLE_SET_GUINT16 (data, len);
ms_biff_put_var_write (bp, data, 2);
ms_biff_put_commit (bp);
g_ptr_array_add (wb->names, g_strdup(text));
names = g_list_next(names);
}
}
int
ms_excel_write_map_errcode (Value const * const v)
{
......@@ -1311,7 +1354,7 @@ write_sheet_tail (BiffPut *bp, ExcelSheet *sheet)
data = ms_biff_put_len_next (bp, BIFF_GCW, 34);
{
int lp;
for (lp=0;lp<34;lp++)
for (lp = 0; lp < 34; lp++)
MS_OLE_SET_GUINT8 (data+lp, 0xff);
MS_OLE_SET_GUINT32 (data, 0xfffd0020);
}
......@@ -1432,13 +1475,13 @@ write_sheet (BiffPut *bp, ExcelSheet *sheet)
printf ("Saving sheet '%s' geom (%d, %d)\n", sheet->gnum_sheet->name,
maxx, maxy);
#endif
for (y=0;y<maxy;y++) {
for (y = 0; y < maxy; y++) {
guint32 run_size = 0;
MsOlePos start;
start = write_rowinfo (bp, y, maxx);
for (x=0;x<maxx;x++) {
for (x = 0; x < maxx; x++) {
Cell *cell = sheet_cell_get (sheet->gnum_sheet, x, y);
if (!cell)
run_size++;
......@@ -1461,7 +1504,7 @@ write_sheet (BiffPut *bp, ExcelSheet *sheet)
biff_eof_write (bp);
}
static void
void
new_sheet (ExcelWorkbook *wb, Sheet *value)
{
ExcelSheet *sheet = g_new (ExcelSheet, 1);
......@@ -1537,6 +1580,7 @@ write_workbook (BiffPut *bp, Workbook *gwb, eBiff_version ver)
wb->ver = ver;
wb->gnum_wb = gwb;
wb->sheets = g_ptr_array_new ();
wb->names = g_ptr_array_new ();
sheets = workbook_sheets (gwb);
while (sheets) {
......@@ -1558,7 +1602,7 @@ write_workbook (BiffPut *bp, Workbook *gwb, eBiff_version ver)
write_xf (bp, wb);
wb->pal = write_palette (bp, wb);
for (lp = 0;lp < wb->sheets->len; lp++) {
for (lp = 0; lp < wb->sheets->len; lp++) {
s = g_ptr_array_index (wb->sheets, lp);
s->boundsheetPos = biff_boundsheet_write_first
(bp, eBiffTWorksheet,
......@@ -1567,6 +1611,7 @@ write_workbook (BiffPut *bp, Workbook *gwb, eBiff_version ver)
ms_formula_write_pre_data (bp, s, EXCEL_NAME, wb->ver);
}
write_names(bp, wb);
biff_eof_write (bp);
/* End of Workbook */
......
......@@ -54,6 +54,7 @@ struct _ExcelWorkbook {
Palette *pal;
Fonts *fonts;
Formats *formats;
GPtrArray *names;
MsOlePos streamPos;
};
......
......@@ -431,7 +431,7 @@ write_ref (PolishData *pd, const CellRef *ref)
if (pd->ver <= eBiffV7) {
guint16 extn_idx = ms_excel_write_get_sheet_idx (pd->sheet->wb,
ref->sheet);
MS_OLE_SET_GUINT16 (data, 0); /* FIXME ? */
MS_OLE_SET_GUINT16 (data, 0xffff); /* FIXME ? */
MS_OLE_SET_GUINT32 (data + 2, 0x0);
MS_OLE_SET_GUINT32 (data + 6, 0x0);
MS_OLE_SET_GUINT16 (data + 10, extn_idx);
......@@ -703,8 +703,26 @@ write_node (PolishData *pd, ExprTree *tree)
write_ref (pd, &tree->u.ref);
break;
case OPER_ARRAY:
case OPER_NAME:
{
guint8 data[14];
guint16 idx;
for (idx = 0; idx <14; idx++) data[idx] = 0;
for (idx = 0; idx < pd->sheet->wb->names->len; idx++) {
if (!strcmp(tree->u.name->name->str,
g_ptr_array_index (pd->sheet->wb->names, idx))) {
MS_OLE_SET_GUINT8 (data + 0, FORMULA_PTG_NAME);
MS_OLE_SET_GUINT16 (data + 1, idx+1);
ms_biff_put_var_write (pd->bp, data, 15);
return;
}
}
}
case OPER_ARRAY:
default:
{
gchar *err = g_strdup_printf ("Unknown Operator %d", tree->oper);
......@@ -733,8 +751,8 @@ write_arrays (PolishData *pd)
array = pd->arrays->data;
g_return_if_fail (array->type == VALUE_ARRAY);
for (lpy=0; lpy < array->v.array.y; lpy++) {
for (lpx=0; lpx < array->v.array.x; lpx++) {
for (lpy = 0; lpy < array->v.array.y; lpy++) {
for (lpx = 0; lpx < array->v.array.x; lpx++) {
const Value *v = array->v.array.vals[lpx][lpy];
if (VALUE_IS_NUMBER (v)) {
......
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