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;
32 add_to_bottom(x_gram *gram)
35 bottom_gram->below = gram;
37 gram->above = bottom_gram;
48 pull_to_top(x_gram *gram)
54 push_to_bottom(x_gram *gram)
59 delete_gram(x_gram *gram)
61 if (gram == bottom_gram) {
63 bottom_gram = gram->above;
64 bottom_gram->below = NULL;
68 } else if (gram == unlinked) {
70 unlinked = gram->above;
71 unlinked->below = NULL;
77 gram->above->below = gram->below;
78 gram->below->above = gram->above;
81 /* fix up above & below pointers so that calling delete_gram
88 unlink_gram(x_gram *gram)
93 unlinked->below = gram;
95 gram->above = unlinked;
112 x_gram *bottom_gram=NULL;
113 static x_gram *top_gram=NULL;
117 print_gram_list(char *str)
123 printf("----- From function %s: Top of tree\n",str);
126 printf("Tree munged: something above top_gram\n");
127 for (gram=top_gram;gram;gram=gram->below) {
128 strncpy(buf,gram->text,63);
130 printf("wid %lx txt: %s\n",(long) gram->w,buf);
133 if (bottom_gram->below)
134 printf("Tree munged: something below bottom_gram\n");
135 printf("----- Bottom of tree\n");
141 pull_to_top(x_gram *gram)
143 if (gram==top_gram) {
146 } else if (top_gram==NULL) {
147 /* no grams at all. Make gram both top and bottom */
150 } else if (gram==bottom_gram) {
151 /* bottom gram is special case */
152 bottom_gram=bottom_gram->above;
153 bottom_gram->below=NULL;
154 top_gram->above=gram;
155 gram->below=top_gram;
158 /* normal case of a gram in the middle */
159 gram->above->below=gram->below;
160 gram->below->above=gram->above;
161 top_gram->above=gram;
162 gram->below=top_gram;
167 print_gram_list("pull_to_top");
172 push_to_bottom(x_gram *gram)
174 if (gram==bottom_gram) {
177 } else if (bottom_gram==NULL) {
178 /* no grams at all. Make gram both top and bottom */
183 } else if (gram==top_gram) {
184 /* top gram is special case */
185 top_gram=top_gram->below;
186 top_gram->above=NULL;
187 bottom_gram->below=gram;
188 gram->above=bottom_gram;
191 /* normal case of a gram in the middle */
192 gram->above->below=gram->below;
193 gram->below->above=gram->above;
194 bottom_gram->below=gram;
195 gram->above=bottom_gram;
200 print_gram_list("push_to_bottom");
205 unlink_gram(x_gram *gram)
207 if (top_gram==bottom_gram) {
208 /* the only gram in the stack */
211 } else if (gram==top_gram) {
212 top_gram=gram->below;
213 top_gram->above=NULL;
214 } else if (gram==bottom_gram) {
215 bottom_gram=gram->above;
216 bottom_gram->below=NULL;
218 gram->above->below=gram->below;
219 gram->below->above=gram->above;
222 print_gram_list("unlink_gram");
228 add_to_top(x_gram *gram)
230 if (top_gram==NULL) {
236 top_gram->above=gram;
238 gram->below=top_gram;
242 print_gram_list("add_to_top");
248 add_to_bottom(x_gram *gram)
250 if (bottom_gram==NULL) {
256 bottom_gram->below=gram;
257 gram->above=bottom_gram;
262 print_gram_list("add_to_bottom");
266 #endif /* TRUEREVSTACK */
268 #endif /* X_DISPLAY_MISSING */