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