Deleted Added
full compact
display.c (119614) display.c (136759)
1/* $FreeBSD: head/contrib/libreadline/display.c 119614 2003-08-31 18:29:38Z ache $ */
1/* $FreeBSD: head/contrib/libreadline/display.c 136759 2004-10-21 20:10:14Z peter $ */
2
2/* display.c -- readline redisplay facility. */
3
3/* display.c -- readline redisplay facility. */
4
4/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
5/* Copyright (C) 1987-2004 Free Software Foundation, Inc.
5
6 This file is part of the GNU Readline Library, a library for
7 reading lines of text with interactive input and history editing.
8
9 The GNU Readline Library is free software; you can redistribute it
10 and/or modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2, or
12 (at your option) any later version.

--- 53 unchanged lines hidden (view full) ---

66
67static void update_line PARAMS((char *, char *, int, int, int, int));
68static void space_to_eol PARAMS((int));
69static void delete_chars PARAMS((int));
70static void insert_some_chars PARAMS((char *, int, int));
71static void cr PARAMS((void));
72
73#if defined (HANDLE_MULTIBYTE)
6
7 This file is part of the GNU Readline Library, a library for
8 reading lines of text with interactive input and history editing.
9
10 The GNU Readline Library is free software; you can redistribute it
11 and/or modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2, or
13 (at your option) any later version.

--- 53 unchanged lines hidden (view full) ---

67
68static void update_line PARAMS((char *, char *, int, int, int, int));
69static void space_to_eol PARAMS((int));
70static void delete_chars PARAMS((int));
71static void insert_some_chars PARAMS((char *, int, int));
72static void cr PARAMS((void));
73
74#if defined (HANDLE_MULTIBYTE)
74static int _rl_col_width PARAMS((char *, int, int));
75static int _rl_col_width PARAMS((const char *, int, int));
75static int *_rl_wrapped_line;
76#else
77# define _rl_col_width(l, s, e) (((e) <= (s)) ? 0 : (e) - (s))
78#endif
79
80static int *inv_lbreaks, *vis_lbreaks;
81static int inv_lbsize, vis_lbsize;
82

--- 91 unchanged lines hidden (view full) ---

174
175/* Number of invisible characters on the first physical line of the prompt.
176 Only valid when the number of physical characters in the prompt exceeds
177 (or is equal to) _rl_screenwidth. */
178static int prompt_invis_chars_first_line;
179
180static int prompt_last_screen_line;
181
76static int *_rl_wrapped_line;
77#else
78# define _rl_col_width(l, s, e) (((e) <= (s)) ? 0 : (e) - (s))
79#endif
80
81static int *inv_lbreaks, *vis_lbreaks;
82static int inv_lbsize, vis_lbsize;
83

--- 91 unchanged lines hidden (view full) ---

