]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/zwgc/xrevstack.c
1549956a3bfdfcb2b85c8e1f962d54de9fbb5567
[1ts-debian.git] / zephyr / zwgc / xrevstack.c
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
3  * client.
4  *
5  *      Created by:     Marc Horowitz <marc@athena.mit.edu>
6  *
7  *      $Id$
8  *
9  *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
10  *      For copying and distribution information, see the file
11  *      "mit-copyright.h".
12  */
13
14 #include <sysdep.h>
15
16 #if (!defined(lint) && !defined(SABER))
17 static const char rcsid_xrevstack_c[] = "$Id$";
18 #endif
19
20 #include <zephyr/mit-copyright.h>
21
22 #ifndef X_DISPLAY_MISSING
23
24 #ifndef TRUEREVSTACK
25 #include "X_gram.h"
26
27 x_gram *bottom_gram = NULL;
28 x_gram *unlinked = NULL;
29 int reverse_stack = 0;
30
31 void add_to_bottom(gram)
32      x_gram *gram;
33 {
34    if (bottom_gram) {
35       bottom_gram->below = gram;
36       gram->below = NULL;
37       gram->above = bottom_gram;
38       bottom_gram = gram;
39    } else {
40       gram->above = NULL;
41       gram->below = NULL;
42       bottom_gram = gram;
43    }
44 }
45
46 /*ARGSUSED*/
47 void pull_to_top(gram)
48      x_gram *gram;
49 {}
50
51 /*ARGSUSED*/
52 void push_to_bottom(gram)
53      x_gram *gram;
54 {}
55
56 void delete_gram(gram)
57      x_gram *gram;
58 {
59    if (gram == bottom_gram) {
60       if (gram->above) {
61          bottom_gram = gram->above;
62          bottom_gram->below = NULL;
63       } else {
64          bottom_gram = NULL;
65       }
66    } else if (gram == unlinked) {
67       if (gram->above) {
68          unlinked = gram->above;
69          unlinked->below = NULL;
70       } else {
71          unlinked = NULL;
72       }
73    } else {
74       if (gram->above)
75         gram->above->below = gram->below;
76       gram->below->above = gram->above;     
77    }
78
79    /* fix up above & below pointers so that calling delete_gram
80       again is safe */
81    gram->below = gram;
82    gram->above = gram;
83 }
84
85 void unlink_gram(gram)
86      x_gram *gram;
87 {
88    delete_gram(gram);
89
90    if (unlinked) {
91       unlinked->below = gram;
92       gram->below = NULL;
93       gram->above = unlinked;
94       unlinked = gram;
95    } else {
96       gram->above = NULL;
97       gram->below = NULL;
98       unlinked = gram;
99    }
100 }
101
102 #endif
103
104 #ifdef TRUEREVSTACK
105
106 #include "X_gram.h"
107 #include "zwgc.h"
108 #include <stdio.h>
109
110 x_gram *bottom_gram=NULL;
111 static x_gram *top_gram=NULL;
112
113 #ifdef DEBUG
114 void print_gram_list(str)
115 char *str;
116 {
117    x_gram *gram;
118    char buf[80];
119
120    if (zwgc_debug) {
121       printf("----- From function %s: Top of tree\n",str);
122       if (top_gram) 
123         if (top_gram->above) 
124           printf("Tree munged: something above top_gram\n");
125       for (gram=top_gram;gram;gram=gram->below) {
126          strncpy(buf,gram->text,63);
127          buf[63]='\0';
128          printf("wid %lx txt: %s\n",(long) gram->w,buf);
129       }
130       if (bottom_gram) 
131         if (bottom_gram->below) 
132           printf("Tree munged: something below bottom_gram\n");
133       printf("----- Bottom of tree\n");
134    }
135 }
136 #endif
137
138 void pull_to_top(gram)
139 x_gram *gram;
140 {
141    if (gram==top_gram) {
142       /* already here */
143       return;
144    } else if (top_gram==NULL) {
145       /* no grams at all.  Make gram both top and bottom */
146       top_gram=gram;
147       bottom_gram=gram;
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;
154       top_gram=gram;
155    } else {
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;
161       gram->above=NULL;
162       top_gram=gram;
163    }
164 #ifdef DEBUG
165    print_gram_list("pull_to_top");
166 #endif
167 }
168
169 void push_to_bottom(gram)
170 x_gram *gram;
171 {
172    if (gram==bottom_gram) {
173       /* already here */
174       return;
175    } else if (bottom_gram==NULL) {
176       /* no grams at all.  Make gram both top and bottom */
177       gram->above=NULL;
178       gram->below=NULL;
179       top_gram=gram;
180       bottom_gram=gram;
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;
187       bottom_gram=gram;
188    } else {
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;
194       gram->below=NULL;
195       bottom_gram=gram;
196    }
197 #ifdef DEBUG
198    print_gram_list("push_to_bottom");
199 #endif
200 }
201
202 void unlink_gram(gram)
203 x_gram *gram;
204 {
205    if (top_gram==bottom_gram) {
206       /* the only gram in the stack */
207       top_gram=NULL;
208       bottom_gram=NULL;
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;
215    } else {
216       gram->above->below=gram->below;
217       gram->below->above=gram->above;
218    }
219 #ifdef DEBUG
220    print_gram_list("unlink_gram");
221 #endif
222 }
223
224 #ifdef notdef
225 void add_to_top(gram)
226 x_gram *gram;
227 {
228    if (top_gram==NULL) {
229       gram->above=NULL;
230       gram->below=NULL;
231       top_gram=gram;
232       bottom_gram=gram;
233    } else {
234       top_gram->above=gram;
235       gram->above=NULL;
236       gram->below=top_gram;
237       top_gram=gram;
238    }
239 #ifdef DEBUG
240    print_gram_list("add_to_top");
241 #endif
242 }
243 #endif
244
245 void add_to_bottom(gram)
246 x_gram *gram;
247 {
248    if (bottom_gram==NULL) {
249       gram->above=NULL;
250       gram->below=NULL;
251       top_gram=gram;
252       bottom_gram=gram;
253    } else {
254       bottom_gram->below=gram;
255       gram->above=bottom_gram;
256       gram->below=NULL;
257       bottom_gram=gram;
258    }
259 #ifdef DEBUG
260    print_gram_list("add_to_bottom");
261 #endif
262 }
263
264 #endif /* TRUEREVSTACK */
265
266 #endif /* X_DISPLAY_MISSING */
267