Re: Bug#317549: tin: Linebreaks between words when lines are longer than window width
Urs Janßen <[email protected]>
| Newsgroups | gmane.network.tin.devel |
|---|---|
| Message-ID | <[email protected]> |
On Sat, Jul 09, 2005 at 08:04:35PM +0200, Urs JanÃen wrote:
> > There is a small issue related to this though. tin generates a warning
> > when a line in a composed message exceeds 78 characters. It's good
> > feature but actually it counts bytes not characters. I use UTF-8 locale
> > and messages often contain multibyte characters. Even when I save my
> > message with no longer lines than 72 characters I get this warning from
> > lines which contain enough multibyte characters to exceed the limit of 78
> > bytes per line.
>
> yes, this is a bug in post.c:check_article_to_be_posted() ~ line 1118
> the code is much older than tins multibyte support and when we added
> the multibyte stuff we failed to update that bits of code as well...
something like the following (untested) should fix this:
--- post.c 2005-07-10 02:07:33.541466569 +0200
+++ post.c 2005-07-10 02:20:51.870511937 +0200
@@ -1114,15 +1114,33 @@
}
#endif /* CHARSET_CONVERSION */
- /* FIXME: this code is wrong for a multibyte environment */
- col = 0;
- for (cp = line; *cp; cp++) {
- if (!contains_8bit && !isascii(*cp))
- contains_8bit = TRUE;
- if (*cp == '\t')
- col += 8 - (col % 8);
- else
+ {
+#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
+ int num_bytes;
+ wchar_t wc;
+#endif /* MULTIBYTE_ABLE && !NO_LOCALE */
+
+ col = 0;
+ for (cp = line; *cp; ) {
+ if (*cp == '\t') {
+ col += 8 - (col % 8);
+ cp++;
+ } else {
+#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
+ if ((num_bytes = mbtowc(&wc, cp, MB_CUR_MAX)) != -1) {
+ cp += num_bytes;
+ if (!contains_8bit && num_bytes > 1)
+ contains_8bit = TRUE;
+ } else
+ cp++;
+#else
+ if (!contains_8bit && !isascii(*cp))
+ contains_8bit = TRUE;
+ cp++;
+#endif
col++;
+ }
+ }
}
if (col > MAX_COL && !got_long_line) {
setup_check_article_screen(&init);