Imported from ../bash-4.0.tar.gz.

This commit is contained in:
Jari Aalto 2009-02-19 22:21:29 +00:00
commit 17345e5ad2
134 changed files with 74214 additions and 4584 deletions

View file

@ -796,6 +796,8 @@ _rl_read_file (filename, sizep)
return ((char *)NULL);
}
RL_CHECK_SIGNALS ();
buffer[i] = '\0';
if (sizep)
*sizep = i;
@ -864,6 +866,7 @@ _rl_read_init_file (filename, include_level)
buffer = _rl_read_file (openname, &file_size);
xfree (openname);
RL_CHECK_SIGNALS ();
if (buffer == 0)
return (errno);

View file

@ -87,6 +87,7 @@ _rl_callback_newline ()
}
readline_internal_setup ();
RL_CHECK_SIGNALS ();
}
/* Install a readline handler, set up the terminal, and issue the prompt. */
@ -127,6 +128,7 @@ rl_callback_read_char ()
do
{
RL_CHECK_SIGNALS ();
if (RL_ISSTATE (RL_STATE_ISEARCH))
{
eof = _rl_isearch_callback (_rl_iscxt);
@ -186,6 +188,7 @@ rl_callback_read_char ()
else
eof = readline_internal_char ();
RL_CHECK_SIGNALS ();
if (rl_done == 0 && _rl_want_redisplay)
{
(*rl_redisplay_function) ();
@ -223,6 +226,7 @@ rl_callback_handler_remove ()
{
rl_linefunc = NULL;
RL_UNSETSTATE (RL_STATE_CALLBACK);
RL_CHECK_SIGNALS ();
if (in_handler)
{
in_handler = 0;

View file

@ -1019,7 +1019,9 @@ gen_completion_matches (text, start, end, our_func, found_quote, quote_char)
variable rl_attempted_completion_function. */
if (rl_attempted_completion_function)
{
_rl_interrupt_immediately++;
matches = (*rl_attempted_completion_function) (text, start, end);
_rl_interrupt_immediately--;
if (matches || rl_attempted_completion_over)
{
@ -1881,6 +1883,7 @@ rl_completion_matches (text, entry_function)
match_list = (char **)xmalloc ((match_list_size + 1) * sizeof (char *));
match_list[1] = (char *)NULL;
_rl_interrupt_immediately++;
while (string = (*entry_function) (text, matches))
{
if (matches + 1 == match_list_size)
@ -1890,6 +1893,7 @@ rl_completion_matches (text, entry_function)
match_list[++matches] = string;
match_list[matches + 1] = (char *)NULL;
}
_rl_interrupt_immediately--;
/* If there were any matches, then look through them finding out the
lowest common denominator. That then becomes match_list[0]. */

View file

@ -1016,7 +1016,7 @@ history_expand (hstring, output)
}
else if (string[i] == history_expansion_char)
{
if (!cc || member (cc, history_no_expand_chars))
if (cc == 0 || member (cc, history_no_expand_chars))
continue;
/* If the calling application has set
history_inhibit_expansion_function to a function that checks
@ -1164,7 +1164,8 @@ history_expand (hstring, output)
/* If the history_expansion_char is followed by one of the
characters in history_no_expand_chars, then it is not a
candidate for expansion of any kind. */
if (member (cc, history_no_expand_chars))
if (cc == 0 || member (cc, history_no_expand_chars) ||
(history_inhibit_expansion_function && (*history_inhibit_expansion_function) (string, i)))
{
ADD_CHAR (string[i]);
break;

View file

@ -252,6 +252,7 @@ rl_gather_tyi ()
{
while (chars_avail--)
{
RL_CHECK_SIGNALS ();
k = (*rl_getc_function) (rl_instream);
if (rl_stuff_char (k) == 0)
break; /* some problem; no more room */
@ -437,6 +438,7 @@ rl_read_key ()
while (rl_event_hook && rl_get_char (&c) == 0)
{
(*rl_event_hook) ();
RL_CHECK_SIGNALS ();
if (rl_done) /* XXX - experimental */
return ('\n');
if (rl_gather_tyi () < 0) /* XXX - EIO */
@ -450,6 +452,7 @@ rl_read_key ()
{
if (rl_get_char (&c) == 0)
c = (*rl_getc_function) (rl_instream);
RL_CHECK_SIGNALS ();
}
}
@ -465,6 +468,8 @@ rl_getc (stream)
while (1)
{
RL_CHECK_SIGNALS ();
#if defined (__MINGW32__)
if (isatty (fileno (stream)))
return (getch ());

View file

@ -383,7 +383,7 @@ _rl_isearch_dispatch (cxt, c)
{
if (cxt->lastc >= 0 && (cxt->mb[0] && cxt->mb[1] == '\0') && ENDSRCH_CHAR (cxt->lastc))
{
/* This sets rl_pending_input to c; it will be picked up the next
/* This sets rl_pending_input to LASTC; it will be picked up the next
time rl_read_key is called. */
rl_execute_next (cxt->lastc);
return (0);

View file

@ -397,6 +397,8 @@ readline_internal_setup ()
if (rl_pre_input_hook)
(*rl_pre_input_hook) ();
RL_CHECK_SIGNALS ();
}
STATIC_CALLBACK char *
@ -406,6 +408,8 @@ readline_internal_teardown (eof)
char *temp;
HIST_ENTRY *entry;
RL_CHECK_SIGNALS ();
/* Restore the original of this history line, iff the line that we
are editing was originally in the history, AND the line has changed. */
entry = current_history ();
@ -542,6 +546,7 @@ readline_internal_charloop ()
lastc = c;
_rl_dispatch ((unsigned char)c, _rl_keymap);
RL_CHECK_SIGNALS ();
/* If there was no change in _rl_last_command_was_kill, then no kill
has taken place. Note that if input is pending we are reading
@ -662,7 +667,6 @@ _rl_dispatch_callback (cxt)
int nkey, r;
/* For now */
#if 1
/* The first time this context is used, we want to read input and dispatch
on it. When traversing the chain of contexts back `up', we want to use
the value from the next context down. We're simulating recursion using
@ -680,13 +684,11 @@ _rl_dispatch_callback (cxt)
}
else
r = cxt->childval;
#else
r = _rl_dispatch_subseq (nkey, cxt->dmap, cxt->subseq_arg);
#endif
/* For now */
r = _rl_subseq_result (r, cxt->oldmap, cxt->okey, (cxt->flags & KSEQ_SUBSEQ));
RL_CHECK_SIGNALS ();
if (r == 0) /* success! */
{
_rl_keyseq_chain_dispose ();
@ -773,6 +775,8 @@ _rl_dispatch_subseq (key, map, got_subseq)
remember the last command executed in this variable. */
if (rl_pending_input == 0 && map[key].function != rl_digit_argument)
rl_last_func = map[key].function;
RL_CHECK_SIGNALS ();
}
else if (map[ANYOTHERKEY].function)
{

View file

@ -37,6 +37,11 @@
#define VI_COMMAND_MODE() (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap)
#define VI_INSERT_MODE() (rl_editing_mode == vi_mode && _rl_keymap == vi_insertion_keymap)
#define RL_CHECK_SIGNALS() \
do { \
if (_rl_caught_signal) _rl_signal_handler (_rl_caught_signal); \
} while (0)
/*************************************************************************
* *
* Global structs undocumented in texinfo manual and not in readline.h *
@ -291,6 +296,8 @@ extern int _rl_restore_tty_signals PARAMS((void));
extern int _rl_nsearch_callback PARAMS((_rl_search_cxt *));
/* signals.c */
extern void _rl_signal_handler PARAMS((int));
extern void _rl_block_sigint PARAMS((void));
extern void _rl_release_sigint PARAMS((void));
@ -424,6 +431,9 @@ extern _rl_keyseq_cxt *_rl_kscxt;
extern _rl_search_cxt *_rl_nscxt;
/* signals.c */
extern int _rl_interrupt_immediately;
extern int volatile _rl_caught_signal;
extern int _rl_echoctl;
extern int _rl_intr_char;

View file

@ -81,6 +81,9 @@ typedef struct { SigHandler *sa_handler; int sa_mask, sa_flags; } sighandler_cxt
static SigHandler *rl_set_sighandler PARAMS((int, SigHandler *, sighandler_cxt *));
static void rl_maybe_set_sighandler PARAMS((int, SigHandler *, sighandler_cxt *));
static RETSIGTYPE rl_signal_handler PARAMS((int));
static RETSIGTYPE _rl_handle_signal PARAMS((int));
/* Exported variables for use by applications. */
/* If non-zero, readline will install its own signal handlers for
@ -95,6 +98,9 @@ int rl_catch_sigwinch = 0; /* for the readline state struct in readline.c */
#endif
/* Private variables. */
int _rl_interrupt_immediately = 0;
int volatile _rl_caught_signal = 0; /* should be sig_atomic_t, but that requires including <signal.h> everywhere */
/* If non-zero, print characters corresponding to received signals. */
int _rl_echoctl = 0;
@ -121,9 +127,33 @@ static sighandler_cxt old_winch;
/* Readline signal handler functions. */
/* Called from RL_CHECK_SIGNALS() macro */
RETSIGTYPE
_rl_signal_handler (sig)
{
_rl_caught_signal = 0; /* XXX */
_rl_handle_signal (sig);
SIGHANDLER_RETURN;
}
static RETSIGTYPE
rl_signal_handler (sig)
int sig;
{
if (_rl_interrupt_immediately)
{
_rl_interrupt_immediately = 0;
_rl_handle_signal (sig);
}
_rl_caught_signal = sig;
SIGHANDLER_RETURN;
}
static RETSIGTYPE
_rl_handle_signal (sig)
int sig;
{
#if defined (HAVE_POSIX_SIGNALS)
sigset_t set;

View file

@ -114,7 +114,7 @@ rl_free_undo_list ()
rl_undo_list = rl_undo_list->next;
if (release->what == UNDO_DELETE)
free (release->text);
xfree (release->text);
xfree (release);
}
@ -191,7 +191,7 @@ rl_do_undo ()
case UNDO_DELETE:
rl_point = start;
rl_insert_text (rl_undo_list->text);
free (rl_undo_list->text);
xfree (rl_undo_list->text);
break;
/* Undoing inserts means deleting some text. */

View file

@ -53,13 +53,17 @@
#endif
/* These must agree with the defines in externs.h */
#define CASE_NOOP 0x0
#define CASE_LOWER 0x01
#define CASE_UPPER 0x02
#define CASE_CAPITALIZE 0x04
#define CASE_UNCAP 0x08
#define CASE_TOGGLE 0x10
#define CASE_TOGGLEALL 0x20
#define CASE_NOOP 0x0000
#define CASE_LOWER 0x0001
#define CASE_UPPER 0x0002
#define CASE_CAPITALIZE 0x0004
#define CASE_UNCAP 0x0008
#define CASE_TOGGLE 0x0010
#define CASE_TOGGLEALL 0x0020
#define CASE_UPFIRST 0x0040
#define CASE_LOWFIRST 0x0080
#define CASE_USEWORDS 0x1000 /* modify behavior to act on words in passed string */
extern char *substring __P((char *, int, int));
@ -96,7 +100,7 @@ sh_modcase (string, pat, flags)
int flags;
{
int start, next, end;
int inword, c, nc, nop, match;
int inword, c, nc, nop, match, usewords;
char *ret, *s;
wchar_t wc;
#if defined (HANDLE_MULTIBYTE)
@ -116,6 +120,10 @@ sh_modcase (string, pat, flags)
ret = (char *)xmalloc (end + 1);
strcpy (ret, string);
/* See if we are supposed to split on alphanumerics and operate on each word */
usewords = (flags & CASE_USEWORDS);
flags &= ~CASE_USEWORDS;
inword = 0;
while (start < end)
{
@ -143,16 +151,41 @@ sh_modcase (string, pat, flags)
}
}
/* XXX - for now, the toggling operators work on the individual
words in the string, breaking on alphanumerics. Should I
leave the capitalization operators to do that also? */
if (flags == CASE_CAPITALIZE)
{
nop = inword ? CASE_LOWER : CASE_UPPER;
if (usewords)
nop = inword ? CASE_LOWER : CASE_UPPER;
else
nop = (start > 0) ? CASE_LOWER : CASE_UPPER;
inword = 1;
}
else if (flags == CASE_UNCAP)
{
nop = inword ? CASE_UPPER : CASE_LOWER;
if (usewords)
nop = inword ? CASE_UPPER : CASE_LOWER;
else
nop = (start > 0) ? CASE_UPPER : CASE_LOWER;
inword = 1;
}
else if (flags == CASE_UPFIRST)
{
if (usewords)
nop = inword ? CASE_NOOP : CASE_UPPER;
else
nop = (start > 0) ? CASE_NOOP : CASE_UPPER;
inword = 1;
}
else if (flags == CASE_LOWFIRST)
{
if (usewords)
nop = inword ? CASE_NOOP : CASE_LOWER;
else
nop = (start > 0) ? CASE_NOOP : CASE_LOWER;
inword = 1;
}
else if (flags == CASE_TOGGLE)
{
nop = inword ? CASE_NOOP : CASE_TOGGLE;

View file

@ -36,6 +36,11 @@ extern int errno;
extern ssize_t zread __P((int, char *, size_t));
extern ssize_t zreadc __P((int, char *));
extern ssize_t zreadintr __P((int, char *, size_t));
extern ssize_t zreadcintr __P((int, char *));
typedef ssize_t breadfunc_t __P((int, char *, size_t));
typedef ssize_t creadfunc_t __P((int, char *));
/* Initial memory allocation for automatic growing buffer in zreadlinec */
#define GET_LINE_INITIAL_ALLOCATION 16
@ -74,31 +79,32 @@ zgetline (fd, lineptr, n, unbuffered_read)
if (retval <= 0)
{
line[nr] = '\0';
if (line && nr > 0)
line[nr] = '\0';
break;
}
if (nr + 2 >= *n)
{
size_t new_size;
size_t new_size;
new_size = (*n == 0) ? GET_LINE_INITIAL_ALLOCATION : *n * 2;
line = xrealloc (*lineptr, new_size);
new_size = (*n == 0) ? GET_LINE_INITIAL_ALLOCATION : *n * 2;
line = (*n >= new_size) ? NULL : xrealloc (*lineptr, new_size);
if (line)
{
*lineptr = line;
*n = new_size;
}
else
{
if (*n > 0)
{
(*lineptr)[*n - 1] = '\0';
nr = *n - 2;
}
break;
}
if (line)
{
*lineptr = line;
*n = new_size;
}
else
{
if (*n > 0)
{
(*lineptr)[*n - 1] = '\0';
nr = *n - 2;
}
break;
}
}
line[nr] = c;

View file

@ -60,7 +60,7 @@ zread (fd, buf, len)
#define NUM_INTR 3
ssize_t
zreadintr (fd, buf, len)
zreadretry (fd, buf, len)
int fd;
char *buf;
size_t len;
@ -75,7 +75,7 @@ zreadintr (fd, buf, len)
return r;
if (r == -1 && errno == EINTR)
{
if (++nintr > NUM_INTR)
if (++nintr >= NUM_INTR)
return -1;
continue;
}
@ -83,6 +83,16 @@ zreadintr (fd, buf, len)
}
}
/* Call read(2) and allow it to be interrupted. Just a stub for now. */
ssize_t
zreadintr (fd, buf, len)
int fd;
char *buf;
size_t len;
{
return (read (fd, buf, len));
}
/* Read one character from FD and return it in CP. Return values are as
in read(2). This does some local buffering to avoid many one-character
calls to read(2), like those the `read' builtin performs. */
@ -113,6 +123,31 @@ zreadc (fd, cp)
return 1;
}
/* Don't mix calls to zreadc and zreadcintr in the same function, since they
use the same local buffer. */
ssize_t
zreadcintr (fd, cp)
int fd;
char *cp;
{
ssize_t nr;
if (lind == lused || lused == 0)
{
nr = zreadintr (fd, lbuf, sizeof (lbuf));
lind = 0;
if (nr <= 0)
{
lused = 0;
return nr;
}
lused = nr;
}
if (cp)
*cp = lbuf[lind++];
return 1;
}
void
zreset ()
{