~ubuntu-branches/ubuntu/feisty/gnumeric/feisty-updates

« back to all changes in this revision

Viewing changes to src/xml-io.c

  • Committer: Bazaar Package Importer
  • Author(s): Gauvain Pocentek
  • Date: 2006-11-14 14:02:03 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061114140203-iv3j2aii3vch6isl
Tags: 1.7.2-1ubuntu1
* Merge with debian experimental:
  - debian/control, debian/*-gtk-*, debian/rules,
    debian/shlibs.local: Xubuntu changes for
    gtk/gnome multibuild.
  - run intltool-update in po*
  - Build Depend on intltool

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 *   Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
10
10
 */
11
11
#include <gnumeric-config.h>
12
 
#include <glib/gi18n.h>
 
12
#include <glib/gi18n-lib.h>
13
13
#include "gnumeric.h"
14
14
#include "xml-io.h"
15
15
#include "xml-sax.h"
81
81
#define XML_INPUT_BUFFER_SIZE      4096
82
82
#define N_ELEMENTS_BETWEEN_UPDATES 20
83
83
 
84
 
#define CC2XML(s) ((const xmlChar *)(s))
 
84
#define CC2XML(s) ((xmlChar const *)(s))
85
85
#define C2XML(s) ((xmlChar *)(s))
86
 
#define CXML2C(s) ((const char *)(s))
 
86
#define CXML2C(s) ((char const *)(s))
87
87
#define XML2C(s) ((char *)(s))
88
88
 
89
89
/* ------------------------------------------------------------------------- */
577
577
 
