X-Git-Url: https://secure.softndesign.org/git/?a=blobdiff_plain;f=program.c;h=7db9d40291b3433a503b32f07c0b605f2ff7497e;hb=89a2c19deeb8b45dc8c655e59bc58f7a606ecd2c;hp=a6801f8a48574ed34a003ed5451e1ef8e6a35ea7;hpb=33b4877a64014cfb19d0ef6928b1ffefe6496903;p=calc.git diff --git a/program.c b/program.c index a6801f8..7db9d40 100644 --- a/program.c +++ b/program.c @@ -81,20 +81,17 @@ double call (int id, int nbargs, element_t **args) VERBOSE (WARNING, fprintf (stdout, "error unknown program (%d)\n", id)); return 0; } - VERBOSE (DEBUG, fprintf (stdout, "id -> n; %d -> %d\n", id, n)); /* set arguments */ - free_tab (argument); - argument = NULL; - VERBOSE (DEBUG, fprintf (stdout, "nbargs; %d\n", nbargs)); - if (nbargs > 0) { - def (nbargs, args); - } + tab_t *old_argument = copy_tab (argument); /* backup context */ workspace_t *tmp = backup_ws (alloc_ws ()); restore_ws (programs[n]); + /* set arguments */ + argument = def (nbargs, args); + /* evaluate program */ answer = 0; element_t *elements = dupelement (programs[n]->root); @@ -102,15 +99,15 @@ double call (int id, int nbargs, element_t **args) VERBOSE (DEBUG, fprintf (stdout, "ret; %g\n", ret)); delelement (elements); - /* clean arguments */ - free_tab (argument); - argument = NULL; - /* restore context */ backup_ws (programs[n]); restore_ws (tmp); free_ws (tmp); + /* clean arguments */ + free_tab (argument); + argument = old_argument; + return ret; }