1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It is one of the source files comprising zwgc, the Zephyr WindowGram
5 * Created by: Marc Horowitz <marc@athena.mit.edu>
9 * Copyright (c) 1989 by the Massachusetts Institute of Technology.
10 * For copying and distribution information, see the file
16 #if (!defined(lint) && !defined(SABER))
17 static const char rcsid_xrevstack_c[] = "$Id$";
20 #include <zephyr/mit-copyright.h>
22 #ifndef X_DISPLAY_MISSING
27 x_gram *bottom_gram = NULL;
28 x_gram *unlinked = NULL;
29 int reverse_stack = 0;
31 void add_to_bottom(gram)
35 bottom_gram->below = gram;
37 gram->above = bottom_gram;
47 void pull_to_top(gram)
52 void push_to_bottom(gram)
56 void delete_gram(gram)
59 if (gram == bottom_gram) {
61 bottom_gram = gram->above;
62 bottom_gram->below = NULL;
66 } else if (gram == unlinked) {
68 unlinked = gram->above;
69 unlinked->below = NULL;
75 gram->above->below = gram->below;
76 gram->below->above = gram->above;
79 /* fix up above & below pointers so that calling delete_gram
85 void unlink_gram(gram)
91 unlinked->below = gram;
93 gram->above = unlinked;
110 x_gram *bottom_gram=NULL;
111 static x_gram *top_gram=NULL;
114 void print_gram_list(str)
121 printf("----- From function %s: Top of tree\n",str);
124 printf("Tree munged: something above top_gram\n");
125 for (gram=top_gram;gram;gram=gram->below) {
126 strncpy(buf,gram->text,63);
128 printf("wid %lx txt: %s\n",(long) gram->w,buf);
131 if (bottom_gram->below)
132 printf("Tree munged: something below bottom_gram\n");
133 printf("----- Bottom of tree\n");
138 void pull_to_top(gram)
141 if (gram==top_gram) {
144 } else if (top_gram==NULL) {
145 /* no grams at all. Make gram both top and bottom */
148 } else if (gram==bottom_gram) {
149 /* bottom gram is special case */
150 bottom_gram=bottom_gram->above;
151 bottom_gram->below=NULL;
152 top_gram->above=gram;
153 gram->below=top_gram;
156 /* normal case of a gram in the middle */
157 gram->above->below=gram->below;
158 gram->below->above=gram->above;
159 top_gram->above=gram;
160 gram->below=top_gram;
165 print_gram_list("pull_to_top");
169 void push_to_bottom(gram)
172 if (gram==bottom_gram) {
175 } else if (bottom_gram==NULL) {
176 /* no grams at all. Make gram both top and bottom */
181 } else if (gram==top_gram) {
182 /* top gram is special case */
183 top_gram=top_gram->below;
184 top_gram->above=NULL;
185 bottom_gram->below=gram;
186 gram->above=bottom_gram;
189 /* normal case of a gram in the middle */
190 gram->above->below=gram->below;
191 gram->below->above=gram->above;
192 bottom_gram->below=gram;
193 gram->above=bottom_gram;
198 print_gram_list("push_to_bottom");
202 void unlink_gram(gram)
205 if (top_gram==bottom_gram) {
206 /* the only gram in the stack */
209 } else if (gram==top_gram) {
210 top_gram=gram->below;
211 top_gram->above=NULL;
212 } else if (gram==bottom_gram) {
213 bottom_gram=gram->above;
214 bottom_gram->below=NULL;
216 gram->above->below=gram->below;
217 gram->below->above=gram->above;
220 print_gram_list("unlink_gram");
225 void add_to_top(gram)
228 if (top_gram==NULL) {
234 top_gram->above=gram;
236 gram->below=top_gram;
240 print_gram_list("add_to_top");
245 void add_to_bottom(gram)
248 if (bottom_gram==NULL) {
254 bottom_gram->below=gram;
255 gram->above=bottom_gram;
260 print_gram_list("add_to_bottom");
264 #endif /* TRUEREVSTACK */
266 #endif /* X_DISPLAY_MISSING */