- struct q_class_t *q_list = *QuoteList;
- struct q_class_t *class = NULL, *tmp = NULL, *ptr, *save;
- char *tail_qptr;
- int offset, tail_lng;
- int lindex = -1;
-
- if (ColorQuoteUsed <= 1) {
- /* not much point in classifying quotes... */
-
- if (*QuoteList == NULL) {
- class = p_new(struct q_class_t, 1);
- class->color = ColorQuote[0];
- *QuoteList = class;
- }
- return (*QuoteList);
- }
-
- /* Did I mention how much I like emulating Lisp in C? */
-
- /* classify quoting prefix */
- while (q_list) {
- if (length <= q_list->length) {
- /* case 1: check the top level nodes */
-
- if (m_strncmp(qptr, q_list->prefix, length) == 0) {
- if (length == q_list->length)
- return q_list; /* same prefix: return the current class */
-
- /* found shorter prefix */
- if (tmp == NULL) {
- /* add a node above q_list */
- tmp = p_new(struct q_class_t, 1);
- tmp->prefix = p_dupstr(qptr, length);
- tmp->length = length;
-
- /* replace q_list by tmp in the top level list */
- if (q_list->next) {
- tmp->next = q_list->next;
- q_list->next->prev = tmp;
- }
- if (q_list->prev) {
- tmp->prev = q_list->prev;
- q_list->prev->next = tmp;
- }
-
- /* make q_list a child of tmp */
- tmp->down = q_list;
- q_list->up = tmp;
-
- /* q_list has no siblings for now */
- q_list->next = NULL;
- q_list->prev = NULL;
-
- /* update the root if necessary */
- if (q_list == *QuoteList)
- *QuoteList = tmp;
-
- lindex = 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
- */
- 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;
-
- /* unlink q_list from the top level list */
- if (q_list->next)
- q_list->next->prev = q_list->prev;
- if (q_list->prev)
- 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->up = tmp;
-
- lindex = q_list->index;
-
- /* next class to test; as above, we shouldn't go down */
- q_list = save;
+ struct q_class_t *q_list = *QuoteList;
+ struct q_class_t *class = NULL, *tmp = NULL, *ptr, *save;
+ char *tail_qptr;
+ int offset, tail_lng;
+ int lindex = -1;
+
+ if (ColorQuoteUsed <= 1) {
+ /* not much point in classifying quotes... */
+
+ if (*QuoteList == NULL) {
+ class = p_new(struct q_class_t, 1);
+ class->color = ColorQuote[0];
+ *QuoteList = class;