Commit ce518b44 authored by Michael Meeks's avatar Michael Meeks

Robert Brady's initial GNU Oleo import filter.

parent 2ea06f97
No preview for this file type
......@@ -24,6 +24,9 @@ Federico:
* Added "open hand" and "closed hand" cursors for dragging the
print preview.
Robert:
* Primitive oleo import : supports numbers and text.
--------------------------------------------------------------------------
Gnumeric 0.39
......
No preview for this file type
......@@ -272,6 +272,7 @@ plugins/sample/Makefile
plugins/excel/Makefile
plugins/excel/libole2/Makefile
plugins/lotus-123/Makefile
plugins/oleo/Makefile
plugins/python/Makefile
plugins/perl/Makefile
plugins/perl/ext/Makefile.PL
......
......@@ -19,6 +19,6 @@ endif
#SUBDIRS = sample stat excel ff-csv text $(PYTHON) $(PERL) $(GUILE_DIR) xbase
SUBDIRS = sample stat excel lotus-123 ff-csv text xbase html $(PYTHON) $(GUILE_DIR)
SUBDIRS = sample stat excel lotus-123 oleo ff-csv text xbase html $(PYTHON) $(GUILE_DIR)
Makefile.in
Makefile
.deps
.libs
*.lo
liboleo.la
1999-11-07 Michael Meeks <mmeeks@gnu.org>
* oleo.c: Quietened warnings.
1999-11-07 Robert Brady <rwb197@ecs.soton.ac.uk>
* oleo.c: Created.
* boot.c: Created.
* Makefile.am: Created.
\ No newline at end of file
GNUMERIC_SRC_DIR = $(top_srcdir)/src
INCLUDES = \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
-DGNUMERIC_VERSION=\""$(VERSION)"\" \
-I$(includedir) \
-I$(top_srcdir)/src \
$(GNOME_INCLUDEDIR)
plugindir = $(libdir)/gnumeric/plugins
plugin_LTLIBRARIES = liboleo.la
liboleo_la_SOURCES = \
boot.c \
oleo.c \
oleo.h
/**
* boot.c: Oleo support for Gnumeric
*
* Author:
* See: README
* Robert Brady <rwb197@ecs.soton.ac.uk>
*
* (this file adapted from lotus-123/boot.c)
**/
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <assert.h>
#include <config.h>
#include <stdio.h>
#include <ctype.h>
#include <gnome.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "main.h"
#include "sheet.h"
#include "file.h"
#include "oleo.h"
#include "plugin.h"
static char *
filename_ext(const char *filename)
{
char *p = strrchr (filename, '.');
if (p == NULL)
return NULL;
return ++p;
}
static gboolean
oleo_probe (const char *filename)
{
char *ext;
if (!filename)
return FALSE;
ext = filename_ext (filename);
if (!ext)
return FALSE;
if (!g_strcasecmp ("oleo", ext))
return TRUE;
return FALSE;
}
static gboolean
oleo_load (Workbook *wb, const char *filename)
{
char *name, *p;
gboolean ret;
ret = oleo_read (wb, filename);
if (ret) {
if ((p = filename_ext (filename)) != NULL)
*p = '\0'; /* remove "oleo" */
name = g_strconcat (p, "gnumeric", NULL);
workbook_set_filename (wb, name);
g_free (name);
}
return ret;
}
static int
oleo_can_unload (PluginData *pd)
{
return TRUE;
}
static void
oleo_cleanup_plugin (PluginData *pd)
{
file_format_unregister_open (oleo_probe, oleo_load);
}
int
init_plugin (PluginData *pd)
{
char *descr = _("GNU Oleo (*.oleo) file format");
file_format_register_open (100, descr, oleo_probe, oleo_load);
pd->can_unload = oleo_can_unload;
pd->cleanup_plugin = oleo_cleanup_plugin;
pd->title = g_strdup (_("GNU Oleo import plugin"));
return 0;
}
/*
* GNU Oleo input filter for Gnumeric
*
* Robert Brady <rwb197@ecs.soton.ac.uk>
*
* partially based on the Lotus-123 code,
* partially based on actual Oleo code.
*
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <assert.h>
#include <config.h>
#include <stdio.h>
#include <ctype.h>
#include <gnome.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "main.h"
#include "sheet.h"
#include "file.h"
#include "utils.h"
#include "oleo.h"
#define OLEO_DEBUG 0
static Sheet *
attach_sheet (Workbook *wb, int idx)
{
Sheet *sheet;
char *sheet_name;
sheet_name = g_strdup_printf ("Sheet%d\n", idx);
sheet = sheet_new (wb, sheet_name);
g_free (sheet_name);
workbook_attach_sheet (wb, sheet);
return sheet;
}
#define OLEO_TO_GNUMERIC(a) ((a)-1)
#define GNUMERIC_TO_OLEO(a) ((a)+1)
static Cell *
oleo_insert_value (Sheet *sheet, guint32 col, guint32 row, Value *val)
{
Cell *cell;
g_return_val_if_fail (val != NULL, NULL);
g_return_val_if_fail (sheet != NULL, NULL);
cell = sheet_cell_fetch (sheet, OLEO_TO_GNUMERIC (col),
OLEO_TO_GNUMERIC (row));
g_return_val_if_fail (cell != NULL, NULL);
cell_set_value (cell, val);
return cell;
}
/* adapted from Oleo */
static long
astol (char **ptr)
{
long i = 0;
int c;
int sign = 1;
char *s;
s = *ptr;
/* Skip whitespace */
while (isspace (*s))
if (*s++ == '\0') {
*ptr = s;
return (0);
}
/* Check for - or + */
if (*s == '-') {
s++;
sign = -1;
}
else if (*s == '+')
s++;
/* Read in the digits */
for (; (c = *s); s++) {
if (!isdigit (c) || i > 214748364 ||
(i == 214748364 && c > (sign > 0 ? '7' : '8')))
break;
i = i * 10 + c - '0';
}
*ptr = s;
return i * sign;
}
static void
oleo_deal_with_cell (char *str, Sheet *sheet, int *ccol, int *crow)
{
char *ptr = str + 1, *cval = NULL;
while (*ptr) {
int quotes = 0;
if (*ptr != ';') {
#if OLEO_DEBUG > 0
fprintf (stderr, "ptr : %s\n", ptr);
#endif
break;
}
*ptr++ = '\0';
switch (*ptr++) {
case 'c' :
*ccol = astol (&ptr);
break;
case 'r' :
*crow = astol (&ptr);
break;
case 'K' :
cval = ptr;
quotes = 0;
while (*ptr && (*ptr != ';' || quotes > 0))
if (*ptr++ == '"')
quotes = !quotes;
break;
default:
#if OLEO_DEBUG > 0
fprintf (stderr, "oleo: Don't know how to deal with C; '%c'\n",
*ptr);
#endif
ptr = ""; /* I wish C had multilevel break */
break;
}
if (!*ptr)
break;
}
if (cval) {
char *error = NULL;
long result;
result = strtol(cval, &error, 10);
if (!*error)
oleo_insert_value (sheet, *ccol, *crow,
value_new_int (result));
else {
double double_result = strtod (cval, &error);
if (!*error)
oleo_insert_value (sheet, *ccol, *crow,
value_new_float ((float)double_result));
else {
char *last = cval + strlen(cval) - 1;
if (*cval == '"' && *last == '"') {
*last = 0;
oleo_insert_value (sheet, *ccol, *crow,
value_new_string (cval + 1));
}
else
oleo_insert_value (sheet, *ccol, *crow,
value_new_string (cval));
}
}
} else {
#if OLEO_DEBUG > 0
fprintf (stderr, "oleo: cval is NULL.\n");
#endif
}
}
gboolean
oleo_read (Workbook *wb, const char *filename)
{
FILE *f = fopen (filename, "rb");
int sheetidx = 0;
int ccol = 0, crow = 0;
Sheet *sheet = NULL;
char str[2048];
if (!f) return FALSE;
cell_deep_freeze_redraws ();
sheet = attach_sheet (wb, sheetidx++);
while (1) {
char *n;
fgets(str, 2000, f);
str[2000] = 0;
if (feof(f)) break;
n = strchr(str, '\n');
if (n)
*n = 0;
else
break;
switch (str[0]) {
case '#': /* Comment */
continue;
case 'C': /* Cell */
oleo_deal_with_cell (str, sheet, &ccol, &crow);
break;
default: /* unknown */
#if OLEO_DEBUG > 0
fprintf (stderr, "oleo: Don't know how to deal with %c.\n",
str[0]);
#endif
break;
}
}
fclose (f);
return TRUE;
}
#ifndef OLEO_H
#define OLEO_H
gboolean oleo_read (Workbook *wb, const char *filename);
#endif
# This file was created by GNU Oleo
# format 1.0
F;DGFL8
O;auto;background;noa0;ticks 1
C;c1;r1;K1
C;r3;K"One"
C;r4;K"Two"
C;r5;K"Three"
C;c2;r1;K2
C;r2;K4
C;c3;r1;K3
C;r2;K5
C;c4;r1;K0
C;r2;K-1
C;r3;K-2
C;r5;K#TRUE
C;r6;K#FALSE
C;r8;E-r3c4;K2
C;r9;Er1c4 + 2;K2
C;r11;Er[-2]c * r[-3]c;K4
C;c5;r1;K0.5
C;r2;K-0.5
C;r3;K-1.5
C;r5;K#INFINITY
C;r6;K#NOT_A_NUMBER
C;r8;E-r3c5;K1.5
C;r9;Er1c5 + 2;K2.5
C;r11;Er[-2]c * r[-3]c;K3.75
C;r13;Esum(r1c1:7);K20.3
C;c6;r1;K1.5
C;r2;K2.5
C;r3;K3.5
C;r5;K#MINUS_INFINITY
C;c7;r1;K12.3
C;r2;K14.3
C;r3;K17.3
O;status 2
W;N1;A10 2;C7 0 7;Ostandout
E
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