Commit fde88d1f authored by JodyGoldberg's avatar JodyGoldberg Committed by Jody Goldberg
Browse files

just use strdup. (mps_add_row) : ditto. (mps_get_line): ditto. convert to


2002-06-14  Jody Goldberg <jody@gnome.org>

	* parser.c (mps_parse_name) : just use strdup.
	(mps_add_row) : ditto.
	(mps_get_line): ditto.
	* mps.c (mps_input_context_new) : convert to libgsf.
parent 2cf8f368
2002-06-14 Jody Goldberg <jody@gnome.org>
* parser.c (mps_parse_name) : just use strdup.
(mps_add_row) : ditto.
(mps_get_line): ditto.
* mps.c (mps_input_context_new) : convert to libgsf.
2002-05-29 Jody Goldberg <jody@gnome.org>
* Release 1.1.4
......
......@@ -59,6 +59,9 @@
GNUMERIC_MODULE_PLUGIN_INFO_DECL;
/* Error margin in the equiality comparison */
static const gchar *BINDING_LIMIT = "0.00000001";
/*************************************************************************
*
......@@ -599,28 +602,16 @@ mps_create_sheet (MpsInputContext *ctxt, WorkbookView *wbv)
/* Make the initializations. */
static MpsInputContext *
mps_input_context_new (IOContext *io_context, Workbook *wb, char const *file_name)
mps_input_context_new (IOContext *io_context, Workbook *wb, GsfInput *input)
{
MpsInputContext *ctxt = NULL;
gint size;
guchar *data;
ErrorInfo *mmap_error;
data = gnumeric_mmap_error_info (file_name, &size, &mmap_error);
if (mmap_error != NULL) {
gnumeric_io_error_info_set (io_context, mmap_error);
return NULL;
}
ctxt = g_new (MpsInputContext, 1);
ctxt->io_context = io_context;
ctxt->data_size = size;
ctxt->data = data;
ctxt->cur = data;
ctxt->input = gsf_input_textline_new (input);
ctxt->line_no = 1;
ctxt->line = g_malloc (1);
ctxt->line_len = 0;
ctxt->alloc_line_len = 0;
ctxt->line = NULL;
ctxt->sheet = workbook_sheet_add (wb, NULL, FALSE);
ctxt->name = NULL;
......@@ -638,7 +629,6 @@ mps_input_context_new (IOContext *io_context, Workbook *wb, char const *file_nam
g_slist_free (ctxt->rows);
io_progress_message (io_context, _("Reading file..."));
memory_io_progress_set (io_context, ctxt->data, ctxt->data_size);
return ctxt;
}
......@@ -669,7 +659,6 @@ mps_input_context_destroy (MpsInputContext *ctxt)
GSList *current;
io_progress_unset (ctxt->io_context);
munmap (ctxt->data, ctxt->data_size);
/* Free ROWS */
for (current = ctxt->rows; current != NULL; current = current->next) {
......@@ -721,6 +710,7 @@ mps_input_context_destroy (MpsInputContext *ctxt)
}
g_free (ctxt->line);
g_free (ctxt->name);
g_object_unref (G_OBJECT (ctxt->input)); ctxt->input = NULL;
g_free (ctxt);
}
......@@ -734,12 +724,12 @@ mps_input_context_destroy (MpsInputContext *ctxt)
void
mps_file_open (GnumFileOpener const *fo, IOContext *io_context,
WorkbookView *wbv, char const *file_name)
WorkbookView *wbv, GsfInput *input)
{
MpsInputContext *ctxt;
ctxt = mps_input_context_new (io_context, wb_view_workbook (wbv),
file_name);
input);
if (ctxt != NULL) {
mps_parse_file (ctxt);
if (gnumeric_io_error_occurred (io_context)) {
......
......@@ -26,6 +26,7 @@
#ifndef GNUMERIC_PLUGINS_MPS_H
#define GNUMERIC_PLUGINS_MPS_H 1
#include <gsf/gsf-input-textline.h>
#define N_INPUT_LINES_BETWEEN_UPDATES 50
#define MAX_COL 160
......@@ -113,12 +114,9 @@ typedef struct {
typedef struct {
IOContext *io_context;
gint data_size;
guchar *data, *cur;
GsfInputTextline *input;
gint line_no;
gchar *line;
gint line_len, alloc_line_len;
Sheet *sheet;
......@@ -152,9 +150,6 @@ static const int VARIABLE_ROW = 5;
static const int CONSTRAINT_COL = 1;
static const int CONSTRAINT_ROW = 10;
/* Error margin in the equiality comparison */
static const gchar *BINDING_LIMIT = "0.00000001";
/*************************************************************************
*
......@@ -163,7 +158,7 @@ static const gchar *BINDING_LIMIT = "0.00000001";
/* Reads the MPS file in and creates a spreadsheet model of it. */
void mps_file_open (GnumFileOpener const *fo, IOContext *io_context,
WorkbookView *wbv, char const *file_name);
WorkbookView *wbv, GsfInput *input);
void mps_parse_file (MpsInputContext *ctxt);
gboolean mps_add_row (MpsInputContext *ctxt, MpsRowType type, gchar *txt);
......
......@@ -63,47 +63,12 @@
static gboolean
mps_get_line (MpsInputContext *ctxt)
{
guchar *p, *p_limit;
try_again:
p_limit = ctxt->data + ctxt->data_size;
if (ctxt->cur >= p_limit) {
ctxt->line[0] = '\0';
ctxt->line_len = 0;
return FALSE;
}
for (p = ctxt->cur; p < p_limit && p[0] != '\n' && p[0] != '\r'; p++);
ctxt->line_len = p - ctxt->cur;
if (ctxt->line_len > ctxt->alloc_line_len) {
g_free (ctxt->line);
ctxt->alloc_line_len = MAX (ctxt->alloc_line_len * 2,
ctxt->line_len);
ctxt->line = g_malloc (ctxt->alloc_line_len + 1);
}
if (ctxt->line_len > 0) {
memcpy (ctxt->line, ctxt->cur, ctxt->line_len);
}
ctxt->line[ctxt->line_len] = '\0';
if (p == p_limit || (p == p_limit - 1 && (p[0] == '\n' ||
p[0] == '\r'))) {
ctxt->cur = p_limit;
} else if ((p[0] == '\n' && p[1] == '\r') || (p[0] == '\r' &&
p[1] == '\n')) {
ctxt->cur = p + 2;
} else {
ctxt->cur = p + 1;
}
if ((++ctxt->line_no % N_INPUT_LINES_BETWEEN_UPDATES) == 0) {
memory_io_progress_update (ctxt->io_context, ctxt->cur);
}
/* Check if a comment line */
if (ctxt->line[0] == '*')
goto try_again;
do {
ctxt->line = gsf_input_textline_ascii_gets (ctxt->input);
if (ctxt->line == NULL)
return FALSE;
/* Check if a comment line */
} while (ctxt->line[0] == '*');
return TRUE;
}
......@@ -244,9 +209,7 @@ mps_parse_name (MpsInputContext *ctxt)
while (isspace ((unsigned char) *line))
line++;
ctxt->name = strcpy (g_malloc (ctxt->line_len -
(line-ctxt->line) + 1),
line);
ctxt->name = g_strdup (ctxt->line);
break;
} else
return FALSE;
......@@ -272,7 +235,7 @@ mps_add_row (MpsInputContext *ctxt, MpsRowType type, gchar *txt)
if (len == 0)
return FALSE;
row->name = strcpy (g_malloc (len + 1), txt);
row->name = g_strdup (txt);
row->type = type;
row->index = ctxt->n_rows;
ctxt->n_rows += 1;
......
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