Submitted By: William Harrington (kb0iic at cross-lfs dot org)
Date: 09-26-2014
Initial Package Version: 4.3
Origin: Upstream
Upstream Status: Applied
Description: Contains all upstream patches up to 4.3-026
diff -Naur bash-4.3.orig/arrayfunc.c bash-4.3/arrayfunc.c
--- bash-4.3.orig/arrayfunc.c 2013-08-02 20:19:59.000000000 +0000
+++ bash-4.3/arrayfunc.c 2014-09-26 23:58:55.592973170 +0000
@@ -179,6 +179,7 @@
array_insert (array_cell (entry), ind, newval);
FREE (newval);
+ VUNSETATTR (entry, att_invisible); /* no longer invisible */
return (entry);
}
@@ -597,6 +598,11 @@
if (assoc_p (var))
{
val = expand_assignment_string_to_string (val, 0);
+ if (val == 0)
+ {
+ val = (char *)xmalloc (1);
+ val[0] = '\0'; /* like do_assignment_internal */
+ }
free_val = 1;
}
diff -Naur bash-4.3.orig/bashline.c bash-4.3/bashline.c
--- bash-4.3.orig/bashline.c 2014-02-10 00:56:58.000000000 +0000
+++ bash-4.3/bashline.c 2014-09-26 23:58:55.579639869 +0000
@@ -4167,9 +4167,16 @@
int qc;
qc = rl_dispatching ? rl_completion_quote_character : 0;
- dfn = bash_dequote_filename ((char *)text, qc);
+ /* If rl_completion_found_quote != 0, rl_completion_matches will call the
+ filename dequoting function, causing the directory name to be dequoted
+ twice. */
+ if (rl_dispatching && rl_completion_found_quote == 0)
+ dfn = bash_dequote_filename ((char *)text, qc);
+ else
+ dfn = (char *)text;
m1 = rl_completion_matches (dfn, rl_filename_completion_function);
- free (dfn);
+ if (dfn != text)
+ free (dfn);
if (m1 == 0 || m1[0] == 0)
return m1;
diff -Naur bash-4.3.orig/builtins/common.h bash-4.3/builtins/common.h
--- bash-4.3.orig/builtins/common.h 2013-07-08 20:54:47.000000000 +0000
+++ bash-4.3/builtins/common.h 2014-09-26 23:58:55.622973097 +0000
@@ -33,6 +33,8 @@
#define SEVAL_RESETLINE 0x010
#define SEVAL_PARSEONLY 0x020
#define SEVAL_NOLONGJMP 0x040
+#define SEVAL_FUNCDEF 0x080 /* only allow function definitions */
+#define SEVAL_ONECMD 0x100 /* only allow a single command */
/* Flags for describe_command, shared between type.def and command.def */
#define CDESC_ALL 0x001 /* type -a */
diff -Naur bash-4.3.orig/builtins/evalstring.c bash-4.3/builtins/evalstring.c
--- bash-4.3.orig/builtins/evalstring.c 2014-02-11 14:42:10.000000000 +0000
+++ bash-4.3/builtins/evalstring.c 2014-09-26 23:58:55.626306422 +0000
@@ -308,6 +308,14 @@
{
struct fd_bitmap *bitmap;
+ if ((flags & SEVAL_FUNCDEF) && command->type != cm_function_def)
+ {
+ internal_warning ("%s: ignoring function definition attempt", from_file);
+ should_jump_to_top_level = 0;
+ last_result = last_command_exit_value = EX_BADUSAGE;
+ break;
+ }
+
bitmap = new_fd_bitmap (FD_BITMAP_SIZE);
begin_unwind_frame ("pe_dispose");
add_unwind_protect (dispose_fd_bitmap, bitmap);
@@ -368,6 +376,9 @@
dispose_command (command);
dispose_fd_bitmap (bitmap);
discard_unwind_frame ("pe_dispose");
+
+ if (flags & SEVAL_ONECMD)
+ break;
}
}
else
diff -Naur bash-4.3.orig/builtins/read.def bash-4.3/builtins/read.def
--- bash-4.3.orig/builtins/read.def 2013-09-02 15:54:00.000000000 +0000
+++ bash-4.3/builtins/read.def 2014-09-26 23:58:55.596306495 +0000
@@ -442,7 +442,10 @@
add_unwind_protect (reset_alarm, (char *)NULL);
#if defined (READLINE)
if (edit)
- add_unwind_protect (reset_attempted_completion_function, (char *)NULL);
+ {
+ add_unwind_protect (reset_attempted_completion_function, (char *)NULL);
+ add_unwind_protect (bashline_reset_event_hook, (char *)NULL);
+ }
#endif
falarm (tmsec, tmusec);
}
@@ -1021,6 +1024,7 @@
old_attempted_completion_function = rl_attempted_completion_function;
rl_attempted_completion_function = (rl_completion_func_t *)NULL;
+ bashline_set_event_hook ();
if (itext)
{
old_startup_hook = rl_startup_hook;
@@ -1032,6 +1036,7 @@
rl_attempted_completion_function = old_attempted_completion_function;
old_attempted_completion_function = (rl_completion_func_t *)NULL;
+ bashline_reset_event_hook ();
if (ret == 0)
return ret;
diff -Naur bash-4.3.orig/execute_cmd.c bash-4.3/execute_cmd.c
--- bash-4.3.orig/execute_cmd.c 2014-01-31 15:54:52.000000000 +0000
+++ bash-4.3/execute_cmd.c 2014-09-26 23:58:55.609639796 +0000
@@ -2409,7 +2409,16 @@
#endif
lstdin = wait_for (lastpid);
#if defined (JOB_CONTROL)
- exec_result = job_exit_status (lastpipe_jid);
+ /* If wait_for removes the job from the jobs table, use result of last
+ command as pipeline's exit status as usual. The jobs list can get
+ frozen and unfrozen at inconvenient times if there are multiple pipelines
+ running simultaneously. */
+ if (INVALID_JOB (lastpipe_jid) == 0)
+ exec_result = job_exit_status (lastpipe_jid);
+ else if (pipefail_opt)
+ exec_result = exec_result | lstdin; /* XXX */
+ /* otherwise we use exec_result */
+
#endif
unfreeze_jobs_list ();
}
diff -Naur bash-4.3.orig/externs.h bash-4.3/externs.h
--- bash-4.3.orig/externs.h 2014-01-02 19:58:20.000000000 +0000
+++ bash-4.3/externs.h 2014-09-26 23:58:55.556306592 +0000
@@ -324,6 +324,7 @@
extern char *sh_backslash_quote __P((char *, const char *, int));
extern char *sh_backslash_quote_for_double_quotes __P((char *));
extern int sh_contains_shell_metas __P((char *));
+extern int sh_contains_quotes __P((char *));
/* declarations for functions defined in lib/sh/spell.c */
extern int spname __P((char *, char *));
diff -Naur bash-4.3.orig/jobs.c bash-4.3/jobs.c
--- bash-4.3.orig/jobs.c 2014-01-10 14:05:34.000000000 +0000
+++ bash-4.3/jobs.c 2014-09-26 23:58:55.566306568 +0000
@@ -3597,6 +3597,7 @@
unwind_protect_int (jobs_list_frozen);
unwind_protect_pointer (the_pipeline);
unwind_protect_pointer (subst_assign_varlist);
+ unwind_protect_pointer (this_shell_builtin);
/* We have to add the commands this way because they will be run
in reverse order of adding. We don't want maybe_set_sigchld_trap ()
@@ -4374,7 +4375,7 @@
void
end_job_control ()
{
- if (interactive_shell) /* XXX - should it be interactive? */
+ if (interactive_shell || job_control) /* XXX - should it be just job_control? */
{
terminate_stopped_jobs ();
diff -Naur bash-4.3.orig/lib/glob/glob.c bash-4.3/lib/glob/glob.c
--- bash-4.3.orig/lib/glob/glob.c 2014-02-01 02:43:51.000000000 +0000
+++ bash-4.3/lib/glob/glob.c 2014-09-26 23:58:55.582973194 +0000
@@ -123,6 +123,8 @@
extern char *glob_patscan __P((char *, char *, int));
extern wchar_t *glob_patscan_wc __P((wchar_t *, wchar_t *, int));
+extern char *glob_dirscan __P((char *, int));
+
/* Compile `glob_loop.c' for single-byte characters. */
#define CHAR unsigned char
#define INT int
@@ -179,42 +181,53 @@
char *pat, *dname;
int flags;
{
- char *pp, *pe, *t;
- int n, r;
+ char *pp, *pe, *t, *se;
+ int n, r, negate;
+ negate = *pat == '!';
pp = pat + 2;
- pe = pp + strlen (pp) - 1; /*(*/
- if (*pe != ')')
+ se = pp + strlen (pp) - 1; /* end of string */
+ pe = glob_patscan (pp, se, 0); /* end of extglob pattern (( */
+ /* we should check for invalid extglob pattern here */
+ if (pe == 0)
return 0;
- if ((t = strchr (pp, '|')) == 0) /* easy case first */
+
+ /* if pe != se we have more of the pattern at the end of the extglob
+ pattern. Check the easy case first ( */
+ if (pe == se && *pe == ')' && (t = strchr (pp, '|')) == 0)
{
*pe = '\0';
+#if defined (HANDLE_MULTIBYTE)
+ r = mbskipname (pp, dname, flags);
+#else
r = skipname (pp, dname, flags); /*(*/
+#endif
*pe = ')';
return r;
}
+
+ /* check every subpattern */
while (t = glob_patscan (pp, pe, '|'))
{
n = t[-1];
t[-1] = '\0';
+#if defined (HANDLE_MULTIBYTE)
+ r = mbskipname (pp, dname, flags);
+#else
r = skipname (pp, dname, flags);
+#endif
t[-1] = n;
if (r == 0) /* if any pattern says not skip, we don't skip */
return r;
pp = t;
} /*(*/
- if (pp == pe) /* glob_patscan might find end of pattern */
+ /* glob_patscan might find end of pattern */
+ if (pp == se)
return r;
- *pe = '\0';
-# if defined (HANDLE_MULTIBYTE)
- r = mbskipname (pp, dname, flags); /*(*/
-# else
- r = skipname (pp, dname, flags); /*(*/
-# endif
- *pe = ')';
- return r;
+ /* but if it doesn't then we didn't match a leading dot */
+ return 0;
}
#endif
@@ -277,20 +290,23 @@
int flags;
{
#if EXTENDED_GLOB
- wchar_t *pp, *pe, *t, n;
- int r;
+ wchar_t *pp, *pe, *t, n, *se;
+ int r, negate;
+ negate = *pat == L'!';
pp = pat + 2;
- pe = pp + wcslen (pp) - 1; /*(*/
- if (*pe != L')')
- return 0;
- if ((t = wcschr (pp, L'|')) == 0)
+ se = pp + wcslen (pp) - 1; /*(*/
+ pe = glob_patscan_wc (pp, se, 0);
+
+ if (pe == se && *pe == ')' && (t = wcschr (pp, L'|')) == 0)
{
*pe = L'\0';
r = wchkname (pp, dname); /*(*/
*pe = L')';
return r;
}
+
+ /* check every subpattern */
while (t = glob_patscan_wc (pp, pe, '|'))
{
n = t[-1];
@@ -305,10 +321,8 @@
if (pp == pe) /* glob_patscan_wc might find end of pattern */
return r;
- *pe = L'\0';
- r = wchkname (pp, dname); /*(*/
- *pe = L')';
- return r;
+ /* but if it doesn't then we didn't match a leading dot */
+ return 0;
#else
return (wchkname (pat, dname));
#endif
@@ -1006,7 +1020,7 @@
{
char **result;
unsigned int result_size;
- char *directory_name, *filename, *dname;
+ char *directory_name, *filename, *dname, *fn;
unsigned int directory_len;
int free_dirname; /* flag */
int dflags;
@@ -1022,6 +1036,18 @@
/* Find the filename. */
filename = strrchr (pathname, '/');
+#if defined (EXTENDED_GLOB)
+ if (filename && extended_glob)
+ {
+ fn = glob_dirscan (pathname, '/');
+#if DEBUG_MATCHING
+ if (fn != filename)
+ fprintf (stderr, "glob_filename: glob_dirscan: fn (%s) != filename (%s)\n", fn ? fn : "(null)", filename);
+#endif
+ filename = fn;
+ }
+#endif
+
if (filename == NULL)
{
filename = pathname;
diff -Naur bash-4.3.orig/lib/glob/gmisc.c bash-4.3/lib/glob/gmisc.c
--- bash-4.3.orig/lib/glob/gmisc.c 2013-10-28 18:45:25.000000000 +0000
+++ bash-4.3/lib/glob/gmisc.c 2014-09-26 23:58:55.582973194 +0000
@@ -42,6 +42,8 @@
#define WLPAREN L'('
#define WRPAREN L')'
+extern char *glob_patscan __P((char *, char *, int));
+
/* Return 1 of the first character of WSTRING could match the first
character of pattern WPAT. Wide character version. */
int
@@ -210,6 +212,7 @@
case '+':
case '!':
case '@':
+ case '?':
return (pat[1] == LPAREN);
default:
return 0;
@@ -374,3 +377,34 @@
return matlen;
}
+
+/* Skip characters in PAT and return the final occurrence of DIRSEP. This
+ is only called when extended_glob is set, so we have to skip over extglob
+ patterns x(...) */
+char *
+glob_dirscan (pat, dirsep)
+ char *pat;
+ int dirsep;
+{
+ char *p, *d, *pe, *se;
+
+ d = pe = se = 0;
+ for (p = pat; p && *p; p++)
+ {
+ if (extglob_pattern_p (p))
+ {
+ if (se == 0)
+ se = p + strlen (p) - 1;
+ pe = glob_patscan (p + 2, se, 0);
+ if (pe == 0)
+ continue;
+ else if (*pe == 0)
+ break;
+ p = pe - 1; /* will do increment above */
+ continue;
+ }
+ if (*p == dirsep)
+ d = p;
+ }
+ return d;
+}
diff -Naur bash-4.3.orig/lib/readline/display.c bash-4.3/lib/readline/display.c
--- bash-4.3.orig/lib/readline/display.c 2013-12-27 18:10:56.000000000 +0000
+++ bash-4.3/lib/readline/display.c 2014-09-26 23:58:55.569639893 +0000
@@ -1637,7 +1637,7 @@
/* If we are changing the number of invisible characters in a line, and
the spot of first difference is before the end of the invisible chars,
lendiff needs to be adjusted. */
- if (current_line == 0 && !_rl_horizontal_scroll_mode &&
+ if (current_line == 0 && /* !_rl_horizontal_scroll_mode && */
current_invis_chars != visible_wrap_offset)
{
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
@@ -1825,8 +1825,13 @@
else
_rl_last_c_pos += bytes_to_insert;
+ /* XXX - we only want to do this if we are at the end of the line
+ so we move there with _rl_move_cursor_relative */
if (_rl_horizontal_scroll_mode && ((oe-old) > (ne-new)))
- goto clear_rest_of_line;
+ {
+ _rl_move_cursor_relative (ne-new, new);
+ goto clear_rest_of_line;
+ }
}
}
/* Otherwise, print over the existing material. */
@@ -2677,7 +2682,8 @@
{
if (_rl_echoing_p)
{
- _rl_move_vert (_rl_vis_botlin);
+ if (_rl_vis_botlin > 0) /* minor optimization plus bug fix */
+ _rl_move_vert (_rl_vis_botlin);
_rl_vis_botlin = 0;
fflush (rl_outstream);
rl_restart_output (1, 0);
diff -Naur bash-4.3.orig/lib/readline/input.c bash-4.3/lib/readline/input.c
--- bash-4.3.orig/lib/readline/input.c 2014-01-10 20:07:08.000000000 +0000
+++ bash-4.3/lib/readline/input.c 2014-09-26 23:58:55.592973170 +0000
@@ -534,8 +534,16 @@
return (RL_ISSTATE (RL_STATE_READCMD) ? READERR : EOF);
else if (_rl_caught_signal == SIGHUP || _rl_caught_signal == SIGTERM)
return (RL_ISSTATE (RL_STATE_READCMD) ? READERR : EOF);
+ /* keyboard-generated signals of interest */
else if (_rl_caught_signal == SIGINT || _rl_caught_signal == SIGQUIT)
RL_CHECK_SIGNALS ();
+ /* non-keyboard-generated signals of interest */
+ else if (_rl_caught_signal == SIGALRM
+#if defined (SIGVTALRM)
+ || _rl_caught_signal == SIGVTALRM
+#endif
+ )
+ RL_CHECK_SIGNALS ();
if (rl_signal_event_hook)
(*rl_signal_event_hook) ();
diff -Naur bash-4.3.orig/lib/readline/misc.c bash-4.3/lib/readline/misc.c
--- bash-4.3.orig/lib/readline/misc.c 2012-09-01 22:03:11.000000000 +0000
+++ bash-4.3/lib/readline/misc.c 2014-09-26 23:58:55.606306471 +0000
@@ -461,6 +461,7 @@
saved_undo_list = 0;
/* Set up rl_line_buffer and other variables from history entry */
rl_replace_from_history (entry, 0); /* entry->line is now current */
+ entry->data = 0; /* entry->data is now current undo list */
/* Undo all changes to this history entry */
while (rl_undo_list)
rl_do_undo ();
@@ -468,7 +469,6 @@
the timestamp. */
FREE (entry->line);
entry->line = savestring (rl_line_buffer);
- entry->data = 0;
}
entry = previous_history ();
}
diff -Naur bash-4.3.orig/lib/readline/readline.c bash-4.3/lib/readline/readline.c
--- bash-4.3.orig/lib/readline/readline.c 2013-10-28 18:58:06.000000000 +0000
+++ bash-4.3/lib/readline/readline.c 2014-09-26 23:58:55.516306690 +0000
@@ -744,7 +744,8 @@
r = _rl_subseq_result (r, cxt->oldmap, cxt->okey, (cxt->flags & KSEQ_SUBSEQ));
RL_CHECK_SIGNALS ();
- if (r == 0) /* success! */
+ /* We only treat values < 0 specially to simulate recursion. */
+ if (r >= 0 || (r == -1 && (cxt->flags & KSEQ_SUBSEQ) == 0)) /* success! or failure! */
{
_rl_keyseq_chain_dispose ();
RL_UNSETSTATE (RL_STATE_MULTIKEY);
@@ -964,7 +965,7 @@
#if defined (VI_MODE)
if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap &&
key != ANYOTHERKEY &&
- rl_key_sequence_length == 1 && /* XXX */
+ _rl_dispatching_keymap == vi_movement_keymap &&
_rl_vi_textmod_command (key))
_rl_vi_set_last (key, rl_numeric_arg, rl_arg_sign);
#endif
diff -Naur bash-4.3.orig/lib/readline/readline.c.orig bash-4.3/lib/readline/readline.c.orig
--- bash-4.3.orig/lib/readline/readline.c.orig 1970-01-01 00:00:00.000000000 +0000
+++ bash-4.3/lib/readline/readline.c.orig 2014-09-26 23:58:55.512973365 +0000
@@ -0,0 +1,1364 @@
+/* readline.c -- a general facility for reading lines of input
+ with emacs style editing and completion. */
+
+/* Copyright (C) 1987-2013 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.
+
+ Readline is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Readline is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Readline. If not, see .
+*/
+
+#define READLINE_LIBRARY
+
+#if defined (HAVE_CONFIG_H)
+# include
+#endif
+
+#include
+#include "posixstat.h"
+#include
+#if defined (HAVE_SYS_FILE_H)
+# include
+#endif /* HAVE_SYS_FILE_H */
+
+#if defined (HAVE_UNISTD_H)
+# include
+#endif /* HAVE_UNISTD_H */
+
+#if defined (HAVE_STDLIB_H)
+# include
+#else
+# include "ansi_stdlib.h"
+#endif /* HAVE_STDLIB_H */
+
+#if defined (HAVE_LOCALE_H)
+# include
+#endif
+
+#include
+#include "posixjmp.h"
+#include
+
+#if !defined (errno)
+extern int errno;
+#endif /* !errno */
+
+/* System-specific feature definitions and include files. */
+#include "rldefs.h"
+#include "rlmbutil.h"
+
+#if defined (__EMX__)
+# define INCL_DOSPROCESS
+# include
+#endif /* __EMX__ */
+
+/* Some standard library routines. */
+#include "readline.h"
+#include "history.h"
+
+#include "rlprivate.h"
+#include "rlshell.h"
+#include "xmalloc.h"
+
+#ifndef RL_LIBRARY_VERSION
+# define RL_LIBRARY_VERSION "5.1"
+#endif
+
+#ifndef RL_READLINE_VERSION
+# define RL_READLINE_VERSION 0x0501
+#endif
+
+extern void _rl_free_history_entry PARAMS((HIST_ENTRY *));
+
+#if defined (COLOR_SUPPORT)
+extern void _rl_parse_colors PARAMS((void)); /* XXX */
+#endif
+
+
+/* Forward declarations used in this file. */
+static char *readline_internal PARAMS((void));
+static void readline_initialize_everything PARAMS((void));
+
+static void bind_arrow_keys_internal PARAMS((Keymap));
+static void bind_arrow_keys PARAMS((void));
+
+static void readline_default_bindings PARAMS((void));
+static void reset_default_bindings PARAMS((void));
+
+static int _rl_subseq_result PARAMS((int, Keymap, int, int));
+static int _rl_subseq_getchar PARAMS((int));
+
+/* **************************************************************** */
+/* */
+/* Line editing input utility */
+/* */
+/* **************************************************************** */
+
+const char *rl_library_version = RL_LIBRARY_VERSION;
+
+int rl_readline_version = RL_READLINE_VERSION;
+
+/* True if this is `real' readline as opposed to some stub substitute. */
+int rl_gnu_readline_p = 1;
+
+/* A pointer to the keymap that is currently in use.
+ By default, it is the standard emacs keymap. */
+Keymap _rl_keymap = emacs_standard_keymap;
+
+/* The current style of editing. */
+int rl_editing_mode = emacs_mode;
+
+/* The current insert mode: input (the default) or overwrite */
+int rl_insert_mode = RL_IM_DEFAULT;
+
+/* Non-zero if we called this function from _rl_dispatch(). It's present
+ so functions can find out whether they were called from a key binding
+ or directly from an application. */
+int rl_dispatching;
+
+/* Non-zero if the previous command was a kill command. */
+int _rl_last_command_was_kill = 0;
+
+/* The current value of the numeric argument specified by the user. */
+int rl_numeric_arg = 1;
+
+/* Non-zero if an argument was typed. */
+int rl_explicit_arg = 0;
+
+/* Temporary value used while generating the argument. */
+int rl_arg_sign = 1;
+
+/* Non-zero means we have been called at least once before. */
+static int rl_initialized;
+
+#if 0
+/* If non-zero, this program is running in an EMACS buffer. */
+static int running_in_emacs;
+#endif
+
+/* Flags word encapsulating the current readline state. */
+int rl_readline_state = RL_STATE_NONE;
+
+/* The current offset in the current input line. */
+int rl_point;
+
+/* Mark in the current input line. */
+int rl_mark;
+
+/* Length of the current input line. */
+int rl_end;
+
+/* Make this non-zero to return the current input_line. */
+int rl_done;
+
+/* The last function executed by readline. */
+rl_command_func_t *rl_last_func = (rl_command_func_t *)NULL;
+
+/* Top level environment for readline_internal (). */
+procenv_t _rl_top_level;
+
+/* The streams we interact with. */
+FILE *_rl_in_stream, *_rl_out_stream;
+
+/* The names of the streams that we do input and output to. */
+FILE *rl_instream = (FILE *)NULL;
+FILE *rl_outstream = (FILE *)NULL;
+
+/* Non-zero means echo characters as they are read. Defaults to no echo;
+ set to 1 if there is a controlling terminal, we can get its attributes,
+ and the attributes include `echo'. Look at rltty.c:prepare_terminal_settings
+ for the code that sets it. */
+int _rl_echoing_p = 0;
+
+/* Current prompt. */
+char *rl_prompt = (char *)NULL;
+int rl_visible_prompt_length = 0;
+
+/* Set to non-zero by calling application if it has already printed rl_prompt
+ and does not want readline to do it the first time. */
+int rl_already_prompted = 0;
+
+/* The number of characters read in order to type this complete command. */
+int rl_key_sequence_length = 0;
+
+/* If non-zero, then this is the address of a function to call just
+ before readline_internal_setup () prints the first prompt. */
+rl_hook_func_t *rl_startup_hook = (rl_hook_func_t *)NULL;
+
+/* If non-zero, this is the address of a function to call just before
+ readline_internal_setup () returns and readline_internal starts
+ reading input characters. */
+rl_hook_func_t *rl_pre_input_hook = (rl_hook_func_t *)NULL;
+
+/* What we use internally. You should always refer to RL_LINE_BUFFER. */
+static char *the_line;
+
+/* The character that can generate an EOF. Really read from
+ the terminal driver... just defaulted here. */
+int _rl_eof_char = CTRL ('D');
+
+/* Non-zero makes this the next keystroke to read. */
+int rl_pending_input = 0;
+
+/* Pointer to a useful terminal name. */
+const char *rl_terminal_name = (const char *)NULL;
+
+/* Non-zero means to always use horizontal scrolling in line display. */
+int _rl_horizontal_scroll_mode = 0;
+
+/* Non-zero means to display an asterisk at the starts of history lines
+ which have been modified. */
+int _rl_mark_modified_lines = 0;
+
+/* The style of `bell' notification preferred. This can be set to NO_BELL,
+ AUDIBLE_BELL, or VISIBLE_BELL. */
+int _rl_bell_preference = AUDIBLE_BELL;
+
+/* String inserted into the line by rl_insert_comment (). */
+char *_rl_comment_begin;
+
+/* Keymap holding the function currently being executed. */
+Keymap rl_executing_keymap;
+
+/* Keymap we're currently using to dispatch. */
+Keymap _rl_dispatching_keymap;
+
+/* Non-zero means to erase entire line, including prompt, on empty input lines. */
+int rl_erase_empty_line = 0;
+
+/* Non-zero means to read only this many characters rather than up to a
+ character bound to accept-line. */
+int rl_num_chars_to_read;
+
+/* Line buffer and maintenance. */
+char *rl_line_buffer = (char *)NULL;
+int rl_line_buffer_len = 0;
+
+/* Key sequence `contexts' */
+_rl_keyseq_cxt *_rl_kscxt = 0;
+
+int rl_executing_key;
+char *rl_executing_keyseq = 0;
+int _rl_executing_keyseq_size = 0;
+
+/* Timeout (specified in milliseconds) when reading characters making up an
+ ambiguous multiple-key sequence */
+int _rl_keyseq_timeout = 500;
+
+#define RESIZE_KEYSEQ_BUFFER() \
+ do \
+ { \
+ if (rl_key_sequence_length + 2 >= _rl_executing_keyseq_size) \
+ { \
+ _rl_executing_keyseq_size += 16; \
+ rl_executing_keyseq = xrealloc (rl_executing_keyseq, _rl_executing_keyseq_size); \
+ } \
+ } \
+ while (0);
+
+/* Forward declarations used by the display, termcap, and history code. */
+
+/* **************************************************************** */
+/* */
+/* `Forward' declarations */
+/* */
+/* **************************************************************** */
+
+/* Non-zero means do not parse any lines other than comments and
+ parser directives. */
+unsigned char _rl_parsing_conditionalized_out = 0;
+
+/* Non-zero means to convert characters with the meta bit set to
+ escape-prefixed characters so we can indirect through
+ emacs_meta_keymap or vi_escape_keymap. */
+int _rl_convert_meta_chars_to_ascii = 1;
+
+/* Non-zero means to output characters with the meta bit set directly
+ rather than as a meta-prefixed escape sequence. */
+int _rl_output_meta_chars = 0;
+
+/* Non-zero means to look at the termios special characters and bind
+ them to equivalent readline functions at startup. */
+int _rl_bind_stty_chars = 1;
+
+/* Non-zero means to go through the history list at every newline (or
+ whenever rl_done is set and readline returns) and revert each line to
+ its initial state. */
+int _rl_revert_all_at_newline = 0;
+
+/* Non-zero means to honor the termios ECHOCTL bit and echo control
+ characters corresponding to keyboard-generated signals. */
+int _rl_echo_control_chars = 1;
+
+/* Non-zero means to prefix the displayed prompt with a character indicating
+ the editing mode: @ for emacs, : for vi-command, + for vi-insert. */
+int _rl_show_mode_in_prompt = 0;
+
+/* **************************************************************** */
+/* */
+/* Top Level Functions */
+/* */
+/* **************************************************************** */
+
+/* Non-zero means treat 0200 bit in terminal input as Meta bit. */
+int _rl_meta_flag = 0; /* Forward declaration */
+
+/* Set up the prompt and expand it. Called from readline() and
+ rl_callback_handler_install (). */
+int
+rl_set_prompt (prompt)
+ const char *prompt;
+{
+ FREE (rl_prompt);
+ rl_prompt = prompt ? savestring (prompt) : (char *)NULL;
+ rl_display_prompt = rl_prompt ? rl_prompt : "";
+
+ rl_visible_prompt_length = rl_expand_prompt (rl_prompt);
+ return 0;
+}
+
+/* Read a line of input. Prompt with PROMPT. An empty PROMPT means
+ none. A return value of NULL means that EOF was encountered. */
+char *
+readline (prompt)
+ const char *prompt;
+{
+ char *value;
+#if 0
+ int in_callback;
+#endif
+
+ /* If we are at EOF return a NULL string. */
+ if (rl_pending_input == EOF)
+ {
+ rl_clear_pending_input ();
+ return ((char *)NULL);
+ }
+
+#if 0
+ /* If readline() is called after installing a callback handler, temporarily
+ turn off the callback state to avoid ensuing messiness. Patch supplied
+ by the gdb folks. XXX -- disabled. This can be fooled and readline
+ left in a strange state by a poorly-timed longjmp. */
+ if (in_callback = RL_ISSTATE (RL_STATE_CALLBACK))
+ RL_UNSETSTATE (RL_STATE_CALLBACK);
+#endif
+
+ rl_set_prompt (prompt);
+
+ rl_initialize ();
+ if (rl_prep_term_function)
+ (*rl_prep_term_function) (_rl_meta_flag);
+
+#if defined (HANDLE_SIGNALS)
+ rl_set_signals ();
+#endif
+
+ value = readline_internal ();
+ if (rl_deprep_term_function)
+ (*rl_deprep_term_function) ();
+
+#if defined (HANDLE_SIGNALS)
+ rl_clear_signals ();
+#endif
+
+#if 0
+ if (in_callback)
+ RL_SETSTATE (RL_STATE_CALLBACK);
+#endif
+
+#if HAVE_DECL_AUDIT_TTY && defined (ENABLE_TTY_AUDIT_SUPPORT)
+ if (value)
+ _rl_audit_tty (value);
+#endif
+
+ return (value);
+}
+
+#if defined (READLINE_CALLBACKS)
+# define STATIC_CALLBACK
+#else
+# define STATIC_CALLBACK static
+#endif
+
+STATIC_CALLBACK void
+readline_internal_setup ()
+{
+ char *nprompt;
+
+ _rl_in_stream = rl_instream;
+ _rl_out_stream = rl_outstream;
+
+ /* Enable the meta key only for the duration of readline(), if this
+ terminal has one and the terminal has been initialized */
+ if (_rl_enable_meta & RL_ISSTATE (RL_STATE_TERMPREPPED))
+ _rl_enable_meta_key ();
+
+ if (rl_startup_hook)
+ (*rl_startup_hook) ();
+
+#if defined (VI_MODE)
+ if (rl_editing_mode == vi_mode)
+ rl_vi_insertion_mode (1, 'i'); /* don't want to reset last */
+#endif /* VI_MODE */
+
+ /* If we're not echoing, we still want to at least print a prompt, because
+ rl_redisplay will not do it for us. If the calling application has a
+ custom redisplay function, though, let that function handle it. */
+ if (_rl_echoing_p == 0 && rl_redisplay_function == rl_redisplay)
+ {
+ if (rl_prompt && rl_already_prompted == 0)
+ {
+ nprompt = _rl_strip_prompt (rl_prompt);
+ fprintf (_rl_out_stream, "%s", nprompt);
+ fflush (_rl_out_stream);
+ xfree (nprompt);
+ }
+ }
+ else
+ {
+ if (rl_prompt && rl_already_prompted)
+ rl_on_new_line_with_prompt ();
+ else
+ rl_on_new_line ();
+ (*rl_redisplay_function) ();
+ }
+
+ if (rl_pre_input_hook)
+ (*rl_pre_input_hook) ();
+
+ RL_CHECK_SIGNALS ();
+}
+
+STATIC_CALLBACK char *
+readline_internal_teardown (eof)
+ int 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 ();
+
+ if (entry && rl_undo_list)
+ {
+ temp = savestring (the_line);
+ rl_revert_line (1, 0);
+ entry = replace_history_entry (where_history (), the_line, (histdata_t)NULL);
+ _rl_free_history_entry (entry);
+
+ strcpy (the_line, temp);
+ xfree (temp);
+ }
+
+ if (_rl_revert_all_at_newline)
+ _rl_revert_all_lines ();
+
+ /* At any rate, it is highly likely that this line has an undo list. Get
+ rid of it now. */
+ if (rl_undo_list)
+ rl_free_undo_list ();
+
+ /* Disable the meta key, if this terminal has one and we were told to use it.
+ The check whether or not we sent the enable string is in
+ _rl_disable_meta_key(); the flag is set in _rl_enable_meta_key */
+ _rl_disable_meta_key ();
+
+ /* Restore normal cursor, if available. */
+ _rl_set_insert_mode (RL_IM_INSERT, 0);
+
+ return (eof ? (char *)NULL : savestring (the_line));
+}
+
+void
+_rl_internal_char_cleanup ()
+{
+#if defined (VI_MODE)
+ /* In vi mode, when you exit insert mode, the cursor moves back
+ over the previous character. We explicitly check for that here. */
+ if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap)
+ rl_vi_check ();
+#endif /* VI_MODE */
+
+ if (rl_num_chars_to_read && rl_end >= rl_num_chars_to_read)
+ {
+ (*rl_redisplay_function) ();
+ _rl_want_redisplay = 0;
+ rl_newline (1, '\n');
+ }
+
+ if (rl_done == 0)
+ {
+ (*rl_redisplay_function) ();
+ _rl_want_redisplay = 0;
+ }
+
+ /* If the application writer has told us to erase the entire line if
+ the only character typed was something bound to rl_newline, do so. */
+ if (rl_erase_empty_line && rl_done && rl_last_func == rl_newline &&
+ rl_point == 0 && rl_end == 0)
+ _rl_erase_entire_line ();
+}
+
+STATIC_CALLBACK int
+#if defined (READLINE_CALLBACKS)
+readline_internal_char ()
+#else
+readline_internal_charloop ()
+#endif
+{
+ static int lastc, eof_found;
+ int c, code, lk;
+
+ lastc = -1;
+ eof_found = 0;
+
+#if !defined (READLINE_CALLBACKS)
+ while (rl_done == 0)
+ {
+#endif
+ lk = _rl_last_command_was_kill;
+
+#if defined (HAVE_POSIX_SIGSETJMP)
+ code = sigsetjmp (_rl_top_level, 0);
+#else
+ code = setjmp (_rl_top_level);
+#endif
+
+ if (code)
+ {
+ (*rl_redisplay_function) ();
+ _rl_want_redisplay = 0;
+ /* If we get here, we're not being called from something dispatched
+ from _rl_callback_read_char(), which sets up its own value of
+ _rl_top_level (saving and restoring the old, of course), so
+ we can just return here. */
+ if (RL_ISSTATE (RL_STATE_CALLBACK))
+ return (0);
+ }
+
+ if (rl_pending_input == 0)
+ {
+ /* Then initialize the argument and number of keys read. */
+ _rl_reset_argument ();
+ rl_key_sequence_length = 0;
+ rl_executing_keyseq[0] = 0;
+ }
+
+ RL_SETSTATE(RL_STATE_READCMD);
+ c = rl_read_key ();
+ RL_UNSETSTATE(RL_STATE_READCMD);
+
+ /* look at input.c:rl_getc() for the circumstances under which this will
+ be returned; punt immediately on read error without converting it to
+ a newline; assume that rl_read_key has already called the signal
+ handler. */
+ if (c == READERR)
+ {
+#if defined (READLINE_CALLBACKS)
+ RL_SETSTATE(RL_STATE_DONE);
+ return (rl_done = 1);
+#else
+ eof_found = 1;
+ break;
+#endif
+ }
+
+ /* EOF typed to a non-blank line is a . If we want to change this,
+ to force any existing line to be ignored when read(2) reads EOF,
+ for example, this is the place to change. */
+ if (c == EOF && rl_end)
+ c = NEWLINE;
+
+ /* The character _rl_eof_char typed to blank line, and not as the
+ previous character is interpreted as EOF. */
+ if (((c == _rl_eof_char && lastc != c) || c == EOF) && !rl_end)
+ {
+#if defined (READLINE_CALLBACKS)
+ RL_SETSTATE(RL_STATE_DONE);
+ return (rl_done = 1);
+#else
+ eof_found = 1;
+ break;
+#endif
+ }
+
+ 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
+ a prefix command, so nothing has changed yet. */
+ if (rl_pending_input == 0 && lk == _rl_last_command_was_kill)
+ _rl_last_command_was_kill = 0;
+
+ _rl_internal_char_cleanup ();
+
+#if defined (READLINE_CALLBACKS)
+ return 0;
+#else
+ }
+
+ return (eof_found);
+#endif
+}
+
+#if defined (READLINE_CALLBACKS)
+static int
+readline_internal_charloop ()
+{
+ int eof = 1;
+
+ while (rl_done == 0)
+ eof = readline_internal_char ();
+ return (eof);
+}
+#endif /* READLINE_CALLBACKS */
+
+/* Read a line of input from the global rl_instream, doing output on
+ the global rl_outstream.
+ If rl_prompt is non-null, then that is our prompt. */
+static char *
+readline_internal ()
+{
+ int eof;
+
+ readline_internal_setup ();
+ eof = readline_internal_charloop ();
+ return (readline_internal_teardown (eof));
+}
+
+void
+_rl_init_line_state ()
+{
+ rl_point = rl_end = rl_mark = 0;
+ the_line = rl_line_buffer;
+ the_line[0] = 0;
+}
+
+void
+_rl_set_the_line ()
+{
+ the_line = rl_line_buffer;
+}
+
+#if defined (READLINE_CALLBACKS)
+_rl_keyseq_cxt *
+_rl_keyseq_cxt_alloc ()
+{
+ _rl_keyseq_cxt *cxt;
+
+ cxt = (_rl_keyseq_cxt *)xmalloc (sizeof (_rl_keyseq_cxt));
+
+ cxt->flags = cxt->subseq_arg = cxt->subseq_retval = 0;
+
+ cxt->okey = 0;
+ cxt->ocxt = _rl_kscxt;
+ cxt->childval = 42; /* sentinel value */
+
+ return cxt;
+}
+
+void
+_rl_keyseq_cxt_dispose (cxt)
+ _rl_keyseq_cxt *cxt;
+{
+ xfree (cxt);
+}
+
+void
+_rl_keyseq_chain_dispose ()
+{
+ _rl_keyseq_cxt *cxt;
+
+ while (_rl_kscxt)
+ {
+ cxt = _rl_kscxt;
+ _rl_kscxt = _rl_kscxt->ocxt;
+ _rl_keyseq_cxt_dispose (cxt);
+ }
+}
+#endif
+
+static int
+_rl_subseq_getchar (key)
+ int key;
+{
+ int k;
+
+ if (key == ESC)
+ RL_SETSTATE(RL_STATE_METANEXT);
+ RL_SETSTATE(RL_STATE_MOREINPUT);
+ k = rl_read_key ();
+ RL_UNSETSTATE(RL_STATE_MOREINPUT);
+ if (key == ESC)
+ RL_UNSETSTATE(RL_STATE_METANEXT);
+
+ return k;
+}
+
+#if defined (READLINE_CALLBACKS)
+int
+_rl_dispatch_callback (cxt)
+ _rl_keyseq_cxt *cxt;
+{
+ int nkey, r;
+
+ /* For now */
+ /* 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
+ a chain of contexts. */
+ if ((cxt->flags & KSEQ_DISPATCHED) == 0)
+ {
+ nkey = _rl_subseq_getchar (cxt->okey);
+ if (nkey < 0)
+ {
+ _rl_abort_internal ();
+ return -1;
+ }
+ r = _rl_dispatch_subseq (nkey, cxt->dmap, cxt->subseq_arg);
+ cxt->flags |= KSEQ_DISPATCHED;
+ }
+ else
+ r = cxt->childval;
+
+ /* For now */
+ if (r != -3) /* don't do this if we indicate there will be other matches */
+ r = _rl_subseq_result (r, cxt->oldmap, cxt->okey, (cxt->flags & KSEQ_SUBSEQ));
+
+ RL_CHECK_SIGNALS ();
+ /* We only treat values < 0 specially to simulate recursion. */
+ if (r >= 0 || (r == -1 && (cxt->flags & KSEQ_SUBSEQ) == 0)) /* success! or failure! */
+ {
+ _rl_keyseq_chain_dispose ();
+ RL_UNSETSTATE (RL_STATE_MULTIKEY);
+ return r;
+ }
+
+ if (r != -3) /* magic value that says we added to the chain */
+ _rl_kscxt = cxt->ocxt;
+ if (_rl_kscxt)
+ _rl_kscxt->childval = r;
+ if (r != -3)
+ _rl_keyseq_cxt_dispose (cxt);
+
+ return r;
+}
+#endif /* READLINE_CALLBACKS */
+
+/* Do the command associated with KEY in MAP.
+ If the associated command is really a keymap, then read
+ another key, and dispatch into that map. */
+int
+_rl_dispatch (key, map)
+ register int key;
+ Keymap map;
+{
+ _rl_dispatching_keymap = map;
+ return _rl_dispatch_subseq (key, map, 0);
+}
+
+int
+_rl_dispatch_subseq (key, map, got_subseq)
+ register int key;
+ Keymap map;
+ int got_subseq;
+{
+ int r, newkey;
+ char *macro;
+ rl_command_func_t *func;
+#if defined (READLINE_CALLBACKS)
+ _rl_keyseq_cxt *cxt;
+#endif
+
+ if (META_CHAR (key) && _rl_convert_meta_chars_to_ascii)
+ {
+ if (map[ESC].type == ISKMAP)
+ {
+ if (RL_ISSTATE (RL_STATE_MACRODEF))
+ _rl_add_macro_char (ESC);
+ RESIZE_KEYSEQ_BUFFER ();
+ rl_executing_keyseq[rl_key_sequence_length++] = ESC;
+ map = FUNCTION_TO_KEYMAP (map, ESC);
+ key = UNMETA (key);
+ return (_rl_dispatch (key, map));
+ }
+ else
+ rl_ding ();
+ return 0;
+ }
+
+ if (RL_ISSTATE (RL_STATE_MACRODEF))
+ _rl_add_macro_char (key);
+
+ r = 0;
+ switch (map[key].type)
+ {
+ case ISFUNC:
+ func = map[key].function;
+ if (func)
+ {
+ /* Special case rl_do_lowercase_version (). */
+ if (func == rl_do_lowercase_version)
+ /* Should we do anything special if key == ANYOTHERKEY? */
+ return (_rl_dispatch (_rl_to_lower (key), map));
+
+ rl_executing_keymap = map;
+ rl_executing_key = key;
+
+ RESIZE_KEYSEQ_BUFFER();
+ rl_executing_keyseq[rl_key_sequence_length++] = key;
+ rl_executing_keyseq[rl_key_sequence_length] = '\0';
+
+ rl_dispatching = 1;
+ RL_SETSTATE(RL_STATE_DISPATCHING);
+ r = (*func) (rl_numeric_arg * rl_arg_sign, key);
+ RL_UNSETSTATE(RL_STATE_DISPATCHING);
+ rl_dispatching = 0;
+
+ /* If we have input pending, then the last command was a prefix
+ command. Don't change the state of rl_last_func. Otherwise,
+ 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)
+ {
+ /* OK, there's no function bound in this map, but there is a
+ shadow function that was overridden when the current keymap
+ was created. Return -2 to note that. */
+ if (RL_ISSTATE (RL_STATE_MACROINPUT))
+ _rl_prev_macro_key ();
+ else
+ _rl_unget_char (key);
+ return -2;
+ }
+ else if (got_subseq)
+ {
+ /* Return -1 to note that we're in a subsequence, but we don't
+ have a matching key, nor was one overridden. This means
+ we need to back up the recursion chain and find the last
+ subsequence that is bound to a function. */
+ if (RL_ISSTATE (RL_STATE_MACROINPUT))
+ _rl_prev_macro_key ();
+ else
+ _rl_unget_char (key);
+ return -1;
+ }
+ else
+ {
+#if defined (READLINE_CALLBACKS)
+ RL_UNSETSTATE (RL_STATE_MULTIKEY);
+ _rl_keyseq_chain_dispose ();
+#endif
+ _rl_abort_internal ();
+ return -1;
+ }
+ break;
+
+ case ISKMAP:
+ if (map[key].function != 0)
+ {
+#if defined (VI_MODE)
+ /* The only way this test will be true is if a subsequence has been
+ bound starting with ESC, generally the arrow keys. What we do is
+ check whether there's input in the queue, which there generally
+ will be if an arrow key has been pressed, and, if there's not,
+ just dispatch to (what we assume is) rl_vi_movement_mode right
+ away. This is essentially an input test with a zero timeout (by
+ default) or a timeout determined by the value of `keyseq-timeout' */
+ /* _rl_keyseq_timeout specified in milliseconds; _rl_input_queued
+ takes microseconds, so multiply by 1000 */
+ if (rl_editing_mode == vi_mode && key == ESC && map == vi_insertion_keymap
+ && _rl_input_queued ((_rl_keyseq_timeout > 0) ? _rl_keyseq_timeout*1000 : 0) == 0)
+ return (_rl_dispatch (ANYOTHERKEY, FUNCTION_TO_KEYMAP (map, key)));
+#endif
+
+ RESIZE_KEYSEQ_BUFFER ();
+ rl_executing_keyseq[rl_key_sequence_length++] = key;
+ _rl_dispatching_keymap = FUNCTION_TO_KEYMAP (map, key);
+
+ /* Allocate new context here. Use linked contexts (linked through
+ cxt->ocxt) to simulate recursion */
+#if defined (READLINE_CALLBACKS)
+ if (RL_ISSTATE (RL_STATE_CALLBACK))
+ {
+ /* Return 0 only the first time, to indicate success to
+ _rl_callback_read_char. The rest of the time, we're called
+ from _rl_dispatch_callback, so we return -3 to indicate
+ special handling is necessary. */
+ r = RL_ISSTATE (RL_STATE_MULTIKEY) ? -3 : 0;
+ cxt = _rl_keyseq_cxt_alloc ();
+
+ if (got_subseq)
+ cxt->flags |= KSEQ_SUBSEQ;
+ cxt->okey = key;
+ cxt->oldmap = map;
+ cxt->dmap = _rl_dispatching_keymap;
+ cxt->subseq_arg = got_subseq || cxt->dmap[ANYOTHERKEY].function;
+
+ RL_SETSTATE (RL_STATE_MULTIKEY);
+ _rl_kscxt = cxt;
+
+ return r; /* don't indicate immediate success */
+ }
+#endif
+
+ /* Tentative inter-character timeout for potential multi-key
+ sequences? If no input within timeout, abort sequence and
+ act as if we got non-matching input. */
+ /* _rl_keyseq_timeout specified in milliseconds; _rl_input_queued
+ takes microseconds, so multiply by 1000 */
+ if (_rl_keyseq_timeout > 0 &&
+ (RL_ISSTATE (RL_STATE_INPUTPENDING|RL_STATE_MACROINPUT) == 0) &&
+ _rl_pushed_input_available () == 0 &&
+ _rl_dispatching_keymap[ANYOTHERKEY].function &&
+ _rl_input_queued (_rl_keyseq_timeout*1000) == 0)
+ return (_rl_subseq_result (-2, map, key, got_subseq));
+
+ newkey = _rl_subseq_getchar (key);
+ if (newkey < 0)
+ {
+ _rl_abort_internal ();
+ return -1;
+ }
+
+ r = _rl_dispatch_subseq (newkey, _rl_dispatching_keymap, got_subseq || map[ANYOTHERKEY].function);
+ return _rl_subseq_result (r, map, key, got_subseq);
+ }
+ else
+ {
+ _rl_abort_internal ();
+ return -1;
+ }
+ break;
+
+ case ISMACR:
+ if (map[key].function != 0)
+ {
+ rl_executing_keyseq[rl_key_sequence_length] = '\0';
+ macro = savestring ((char *)map[key].function);
+ _rl_with_macro_input (macro);
+ return 0;
+ }
+ break;
+ }
+#if defined (VI_MODE)
+ if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap &&
+ key != ANYOTHERKEY &&
+ rl_key_sequence_length == 1 && /* XXX */
+ _rl_vi_textmod_command (key))
+ _rl_vi_set_last (key, rl_numeric_arg, rl_arg_sign);
+#endif
+
+ return (r);
+}
+
+static int
+_rl_subseq_result (r, map, key, got_subseq)
+ int r;
+ Keymap map;
+ int key, got_subseq;
+{
+ Keymap m;
+ int type, nt;
+ rl_command_func_t *func, *nf;
+
+ if (r == -2)
+ /* We didn't match anything, and the keymap we're indexed into
+ shadowed a function previously bound to that prefix. Call
+ the function. The recursive call to _rl_dispatch_subseq has
+ already taken care of pushing any necessary input back onto
+ the input queue with _rl_unget_char. */
+ {
+ m = _rl_dispatching_keymap;
+ type = m[ANYOTHERKEY].type;
+ func = m[ANYOTHERKEY].function;
+ if (type == ISFUNC && func == rl_do_lowercase_version)
+ r = _rl_dispatch (_rl_to_lower (key), map);
+ else if (type == ISFUNC && func == rl_insert)
+ {
+ /* If the function that was shadowed was self-insert, we
+ somehow need a keymap with map[key].func == self-insert.
+ Let's use this one. */
+ nt = m[key].type;
+ nf = m[key].function;
+
+ m[key].type = type;
+ m[key].function = func;
+ r = _rl_dispatch (key, m);
+ m[key].type = nt;
+ m[key].function = nf;
+ }
+ else
+ r = _rl_dispatch (ANYOTHERKEY, m);
+ }
+ else if (r && map[ANYOTHERKEY].function)
+ {
+ /* We didn't match (r is probably -1), so return something to
+ tell the caller that it should try ANYOTHERKEY for an
+ overridden function. */
+ if (RL_ISSTATE (RL_STATE_MACROINPUT))
+ _rl_prev_macro_key ();
+ else
+ _rl_unget_char (key);
+ _rl_dispatching_keymap = map;
+ return -2;
+ }
+ else if (r && got_subseq)
+ {
+ /* OK, back up the chain. */
+ if (RL_ISSTATE (RL_STATE_MACROINPUT))
+ _rl_prev_macro_key ();
+ else
+ _rl_unget_char (key);
+ _rl_dispatching_keymap = map;
+ return -1;
+ }
+
+ return r;
+}
+
+/* **************************************************************** */
+/* */
+/* Initializations */
+/* */
+/* **************************************************************** */
+
+/* Initialize readline (and terminal if not already). */
+int
+rl_initialize ()
+{
+ /* If we have never been called before, initialize the
+ terminal and data structures. */
+ if (!rl_initialized)
+ {
+ RL_SETSTATE(RL_STATE_INITIALIZING);
+ readline_initialize_everything ();
+ RL_UNSETSTATE(RL_STATE_INITIALIZING);
+ rl_initialized++;
+ RL_SETSTATE(RL_STATE_INITIALIZED);
+ }
+
+ /* Initialize the current line information. */
+ _rl_init_line_state ();
+
+ /* We aren't done yet. We haven't even gotten started yet! */
+ rl_done = 0;
+ RL_UNSETSTATE(RL_STATE_DONE);
+
+ /* Tell the history routines what is going on. */
+ _rl_start_using_history ();
+
+ /* Make the display buffer match the state of the line. */
+ rl_reset_line_state ();
+
+ /* No such function typed yet. */
+ rl_last_func = (rl_command_func_t *)NULL;
+
+ /* Parsing of key-bindings begins in an enabled state. */
+ _rl_parsing_conditionalized_out = 0;
+
+#if defined (VI_MODE)
+ if (rl_editing_mode == vi_mode)
+ _rl_vi_initialize_line ();
+#endif
+
+ /* Each line starts in insert mode (the default). */
+ _rl_set_insert_mode (RL_IM_DEFAULT, 1);
+
+ return 0;
+}
+
+#if 0
+#if defined (__EMX__)
+static void
+_emx_build_environ ()
+{
+ TIB *tibp;
+ PIB *pibp;
+ char *t, **tp;
+ int c;
+
+ DosGetInfoBlocks (&tibp, &pibp);
+ t = pibp->pib_pchenv;
+ for (c = 1; *t; c++)
+ t += strlen (t) + 1;
+ tp = environ = (char **)xmalloc ((c + 1) * sizeof (char *));
+ t = pibp->pib_pchenv;
+ while (*t)
+ {
+ *tp++ = t;
+ t += strlen (t) + 1;
+ }
+ *tp = 0;
+}
+#endif /* __EMX__ */
+#endif
+
+/* Initialize the entire state of the world. */
+static void
+readline_initialize_everything ()
+{
+#if 0
+#if defined (__EMX__)
+ if (environ == 0)
+ _emx_build_environ ();
+#endif
+#endif
+
+#if 0
+ /* Find out if we are running in Emacs -- UNUSED. */
+ running_in_emacs = sh_get_env_value ("EMACS") != (char *)0;
+#endif
+
+ /* Set up input and output if they are not already set up. */
+ if (!rl_instream)
+ rl_instream = stdin;
+
+ if (!rl_outstream)
+ rl_outstream = stdout;
+
+ /* Bind _rl_in_stream and _rl_out_stream immediately. These values
+ may change, but they may also be used before readline_internal ()
+ is called. */
+ _rl_in_stream = rl_instream;
+ _rl_out_stream = rl_outstream;
+
+ /* Allocate data structures. */
+ if (rl_line_buffer == 0)
+ rl_line_buffer = (char *)xmalloc (rl_line_buffer_len = DEFAULT_BUFFER_SIZE);
+
+ /* Initialize the terminal interface. */
+ if (rl_terminal_name == 0)
+ rl_terminal_name = sh_get_env_value ("TERM");
+ _rl_init_terminal_io (rl_terminal_name);
+
+ /* Bind tty characters to readline functions. */
+ readline_default_bindings ();
+
+ /* Initialize the function names. */
+ rl_initialize_funmap ();
+
+ /* Decide whether we should automatically go into eight-bit mode. */
+ _rl_init_eightbit ();
+
+ /* Read in the init file. */
+ rl_read_init_file ((char *)NULL);
+
+ /* XXX */
+ if (_rl_horizontal_scroll_mode && _rl_term_autowrap)
+ {
+ _rl_screenwidth--;
+ _rl_screenchars -= _rl_screenheight;
+ }
+
+ /* Override the effect of any `set keymap' assignments in the
+ inputrc file. */
+ rl_set_keymap_from_edit_mode ();
+
+ /* Try to bind a common arrow key prefix, if not already bound. */
+ bind_arrow_keys ();
+
+ /* If the completion parser's default word break characters haven't
+ been set yet, then do so now. */
+ if (rl_completer_word_break_characters == (char *)NULL)
+ rl_completer_word_break_characters = (char *)rl_basic_word_break_characters;
+
+#if defined (COLOR_SUPPORT)
+ if (_rl_colored_stats)
+ _rl_parse_colors ();
+#endif
+
+ rl_executing_keyseq = malloc (_rl_executing_keyseq_size = 16);
+ if (rl_executing_keyseq)
+ rl_executing_keyseq[0] = '\0';
+}
+
+/* If this system allows us to look at the values of the regular
+ input editing characters, then bind them to their readline
+ equivalents, iff the characters are not bound to keymaps. */
+static void
+readline_default_bindings ()
+{
+ if (_rl_bind_stty_chars)
+ rl_tty_set_default_bindings (_rl_keymap);
+}
+
+/* Reset the default bindings for the terminal special characters we're
+ interested in back to rl_insert and read the new ones. */
+static void
+reset_default_bindings ()
+{
+ if (_rl_bind_stty_chars)
+ {
+ rl_tty_unset_default_bindings (_rl_keymap);
+ rl_tty_set_default_bindings (_rl_keymap);
+ }
+}
+
+/* Bind some common arrow key sequences in MAP. */
+static void
+bind_arrow_keys_internal (map)
+ Keymap map;
+{
+ Keymap xkeymap;
+
+ xkeymap = _rl_keymap;
+ _rl_keymap = map;
+
+#if defined (__MSDOS__)
+ rl_bind_keyseq_if_unbound ("\033[0A", rl_get_previous_history);
+ rl_bind_keyseq_if_unbound ("\033[0B", rl_backward_char);
+ rl_bind_keyseq_if_unbound ("\033[0C", rl_forward_char);
+ rl_bind_keyseq_if_unbound ("\033[0D", rl_get_next_history);
+#endif
+
+ rl_bind_keyseq_if_unbound ("\033[A", rl_get_previous_history);
+ rl_bind_keyseq_if_unbound ("\033[B", rl_get_next_history);
+ rl_bind_keyseq_if_unbound ("\033[C", rl_forward_char);
+ rl_bind_keyseq_if_unbound ("\033[D", rl_backward_char);
+ rl_bind_keyseq_if_unbound ("\033[H", rl_beg_of_line);
+ rl_bind_keyseq_if_unbound ("\033[F", rl_end_of_line);
+
+ rl_bind_keyseq_if_unbound ("\033OA", rl_get_previous_history);
+ rl_bind_keyseq_if_unbound ("\033OB", rl_get_next_history);
+ rl_bind_keyseq_if_unbound ("\033OC", rl_forward_char);
+ rl_bind_keyseq_if_unbound ("\033OD", rl_backward_char);
+ rl_bind_keyseq_if_unbound ("\033OH", rl_beg_of_line);
+ rl_bind_keyseq_if_unbound ("\033OF", rl_end_of_line);
+
+#if defined (__MINGW32__)
+ rl_bind_keyseq_if_unbound ("\340H", rl_get_previous_history);
+ rl_bind_keyseq_if_unbound ("\340P", rl_get_next_history);
+ rl_bind_keyseq_if_unbound ("\340M", rl_forward_char);
+ rl_bind_keyseq_if_unbound ("\340K", rl_backward_char);
+ rl_bind_keyseq_if_unbound ("\340G", rl_beg_of_line);
+ rl_bind_keyseq_if_unbound ("\340O", rl_end_of_line);
+ rl_bind_keyseq_if_unbound ("\340S", rl_delete);
+ rl_bind_keyseq_if_unbound ("\340R", rl_overwrite_mode);
+
+ /* These may or may not work because of the embedded NUL. */
+ rl_bind_keyseq_if_unbound ("\\000H", rl_get_previous_history);
+ rl_bind_keyseq_if_unbound ("\\000P", rl_get_next_history);
+ rl_bind_keyseq_if_unbound ("\\000M", rl_forward_char);
+ rl_bind_keyseq_if_unbound ("\\000K", rl_backward_char);
+ rl_bind_keyseq_if_unbound ("\\000G", rl_beg_of_line);
+ rl_bind_keyseq_if_unbound ("\\000O", rl_end_of_line);
+ rl_bind_keyseq_if_unbound ("\\000S", rl_delete);
+ rl_bind_keyseq_if_unbound ("\\000R", rl_overwrite_mode);
+#endif
+
+ _rl_keymap = xkeymap;
+}
+
+/* Try and bind the common arrow key prefixes after giving termcap and
+ the inputrc file a chance to bind them and create `real' keymaps
+ for the arrow key prefix. */
+static void
+bind_arrow_keys ()
+{
+ bind_arrow_keys_internal (emacs_standard_keymap);
+
+#if defined (VI_MODE)
+ bind_arrow_keys_internal (vi_movement_keymap);
+ /* Unbind vi_movement_keymap[ESC] to allow users to repeatedly hit ESC
+ in vi command mode while still allowing the arrow keys to work. */
+ if (vi_movement_keymap[ESC].type == ISKMAP)
+ rl_bind_keyseq_in_map ("\033", (rl_command_func_t *)NULL, vi_movement_keymap);
+ bind_arrow_keys_internal (vi_insertion_keymap);
+#endif
+}
+
+/* **************************************************************** */
+/* */
+/* Saving and Restoring Readline's state */
+/* */
+/* **************************************************************** */
+
+int
+rl_save_state (sp)
+ struct readline_state *sp;
+{
+ if (sp == 0)
+ return -1;
+
+ sp->point = rl_point;
+ sp->end = rl_end;
+ sp->mark = rl_mark;
+ sp->buffer = rl_line_buffer;
+ sp->buflen = rl_line_buffer_len;
+ sp->ul = rl_undo_list;
+ sp->prompt = rl_prompt;
+
+ sp->rlstate = rl_readline_state;
+ sp->done = rl_done;
+ sp->kmap = _rl_keymap;
+
+ sp->lastfunc = rl_last_func;
+ sp->insmode = rl_insert_mode;
+ sp->edmode = rl_editing_mode;
+ sp->kseqlen = rl_key_sequence_length;
+ sp->inf = rl_instream;
+ sp->outf = rl_outstream;
+ sp->pendingin = rl_pending_input;
+ sp->macro = rl_executing_macro;
+
+ sp->catchsigs = rl_catch_signals;
+ sp->catchsigwinch = rl_catch_sigwinch;
+
+ return (0);
+}
+
+int
+rl_restore_state (sp)
+ struct readline_state *sp;
+{
+ if (sp == 0)
+ return -1;
+
+ rl_point = sp->point;
+ rl_end = sp->end;
+ rl_mark = sp->mark;
+ the_line = rl_line_buffer = sp->buffer;
+ rl_line_buffer_len = sp->buflen;
+ rl_undo_list = sp->ul;
+ rl_prompt = sp->prompt;
+
+ rl_readline_state = sp->rlstate;
+ rl_done = sp->done;
+ _rl_keymap = sp->kmap;
+
+ rl_last_func = sp->lastfunc;
+ rl_insert_mode = sp->insmode;
+ rl_editing_mode = sp->edmode;
+ rl_key_sequence_length = sp->kseqlen;
+ rl_instream = sp->inf;
+ rl_outstream = sp->outf;
+ rl_pending_input = sp->pendingin;
+ rl_executing_macro = sp->macro;
+
+ rl_catch_signals = sp->catchsigs;
+ rl_catch_sigwinch = sp->catchsigwinch;
+
+ return (0);
+}
diff -Naur bash-4.3.orig/lib/sh/shquote.c bash-4.3/lib/sh/shquote.c
--- bash-4.3.orig/lib/sh/shquote.c 2013-04-01 01:53:32.000000000 +0000
+++ bash-4.3/lib/sh/shquote.c 2014-09-26 23:58:55.556306592 +0000
@@ -311,3 +311,17 @@
return (0);
}
+
+int
+sh_contains_quotes (string)
+ char *string;
+{
+ char *s;
+
+ for (s = string; s && *s; s++)
+ {
+ if (*s == '\'' || *s == '"' || *s == '\\')
+ return 1;
+ }
+ return 0;
+}
diff -Naur bash-4.3.orig/parse.y bash-4.3/parse.y
--- bash-4.3.orig/parse.y 2014-02-11 14:42:10.000000000 +0000
+++ bash-4.3/parse.y 2014-09-26 23:58:55.632973072 +0000
@@ -2424,7 +2424,7 @@
not already end in an EOF character. */
if (shell_input_line_terminator != EOF)
{
- if (shell_input_line_size < SIZE_MAX && shell_input_line_len > shell_input_line_size - 3)
+ if (shell_input_line_size < SIZE_MAX-3 && (shell_input_line_len+3 > shell_input_line_size))
shell_input_line = (char *)xrealloc (shell_input_line,
1 + (shell_input_line_size += 2));
@@ -2642,7 +2642,7 @@
int r;
r = 0;
- while (need_here_doc)
+ while (need_here_doc > 0)
{
parser_state |= PST_HEREDOC;
make_here_document (redir_stack[r++], line_number);
@@ -2953,6 +2953,8 @@
FREE (word_desc_to_read);
word_desc_to_read = (WORD_DESC *)NULL;
+ eol_ungetc_lookahead = 0;
+
current_token = '\n'; /* XXX */
last_read_token = '\n';
token_to_read = '\n';
@@ -3398,7 +3400,7 @@
within a double-quoted ${...} construct "an even number of
unescaped double-quotes or single-quotes, if any, shall occur." */
/* This was changed in Austin Group Interp 221 */
- if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'')
+ if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && dolbrace_state != DOLBRACE_QUOTE2 && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'')
continue;
/* Could also check open == '`' if we want to parse grouping constructs
@@ -6075,6 +6077,7 @@
ps->expand_aliases = expand_aliases;
ps->echo_input_at_read = echo_input_at_read;
+ ps->need_here_doc = need_here_doc;
ps->token = token;
ps->token_buffer_size = token_buffer_size;
@@ -6123,6 +6126,7 @@
expand_aliases = ps->expand_aliases;
echo_input_at_read = ps->echo_input_at_read;
+ need_here_doc = ps->need_here_doc;
FREE (token);
token = ps->token;
diff -Naur bash-4.3.orig/patchlevel.h bash-4.3/patchlevel.h
--- bash-4.3.orig/patchlevel.h 2012-12-29 15:47:57.000000000 +0000
+++ bash-4.3/patchlevel.h 2014-09-26 23:58:55.636306397 +0000
@@ -25,6 +25,6 @@
regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
looks for to find the patch level (for the sccs version string). */
-#define PATCHLEVEL 0
+#define PATCHLEVEL 26
#endif /* _PATCHLEVEL_H_ */
diff -Naur bash-4.3.orig/pcomplete.c bash-4.3/pcomplete.c
--- bash-4.3.orig/pcomplete.c 2013-08-26 19:23:45.000000000 +0000
+++ bash-4.3/pcomplete.c 2014-09-26 23:58:55.559639918 +0000
@@ -183,6 +183,7 @@
COMPSPEC *pcomp_curcs;
const char *pcomp_curcmd;
+const char *pcomp_curtxt;
#ifdef DEBUG
/* Debugging code */
@@ -753,6 +754,32 @@
quoted strings. */
dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
}
+ /* Intended to solve a mismatched assumption by bash-completion. If
+ the text to be completed is empty, but bash-completion turns it into
+ a quoted string ('') assuming that this code will dequote it before
+ calling readline, do the dequoting. */
+ else if (iscompgen && iscompleting &&
+ pcomp_curtxt && *pcomp_curtxt == 0 &&
+ text && (*text == '\'' || *text == '"') && text[1] == text[0] && text[2] == 0 &&
+ rl_filename_dequoting_function)
+ dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
+ /* Another mismatched assumption by bash-completion. If compgen is being
+ run as part of bash-completion, and the argument to compgen is not
+ the same as the word originally passed to the programmable completion
+ code, dequote the argument if it has quote characters. It's an
+ attempt to detect when bash-completion is quoting its filename
+ argument before calling compgen. */
+ /* We could check whether gen_shell_function_matches is in the call
+ stack by checking whether the gen-shell-function-matches tag is in
+ the unwind-protect stack, but there's no function to do that yet.
+ We could simply check whether we're executing in a function by
+ checking variable_context, and may end up doing that. */
+ else if (iscompgen && iscompleting && rl_filename_dequoting_function &&
+ pcomp_curtxt && text &&
+ STREQ (pcomp_curtxt, text) == 0 &&
+ variable_context &&
+ sh_contains_quotes (text)) /* guess */
+ dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
else
dfn = savestring (text);
}
@@ -1522,7 +1549,7 @@
COMPSPEC **lastcs;
{
COMPSPEC *cs, *oldcs;
- const char *oldcmd;
+ const char *oldcmd, *oldtxt;
STRINGLIST *ret;
cs = progcomp_search (ocmd);
@@ -1545,14 +1572,17 @@
oldcs = pcomp_curcs;
oldcmd = pcomp_curcmd;
+ oldtxt = pcomp_curtxt;
pcomp_curcs = cs;
pcomp_curcmd = cmd;
+ pcomp_curtxt = word;
ret = gen_compspec_completions (cs, cmd, word, start, end, foundp);
pcomp_curcs = oldcs;
pcomp_curcmd = oldcmd;
+ pcomp_curtxt = oldtxt;
/* We need to conditionally handle setting *retryp here */
if (retryp)
diff -Naur bash-4.3.orig/shell.h bash-4.3/shell.h
--- bash-4.3.orig/shell.h 2012-12-26 02:11:01.000000000 +0000
+++ bash-4.3/shell.h 2014-09-26 23:58:55.596306495 +0000
@@ -168,7 +168,8 @@
/* flags state affecting the parser */
int expand_aliases;
int echo_input_at_read;
-
+ int need_here_doc;
+
} sh_parser_state_t;
typedef struct _sh_input_line_state_t {
diff -Naur bash-4.3.orig/subst.c bash-4.3/subst.c
--- bash-4.3.orig/subst.c 2014-01-23 21:26:37.000000000 +0000
+++ bash-4.3/subst.c 2014-09-26 23:58:55.629639747 +0000
@@ -1192,12 +1192,18 @@
Start extracting at (SINDEX) as if we had just seen "<(".
Make (SINDEX) get the position of the matching ")". */ /*))*/
char *
-extract_process_subst (string, starter, sindex)
+extract_process_subst (string, starter, sindex, xflags)
char *string;
char *starter;
int *sindex;
+ int xflags;
{
+#if 0
return (extract_delimited_string (string, sindex, starter, "(", ")", SX_COMMAND));
+#else
+ xflags |= (no_longjmp_on_fatal_error ? SX_NOLONGJMP : 0);
+ return (xparse_dolparen (string, string+*sindex, sindex, xflags));
+#endif
}
#endif /* PROCESS_SUBSTITUTION */
@@ -1785,7 +1791,7 @@
si = i + 2;
if (string[si] == '\0')
CQ_RETURN(si);
- temp = extract_process_subst (string, (c == '<') ? "<(" : ">(", &si);
+ temp = extract_process_subst (string, (c == '<') ? "<(" : ">(", &si, 0);
free (temp); /* no SX_ALLOC here */
i = si;
if (string[i] == '\0')
@@ -3248,8 +3254,10 @@
if (w->word == 0 || w->word[0] == '\0')
return ((char *)NULL);
+ expand_no_split_dollar_star = 1;
w->flags |= W_NOSPLIT2;
l = call_expand_word_internal (w, 0, 0, (int *)0, (int *)0);
+ expand_no_split_dollar_star = 0;
if (l)
{
if (special == 0) /* LHS */
@@ -7366,7 +7374,13 @@
}
if (want_indir)
- tdesc = parameter_brace_expand_indir (name + 1, var_is_special, quoted, quoted_dollar_atp, contains_dollar_at);
+ {
+ tdesc = parameter_brace_expand_indir (name + 1, var_is_special, quoted, quoted_dollar_atp, contains_dollar_at);
+ /* Turn off the W_ARRAYIND flag because there is no way for this function
+ to return the index we're supposed to be using. */
+ if (tdesc && tdesc->flags)
+ tdesc->flags &= ~W_ARRAYIND;
+ }
else
tdesc = parameter_brace_expand_word (name, var_is_special, quoted, PF_IGNUNBOUND|(pflags&(PF_NOSPLIT2|PF_ASSIGNRHS)), &ind);
@@ -7847,6 +7861,10 @@
We also want to make sure that splitting is done no matter what --
according to POSIX.2, this expands to a list of the positional
parameters no matter what IFS is set to. */
+ /* XXX - what to do when in a context where word splitting is not
+ performed? Even when IFS is not the default, posix seems to imply
+ that we behave like unquoted $* ? Maybe we should use PF_NOSPLIT2
+ here. */
temp = string_list_dollar_at (list, (pflags & PF_ASSIGNRHS) ? (quoted|Q_DOUBLE_QUOTES) : quoted);
tflag |= W_DOLLARAT;
@@ -8029,7 +8047,9 @@
goto return0;
}
- else if (var = find_variable_last_nameref (temp1))
+ else if (var && (invisible_p (var) || var_isset (var) == 0))
+ temp = (char *)NULL;
+ else if ((var = find_variable_last_nameref (temp1)) && var_isset (var) && invisible_p (var) == 0)
{
temp = nameref_cell (var);
#if defined (ARRAY_VARS)
@@ -8243,7 +8263,7 @@
else
t_index = sindex + 1; /* skip past both '<' and LPAREN */
- temp1 = extract_process_subst (string, (c == '<') ? "<(" : ">(", &t_index); /*))*/
+ temp1 = extract_process_subst (string, (c == '<') ? "<(" : ">(", &t_index, 0); /*))*/
sindex = t_index;
/* If the process substitution specification is `<()', we want to
@@ -8816,6 +8836,7 @@
else
{
char *ifs_chars;
+ char *tstring;
ifs_chars = (quoted_dollar_at || has_dollar_at) ? ifs_value : (char *)NULL;
@@ -8830,11 +8851,36 @@
regardless of what else has happened to IFS since the expansion. */
if (split_on_spaces)
list = list_string (istring, " ", 1); /* XXX quoted == 1? */
+ /* If we have $@ (has_dollar_at != 0) and we are in a context where we
+ don't want to split the result (W_NOSPLIT2), and we are not quoted,
+ we have already separated the arguments with the first character of
+ $IFS. In this case, we want to return a list with a single word
+ with the separator possibly replaced with a space (it's what other
+ shells seem to do).
+ quoted_dollar_at is internal to this function and is set if we are
+ passed an argument that is unquoted (quoted == 0) but we encounter a
+ double-quoted $@ while expanding it. */
+ else if (has_dollar_at && quoted_dollar_at == 0 && ifs_chars && quoted == 0 && (word->flags & W_NOSPLIT2))
+ {
+ /* Only split and rejoin if we have to */
+ if (*ifs_chars && *ifs_chars != ' ')
+ {
+ list = list_string (istring, *ifs_chars ? ifs_chars : " ", 1);
+ tstring = string_list (list);
+ }
+ else
+ tstring = istring;
+ tword = make_bare_word (tstring);
+ if (tstring != istring)
+ free (tstring);
+ goto set_word_flags;
+ }
else if (has_dollar_at && ifs_chars)
list = list_string (istring, *ifs_chars ? ifs_chars : " ", 1);
else
{
tword = make_bare_word (istring);
+set_word_flags:
if ((quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)) || (quoted_state == WHOLLY_QUOTED))
tword->flags |= W_QUOTED;
if (word->flags & W_ASSIGNMENT)
diff -Naur bash-4.3.orig/subst.h bash-4.3/subst.h
--- bash-4.3.orig/subst.h 2014-01-12 02:02:27.000000000 +0000
+++ bash-4.3/subst.h 2014-09-26 23:58:55.612973121 +0000
@@ -82,7 +82,7 @@
/* Extract the <( or >( construct in STRING, and return a new string.
Start extracting at (SINDEX) as if we had just seen "<(".
Make (SINDEX) get the position just after the matching ")". */
-extern char *extract_process_subst __P((char *, char *, int *));
+extern char *extract_process_subst __P((char *, char *, int *, int));
#endif /* PROCESS_SUBSTITUTION */
/* Extract the name of the variable to bind to from the assignment string. */
diff -Naur bash-4.3.orig/test.c bash-4.3/test.c
--- bash-4.3.orig/test.c 2014-02-04 21:52:58.000000000 +0000
+++ bash-4.3/test.c 2014-09-26 23:58:55.506306714 +0000
@@ -646,8 +646,8 @@
return (v && invisible_p (v) == 0 && var_isset (v) ? TRUE : FALSE);
case 'R':
- v = find_variable (arg);
- return (v && invisible_p (v) == 0 && var_isset (v) && nameref_p (v) ? TRUE : FALSE);
+ v = find_variable_noref (arg);
+ return ((v && invisible_p (v) == 0 && var_isset (v) && nameref_p (v)) ? TRUE : FALSE);
}
/* We can't actually get here, but this shuts up gcc. */
@@ -723,6 +723,7 @@
case 'o': case 'p': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'z':
case 'G': case 'L': case 'O': case 'S': case 'N':
+ case 'R':
return (1);
}
diff -Naur bash-4.3.orig/trap.c bash-4.3/trap.c
--- bash-4.3.orig/trap.c 2014-02-05 15:03:21.000000000 +0000
+++ bash-4.3/trap.c 2014-09-26 23:58:55.509640040 +0000
@@ -920,7 +920,8 @@
subst_assign_varlist = 0;
#if defined (JOB_CONTROL)
- save_pipeline (1); /* XXX only provides one save level */
+ if (sig != DEBUG_TRAP) /* run_debug_trap does this */
+ save_pipeline (1); /* XXX only provides one save level */
#endif
/* If we're in a function, make sure return longjmps come here, too. */
@@ -940,7 +941,8 @@
trap_exit_value = last_command_exit_value;
#if defined (JOB_CONTROL)
- restore_pipeline (1);
+ if (sig != DEBUG_TRAP) /* run_debug_trap does this */
+ restore_pipeline (1);
#endif
subst_assign_varlist = save_subst_varlist;
diff -Naur bash-4.3.orig/variables.c bash-4.3/variables.c
--- bash-4.3.orig/variables.c 2014-02-14 16:55:12.000000000 +0000
+++ bash-4.3/variables.c 2014-09-26 23:58:55.626306422 +0000
@@ -358,13 +358,11 @@
temp_string[char_index] = ' ';
strcpy (temp_string + char_index + 1, string);
- if (posixly_correct == 0 || legal_identifier (name))
- parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST);
-
- /* Ancient backwards compatibility. Old versions of bash exported
- functions like name()=() {...} */
- if (name[char_index - 1] == ')' && name[char_index - 2] == '(')
- name[char_index - 2] = '\0';
+ /* Don't import function names that are invalid identifiers from the
+ environment, though we still allow them to be defined as shell
+ variables. */
+ if (legal_identifier (name))
+ parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD);
if (temp_var = find_function (name))
{
@@ -381,10 +379,6 @@
last_command_exit_value = 1;
report_error (_("error importing function definition for `%s'"), name);
}
-
- /* ( */
- if (name[char_index - 1] == ')' && name[char_index - 2] == '\0')
- name[char_index - 2] = '('; /* ) */
}
#if defined (ARRAY_VARS)
# if ARRAY_EXPORT
@@ -2197,10 +2191,7 @@
/* local foo; local foo; is a no-op. */
old_var = find_variable (name);
if (old_var && local_p (old_var) && old_var->context == variable_context)
- {
- VUNSETATTR (old_var, att_invisible); /* XXX */
- return (old_var);
- }
+ return (old_var);
was_tmpvar = old_var && tempvar_p (old_var);
/* If we're making a local variable in a shell function, the temporary env
diff -Naur bash-4.3.orig/y.tab.c bash-4.3/y.tab.c
--- bash-4.3.orig/y.tab.c 2014-02-11 15:57:47.000000000 +0000
+++ bash-4.3/y.tab.c 2014-09-26 23:58:55.636306397 +0000
@@ -4736,7 +4736,7 @@
not already end in an EOF character. */
if (shell_input_line_terminator != EOF)
{
- if (shell_input_line_size < SIZE_MAX && shell_input_line_len > shell_input_line_size - 3)
+ if (shell_input_line_size < SIZE_MAX-3 && (shell_input_line_len+3 > shell_input_line_size))
shell_input_line = (char *)xrealloc (shell_input_line,
1 + (shell_input_line_size += 2));
@@ -4954,7 +4954,7 @@
int r;
r = 0;
- while (need_here_doc)
+ while (need_here_doc > 0)
{
parser_state |= PST_HEREDOC;
make_here_document (redir_stack[r++], line_number);
@@ -5265,6 +5265,8 @@
FREE (word_desc_to_read);
word_desc_to_read = (WORD_DESC *)NULL;
+ eol_ungetc_lookahead = 0;
+
current_token = '\n'; /* XXX */
last_read_token = '\n';
token_to_read = '\n';
@@ -5710,7 +5712,7 @@
within a double-quoted ${...} construct "an even number of
unescaped double-quotes or single-quotes, if any, shall occur." */
/* This was changed in Austin Group Interp 221 */
- if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'')
+ if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && dolbrace_state != DOLBRACE_QUOTE2 && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'')
continue;
/* Could also check open == '`' if we want to parse grouping constructs
@@ -8387,6 +8389,7 @@
ps->expand_aliases = expand_aliases;
ps->echo_input_at_read = echo_input_at_read;
+ ps->need_here_doc = need_here_doc;
ps->token = token;
ps->token_buffer_size = token_buffer_size;
@@ -8435,6 +8438,7 @@
expand_aliases = ps->expand_aliases;
echo_input_at_read = ps->echo_input_at_read;
+ need_here_doc = ps->need_here_doc;
FREE (token);
token = ps->token;
@@ -8537,4 +8541,3 @@
}
}
#endif /* HANDLE_MULTIBYTE */
-