307 |
printf("#<function %p>", (funcp)(stack_head->item->content.ptr)); |
printf("#<function %p>", (funcp)(stack_head->item->content.ptr)); |
308 |
break; |
break; |
309 |
case list: |
case list: |
310 |
printf("#<list %p>", (funcp)(stack_head->item->content.ptr)); |
/* A list is just a stack, so make stack_head point to it */ |
311 |
|
stack_head=(stackitem *)(stack_head->item->content.ptr); |
312 |
|
printf("[ "); |
313 |
|
while(stack_head != NULL) { |
314 |
|
print_h(stack_head); |
315 |
|
printf(" "); |
316 |
|
stack_head=stack_head->next; |
317 |
|
} |
318 |
|
printf("]"); |
319 |
break; |
break; |
320 |
default: |
default: |
321 |
printf("#<unknown %p>", (funcp)(stack_head->item->content.ptr)); |
printf("#<unknown %p>", (stack_head->item->content.ptr)); |
322 |
break; |
break; |
323 |
} |
} |
324 |
} |
} |
454 |
} |
} |
455 |
} |
} |
456 |
|
|
457 |
|
/* Reverse a list */ |
458 |
|
extern void rev(environment *env){ |
459 |
|
stackitem *old_head, *new_head, *item; |
460 |
|
|
461 |
|
if((env->head)==NULL) { |
462 |
|
printerr("Too Few Arguments"); |
463 |
|
env->err=1; |
464 |
|
return; |
465 |
|
} |
466 |
|
|
467 |
|
if(env->head->item->type!=list) { |
468 |
|
printerr("Bad Argument Type"); |
469 |
|
env->err=2; |
470 |
|
return; |
471 |
|
} |
472 |
|
|
473 |
|
old_head=(stackitem *)(env->head->item->content.ptr); |
474 |
|
new_head=NULL; |
475 |
|
while(old_head != NULL){ |
476 |
|
item=old_head; |
477 |
|
old_head=old_head->next; |
478 |
|
item->next=new_head; |
479 |
|
new_head=item; |
480 |
|
} |
481 |
|
env->head->item->content.ptr=new_head; |
482 |
|
} |
483 |
|
|
484 |
/* Make a list. */ |
/* Make a list. */ |
485 |
extern void pack(environment *env) |
extern void pack(environment *env) |
486 |
{ |
{ |
521 |
temp->item= pack; |
temp->item= pack; |
522 |
|
|
523 |
push(&(env->head), temp); |
push(&(env->head), temp); |
524 |
|
rev(env); |
525 |
} |
} |
526 |
|
|
527 |
/* Parse input. */ |
/* Parse input. */ |
537 |
rest= malloc(inlength); |
rest= malloc(inlength); |
538 |
|
|
539 |
do { |
do { |
540 |
|
/* If comment */ |
541 |
|
if((convert= sscanf(in_line, "#%[^\n\r]", rest))) { |
542 |
|
free(temp); free(rest); |
543 |
|
return; |
544 |
|
} |
545 |
|
|
546 |
/* If string */ |
/* If string */ |
547 |
if((convert= sscanf(in_line, "\"%[^\"\n\r]\" %[^\n\r]", temp, rest))) { |
if((convert= sscanf(in_line, "\"%[^\"\n\r]\" %[^\n\r]", temp, rest))) { |
548 |
push_cstring(&(env->head), temp); |
push_cstring(&(env->head), temp); |
621 |
return; |
return; |
622 |
} |
} |
623 |
|
|
624 |
|
rev(env); |
625 |
|
|
626 |
|
if(env->err) |
627 |
|
return; |
628 |
|
|
629 |
/* The first list element is the new stack head */ |
/* The first list element is the new stack head */ |
630 |
new_head= temp= env->head->item->content.ptr; |
new_head= temp= env->head->item->content.ptr; |
631 |
|
|
808 |
} |
} |
809 |
printf("okidok\n "); |
printf("okidok\n "); |
810 |
} |
} |
811 |
|
quit(&myenv); |
812 |
exit(EXIT_SUCCESS); |
return EXIT_FAILURE; |
813 |
} |
} |