175
176/* Number of invisible characters on the first physical line of the prompt.
177 Only valid when the number of physical characters in the prompt exceeds
178 (or is equal to) _rl_screenwidth. */
179static int prompt_invis_chars_first_line;
180
181static int prompt_last_screen_line;
182
183static int prompt_physical_chars;
184
182/* Expand the prompt string S and return the number of visible
183 characters in *LP, if LP is not null. This is currently more-or-less
184 a placeholder for expansion. LIP, if non-null is a place to store the
185 index of the last invisible character in the returned string. NIFLP,
186 if non-zero, is a place to store the number of invisible characters in
185/* Expand the prompt string S and return the number of visible
186 characters in *LP, if LP is not null. This is currently more-or-less
187 a placeholder for expansion. LIP, if non-null is a place to store the
188 index of the last invisible character in the returned string. NIFLP,
189 if non-zero, is a place to store the number of invisible characters in
187 the first prompt line. */
190 the first prompt line. The previous are used as byte counts -- indexes
191 into a character buffer. */
188
189/* Current implementation:
190 \001 (^A) start non-visible characters
191 \002 (^B) end non-visible characters
192 all characters except \001 and \002 (following a \001) are copied to
193 the returned string; all characters except those between \001 and
194 \002 are assumed to be `visible'. */
195
196static char *
192
193/* Current implementation:
194 \001 (^A) start non-visible characters
195 \002 (^B) end non-visible characters
196 all characters except \001 and \002 (following a \001) are copied to
197 the returned string; all characters except those between \001 and
198 \002 are assumed to be `visible'. */
199
200static char *
197expand_prompt (pmt, lp, lip, niflp)
201expand_prompt (pmt, lp, lip, niflp, vlp)
198 char *pmt;
202 char *pmt;
199 int *lp, *lip, *niflp;
203 int *lp, *lip, *niflp, *vlp;
200{
201 char *r, *ret, *p;
204{
205 char *r, *ret, *p;
202 int l, rl, last, ignoring, ninvis, invfl;
206 int l, rl, last, ignoring, ninvis, invfl, invflset, ind, pind, physchars;
203
204 /* Short-circuit if we can. */
207
208 /* Short-circuit if we can. */
205 if (strchr (pmt, RL_PROMPT_START_IGNORE) == 0)
209 if ((MB_CUR_MAX <= 1 || rl_byte_oriented) && strchr (pmt, RL_PROMPT_START_IGNORE) == 0)
206 {
207 r = savestring (pmt);
208 if (lp)
209 *lp = strlen (r);
210 {
211 r = savestring (pmt);
212 if (lp)
213 *lp = strlen (r);
214 if (lip)
215 *lip = 0;
216 if (niflp)
217 *niflp = 0;
218 if (vlp)
219 *vlp = lp ? *lp : strlen (r);
210 return r;
211 }
212
213 l = strlen (pmt);
214 r = ret = (char *)xmalloc (l + 1);
215
216 invfl = 0; /* invisible chars in first line of prompt */
220 return r;
221 }
222
223 l = strlen (pmt);
224 r = ret = (char *)xmalloc (l + 1);
225
226 invfl = 0; /* invisible chars in first line of prompt */
227 invflset = 0; /* we only want to set invfl once */
217
228
218 for (rl = ignoring = last = ninvis = 0, p = pmt; p && *p; p++)
229 for (rl = ignoring = last = ninvis = physchars = 0, p = pmt; p && *p; p++)
219 {
220 /* This code strips the invisible character string markers
221 RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE */
222 if (*p == RL_PROMPT_START_IGNORE)
223 {
224 ignoring++;
225 continue;
226 }
227 else if (ignoring && *p == RL_PROMPT_END_IGNORE)
228 {
229 ignoring = 0;
230 last = r - ret - 1;
231 continue;
232 }
233 else
234 {
230 {
231 /* This code strips the invisible character string markers
232 RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE */
233 if (*p == RL_PROMPT_START_IGNORE)
234 {
235 ignoring++;
236 continue;
237 }
238 else if (ignoring && *p == RL_PROMPT_END_IGNORE)
239 {
240 ignoring = 0;
241 last = r - ret - 1;
242 continue;
243 }
244 else
245 {
235 *r++ = *p;
236 if (!ignoring)
237 rl++;
246#if defined (HANDLE_MULTIBYTE)
247 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
248 {
249 pind = p - pmt;
250 ind = _rl_find_next_mbchar (pmt, pind, 1, MB_FIND_NONZERO);
251 l = ind - pind;
252 while (l--)
253 *r++ = *p++;
254 if (!ignoring)
255 {
256 rl += ind - pind;
257 physchars += _rl_col_width (pmt, pind, ind);
258 }
259 else
260 ninvis += ind - pind;
261 p--; /* compensate for later increment */
262 }
238 else
263 else
239 ninvis++;
240 if (rl == _rl_screenwidth)
241 invfl = ninvis;
264#endif
265 {
266 *r++ = *p;
267 if (!ignoring)
268 {
269 rl++; /* visible length byte counter */
270 physchars++;
271 }
272 else
273 ninvis++; /* invisible chars byte counter */
274 }
275
276 if (invflset == 0 && rl >= _rl_screenwidth)
277 {
278 invfl = ninvis;
279 invflset = 1;
280 }
242 }
243 }
244
245 if (rl < _rl_screenwidth)
246 invfl = ninvis;
247
248 *r = '\0';
249 if (lp)
250 *lp = rl;
251 if (lip)
252 *lip = last;
253 if (niflp)
254 *niflp = invfl;
281 }
282 }
283
284 if (rl < _rl_screenwidth)
285 invfl = ninvis;
286
287 *r = '\0';
288 if (lp)
289 *lp = rl;
290 if (lip)
291 *lip = last;
292 if (niflp)
293 *niflp = invfl;
294 if (vlp)
295 *vlp = physchars;
255 return ret;
256}
257
258/* Just strip out RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE from
259 PMT and return the rest of PMT. */
260char *
261_rl_strip_prompt (pmt)
262 char *pmt;
263{
264 char *ret;
265
296 return ret;
297}
298
299/* Just strip out RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE from
300 PMT and return the rest of PMT. */
301char *
302_rl_strip_prompt (pmt)
303 char *pmt;
304{
305 char *ret;
306
266 ret = expand_prompt (pmt, (int *)NULL, (int *)NULL, (int *)NULL);
307 ret = expand_prompt (pmt, (int *)NULL, (int *)NULL, (int *)NULL, (int *)NULL);
267 return ret;
268}
269
270/*
271 * Expand the prompt string into the various display components, if
272 * necessary.
273 *
274 * local_prompt = expanded last line of string in rl_display_prompt

--- 27 unchanged lines hidden (view full) ---

302 return (0);
303
304 p = strrchr (prompt, '\n');
305 if (!p)
306 {
307 /* The prompt is only one logical line, though it might wrap. */
308 local_prompt = expand_prompt (prompt, &prompt_visible_length,
309 &prompt_last_invisible,
308 return ret;
309}
310
311/*
312 * Expand the prompt string into the various display components, if
313 * necessary.
314 *
315 * local_prompt = expanded last line of string in rl_display_prompt

--- 27 unchanged lines hidden (view full) ---

343 return (0);
344
345 p = strrchr (prompt, '\n');
346 if (!p)
347 {
348 /* The prompt is only one logical line, though it might wrap. */
349 local_prompt = expand_prompt (prompt, &prompt_visible_length,
350 &prompt_last_invisible,
310 &prompt_invis_chars_first_line);
351 &prompt_invis_chars_first_line,
352 &prompt_physical_chars);
311 local_prompt_prefix = (char *)0;
312 return (prompt_visible_length);
313 }
314 else
315 {
316 /* The prompt spans multiple lines. */
317 t = ++p;
318 local_prompt = expand_prompt (p, &prompt_visible_length,
319 &prompt_last_invisible,
353 local_prompt_prefix = (char *)0;
354 return (prompt_visible_length);
355 }
356 else
357 {
358 /* The prompt spans multiple lines. */
359 t = ++p;
360 local_prompt = expand_prompt (p, &prompt_visible_length,
361 &prompt_last_invisible,
320 &prompt_invis_chars_first_line);
362 (int *)NULL,
363 &prompt_physical_chars);
321 c = *t; *t = '\0';
322 /* The portion of the prompt string up to and including the
323 final newline is now null-terminated. */
324 local_prompt_prefix = expand_prompt (prompt, &prompt_prefix_length,
325 (int *)NULL,
364 c = *t; *t = '\0';
365 /* The portion of the prompt string up to and including the
366 final newline is now null-terminated. */
367 local_prompt_prefix = expand_prompt (prompt, &prompt_prefix_length,
368 (int *)NULL,
326 &prompt_invis_chars_first_line);
369 &prompt_invis_chars_first_line,
370 (int *)NULL);
327 *t = c;
328 return (prompt_prefix_length);
329 }
330}
331
332/* Initialize the VISIBLE_LINE and INVISIBLE_LINE arrays, and their associated
333 arrays of line break markers. MINSIZE is the minimum size of VISIBLE_LINE
334 and INVISIBLE_LINE; if it is greater than LINE_SIZE, LINE_SIZE is

--- 42 unchanged lines hidden (view full) ---

377
378/* Basic redisplay algorithm. */
379void
380rl_redisplay ()
381{
382 register int in, out, c, linenum, cursor_linenum;
383 register char *line;
384 int c_pos, inv_botlin, lb_botlin, lb_linenum;
371 *t = c;
372 return (prompt_prefix_length);
373 }
374}
375
376/* Initialize the VISIBLE_LINE and INVISIBLE_LINE arrays, and their associated
377 arrays of line break markers. MINSIZE is the minimum size of VISIBLE_LINE
378 and INVISIBLE_LINE; if it is greater than LINE_SIZE, LINE_SIZE is

--- 42 unchanged lines hidden (view full) ---

421
422/* Basic redisplay algorithm. */
423void
424rl_redisplay ()
425{
426 register int in, out, c, linenum, cursor_linenum;
427 register char *line;
428 int c_pos, inv_botlin, lb_botlin, lb_linenum;
385 int newlines, lpos, temp;
429 int newlines, lpos, temp, modmark, n0, num;
386 char *prompt_this_line;
387#if defined (HANDLE_MULTIBYTE)
388 wchar_t wc;
389 size_t wc_bytes;
390 int wc_width;
391 mbstate_t ps;
392 int _rl_wrapped_multicolumn = 0;
393#endif

--- 13 unchanged lines hidden (view full) ---

407 /* Draw the line into the buffer. */
408 c_pos = -1;
409
410 line = invisible_line;
411 out = inv_botlin = 0;
412
413 /* Mark the line as modified or not. We only do this for history
414 lines. */
430 char *prompt_this_line;
431#if defined (HANDLE_MULTIBYTE)
432 wchar_t wc;
433 size_t wc_bytes;
434 int wc_width;
435 mbstate_t ps;
436 int _rl_wrapped_multicolumn = 0;
437#endif

--- 13 unchanged lines hidden (view full) ---

451 /* Draw the line into the buffer. */
452 c_pos = -1;
453
454 line = invisible_line;
455 out = inv_botlin = 0;
456
457 /* Mark the line as modified or not. We only do this for history
458 lines. */
459 modmark = 0;
415 if (_rl_mark_modified_lines && current_history () && rl_undo_list)
416 {
417 line[out++] = '*';
418 line[out] = '\0';
460 if (_rl_mark_modified_lines && current_history () && rl_undo_list)
461 {
462 line[out++] = '*';
463 line[out] = '\0';
464 modmark = 1;
419 }
420
421 /* If someone thought that the redisplay was handled, but the currently
422 visible line has a different modification state than the one about
423 to become visible, then correct the caller's misconception. */
424 if (visible_line[0] != invisible_line[0])
425 rl_display_fixed = 0;
426

--- 37 unchanged lines hidden (view full) ---

464 _rl_output_some_chars (rl_display_prompt, pmtlen);
465 /* Make sure we are at column zero even after a newline,
466 regardless of the state of terminal output processing. */
467 if (pmtlen < 2 || prompt_this_line[-2] != '\r')
468 cr ();
469 }
470 }
471
465 }
466
467 /* If someone thought that the redisplay was handled, but the currently
468 visible line has a different modification state than the one about
469 to become visible, then correct the caller's misconception. */
470 if (visible_line[0] != invisible_line[0])
471 rl_display_fixed = 0;
472

