[gnumeric] sc import: support "fmt"
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] sc import: support "fmt"
- Date: Fri, 8 Oct 2010 17:17:09 +0000 (UTC)
commit fe5c2f8652b91356a3995137bd609a6d765db8ff
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Fri Oct 8 11:17:05 2010 -0600
sc import: support "fmt"
2010-10-08 Andreas J. Guelzow <aguelzow pyrshep ca>
* sc.c (sc_parse_coord_real): new, former part of sc_parse_coord
(sc_parse_coord): use sc_parse_coord_real
(sc_parse_fmt): new
(sc_cmd_list): connect sc_parse_fmt
plugins/sc/ChangeLog | 7 ++++
plugins/sc/sc.c | 91 ++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 77 insertions(+), 21 deletions(-)
---
diff --git a/plugins/sc/ChangeLog b/plugins/sc/ChangeLog
index f86a0d0..6b34f38 100644
--- a/plugins/sc/ChangeLog
+++ b/plugins/sc/ChangeLog
@@ -1,5 +1,12 @@
2010-10-08 Andreas J. Guelzow <aguelzow pyrshep ca>
+ * sc.c (sc_parse_coord_real): new, former part of sc_parse_coord
+ (sc_parse_coord): use sc_parse_coord_real
+ (sc_parse_fmt): new
+ (sc_cmd_list): connect sc_parse_fmt
+
+2010-10-08 Andreas J. Guelzow <aguelzow pyrshep ca>
+
* sc.c (ScParseState): add fields
(sc_go_error_info_new_vprintf): new
(sc_warning): new; replace all g_warnings with calls to sc_warning
diff --git a/plugins/sc/sc.c b/plugins/sc/sc.c
index 49e7c19..69018a6 100644
--- a/plugins/sc/sc.c
+++ b/plugins/sc/sc.c
@@ -204,39 +204,25 @@ err_out:
}
+
static gboolean
-sc_parse_coord (ScParseState *state, char const **strdata, GnmCellPos *pos)
+sc_parse_coord_real (ScParseState *state, char const *strdata, GnmCellPos *pos,
+ size_t tmplen)
{
- char const *s = *strdata, *eq;
- int len = strlen (s);
- char tmpstr[16];
- size_t tmplen;
+ char *tmpstr;
GnmNamedExpr *nexpr;
GnmParsePos pp;
GnmValue *v;
g_return_val_if_fail (strdata, FALSE);
- eq = strstr (s, " = ");
- if (!eq)
- return FALSE;
-
- tmplen = eq - s;
- if (tmplen >= sizeof (tmpstr))
- return FALSE;
-
- memcpy (tmpstr, s, tmplen);
- tmpstr [tmplen] = 0;
+ tmpstr = g_strndup (strdata, tmplen);
/* It ought to be a cellref. */
if (sc_cellname_to_coords (tmpstr, pos)) {
g_return_val_if_fail (pos->col >= 0, FALSE);
g_return_val_if_fail (pos->row >= 0, FALSE);
-
- if ((eq - s + 1 + 3) > len)
- return FALSE;
-
- *strdata = eq + 3;
+ g_free (tmpstr);
return TRUE;
}
@@ -253,15 +239,41 @@ sc_parse_coord (ScParseState *state, char const **strdata, GnmCellPos *pos)
pos->col = gnm_cellref_get_col (cr, &ep);
pos->row = gnm_cellref_get_row (cr, &ep);
value_release (v);
+ g_free (tmpstr);
return TRUE;
}
value_release (v);
}
-
+ g_free (tmpstr);
return FALSE;
}
+static gboolean
+sc_parse_coord (ScParseState *state, char const **strdata, GnmCellPos *pos)
+{
+ char const *s, *eq;
+ gboolean res;
+
+ g_return_val_if_fail (strdata, FALSE);
+ g_return_val_if_fail (*strdata, FALSE);
+
+ s = *strdata;
+
+ eq = strstr (s, " = ");
+ if (!eq)
+ return FALSE;
+
+ res = sc_parse_coord_real (state, s, pos, eq - s);
+
+ if (res) {
+ if ((eq - s + 1 + 3) > (int) strlen (s))
+ res = FALSE;
+ else
+ *strdata = eq + 3;
+ }
+ return res;
+}
static void
set_h_align (Sheet *sheet, GnmCellPos const *pos, GnmHAlign ha)
@@ -274,6 +286,42 @@ set_h_align (Sheet *sheet, GnmCellPos const *pos, GnmHAlign ha)
}
static gboolean
+sc_parse_fmt (ScParseState *state, char const *cmd, char const *str,
+ GnmCellPos const *cpos)
+{
+ char const *s = str, *space;
+ char *fmt;
+ gboolean res;
+ GOFormat *gfmt;
+ GnmStyle *style;
+ GnmCellPos pos = { -1, -1 };
+
+ space = strstr (s, "\"");
+ space--;
+ if (!space)
+ return FALSE;
+
+ res = sc_parse_coord_real (state, s, &pos, space - s);
+ if (!res)
+ return FALSE;
+ s = space + 2;
+ space = strstr (s, "\"");
+ if (!space)
+ return FALSE;
+ fmt = g_strndup (s, space - s);
+ gfmt = go_format_new_from_XL (fmt);
+ style = gnm_style_new_default ();
+ gnm_style_set_format (style, gfmt);
+
+ sheet_style_apply_pos (state->sheet, pos.col, pos.row, style);
+ /* gnm_style_unref (style); reference has been absorbed */
+ go_format_unref (gfmt);
+ g_free (fmt);
+
+ return TRUE;
+}
+
+static gboolean
sc_parse_label (ScParseState *state, char const *cmd, char const *str,
GnmCellPos const *pos)
{
@@ -563,6 +611,7 @@ static sc_cmd_t const sc_cmd_list[] = {
{ "label", 5, sc_parse_label, TRUE },
{ "let", 3, sc_parse_let, TRUE },
{ "define", 6, sc_parse_define, FALSE },
+ { "fmt", 3, sc_parse_fmt, FALSE },
{ NULL, 0, NULL, 0 },
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]