diff options
author | Thomas Roessler <roessler@does-not-exist.org> | 1998-09-24 21:16:22 +0000 |
---|---|---|
committer | Thomas Roessler <roessler@does-not-exist.org> | 1998-09-24 21:16:22 +0000 |
commit | 0294b7da5015618b22f7a4c4a5b4557f8092fcc6 (patch) | |
tree | 1b5fa6ecbb598897f67896e94a54414b226c41eb /pager.c | |
parent | 45eb8193b7c840d5560c9d6f49ad7dc1454051c2 (diff) |
Undoing Livius quote-levels patch for now.
Diffstat (limited to 'pager.c')
-rw-r--r-- | pager.c | 146 |
1 files changed, 44 insertions, 102 deletions
@@ -83,7 +83,6 @@ struct q_class_t { int length; - int index; int color; char *prefix; struct q_class_t *next, *prev; @@ -311,51 +310,6 @@ append_line (struct line_t *lineInfo, int n, int cnt) } static void -new_class_color (struct q_class_t *class, int *q_level) -{ - class->index = (*q_level)++; - class->color = ColorQuote[class->index % ColorQuoteUsed]; -} - -static void -shift_class_colors (struct q_class_t *QuoteList, struct q_class_t *new_class, - int index, int *q_level) -{ - struct q_class_t * q_list; - - q_list = QuoteList; - new_class->index = -1; - - while (q_list) - { - if (q_list->index >= index) - { - q_list->index++; - q_list->color = ColorQuote[q_list->index % ColorQuoteUsed]; - } - if (q_list->down) - q_list = q_list->down; - else if (q_list->next) - q_list = q_list->next; - else - { - while (!q_list->next) - { - q_list = q_list->up; - if (q_list == NULL) - break; - } - if (q_list) - q_list = q_list->next; - } - } - - new_class->index = index; - new_class->color = ColorQuote[index % ColorQuoteUsed]; - (*q_level)++; -} - -static void cleanup_quote (struct q_class_t **QuoteList) { struct q_class_t *ptr; @@ -378,10 +332,9 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, int length, int *force_redraw, int *q_level) { struct q_class_t *q_list = *QuoteList; - struct q_class_t *class = NULL, *tmp = NULL, *ptr, *save; + struct q_class_t *class = NULL, *tmp = NULL, *ptr; char *tail_qptr; int offset, tail_lng; - int index = -1; /* Did I mention how much I like emulating Lisp in C? */ @@ -390,14 +343,13 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, { if (length <= q_list->length) { - /* case 1: check the top level nodes */ - if (strncmp (qptr, q_list->prefix, length) == 0) { + /* same prefix: return the current class */ if (length == q_list->length) - return q_list; /* same prefix: return the current class */ + return q_list; - /* found shorter prefix */ + /* found shorter common prefix */ if (tmp == NULL) { /* add a node above q_list */ @@ -405,6 +357,11 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, tmp->prefix = (char *) safe_calloc (1, length + 1); strncpy (tmp->prefix, qptr, length); tmp->length = length; + if (*q_level >= ColorQuoteUsed) + *q_level = 1; + else + (*q_level)++; + tmp->color = ColorQuote[(*q_level) - 1]; /* replace q_list by tmp in the top level list */ if (q_list->next) @@ -422,7 +379,7 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, tmp->down = q_list; q_list->up = tmp; - /* q_list has no siblings for now */ + /* q_list has no siblings */ q_list->next = NULL; q_list->prev = NULL; @@ -430,23 +387,16 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, if (q_list == *QuoteList) *QuoteList = tmp; - index = q_list->index; - /* tmp should be the return class too */ class = tmp; - /* next class to test; if tmp is a shorter prefix for another - * node, that node can only be in the top level list, so don't - * go down after this point - */ + /* next class to test */ q_list = tmp->next; } else { - /* found another branch for which tmp is a shorter prefix */ - /* save the next sibling for later */ - save = q_list->next; + ptr = q_list->next; /* unlink q_list from the top level list */ if (q_list->next) @@ -455,22 +405,17 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, q_list->prev->next = q_list->next; /* at this point, we have a tmp->down; link q_list to it */ - ptr = tmp->down; - /* sibling order is important here, q_list should be linked last */ - while (ptr->next) - ptr = ptr->next; - ptr->next = q_list; - q_list->next = NULL; - q_list->prev = ptr; + q_list->next = tmp->down; + tmp->down->prev = q_list; + q_list->prev = NULL; + tmp->down = q_list; q_list->up = tmp; - index = q_list->index; - - /* next class to test; as above, we shouldn't go down */ - q_list = save; + /* next class to test */ + q_list = ptr; } - /* we found a shorter prefix, so certain quotes have changed classes */ + /* in both cases q_list points now to the next top-level node */ *force_redraw = 1; continue; } @@ -483,13 +428,10 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, } else { - /* case 2: try subclassing the current top level node */ - - /* tmp != NULL means we already found a shorter prefix at case 1 */ + /* longer than the top level prefix: try subclassing it */ if (tmp == NULL && strncmp (qptr, q_list->prefix, q_list->length) == 0) { - /* ok, it's a subclass somewhere on this branch */ - + /* ok, we may link it as a subclass */ ptr = q_list; offset = q_list->length; @@ -516,6 +458,11 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, tmp->prefix = (char *) safe_calloc (1, length + 1); strncpy (tmp->prefix, qptr, length); tmp->length = length; + if (*q_level >= ColorQuoteUsed) + *q_level = 1; + else + (*q_level)++; + tmp->color = ColorQuote[(*q_level) - 1]; /* replace q_list by tmp */ if (q_list->next) @@ -540,8 +487,6 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, q_list->next = NULL; q_list->prev = NULL; - index = q_list->index; - /* tmp should be the return class too */ class = tmp; @@ -550,10 +495,8 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, } else { - /* found another branch for which tmp is a shorter prefix */ - /* save the next sibling for later */ - save = q_list->next; + ptr = q_list->next; /* unlink q_list from the top level list */ if (q_list->next) @@ -562,21 +505,16 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, q_list->prev->next = q_list->next; /* at this point, we have a tmp->down; link q_list to it */ - ptr = tmp->down; - while (ptr->next) - ptr = ptr->next; - ptr->next = q_list; - q_list->next = NULL; - q_list->prev = ptr; + q_list->next = tmp->down; + tmp->down->prev = q_list; + q_list->prev = NULL; + tmp->down = q_list; q_list->up = tmp; - index = q_list->index; - /* next class to test */ - q_list = save; + q_list = ptr; } - /* we found a shorter prefix, so we need a redraw */ *force_redraw = 1; continue; } @@ -611,13 +549,18 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, } } - /* still not found so far: add it as a sibling to the current node */ + /* if it's still not found so far we mai add it as a sibling */ if (class == NULL) { tmp = (struct q_class_t *) safe_calloc (1, sizeof (struct q_class_t)); tmp->prefix = (char *) safe_calloc (1, length + 1); strncpy (tmp->prefix, qptr, length); tmp->length = length; + if (*q_level >= ColorQuoteUsed) + *q_level = 1; + else + (*q_level)++; + tmp->color = ColorQuote[(*q_level) - 1]; if (ptr->down) { @@ -626,9 +569,7 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, } ptr->down = tmp; tmp->up = ptr; - - new_class_color (tmp, q_level); - + return tmp; } else @@ -650,7 +591,11 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, class->prefix = (char *) safe_calloc (1, length + 1); strncpy (class->prefix, qptr, length); class->length = length; - new_class_color (class, q_level); + if (*q_level >= ColorQuoteUsed) + *q_level = 1; + else + (*q_level)++; + class->color = ColorQuote[(*q_level) - 1]; if (*QuoteList) { @@ -660,9 +605,6 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr, *QuoteList = class; } - if (index != -1) - shift_class_colors (*QuoteList, tmp, index, q_level); - return class; } |