commit bash-20110525 snapshot

This commit is contained in:
Chet Ramey
2011-12-29 13:08:48 -05:00
parent 22818c1449
commit 276cb932b6
35 changed files with 14195 additions and 159 deletions
+62 -48
View File
@@ -72,11 +72,15 @@ extern char *strchr (), *strrchr ();
/* Variables exported by this file. */
Keymap rl_binding_keymap;
static int _rl_skip_to_delim PARAMS((char *, int, int));
static char *_rl_read_file PARAMS((char *, size_t *));
static void _rl_init_file_error PARAMS((const char *));
static int _rl_read_init_file PARAMS((const char *, int));
static int glean_key_from_name PARAMS((char *));
static int find_boolean_var PARAMS((const char *));
static int find_string_var PARAMS((const char *));
static char *_rl_get_string_variable_value PARAMS((const char *));
static int substring_member_of_array PARAMS((const char *, const char * const *));
@@ -1157,6 +1161,38 @@ handle_parser_directive (statement)
return (1);
}
/* Start at STRING[START] and look for DELIM. Return I where STRING[I] ==
DELIM or STRING[I] == 0. DELIM is usually a double quote. */
static int
_rl_skip_to_delim (string, start, delim)
char *string;
int start, delim;
{
int i, c, passc;
for (i = start,passc = 0; c = string[i]; i++)
{
if (passc)
{
passc = 0;
if (c == 0)
break;
continue;
}
if (c == '\\')
{
passc = 1;
continue;
}
if (c == delim)
break;
}
return i;
}
/* Read the binding command from STRING and perform it.
A key binding command looks like: Keyname: function-name\0,
a variable binding command looks like: set variable value.
@@ -1172,7 +1208,7 @@ rl_parse_and_bind (string)
while (string && whitespace (*string))
string++;
if (!string || !*string || *string == '#')
if (string == 0 || *string == 0 || *string == '#')
return 0;
/* If this is a parser directive, act on it. */
@@ -1192,31 +1228,16 @@ rl_parse_and_bind (string)
backslash to quote characters in the key expression. */
if (*string == '"')
{
int passc = 0;
i = _rl_skip_to_delim (string, 1, '"');
for (i = 1; c = string[i]; i++)
{
if (passc)
{
passc = 0;
continue;
}
if (c == '\\')
{
passc++;
continue;
}
if (c == '"')
break;
}
/* If we didn't find a closing quote, abort the line. */
if (string[i] == '\0')
{
_rl_init_file_error ("no closing `\"' in key binding");
return 1;
}
else
i++; /* skip past closing double quote */
}
/* Advance to the colon (:) or whitespace which separates the two objects. */
@@ -1236,6 +1257,7 @@ rl_parse_and_bind (string)
if (_rl_stricmp (string, "set") == 0)
{
char *var, *value, *e;
int s;
var = string + i;
/* Make VAR point to start of variable name. */
@@ -1243,25 +1265,36 @@ rl_parse_and_bind (string)
/* Make VALUE point to start of value string. */
value = var;
while (*value && !whitespace (*value)) value++;
while (*value && whitespace (*value) == 0) value++;
if (*value)
*value++ = '\0';
while (*value && whitespace (*value)) value++;
/* Strip trailing whitespace from values to boolean variables. Temp
fix until I get a real quoted-string parser here. */
i = find_boolean_var (var);
if (i >= 0)
/* Strip trailing whitespace from values of boolean variables. */
if (find_boolean_var (var) >= 0)
{
/* remove trailing whitespace */
remove_trailing:
e = value + strlen (value) - 1;
while (e >= value && whitespace (*e))
e--;
e++; /* skip back to whitespace or EOS */
if (*e && e >= value)
*e = '\0';
}
else if ((i = find_string_var (var)) >= 0)
{
/* Allow quoted strings in variable values */
if (*value == '"')
{
i = _rl_skip_to_delim (value, 1, *value);
value[i] = '\0';
}
else
goto remove_trailing;
}
rl_variable_bind (var, value);
return 0;
}
@@ -1282,32 +1315,13 @@ rl_parse_and_bind (string)
the quoted string delimiter, like the shell. */
if (*funname == '\'' || *funname == '"')
{
int delimiter, passc;
delimiter = string[i++];
for (passc = 0; c = string[i]; i++)
{
if (passc)
{
passc = 0;
continue;
}
if (c == '\\')
{
passc = 1;
continue;
}
if (c == delimiter)
break;
}
if (c)
i = _rl_skip_to_delim (string, i+1, *funname);
if (string[i])
i++;
}
/* Advance to the end of the string. */
for (; string[i] && !whitespace (string[i]); i++);
for (; string[i] && whitespace (string[i]) == 0; i++);
/* No extra whitespace at the end of the string. */
string[i] = '\0';
@@ -1367,7 +1381,7 @@ rl_parse_and_bind (string)
/* Get the actual character we want to deal with. */
kname = strrchr (string, '-');
if (!kname)
if (kname == 0)
kname = string;
else
kname++;