add a few missing NANO_WIDE #ifdefs, and remove display_string_len()

until I can fix it to no longer cause memory corruption


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2201 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-12-27 18:53:38 +00:00
parent 4fd76bab73
commit a35bdd1f03
3 changed files with 42 additions and 102 deletions

View File

@ -52,12 +52,12 @@ CVS code -
Movement and cursor display in the edit window should now work Movement and cursor display in the edit window should now work
properly with files containing multibyte characters, and text properly with files containing multibyte characters, and text
display of such files should work properly some of the time. display of such files should work properly some of the time.
New functions control_rep(), parse_char(), move_left(), New functions control_rep(), parse_char(), move_left(), and
move_right(), and display_string_len(); changes to do_left(), move_right(); changes to do_left(), do_right(), do_delete(),
do_right(), do_delete(), breakable(), break_line(), breakable(), break_line(), do_output(), get_buffer(),
do_output(), get_buffer(), unget_input(), actual_x(), unget_input(), actual_x(), strnlenpt(), display_string(),
strnlenpt(), display_string(), titlebar(), statusbar(), titlebar(), statusbar(), onekey(), and do_credits(). (David
onekey(), and do_credits(). (David Benbennick and DLR) Benbennick and DLR)
- cut.c: - cut.c:
do_cut_text() do_cut_text()
- If keep_cutbuffer is FALSE, only blow away the text in the - If keep_cutbuffer is FALSE, only blow away the text in the

View File

@ -3596,11 +3596,9 @@ void do_output(int *kbinput, size_t kbinput_len)
char *key = char *key =
#ifdef NANO_WIDE #ifdef NANO_WIDE
charalloc(MB_CUR_MAX) !ISSET(NO_UTF8) ? charalloc(MB_CUR_MAX) :
#else
charalloc(1)
#endif #endif
; charalloc(1);
assert(current != NULL && current->data != NULL); assert(current != NULL && current->data != NULL);

View File

