Commit 4ad8a5b7 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

fix leaks.

2001-10-25  Jody Goldberg <jgoldberg@home.com>

	* src/number-match.c (compute_value) : fix leaks.

	* src/sheet-autofill.c (autofill_cell) : fix leak.

	* gnumeric.xsd : add the scaling information.

	* src/xml-io.c (xml_write_print_info) : why weren't we saving scaling
	  info ?
	(xml_read_print_info) : or reading back.
parent 6e54f904
2001-10-25 Jody Goldberg <jgoldberg@home.com>
* src/number-match.c (compute_value) : fix leaks.
* src/sheet-autofill.c (autofill_cell) : fix leak.
* gnumeric.xsd : add the scaling information.
* src/xml-io.c (xml_write_print_info) : why weren't we saving scaling
info ?
(xml_read_print_info) : or reading back.
2001-10-25 Jody Goldberg <jgoldberg@home.com>
* src/ranges.c (global_range_list_parse) : put things in the right
......
2001-10-25 Jody Goldberg <jgoldberg@home.com>
* src/number-match.c (compute_value) : fix leaks.
* src/sheet-autofill.c (autofill_cell) : fix leak.
* gnumeric.xsd : add the scaling information.
* src/xml-io.c (xml_write_print_info) : why weren't we saving scaling
info ?
(xml_read_print_info) : or reading back.
2001-10-25 Jody Goldberg <jgoldberg@home.com>
* src/ranges.c (global_range_list_parse) : put things in the right
......
2001-10-25 Jody Goldberg <jgoldberg@home.com>
* src/number-match.c (compute_value) : fix leaks.
* src/sheet-autofill.c (autofill_cell) : fix leak.
* gnumeric.xsd : add the scaling information.
* src/xml-io.c (xml_write_print_info) : why weren't we saving scaling
info ?
(xml_read_print_info) : or reading back.
2001-10-25 Jody Goldberg <jgoldberg@home.com>
* src/ranges.c (global_range_list_parse) : put things in the right
......
2001-10-25 Jody Goldberg <jgoldberg@home.com>
* src/number-match.c (compute_value) : fix leaks.
* src/sheet-autofill.c (autofill_cell) : fix leak.
* gnumeric.xsd : add the scaling information.
* src/xml-io.c (xml_write_print_info) : why weren't we saving scaling
info ?
(xml_read_print_info) : or reading back.
2001-10-25 Jody Goldberg <jgoldberg@home.com>
* src/ranges.c (global_range_list_parse) : put things in the right
......
2001-10-25 Jody Goldberg <jgoldberg@home.com>
* xml-sax-read.c (xml_sax_print_scale) : new function.
2001-10-23 Jody Goldberg <jgoldberg@home.com>
* xml-sax-read.c (xml_sax_finish_parse_wb_names_name) : support
......
......@@ -21,8 +21,8 @@
* USA
*/
#include "config.h"
#include <gnome.h>
#include <config.h>
#include "xml-io-version.h"
#include "gnumeric.h"
#include "io-context.h"
#include "plugin.h"
......@@ -50,6 +50,7 @@
#include <stdlib.h>
#include <string.h>
#include <gnome.h>
#include <gnome-xml/tree.h>
#include <gnome-xml/parser.h>
#include <gnome-xml/parserInternals.h>
......@@ -259,6 +260,7 @@ STATE_WB,
STATE_PRINT_MARGIN_RIGHT,
STATE_PRINT_MARGIN_HEADER,
STATE_PRINT_MARGIN_FOOTER,
STATE_PRINT_SCALE,
STATE_PRINT_VCENTER,
STATE_PRINT_HCENTER,
STATE_PRINT_GRID,
......@@ -356,6 +358,7 @@ static char const * const xmlSax_state_names[] =
"gmr:right",
"gmr:header",
"gmr:footer",
"gmr:Scale",
"gmr:vcenter",
"gmr:hcenter",
"gmr:grid",
......@@ -408,21 +411,6 @@ static char const * const xmlSax_state_names[] =
NULL
};
typedef enum
{
GNUM_XML_UNKNOWN = 0,
GNUM_XML_V1,
GNUM_XML_V2,
GNUM_XML_V3, /* >= 0.52 */
GNUM_XML_V4, /* >= 0.57 */
GNUM_XML_V5, /* >= 0.58 */
GNUM_XML_V6, /* >= 0.62 */
GNUM_XML_V7, /* >= 0.66 */
GNUM_XML_V8, /* >= 0.68 */
/* NOTE : Keep this up to date */
GNUM_XML_LATEST = GNUM_XML_V8
} GnumericXMLVersion;
typedef struct _XMLSaxParseState
{
xmlSaxState state;
......@@ -831,6 +819,30 @@ xml_sax_print_margins (XMLSaxParseState *state, CHAR const **attrs)
}
}
static void
xml_sax_print_scale (XMLSaxParseState *state, CHAR const **attrs)
{
PrintInformation *pi;
double percentage;
int cols, rows;
g_return_if_fail (state->sheet != NULL);
g_return_if_fail (state->sheet->print_info != NULL);
pi = state->sheet->print_info;
for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) {
if (!strcmp (attrs[0], "type"))
pi->scaling.type = strcmp (attrs[1], "percentage")
? SIZE_FIT : PERCENTAGE;
else if (xml_sax_attr_double (attrs, "percentage", &percentage))
pi->scaling.percentage = percentage;
else if (xml_sax_attr_int (attrs, "cols", &cols))
pi->scaling.dim.cols = cols;
else if (xml_sax_attr_int (attrs, "rows", &rows))
pi->scaling.dim.rows = rows;
}
}
static void
xml_sax_selection_range (XMLSaxParseState *state, CHAR const **attrs)
{
......@@ -1635,6 +1647,8 @@ xml_sax_start_element (XMLSaxParseState *state, CHAR const *name, CHAR const **a
case STATE_SHEET_PRINTINFO :
if (xml_sax_switch_state (state, name, STATE_PRINT_MARGINS)) {
} else if (xml_sax_switch_state (state, name, STATE_PRINT_SCALE)) {
xml_sax_print_scale (state, attrs);
} else if (xml_sax_switch_state (state, name, STATE_PRINT_VCENTER)) {
} else if (xml_sax_switch_state (state, name, STATE_PRINT_HCENTER)) {
} else if (xml_sax_switch_state (state, name, STATE_PRINT_GRID)) {
......@@ -1658,8 +1672,7 @@ xml_sax_start_element (XMLSaxParseState *state, CHAR const *name, CHAR const **a
xml_sax_switch_state (state, name, STATE_PRINT_MARGIN_BOTTOM) ||
xml_sax_switch_state (state, name, STATE_PRINT_MARGIN_LEFT) ||
xml_sax_switch_state (state, name, STATE_PRINT_MARGIN_RIGHT) ||
xml_sax_switch_state (state, name,
STATE_PRINT_MARGIN_HEADER) ||
xml_sax_switch_state (state, name, STATE_PRINT_MARGIN_HEADER) ||
xml_sax_switch_state (state, name, STATE_PRINT_MARGIN_FOOTER)) {
xml_sax_print_margins (state, attrs);
} else
......
......@@ -237,6 +237,7 @@ GNUMERIC_BASE = \
workbook-control-gui-priv.h \
xml-io.c \
xml-io.h \
xml-io-version.h \
xml-io-autoft.c \
xml-io-autoft.h
......
......@@ -757,8 +757,10 @@ compute_value (char const *s, const regmatch_t *mp,
switch (type) {
case MATCH_MONTH_FULL:
month = table_lookup (str, month_long);
if (month == -1)
if (month == -1) {
g_free (str);
return NULL;
}
month++;
break;
......@@ -768,8 +770,10 @@ compute_value (char const *s, const regmatch_t *mp,
case MATCH_MONTH_SHORT:
month = table_lookup (str, month_short);
if (month == -1)
if (month == -1) {
g_free (str);
return NULL;
}
month++;
break;
......@@ -789,15 +793,19 @@ compute_value (char const *s, const regmatch_t *mp,
/* FIXME: this loop is bogus. */
do {
int thisnumber;
if (fabs (number) > DBL_MAX/1000.)
if (fabs (number) > DBL_MAX/1000.) {
g_free (str);
return NULL;
}
number *= 1000.;
errno = 0; /* strtol sets errno, but does not clear it. */
thisnumber = strtol (ptr, &ptr, 10);
if (errno == ERANGE)
if (errno == ERANGE) {
g_free (str);
return NULL;
}
if (number >= 0)
number += thisnumber;
else
......@@ -878,7 +886,7 @@ compute_value (char const *s, const regmatch_t *mp,
break;
case MATCH_STRING_CONSTANT:
return value_new_string (str);
return value_new_string_str (string_get_nocopy (str));
default :
g_warning ("compute_value: This should not happen\n");
......
......@@ -418,6 +418,7 @@ autofill_compute_delta (GList *list_last, GList *fill_item_list)
else if (fi->type != FILL_NUMBER)
return;
}
/* fall through */
case FILL_NUMBER: {
double a, b;
......@@ -564,12 +565,6 @@ autofill_destroy_fill_items (GList *all_items)
static void
autofill_cell (Cell *cell, int idx, FillItem *fi)
{
if (fi->type == FILL_DAYS) {
FillItem *last = fi->group_last;
g_return_if_fail (last != NULL);
fi->type = FILL_MONTHS;
}
switch (fi->type) {
case FILL_EMPTY:
case FILL_INVALID:
......@@ -616,9 +611,10 @@ autofill_cell (Cell *cell, int idx, FillItem *fi)
if (last->delta_is_float) {
double const d = value_get_as_float (last->v.value);
v = value_new_float (d + idx * last->delta.d_float);
} else
v = value_new_int (last->v.value->v_int.val +
idx * last->delta.d_int);
} else {
int const i = value_get_as_int (last->v.value);
v = value_new_int (i + idx * last->delta.d_int);
}
cell_set_value (cell, v, fi->fmt);
return;
}
......@@ -643,6 +639,7 @@ autofill_cell (Cell *cell, int idx, FillItem *fi)
g_date_subtract_years (date, -d);
}
d = datetime_g_to_serial (date);
g_date_free (date);
res -= floor (res);
v = (res < 1e-6) ? value_new_int (d)
......
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef GNUMERIC_XML_IO_VERSION_H
#define GNUMERIC_XML_IO_VERSION_H
typedef enum
{
GNUM_XML_UNKNOWN = -1,
GNUM_XML_V1,
GNUM_XML_V2,
GNUM_XML_V3, /* >= 0.52 */
GNUM_XML_V4, /* >= 0.57 */
GNUM_XML_V5, /* >= 0.58 */
GNUM_XML_V6, /* >= 0.62 */
GNUM_XML_V7, /* >= 0.66 */
GNUM_XML_V8, /* >= 0.71 */
GNUM_XML_V9, /* >= 0.73 add print scaling */
/* NOTE : Keep this up to date (and in sync with the schema) */
GNUM_XML_LATEST = GNUM_XML_V9
} GnumericXMLVersion;
#endif /* GNUMERIC_XML_IO_VERSION_H */
......@@ -1033,6 +1033,16 @@ xml_write_print_info (XmlParseContext *ctxt, PrintInformation *pi)
xml_node_set_print_unit (child, "header", &pi->margins.header);
xml_node_set_print_unit (child, "footer", &pi->margins.footer);
child = xmlNewChild (cur, ctxt->ns, "Scale", NULL);
if (pi->scaling.type == PERCENTAGE) {
xml_node_set_cstr (child, "type", "percentage");
xml_node_set_double (child, "percentage", pi->scaling.percentage, -1);
} else {
xml_node_set_cstr (child, "type", "size_fit");
xml_node_set_double (child, "cols", pi->scaling.dim.cols, -1);
xml_node_set_double (child, "rows", pi->scaling.dim.rows, -1);
}
child = xmlNewChild (cur, ctxt->ns, "vcenter", NULL);
xml_node_set_int (child, "value", pi->center_vertically);
child = xmlNewChild (cur, ctxt->ns, "hcenter", NULL);
......@@ -1165,6 +1175,27 @@ xml_read_print_info (XmlParseContext *ctxt, xmlNodePtr tree)
if ((child = e_xml_get_child_by_name (tree, "Margins"))) {
xml_read_print_margins (ctxt, child);
}
if ((child = e_xml_get_child_by_name (tree, "Scale"))) {
xmlChar *type = xml_node_get_cstr (child, "type");
if (type != NULL) {
if (!strcmp (type, "percentage")) {
double tmp;
pi->scaling.type = PERCENTAGE;
if (xml_node_get_double (child, "percentage", &tmp))
pi->scaling.percentage = tmp;
} else {
int cols, rows;
pi->scaling.type = SIZE_FIT;
if (xml_node_get_int (child, "cols", &cols) &&
xml_node_get_int (child, "rows", &rows)) {
pi->scaling.dim.cols = cols;
pi->scaling.dim.rows = rows;
}
}
xmlFree (type);
}
}
if ((child = e_xml_get_child_by_name (tree, "vcenter"))) {
xml_node_get_int (child, "value", &b);
pi->center_vertically = (b == 1);
......
/*
* xml-io.h: interfaces to save/read gnumeric Sheets using an XML encoding.
*
* Daniel Veillard <Daniel.Veillard@w3.org>
*
* $Id$
*/
#ifndef GNUMERIC_XML_IO_H
#define GNUMERIC_XML_IO_H
......@@ -14,25 +6,11 @@
#include <bonobo/bonobo-stream.h>
#endif
#include "gnumeric.h"
#include "xml-io-version.h"
#include "file.h"
#include <gnome-xml/tree.h>
#include <gnome-xml/xmlmemory.h>
typedef enum
{
GNUM_XML_V1,
GNUM_XML_V2,
GNUM_XML_V3, /* >= 0.52 */
GNUM_XML_V4, /* >= 0.57 */
GNUM_XML_V5, /* >= 0.58 */
GNUM_XML_V6, /* >= 0.62 */
GNUM_XML_V7, /* >= 0.66 */
GNUM_XML_V8, /* >= 0.71 */
/* NOTE : Keep this up to date (and in sync with the schema) */
GNUM_XML_LATEST = GNUM_XML_V8
} GnumericXMLVersion;
typedef struct _XmlParseContext XmlParseContext;
typedef gboolean (*XmlSheetObjectWriteFn) (xmlNodePtr cur,
......
......@@ -21,8 +21,8 @@
* USA
*/
#include "config.h"
#include <gnome.h>
#include <config.h>
#include "xml-io-version.h"
#include "gnumeric.h"
#include "io-context.h"
#include "plugin.h"
......@@ -50,6 +50,7 @@
#include <stdlib.h>
#include <string.h>
#include <gnome.h>
#include <gnome-xml/tree.h>
#include <gnome-xml/parser.h>
#include <gnome-xml/parserInternals.h>
......@@ -259,6 +260,7 @@ STATE_WB,
STATE_PRINT_MARGIN_RIGHT,
STATE_PRINT_MARGIN_HEADER,
STATE_PRINT_MARGIN_FOOTER,
STATE_PRINT_SCALE,
STATE_PRINT_VCENTER,
STATE_PRINT_HCENTER,
STATE_PRINT_GRID,
......@@ -356,6 +358,7 @@ static char const * const xmlSax_state_names[] =
"gmr:right",
"gmr:header",
"gmr:footer",
"gmr:Scale",
"gmr:vcenter",
"gmr:hcenter",
"gmr:grid",
......@@ -408,21 +411,6 @@ static char const * const xmlSax_state_names[] =
NULL
};
typedef enum
{
GNUM_XML_UNKNOWN = 0,
GNUM_XML_V1,
GNUM_XML_V2,
GNUM_XML_V3, /* >= 0.52 */
GNUM_XML_V4, /* >= 0.57 */
GNUM_XML_V5, /* >= 0.58 */
GNUM_XML_V6, /* >= 0.62 */
GNUM_XML_V7, /* >= 0.66 */
GNUM_XML_V8, /* >= 0.68 */
/* NOTE : Keep this up to date */
GNUM_XML_LATEST = GNUM_XML_V8
} GnumericXMLVersion;
typedef struct _XMLSaxParseState
{
xmlSaxState state;
......@@ -831,6 +819,30 @@ xml_sax_print_margins (XMLSaxParseState *state, CHAR const **attrs)
}
}
static void
xml_sax_print_scale (XMLSaxParseState *state, CHAR const **attrs)
{
PrintInformation *pi;
double percentage;
int cols, rows;
g_return_if_fail (state->sheet != NULL);
g_return_if_fail (state->sheet->print_info != NULL);
pi = state->sheet->print_info;
for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) {
if (!strcmp (attrs[0], "type"))
pi->scaling.type = strcmp (attrs[1], "percentage")
? SIZE_FIT : PERCENTAGE;
else if (xml_sax_attr_double (attrs, "percentage", &percentage))
pi->scaling.percentage = percentage;
else if (xml_sax_attr_int (attrs, "cols", &cols))
pi->scaling.dim.cols = cols;
else if (xml_sax_attr_int (attrs, "rows", &rows))
pi->scaling.dim.rows = rows;
}
}
static void
xml_sax_selection_range (XMLSaxParseState *state, CHAR const **attrs)
{
......@@ -1635,6 +1647,8 @@ xml_sax_start_element (XMLSaxParseState *state, CHAR const *name, CHAR const **a
case STATE_SHEET_PRINTINFO :
if (xml_sax_switch_state (state, name, STATE_PRINT_MARGINS)) {
} else if (xml_sax_switch_state (state, name, STATE_PRINT_SCALE)) {
xml_sax_print_scale (state, attrs);
} else if (xml_sax_switch_state (state, name, STATE_PRINT_VCENTER)) {
} else if (xml_sax_switch_state (state, name, STATE_PRINT_HCENTER)) {
} else if (xml_sax_switch_state (state, name, STATE_PRINT_GRID)) {
......@@ -1658,8 +1672,7 @@ xml_sax_start_element (XMLSaxParseState *state, CHAR const *name, CHAR const **a
xml_sax_switch_state (state, name, STATE_PRINT_MARGIN_BOTTOM) ||
xml_sax_switch_state (state, name, STATE_PRINT_MARGIN_LEFT) ||
xml_sax_switch_state (state, name, STATE_PRINT_MARGIN_RIGHT) ||
xml_sax_switch_state (state, name,
STATE_PRINT_MARGIN_HEADER) ||
xml_sax_switch_state (state, name, STATE_PRINT_MARGIN_HEADER) ||
xml_sax_switch_state (state, name, STATE_PRINT_MARGIN_FOOTER)) {
xml_sax_print_margins (state, attrs);
} else
......
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