Commit 97ab95f0 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

don't take a user pointer, but the conventions instead.

2003-01-07  Morten Welinder  <terra@diku.dk>

	* src/parse-util.h (GnmParseFunctionHandler): don't take a user
	pointer, but the conventions instead.

	* src/parser.y: Supply convs to handlers.  Look up functions in
	rewriter hash and act accordingly.


2003-01-07  Morten Welinder  <terra@diku.dk>

	* applix-read.c (function_renamer): New function.
	(applix_conventions): Initialize the function rewriter.
parent dd940d5e
......@@ -15,6 +15,8 @@ Morten:
* Fix MDETERM.
* Lower number of matrix LU-decomposition routines from three to
one.
* Add function renaming support for file formats that use function
names different from our.
--------------------------------------------------------------------------
Gnumeric 1.1.15
......
2003-01-07 Morten Welinder <terra@diku.dk>
* applix-read.c (function_renamer): New function.
(applix_conventions): Initialize the function rewriter.
2003-01-02 Jody Goldberg <jody@gnome.org>
* applix-read.c (applix_parse_cellref) : warning.
......
......@@ -1454,6 +1454,38 @@ cb_remove_style (gpointer key, gpointer value, gpointer user_data)
return TRUE;
}
static const struct {
const char *applixname;
const char *gnumericname;
} simple_renames[] = {
{ "IPAYMT", "IPMT" },
{ "PAYMT", "PMT" },
{ "PPAYMT", "PPMT" },
{ 0, 0 }
};
static GnmExpr const *
function_renamer (const char *name,
GnmExprList *args,
GnmExprConventions *convs)
{
const char *newname = NULL;
Workbook *wb = NULL;
int i;
for (i = 0; simple_renames[i].applixname; i++)
if (strcmp (name, simple_renames[i].applixname) == 0)
newname = simple_renames[i].gnumericname;
if (newname) {
GnmFunc *f = gnm_func_lookup (newname, wb);
if (f)
return gnm_expr_new_funcall (f, args);
}
return gnm_func_placeholder_factory (name, args, convs);
}
static GnmExprConventions *
applix_conventions (void)
{
......@@ -1466,6 +1498,12 @@ applix_conventions (void)
res->unknown_function_handler = gnm_func_placeholder_factory;
res->ref_parser = applix_rangeref_parse;
res->function_rewriter_hash =
g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (res->function_rewriter_hash,
(gchar *)"IPAYMT",
function_renamer);
return res;
}
......
......@@ -536,7 +536,7 @@ gnm_func_add_placeholder (char const *name, char const *type,
GnmExpr const *
gnm_func_placeholder_factory (const char *name,
GnmExprList *args,
gpointer userdata)
G_GNUC_UNUSED GnmExprConventions *convs)
{
GnmFunc *f = gnm_func_add_placeholder (name, "", TRUE);
return gnm_expr_new_funcall (f, args);
......
......@@ -194,7 +194,7 @@ GnmFunc *gnm_func_add_placeholder (char const *name,
gboolean copy_name);
GnmExpr const *gnm_func_placeholder_factory (const char *name,
GnmExprList *args,
gpointer userdata);
GnmExprConventions *convs);
/* TODO */
......
......@@ -85,7 +85,7 @@ typedef char const *(*GnmRangeRefParse) (RangeRef *res, char const *in,
*/
typedef GnmExpr const *(*GnmParseFunctionHandler) (const char *name,
GnmExprList *args,
gpointer userdata);
GnmExprConventions *convs);
typedef void (*GnmParseExprNameHandler) (GString *target,
const ParsePos *pp,
......
......@@ -617,18 +617,24 @@ exp: CONSTANT { $$ = $1; }
function : STRING '(' arg_list ')' {
char const *name = $1->constant.value->v_str.val->str;
GnmFunc *f = gnm_func_lookup (name, state->pos->wb);
GnmFunc *f;
GnmExpr const *f_call = NULL;
GnmParseFunctionHandler h = NULL;
$$ = NULL;
if (f == NULL) {
GnmParseFunctionHandler h =
state->convs->unknown_function_handler;
if (h)
f_call = h (name, $3, NULL);
} else
if (state->convs->function_rewriter_hash)
h = g_hash_table_lookup (state->convs->function_rewriter_hash, name);
if (h) {
f_call = h (name, $3, state->convs);
} else if ((f = gnm_func_lookup (name, state->pos->wb))) {
f_call = gnm_expr_new_funcall (f, $3);
} else {
h = state->convs->unknown_function_handler;
if (h)
f_call = h (name, $3, state->convs);
}
/* We're done with the function name. */
unregister_allocation ($1); gnm_expr_unref ($1);
......
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