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>
7 * $Id: xrevstack.c 2336 2009-03-22 18:59:56Z kcr $
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: xrevstack.c 2336 2009-03-22 18:59:56Z kcr $";
20 #include <zephyr/mit-copyright.h>
22 #ifndef X_DISPLAY_MISSING
25 #include <zephyr/zephyr.h>
28 x_gram *bottom_gram = NULL;
29 x_gram *unlinked = NULL;
30 int reverse_stack = 0;
33 add_to_bottom(x_gram *gram)
36 bottom_gram->below = gram;
38 gram->above = bottom_gram;
49 pull_to_top(x_gram *gram)
55 push_to_bottom(x_gram *gram)
60 delete_gram(x_gram *gram)
62 if (gram == bottom_gram) {
64 bottom_gram = gram->above;
65 bottom_gram->below = NULL;
69 } else if (gram == unlinked) {
71 unlinked = gram->above;
72 unlinked->below = NULL;
78 gram->above->below = gram->below;
79 gram->below->above = gram->above;
82 /* fix up above & below pointers so that calling delete_gram
89 unlink_gram(x_gram *gram)
94 unlinked->below = gram;
96 gram->above = unlinked;
113 x_gram *bottom_gram=NULL;
114 static x_gram *top_gram=NULL;
118 print_gram_list(char *str)
124 printf("----- From function %s: Top of tree\n",str);
127 printf("Tree munged: something above top_gram\n");
128 for (gram=top_gram;gram;gram=gram->below) {
129 strncpy(buf,gram->text,63);
131 printf("wid %lx txt: %s\n",(long) gram->w,buf);
134 if (bottom_gram->below)
135 printf("Tree munged: something below bottom_gram\n");
136 printf("----- Bottom of tree\n");
142 pull_to_top(x_gram *gram)
144 if (gram==top_gram) {
147 } else if (top_gram==NULL) {
148 /* no grams at all. Make gram both top and bottom */
151 } else if (gram==bottom_gram) {
152 /* bottom gram is special case */
153 bottom_gram=bottom_gram->above;
154 bottom_gram->below=NULL;
155 top_gram->above=gram;
156 gram->below=top_gram;
159 /* normal case of a gram in the middle */
160 gram->above->below=gram->below;
161 gram->below->above=gram->above;
162 top_gram->above=gram;
163 gram->below=top_gram;
168 print_gram_list("pull_to_top");
173 push_to_bottom(x_gram *gram)
175 if (gram==bottom_gram) {
178 } else if (bottom_gram==NULL) {
179 /* no grams at all. Make gram both top and bottom */
184 } else if (gram==top_gram) {
185 /* top gram is special case */
186 top_gram=top_gram->below;
187 top_gram->above=NULL;
188 bottom_gram->below=gram;
189 gram->above=bottom_gram;
192 /* normal case of a gram in the middle */
193 gram->above->below=gram->below;
194 gram->below->above=gram->above;
195 bottom_gram->below=gram;
196 gram->above=bottom_gram;
201 print_gram_list("push_to_bottom");
206 unlink_gram(x_gram *gram)
208 if (top_gram==bottom_gram) {
209 /* the only gram in the stack */
212 } else if (gram==top_gram) {
213 top_gram=gram->below;
214 top_gram->above=NULL;
215 } else if (gram==bottom_gram) {
216 bottom_gram=gram->above;
217 bottom_gram->below=NULL;
219 gram->above->below=gram->below;
220 gram->below->above=gram->above;
223 print_gram_list("unlink_gram");
229 add_to_top(x_gram *gram)
231 if (top_gram==NULL) {
237 top_gram->above=gram;
239 gram->below=top_gram;
243 print_gram_list("add_to_top");
249 add_to_bottom(x_gram *gram)
251 if (bottom_gram==NULL) {
257 bottom_gram->below=gram;
258 gram->above=bottom_gram;
263 print_gram_list("add_to_bottom");
267 #endif /* TRUEREVSTACK */
269 #endif /* X_DISPLAY_MISSING */