From d1462a555eeaa2dab3335d39d5b9a13eb1e5fd6c Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 17 Feb 2016 19:46:21 +0000 Subject: [PATCH] tidy code --- color.c | 148 +++++++++++++++++++++++--------------------------- curs_lib.c | 10 ++-- hdrline.c | 147 +++++++++++++++++++++++++------------------------ menu.c | 78 +++++++++++++------------- mutt_curses.h | 2 +- 5 files changed, 188 insertions(+), 197 deletions(-) diff --git a/color.c b/color.c index 48272880b..07663b690 100644 --- a/color.c +++ b/color.c @@ -35,9 +35,9 @@ int ColorDefs[MT_COLOR_MAX]; COLOR_LINE *ColorHdrList = NULL; COLOR_LINE *ColorBodyList = NULL; COLOR_LINE *ColorIndexList = NULL; -COLOR_LINE *ColorIndexSubjectList = NULL; COLOR_LINE *ColorIndexAuthorList = NULL; COLOR_LINE *ColorIndexFlagsList = NULL; +COLOR_LINE *ColorIndexSubjectList = NULL; /* local to this file */ static int ColorQuoteSize; @@ -96,7 +96,6 @@ static const struct mapping_t Fields[] = { "bold", MT_COLOR_BOLD }, { "underline", MT_COLOR_UNDERLINE }, { "index", MT_COLOR_INDEX }, - { "index_subject", MT_COLOR_INDEX_SUBJECT }, { "index_author", MT_COLOR_INDEX_AUTHOR }, { "index_collapsed", MT_COLOR_INDEX_COLLAPSED }, { "index_date", MT_COLOR_INDEX_DATE }, @@ -104,6 +103,7 @@ static const struct mapping_t Fields[] = { "index_label", MT_COLOR_INDEX_LABEL }, { "index_number", MT_COLOR_INDEX_NUMBER }, { "index_size", MT_COLOR_INDEX_SIZE }, + { "index_subject", MT_COLOR_INDEX_SUBJECT }, { "prompt", MT_COLOR_PROMPT }, { NULL, 0 } }; @@ -395,48 +395,46 @@ int mutt_parse_unmono (BUFFER *buf, BUFFER *s, unsigned long data, return _mutt_parse_uncolor(buf, s, data, err, 0); } +/** + * mutt_do_uncolor - XXX + */ static void mutt_do_uncolor (BUFFER *buf, BUFFER *s, COLOR_LINE **ColorList, int *do_cache, int parse_uncolor) { - COLOR_LINE *tmp, *last = NULL; - - do - { - mutt_extract_token (buf, s, 0); - if (!mutt_strcmp ("*", buf->data)) - { - for (tmp = *ColorList; tmp; ) - { - if (!*do_cache) - *do_cache = 1; - last = tmp; - tmp = tmp->next; - mutt_free_color_line(&last, parse_uncolor); - } - *ColorList = NULL; - } - else - { - for (last = NULL, tmp = *ColorList; tmp; last = tmp, tmp = tmp->next) - { - if (!mutt_strcmp (buf->data, tmp->pattern)) - { - if (!*do_cache) - *do_cache = 1; - dprint(1,(debugfile,"Freeing pattern \"%s\" from ColorList\n", - tmp->pattern)); - if (last) - last->next = tmp->next; - else - *ColorList = tmp->next; - mutt_free_color_line(&tmp, parse_uncolor); - break; - } - } - } - } - while (MoreArgs (s)); + COLOR_LINE *tmp, *last = NULL; + + do { + mutt_extract_token (buf, s, 0); + if (mutt_strcmp ("*", buf->data) == 0) { + for (tmp = *ColorList; tmp; ) { + if (!*do_cache) { + *do_cache = 1; + } + last = tmp; + tmp = tmp->next; + mutt_free_color_line (&last, parse_uncolor); + } + *ColorList = NULL; + } else { + for (last = NULL, tmp = *ColorList; tmp; last = tmp, tmp = tmp->next) { + if (mutt_strcmp (buf->data, tmp->pattern) == 0) { + if (!*do_cache) { + *do_cache = 1; + } + dprint (1, (debugfile,"Freeing pattern \"%s\" from ColorList\n", + tmp->pattern)); + if (last) { + last->next = tmp->next; + } else { + *ColorList = tmp->next; + } + mutt_free_color_line (&tmp, parse_uncolor); + break; + } + } + } + } while (MoreArgs (s)); } static int _mutt_parse_uncolor (BUFFER *buf, BUFFER *s, unsigned long data, @@ -452,16 +450,15 @@ static int _mutt_parse_uncolor (BUFFER *buf, BUFFER *s, unsigned long data, return (-1); } - if (object > MT_COLOR_INDEX_SUBJECT) /* uncolor index column */ - { + if (object > MT_COLOR_INDEX_SUBJECT) { /* uncolor index column */ ColorDefs[object] = 0; set_option (OPTFORCEREDRAWINDEX); - return (0); + return 0; } - if ((mutt_strncmp (buf->data, "index", 5) != 0) && - (mutt_strncmp (buf->data, "body", 4) != 0) && - (mutt_strncmp (buf->data, "header", 6) != 0)) + if ((mutt_strncmp (buf->data, "body", 4) != 0) && + (mutt_strncmp (buf->data, "header", 6) != 0) && + (mutt_strncmp (buf->data, "index", 5) != 0)) { snprintf (err->data, err->dsize, _("%s: command valid only for index, body, header objects"), @@ -498,18 +495,18 @@ static int _mutt_parse_uncolor (BUFFER *buf, BUFFER *s, unsigned long data, return 0; } - if (object == MT_COLOR_INDEX) - mutt_do_uncolor(buf, s, &ColorIndexList, &do_cache, parse_uncolor); - else if (object == MT_COLOR_INDEX_SUBJECT) - mutt_do_uncolor(buf, s, &ColorIndexSubjectList, &do_cache, parse_uncolor); + if (object == MT_COLOR_BODY) + mutt_do_uncolor (buf, s, &ColorBodyList, &do_cache, parse_uncolor); + else if (object == MT_COLOR_HEADER) + mutt_do_uncolor (buf, s, &ColorHdrList, &do_cache, parse_uncolor); + else if (object == MT_COLOR_INDEX) + mutt_do_uncolor (buf, s, &ColorIndexList, &do_cache, parse_uncolor); else if (object == MT_COLOR_INDEX_AUTHOR) - mutt_do_uncolor(buf, s, &ColorIndexAuthorList, &do_cache, parse_uncolor); + mutt_do_uncolor (buf, s, &ColorIndexAuthorList, &do_cache, parse_uncolor); else if (object == MT_COLOR_INDEX_FLAGS) - mutt_do_uncolor(buf, s, &ColorIndexFlagsList, &do_cache, parse_uncolor); - else if (object == MT_COLOR_BODY) - mutt_do_uncolor(buf, s, &ColorBodyList, &do_cache, parse_uncolor); - else if (object == MT_COLOR_HEADER) - mutt_do_uncolor(buf, s, &ColorHdrList, &do_cache, parse_uncolor); + mutt_do_uncolor (buf, s, &ColorIndexFlagsList, &do_cache, parse_uncolor); + else if (object == MT_COLOR_INDEX_SUBJECT) + mutt_do_uncolor (buf, s, &ColorIndexSubjectList, &do_cache, parse_uncolor); if (do_cache && !option (OPTNOCURSES)) { @@ -749,17 +746,15 @@ _mutt_parse_color (BUFFER *buf, BUFFER *s, BUFFER *err, /* extract a regular expression if needed */ - if (object == MT_COLOR_HEADER || - object == MT_COLOR_BODY || - object == MT_COLOR_INDEX || - object == MT_COLOR_INDEX_SUBJECT || - object == MT_COLOR_INDEX_AUTHOR || - object == MT_COLOR_INDEX_FLAGS) - { - if (!MoreArgs (s)) - { + if ((object == MT_COLOR_BODY) || + (object == MT_COLOR_HEADER) || + (object == MT_COLOR_INDEX) || + (object == MT_COLOR_INDEX_AUTHOR) || + (object == MT_COLOR_INDEX_FLAGS) || + (object == MT_COLOR_INDEX_SUBJECT)) { + if (!MoreArgs (s)) { strfcpy (err->data, _("too few arguments"), err->dsize); - return (-1); + return -1; } mutt_extract_token (buf, s, 0); @@ -797,23 +792,14 @@ _mutt_parse_color (BUFFER *buf, BUFFER *s, BUFFER *err, { r = add_pattern (&ColorIndexList, buf->data, 1, fg, bg, attr, err, 1); set_option (OPTFORCEREDRAWINDEX); - } - else if (object == MT_COLOR_INDEX_SUBJECT) - { - r = add_pattern (&ColorIndexSubjectList, buf->data, - 1, fg, bg, attr, err, 1); + } else if (object == MT_COLOR_INDEX_AUTHOR) { + r = add_pattern (&ColorIndexAuthorList, buf->data, 1, fg, bg, attr, err, 1); set_option (OPTFORCEREDRAWINDEX); - } - else if (object == MT_COLOR_INDEX_AUTHOR) - { - r = add_pattern (&ColorIndexAuthorList, buf->data, - 1, fg, bg, attr, err, 1); + } else if (object == MT_COLOR_INDEX_FLAGS) { + r = add_pattern (&ColorIndexFlagsList, buf->data, 1, fg, bg, attr, err, 1); set_option (OPTFORCEREDRAWINDEX); - } - else if (object == MT_COLOR_INDEX_FLAGS) - { - r = add_pattern (&ColorIndexFlagsList, buf->data, - 1, fg, bg, attr, err, 1); + } else if (object == MT_COLOR_INDEX_SUBJECT) { + r = add_pattern (&ColorIndexSubjectList, buf->data, 1, fg, bg, attr, err, 1); set_option (OPTFORCEREDRAWINDEX); } else if (object == MT_COLOR_QUOTED) diff --git a/curs_lib.c b/curs_lib.c index 51fcd78f1..3567e6363 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -798,13 +798,12 @@ void mutt_format_string (char *dest, size_t destlen, if (escaped) { escaped = 0; w = 0; - } - else if (arboreal && wc == M_SPECIAL_INDEX) { + } else if (arboreal && wc == M_SPECIAL_INDEX) { escaped = 1; w = 0; - } - else if (arboreal && wc < M_TREE_MAX) + } else if (arboreal && wc < M_TREE_MAX) { w = 1; /* hack */ + } else { #ifdef HAVE_ISWBLANK @@ -1041,8 +1040,7 @@ int mutt_strwidth (const char *s) memset (&mbstate, 0, sizeof (mbstate)); for (w=0; n && (k = mbrtowc (&wc, s, n, &mbstate)); s += k, n -= k) { - if (*s == M_SPECIAL_INDEX) - { + if (*s == M_SPECIAL_INDEX) { s += 2; /* skip the index coloring sequence */ k = 0; continue; diff --git a/hdrline.c b/hdrline.c index 6d15fb9a5..a60ca2578 100644 --- a/hdrline.c +++ b/hdrline.c @@ -103,32 +103,36 @@ static int first_mailing_list (char *buf, size_t buflen, ADDRESS *a) return 0; } -/* Takes the color to embed, the buffer to manipulate and the buffer length as +/** + * add_index_color - XXX + * + * Takes the color to embed, the buffer to manipulate and the buffer length as * arguments. - * Returns the number of chars written. */ -static size_t add_index_color(char *buf, size_t buflen, - format_flag flags, char color) + * Returns the number of chars written. + */ +static size_t +add_index_color (char *buf, size_t buflen, format_flag flags, char color) { - int len; + int len; - /* only add color markers if we are operating on main index entries. */ - if (!(flags & M_FORMAT_INDEX)) - return 0; + /* only add color markers if we are operating on main index entries. */ + if (!(flags & M_FORMAT_INDEX)) + return 0; - if (color == MT_COLOR_INDEX) { /* buf might be uninitialized other cases */ - len = mutt_strlen(buf); - buf += len; - buflen -= len; - } + if (color == MT_COLOR_INDEX) { /* buf might be uninitialized other cases */ + len = mutt_strlen (buf); + buf += len; + buflen -= len; + } - if (buflen < 2) - return 0; + if (buflen < 2) + return 0; - buf[0] = M_SPECIAL_INDEX; - buf[1] = color; - buf[2] = '\0'; + buf[0] = M_SPECIAL_INDEX; + buf[1] = color; + buf[2] = '\0'; - return 2; + return 2; } static void make_from (ENVELOPE *hdr, char *buf, size_t len, int do_lists) @@ -294,9 +298,9 @@ hdr_format_str (char *dest, case 'A': if(hdr->env->reply_to && hdr->env->reply_to->mailbox) { - colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); - mutt_format_s (dest+colorlen, destlen-colorlen, prefix, mutt_addr_for_display (hdr->env->reply_to)); - add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); + mutt_format_s (dest + colorlen, destlen - colorlen, prefix, mutt_addr_for_display (hdr->env->reply_to)); + add_index_color (dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); break; } /* fall through if 'A' returns nothing */ @@ -304,9 +308,9 @@ hdr_format_str (char *dest, case 'a': if(hdr->env->from && hdr->env->from->mailbox) { - colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); - mutt_format_s (dest+colorlen, destlen-colorlen, prefix, mutt_addr_for_display (hdr->env->from)); - add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); + mutt_format_s (dest + colorlen, destlen - colorlen, prefix, mutt_addr_for_display (hdr->env->from)); + add_index_color (dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); } else dest[0] = '\0'; @@ -339,16 +343,16 @@ hdr_format_str (char *dest, break; case 'c': - colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_SIZE); + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_SIZE); mutt_pretty_size (buf2, sizeof (buf2), (long) hdr->content->length); - mutt_format_s (dest+colorlen, destlen-colorlen, prefix, buf2); - add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); + mutt_format_s (dest + colorlen, destlen - colorlen, prefix, buf2); + add_index_color (dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); break; case 'C': - colorlen = add_index_color(fmt, sizeof(fmt), flags, MT_COLOR_INDEX_NUMBER); - snprintf (fmt+colorlen, sizeof(fmt)-colorlen, "%%%sd", prefix); - add_index_color(fmt+colorlen, sizeof(fmt)-colorlen, flags, MT_COLOR_INDEX); + colorlen = add_index_color (fmt, sizeof (fmt), flags, MT_COLOR_INDEX_NUMBER); + snprintf (fmt + colorlen, sizeof (fmt) - colorlen, "%%%sd", prefix); + add_index_color (fmt + colorlen, sizeof (fmt) - colorlen, flags, MT_COLOR_INDEX); snprintf (dest, destlen, fmt, hdr->msgno + 1); break; @@ -447,9 +451,9 @@ hdr_format_str (char *dest, if (do_locales) setlocale (LC_TIME, "C"); - colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_DATE); - mutt_format_s (dest+colorlen, destlen-colorlen, prefix, buf2); - add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_DATE); + mutt_format_s (dest + colorlen, destlen - colorlen, prefix, buf2); + add_index_color (dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); if (len > 0 && op != 'd' && op != 'D') /* Skip ending op */ src = cp + 1; @@ -480,10 +484,10 @@ hdr_format_str (char *dest, case 'F': if (!optional) { - colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); make_from (hdr->env, buf2, sizeof (buf2), 0); - mutt_format_s (dest+colorlen, destlen-colorlen, prefix, buf2); - add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); + mutt_format_s (dest + colorlen, destlen - colorlen, prefix, buf2); + add_index_color (dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); } else if (mutt_addr_is_user (hdr->env->from)) optional = 0; @@ -509,9 +513,9 @@ hdr_format_str (char *dest, if (!optional) { snprintf (fmt, sizeof (fmt), "%%%sd", prefix); - colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_SIZE); - snprintf (dest+colorlen, destlen-colorlen, fmt, (int) hdr->lines); - add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_SIZE); + snprintf (dest + colorlen, destlen - colorlen, fmt, (int) hdr->lines); + add_index_color (dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); } else if (hdr->lines <= 0) optional = 0; @@ -520,10 +524,10 @@ hdr_format_str (char *dest, case 'L': if (!optional) { - colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); make_from (hdr->env, buf2, sizeof (buf2), 1); - mutt_format_s (dest+colorlen, destlen-colorlen, prefix, buf2); - add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); + mutt_format_s (dest + colorlen, destlen - colorlen, prefix, buf2); + add_index_color (dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); } else if (!check_for_mailing_list (hdr->env->to, NULL, NULL, 0) && !check_for_mailing_list (hdr->env->cc, NULL, NULL, 0)) @@ -543,9 +547,9 @@ hdr_format_str (char *dest, break; case 'n': - colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); - mutt_format_s (dest+colorlen, destlen-colorlen, prefix, mutt_get_name (hdr->env->from)); - add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_AUTHOR); + mutt_format_s (dest + colorlen, destlen - colorlen, prefix, mutt_get_name (hdr->env->from)); + add_index_color (dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); break; case 'N': @@ -580,15 +584,14 @@ hdr_format_str (char *dest, snprintf (fmt, sizeof (fmt), "%%%sd", prefix); if (!optional) { - colorlen = add_index_color(dest, destlen, flags, + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_COLLAPSED); if (threads && is_index && hdr->collapsed && hdr->num_hidden > 1) { - snprintf (dest+colorlen, destlen-colorlen, fmt, hdr->num_hidden); - add_index_color(dest, destlen-colorlen, flags, MT_COLOR_INDEX); - } - else if (is_index && threads) { - mutt_format_s (dest+colorlen, destlen-colorlen, prefix, " "); - add_index_color(dest, destlen-colorlen, flags, MT_COLOR_INDEX); + snprintf (dest + colorlen, destlen - colorlen, fmt, hdr->num_hidden); + add_index_color (dest, destlen - colorlen, flags, MT_COLOR_INDEX); + } else if (is_index && threads) { + mutt_format_s (dest + colorlen, destlen - colorlen, prefix, " "); + add_index_color (dest, destlen - colorlen, flags, MT_COLOR_INDEX); } else *dest = '\0'; @@ -626,9 +629,9 @@ hdr_format_str (char *dest, { if (flags & M_FORMAT_FORCESUBJ) { - colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_SUBJECT); - mutt_format_s (dest+colorlen, destlen-colorlen, "", NONULL (hdr->env->subject)); - add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_SUBJECT); + mutt_format_s (dest + colorlen, destlen - colorlen, "", NONULL (hdr->env->subject)); + add_index_color (dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); snprintf (buf2, sizeof (buf2), "%s%s", hdr->tree, dest); mutt_format_s_tree (dest, destlen, prefix, buf2); } @@ -636,9 +639,9 @@ hdr_format_str (char *dest, mutt_format_s_tree (dest, destlen, prefix, hdr->tree); } else { - colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_SUBJECT); - mutt_format_s (dest+colorlen, destlen-colorlen, prefix, NONULL (hdr->env->subject)); - add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_SUBJECT); + mutt_format_s (dest + colorlen, destlen - colorlen, prefix, NONULL (hdr->env->subject)); + add_index_color (dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); } break; @@ -664,9 +667,9 @@ hdr_format_str (char *dest, a short string passed into this routine */ buf2[0] = ch; buf2[1] = 0; - colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_FLAGS); - mutt_format_s (dest+colorlen, destlen-colorlen, prefix, buf2); - add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_FLAGS); + mutt_format_s (dest + colorlen, destlen - colorlen, prefix, buf2); + add_index_color (dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); break; case 't': @@ -738,9 +741,9 @@ hdr_format_str (char *dest, hdr->tagged ? '*' : (hdr->flagged ? '!' : (Tochars && ((i = mutt_user_is_recipient (hdr)) < mutt_strlen (Tochars)) ? Tochars[i] : ' '))); - colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_FLAGS); - mutt_format_s (dest+colorlen, destlen-colorlen, prefix, buf2); - add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_FLAGS); + mutt_format_s (dest + colorlen, destlen - colorlen, prefix, buf2); + add_index_color (dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); break; case 'X': @@ -760,9 +763,9 @@ hdr_format_str (char *dest, if (optional) optional = hdr->env->x_label ? 1 : 0; - colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_LABEL); - mutt_format_s (dest+colorlen, destlen-colorlen, prefix, NONULL (hdr->env->x_label)); - add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_LABEL); + mutt_format_s (dest + colorlen, destlen - colorlen, prefix, NONULL (hdr->env->x_label)); + add_index_color (dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); break; case 'Y': @@ -788,12 +791,12 @@ hdr_format_str (char *dest, if (optional) optional = i; - colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_LABEL); + colorlen = add_index_color (dest, destlen, flags, MT_COLOR_INDEX_LABEL); if (i) - mutt_format_s (dest+colorlen, destlen-colorlen, prefix, NONULL (hdr->env->x_label)); + mutt_format_s (dest + colorlen, destlen - colorlen, prefix, NONULL (hdr->env->x_label)); else - mutt_format_s (dest+colorlen, destlen-colorlen, prefix, ""); - add_index_color(dest+colorlen, destlen-colorlen, flags, MT_COLOR_INDEX); + mutt_format_s (dest + colorlen, destlen - colorlen, prefix, ""); + add_index_color (dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); break; diff --git a/menu.c b/menu.c index 1be3b9461..46ea6c269 100644 --- a/menu.c +++ b/menu.c @@ -27,31 +27,36 @@ char* SearchBuffers[MENU_MAX]; -static int get_color(int index, unsigned char *s) { - COLOR_LINE *color; - HEADER *hdr = Context->hdrs[Context->v2r[index]]; - int type = *s; - - switch (type) { - case MT_COLOR_INDEX_SUBJECT: - color = ColorIndexSubjectList; - break; - case MT_COLOR_INDEX_AUTHOR: - color = ColorIndexAuthorList; - break; - case MT_COLOR_INDEX_FLAGS: - color = ColorIndexFlagsList; - break; - default: - return ColorDefs[type]; - } +/** + * get_color - XXX + */ +static int +get_color (int index, unsigned char *s) +{ + COLOR_LINE *color; + HEADER *hdr = Context->hdrs[Context->v2r[index]]; + int type = *s; + + switch (type) { + case MT_COLOR_INDEX_AUTHOR: + color = ColorIndexAuthorList; + break; + case MT_COLOR_INDEX_FLAGS: + color = ColorIndexFlagsList; + break; + case MT_COLOR_INDEX_SUBJECT: + color = ColorIndexSubjectList; + break; + default: + return ColorDefs[type]; + } - for (; color; color = color->next) - if (mutt_pattern_exec (color->color_pattern, M_MATCH_FULL_ADDRESS, - Context, hdr)) - return color->pair; + for (; color; color = color->next) + if (mutt_pattern_exec (color->color_pattern, M_MATCH_FULL_ADDRESS, + Context, hdr)) + return color->pair; - return 0; + return 0; } static void print_enriched_string (int index, int attr, unsigned char *s, int do_color) @@ -186,21 +191,20 @@ static void print_enriched_string (int index, int attr, unsigned char *s, int do } if (do_color) ATTRSET(attr); } - else if (*s == M_SPECIAL_INDEX) - { + else if (*s == M_SPECIAL_INDEX) { s++; if (do_color) { - if (*s == MT_COLOR_INDEX) - attrset(attr); - else - { - if (get_color(index, s) == 0) - attron(attr); - else - attron(get_color(index, s)); + if (*s == MT_COLOR_INDEX) { + attrset (attr); + } else { + if (get_color (index, s) == 0) { + attron (attr); + } else { + attron (get_color (index, s)); + } } } - s++; + s++; n -= 2; } else if ((k = mbrtowc (&wc, (char *)s, n, &mbstate)) > 0) @@ -344,7 +348,7 @@ void menu_redraw_motion (MUTTMENU *menu) menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent); menu_pad_string (buf, sizeof (buf)); move (menu->oldcurrent + menu->offset - menu->top, 3); - print_enriched_string (menu->oldcurrent, menu->color(menu->oldcurrent), (unsigned char *) buf, 1); + print_enriched_string (menu->oldcurrent, menu->color (menu->oldcurrent), (unsigned char *) buf, 1); } /* now draw it in the new location */ @@ -356,14 +360,14 @@ void menu_redraw_motion (MUTTMENU *menu) /* erase the current indicator */ menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent); menu_pad_string (buf, sizeof (buf)); - print_enriched_string (menu->oldcurrent, menu->color(menu->oldcurrent), (unsigned char *) buf, 1); + print_enriched_string (menu->oldcurrent, menu->color (menu->oldcurrent), (unsigned char *) buf, 1); /* now draw the new one to reflect the change */ menu_make_entry (buf, sizeof (buf), menu, menu->current); menu_pad_string (buf, sizeof (buf)); SETCOLOR(MT_COLOR_INDICATOR); move(menu->current - menu->top + menu->offset, 0); - print_enriched_string (menu->current, menu->color(menu->current), (unsigned char *) buf, 0); + print_enriched_string (menu->current, menu->color (menu->current), (unsigned char *) buf, 0); } menu->redraw &= REDRAW_STATUS; NORMAL_COLOR; diff --git a/mutt_curses.h b/mutt_curses.h index 56ede9b26..e8bb9aa01 100644 --- a/mutt_curses.h +++ b/mutt_curses.h @@ -187,9 +187,9 @@ extern int ColorDefs[]; extern COLOR_LINE *ColorHdrList; extern COLOR_LINE *ColorBodyList; extern COLOR_LINE *ColorIndexList; -extern COLOR_LINE *ColorIndexSubjectList; extern COLOR_LINE *ColorIndexAuthorList; extern COLOR_LINE *ColorIndexFlagsList; +extern COLOR_LINE *ColorIndexSubjectList; void ci_init_color (void); void ci_start_color (void); -- 2.50.1