X-Git-Url: https://secure.softndesign.org/git/?a=blobdiff_plain;f=parser.c;h=0359234f352fb4669805cd3162d7aa957784d0c4;hb=523841a1e0785a34286154a46319d9bd435bd8d7;hp=3d8681cdf3bb7f6d8972459744b15f2b64486928;hpb=779282bba9b01f32ff208220e35cfc266721bacc;p=calc.git diff --git a/parser.c b/parser.c index 3d8681c..0359234 100644 --- a/parser.c +++ b/parser.c @@ -480,7 +480,9 @@ element_t *parser (char *str, char **next, int prio) } /* save string */ - root->string = string; + if (root != NULL) { + root->string = string; + } return root; } @@ -673,12 +675,15 @@ double while_do (element_t *cond, element_t *action) VERBOSE (DEBUG, fprintf (stdout, "loop...\n")); temp = dupelement (cond); - if (!evaluate_element (temp, 0)) { + double test = evaluate_element (temp, 0); + delelement (temp); + if (!test) { break; } if (action) { temp = dupelement (action); ret = evaluate_element (temp, 0); + delelement (temp); } } @@ -780,6 +785,7 @@ void prog (int id, int nbmems, element_t *root) } if ((programs + n)->string) { free ((programs + n)->string); + (programs + n)->string = NULL; } } } @@ -837,6 +843,7 @@ double call (int id, int nbops, element_t **ops) /* evaluate program */ element_t *elements = dupelement ((programs + n)->root); ret = evaluate_element (elements, 0); + delelement (elements); /* restore context */ answer = tmp.answer; @@ -893,15 +900,16 @@ void savestring (int id, char *string) } } } - if (n == -1) { - VERBOSE (WARNING, fprintf (stdout, "error unknown program (%d)\n", id)); - return; - } - /* save program */ - if ((programs + n)->string) { - free ((programs + n)->string); - } + /* unnecesary code */ + //if (n == -1) { + // VERBOSE (WARNING, fprintf (stdout, "error unknown program (%d)\n", id)); + // return; + //} + //if ((programs + n)->string) { + // free ((programs + n)->string); + //} + (programs + n)->string = strdup (string); } @@ -1206,7 +1214,7 @@ void free_completion_list (char **list) int i; if (list) { - for (i = 0; i < NB_FUNCTIONS + NB_CONSTANTS; i++) { + for (i = 0; i < NB_OPERATORS + NB_FUNCTIONS + NB_CONSTANTS + NB_SYMBOLS + 1; i++) { if (list[i] != NULL) { free (list[i]); }