--- 37 unchanged lines hidden (view full) ---

510 _rl_output_some_chars (rl_display_prompt, pmtlen);
511 /* Make sure we are at column zero even after a newline,
512 regardless of the state of terminal output processing. */
513 if (pmtlen < 2 || prompt_this_line[-2] != '\r')
514 cr ();
515 }
516 }
517
472 pmtlen = strlen (prompt_this_line);
518 prompt_physical_chars = pmtlen = strlen (prompt_this_line);
473 temp = pmtlen + out + 2;
474 if (temp >= line_size)
475 {
476 line_size = (temp + 1024) - (temp % 1024);
477 visible_line = (char *)xrealloc (visible_line, line_size);
478 line = invisible_line = (char *)xrealloc (invisible_line, line_size);
479 }
480 strncpy (line + out, prompt_this_line, pmtlen);

--- 42 unchanged lines hidden (view full) ---

523 inv_lbreaks[++newlines] = out; \
524 lpos = 0; \
525 } \
526 } while (0)
527#endif
528
529 /* inv_lbreaks[i] is where line i starts in the buffer. */
530 inv_lbreaks[newlines = 0] = 0;
519 temp = pmtlen + out + 2;
520 if (temp >= line_size)
521 {
522 line_size = (temp + 1024) - (temp % 1024);
523 visible_line = (char *)xrealloc (visible_line, line_size);
524 line = invisible_line = (char *)xrealloc (invisible_line, line_size);
525 }
526 strncpy (line + out, prompt_this_line, pmtlen);

--- 42 unchanged lines hidden (view full) ---

