~ubuntu-branches/ubuntu/feisty/gnumeric/feisty-security

« back to all changes in this revision

Viewing changes to plugins/openoffice/openoffice-read.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:
3
3
/*
4
4
 * openoffice-read.c : import open/star calc files
5
5
 *
6
 
 * Copyright (C) 2002-2005 Jody Goldberg (jody@gnome.org)
 
6
 * Copyright (C) 2002-2006 Jody Goldberg (jody@gnome.org)
7
7
 * Copyright (C) 2006 Luciano Miguel Wolf (luciano.wolf@indt.org.br)
8
8
 *
9
9
 * This program is free software; you can redistribute it and/or
54
54
#include <gsf/gsf-opendoc-utils.h>
55
55
#include <gsf/gsf-doc-meta-data.h>
56
56
#include <gsf/gsf-output-stdio.h>
57
 
#include <glib/gi18n.h>
 
57
#include <glib/gi18n-lib.h>
58
58
 
59
59
#include <string.h>
60
60
#include <locale.h>
568
568
oo_cellref_parse (GnmCellRef *ref, char const *start, GnmParsePos const *pp)
569
569
{
570
570
        char const *tmp1, *tmp2, *ptr = start;
571
 
        /* sheet name cannot contain '.' a '\'' or a '\"' */
 
571
 
572
572
        if (*ptr != '.') {
573
 
                char *name;
574
 
                int offset = 0;
575
 
 
576
 
                if (*ptr == '$') /* ignore abs vs rel sheet name */
577
 
                        ptr++;
578
 
                tmp1 = strchr (ptr, '.');
579
 
                if (tmp1 == NULL)
580
 
                        return start;
581
 
                if ((*ptr == '\'' || *ptr == '\"') && *ptr == tmp1[-1]) {
582
 
                        ptr++;
583
 
                        tmp1--;
584
 
                        offset = 1;
 
573
                char *name, *accum;
 
574
 
 
575
                /* ignore abs vs rel for sheets */
 
576
                if (*ptr == '$')
 
577
                        ptr++;
 
578
 
 
579
                /* From the spec :
 
580
                 *      SheetName   ::= [^\. ']+ | "'" ([^'] | "''")+ "'" */
 
581
                if ('\'' == *ptr) {
 
582
                        tmp1 = ++ptr;
 
583
two_quotes :
 
584
                        /* missing close paren */
 
585
                        if (NULL == (tmp1 = strchr (tmp1, '\'')))
 
586
                                return start;
 
587
 
 
588
                        /* two in a row is the escape for a single */
 
589
                        if (tmp1[1] == '\'') {
 
590
                                tmp1 += 2;
 
591
                                goto two_quotes;
 
592
                        }
 
593
 
 
594
                        /* If a name is quoted the entire named must be quoted */
 
595
                        if (tmp1[1] != '.')
 
596
                                return start;
 
597
 
 
598
                        accum = name = g_alloca (tmp1-ptr+1);
 
599
                        while (ptr != tmp1)
 
600
                                if ('\'' == (*accum++ = *ptr++))
 
601
                                        ptr++;
 
602
                        *accum = '\0';
 
603
                        ptr += 2;
 
604
                } else {
 
605
                        if (NULL == (tmp1 = strchr (ptr, '.')))
 
606
                                return start;
 
607
                        name = g_alloca (tmp1-ptr+1);
 
608
                        strncpy (name, ptr, tmp1-ptr);
 
609
                        name[tmp1-ptr] = '\0';
 
610
                        ptr = tmp1 + 1;
585
611
                }
586
612
 
587
 
                name = g_alloca (tmp1-ptr+1);
588
 
                strncpy (name, ptr, tmp1-ptr);
589
 
                name[tmp1-ptr] = 0;
590
 
                ptr = tmp1 + 1 + offset;
591
 
 
592
613
                /* OpenCalc does not pre-declare its sheets, but it does have a
593
614
                 * nice unambiguous format.  So if we find a name that has not
594
 
                 * been added yet add it.  Reorder below.
595
 
                 */
 
615
                 * been added yet add it.  Reorder below. */
596
616
                ref->sheet = workbook_sheet_by_name (pp->wb, name);
597
617
                if (ref->sheet == NULL) {
598
618
                        ref->sheet = sheet_new (pp->wb, name);
658
678
        gboolean         bool_val;
659
679
        gnm_float        float_val = 0;
660
680
        int array_cols = -1, array_rows = -1;
661
 
        int merge_cols = -1, merge_rows = -1;
 
681
        int merge_cols = 1, merge_rows = 1;
662
682
        GnmStyle *style = NULL;
663
683
        char const *expr_string;
664
684
        GnmRange tmp;
730
750
                                                val = value_new_int (d_serial);
731
751
                                }
732
752
                        }
733
 
                } else if (gsf_xml_in_namecmp (xin, attrs[0], OO_NS_TABLE, "time-value")) {
 
753
                } else if (gsf_xml_in_namecmp (xin, attrs[0],
 
754
                                               (state->ver == OOO_VER_OPENDOC) ? OO_NS_OFFICE : OO_NS_TABLE,
 
755
                                               "time-value")) {
734
756
                        unsigned h, m, s;
735
 
                        if (3 == sscanf (attrs[1], "PT%uH%uM%uS", &h, &m, &s))
736
 
                                val = value_new_float (h + ((double)m / 60.) + ((double)s / 3600.));
 
757
                        if (3 == sscanf (attrs[1], "PT%uH%uM%uS", &h, &m, &s)) {
 
758
                                unsigned secs = h * 3600 + m * 60 + s;
 
759
                                val = value_new_float (secs / (gnm_float)86400);
 
760
                        }
737
761
                } else if (gsf_xml_in_namecmp (xin, attrs[0], OO_NS_TABLE, "string-value"))
