Commit 90956c8c authored by Michael Meeks's avatar Michael Meeks Committed by Michael Meeks

Privatize FunctionDefinition

remove dump.[ch]; moving to func.c for now,
various stylistic cleans,
make plugin-sample better practice,

1999-12-06  Michael Meeks  <mmeeks@gnu.org>

	* src/eval.c (search_cell_deps): Cull dead 'draw' code.

1999-12-05  Michael Meeks  <mmeeks@gnu.org>

	* src/expr.c (eval_funcall): Extract body to func.c
	(cell_ref_make_absolute, free_values): move to func.c
	(do_expr_decode_tree): Use function_def_get_name

	* src/func.c (function_call_with_list): Clean to use new
	helper functions + update style; use eval_expr not
	eval_expr_real in 1 place; cleans flow;
	(cell_ref_make_absolute): make args more convenient.

	* Makefile.am: Kill dump.[ch]

	* src/dump.[ch]: kill + move to

	* src/func.c: (function_dump_defs).

	* src/main.c (gnumeric_main): Use function_dump_defs

	* src/func.c (function_def_get_fn): implement.
	(function_def_get_user_data, function_def_set_user_data),
	(function_def_count_args, function_def_get_name): implement.
	(function_def_get_arg_type): implement.
	Hide FunctionDefinition here. Stylistic cleans.

	* plugins/python/python.c (marshal_func): use function_def_count_args
	(__register_function): kill ancient mem leak in duff code.

	* src/dialogs/dialog-function-select.c (function_definition_update):
	use function_def_get_name.

	* src/dialogs/dialog-function-wizard.c (arg_data_list_new): rewrite to
	use count_args + get_arg_type: much safer. (get_text_value): use get_name.

	* src/expr.h: Add user_data to function definition + hack it out.

	* src/sheet.c (sheet_cell_get, sheet_cell_fetch): move up & inline
