X-Git-Url: https://secure.softndesign.org/git/?a=blobdiff_plain;f=program.c;h=1e960f728641a02a44c5f660600031403ae28f3d;hb=9e527b672cea0530effc91bc13e0ce49d552ecdd;hp=e8cd2d1301379c1f6efffebafaa7985b258f67bf;hpb=e952523a06b81e8915751bdcb01ca87aad06ce1c;p=calc.git diff --git a/program.c b/program.c index e8cd2d1..1e960f7 100644 --- a/program.c +++ b/program.c @@ -82,35 +82,38 @@ double call (int id, int nbargs, element_t **args) return 0; } + /* set arguments */ + VERBOSE (DEBUG, fprintf (stdout, "1 arg[0]: %g\n", get_tab (argument, 1))); + tab_t *old_argument = copy_tab (argument); + /* backup context */ workspace_t *tmp = backup_ws (alloc_ws ()); restore_ws (programs[n]); - + VERBOSE (DEBUG, fprintf (stdout, "2 arg[0]: %g\n", get_tab (argument, 1))); + /* set arguments */ - free_tab (argument); - argument = NULL; - if (nbargs > 0) { - def (nbargs, args); - } + argument = def (nbargs, args); + VERBOSE (DEBUG, fprintf (stdout, "3 arg[0]: %g\n", get_tab (argument, 1))); /* evaluate program */ answer = 0; element_t *elements = dupelement (programs[n]->root); + VERBOSE (DEBUG, fprintf (stdout, "4 arg[0]: %g\n", get_tab (argument, 1))); ret = evaluate_element (elements, 0); + VERBOSE (DEBUG, fprintf (stdout, "ret; %g\n", ret)); + VERBOSE (DEBUG, fprintf (stdout, "5 arg[0]: %g\n", get_tab (argument, 1))); delelement (elements); - /* clean arguments */ - if (argument) { - free_tab (argument); - } - argument = NULL; - if (nbargs > 0) { - def (nbargs, args); - } - /* restore context */ backup_ws (programs[n]); restore_ws (tmp); + free_ws (tmp); + VERBOSE (DEBUG, fprintf (stdout, "6 arg[0]: %g\n", get_tab (argument, 1))); + + /* clean arguments */ + free_tab (argument); + argument = old_argument; + VERBOSE (DEBUG, fprintf (stdout, "7 arg[0]: %g\n", get_tab (argument, 1))); return ret; } @@ -167,13 +170,10 @@ void del (int id) free_ws (programs[n]); /* remove entry */ - workspace_t **tmp = (workspace_t **) callocordie (--nb_programs, sizeof (workspace_t *)); - if (n != 0) { - memcpy (tmp, programs, (n - 1) * sizeof (workspace_t)); - } - if (n != nb_programs) { - memcpy (tmp + n - 1, programs + n, (nb_programs - n) * sizeof (workspace_t)); - } + workspace_t **tmp = (workspace_t **) callocordie (nb_programs - 1, sizeof (workspace_t *)); + memcpy (tmp, programs, n * sizeof (workspace_t *)); + memcpy (tmp + n, programs + n + 1, (nb_programs - n - 1) * sizeof (workspace_t *)); + nb_programs--; free (programs); programs = tmp; }