Commit e6ed216d authored by Morten Welinder's avatar Morten Welinder

Polish up the csv file format. It might still not work.

parent b92dfe80
1999-06-14 Morten Welinder <terra@diku.dk>
* csv-io.c (csv_read_workbook): Make static.
(csv_read_workbook): Make static.
(csv_init): Make static.
(csv_cleanup_plugin): Fix type.
* csv-io.h: Fix includes.
1999-04-06 Miguel de Icaza <miguel@nuclecu.unam.mx>
* csv-io.c (csv_cleanup_plugin): Return proper value.
......@@ -10,4 +19,3 @@
1999-02-06 Vincent Renardias <vincent@ldsol.com>
* csv-io.h, csv-io.c: A few fixes.
......@@ -11,7 +11,7 @@ GNUMERIC_SRC_DIR = $(top_srcdir)/src
plugindir = $(libdir)/gnumeric/plugins
CFLAGS += -g -Wall \
-Wshadow -Wpointer-arith \
-Wpointer-arith \
-Wmissing-prototypes -Wmissing-declarations
plugin_LTLIBRARIES = libcsv.la
......
......@@ -15,18 +15,18 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <gnome.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include "../../src/gnumeric.h"
#include "../../src/gnumeric-util.h"
#include "../../src/plugin.h"
#include "csv-io.h"
#include "file.h"
#include "gnumeric-util.h"
static char
......@@ -39,12 +39,12 @@ insert_csv_cell (Sheet* sheet, char *string, int start, int end, int col, int ro
if(sheet == NULL)
return 0;
if (start > 1 && end > 1){
p = g_malloc (end - start + 1);
g_assert (p != NULL);
for (i = start; i <= end; i++){
p [ii++] = string [i];
}
......@@ -85,15 +85,15 @@ csv_parse_file (const char *filename,Sheet *sheet)
if ((fd = open (filename, O_RDONLY)) < 0){
char *msg;
int err = errno;
msg = g_strdup_printf (_("While opening %s\n%s"),
filename, g_strerror (err));
gnumeric_notice (NULL, GNOME_MESSAGE_BOX_ERROR, msg);
g_free (msg);
return 0;
return 0;
}
if (fstat (fd, &buf) == -1){
gnumeric_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
"Can not stat the file");
......@@ -102,13 +102,13 @@ csv_parse_file (const char *filename,Sheet *sheet)
}
/* FIXME: ARBITRARY VALUE */
if (buf.st_size < 1 || buf.st_size > 1000000){
if (buf.st_size < 1 || buf.st_size > 1000000){
close(fd);
return 0;
} else {
flen = buf.st_size;
}
if ((file = mmap (NULL, flen, PROT_READ, MAP_PRIVATE, fd, 0)) == (char*)-1){
gnumeric_notice (NULL, GNOME_MESSAGE_BOX_ERROR, "Can not mmap the file");
close (fd);
......@@ -119,7 +119,7 @@ csv_parse_file (const char *filename,Sheet *sheet)
switch (file [idx]){
case '\r':
if (file [idx+1] == '\n')
idx++;
idx++;
break;
case '\n':
if (data){ /* Non empty line */
......@@ -147,7 +147,7 @@ csv_parse_file (const char *filename,Sheet *sheet)
default:
if (file [idx] < 21 || file [idx] > 126){
non_printable++;
if (non_printable > 10){ /* FIXME: ARBITRARY VALUE */
if (non_printable > 10){ /* FIXME: ARBITRARY VALUE */
close (fd);
return 0;
}
......@@ -162,27 +162,30 @@ csv_parse_file (const char *filename,Sheet *sheet)
sheet->max_col_used=mcol;
sheet->max_row_used=crow;
}
munmap (file, flen);
munmap (file, flen);
close (fd);
return 1;
}
Workbook *
static Workbook *
csv_read_workbook (const char* filename)
{
Workbook *book;
Sheet *sheet;
book = workbook_new (); /* FIXME: Can this return NULL? */
book = workbook_new ();
if (!book) return NULL;
sheet = sheet_new (book, _("NoName"));
workbook_attach_sheet (book, sheet);
/*if (sheet != NULL){
book->sheet = sheet;
}*/
}*/
if ((csv_parse_file (filename, sheet)) == 0){
if ((csv_parse_file (filename, sheet)) == 0) {
workbook_destroy (book);
return NULL;
}
......@@ -200,21 +203,20 @@ csv_probe (const char *filename)
}
}
void
static void
csv_init (void)
{
char *desc = _("CSV (comma separated values)");
const char *desc = _("CSV (comma separated values)");
file_format_register_open (0, desc, csv_probe, csv_read_workbook);
/* file_format_register_save (".csv", desc, gnumericWriteCSVWorkbook);*/
}
static int
static void
csv_cleanup_plugin (PluginData *pd)
{
file_format_unregister_save (csv_read_workbook);
return TRUE;
file_format_unregister_open (csv_probe, csv_read_workbook);
/* file_format_unregister_save (csv_read_workbook); */
}
static int
......@@ -231,6 +233,6 @@ init_plugin (PluginData *pd)
pd->can_unload = csv_can_unload;
pd->cleanup_plugin = csv_cleanup_plugin;
pd->title = g_strdup (_("CSV (comma separated value file import/export plugin)"));
return 0;
}
......@@ -10,12 +10,9 @@
#ifndef GNUMERIC_CSV_IO_H
#define GNUMERIC_CSV_IO_H
Sheet *gnumericReadCSVSheet (const char *filename);
Workbook *gnumericReadCSVWorkbook (const char *filename);
/* not yet
int gnumericWriteCSVSheet (Sheet *sheet, const char *filename);
int gnumericWriteCSVWorkbook (Workbook *sheet, const char *filename);
*/
void csv_init (void);
#include "sheet.h"
#include "plugin.h"
int init_plugin (PluginData *pd);
#endif /* GNUMERIC_CSV_IO_H */
#
# Makefile for the Python Gnumeric plugin.
# Makefile for the Perl Gnumeric plugin.
#
#
......@@ -45,4 +45,4 @@ EXTRA_DIST = startup.pl
dist-hook:
mkdir $(distdir)/ext
cp $(srcdir)/ext/Gnumeric.* $(srcdir)/ext/Makefile.PL.in $(distdir)/ext
\ No newline at end of file
cp $(srcdir)/ext/Gnumeric.* $(srcdir)/ext/Makefile.PL.in $(distdir)/ext
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