Commit 333a8167 authored by Jon K Hellan's avatar Jon K Hellan Committed by Jon Kåre Hellan

Megacommit.

2000-01-29  Jon K Hellan  <hellan@acm.org>

	Megacommit.

	The purpose of the changeset is twofold:

	1. Use CommandContexts for error reporting for file read/save.
	2. This allows us to let FileFormatOpen return 0 on success, -1 on
	   failure, same as FileFormatSave. The convention to return NULL
	   on success was highly ideosyncratic.

	* src/file.h (FileFormatOpen, FileFormatSave, workbook_load_from,
	workbook_import): Add CommandContext
	(FileFormatOpen, workbook_load_from): Return int instead of char*.

	* src/file.c (workbook_load_from, workbook_try_read,
	workbook_read, workbook_import, workbook_save_as, workbook_save)
	(file_error_message): Remove function
	(workbook_read, workbook_load_from, workbook_save_as,
	workbook_save): Do not display message, message, plugin does -
	using CommandContext.
	(workbook_load_from): Return int instead of char*.
	(workbook_load_from, workbook_import): fo->open returns int
	instead of char*.
	(workbook_try_read): Remove msg paramenter

	* src/workbook.c (workbook_persist_file_load,
	workbook_persist_file_save): Use workbook_command_context_gui.
	(file_import_cmd): ditto
	(file_open_cmd): ditto

	* src/gnumeric-sheet.c (gnumeric_sheet_filenames_dropped): Use
	workbook_command_context_gui. Call workbook_try_read without msg
	argument.

	* src/workbook.h (workbook_try_read, workbook_read,
	workbook_save_as, workbook_save): Add command context
	(workbook_try_read): Remove msg paramenter

	* src/dialogs/dialog-autosave.c (dialog_autosave_callback):
	ditto

	* src/command-context.[ch] (gnumeric_error_read,
	gnumeric_error_save): New functions.

	* src/command-context-corba.c (ccc_error_read, ccc_error_save):
	Ditto.
	(ccc_init_class): Initialize error_read, error_save.

	* src/command-context-gui.c (ccg_error_read, ccg_error_save):
	Ditto.
	(ccg_init_class): Initialize error_read, error_save.

	* src/main.c (gnumeric_main): Make a CommandContext for use before
	we make first workbook. Unref it when no longer needed. Call
	plugins_init and workbook_read with CommandContext.

	* src/plugin-manager.c (add_cb): Use gnumeric_error_plugin_problem.
	(remove_cb): Ditto.

	* src/plugin.c (plugin_load, plugin_unload): CommandContext
	instead of workbook.
	(plugins_init): Add CommandContext.

	* src/plugin.c (plugin_load, plugin_unload): CommandContext
	instead of workbook.
	(plugin_unload): Use gnumeric_error_plugin_problem.
	(plugin_load_plugins_in_dir, load_all_plugins, plugins_init): Add
	CommandContext.

	* src/xml-io.h:  ditto

	* src/xml-io.c (gnumeric_xml_read_workbook,
	gnumeric_xml_write_workbook):  ditto

In plugins/dif:

	* dif.c (dif_read_workbook, dif_write_workbook): Add
	CommandContext.
	(dif_read_workbook): Return 0 on success, -1 on failure.
	 Use gnumeric_error_read to report errors.