578
578
                if (s) {
579
579
                        GnmRange r;
580
 
                        if (parse_range (CXML2C (s), &r)) {
 
580
                        if (range_parse (&r, CXML2C (s))) {
581
581
                                range->range = r;
582
582
                                range->use   = TRUE;
583
583
                        }
1135
1135
 
1136
1136
        cell = sheet_cell_get (ctxt->sheet, col, row);
1137
1137
        if ((is_new_cell = (cell == NULL)))
1138
 
                cell = sheet_cell_new (ctxt->sheet, col, row);
 
1138
                cell = sheet_cell_create (ctxt->sheet, col, row);
1139
1139
        if (cell == NULL)
1140
1140
                return NULL;
1141
1141
 
1450
1450
                area = xml_node_get_cstr (filter_node, "Area");
1451
1451
                if (area == NULL)
1452
1452
                        continue;
1453
 
                if (parse_range (CXML2C (area), &r)) {
 
1453
                if (range_parse (&r, CXML2C (area))) {
1454
1454
                        filter = gnm_filter_new (ctxt->sheet, &r);
1455
1455
                        for (field = filter_node->xmlChildrenNode; field != NULL; field = field->next)
1456
1456
                                if (!xmlIsBlankNode (field))
1681
1681
        tmp = (char *) xmlGetProp (tree, (xmlChar *)"ObjectBound");
1682
1682
        if (tmp != NULL) {
1683
1683
                GnmRange r;
1684
 
                if (parse_range (tmp, &r))
 
1684
                if (range_parse (&r, tmp))
1685
1685
                        so->anchor.cell_bound = r;
1686
1686
                xmlFree (tmp);
1687
1687
        }
1705
1705
        }
1706
1706
 
1707
1707
        if (xml_node_get_int (tree, "Direction", &tmp_int))
1708
 
                so->anchor.direction = tmp_int;
 
1708
                so->anchor.base.direction = tmp_int;
1709
1709
        else
1710
 
                so->anchor.direction = SO_DIR_UNKNOWN;
 
1710
                so->anchor.base.direction = GOD_ANCHOR_DIR_UNKNOWN;
1711
1711
 
1712
1712
        /* Do not assign to a sheet when extracting a cell region */
1713
1713
        if (NULL != ctxt->sheet) {
1731
1731
                        xmlChar *content = xml_node_get_cstr (region, NULL);
1732
1732
                        GnmRange r;
1733
1733
                        if (content != NULL) {
1734
 
                                if (parse_range (CXML2C (content), &r))
 
1734
                                if (range_parse (&r, CXML2C (content)))
1735
1735
                                        sheet_merge_add (ctxt->sheet, &r, FALSE, NULL);
1736
1736
                                xmlFree (content);
1737
1737
                        }
1755
1755
        }
1756
1756
}
1757
1757
 
1758
 
/*
1759
 
 * Create a ColRowInfo equivalent to the XML subtree of doc.
1760
 
 */
1761
 
static int
 
1758
static void
1762
1759
xml_read_colrow_info (XmlParseContext *ctxt, xmlNodePtr tree,
1763
 
                      ColRowInfo *info, double *size_pts)
 
1760
                      gboolean is_cols)
1764
1761
{
1765
 
        int val, count;
1766
 
 
1767
 
        info->size_pts = -1;
1768
 
        xml_node_get_int (tree, "No", &info->pos);
1769
 
        xml_node_get_double (tree, "Unit", size_pts);
1770
 
        if (xml_node_get_int (tree, "MarginA", &val))
1771
 
                info->margin_a = val;
1772
 
        if (xml_node_get_int (tree, "MarginB", &val))
1773
 
                info->margin_b = val;
 
1762
        ColRowInfo *cri;
 
1763
        double size_pts;
 
1764
        int pos, val;
 
1765
 
 
1766
        if (!xml_node_get_int (tree, "No", &pos) ||
 
1767
            NULL == (cri = sheet_colrow_fetch (ctxt->sheet, pos, is_cols)))
 
1768
                return;
 
1769
 
1774
1770
        if (xml_node_get_int (tree, "HardSize", &val))
1775
 
                info->hard_size = val;
 
1771
                cri->hard_size = val;
 
1772
        if (xml_node_get_double (tree, "Unit", &size_pts)) {
 
1773
                if (is_cols)
 
1774
                        sheet_col_set_size_pts (ctxt->sheet,
 
1775
                                pos, size_pts, cri->hard_size);
 
1776
                else
 
1777
                        sheet_row_set_size_pts (ctxt->sheet,
 
1778
                                pos, size_pts, cri->hard_size);
 
1779
        }
 
1780
 
1776
1781
        if (xml_node_get_int (tree, "Hidden", &val) && val)
1777
 
                info->visible = FALSE;
 
1782
                cri->visible = FALSE;
1778
1783
        if (xml_node_get_int (tree, "Collapsed", &val) && val)
1779
 
                info->is_collapsed = TRUE;
 
1784
                cri->is_collapsed = TRUE;
1780
1785
        if (xml_node_get_int (tree, "OutlineLevel", &val) && val > 0)
1781
 
                info->outline_level = val;
1782
 
        if (xml_node_get_int (tree, "Count", &count))
1783
 
                return count;
1784
 
        return 1;
 
1786
                cri->outline_level = val;
 
1787
 
 
1788
        if (xml_node_get_int (tree, "Count", &val)) {
 
1789
                /* resize flags are already set only need to copy the sizes */
 
1790
                for ( ; --val > 0 ; )
 
1791
                        colrow_copy (sheet_colrow_fetch (ctxt->sheet, ++pos, is_cols), cri);
 
1792
        }
1785
1793
}
1786
1794
 
1787
1795
static void
1788
1796
xml_read_cols_info (XmlParseContext *ctxt, xmlNodePtr tree)
1789
1797
{
1790
1798
        xmlNodePtr cols, col;
1791
 
        double size_pts, tmp;
1792
 
        ColRowInfo *info;
1793
 
        int count, pos;
1794
 
        Sheet *sheet = ctxt->sheet;
 
1799
        double tmp;
1795
1800
 
1796
1801
        cols = e_xml_get_child_by_name (tree, CC2XML ("Cols"));
1797
1802
        if (cols == NULL)
1798
1803
                return;
1799
1804
 
1800
1805
        if (xml_node_get_double (cols, "DefaultSizePts", &tmp))
1801
 
                sheet_col_set_default_size_pts (sheet, tmp);
 
1806
                sheet_col_set_default_size_pts (ctxt->sheet, tmp);
1802
1807
 
1803
1808
        for (col = cols->xmlChildrenNode; col; col = col->next)
1804
 
                if (!xmlIsBlankNode (col)) {
1805
 
                        info = sheet_col_new (sheet);
1806
 
                        count = xml_read_colrow_info (ctxt, col, info, &size_pts);
1807
 
                        sheet_col_add (sheet, info);
1808
 
                        sheet_col_set_size_pts (ctxt->sheet, info->pos, size_pts, info->hard_size);
1809
 
 
1810
 
                        /* resize flags are already set only need to copy the sizes */
1811
 
                        for (pos = info->pos ; --count > 0 ; )
1812
 
                                colrow_copy (sheet_col_fetch (ctxt->sheet, ++pos), info);
1813
 
                }
 
1809
                if (!xmlIsBlankNode (col))
 
1810
                        xml_read_colrow_info (ctxt, col, TRUE);
1814
1811
}
1815
1812
 
1816
1813
static void
1817
1814
xml_read_rows_info (XmlParseContext *ctxt, xmlNodePtr tree)
1818
1815
{
1819
1816
        xmlNodePtr rows, row;
1820
 
        double size_pts, tmp;
1821
 
        ColRowInfo *info;
1822
 
        int count, pos;
1823
 
        Sheet *sheet = ctxt->sheet;
 
1817
        double tmp;
1824
1818
 
1825
1819
        rows = e_xml_get_child_by_name (tree, CC2XML ("Rows"));
1826
1820
        if (rows == NULL)
1827
1821
                return;
1828
1822
 
1829
1823
        if (xml_node_get_double (rows, "DefaultSizePts", &tmp))
1830
 
                sheet_row_set_default_size_pts (sheet, tmp);
 
1824
                sheet_row_set_default_size_pts (ctxt->sheet, tmp);
1831
1825
 
1832
1826
        for (row = rows->xmlChildrenNode; row; row = row->next)
1833
 
                if (!xmlIsBlankNode (row)) {
1834
 
                        info = sheet_row_new (sheet);
1835
 
                        count = xml_read_colrow_info (ctxt, row, info, &size_pts);
1836
 
                        sheet_row_add (sheet, info);
1837
 
                        sheet_row_set_size_pts (ctxt->sheet, info->pos, size_pts, info->hard_size);
1838
 
 
1839
 
                        /* resize flags are already set only need to copy the sizes */
1840
 
                        for (pos = info->pos ; --count > 0 ; )
1841
 
                                colrow_copy (sheet_row_fetch (ctxt->sheet, ++pos), info);
1842
 
                }
 
1827
                if (!xmlIsBlankNode (row))
 
1828
                        xml_read_colrow_info (ctxt, row, FALSE);
1843
1829
}
1844
1830
 
1845
1831
static void
2058
2044
                                                (value_new_string
2059
2045
                                                 (gnm_expr_char_start_p
2060
2046
                                                  (CXML2C (content))));
2061
 
                                        value_release (cc->val);
2062
 
                                        cc->val = value_new_empty ();
 
2047
                                        if (cc->val) {
 
2048
                                                value_release (cc->val);
 
2049
                                                cc->val = NULL;
 
2050
                                        }
2063
2051
                                }