569 inv_lbreaks[++newlines] = out; \
570 lpos = 0; \
571 } \
572 } while (0)
573#endif
574
575 /* inv_lbreaks[i] is where line i starts in the buffer. */
576 inv_lbreaks[newlines = 0] = 0;
577#if 0
531 lpos = out - wrap_offset;
578 lpos = out - wrap_offset;
579#else
580 lpos = prompt_physical_chars + modmark;
581#endif
582
532#if defined (HANDLE_MULTIBYTE)
533 memset (_rl_wrapped_line, 0, vis_lbsize);
583#if defined (HANDLE_MULTIBYTE)
584 memset (_rl_wrapped_line, 0, vis_lbsize);
585 num = 0;
534#endif
535
536 /* prompt_invis_chars_first_line is the number of invisible characters in
537 the first physical line of the prompt.
538 wrap_offset - prompt_invis_chars_first_line is the number of invis
539 chars on the second line. */
540
541 /* what if lpos is already >= _rl_screenwidth before we start drawing the
542 contents of the command line? */
543 while (lpos >= _rl_screenwidth)
544 {
545 /* fix from Darin Johnson <darin@acuson.com> for prompt string with
546 invisible characters that is longer than the screen width. The
547 prompt_invis_chars_first_line variable could be made into an array
548 saying how many invisible characters there are per line, but that's
549 probably too much work for the benefit gained. How many people have
586#endif
587
588 /* prompt_invis_chars_first_line is the number of invisible characters in
589 the first physical line of the prompt.
590 wrap_offset - prompt_invis_chars_first_line is the number of invis
591 chars on the second line. */
592
593 /* what if lpos is already >= _rl_screenwidth before we start drawing the
594 contents of the command line? */
595 while (lpos >= _rl_screenwidth)
596 {
597 /* fix from Darin Johnson <darin@acuson.com> for prompt string with
598 invisible characters that is longer than the screen width. The
599 prompt_invis_chars_first_line variable could be made into an array
600 saying how many invisible characters there are per line, but that's
601 probably too much work for the benefit gained. How many people have
550 prompts that exceed two physical lines? */
551 temp = ((newlines + 1) * _rl_screenwidth) +
552#if 0
553 ((newlines == 0) ? prompt_invis_chars_first_line : 0) +
602 prompts that exceed two physical lines?
603 Additional logic fix from Edward Catmur <ed@catmur.co.uk> */
604#if defined (HANDLE_MULTIBYTE)
605 n0 = num;
606 temp = local_prompt ? strlen (local_prompt) : 0;
607 while (num < temp)
608 {
609 if (_rl_col_width (local_prompt, n0, num) > _rl_screenwidth)
610 {
611 num = _rl_find_prev_mbchar (local_prompt, num, MB_FIND_ANY);
612 break;
613 }
614 num++;
615 }
616 temp = num +
554#else
617#else
555 ((newlines == 0 && local_prompt_prefix == 0) ? prompt_invis_chars_first_line : 0) +
556#endif
557 ((newlines == 1) ? wrap_offset : 0);
558
618 temp = ((newlines + 1) * _rl_screenwidth) +
619#endif /* !HANDLE_MULTIBYTE */
620 ((local_prompt_prefix == 0) ? ((newlines == 0) ? prompt_invis_chars_first_line
621 : ((newlines == 1) ? wrap_offset : 0))
622 : ((newlines == 0) ? wrap_offset :0));
623
559 inv_lbreaks[++newlines] = temp;
624 inv_lbreaks[++newlines] = temp;
625#if defined (HANDLE_MULTIBYTE)
626 lpos -= _rl_col_width (local_prompt, n0, num);
627#else
560 lpos -= _rl_screenwidth;
628 lpos -= _rl_screenwidth;
629#endif
561 }
562
563 prompt_last_screen_line = newlines;
564
565 /* Draw the rest of the line (after the prompt) into invisible_line, keeping
566 track of where the cursor is (c_pos), the number of the line containing
567 the cursor (lb_linenum), the last line number (lb_botlin and inv_botlin).
568 It maintains an array of line breaks for display (inv_lbreaks).

--- 13 unchanged lines hidden (view full) ---

582 for (in = 0; in < rl_end; in++)
583#endif
584 {
585 c = (unsigned char)rl_line_buffer[in];
586
587#if defined (HANDLE_MULTIBYTE)
588 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
589 {
630 }
631
632 prompt_last_screen_line = newlines;
633
634 /* Draw the rest of the line (after the prompt) into invisible_line, keeping
635 track of where the cursor is (c_pos), the number of the line containing
636 the cursor (lb_linenum), the last line number (lb_botlin and inv_botlin).
637 It maintains an array of line breaks for display (inv_lbreaks).

--- 13 unchanged lines hidden (view full) ---

651 for (in = 0; in < rl_end; in++)
652#endif
653 {
654 c = (unsigned char)rl_line_buffer[in];
655
656#if defined (HANDLE_MULTIBYTE)
657 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
658 {
590 if (wc_bytes == (size_t)-1 || wc_bytes == (size_t)-2)
659 if (MB_INVALIDCH (wc_bytes))
591 {
592 /* Byte sequence is invalid or shortened. Assume that the
593 first byte represents a character. */
594 wc_bytes = 1;
595 /* Assume that a character occupies a single column. */
596 wc_width = 1;
597 memset (&ps, 0, sizeof (mbstate_t));
598 }
660 {
661 /* Byte sequence is invalid or shortened. Assume that the
662 first byte represents a character. */
663 wc_bytes = 1;
664 /* Assume that a character occupies a single column. */
665 wc_width = 1;
666 memset (&ps, 0, sizeof (mbstate_t));
667 }
599 else if (wc_bytes == (size_t)0)
668 else if (MB_NULLWCH (wc_bytes))
600 break; /* Found '\0' */
601 else
602 {
603 temp = wcwidth (wc);
669 break; /* Found '\0' */
670 else
671 {
672 temp = wcwidth (wc);
604 wc_width = (temp < 0) ? 1 : temp;
673 wc_width = (temp >= 0) ? temp : 1;
605 }
606 }
607#endif
608
609 if (out + 8 >= line_size) /* XXX - 8 for \t */
610 {
611 line_size *= 2;
612 visible_line = (char *)xrealloc (visible_line, line_size);

--- 250 unchanged lines hidden (view full) ---

863#if defined (__MSDOS__)
864 putc ('\r', rl_outstream);
865#else
866 if (_rl_term_cr)
867 tputs (_rl_term_cr, 1, _rl_output_character_function);
868#endif
869 _rl_output_some_chars (local_prompt, nleft);
870 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
674 }
675 }
676#endif
677
678 if (out + 8 >= line_size) /* XXX - 8 for \t */
679 {
680 line_size *= 2;
681 visible_line = (char *)xrealloc (visible_line, line_size);

--- 250 unchanged lines hidden (view full) ---

932#if defined (__MSDOS__)
933 putc ('\r', rl_outstream);
934#else
935 if (_rl_term_cr)
936 tputs (_rl_term_cr, 1, _rl_output_character_function);
937#endif
938 _rl_output_some_chars (local_prompt, nleft);
939 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
871 _rl_last_c_pos = _rl_col_width(local_prompt, 0, nleft);
940 _rl_last_c_pos = _rl_col_width (local_prompt, 0, nleft);
872 else
873 _rl_last_c_pos = nleft;
874 }
875
876 /* Where on that line? And where does that line start
877 in the buffer? */
878 pos = inv_lbreaks[cursor_linenum];
879 /* nleft == number of characters in the line buffer between the

--- 185 unchanged lines hidden (view full) ---

1065 /* This fixes only double-column characters, but if the wrapped
1066 character comsumes more than three columns, spaces will be
1067 inserted in the string buffer. */
1068 if (_rl_wrapped_line[current_line] > 0)
1069 _rl_clear_to_eol (_rl_wrapped_line[current_line]);
1070
1071 memset (&ps, 0, sizeof (mbstate_t));
1072 ret = mbrtowc (&wc, new, MB_CUR_MAX, &ps);
941 else
942 _rl_last_c_pos = nleft;
943 }
944
945 /* Where on that line? And where does that line start
946 in the buffer? */
947 pos = inv_lbreaks[cursor_linenum];
948 /* nleft == number of characters in the line buffer between the

--- 185 unchanged lines hidden (view full) ---

1134 /* This fixes only double-column characters, but if the wrapped
1135 character comsumes more than three columns, spaces will be
1136 inserted in the string buffer. */
1137 if (_rl_wrapped_line[current_line] > 0)
1138 _rl_clear_to_eol (_rl_wrapped_line[current_line]);
1139
1140 memset (&ps, 0, sizeof (mbstate_t));
1141 ret = mbrtowc (&wc, new, MB_CUR_MAX, &ps);
1073 if (ret == (size_t)-1 || ret == (size_t)-2)
1142 if (MB_INVALIDCH (ret))
1074 {
1075 tempwidth = 1;
1076 ret = 1;
1077 }
1143 {
1144 tempwidth = 1;
1145 ret = 1;
1146 }
1078 else if (ret == 0)
1147 else if (MB_NULLWCH (ret))
1079 tempwidth = 0;
1080 else
1081 tempwidth = wcwidth (wc);
1082
1083 if (tempwidth > 0)
1084 {
1085 int count;
1086 bytes = ret;
1087 for (count = 0; count < bytes; count++)
1088 putc (new[count], rl_outstream);
1089 _rl_last_c_pos = tempwidth;
1090 _rl_last_v_pos++;
1091 memset (&ps, 0, sizeof (mbstate_t));
1092 ret = mbrtowc (&wc, old, MB_CUR_MAX, &ps);
1093 if (ret != 0 && bytes != 0)
1094 {
1148 tempwidth = 0;
1149 else
1150 tempwidth = wcwidth (wc);
1151
1152 if (tempwidth > 0)
1153 {
1154 int count;
1155 bytes = ret;
1156 for (count = 0; count < bytes; count++)
1157 putc (new[count], rl_outstream);
1158 _rl_last_c_pos = tempwidth;
1159 _rl_last_v_pos++;
1160 memset (&ps, 0, sizeof (mbstate_t));
1161 ret = mbrtowc (&wc, old, MB_CUR_MAX, &ps);
1162 if (ret != 0 && bytes != 0)
1163 {
1095 if (ret == (size_t)-1 || ret == (size_t)-2)
1164 if (MB_INVALIDCH (ret))
1096 memmove (old+bytes, old+1, strlen (old+1));
1097 else
1098 memmove (old+bytes, old+ret, strlen (old+ret));
1099 memcpy (old, new, bytes);
1100 }
1101 }
1102 else
1103 {

--- 18 unchanged lines hidden (view full) ---

1122 }
1123 }
1124
1125
1126 /* Find first difference. */
1127#if defined (HANDLE_MULTIBYTE)
1128 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
1129 {
1165 memmove (old+bytes, old+1, strlen (old+1));
1166 else
1167 memmove (old+bytes, old+ret, strlen (old+ret));
1168 memcpy (old, new, bytes);
1169 }
1170 }
1171 else
1172 {

--- 18 unchanged lines hidden (view full) ---

1191 }
1192 }
1193
1194
1195 /* Find first difference. */
1196#if defined (HANDLE_MULTIBYTE)
1197 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
1198 {
1130 memset (&ps_new, 0, sizeof(mbstate_t));
1131 memset (&ps_old, 0, sizeof(mbstate_t));
1132
1133 new_offset = old_offset = 0;
1134 for (ofd = old, nfd = new;
1135 (ofd - old < omax) && *ofd &&
1136 _rl_compare_chars(old, old_offset, &ps_old, new, new_offset, &ps_new); )
1199 /* See if the old line is a subset of the new line, so that the
1200 only change is adding characters. */
1201 temp = (omax < nmax) ? omax : nmax;
1202 if (memcmp (old, new, temp) == 0)
1137 {
1203 {
1138 old_offset = _rl_find_next_mbchar (old, old_offset, 1, MB_FIND_ANY);
1139 new_offset = _rl_find_next_mbchar (new, new_offset, 1, MB_FIND_ANY);
1140 ofd = old + old_offset;
1141 nfd = new + new_offset;
1204 ofd = old + temp;
1205 nfd = new + temp;
1142 }
1206 }
1207 else
1208 {
1209 memset (&ps_new, 0, sizeof(mbstate_t));
1210 memset (&ps_old, 0, sizeof(mbstate_t));
1211
1212 if (omax == nmax && STREQN (new, old, omax))
1213 {
1214 ofd = old + omax;
1215 nfd = new + nmax;
1216 }
1217 else
1218 {
1219 new_offset = old_offset = 0;
1220 for (ofd = old, nfd = new;
1221 (ofd - old < omax) && *ofd &&
1222 _rl_compare_chars(old, old_offset, &ps_old, new, new_offset, &ps_new); )
1223 {
1224 old_offset = _rl_find_next_mbchar (old, old_offset, 1, MB_FIND_ANY);
1225 new_offset = _rl_find_next_mbchar (new, new_offset, 1, MB_FIND_ANY);
1226 ofd = old + old_offset;
1227 nfd = new + new_offset;
1228 }
1229 }
1230 }
1143 }
1144 else
1145#endif
1146 for (ofd = old, nfd = new;
1147 (ofd - old < omax) && *ofd && (*ofd == *nfd);
1148 ofd++, nfd++)
1149 ;
1150