In plugins/excel:

	* excel.h (ms_excel_read_workbook, ms_excel_write_workbook) Add
	CommandContext. Return int.

	* ms-excel-read.c (ms_excel_read_workbook): Add
	CommandContext. Return 0 on success, -1 on failure. Use
	gnumeric_error_read to display messages.

	* ms-excel-write.c (write_sheet): Check max no. of rows for the
	format.
	(new_sheet): Return the ExcelSheet. Let caller add it to
	wb->sheets.
	(pre_pass): Add CommandContext.
	(free_workbook): New function, previously in write_workbook.
	(write_workbook): Change parameter from Workbook to ExcelWorkbook.
	Move deallocation to free_workbook.
	(check_sheet): New function. Check if we are able to save the
	sheet.
	(ms_excel_check_write): New function. Check if we are able to save
	to the file. Do initialization previously in
	ms_excel_write_workbook.
	(ms_excel_write_workbook): Add CommandContext. Add state. Change
	wb from Workbook to ExcelWorkbook. Use gnumeric_error_save to
	report problems. Return 0 on success, -1 on failure.

	* ms-excel-biff.h: Define enum for max no. of rows. Fix typo.

	* boot.c (excel_load, excel_save, excel_save_98, excel_save_95):
	Add CommandContext.
	(excel_load): Return 0 on success, -1 on failure.
	Use gnumeric_error_read to display messages. Remove "Opening .. "
	message on stdout.
	(excel_probe_write): New function. Check if we are able to save to
	the file.
	(excel_save): Use gnumeric_error_save to display messages.
	Return 0 on success, -1 on failure.

In plugins/ff-csv:

	* csv-io.c (csv_read_workbook, csv_write_workbook,
	csv_parse_sheet, csv_parse_field): Add CommandContext. Return 0 on
	success, -1 on failure. Use gnumeric_error_read to report errors.

In plugins/ff-stf:

	* dialog-stf.h: Add CommandContext. Return int.

	* dialog-stf.c (dialog_stf) : Add CommandContext. Return 0 on success,
	-1 on failure. Use gnumeric_error_read to report errors.

	* stf.c (stf_read_workbook): Ditto.

In plugins/html:

	* epsf.h (epsf_write_wb): Add CommandContext.

	* epsf.c (epsf_write_wb): ditto.

	* latex.h (html_write_wb_latex, html_write_wb_latex2e): ditto

	* latex.c (html_write_wb_latex, html_write_wb_latex2e): ditto

	* roff.c (html_write_wb_roff_ps, html_write_wb_roff_dvi,
	html_write_wb_roff_pdf, html_write_wb_roff): ditto

	* roff.c (html_write_wb_roff_ps, html_write_wb_roff_dvi,
	html_write_wb_roff_pdf, html_write_wb_roff): ditto

	* html.h (html_read, html_write_wb_html40, html_write_wb_html32):
	ditto.
	(html_read): Return int.

	* html.c (html_read, html_write_wb_html40, html_write_wb_html32):
	ditto
	(html_read): Return 0 on success, -1 on failure. Use
	gnumeric_error_read to report errors.

In plugins/lotus-123:

	* lotus.c (lotus_read): Add CommandContext. Return 0 on success,
	-1 on failure. Use gnumeric_error_read to report errors. Close
	file unconditionally.
	(read_workbook): Return 0 on success, -1 on failure. Remove unused
	panic_message variable.

	* lotus.h (lotus_read): Add CommandContext. Return int.

	* boot.c (lotus_load): Ditto

In plugins/oleo:

	* oleo.c (oleo_read): Add CommandContext. Return 0 on success,
	-1 on failure. Use gnumeric_error_read to report errors.

	* oleo.h (oleo_read): Add CommandContext. Return int.

	* boot.c (oleo_load): Ditto.

In plugins/plan-perfect:

	* pln.c (pln_parse_sheet, pln_read_workbook): Add
	CommandContext. Return 0 on success, -1 on failure. Use
	gnumeric_error_read to report errors.

In plugins/sc:

	* sc.c (sc_read_workbook, sc_parse_sheet): Add
	CommandContext. Return 0 on success, -1 on failure.  Use
	gnumeric_error_read to report errors.

In plugins/sylk:

	* sylk.c (sylk_read_workbook, sylk_parse_sheet): Add
	CommandContext. Return 0 on success, -1 on failure. Use
	gnumeric_error_read to report errors.

In plugins/text:

	* text-io.c (text_read_workbook, text_write_workbook,
	readTextWorkbook): Add CommandContext.
	(text_read_workbook, readTextWorkbook): Return 0 on success, -1 on
	failure.
	(readTextWorkbook): Use gnumeric_error_read to report errors.

