[Pine-info] [PATCH] Margins in exported messages
Andrej Lajovic
andrej.lajovic at guest.arnes.si
Wed Sep 6 16:05:03 PDT 2006
I have found a bug in pine (4.64) which affects the margins in exported
messages. The following procedure illustrates the effect:
- open an xterm (or any terminal emulator) and set its size to 80 columns
- run pine
- in Setup/Config set "viewer-margin-right" to "80c"
- export a message to file
- resize the terminal to 120 columns
- export the same message to a different file
- compare the formatting
The width of the text clearly decreases with increasing terminal size and
this effect can even cause pine to hang while exporting a message on very
large terminals.
The problem lies in the function format_view_margin (mailview.c), which
computes margins assuming the text width is ps_global->ttyo->screen_cols,
regardless of whether the text is really bound for display. The solution
is to explicitly pass the requested text width to the function.
A patch is attached below, please test.
Kind regards,
Andrej Lajovic
------------8<------------(mailview.c.patch)------------8<------------
--- mailview.c.orig 2005-09-20 20:26:20.000000000 +0200
+++ mailview.c 2006-09-06 23:27:03.000000000 +0200
@@ -293,7 +293,7 @@
int format_raw_hdr_string PROTO((char *, char *, gf_io_t, int));
int format_env_puts PROTO((char *, gf_io_t));
long format_size_guess PROTO((BODY *));
-int *format_view_margin PROTO((void));
+int *format_view_margin PROTO((int));
void pine_rfc822_write_address_noquote PROTO((ADDRESS *,
gf_io_t, int *));
void pine2_rfc822_write_address_noquote PROTO((char *,ADDRESS *,int *));
@@ -1608,9 +1608,9 @@
&& !(flgs & FM_NOCOLOR)
&& pico_usingcolor())
wrapflags |= GFW_USECOLOR;
- gf_link_filter(gf_wrap, gf_wrap_filter_opt(ps_global->ttyo->screen_cols,
- ps_global->ttyo->screen_cols,
- format_view_margin(),
+ gf_link_filter(gf_wrap, gf_wrap_filter_opt(width,
+ width,
+ format_view_margin(width),
0,
wrapflags));
gf_link_filter(gf_nvtnl_local, NULL);
@@ -1661,7 +1661,7 @@
* can be only a fraction of screen_cols we've already checked
* is less than #define MAX_SCREEN_COLS, right?
*/
- margin = format_view_margin();
+ margin = format_view_margin(width);
strncpy(margin_str, repeat_char(margin[0], ' '), sizeof(margin_str)-1);
margin_str[sizeof(margin_str)-1] = '\0';
@@ -1879,7 +1879,7 @@
if(!(gf_puts(NEWLINE, pc)
&& !format_editorial(tmp_20k_buf,
- ps_global->ttyo->screen_cols, pc)
+ width, pc)
&& gf_puts(NEWLINE, pc) && gf_puts(NEWLINE, pc)))
goto write_error;
@@ -1905,8 +1905,8 @@
else if(a->body->subtype
&& strucmp(a->body->subtype, "external-body") == 0) {
char es[512];
- int *m = format_view_margin();
- int c = ps_global->ttyo->screen_cols;
+ int *m = format_view_margin(width);
+ int c = width;
c -= (m != NULL) ? m[0] : 0;
c -= (m != NULL) ? m[1] : 0;
@@ -1985,7 +1985,7 @@
if(tmp)
fs_give((void **)&tmp);
- margin = format_view_margin();
+ margin = format_view_margin(width);
width -= (margin[0] + margin[1]);
if(width > 40){
@@ -2246,7 +2246,8 @@
* format_view_margin - return sane value for vertical margins
*/
int *
-format_view_margin()
+format_view_margin(width)
+ int width;
{
static int margin[2];
char tmp[100], e[200], *err, lastchar = 0;
@@ -2288,7 +2289,7 @@
else
leftm = left;
- leftm = min(max(0, leftm), ps_global->ttyo->screen_cols);
+ leftm = min(max(0, leftm), width);
}
}
}
@@ -2311,17 +2312,17 @@
}
else{
if(lastchar == 'c')
- rightm = ps_global->ttyo->screen_cols - right;
+ rightm = width - right;
else
rightm = right;
- rightm = min(max(0, rightm), ps_global->ttyo->screen_cols);
+ rightm = min(max(0, rightm), width);
}
}
}
if((rightm > 0 || leftm > 0) && rightm >= 0 && leftm >= 0
- && ps_global->ttyo->screen_cols - rightm - leftm >= 8){
+ && width - rightm - leftm >= 8){
margin[0] = leftm;
margin[1] = rightm;
}
@@ -5836,7 +5837,7 @@
wrapit = 0; /* wrap already handled! */
filters[filtcnt].filter = gf_html2plain;
filters[filtcnt++].data = gf_html2plain_opt(NULL, column,
- format_view_margin(),
+ format_view_margin(column),
handlesp, opts);
}
@@ -5893,7 +5894,7 @@
filters[filtcnt++].data = gf_wrap_filter_opt(wrapit, column,
(flags & FM_NOINDENT)
? 0
- : format_view_margin(),
+ : format_view_margin(column),
0, wrapflags);
}
@@ -5915,7 +5916,7 @@
dq.is_flowed = is_flowed_msg;
dq.indent_length = (wrapit && !(flags & FM_NOWRAP)
&& !(flags & FM_NOINDENT))
- ? format_view_margin()[0]
+ ? format_view_margin(column)[0]
: 0;
dq.saved_line = &free_this;
dq.handlesp = handlesp;
@@ -6296,7 +6297,7 @@
gf_link_filter(gf_wrap,
gf_wrap_filter_opt(column, column,
(flags & FM_NOINDENT)
- ? 0 : format_view_margin(), 4,
+ ? 0 : format_view_margin(column), 4,
GFW_ONCOMMA | (handlesp ? GFW_HANDLES : 0)));
if(prefix && *prefix)
More information about the Pine-info
mailing list