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

This commit is contained in:
Jari Aalto 1998-04-17 19:52:44 +00:00
commit cce855bc5b
323 changed files with 33916 additions and 12321 deletions

View file

@ -36,6 +36,7 @@
#include "bashhist.h"
#include "bashline.h"
#include "execute_cmd.h"
#include "findcmd.h"
#include "pathexp.h"
#include "builtins/common.h"
#include <readline/rlconf.h>
@ -55,13 +56,20 @@ extern void bash_brace_completion ();
/* Functions bound to keys in Readline for Bash users. */
static void shell_expand_line ();
static void display_shell_version (), operate_and_get_next ();
static void history_expand_line (), bash_ignore_filenames ();
#ifdef ALIAS
static void alias_expand_line ();
#endif
static void history_and_alias_expand_line ();
static void bash_ignore_filenames ();
static void cleanup_expansion_error (), set_up_new_line ();
#if defined (BANG_HISTORY)
static int history_expand_line ();
static int tcsh_magic_space ();
#endif /* BANG_HISTORY */
#ifdef ALIAS
static int alias_expand_line ();
#endif
#if defined (BANG_HISTORY) && defined (ALIAS)
static int history_and_alias_expand_line ();
#endif
/* Helper functions for Readline. */
static int bash_directory_completion_hook ();
static void filename_completion_ignore ();
@ -196,9 +204,13 @@ initialize_readline ()
rl_bind_key_in_map (CTRL('E'), (Function *)shell_expand_line, emacs_meta_keymap);
/* Bind up our special shell functions. */
#ifdef BANG_HISTORY
rl_add_defun ("history-expand-line", (Function *)history_expand_line, -1);
rl_bind_key_in_map ('^', (Function *)history_expand_line, emacs_meta_keymap);
rl_add_defun ("magic-space", (Function *)tcsh_magic_space, -1);
#endif
#ifdef ALIAS
rl_add_defun ("alias-expand-line", (Function *)alias_expand_line, -1);
rl_add_defun ("history-and-alias-expand-line", (Function *)history_and_alias_expand_line, -1);
@ -1030,7 +1042,7 @@ command_subst_completion_function (text, state)
orig_start = text;
if (*text == '`')
text++;
else if (*text == '$' && text[1] == '(')
else if (*text == '$' && text[1] == '(') /* ) */
text += 2;
start_len = text - orig_start;
filename_text = savestring (text);
@ -1173,7 +1185,12 @@ hostname_completion_function (text, state)
return ((char *)NULL);
}
/* History and alias expand the line. */
/* Functions to perform history and alias expansions on the current line. */
#if defined (BANG_HISTORY)
/* Perform history expansion on the current line. If no history expansion
is done, pre_process_line() returns what it was passed, so we need to
allocate a new line here. */
static char *
history_expand_line_internal (line)
char *line;
@ -1183,22 +1200,6 @@ history_expand_line_internal (line)
new_line = pre_process_line (line, 0, 0);
return (new_line == line) ? savestring (line) : new_line;
}
#if defined (ALIAS)
/* Expand aliases in the current readline line. */
static void
alias_expand_line (ignore)
int ignore;
{
char *new_line;
new_line = alias_expand (rl_line_buffer);
if (new_line)
set_up_new_line (new_line);
else
cleanup_expansion_error ();
}
#endif
/* There was an error in expansion. Let the preprocessor print
@ -1259,8 +1260,32 @@ set_up_new_line (new_line)
}
}
#if defined (ALIAS)
/* Expand aliases in the current readline line. */
static int
alias_expand_line (ignore)
int ignore;
{
char *new_line;
new_line = alias_expand (rl_line_buffer);
if (new_line)
{
set_up_new_line (new_line);
return (0);
}
else
{
cleanup_expansion_error ();
return (1);
}
}
#endif
#if defined (BANG_HISTORY)
/* History expand the line. */
static void
static int
history_expand_line (ignore)
int ignore;
{
@ -1269,13 +1294,35 @@ history_expand_line (ignore)
new_line = history_expand_line_internal (rl_line_buffer);
if (new_line)
set_up_new_line (new_line);
{
set_up_new_line (new_line);
return (0);
}
else
cleanup_expansion_error ();
{
cleanup_expansion_error ();
return (1);
}
}
/* Expand history substitutions in the current line and then insert a
space wherever set_up_new_line decided to put rl_point. */
static int
tcsh_magic_space (ignore)
int ignore;
{
if (history_expand_line (ignore) == 0)
{
rl_insert (1, ' ');
return (0);
}
else
return (1);
}
#endif
/* History and alias expand the line. */
static void
static int
history_and_alias_expand_line (ignore)
int ignore;
{
@ -1297,13 +1344,21 @@ history_and_alias_expand_line (ignore)
#endif /* ALIAS */
if (new_line)
set_up_new_line (new_line);
{
set_up_new_line (new_line);
return (0);
}
else
cleanup_expansion_error ();
{
cleanup_expansion_error ();
return (1);
}
}
/* History and alias expand the line, then perform the shell word
expansions by calling expand_string. */
expansions by calling expand_string. This can't use set_up_new_line()
because we want the variable expansions as a separate undo'able
set of operations. */
static void
shell_expand_line (ignore)
int ignore;
@ -1369,6 +1424,10 @@ shell_expand_line (ignore)
cleanup_expansion_error ();
}
/* Define NO_FORCE_FIGNORE if you want to match filenames that would
otherwise be ignored if they are the only possible matches. */
/* #define NO_FORCE_FIGNORE */
/* If FIGNORE is set, then don't match files with the given suffixes when
completing filenames. If only one of the possibilities has an acceptable
suffix, delete the others, else just return and let the completer
@ -1393,6 +1452,10 @@ _ignore_completion_names (names, name_func)
{
char **newnames;
int idx, nidx;
#ifdef NO_FORCE_FIGNORE
char **oldnames;
int oidx;
#endif
/* If there is only one completion, see if it is acceptable. If it is
not, free it up. In any case, short-circuit and return. This is a
@ -1400,11 +1463,13 @@ _ignore_completion_names (names, name_func)
if there is only one completion; it is the completion itself. */
if (names[1] == (char *)0)
{
#ifndef NO_FORCE_FIGNORE
if ((*name_func) (names[0]) == 0)
{
free (names[0]);
names[0] = (char *)NULL;
}
#endif
return;
}
@ -1413,6 +1478,10 @@ _ignore_completion_names (names, name_func)
for (nidx = 1; names[nidx]; nidx++)
;
newnames = (char **)xmalloc ((nidx + 1) * (sizeof (char *)));
#ifdef NO_FORCE_FIGNORE
oldnames = (char **)xmalloc ((nidx - 1) * (sizeof (char *)));
oidx = 0;
#endif
newnames[0] = names[0];
for (idx = nidx = 1; names[idx]; idx++)
@ -1420,7 +1489,11 @@ _ignore_completion_names (names, name_func)
if ((*name_func) (names[idx]))
newnames[nidx++] = names[idx];
else
#ifndef NO_FORCE_FIGNORE
free (names[idx]);
#else
oldnames[oidx++] = names[idx];
#endif
}
newnames[nidx] = (char *)NULL;
@ -1428,12 +1501,22 @@ _ignore_completion_names (names, name_func)
/* If none are acceptable then let the completer handle it. */
if (nidx == 1)
{
#ifndef NO_FORCE_FIGNORE
free (names[0]);
names[0] = (char *)NULL;
#else
free (oldnames);
#endif
free (newnames);
return;
}
#ifdef NO_FORCE_FIGNORE
while (oidx)
free (oldnames[--oidx]);
free (oldnames);
#endif
/* If only one is acceptable, copy it to names[0] and return. */
if (nidx == 2)
{