In plugins/xbase:

	* xbase.h (xbase_open): Add CommandContext.

	* xbase.c (xbase_open): Add CommandContext. Remove progress
	message to stdout. Use gnumeric_error_read to report errors.

	* boot.c (xbase_load): Add CommandContext. Return 0 on success, -1
	on failure.
parent 6b1c82d3
2000-01-29 Jon K Hellan <hellan@acm.org>
Megacommit.
The purpose of the changeset is twofold:
1. Use CommandContexts for error reporting for file read/save.
2. This allows us to let FileFormatOpen return 0 on success, -1 on
failure, same as FileFormatSave. The convention to return NULL
on success was highly ideosyncratic.
* src/file.h (FileFormatOpen, FileFormatSave, workbook_load_from,
workbook_import): Add CommandContext
(FileFormatOpen, workbook_load_from): Return int instead of char*.
* src/file.c (workbook_load_from, workbook_try_read,
workbook_read, workbook_import, workbook_save_as, workbook_save)
(file_error_message): Remove function
(workbook_read, workbook_load_from, workbook_save_as,
workbook_save): Do not display message, message, plugin does -
using CommandContext.
(workbook_load_from): Return int instead of char*.
(workbook_load_from, workbook_import): fo->open returns int
instead of char*.
(workbook_try_read): Remove msg paramenter
* src/workbook.c (workbook_persist_file_load,
workbook_persist_file_save): Use workbook_command_context_gui.
(file_import_cmd): ditto
(file_open_cmd): ditto
* src/gnumeric-sheet.c (gnumeric_sheet_filenames_dropped): Use
workbook_command_context_gui. Call workbook_try_read without msg
argument.
* src/workbook.h (workbook_try_read, workbook_read,
workbook_save_as, workbook_save): Add command context
(workbook_try_read): Remove msg paramenter
* src/dialogs/dialog-autosave.c (dialog_autosave_callback):
ditto
* src/command-context.[ch] (gnumeric_error_read,
gnumeric_error_save): New functions.
* src/command-context-corba.c (ccc_error_read, ccc_error_save):
Ditto.
(ccc_init_class): Initialize error_read, error_save.
* src/command-context-gui.c (ccg_error_read, ccg_error_save):
Ditto.
(ccg_init_class): Initialize error_read, error_save.
* src/main.c (gnumeric_main): Make a CommandContext for use before
we make first workbook. Unref it when no longer needed. Call
plugins_init and workbook_read with CommandContext.
* src/plugin-manager.c (add_cb): Use gnumeric_error_plugin_problem.
(remove_cb): Ditto.
* src/plugin.c (plugin_load, plugin_unload): CommandContext
instead of workbook.
(plugins_init): Add CommandContext.
* src/plugin.c (plugin_load, plugin_unload): CommandContext
instead of workbook.
(plugin_unload): Use gnumeric_error_plugin_problem.
(plugin_load_plugins_in_dir, load_all_plugins, plugins_init): Add
CommandContext.
* src/xml-io.h: ditto
* src/xml-io.c (gnumeric_xml_read_workbook,
gnumeric_xml_write_workbook): ditto
2000-01-28 Mike Kestner <mkestner@ameritech.net>
* src/sheet-style.c (sheet_style_insert_colrow): Now does option checking
......
2000-01-29 Jon K Hellan <hellan@acm.org>
Megacommit.
The purpose of the changeset is twofold:
1. Use CommandContexts for error reporting for file read/save.
2. This allows us to let FileFormatOpen return 0 on success, -1 on
failure, same as FileFormatSave. The convention to return NULL
on success was highly ideosyncratic.
* src/file.h (FileFormatOpen, FileFormatSave, workbook_load_from,
workbook_import): Add CommandContext
(FileFormatOpen, workbook_load_from): Return int instead of char*.
* src/file.c (workbook_load_from, workbook_try_read,
workbook_read, workbook_import, workbook_save_as, workbook_save)
(file_error_message): Remove function
(workbook_read, workbook_load_from, workbook_save_as,
workbook_save): Do not display message, message, plugin does -
using CommandContext.
(workbook_load_from): Return int instead of char*.
(workbook_load_from, workbook_import): fo->open returns int
instead of char*.
(workbook_try_read): Remove msg paramenter
* src/workbook.c (workbook_persist_file_load,
workbook_persist_file_save): Use workbook_command_context_gui.
(file_import_cmd): ditto
(file_open_cmd): ditto
* src/gnumeric-sheet.c (gnumeric_sheet_filenames_dropped): Use
workbook_command_context_gui. Call workbook_try_read without msg
argument.
* src/workbook.h (workbook_try_read, workbook_read,
workbook_save_as, workbook_save): Add command context
(workbook_try_read): Remove msg paramenter
* src/dialogs/dialog-autosave.c (dialog_autosave_callback):
ditto
* src/command-context.[ch] (gnumeric_error_read,
gnumeric_error_save): New functions.
* src/command-context-corba.c (ccc_error_read, ccc_error_save):
Ditto.
(ccc_init_class): Initialize error_read, error_save.
* src/command-context-gui.c (ccg_error_read, ccg_error_save):
Ditto.
(ccg_init_class): Initialize error_read, error_save.
* src/main.c (gnumeric_main): Make a CommandContext for use before
we make first workbook. Unref it when no longer needed. Call
plugins_init and workbook_read with CommandContext.
* src/plugin-manager.c (add_cb): Use gnumeric_error_plugin_problem.
(remove_cb): Ditto.
* src/plugin.c (plugin_load, plugin_unload): CommandContext
instead of workbook.
(plugins_init): Add CommandContext.
* src/plugin.c (plugin_load, plugin_unload): CommandContext
instead of workbook.
(plugin_unload): Use gnumeric_error_plugin_problem.
(plugin_load_plugins_in_dir, load_all_plugins, plugins_init): Add
CommandContext.
* src/xml-io.h: ditto
* src/xml-io.c (gnumeric_xml_read_workbook,
gnumeric_xml_write_workbook): ditto
2000-01-28 Mike Kestner <mkestner@ameritech.net>
* src/sheet-style.c (sheet_style_insert_colrow): Now does option checking
......
2000-01-29 Jon K Hellan <hellan@acm.org>
* dif.c (dif_read_workbook, dif_write_workbook): Add
CommandContext.
(dif_read_workbook): Return 0 on success, -1 on failure.
Use gnumeric_error_read to report errors.
1999-12-30 Jody Goldberg <jgoldberg@home.com>
* dif.c (dif_read_workbook) : Preliminary error reporting support.
......
......@@ -19,6 +19,7 @@
#include "plugin.h"
#include "gnumeric.h"
#include "file.h"
#include "command-context.h"
typedef struct {
char const *data, *cur;
......@@ -236,20 +237,25 @@ g_warning("DIF SUCCESS");
# define MAP_FAILED -1
#endif
static char *
dif_read_workbook (Workbook *book, char const *filename)
static int
dif_read_workbook (CommandContext *context,
Workbook *book, char const *filename)
{
char *result = NULL;
int result = 0;
int len;
struct stat sbuf;
char const *data;
int const fd = open(filename, O_RDONLY);
if (fd < 0)
return g_strdup (g_strerror(errno));
if (fd < 0) {
gnumeric_error_read (context, g_strerror (errno));
return -1;
}
if (fstat(fd, &sbuf) < 0) {
close (fd);
return g_strdup (g_strerror(errno));
gnumeric_error_read (context, g_strerror (errno));
return -1;
}
len = sbuf.st_size;
......@@ -269,12 +275,16 @@ dif_read_workbook (Workbook *book, char const *filename)
if (!dif_parse_sheet (&src)) {
workbook_detach_sheet (book, src.sheet, TRUE);
result = g_strdup(_(("DIF : Failed to load sheet")));
gnumeric_error_read
(context , _("DIF : Failed to load sheet"));
result = -1;
}
munmap((char *)data, len);
} else
result = g_strdup (_("Unable to mmap the file"));
} else {
result = -1;
gnumeric_error_read (context, _("Unable to mmap the file"));
}
close(fd);
return result;
......@@ -358,7 +368,8 @@ dif_write_cell (FILE *f, Cell *cell, int col, int row)
* write every sheet of the workbook to a DIF format file
*/
static int
dif_write_workbook (Workbook *wb, const char *filename)
dif_write_workbook (CommandContext *context,
Workbook *wb, const char *filename)
{
GList *sheet_list;
Sheet *sheet;
......
2000-01-29 Jon K Hellan <hellan@acm.org>
Megacommit.
The purpose of the changeset is twofold:
1. Use CommandContexts for error reporting for file read/save.
2. This allows us to let FileFormatOpen return 0 on success, -1 on
failure, same as FileFormatSave. The convention to return NULL
on success was highly ideosyncratic.
* excel.h (ms_excel_read_workbook, ms_excel_write_workbook) Add
CommandContext. Return int.
* ms-excel-read.c (ms_excel_read_workbook): Add
CommandContext. Return 0 on success, -1 on failure. Use
gnumeric_error_read to display messages.
* ms-excel-write.c (write_sheet): Check max no. of rows for the
format.
(new_sheet): Return the ExcelSheet. Let caller add it to
wb->sheets.
(pre_pass): Add CommandContext.
(free_workbook): New function, previously in write_workbook.
(write_workbook): Change parameter from Workbook to ExcelWorkbook.
Move deallocation to free_workbook.
(check_sheet): New function. Check if we are able to save the
sheet.
(ms_excel_check_write): New function. Check if we are able to save
to the file. Do initialization previously in
ms_excel_write_workbook.
(ms_excel_write_workbook): Add CommandContext. Add state. Change
wb from Workbook to ExcelWorkbook. Use gnumeric_error_save to
report problems. Return 0 on success, -1 on failure.
* ms-excel-biff.h: Define enum for max no. of rows. Fix typo.
* boot.c (excel_load, excel_save, excel_save_98, excel_save_95):
Add CommandContext.
(excel_load): Return 0 on success, -1 on failure.
Use gnumeric_error_read to display messages. Remove "Opening .. "
message on stdout.
(excel_probe_write): New function. Check if we are able to save to
the file.
(excel_save): Use gnumeric_error_save to display messages.
Return 0 on success, -1 on failure.
2000-01-18 Jody Goldberg <jgoldberg@home.com>
* ms-formula-read.c (ms_excel_parse_formula) : Add OPER_UNARY_PLUS.
......
......@@ -15,6 +15,7 @@
#include "gnumeric-util.h"
#include "file.h"
#include "main.h"
#include "command-context.h"
#include "excel.h"
#include "ms-summary.h"
......@@ -47,24 +48,33 @@ excel_probe (const char *filename)
return FALSE;
}
static char *
excel_load (Workbook *wb, const char *filename)
/*
* excel_load
* @context command context
* @wb workbook
* @filename file name
*
* Load en excel workbook.
* Returns 0 on success, -1 on failure.
*/
static int
excel_load (CommandContext *context, Workbook *wb, const char *filename)
{
MsOleErr ole_error;
MsOle *f;
char *workbook_error;
int result;
ole_error = ms_ole_open (&f, filename);
if (ole_error != MS_OLE_ERR_OK) {
ms_ole_destroy (&f);
/* FIXME : The null string indicates using the default message
* We need a more detailed message from ole_open */
return "";
/* FIXME : We need a more detailed message from
* ole_open */
gnumeric_error_read (context, "");
return -1;
}
printf ("Opening '%s' ", filename);
workbook_error = ms_excel_read_workbook (wb, f);
if (workbook_error == NULL) {
result = ms_excel_read_workbook (context, wb, f);
if (result == 0) {
char *name = g_strconcat (filename, ".gnumeric", NULL);
ms_summary_read (f, wb->summary_info);
......@@ -77,61 +87,73 @@ excel_load (Workbook *wb, const char *filename)
ms_ole_destroy (&f);
return workbook_error;
return result;
}
/*
* Here's why the state which is carried from excel_check_write to
* ms_excel_write_workbook is void *: The state is actually an
* ExcelWorksheet * as defined in ms-excel-write.h. But we can't
* import that definition here: There's a different definition of
* ExcelWorksheet in ms-excel-read.h.
*/
static int
excel_save (Workbook *wb, const char *filename, eBiff_version ver)
excel_save (CommandContext *context, Workbook *wb, const char *filename,
eBiff_version ver)
{
MsOle *f;
int ans;
struct stat s;
MsOleErr result;
void *state = NULL;
if ((stat (filename, &s) != -1)) {
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR,
_("Saving over old files disabled for safety"));
return 1;
gnumeric_error_save
(context,
_("Saving over old files disabled for safety"));
return -1;
}
if (ms_excel_check_write (context, &state, wb, ver) != 0)
return -1;
result = ms_ole_create (&f, filename);
if (result != MS_OLE_ERR_OK) {
char *str = g_strdup_printf ("%s %s",
_("Can't open"),
filename);
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR, str);
gnumeric_error_save (context, str);
ms_ole_destroy (&f);
g_free (str);
return 1;
return -1;
}
ans = ms_excel_write_workbook (f, wb, ver);
ans = ms_excel_write_workbook (context, f, state, ver);
ms_summary_write (f, wb->summary_info);
ms_ole_destroy (&f);
if (ans)
if (ans == 0)
printf ("Written successfully\n");
else
printf ("Error whilst writing\n");
return !ans;
return ans;
}
static int
excel_save_98 (Workbook *wb, const char *filename)
excel_save_98 (CommandContext *context, Workbook *wb, const char *filename)
{
return excel_save (wb, filename, eBiffV8);
return excel_save (context, wb, filename, eBiffV8);
}
static int
excel_save_95 (Workbook *wb, const char *filename)
excel_save_95 (CommandContext *context, Workbook *wb, const char *filename)
{
return excel_save (wb, filename, eBiffV7);
return excel_save (context, wb, filename, eBiffV7);
}
void
......
......@@ -19,9 +19,19 @@ typedef enum _eBiff_version { eBiffV2=2, eBiffV3=3,
eBiffV8=8, /* Excel 97 */
eBiffVUnknown=0} eBiff_version ;
extern char * ms_excel_read_workbook (Workbook *wb, MsOle *file);
extern int ms_excel_write_workbook (MsOle *file, Workbook *wb,
eBiff_version ver);
extern int ms_excel_read_workbook (CommandContext *context,
Workbook *wb, MsOle *file);
/*
* Here's why the state which is carried from excel_check_write to
* ms_excel_write_workbook is void *: The state is actually an
* ExcelWorksheet * as defined in ms-excel-write.h. But we can't
* import that definition here: There's a different definition of
* ExcelWorksheet in ms-excel-read.h.
*/
extern int ms_excel_check_write (CommandContext *context, void **state,
Workbook *wb, eBiff_version ver);
extern int ms_excel_write_workbook (CommandContext *context, MsOle *file,
void *state, eBiff_version ver);
/* We need to use these for both read and write */
typedef struct {
......
......@@ -79,7 +79,7 @@ typedef enum _eBiffDifferences { /* Differences to parent styles */
eBiffDBorderbit = 13,
eBiffDFillbit = 14,
eBiffDLockbit = 15
} _eBiffDifferences;
} eBiffDifferences;
typedef struct _BIFF_BOF_DATA
{
......@@ -87,6 +87,11 @@ typedef struct _BIFF_BOF_DATA
eBiff_filetype type ;
} BIFF_BOF_DATA ;
typedef enum {
eBiffMaxRowsV7 = 16384,
eBiffMaxRowsV8 = 65536
} eBiffMaxRows;
extern BIFF_BOF_DATA *new_ms_biff_bof_data (BiffQuery *pos) ;
extern void free_ms_biff_bof_data (BIFF_BOF_DATA *data) ;
......
......@@ -9,6 +9,7 @@
**/
#include <config.h>
#include "command-context.h"
#include "ms-formula-read.h"
#include "ms-excel-read.h"
......@@ -3470,8 +3471,9 @@ ms_excel_read_supporting_wb (BIFF_BOF_DATA *ver, BiffQuery *q)
#endif
}
char *
ms_excel_read_workbook (Workbook *workbook, MsOle *file)
int
ms_excel_read_workbook (CommandContext *context, Workbook *workbook,
MsOle *file)
{
ExcelWorkbook *wb = NULL;
MsOleStream *stream;
......@@ -3484,9 +3486,8 @@ ms_excel_read_workbook (Workbook *workbook, MsOle *file)
cell_deep_freeze_redraws ();
/* Find that book file */
/* Look for workbook before book so that we load the office97 format rather than
* office5 when there are multiple streams.
*/
/* Look for workbook before book so that we load the office97
* format rather than office5 when there are multiple streams. */
result = ms_ole_stream_open (&stream, file, "/", "workbook", 'r');
if (result != MS_OLE_ERR_OK) {
ms_ole_stream_close (&stream);
......@@ -3494,7 +3495,10 @@ ms_excel_read_workbook (Workbook *workbook, MsOle *file)
result = ms_ole_stream_open (&stream, file, "/", "book", 'r');
if (result != MS_OLE_ERR_OK) {
ms_ole_stream_close (&stream);
return g_strdup (_("No book or workbook streams found."));
gnumeric_error_read
(context,
_("No book or workbook streams found."));
return -1;
}
}
......@@ -3995,8 +3999,9 @@ ms_excel_read_workbook (Workbook *workbook, MsOle *file)
if (problem_loading == NULL)
workbook_recalc (wb->gnum_wb);
ms_excel_workbook_destroy (wb);
return problem_loading;
gnumeric_error_read (context, problem_loading);
return -1;
}
return "";
return 0;
}
......@@ -13,6 +13,9 @@
* collected.
**/
/*
* FIXME: Check for errors and propagate upward. We've only started.
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
......@@ -35,6 +38,7 @@
#include "main.h"
#include "utils.h"
#include "print-info.h"
#include "command-context.h"
#include "ms-ole.h"
#include "ms-biff.h"
......@@ -3119,7 +3123,7 @@ write_block (BiffPut *bp, ExcelSheet *sheet, guint32 begin, int nrows)
static void
write_sheet (BiffPut *bp, ExcelSheet *sheet)
{
guint32 y, block_end;
guint32 y, block_end, maxrows;
int rows_in_block = ROW_BLOCK_MAX_LEN;
MsOlePos index_off;
/* No. of blocks of rows. Only correct as long as all rows -
......@@ -3127,9 +3131,10 @@ write_sheet (BiffPut *bp, ExcelSheet *sheet)
guint32 nblocks = (sheet->maxy - 1) / rows_in_block + 1;
sheet->streamPos = biff_bof_write (bp, sheet->wb->ver, eBiffTWorksheet);
if (sheet->maxy > 16544)
g_error ("Sheet seems impossibly big");
/* We catch too large sheets during write check, but leave this in: */
maxrows = (sheet->wb->ver >= eBiffV8)
? eBiffMaxRowsV8 : eBiffMaxRowsV7;
g_assert (sheet->maxy > maxrows);
if (sheet->wb->ver >= eBiffV8) {
guint8 *data = ms_biff_put_len_next (bp, 0x200|BIFF_INDEX,
......@@ -3166,15 +3171,15 @@ write_sheet (BiffPut *bp, ExcelSheet *sheet)
biff_eof_write (bp);
}
static void
static ExcelSheet *
new_sheet (ExcelWorkbook *wb, Sheet *value)
{
ExcelSheet *sheet = g_new (ExcelSheet, 1);
Range extent;
ExcelCell **p, **pmax;
g_return_if_fail (value);
g_return_if_fail (wb);
g_return_val_if_fail (value, NULL);
g_return_val_if_fail (wb, NULL);
sheet->gnum_sheet = value;
sheet->streamPos = 0x0deadbee;
......@@ -3185,14 +3190,14 @@ new_sheet (ExcelWorkbook *wb, Sheet *value)
sheet->dbcells = g_array_new (FALSE, FALSE, sizeof (MsOlePos));
sheet->base_char_width = 0;
g_ptr_array_add (wb->sheets, sheet);
ms_formula_cache_init (sheet);
sheet->cell_used_map = cell_used_map_new (sheet);
sheet->cells = g_new (ExcelCell *, sheet->maxy);
for (p = sheet->cells, pmax = p + sheet->maxy; p < pmax; p++)
*p = g_new0 (ExcelCell, sheet->maxx);
return sheet;
}
static void
......@@ -3213,6 +3218,7 @@ free_sheet (ExcelSheet *sheet)
/**
* pre_pass
* @context: Command context.
* @wb: the workbook to scan
*
* Scans all the workbook items. Adds all styles, fonts, formats and
......@@ -3220,9 +3226,11 @@ free_sheet (ExcelSheet *sheet)
* occur, hence the records can be written in a linear order.
*
**/
static void
pre_pass (ExcelWorkbook *wb)
static int
pre_pass (CommandContext *context, ExcelWorkbook *wb)
{
int ret = 0;
/* The default style first */
put_mstyle (wb, wb->xf->default_style);
/* Its font and format */
......@@ -3234,32 +3242,38 @@ pre_pass (ExcelWorkbook *wb)
gather_fonts (wb);
gather_formats (wb);
gather_palette (wb);
return ret;
}
/*
* free_workbook
* @wb Workbook
*
* Free various bits
*/
static void
write_workbook (BiffPut *bp, Workbook *gwb, eBiff_version ver)
free_workbook (ExcelWorkbook *wb)
{
ExcelWorkbook *wb = g_new (ExcelWorkbook, 1);
ExcelSheet *s = 0;
int lp;
GList *sheets;
wb->ver = ver;
wb->gnum_wb = gwb;
wb->sheets = g_ptr_array_new ();
wb->names = g_ptr_array_new ();
fonts_init (wb);
formats_init (wb);
palette_init (wb);
xf_init (wb);
sheets = workbook_sheets (gwb);
while (sheets) {
new_sheet (wb, sheets->data);
sheets = g_list_next (sheets);
int lp;
fonts_free (wb);
formats_free (wb);
palette_free (wb);
xf_free (wb);
for (lp = 0; lp < wb->sheets->len; lp++) {
ExcelSheet *s = g_ptr_array_index (wb->sheets, lp);
free_sheet (s);
}
pre_pass (wb);
g_free (wb);
}
static void
write_workbook (BiffPut *bp, ExcelWorkbook *wb, eBiff_version ver)
{
ExcelSheet *s = 0;
int lp;
/* Workbook */
wb->streamPos = biff_bof_write (bp, ver, eBiffTWorkbook);
......@@ -3299,37 +3313,101 @@ write_workbook (BiffPut *bp, Workbook *gwb, eBiff_version ver)
}
/* End Finalised workbook */
/* Free various bits */
fonts_free (wb);
formats_free (wb);
palette_free (wb);
xf_free (wb);
for (lp = 0; lp < wb->sheets->len; lp++) {
ExcelSheet *s = g_ptr_array_index (wb->sheets, lp);
free_sheet (s);
free_workbook (wb);
}
/*
* check_sheet
* @context Command context
* @sheet Sheet
*
* Check if we are able to save the sheet. Return -1 if we would, 0 otherwise.
*
* FIXME: Check if the 16384 rows limit is a limit on max row no. or
* on no. of row records. If the latter, change the test if we avoid
* storing empty row records.
*/
static int
check_sheet (CommandContext *context, ExcelSheet *sheet)
{
guint32 maxrows;
int ret = 0;
maxrows = (sheet->wb->ver >= eBiffV8)
? eBiffMaxRowsV8 : eBiffMaxRowsV7;
if (sheet->maxy > maxrows) {
gnumeric_error_save
(context, _("Too many rows for this format"));
ret = -1;
}
return ret;
}