From: Richard Russon Date: Thu, 25 Jul 2019 14:22:33 +0000 (+0100) Subject: window: don't pass a Window when an int will do X-Git-Tag: 2019-10-25~107^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ea6dc5319d1067764e8a27d09514b16fd72407fa;p=neomutt window: don't pass a Window when an int will do --- diff --git a/copy.c b/copy.c index 8d45e4cb5..609082edf 100644 --- a/copy.c +++ b/copy.c @@ -348,7 +348,7 @@ int mutt_copy_hdr(FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end, if (chflags & (CH_DECODE | CH_PREFIX)) { const char *pre = (chflags & CH_PREFIX) ? prefix : NULL; - const int wraplen = mutt_window_wrap_cols(MuttIndexWindow, C_Wrap); + const int wraplen = mutt_window_wrap_cols(MuttIndexWindow->cols, C_Wrap); if (mutt_write_one_header(fp_out, 0, headers[x], pre, wraplen, chflags) == -1) { @@ -504,7 +504,7 @@ int mutt_copy_header(FILE *fp_in, struct Email *e, FILE *fp_out, } if (mutt_write_one_header( fp_out, "X-Label", temp_hdr, (chflags & CH_PREFIX) ? prefix : 0, - mutt_window_wrap_cols(MuttIndexWindow, C_Wrap), chflags) == -1) + mutt_window_wrap_cols(MuttIndexWindow->cols, C_Wrap), chflags) == -1) { return -1; } @@ -524,8 +524,10 @@ int mutt_copy_header(FILE *fp_in, struct Email *e, FILE *fp_out, } if (mutt_write_one_header( fp_out, "Subject", temp_hdr, (chflags & CH_PREFIX) ? prefix : 0, - mutt_window_wrap_cols(MuttIndexWindow, C_Wrap), chflags) == -1) + mutt_window_wrap_cols(MuttIndexWindow->cols, C_Wrap), chflags) == -1) + { return -1; + } if (!(chflags & CH_DECODE)) FREE(&temp_hdr); } diff --git a/mutt_window.c b/mutt_window.c index 515b29fbf..39841ffbd 100644 --- a/mutt_window.c +++ b/mutt_window.c @@ -286,19 +286,19 @@ void mutt_window_reflow_message_rows(int mw_rows) } /** - * mutt_window_wrap_cols - Calculate the wrap column for a Window - * @param win Window - * @param wrap Wrap config + * mutt_window_wrap_cols - Calculate the wrap column for a given screen width + * @param width Screen width + * @param wrap Wrap config * @retval num Column that text should be wrapped at * * The wrap variable can be negative, meaning there should be a right margin. */ -int mutt_window_wrap_cols(struct MuttWindow *win, short wrap) +int mutt_window_wrap_cols(int width, short wrap) { if (wrap < 0) - return (win->cols > -wrap) ? (win->cols + wrap) : win->cols; + return (width > -wrap) ? (width + wrap) : width; else if (wrap) - return (wrap < win->cols) ? wrap : win->cols; + return (wrap < width) ? wrap : width; else - return win->cols; + return width; } diff --git a/mutt_window.h b/mutt_window.h index e3493ff6c..f0502b6a7 100644 --- a/mutt_window.h +++ b/mutt_window.h @@ -58,6 +58,6 @@ int mutt_window_mvaddstr(struct MuttWindow *win, int row, int col, const char * int mutt_window_mvprintw(struct MuttWindow *win, int row, int col, const char *fmt, ...); void mutt_window_reflow_message_rows(int mw_rows); void mutt_window_reflow(void); -int mutt_window_wrap_cols(struct MuttWindow *win, short wrap); +int mutt_window_wrap_cols(int width, short wrap); #endif /* MUTT_MUTT_WINDOW_H */ diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index 96df17fe8..7fc8e1752 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -1059,7 +1059,7 @@ int mutt_protected_headers_handler(struct Body *a, struct State *s) state_mark_protected_header(s); mutt_write_one_header(s->fp_out, "Subject", a->mime_headers->subject, s->prefix, - mutt_window_wrap_cols(MuttIndexWindow, C_Wrap), + mutt_window_wrap_cols(MuttIndexWindow->cols, C_Wrap), (s->flags & MUTT_DISPLAY) ? CH_DISPLAY : CH_NO_FLAGS); state_puts("\n", s); } diff --git a/pager.c b/pager.c index 267d33f82..ff5d8ff6c 100644 --- a/pager.c +++ b/pager.c @@ -1425,22 +1425,22 @@ static int fill_buffer(FILE *fp, LOFF_T *last_pos, LOFF_T offset, unsigned char /** * format_line - Display a line of text in the pager - * @param[out] line_info Line info - * @param[in] n Line number (index into line_info) - * @param[in] buf Text to display - * @param[in] flags Flags, see #PagerFlags - * @param[out] pa ANSI attributes used - * @param[in] cnt Length of text buffer - * @param[out] pspace Index of last whitespace character - * @param[out] pvch Number of bytes read - * @param[out] pcol Number of columns used - * @param[out] pspecial Attribute flags, e.g. A_UNDERLINE - * @param[in] pager_window Window to write to + * @param[out] line_info Line info + * @param[in] n Line number (index into line_info) + * @param[in] buf Text to display + * @param[in] flags Flags, see #PagerFlags + * @param[out] pa ANSI attributes used + * @param[in] cnt Length of text buffer + * @param[out] pspace Index of last whitespace character + * @param[out] pvch Number of bytes read + * @param[out] pcol Number of columns used + * @param[out] pspecial Attribute flags, e.g. A_UNDERLINE + * @param[in] width Width of screen (to wrap to) * @retval num Number of characters displayed */ static int format_line(struct Line **line_info, int n, unsigned char *buf, - PagerFlags flags, struct AnsiAttr *pa, int cnt, int *pspace, - int *pvch, int *pcol, int *pspecial, struct MuttWindow *pager_window) + PagerFlags flags, struct AnsiAttr *pa, int cnt, + int *pspace, int *pvch, int *pcol, int *pspecial, int width) { int space = -1; /* index of the last space or TAB */ int col = C_Markers ? (*line_info)[n].continuation : 0; @@ -1448,11 +1448,10 @@ static int format_line(struct Line **line_info, int n, unsigned char *buf, int ch, vch, last_special = -1, special = 0, t; wchar_t wc; mbstate_t mbstate; - int wrap_cols = - mutt_window_wrap_cols(pager_window, (flags & MUTT_PAGER_NOWRAP) ? 0 : C_Wrap); + int wrap_cols = mutt_window_wrap_cols(width, (flags & MUTT_PAGER_NOWRAP) ? 0 : C_Wrap); if (check_attachment_marker((char *) buf) == 0) - wrap_cols = pager_window->cols; + wrap_cols = width; /* FIXME: this should come from line_info */ memset(&mbstate, 0, sizeof(mbstate)); @@ -1802,7 +1801,7 @@ static int display_line(FILE *fp, LOFF_T *last_pos, struct Line **line_info, /* now chose a good place to break the line */ cnt = format_line(line_info, n, buf, flags, NULL, b_read, &ch, &vch, &col, - &special, pager_window); + &special, pager_window->cols); buf_ptr = buf + cnt; /* move the break point only if smart_wrap is set */ @@ -1850,7 +1849,8 @@ static int display_line(FILE *fp, LOFF_T *last_pos, struct Line **line_info, } /* display the line */ - format_line(line_info, n, buf, flags, &a, cnt, &ch, &vch, &col, &special, pager_window); + format_line(line_info, n, buf, flags, &a, cnt, &ch, &vch, &col, &special, + pager_window->cols); /* avoid a bug in ncurses... */ #ifndef USE_SLANG_CURSES diff --git a/rfc3676.c b/rfc3676.c index 41000e96b..7a2246719 100644 --- a/rfc3676.c +++ b/rfc3676.c @@ -191,7 +191,7 @@ static void flush_par(struct State *s, struct FlowedState *fst) */ static int quote_width(struct State *s, int ql) { - int width = mutt_window_wrap_cols(MuttIndexWindow, C_ReflowWrap); + int width = mutt_window_wrap_cols(MuttIndexWindow->cols, C_ReflowWrap); if (C_TextFlowed && (s->flags & MUTT_REPLYING)) { /* When replying, force a wrap at FLOWED_MAX to comply with RFC3676