--- stack/symbols.c 2003/08/04 14:13:16 1.2 +++ stack/symbols.c 2003/08/08 14:20:49 1.5 @@ -1,5 +1,5 @@ -#include #include "stack.h" +#include "messages.h" /* Print newline. */ extern void nl(environment *env) @@ -294,7 +294,7 @@ } /* long names are a pain */ - sym= CAR(env->head)->content.ptr; + sym= CAR(env->head)->content.sym; /* Bind the symbol to the value */ sym->val= CAR(CDR(env->head)); @@ -305,8 +305,7 @@ /* Clear stack */ extern void clear(environment *env) { - while(env->head->type != empty) - toss(env); + env->head= new_val(env); } /* Forgets a symbol (remove it from the hash table) */ @@ -360,11 +359,11 @@ protect(a_val); protect(b_val); toss(env); if(env->err) return; toss(env); if(env->err) return; - len= strlen(a_val->content.ptr)+strlen(b_val->content.ptr)+1; + len= strlen(a_val->content.string)+strlen(b_val->content.string)+1; new_string= malloc(len); assert(new_string != NULL); - strcpy(new_string, b_val->content.ptr); - strcat(new_string, a_val->content.ptr); + strcpy(new_string, b_val->content.string); + strcat(new_string, a_val->content.string); push_cstring(env, new_string); unprotect(a_val); unprotect(b_val); free(new_string); @@ -1439,3 +1438,152 @@ toss(env); } + +extern void mangle(environment *env) +{ + char *new_string; + + if(env->head->type==empty) { + printerr("Too Few Arguments"); + env->err= 1; + return; + } + + if(CAR(env->head)->type!=string) { + printerr("Bad Argument Type"); + env->err= 2; + return; + } + + new_string= mangle_str(CAR(env->head)->content.string); + + toss(env); + if(env->err) return; + + push_cstring(env, new_string); +} + +/* "fork" */ +extern void sx_666f726b(environment *env) +{ + push_int(env, fork()); +} + +/* "waitpid" */ +extern void sx_77616974706964(environment *env) +{ + + if(env->head->type==empty) { + printerr("Too Few Arguments"); + env->err= 1; + return; + } + + if(CAR(env->head)->type!=integer) { + printerr("Bad Argument Type"); + env->err= 2; + return; + } + + push_int(env, waitpid(CAR(env->head)->content.i, NULL, 0)); + swap(env); toss(env); +} + + +/* Discard the top element of the stack. */ +extern void toss(environment *env) +{ + if(env->head->type==empty) { + printerr("Too Few Arguments"); + env->err= 1; + return; + } + + env->head= CDR(env->head); /* Remove the top stack item */ +} + + +/* Quit stack. */ +extern void quit(environment *env) +{ + int i; + + env->head= new_val(env); + + if (env->err) return; + for(i= 0; isymbols[i]!= NULL) { + forget_sym(&(env->symbols[i])); + } + env->symbols[i]= NULL; + } + + env->gc_limit= 0; + gc_maybe(env); + + words(env); + + if(env->free_string!=NULL) + free(env->free_string); + +#ifdef __linux__ + muntrace(); +#endif + + exit(EXIT_SUCCESS); +} + + +/* List all defined words */ +extern void words(environment *env) +{ + symbol *temp; + int i; + + for(i= 0; isymbols[i]; + while(temp!=NULL) { +#ifdef DEBUG + if (temp->val != NULL && temp->val->gc.flag.protect) + printf("(protected) "); +#endif /* DEBUG */ + printf("%s ", temp->id); + temp= temp->next; + } + } +} + + +/* Only to be called by itself function printstack. */ +void print_st(environment *env, value *stack_head, long counter) +{ + if(CDR(stack_head)->type != empty) + print_st(env, CDR(stack_head), counter+1); + printf("%ld: ", counter); + print_val(env, CAR(stack_head), 0, NULL, stdout); + printf("\n"); +} + + +/* Prints the stack. */ +extern void printstack(environment *env) +{ + if(env->head->type == empty) { + printf("Stack Empty\n"); + return; + } + + print_st(env, env->head, 1); +} + + +extern void copying(environment *env) +{ + printf(license_message); +} + + +extern void warranty(environment *env) +{ + printf(warranty_message); +}