Commit 7f442c3b authored by Michael Meeks's avatar Michael Meeks
Browse files

Started re-organising for write-side.

Stubbed BIFF helper functions.
Cleaned NUMBER reading.
parent 6604f0f8
1999-05-12 Michael Meeks <michael@imaginator.com>
* ms-biff.h: Major overhaul, added some fields to be implemented.
Added stubs for new BIFF write-side.
* ms-biff.c (biff_setdouble): Implemented.
* ms-excel.c (ms_excel_read_cell): BIFF_NUMBER: Removed last
vestige of nasty number->text->number sillyness.
* Makefile.am (libexcel_a_SOURCES): Added excel.h,
ms-excel-write.[ch].
* boot.c (excel_load): Updated name & headers.
* ms-excel.c (ms_excel_write_workbook): Stubbed.
* ms-excel.h: Split out excel specifics into smaller header.
Renamed functions to remove nasty mixed case.
1999-05-12 Michael Meeks <michael@imaginator.com>
* ole.c (main): Add check on ptr to fix NULL pointers getting
......
......@@ -11,6 +11,7 @@ noinst_LIBRARIES = libexcel.a
libexcel_a_SOURCES = \
boot.c \
boot.h \
excel.h \
ms-excel-biff.h \
ms-biff.c \
ms-biff.h \
......@@ -20,6 +21,8 @@ libexcel_a_SOURCES = \
ms-escher.h \
ms-excel.c \
ms-excel.h \
ms-excel-write.c \
ms-excel-write.h \
ms-formula.c \
ms-formula.h \
ms-obj.c \
......
......@@ -30,4 +30,9 @@ Or to put / get files to / from an OLE file use:
or
./ole somefile.xls get <stream name> <filename>
1999-04-13 Michael Meeks <michael@imaginator.com>
\ No newline at end of file
1999-04-13 Michael Meeks <michael@imaginator.com>
TODO:
padding in BIFF records, implement properly.
biff_put etc. needs to be written.
\ No newline at end of file
......@@ -19,8 +19,7 @@
#include "sheet.h"
#include "file.h"
#include "ms-ole.h"
#include "ms-excel.h"
#include "excel.h"
#include "boot.h"
static gboolean
......@@ -48,7 +47,7 @@ excel_load (const char *filename)
if (!f)
return NULL;
wb = ms_excelReadWorkbook (f);
wb = ms_excel_read_workbook (f);
if (wb) {
char *name = g_strconcat (filename, ".gnumeric", NULL);
workbook_set_filename (wb, name);
......
/**
* excel.h: Excel support interface to gnumeric
*
* Author:
* Michael Meeks (michael@imaginator.com)
**/
#ifndef GNUMERIC_EXCEL_H
#define GNUMERIC_EXCEL_H
#include "ms-ole.h"
extern Workbook *ms_excel_read_workbook (MS_OLE *file);
extern void ms_excel_write_workbook (MS_OLE *file, Workbook *wb);
#endif
......@@ -21,6 +21,35 @@
#define BIFF_DEBUG 0
/*******************************************************************************/
/* Helper Functions */
/*******************************************************************************/
#if G_BYTE_ORDER == G_BIG_ENDIAN
double biff_getdouble (guint8 *p)
{
double d;
int i;
guint8 *t = (guint8 *)&d;
int sd = sizeof (d);
for (i = 0; i < sd; i++)
t[i] = p[sd - 1 - i];
return d;
}
void biff_setdouble (guint8 *p, double d)
{
int i;
guint8 *t = (guint8 *)&d;
int sd = sizeof (d);
for (i = 0; i < sd; i++)
p[sd - 1 - i] = t[i];
}
#endif
static void
dump_biff (BIFF_QUERY *bq)
{
......@@ -30,6 +59,10 @@ dump_biff (BIFF_QUERY *bq)
/* dump_stream (bq->pos); */
}
/*******************************************************************************/
/* Read Side */
/*******************************************************************************/
BIFF_QUERY *
ms_biff_query_new (MS_OLE_STREAM *ptr)
{
......@@ -221,17 +254,41 @@ ms_biff_query_destroy (BIFF_QUERY *bq)
}
}
#if G_BYTE_ORDER == G_BIG_ENDIAN
double biff_getdouble(guint8 *p)
{
double d;
int i;
guint8 *t = (guint8 *)&d;
int sd = sizeof (d);
/*******************************************************************************/
/* Write Side */
/*******************************************************************************/
for (i = 0; i < sd; i++)
t[i] = p[sd - 1 - i];
return d;
/* Sets up a record on a stream */
BIFF_PUT *
ms_biff_put_new (MS_OLE_STREAM *s)
{
return 0;
}
#endif
void
ms_biff_put_set_pad (BIFF_PUT *bp, guint pad)
{
}
guint8 *
ms_biff_put_next_len (BIFF_PUT *bp, guint32 len)
{
return 0;
}
void
ms_biff_put_commit_len (BIFF_PUT *bp)
{
}
MS_OLE_STREAM *
ms_biff_put_next_var (BIFF_PUT *bp)
{
return 0;
}
void
ms_biff_put_commit_var (BIFF_PUT *bp, guint32 len)
{
}
void
ms_biff_put_destroy (BIFF_PUT *bp)
{
}
......@@ -24,10 +24,17 @@ typedef guint64 DLONG;
double biff_getdouble(guint8 *p);
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
# define BIFF_GETDOUBLE(p) (*((double*)(p)))
# define BIFF_GETDOUBLE(p) (*((double*)(p)))
# define BIFF_SETDOUBLE(p,q) (*((double*)(p))=(q))
#else
# define BIFF_GETDOUBLE(p) (biff_getdouble(p))
# define BIFF_GETDOUBLE(p) (biff_getdouble(p))
# define BIFF_SETDOUBLE(p,q) (biff_setdouble(p,q))
#endif
/*******************************************************************************/
/* Read Side */
/*******************************************************************************/
/**
* Returns query data, it is imperative that copies of
* 'data *' should _not_ be kept.
......@@ -41,21 +48,49 @@ typedef struct _BIFF_QUERY
guint8 *data;
guint32 streamPos;
guint16 num_merges;
guint16 padding;
int data_malloced; /* is *data a copy ? */
MS_OLE_STREAM *pos;
} BIFF_QUERY;
/* Sets up a query on a stream */
extern BIFF_QUERY *ms_biff_query_new (MS_OLE_STREAM *);
extern BIFF_QUERY *ms_biff_query_new (MS_OLE_STREAM *);
/* Duplicates this query, so chaining can re-commence here */
extern BIFF_QUERY *ms_biff_query_copy (const BIFF_QUERY *p);
/**
* Updates the BIFF_QUERY structure with the next BIFF record
* returns: 1 for succes, and 0 for EOS(tream)
**/
extern int ms_biff_query_next (BIFF_QUERY *);
extern int ms_biff_query_next_merge (BIFF_QUERY *, gboolean do_merge);
extern BIFF_QUERY *ms_biff_query_copy (const BIFF_QUERY *p);
/* Updates the BIFF_QUERY structure with the next BIFF record
* returns: 1 for succes, and 0 for EOS(tream) */
extern int ms_biff_query_next (BIFF_QUERY *);
extern int ms_biff_query_next_merge (BIFF_QUERY *, gboolean do_merge);
/* Converts a merged query to the un-merged equivalent */
extern void ms_biff_query_unmerge (BIFF_QUERY *);
extern void ms_biff_query_destroy (BIFF_QUERY *);
extern void ms_biff_query_unmerge (BIFF_QUERY *);
extern void ms_biff_query_destroy (BIFF_QUERY *);
/*******************************************************************************/
/* Write Side */
/*******************************************************************************/
typedef struct _BIFF_PUT
{
guint8 ms_op;
guint8 ls_op;
guint32 length; /* NB. can be extended by a continue opcode */
guint8 *data;
guint32 streamPos;
guint16 num_merges;
guint padding;
int data_malloced; /* is *data a copy ? */
MS_OLE_STREAM *pos;
} BIFF_PUT;
/* Sets up a record on a stream */
extern BIFF_PUT *ms_biff_put_new (MS_OLE_STREAM *);
extern void ms_biff_put_set_pad (BIFF_PUT *, guint);
/* For known length records */
extern guint8 *ms_biff_put_next_len (BIFF_PUT *, guint32 len);
extern void ms_biff_put_commit_len (BIFF_PUT *);
/* For unknown length records */
extern MS_OLE_STREAM *ms_biff_put_next_var (BIFF_PUT *);
extern void ms_biff_put_commit_var (BIFF_PUT *, guint32 len);
extern void ms_biff_put_destroy (BIFF_PUT *);
#endif
......@@ -28,18 +28,21 @@
#include "ms-ole.h"
#include "ms-biff.h"
#include "ms-formula.h"
#include "excel.h"
#include "ms-excel.h"
#include "ms-excel-biff.h"
#include "ms-obj.h"
#include "ms-escher.h"
#define EXCEL_DEBUG 0
/* This many styles are reserved */
#define XF_MAGIC_OFFSET (16 + 4)
/* Forward references */
static MS_EXCEL_SHEET *ms_excel_sheet_new (MS_EXCEL_WORKBOOK * wb, char *name) ;
static void ms_excel_workbook_attach (MS_EXCEL_WORKBOOK * wb, MS_EXCEL_SHEET * ans) ;
static MS_EXCEL_SHEET *ms_excel_sheet_new (MS_EXCEL_WORKBOOK *wb,
char *name) ;
static void ms_excel_workbook_attach (MS_EXCEL_WORKBOOK *wb,
MS_EXCEL_SHEET *ans) ;
/**
* Generic 16 bit int index pointer functions.
......@@ -159,8 +162,7 @@ biff_get_text (BYTE *pos, guint32 length, guint32* byte_length)
dump (pos, *byte_length) ;
}
for (lp = 0; lp < length; lp++)
{
for (lp = 0; lp < length; lp++) {
guint16 c;
if (high_byte) {
c = BIFF_GETWORD(ptr);
......@@ -1541,20 +1543,12 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
case BIFF_DBCELL: /* S59D6D.HTM */
/* Can be ignored on read side */
break ;
case BIFF_NUMBER:
{
char buf[MS_EXCEL_DOUBLE_FORMAT_LEN];
double num = BIFF_GETDOUBLE (q->data + 6); /*
* FIXME GETDOUBLE is not endian independant
*/
/* dump (q->data, q->length);
snprintf (buf, 64, "NUM %f", num); */
snprintf (buf, MS_EXCEL_DOUBLE_FORMAT_LEN-1,
MS_EXCEL_DOUBLE_FORMAT, num);
ms_excel_sheet_insert (sheet, EX_GETXF (q), EX_GETCOL (q),
EX_GETROW (q), buf);
break;
}
case BIFF_NUMBER: {
Value *v = value_float (BIFF_GETDOUBLE (q->data + 6));
ms_excel_sheet_insert_val (sheet, EX_GETXF (q), EX_GETCOL (q),
EX_GETROW (q), v);
break;
}
case BIFF_COLINFO: /* FIXME: See: S59D67.HTM */
{
int firstcol, lastcol, lp ;
......@@ -2053,7 +2047,7 @@ find_workbook (MS_OLE * ptr)
}
Workbook *
ms_excelReadWorkbook (MS_OLE * file)
ms_excel_read_workbook (MS_OLE * file)
{
MS_EXCEL_WORKBOOK *wb = NULL;
xmlNodePtr child;
......
......@@ -11,75 +11,73 @@
#include "ms-biff.h"
#include "ms-excel-biff.h"
extern Workbook *ms_excelReadWorkbook(MS_OLE *file) ;
typedef struct _MS_EXCEL_SHEET
{
int blank ;
Sheet *gnum_sheet ;
struct _MS_EXCEL_WORKBOOK *wb ;
eBiff_version ver ;
GHashTable *shared_formulae ;
} MS_EXCEL_SHEET ;
int blank;
Sheet *gnum_sheet;
struct _MS_EXCEL_WORKBOOK *wb;
eBiff_version ver;
GHashTable *shared_formulae;
} MS_EXCEL_SHEET;
typedef struct _BIFF_BOUNDSHEET_DATA
{
guint16 index ;
guint32 streamStartPos ;
eBiff_filetype type ;
eBiff_hidden hidden ;
char *name ;
guint16 index;
guint32 streamStartPos;
eBiff_filetype type;
eBiff_hidden hidden;
char *name;
MS_EXCEL_SHEET *sheet;
} BIFF_BOUNDSHEET_DATA ;
} BIFF_BOUNDSHEET_DATA;
typedef struct {
guint16 col ;
guint16 row ;
} BIFF_SHARED_FORMULA_KEY ;
guint16 col;
guint16 row;
} BIFF_SHARED_FORMULA_KEY;
typedef struct {
BIFF_SHARED_FORMULA_KEY key ;
BYTE *data ;
guint32 data_len ;
} BIFF_SHARED_FORMULA ;
BIFF_SHARED_FORMULA_KEY key;
BYTE *data;
guint32 data_len;
} BIFF_SHARED_FORMULA;
extern ExprTree *ms_excel_sheet_shared_formula (MS_EXCEL_SHEET *sheet,
int shr_col, int shr_row,
int col, int row) ;
int col, int row);
typedef struct _MS_EXCEL_PALETTE
{
int *red ;
int *green ;
int *blue ;
int length ;
StyleColor **gnum_cols ;
} MS_EXCEL_PALETTE ;
int *red;
int *green;
int *blue;
int length;
StyleColor **gnum_cols;
} MS_EXCEL_PALETTE;
typedef struct _BIFF_FONT_DATA
{
guint16 index ;
int height ; /* in 1/20ths of a point */
int italic ; /* boolean */
int struck_out ; /* boolean : strikethrough */
int color_idx ;
int boldness ; /* 100->1000 dec, normal = 0x190, bold = 0x2bc */
int script ; /* sub = -1, none = 0, super = 1 */
eBiffFontUnderline underline ;
char *fontname ;
StyleFont *style_font ;
} BIFF_FONT_DATA ;
guint16 index;
int height; /* in 1/20ths of a point */
int italic; /* boolean */
int struck_out; /* boolean : strikethrough */
int color_idx;
int boldness; /* 100->1000 dec, normal = 0x190, bold = 0x2bc */
int script; /* sub = -1, none = 0, super = 1 */
eBiffFontUnderline underline;
char *fontname;
StyleFont *style_font;
} BIFF_FONT_DATA;
typedef struct _BIFF_EXTERNSHEET_DATA {
guint16 sup_idx ;
guint16 first_tab ;
guint16 last_tab ;
} BIFF_EXTERNSHEET_DATA ;
guint16 sup_idx;
guint16 first_tab;
guint16 last_tab;
} BIFF_EXTERNSHEET_DATA;
typedef struct _BIFF_FORMAT_DATA {
guint16 idx ;
char *name ;
} BIFF_FORMAT_DATA ;
guint16 idx;
char *name;
} BIFF_FORMAT_DATA;
typedef struct _MS_EXCEL_WORKBOOK
{
......@@ -101,14 +99,11 @@ typedef struct _MS_EXCEL_WORKBOOK
/**
* Gnumeric parallel workbook
**/
Workbook *gnum_wb ;
} MS_EXCEL_WORKBOOK ;
#define MS_EXCEL_DOUBLE_FORMAT "%.16G"
#define MS_EXCEL_DOUBLE_FORMAT_LEN 65
Workbook *gnum_wb;
} MS_EXCEL_WORKBOOK;
extern Sheet* biff_get_externsheet_name (MS_EXCEL_WORKBOOK *wb, guint16 idx, gboolean get_first) ;
extern char* biff_get_text (BYTE *ptr, guint32 length, guint32 *byte_length) ;
extern const char* biff_get_error_text (const guint8 err) ;
extern char* biff_name_data_get_name (MS_EXCEL_SHEET *sheet, guint16 idx) ;
extern Sheet* biff_get_externsheet_name (MS_EXCEL_WORKBOOK *wb, guint16 idx, gboolean get_first);
extern char* biff_get_text (BYTE *ptr, guint32 length, guint32 *byte_length);
extern const char* biff_get_error_text (const guint8 err);
extern char* biff_name_data_get_name (MS_EXCEL_SHEET *sheet, guint16 idx);
#endif
/**
* ms-excel-write.c: MS Excel support for Gnumeric
*
* Author:
* Michael Meeks (michael@imaginator.com)
**/
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <config.h>
#include <stdio.h>
#include <ctype.h>
#include <gnome.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "gnome-xml/tree.h"
#include "gnome-xml/parser.h"
#include "gnumeric-sheet.h"
#include "format.h"
#include "color.h"
#include "sheet-object.h"
#include "style.h"
#include "main.h"
#include "ms-ole.h"
#include "ms-biff.h"
#include "excel.h"
#include "ms-excel-write.h"
void
ms_excel_write_workbook (MS_OLE *file, Workbook *wb)
{
}
/**
* ms-excel-write.h: MS Excel support for Gnumeric
*
* Author:
* Michael Meeks (michael@imaginator.com)
**/
#ifndef GNUMERIC_MS_EXCEL_WRITE_H
#define GNUMERIC_MS_EXCEL_WRITE_H
#include "ms-ole.h"
#include "ms-biff.h"
#include "ms-excel-biff.h"
typedef struct _MS_EXCEL_WORKBOOK
{
Workbook *gnum_wb;
} MS_EXCEL_WORKBOOK;
#endif
......@@ -28,18 +28,21 @@
#include "ms-ole.h"
#include "ms-biff.h"
#include "ms-formula.h"
#include "excel.h"
#include "ms-excel.h"
#include "ms-excel-biff.h"
#include "ms-obj.h"
#include "ms-escher.h"
#define EXCEL_DEBUG 0
/* This many styles are reserved */
#define XF_MAGIC_OFFSET (16 + 4)
/* Forward references */
static MS_EXCEL_SHEET *ms_excel_sheet_new (MS_EXCEL_WORKBOOK * wb, char *name) ;
static void ms_excel_workbook_attach (MS_EXCEL_WORKBOOK * wb, MS_EXCEL_SHEET * ans) ;
static MS_EXCEL_SHEET *ms_excel_sheet_new (MS_EXCEL_WORKBOOK *wb,
char *name) ;
static void ms_excel_workbook_attach (MS_EXCEL_WORKBOOK *wb,
MS_EXCEL_SHEET *ans) ;
/**
* Generic 16 bit int index pointer functions.
......@@ -159,8 +162,7 @@ biff_get_text (BYTE *pos, guint32 length, guint32* byte_length)
dump (pos, *byte_length) ;
}
for (lp = 0; lp < length; lp++)
{
for (lp = 0; lp < length; lp++) {
guint16 c;
if (high_byte) {
c = BIFF_GETWORD(ptr);
......@@ -1541,20 +1543,12 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
case BIFF_DBCELL: /* S59D6D.HTM */
/* Can be ignored on read side */
break ;
case BIFF_NUMBER:
{
char buf[MS_EXCEL_DOUBLE_FORMAT_LEN];
double num = BIFF_GETDOUBLE (q->data + 6); /*
* FIXME GETDOUBLE is not endian independant
*/
/* dump (q->data, q->length);
snprintf (buf, 64, "NUM %f", num); */
snprintf (buf, MS_EXCEL_DOUBLE_FORMAT_LEN-1,
MS_EXCEL_DOUBLE_FORMAT, num);
ms_excel_sheet_insert (sheet, EX_GETXF (q), EX_GETCOL (q),
EX_GETROW (q), buf);
break;
}
case BIFF_NUMBER: {
Value *v = value_float (BIFF_GETDOUBLE (q->data + 6));
ms_excel_sheet_insert_val (sheet, EX_GETXF (q), EX_GETCOL (q),
EX_GETROW (q), v);
break;
}
case BIFF_COLINFO: /* FIXME: See: S59D67.HTM */
{
int firstcol, lastcol, lp ;
......@@ -2053,7 +2047,7 @@ find_workbook (MS_OLE * ptr)
}
Workbook *
ms_excelReadWorkbook (MS_OLE * file)
ms_excel_read_workbook (MS_OLE * file)
{
MS_EXCEL_WORKBOOK *wb = NULL;
xmlNodePtr child;
......
......@@ -11,75 +11,73 @@
#include "ms-biff.h"
#include "ms-excel-biff.h"
extern Workbook *ms_excelReadWorkbook(MS_OLE *file) ;
typedef struct _MS_EXCEL_SHEET
{
int blank ;
Sheet *gnum_sheet ;
struct _MS_EXCEL_WORKBOOK *wb ;
eBiff_version ver ;
GHashTable *shared_formulae ;
} MS_EXCEL_SHEET ;
int blank;
Sheet *gnum_sheet;
struct _MS_EXCEL_WORKBOOK *wb;
eBiff_version ver;
GHashTable *shared_formulae;
} MS_EXCEL_SHEET;
typedef struct _BIFF_BOUNDSHEET_DATA