1 /*
2 Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8 
9     - Redistributions of source code must retain the above copyright
10       notice, this list of conditions and the following disclaimer.
11 
12     - Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions and the following disclaimer in
14       the documentation and/or other materials provided with the
15       distribution.
16 
17     - Neither the name of The Numerical ALgorithms Group Ltd. nor the
18       names of its contributors may be used to endorse or promote products
19       derived from this software without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
34 #include "fricas_c_macros.h"
35 #define _ITEM_C
36 #include "debug.h"
37 #include "extent.h"
38 
39 #include "all_hyper_proto.H1"
40 
41 /*
42  * Here are structures needed for manipulating the item stack
43  */
44 ItemStack *gTopOfItemStack = NULL;
45 
46 
47 void
push_item_stack(void)48 push_item_stack(void)
49 {
50     ItemStack *is = (ItemStack *) halloc(sizeof(ItemStack), "Item stack");
51 
52     is->indent = indent;
53     is->item_indent = item_indent;
54     is->next = gTopOfItemStack;
55     is->in_item = gInItem;
56     gTopOfItemStack = is;
57     return;
58 }
59 void
clear_item_stack(void)60 clear_item_stack(void)
61 {
62     ItemStack *is = gTopOfItemStack, *chuck;
63 
64     while (is != NULL) {
65         chuck = is;
66         is = is->next;
67         free(chuck);
68     }
69     return;
70 }
71 void
pop_item_stack(void)72 pop_item_stack(void)
73 {
74     ItemStack *chuck;
75 
76     if (gTopOfItemStack == NULL) {
77         fprintf(stderr, "Tried to pop an empty item stack\n");
78         return;
79     }
80     chuck = gTopOfItemStack;
81     gTopOfItemStack = gTopOfItemStack->next;
82     indent = chuck->indent;
83     item_indent = chuck->item_indent;
84     gInItem = chuck->in_item;
85     free(chuck);
86 }
87 
88 ItemStack *
copy_item_stack(void)89 copy_item_stack(void)
90 {
91     ItemStack *new = NULL;
92     ItemStack *prev = NULL;
93     ItemStack *trace = gTopOfItemStack;
94     ItemStack *first = NULL;
95 
96     while (trace) {
97         new = (ItemStack *) halloc(sizeof(ItemStack), "Item stack");
98         new->indent = trace->indent;
99         new->item_indent = trace->item_indent;
100         new->in_item = gInItem;
101         if (!first)
102             first = new;
103         else
104             prev->next = new;
105         prev = new;
106         trace = trace->next;
107     }
108     if (new)
109         new->next = NULL;
110     return first;
111 }
112 
113 void
free_item_stack(ItemStack * is)114 free_item_stack(ItemStack *is)
115 {
116     ItemStack *junk = NULL;
117     ItemStack *trace = is;
118 
119     while (trace) {
120         junk = trace;
121         trace = trace->next;
122         free(junk);
123     }
124 }
125