Deleted Added
full compact
1c1
< /* $FreeBSD: head/contrib/libreadline/display.c 157195 2006-03-27 23:53:05Z ache $ */
---
> /* $FreeBSD: head/contrib/libreadline/display.c 165675 2006-12-31 09:22:31Z ache $ */
4c4
< /* Copyright (C) 1987-2005 Free Software Foundation, Inc.
---
> /* Copyright (C) 1987-2006 Free Software Foundation, Inc.
63,66d62
< #if defined (HACK_TERMCAP_MOTION)
< extern char *_rl_term_forward_char;
< #endif
<
84c80,81
< by backing up or outputting a carriage return and moving forward. */
---
> by backing up or outputting a carriage return and moving forward. CUR
> and NEW are either both buffer positions or absolute screen positions. */
86a84,91
> /* _rl_last_c_pos is an absolute cursor position in multibyte locales and a
> buffer index in others. This macro is used when deciding whether the
> current cursor position is in the middle of a prompt string containing
> invisible characters. */
> #define PROMPT_ENDING_INDEX \
> ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) ? prompt_physical_chars : prompt_last_invisible+1)
>
>
138a144
> static int cpos_buffer_position;
165a172
> static int local_prompt_len;
200a208
> static int saved_local_length;
224c232
< char *r, *ret, *p;
---
> char *r, *ret, *p, *igstart;
247a256
> igstart = 0;
252c261
< if (*p == RL_PROMPT_START_IGNORE)
---
> if (ignoring == 0 && *p == RL_PROMPT_START_IGNORE) /* XXX - check ignoring? */
254c263,264
< ignoring++;
---
> ignoring = 1;
> igstart = p;
260c270
< if (p[-1] != RL_PROMPT_START_IGNORE)
---
> if (p != (igstart + 1))
359a370
> local_prompt_len = 0;
374a386
> local_prompt_len = local_prompt ? strlen (local_prompt) : 0;
392a405
> local_prompt_len = local_prompt ? strlen (local_prompt) : 0;
449c462
< int c_pos, inv_botlin, lb_botlin, lb_linenum, o_cpos;
---
> int inv_botlin, lb_botlin, lb_linenum, o_cpos;
473c486
< c_pos = -1;
---
> cpos_buffer_position = -1;
500d512
< int local_len = local_prompt ? strlen (local_prompt) : 0;
504c516
< if (local_len > 0)
---
> if (local_prompt_len > 0)
506c518
< temp = local_len + out + 2;
---
> temp = local_prompt_len + out + 2;
513,514c525,526
< strncpy (line + out, local_prompt, local_len);
< out += local_len;
---
> strncpy (line + out, local_prompt, local_prompt_len);
> out += local_prompt_len;
517c529
< wrap_offset = local_len - prompt_visible_length;
---
> wrap_offset = local_prompt_len - prompt_visible_length;
617a630
> int z;
626,628c639
< n0 = num;
< temp = local_prompt ? strlen (local_prompt) : 0;
< while (num < temp)
---
> if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
630c641,643
< if (_rl_col_width (local_prompt, n0, num) > _rl_screenwidth)
---
> n0 = num;
> temp = local_prompt_len;
> while (num < temp)
632,633c645,653
< num = _rl_find_prev_mbchar (local_prompt, num, MB_FIND_ANY);
< break;
---
> z = _rl_col_width (local_prompt, n0, num);
> if (z > _rl_screenwidth)
> {
> num = _rl_find_prev_mbchar (local_prompt, num, MB_FIND_ANY);
> break;
> }
> else if (z == _rl_screenwidth)
> break;
> num++;
635c655
< num++;
---
> temp = num;
637,639c657
< temp = num +
< #else
< temp = ((newlines + 1) * _rl_screenwidth) +
---
> else
641,643c659,664
< ((local_prompt_prefix == 0) ? ((newlines == 0) ? prompt_invis_chars_first_line
< : ((newlines == 1) ? wrap_offset : 0))
< : ((newlines == 0) ? wrap_offset :0));
---
> temp = ((newlines + 1) * _rl_screenwidth);
>
> /* Now account for invisible characters in the current line. */
> temp += ((local_prompt_prefix == 0) ? ((newlines == 0) ? prompt_invis_chars_first_line
> : ((newlines == 1) ? wrap_offset : 0))
> : ((newlines == 0) ? wrap_offset :0));
647,649c668,670
< lpos -= _rl_col_width (local_prompt, n0, num);
< #else
< lpos -= _rl_screenwidth;
---
> if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
> lpos -= _rl_col_width (local_prompt, n0, num);
> else
650a672
> lpos -= _rl_screenwidth;
656c678
< track of where the cursor is (c_pos), the number of the line containing
---
> track of where the cursor is (cpos_buffer_position), the number of the line containing
709c731
< c_pos = out;
---
> cpos_buffer_position = out;
803c825
< c_pos = out;
---
> cpos_buffer_position = out;
834c856
< if (c_pos < 0)
---
> if (cpos_buffer_position < 0)
836c858
< c_pos = out;
---
> cpos_buffer_position = out;
845c867
< /* C_POS == position in buffer where cursor should be placed.
---
> /* CPOS_BUFFER_POSITION == position in buffer where cursor should be placed.
889a912,913
> /* This can lead us astray if we execute a program that changes
> the locale from a non-multibyte to a multibyte one. */
902c926,930
< this back by setting cpos_adjusted */
---
> this back by setting cpos_adjusted. If we assume that
> _rl_last_c_pos is correct (an absolute cursor position) each
> time update_line is called, then we can assume in our
> calculations that o_cpos does not need to be adjusted by
> wrap_offset. */
971c999,1003
< _rl_last_c_pos <= prompt_last_invisible && local_prompt)
---
> #if 0
> _rl_last_c_pos <= PROMPT_ENDING_INDEX && local_prompt)
> #else
> _rl_last_c_pos < PROMPT_ENDING_INDEX && local_prompt)
> #endif
990,991c1022,1023
< start of the line and the cursor position. */
< nleft = c_pos - pos;
---
> start of the line and the desired cursor position. */
> nleft = cpos_buffer_position - pos;
1002a1035
> /* TX == new physical cursor position in multibyte locale. */
1036c1069
< ndisp = c_pos - wrap_offset;
---
> ndisp = cpos_buffer_position - wrap_offset;
1040c1073
< phys_c_pos = c_pos - (last_lmargin ? last_lmargin : wrap_offset);
---
> phys_c_pos = cpos_buffer_position - (last_lmargin ? last_lmargin : wrap_offset);
1051c1084
< lmargin = c_pos - (2 * t);
---
> lmargin = cpos_buffer_position - (2 * t);
1065c1098
< lmargin = ((c_pos - 1) / t) * t; /* XXX */
---
> lmargin = ((cpos_buffer_position - 1) / t) * t; /* XXX */
1110c1143
< _rl_move_cursor_relative (c_pos - lmargin, &invisible_line[lmargin]);
---
> _rl_move_cursor_relative (cpos_buffer_position - lmargin, &invisible_line[lmargin]);
1168c1201
< int new_offset, old_offset, tmp;
---
> int new_offset, old_offset;
1401c1434
< lendiff = local_prompt ? strlen (local_prompt) : 0;
---
> lendiff = local_prompt_len;
1405c1438
< od >= lendiff && _rl_last_c_pos <= prompt_last_invisible)
---
> od >= lendiff && _rl_last_c_pos < PROMPT_ENDING_INDEX)
1423a1457,1459
> /* When this function returns, _rl_last_c_pos is correct, and an absolute
> cursor postion in multibyte mode, but a buffer index when not in a
> multibyte locale. */
1424a1461,1469
> #if 1
> #if defined (HANDLE_MULTIBYTE)
> /* We need to indicate that the cursor position is correct in the presence of
> invisible characters in the prompt string. Let's see if setting this when
> we make sure we're at the end of the drawn prompt string works. */
> if (current_line == 0 && MB_CUR_MAX > 1 && rl_byte_oriented == 0 && _rl_last_c_pos == prompt_physical_chars)
> cpos_adjusted = 1;
> #endif
> #endif
1651a1697,1698
> register char *temp;
>
1654,1655c1701
< register char *temp = visible_line;
<
---
> temp = visible_line;
1690,1691c1736,1743
< if (dpos > woff)
< dpos -= woff;
---
> if (dpos > prompt_last_invisible) /* XXX - don't use woff here */
> {
> dpos -= woff;
> /* Since this will be assigned to _rl_last_c_pos at the end (more
> precisely, _rl_last_c_pos == dpos when this function returns),
> let the caller know. */
> cpos_adjusted = 1;
> }
1710c1762
< if (new == 0 || CR_FASTER (new, _rl_last_c_pos) ||
---
> if (dpos == 0 || CR_FASTER (dpos, _rl_last_c_pos) ||
1732,1739c1784,1791
< #if defined (HACK_TERMCAP_MOTION)
< if (_rl_term_forward_char)
< {
< for (i = cpos; i < dpos; i++)
< tputs (_rl_term_forward_char, 1, _rl_output_character_function);
< }
< else
< #endif /* HACK_TERMCAP_MOTION */
---
>
> /* However, we need a handle on where the current display position is
> in the buffer for the immediately preceding comment to be true.
> In multibyte locales, we don't currently have that info available.
> Without it, we don't know where the data we have to display begins
> in the buffer and we have to go back to the beginning of the screen
> line. In this case, we can use the terminal sequence to move forward
> if it's available. */
1742,1744c1794,1804
< tputs (_rl_term_cr, 1, _rl_output_character_function);
< for (i = 0; i < new; i++)
< putc (data[i], rl_outstream);
---
> if (_rl_term_forward_char)
> {
> for (i = cpos; i < dpos; i++)
> tputs (_rl_term_forward_char, 1, _rl_output_character_function);
> }
> else
> {
> tputs (_rl_term_cr, 1, _rl_output_character_function);
> for (i = 0; i < new; i++)
> putc (data[i], rl_outstream);
> }
1892a1953
> local_prompt_len = local_prompt ? strlen (local_prompt) : 0;
1915a1977
> local_prompt_len = local_prompt ? strlen (local_prompt) : 0;
1951a2014
> saved_local_length = local_prompt_len;
1957a2021
> local_prompt_len = 0;
1969a2034
> local_prompt_len = saved_local_length;
1977a2043
> saved_local_length = 0;
2166c2232,2233
< _rl_move_cursor_relative (_rl_screenwidth - 1, last_line);
---
> cpos_buffer_position = -1; /* don't know where we are in buffer */
> _rl_move_cursor_relative (_rl_screenwidth - 1, last_line); /* XXX */
2208a2276
> local_prompt_len = local_prompt ? strlen (local_prompt) : 0;
2311c2379
< mbstate_t ps = {0};
---
> mbstate_t ps;
2316a2385,2386
> memset (&ps, 0, sizeof (mbstate_t));
>