[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Use gnulib's mbswidth module
From: |
Miloslav Trmac |
Subject: |
[PATCH] Use gnulib's mbswidth module |
Date: |
Wed, 24 Jan 2007 20:39:30 +0100 |
User-agent: |
Thunderbird 1.5.0.9 (X11/20061219) |
Hello,
the attached patch against texinfo CVS modifies makeinfo to use the
mbswidth module from gnulib instead of using private string_width ().
mbswidth() requires mbrtowc (), while string_width () required only
mbtowc(). Therefore this patch requires newer a newer libc to support
multibyte characters; OTOH this allows correct handling of partial
multibyte characters when filling paragraphs.
To use the patch, import the mbswidth module from gnulib.
* configure.ac: Remove unnecessary wcwidth () test. Add missing
setlocale () test.
* makeinfo/makeinfo.c (string_width): Remove.
* makeinfo/makeinfo.h (string_width): Remove declaration.
* makeinfo/cmds.c (cm_center)
* makeinfo/index.c (insert_index_output_line_no, cm_printindex):
* makeinfo/makeinfo.c (do_flush_right_indentation)
* makeinfo/multi.c (output_multitable_row): Use mbswidth () and
mbsnwidth () instead of string_width ().
Thanks,
Mirek
Index: configure.ac
===================================================================
RCS file: /sources/texinfo/texinfo/configure.ac,v
retrieving revision 1.67
diff -u -r1.67 configure.ac
--- configure.ac 27 Dec 2006 16:20:17 -0000 1.67
+++ configure.ac 24 Jan 2007 19:27:41 -0000
@@ -81,8 +81,8 @@
# in theory only pre-sysvr3 systems needed this and it's not likely
# that anyone compiling new texinfo still has such a thing? we'll see.
# AC_FUNC_SETVBUF_REVERSED
-AC_CHECK_FUNCS(bzero getcwd memset setvbuf sigaction sigprocmask \
- sigsetmask strchr wcwidth)
+AC_CHECK_FUNCS(bzero getcwd memset setlocale setvbuf sigaction sigprocmask \
+ sigsetmask strchr)
AC_REPLACE_FUNCS(memcpy memmove strdup strerror)
# We want to recognize djgpp to avoid the useless warning about no
Index: makeinfo/cmds.c
===================================================================
RCS file: /sources/texinfo/texinfo/makeinfo/cmds.c,v
retrieving revision 1.68
diff -u -r1.68 cmds.c
--- makeinfo/cmds.c 7 Jan 2007 22:59:08 -0000 1.68
+++ makeinfo/cmds.c 24 Jan 2007 19:27:41 -0000
@@ -19,6 +19,7 @@
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include "system.h"
+#include "mbswidth.h"
#include "cmds.h"
#include "defun.h"
#include "files.h"
@@ -1545,7 +1546,7 @@
output_paragraph_offset = ++i;
length = output_paragraph_offset - start;
- width = string_width ((char *)(output_paragraph + start), length);
+ width = mbsnwidth ((char *)(output_paragraph + start), length, 0);
if (width < (fill_column - fudge_factor))
{
Index: makeinfo/index.c
===================================================================
RCS file: /sources/texinfo/texinfo/makeinfo/index.c,v
retrieving revision 1.21
diff -u -r1.21 index.c
--- makeinfo/index.c 11 Dec 2006 14:59:59 -0000 1.21
+++ makeinfo/index.c 24 Jan 2007 19:27:41 -0000
@@ -19,6 +19,7 @@
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include "system.h"
+#include "mbswidth.h"
#include "files.h"
#include "footnote.h"
#include "html.h"
@@ -673,11 +674,11 @@
int i = output_paragraph_offset;
while (0 < i && output_paragraph[i-1] != '\n')
i--;
- last_column = string_width ((char *)(output_paragraph + i),
- output_paragraph_offset - i);
+ last_column = mbsnwidth ((char *)(output_paragraph + i),
+ output_paragraph_offset - i, 0);
}
- out_line_no_width = string_width (out_line_no_str, strlen (out_line_no_str));
+ out_line_no_width = mbswidth (out_line_no_str, 0);
if (last_column + out_line_no_width > fill_column)
{
insert ('\n');
@@ -895,7 +896,7 @@
{
int width;
- width = string_width (index->entry, strlen (index->entry));
+ width = mbswidth (index->entry, 0);
sprintf (line, "* %*s ", width < MIN_ENTRY_COLUMNS
? -(strlen (index->entry)
+ (MIN_ENTRY_COLUMNS - width))
Index: makeinfo/makeinfo.c
===================================================================
RCS file: /sources/texinfo/texinfo/makeinfo/makeinfo.c,v
retrieving revision 1.89
diff -u -r1.89 makeinfo.c
--- makeinfo/makeinfo.c 11 Dec 2006 14:59:59 -0000 1.89
+++ makeinfo/makeinfo.c 24 Jan 2007 19:27:42 -0000
@@ -22,6 +22,7 @@
#include "system.h"
#include "getopt.h"
+#include "mbswidth.h"
#define COMPILING_MAKEINFO
#include "makeinfo.h"
@@ -39,10 +40,6 @@
#include "toc.h"
#include "xml.h"
-#ifdef HAVE_WCWIDTH
-# include <wchar.h>
-#endif
-
/* You can change some of the behavior of Makeinfo by changing the
following defines: */
@@ -2463,45 +2460,6 @@
}
}
-/* Return the number of columns necessary for displaying STRING of LEN
- bytes. */
-int
-string_width (const char *string, size_t length)
-{
-#ifdef HAVE_WCWIDTH
- int width;
-
- mbtowc (NULL, NULL, 0);
- width = 0;
- while (length > 0)
- {
- wchar_t wc;
- int l, w;
-
- l = mbtowc (&wc, string, length);
- if (l == -1)
- {
- mbtowc (NULL, NULL, 0);
- w = 1;
- l = 1;
- }
- else
- {
- if (l == 0)
- l = 1;
- w = wcwidth (wc);
- if (w == -1)
- w = 1;
- }
- width += w;
- string += l;
- length -= l;
- }
- return width;
-#endif
- return length;
-}
-
/* Return the 0-based number of the current output column */
int
current_output_column (void)
@@ -2530,7 +2488,7 @@
}
if (i < j)
{
- column += string_width ((char *)(output_paragraph + i), j - i);
+ column += mbsnwidth ((char *)(output_paragraph + i), j - i, 0);
i = j;
}
if (i < output_paragraph_offset)
@@ -2808,15 +2766,6 @@
output_paragraph_offset++;
column = current_output_column ();
output_paragraph_offset--;
- /* The string_width () in current_output_column () cannot predict
- future incoming bytes. So if output_paragraph ends in a partial
- multibyte character, its bytes are counted as separate column
- positions. This may push column past fill_column, even though the
- finished multibyte character would fit on the current line.
-
- This is too hard to fix without modifying add_char () to recieve
- complete multibyte characters at a time, and causes only slightly
- incorrect paragraph filling, so we punt. */
if (column > fill_column)
{
if (filling_enabled && !html)
@@ -3211,7 +3160,8 @@
{
int width;
- width = string_width((char *)output_paragraph, output_paragraph_offset);
+ width = mbsnwidth ((char *)output_paragraph, output_paragraph_offset - 1,
+ 0) + 1;
if (width < fill_column)
{
int i;
Index: makeinfo/makeinfo.h
===================================================================
RCS file: /sources/texinfo/texinfo/makeinfo/makeinfo.h,v
retrieving revision 1.22
diff -u -r1.22 makeinfo.h
--- makeinfo/makeinfo.h 11 Dec 2006 14:59:59 -0000 1.22
+++ makeinfo/makeinfo.h 24 Jan 2007 19:27:42 -0000
@@ -369,7 +369,6 @@
search_forward (char *string, int from),
search_forward_until_pos (char *string, int from, int end_pos),
next_nonwhitespace_character (void),
- string_width (const char *string, size_t length),
current_output_column (void),
fs_error (char *filename);
Index: makeinfo/multi.c
===================================================================
RCS file: /sources/texinfo/texinfo/makeinfo/multi.c,v
retrieving revision 1.13
diff -u -r1.13 multi.c
--- makeinfo/multi.c 11 Dec 2006 14:59:59 -0000 1.13
+++ makeinfo/multi.c 24 Jan 2007 19:27:42 -0000
@@ -21,6 +21,7 @@
Originally written by address@hidden (Paul Rubin). */
#include "system.h"
+#include "mbswidth.h"
#include "cmds.h"
#include "insertion.h"
#include "makeinfo.h"
@@ -468,7 +469,7 @@
/* Do not output trailing blanks if we're in the last column and
there will be no trailing |. */
if (i < last_column && !vsep)
- for (s = string_width ((char *)&CHAR_AT (0), j);
+ for (s = mbsnwidth ((char *)&CHAR_AT (0), j, 0);
s <= envs[i].fill_column; s++)
out_char (' ');
if (vsep)
- [PATCH] Use gnulib's mbswidth module,
Miloslav Trmac <=