2064
2052
                                g_ptr_array_add (ctxt->shared_exprs,
2065
2053
                                                 (gpointer)cc->texpr);
2077
2065
                } else {
2078
2066
                        g_warning ("XML-IO: Missing shared expression");
2079
2067
                }
 
2068
        }
 
2069
        go_format_unref (value_fmt);
 
2070
 
 
2071
        if (!cc->val)
2080
2072
                cc->val = value_new_empty ();
2081
 
        }
2082
 
        go_format_unref (value_fmt);
2083
2073
 
2084
2074
        cr->contents = g_slist_prepend (cr->contents, cc);
2085
2075
}
2154
2144
                        if (!xmlIsBlankNode (l)) {
2155
2145
                                GnmRange r;
2156
2146
                                xmlChar *content = (char *)xmlNodeGetContent (l);
2157
 
                                if (parse_range (CXML2C (content), &r))
 
2147
                                if (range_parse (&r, CXML2C (content)))
2158
2148
                                        cr->merged = g_slist_prepend (cr->merged,
2159
2149
                                                                      range_dup (&r));
2160
2150
                                xmlFree (content);
2444
2434
        GString *buffer;
2445
2435
        guint ui;
2446
2436
        char *converted;
2447
 
        const char *encoding;
 
2437
        char const *encoding;
2448
2438
        gboolean ok;
2449
2439
 
2450
2440
        buf = gsf_input_read (input, strlen (noencheader), NULL);
2715
2705
        xml_sax_prober.error      = (errorSAXFunc) xml_probe_problem;
2716
2706
        xml_sax_prober.fatalError = (fatalErrorSAXFunc) xml_probe_problem;
2717
2707
        xml_sax_prober.startElement = (startElementSAXFunc) xml_probe_start_element;
 
2708
#warning REMOVE for 2.0
2718
2709
        go_file_opener_register (go_file_opener_new (
2719
2710
                "Gnumeric_XmlIO:gnum_xml",
2720
 
                _("Gnumeric XML (*.gnumeric)"),
 
2711
                _("Gnumeric XML (*.gnumeric) Old slow importer"),
2721
2712
                suffixes, mimes,
2722
 
                xml_probe, gnumeric_xml_read_workbook), 50);
 
2713
                xml_probe, gnumeric_xml_read_workbook), 40);
2723
2714
 
2724
2715
        go_file_opener_register (go_file_opener_new (
2725
2716
                "Gnumeric_XmlIO:xml_sax",