--- /dev/null
+%{
+#define YYSTYPE char *
+
+#include <string.h>
+
+#include <glib.h>
+
+#include "lexycal.yy.h"
+#include "rptreport_priv.h"
+
+void yyerror (RptReport *rpt_report, gint row, gchar **ret, char const *s);
+%}
+
+%token INTEGER
+%token FLOAT
+%token STRING
+%token FIELD
+%token SPECIAL
+%token FUNCTION
+
+%left '&'
+%left '+'
+%left '-'
+%left '*'
+%left '/'
+
+%parse-param {RptReport *rpt_report}
+%parse-param {gint row}
+%parse-param {gchar **ret}
+
+%% /* Grammar rules and actions */
+input: /* empty */
+ | input string
+;
+
+string: exp { *ret = g_strdup ($1); }
+;
+
+exp: INTEGER { $$ = $1; }
+ | FLOAT { $$ = $1; }
+ | STRING { $$ = g_strndup ($1 + 1, strlen ($1) - 2) }
+ | FIELD { $$ = rpt_report_get_field (rpt_report, g_strndup ($1 + 1, strlen ($1) - 2), row); }
+ | SPECIAL { $$ = rpt_report_get_special (rpt_report, $1, row); }
+ | exp '+' exp { $$ = g_strdup_printf ("%f", strtod ($1, NULL) + strtod ($3, NULL)); }
+ | exp '-' exp { $$ = g_strdup_printf ("%f", strtod ($1, NULL) - strtod ($3, NULL)); }
+ | exp '*' exp { $$ = g_strdup_printf ("%f", strtod ($1, NULL) * strtod ($3, NULL)); }
+ | exp '/' exp { $$ = g_strdup_printf ("%f", strtod ($1, NULL) / strtod ($3, NULL)); }
+ | exp '&' exp { $$ = g_strconcat ($1, $3, NULL); }
+ | '(' exp ')' { $$ = $2; }
+;
+%%
+
+/* Called by yyparse on error. */
+void
+yyerror (RptReport *rpt_report, gint row, gchar **ret, char const *s)
+{
+ fprintf (stderr, "BISON ERROR: %s\n", s);
+}
#endif
#include "rptreport.h"
+#include "rptreport_priv.h"
#include "rptcommon.h"
#include "rptobjecttext.h"
#include "rptobjectline.h"
#include "rptmarshal.h"
+#include "parser.tab.h"
+
typedef struct
{
gchar *provider_id;
xmlNode *xnode,
gint row);
+static void rpt_report_change_specials (RptReport *rpt_report, xmlDoc *xdoc);
+
#define RPT_REPORT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_RPT_REPORT, RptReportPrivate))
cur_y = priv->page->size->height - priv->page->margin_top - priv->page->margin_bottom - priv->page_footer->height;
rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER, row - 1);
}
+
+ /* change @Pages */
+ rpt_report_change_specials (rpt_report, xdoc);
}
else
{
static void
rpt_report_rptprint_parse_text_source (RptReport *rpt_report, RptObject *rptobj, xmlNode *xnode, gint row)
{
- /* TO DO */
gchar *source;
+ gchar *ret;
RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
g_object_get (G_OBJECT (rptobj), "source", &source, NULL);
- if (row > -1 && priv->db->gda_datamodel != NULL && source[0] == '[' && source[strlen (source) - 1] == ']')
+ yy_scan_string (source);
+ yyparse (rpt_report, row, &ret);
+
+ if (ret == NULL)
{
- gint col;
- gchar *field;
+ xmlNodeSetContent (xnode, "");
+ }
+ else
+ {
+ xmlNodeSetContent (xnode, ret);
+ }
+}
- field = g_strstrip (g_strndup (source + 1, strlen (source) - 2));
- col = gda_data_model_get_column_position (priv->db->gda_datamodel, field);
+static void
+rpt_report_change_specials (RptReport *rpt_report, xmlDoc *xdoc)
+{
+ xmlXPathContextPtr xpcontext;
+ xmlXPathObjectPtr xpresult;
+ xmlNodeSetPtr xnodeset;
+ RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
- if (col > -1)
- {
- source = gda_value_stringify ((GdaValue *)gda_data_model_get_value_at (priv->db->gda_datamodel, col, row));
- }
- else
- {
- /* ask value */
- gchar *ret;
- RptReportClass *klass = RPT_REPORT_GET_CLASS (rpt_report);
+ xpcontext = xmlXPathNewContext (xdoc);
- g_signal_emit (rpt_report, klass->field_request_signal_id,
- 0, field, priv->db->gda_datamodel, row, &ret);
- if (ret != NULL)
- {
- source = g_strdup (ret);
- }
- else
+ xpcontext->node = xmlDocGetRootElement (xdoc);
+ xpresult = xmlXPathEvalExpression ((const xmlChar *)"//text[contains(node(), \"@Pages\")]", xpcontext);
+ if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval))
+ {
+ gint i;
+ xmlNode *cur;
+ gchar *ref;
+ gchar *cont;
+
+ xnodeset = xpresult->nodesetval;
+
+ for (i = 0; i < xnodeset->nodeNr; i++)
+ {
+ cur = xnodeset->nodeTab[i];
+ cont = g_strdup (xmlNodeGetContent (cur));
+ while ((ref = strstr (cont, "@Pages")) != NULL)
{
- source = g_strdup ("");
+ cont = g_strconcat ("",
+ g_strndup (cont, strlen (cont) - strlen (ref)),
+ g_strdup_printf ("%d", priv->cur_page),
+ g_strndup (ref + 6, strlen (ref - 6)),
+ NULL);
}
+ xmlNodeSetContent (cur, cont);
}
}
- else if (source[0] == '[' && source[strlen (source) - 1] == ']')
+}
+
+gchar
+*rpt_report_get_field (RptReport *rpt_report, const gchar *field_name, gint row)
+{
+ gint col;
+ gchar *ret = NULL;
+
+ RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+ col = gda_data_model_get_column_position (priv->db->gda_datamodel, field_name);
+
+ if (col > -1)
{
- /* ask value */
- gchar *ret;
- gchar *field;
- RptReportClass *klass = RPT_REPORT_GET_CLASS (rpt_report);
-
- field = g_strstrip (g_strndup (source + 1, strlen (source) - 2));
- g_signal_emit (rpt_report, klass->field_request_signal_id,
- 0, field, NULL, row, &ret);
- if (ret != NULL)
- {
- source = g_strdup (ret);
- }
- else
- {
- source = g_strdup ("");
- }
+ ret = gda_value_stringify ((GdaValue *)gda_data_model_get_value_at (priv->db->gda_datamodel, col, row));
}
- else if (source[0] == '@')
+ else
{
- /* TO DO */
- /* special values */
+ ret = rpt_report_ask_field (rpt_report, field_name, row);
+ }
- if (strcmp (source + 1, "Page") == 0)
- {
- source = g_strdup_printf ("%d", priv->cur_page);
- }
- else if (strcmp (source + 1, "Date") == 0)
- {
- char date[11] = "\0";
- time_t now = time (NULL);
- struct tm *tm = localtime (&now);
- strftime (date, 11, "%F", tm);
- source = g_strdup_printf ("%s", &date);
- }
- else if (strcmp (source + 1, "Time") == 0)
- {
- char date[6] = "";
- time_t now = time (NULL);
- struct tm *tm = localtime (&now);
- strftime (date, 6, "%H:%M", tm);
- source = g_strdup_printf ("%s", &date);
- }
+ return ret;
+}
+
+gchar
+*rpt_report_ask_field (RptReport *rpt_report, const gchar *field, gint row)
+{
+ gchar *ret = NULL;
+
+ RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+ RptReportClass *klass = RPT_REPORT_GET_CLASS (rpt_report);
+
+ g_signal_emit (rpt_report, klass->field_request_signal_id,
+ 0, field, priv->db->gda_datamodel, row, &ret);
+ if (ret != NULL)
+ {
+ ret = g_strdup (ret);
}
- else if (source[0] = '"' && source[strlen (source) - 1] == '"')
+
+ return ret;
+}
+
+gchar
+*rpt_report_get_special (RptReport *rpt_report, const gchar *special, gint row)
+{
+ gchar *ret = NULL;
+
+ RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+ if (strcmp (special, "@Page") == 0)
{
- source = g_strndup (source + 1, strlen (source) - 2);
+ ret = g_strdup_printf ("%d", priv->cur_page);
}
- else
+ else if (strcmp (special, "@Pages") == 0)
+ {
+ ret = g_strdup ("@Pages");
+ }
+ else if (strcmp (special, "@Date") == 0)
+ {
+ char date[11] = "\0";
+ time_t now = time (NULL);
+ struct tm *tm = localtime (&now);
+ strftime (date, 11, "%F", tm);
+ ret = g_strdup_printf ("%s", &date);
+ }
+ else if (strcmp (special, "@Time") == 0)
{
- source = g_strdup ("");
+ char date[6] = "";
+ time_t now = time (NULL);
+ struct tm *tm = localtime (&now);
+ strftime (date, 6, "%H:%M", tm);
+ ret = g_strdup_printf ("%s", &date);
}
- xmlNodeSetContent (xnode, source);
+ return ret;
}