Commit 5545f74b authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

About time we got something like this.


2000-08-15  Morten Welinder  <terra@diku.dk>

	* src/gutils.c (gnumeric_get_le_int16, gnumeric_get_le_uint16,
 	gnumeric_get_le_int32, gnumeric_get_le_uint32,
 	gnumeric_get_le_double, gnumeric_set_le_double): new functions,
 	mostly for plugin support.
parent b9075446
2000-08-15 Morten Welinder <terra@diku.dk>
* src/gutils.c (gnumeric_get_le_int16, gnumeric_get_le_uint16,
gnumeric_get_le_int32, gnumeric_get_le_uint32,
gnumeric_get_le_double, gnumeric_set_le_double): new functions,
mostly for plugin support.
2000-08-15 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c (workbook_new) : Set the size after initializing
......
2000-08-15 Morten Welinder <terra@diku.dk>
* src/gutils.c (gnumeric_get_le_int16, gnumeric_get_le_uint16,
gnumeric_get_le_int32, gnumeric_get_le_uint32,
gnumeric_get_le_double, gnumeric_set_le_double): new functions,
mostly for plugin support.
2000-08-15 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c (workbook_new) : Set the size after initializing
......
2000-08-15 Morten Welinder <terra@diku.dk>
* src/gutils.c (gnumeric_get_le_int16, gnumeric_get_le_uint16,
gnumeric_get_le_int32, gnumeric_get_le_uint32,
gnumeric_get_le_double, gnumeric_set_le_double): new functions,
mostly for plugin support.
2000-08-15 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c (workbook_new) : Set the size after initializing
......
2000-08-15 Morten Welinder <terra@diku.dk>
* src/gutils.c (gnumeric_get_le_int16, gnumeric_get_le_uint16,
gnumeric_get_le_int32, gnumeric_get_le_uint32,
gnumeric_get_le_double, gnumeric_set_le_double): new functions,
mostly for plugin support.
2000-08-15 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c (workbook_new) : Set the size after initializing
......
2000-08-15 Morten Welinder <terra@diku.dk>
* src/gutils.c (gnumeric_get_le_int16, gnumeric_get_le_uint16,
gnumeric_get_le_int32, gnumeric_get_le_uint32,
gnumeric_get_le_double, gnumeric_set_le_double): new functions,
mostly for plugin support.
2000-08-15 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c (workbook_new) : Set the size after initializing
......
2000-08-15 Morten Welinder <terra@diku.dk>
* src/gutils.c (gnumeric_get_le_int16, gnumeric_get_le_uint16,
gnumeric_get_le_int32, gnumeric_get_le_uint32,
gnumeric_get_le_double, gnumeric_set_le_double): new functions,
mostly for plugin support.
2000-08-15 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c (workbook_new) : Set the size after initializing
......
2000-08-15 Morten Welinder <terra@diku.dk>
* src/gutils.c (gnumeric_get_le_int16, gnumeric_get_le_uint16,
gnumeric_get_le_int32, gnumeric_get_le_uint32,
gnumeric_get_le_double, gnumeric_set_le_double): new functions,
mostly for plugin support.
2000-08-15 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c (workbook_new) : Set the size after initializing
......
2000-08-15 Morten Welinder <terra@diku.dk>
* xbase.c: use new gnumeric_get_le_... support.
2000-07-27 Morten Welinder <terra@diku.dk>
* boot.c (xbase_field_as_value): Plug huge leaks. Fix 'I' case.
......
......@@ -32,24 +32,6 @@ static const char *field_type_descriptions [] = { /* FIXME: fix array size from
#endif
static guint16
deref_le_guint16 (const void *p)
{
guint16 data;
memcpy (&data, p, sizeof (data));
return GUINT16_FROM_LE (data);
}
static guint32
deref_le_guint32 (const void *p)
{
guint32 data;
memcpy (&data, p, sizeof (data));
return GUINT32_FROM_LE (data);
}
/**
* Newly allocated pointer to record, initialised as first in database.
*/
......@@ -143,17 +125,17 @@ xbase_read_header (XBfile *x)
default:
fprintf (stderr, "unknown!\n");
}
x->records = deref_le_guint32 (hdr + 4);
x->fieldlen = deref_le_guint16 (hdr + 10);
x->records = gnumeric_get_le_uint32 (hdr + 4);
x->fieldlen = gnumeric_get_le_uint16 (hdr + 10);
#if XBASE_DEBUG > 0
fprintf (stderr, "Last update (YY/MM/DD):\t%2d/%2d/%2d\n",hdr[1],hdr[2],hdr[3]); /* Y2K ?!? */
fprintf (stderr, "Records:\t%u\n", x->records);
fprintf (stderr, "Header length:\t%d\n", deref_le_guint16 (hdr + 8));
fprintf (stderr, "Header length:\t%d\n", gnumeric_get_le_uint16 (hdr + 8));
fprintf (stderr, "Record length:\t%d\n", x->fieldlen);
fprintf (stderr, "Reserved:\t%d\n", deref_le_guint16 (hdr + 12));
fprintf (stderr, "Reserved:\t%d\n", gnumeric_get_le_uint16 (hdr + 12));
fprintf (stderr, "Incomplete transaction:\t%d\n", hdr[14]);
fprintf (stderr, "Encryption flag:\t%d\n", hdr[15]);
fprintf (stderr, "Free record thread:\t%u\n", deref_le_guint32 (hdr + 16));
fprintf (stderr, "Free record thread:\t%u\n", gnumeric_get_le_uint32 (hdr + 16));
#ifdef THIS_IS_BOGUS
fprintf (stderr, "Reserved (multi-user):\t%lu\n", GUINT64_FROM_LE((guint64)hdr[20])); /* FIXME: printf needs to support 64-bit integers */
#endif
......@@ -184,7 +166,7 @@ xbase_read_header (XBfile *x)
default:
fprintf (stderr, "unknown!\n");
}
fprintf (stderr, "Reserved:\t%d\n", deref_le_guint16 (hdr + 30));
fprintf (stderr, "Reserved:\t%d\n", gnumeric_get_le_uint16 (hdr + 30));
#endif
return FALSE;
}
......@@ -225,7 +207,7 @@ xbase_read_field (XBfile *file)
else
fprintf (stderr, "Type:\t%c (%s)\n", ans->type,
field_type_descriptions [p-field_types]);
fprintf (stderr, "Data address:\t0x%.8X\n", deref_le_guint32 (buf + 12));
fprintf (stderr, "Data address:\t0x%.8X\n", gnumeric_get_le_uint32 (buf + 12));
fprintf (stderr, "Length:\t%d\n", ans->len);
fprintf (stderr, "Decimal count:\t%d\n", buf[17]);
#endif
......
......@@ -144,3 +144,109 @@ gnumeric_usr_plugin_dir (void)
{
return gnumeric_usr_dir (PLUGIN_SUFFIX);
}
/* ------------------------------------------------------------------------- */
/*
* Note: the code below might look awful, but fixed-sized memcpy ought to
* produce reasonable code.
*/
gint16
gnumeric_get_le_int16 (const void *p)
{
gint16 data;
memcpy (&data, p, sizeof (data));
return GINT16_FROM_LE (data);
}
guint16
gnumeric_get_le_uint16 (const void *p)
{
guint16 data;
memcpy (&data, p, sizeof (data));
return GUINT16_FROM_LE (data);
}
gint32
gnumeric_get_le_int32 (const void *p)
{
gint32 data;
memcpy (&data, p, sizeof (data));
return GINT32_FROM_LE (data);
}
guint32
gnumeric_get_le_uint32 (const void *p)
{
guint32 data;
memcpy (&data, p, sizeof (data));
return GUINT32_FROM_LE (data);
}
double
gnumeric_get_le_double (const void *p)
{
#if G_BYTE_ORDER == G_BIG_ENDIAN
if (sizeof (double) == 8) {
double d;
int i;
guint8 *t = (guint8 *)&d;
guint8 *p2 = (guint8 *)p;
int sd = sizeof (d);
for (i = 0; i < sd; i++)
t[i] = p2[sd - 1 - i];
return d;
} else {
g_error ("Big endian machine, but weird size of doubles");
}
#elif G_BYTE_ORDER == G_LITTLE_ENDIAN
if (sizeof (double) == 8) {
/*
* On i86, we could access directly, but Alphas require
* aligned access.
*/
double data;
memcpy (&data, p, sizeof (data));
return data;
} else {
g_error ("Little endian machine, but weird size of doubles");
}
#else
#error "Byte order not recognised -- out of luck"
#endif
}
void
gnumeric_set_le_double (void *p, double d)
{
#if G_BYTE_ORDER == G_BIG_ENDIAN
if (sizeof (double) == 8) {
int i;
guint8 *t = (guint8 *)&d;
guint8 *p2 = (guint8 *)p;
int sd = sizeof (d);
for (i = 0; i < sd; i++)
p2[sd - 1 - i] = t[i];
} else {
g_error ("Big endian machine, but weird size of doubles");
}
#elif G_BYTE_ORDER == G_LITTLE_ENDIAN
if (sizeof (double) == 8) {
/*
* On i86, we could access directly, but Alphas require
* aligned access.
*/
memcpy (p, &d, sizeof (d));
} else {
g_error ("Little endian machine, but weird size of doubles");
}
#else
#error "Byte order not recognised -- out of luck"
#endif
}
/* ------------------------------------------------------------------------- */
......@@ -22,4 +22,14 @@ char * gnumeric_sys_plugin_dir (void);
char * gnumeric_usr_dir (const char *subdir);
char * gnumeric_usr_plugin_dir (void);
/*
* Function to help with accessing non-aligned little-endian data.
*/
gint16 gnumeric_get_le_int16 (const void *p);
guint16 gnumeric_get_le_uint16 (const void *p);
gint32 gnumeric_get_le_int32 (const void *p);
guint32 gnumeric_get_le_uint32 (const void *p);
double gnumeric_get_le_double (const void *p);
void gnumeric_set_le_double (void *p, double d);
#endif /* GNUMERIC_UTILS_H */
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