|
56 | 56 | #include <windows.h> |
57 | 57 | /* Prototype */ |
58 | 58 | static char * lt_dlerror (void); |
| 59 | +void init_call_stack_list (void); |
| 60 | +struct call_stack_list |
| 61 | + cob_create_call_stack_list (const char *); |
| 62 | +void cob_cancel_call_stack_list (struct call_stack_list *); |
59 | 63 |
|
60 | 64 | static HMODULE |
61 | 65 | lt_dlopen (const char *x) |
@@ -145,6 +149,12 @@ static struct call_hash *call_table = NULL; |
145 | 149 | static struct call_hash **call_table = NULL; |
146 | 150 | #endif |
147 | 151 |
|
| 152 | +/* |
| 153 | + * Call List |
| 154 | + */ |
| 155 | +struct call_stack_list *call_stack_list_head = NULL; |
| 156 | +struct call_stack_list *current_call_stack_list = NULL; |
| 157 | + |
148 | 158 | struct system_table { |
149 | 159 | const char *syst_name; |
150 | 160 | void *syst_call; |
@@ -686,3 +696,98 @@ coblongjmp (struct cobjmp_buf *jbuf) |
686 | 696 | cobjmp_primed = 0; |
687 | 697 | longjmp (jbuf->cbj_jmp_buf, 1); |
688 | 698 | } |
| 699 | + |
| 700 | +void |
| 701 | +init_call_stack_list() |
| 702 | +{ |
| 703 | + if (!call_stack_list_head) { |
| 704 | + call_stack_list_head = cob_malloc (sizeof (struct call_stack_list)); |
| 705 | + memset (call_stack_list_head, 0, sizeof (struct call_stack_list)); |
| 706 | + } |
| 707 | + current_call_stack_list = call_stack_list_head; |
| 708 | +} |
| 709 | + |
| 710 | +struct call_stack_list * |
| 711 | +cob_create_call_stack_list (char *name) |
| 712 | +{ |
| 713 | + struct call_stack_list *new_list = cob_malloc (sizeof (struct call_stack_list)); |
| 714 | + memset (new_list, 0, sizeof (struct call_stack_list)); |
| 715 | + new_list->parent = current_call_stack_list; |
| 716 | + new_list->name = cob_malloc (strlen(name) + 1); |
| 717 | + strcpy (new_list->name, name); |
| 718 | + current_call_stack_list = new_list; |
| 719 | + return new_list; |
| 720 | +} |
| 721 | + |
| 722 | +void |
| 723 | +cob_push_call_stack_list (char *name) |
| 724 | +{ |
| 725 | + if (!current_call_stack_list) { |
| 726 | + init_call_stack_list (); |
| 727 | + } |
| 728 | + |
| 729 | + struct call_stack_list *p = current_call_stack_list->children; |
| 730 | + if (!p) { |
| 731 | + current_call_stack_list->children = cob_create_call_stack_list (name); |
| 732 | + return; |
| 733 | + } |
| 734 | + if (strcmp (p->name, name) == 0) { |
| 735 | + current_call_stack_list = p; |
| 736 | + return; |
| 737 | + } |
| 738 | + if (!p->sister) { |
| 739 | + p->sister = cob_create_call_stack_list (name); |
| 740 | + return; |
| 741 | + } |
| 742 | + |
| 743 | + p = p->sister; |
| 744 | + for (;;) { |
| 745 | + if (strcmp (p->name, name) == 0) { |
| 746 | + current_call_stack_list = p; |
| 747 | + return; |
| 748 | + } |
| 749 | + if (p->sister == NULL) { |
| 750 | + break; |
| 751 | + } |
| 752 | + p = p->sister; |
| 753 | + } |
| 754 | + current_call_stack_list->sister = cob_create_call_stack_list (name); |
| 755 | + return; |
| 756 | +} |
| 757 | + |
| 758 | +void |
| 759 | +cob_pop_call_stack_list () |
| 760 | +{ |
| 761 | + current_call_stack_list = current_call_stack_list->parent; |
| 762 | +} |
| 763 | + |
| 764 | +void |
| 765 | +cob_cancel_call_stack_list (struct call_stack_list *p) |
| 766 | +{ |
| 767 | + if (!p) { |
| 768 | + /*No program*/ |
| 769 | + return; |
| 770 | + } |
| 771 | + static cob_field_attr a_2 = {33, 0, 0, 0, NULL}; |
| 772 | + cob_field f = {strlen (p->name), (unsigned char *) p->name, &a_2}; |
| 773 | + cob_field_cancel (&f); |
| 774 | + if (p->children) { |
| 775 | + cob_cancel_call_stack_list (p->children); |
| 776 | + } |
| 777 | + struct call_stack_list *s = p->sister; |
| 778 | + while (s != NULL) { |
| 779 | + cob_cancel_call_stack_list (s); |
| 780 | + s = s->sister; |
| 781 | + } |
| 782 | +} |
| 783 | + |
| 784 | +void |
| 785 | +cob_cancel_all() |
| 786 | +{ |
| 787 | + if (!current_call_stack_list) { |
| 788 | + cob_runtime_error ("Call to 'cob_cancel_all' current stack is NULL"); |
| 789 | + return; |
| 790 | + } |
| 791 | + cob_cancel_call_stack_list (current_call_stack_list->children); |
| 792 | + return; |
| 793 | +} |
0 commit comments