]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/zwgc/xrevstack.c
r4264@bucket (orig r254): kcr | 2008-01-20 22:11:44 -0500
[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
32 add_to_bottom(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
48 pull_to_top(x_gram *gram)
49 {
50 }
51
52 /*ARGSUSED*/
53 void
54 push_to_bottom(x_gram *gram)
55 {
56 }
57
58 void
59 delete_gram(x_gram *gram)
60 {
61    if (gram == bottom_gram) {
62       if (gram->above) {
63          bottom_gram = gram->above;
64          bottom_gram->below = NULL;
65       } else {
66          bottom_gram = NULL;
67       }
68    } else if (gram == unlinked) {
69       if (gram->above) {
70          unlinked = gram->above;
71          unlinked->below = NULL;
72       } else {
73          unlinked = NULL;
74       }
75    } else {
76       if (gram->above)
77         gram->above->below = gram->below;
78       gram->below->above = gram->above;     
79    }
80
81    /* fix up above & below pointers so that calling delete_gram
82       again is safe */
83    gram->below = gram;
84    gram->above = gram;
85 }
86
87 void
88 unlink_gram(x_gram *gram)
89 {
90    delete_gram(gram);
91
92    if (unlinked) {
93       unlinked->below = gram;
94       gram->below = NULL;
95       gram->above = unlinked;
96       unlinked = gram;
97    } else {
98       gram->above = NULL;
99       gram->below = NULL;
100       unlinked = gram;
101    }
102 }
103
104 #endif
105
106 #ifdef TRUEREVSTACK
107
108 #include "X_gram.h"
109 #include "zwgc.h"
110 #include <stdio.h>
111
112 x_gram *bottom_gram=NULL;
113 static x_gram *top_gram=NULL;
114
115 #ifdef DEBUG
116 void
117 print_gram_list(char *str)
118 {
119    x_gram *gram;
120    char buf[80];
121
122    if (zwgc_debug) {
123       printf("----- From function %s: Top of tree\n",str);
124       if (top_gram) 
125         if (top_gram->above) 
126           printf("Tree munged: something above top_gram\n");
127       for (gram=top_gram;gram;gram=gram->below) {
128          strncpy(buf,gram->text,63);
129          buf[63]='\0';
130          printf("wid %lx txt: %s\n",(long) gram->w,buf);
131       }
132       if (bottom_gram) 
133         if (bottom_gram->below) 
134           printf("Tree munged: something below bottom_gram\n");
135       printf("----- Bottom of tree\n");
136    }
137 }
138 #endif
139
140 void
141 pull_to_top(x_gram *gram)
142 {
143    if (gram==top_gram) {
144       /* already here */
145       return;
146    } else if (top_gram==NULL) {
147       /* no grams at all.  Make gram both top and bottom */
148       top_gram=gram;
149       bottom_gram=gram;
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;
156       top_gram=gram;
157    } else {
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;
163       gram->above=NULL;
164       top_gram=gram;
165    }
166 #ifdef DEBUG
167    print_gram_list("pull_to_top");
168 #endif
169 }
170
171 void
172 push_to_bottom(x_gram *gram)
173 {
174    if (gram==bottom_gram) {
175       /* already here */
176       return;
177    } else if (bottom_gram==NULL) {
178       /* no grams at all.  Make gram both top and bottom */
179       gram->above=NULL;
180       gram->below=NULL;
181       top_gram=gram;
182       bottom_gram=gram;
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;
189       bottom_gram=gram;
190    } else {
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;
196       gram->below=NULL;
197       bottom_gram=gram;
198    }
199 #ifdef DEBUG
200    print_gram_list("push_to_bottom");
201 #endif
202 }
203
204 void
205 unlink_gram(x_gram *gram)
206 {
207    if (top_gram==bottom_gram) {
208       /* the only gram in the stack */
209       top_gram=NULL;
210       bottom_gram=NULL;
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;
217    } else {
218       gram->above->below=gram->below;
219       gram->below->above=gram->above;
220    }
221 #ifdef DEBUG
222    print_gram_list("unlink_gram");
223 #endif
224 }
225
226 #ifdef notdef
227 void
228 add_to_top(x_gram *gram)
229 {
230    if (top_gram==NULL) {
231       gram->above=NULL;
232       gram->below=NULL;
233       top_gram=gram;
234       bottom_gram=gram;
235    } else {
236       top_gram->above=gram;
237       gram->above=NULL;
238       gram->below=top_gram;
239       top_gram=gram;
240    }
241 #ifdef DEBUG
242    print_gram_list("add_to_top");
243 #endif
244 }
245 #endif
246
247 void
248 add_to_bottom(x_gram *gram)
249 {
250    if (bottom_gram==NULL) {
251       gram->above=NULL;
252       gram->below=NULL;
253       top_gram=gram;
254       bottom_gram=gram;
255    } else {
256       bottom_gram->below=gram;
257       gram->above=bottom_gram;
258       gram->below=NULL;
259       bottom_gram=gram;
260    }
261 #ifdef DEBUG
262    print_gram_list("add_to_bottom");
263 #endif
264 }
265
266 #endif /* TRUEREVSTACK */
267
268 #endif /* X_DISPLAY_MISSING */
269