--- stack/stack.c 2002/02/14 19:49:48 1.82 +++ 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 @@ -111,7 +113,7 @@ free(val->content.ptr); break; } - free(val); /* Free the actual list value */ + free(val); /* Free the actual value structure */ } } @@ -177,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); } @@ -190,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); } @@ -609,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); @@ -738,6 +740,7 @@ extern void clear(environment *); void forget_sym(symbol **); +extern void words(environment *); /* Quit stack. */ extern void quit(environment *env) @@ -745,6 +748,9 @@ long i; clear(env); + + words(env); + if (env->err) return; for(i= 0; isymbols[i]!= NULL) { @@ -752,6 +758,14 @@ } env->symbols[i]= NULL; } + + words(env); + + if(env->free_string!=NULL) + free(env->free_string); + + muntrace(); + exit(EXIT_SUCCESS); } @@ -826,6 +840,8 @@ { environment myenv; + mtrace(); + init_env(&myenv); while(1) { @@ -1201,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); @@ -1227,7 +1243,7 @@ int itemp, readlength= -1; static int depth= 0; - char *rest, *match; + char *match; size_t inlength; if(env->in_string==NULL) { @@ -1244,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) { @@ -1272,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); }