parent 36fda609
1999-12-06 Michael Meeks <mmeeks@gnu.org>
* src/eval.c (search_cell_deps): Cull dead 'draw' code.
1999-12-05 Michael Meeks <mmeeks@gnu.org>
* src/expr.c (eval_funcall): Extract body to func.c
(cell_ref_make_absolute, free_values): move to func.c
(do_expr_decode_tree): Use function_def_get_name
* src/func.c (function_call_with_list): Clean to use new
helper functions + update style; use eval_expr not
eval_expr_real in 1 place; cleans flow;
(cell_ref_make_absolute): make args more convenient.
* Makefile.am: Kill dump.[ch]
* src/dump.[ch]: kill + move to
* src/func.c: (function_dump_defs).
* src/main.c (gnumeric_main): Use function_dump_defs
* src/func.c (function_def_get_fn): implement.
(function_def_get_user_data, function_def_set_user_data),
(function_def_count_args, function_def_get_name): implement.
(function_def_get_arg_type): implement.
Hide FunctionDefinition here. Stylistic cleans.
* plugins/python/python.c (marshal_func): use function_def_count_args
(__register_function): kill ancient mem leak in duff code.
* src/dialogs/dialog-function-select.c (function_definition_update):
use function_def_get_name.
* src/dialogs/dialog-function-wizard.c (arg_data_list_new): rewrite to
use count_args + get_arg_type: much safer. (get_text_value): use get_name.
* src/expr.h: Add user_data to function definition + hack it out.
* src/sheet.c (sheet_cell_get, sheet_cell_fetch): move up & inline
1999-12-04 Michael Meeks <mmeeks@gnu.org>
* plugins/sample/plugin-sample.c (func_plusone): Make this a good
example ! ug + stylistic clean.
1999-12-05 Ariel Rios <jarios@usa.net>
* plugins/guile/Makefile.am: Modified to include functions.scm
......
1999-12-06 Michael Meeks <mmeeks@gnu.org>
* src/eval.c (search_cell_deps): Cull dead 'draw' code.
1999-12-05 Michael Meeks <mmeeks@gnu.org>
* src/expr.c (eval_funcall): Extract body to func.c
(cell_ref_make_absolute, free_values): move to func.c
(do_expr_decode_tree): Use function_def_get_name
* src/func.c (function_call_with_list): Clean to use new
helper functions + update style; use eval_expr not
eval_expr_real in 1 place; cleans flow;
(cell_ref_make_absolute): make args more convenient.
* Makefile.am: Kill dump.[ch]
* src/dump.[ch]: kill + move to
* src/func.c: (function_dump_defs).
* src/main.c (gnumeric_main): Use function_dump_defs
* src/func.c (function_def_get_fn): implement.
(function_def_get_user_data, function_def_set_user_data),
(function_def_count_args, function_def_get_name): implement.
(function_def_get_arg_type): implement.
Hide FunctionDefinition here. Stylistic cleans.
* plugins/python/python.c (marshal_func): use function_def_count_args
(__register_function): kill ancient mem leak in duff code.
* src/dialogs/dialog-function-select.c (function_definition_update):
use function_def_get_name.
* src/dialogs/dialog-function-wizard.c (arg_data_list_new): rewrite to
use count_args + get_arg_type: much safer. (get_text_value): use get_name.
* src/expr.h: Add user_data to function definition + hack it out.
* src/sheet.c (sheet_cell_get, sheet_cell_fetch): move up & inline
1999-12-04 Michael Meeks <mmeeks@gnu.org>
* plugins/sample/plugin-sample.c (func_plusone): Make this a good
example ! ug + stylistic clean.
1999-12-05 Ariel Rios <jarios@usa.net>
* plugins/guile/Makefile.am: Modified to include functions.scm
......
......@@ -246,6 +246,10 @@ Office 2000 and 'explorer' compatibility.
2. Pre-parse formulas
3. Pre-render contents.
struct _Cell should be optimized with a typed union; merge
text, entered_text. Think about width, height, render_color
merge flags + generation + move comments to a parallel hash.
* Rendering
* Sort out the cell span stuff
......@@ -254,10 +258,13 @@ Office 2000 and 'explorer' compatibility.
* Calculation
* Rework dependencies to only supply one level of indirection.
* Rework 'Name' dependencies so we can re-express names.
* Think about allowing a formula to specify that it does not depend on the
contents of a reference, only the adress (ie the AREAS function)
* Dependancies for - INDIRECT and CELL functions.
- Sheet objects.
- Sheet objects
* Teach dependencies about implicit intersections
( big speedup (assesed2.xls))
* Drawing
* Rework borders to agregate the lines and draw them after backgrounds
......
......@@ -25,17 +25,17 @@ typedef struct {
} item_t;
const guint32 sum_fmtid[4] = {
0XF29F85E0,
0X10684FF9,
0X000891AB,
0XD9B3272B
0xF29F85E0,
0x10684FF9,
0x000891AB,
0xD9B3272B
};
const guint32 doc_fmtid[4] = {
0XD5CDD502,
0X101B2E9C,
0X00089793,
0XAEF92C2B
0xD5CDD502,
0x101B2E9C,
0x00089793,
0xAEF92C2B
};
......
......@@ -87,24 +87,26 @@ fndef_compare(FuncData *fdata, FunctionDefinition *fndef)
}
static Value *
marshal_func (FunctionEvalInfo *ei, Value *argv[])
marshal_func (FunctionEvalInfo *ei, Value *argv [])
{
PyObject *args, *result;
FunctionDefinition *fndef = ei->func_def;
Value *v;
GList *l;
int i, count = strlen(fndef->args);
int i, min, max;
function_def_count_args (fndef, &min, &max);
/* Find the Python code object for this FunctionDefinition. */
l = g_list_find_custom(funclist, fndef, (GCompareFunc) fndef_compare);
l = g_list_find_custom (funclist, fndef, (GCompareFunc) fndef_compare);
if (!l)
return value_new_error (&ei->pos, _("Unable to lookup Python code object."));
/* Build the argument list which is a Python tuple. */
args = PyTuple_New (count);
for (i = 0; i < count; i++){
args = PyTuple_New (min);
for (i = 0; i < min; i++) {
/* ref is stolen from us */
PyTuple_SetItem(args, i, convert_value_to_python (argv[i]));
PyTuple_SetItem (args, i, convert_value_to_python (argv [i]));
}
/* Call the Python object. */
......@@ -138,12 +140,6 @@ __register_function (PyObject *m, PyObject *py_args)
return NULL;
}
fndef = g_new0 (FunctionDefinition, 1);
if (!fndef){
PyErr_SetString (PyExc_MemoryError, _("could not alloc FuncDef"));
return NULL;
}
cat = function_get_category (_("Perl"));
help = g_new (char *, 1);
*help = g_strdup (help1);
......
......@@ -14,12 +14,7 @@
static Value *
func_plusone (FunctionEvalInfo *ei, Value *argv [])
{
Value *v = g_new (Value, 1);
v->type = VALUE_FLOAT;
v->v.v_float = value_get_as_float (argv [0]) + 1.0;
return v;
return value_new_float (value_get_as_float (argv [0]) + 1.0);
}
static int
......@@ -38,9 +33,8 @@ cleanup_plugin (PluginData *pd)
g_free (pd->title);
sym = symbol_lookup (global_symbol_table, "plusone");
if (sym) {
symbol_unref(sym);
}
if (sym)
symbol_unref (sym);
}
int
......@@ -53,6 +47,7 @@ init_plugin (PluginData *pd)
pd->can_unload = can_unload;
pd->cleanup_plugin = cleanup_plugin;
pd->title = g_strdup ("PlusOne Plugin");
return 0;
}
1999-12-05 Michael Meeks <mmeeks@gnu.org>
* POTFILES.in: hack dump.c
1999-12-01 Richard Hult <rhult@hem2.passagen.se>
* sv.po: Updated Swedish translation.
......
......@@ -45,7 +45,6 @@ src/dialogs/summary.glade.h
src/dialogs/cell-format.glade.h
src/dialogs/cell-sort.glade.h
src/dialogs/dialog-zoom.glade.h
src/dump.c
src/embeddable-grid.c
src/eval.c
src/expr-name.c
......
......@@ -71,8 +71,6 @@ GNUMERIC_BASE_SOURCES = \
cursors.h \
dates.c \
dates.h \
dump.c \
dump.h \
eval.h \
eval.c \
expr.c \
......
......@@ -630,7 +630,7 @@ cell_set_array_formula (Sheet *sheet,
for (y = 0; y < num_rows; ++y) {
if (x == 0 && y == 0)
continue;
cell = sheet_cell_fetch (sheet, col_a+x,row_a+y);
cell = sheet_cell_fetch (sheet, col_a + x, row_a + y);
wrapper = expr_tree_array_formula (x, y,
num_rows, num_cols);
wrapper->u.array.corner.cell = corner;
......
......@@ -98,10 +98,6 @@ struct _Cell {
char generation;
};
/*
* #define CELL_IS_FORMAT_SET(cell) ((cell)->flags & CELL_FORMAT_SET)
*/
typedef enum {
CELL_COPY_TYPE_CELL,
CELL_COPY_TYPE_TEXT,
......
......@@ -430,7 +430,7 @@ Sheet_cell_get_text (PortableServer_Servant servant,
verify_row_val (row, NULL);
cell = sheet_cell_get (sheet, col, row);
if (cell){
if (cell) {
char *str;
str = cell_get_text (cell);
......
......@@ -17,7 +17,7 @@ static void
cell_eval_content (Cell *cell)
{
Value *v;
FunctionEvalInfo s;
FunctionEvalInfo ei;
#ifdef DEBUG_EVALUATION
{
......@@ -32,7 +32,8 @@ cell_eval_content (Cell *cell)
}
#endif
v = eval_expr (func_eval_info_cell (&s, cell), cell->parsed_node);
v = eval_expr (func_eval_info_cell (&ei, cell),
cell->parsed_node);
#ifdef DEBUG_EVALUATION
{
......@@ -50,7 +51,7 @@ cell_eval_content (Cell *cell)
value_release (cell->value);
if (v == NULL)
v = value_new_error (&s.pos, "Internal error");
v = value_new_error (&ei.pos, "Internal error");
cell->value = v;
cell_render_value (cell);
......@@ -71,13 +72,13 @@ cell_eval (Cell *cell)
cell->generation = cell->sheet->workbook->generation;
if (cell->parsed_node){
if (cell->parsed_node) {
GList *deps, *l;
cell_eval_content (cell);
deps = cell_get_dependencies (cell);
for (l = deps; l; l = l->next){
for (l = deps; l; l = l->next) {
Cell *one_cell;
one_cell = l->data;
......@@ -192,7 +193,7 @@ add_cell_range_deps (Cell *cell, const CellRef *a, const CellRef *b)
static void
add_value_deps (Cell *cell, const Value *value)
{
switch (value->type){
switch (value->type) {
case VALUE_EMPTY:
case VALUE_STRING:
case VALUE_INTEGER:
......@@ -203,6 +204,7 @@ add_value_deps (Cell *cell, const Value *value)
break;
/* Check every element of the array */
/* FIXME: currently array's only hold alphanumerics */
case VALUE_ARRAY:
{
int x, y;
......@@ -234,7 +236,7 @@ add_tree_deps (Cell *cell, ExprTree *tree)
{
GList *l;
switch (tree->oper){
switch (tree->oper) {
case OPER_ANY_BINARY:
add_tree_deps (cell, tree->u.binary.value_a);
add_tree_deps (cell, tree->u.binary.value_b);
......@@ -255,6 +257,10 @@ add_tree_deps (Cell *cell, ExprTree *tree)
add_value_deps (cell, tree->u.constant);
return;
/*
* FIXME: needs to be taught implicit intersection +
* more cunning handling of argument type matching.
*/
case OPER_FUNCALL:
for (l = tree->u.function.arg_list; l; l = l->next)
add_tree_deps (cell, l->data);
......@@ -268,7 +274,7 @@ add_tree_deps (Cell *cell, ExprTree *tree)
return;
case OPER_ARRAY:
if (tree->u.array.x != 0 || tree->u.array.y != 0){
if (tree->u.array.x != 0 || tree->u.array.y != 0) {
/* Non-corner cells depend on the corner */
DependencyRange range;
range.ref_count = 0;
......@@ -341,8 +347,8 @@ cell_drop_dependencies (Cell *cell)
{
GHashTable *dependency_hash;
g_return_if_fail (cell != NULL);
g_return_if_fail (cell->parsed_node != NULL);
g_return_if_fail (cell->sheet != NULL);
g_return_if_fail (cell->parsed_node != NULL);
dependency_hash = cell->sheet->dependency_hash;
if (!dependency_hash)
......@@ -350,11 +356,14 @@ cell_drop_dependencies (Cell *cell)
g_hash_table_foreach (dependency_hash, dependency_remove_cell, cell);
/* Drop any unused DependencyRanges (because their ref_count reached zero) */
if (remove_list){
/*
* Drop any unused DependencyRanges (because their
* ref_count reached zero)
*/
if (remove_list) {
GList *l = remove_list;
for (; l; l = l->next){
for (; l; l = l->next) {
g_hash_table_remove (dependency_hash, l->data);
g_free (l->data);
}
......@@ -425,20 +434,18 @@ search_cell_deps (gpointer key, gpointer value, gpointer closure)
Range *range = &(deprange->range);
get_cell_dep_closure_t *c = closure;
GList *l;
int draw;
/* int draw;*/
if (deprange->sheet != c->sheet)
return;
draw = FALSE;
if (c->col == 1 && c->row == 1){
draw = TRUE;
}
/* draw = FALSE;
if (c->col == 1 && c->row == 1)
draw = TRUE;*/
/* No intersection is the common case */
if (!range_contains (range, c->col, c->row)){
if (!range_contains (range, c->col, c->row))
return;
}
for (l = deprange->cell_list; l; l = l->next) {
Cell *cell = l->data;
......@@ -450,7 +457,8 @@ search_cell_deps (gpointer key, gpointer value, gpointer closure)
for (l = deprange->cell_list; l; l = l->next) {
Cell *cell = l->data;
printf (" %s(%d), ", cell_name (cell->col->pos, cell->row->pos), cell->generation);
printf (" %s(%d), ", cell_name (cell->col->pos, cell->row->pos),
cell->generation);
}
printf ("]\n");
#endif
......@@ -471,7 +479,7 @@ cell_get_dependencies (Cell *cell)
closure.list = NULL;
sheets = workbook_sheets (cell->sheet->workbook);
for (l = sheets; l; l = l->next){
for (l = sheets; l; l = l->next) {
Sheet *sheet = l->data;
if (!sheet->dependency_hash)
......@@ -587,10 +595,10 @@ pick_next_cell_from_queue (Workbook *wb)
void
workbook_next_generation (Workbook *wb)
{
if (wb->generation == 255){
if (wb->generation == 255) {
GList *cell_list = wb->formula_cell_list;
for (; cell_list; cell_list = cell_list->next){
for (; cell_list; cell_list = cell_list->next) {
Cell *cell = cell_list->data;
cell->generation = 0;
......@@ -613,7 +621,7 @@ workbook_recalc (Workbook *wb)
workbook_next_generation (wb);
generation = wb->generation;
while ((cell = pick_next_cell_from_queue (wb))){
while ((cell = pick_next_cell_from_queue (wb))) {
if (cell->generation == generation)
continue;
......
......@@ -75,8 +75,8 @@ arg_data_list_new (State *state)
gchar *copy_args;
const gchar *syntax;
gchar *ptr, *start = NULL;
gchar const *type;
int optional = 0;
int i;
int arg_max, arg_min;
if (!state || !state->fd ||
!state->tok)
......@@ -84,18 +84,18 @@ arg_data_list_new (State *state)
state->args = g_ptr_array_new ();
type = state->fd->args;
if (!type){
function_def_count_args (state->fd, &arg_min, &arg_max);
if (arg_max == G_MAXINT) {
int lp;
for (lp = 0; lp < INPUTS_FOR_MULTI_ARG; lp++){
for (lp = 0; lp < INPUTS_FOR_MULTI_ARG; lp++) {
ARG_DATA *ad;
ad = g_new (ARG_DATA, 1);
ad->arg_name = g_strdup ("Value");
ad->wb = state->wb;
ad->type = '?';
ad->optional = (lp!=0);
ad->optional = (lp != 0);
ad->entry = NULL;
g_ptr_array_add (state->args, ad);
}
......@@ -103,41 +103,37 @@ arg_data_list_new (State *state)
}
syntax = tokenized_help_find (state->tok, "SYNTAX");
if (!syntax){
if (!syntax) {
g_ptr_array_free (state->args, FALSE);
state->args = NULL;
return;
}
ptr = copy_args = g_strdup (syntax);
while (*ptr){
i = 0;
while (*ptr) {
if (*ptr == '(' && !start)
start = ptr+1;
if (*ptr == '[' || *ptr == ']'){
start = ptr + 1;
if (*ptr == '[' || *ptr == ']') {
*ptr = '\0';
if (start == ptr)
start++;
ptr++;
continue;
}
if (*ptr == ',' || *ptr == ')'){
if (*type=='|'){
type++;
optional = 1;
}
if (ptr > start){
if (*ptr == ',' || *ptr == ')') {
if (ptr > start) {
ARG_DATA *ad;
ad = g_new (ARG_DATA, 1);
ad->arg_name = g_strndup (start, (int)(ptr-start));
ad->arg_name = g_strndup (start, (int)(ptr - start));
ad->wb = state->wb;
ad->type = *type;
ad->optional = optional;
ad->type = function_def_get_arg_type (state->fd, i);
ad->optional = (i >= arg_min);
ad->entry = NULL;
g_ptr_array_add (state->args, ad);
i++;
}
type++;
start = ptr+1;
start = ptr + 1;
}
ptr++;
}
......@@ -284,19 +280,21 @@ static char*
get_text_value (State *state)
{
gchar *txt, *txt2;
const char *name;
int lp;
g_return_val_if_fail (state, NULL);
g_return_val_if_fail (state->fd, NULL);
g_return_val_if_fail (state->args, NULL);
g_return_val_if_fail (state != NULL, NULL);
g_return_val_if_fail (state->fd != NULL, NULL);
g_return_val_if_fail (state->args != NULL, NULL);
txt = g_strconcat (state->fd->name, "(", NULL);
name = function_def_get_name (state->fd);
txt = g_strconcat (name, "(", NULL);
for (lp = 0; lp < state->args->len; lp++){
for (lp = 0; lp < state->args->len; lp++) {
ARG_DATA *ad = g_ptr_array_index (state->args, lp);
gchar *val = gtk_entry_get_text (ad->entry);
if (!ad->optional || strlen(val)){
if (!ad->optional || strlen (val)) {
txt2 = txt;
txt = g_strconcat (txt2, lp?",":"", val, NULL);
g_free (txt2);
......
......@@ -72,7 +72,7 @@ function_definition_update (SelectorState *selector_state)
gchar *cols [1];
FunctionDefinition *fn = p->data;
cols[0] = (gchar *)fn->name; /* Const cast */
cols[0] = (gchar *)function_def_get_name (fn); /* Const cast */
gtk_clist_append (cl, cols);
if (i == selector_state->selected_func)
......
......@@ -75,8 +75,8 @@ arg_data_list_new (State *state)
gchar *copy_args;
const gchar *syntax;
gchar *ptr, *start = NULL;
gchar const *type;
int optional = 0;
int i;
int arg_max, arg_min;
if (!state || !state->fd ||
!state->tok)
......@@ -84,18 +84,18 @@ arg_data_list_new (State *state)
state->args = g_ptr_array_new ();
type = state->fd->args;
if (!type){
function_def_count_args (state->fd, &arg_min, &arg_max);
if (arg_max == G_MAXINT) {
int lp;
for (lp = 0; lp < INPUTS_FOR_MULTI_ARG; lp++){
for (lp = 0; lp < INPUTS_FOR_MULTI_ARG; lp++) {
ARG_DATA *ad;
ad = g_new (ARG_DATA, 1);
ad->arg_name = g_strdup ("Value");
ad->wb = state->wb;
ad->type = '?';
ad->optional = (lp!=0);
ad->optional = (lp != 0);
ad->entry = NULL;
g_ptr_array_add (state->args, ad);
}
......@@ -103,41 +103,37 @@ arg_data_list_new (State *state)
}
syntax = tokenized_help_find (state->tok, "SYNTAX");
if (!syntax){
if (!syntax) {
g_ptr_array_free (state->args, FALSE);
state->args = NULL;
return;
}
ptr = copy_args = g_strdup (syntax);
while (*ptr){
i = 0;
while (*ptr) {
if (*ptr == '(' && !start)
start = ptr+1;
if (*ptr == '[' || *ptr == ']'){