diff options
author | Marc Horowitz <marc@mit.edu> | 1989-11-01 20:02:01 +0000 |
---|---|---|
committer | Marc Horowitz <marc@mit.edu> | 1989-11-01 20:02:01 +0000 |
commit | d13d8a046838ce3d0e2643bb5b49f2ff77d679ca (patch) | |
tree | 05737bc11e3461836ce817939b9129ed58545ac7 /zwgc/xrevstack.c | |
parent | fd994e4099ad66fb3bf26cd636ca5d5cae72da68 (diff) |
Initial revision
Diffstat (limited to 'zwgc/xrevstack.c')
-rw-r--r-- | zwgc/xrevstack.c | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/zwgc/xrevstack.c b/zwgc/xrevstack.c new file mode 100644 index 0000000..fb196fc --- /dev/null +++ b/zwgc/xrevstack.c @@ -0,0 +1,158 @@ +#include "X_gram.h" +#include "zwgc.h" +#include <stdio.h> + +x_gram *bottom_gram=NULL; +static x_gram *top_gram=NULL; + +#ifdef DEBUG +void print_gram_list(str) +char *str; +{ + x_gram *gram; + char buf[80]; + + if (zwgc_debug) { + printf("----- From function %s: Top of tree\n",str); + if (top_gram) + if (top_gram->above) + printf("Tree munged: something above top_gram\n"); + for (gram=top_gram;gram;gram=gram->below) { + strncpy(buf,gram->text,63); + buf[63]='\0'; + printf("wid %lx txt: %s\n",(long) gram->w,buf); + } + if (bottom_gram) + if (bottom_gram->below) + printf("Tree munged: something below bottom_gram\n"); + printf("----- Bottom of tree\n"); + } +} +#endif + +void pull_to_top(gram) +x_gram *gram; +{ + if (gram==top_gram) { + /* already here */ + return; + } else if (top_gram==NULL) { + /* no grams at all. Make gram both top and bottom */ + top_gram=gram; + bottom_gram=gram; + } else if (gram==bottom_gram) { + /* bottom gram is special case */ + bottom_gram=bottom_gram->above; + bottom_gram->below=NULL; + top_gram->above=gram; + gram->below=top_gram; + top_gram=gram; + } else { + /* normal case of a gram in the middle */ + gram->above->below=gram->below; + gram->below->above=gram->above; + top_gram->above=gram; + gram->below=top_gram; + gram->above=NULL; + top_gram=gram; + } +#ifdef DEBUG + print_gram_list("pull_to_top"); +#endif +} + +void push_to_bottom(gram) +x_gram *gram; +{ + if (gram==bottom_gram) { + /* already here */ + return; + } else if (bottom_gram==NULL) { + /* no grams at all. Make gram both top and bottom */ + gram->above=NULL; + gram->below=NULL; + top_gram=gram; + bottom_gram=gram; + } else if (gram==top_gram) { + /* top gram is special case */ + top_gram=top_gram->below; + top_gram->above=NULL; + bottom_gram->below=gram; + gram->above=bottom_gram; + bottom_gram=gram; + } else { + /* normal case of a gram in the middle */ + gram->above->below=gram->below; + gram->below->above=gram->above; + bottom_gram->below=gram; + gram->above=bottom_gram; + gram->below=NULL; + bottom_gram=gram; + } +#ifdef DEBUG + print_gram_list("push_to_bottom"); +#endif +} + +void unlink_gram(gram) +x_gram *gram; +{ + if (top_gram==bottom_gram) { + /* the only gram in the stack */ + top_gram=NULL; + bottom_gram=NULL; + } else if (gram==top_gram) { + top_gram=gram->below; + top_gram->above=NULL; + } else if (gram==bottom_gram) { + bottom_gram=gram->above; + bottom_gram->below=NULL; + } else { + gram->above->below=gram->below; + gram->below->above=gram->above; + } +#ifdef DEBUG + print_gram_list("unlink_gram"); +#endif +} + +#ifdef notdef +void add_to_top(gram) +x_gram *gram; +{ + if (top_gram==NULL) { + gram->above=NULL; + gram->below=NULL; + top_gram=gram; + bottom_gram=gram; + } else { + top_gram->above=gram; + gram->above=NULL; + gram->below=top_gram; + top_gram=gram; + } +#ifdef DEBUG + print_gram_list("add_to_top"); +#endif +} +#endif + +void add_to_bottom(gram) +x_gram *gram; +{ + if (bottom_gram==NULL) { + gram->above=NULL; + gram->below=NULL; + top_gram=gram; + bottom_gram=gram; + } else { + bottom_gram->below=gram; + gram->above=bottom_gram; + gram->below=NULL; + bottom_gram=gram; + } +#ifdef DEBUG + print_gram_list("add_to_bottom"); +#endif +} + |