1
1

miscellaneous fixes: skip over invalid wide characters, and if wcwidth()

returns -1, don't add its value to any column counter; also update
another copyright year


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2219 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Этот коммит содержится в:
David Lawrence Ramsey 2005-01-03 06:56:38 +00:00
родитель 6e1cd06b96
Коммит 956da0d0e1
2 изменённых файлов: 44 добавлений и 34 удалений

Просмотреть файл

@ -2,7 +2,7 @@
/************************************************************************** /**************************************************************************
* utils.c * * utils.c *
* * * *
* Copyright (C) 1999-2004 Chris Allegretta * * Copyright (C) 1999-2005 Chris Allegretta *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2, or (at your option) * * the Free Software Foundation; either version 2, or (at your option) *
@ -188,16 +188,24 @@ int parse_char(const char *str, int *chr, size_t *col
(*col)++; (*col)++;
wide_str = control_rep((unsigned char)wide_str); wide_str = control_rep((unsigned char)wide_str);
if (wctomb(ctrl_wide_str, (wchar_t)wide_str) != -1) if (wctomb(ctrl_wide_str, (wchar_t)wide_str) != -1) {
*col += wcwidth(wide_str); int width = wcwidth(wide_str);
if (width != -1)
*col += width;
}
else else
(*col)++; (*col)++;
free(ctrl_wide_str); free(ctrl_wide_str);
/* If we have a normal character, get its width in columns /* If we have a normal character, get its width in columns
* normally. */ * normally. */
} else } else {
*col += wcwidth(wide_str); int width = wcwidth(wide_str);
if (width != -1)
*col += width;
}
} }
} else { } else {
#endif #endif

Просмотреть файл

@ -2119,8 +2119,6 @@ size_t display_string_len(const char *buf, size_t start_col, size_t
if (bad_wide_buf_len != -1) if (bad_wide_buf_len != -1)
retval += bad_wide_buf_len; retval += bad_wide_buf_len;
else
retval++;
free(bad_wide_buf); free(bad_wide_buf);
} else { } else {
@ -2242,15 +2240,10 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
wide_buf = control_rep((unsigned char)wide_buf); wide_buf = control_rep((unsigned char)wide_buf);
#ifdef NANO_WIDE #ifdef NANO_WIDE
if (!ISSET(NO_UTF8)) { if (!ISSET(NO_UTF8))
ctrl_wide_buf_len = wctomb(ctrl_wide_buf, ctrl_wide_buf_len = wctomb(ctrl_wide_buf,
(wchar_t)wide_buf); (wchar_t)wide_buf);
else {
if (ctrl_wide_buf_len == -1) {
ctrl_wide_buf_len = 1;
ctrl_wide_buf[0] = ' ';
}
} else {
#endif #endif
ctrl_wide_buf_len = 1; ctrl_wide_buf_len = 1;
ctrl_wide_buf[0] = (unsigned char)wide_buf; ctrl_wide_buf[0] = (unsigned char)wide_buf;
@ -2263,10 +2256,21 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
free(ctrl_wide_buf); free(ctrl_wide_buf);
start_col++; #ifdef NANO_WIDE
if (!ISSET(NO_UTF8)) {
int width = wcwidth((wchar_t)wide_buf);
if (width != -1)
start_col += width;
} else
#endif
start_col++;
start_index += wide_buf_len; start_index += wide_buf_len;
} }
} else if (wcwidth(wide_buf) > 1) { }
#ifdef NANO_WIDE
else if (wcwidth((wchar_t)wide_buf) > 1) {
/* If dollars is TRUE, make room for the "$" at the /* If dollars is TRUE, make room for the "$" at the
* beginning of the line. Also make sure that we don't try * beginning of the line. Also make sure that we don't try
* to display only part of a multicolumn character there. */ * to display only part of a multicolumn character there. */
@ -2280,6 +2284,7 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
start_col++; start_col++;
start_index += wide_buf_len; start_index += wide_buf_len;
} }
#endif
} }
while (index < alloc_len && buf[start_index] != '\0') { while (index < alloc_len && buf[start_index] != '\0') {
@ -2321,15 +2326,10 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
wide_buf = control_rep((unsigned char)wide_buf); wide_buf = control_rep((unsigned char)wide_buf);
#ifdef NANO_WIDE #ifdef NANO_WIDE
if (!ISSET(NO_UTF8)) { if (!ISSET(NO_UTF8))
ctrl_wide_buf_len = wctomb(ctrl_wide_buf, ctrl_wide_buf_len = wctomb(ctrl_wide_buf,
(wchar_t)wide_buf); (wchar_t)wide_buf);
else {
if (ctrl_wide_buf_len == -1) {
ctrl_wide_buf_len = 1;
ctrl_wide_buf[0] = ' ';
}
} else {
#endif #endif
ctrl_wide_buf_len = 1; ctrl_wide_buf_len = 1;
ctrl_wide_buf[0] = (unsigned char)wide_buf; ctrl_wide_buf[0] = (unsigned char)wide_buf;
@ -2342,11 +2342,15 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
free(ctrl_wide_buf); free(ctrl_wide_buf);
start_col +=
#ifdef NANO_WIDE #ifdef NANO_WIDE
!ISSET(NO_UTF8) ? wcwidth((wchar_t)wide_buf) : if (!ISSET(NO_UTF8)) {
int width = wcwidth((wchar_t)wide_buf);
if (width != -1)
start_col += width;
} else
#endif #endif
1; start_col++;
} else if (wide_buf == ' ') { } else if (wide_buf == ' ') {
converted[index++] = converted[index++] =
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC) #if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
@ -2368,11 +2372,6 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
bad_wide_buf_len = wctomb(bad_wide_buf, bad_wide_buf_len = wctomb(bad_wide_buf,
(wchar_t)wide_buf); (wchar_t)wide_buf);
if (bad_wide_buf_len == -1) {
bad_wide_buf_len = 1;
bad_wide_buf[0] = ' ';
}
for (i = 0; i < bad_wide_buf_len; i++) for (i = 0; i < bad_wide_buf_len; i++)
converted[index++] = bad_wide_buf[i]; converted[index++] = bad_wide_buf[i];
@ -2384,9 +2383,12 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
#ifdef NANO_WIDE #ifdef NANO_WIDE
} }
if (!ISSET(NO_UTF8)) if (!ISSET(NO_UTF8)) {
start_col += wcwidth((wchar_t)wide_buf); int width = wcwidth((wchar_t)wide_buf);
else
if (width != -1)
start_col += width;
} else
#endif #endif
start_col++; start_col++;
} }