--- stack/stack.c 2002/02/14 12:20:09 1.80 +++ stack/stack.c 2002/02/14 22:44:49 1.83 @@ -8,6 +8,8 @@ #include /* strcmp, strcpy, strlen, strcat, strdup */ #include +/* mtrace, muntrace */ +#include #define HASHTBLSIZE 2048 @@ -58,7 +60,6 @@ stackitem *head; /* Head of the stack */ hashtbl symbols; /* Hash table of all variable bindings */ int err; /* Error flag */ - int non_eval_flag; char *in_string; /* Input pending to be read */ char *free_string; /* Free this string when all input is read from in_string */ @@ -75,7 +76,6 @@ env->in_string= NULL; env->err= 0; - env->non_eval_flag= 0; for(i= 0; isymbols[i]= NULL; } @@ -102,13 +102,18 @@ free(item); /* free the stackitem */ item=temp; /* go to next stackitem */ } - free(val); /* Free the actual list value */ break; case integer: case func: + break; case symb: + free(((symbol*)(val->content.ptr))->id); + if(((symbol*)(val->content.ptr))->val!=NULL) + free_val(((symbol*)(val->content.ptr))->val); + free(val->content.ptr); break; } + free(val); /* Free the actual value structure */ } } @@ -174,7 +179,7 @@ new_value->content.val= in_val; new_value->type= integer; - new_value->refcount=1; + new_value->refcount= 0; push_val(env, new_value); } @@ -187,7 +192,7 @@ new_value->content.ptr= malloc(strlen(in_string)+1); strcpy(new_value->content.ptr, in_string); new_value->type= string; - new_value->refcount=1; + new_value->refcount= 0; push_val(env, new_value); } @@ -213,7 +218,6 @@ } extern void mangle(environment *env){ - value *new_value; char *new_string; if((env->head)==NULL) { @@ -233,12 +237,7 @@ toss(env); if(env->err) return; - new_value= malloc(sizeof(value)); - new_value->content.ptr= new_string; - new_value->type= string; - new_value->refcount=1; - - push_val(env, new_value); + push_cstring(env, new_string); } /* Push a symbol onto the stack. */ @@ -612,7 +611,7 @@ pack= malloc(sizeof(value)); pack->type= list; pack->content.ptr= temp; - pack->refcount= 1; + pack->refcount= 0; push_val(env, pack); rev(env); @@ -741,6 +740,7 @@ extern void clear(environment *); void forget_sym(symbol **); +extern void words(environment *); /* Quit stack. */ extern void quit(environment *env) @@ -748,6 +748,9 @@ long i; clear(env); + + words(env); + if (env->err) return; for(i= 0; isymbols[i]!= NULL) { @@ -755,6 +758,14 @@ } env->symbols[i]= NULL; } + + words(env); + + if(env->free_string!=NULL) + free(env->free_string); + + muntrace(); + exit(EXIT_SUCCESS); } @@ -829,6 +840,8 @@ { environment myenv; + mtrace(); + init_env(&myenv); while(1) { @@ -1204,7 +1217,7 @@ temp_val= malloc(sizeof(value)); temp_val->content.ptr= env->head; - temp_val->refcount= 1; + temp_val->refcount= 0; temp_val->type= list; env->head= temp_head; push_val(env, temp_val); @@ -1230,7 +1243,7 @@ int itemp, readlength= -1; static int depth= 0; - char *rest, *match; + char *match; size_t inlength; if(env->in_string==NULL) { @@ -1247,7 +1260,6 @@ inlength= strlen(env->in_string)+1; match= malloc(inlength); - rest= malloc(inlength); if(sscanf(env->in_string, blankform, &readlength)!=EOF && readlength != -1) { @@ -1275,12 +1287,13 @@ } else { free(env->free_string); env->in_string = env->free_string = NULL; - free(match); } if ( env->in_string != NULL) { env->in_string += readlength; } + free(match); + if(depth) return read(env); }