Deleted Added
full compact
0a1
> /* $FreeBSD: head/contrib/libreadline/display.c 58314 2000-03-19 22:00:57Z ache $ */
10c11
< as published by the Free Software Foundation; either version 1, or
---
> as published by the Free Software Foundation; either version 2, or
21c22
< 675 Mass Ave, Cambridge, MA 02139, USA. */
---
> 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
44,48d44
< #if defined (__GO32__)
< # include <go32.h>
< # include <pc.h>
< #endif /* __GO32__ */
<
58a55,57
> #include "rlprivate.h"
> #include "xmalloc.h"
>
63,78c62,63
< /* Global and pseudo-global variables and functions
< imported from readline.c. */
< extern char *rl_prompt;
< extern int readline_echoing_p;
<
< extern int _rl_output_meta_chars;
< extern int _rl_horizontal_scroll_mode;
< extern int _rl_mark_modified_lines;
< extern int _rl_prefer_visible_bell;
<
< /* Variables and functions imported from terminal.c */
< extern void _rl_output_some_chars ();
< #ifdef _MINIX
< extern void _rl_output_character_function ();
< #else
< extern int _rl_output_character_function ();
---
> #if defined (HACK_TERMCAP_MOTION)
> extern char *term_forward_char;
80d64
< extern int _rl_backspace ();
82,86c66,70
< extern char *term_clreol, *term_clrpag;
< extern char *term_im, *term_ic, *term_ei, *term_DC;
< extern char *term_up, *term_dc, *term_cr, *term_IC;
< extern int screenheight, screenwidth, screenchars;
< extern int terminal_can_insert, _rl_term_autowrap;
---
> static void update_line __P((char *, char *, int, int, int, int));
> static void space_to_eol __P((int));
> static void delete_chars __P((int));
> static void insert_some_chars __P((char *, int));
> static void cr __P((void));
88,97d71
< /* Pseudo-global functions (local to the readline library) exported
< by this file. */
< void _rl_move_cursor_relative (), _rl_output_some_chars ();
< void _rl_move_vert ();
< void _rl_clear_to_eol (), _rl_clear_screen ();
<
< static void update_line (), space_to_eol ();
< static void delete_chars (), insert_some_chars ();
< static void cr ();
<
98a73
> static int inv_lbsize, vis_lbsize;
100,101d74
< extern char *xmalloc (), *xrealloc ();
<
193c166
< index of the last invisible character in ther eturned string. */
---
> index of the last invisible character in the returned string. */
252a226,237
> /* Just strip out RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE from
> PMT and return the rest of PMT. */
> char *
> _rl_strip_prompt (pmt)
> char *pmt;
> {
> char *ret;
>
> ret = expand_prompt (pmt, (int *)NULL, (int *)NULL);
> return ret;
> }
>
309a295,337
> /* Initialize the VISIBLE_LINE and INVISIBLE_LINE arrays, and their associated
> arrays of line break markers. MINSIZE is the minimum size of VISIBLE_LINE
> and INVISIBLE_LINE; if it is greater than LINE_SIZE, LINE_SIZE is
> increased. If the lines have already been allocated, this ensures that
> they can hold at least MINSIZE characters. */
> static void
> init_line_structures (minsize)
> int minsize;
> {
> register int n;
>
> if (invisible_line == 0) /* initialize it */
> {
> if (line_size < minsize)
> line_size = minsize;
> visible_line = xmalloc (line_size);
> invisible_line = xmalloc (line_size);
> }
> else if (line_size < minsize) /* ensure it can hold MINSIZE chars */
> {
> line_size *= 2;
> if (line_size < minsize)
> line_size = minsize;
> visible_line = xrealloc (visible_line, line_size);
> invisible_line = xrealloc (invisible_line, line_size);
> }
>
> for (n = minsize; n < line_size; n++)
> {
> visible_line[n] = 0;
> invisible_line[n] = 1;
> }
>
> if (vis_lbreaks == 0)
> {
> /* should be enough. */
> inv_lbsize = vis_lbsize = 256;
> inv_lbreaks = (int *)xmalloc (inv_lbsize * sizeof (int));
> vis_lbreaks = (int *)xmalloc (vis_lbsize * sizeof (int));
> inv_lbreaks[0] = vis_lbreaks[0] = 0;
> }
> }
>
328,340c356
< visible_line = xmalloc (line_size);
< invisible_line = xmalloc (line_size);
< for (in = 0; in < line_size; in++)
< {
< visible_line[in] = 0;
< invisible_line[in] = 1;
< }
<
< /* should be enough, but then again, this is just for testing. */
< inv_lbreaks = (int *)malloc (256 * sizeof (int));
< vis_lbreaks = (int *)malloc (256 * sizeof (int));
< inv_lbreaks[0] = vis_lbreaks[0] = 0;
<
---
> init_line_structures (0);
397a414
> pmtlen = prompt_this_line - rl_display_prompt; /* temp var */
400c417
< _rl_output_some_chars (rl_display_prompt, prompt_this_line - rl_display_prompt);
---
> _rl_output_some_chars (rl_display_prompt, pmtlen);
403c420
< if (prompt_this_line[-2] != '\r')
---
> if (pmtlen < 2 || prompt_this_line[-2] != '\r')
421a439,447
> #define CHECK_INV_LBREAKS() \
> do { \
> if (newlines >= (inv_lbsize - 2)) \
> { \
> inv_lbsize *= 2; \
> inv_lbreaks = (int *)xrealloc (inv_lbreaks, inv_lbsize * sizeof (int)); \
> } \
> } while (0)
>
426a453,457
> if (newlines >= (inv_lbsize - 2)) \
> { \
> inv_lbsize *= 2; \
> inv_lbreaks = (int *)xrealloc (inv_lbreaks, inv_lbsize * sizeof (int)); \
> } \
440,442d470
< #if 0
< temp = ((newlines + 1) * screenwidth) - ((newlines == 0) ? wrap_offset : 0);
< #else
445c473,475
< width. */
---
> width. XXX - this doesn't work right if invisible characters have
> to be put on the second screen line -- it adds too much (the number
> of invisible chars after the screenwidth). */
447c477
< #endif
---
>
479a510
> CHECK_INV_LBREAKS ();
508a540
> CHECK_INV_LBREAKS ();
524a557
> CHECK_INV_LBREAKS ();
548a582
> CHECK_INV_LBREAKS ();
653a688,690
> #if defined (__MSDOS__)
> putc ('\r', rl_outstream);
> #else
655a693
> #endif
775c813,814
< int *itemp = vis_lbreaks;
---
> int *itemp = vis_lbreaks, ntemp = vis_lbsize;
>
777a817
>
779a820,823
>
> vis_lbsize = inv_lbsize;
> inv_lbsize = ntemp;
>
901a946,948
> #if defined (__MSDOS__)
> putc ('\r', rl_outstream);
> #else
902a950
> #endif
1031a1080,1131
> /* Tell the update routines that we have moved onto a new line with the
> prompt already displayed. Code originally from the version of readline
> distributed with CLISP. */
> int
> rl_on_new_line_with_prompt ()
> {
> int prompt_size, i, l, real_screenwidth, newlines;
> char *prompt_last_line;
>
> /* Initialize visible_line and invisible_line to ensure that they can hold
> the already-displayed prompt. */
> prompt_size = strlen (rl_prompt) + 1;
> init_line_structures (prompt_size);
>
> /* Make sure the line structures hold the already-displayed prompt for
> redisplay. */
> strcpy (visible_line, rl_prompt);
> strcpy (invisible_line, rl_prompt);
>
> /* If the prompt contains newlines, take the last tail. */
> prompt_last_line = strrchr (rl_prompt, '\n');
> if (!prompt_last_line)
> prompt_last_line = rl_prompt;
>
> l = strlen (prompt_last_line);
> _rl_last_c_pos = l;
>
> /* Dissect prompt_last_line into screen lines. Note that here we have
> to use the real screenwidth. Readline's notion of screenwidth might be
> one less, see terminal.c. */
> real_screenwidth = screenwidth + (_rl_term_autowrap ? 0 : 1);
> _rl_last_v_pos = l / real_screenwidth;
> /* If the prompt length is a multiple of real_screenwidth, we don't know
> whether the cursor is at the end of the last line, or already at the
> beginning of the next line. Output a newline just to be safe. */
> if (l > 0 && (l % real_screenwidth) == 0)
> _rl_output_some_chars ("\n", 1);
> last_lmargin = 0;
>
> newlines = 0; i = 0;
> while (i <= l)
> {
> _rl_vis_botlin = newlines;
> vis_lbreaks[newlines++] = i;
> i += real_screenwidth;
> }
> vis_lbreaks[newlines] = l;
> visible_wrap_offset = 0;
>
> return 0;
> }
>
1089,1090d1188
< extern char *term_forward_char;
<
1117,1125d1214
< #if defined (__GO32__)
< {
< int row, col;
<
< ScreenGetCursor (&row, &col);
< ScreenSetCursor ((row + to - _rl_last_v_pos), col);
< }
< #else /* !__GO32__ */
<
1129a1219,1221
> #if defined (__MSDOS__)
> putc ('\r', rl_outstream);
> #else
1130a1223
> #endif
1139c1232
< #endif /* !__GO32__ */
---
>
1347d1439
< #if !defined (__GO32__)
1351d1442
< #endif /* !__GO32__ */
1372d1462
< #if !defined (__GO32__)
1376d1465
< #endif /* !__GO32__ */
1386,1399d1474
< #if defined (__GO32__)
< int row, col, width;
< char *row_start;
<
< ScreenGetCursor (&row, &col);
< width = ScreenCols ();
< row_start = ScreenPrimary + (row * width);
<
< memcpy (row_start + col + count, row_start + col, width - col - count);
<
< /* Place the text on the screen. */
< _rl_output_some_chars (string, count);
< #else /* !_GO32 */
<
1432d1506
< #endif /* !__GO32__ */
1440,1451d1513
< #if defined (__GO32__)
< int row, col, width;
< char *row_start;
<
< ScreenGetCursor (&row, &col);
< width = ScreenCols ();
< row_start = ScreenPrimary + (row * width);
<
< memcpy (row_start + col, row_start + col + count, width - col - count);
< memset (row_start + width - count, 0, count * 2);
< #else /* !_GO32 */
<
1467d1528
< #endif /* !__GO32__ */
1488a1550
> #if 0
1489a1552,1554
> #else
> last_line = &visible_line[vis_lbreaks[_rl_vis_botlin]];
> #endif
1505a1571,1573
> #if defined (__MSDOS__)
> putc ('\r', rl_outstream);
> #else
1506a1575
> #endif
1510a1580,1610
> /* Redraw the last line of a multi-line prompt that may possibly contain
> terminal escape sequences. Called with the cursor at column 0 of the
> line to draw the prompt on. */
> static void
> redraw_prompt (t)
> char *t;
> {
> char *oldp, *oldl, *oldlprefix;
> int oldlen, oldlast, oldplen;
>
> /* Geez, I should make this a struct. */
> oldp = rl_display_prompt;
> oldl = local_prompt;
> oldlprefix = local_prompt_prefix;
> oldlen = visible_length;
> oldplen = prefix_length;
> oldlast = last_invisible;
>
> rl_display_prompt = t;
> local_prompt = expand_prompt (t, &visible_length, &last_invisible);
> local_prompt_prefix = (char *)NULL;
> rl_forced_update_display ();
>
> rl_display_prompt = oldp;
> local_prompt = oldl;
> local_prompt_prefix = oldlprefix;
> visible_length = oldlen;
> prefix_length = oldplen;
> last_invisible = oldlast;
> }
>
1515c1615
< char *t, *oldp, *oldl, *oldlprefix;
---
> char *t;
1520a1621,1623
> #if defined (__MSDOS__)
> putc ('\r', rl_outstream);
> #else
1521a1625
> #endif
1522a1627,1630
> #if defined (__MSDOS__)
> space_to_eol (screenwidth);
> putc ('\r', rl_outstream);
> #else
1529a1638
> #endif
1539,1549c1648
< {
< oldp = rl_display_prompt;
< oldl = local_prompt;
< oldlprefix = local_prompt_prefix;
< rl_display_prompt = ++t;
< local_prompt = local_prompt_prefix = (char *)NULL;
< rl_forced_update_display ();
< rl_display_prompt = oldp;
< local_prompt = oldl;
< local_prompt_prefix = oldlprefix;
< }
---
> redraw_prompt (++t);
1573a1673,1694
>
> /* return the `current display line' of the cursor -- the number of lines to
> move up to get to the first screen line of the current readline line. */
> int
> _rl_current_display_line ()
> {
> int ret, nleft;
>
> /* Find out whether or not there might be invisible characters in the
> editing buffer. */
> if (rl_display_prompt == rl_prompt)
> nleft = _rl_last_c_pos - screenwidth - rl_visible_prompt_length;
> else
> nleft = _rl_last_c_pos - screenwidth;
>
> if (nleft > 0)
> ret = 1 + nleft / screenwidth;
> else
> ret = 0;
>
> return ret;
> }