@ -1720,89 +1720,6 @@ void blank_bottombars(void)
} }
} }
/* buf is a multibyte string to be displayed. We need to expand tabs
* and control characters. How many bytes do we need to display buf
* properly, not counting the null terminator? start_col is the column
* of *buf (usually 0). We display to (end_col - 1). */
size_t display_string_len(const char *buf, size_t start_col, size_t
end_col)
{
size_t retval = 0;
assert(buf != NULL);
/* Throughout the loop, we maintain the fact that *buf displays at
* column start_col. */
while (start_col <= end_col && *buf != '\0') {
int wide_buf;
/* The current wide character. */
int wide_buf_len;
/* How many bytes wide is this character? */
size_t old_col = start_col;
#ifdef NANO_WIDE
bool bad_char;
#endif
wide_buf_len = parse_char(buf, &wide_buf, &start_col
#ifdef NANO_WIDE
, &bad_char
#endif
);
#ifdef NANO_WIDE
/* If buf contains a null byte or an invalid multibyte
* character, interpret its first byte as though it's a wide
* character. */
if (!ISSET(NO_UTF8) && bad_char) {
char *bad_wide_buf = charalloc(MB_CUR_MAX);
int bad_wide_buf_len;
/* If we have a control character, add one byte to account
* for the "^" that will be displayed in front of it, and
* translate the character to its visible equivalent as
* returned by control_rep(). */
if (is_cntrl_char(wide_buf)) {
retval++;
wide_buf = control_rep((unsigned char)wide_buf);
}
/* Translate the wide character to its multibyte
* equivalent. */
bad_wide_buf_len = wctomb(bad_wide_buf, (wchar_t)wide_buf);
if (bad_wide_buf_len != -1)
retval += bad_wide_buf_len;
free(bad_wide_buf);
} else
#endif
/* If we have a tab, get its width in bytes using the current
* value of col. */
if (wide_buf == '\t')
retval += start_col - old_col;
/* If we have a control character, add one byte to account for
* the "^" that will be displayed in front of it, and translate
* the byte to its visible equivalent as returned by
* control_rep(). */
else if (is_cntrl_char(wide_buf)) {
char ctrl_wide_buf = control_rep((unsigned char)wide_buf);
retval += parse_char(&ctrl_wide_buf, NULL, NULL
#ifdef NANO_WIDE
, NULL
#endif
) + 1;
/* If we have a normal character, add its width in bytes
* normally. */
} else
retval += wide_buf_len;
buf += wide_buf_len;
}
return retval;
}
/* Convert buf into a string that can be displayed on screen. The /* Convert buf into a string that can be displayed on screen. The
* caller wants to display buf starting with column start_col, and * caller wants to display buf starting with column start_col, and
* extending for at most len columns. start_col is zero-based. len is * extending for at most len columns. start_col is zero-based. len is
@ -1838,8 +1755,13 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
assert(column <= start_col); assert(column <= start_col);
alloc_len = display_string_len(buf + start_index, start_col, #ifdef NANO_WIDE
column + len) + 2; if (!ISSET(NO_UTF8))
alloc_len = len * MB_CUR_MAX;
else
#endif
alloc_len = len;
converted = charalloc(alloc_len + 1); converted = charalloc(alloc_len + 1);
index = 0; index = 0;
@ -1857,12 +1779,20 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
if (is_cntrl_char(wide_buf)) { if (is_cntrl_char(wide_buf)) {
if (column < start_col) { if (column < start_col) {
char *ctrl_wide_buf = charalloc(MB_CUR_MAX); char *ctrl_wide_buf =
#ifdef NANO_WIDE
!ISSET(NO_UTF8) ? charalloc(MB_CUR_MAX) :
#endif
charalloc(1);
int ctrl_wide_buf_len, i; int ctrl_wide_buf_len, i;
wide_buf = control_rep((unsigned char)wide_buf); wide_buf = control_rep((unsigned char)wide_buf);
ctrl_wide_buf_len = wctomb(ctrl_wide_buf, ctrl_wide_buf_len =
(wchar_t)wide_buf); #ifdef NANO_WIDE
!ISSET(NO_UTF8) ? wctomb(ctrl_wide_buf,
(wchar_t)wide_buf) :
#endif
1;
for (i = 0; i < ctrl_wide_buf_len; i++) for (i = 0; i < ctrl_wide_buf_len; i++)
converted[index++] = ctrl_wide_buf[i]; converted[index++] = ctrl_wide_buf[i];
@ -1929,22 +1859,34 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
start_col++; start_col++;
} }
} else if (is_cntrl_char(wide_buf)) { } else if (is_cntrl_char(wide_buf)) {
char *ctrl_wide_buf = charalloc(MB_CUR_MAX); char *ctrl_wide_buf =
#ifdef NANO_WIDE
!ISSET(NO_UTF8) ? charalloc(MB_CUR_MAX) :
#endif
charalloc(1);
int ctrl_wide_buf_len, i; int ctrl_wide_buf_len, i;
converted[index++] = '^'; converted[index++] = '^';
start_col++; start_col++;
wide_buf = control_rep((unsigned char)wide_buf); wide_buf = control_rep((unsigned char)wide_buf);
ctrl_wide_buf_len = wctomb(ctrl_wide_buf, ctrl_wide_buf_len =
(wchar_t)wide_buf); #ifdef NANO_WIDE
!ISSET(NO_UTF8) ? wctomb(ctrl_wide_buf,
(wchar_t)wide_buf) :
#endif
1;
for (i = 0; i < ctrl_wide_buf_len; i++) for (i = 0; i < ctrl_wide_buf_len; i++)
converted[index++] = ctrl_wide_buf[i]; converted[index++] = ctrl_wide_buf[i];
free(ctrl_wide_buf); free(ctrl_wide_buf);
start_col += wcwidth((wchar_t)wide_buf); start_col +=
#ifdef NANO_WIDE
!ISSET(NO_UTF8) ? wcwidth((wchar_t)wide_buf) :
#endif
1;
} 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)