diff options
author | ache <ache@FreeBSD.org> | 1998-04-28 06:49:42 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1998-04-28 06:49:42 +0000 |
commit | f66beda6a7ff067d589b7c68e3fc91a6b88d1e1a (patch) | |
tree | 8711b2fecbdbe619218d4146753e3cbbf77bbcc3 /contrib/libreadline/util.c | |
parent | 57352a1b33380d0d7c25addd55cf6bdc669428f5 (diff) | |
download | FreeBSD-src-f66beda6a7ff067d589b7c68e3fc91a6b88d1e1a.zip FreeBSD-src-f66beda6a7ff067d589b7c68e3fc91a6b88d1e1a.tar.gz |
Merge local changes
Diffstat (limited to 'contrib/libreadline/util.c')
-rw-r--r-- | contrib/libreadline/util.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/contrib/libreadline/util.c b/contrib/libreadline/util.c index d96b29e..fde012e 100644 --- a/contrib/libreadline/util.c +++ b/contrib/libreadline/util.c @@ -166,6 +166,58 @@ rl_extend_line_buffer (len) _rl_set_the_line (); } + +/* A function for simple tilde expansion. */ +int +rl_tilde_expand (ignore, key) + int ignore, key; +{ + register int start, end; + char *homedir, *temp; + int len; + + end = rl_point; + start = end - 1; + + if (rl_point == rl_end && rl_line_buffer[rl_point] == '~') + { + homedir = tilde_expand ("~"); + _rl_replace_text (homedir, start, end); + return (0); + } + else if (rl_line_buffer[start] != '~') + { + for (; !whitespace (rl_line_buffer[start]) && start >= 0; start--) + ; + start++; + } + + end = start; + do + end++; + while (whitespace (rl_line_buffer[end]) == 0 && end < rl_end); + + if (whitespace (rl_line_buffer[end]) || end >= rl_end) + end--; + + /* If the first character of the current word is a tilde, perform + tilde expansion and insert the result. If not a tilde, do + nothing. */ + if (rl_line_buffer[start] == '~') + { + len = end - start + 1; + temp = xmalloc (len + 1); + strncpy (temp, rl_line_buffer + start, len); + temp[len] = '\0'; + homedir = tilde_expand (temp); + free (temp); + + _rl_replace_text (homedir, start, end); + } + + return (0); +} + /* **************************************************************** */ /* */ /* String Utility Functions */ @@ -300,3 +352,13 @@ _rl_digit_value (c) { return (isdigit (c) ? c - '0' : c); } + +/* Backwards compatibility, now that savestring has been removed from + all `public' readline header files. */ +#undef _rl_savestring +char * +_rl_savestring (s) + char *s; +{ + return ((char *)strcpy (xmalloc (1 + (int)strlen (s)), (s))); +} |