--- stack/stack.c 2002/02/14 12:01:58 1.79 +++ stack/stack.c 2002/02/14 12:20:09 1.80 @@ -340,14 +340,17 @@ } /* Prints the top element of the stack. */ -void print_h(stackitem *stack_head) +void print_h(stackitem *stack_head, int noquote) { switch(stack_head->item->type) { case integer: printf("%d", stack_head->item->content.val); break; case string: - printf("%s", (char*)stack_head->item->content.ptr); + if(noquote) + printf("%s", (char*)stack_head->item->content.ptr); + else + printf("\"%s\"", (char*)stack_head->item->content.ptr); break; case symb: printf("%s", ((symbol *)(stack_head->item->content.ptr))->id); @@ -360,7 +363,7 @@ stack_head=(stackitem *)(stack_head->item->content.ptr); printf("[ "); while(stack_head != NULL) { - print_h(stack_head); + print_h(stack_head, noquote); printf(" "); stack_head=stack_head->next; } @@ -375,7 +378,8 @@ env->err=1; return; } - print_h(env->head); + print_h(env->head, 0); + nl(); } /* Prints the top element of the stack and then discards it. */ @@ -386,13 +390,30 @@ toss(env); } +extern void princ_(environment *env) { + if(env->head==NULL) { + printerr("Too Few Arguments"); + env->err=1; + return; + } + print_h(env->head, 1); +} + +/* Prints the top element of the stack and then discards it. */ +extern void princ(environment *env) +{ + princ_(env); + if(env->err) return; + toss(env); +} + /* Only to be called by function printstack. */ void print_st(stackitem *stack_head, long counter) { if(stack_head->next != NULL) print_st(stack_head->next, counter+1); printf("%ld: ", counter); - print_h(stack_head); + print_h(stack_head, 0); nl(); } @@ -400,10 +421,10 @@ extern void printstack(environment *env) { if(env->head == NULL) { + printf("Stack Empty\n"); return; } print_st(env->head, 1); - nl(); } /* Swap the two top elements on the stack. */ @@ -476,14 +497,14 @@ value* temp_val; stackitem* iterator; + eval_start: + if(env->head==NULL) { printerr("Too Few Arguments"); env->err=1; return; } - eval_start: - switch(env->head->item->type) { /* if it's a symbol */ case symb: @@ -731,8 +752,8 @@ for(i= 0; isymbols[i]!= NULL) { forget_sym(&(env->symbols[i])); - env->symbols[i]= NULL; } + env->symbols[i]= NULL; } exit(EXIT_SUCCESS); } @@ -811,8 +832,11 @@ init_env(&myenv); while(1) { - if(myenv.in_string==NULL) + if(myenv.in_string==NULL) { + nl(); printstack(&myenv); + printf("> "); + } read(&myenv); if(myenv.err) { printf("(error %d) ", myenv.err); @@ -1210,6 +1234,9 @@ size_t inlength; if(env->in_string==NULL) { + if(depth > 0) { + printf("]> "); + } readline(env); if(env->err) return; env->in_string= malloc(strlen(env->head->item->content.ptr)+1);