--- 14 unchanged lines hidden (view full) ---

1165 {
1166 ols = old + _rl_find_prev_mbchar (old, oe - old, MB_FIND_ANY);
1167 nls = new + _rl_find_prev_mbchar (new, ne - new, MB_FIND_ANY);
1168 while ((ols > ofd) && (nls > nfd))
1169 {
1170 memset (&ps_old, 0, sizeof (mbstate_t));
1171 memset (&ps_new, 0, sizeof (mbstate_t));
1172
1231 }
1232 else
1233#endif
1234 for (ofd = old, nfd = new;
1235 (ofd - old < omax) && *ofd && (*ofd == *nfd);
1236 ofd++, nfd++)
1237 ;
1238

--- 14 unchanged lines hidden (view full) ---

1253 {
1254 ols = old + _rl_find_prev_mbchar (old, oe - old, MB_FIND_ANY);
1255 nls = new + _rl_find_prev_mbchar (new, ne - new, MB_FIND_ANY);
1256 while ((ols > ofd) && (nls > nfd))
1257 {
1258 memset (&ps_old, 0, sizeof (mbstate_t));
1259 memset (&ps_new, 0, sizeof (mbstate_t));
1260
1261#if 0
1262 /* On advice from jir@yamato.ibm.com */
1173 _rl_adjust_point (old, ols - old, &ps_old);
1174 _rl_adjust_point (new, nls - new, &ps_new);
1263 _rl_adjust_point (old, ols - old, &ps_old);
1264 _rl_adjust_point (new, nls - new, &ps_new);
1265#endif
1175
1176 if (_rl_compare_chars (old, ols - old, &ps_old, new, nls - new, &ps_new) == 0)
1177 break;
1178
1179 if (*ols == ' ')
1180 wsatend = 0;
1181
1182 ols = old + _rl_find_prev_mbchar (old, ols - old, MB_FIND_ANY);

--- 137 unchanged lines hidden (view full) ---

1320 _rl_term_IC or _rl_term_ic will screw up the screen because of the
1321 invisible characters. We need to just draw them. */
1322 if (*ols && (!_rl_horizontal_scroll_mode || _rl_last_c_pos > 0 ||
1323 lendiff <= prompt_visible_length || !current_invis_chars))
1324 {
1325 insert_some_chars (nfd, lendiff, col_lendiff);
1326 _rl_last_c_pos += col_lendiff;
1327 }
1266
1267 if (_rl_compare_chars (old, ols - old, &ps_old, new, nls - new, &ps_new) == 0)
1268 break;
1269
1270 if (*ols == ' ')
1271 wsatend = 0;
1272
1273 ols = old + _rl_find_prev_mbchar (old, ols - old, MB_FIND_ANY);

--- 137 unchanged lines hidden (view full) ---

1411 _rl_term_IC or _rl_term_ic will screw up the screen because of the
1412 invisible characters. We need to just draw them. */
1413 if (*ols && (!_rl_horizontal_scroll_mode || _rl_last_c_pos > 0 ||
1414 lendiff <= prompt_visible_length || !current_invis_chars))
1415 {
1416 insert_some_chars (nfd, lendiff, col_lendiff);
1417 _rl_last_c_pos += col_lendiff;
1418 }
1328 else if (*ols == 0)
1419 else if (*ols == 0 && lendiff > 0)
1329 {
1330 /* At the end of a line the characters do not have to
1331 be "inserted". They can just be placed on the screen. */
1332 /* However, this screws up the rest of this block, which
1333 assumes you've done the insert because you can. */
1334 _rl_output_some_chars (nfd, lendiff);
1335 _rl_last_c_pos += col_lendiff;
1336 }

--- 6 unchanged lines hidden (view full) ---

1343 _rl_last_c_pos += col_temp;
1344 return;
1345 }
1346 /* Copy (new) chars to screen from first diff to last match. */
1347 temp = nls - nfd;
1348 if ((temp - lendiff) > 0)
1349 {
1350 _rl_output_some_chars (nfd + lendiff, temp - lendiff);
1420 {
1421 /* At the end of a line the characters do not have to
1422 be "inserted". They can just be placed on the screen. */
1423 /* However, this screws up the rest of this block, which
1424 assumes you've done the insert because you can. */
1425 _rl_output_some_chars (nfd, lendiff);
1426 _rl_last_c_pos += col_lendiff;
1427 }

--- 6 unchanged lines hidden (view full) ---

1434 _rl_last_c_pos += col_temp;
1435 return;
1436 }
1437 /* Copy (new) chars to screen from first diff to last match. */
1438 temp = nls - nfd;
1439 if ((temp - lendiff) > 0)
1440 {
1441 _rl_output_some_chars (nfd + lendiff, temp - lendiff);
1351#if 0
1352 _rl_last_c_pos += _rl_col_width (nfd+lendiff, 0, temp-lendiff) - col_lendiff;
1353#else
1442#if 1
1443 /* XXX -- this bears closer inspection. Fixes a redisplay bug
1444 reported against bash-3.0-alpha by Andreas Schwab involving
1445 multibyte characters and prompt strings with invisible
1446 characters, but was previously disabled. */
1354 _rl_last_c_pos += _rl_col_width (nfd+lendiff, 0, temp-col_lendiff);
1447 _rl_last_c_pos += _rl_col_width (nfd+lendiff, 0, temp-col_lendiff);
1448#else
1449 _rl_last_c_pos += _rl_col_width (nfd+lendiff, 0, temp-lendiff);
1355#endif
1356 }
1357 }
1358 else
1359 {
1360 /* cannot insert chars, write to EOL */
1361 _rl_output_some_chars (nfd, temp);
1362 _rl_last_c_pos += col_temp;

--- 59 unchanged lines hidden (view full) ---

1422 if (vis_lbreaks)
1423 vis_lbreaks[0] = vis_lbreaks[1] = 0;
1424 visible_wrap_offset = 0;
1425 return 0;
1426}
1427
1428/* Tell the update routines that we have moved onto a new line with the
1429 prompt already displayed. Code originally from the version of readline
1450#endif
1451 }
1452 }
1453 else
1454 {
1455 /* cannot insert chars, write to EOL */
1456 _rl_output_some_chars (nfd, temp);
1457 _rl_last_c_pos += col_temp;

--- 59 unchanged lines hidden (view full) ---

1517 if (vis_lbreaks)
1518 vis_lbreaks[0] = vis_lbreaks[1] = 0;
1519 visible_wrap_offset = 0;
1520 return 0;
1521}
1522
1523/* Tell the update routines that we have moved onto a new line with the
1524 prompt already displayed. Code originally from the version of readline
1430 distributed with CLISP. */
1525 distributed with CLISP. rl_expand_prompt must have already been called
1526 (explicitly or implicitly). This still doesn't work exactly right. */
1431int
1432rl_on_new_line_with_prompt ()
1433{
1434 int prompt_size, i, l, real_screenwidth, newlines;
1527int
1528rl_on_new_line_with_prompt ()
1529{
1530 int prompt_size, i, l, real_screenwidth, newlines;
1435 char *prompt_last_line;
1531 char *prompt_last_line, *lprompt;
1436
1437 /* Initialize visible_line and invisible_line to ensure that they can hold
1438 the already-displayed prompt. */
1439 prompt_size = strlen (rl_prompt) + 1;
1440 init_line_structures (prompt_size);
1441
1442 /* Make sure the line structures hold the already-displayed prompt for
1443 redisplay. */
1532
1533 /* Initialize visible_line and invisible_line to ensure that they can hold
1534 the already-displayed prompt. */
1535 prompt_size = strlen (rl_prompt) + 1;
1536 init_line_structures (prompt_size);
1537
1538 /* Make sure the line structures hold the already-displayed prompt for
1539 redisplay. */
1444 strcpy (visible_line, rl_prompt);
1445 strcpy (invisible_line, rl_prompt);
1540 lprompt = local_prompt ? local_prompt : rl_prompt;
1541 strcpy (visible_line, lprompt);
1542 strcpy (invisible_line, lprompt);
1446
1447 /* If the prompt contains newlines, take the last tail. */
1448 prompt_last_line = strrchr (rl_prompt, '\n');
1449 if (!prompt_last_line)
1450 prompt_last_line = rl_prompt;
1451
1452 l = strlen (prompt_last_line);
1453 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)

--- 18 unchanged lines hidden (view full) ---

1472 {
1473 _rl_vis_botlin = newlines;
1474 vis_lbreaks[newlines++] = i;
1475 i += real_screenwidth;
1476 }
1477 vis_lbreaks[newlines] = l;
1478 visible_wrap_offset = 0;
1479
1543
1544 /* If the prompt contains newlines, take the last tail. */
1545 prompt_last_line = strrchr (rl_prompt, '\n');
1546 if (!prompt_last_line)
1547 prompt_last_line = rl_prompt;
1548
1549 l = strlen (prompt_last_line);
1550 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)

