/* text.c -- text handling commands for readline. */
-/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
static int _rl_char_search_callback PARAMS((_rl_callback_generic_arg *));
#endif
+/* The largest chunk of text that can be inserted in one call to
+ rl_insert_text. Text blocks larger than this are divided. */
+#define TEXT_COUNT_MAX 1024
+
/* **************************************************************** */
/* */
/* Insert and Delete */
if (_rl_doing_an_undo == 0)
rl_add_undo (UNDO_DELETE, from, to, text);
else
- free (text);
+ xfree (text);
rl_end -= diff;
rl_line_buffer[rl_end] = '\0';
{
int n;
+ n = 0;
rl_begin_undo_group ();
- rl_delete_text (start, end + 1);
+ if (start <= end)
+ rl_delete_text (start, end + 1);
rl_point = start;
- n = rl_insert_text (text);
+ if (*text)
+ n = rl_insert_text (text);
rl_end_undo_group ();
return n;
this is the same as rl_end.
Any command that is called interactively receives two arguments.
- The first is a count: the numeric arg pased to this command.
+ The first is a count: the numeric arg passed to this command.
The second is the key which invoked this command.
*/
if (count > 0)
{
- int end = rl_point + count;
+ int end, lend;
+
+ end = rl_point + count;
#if defined (VI_MODE)
- int lend = rl_end > 0 ? rl_end - (VI_COMMAND_MODE()) : rl_end;
+ lend = rl_end > 0 ? rl_end - (VI_COMMAND_MODE()) : rl_end;
#else
- int lend = rl_end;
+ lend = rl_end;
#endif
if (end > lend)
return 0;
}
+int
+_rl_forward_char_internal (count)
+ int count;
+{
+ int point;
+
+#if defined (HANDLE_MULTIBYTE)
+ point = _rl_find_next_mbchar (rl_line_buffer, rl_point, count, MB_FIND_NONZERO);
+
+#if defined (VI_MODE)
+ if (point >= rl_end && VI_COMMAND_MODE())
+ point = _rl_find_prev_mbchar (rl_line_buffer, rl_end, MB_FIND_NONZERO);
+#endif
+
+ if (rl_end < 0)
+ rl_end = 0;
+#else
+ point = rl_point + count;
+ if (point > rl_end)
+ point = rl_end;
+#endif
+
+ return (point);
+}
+
#if defined (HANDLE_MULTIBYTE)
/* Move forward COUNT characters. */
int
return 0;
}
- point = _rl_find_next_mbchar (rl_line_buffer, rl_point, count, MB_FIND_NONZERO);
-
-#if defined (VI_MODE)
- if (point >= rl_end && VI_COMMAND_MODE())
- point = _rl_find_prev_mbchar (rl_line_buffer, rl_end, MB_FIND_NONZERO);
-#endif
+ point = _rl_forward_char_internal (count);
if (rl_point == point)
rl_ding ();
rl_point = point;
-
- if (rl_end < 0)
- rl_end = 0;
}
return 0;
}
int
+rl_skip_csi_sequence (count, key)
+ int count, key;
+{
+ int ch;
+
+ RL_SETSTATE (RL_STATE_MOREINPUT);
+ do
+ ch = rl_read_key ();
+ while (ch >= 0x20 && ch < 0x40);
+ RL_UNSETSTATE (RL_STATE_MOREINPUT);
+
+ return 0;
+}
+
+int
rl_arrow_keys (count, c)
int count, c;
{
/* If we can optimize, then do it. But don't let people crash
readline because of extra large arguments. */
- if (count > 1 && count <= 1024)
+ if (count > 1 && count <= TEXT_COUNT_MAX)
{
#if defined (HANDLE_MULTIBYTE)
string_size = count * incoming_length;
string[i] = '\0';
rl_insert_text (string);
- free (string);
+ xfree (string);
return 0;
}
- if (count > 1024)
+ if (count > TEXT_COUNT_MAX)
{
int decreaser;
#if defined (HANDLE_MULTIBYTE)
- string_size = incoming_length * 1024;
+ string_size = incoming_length * TEXT_COUNT_MAX;
string = (char *)xmalloc (1 + string_size);
i = 0;
while (count)
{
- decreaser = (count > 1024) ? 1024 : count;
+ decreaser = (count > TEXT_COUNT_MAX) ? TEXT_COUNT_MAX : count;
string[decreaser*incoming_length] = '\0';
rl_insert_text (string);
count -= decreaser;
}
- free (string);
+ xfree (string);
incoming_length = 0;
stored_count = 0;
#else /* !HANDLE_MULTIBYTE */
- char str[1024+1];
+ char str[TEXT_COUNT_MAX+1];
- for (i = 0; i < 1024; i++)
+ for (i = 0; i < TEXT_COUNT_MAX; i++)
str[i] = c;
while (count)
{
- decreaser = (count > 1024 ? 1024 : count);
+ decreaser = (count > TEXT_COUNT_MAX ? TEXT_COUNT_MAX : count);
str[decreaser] = '\0';
rl_insert_text (str);
count -= decreaser;
/* We are inserting a single character.
If there is pending input, then make a string of all of the
pending characters that are bound to rl_insert, and insert
- them all. */
- if (_rl_any_typein ())
+ them all. Don't do this if we're current reading input from
+ a macro. */
+ if ((RL_ISSTATE (RL_STATE_MACROINPUT) == 0) && _rl_pushed_input_available ())
_rl_insert_typein (c);
else
{
if (c < 0)
return -1;
+ if (RL_ISSTATE (RL_STATE_MACRODEF))
+ _rl_add_macro_char (c);
+
#if defined (HANDLE_SIGNALS)
if (RL_ISSTATE (RL_STATE_CALLBACK) == 0)
_rl_restore_tty_signals ();
rl_delete_horizontal_space (count, ignore)
int count, ignore;
{
- int start = rl_point;
+ int start;
while (rl_point && whitespace (rl_line_buffer[rl_point - 1]))
rl_point--;
wchar_t wc, nwc;
char mb[MB_LEN_MAX+1];
int mlen;
+ size_t m;
mbstate_t mps;
#endif
#if defined (HANDLE_MULTIBYTE)
else
{
- mbrtowc (&wc, rl_line_buffer + start, end - start, &mps);
+ m = mbrtowc (&wc, rl_line_buffer + start, end - start, &mps);
+ if (MB_INVALIDCH (m))
+ wc = (wchar_t)rl_line_buffer[start];
+ else if (MB_NULLWCH (m))
+ wc = L'\0';
nwc = (nop == UpCase) ? _rl_to_wupper (wc) : _rl_to_wlower (wc);
if (nwc != wc) /* just skip unchanged characters */
{
/* I think that does it. */
rl_end_undo_group ();
- free (word1);
- free (word2);
+ xfree (word1);
+ xfree (word2);
return 0;
}
rl_end_undo_group ();
#if defined (HANDLE_MULTIBYTE)
- free (dummy);
+ xfree (dummy);
#endif
return 0;
int prepos;
#endif
+ if (dir == 0)
+ return -1;
+
pos = rl_point;
inc = (dir < 0) ? -1 : 1;
while (count)