From ad303d5eab5c92f9546cc9d3703a24534d6bb5e0 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Fri, 18 May 2007 13:31:23 +0200 Subject: [PATCH] small updates. Signed-off-by: Pierre Habouzit --- CMakeLists.txt | 2 +- commands.c | 3 +- gen_defs | 52 +-- help.c | 14 +- keymap.h | 3 +- pager.c | 1030 ++++++++++++++++++++++++------------------------ recvattach.c | 2 + recvcmd.c | 3 +- sort.h | 5 + 9 files changed, 566 insertions(+), 548 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f49365..c4570ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -373,7 +373,7 @@ TARGET_LINK_LIBRARIES(madmutt_dotlock lib) ADD_CUSTOM_COMMAND( OUTPUT ${madmutt_SOURCE_DIR}/keymap_defs.h - DEPENDS ${madmutt_SOURCE_DIR}/OPS + DEPENDS ${madmutt_SOURCE_DIR}/OPS ${madmutt_SOURCE_DIR}/gen_defs COMMAND ${madmutt_SOURCE_DIR}/gen_defs ${madmutt_SOURCE_DIR}/OPS > ${madmutt_SOURCE_DIR}/keymap_defs.h COMMENT "Generating ${madmutt_SOURCE_DIR}/keymap_defs.h from ${madmutt_SOURCE_DIR}/OPS" ) diff --git a/commands.c b/commands.c index 8e24718..2617f7a 100644 --- a/commands.c +++ b/commands.c @@ -204,11 +204,11 @@ void ci_bounce_message (HEADER * h, int *redraw) buf[0] = 0; rfc822_addrcat(buf, sizeof (buf), adr, 1); -#define extra_space (15 + 7 + 2) snprintf (prompt, sizeof (prompt), (h ? _("Bounce message to %s") : _("Bounce messages to %s")), buf); +#define extra_space (15 + 7 + 2) if (m_strwidth(prompt) > COLS - extra_space) { mutt_format_string(prompt, sizeof(prompt), 0, COLS - extra_space, 0, 0, prompt, sizeof(prompt), 0); @@ -216,6 +216,7 @@ void ci_bounce_message (HEADER * h, int *redraw) } else { m_strcat(prompt, sizeof(prompt), "?"); } +#undef extra_space if (query_quadoption (OPT_BOUNCE, prompt) != M_YES) { address_list_wipe(&adr); diff --git a/gen_defs b/gen_defs index 0277a28..63919dc 100755 --- a/gen_defs +++ b/gen_defs @@ -6,30 +6,34 @@ echo '/* Automatically generated by gen_defs. Do not edit! */' echo '' for mode in help defs; do - case $mode in - help) - echo "#ifdef HELP_C" - echo "const char *HelpStrings[] = {" - expr='s;^[^ ]* *\(.*\); N_(\1),;' - ;; - *) - echo "enum {" - expr='s;^\([^ ]*\).*; \1,;' - ;; - esac - for i in $*; do - sed -e '/^\/\*/d' -e "$expr" < $i - done - if test $mode = help; then - echo ' NULL' - else - echo ' OP_MAX' - fi - echo "};" - if test $mode = help; then - echo "#endif /* MAIN_C */" - echo '' - fi + if test $mode = help; then + echo "#ifdef HELP_C" + echo "#ifndef KEYMAP_DEFS_HELP_C" + echo "#define KEYMAP_DEFS_HELP_C" + echo "const char *HelpStrings[] = {" + expr='s;^[^ ]* *\(.*\); N_(\1),;' + else + echo "#ifndef KEYMAP_DEFS_H" + echo "#define KEYMAP_DEFS_H" + echo "enum {" + expr='s;^\([^ ]*\).*; \1,;' + fi + for i in $*; do + sed -e '/^\/\*/d' -e "$expr" < $i + done + if test $mode = help; then + echo ' NULL' + else + echo ' OP_MAX' + fi + echo "};" + if test $mode = help; then + echo "#endif /* KEYMAP_DEFS_HELP_C */" + echo "#endif /* HELP_C */" + echo '' + else + echo "#endif /* KEYMAP_DEFS_H */" + fi done exit 0 diff --git a/help.c b/help.c index bce7b3d..ea694c3 100644 --- a/help.c +++ b/help.c @@ -140,8 +140,8 @@ static int pad (FILE * f, int col, int i) return (col + 1); } -static void format_line (FILE * f, int ismacro, - const char *t1, const char *t2, const char *t3) +static void help_format_line (FILE * f, int ismacro, + const char *t1, const char *t2, const char *t3) { int col; int col_a, col_b; @@ -227,13 +227,13 @@ static void dump_menu (FILE * f, int menu) if (map->op == OP_MACRO) { if (map->descr == NULL) - format_line (f, -1, buf, "macro", map->macro); + help_format_line (f, -1, buf, "macro", map->macro); else - format_line (f, 1, buf, map->macro, map->descr); + help_format_line (f, 1, buf, map->macro, map->descr); } else { b = help_lookupFunction (map->op, menu); - format_line (f, 0, buf, b ? b->name : "UNKNOWN", + help_format_line (f, 0, buf, b ? b->name : "UNKNOWN", b ? _(HelpStrings[b->op]) : _("ERROR: please report this bug")); } @@ -258,7 +258,7 @@ static void dump_unbound (FILE * f, for (i = 0; funcs[i].name; i++) { if (!is_bound (map, funcs[i].op) && (!aux || !is_bound (aux, funcs[i].op))) - format_line (f, 0, funcs[i].name, "", _(HelpStrings[funcs[i].op])); + help_format_line (f, 0, funcs[i].name, "", _(HelpStrings[funcs[i].op])); } } @@ -302,3 +302,5 @@ void mutt_help (int menu) M_PAGER_RETWINCH | M_PAGER_MARKER | M_PAGER_NSKIP, NULL) == OP_REFORMAT_WINCH); } + +#undef HELP_C diff --git a/keymap.h b/keymap.h index 58affcb..0a0d428 100644 --- a/keymap.h +++ b/keymap.h @@ -81,6 +81,5 @@ struct binding_t *km_get_table (int menu); #define MUTT_FUNCTIONS_PROTO #include "functions.def" -#include "keymap_defs.h" - #endif /* KEYMAP_H */ +#include "keymap_defs.h" diff --git a/pager.c b/pager.c index 966955c..5880834 100644 --- a/pager.c +++ b/pager.c @@ -263,52 +263,52 @@ static void append_line (struct line_t *lineInfo, int n, int cnt) /* 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) @@ -326,271 +326,271 @@ static struct q_class_t *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; - 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; @@ -603,138 +603,138 @@ resolve_types (char *buf, char *rawbuf, struct line_t *lineInfo, int n, int last 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) @@ -754,141 +754,141 @@ static int check_attachment_marker(char *p) 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 @@ -2517,3 +2517,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra) mutt_menuDestroy (&pager_index); return (rc != -1 ? rc : 0); } + +#undef CHECK_ATTACH +#undef CHECK_READONLY +#undef CHECK_MODE diff --git a/recvattach.c b/recvattach.c index ccbcf1a..1c2d85b 100644 --- a/recvattach.c +++ b/recvattach.c @@ -1149,5 +1149,7 @@ void mutt_view_attachments (HEADER * hdr) op = OP_NULL; } +#undef CHECK_READONLY +#undef CHECK_ATTACH /* not reached */ } diff --git a/recvcmd.c b/recvcmd.c index 71fc95b..e0c8457 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -155,7 +155,6 @@ void mutt_attach_bounce (FILE * fp, HEADER * hdr __attribute__ ((unused)), buf[0] = 0; rfc822_addrcat(buf, sizeof(buf), adr, 1); -#define extra_space (15+7+2) /* * See commands.c. */ @@ -163,6 +162,7 @@ void mutt_attach_bounce (FILE * fp, HEADER * hdr __attribute__ ((unused)), (p ? _("Bounce message to %s") : _("Bounce messages to %s")), buf); +#define extra_space (15+7+2) if (m_strwidth(prompt) > COLS - extra_space) { mutt_format_string (prompt, sizeof (prompt) - 4, 0, COLS - extra_space, 0, 0, @@ -171,6 +171,7 @@ void mutt_attach_bounce (FILE * fp, HEADER * hdr __attribute__ ((unused)), } else { m_strcat(prompt, sizeof(prompt), "?"); } +#undef extra_space if (query_quadoption (OPT_BOUNCE, prompt) != M_YES) { address_list_wipe(&adr); diff --git a/sort.h b/sort.h index 50c017b..d4f9241 100644 --- a/sort.h +++ b/sort.h @@ -7,6 +7,9 @@ * please see the file GPL in the top level source directory. */ +#ifndef MUTT_SORT_H +#define MUTT_SORT_H + #define SORT_DATE 1 /* the date the mail was sent. */ #define SORT_SIZE 2 #define SORT_SUBJECT 3 @@ -43,3 +46,5 @@ WHERE short SortAlias INITVAL (SORT_ALIAS); WHERE short PgpSortKeys INITVAL (SORT_ADDRESS); extern const struct mapping_t SortMethods[]; + +#endif -- 2.20.1