--- 18 unchanged lines hidden (view full) ---

1569 {
1570 _rl_vis_botlin = newlines;
1571 vis_lbreaks[newlines++] = i;
1572 i += real_screenwidth;
1573 }
1574 vis_lbreaks[newlines] = l;
1575 visible_wrap_offset = 0;
1576
1577 rl_display_prompt = rl_prompt; /* XXX - make sure it's set */
1578
1480 return 0;
1481}
1482
1483/* Actually update the display, period. */
1484int
1485rl_forced_update_display ()
1486{
1487 if (visible_line)

--- 18 unchanged lines hidden (view full) ---

1506 const char *data;
1507{
1508 register int i;
1509
1510 /* If we don't have to do anything, then return. */
1511#if defined (HANDLE_MULTIBYTE)
1512 /* If we have multibyte characters, NEW is indexed by the buffer point in
1513 a multibyte string, but _rl_last_c_pos is the display position. In
1579 return 0;
1580}
1581
1582/* Actually update the display, period. */
1583int
1584rl_forced_update_display ()
1585{
1586 if (visible_line)

--- 18 unchanged lines hidden (view full) ---

1605 const char *data;
1606{
1607 register int i;
1608
1609 /* If we don't have to do anything, then return. */
1610#if defined (HANDLE_MULTIBYTE)
1611 /* If we have multibyte characters, NEW is indexed by the buffer point in
1612 a multibyte string, but _rl_last_c_pos is the display position. In
1514 this case, NEW's display position is not obvious. */
1515 if ((MB_CUR_MAX == 1 || rl_byte_oriented ) && _rl_last_c_pos == new) return;
1613 this case, NEW's display position is not obvious and must be
1614 calculated. */
1615 if (MB_CUR_MAX == 1 || rl_byte_oriented)
1616 {
1617 if (_rl_last_c_pos == new)
1618 return;
1619 }
1620 else if (_rl_last_c_pos == _rl_col_width (data, 0, new))
1621 return;
1516#else
1517 if (_rl_last_c_pos == new) return;
1518#endif
1519
1520 /* It may be faster to output a CR, and then move forwards instead
1521 of moving backwards. */
1522 /* i == current physical cursor position. */
1523 i = _rl_last_c_pos - W_OFFSET(_rl_last_v_pos, visible_wrap_offset);

--- 66 unchanged lines hidden (view full) ---

1590 of the string, which means that if NEW == _rl_last_c_pos, then NEW's
1591 display point is less than _rl_last_c_pos. */
1592 else if (_rl_last_c_pos >= new)
1593#else
1594 else if (_rl_last_c_pos > new)
1595#endif
1596 {
1597 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
1622#else
1623 if (_rl_last_c_pos == new) return;
1624#endif
1625
1626 /* It may be faster to output a CR, and then move forwards instead
1627 of moving backwards. */
1628 /* i == current physical cursor position. */
1629 i = _rl_last_c_pos - W_OFFSET(_rl_last_v_pos, visible_wrap_offset);

--- 66 unchanged lines hidden (view full) ---

1696 of the string, which means that if NEW == _rl_last_c_pos, then NEW's
1697 display point is less than _rl_last_c_pos. */
1698 else if (_rl_last_c_pos >= new)
1699#else
1700 else if (_rl_last_c_pos > new)
1701#endif
1702 {
1703 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
1598 {
1599 tputs (_rl_term_cr, 1, _rl_output_character_function);
1600 for (i = 0; i < new; i++)
1601 putc (data[i], rl_outstream);
1602 }
1704 _rl_backspace (_rl_last_c_pos - _rl_col_width (data, 0, new));
1603 else
1604 _rl_backspace (_rl_last_c_pos - new);
1605 }
1606
1607 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
1608 _rl_last_c_pos = _rl_col_width (data, 0, new);
1609 else
1610 _rl_last_c_pos = new;

--- 149 unchanged lines hidden (view full) ---

1760{
1761 rl_on_new_line ();
1762
1763 rl_display_prompt = rl_prompt ? rl_prompt : "";
1764 forced_display = 1;
1765 return 0;
1766}
1767
1705 else
1706 _rl_backspace (_rl_last_c_pos - new);
1707 }
1708
1709 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
1710 _rl_last_c_pos = _rl_col_width (data, 0, new);
1711 else
1712 _rl_last_c_pos = new;

--- 149 unchanged lines hidden (view full) ---

1862{
1863 rl_on_new_line ();
1864
1865 rl_display_prompt = rl_prompt ? rl_prompt : "";
1866 forced_display = 1;
1867 return 0;
1868}
1869
1870/* These are getting numerous enough that it's time to create a struct. */
1871
1768static char *saved_local_prompt;
1769static char *saved_local_prefix;
1770static int saved_last_invisible;
1771static int saved_visible_length;
1872static char *saved_local_prompt;
1873static char *saved_local_prefix;
1874static int saved_last_invisible;
1875static int saved_visible_length;
1876static int saved_invis_chars_first_line;
1877static int saved_physical_chars;
1772
1773void
1774rl_save_prompt ()
1775{
1776 saved_local_prompt = local_prompt;
1777 saved_local_prefix = local_prompt_prefix;
1778 saved_last_invisible = prompt_last_invisible;
1779 saved_visible_length = prompt_visible_length;
1878
1879void
1880rl_save_prompt ()
1881{
1882 saved_local_prompt = local_prompt;
1883 saved_local_prefix = local_prompt_prefix;
1884 saved_last_invisible = prompt_last_invisible;
1885 saved_visible_length = prompt_visible_length;
1886 saved_invis_chars_first_line = prompt_invis_chars_first_line;
1887 saved_physical_chars = prompt_physical_chars;
1780
1781 local_prompt = local_prompt_prefix = (char *)0;
1782 prompt_last_invisible = prompt_visible_length = 0;
1888
1889 local_prompt = local_prompt_prefix = (char *)0;
1890 prompt_last_invisible = prompt_visible_length = 0;
1891 prompt_invis_chars_first_line = prompt_physical_chars = 0;
1783}
1784
1785void
1786rl_restore_prompt ()
1787{
1788 FREE (local_prompt);
1789 FREE (local_prompt_prefix);
1790
1791 local_prompt = saved_local_prompt;
1792 local_prompt_prefix = saved_local_prefix;
1793 prompt_last_invisible = saved_last_invisible;
1794 prompt_visible_length = saved_visible_length;
1892}
1893
1894void
1895rl_restore_prompt ()
1896{
1897 FREE (local_prompt);
1898 FREE (local_prompt_prefix);
1899
1900 local_prompt = saved_local_prompt;
1901 local_prompt_prefix = saved_local_prefix;
1902 prompt_last_invisible = saved_last_invisible;
1903 prompt_visible_length = saved_visible_length;
1904 prompt_invis_chars_first_line = saved_invis_chars_first_line;
1905 prompt_physical_chars = saved_physical_chars;
1795}
1796
1797char *
1798_rl_make_prompt_for_search (pchar)
1799 int pchar;
1800{
1801 int len;
1802 char *pmt;

--- 16 unchanged lines hidden (view full) ---

1819 if (len)
1820 strcpy (pmt, saved_local_prompt);
1821 pmt[len] = pchar;
1822 pmt[len+1] = '\0';
1823 local_prompt = savestring (pmt);
1824 prompt_last_invisible = saved_last_invisible;
1825 prompt_visible_length = saved_visible_length + 1;
1826 }
1906}
1907
1908char *
1909_rl_make_prompt_for_search (pchar)
1910 int pchar;
1911{
1912 int len;
1913 char *pmt;

--- 16 unchanged lines hidden (view full) ---

1930 if (len)
1931 strcpy (pmt, saved_local_prompt);
1932 pmt[len] = pchar;
1933 pmt[len+1] = '\0';
1934 local_prompt = savestring (pmt);
1935 prompt_last_invisible = saved_last_invisible;
1936 prompt_visible_length = saved_visible_length + 1;
1937 }
1938
1827 return pmt;
1828}
1829
1830/* Quick redisplay hack when erasing characters at the end of the line. */
1831void
1832_rl_erase_at_end_of_line (l)
1833 int l;
1834{

--- 160 unchanged lines hidden (view full) ---

1995/* Redraw the last line of a multi-line prompt that may possibly contain
1996 terminal escape sequences. Called with the cursor at column 0 of the
1997 line to draw the prompt on. */
1998static void
1999redraw_prompt (t)
2000 char *t;
2001{
2002 char *oldp, *oldl, *oldlprefix;
1939 return pmt;
1940}
1941
1942/* Quick redisplay hack when erasing characters at the end of the line. */
1943void
1944_rl_erase_at_end_of_line (l)
1945 int l;
1946{

--- 160 unchanged lines hidden (view full) ---

2107/* Redraw the last line of a multi-line prompt that may possibly contain
2108 terminal escape sequences. Called with the cursor at column 0 of the
2109 line to draw the prompt on. */
2110static void
2111redraw_prompt (t)
2112 char *t;
2113{
2114 char *oldp, *oldl, *oldlprefix;
2003 int oldlen, oldlast, oldplen, oldninvis;
2115 int oldlen, oldlast, oldplen, oldninvis, oldphyschars;
2004
2005 /* Geez, I should make this a struct. */
2006 oldp = rl_display_prompt;
2007 oldl = local_prompt;
2008 oldlprefix = local_prompt_prefix;
2009 oldlen = prompt_visible_length;
2010 oldplen = prompt_prefix_length;
2011 oldlast = prompt_last_invisible;
2012 oldninvis = prompt_invis_chars_first_line;
2116
2117 /* Geez, I should make this a struct. */
2118 oldp = rl_display_prompt;
2119 oldl = local_prompt;
2120 oldlprefix = local_prompt_prefix;
2121 oldlen = prompt_visible_length;
2122 oldplen = prompt_prefix_length;
2123 oldlast = prompt_last_invisible;
2124 oldninvis = prompt_invis_chars_first_line;
2125 oldphyschars = prompt_physical_chars;
2013
2014 rl_display_prompt = t;
2015 local_prompt = expand_prompt (t, &prompt_visible_length,
2016 &prompt_last_invisible,
2126
2127 rl_display_prompt = t;
2128 local_prompt = expand_prompt (t, &prompt_visible_length,
2129 &prompt_last_invisible,
2017 &prompt_invis_chars_first_line);
2130 &prompt_invis_chars_first_line,
2131 &prompt_physical_chars);
2018 local_prompt_prefix = (char *)NULL;
2019 rl_forced_update_display ();
2020
2021 rl_display_prompt = oldp;
2022 local_prompt = oldl;
2023 local_prompt_prefix = oldlprefix;
2024 prompt_visible_length = oldlen;
2025 prompt_prefix_length = oldplen;
2026 prompt_last_invisible = oldlast;
2027 prompt_invis_chars_first_line = oldninvis;
2132 local_prompt_prefix = (char *)NULL;
2133 rl_forced_update_display ();
2134
2135 rl_display_prompt = oldp;
2136 local_prompt = oldl;
2137 local_prompt_prefix = oldlprefix;
2138 prompt_visible_length = oldlen;
2139 prompt_prefix_length = oldplen;
2140 prompt_last_invisible = oldlast;
2141 prompt_invis_chars_first_line = oldninvis;
2142 prompt_physical_chars = oldphyschars;
2028}
2029
2030/* Redisplay the current line after a SIGWINCH is received. */
2031void
2032_rl_redisplay_after_sigwinch ()
2033{
2034 char *t;
2035

--- 77 unchanged lines hidden (view full) ---

2113}
2114
2115#if defined (HANDLE_MULTIBYTE)
2116/* Calculate the number of screen columns occupied by STR from START to END.
2117 In the case of multibyte characters with stateful encoding, we have to
2118 scan from the beginning of the string to take the state into account. */
2119static int
2120_rl_col_width (str, start, end)
2143}
2144
2145/* Redisplay the current line after a SIGWINCH is received. */
2146void
2147_rl_redisplay_after_sigwinch ()
2148{
2149 char *t;
2150

--- 77 unchanged lines hidden (view full) ---

2228}
2229
2230#if defined (HANDLE_MULTIBYTE)
2231/* Calculate the number of screen columns occupied by STR from START to END.
2232 In the case of multibyte characters with stateful encoding, we have to
2233 scan from the beginning of the string to take the state into account. */
2234static int
2235_rl_col_width (str, start, end)
2121 char *str;
2236 const char *str;
2122 int start, end;
2123{
2124 wchar_t wc;
2125 mbstate_t ps = {0};
2126 int tmp, point, width, max;
2127
2128 if (end <= start)
2129 return 0;
2130
2131 point = 0;
2132 max = end;
2133
2134 while (point < start)
2135 {
2136 tmp = mbrlen (str + point, max, &ps);
2237 int start, end;
2238{
2239 wchar_t wc;
2240 mbstate_t ps = {0};
2241 int tmp, point, width, max;
2242
2243 if (end <= start)
2244 return 0;
2245
2246 point = 0;
2247 max = end;
2248
2249 while (point < start)
2250 {
2251 tmp = mbrlen (str + point, max, &ps);
2137 if ((size_t)tmp == (size_t)-1 || (size_t)tmp == (size_t)-2)
2252 if (MB_INVALIDCH ((size_t)tmp))
2138 {
2139 /* In this case, the bytes are invalid or too short to compose a
2140 multibyte character, so we assume that the first byte represents
2141 a single character. */
2142 point++;
2143 max--;
2144
2145 /* Clear the state of the byte sequence, because in this case the
2146 effect of mbstate is undefined. */
2147 memset (&ps, 0, sizeof (mbstate_t));
2148 }
2253 {
2254 /* In this case, the bytes are invalid or too short to compose a
2255 multibyte character, so we assume that the first byte represents
2256 a single character. */
2257 point++;
2258 max--;
2259
2260 /* Clear the state of the byte sequence, because in this case the
2261 effect of mbstate is undefined. */
2262 memset (&ps, 0, sizeof (mbstate_t));
2263 }
2149 else if (tmp == 0)
2150 break; /* Found '\0' */
2264 else if (MB_NULLWCH (tmp))
2265 break; /* Found '\0' */
2151 else
2152 {
2153 point += tmp;
2154 max -= tmp;
2155 }
2156 }
2157
2158 /* If START is not a byte that starts a character, then POINT will be
2159 greater than START. In this case, assume that (POINT - START) gives
2160 a byte count that is the number of columns of difference. */
2161 width = point - start;
2162
2163 while (point < end)
2164 {
2165 tmp = mbrtowc (&wc, str + point, max, &ps);
2266 else
2267 {
2268 point += tmp;
2269 max -= tmp;
2270 }
2271 }
2272
2273 /* If START is not a byte that starts a character, then POINT will be
2274 greater than START. In this case, assume that (POINT - START) gives
2275 a byte count that is the number of columns of difference. */
2276 width = point - start;
2277
2278 while (point < end)
2279 {
2280 tmp = mbrtowc (&wc, str + point, max, &ps);
2166 if ((size_t)tmp == (size_t)-1 || (size_t)tmp == (size_t)-2)
2281 if (MB_INVALIDCH ((size_t)tmp))
2167 {
2168 /* In this case, the bytes are invalid or too short to compose a
2169 multibyte character, so we assume that the first byte represents
2170 a single character. */
2171 point++;
2172 max--;
2173
2174 /* and assume that the byte occupies a single column. */
2175 width++;
2176
2177 /* Clear the state of the byte sequence, because in this case the
2178 effect of mbstate is undefined. */
2179 memset (&ps, 0, sizeof (mbstate_t));
2180 }
2282 {
2283 /* In this case, the bytes are invalid or too short to compose a
2284 multibyte character, so we assume that the first byte represents
2285 a single character. */
2286 point++;
2287 max--;
2288
2289 /* and assume that the byte occupies a single column. */
2290 width++;
2291
2292 /* Clear the state of the byte sequence, because in this case the
2293 effect of mbstate is undefined. */
2294 memset (&ps, 0, sizeof (mbstate_t));
2295 }
2181 else if (tmp == 0)
2182 break; /* Found '\0' */
2296 else if (MB_NULLWCH (tmp))
2297 break; /* Found '\0' */
2183 else
2184 {
2185 point += tmp;
2186 max -= tmp;
2187 tmp = wcwidth(wc);
2188 width += (tmp >= 0) ? tmp : 1;
2189 }
2190 }
2191
2192 width += point - end;
2193
2194 return width;
2195}
2196#endif /* HANDLE_MULTIBYTE */
2298 else
2299 {
2300 point += tmp;
2301 max -= tmp;
2302 tmp = wcwidth(wc);
2303 width += (tmp >= 0) ? tmp : 1;
2304 }
2305 }
2306
2307 width += point - end;
2308
2309 return width;
2310}
2311#endif /* HANDLE_MULTIBYTE */
2197