Commit 000bec1e authored by Michael Meeks's avatar Michael Meeks

Fairly large ole API re-write,

few compile warnings fixed.
parent 1d919dff
1999-09-19 Michael Meeks <michael@nuclecu.unam.mx>
* src/workbook.c (about_cmd): make static.
* src/sheet-object-container.c (sheet_object_container_load): fix
return value.
* src/workbook.c (create_format_toolbar): cast to widget not entry.
1999-09-19 Morten Welinder <terra@diku.dk>
* src/functions/fn-stat.c (callback_function_make_list): Static.
......
1999-09-19 Michael Meeks <michael@nuclecu.unam.mx>
* src/workbook.c (about_cmd): make static.
* src/sheet-object-container.c (sheet_object_container_load): fix
return value.
* src/workbook.c (create_format_toolbar): cast to widget not entry.
1999-09-19 Morten Welinder <terra@diku.dk>
* src/functions/fn-stat.c (callback_function_make_list): Static.
......
1999-09-19 Michael Meeks <michael@nuclecu.unam.mx>
* Makefile.am: comment out ole.
* ms-summary.c (sum_name_to_excel): made static.
* ms-excel-write.c (ms_excel_write_workbook): updated.
* ms-excel-read.c (ms_excel_read_workbook): use better API.
(find_workbook): removed.
* ms-biff.c (ms_biff_query_copy): Updated duplicate.
* boot.c (excel_probe, excel_save, excel_load): new ole api.
* ms-excel-write.c (ms_excel_write_workbook): fix leak.
1999-09-18 Morten Welinder <terra@diku.dk>
* ole.c (cur_dir, delim): static.
......
......@@ -37,18 +37,18 @@ libexcel_a_SOURCES = \
ms-summary.c \
ms-summary.h
noinst_PROGRAMS = \
ole
ole_SOURCES = \
ole.c
ole_LDADD = \
ms-biff.o \
libole2/libole2.a \
$(GNOME_LIBDIR) \
$(GNOME_LIBS) \
$(INTLLIBS)
#noinst_PROGRAMS = \
# ole
#
#ole_SOURCES = \
# ole.c
#
#
#ole_LDADD = \
# ms-biff.o \
# libole2/libole2.a \
# $(GNOME_LIBDIR) \
# $(GNOME_LIBS) \
# $(INTLLIBS)
#
SUBDIRS = libole2
......@@ -22,16 +22,13 @@ extern int ms_excel_read_debug;
static gboolean
excel_probe (const char *filename)
{
MsOle *f;
int res;
MsOle *f;
MsOleErr result;
f = ms_ole_open (filename);
res = f != NULL;
ms_ole_destroy (f);
result = ms_ole_open (&f, filename);
ms_ole_destroy (&f);
return res;
return result == MS_OLE_ERR_OK;
}
static gboolean
......@@ -39,10 +36,13 @@ excel_load (Workbook *wb, const char *filename)
{
MsOle *f;
gboolean ret;
MsOleErr result;
f = ms_ole_open (filename);
if (!f)
result = ms_ole_open (&f, filename);
if (result != MS_OLE_ERR_OK) {
ms_ole_destroy (&f);
return FALSE;
}
printf ("Opening '%s' ", filename);
ret = ms_excel_read_workbook (wb, f);
......@@ -57,7 +57,7 @@ excel_load (Workbook *wb, const char *filename)
g_free(name);
}
ms_ole_destroy (f);
ms_ole_destroy (&f);
return ret;
}
......@@ -69,6 +69,7 @@ excel_save (Workbook *wb, const char *filename, eBiff_version ver)
MsOle *f;
int ans;
struct stat s;
MsOleErr result;
if ((stat (filename, &s) != -1)) {
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR,
......@@ -76,14 +77,15 @@ excel_save (Workbook *wb, const char *filename, eBiff_version ver)
return 0;
}
f = ms_ole_create (filename);
result = ms_ole_create (&f, filename);
if (!f) {
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);
ms_ole_destroy (&f);
g_free (str);
return 0;
}
......@@ -92,11 +94,13 @@ excel_save (Workbook *wb, const char *filename, eBiff_version ver)
ms_summary_write (f, wb->summary_info);
ms_ole_destroy (f);
ms_ole_destroy (&f);
if (ans)
printf ("Written successfully\n");
else
printf ("Error whilst writing\n");
return ans;
}
......
1999-09-19 Michael Meeks <michael@nuclecu.unam.mx>
* Makefile.am: Killed storage.
* gnome-storage-ole.[ch]: Killed.
* ms-ole-summary.c (ms_ole_summary_open):
* ms-ole.c (MAP_FAILED): Hack for wierd systems.
(ms_ols_*directory*): Destroyed, all new API. This time its permanant.
will allow clean VFS integration & simple leak free usage. It cleans
the header file & namespace and improves performance.
(path_to_pps, pps_create): helper functions.
(pps_create, pps_decode_tree): PPS signature for debugging.
1999-09-17 Michael Meeks <michael@nuclecu.unam.mx>
* ms-ole-summary.c (ms_ole_summary_set_string): Remove verbose
......
......@@ -5,24 +5,10 @@ INCLUDES = \
-I$(top_srcdir)/src \
$(GNOME_INCLUDEDIR)
if BONOBO
other = libstorage_ole.a
else
other =
endif
noinst_LIBRARIES = libole2.a $(other)
noinst_LIBRARIES = libole2.a
libole2_a_SOURCES = \
ms-ole.c \
ms-ole.h \
ms-ole-summary.c \
ms-ole-summary.h
libstorage_ole_a_SOURCES = \
gnome-storage-ole.c \
gnome-storage-ole.h \
gnome-stream-ole.c \
gnome-stream-ole.h
Run time determine whether we can mmap or not.
Ref count ms_ole_stream & ms_ole
Write summary info.
Add Bonobo::Storage interface.
libvfs integration (?)
write nice simple file handle style macros / wrappers.
sort out the directory / path mess ( use the UNIX methodology ).
......@@ -225,10 +225,12 @@ MsOleSummary *
ms_ole_summary_open (MsOle *f)
{
MsOleStream *s;
MsOleErr result;
g_return_val_if_fail (f != NULL, NULL);
s = ms_ole_stream_open_name (f, "SummaryInformation", 'r');
if (!s)
result = ms_ole_stream_open (&s, f, "/",
"SummaryInformation", 'r');
if (result != MS_OLE_ERR_OK || !s)
return NULL;
return ms_ole_summary_open_stream (s);
......@@ -285,21 +287,14 @@ ms_ole_summary_create_stream (MsOleStream *s)
MsOleSummary *
ms_ole_summary_create (MsOle *f)
{
MsOleDirectory *dir;
MsOleStream *s;
MsOleStream *s;
MsOleErr result;
g_return_val_if_fail (f != NULL, NULL);
dir = ms_ole_directory_create (ms_ole_get_root (f),
"SummaryInformation",
MsOlePPSStream);
if (!dir) {
printf ("ms_ole_summary_create: Can't create stream\n");
return NULL;
}
s = ms_ole_stream_open (dir, 'w');
if (!s) {
result = ms_ole_stream_open (&s, f, "/",
"SummaryInformation", 'w');
if (result != MS_OLE_ERR_OK || !s) {
printf ("ms_ole_summary_create: Can't open stream for writing\n");
return NULL;
}
......@@ -343,8 +338,7 @@ void ms_ole_summary_close (MsOleSummary *si)
si->items = NULL;
if (si->s)
ms_ole_stream_close (si->s);
si->s = NULL;
ms_ole_stream_close (&si->s);
g_free (si);
}
......
This diff is collapsed.
......@@ -35,13 +35,21 @@
/* Whether to use memory mapped IO */
#define OLE_MMAP 1
typedef enum { MS_OLE_ERR_OK,
MS_OLE_ERR_EXIST,
MS_OLE_ERR_INVALID,
MS_OLE_ERR_FORMAT,
MS_OLE_ERR_PERM,
MS_OLE_ERR_MEM,
MS_OLE_ERR_SPACE,
MS_OLE_ERR_BADARG } MsOleErr;
/* Block pointer */
typedef guint32 BLP;
/* Forward declarations of types */
typedef struct _MsOle MsOle;
typedef struct _MsOle MsOle;
typedef struct _MsOleStream MsOleStream;
typedef struct _MsOleDirectory MsOleDirectory;
typedef enum { MsOleSeekSet, MsOleSeekCur, MsOleSeekEnd } MsOleSeek;
#ifdef G_HAVE_GINT64
......@@ -52,72 +60,25 @@ typedef enum { MsOleSeekSet, MsOleSeekCur, MsOleSeekEnd } MsOleSeek;
typedef guint32 MsOlePos;
#endif
typedef guint32 PPS_IDX ;
typedef enum _PPSType { MsOlePPSStorage = 1,
MsOlePPSStream = 2,
MsOlePPSRoot = 5} PPSType ;
/**
* Structure describing an OLE file
**/
struct _MsOle
{
guint8 *mem ;
guint32 length ;
/**
* To be considered private
**/
char mode;
int file_des;
int dirty;
GArray *bb; /* Big blocks status */
#if !OLE_MMAP
GPtrArray *bbattr; /* Pointers to block structures */
#endif
GArray *sb; /* Small block status */
GArray *sbf; /* The small block file */
guint32 num_pps;/* Count of number of property sets */
GList *pps; /* Property Storage -> struct _PPS, always 1 valid entry or NULL */
};
#ifndef MS_OLE_H_IMPLEMENTATION
struct _MsOle {
int dummy;
};
#endif /* MS_OLE_H_IMPLEMENTATION */
/* Create new OLE file */
extern MsOle *ms_ole_create (const char *name) ;
extern MsOleErr ms_ole_create (MsOle **, const char *name) ;
/* Open existing OLE file */
extern MsOle *ms_ole_open (const char *name) ;
/* Get a root directory handle */
extern MsOleDirectory *ms_ole_get_root (MsOle *);
extern void ms_ole_destroy (MsOle *ptr) ;
extern MsOleDirectory *ms_ole_path_decode (MsOle *, const char *path);
extern MsOleDirectory *ms_ole_file_decode (MsOle *, const char *path, const char *file);
struct _MsOleDirectory
{
char *name;
MsOlePos length;
PPSType type;
GList *pps;
int first;
/* Private */
MsOle *file ;
};
/* Directory manipulation API */
extern MsOleDirectory *ms_ole_directory_new (MsOle *) ;
extern gboolean ms_ole_directory_next (MsOleDirectory *) ;
extern void ms_ole_directory_enter (MsOleDirectory *) ;
/* Pointer to the directory in which to create a new stream / storage object */
extern MsOleDirectory *ms_ole_directory_create (MsOleDirectory *d,
char *name,
PPSType type) ;
extern MsOleDirectory *ms_ole_directory_copy (const MsOleDirectory *);
extern void ms_ole_directory_unlink (MsOleDirectory *) ;
extern void ms_ole_directory_destroy (MsOleDirectory *) ;
extern MsOleErr ms_ole_open (MsOle **, const char *name) ;
extern void ms_ole_ref (MsOle *);
extern void ms_ole_unref (MsOle *);
extern void ms_ole_destroy (MsOle **);
struct _MsOleStream
{
enum { MsOleSmallBlock, MsOleLargeBlock } type;
MsOlePos size; /* Size in bytes */
MsOleDirectory *dir; /* directory handle for this file */
/**
* Attempts to copy length bytes into *ptr, returns true if
......@@ -142,22 +103,23 @@ struct _MsOleStream
* PRIVATE
**/
MsOle *file ;
void *pps ; /* Straight PPS * */
void *pps ; /* Straight PPS * */
GArray *blocks; /* A list of the blocks in the file if NULL: no file */
MsOlePos position; /* Current offset into file. Points to the next byte to read */
enum { MsOleSmallBlock, MsOleLargeBlock } strtype; /* Type of stream */
};
/* Mode = 'r' or 'w' */
extern MsOleStream *ms_ole_stream_open (MsOleDirectory *d, char mode) ;
extern MsOleStream *ms_ole_stream_open_name (MsOle *f, const char *name, char mode) ;
extern MsOleStream *ms_ole_stream_copy (MsOleStream *);
extern void ms_ole_stream_close (MsOleStream *) ;
extern MsOleErr ms_ole_stream_open (MsOleStream ** const stream, MsOle *f,
const char *path, const char *fname, char mode);
extern MsOleErr ms_ole_stream_close (MsOleStream ** const stream);
extern MsOleErr ms_ole_stream_duplicate (MsOleStream ** const copy,
const MsOleStream * const stream);
extern MsOleErr ms_ole_storage_unlink (MsOle *f, const char *path);
extern MsOleErr ms_ole_stream_unlink (MsOle *f, const char *path);
extern MsOleErr ms_ole_storage_directory (char ***names, const char *path);
extern void dump (guint8 const *ptr, guint32 len) ;
/* Do not use */
extern void ms_ole_debug (MsOle *, int magic);
#endif
......@@ -109,13 +109,21 @@ BiffQuery *
ms_biff_query_copy (const BiffQuery *p)
{
BiffQuery *bf = g_new (BiffQuery, 1);
memcpy (bf, p, sizeof (BiffQuery));
if (p->data_malloced)
{
if (p->data_malloced) {
bf->data = (guint8 *)g_malloc (p->length);
memcpy (bf->data, p->data, p->length);
}
bf->pos=ms_ole_stream_copy (p->pos);
if (ms_ole_stream_duplicate (&bf->pos, p->pos) !=
MS_OLE_ERR_OK) {
g_free (bf->data);
g_free (bf);
return NULL;
}
return bf;
}
......
......@@ -2717,43 +2717,6 @@ biff_get_externsheet_name(ExcelWorkbook *wb, guint16 idx, gboolean get_first)
return bsd->sheet->gnum_sheet;
}
/**
* Find a stream with the correct name
**/
static MsOleStream *
find_workbook (MsOle *ptr)
{
/* Find the right Stream ... John 4:13-14 */
MsOleDirectory *d = ms_ole_get_root (ptr);
ms_ole_directory_enter (d);
/*
* The thing to seek; first the kingdom of God, then this:
*/
while (ms_ole_directory_next (d)) {
if (d->type == MsOlePPSStream) {
int hit = 0;
/*
* printf ("Checking '%s'\n", d->name);
*/
hit |= (g_strncasecmp (d->name, "book", 4) == 0);
hit |= (g_strncasecmp (d->name, "workbook", 8) == 0);
if (hit) {
MsOleStream *stream;
printf (" '%s' ", d->name);
stream = ms_ole_stream_open (d, 'r');
ms_ole_directory_destroy (d);
return stream;
}
}
}
printf ("No Excel file found\n");
ms_ole_directory_destroy (d);
return 0;
}
/*
* see S59DEC.HM,
*/
......@@ -2807,6 +2770,7 @@ ms_excel_read_workbook (Workbook *workbook, MsOle *file)
{
ExcelWorkbook *wb = NULL;
MsOleStream *stream;
MsOleErr result;
BiffQuery *q;
BIFF_BOF_DATA *ver = 0;
int current_sheet = 0;
......@@ -2815,7 +2779,18 @@ ms_excel_read_workbook (Workbook *workbook, MsOle *file)
/* cell_deep_freeze_dependencies (); */
/* Find that book file */
stream = find_workbook (file);
result = ms_ole_stream_open (&stream, file, "/", "book", 'r');
if (result != MS_OLE_ERR_OK) {
ms_ole_stream_close (&stream);
result = ms_ole_stream_open (&stream, file, "/", "workbook", 'r');
if (result != MS_OLE_ERR_OK) {
ms_ole_stream_close (&stream);
g_warning ("No Excel stream found: wierd");
return FALSE;
}
}
q = ms_biff_query_new (stream);
while (ms_biff_query_next (q)) {
......@@ -3237,8 +3212,7 @@ ms_excel_read_workbook (Workbook *workbook, MsOle *file)
ms_biff_query_destroy (q);
if (ver)
ms_biff_bof_data_destroy (ver);
ms_ole_stream_close (stream);
ms_ole_stream_close (&stream);
#ifndef NO_DEBUG_EXCEL
if (ms_excel_read_debug > 1) {
......
......@@ -1509,34 +1509,28 @@ int
ms_excel_write_workbook (MsOle *file, Workbook *wb,
eBiff_version ver)
{
MsOleDirectory *dir;
MsOleStream *str;
BiffPut *bp;
char *strname;
MsOleErr result;
char *strname;
MsOleStream *str;
BiffPut *bp;
g_return_val_if_fail (wb, 0);
g_return_val_if_fail (file, 0);
g_return_val_if_fail (ver>=eBiffV7, 0);
g_return_val_if_fail (wb != NULL, 0);
g_return_val_if_fail (file != NULL, 0);
g_return_val_if_fail (ver >= eBiffV7, 0);
if (!file || !wb) {
printf ("Can't write Null pointers\n");
return 0;
}
if (ver>=eBiffV8)
if (ver >= eBiffV8)
strname = "Workbook";
else
strname = "Book";
dir = ms_ole_directory_create (ms_ole_get_root (file),
strname,
MsOlePPSStream);
if (!dir) {
printf ("Can't create stream\n");
return 0;
}
str = ms_ole_stream_open (dir, 'w');
if (!str) {
result = ms_ole_stream_open (&str, file, "/", strname, 'w');
if (result != MS_OLE_ERR_OK) {
printf ("Can't open stream for writing\n");
return 0;
}
......@@ -1551,9 +1545,13 @@ ms_excel_write_workbook (MsOle *file, Workbook *wb,
ms_biff_put_commit (bp);
}
ms_biff_put_destroy (bp);
ms_biff_put_destroy (bp);
ms_ole_stream_close (&str);
ms_ole_stream_close (str);
ms_ole_directory_destroy (dir);
return 1;
}
......@@ -61,7 +61,7 @@ excel_to_gnumeric (guint32 type)
* converts it back to an MsOleSummaryPID.
*
**/
MsOleSummaryPID
static MsOleSummaryPID
sum_name_to_excel (gchar *name)
{
gint i, j;
......
......@@ -340,7 +340,7 @@ sheet_object_container_load (SheetObject *so,
soc->client_site = gnome_client_site_new (so->sheet->workbook->gnome_container);
if (!soc->repoid)
return NULL;
return FALSE;
soc->object_server = gnome_object_activate_with_goad_id (NULL, soc->repoid, 0, NULL);
if (!soc->object_server)
......
......@@ -120,7 +120,7 @@ plugins_cmd (GtkWidget *widget, Workbook *wb)
gtk_widget_show(pm);
}
void
static void
about_cmd (GtkWidget *widget, Workbook *wb)
{
dialog_about (wb);
......@@ -2198,7 +2198,7 @@ create_format_toolbar (Workbook *wb)
gtk_widget_show (wb->priv->size_widget);
len = gdk_string_measure (wb->priv->size_widget->style->font, "000000");
gtk_widget_set_usize (GTK_ENTRY (wb->priv->size_widget), len, 0);
gtk_widget_set_usize (GTK_WIDGET (wb->priv->size_widget), len, 0);
gtk_signal_connect (
GTK_OBJECT (wb->priv->size_widget), "activate",
GTK_SIGNAL_FUNC (change_font_size_in_selection_cmd), wb);
......
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