738
762
                        val = value_new_string (attrs[1]);
739
763
                else if (oo_attr_float (xin, attrs,
756
780
        if (style != NULL) {
757
781
                gnm_style_ref (style);
758
782
                if (state->col_inc > 1 || state->row_inc > 1) {
759
 
                        range_init (&tmp,
760
 
                                state->pos.eval.col, state->pos.eval.row,
761
 
                                state->pos.eval.col + state->col_inc - 1,
762
 
                                state->pos.eval.row + state->row_inc - 1);
 
783
                        range_init_cellpos_size (&tmp, &state->pos.eval,
 
784
                                state->col_inc, state->row_inc);
763
785
                        sheet_style_set_range (state->pos.sheet, &tmp, style);
764
 
                } else if (merge_cols > 0 || merge_rows > 0) {
765
 
                        GnmRange tmp;
766
 
                        range_init (&tmp,
767
 
                                state->pos.eval.col, state->pos.eval.row,
768
 
                                state->pos.eval.col + merge_cols - 1,
769
 
                                state->pos.eval.row + merge_rows - 1);
 
786
                } else if (merge_cols > 1 || merge_rows > 1) {
 
787
                        range_init_cellpos_size (&tmp, &state->pos.eval,
 
788
                                merge_cols, merge_rows);
770
789
                        sheet_style_set_range (state->pos.sheet, &tmp, style);
771
790
                } else
772
791
                        sheet_style_set_pos (state->pos.sheet,
779
798
                        state->pos.eval.col, state->pos.eval.row);
780
799
 
781
800
                if (array_cols > 0 || array_rows > 0) {
782
 
                        if (array_cols < 0) {
 
801
                        if (array_cols <= 0) {
783
802
                                array_cols = 1;
784
803
                                oo_warning (xin, _("Invalid array expression does not specify number of columns."));
785
 
                        } else if (array_rows < 0) {
 
804
                        } else if (array_rows <= 0) {
786
805
                                array_rows = 1;
787
806
                                oo_warning (xin, _("Invalid array expression does not specify number of rows."));
788
807
                        }
814
833
                /* store the content as a string */
815
834
                state->simple_content = TRUE;
816
835
 
817
 
        if (merge_cols > 0 && merge_rows > 0) {
818
 
                GnmRange r;
819
 
                range_init (&r,
820
 
                        state->pos.eval.col, state->pos.eval.row,
821
 
                        state->pos.eval.col + merge_cols - 1,
822
 
                        state->pos.eval.row + merge_rows - 1);
823
 
                sheet_merge_add (state->pos.sheet, &r, FALSE,
824
 
                                 NULL);
 
836
        if (merge_cols > 1 || merge_rows > 1) {
 
837
                range_init_cellpos_size (&tmp, &state->pos.eval,
 
838
                        merge_cols, merge_rows);
 
839
                sheet_merge_add (state->pos.sheet, &tmp, FALSE, NULL);
825
840
        }
826
841
}
827
842
 
1551
1566
        frame_offset[2] = (width/col->size_pts);
1552
1567
        frame_offset[3] = (height/row->size_pts);
1553
1568
 
1554
 
        sheet_object_anchor_init (&state->cur_frame.anchor, &cell_base, frame_offset, NULL, SO_DIR_DOWN_RIGHT);
 
1569
        sheet_object_anchor_init (&state->cur_frame.anchor, &cell_base, frame_offset, NULL, GOD_ANCHOR_DIR_DOWN_RIGHT);
1555
1570
}
1556
1571
 
1557
1572
static void
2440
2455
        state.cur_frame.has_legend = FALSE;
2441
2456
 
2442
2457
        if (state.ver == OOO_VER_OPENDOC) {
2443
 
                GsfInput *meta_file =
2444
 
                        meta_file = gsf_infile_child_by_name (zip, "meta.xml");
2445
 
                if (meta_file != NULL) {
 
2458
                GsfInput *meta_file = gsf_infile_child_by_name (zip, "meta.xml");
 
2459
                if (NULL != meta_file) {
2446
2460
                        meta_data = gsf_doc_meta_data_new ();
2447
2461
                        err = gsf_opendoc_metadata_read (meta_file, meta_data);
2448
2462
                        if (NULL != err) {
2456
2470
                }
2457
2471
        }
2458
2472
 
2459
 
        if (styles != NULL) {
 
2473
        if (NULL != styles) {
2460
2474
                GsfXMLInDoc *doc = gsf_xml_in_doc_new (styles_dtd, gsf_ooo_ns);
2461
2475
                gsf_xml_in_doc_parse (doc, styles, &state);
2462
2476
                gsf_xml_in_doc_free (doc);