/* find the real start of the line */
for (m = n; m >= 0; m--)
- if (lineInfo[m].continuation == 0)
- break;
+ if (lineInfo[m].continuation == 0)
+ break;
(lineInfo[n + 1].syntax)[0].first = m;
(lineInfo[n + 1].syntax)[0].last = (lineInfo[n].continuation) ?
- cnt + (lineInfo[n].syntax)[0].last : cnt;
+ cnt + (lineInfo[n].syntax)[0].last : cnt;
}
static void new_class_color (struct q_class_t *class, int *q_level)
{
- class->index = (*q_level)++;
- class->color = ColorQuote[class->index % ColorQuoteUsed];
+ 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 lindex, int *q_level)
{
- struct q_class_t *q_list;
+ struct q_class_t *q_list;
- q_list = QuoteList;
- new_class->index = -1;
+ q_list = QuoteList;
+ new_class->index = -1;
- while (q_list) {
- if (q_list->index >= lindex) {
- 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;
+ while (q_list) {
+ if (q_list->index >= lindex) {
+ 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 = lindex;
- new_class->color = ColorQuote[lindex % ColorQuoteUsed];
- (*q_level)++;
+ new_class->index = lindex;
+ new_class->color = ColorQuote[lindex % ColorQuoteUsed];
+ (*q_level)++;
}
static void cleanup_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;
- 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;
}
+ return (*QuoteList);
+ }
- /* we found a shorter prefix, so certain quotes have changed classes */
- *force_redraw = 1;
- continue;
- } else {
- /* shorter, but not a substring of the current class: try next */
- q_list = q_list->next;
- continue;
- }
- } else {
- /* case 2: try subclassing the current top level node */
-
- /* tmp != NULL means we already found a shorter prefix at case 1 */
- if (tmp == NULL
- && m_strncmp(qptr, q_list->prefix, q_list->length) == 0) {
- /* ok, it's a subclass somewhere on this branch */
-
- ptr = q_list;
- offset = q_list->length;
-
- q_list = q_list->down;
- tail_lng = length - offset;
- tail_qptr = (char *) qptr + offset;
-
- while (q_list) {
- if (length <= q_list->length) {
- if (m_strncmp(tail_qptr, (q_list->prefix) + offset, tail_lng)
- == 0) {
- /* same prefix: return the current class */
- if (length == q_list->length)
- return q_list;
-
- /* found shorter common 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 */
- 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;
+ /* 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;
}
- /* make q_list a child of tmp */
- tmp->down = q_list;
- tmp->up = q_list->up;
- q_list->up = tmp;
- if (tmp->up->down == q_list)
- tmp->up->down = tmp;
-
- /* q_list has no siblings */
- q_list->next = NULL;
- q_list->prev = NULL;
-
- lindex = q_list->index;
-
- /* tmp should be the return class too */
- class = tmp;
-
- /* 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;
-
- /* 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;
- 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 */
- q_list = save;
- }
-
- /* we found a shorter prefix, so we need a redraw */
- *force_redraw = 1;
- continue;
+ /* we found a shorter prefix, so certain quotes have changed classes */
+ *force_redraw = 1;
+ continue;
} else {
- q_list = q_list->next;
- continue;
+ /* shorter, but not a substring of the current class: try next */
+ q_list = q_list->next;
+ continue;
}
- } else {
- /* longer than the current prefix: try subclassing it */
+ } else {
+ /* case 2: try subclassing the current top level node */
+
+ /* tmp != NULL means we already found a shorter prefix at case 1 */
if (tmp == NULL
- && m_strncmp(tail_qptr, (q_list->prefix) + offset,
- q_list->length - offset) == 0) {
- /* still a subclass: go down one level */
- ptr = q_list;
- offset = q_list->length;
+ && m_strncmp(qptr, q_list->prefix, q_list->length) == 0) {
+ /* ok, it's a subclass somewhere on this branch */
+
+ ptr = q_list;
+ offset = q_list->length;
+
+ q_list = q_list->down;
+ tail_lng = length - offset;
+ tail_qptr = (char *) qptr + offset;
+
+ while (q_list) {
+ if (length <= q_list->length) {
+ if (m_strncmp(tail_qptr, (q_list->prefix) + offset, tail_lng)
+ == 0) {
+ /* same prefix: return the current class */
+ if (length == q_list->length)
+ return q_list;
+
+ /* found shorter common 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 */
+ 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;
+ tmp->up = q_list->up;
+ q_list->up = tmp;
+ if (tmp->up->down == q_list)
+ tmp->up->down = tmp;
+
+ /* q_list has no siblings */
+ q_list->next = NULL;
+ q_list->prev = NULL;
+
+ lindex = q_list->index;
+
+ /* tmp should be the return class too */
+ class = tmp;
+
+ /* 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;
+
+ /* 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;
+ 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 */
+ q_list = save;
+ }
+
+ /* we found a shorter prefix, so we need a redraw */
+ *force_redraw = 1;
+ continue;
+ } else {
+ q_list = q_list->next;
+ continue;
+ }
+ } else {
+ /* longer than the current prefix: try subclassing it */
+ if (tmp == NULL
+ && m_strncmp(tail_qptr, (q_list->prefix) + offset,
+ q_list->length - offset) == 0) {
+ /* still a subclass: go down one level */
+ ptr = q_list;
+ offset = q_list->length;
+
+ q_list = q_list->down;
+ tail_lng = length - offset;
+ tail_qptr = (char *) qptr + offset;
+
+ continue;
+ } else {
+ /* nope, try the next prefix */
+ q_list = q_list->next;
+ continue;
+ }
+ }
+ }
- q_list = q_list->down;
- tail_lng = length - offset;
- tail_qptr = (char *) qptr + offset;
+ /* still not found so far: add it as a sibling to the current node */
+ if (class == NULL) {
+ tmp = p_new(struct q_class_t, 1);
+ tmp->prefix = p_dupstr(qptr, length);
+ tmp->length = length;
- continue;
- } else {
- /* nope, try the next prefix */
- q_list = q_list->next;
- continue;
- }
- }
- }
+ if (ptr->down) {
+ tmp->next = ptr->down;
+ ptr->down->prev = tmp;
+ }
+ ptr->down = tmp;
+ tmp->up = ptr;
- /* still not found so far: add it as a sibling to the current node */
- if (class == NULL) {
- tmp = p_new(struct q_class_t, 1);
- tmp->prefix = p_dupstr(qptr, length);
- tmp->length = length;
-
- if (ptr->down) {
- tmp->next = ptr->down;
- ptr->down->prev = tmp;
- }
- ptr->down = tmp;
- tmp->up = ptr;
+ new_class_color (tmp, q_level);
- new_class_color (tmp, q_level);
+ return tmp;
+ } else {
+ if (lindex != -1)
+ shift_class_colors (*QuoteList, tmp, lindex, q_level);
- return tmp;
- } else {
- if (lindex != -1)
- shift_class_colors (*QuoteList, tmp, lindex, q_level);
-
- return class;
+ return class;
+ }
+ } else {
+ /* nope, try the next prefix */
+ q_list = q_list->next;
+ continue;
+ }
}
- } else {
- /* nope, try the next prefix */
- q_list = q_list->next;
- continue;
- }
}
- }
- if (class == NULL) {
- /* not found so far: add it as a top level class */
- class = p_new(struct q_class_t, 1);
- class->prefix = p_dupstr(qptr, length);
- class->length = length;
- new_class_color (class, q_level);
+ if (class == NULL) {
+ /* not found so far: add it as a top level class */
+ class = p_new(struct q_class_t, 1);
+ class->prefix = p_dupstr(qptr, length);
+ class->length = length;
+ new_class_color (class, q_level);
- if (*QuoteList) {
- class->next = *QuoteList;
- (*QuoteList)->prev = class;
+ if (*QuoteList) {
+ class->next = *QuoteList;
+ (*QuoteList)->prev = class;
+ }
+ *QuoteList = class;
}
- *QuoteList = class;
- }
- if (lindex != -1)
- shift_class_colors (*QuoteList, tmp, lindex, q_level);
+ if (lindex != -1)
+ shift_class_colors (*QuoteList, tmp, lindex, q_level);
- return class;
+ return class;
}
static int brailleLine = -1;
struct q_class_t **QuoteList, int *q_level, int *force_redraw,
int q_classify)
{
- COLOR_LINE *color_line;
- regmatch_t pmatch[1], smatch[1];
- int found, offset, null_rx, i;
-
- if (n == 0 || ISHEADER (lineInfo[n - 1].type)) {
- if (buf[0] == '\n') {
- lineInfo[n].type = MT_COLOR_NORMAL;
- getyx(stdscr, brailleLine, brailleCol);
- }
- else if (n > 0 && (buf[0] == ' ' || buf[0] == '\t')) {
- lineInfo[n].type = lineInfo[n - 1].type; /* wrapped line */
- (lineInfo[n].syntax)[0].color = (lineInfo[n - 1].syntax)[0].color;
- } else {
- lineInfo[n].type = MT_COLOR_HDEFAULT;
- color_line = ColorHdrList;
- while (color_line) {
- if (REGEXEC (&color_line->rx, buf) == 0) {
- lineInfo[n].type = MT_COLOR_HEADER;
- lineInfo[n].syntax[0].color = color_line->pair;
- break;
+ COLOR_LINE *color_line;
+ regmatch_t pmatch[1], smatch[1];
+ int found, offset, null_rx, i;
+
+ if (n == 0 || ISHEADER (lineInfo[n - 1].type)) {
+ if (buf[0] == '\n') {
+ lineInfo[n].type = MT_COLOR_NORMAL;
+ getyx(stdscr, brailleLine, brailleCol);
+ }
+ else if (n > 0 && (buf[0] == ' ' || buf[0] == '\t')) {
+ lineInfo[n].type = lineInfo[n - 1].type; /* wrapped line */
+ (lineInfo[n].syntax)[0].color = (lineInfo[n - 1].syntax)[0].color;
+ } else {
+ lineInfo[n].type = MT_COLOR_HDEFAULT;
+ color_line = ColorHdrList;
+ while (color_line) {
+ if (REGEXEC (&color_line->rx, buf) == 0) {
+ lineInfo[n].type = MT_COLOR_HEADER;
+ lineInfo[n].syntax[0].color = color_line->pair;
+ break;
+ }
+ color_line = color_line->next;
+ }
}
- color_line = color_line->next;
- }
}
- }
- else if (m_strncmp("\033[0m", rawbuf, 4) == 0) /* a little hack... */
- lineInfo[n].type = MT_COLOR_NORMAL;
- else if (check_attachment_marker ((char *) rawbuf) == 0)
- lineInfo[n].type = MT_COLOR_ATTACHMENT;
- else if (m_strcmp("-- \n", buf) == 0
- || m_strcmp("-- \r\n", buf) == 0) {
- i = n + 1;
-
- lineInfo[n].type = MT_COLOR_SIGNATURE;
- while (i < last && check_sig(buf, lineInfo, i - 1) == 0 &&
- (lineInfo[i].type == MT_COLOR_NORMAL ||
- lineInfo[i].type == MT_COLOR_QUOTED ||
- lineInfo[i].type == MT_COLOR_HEADER)) {
- /* oops... */
- if (lineInfo[i].chunks) {
- lineInfo[i].chunks = 0;
- p_realloc(&(lineInfo[n].syntax), 1);
- }
- lineInfo[i++].type = MT_COLOR_SIGNATURE;
+ else if (m_strncmp("\033[0m", rawbuf, 4) == 0) /* a little hack... */
+ lineInfo[n].type = MT_COLOR_NORMAL;
+ else if (check_attachment_marker ((char *) rawbuf) == 0)
+ lineInfo[n].type = MT_COLOR_ATTACHMENT;
+ else if (m_strcmp("-- \n", buf) == 0
+ || m_strcmp("-- \r\n", buf) == 0) {
+ i = n + 1;
+
+ lineInfo[n].type = MT_COLOR_SIGNATURE;
+ while (i < last && check_sig(buf, lineInfo, i - 1) == 0 &&
+ (lineInfo[i].type == MT_COLOR_NORMAL ||
+ lineInfo[i].type == MT_COLOR_QUOTED ||
+ lineInfo[i].type == MT_COLOR_HEADER)) {
+ /* oops... */
+ if (lineInfo[i].chunks) {
+ lineInfo[i].chunks = 0;
+ p_realloc(&(lineInfo[n].syntax), 1);
+ }
+ lineInfo[i++].type = MT_COLOR_SIGNATURE;
+ }
}
- }
- else if (check_sig(buf, lineInfo, n - 1) == 0)
- lineInfo[n].type = MT_COLOR_SIGNATURE;
- else if (regexec ((regex_t *) QuoteRegexp.rx, buf, 1, pmatch, 0) == 0) {
- if (regexec ((regex_t *) Smileys.rx, buf, 1, smatch, 0) == 0) {
- if (smatch[0].rm_so > 0) {
- char c;
-
- /* hack to avoid making an extra copy of buf */
- c = buf[smatch[0].rm_so];
- buf[smatch[0].rm_so] = 0;
-
- if (regexec ((regex_t *) QuoteRegexp.rx, buf, 1, pmatch, 0) == 0) {
- if (q_classify && lineInfo[n].quote == NULL)
- lineInfo[n].quote = classify_quote (QuoteList,
- buf + pmatch[0].rm_so,
- pmatch[0].rm_eo -
- pmatch[0].rm_so, force_redraw,
- q_level);
- lineInfo[n].type = MT_COLOR_QUOTED;
+ else if (check_sig(buf, lineInfo, n - 1) == 0)
+ lineInfo[n].type = MT_COLOR_SIGNATURE;
+ else if (regexec ((regex_t *) QuoteRegexp.rx, buf, 1, pmatch, 0) == 0) {
+ if (regexec ((regex_t *) Smileys.rx, buf, 1, smatch, 0) == 0) {
+ if (smatch[0].rm_so > 0) {
+ char c;
+
+ /* hack to avoid making an extra copy of buf */
+ c = buf[smatch[0].rm_so];
+ buf[smatch[0].rm_so] = 0;
+
+ if (regexec ((regex_t *) QuoteRegexp.rx, buf, 1, pmatch, 0) == 0) {
+ if (q_classify && lineInfo[n].quote == NULL)
+ lineInfo[n].quote = classify_quote (QuoteList,
+ buf + pmatch[0].rm_so,
+ pmatch[0].rm_eo -
+ pmatch[0].rm_so, force_redraw,
+ q_level);
+ lineInfo[n].type = MT_COLOR_QUOTED;
+ } else {
+ lineInfo[n].type = MT_COLOR_NORMAL;
+ }
+
+ buf[smatch[0].rm_so] = c;
+ } else {
+ lineInfo[n].type = MT_COLOR_NORMAL;
+ }
} else {
- lineInfo[n].type = MT_COLOR_NORMAL;
+ if (q_classify && lineInfo[n].quote == NULL)
+ lineInfo[n].quote = classify_quote (QuoteList, buf + pmatch[0].rm_so,
+ pmatch[0].rm_eo - pmatch[0].rm_so,
+ force_redraw, q_level);
+ lineInfo[n].type = MT_COLOR_QUOTED;
}
-
- buf[smatch[0].rm_so] = c;
- } else {
- lineInfo[n].type = MT_COLOR_NORMAL;
- }
} else {
- if (q_classify && lineInfo[n].quote == NULL)
- lineInfo[n].quote = classify_quote (QuoteList, buf + pmatch[0].rm_so,
- pmatch[0].rm_eo - pmatch[0].rm_so,
- force_redraw, q_level);
- lineInfo[n].type = MT_COLOR_QUOTED;
+ lineInfo[n].type = MT_COLOR_NORMAL;
}
- } else {
- lineInfo[n].type = MT_COLOR_NORMAL;
- }
- /* body patterns */
- if (lineInfo[n].type == MT_COLOR_NORMAL ||
- lineInfo[n].type == MT_COLOR_QUOTED) {
- i = 0;
+ /* body patterns */
+ if (lineInfo[n].type == MT_COLOR_NORMAL ||
+ lineInfo[n].type == MT_COLOR_QUOTED) {
+ i = 0;
- offset = 0;
- lineInfo[n].chunks = 0;
- do {
- if (!buf[offset])
- break;
+ offset = 0;
+ lineInfo[n].chunks = 0;
+ do {
+ if (!buf[offset])
+ break;
- found = 0;
- null_rx = 0;
- color_line = ColorBodyList;
- while (color_line) {
- if (regexec (&color_line->rx, buf + offset, 1, pmatch,
- (offset ? REG_NOTBOL : 0)) == 0) {
- if (pmatch[0].rm_eo != pmatch[0].rm_so) {
- if (!found) {
- if (++(lineInfo[n].chunks) > 1)
- p_realloc(&(lineInfo[n].syntax), lineInfo[n].chunks);
- }
- i = lineInfo[n].chunks - 1;
- pmatch[0].rm_so += offset;
- pmatch[0].rm_eo += offset;
- if (!found ||
- pmatch[0].rm_so < (lineInfo[n].syntax)[i].first ||
- (pmatch[0].rm_so == (lineInfo[n].syntax)[i].first &&
- pmatch[0].rm_eo > (lineInfo[n].syntax)[i].last)) {
- (lineInfo[n].syntax)[i].color = color_line->pair;
- (lineInfo[n].syntax)[i].first = pmatch[0].rm_so;
- (lineInfo[n].syntax)[i].last = pmatch[0].rm_eo;
- }
- found = 1;
+ found = 0;
null_rx = 0;
- } else {
- null_rx = 1; /* empty regexp; don't add it, but keep looking */
- }
- }
- color_line = color_line->next;
- }
+ color_line = ColorBodyList;
+ while (color_line) {
+ if (regexec (&color_line->rx, buf + offset, 1, pmatch,
+ (offset ? REG_NOTBOL : 0)) == 0) {
+ if (pmatch[0].rm_eo != pmatch[0].rm_so) {
+ if (!found) {
+ if (++(lineInfo[n].chunks) > 1)
+ p_realloc(&(lineInfo[n].syntax), lineInfo[n].chunks);
+ }
+ i = lineInfo[n].chunks - 1;
+ pmatch[0].rm_so += offset;
+ pmatch[0].rm_eo += offset;
+ if (!found ||
+ pmatch[0].rm_so < (lineInfo[n].syntax)[i].first ||
+ (pmatch[0].rm_so == (lineInfo[n].syntax)[i].first &&
+ pmatch[0].rm_eo > (lineInfo[n].syntax)[i].last)) {
+ (lineInfo[n].syntax)[i].color = color_line->pair;
+ (lineInfo[n].syntax)[i].first = pmatch[0].rm_so;
+ (lineInfo[n].syntax)[i].last = pmatch[0].rm_eo;
+ }
+ found = 1;
+ null_rx = 0;
+ } else {
+ null_rx = 1; /* empty regexp; don't add it, but keep looking */
+ }
+ }
+ color_line = color_line->next;
+ }
- if (null_rx)
- offset++; /* avoid degenerate cases */
- else
- offset = lineInfo[n].syntax[i].last;
- } while (found || null_rx);
- }
+ if (null_rx)
+ offset++; /* avoid degenerate cases */
+ else
+ offset = lineInfo[n].syntax[i].last;
+ } while (found || null_rx);
+ }
}
static int is_ansi(unsigned char *buf)
static int grok_ansi (unsigned char *buf, int pos, ansi_attr * a)
{
- int x = pos;
-
- while (isdigit (buf[x]) || buf[x] == ';')
- x++;
-
- /* Character Attributes */
- if (option (OPTALLOWANSI) && a != NULL && buf[x] == 'm') {
- if (pos == x) {
- if (a->pair != -1)
- mutt_free_color (a->fg, a->bg);
- a->attr = ANSI_OFF;
- a->pair = -1;
- }
- a->bg = -2;
- a->fg = -2;
- while (pos < x) {
- if (buf[pos] == '1' && (pos + 1 == x || buf[pos + 1] == ';')) {
- a->attr |= ANSI_BOLD;
- pos += 2;
- }
- else if (buf[pos] == '4' && (pos + 1 == x || buf[pos + 1] == ';')) {
- a->attr |= ANSI_UNDERLINE;
- pos += 2;
- }
- else if (buf[pos] == '5' && (pos + 1 == x || buf[pos + 1] == ';')) {
- a->attr |= ANSI_BLINK;
- pos += 2;
- }
- else if (buf[pos] == '7' && (pos + 1 == x || buf[pos + 1] == ';')) {
- a->attr |= ANSI_REVERSE;
- pos += 2;
- }
- else if (buf[pos] == '0' && (pos + 1 == x || buf[pos + 1] == ';')) {
+ int x = pos;
+
+ while (isdigit (buf[x]) || buf[x] == ';')
+ x++;
+
+ /* Character Attributes */
+ if (option (OPTALLOWANSI) && a != NULL && buf[x] == 'm') {
+ if (pos == x) {
+ if (a->pair != -1)
+ mutt_free_color (a->fg, a->bg);
+ a->attr = ANSI_OFF;
+ a->pair = -1;
+ }
a->bg = -2;
a->fg = -2;
- pos += 2;
- }
- else if (buf[pos] == '3' && isdigit (buf[pos + 1])) {
- if (a->pair != -1)
- mutt_free_color (a->fg, a->bg);
- a->pair = -1;
- a->attr |= ANSI_COLOR;
- if (buf[pos + 1] != '9')
- a->fg = buf[pos + 1] - '0';
- pos += 3;
- }
- else if (buf[pos] == '4' && isdigit (buf[pos + 1])) {
- if (a->pair != -1)
- mutt_free_color (a->fg, a->bg);
- a->pair = -1;
- a->attr |= ANSI_COLOR;
- if (buf[pos + 1] != '9')
- a->bg = buf[pos + 1] - '0';
- pos += 3;
- } else {
- while (pos < x && buf[pos] != ';')
- pos++;
- pos++;
- }
+ while (pos < x) {
+ if (buf[pos] == '1' && (pos + 1 == x || buf[pos + 1] == ';')) {
+ a->attr |= ANSI_BOLD;
+ pos += 2;
+ }
+ else if (buf[pos] == '4' && (pos + 1 == x || buf[pos + 1] == ';')) {
+ a->attr |= ANSI_UNDERLINE;
+ pos += 2;
+ }
+ else if (buf[pos] == '5' && (pos + 1 == x || buf[pos + 1] == ';')) {
+ a->attr |= ANSI_BLINK;
+ pos += 2;
+ }
+ else if (buf[pos] == '7' && (pos + 1 == x || buf[pos + 1] == ';')) {
+ a->attr |= ANSI_REVERSE;
+ pos += 2;
+ }
+ else if (buf[pos] == '0' && (pos + 1 == x || buf[pos + 1] == ';')) {
+ a->bg = -2;
+ a->fg = -2;
+ pos += 2;
+ }
+ else if (buf[pos] == '3' && isdigit (buf[pos + 1])) {
+ if (a->pair != -1)
+ mutt_free_color (a->fg, a->bg);
+ a->pair = -1;
+ a->attr |= ANSI_COLOR;
+ if (buf[pos + 1] != '9')
+ a->fg = buf[pos + 1] - '0';
+ pos += 3;
+ }
+ else if (buf[pos] == '4' && isdigit (buf[pos + 1])) {
+ if (a->pair != -1)
+ mutt_free_color (a->fg, a->bg);
+ a->pair = -1;
+ a->attr |= ANSI_COLOR;
+ if (buf[pos + 1] != '9')
+ a->bg = buf[pos + 1] - '0';
+ pos += 3;
+ } else {
+ while (pos < x && buf[pos] != ';')
+ pos++;
+ pos++;
+ }
+ }
}
- }
- pos = x;
- return pos;
+ pos = x;
+ return pos;
}
/* trim tail of buf so that it contains complete multibyte characters */
static int trim_incomplete_mbyte(unsigned char *buf, size_t len) {
- mbstate_t mbstate;
- ssize_t k;
+ mbstate_t mbstate;
+ ssize_t k;
- p_clear(&mbstate, 1);
- for (; len > 0; buf += k, len -= k) {
- k = mbrtowc (NULL, (char *) buf, len, &mbstate);
- if (k == -2)
- break;
- if (k == -1 || k == 0)
- k = 1;
- }
- *buf = '\0';
+ p_clear(&mbstate, 1);
+ for (; len > 0; buf += k, len -= k) {
+ k = mbrtowc (NULL, (char *) buf, len, &mbstate);
+ if (k == -2)
+ break;
+ if (k == -1 || k == 0)
+ k = 1;
+ }
+ *buf = '\0';
- return len;
+ return len;
}
static int
fill_buffer (FILE * f, off_t *last_pos, off_t offset, unsigned char *buf,
unsigned char *fmt, ssize_t blen, int *buf_ready)
{
- unsigned char *p;
- static int b_read = 0;
-
- if (*buf_ready == 0) {
- buf[blen - 1] = 0;
- if (offset != *last_pos)
- fseeko (f, offset, 0);
- if (fgets ((char *) buf, blen - 1, f) == NULL) {
- fmt[0] = 0;
- return (-1);
- }
- *last_pos = ftello (f);
- b_read = (int) (*last_pos - offset);
- *buf_ready = 1;
-
- /* incomplete mbyte characters trigger a segfault in regex processing for
- * certain versions of glibc. Trim them if necessary. */
- if (b_read == blen - 2)
- b_read -= trim_incomplete_mbyte(buf, b_read);
-
- /* copy "buf" to "fmt", but without bold and underline controls */
- p = buf;
- while (*p) {
- if (*p == '\010' && (p > buf)) {
- if (*(p + 1) == '_') /* underline */
- p += 2;
- else if (*(p + 1)) { /* bold or overstrike */
- *(fmt - 1) = *(p + 1);
- p += 2;
- } else { /* ^H */
- *fmt++ = *p++;
+ unsigned char *p;
+ static int b_read = 0;
+
+ if (*buf_ready == 0) {
+ buf[blen - 1] = 0;
+ if (offset != *last_pos)
+ fseeko (f, offset, 0);
+ if (fgets ((char *) buf, blen - 1, f) == NULL) {
+ fmt[0] = 0;
+ return (-1);
}
- }
- else if (*p == '\033' && *(p + 1) == '[' && is_ansi (p + 2)) {
- while (*p++ != 'm') /* skip ANSI sequence */
- ;
- }
- else if (*p == '\033' && *(p + 1) == ']'
- && check_attachment_marker ((char *) p) == 0) {
- while (*p++ != '\a') /* skip pseudo-ANSI sequence */
- ;
- } else {
- *fmt++ = *p++;
- }
+ *last_pos = ftello (f);
+ b_read = (int) (*last_pos - offset);
+ *buf_ready = 1;
+
+ /* incomplete mbyte characters trigger a segfault in regex processing for
+ * certain versions of glibc. Trim them if necessary. */
+ if (b_read == blen - 2)
+ b_read -= trim_incomplete_mbyte(buf, b_read);
+
+ /* copy "buf" to "fmt", but without bold and underline controls */
+ p = buf;
+ while (*p) {
+ if (*p == '\010' && (p > buf)) {
+ if (*(p + 1) == '_') /* underline */
+ p += 2;
+ else if (*(p + 1)) { /* bold or overstrike */
+ *(fmt - 1) = *(p + 1);
+ p += 2;
+ } else { /* ^H */
+ *fmt++ = *p++;
+ }
+ }
+ else if (*p == '\033' && *(p + 1) == '[' && is_ansi (p + 2)) {
+ while (*p++ != 'm') /* skip ANSI sequence */
+ ;
+ }
+ else if (*p == '\033' && *(p + 1) == ']'
+ && check_attachment_marker ((char *) p) == 0) {
+ while (*p++ != '\a') /* skip pseudo-ANSI sequence */
+ ;
+ } else {
+ *fmt++ = *p++;
+ }
+ }
+ *fmt = 0;
}
- *fmt = 0;
- }
- return b_read;
+ return b_read;
}
#ifdef USE_NNTP
mutt_menuDestroy (&pager_index);
return (rc != -1 ? rc : 0);
}
+
+#undef CHECK_ATTACH
+#undef CHECK_READONLY
+#undef CHECK_MODE