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

This commit is contained in:
Jari Aalto 2001-04-06 19:14:31 +00:00
commit 28ef6c316f
251 changed files with 22319 additions and 12413 deletions

View file

@ -9,12 +9,12 @@
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
Bash 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 Bash; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
@ -22,7 +22,7 @@
#include <config.h>
#include <stdio.h> /* for debugging */
#include "fnmatch.h"
#include "collsyms.h"
#include <ctype.h>
@ -68,18 +68,14 @@ static char *patscan ();
#define STREQN(a, b, n) ((a)[0] == (b)[0] && strncmp(a, b, n) == 0)
#endif
/* We don't use strcoll(3) for range comparisons in bracket expressions,
even if we have it, since it can have unwanted side effects in locales
/* We use strcoll(3) for range comparisons in bracket expressions,
even though it can have unwanted side effects in locales
other than POSIX or US. For instance, in the de locale, [A-Z] matches
all characters. So, for ranges we use ASCII collation, and for
collating symbol equivalence we use strcoll(). The casts to int are
to handle tests that use unsigned chars. */
#define rangecmp(c1, c2) ((int)(c1) - (int)(c2))
all characters. */
#if defined (HAVE_STRCOLL)
/* Helper function for collating symbol equivalence. */
static int rangecmp2 (c1, c2)
static int rangecmp (c1, c2)
int c1, c2;
{
static char s1[2] = { ' ', '\0' };
@ -101,14 +97,14 @@ static int rangecmp2 (c1, c2)
return (c1 - c2);
}
#else /* !HAVE_STRCOLL */
# define rangecmp2(c1, c2) ((int)(c1) - (int)(c2))
# define rangecmp(c1, c2) ((int)(c1) - (int)(c2))
#endif /* !HAVE_STRCOLL */
#if defined (HAVE_STRCOLL)
static int collequiv (c1, c2)
int c1, c2;
{
return (rangecmp2 (c1, c2) == 0);
return (rangecmp (c1, c2) == 0);
}
#else
# define collequiv(c1, c2) ((c1) == (c2))
@ -124,7 +120,7 @@ collsym (s, len)
for (csp = posix_collsyms; csp->name; csp++)
{
if (STREQN(csp->name, s, len) && csp->name[len] == '\0')
return (csp->code);
return (csp->code);
}
if (len == 1)
return s[0];
@ -166,6 +162,11 @@ gmatch (string, se, pattern, pe, flags)
if (string == 0 || pattern == 0)
return FNM_NOMATCH;
#if DEBUG_MATCHING
fprintf(stderr, "gmatch: string = %s; se = %s\n", string, se);
fprintf(stderr, "gmatch: pattern = %s; pe = %s\n", pattern, pe);
#endif
while (p < pe)
{
c = *p++;
@ -270,7 +271,7 @@ gmatch (string, se, pattern, pe, flags)
}
#endif
if (p == pe)
break;
break;
}
/* If we've hit the end of the pattern and the last character of
@ -290,14 +291,14 @@ gmatch (string, se, pattern, pe, flags)
/* Only call fnmatch if the first character indicates a
possible match. We can check the first character if
we're not doing an extended glob match. */
if ((flags & FNM_EXTMATCH) == 0 && c != '[' && FOLD (*n) != c1)
if ((flags & FNM_EXTMATCH) == 0 && c != '[' && FOLD (*n) != c1) /*]*/
continue;
/* If we're doing an extended glob match and the pattern is not
one of the extended glob patterns, we can check the first
character. */
if ((flags & FNM_EXTMATCH) && p[1] != '(' && /*)*/
strchr ("?*+@!", *p) == 0 && c != '[' && FOLD (*n) != c1)
strchr ("?*+@!", *p) == 0 && c != '[' && FOLD (*n) != c1) /*]*/
continue;
/* Otherwise, we just recurse. */
@ -339,7 +340,7 @@ gmatch (string, se, pattern, pe, flags)
if ((flags & FNM_LEADING_DIR) && *n == '/')
/* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
return 0;
return (FNM_NOMATCH);
}
@ -355,7 +356,7 @@ parse_collsym (p, vp)
int val;
p++; /* move past the `.' */
for (pc = 0; p[pc]; pc++)
if (p[pc] == '.' && p[pc+1] == ']')
break;
@ -382,7 +383,7 @@ brackmatch (p, test, flags)
/* POSIX.2 3.13.1 says that an exclamation mark (`!') shall replace the
circumflex (`^') in its role in a `nonmatching list'. A bracket
expression starging with an unquoted circumflex character produces
expression starting with an unquoted circumflex character produces
unspecified results. This implementation treats the two identically. */
if (not = (*p == '!' || *p == '^'))
++p;
@ -404,19 +405,24 @@ brackmatch (p, test, flags)
pc = FOLD (p[1]);
p += 4;
if (collequiv (test, pc))
goto matched;
{
/*[*/ /* Move past the closing `]', since the first thing we do at
the `matched:' label is back p up one. */
p++;
goto matched;
}
else
{
c = *p++;
if (c == '\0')
return ((test == '[') ? savep : (char *)0);
return ((test == '[') ? savep : (char *)0); /*]*/
c = FOLD (c);
continue;
}
}
}
/* POSIX.2 character class expression. See POSIX.2 2.8.3.2. */
if (c == '[' && *p == ':')
if (c == '[' && *p == ':') /*]*/
{
pc = 0; /* make sure invalid char classes don't match. */
if (STREQN (p+1, "alnum:]", 7))
@ -446,7 +452,12 @@ brackmatch (p, test, flags)
else if (STREQN (p+1, "ascii:]", 7))
{ pc = isascii (test); p += 8; }
if (pc)
{
/*[*/ /* Move past the closing `]', since the first thing we do at
the `matched:' label is back p up one. */
p++;
goto matched;
}
else
{
/* continue the loop here, since this expression can't be
@ -455,7 +466,7 @@ brackmatch (p, test, flags)
if (c == '\0')
return ((test == '[') ? savep : (char *)0);
else if (c == ']')
break;
break;
c = FOLD (c);
continue;
}
@ -528,7 +539,7 @@ brackmatch (p, test, flags)
if (rangecmp (cstart, cend) > 0)
{
if (c == ']')
break;
break;
c = FOLD (c);
continue;
}
@ -545,7 +556,12 @@ brackmatch (p, test, flags)
matched:
/* Skip the rest of the [...] that already matched. */
#if 0
brcnt = (c != ']') + (c == '[' && (*p == '=' || *p == ':' || *p == '.'));
#else
c = *--p;
brcnt = 1;
#endif
while (brcnt > 0)
{
/* A `[' without a matching `]' is just another character to match. */
@ -554,9 +570,9 @@ matched:
c = *p++;
if (c == '[' && (*p == '=' || *p == ':' || *p == '.'))
brcnt++;
brcnt++;
else if (c == ']')
brcnt--;
brcnt--;
else if (!(flags & FNM_NOESCAPE) && c == '\\')
{
if (*p == '\0')
@ -593,29 +609,56 @@ patscan (string, end, delim)
char *string, *end;
int delim;
{
int pnest, bnest;
char *s, c;
int pnest, bnest, cchar;
char *s, c, *bfirst;
pnest = bnest = 0;
pnest = bnest = cchar = 0;
bfirst = 0;
for (s = string; c = *s; s++)
{
if (s >= end)
return (s);
return (s);
switch (c)
{
case '\0':
return ((char *)0);
/* `[' is not special inside a bracket expression, but it may
introduce one of the special POSIX bracket expressions
([.SYM.], [=c=], [: ... :]) that needs special handling. */
case '[':
bnest++;
if (bnest == 0)
{
bfirst = s + 1;
if (*bfirst == '!' || *bfirst == '^')
bfirst++;
bnest++;
}
else if (s[1] == ':' || s[1] == '.' || s[1] == '=')
cchar = s[1];
break;
/* `]' is not special if it's the first char (after a leading `!'
or `^') in a bracket expression or if it's part of one of the
special POSIX bracket expressions ([.SYM.], [=c=], [: ... :]) */
case ']':
if (bnest)
bnest--;
{
if (cchar && s[-1] == cchar)
cchar = 0;
else if (s != bfirst)
{
bnest--;
bfirst = 0;
}
}
break;
case '(':
if (bnest == 0)
pnest++;
break;
case ')':
#if 0
if (bnest == 0)
@ -627,6 +670,7 @@ patscan (string, end, delim)
return ++s;
#endif
break;
case '|':
if (bnest == 0 && pnest == 0 && delim == '|')
return ++s;
@ -678,7 +722,7 @@ extmatch (xc, s, se, p, pe, flags)
char *srest; /* pointer to rest of string */
int m1, m2;
#if 0
#if DEBUG_MATCHING
fprintf(stderr, "extmatch: xc = %c\n", xc);
fprintf(stderr, "extmatch: s = %s; se = %s\n", s, se);
fprintf(stderr, "extmatch: p = %s; pe = %s\n", p, pe);
@ -701,8 +745,8 @@ fprintf(stderr, "extmatch: p = %s; pe = %s\n", p, pe);
return 0;
/* OK, we have to do this the hard way. First, we make sure one of
the subpatterns matches, then we try to match the rest of the
string. */
the subpatterns matches, then we try to match the rest of the
string. */
for (psub = p + 1; ; psub = pnext)
{
pnext = patscan (psub, pe, '|');
@ -718,7 +762,7 @@ fprintf(stderr, "extmatch: p = %s; pe = %s\n", p, pe);
m2 = (gmatch (srest, se, prest, pe, flags) == 0) ||
(s != srest && gmatch (srest, se, p - 1, pe, flags) == 0);
if (m1 && m2)
return (0);
return (0);
}
if (pnext == prest)
break;
@ -765,7 +809,7 @@ fprintf(stderr, "extmatch: p = %s; pe = %s\n", p, pe);
break;
}
if (m1 == 0 && gmatch (srest, se, prest, pe, flags) == 0)
return (0);
return (0);
}
return (FNM_NOMATCH);
}

View file

@ -343,7 +343,7 @@ glob_vector (pat, dir)
return ((char **) &glob_error_return);
/* Compute the flags that will be passed to fnmatch(). We don't
need to do this every time through the loop. */
need to do this every time through the loop. */
flags = (noglob_dot_filenames ? FNM_PERIOD : 0) | FNM_PATHNAME;
#ifdef FNM_CASEFOLD
@ -480,14 +480,11 @@ glob_dir_to_array (dir, array)
+ strlen (array[i]) + 1);
if (result[i] == NULL)
return (NULL);
#if 1
strcpy (result[i], dir);
if (add_slash)
result[i][l] = '/';
result[i][l] = '/';
strcpy (result[i] + l + add_slash, array[i]);
#else
(void)sprintf (result[i], "%s%s%s", dir, add_slash ? "/" : "", array[i]);
#endif
}
result[i] = NULL;

View file

@ -651,7 +651,7 @@ imalloc (size)
final free block; if so we don't need to get as much. */
if (_heaplimit != 0 && block + lastblocks == _heaplimit &&
/* We can't do this if we will have to make the heap info
table bigger to accomodate the new space. */
table bigger to accomodate the new space. */
block + wantblocks <= heapsize &&
get_contiguous_space ((wantblocks - lastblocks) * BLOCKSIZE,
ADDRESS (block + lastblocks)))
@ -1165,7 +1165,7 @@ irealloc (ptr, size)
the thing we just freed. Unfortunately it might
have been coalesced with its neighbors. */
if (_heapindex == block)
(void) imalloc (blocks * BLOCKSIZE);
(void) imalloc (blocks * BLOCKSIZE);
else
{
genptr_t previous;

View file

@ -278,6 +278,11 @@ static int pagesz; /* system page size. */
static int pagebucket; /* bucket for requests a page in size */
static int maxbuck; /* highest bucket receiving allocation request. */
#ifdef SHELL
extern int interrupt_immediately;
extern int signal_is_trapped ();
#endif
#if 0
/* Coalesce two adjacent free blocks off the free list for size NU - 1,
as long as there are at least MIN_COMBINE_FREE free blocks and we
@ -399,6 +404,34 @@ bsplit (nu)
CHAIN (mp) = 0;
}
static void
block_signals (setp, osetp)
sigset_t *setp, *osetp;
{
#ifdef HAVE_POSIX_SIGNALS
sigfillset (setp);
sigemptyset (osetp);
sigprocmask (SIG_BLOCK, setp, osetp);
#else
# if defined (HAVE_BSD_SIGNALS)
*osetp = sigsetmask (-1);
# endif
#endif
}
static void
unblock_signals (setp, osetp)
sigset_t *setp, *osetp;
{
#ifdef HAVE_POSIX_SIGNALS
sigprocmask (SIG_SETMASK, osetp, (sigset_t *)NULL);
#else
# if defined (HAVE_BSD_SIGNALS)
sigsetmask (*osetp);
# endif
#endif
}
static void
morecore (nu) /* ask system for more memory */
register int nu; /* size index to get more of */
@ -407,19 +440,18 @@ morecore (nu) /* ask system for more memory */
register int nblks;
register long siz;
long sbrk_amt; /* amount to get via sbrk() */
sigset_t set, oset;
int blocked_sigs;
/* Block all signals in case we are executed from a signal handler. */
#if defined (HAVE_BSD_SIGNALS)
int oldmask;
oldmask = sigsetmask (-1);
#else
# if defined (HAVE_POSIX_SIGNALS)
sigset_t set, oset;
sigfillset (&set);
sigemptyset (&oset);
sigprocmask (SIG_BLOCK, &set, &oset);
# endif /* HAVE_POSIX_SIGNALS */
#endif /* HAVE_BSD_SIGNALS */
blocked_sigs = 0;
#ifdef SHELL
if (interrupt_immediately || signal_is_trapped (SIGINT) || signal_is_trapped (SIGCHLD))
#endif
{
block_signals (&set, &oset);
blocked_sigs = 1;
}
siz = 1 << (nu + 3); /* size of desired block for nextf[nu] */
@ -450,7 +482,7 @@ morecore (nu) /* ask system for more memory */
{
bcoalesce (nu);
if (nextf[nu] != 0)
goto morecore_done;
goto morecore_done;
}
#endif
@ -507,15 +539,8 @@ morecore (nu) /* ask system for more memory */
CHAIN (mp) = 0;
morecore_done:
#if defined (HAVE_BSD_SIGNALS)
sigsetmask (oldmask);
#else
# if defined (HAVE_POSIX_SIGNALS)
sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL);
# else
; /* nothing to do, but need a null statement before the brace */
# endif
#endif /* HAVE_BSD_SIGNALS */
if (blocked_sigs)
unblock_signals (&set, &oset);
}
#if defined (MEMSCRAMBLE) || !defined (NO_CALLOC)
@ -557,30 +582,30 @@ malloc (n) /* get a block */
pagesz = getpagesize ();
if (pagesz < 1024)
pagesz = 1024;
pagesz = 1024;
/* OK, how much do we need to allocate to make things page-aligned?
This partial page is wasted space. Once we figure out how much
to advance the break pointer, go ahead and do it. */
This partial page is wasted space. Once we figure out how much
to advance the break pointer, go ahead and do it. */
sbrk_needed = pagesz - ((long)sbrk (0) & (pagesz - 1)); /* sbrk(0) % pagesz */
if (sbrk_needed < 0)
sbrk_needed += pagesz;
sbrk_needed += pagesz;
/* Now allocate the wasted space. */
if (sbrk_needed)
{
{
#ifdef MALLOC_STATS
_mstats.nsbrk++;
_mstats.tsbrk += sbrk_needed;
#endif
if ((long)sbrk (sbrk_needed) == -1)
return (NULL);
}
if ((long)sbrk (sbrk_needed) == -1)
return (NULL);
}
nunits = 0;
nbytes = 8;
while (pagesz > nbytes)
{
nbytes <<= 1;
nunits++;
}
{
nbytes <<= 1;
nunits++;
}
pagebucket = nunits;
}
@ -605,10 +630,10 @@ malloc (n) /* get a block */
nunits = pagebucket;
amt = pagesz;
while (nbytes > amt)
{
amt <<= 1;
nunits++;
}
{
amt <<= 1;
nunits++;
}
}
/* In case this is reentrant use of malloc from signal handler,
@ -924,6 +949,7 @@ _print_malloc_stats (s, fp)
void
print_malloc_stats (s)
char *s;
{
_print_malloc_stats (s, stderr);
}
@ -933,6 +959,7 @@ extern char *inttostr ();
void
trace_malloc_stats (s)
char *s;
{
char ibuf[32], *ip;
char fname[64];

View file

@ -305,7 +305,7 @@ the "copyright" line and a pointer to where the full notice is found.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
Also add information on how to contact you by electronic and paper mail.

View file

@ -72,19 +72,21 @@ CSOURCES = $(srcdir)/readline.c $(srcdir)/funmap.c $(srcdir)/keymaps.c \
$(srcdir)/callback.c $(srcdir)/terminal.c $(srcdir)/xmalloc.c \
$(srcdir)/history.c $(srcdir)/histsearch.c $(srcdir)/histexpand.c \
$(srcdir)/histfile.c $(srcdir)/nls.c $(srcdir)/search.c \
$(srcdir)/shell.c $(srcdir)/tilde.c $(srcdir)/savestring.c
$(srcdir)/shell.c $(srcdir)/tilde.c $(srcdir)/savestring.c \
$(srcdir)/compat.c
# The header files for this library.
HSOURCES = readline.h rldefs.h chardefs.h keymaps.h history.h histlib.h \
posixstat.h posixdir.h posixjmp.h tilde.h rlconf.h rltty.h \
ansi_stdlib.h rlstdc.h tcap.h rlprivate.h rlshell.h
ansi_stdlib.h rlstdc.h tcap.h xmalloc.h rlprivate.h rlshell.h \
rltypedefs.h
HISTOBJ = history.o histexpand.o histfile.o histsearch.o shell.o savestring.o
TILDEOBJ = tilde.o
OBJECTS = readline.o vi_mode.o funmap.o keymaps.o parens.o search.o \
rltty.o complete.o bind.o isearch.o display.o signals.o \
util.o kill.o undo.o macro.o input.o callback.o terminal.o \
nls.o $(HISTOBJ) $(TILDEOBJ) xmalloc.o
nls.o $(HISTOBJ) $(TILDEOBJ) xmalloc.o compat.o
# The texinfo files which document this library.
DOCSOURCE = doc/rlman.texinfo doc/rltech.texinfo doc/rluser.texinfo
@ -98,7 +100,8 @@ SOURCES = $(CSOURCES) $(HSOURCES) $(DOCSOURCE)
THINGS_TO_TAR = $(SOURCES) $(SUPPORT)
INSTALLED_HEADERS = readline.h chardefs.h keymaps.h history.h tilde.h
INSTALLED_HEADERS = readline.h chardefs.h keymaps.h history.h tilde.h \
rlstdc.h rlconf.h rltypedefs.h
##########################################################################
@ -147,20 +150,21 @@ distclean maintainer-clean: clean
# Dependencies
bind.o: ansi_stdlib.h posixstat.h
bind.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
bind.o: readline.h keymaps.h chardefs.h tilde.h
bind.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
bind.o: history.h rlstdc.h
callback.o: rlconf.h
callback.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
callback.o: readline.h keymaps.h chardefs.h tilde.h rlstdc.h
callback.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
compat.o: rlstdc.h
complete.o: ansi_stdlib.h posixdir.h posixstat.h
complete.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
complete.o: readline.h keymaps.h chardefs.h tilde.h rlstdc.h
complete.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
display.o: ansi_stdlib.h posixstat.h
display.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
display.o: tcap.h
display.o: readline.h keymaps.h chardefs.h tilde.h
display.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
display.o: history.h rlstdc.h
funmap.o: readline.h keymaps.h chardefs.h tilde.h
funmap.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
funmap.o: rlconf.h ansi_stdlib.h rlstdc.h
funmap.o: ${BUILD_DIR}/config.h
histexpand.o: ansi_stdlib.h
@ -177,59 +181,59 @@ histsearch.o: history.h histlib.h rlstdc.h
histsearch.o: ${BUILD_DIR}/config.h
input.o: ansi_stdlib.h
input.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
input.o: readline.h keymaps.h chardefs.h tilde.h rlstdc.h
input.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
isearch.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
isearch.o: readline.h keymaps.h chardefs.h tilde.h
isearch.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
isearch.o: ansi_stdlib.h history.h rlstdc.h
keymaps.o: emacs_keymap.c vi_keymap.c
keymaps.o: keymaps.h chardefs.h rlconf.h ansi_stdlib.h
keymaps.o: readline.h keymaps.h chardefs.h tilde.h
keymaps.o: keymaps.h rltypedefs.h chardefs.h rlconf.h ansi_stdlib.h
keymaps.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
keymaps.o: ${BUILD_DIR}/config.h rlstdc.h
kill.o: ansi_stdlib.h
kill.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
kill.o: readline.h keymaps.h chardefs.h tilde.h
kill.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
kill.o: history.h rlstdc.h
macro.o: ansi_stdlib.h
macro.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
macro.o: readline.h keymaps.h chardefs.h tilde.h
macro.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
macro.o: history.h rlstdc.h
nls.o: ansi_stdlib.h
nls.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
nls.o: readline.h keymaps.h chardefs.h tilde.h
nls.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
nls.o: history.h rlstdc.h
parens.o: rlconf.h
parens.o: ${BUILD_DIR}/config.h
parens.o: readline.h keymaps.h chardefs.h tilde.h rlstdc.h
readline.o: readline.h keymaps.h chardefs.h tilde.h
parens.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
readline.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
readline.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
readline.o: history.h rlstdc.h
readline.o: posixstat.h ansi_stdlib.h posixjmp.h
rltty.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
rltty.o: rltty.h
rltty.o: readline.h keymaps.h chardefs.h tilde.h rlstdc.h
rltty.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
search.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
search.o: readline.h keymaps.h chardefs.h tilde.h
search.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
search.o: ansi_stdlib.h history.h rlstdc.h
shell.o: ${BUILD_DIR}/config.h ansi_stdlib.h
signals.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
signals.o: readline.h keymaps.h chardefs.h tilde.h
signals.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
signals.o: history.h rlstdc.h
terminal.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
terminal.o: tcap.h
terminal.o: readline.h keymaps.h chardefs.h tilde.h
terminal.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
terminal.o: history.h rlstdc.h
tilde.o: ansi_stdlib.h
tilde.o: ${BUILD_DIR}/config.h
tilde.o: tilde.h
undo.o: ansi_stdlib.h
undo.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
undo.o: readline.h keymaps.h chardefs.h tilde.h
undo.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
undo.o: history.h rlstdc.h
util.o: posixjmp.h ansi_stdlib.h
util.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
util.o: readline.h keymaps.h chardefs.h tilde.h rlstdc.h
util.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
vi_mode.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
vi_mode.o: readline.h keymaps.h chardefs.h tilde.h
vi_mode.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
vi_mode.o: history.h ansi_stdlib.h rlstdc.h
xmalloc.o: ${BUILD_DIR}/config.h ansi_stdlib.h
@ -284,6 +288,7 @@ vi_mode.o: xmalloc.h
# Rules for deficient makes, like SunOS and Solaris
bind.o: bind.c
callback.o: callback.c
compat.o: compat.c
complete.o: complete.c
display.o: display.c
funmap.o: funmap.c

View file

@ -27,6 +27,9 @@
extern int atoi ();
extern long int atol ();
extern double atof ();
extern double strtod ();
/* Memory allocation functions. */
extern char *malloc ();
extern char *realloc ();

View file

@ -68,9 +68,9 @@ extern char *strchr (), *strrchr ();
/* Variables exported by this file. */
Keymap rl_binding_keymap;
static int _rl_read_init_file __P((char *, int));
static int _rl_read_init_file __P((const char *, int));
static int glean_key_from_name __P((char *));
static int substring_member_of_array __P((char *, char **));
static int substring_member_of_array __P((char *, const char **));
static int currently_reading_init_file;
@ -83,13 +83,13 @@ static int _rl_prefer_visible_bell = 1;
/* */
/* **************************************************************** */
/* rl_add_defun (char *name, Function *function, int key)
/* rl_add_defun (char *name, rl_command_func_t *function, int key)
Add NAME to the list of named functions. Make FUNCTION be the function
that gets called. If KEY is not -1, then bind it. */
int
rl_add_defun (name, function, key)
char *name;
Function *function;
const char *name;
rl_command_func_t *function;
int key;
{
if (key != -1)
@ -102,7 +102,7 @@ rl_add_defun (name, function, key)
int
rl_bind_key (key, function)
int key;
Function *function;
rl_command_func_t *function;
{
if (key < 0)
return (key);
@ -133,7 +133,7 @@ rl_bind_key (key, function)
int
rl_bind_key_in_map (key, function, map)
int key;
Function *function;
rl_command_func_t *function;
Keymap map;
{
int result;
@ -152,7 +152,7 @@ int
rl_unbind_key (key)
int key;
{
return (rl_bind_key (key, (Function *)NULL));
return (rl_bind_key (key, (rl_command_func_t *)NULL));
}
/* Make KEY do nothing in MAP.
@ -162,13 +162,13 @@ rl_unbind_key_in_map (key, map)
int key;
Keymap map;
{
return (rl_bind_key_in_map (key, (Function *)NULL, map));
return (rl_bind_key_in_map (key, (rl_command_func_t *)NULL, map));
}
/* Unbind all keys bound to FUNCTION in MAP. */
int
rl_unbind_function_in_map (func, map)
Function *func;
rl_command_func_t *func;
Keymap map;
{
register int i, rval;
@ -177,7 +177,7 @@ rl_unbind_function_in_map (func, map)
{
if (map[i].type == ISFUNC && map[i].function == func)
{
map[i].function = (Function *)NULL;
map[i].function = (rl_command_func_t *)NULL;
rval = 1;
}
}
@ -186,10 +186,10 @@ rl_unbind_function_in_map (func, map)
int
rl_unbind_command_in_map (command, map)
char *command;
const char *command;
Keymap map;
{
Function *func;
rl_command_func_t *func;
func = rl_named_function (command);
if (func == 0)
@ -202,8 +202,8 @@ rl_unbind_command_in_map (command, map)
place to do bindings is in MAP. */
int
rl_set_key (keyseq, function, map)
char *keyseq;
Function *function;
const char *keyseq;
rl_command_func_t *function;
Keymap map;
{
return (rl_generic_bind (ISFUNC, keyseq, (char *)function, map));
@ -214,7 +214,7 @@ rl_set_key (keyseq, function, map)
necessary. The initial place to do bindings is in MAP. */
int
rl_macro_bind (keyseq, macro, map)
char *keyseq, *macro;
const char *keyseq, *macro;
Keymap map;
{
char *macro_keys;
@ -239,7 +239,8 @@ rl_macro_bind (keyseq, macro, map)
int
rl_generic_bind (type, keyseq, data, map)
int type;
char *keyseq, *data;
const char *keyseq;
char *data;
Keymap map;
{
char *keys;
@ -309,7 +310,8 @@ rl_generic_bind (type, keyseq, data, map)
non-zero if there was an error parsing SEQ. */
int
rl_translate_keyseq (seq, array, len)
char *seq, *array;
const char *seq;
char *array;
int *len;
{
register int i, c, l, temp;
@ -513,9 +515,9 @@ _rl_untranslate_macro_value (seq)
/* Return a pointer to the function that STRING represents.
If STRING doesn't have a matching function, then a NULL pointer
is returned. */
Function *
rl_command_func_t *
rl_named_function (string)
char *string;
const char *string;
{
register int i;
@ -524,7 +526,7 @@ rl_named_function (string)
for (i = 0; funmap[i]; i++)
if (_rl_stricmp (funmap[i]->name, string) == 0)
return (funmap[i]->function);
return ((Function *)NULL);
return ((rl_command_func_t *)NULL);
}
/* Return the function (or macro) definition which would be invoked via
@ -532,9 +534,9 @@ rl_named_function (string)
used. TYPE, if non-NULL, is a pointer to an int which will receive the
type of the object pointed to. One of ISFUNC (function), ISKMAP (keymap),
or ISMACR (macro). */
Function *
rl_command_func_t *
rl_function_of_keyseq (keyseq, map, type)
char *keyseq;
const char *keyseq;
Keymap map;
int *type;
{
@ -585,14 +587,14 @@ rl_function_of_keyseq (keyseq, map, type)
return (map[ic].function);
}
}
return ((Function *) NULL);
return ((rl_command_func_t *) NULL);
}
/* The last key bindings file read. */
static char *last_readline_init_file = (char *)NULL;
/* The file we're currently reading key bindings from. */
static char *current_readline_init_file;
static const char *current_readline_init_file;
static int current_readline_init_include_level;
static int current_readline_init_lineno;
@ -659,7 +661,7 @@ rl_re_read_init_file (count, ignore)
int count, ignore;
{
int r;
r = rl_read_init_file ((char *)NULL);
r = rl_read_init_file ((const char *)NULL);
rl_set_keymap_from_edit_mode ();
return r;
}
@ -673,14 +675,14 @@ rl_re_read_init_file (count, ignore)
otherwise errno is returned. */
int
rl_read_init_file (filename)
char *filename;
const char *filename;
{
/* Default the filename. */
if (filename == 0)
{
filename = last_readline_init_file;
if (filename == 0)
filename = get_env_value ("INPUTRC");
filename = sh_get_env_value ("INPUTRC");
if (filename == 0)
filename = DEFAULT_INPUTRC;
}
@ -698,7 +700,7 @@ rl_read_init_file (filename)
static int
_rl_read_init_file (filename, include_level)
char *filename;
const char *filename;
int include_level;
{
register int i;
@ -733,7 +735,7 @@ _rl_read_init_file (filename, include_level)
/* Find the end of this line. */
for (i = 0; line + i != end && line[i] != '\n'; i++);
#if defined (__CYGWIN32__)
#if defined (__CYGWIN__)
/* ``Be liberal in what you accept.'' */
if (line[i] == '\n' && line[i-1] == '\r')
line[i - 1] = '\0';
@ -780,10 +782,21 @@ _rl_init_file_error (msg)
/* */
/* **************************************************************** */
typedef int _rl_parser_func_t __P((char *));
/* Things that mean `Control'. */
const char *_rl_possible_control_prefixes[] = {
"Control-", "C-", "CTRL-", (const char *)NULL
};
const char *_rl_possible_meta_prefixes[] = {
"Meta", "M-", (const char *)NULL
};
/* Conditionals. */
/* Calling programs set this to have their argv[0]. */
char *rl_readline_name = "other";
const char *rl_readline_name = "other";
/* Stack of previous values of parsing_conditionalized_out. */
static unsigned char *if_stack = (unsigned char *)NULL;
@ -905,7 +918,8 @@ static int
parser_include (args)
char *args;
{
char *old_init_file, *e;
const char *old_init_file;
char *e;
int old_line_number, old_include_level, r;
if (_rl_parsing_conditionalized_out)
@ -918,7 +932,7 @@ parser_include (args)
e = strchr (args, '\n');
if (e)
*e = '\0';
r = _rl_read_init_file (args, old_include_level + 1);
r = _rl_read_init_file ((const char *)args, old_include_level + 1);
current_readline_init_file = old_init_file;
current_readline_init_lineno = old_line_number;
@ -929,14 +943,14 @@ parser_include (args)
/* Associate textual names with actual functions. */
static struct {
char *name;
Function *function;
const char *name;
_rl_parser_func_t *function;
} parser_directives [] = {
{ "if", parser_if },
{ "endif", parser_endif },
{ "else", parser_else },
{ "include", parser_include },
{ (char *)0x0, (Function *)0x0 }
{ (char *)0x0, (_rl_parser_func_t *)0x0 }
};
/* Handle a parser directive. STATEMENT is the line of the directive
@ -1180,10 +1194,10 @@ rl_parse_and_bind (string)
key = glean_key_from_name (kname);
/* Add in control and meta bits. */
if (substring_member_of_array (string, possible_control_prefixes))
if (substring_member_of_array (string, _rl_possible_control_prefixes))
key = CTRL (_rl_to_upper (key));
if (substring_member_of_array (string, possible_meta_prefixes))
if (substring_member_of_array (string, _rl_possible_meta_prefixes))
key = META (key);
/* Temporary. Handle old-style keyname with macro-binding. */
@ -1221,7 +1235,7 @@ rl_parse_and_bind (string)
#define V_SPECIAL 0x1
static struct {
char *name;
const char *name;
int *value;
int flags;
} boolean_varlist [] = {
@ -1265,7 +1279,7 @@ static void
hack_special_boolean_var (i)
int i;
{
char *name;
const char *name;
name = boolean_varlist[i].name;
@ -1280,6 +1294,8 @@ hack_special_boolean_var (i)
}
}
typedef int _rl_sv_func_t __P((const char *));
/* These *must* correspond to the array indices for the appropriate
string variable. (Though they're not used right now.) */
#define V_BELLSTYLE 0
@ -1292,17 +1308,17 @@ hack_special_boolean_var (i)
#define V_INT 2
/* Forward declarations */
static int sv_bell_style __P((char *));
static int sv_combegin __P((char *));
static int sv_compquery __P((char *));
static int sv_editmode __P((char *));
static int sv_isrchterm __P((char *));
static int sv_keymap __P((char *));
static int sv_bell_style __P((const char *));
static int sv_combegin __P((const char *));
static int sv_compquery __P((const char *));
static int sv_editmode __P((const char *));
static int sv_isrchterm __P((const char *));
static int sv_keymap __P((const char *));
static struct {
char *name;
const char *name;
int flags;
Function *set_func;
_rl_sv_func_t *set_func;
} string_varlist[] = {
{ "bell-style", V_STRING, sv_bell_style },
{ "comment-begin", V_STRING, sv_combegin },
@ -1339,7 +1355,7 @@ bool_to_int (value)
int
rl_variable_bind (name, value)
char *name, *value;
const char *name, *value;
{
register int i;
int v;
@ -1367,7 +1383,7 @@ rl_variable_bind (name, value)
static int
sv_editmode (value)
char *value;
const char *value;
{
if (_rl_strnicmp (value, "vi", 2) == 0)
{
@ -1388,7 +1404,7 @@ sv_editmode (value)
static int
sv_combegin (value)
char *value;
const char *value;
{
if (value && *value)
{
@ -1401,7 +1417,7 @@ sv_combegin (value)
static int
sv_compquery (value)
char *value;
const char *value;
{
int nval = 100;
@ -1417,7 +1433,7 @@ sv_compquery (value)
static int
sv_keymap (value)
char *value;
const char *value;
{
Keymap kmap;
@ -1434,7 +1450,7 @@ sv_keymap (value)
static int
sv_bell_style (value)
char *value;
const char *value;
{
if (value == 0 || *value == '\0')
_SET_BELL (AUDIBLE_BELL);
@ -1451,7 +1467,7 @@ sv_bell_style (value)
static int
sv_isrchterm (value)
char *value;
const char *value;
{
int beg, end, delim;
char *v;
@ -1489,7 +1505,7 @@ sv_isrchterm (value)
For example, `Space' returns ' '. */
typedef struct {
char *name;
const char *name;
int value;
} assoc_list;
@ -1523,7 +1539,7 @@ glean_key_from_name (name)
/* Auxiliary functions to manage keymaps. */
static struct {
char *name;
const char *name;
Keymap map;
} keymap_names[] = {
{ "emacs", emacs_standard_keymap },
@ -1541,12 +1557,12 @@ static struct {
Keymap
rl_get_keymap_by_name (name)
char *name;
const char *name;
{
register int i;
for (i = 0; keymap_names[i].name; i++)
if (strcmp (name, keymap_names[i].name) == 0)
if (_rl_stricmp (name, keymap_names[i].name) == 0)
return (keymap_names[i].map);
return ((Keymap) NULL);
}
@ -1558,7 +1574,7 @@ rl_get_keymap_name (map)
register int i;
for (i = 0; keymap_names[i].name; i++)
if (map == keymap_names[i].map)
return (keymap_names[i].name);
return ((char *)keymap_names[i].name);
return ((char *)NULL);
}
@ -1616,7 +1632,7 @@ void
rl_list_funmap_names ()
{
register int i;
char **funmap_names;
const char **funmap_names;
funmap_names = rl_funmap_names ();
@ -1706,7 +1722,7 @@ _rl_get_keyname (key)
sequences that are used to invoke FUNCTION in MAP. */
char **
rl_invoking_keyseqs_in_map (function, map)
Function *function;
rl_command_func_t *function;
Keymap map;
{
register int key;
@ -1806,7 +1822,7 @@ rl_invoking_keyseqs_in_map (function, map)
sequences that can be used to invoke FUNCTION using the current keymap. */
char **
rl_invoking_keyseqs (function)
Function *function;
rl_command_func_t *function;
{
return (rl_invoking_keyseqs_in_map (function, _rl_keymap));
}
@ -1819,8 +1835,8 @@ rl_function_dumper (print_readably)
int print_readably;
{
register int i;
char **names;
char *name;
const char **names;
const char *name;
names = rl_funmap_names ();
@ -1828,7 +1844,7 @@ rl_function_dumper (print_readably)
for (i = 0; name = names[i]; i++)
{
Function *function;
rl_command_func_t *function;
char **invokers;
function = rl_named_function (name);
@ -1985,7 +2001,7 @@ rl_variable_dumper (print_readably)
int print_readably;
{
int i;
char *kname;
const char *kname;
for (i = 0; boolean_varlist[i].name; i++)
{
@ -2073,10 +2089,10 @@ rl_dump_variables (count, key)
/* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. */
void
_rl_bind_if_unbound (keyseq, default_func)
char *keyseq;
Function *default_func;
const char *keyseq;
rl_command_func_t *default_func;
{
Function *func;
rl_command_func_t *func;
if (keyseq)
{
@ -2089,7 +2105,8 @@ _rl_bind_if_unbound (keyseq, default_func)
/* Return non-zero if any members of ARRAY are a substring in STRING. */
static int
substring_member_of_array (string, array)
char *string, **array;
char *string;
const char **array;
{
while (*array)
{

View file

@ -52,7 +52,7 @@
text read in at each end of line. The terminal is kept prepped and
signals handled all the time, except during calls to the user's function. */
VFunction *rl_linefunc; /* user callback function */
rl_vcpfunc_t *rl_linefunc; /* user callback function */
static int in_handler; /* terminal_prepped and signals set? */
/* Make sure the terminal is set up, initialize readline, and prompt. */
@ -78,11 +78,10 @@ _rl_callback_newline ()
/* Install a readline handler, set up the terminal, and issue the prompt. */
void
rl_callback_handler_install (prompt, linefunc)
char *prompt;
VFunction *linefunc;
const char *prompt;
rl_vcpfunc_t *linefunc;
{
rl_prompt = prompt;
rl_visible_prompt_length = rl_prompt ? rl_expand_prompt (rl_prompt) : 0;
rl_set_prompt (prompt);
rl_linefunc = linefunc;
_rl_callback_newline ();
}
@ -102,24 +101,33 @@ rl_callback_read_char ()
eof = readline_internal_char ();
if (rl_done)
/* We loop in case some function has pushed input back with rl_execute_next. */
for (;;)
{
line = readline_internal_teardown (eof);
if (rl_done)
{
line = readline_internal_teardown (eof);
(*rl_deprep_term_function) ();
(*rl_deprep_term_function) ();
#if defined (HANDLE_SIGNALS)
rl_clear_signals ();
rl_clear_signals ();
#endif
in_handler = 0;
(*rl_linefunc) (line);
in_handler = 0;
(*rl_linefunc) (line);
/* If the user did not clear out the line, do it for him. */
if (rl_line_buffer[0])
_rl_init_line_state ();
/* If the user did not clear out the line, do it for him. */
if (rl_line_buffer[0])
_rl_init_line_state ();
/* Redisplay the prompt if readline_handler_{install,remove} not called. */
if (in_handler == 0 && rl_linefunc)
_rl_callback_newline ();
/* Redisplay the prompt if readline_handler_{install,remove}
not called. */
if (in_handler == 0 && rl_linefunc)
_rl_callback_newline ();
}
if (rl_pending_input)
eof = readline_internal_char ();
else
break;
}
}

View file

@ -51,7 +51,7 @@
#define meta_character_bit 0x080 /* x0000000, must be on. */
#define largest_char 255 /* Largest character value. */
#define CTRL_CHAR(c) ((c) < control_character_threshold && (c) >= 0)
#define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0))
#define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
#define CTRL(c) ((c) & control_character_mask)

113
lib/readline/compat.c Normal file
View file

@ -0,0 +1,113 @@
/* compat.c -- backwards compatibility functions. */
/* Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
The GNU Readline Library 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 2, or
(at your option) any later version.
The GNU Readline Library 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.
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#define READLINE_LIBRARY
#if defined (HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdio.h>
#include "rlstdc.h"
#include "rltypedefs.h"
extern void rl_free_undo_list __P((void));
extern int rl_maybe_save_line __P((void));
extern int rl_maybe_unsave_line __P((void));
extern int rl_maybe_replace_line __P((void));
extern int rl_crlf __P((void));
extern int rl_ding __P((void));
extern int rl_alphabetic __P((int));
extern char **rl_completion_matches __P((const char *, rl_compentry_func_t *));
extern char *rl_username_completion_function __P((const char *, int));
extern char *rl_filename_completion_function __P((const char *, int));
/* Provide backwards-compatible entry points for old function names. */
void
free_undo_list ()
{
rl_free_undo_list ();
}
int
maybe_replace_line ()
{
return rl_maybe_replace_line ();
}
int
maybe_save_line ()
{
return rl_maybe_save_line ();
}
int
maybe_unsave_line ()
{
return rl_maybe_unsave_line ();
}
int
ding ()
{
return rl_ding ();
}
int
crlf ()
{
return rl_crlf ();
}
int
alphabetic (c)
int c;
{
return rl_alphabetic (c);
}
char **
completion_matches (s, f)
const char *s;
rl_compentry_func_t *f;
{
return rl_completion_matches (s, f);
}
char *
username_completion_function (s, i)
const char *s;
int i;
{
return rl_username_completion_function (s, i);
}
char *
filename_completion_function (s, i)
const char *s;
int i;
{
return rl_filename_completion_function (s, i);
}

View file

@ -49,18 +49,6 @@ extern int errno;
#endif /* !errno */
#include <pwd.h>
#if !defined (HAVE_GETPW_DECLS)
extern struct passwd *getpwent ();
#endif /* USG && !HAVE_GETPW_DECLS */
/* ISC systems don't define getpwent() if _POSIX_SOURCE is defined. */
#if defined (isc386) && defined (_POSIX_SOURCE)
# if defined (__STDC__)
extern struct passwd *getpwent (void);
# else
extern struct passwd *getpwent ();
# endif /* !__STDC__ */
#endif /* isc386 && _POSIX_SOURCE */
#include "posixdir.h"
#include "posixstat.h"
@ -79,6 +67,12 @@ typedef int QSFUNC (const void *, const void *);
typedef int QSFUNC ();
#endif
/* Most systems don't declare getpwent in <pwd.h> if _POSIX_SOURCE is
defined. */
#if !defined (HAVE_GETPW_DECLS) || defined (_POSIX_SOURCE)
extern struct passwd *getpwent __P((void));
#endif /* !HAVE_GETPW_DECLS || _POSIX_SOURCE */
/* If non-zero, then this is the address of a function to call when
completing a word would normally display the list of possible matches.
This function is called instead of actually doing the display.
@ -86,11 +80,7 @@ typedef int QSFUNC ();
where MATCHES is the array of strings that matched, NUM_MATCHES is the
number of strings in that array, and MAX_LENGTH is the length of the
longest string in that array. */
VFunction *rl_completion_display_matches_hook = (VFunction *)NULL;
/* Forward declarations for functions defined and used in this file. */
char *filename_completion_function __P((char *, int));
char **completion_matches __P((char *, CPFunction *));
rl_compdisp_func_t *rl_completion_display_matches_hook = (rl_compdisp_func_t *)NULL;
#if defined (VISIBLE_STATS)
# if !defined (X_OK)
@ -100,14 +90,13 @@ static int stat_char __P((char *));
#endif
static char *rl_quote_filename __P((char *, int, char *));
static char *rl_strpbrk __P((char *, char *));
static char **remove_duplicate_matches __P((char **));
static void insert_match __P((char *, int, int, char *));
static int append_to_match __P((char *, int, int));
static void insert_all_matches __P((char **, int, char *));
static void display_matches __P((char **));
static int compute_lcd_of_matches __P((char **, int, char *));
static int compute_lcd_of_matches __P((char **, int, const char *));
/* **************************************************************** */
/* */
@ -146,15 +135,17 @@ int rl_visible_stats = 0;
/* If non-zero, then this is the address of a function to call when
completing on a directory name. The function is called with
the address of a string (the current directory name) as an arg. */
Function *rl_directory_completion_hook = (Function *)NULL;
rl_icppfunc_t *rl_directory_completion_hook = (rl_icppfunc_t *)NULL;
rl_icppfunc_t *rl_directory_rewrite_hook = (rl_icppfunc_t *)NULL;
/* Non-zero means readline completion functions perform tilde expansion. */
int rl_complete_with_tilde_expansion = 0;
/* Pointer to the generator function for completion_matches ().
NULL means to use filename_completion_function (), the default filename
NULL means to use rl_filename_completion_function (), the default filename
completer. */
Function *rl_completion_entry_function = (Function *)NULL;
rl_compentry_func_t *rl_completion_entry_function = (rl_compentry_func_t *)NULL;
/* Pointer to alternative function to create matches.
Function is called with TEXT, START, and END.
@ -163,7 +154,7 @@ Function *rl_completion_entry_function = (Function *)NULL;
If this function exists and returns NULL then call the value of
rl_completion_entry_function to try to match, otherwise use the
array of strings returned. */
CPPFunction *rl_attempted_completion_function = (CPPFunction *)NULL;
rl_completion_func_t *rl_attempted_completion_function = (rl_completion_func_t *)NULL;
/* Non-zero means to suppress normal filename completion after the
user-specified completion function has been called. */
@ -182,29 +173,29 @@ int rl_completion_query_items = 100;
/* The basic list of characters that signal a break between words for the
completer routine. The contents of this variable is what breaks words
in the shell, i.e. " \t\n\"\\'`@$><=" */
char *rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&{(";
const char *rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&{(";
/* List of basic quoting characters. */
char *rl_basic_quote_characters = "\"'";
const char *rl_basic_quote_characters = "\"'";
/* The list of characters that signal a break between words for
rl_complete_internal. The default list is the contents of
rl_basic_word_break_characters. */
char *rl_completer_word_break_characters = (char *)NULL;
const char *rl_completer_word_break_characters = (const char *)NULL;
/* List of characters which can be used to quote a substring of the line.
Completion occurs on the entire substring, and within the substring
rl_completer_word_break_characters are treated as any other character,
unless they also appear within this list. */
char *rl_completer_quote_characters = (char *)NULL;
const char *rl_completer_quote_characters = (const char *)NULL;
/* List of characters that should be quoted in filenames by the completer. */
char *rl_filename_quote_characters = (char *)NULL;
const char *rl_filename_quote_characters = (const char *)NULL;
/* List of characters that are word break characters, but should be left
in TEXT when it is passed to the completion function. The shell uses
this to help determine what kind of completing to do. */
char *rl_special_prefixes = (char *)NULL;
const char *rl_special_prefixes = (const char *)NULL;
/* If non-zero, then disallow duplicates in the matches. */
int rl_ignore_completion_duplicates = 1;
@ -230,24 +221,24 @@ int rl_filename_quoting_desired = 1;
the list of matches as required, but all elements of the array must be
free()'d if they are deleted. The main intent of this function is
to implement FIGNORE a la SunOS csh. */
Function *rl_ignore_some_completions_function = (Function *)NULL;
rl_compignore_func_t *rl_ignore_some_completions_function = (rl_compignore_func_t *)NULL;
/* Set to a function to quote a filename in an application-specific fashion.
Called with the text to quote, the type of match found (single or multiple)
and a pointer to the quoting character to be used, which the function can
reset if desired. */
CPFunction *rl_filename_quoting_function = rl_quote_filename;
rl_quote_func_t *rl_filename_quoting_function = rl_quote_filename;
/* Function to call to remove quoting characters from a filename. Called
before completion is attempted, so the embedded quotes do not interfere
with matching names in the file system. Readline doesn't do anything
with this; it's set only by applications. */
CPFunction *rl_filename_dequoting_function = (CPFunction *)NULL;
rl_dequote_func_t *rl_filename_dequoting_function = (rl_dequote_func_t *)NULL;
/* Function to call to decide whether or not a word break character is
quoted. If a character is quoted, it does not break words for the
completer. */
Function *rl_char_is_quoted_p = (Function *)NULL;
rl_linebuf_func_t *rl_char_is_quoted_p = (rl_linebuf_func_t *)NULL;
/* Character appended to completed words when at the end of the line. The
default is a space. */
@ -269,7 +260,7 @@ static int completion_changed_buffer;
/* Complete the word at or before point. You have supplied the function
that does the initial simple matching selection algorithm (see
completion_matches ()). The default is to do filename completion. */
rl_completion_matches ()). The default is to do filename completion. */
int
rl_complete (ignore, invoking_key)
int ignore, invoking_key;
@ -305,27 +296,6 @@ rl_insert_completions (ignore, invoking_key)
/* */
/************************************/
/* Find the first occurrence in STRING1 of any character from STRING2.
Return a pointer to the character in STRING1. */
static char *
rl_strpbrk (string1, string2)
char *string1, *string2;
{
register char *scan;
for (; *string1; string1++)
{
for (scan = string2; *scan; scan++)
{
if (*string1 == *scan)
{
return (string1);
}
}
}
return ((char *)NULL);
}
/* The user must press "y" or "n". Non-zero return means "y" pressed. */
static int
get_y_or_n ()
@ -334,14 +304,17 @@ get_y_or_n ()
for (;;)
{
RL_SETSTATE(RL_STATE_MOREINPUT);
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
if (c == 'y' || c == 'Y' || c == ' ')
return (1);
if (c == 'n' || c == 'N' || c == RUBOUT)
return (0);
if (c == ABORT_CHAR)
_rl_abort_internal ();
ding ();
rl_ding ();
}
}
@ -571,7 +544,11 @@ find_completion_word (fp, dp)
continue;
}
if (rl_line_buffer[scan] == '\\')
/* Shell-like semantics for single quotes -- don't allow backslash
to quote anything in single quotes, especially not the closing
quote. If you don't like this, take out the check on the value
of quote_char. */
if (quote_char != '\'' && rl_line_buffer[scan] == '\\')
{
pass_next = 1;
found_quote |= RL_QF_BACKSLASH;
@ -671,7 +648,7 @@ static char **
gen_completion_matches (text, start, end, our_func, found_quote, quote_char)
char *text;
int start, end;
Function *our_func;
rl_compentry_func_t *our_func;
int found_quote, quote_char;
{
char **matches, *temp;
@ -695,7 +672,7 @@ gen_completion_matches (text, start, end, our_func, found_quote, quote_char)
filename dequoting function. */
temp = (char *)NULL;
if (found_quote && our_func == (Function *)filename_completion_function &&
if (found_quote && our_func == rl_filename_completion_function &&
rl_filename_dequoting_function)
{
/* delete single and double quotes */
@ -703,7 +680,7 @@ gen_completion_matches (text, start, end, our_func, found_quote, quote_char)
text = temp; /* not freeing text is not a memory leak */
}
matches = completion_matches (text, (CPFunction *)our_func);
matches = rl_completion_matches (text, our_func);
FREE (temp);
return matches;
}
@ -775,7 +752,7 @@ static int
compute_lcd_of_matches (match_list, matches, text)
char **match_list;
int matches;
char *text;
const char *text;
{
register int i, c1, c2, si;
int low; /* Count of max-matched characters. */
@ -901,11 +878,11 @@ rl_display_match_list (matches, len, max)
/* How many items of MAX length can we fit in the screen window? */
max += 2;
limit = screenwidth / max;
if (limit != 1 && (limit * max == screenwidth))
limit = _rl_screenwidth / max;
if (limit != 1 && (limit * max == _rl_screenwidth))
limit--;
/* Avoid a possible floating exception. If max > screenwidth,
/* Avoid a possible floating exception. If max > _rl_screenwidth,
limit will be 0 and a divide-by-zero fault will result. */
if (limit == 0)
limit = 1;
@ -921,7 +898,7 @@ rl_display_match_list (matches, len, max)
if (rl_ignore_completion_duplicates == 0)
qsort (matches + 1, len, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
crlf ();
rl_crlf ();
if (_rl_print_completions_horizontally == 0)
{
@ -943,7 +920,7 @@ rl_display_match_list (matches, len, max)
}
l += count;
}
crlf ();
rl_crlf ();
}
}
else
@ -957,13 +934,13 @@ rl_display_match_list (matches, len, max)
if (matches[i+1])
{
if (i && (limit > 1) && (i % limit) == 0)
crlf ();
rl_crlf ();
else
for (k = 0; k < max - printed_len; k++)
putc (' ', rl_outstream);
}
}
crlf ();
rl_crlf ();
}
}
@ -992,9 +969,9 @@ display_matches (matches)
if (matches[1] == 0)
{
temp = printable_part (matches[0]);
crlf ();
rl_crlf ();
print_filename (temp, matches[0]);
crlf ();
rl_crlf ();
rl_forced_update_display ();
rl_display_fixed = 1;
@ -1026,12 +1003,12 @@ display_matches (matches)
see them all. */
if (len >= rl_completion_query_items)
{
crlf ();
rl_crlf ();
fprintf (rl_outstream, "Display all %d possibilities? (y or n)", len);
fflush (rl_outstream);
if (get_y_or_n () == 0)
{
crlf ();
rl_crlf ();
rl_forced_update_display ();
rl_display_fixed = 1;
@ -1079,7 +1056,7 @@ make_quoted_replacement (match, mtype, qc)
This also checks whether the common prefix of several
matches needs to be quoted. */
should_quote = rl_filename_quote_characters
? (rl_strpbrk (match, rl_filename_quote_characters) != 0)
? (_rl_strpbrk (match, rl_filename_quote_characters) != 0)
: 0;
do_replace = should_quote ? mtype : NO_MATCH;
@ -1232,11 +1209,12 @@ rl_complete_internal (what_to_do)
int what_to_do;
{
char **matches;
Function *our_func;
rl_compentry_func_t *our_func;
int start, end, delimiter, found_quote, i;
char *text, *saved_line_buffer;
char quote_char;
RL_SETSTATE(RL_STATE_COMPLETING);
/* Only the completion entry function can change these. */
rl_filename_completion_desired = 0;
rl_filename_quoting_desired = 1;
@ -1245,7 +1223,7 @@ rl_complete_internal (what_to_do)
saved_line_buffer = rl_line_buffer ? savestring (rl_line_buffer) : (char *)NULL;
our_func = rl_completion_entry_function
? rl_completion_entry_function
: (Function *)filename_completion_function;
: rl_filename_completion_function;
/* We now look backwards for the start of a filename/variable word. */
end = rl_point;
@ -1266,27 +1244,23 @@ rl_complete_internal (what_to_do)
if (matches == 0)
{
ding ();
rl_ding ();
FREE (saved_line_buffer);
RL_UNSETSTATE(RL_STATE_COMPLETING);
return (0);
}
#if 0
/* If we are matching filenames, our_func will have been set to
filename_completion_function */
i = our_func == (Function *)filename_completion_function;
#else
/* If we are matching filenames, the attempted completion function will
have set rl_filename_completion_desired to a non-zero value. The basic
filename_completion_function does this. */
rl_filename_completion_function does this. */
i = rl_filename_completion_desired;
#endif
if (postprocess_matches (&matches, i) == 0)
{
ding ();
rl_ding ();
FREE (saved_line_buffer);
completion_changed_buffer = 0;
RL_UNSETSTATE(RL_STATE_COMPLETING);
return (0);
}
@ -1314,7 +1288,7 @@ rl_complete_internal (what_to_do)
break;
}
else if (rl_editing_mode != vi_mode)
ding (); /* There are other matches remaining. */
rl_ding (); /* There are other matches remaining. */
}
else
append_to_match (matches[0], delimiter, quote_char);
@ -1331,8 +1305,9 @@ rl_complete_internal (what_to_do)
default:
fprintf (stderr, "\r\nreadline: bad value %d for what_to_do in rl_complete\n", what_to_do);
ding ();
rl_ding ();
FREE (saved_line_buffer);
RL_UNSETSTATE(RL_STATE_COMPLETING);
return 1;
}
@ -1345,6 +1320,7 @@ rl_complete_internal (what_to_do)
free (saved_line_buffer);
}
RL_UNSETSTATE(RL_STATE_COMPLETING);
return 0;
}
@ -1367,9 +1343,9 @@ rl_complete_internal (what_to_do)
when there are no more matches.
*/
char **
completion_matches (text, entry_function)
char *text;
CPFunction *entry_function;
rl_completion_matches (text, entry_function)
const char *text;
rl_compentry_func_t *entry_function;
{
/* Number of slots in match_list. */
int match_list_size;
@ -1414,8 +1390,8 @@ completion_matches (text, entry_function)
TEXT contains a partial username preceded by a random
character (usually `~'). */
char *
username_completion_function (text, state)
char *text;
rl_username_completion_function (text, state)
const char *text;
int state;
{
#if defined (__WIN32__) || defined (__OPENNT)
@ -1471,8 +1447,8 @@ username_completion_function (text, state)
because of all the pathnames that must be followed when looking up the
completion for a command. */
char *
filename_completion_function (text, state)
char *text;
rl_filename_completion_function (text, state)
const char *text;
int state;
{
static DIR *directory = (DIR *)NULL;
@ -1542,6 +1518,9 @@ filename_completion_function (text, state)
dirname = temp;
}
if (rl_directory_rewrite_hook)
(*rl_directory_rewrite_hook) (&dirname);
if (rl_directory_completion_hook && (*rl_directory_completion_hook) (&dirname))
{
free (users_dirname);
@ -1641,8 +1620,11 @@ filename_completion_function (text, state)
else
{
dirlen = strlen (users_dirname);
temp = xmalloc (1 + dirlen + D_NAMLEN (entry));
temp = xmalloc (2 + dirlen + D_NAMLEN (entry));
strcpy (temp, users_dirname);
/* Make sure that temp has a trailing slash here. */
if (users_dirname[dirlen - 1] != '/')
temp[dirlen++] = '/';
}
strcpy (temp + dirlen, entry->d_name);
@ -1667,7 +1649,7 @@ int
rl_menu_complete (count, ignore)
int count, ignore;
{
Function *our_func;
rl_compentry_func_t *our_func;
int matching_filenames, found_quote;
static char *orig_text;
@ -1697,7 +1679,7 @@ rl_menu_complete (count, ignore)
our_func = rl_completion_entry_function
? rl_completion_entry_function
: (Function *)filename_completion_function;
: rl_filename_completion_function;
/* We now look backwards for the start of a filename/variable word. */
orig_end = rl_point;
@ -1716,19 +1698,14 @@ rl_menu_complete (count, ignore)
matches = gen_completion_matches (orig_text, orig_start, orig_end,
our_func, found_quote, quote_char);
#if 0
/* If we are matching filenames, our_func will have been set to
filename_completion_function */
matching_filenames = our_func == (Function *)filename_completion_function;
#else
/* If we are matching filenames, the attempted completion function will
have set rl_filename_completion_desired to a non-zero value. The basic
filename_completion_function does this. */
rl_filename_completion_function does this. */
matching_filenames = rl_filename_completion_desired;
#endif
if (matches == 0 || postprocess_matches (&matches, matching_filenames) == 0)
{
ding ();
rl_ding ();
FREE (matches);
matches = (char **)0;
FREE (orig_text);
@ -1749,7 +1726,7 @@ rl_menu_complete (count, ignore)
if (matches == 0 || match_list_size == 0)
{
ding ();
rl_ding ();
FREE (matches);
matches = (char **)0;
completion_changed_buffer = 0;
@ -1762,7 +1739,7 @@ rl_menu_complete (count, ignore)
if (match_list_index == 0 && match_list_size > 1)
{
ding ();
rl_ding ();
insert_match (orig_text, orig_start, MULT_MATCH, &quote_char);
}
else

View file

@ -59,7 +59,7 @@ extern char *strchr (), *strrchr ();
#endif /* !strchr && !__STDC__ */
#if defined (HACK_TERMCAP_MOTION)
extern char *term_forward_char;
extern char *_rl_term_forward_char;
#endif
static void update_line __P((char *, char *, int, int, int, int));
@ -103,7 +103,7 @@ static int inv_lbsize, vis_lbsize;
RL_DISPLAY_FIXED variable. This is good for efficiency. */
/* Application-specific redisplay function. */
VFunction *rl_redisplay_function = rl_redisplay;
rl_voidfunc_t *rl_redisplay_function = rl_redisplay;
/* Global variables declared here. */
/* What YOU turn on when you have handled all redisplay yourself. */
@ -142,27 +142,40 @@ static int forced_display;
/* Default and initial buffer size. Can grow. */
static int line_size = 1024;
/* Variables to keep track of the expanded prompt string, which may
include invisible characters. */
static char *local_prompt, *local_prompt_prefix;
static int visible_length, prefix_length;
static int prompt_visible_length, prompt_prefix_length;
/* The number of invisible characters in the line currently being
displayed on the screen. */
static int visible_wrap_offset;
/* static so it can be shared between rl_redisplay and update_line */
/* The number of invisible characters in the prompt string. Static so it
can be shared between rl_redisplay and update_line */
static int wrap_offset;
/* The index of the last invisible_character in the prompt string. */
static int last_invisible;
/* The index of the last invisible character in the prompt string. */
static int prompt_last_invisible;
/* The length (buffer offset) of the first line of the last (possibly
multi-line) buffer displayed on the screen. */
static int visible_first_line_len;
/* Number of invisible characters on the first physical line of the prompt.
Only valid when the number of physical characters in the prompt exceeds
(or is equal to) _rl_screenwidth. */
static int prompt_invis_chars_first_line;
static int prompt_last_screen_line;
/* Expand the prompt string S and return the number of visible
characters in *LP, if LP is not null. This is currently more-or-less
a placeholder for expansion. LIP, if non-null is a place to store the
index of the last invisible character in the returned string. */
index of the last invisible character in the returned string. NIFLP,
if non-zero, is a place to store the number of invisible characters in
the first prompt line. */
/* Current implementation:
\001 (^A) start non-visible characters
@ -172,12 +185,12 @@ static int visible_first_line_len;
\002 are assumed to be `visible'. */
static char *
expand_prompt (pmt, lp, lip)
expand_prompt (pmt, lp, lip, niflp)
char *pmt;
int *lp, *lip;
int *lp, *lip, *niflp;
{
char *r, *ret, *p;
int l, rl, last, ignoring;
int l, rl, last, ignoring, ninvis, invfl;
/* Short-circuit if we can. */
if (strchr (pmt, RL_PROMPT_START_IGNORE) == 0)
@ -190,8 +203,10 @@ expand_prompt (pmt, lp, lip)
l = strlen (pmt);
r = ret = xmalloc (l + 1);
for (rl = ignoring = last = 0, p = pmt; p && *p; p++)
invfl = 0; /* invisible chars in first line of prompt */
for (rl = ignoring = last = ninvis = 0, p = pmt; p && *p; p++)
{
/* This code strips the invisible character string markers
RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE */
@ -211,14 +226,23 @@ expand_prompt (pmt, lp, lip)
*r++ = *p;
if (!ignoring)
rl++;
else
ninvis++;
if (rl == _rl_screenwidth)
invfl = ninvis;
}
}
if (rl < _rl_screenwidth)
invfl = ninvis;
*r = '\0';
if (lp)
*lp = rl;
if (lip)
*lip = last;
if (niflp)
*niflp = invfl;
return ret;
}
@ -230,7 +254,7 @@ _rl_strip_prompt (pmt)
{
char *ret;
ret = expand_prompt (pmt, (int *)NULL, (int *)NULL);
ret = expand_prompt (pmt, (int *)NULL, (int *)NULL, (int *)NULL);
return ret;
}
@ -242,8 +266,8 @@ _rl_strip_prompt (pmt)
* (portion after the final newline)
* local_prompt_prefix = portion before last newline of rl_display_prompt,
* expanded via expand_prompt
* visible_length = number of visible characters in local_prompt
* prefix_length = number of visible characters in local_prompt_prefix
* prompt_visible_length = number of visible characters in local_prompt
* prompt_prefix_length = number of visible characters in local_prompt_prefix
*
* This function is called once per call to readline(). It may also be
* called arbitrarily to expand the primary prompt.
@ -259,12 +283,11 @@ rl_expand_prompt (prompt)
int c;
/* Clear out any saved values. */
if (local_prompt)
free (local_prompt);
if (local_prompt_prefix)
free (local_prompt_prefix);
FREE (local_prompt);
FREE (local_prompt_prefix);
local_prompt = local_prompt_prefix = (char *)0;
last_invisible = visible_length = 0;
prompt_last_invisible = prompt_visible_length = 0;
if (prompt == 0 || *prompt == 0)
return (0);
@ -272,22 +295,28 @@ rl_expand_prompt (prompt)
p = strrchr (prompt, '\n');
if (!p)
{
/* The prompt is only one line. */
local_prompt = expand_prompt (prompt, &visible_length, &last_invisible);
/* The prompt is only one logical line, though it might wrap. */
local_prompt = expand_prompt (prompt, &prompt_visible_length,
&prompt_last_invisible,
&prompt_invis_chars_first_line);
local_prompt_prefix = (char *)0;
return (visible_length);
return (prompt_visible_length);
}
else
{
/* The prompt spans multiple lines. */
t = ++p;
local_prompt = expand_prompt (p, &visible_length, &last_invisible);
local_prompt = expand_prompt (p, &prompt_visible_length,
&prompt_last_invisible,
&prompt_invis_chars_first_line);
c = *t; *t = '\0';
/* The portion of the prompt string up to and including the
final newline is now null-terminated. */
local_prompt_prefix = expand_prompt (prompt, &prefix_length, (int *)NULL);
local_prompt_prefix = expand_prompt (prompt, &prompt_prefix_length,
(int *)NULL,
&prompt_invis_chars_first_line);
*t = c;
return (prefix_length);
return (prompt_prefix_length);
}
}
@ -399,7 +428,7 @@ rl_redisplay ()
out += local_len;
}
line[out] = '\0';
wrap_offset = local_len - visible_length;
wrap_offset = local_len - prompt_visible_length;
}
else
{
@ -432,7 +461,7 @@ rl_redisplay ()
strncpy (line + out, prompt_this_line, pmtlen);
out += pmtlen;
line[out] = '\0';
wrap_offset = 0;
wrap_offset = prompt_invis_chars_first_line = 0;
}
#define CHECK_INV_LBREAKS() \
@ -447,7 +476,7 @@ rl_redisplay ()
#define CHECK_LPOS() \
do { \
lpos++; \
if (lpos >= screenwidth) \
if (lpos >= _rl_screenwidth) \
{ \
if (newlines >= (inv_lbsize - 2)) \
{ \
@ -463,21 +492,36 @@ rl_redisplay ()
inv_lbreaks[newlines = 0] = 0;
lpos = out - wrap_offset;
/* XXX - what if lpos is already >= screenwidth before we start drawing the
/* prompt_invis_chars_first_line is the number of invisible characters in
the first physical line of the prompt.
wrap_offset - prompt_invis_chars_first_line is the number of invis
chars on the second line. */
/* what if lpos is already >= _rl_screenwidth before we start drawing the
contents of the command line? */
while (lpos >= screenwidth)
while (lpos >= _rl_screenwidth)
{
/* XXX - possible fix from Darin Johnson <darin@acuson.com> for prompt
string with invisible characters that is longer than the screen
width. XXX - this doesn't work right if invisible characters have
to be put on the second screen line -- it adds too much (the number
of invisible chars after the screenwidth). */
temp = ((newlines + 1) * screenwidth) + ((newlines == 0) ? wrap_offset : 0);
/* fix from Darin Johnson <darin@acuson.com> for prompt string with
invisible characters that is longer than the screen width. The
prompt_invis_chars_first_line variable could be made into an array
saying how many invisible characters there are per line, but that's
probably too much work for the benefit gained. How many people have
prompts that exceed two physical lines? */
temp = ((newlines + 1) * _rl_screenwidth) +
((newlines == 0) ? prompt_invis_chars_first_line : 0) +
((newlines == 1) ? wrap_offset : 0);
inv_lbreaks[++newlines] = temp;
lpos -= screenwidth;
lpos -= _rl_screenwidth;
}
prompt_last_screen_line = newlines;
/* Draw the rest of the line (after the prompt) into invisible_line, keeping
track of where the cursor is (c_pos), the number of the line containing
the cursor (lb_linenum), the last line number (lb_botlin and inv_botlin).
It maintains an array of line breaks for display (inv_lbreaks).
This handles expanding tabs for display and displaying meta characters. */
lb_linenum = 0;
for (in = 0; in < rl_end; in++)
{
@ -503,9 +547,9 @@ rl_redisplay ()
{
sprintf (line + out, "\\%o", c);
if (lpos + 4 >= screenwidth)
if (lpos + 4 >= _rl_screenwidth)
{
temp = screenwidth - lpos;
temp = _rl_screenwidth - lpos;
CHECK_INV_LBREAKS ();
inv_lbreaks[++newlines] = out + temp;
lpos = 4 - temp;
@ -524,7 +568,7 @@ rl_redisplay ()
#if defined (DISPLAY_TABS)
else if (c == '\t')
{
register int temp, newout;
register int newout;
#if 0
newout = (out | (int)7) + 1;
@ -532,10 +576,10 @@ rl_redisplay ()
newout = out + 8 - lpos % 8;
#endif
temp = newout - out;
if (lpos + temp >= screenwidth)
if (lpos + temp >= _rl_screenwidth)
{
register int temp2;
temp2 = screenwidth - lpos;
temp2 = _rl_screenwidth - lpos;
CHECK_INV_LBREAKS ();
inv_lbreaks[++newlines] = out + temp2;
lpos = temp - temp2;
@ -550,7 +594,7 @@ rl_redisplay ()
}
}
#endif
else if (c == '\n' && _rl_horizontal_scroll_mode == 0 && term_up && *term_up)
else if (c == '\n' && _rl_horizontal_scroll_mode == 0 && _rl_term_up && *_rl_term_up)
{
line[out++] = '\0'; /* XXX - sentinel */
CHECK_INV_LBREAKS ();
@ -582,7 +626,8 @@ rl_redisplay ()
inv_lbreaks[newlines+1] = out;
cursor_linenum = lb_linenum;
/* C_POS == position in buffer where cursor should be placed. */
/* C_POS == position in buffer where cursor should be placed.
CURSOR_LINENUM == line number where the cursor should be placed. */
/* PWP: now is when things get a bit hairy. The visible and invisible
line buffers are really multiple lines, which would wrap every
@ -593,7 +638,7 @@ rl_redisplay ()
otherwise, let long lines display in a single terminal line, and
horizontally scroll it. */
if (_rl_horizontal_scroll_mode == 0 && term_up && *term_up)
if (_rl_horizontal_scroll_mode == 0 && _rl_term_up && *_rl_term_up)
{
int nleft, pos, changed_screen_line;
@ -604,8 +649,8 @@ rl_redisplay ()
/* If we have more than a screenful of material to display, then
only display a screenful. We should display the last screen,
not the first. */
if (out >= screenchars)
out = screenchars - 1;
if (out >= _rl_screenchars)
out = _rl_screenchars - 1;
/* The first line is at character position 0 in the buffer. The
second and subsequent lines start at inv_lbreaks[N], offset by
@ -635,7 +680,7 @@ rl_redisplay ()
(wrap_offset > visible_wrap_offset) &&
(_rl_last_c_pos < visible_first_line_len))
{
nleft = screenwidth + wrap_offset - _rl_last_c_pos;
nleft = _rl_screenwidth + wrap_offset - _rl_last_c_pos;
if (nleft)
_rl_clear_to_eol (nleft);
}
@ -656,7 +701,7 @@ rl_redisplay ()
_rl_move_vert (linenum);
_rl_move_cursor_relative (0, tt);
_rl_clear_to_eol
((linenum == _rl_vis_botlin) ? strlen (tt) : screenwidth);
((linenum == _rl_vis_botlin) ? strlen (tt) : _rl_screenwidth);
}
}
_rl_vis_botlin = inv_botlin;
@ -667,7 +712,7 @@ rl_redisplay ()
if (changed_screen_line)
{
_rl_move_vert (cursor_linenum);
/* If we moved up to the line with the prompt using term_up,
/* If we moved up to the line with the prompt using _rl_term_up,
the physical cursor position on the screen stays the same,
but the buffer position needs to be adjusted to account
for invisible characters. */
@ -680,15 +725,15 @@ rl_redisplay ()
the characters from the current cursor position. But we
only need to reprint it if the cursor is before the last
invisible character in the prompt string. */
nleft = visible_length + wrap_offset;
nleft = prompt_visible_length + wrap_offset;
if (cursor_linenum == 0 && wrap_offset > 0 && _rl_last_c_pos > 0 &&
_rl_last_c_pos <= last_invisible && local_prompt)
_rl_last_c_pos <= prompt_last_invisible && local_prompt)
{
#if defined (__MSDOS__)
putc ('\r', rl_outstream);
#else
if (term_cr)
tputs (term_cr, 1, _rl_output_character_function);
if (_rl_term_cr)
tputs (_rl_term_cr, 1, _rl_output_character_function);
#endif
_rl_output_some_chars (local_prompt, nleft);
_rl_last_c_pos = nleft;
@ -727,11 +772,11 @@ rl_redisplay ()
/* The number of characters that will be displayed before the cursor. */
ndisp = c_pos - wrap_offset;
nleft = visible_length + wrap_offset;
nleft = prompt_visible_length + wrap_offset;
/* Where the new cursor position will be on the screen. This can be
longer than SCREENWIDTH; if it is, lmargin will be adjusted. */
phys_c_pos = c_pos - (last_lmargin ? last_lmargin : wrap_offset);
t = screenwidth / 3;
t = _rl_screenwidth / 3;
/* If the number of characters had already exceeded the screenwidth,
last_lmargin will be > 0. */
@ -739,7 +784,7 @@ rl_redisplay ()
/* If the number of characters to be displayed is more than the screen
width, compute the starting offset so that the cursor is about
two-thirds of the way across the screen. */
if (phys_c_pos > screenwidth - 2)
if (phys_c_pos > _rl_screenwidth - 2)
{
lmargin = c_pos - (2 * t);
if (lmargin < 0)
@ -749,7 +794,7 @@ rl_redisplay ()
if (wrap_offset && lmargin > 0 && lmargin < nleft)
lmargin = nleft;
}
else if (ndisp < screenwidth - 2) /* XXX - was -1 */
else if (ndisp < _rl_screenwidth - 2) /* XXX - was -1 */
lmargin = 0;
else if (phys_c_pos < 1)
{
@ -771,7 +816,7 @@ rl_redisplay ()
the whole line, indicate that with a special character at the
right edge of the screen. If LMARGIN is 0, we need to take the
wrap offset into account. */
t = lmargin + M_OFFSET (lmargin, wrap_offset) + screenwidth;
t = lmargin + M_OFFSET (lmargin, wrap_offset) + _rl_screenwidth;
if (t < out)
line[t - 1] = '>';
@ -781,8 +826,8 @@ rl_redisplay ()
update_line (&visible_line[last_lmargin],
&invisible_line[lmargin],
0,
screenwidth + visible_wrap_offset,
screenwidth + (lmargin ? 0 : wrap_offset),
_rl_screenwidth + visible_wrap_offset,
_rl_screenwidth + (lmargin ? 0 : wrap_offset),
0);
/* If the visible new line is shorter than the old, but the number
@ -793,12 +838,12 @@ rl_redisplay ()
(_rl_last_c_pos == out) &&
t < visible_first_line_len)
{
nleft = screenwidth - t;
nleft = _rl_screenwidth - t;
_rl_clear_to_eol (nleft);
}
visible_first_line_len = out - lmargin - M_OFFSET (lmargin, wrap_offset);
if (visible_first_line_len > screenwidth)
visible_first_line_len = screenwidth;
if (visible_first_line_len > _rl_screenwidth)
visible_first_line_len = _rl_screenwidth;
_rl_move_cursor_relative (c_pos - lmargin, &invisible_line[lmargin]);
last_lmargin = lmargin;
@ -808,11 +853,11 @@ rl_redisplay ()
/* Swap visible and non-visible lines. */
{
char *temp = visible_line;
char *vtemp = visible_line;
int *itemp = vis_lbreaks, ntemp = vis_lbsize;
visible_line = invisible_line;
invisible_line = temp;
invisible_line = vtemp;
vis_lbreaks = inv_lbreaks;
inv_lbreaks = itemp;
@ -862,7 +907,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
emulators. In this calculation, TEMP is the physical screen
position of the cursor. */
temp = _rl_last_c_pos - W_OFFSET(_rl_last_v_pos, visible_wrap_offset);
if (temp == screenwidth && _rl_term_autowrap && !_rl_horizontal_scroll_mode
if (temp == _rl_screenwidth && _rl_term_autowrap && !_rl_horizontal_scroll_mode
&& _rl_last_v_pos == current_line - 1)
{
if (new[0])
@ -939,13 +984,13 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
lendiff = local_prompt ? strlen (local_prompt) : 0;
od = ofd - old; /* index of first difference in visible line */
if (current_line == 0 && !_rl_horizontal_scroll_mode &&
term_cr && lendiff > visible_length && _rl_last_c_pos > 0 &&
od > lendiff && _rl_last_c_pos < last_invisible)
_rl_term_cr && lendiff > prompt_visible_length && _rl_last_c_pos > 0 &&
od >= lendiff && _rl_last_c_pos <= prompt_last_invisible)
{
#if defined (__MSDOS__)
putc ('\r', rl_outstream);
#else
tputs (term_cr, 1, _rl_output_character_function);
tputs (_rl_term_cr, 1, _rl_output_character_function);
#endif
_rl_output_some_chars (local_prompt, lendiff);
_rl_last_c_pos = lendiff;
@ -973,14 +1018,14 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
use the terminal's capabilities. If we're growing the number
of lines, make sure we actually cause the new line to wrap
around on auto-wrapping terminals. */
if (terminal_can_insert && ((2 * temp) >= lendiff || term_IC) && (!_rl_term_autowrap || !gl))
if (_rl_terminal_can_insert && ((2 * temp) >= lendiff || _rl_term_IC) && (!_rl_term_autowrap || !gl))
{
/* If lendiff > visible_length and _rl_last_c_pos == 0 and
/* If lendiff > prompt_visible_length and _rl_last_c_pos == 0 and
_rl_horizontal_scroll_mode == 1, inserting the characters with
term_IC or term_ic will screw up the screen because of the
_rl_term_IC or _rl_term_ic will screw up the screen because of the
invisible characters. We need to just draw them. */
if (*ols && (!_rl_horizontal_scroll_mode || _rl_last_c_pos > 0 ||
lendiff <= visible_length || !current_invis_chars))
lendiff <= prompt_visible_length || !current_invis_chars))
{
insert_some_chars (nfd, lendiff);
_rl_last_c_pos += lendiff;
@ -1021,7 +1066,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
else /* Delete characters from line. */
{
/* If possible and inexpensive to use terminal deletion, then do so. */
if (term_dc && (2 * temp) >= -lendiff)
if (_rl_term_dc && (2 * temp) >= -lendiff)
{
/* If all we're doing is erasing the invisible characters in the
prompt string, don't bother. It screws up the assumptions
@ -1106,7 +1151,7 @@ rl_on_new_line_with_prompt ()
/* Dissect prompt_last_line into screen lines. Note that here we have
to use the real screenwidth. Readline's notion of screenwidth might be
one less, see terminal.c. */
real_screenwidth = screenwidth + (_rl_term_autowrap ? 0 : 1);
real_screenwidth = _rl_screenwidth + (_rl_term_autowrap ? 0 : 1);
_rl_last_v_pos = l / real_screenwidth;
/* If the prompt length is a multiple of real_screenwidth, we don't know
whether the cursor is at the end of the last line, or already at the
@ -1151,7 +1196,7 @@ rl_forced_update_display ()
void
_rl_move_cursor_relative (new, data)
int new;
char *data;
const char *data;
{
register int i;
@ -1163,12 +1208,12 @@ _rl_move_cursor_relative (new, data)
/* i == current physical cursor position. */
i = _rl_last_c_pos - W_OFFSET(_rl_last_v_pos, visible_wrap_offset);
if (new == 0 || CR_FASTER (new, _rl_last_c_pos) ||
(_rl_term_autowrap && i == screenwidth))
(_rl_term_autowrap && i == _rl_screenwidth))
{
#if defined (__MSDOS__)
putc ('\r', rl_outstream);
#else
tputs (term_cr, 1, _rl_output_character_function);
tputs (_rl_term_cr, 1, _rl_output_character_function);
#endif /* !__MSDOS__ */
_rl_last_c_pos = 0;
}
@ -1185,9 +1230,9 @@ _rl_move_cursor_relative (new, data)
That kind of control is for people who don't know what the
data is underneath the cursor. */
#if defined (HACK_TERMCAP_MOTION)
if (term_forward_char)
if (_rl_term_forward_char)
for (i = _rl_last_c_pos; i < new; i++)
tputs (term_forward_char, 1, _rl_output_character_function);
tputs (_rl_term_forward_char, 1, _rl_output_character_function);
else
for (i = _rl_last_c_pos; i < new; i++)
putc (data[i], rl_outstream);
@ -1208,7 +1253,7 @@ _rl_move_vert (to)
{
register int delta, i;
if (_rl_last_v_pos == to || to > screenheight)
if (_rl_last_v_pos == to || to > _rl_screenheight)
return;
if ((delta = to - _rl_last_v_pos) > 0)
@ -1218,15 +1263,15 @@ _rl_move_vert (to)
#if defined (__MSDOS__)
putc ('\r', rl_outstream);
#else
tputs (term_cr, 1, _rl_output_character_function);
tputs (_rl_term_cr, 1, _rl_output_character_function);
#endif
_rl_last_c_pos = 0;
}
else
{ /* delta < 0 */
if (term_up && *term_up)
if (_rl_term_up && *_rl_term_up)
for (i = 0; i < -delta; i++)
tputs (term_up, 1, _rl_output_character_function);
tputs (_rl_term_up, 1, _rl_output_character_function);
}
_rl_last_v_pos = to; /* Now TO is here */
@ -1360,25 +1405,23 @@ rl_save_prompt ()
{
saved_local_prompt = local_prompt;
saved_local_prefix = local_prompt_prefix;
saved_last_invisible = last_invisible;
saved_visible_length = visible_length;
saved_last_invisible = prompt_last_invisible;
saved_visible_length = prompt_visible_length;
local_prompt = local_prompt_prefix = (char *)0;
last_invisible = visible_length = 0;
prompt_last_invisible = prompt_visible_length = 0;
}
void
rl_restore_prompt ()
{
if (local_prompt)
free (local_prompt);
if (local_prompt_prefix)
free (local_prompt_prefix);
FREE (local_prompt);
FREE (local_prompt_prefix);
local_prompt = saved_local_prompt;
local_prompt_prefix = saved_local_prefix;
last_invisible = saved_last_invisible;
visible_length = saved_visible_length;
prompt_last_invisible = saved_last_invisible;
prompt_visible_length = saved_visible_length;
}
char *
@ -1408,8 +1451,8 @@ _rl_make_prompt_for_search (pchar)
pmt[len] = pchar;
pmt[len+1] = '\0';
local_prompt = savestring (pmt);
last_invisible = saved_last_invisible;
visible_length = saved_visible_length + 1;
prompt_last_invisible = saved_last_invisible;
prompt_visible_length = saved_visible_length + 1;
}
return pmt;
}
@ -1436,8 +1479,8 @@ void
_rl_clear_to_eol (count)
int count;
{
if (term_clreol)
tputs (term_clreol, 1, _rl_output_character_function);
if (_rl_term_clreol)
tputs (_rl_term_clreol, 1, _rl_output_character_function);
else if (count)
space_to_eol (count);
}
@ -1459,10 +1502,10 @@ space_to_eol (count)
void
_rl_clear_screen ()
{
if (term_clrpag)
tputs (term_clrpag, 1, _rl_output_character_function);
if (_rl_term_clrpag)
tputs (_rl_term_clrpag, 1, _rl_output_character_function);
else
crlf ();
rl_crlf ();
}
/* Insert COUNT characters from STRING to the output stream. */
@ -1472,10 +1515,10 @@ insert_some_chars (string, count)
int count;
{
/* If IC is defined, then we do not have to "enter" insert mode. */
if (term_IC)
if (_rl_term_IC)
{
char *buffer;
buffer = tgoto (term_IC, 0, count);
buffer = tgoto (_rl_term_IC, 0, count);
tputs (buffer, 1, _rl_output_character_function);
_rl_output_some_chars (string, count);
}
@ -1484,15 +1527,15 @@ insert_some_chars (string, count)
register int i;
/* If we have to turn on insert-mode, then do so. */
if (term_im && *term_im)
tputs (term_im, 1, _rl_output_character_function);
if (_rl_term_im && *_rl_term_im)
tputs (_rl_term_im, 1, _rl_output_character_function);
/* If there is a special command for inserting characters, then
use that first to open up the space. */
if (term_ic && *term_ic)
if (_rl_term_ic && *_rl_term_ic)
{
for (i = count; i--; )
tputs (term_ic, 1, _rl_output_character_function);
tputs (_rl_term_ic, 1, _rl_output_character_function);
}
/* Print the text. */
@ -1500,8 +1543,8 @@ insert_some_chars (string, count)
/* If there is a string to turn off insert mode, we had best use
it now. */
if (term_ei && *term_ei)
tputs (term_ei, 1, _rl_output_character_function);
if (_rl_term_ei && *_rl_term_ei)
tputs (_rl_term_ei, 1, _rl_output_character_function);
}
}
@ -1510,20 +1553,20 @@ static void
delete_chars (count)
int count;
{
if (count > screenwidth) /* XXX */
if (count > _rl_screenwidth) /* XXX */
return;
if (term_DC && *term_DC)
if (_rl_term_DC && *_rl_term_DC)
{
char *buffer;
buffer = tgoto (term_DC, count, count);
buffer = tgoto (_rl_term_DC, count, count);
tputs (buffer, count, _rl_output_character_function);
}
else
{
if (term_dc && *term_dc)
if (_rl_term_dc && *_rl_term_dc)
while (count--)
tputs (term_dc, 1, _rl_output_character_function);
tputs (_rl_term_dc, 1, _rl_output_character_function);
}
}
@ -1543,7 +1586,7 @@ _rl_update_final ()
}
_rl_move_vert (_rl_vis_botlin);
/* If we've wrapped lines, remove the final xterm line-wrap flag. */
if (full_lines && _rl_term_autowrap && (VIS_LLEN(_rl_vis_botlin) == screenwidth))
if (full_lines && _rl_term_autowrap && (VIS_LLEN(_rl_vis_botlin) == _rl_screenwidth))
{
char *last_line;
#if 0
@ -1551,12 +1594,12 @@ _rl_update_final ()
#else
last_line = &visible_line[vis_lbreaks[_rl_vis_botlin]];
#endif
_rl_move_cursor_relative (screenwidth - 1, last_line);
_rl_move_cursor_relative (_rl_screenwidth - 1, last_line);
_rl_clear_to_eol (0);
putc (last_line[screenwidth - 1], rl_outstream);
putc (last_line[_rl_screenwidth - 1], rl_outstream);
}
_rl_vis_botlin = 0;
crlf ();
rl_crlf ();
fflush (rl_outstream);
rl_display_fixed++;
}
@ -1565,12 +1608,12 @@ _rl_update_final ()
static void
cr ()
{
if (term_cr)
if (_rl_term_cr)
{
#if defined (__MSDOS__)
putc ('\r', rl_outstream);
#else
tputs (term_cr, 1, _rl_output_character_function);
tputs (_rl_term_cr, 1, _rl_output_character_function);
#endif
_rl_last_c_pos = 0;
}
@ -1584,27 +1627,31 @@ redraw_prompt (t)
char *t;
{
char *oldp, *oldl, *oldlprefix;
int oldlen, oldlast, oldplen;
int oldlen, oldlast, oldplen, oldninvis;
/* Geez, I should make this a struct. */
oldp = rl_display_prompt;
oldl = local_prompt;
oldlprefix = local_prompt_prefix;
oldlen = visible_length;
oldplen = prefix_length;
oldlast = last_invisible;
oldlen = prompt_visible_length;
oldplen = prompt_prefix_length;
oldlast = prompt_last_invisible;
oldninvis = prompt_invis_chars_first_line;
rl_display_prompt = t;
local_prompt = expand_prompt (t, &visible_length, &last_invisible);
local_prompt = expand_prompt (t, &prompt_visible_length,
&prompt_last_invisible,
&prompt_invis_chars_first_line);
local_prompt_prefix = (char *)NULL;
rl_forced_update_display ();
rl_display_prompt = oldp;
local_prompt = oldl;
local_prompt_prefix = oldlprefix;
visible_length = oldlen;
prefix_length = oldplen;
last_invisible = oldlast;
prompt_visible_length = oldlen;
prompt_prefix_length = oldplen;
prompt_last_invisible = oldlast;
prompt_invis_chars_first_line = oldninvis;
}
/* Redisplay the current line after a SIGWINCH is received. */
@ -1615,31 +1662,31 @@ _rl_redisplay_after_sigwinch ()
/* Clear the current line and put the cursor at column 0. Make sure
the right thing happens if we have wrapped to a new screen line. */
if (term_cr)
if (_rl_term_cr)
{
#if defined (__MSDOS__)
putc ('\r', rl_outstream);
#else
tputs (term_cr, 1, _rl_output_character_function);
tputs (_rl_term_cr, 1, _rl_output_character_function);
#endif
_rl_last_c_pos = 0;
#if defined (__MSDOS__)
space_to_eol (screenwidth);
space_to_eol (_rl_screenwidth);
putc ('\r', rl_outstream);
#else
if (term_clreol)
tputs (term_clreol, 1, _rl_output_character_function);
if (_rl_term_clreol)
tputs (_rl_term_clreol, 1, _rl_output_character_function);
else
{
space_to_eol (screenwidth);
tputs (term_cr, 1, _rl_output_character_function);
space_to_eol (_rl_screenwidth);
tputs (_rl_term_cr, 1, _rl_output_character_function);
}
#endif
if (_rl_last_v_pos > 0)
_rl_move_vert (0);
}
else
crlf ();
rl_crlf ();
/* Redraw only the last line of a multi-line prompt. */
t = strrchr (rl_display_prompt, '\n');
@ -1680,12 +1727,12 @@ _rl_current_display_line ()
/* Find out whether or not there might be invisible characters in the
editing buffer. */
if (rl_display_prompt == rl_prompt)
nleft = _rl_last_c_pos - screenwidth - rl_visible_prompt_length;
nleft = _rl_last_c_pos - _rl_screenwidth - rl_visible_prompt_length;
else
nleft = _rl_last_c_pos - screenwidth;
nleft = _rl_last_c_pos - _rl_screenwidth;
if (nleft > 0)
ret = 1 + nleft / screenwidth;
ret = 1 + nleft / _rl_screenwidth;
else
ret = 0;

View file

@ -18,7 +18,7 @@ This document describes the GNU History library, a programming tool that
provides a consistent user interface for recalling lines of previously
typed input.
Copyright (C) 1988-1999 Free Software Foundation, Inc.
Copyright (C) 1988-2001 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@ -73,7 +73,7 @@ except that this permission notice may be stated in a translation approved
by the Free Software Foundation.
@vskip 0pt plus 1filll
Copyright @copyright{} 1988-1999 Free Software Foundation, Inc.
Copyright @copyright{} 1988-2001 Free Software Foundation, Inc.
@end titlepage
@ifinfo

View file

@ -1,7 +1,7 @@
@ignore
This file documents the user interface to the GNU History library.
Copyright (C) 1988, 1991, 1994, 1996 Free Software Foundation, Inc.
Copyright (C) 1988-2001 Free Software Foundation, Inc.
Authored by Brian Fox and Chet Ramey.
Permission is granted to make and distribute verbatim copies of this manual
@ -27,9 +27,9 @@ into another language, under the above conditions for modified versions.
@chapter Programming with GNU History
This chapter describes how to interface programs that you write
with the GNU History Library.
with the @sc{gnu} History Library.
It should be considered a technical guide.
For information on the interactive use of GNU History, @pxref{Using
For information on the interactive use of @sc{gnu} History, @pxref{Using
History Interactively}.
@menu
@ -43,10 +43,10 @@ History Interactively}.
@node Introduction to History
@section Introduction to History
Many programs read input from the user a line at a time. The GNU History
library is able to keep track of those lines, associate arbitrary data with
each line, and utilize information from previous lines in composing new
ones.
Many programs read input from the user a line at a time. The @sc{gnu}
History library is able to keep track of those lines, associate arbitrary
data with each line, and utilize information from previous lines in
composing new ones.
The programmer using the History library has available functions
for remembering lines on a history list, associating arbitrary data
@ -80,9 +80,11 @@ The history list is an array of history entries. A history entry is
declared as follows:
@example
typedef void *histdata_t;
typedef struct _hist_entry @{
char *line;
char *data;
histdata_t data;
@} HIST_ENTRY;
@end example
@ -95,12 +97,14 @@ HIST_ENTRY **the_history_list;
The state of the History library is encapsulated into a single structure:
@example
/* A structure used to pass the current state of the history stuff around. */
/*
* A structure used to pass around the current state of the history.
*/
typedef struct _hist_state @{
HIST_ENTRY **entries; /* Pointer to the entries themselves. */
int offset; /* The location pointer within this array. */
int length; /* Number of elements within this array. */
int size; /* Number of slots allocated to this array. */
HIST_ENTRY **entries; /* Pointer to the entries themselves. */
int offset; /* The location pointer within this array. */
int length; /* Number of elements within this array. */
int size; /* Number of slots allocated to this array. */
int flags;
@} HISTORY_STATE;
@end example
@ -112,7 +116,7 @@ stifled.
@section History Functions
This section describes the calling sequence for the various functions
present in GNU History.
exported by the @sc{gnu} History library.
@menu
* Initializing History and State Management:: Functions to call when you
@ -139,12 +143,12 @@ This section describes functions used to initialize and manage
the state of the History library when you want to use the history
functions in your program.
@deftypefun void using_history ()
@deftypefun void using_history (void)
Begin a session in which the history functions might be used. This
initializes the interactive variables.
@end deftypefun
@deftypefun {HISTORY_STATE *} history_get_history_state ()
@deftypefun {HISTORY_STATE *} history_get_history_state (void)
Return a structure describing the current state of the input history.
@end deftypefun
@ -158,7 +162,7 @@ Set the state of the history list according to @var{state}.
These functions manage individual entries on the history list, or set
parameters managing the list itself.
@deftypefun void add_history (char *string)
@deftypefun void add_history (const char *string)
Place @var{string} at the end of the history list. The associated data
field (if any) is set to @code{NULL}.
@end deftypefun
@ -169,13 +173,13 @@ removed element is returned so you can free the line, data,
and containing structure.
@end deftypefun
@deftypefun {HIST_ENTRY *} replace_history_entry (int which, char *line, char *data)
@deftypefun {HIST_ENTRY *} replace_history_entry (int which, const char *line, histdata_t data)
Make the history entry at offset @var{which} have @var{line} and @var{data}.
This returns the old entry so you can dispose of the data. In the case
of an invalid @var{which}, a @code{NULL} pointer is returned.
@end deftypefun
@deftypefun void clear_history ()
@deftypefun void clear_history (void)
Clear the history list by deleting all the entries.
@end deftypefun
@ -183,13 +187,13 @@ Clear the history list by deleting all the entries.
Stifle the history list, remembering only the last @var{max} entries.
@end deftypefun
@deftypefun int unstifle_history ()
@deftypefun int unstifle_history (void)
Stop stifling the history. This returns the previous amount the
history was stifled. The value is positive if the history was
stifled, negative if it wasn't.
@end deftypefun
@deftypefun int history_is_stifled ()
@deftypefun int history_is_stifled (void)
Returns non-zero if the history is stifled, zero if it is not.
@end deftypefun
@ -199,29 +203,30 @@ Returns non-zero if the history is stifled, zero if it is not.
These functions return information about the entire history list or
individual list entries.
@deftypefun {HIST_ENTRY **} history_list ()
Return a @code{NULL} terminated array of @code{HIST_ENTRY} which is the
@deftypefun {HIST_ENTRY **} history_list (void)
Return a @code{NULL} terminated array of @code{HIST_ENTRY *} which is the
current input history. Element 0 of this list is the beginning of time.
If there is no history, return @code{NULL}.
@end deftypefun
@deftypefun int where_history ()
@deftypefun int where_history (void)
Returns the offset of the current history element.
@end deftypefun
@deftypefun {HIST_ENTRY *} current_history ()
@deftypefun {HIST_ENTRY *} current_history (void)
Return the history entry at the current position, as determined by
@code{where_history ()}. If there is no entry there, return a @code{NULL}
@code{where_history()}. If there is no entry there, return a @code{NULL}
pointer.
@end deftypefun
@deftypefun {HIST_ENTRY *} history_get (int offset)
Return the history entry at position @var{offset}, starting from
@code{history_base}. If there is no entry there, or if @var{offset}
@code{history_base} (@pxref{History Variables}).
If there is no entry there, or if @var{offset}
is greater than the history length, return a @code{NULL} pointer.
@end deftypefun
@deftypefun int history_total_bytes ()
@deftypefun int history_total_bytes (void)
Return the number of bytes that the primary history entries are using.
This function returns the sum of the lengths of all the lines in the
history.
@ -234,17 +239,19 @@ These functions allow the current index into the history list to be
set or changed.
@deftypefun int history_set_pos (int pos)
Set the position in the history list to @var{pos}, an absolute index
Set the current history offset to @var{pos}, an absolute index
into the list.
Returns 1 on success, 0 if @var{pos} is less than zero or greater
than the number of history entries.
@end deftypefun
@deftypefun {HIST_ENTRY *} previous_history ()
@deftypefun {HIST_ENTRY *} previous_history (void)
Back up the current history offset to the previous history entry, and
return a pointer to that entry. If there is no previous entry, return
a @code{NULL} pointer.
@end deftypefun
@deftypefun {HIST_ENTRY *} next_history ()
@deftypefun {HIST_ENTRY *} next_history (void)
Move the current history offset forward to the next history entry, and
return the a pointer to that entry. If there is no next entry, return
a @code{NULL} pointer.
@ -260,26 +267,28 @@ from the current history position. The search may be @dfn{anchored},
meaning that the string must match at the beginning of the history entry.
@cindex anchored search
@deftypefun int history_search (char *string, int direction)
Search the history for @var{string}, starting at the current history
offset. If @var{direction} < 0, then the search is through previous entries,
else through subsequent. If @var{string} is found, then
@deftypefun int history_search (const char *string, int direction)
Search the history for @var{string}, starting at the current history offset.
If @var{direction} is less than 0, then the search is through
previous entries, otherwise through subsequent entries.
If @var{string} is found, then
the current history index is set to that history entry, and the value
returned is the offset in the line of the entry where
@var{string} was found. Otherwise, nothing is changed, and a -1 is
returned.
@end deftypefun
@deftypefun int history_search_prefix (char *string, int direction)
@deftypefun int history_search_prefix (const char *string, int direction)
Search the history for @var{string}, starting at the current history
offset. The search is anchored: matching lines must begin with
@var{string}. If @var{direction} < 0, then the search is through previous
entries, else through subsequent. If @var{string} is found, then the
@var{string}. If @var{direction} is less than 0, then the search is
through previous entries, otherwise through subsequent entries.
If @var{string} is found, then the
current history index is set to that entry, and the return value is 0.
Otherwise, nothing is changed, and a -1 is returned.
@end deftypefun
@deftypefun int history_search_pos (char *string, int direction, int pos)
@deftypefun int history_search_pos (const char *string, int direction, int pos)
Search for @var{string} in the history list, starting at @var{pos}, an
absolute index into the list. If @var{direction} is negative, the search
proceeds backward from @var{pos}, otherwise forward. Returns the absolute
@ -292,41 +301,46 @@ index of the history element where @var{string} was found, or -1 otherwise.
The History library can read the history from and write it to a file.
This section documents the functions for managing a history file.
@deftypefun int read_history (char *filename)
Add the contents of @var{filename} to the history list, a line at a
time. If @var{filename} is @code{NULL}, then read from
@file{~/.history}. Returns 0 if successful, or errno if not.
@deftypefun int read_history (const char *filename)
Add the contents of @var{filename} to the history list, a line at a time.
If @var{filename} is @code{NULL}, then read from @file{~/.history}.
Returns 0 if successful, or @code{errno} if not.
@end deftypefun
@deftypefun int read_history_range (char *filename, int from, int to)
@deftypefun int read_history_range (const char *filename, int from, int to)
Read a range of lines from @var{filename}, adding them to the history list.
Start reading at line @var{from} and end at @var{to}. If
@var{from} is zero, start at the beginning. If @var{to} is less than
Start reading at line @var{from} and end at @var{to}.
If @var{from} is zero, start at the beginning. If @var{to} is less than
@var{from}, then read until the end of the file. If @var{filename} is
@code{NULL}, then read from @file{~/.history}. Returns 0 if successful,
or @code{errno} if not.
@end deftypefun
@deftypefun int write_history (char *filename)
@deftypefun int write_history (const char *filename)
Write the current history to @var{filename}, overwriting @var{filename}
if necessary. If @var{filename} is
@code{NULL}, then write the history list to @file{~/.history}. Values
returned are as in @code{read_history ()}.
if necessary.
If @var{filename} is @code{NULL}, then write the history list to
@file{~/.history}.
Returns 0 on success, or @code{errno} on a read or write error.
@end deftypefun
@deftypefun int append_history (int nelements, char *filename)
@deftypefun int append_history (int nelements, const char *filename)
Append the last @var{nelements} of the history list to @var{filename}.
If @var{filename} is @code{NULL}, then append to @file{~/.history}.
Returns 0 on success, or @code{errno} on a read or write error.
@end deftypefun
@deftypefun int history_truncate_file (char *filename, int nlines)
@deftypefun int history_truncate_file (const char *filename, int nlines)
Truncate the history file @var{filename}, leaving only the last
@var{nlines} lines.
If @var{filename} is @code{NULL}, then @file{~/.history} is truncated.
Returns 0 on success, or @code{errno} on failure.
@end deftypefun
@node History Expansion
@subsection History Expansion
These functions implement @code{csh}-like history expansion.
These functions implement history expansion.
@deftypefun int history_expand (char *string, char **output)
Expand @var{string}, placing the result into @var{output}, a pointer
@ -334,7 +348,7 @@ to a string (@pxref{History Interaction}). Returns:
@table @code
@item 0
If no expansions took place (or, if the only change in
the text was the de-slashifying of the history expansion
the text was the removal of escape characters preceding the history expansion
character);
@item 1
if expansions did take place;
@ -349,12 +363,7 @@ If an error ocurred in expansion, then @var{output} contains a descriptive
error message.
@end deftypefun
@deftypefun {char *} history_arg_extract (int first, int last, char *string)
Extract a string segment consisting of the @var{first} through @var{last}
arguments present in @var{string}. Arguments are broken up as in Bash.
@end deftypefun
@deftypefun {char *} get_history_event (char *string, int *cindex, int qchar)
@deftypefun {char *} get_history_event (const char *string, int *cindex, int qchar)
Returns the text of the history event beginning at @var{string} +
@var{*cindex}. @var{*cindex} is modified to point to after the event
specifier. At function entry, @var{cindex} points to the index into
@ -363,18 +372,24 @@ is a character that is allowed to end the event specification in addition
to the ``normal'' terminating characters.
@end deftypefun
@deftypefun {char **} history_tokenize (char *string)
@deftypefun {char **} history_tokenize (const char *string)
Return an array of tokens parsed out of @var{string}, much as the
shell might. The tokens are split on white space and on the
characters @code{()<>;&|$}, and shell quoting conventions are
obeyed.
shell might. The tokens are split on the characters in the
@var{history_word_delimiters} variable,
and shell quoting conventions are obeyed.
@end deftypefun
@deftypefun {char *} history_arg_extract (int first, int last, const char *string)
Extract a string segment consisting of the @var{first} through @var{last}
arguments present in @var{string}. Arguments are split using
@code{history_tokenize}.
@end deftypefun
@node History Variables
@section History Variables
This section describes the externally visible variables exported by
the GNU History Library.
This section describes the externally-visible variables exported by
the @sc{gnu} History Library.
@deftypevar int history_base
The logical offset of the first entry in the history list.
@ -384,13 +399,14 @@ The logical offset of the first entry in the history list.
The number of entries currently stored in the history list.
@end deftypevar
@deftypevar int max_input_history
@deftypevar int history_max_entries
The maximum number of history entries. This must be changed using
@code{stifle_history ()}.
@code{stifle_history()}.
@end deftypevar
@deftypevar char history_expansion_char
The character that starts a history event. The default is @samp{!}.
The character that introduces a history event. The default is @samp{!}.
Setting this to 0 inhibits history expansion.
@end deftypevar
@deftypevar char history_subst_char
@ -405,15 +421,20 @@ ignored, suppressing history expansion for the remainder of the line.
This is disabled by default.
@end deftypevar
@deftypevar {char *} history_word_delimiters
The characters that separate tokens for \fBhistory_tokenize()\fP.
The default value is @code{" \t\n()<>;&|"}.
@end deftypevar
@deftypevar {char *} history_no_expand_chars
The list of characters which inhibit history expansion if found immediately
following @var{history_expansion_char}. The default is whitespace and
@samp{=}.
following @var{history_expansion_char}. The default is space, tab, newline,
carriage return, and @samp{=}.
@end deftypevar
@deftypevar {char *} history_search_delimiter_chars
The list of additional characters which can delimit a history search
string, in addition to whitespace, @samp{:} and @samp{?} in the case of
string, in addition to space, TAB, @samp{:} and @samp{?} in the case of
a substring search. The default is empty.
@end deftypevar
@ -422,24 +443,30 @@ If non-zero, single-quoted words are not scanned for the history expansion
character. The default value is 0.
@end deftypevar
@deftypevar {Function *} history_inhibit_expansion_function
@deftypevar {rl_linebuf_func_t *} history_inhibit_expansion_function
This should be set to the address of a function that takes two arguments:
a @code{char *} (@var{string}) and an integer index into that string (@var{i}).
a @code{char *} (@var{string})
and an @code{int} index into that string (@var{i}).
It should return a non-zero value if the history expansion starting at
@var{string[i]} should not be performed; zero if the expansion should
be done.
It is intended for use by applications like Bash that use the history
expansion character for additional purposes.
By default, this variable is set to NULL.
By default, this variable is set to @code{NULL}.
@end deftypevar
@node History Programming Example
@section History Programming Example
The following program demonstrates simple use of the GNU History Library.
The following program demonstrates simple use of the @sc{gnu} History Library.
@smallexample
main ()
#include <stdio.h>
#include <readline/history.h>
main (argc, argv)
int argc;
char **argv;
@{
char line[1024], *t;
int len, done = 0;

View file

@ -38,9 +38,9 @@ For information on using the @sc{gnu} History Library in other programs,
see the @sc{gnu} Readline Library Manual.
@end ifset
@ifclear BashFeatures
This chapter describes how to use the GNU History Library interactively,
This chapter describes how to use the @sc{gnu} History Library interactively,
from a user's standpoint. It should be considered a user's guide. For
information on using the GNU History Library in your own programs,
information on using the @sc{gnu} History Library in your own programs,
@pxref{Programming with GNU History}.
@end ifclear
@ -65,36 +65,36 @@ information on using the GNU History Library in your own programs,
@cindex command history
@cindex history list
When the @samp{-o history} option to the @code{set} builtin
When the @option{-o history} option to the @code{set} builtin
is enabled (@pxref{The Set Builtin}),
the shell provides access to the @var{command history},
the shell provides access to the @dfn{command history},
the list of commands previously typed.
The value of the @code{HISTSIZE} shell variable is used as the
The value of the @env{HISTSIZE} shell variable is used as the
number of commands to save in a history list.
The text of the last @code{$HISTSIZE}
The text of the last @env{$HISTSIZE}
commands (default 500) is saved.
The shell stores each command in the history list prior to
parameter and variable expansion
but after history expansion is performed, subject to the
values of the shell variables
@code{HISTIGNORE} and @code{HISTCONTROL}.
@env{HISTIGNORE} and @env{HISTCONTROL}.
When the shell starts up, the history is initialized from the
file named by the @code{HISTFILE} variable (default @file{~/.bash_history}).
The file named by the value of @code{HISTFILE} is truncated, if
file named by the @env{HISTFILE} variable (default @file{~/.bash_history}).
The file named by the value of @env{HISTFILE} is truncated, if
necessary, to contain no more than the number of lines specified by
the value of the @code{HISTFILESIZE} variable.
the value of the @env{HISTFILESIZE} variable.
When an interactive shell exits, the last
@code{$HISTSIZE} lines are copied from the history list to the file
named by @code{$HISTFILE}.
@env{$HISTSIZE} lines are copied from the history list to the file
named by @env{$HISTFILE}.
If the @code{histappend} shell option is set (@pxref{Bash Builtins}),
the lines are appended to the history file,
otherwise the history file is overwritten.
If @code{HISTFILE}
If @env{HISTFILE}
is unset, or if the history file is unwritable, the history is
not saved. After saving the history, the history file is truncated
to contain no more than @code{$HISTFILESIZE}
lines. If @code{HISTFILESIZE} is not set, no truncation is performed.
to contain no more than @env{$HISTFILESIZE}
lines. If @env{HISTFILESIZE} is not set, no truncation is performed.
The builtin command @code{fc} may be used to list or edit and re-execute
a portion of the history list.
@ -105,7 +105,7 @@ are available in each editing mode that provide access to the
history list (@pxref{Commands For History}).
The shell allows control over which commands are saved on the history
list. The @code{HISTCONTROL} and @code{HISTIGNORE}
list. The @env{HISTCONTROL} and @env{HISTIGNORE}
variables may be set to cause the shell to save only a subset of the
commands entered.
The @code{cmdhist}
@ -141,15 +141,15 @@ command beginning with that string) or as a number (an index into the
history list, where a negative number is used as an offset from the
current command number). If @var{last} is not specified it is set to
@var{first}. If @var{first} is not specified it is set to the previous
command for editing and @minus{}16 for listing. If the @samp{-l} flag is
given, the commands are listed on standard output. The @samp{-n} flag
suppresses the command numbers when listing. The @samp{-r} flag
command for editing and @minus{}16 for listing. If the @option{-l} flag is
given, the commands are listed on standard output. The @option{-n} flag
suppresses the command numbers when listing. The @option{-r} flag
reverses the order of the listing. Otherwise, the editor given by
@var{ename} is invoked on a file containing those commands. If
@var{ename} is not given, the value of the following variable expansion
is used: @code{$@{FCEDIT:-$@{EDITOR:-vi@}@}}. This says to use the
value of the @code{FCEDIT} variable if set, or the value of the
@code{EDITOR} variable if that is set, or @code{vi} if neither is set.
value of the @env{FCEDIT} variable if set, or the value of the
@env{EDITOR} variable if that is set, or @code{vi} if neither is set.
When editing is complete, the edited commands are echoed and executed.
In the second form, @var{command} is re-executed after each instance
@ -170,7 +170,7 @@ history -ps @var{arg}
@end example
With no options, display the history list with line numbers.
Lines prefixed with with a @samp{*} have been modified.
Lines prefixed with a @samp{*} have been modified.
An argument of @var{n} lists only the last @var{n} lines.
Options, if supplied, have the following meanings:
@ -211,10 +211,10 @@ the history list as a single entry.
@end table
When any of the @samp{-w}, @samp{-r}, @samp{-a}, or @samp{-n} options is
When any of the @option{-w}, @option{-r}, @option{-a}, or @option{-n} options is
used, if @var{filename}
is given, then it is used as the history file. If not, then
the value of the @code{HISTFILE} variable is used.
the value of the @env{HISTFILE} variable is used.
@end table
@end ifset
@ -260,9 +260,9 @@ editing buffer for further modification.
If Readline is being used, and the @code{histreedit}
shell option is enabled, a failed history expansion will be
reloaded into the Readline editing buffer for correction.
The @samp{-p} option to the @code{history} builtin command
The @option{-p} option to the @code{history} builtin command
may be used to see what a history expansion will do before using it.
The @samp{-s} option to the @code{history} builtin may be used to
The @option{-s} option to the @code{history} builtin may be used to
add commands to the end of the history list without actually executing
them, so that they are available for subsequent recall.
This is most useful in conjunction with Readline.

View file

@ -1,6 +1,6 @@
@set EDITION 4.1
@set VERSION 4.1
@set UPDATED 2000 January 19
@set UPDATE-MONTH January 2000
@set EDITION 4.2-beta
@set VERSION 4.2-beta
@set UPDATED 2001 Mar 12
@set UPDATE-MONTH Mar 2001
@set LASTCHANGE Wed Jan 19 12:16:30 EST 2000
@set LASTCHANGE Mon Mar 12 05:36:44 EST 2001

View file

@ -18,7 +18,7 @@ This document describes the GNU Readline Library, a utility which aids
in the consistency of user interface across discrete programs that need
to provide a command line interface.
Copyright (C) 1988-1999 Free Software Foundation, Inc.
Copyright (C) 1988-2001 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@ -73,7 +73,7 @@ except that this permission notice may be stated in a translation approved
by the Free Software Foundation.
@vskip 0pt plus 1filll
Copyright @copyright{} 1988-1999 Free Software Foundation, Inc.
Copyright @copyright{} 1988-2001 Free Software Foundation, Inc.
@end titlepage
@ifinfo

File diff suppressed because it is too large Load diff

View file

@ -10,7 +10,7 @@ use these features. There is a document entitled "readline.texinfo"
which contains both end-user and programmer documentation for the
GNU Readline Library.
Copyright (C) 1988-1999 Free Software Foundation, Inc.
Copyright (C) 1988-2000 Free Software Foundation, Inc.
Authored by Brian Fox and Chet Ramey.
@ -72,11 +72,11 @@ used by several different programs, including Bash.
The following paragraphs describe the notation used to represent
keystrokes.
The text @key{C-k} is read as `Control-K' and describes the character
The text @kbd{C-k} is read as `Control-K' and describes the character
produced when the @key{k} key is pressed while the Control key
is depressed.
The text @key{M-k} is read as `Meta-K' and describes the character
The text @kbd{M-k} is read as `Meta-K' and describes the character
produced when the Meta key (if you have one) is depressed, and the @key{k}
key is pressed.
The Meta key is labeled @key{ALT} on many keyboards.
@ -89,11 +89,11 @@ Compose key for typing accented characters.
If you do not have a Meta or @key{ALT} key, or another key working as
a Meta key, the identical keystroke can be generated by typing @key{ESC}
@i{first}, and then typing @key{k}.
@emph{first}, and then typing @key{k}.
Either process is known as @dfn{metafying} the @key{k} key.
The text @key{M-C-k} is read as `Meta-Control-k' and describes the
character produced by @dfn{metafying} @key{C-k}.
The text @kbd{M-C-k} is read as `Meta-Control-k' and describes the
character produced by @dfn{metafying} @kbd{C-k}.
In addition, several keys have their own names. Specifically,
@key{DEL}, @key{ESC}, @key{LFD}, @key{SPC}, @key{RET}, and @key{TAB} all
@ -115,8 +115,8 @@ as you type it in, allowing you to just fix your typo, and not forcing
you to retype the majority of the line. Using these editing commands,
you move the cursor to the place that needs correction, and delete or
insert the text of the corrections. Then, when you are satisfied with
the line, you simply press @key{RETURN}. You do not have to be at the
end of the line to press @key{RETURN}; the entire line is accepted
the line, you simply press @key{RET}. You do not have to be at the
end of the line to press @key{RET}; the entire line is accepted
regardless of the location of the cursor within the line.
@menu
@ -140,9 +140,9 @@ erase character to back up and delete the mistyped character.
Sometimes you may mistype a character, and
not notice the error until you have typed several other characters. In
that case, you can type @key{C-b} to move the cursor to the left, and then
that case, you can type @kbd{C-b} to move the cursor to the left, and then
correct your mistake. Afterwards, you can move the cursor to the right
with @key{C-f}.
with @kbd{C-f}.
When you add text in the middle of a line, you will notice that characters
to the right of the cursor are `pushed over' to make room for the text
@ -152,17 +152,17 @@ blank space created by the removal of the text. A list of the bare
essentials for editing the text of an input line follows.
@table @asis
@item @key{C-b}
@item @kbd{C-b}
Move back one character.
@item @key{C-f}
@item @kbd{C-f}
Move forward one character.
@item @key{DEL} or @key{Backspace}
Delete the character to the left of the cursor.
@item @key{C-d}
@item @kbd{C-d}
Delete the character underneath the cursor.
@item @w{Printing characters}
Insert the character into the line at the cursor.
@item @key{C-_} or @key{C-x C-u}
@item @kbd{C-_} or @kbd{C-x C-u}
Undo the last editing command. You can undo all the way back to an
empty line.
@end table
@ -170,7 +170,7 @@ empty line.
@noindent
(Depending on your configuration, the @key{Backspace} key be set to
delete the character to the left of the cursor and the @key{DEL} key set
to delete the character underneath the cursor, like @key{C-d}, rather
to delete the character underneath the cursor, like @kbd{C-d}, rather
than the character to the left of the cursor.)
@node Readline Movement Commands
@ -179,11 +179,11 @@ than the character to the left of the cursor.)
The above table describes the most basic keystrokes that you need
in order to do editing of the input line. For your convenience, many
other commands have been added in addition to @key{C-b}, @key{C-f},
@key{C-d}, and @key{DEL}. Here are some commands for moving more rapidly
other commands have been added in addition to @kbd{C-b}, @kbd{C-f},
@kbd{C-d}, and @key{DEL}. Here are some commands for moving more rapidly
about the line.
@table @key
@table @kbd
@item C-a
Move to the start of the line.
@item C-e
@ -196,7 +196,7 @@ Move backward a word.
Clear the screen, reprinting the current line at the top.
@end table
Notice how @key{C-f} moves forward a character, while @key{M-f} moves
Notice how @kbd{C-f} moves forward a character, while @kbd{M-f} moves
forward a word. It is a loose convention that control keystrokes
operate on characters while meta keystrokes operate on words.
@ -225,36 +225,36 @@ another line.
Here is the list of commands for killing text.
@table @key
@table @kbd
@item C-k
Kill the text from the current cursor position to the end of the line.
@item M-d
Kill from the cursor to the end of the current word, or, if between
words, to the end of the next word.
Word boundaries are the same as those used by @key{M-f}.
Word boundaries are the same as those used by @kbd{M-f}.
@item M-DEL
@item M-@key{DEL}
Kill from the cursor the start of the previous word, or, if between
words, to the start of the previous word.
Word boundaries are the same as those used by @key{M-b}.
Word boundaries are the same as those used by @kbd{M-b}.
@item C-w
Kill from the cursor to the previous whitespace. This is different than
@key{M-DEL} because the word boundaries differ.
@kbd{M-@key{DEL}} because the word boundaries differ.
@end table
Here is how to @dfn{yank} the text back into the line. Yanking
means to copy the most-recently-killed text from the kill buffer.
@table @key
@table @kbd
@item C-y
Yank the most recently killed text back into the buffer at the cursor.
@item M-y
Rotate the kill-ring, and yank the new top. You can only do this if
the prior command is @key{C-y} or @key{M-y}.
the prior command is @kbd{C-y} or @kbd{M-y}.
@end table
@node Readline Arguments
@ -272,7 +272,8 @@ digits before the command. If the first `digit' typed is a minus
sign (@samp{-}), then the sign of the argument will be negative. Once
you have typed one meta digit to get the argument started, you can type
the remainder of the digits, and then the command. For example, to give
the @key{C-d} command an argument of 10, you could type @samp{M-1 0 C-d}.
the @kbd{C-d} command an argument of 10, you could type @samp{M-1 0 C-d},
which will delete the next ten characters on the input line.
@node Searching
@subsection Searching for Commands in the History
@ -282,7 +283,7 @@ Readline provides commands for searching through the command history
(@pxref{Bash History Facilities})
@end ifset
for lines containing a specified string.
There are two search modes: @var{incremental} and @var{non-incremental}.
There are two search modes: @dfn{incremental} and @dfn{non-incremental}.
Incremental searches begin before the user has finished typing the
search string.
@ -291,23 +292,25 @@ the next entry from the history matching the string typed so far.
An incremental search requires only as many characters as needed to
find the desired history entry.
To search backward in the history for a particular string, type
@key{C-r}. Typing @key{C-s} searches forward through the history.
@kbd{C-r}. Typing @kbd{C-s} searches forward through the history.
The characters present in the value of the @code{isearch-terminators} variable
are used to terminate an incremental search.
If that variable has not been assigned a value, the @key{ESC} and
@key{C-J} characters will terminate an incremental search.
@key{C-g} will abort an incremental search and restore the original line.
@kbd{C-J} characters will terminate an incremental search.
@kbd{C-g} will abort an incremental search and restore the original line.
When the search is terminated, the history entry containing the
search string becomes the current line.
To find other matching entries in the history list, type @key{C-r} or
@key{C-s} as appropriate.
To find other matching entries in the history list, type @kbd{C-r} or
@kbd{C-s} as appropriate.
This will search backward or forward in the history for the next
entry matching the search string typed so far.
Any other key sequence bound to a Readline command will terminate
the search and execute that command.
For instance, a @key{RET} will terminate the search and accept
the line, thereby executing the command from the history list.
A movement command will terminate the search, make the last line found
the current line, and begin editing.
Non-incremental searches read the entire search string before starting
to search for matching history lines. The search string may be
@ -324,10 +327,10 @@ Any user can customize programs that use Readline by putting
commands in an @dfn{inputrc} file, conventionally in his home directory.
The name of this
@ifset BashFeatures
file is taken from the value of the shell variable @code{INPUTRC}. If
file is taken from the value of the shell variable @env{INPUTRC}. If
@end ifset
@ifclear BashFeatures
file is taken from the value of the environment variable @code{INPUTRC}. If
file is taken from the value of the environment variable @env{INPUTRC}. If
@end ifclear
that variable is unset, the default is @file{~/.inputrc}.
@ -359,7 +362,15 @@ denote variable settings and key bindings.
@item Variable Settings
You can modify the run-time behavior of Readline by
altering the values of variables in Readline
using the @code{set} command within the init file. Here is how to
using the @code{set} command within the init file.
The syntax is simple:
@example
set @var{variable} @var{value}
@end example
@noindent
Here, for example, is how to
change from the default Emacs-like key binding to use
@code{vi} line editing commands:
@ -367,6 +378,9 @@ change from the default Emacs-like key binding to use
set editing-mode vi
@end example
Variable names and values, where appropriate, are recognized without regard
to case.
@ifset BashFeatures
The @w{@code{bind -V}} command lists the current Readline variable names
and values. @xref{Bash Builtins}.
@ -375,6 +389,7 @@ and values. @xref{Bash Builtins}.
A great deal of run-time behavior is changeable with the following
variables.
@cindex variables, readline
@table @code
@item bell-style
@ -402,13 +417,14 @@ The number of possible completions that determines when the user is
asked whether he wants to see the list of possibilities. If the
number of possible completions is greater than this value,
Readline will ask the user whether or not he wishes to view
them; otherwise, they are simply listed. The default limit is
@code{100}.
them; otherwise, they are simply listed.
This variable must be set to an integer value greater than or equal to 0.
The default limit is @code{100}.
@item convert-meta
@vindex convert-meta
If set to @samp{on}, Readline will convert characters with the
eighth bit set to an ASCII key sequence by stripping the eighth
eighth bit set to an @sc{ascii} key sequence by stripping the eighth
bit and prefixing an @key{ESC} character, converting them to a
meta-prefixed key sequence. The default value is @samp{on}.
@ -448,7 +464,7 @@ this variable is set to @samp{off}.
@vindex input-meta
@vindex meta-flag
If set to @samp{on}, Readline will enable eight-bit input (it
will not strip the eighth bit from the characters it reads),
will not clear the eighth bit in the characters it reads),
regardless of what the terminal claims it can support. The
default value is @samp{off}. The name @code{meta-flag} is a
synonym for this variable.
@ -458,7 +474,7 @@ synonym for this variable.
The string of characters that should terminate an incremental search without
subsequently executing the character as a command (@pxref{Searching}).
If this variable has not been given a value, the characters @key{ESC} and
@key{C-J} will terminate an incremental search.
@kbd{C-J} will terminate an incremental search.
@item keymap
@vindex keymap
@ -469,6 +485,7 @@ Acceptable @code{keymap} names are
@code{emacs-meta},
@code{emacs-ctlx},
@code{vi},
@code{vi-move},
@code{vi-command}, and
@code{vi-insert}.
@code{vi} is equivalent to @code{vi-command}; @code{emacs} is
@ -520,11 +537,15 @@ want to change. The following sections contain tables of the command
name, the default keybinding, if any, and a short description of what
the command does.
Once you know the name of the command, simply place the name of the key
Once you know the name of the command, simply place on a line
in the init file the name of the key
you wish to bind the command to, a colon, and then the name of the
command on a line in the init file. The name of the key
can be expressed in different ways, depending on which is most
comfortable for you.
command. The name of the key
can be expressed in different ways, depending on what you find most
comfortable.
In addition to command names, readline allows keys to be bound
to a string that is inserted when the key is pressed (a @var{macro}).
@ifset BashFeatures
The @w{@code{bind -p}} command displays Readline function names and
@ -541,11 +562,28 @@ Meta-Rubout: backward-kill-word
Control-o: "> output"
@end example
In the above example, @key{C-u} is bound to the function
@code{universal-argument}, and @key{C-o} is bound to run the macro
In the above example, @kbd{C-u} is bound to the function
@code{universal-argument},
@kbd{M-DEL} is bound to the function @code{backward-kill-word}, and
@kbd{C-o} is bound to run the macro
expressed on the right hand side (that is, to insert the text
@samp{> output} into the line).
A number of symbolic character names are recognized while
processing this key binding syntax:
@var{DEL},
@var{ESC},
@var{ESCAPE},
@var{LFD},
@var{NEWLINE},
@var{RET},
@var{RETURN},
@var{RUBOUT},
@var{SPACE},
@var{SPC},
and
@var{TAB}.
@item @w{"@var{keyseq}": @var{function-name} or @var{macro}}
@var{keyseq} differs from @var{keyname} above in that strings
denoting an entire key sequence can be specified, by placing
@ -559,9 +597,9 @@ special character names are not recognized.
"\e[11~": "Function Key 1"
@end example
In the above example, @key{C-u} is bound to the function
In the above example, @kbd{C-u} is again bound to the function
@code{universal-argument} (just as it was in the first example),
@samp{@key{C-x} @key{C-r}} is bound to the function @code{re-read-init-file},
@samp{@kbd{C-x} @kbd{C-r}} is bound to the function @code{re-read-init-file},
and @samp{@key{ESC} @key{[} @key{1} @key{1} @key{~}} is bound to insert
the text @samp{Function Key 1}.
@ -606,10 +644,10 @@ horizontal tab
@item \v
vertical tab
@item \@var{nnn}
the character whose @code{ASCII} code is the octal value @var{nnn}
the character whose @sc{ascii} code is the octal value @var{nnn}
(one to three digits)
@item \x@var{nnn}
the character whose @code{ASCII} code is the hexadecimal value @var{nnn}
the character whose @sc{ascii} code is the hexadecimal value @var{nnn}
(one to three digits)
@end table
@ -619,7 +657,7 @@ Unquoted text is assumed to be a function name.
In the macro body, the backslash escapes described above are expanded.
Backslash will quote any other character in the macro text,
including @samp{"} and @samp{'}.
For example, the following binding will make @samp{C-x \}
For example, the following binding will make @samp{@kbd{C-x} \}
insert a single @samp{\} into the line:
@example
"\C-x\\": "\\"
@ -663,7 +701,8 @@ for instance.
@item application
The @var{application} construct is used to include
application-specific settings. Each program using the Readline
library sets the @var{application name}, and you can test for it.
library sets the @var{application name}, and you can test for
a particular value.
This could be used to bind key sequences to functions useful for
a specific program. For instance, the following command adds a
key sequence that quotes the current or previous word in Bash:
@ -686,6 +725,7 @@ the test fails.
@item $include
This directive takes a single filename as an argument and reads commands
and bindings from that file.
For example, the following directive reads from @file{/etc/inputrc}:
@example
$include /etc/inputrc
@end example
@ -694,7 +734,7 @@ $include /etc/inputrc
@node Sample Init File
@subsection Sample Init File
Here is an example of an inputrc file. This illustrates key
Here is an example of an @var{inputrc} file. This illustrates key
binding, variable assignment, and conditional syntax.
@example
@ -819,12 +859,12 @@ You can list your key bindings by executing
@w{@code{bind -P}} or, for a more terse format, suitable for an
@var{inputrc} file, @w{@code{bind -p}}. (@xref{Bash Builtins}.)
@end ifset
Command names without an accompanying key sequence are unbound by default.
In the following descriptions, @var{point} refers to the current cursor
position, and @var{mark} refers to a cursor position saved by the
In the following descriptions, @dfn{point} refers to the current cursor
position, and @dfn{mark} refers to a cursor position saved by the
@code{set-mark} command.
The text between the point and mark is referred to as the @var{region}.
The text between the point and mark is referred to as the @dfn{region}.
@node Commands For Moving
@subsection Commands For Moving
@ -862,25 +902,29 @@ Refresh the current line. By default, this is unbound.
@subsection Commands For Manipulating The History
@ftable @code
@item accept-line (Newline, Return)
@item accept-line (Newline or Return)
@ifset BashFeatures
Accept the line regardless of where the cursor is. If this line is
Accept the line regardless of where the cursor is.
If this line is
non-empty, add it to the history list according to the setting of
the @code{HISTCONTROL} and @code{HISTIGNORE} variables.
If this line was a history line, then restore the history line to its
original state.
the @env{HISTCONTROL} and @env{HISTIGNORE} variables.
If this line is a modified history line, then restore the history line
to its original state.
@end ifset
@ifclear BashFeatures
Accept the line regardless of where the cursor is. If this line is
non-empty, add it to the history list. If this line was a history
line, then restore the history line to its original state.
Accept the line regardless of where the cursor is.
If this line is
non-empty, it may be added to the history list for future recall with
@code{add_history()}.
If this line is a modified history line, the history line is restored
to its original state.
@end ifclear
@item previous-history (C-p)
Move `up' through the history list.
Move `back' through the history list, fetching the previous command.
@item next-history (C-n)
Move `down' through the history list.
Move `forward' through the history list, fetching the next command.
@item beginning-of-history (M-<)
Move to the first line in the history.
@ -920,12 +964,13 @@ is a non-incremental search. By default, this command is unbound.
@item yank-nth-arg (M-C-y)
Insert the first argument to the previous command (usually
the second word on the previous line). With an argument @var{n},
the second word on the previous line) at point.
With an argument @var{n},
insert the @var{n}th word from the previous command (the words
in the previous command begin with word 0). A negative argument
inserts the @var{n}th word from the end of the previous command.
@item yank-last-arg (M-., M-_)
@item yank-last-arg (M-. or M-_)
Insert last argument to the previous command (the last word of the
previous history entry). With an
argument, behave exactly like @code{yank-nth-arg}.
@ -939,10 +984,10 @@ list, inserting the last argument of each line in turn.
@ftable @code
@item delete-char (C-d)
Delete the character under the cursor. If the cursor is at the
Delete the character at point. If point is at the
beginning of the line, there are no characters in the line, and
the last character typed was not bound to @code{delete-char}, then
return @code{EOF}.
return @sc{eof}.
@item backward-delete-char (Rubout)
Delete the character behind the cursor. A numeric argument means
@ -953,16 +998,16 @@ Delete the character under the cursor, unless the cursor is at the
end of the line, in which case the character behind the cursor is
deleted. By default, this is not bound to a key.
@item quoted-insert (C-q, C-v)
@item quoted-insert (C-q or C-v)
Add the next character typed to the line verbatim. This is
how to insert key sequences like @key{C-q}, for example.
how to insert key sequences like @kbd{C-q}, for example.
@ifclear BashFeatures
@item tab-insert (M-TAB)
@item tab-insert (M-@key{TAB})
Insert a tab character.
@end ifclear
@item self-insert (a, b, A, 1, !, ...)
@item self-insert (a, b, A, 1, !, @dots{})
Insert yourself.
@item transpose-chars (C-t)
@ -1006,7 +1051,7 @@ Kill backward to the beginning of the line.
Kill backward from the cursor to the beginning of the current line.
@item kill-whole-line ()
Kill all characters on the current line, no matter point is.
Kill all characters on the current line, no matter where point is.
By default, this is unbound.
@item kill-word (M-d)
@ -1014,7 +1059,7 @@ Kill from point to the end of the current word, or if between
words, to the end of the next word.
Word boundaries are the same as @code{forward-word}.
@item backward-kill-word (M-DEL)
@item backward-kill-word (M-@key{DEL})
Kill the word behind point.
Word boundaries are the same as @code{backward-word}.
@ -1044,21 +1089,20 @@ The word boundaries are the same as @code{forward-word}.
By default, this command is unbound.
@item yank (C-y)
Yank the top of the kill ring into the buffer at the current
cursor position.
Yank the top of the kill ring into the buffer at point.
@item yank-pop (M-y)
Rotate the kill-ring, and yank the new top. You can only do this if
the prior command is yank or yank-pop.
the prior command is @code{yank} or @code{yank-pop}.
@end ftable
@node Numeric Arguments
@subsection Specifying Numeric Arguments
@ftable @code
@item digit-argument (M-0, M-1, ... M--)
@item digit-argument (@kbd{M-0}, @kbd{M-1}, @dots{} @kbd{M--})
Add this digit to the argument already accumulating, or start a new
argument. @key{M--} starts a negative argument.
argument. @kbd{M--} starts a negative argument.
@item universal-argument ()
This is another way to specify an argument.
@ -1079,13 +1123,9 @@ By default, this is not bound to a key.
@subsection Letting Readline Type For You
@ftable @code
@item complete (TAB)
Attempt to do completion on the text before the cursor. This is
application-specific. Generally, if you are typing a filename
argument, you can do filename completion; if you are typing a command,
you can do command completion; if you are typing in a symbol to GDB, you
can do symbol name completion; if you are typing in a variable to Bash,
you can do variable name completion, and so on.
@item complete (@key{TAB})
Attempt to perform completion on the text before point.
The actual completion performed is application-specific.
@ifset BashFeatures
Bash attempts completion treating the text as a variable (if the
text begins with @samp{$}), username (if the text begins with
@ -1093,9 +1133,12 @@ text begins with @samp{$}), username (if the text begins with
command (including aliases and functions) in turn. If none
of these produces a match, filename completion is attempted.
@end ifset
@ifclear BashFeatures
The default is filename completion.
@end ifclear
@item possible-completions (M-?)
List the possible completions of the text before the cursor.
List the possible completions of the text before point.
@item insert-completions (M-*)
Insert all completions of the text before point that would have
@ -1106,12 +1149,13 @@ Similar to @code{complete}, but replaces the word to be completed
with a single match from the list of possible completions.
Repeated execution of @code{menu-complete} steps through the list
of possible completions, inserting each match in turn.
At the end of the list of completions, the bell is rung and the
original text is restored.
At the end of the list of completions, the bell is rung
(subject to the setting of @code{bell-style})
and the original text is restored.
An argument of @var{n} moves @var{n} positions forward in the list
of matches; a negative argument may be used to move backward
through the list.
This command is intended to be bound to @code{TAB}, but is unbound
This command is intended to be bound to @key{TAB}, but is unbound
by default.
@item delete-char-or-list ()
@ -1164,7 +1208,7 @@ in that order.
List the possible completions of the text before point,
treating it as a command name.
@item dynamic-complete-history (M-TAB)
@item dynamic-complete-history (M-@key{TAB})
Attempt completion on the text before point, comparing
the text against lines from the history list for possible
completion matches.
@ -1211,12 +1255,12 @@ ring the terminal's bell (subject to the setting of
If the metafied character @var{x} is lowercase, run the command
that is bound to the corresponding uppercase character.
@item prefix-meta (ESC)
Make the next character typed be metafied. This is for keyboards
without a meta key. Typing @samp{ESC f} is equivalent to typing
@samp{M-f}.
@item prefix-meta (@key{ESC})
Metafy the next character typed. This is for keyboards
without a meta key. Typing @samp{@key{ESC} f} is equivalent to typing
@kbd{M-f}.
@item undo (C-_, C-x C-u)
@item undo (C-_ or C-x C-u)
Incremental undo, separately remembered for each line.
@item revert-line (M-r)
@ -1232,7 +1276,7 @@ command enough times to get back to the beginning.
Perform tilde expansion on the current word.
@item set-mark (C-@@)
Set the mark to the current point. If a
Set the mark to the point. If a
numeric argument is supplied, the mark is set to that position.
@item exchange-point-and-mark (C-x C-x)
@ -1271,7 +1315,7 @@ of an @var{inputrc} file. This command is unbound by default.
@item dump-macros ()
Print all of the Readline key sequences bound to macros and the
strings they ouput. If a numeric argument is supplied,
strings they output. If a numeric argument is supplied,
the output is formatted in such a way that it can be made part
of an @var{inputrc} file. This command is unbound by default.
@ -1305,7 +1349,7 @@ Perform alias expansion on the current line (@pxref{Aliases}).
@item history-and-alias-expand-line ()
Perform history and alias expansion on the current line.
@item insert-last-argument (M-., M-_)
@item insert-last-argument (M-. or M-_)
A synonym for @code{yank-last-arg}.
@item operate-and-get-next (C-o)
@ -1328,7 +1372,7 @@ been executed.
While the Readline library does not have a full set of @code{vi}
editing functions, it does contain enough to allow simple editing
of the line. The Readline @code{vi} mode behaves as specified in
the @sc{POSIX} 1003.2 standard.
the @sc{posix} 1003.2 standard.
@ifset BashFeatures
In order to switch interactively between @code{emacs} and @code{vi}
@ -1337,7 +1381,8 @@ commands (@pxref{The Set Builtin}).
@end ifset
@ifclear BashFeatures
In order to switch interactively between @code{emacs} and @code{vi}
editing modes, use the command M-C-j (toggle-editing-mode).
editing modes, use the command @kbd{M-C-j} (bound to emacs-editing-mode
when in @code{vi} mode and to vi-editing-mode in @code{emacs} mode).
@end ifclear
The Readline default is @code{emacs} mode.
@ -1374,20 +1419,20 @@ described above (@pxref{Commands For Completion}) is performed.
First, the actions specified by the compspec are used.
Only matches which are prefixed by the word being completed are
returned.
When the @samp{-f} or @samp{-d} option is used for filename or
directory name completion, the shell variable @code{FIGNORE} is
When the @option{-f} or @option{-d} option is used for filename or
directory name completion, the shell variable @env{FIGNORE} is
used to filter the matches.
@xref{Bash Variables}, for a description of @code{FIGNORE}.
@xref{Bash Variables}, for a description of @env{FIGNORE}.
Any completions specified by a filename expansion pattern to the
@samp{-G} option are generated next.
@option{-G} option are generated next.
The words generated by the pattern need not match the word being completed.
The @code{GLOBIGNORE} shell variable is not used to filter the matches,
but the @code{FIGNORE} shell variable is used.
The @env{GLOBIGNORE} shell variable is not used to filter the matches,
but the @env{FIGNORE} shell variable is used.
Next, the string specified as the argument to the @samp{-W} option
Next, the string specified as the argument to the @option{-W} option
is considered.
The string is first split using the characters in the @code{IFS}
The string is first split using the characters in the @env{IFS}
special variable as delimiters.
Shell quoting is honored.
Each word is then expanded using
@ -1400,12 +1445,12 @@ The results of the expansion are prefix-matched against the word being
completed, and the matching words become the possible completions.
After these matches have been generated, any shell function or command
specified with the @samp{-F} and @samp{-C} options is invoked.
When the command or function is invoked, the @code{COMP_LINE} and
@code{COMP_POINT} variables are assigned values as described above
specified with the @option{-F} and @option{-C} options is invoked.
When the command or function is invoked, the @env{COMP_LINE} and
@env{COMP_POINT} variables are assigned values as described above
(@pxref{Bash Variables}).
If a shell function is being invoked, the @code{COMP_WORDS} and
@code{COMP_CWORD} variables are also set.
If a shell function is being invoked, the @env{COMP_WORDS} and
@env{COMP_CWORD} variables are also set.
When the function or command is invoked, the first argument is the
name of the command whose arguments are being completed, the
second argument is the word being completed, and the third argument
@ -1414,21 +1459,21 @@ No filtering of the generated completions against the word being completed
is performed; the function or command has complete freedom in generating
the matches.
Any function specified with @samp{-F} is invoked first.
Any function specified with @option{-F} is invoked first.
The function may use any of the shell facilities, including the
@code{compgen} builtin described below
(@pxref{Programmable Completion Builtins}), to generate the matches.
It must put the possible completions in the @code{COMPREPLY} array
It must put the possible completions in the @env{COMPREPLY} array
variable.
Next, any command specified with the @samp{-C} option is invoked
Next, any command specified with the @option{-C} option is invoked
in an environment equivalent to command substitution.
It should print a list of completions, one per line, to
the standard output.
Backslash may be used to escape a newline, if necessary.
After all of the possible completions are generated, any filter
specified with the @samp{-X} option is applied to the list.
specified with the @option{-X} option is applied to the list.
The filter is a pattern as used for pathname expansion; a @samp{&}
in the pattern is replaced with the text of the word being completed.
A literal @samp{&} may be escaped with a backslash; the backslash
@ -1437,15 +1482,22 @@ Any completion that matches the pattern will be removed from the list.
A leading @samp{!} negates the pattern; in this case any completion
not matching the pattern will be removed.
Finally, any prefix and suffix specified with the @samp{-P} and @samp{-S}
Finally, any prefix and suffix specified with the @option{-P} and @option{-S}
options are added to each member of the completion list, and the result is
returned to the Readline completion code as the list of possible
completions.
If a compspec is found, whatever it generates is returned to the completion
code as the full set of possible completions.
The default Bash completions are not attempted, and the Readline
default of filename completion is disabled.
If the previously-applied actions do not generate any matches, and the
@option{-o dirnames} option was supplied to @code{complete} when the
compspec was defined, directory name completion is attempted.
By default, if a compspec is found, whatever it generates is returned to
the completion code as the full set of possible completions.
The default Bash completions are not attempted, and the Readline default
of filename completion is disabled.
If the @option{-o default} option was supplied to @code{complete} when the
compspec was defined, Readline's default completion will be performed
if the compspec generates no matches.
@node Programmable Completion Builtins
@section Programmable Completion Builtins
@ -1464,9 +1516,9 @@ facilities.
Generate possible completion matches for @var{word} according to
the @var{option}s, which may be any option accepted by the
@code{complete}
builtin with the exception of @samp{-p} and @samp{-r}, and write
builtin with the exception of @option{-p} and @option{-r}, and write
the matches to the standard output.
When using the @samp{-F} or @samp{-C} options, the various shell variables
When using the @option{-F} or @option{-C} options, the various shell variables
set by the programmable completion facilities, while available, will not
have useful values.
@ -1482,17 +1534,17 @@ matches were generated.
@item complete
@btindex complete
@example
@code{complete [-abcdefjkvu] [-A @var{action}] [-G @var{globpat}] [-W @var{wordlist}]
@code{complete [-abcdefjkvu] [-o @var{comp-option}] [-A @var{action}] [-G @var{globpat}] [-W @var{wordlist}]
[-P @var{prefix}] [-S @var{suffix}] [-X @var{filterpat}] [-F @var{function}]
[-C @var{command}] @var{name} [@var{name} @dots{}]}
@code{complete -pr [@var{name} @dots{}]}
@end example
Specify how arguments to each @var{name} should be completed.
If the @samp{-p} option is supplied, or if no options are supplied, existing
If the @option{-p} option is supplied, or if no options are supplied, existing
completion specifications are printed in a way that allows them to be
reused as input.
The @samp{-r} option removes a completion specification for
The @option{-r} option removes a completion specification for
each @var{name}, or, if no @var{name}s are supplied, all
completion specifications.
@ -1500,19 +1552,40 @@ The process of applying these completion specifications when word completion
is attempted is described above (@pxref{Programmable Completion}).
Other options, if specified, have the following meanings.
The arguments to the @samp{-G}, @samp{-W}, and @samp{-X} options
(and, if necessary, the @samp{-P} and @samp{-S} options)
The arguments to the @option{-G}, @option{-W}, and @option{-X} options
(and, if necessary, the @option{-P} and @option{-S} options)
should be quoted to protect them from expansion before the
@code{complete} builtin is invoked.
@table @code
@item -o @var{comp-option}
The @var{comp-option} controls several aspects of the compspec's behavior
beyond the simple generation of completions.
@var{comp-option} may be one of:
@table @code
@item default
Use readline's default completion if the compspec generates no matches.
@item dirnames
Perform directory name completion if the compspec generates no matches.
@item filenames
Tell Readline that the compspec generates filenames, so it can perform any
filename\-specific processing (like adding a slash to directory names or
suppressing trailing spaces). This option is intended to be used with
shell functions specified with @option{-F}.
@end table
@item -A @var{action}
The @var{action} may be one of the following to generate a list of possible
completions:
@table @code
@item alias
Alias names. May also be specified as @samp{-a}.
Alias names. May also be specified as @option{-a}.
@item arrayvar
Array variable names.
@ -1521,13 +1594,13 @@ Array variable names.
Readline key binding names (@pxref{Bindable Readline Commands}).
@item builtin
Names of shell builtin commands. May also be specified as @samp{-b}.
Names of shell builtin commands. May also be specified as @option{-b}.
@item command
Command names. May also be specified as @samp{-c}.
Command names. May also be specified as @option{-c}.
@item directory
Directory names. May also be specified as @samp{-d}.
Directory names. May also be specified as @option{-d}.
@item disabled
Names of disabled shell builtins.
@ -1536,10 +1609,10 @@ Names of disabled shell builtins.
Names of enabled shell builtins.
@item export
Names of exported shell variables. May also be specified as @samp{-e}.
Names of exported shell variables. May also be specified as @option{-e}.
@item file
File names. May also be specified as @samp{-f}.
File names. May also be specified as @option{-f}.
@item function
Names of shell functions.
@ -1549,19 +1622,19 @@ Help topics as accepted by the @code{help} builtin (@pxref{Bash Builtins}).
@item hostname
Hostnames, as taken from the file specified by the
@code{HOSTFILE} shell variable (@pxref{Bash Variables}).
@env{HOSTFILE} shell variable (@pxref{Bash Variables}).
@item job
Job names, if job control is active. May also be specified as @samp{-j}.
Job names, if job control is active. May also be specified as @option{-j}.
@item keyword
Shell reserved words. May also be specified as @samp{-k}.
Shell reserved words. May also be specified as @option{-k}.
@item running
Names of running jobs, if job control is active.
@item setopt
Valid arguments for the @samp{-o} option to the @code{set} builtin
Valid arguments for the @option{-o} option to the @code{set} builtin
(@pxref{The Set Builtin}).
@item shopt
@ -1575,10 +1648,10 @@ Signal names.
Names of stopped jobs, if job control is active.
@item user
User names. May also be specified as @samp{-u}.
User names. May also be specified as @option{-u}.
@item variable
Names of all shell variables. May also be specified as @samp{-v}.
Names of all shell variables. May also be specified as @option{-v}.
@end table
@item -G @var{globpat}
@ -1587,7 +1660,7 @@ the possible completions.
@item -W @var{wordlist}
The @var{wordlist} is split using the characters in the
@code{IFS} special variable as delimiters, and each resultant word
@env{IFS} special variable as delimiters, and each resultant word
is expanded.
The possible completions are the members of the resultant list which
match the word being completed.
@ -1600,7 +1673,7 @@ used as the possible completions.
The shell function @var{function} is executed in the current shell
environment.
When it finishes, the possible completions are retrieved from the value
of the @code{COMPREPLY} array variable.
of the @env{COMPREPLY} array variable.
@item -X @var{filterpat}
@var{filterpat} is a pattern as used for filename expansion.
@ -1620,7 +1693,7 @@ after all other options have been applied.
@end table
The return value is true unless an invalid option is supplied, an option
other than @samp{-p} or @samp{-r} is supplied without a @var{name}
other than @option{-p} or @option{-r} is supplied without a @var{name}
argument, an attempt is made to remove a completion specification for
a @var{name} for which no specification exists, or
an error occurs adding a completion specification.

View file

@ -10,14 +10,14 @@
@ifinfo
@dircategory Libraries
@direntry
* Readline: (readline). The GNU readline library API
* RLuserman: (rluserman). The GNU readline library User's Manual.
@end direntry
This document describes the end user interface of the GNU Readline Library,
a utility which aids in the consistency of user interface across discrete
programs that need to provide a command line interface.
Copyright (C) 1988-1999 Free Software Foundation, Inc.
Copyright (C) 1988-2001 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@ -72,7 +72,7 @@ except that this permission notice may be stated in a translation approved
by the Free Software Foundation.
@vskip 0pt plus 1filll
Copyright @copyright{} 1988-1999 Free Software Foundation, Inc.
Copyright @copyright{} 1988-2001 Free Software Foundation, Inc.
@end titlepage
@ifinfo

File diff suppressed because it is too large Load diff

View file

@ -153,6 +153,8 @@ process_line(char *line)
} else {
fprintf(stderr, "|%s|\n", line);
}
free (line);
}
int

View file

@ -41,15 +41,22 @@
extern char *xmalloc ();
/* The names of functions that actually do the manipulation. */
int com_list (), com_view (), com_rename (), com_stat (), com_pwd ();
int com_delete (), com_help (), com_cd (), com_quit ();
int com_list __P((char *));
int com_view __P((char *));
int com_rename __P((char *));
int com_stat __P((char *));
int com_pwd __P((char *));
int com_delete __P((char *));
int com_help __P((char *));
int com_cd __P((char *));
int com_quit __P((char *));
/* A structure which contains information on the commands this program
can understand. */
typedef struct {
char *name; /* User printable name of the function. */
Function *func; /* Function to call to do the job. */
rl_icpfunc_t *func; /* Function to call to do the job. */
char *doc; /* Documentation for this function. */
} COMMAND;
@ -65,7 +72,7 @@ COMMAND commands[] = {
{ "rename", com_rename, "Rename FILE to NEWNAME" },
{ "stat", com_stat, "Print out statistics on FILE" },
{ "view", com_view, "View the contents of FILE" },
{ (char *)NULL, (Function *)NULL, (char *)NULL }
{ (char *)NULL, (rl_icpfunc_t *)NULL, (char *)NULL }
};
/* Forward declarations. */
@ -205,8 +212,8 @@ stripwhite (string)
/* */
/* **************************************************************** */
char *command_generator ();
char **fileman_completion ();
char *command_generator __P((const char *, int));
char **fileman_completion __P((const char *, int, int));
/* Tell the GNU Readline library how to complete. We want to try to complete
on command names if this is the first word in the line, or on filenames
@ -217,7 +224,7 @@ initialize_readline ()
rl_readline_name = "FileMan";
/* Tell the completer that we want a crack first. */
rl_attempted_completion_function = (CPPFunction *)fileman_completion;
rl_attempted_completion_function = fileman_completion;
}
/* Attempt to complete on the contents of TEXT. START and END bound the
@ -227,7 +234,7 @@ initialize_readline ()
or NULL if there aren't any. */
char **
fileman_completion (text, start, end)
char *text;
const char *text;
int start, end;
{
char **matches;
@ -238,7 +245,7 @@ fileman_completion (text, start, end)
to complete. Otherwise it is the name of a file in the current
directory. */
if (start == 0)
matches = completion_matches (text, command_generator);
matches = rl_completion_matches (text, command_generator);
return (matches);
}
@ -248,7 +255,7 @@ fileman_completion (text, start, end)
start at the top of the list. */
char *
command_generator (text, state)
char *text;
const char *text;
int state;
{
static int list_index, len;

View file

@ -1,4 +1,14 @@
main ()
#include <stdio.h>
#ifdef READLINE_LIBRARY
# include "history.h"
#else
# include <readline/history.h>
#endif
main (argc, argv)
int argc;
char **argv;
{
char line[1024], *t;
int len, done = 0;

View file

@ -3,10 +3,9 @@
#include <stdio.h>
#include <readline/readline.h>
/* **************************************************************** */
/* */
* How to Emulate gets () */
/* How to Emulate gets () */
/* */
/* **************************************************************** */
@ -82,13 +81,12 @@ invert_case_line (count, key)
for (; start != end; start += direction)
{
if (uppercase_p (rl_line_buffer[start]))
rl_line_buffer[start] = to_lower (rl_line_buffer[start]);
else if (lowercase_p (rl_line_buffer[start]))
rl_line_buffer[start] = to_upper (rl_line_buffer[start]);
if (_rl_uppercase_p (rl_line_buffer[start]))
rl_line_buffer[start] = _rl_to_lower (rl_line_buffer[start]);
else if (_rl_lowercase_p (rl_line_buffer[start]))
rl_line_buffer[start] = _rl_to_upper (rl_line_buffer[start]);
}
/* Move point to on top of the last character changed. */
rl_point = end - direction;
}

View file

@ -38,7 +38,7 @@ set_deftext ()
{
rl_insert_text (deftext);
deftext = (char *)NULL;
rl_startup_hook = (Function *)NULL;
rl_startup_hook = (rl_hook_func_t *)NULL;
}
return 0;
}
@ -126,6 +126,6 @@ main (argc, argv)
if (temp == 0)
exit (1);
puts (temp);
printf ("%s\n", temp);
exit (0);
}

View file

@ -46,7 +46,7 @@ typedef int QSFUNC (const void *, const void *);
typedef int QSFUNC ();
#endif
extern int _rl_qsort_string_compare ();
extern int _rl_qsort_string_compare __P((char **, char **));
FUNMAP **funmap;
static int funmap_size;
@ -108,7 +108,7 @@ static FUNMAP default_funmap[] = {
{ "non-incremental-reverse-search-history", rl_noninc_reverse_search },
{ "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
{ "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
#ifdef __CYGWIN32__
#ifdef __CYGWIN__
{ "paste-from-clipboard", rl_paste_from_clipboard },
#endif
{ "possible-completions", rl_possible_completions },
@ -142,7 +142,6 @@ static FUNMAP default_funmap[] = {
{ "vi-arg-digit", rl_vi_arg_digit },
{ "vi-back-to-indent", rl_vi_back_to_indent },
{ "vi-bWord", rl_vi_bWord },
{ "vi-bracktype", rl_vi_bracktype },
{ "vi-bword", rl_vi_bword },
{ "vi-change-case", rl_vi_change_case },
{ "vi-change-char", rl_vi_change_char },
@ -182,13 +181,13 @@ static FUNMAP default_funmap[] = {
{ "vi-yank-to", rl_vi_yank_to },
#endif /* VI_MODE */
{(char *)NULL, (Function *)NULL }
{(char *)NULL, (rl_command_func_t *)NULL }
};
int
rl_add_funmap_entry (name, function)
char *name;
Function *function;
const char *name;
rl_command_func_t *function;
{
if (funmap_entry + 2 >= funmap_size)
{
@ -225,21 +224,21 @@ rl_initialize_funmap ()
/* Produce a NULL terminated array of known function names. The array
is sorted. The array itself is allocated, but not the strings inside.
You should free () the array when you done, but not the pointrs. */
char **
const char **
rl_funmap_names ()
{
char **result;
const char **result;
int result_size, result_index;
/* Make sure that the function map has been initialized. */
rl_initialize_funmap ();
for (result_index = result_size = 0, result = (char **)NULL; funmap[result_index]; result_index++)
for (result_index = result_size = 0, result = (const char **)NULL; funmap[result_index]; result_index++)
{
if (result_index + 2 > result_size)
{
result_size += 20;
result = (char **)xrealloc (result, result_size * sizeof (char *));
result = (const char **)xrealloc (result, result_size * sizeof (char *));
}
result[result_index] = funmap[result_index]->name;
@ -249,12 +248,3 @@ rl_funmap_names ()
qsort (result, result_index, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
return (result);
}
/* Things that mean `Control'. */
char *possible_control_prefixes[] = {
"Control-", "C-", "CTRL-", (char *)NULL
};
char *possible_meta_prefixes[] = {
"Meta", "M-", (char *)NULL
};

View file

@ -56,6 +56,8 @@
#define HISTORY_WORD_DELIMITERS " \t\n;&()|<>"
#define HISTORY_QUOTE_CHARACTERS "\"'`"
typedef int _hist_search_func_t __P((const char *, int));
static char error_pointer;
static char *subst_lhs;
@ -91,9 +93,12 @@ char *history_no_expand_chars = " \t\n\r=";
The default is 0. */
int history_quotes_inhibit_expansion = 0;
/* Used to split words by history_tokenize_internal. */
char *history_word_delimiters = HISTORY_WORD_DELIMITERS;
/* If set, this points to a function that is called to verify that a
particular history expansion should be performed. */
Function *history_inhibit_expansion_function;
rl_linebuf_func_t *history_inhibit_expansion_function;
/* **************************************************************** */
/* */
@ -122,7 +127,7 @@ static char *search_match;
line = get_history_event ("!echo:p", &index, 0); */
char *
get_history_event (string, caller_index, delimiting_quote)
char *string;
const char *string;
int *caller_index;
int delimiting_quote;
{
@ -130,7 +135,7 @@ get_history_event (string, caller_index, delimiting_quote)
register char c;
HIST_ENTRY *entry;
int which, sign, local_index, substring_okay;
Function *search_func;
_hist_search_func_t *search_func;
char *temp;
/* The event can be specified in a number of ways.
@ -340,7 +345,8 @@ hist_error(s, start, current, errtype)
char *s;
int start, current, errtype;
{
char *temp, *emsg;
char *temp;
const char *emsg;
int ll, elen;
ll = current - start;
@ -622,7 +628,7 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
case '&':
case 's':
{
char *new_event, *t;
char *new_event;
int delimiter, failed, si, l_temp;
if (c == 's')
@ -741,7 +747,7 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
char *x;
if (want_quotes == 'q')
x = single_quote (temp);
x = sh_single_quote (temp);
else if (want_quotes == 'x')
x = quote_breaks (temp);
else
@ -816,6 +822,9 @@ history_expand (hstring, output)
/* Used when adding the string. */
char *temp;
if (output == 0)
return 0;
/* Setting the history expansion character to 0 inhibits all
history expansion. */
if (history_expansion_char == 0)
@ -865,7 +874,7 @@ history_expand (hstring, output)
history expansion performed on it.
Skip the rest of the line and break out of the loop. */
if (history_comment_char && string[i] == history_comment_char &&
(i == 0 || member (string[i - 1], HISTORY_WORD_DELIMITERS)))
(i == 0 || member (string[i - 1], history_word_delimiters)))
{
while (string[i])
i++;
@ -963,7 +972,7 @@ history_expand (hstring, output)
}
case -2: /* history_comment_char */
if (i == 0 || member (string[i - 1], HISTORY_WORD_DELIMITERS))
if (i == 0 || member (string[i - 1], history_word_delimiters))
{
temp = xmalloc (l - i + 1);
strcpy (temp, string + i);
@ -1151,7 +1160,7 @@ get_history_word_specifier (spec, from, caller_index)
char *
history_arg_extract (first, last, string)
int first, last;
char *string;
const char *string;
{
register int i, len;
char *result;
@ -1217,13 +1226,18 @@ history_arg_extract (first, last, string)
*INDP. */
static char **
history_tokenize_internal (string, wind, indp)
char *string;
const char *string;
int wind, *indp;
{
char **result;
register int i, start, result_index, size;
int len, delimiter;
/* If we're searching for a string that's not part of a word (e.g., " "),
make sure we set *INDP to a reasonable value. */
if (indp && wind != -1)
*indp = -1;
/* Get a token, and stuff it into RESULT. The tokens are split
exactly where the shell would split them. */
for (i = result_index = size = 0, result = (char **)NULL; string[i]; )
@ -1298,7 +1312,7 @@ history_tokenize_internal (string, wind, indp)
continue;
}
if (!delimiter && (member (string[i], HISTORY_WORD_DELIMITERS)))
if (!delimiter && (member (string[i], history_word_delimiters)))
break;
if (!delimiter && member (string[i], HISTORY_QUOTE_CHARACTERS))
@ -1328,7 +1342,7 @@ history_tokenize_internal (string, wind, indp)
parsed out of STRING. */
char **
history_tokenize (string)
char *string;
const char *string;
{
return (history_tokenize_internal (string, -1, (int *)NULL));
}
@ -1345,7 +1359,7 @@ history_find_word (line, ind)
int i, wind;
words = history_tokenize_internal (line, ind, &wind);
if (wind == -1)
if (wind == -1 || words == 0)
return ((char *)NULL);
s = words[wind];
for (i = 0; i < wind; i++)

View file

@ -84,9 +84,10 @@ extern int errno;
filename to read_history (), or write_history (). */
static char *
history_filename (filename)
char *filename;
const char *filename;
{
char *return_val, *home;
char *return_val;
const char *home;
int home_len;
return_val = filename ? savestring (filename) : (char *)NULL;
@ -94,7 +95,7 @@ history_filename (filename)
if (return_val)
return (return_val);
home = get_env_value ("HOME");
home = sh_get_env_value ("HOME");
if (home == 0)
{
@ -121,7 +122,7 @@ history_filename (filename)
successful, or errno if not. */
int
read_history (filename)
char *filename;
const char *filename;
{
return (read_history_range (filename, 0, -1));
}
@ -133,7 +134,7 @@ read_history (filename)
~/.history. Returns 0 if successful, or errno if not. */
int
read_history_range (filename, from, to)
char *filename;
const char *filename;
int from, to;
{
register int line_start, line_end;
@ -221,14 +222,15 @@ read_history_range (filename, from, to)
}
/* Truncate the history file FNAME, leaving only LINES trailing lines.
If FNAME is NULL, then use ~/.history. */
If FNAME is NULL, then use ~/.history. Returns 0 on success, errno
on failure. */
int
history_truncate_file (fname, lines)
char *fname;
const char *fname;
int lines;
{
register int i;
int file, chars_read;
int file, chars_read, rv;
char *buffer, *filename;
struct stat finfo;
size_t file_size;
@ -236,13 +238,27 @@ history_truncate_file (fname, lines)
buffer = (char *)NULL;
filename = history_filename (fname);
file = open (filename, O_RDONLY|O_BINARY, 0666);
if (file == -1 || fstat (file, &finfo) == -1)
goto truncate_exit;
rv = 0;
/* Don't try to truncate non-regular files. */
if (S_ISREG(finfo.st_mode) == 0)
goto truncate_exit;
if (file == -1 || fstat (file, &finfo) == -1)
{
rv = errno;
if (file != -1)
close (file);
goto truncate_exit;
}
if (S_ISREG (finfo.st_mode) == 0)
{
close (file);
#ifdef EFTYPE
rv = EFTYPE;
#else
rv = EINVAL;
#endif
goto truncate_exit;
}
file_size = (size_t)finfo.st_size;
@ -251,7 +267,11 @@ history_truncate_file (fname, lines)
{
close (file);
#if defined (EFBIG)
errno = EFBIG;
rv = errno = EFBIG;
#elif defined (EOVERFLOW)
rv = errno = EOVERFLOW;
#else
rv = errno = EINVAL;
#endif
goto truncate_exit;
}
@ -261,7 +281,10 @@ history_truncate_file (fname, lines)
close (file);
if (chars_read <= 0)
goto truncate_exit;
{
rv = (chars_read < 0) ? errno : 0;
goto truncate_exit;
}
/* Count backwards from the end of buffer until we have passed
LINES lines. */
@ -302,7 +325,7 @@ history_truncate_file (fname, lines)
FREE (buffer);
free (filename);
return 0;
return rv;
}
/* Workhorse function for writing history. Writes NELEMENT entries
@ -310,15 +333,16 @@ history_truncate_file (fname, lines)
wish to replace FILENAME with the entries. */
static int
history_do_write (filename, nelements, overwrite)
char *filename;
const char *filename;
int nelements, overwrite;
{
register int i;
char *output;
int file, mode;
int file, mode, rv;
mode = overwrite ? O_WRONLY|O_CREAT|O_TRUNC|O_BINARY : O_WRONLY|O_APPEND|O_BINARY;
output = history_filename (filename);
rv = 0;
if ((file = open (output, mode, 0600)) == -1)
{
@ -352,7 +376,8 @@ history_do_write (filename, nelements, overwrite)
buffer[j++] = '\n';
}
write (file, buffer, buffer_size);
if (write (file, buffer, buffer_size) < 0)
rv = errno;
free (buffer);
}
@ -360,7 +385,7 @@ history_do_write (filename, nelements, overwrite)
FREE (output);
return (0);
return (rv);
}
/* Append NELEMENT entries to FILENAME. The entries appended are from
@ -368,7 +393,7 @@ history_do_write (filename, nelements, overwrite)
int
append_history (nelements, filename)
int nelements;
char *filename;
const char *filename;
{
return (history_do_write (filename, nelements, HISTORY_APPEND));
}
@ -378,7 +403,7 @@ append_history (nelements, filename)
are as in read_history ().*/
int
write_history (filename)
char *filename;
const char *filename;
{
return (history_do_write (filename, history_length, HISTORY_OVERWRITE));
}

View file

@ -22,15 +22,6 @@
#if !defined (_HISTLIB_H_)
#define _HISTLIB_H_
/* Function pointers can be declared as (Function *)foo. */
#if !defined (_FUNCTION_DEF)
# define _FUNCTION_DEF
typedef int Function ();
typedef void VFunction ();
typedef char *CPFunction ();
typedef char **CPPFunction ();
#endif /* _FUNCTION_DEF */
#if !defined (STREQ)
#define STREQ(a, b) (((a)[0] == (b)[0]) && (strcmp ((a), (b)) == 0))
#define STREQN(a, b, n) (((n) == 0) ? (1) \

View file

@ -73,7 +73,8 @@ static int history_stifled;
/* If HISTORY_STIFLED is non-zero, then this is the maximum number of
entries to remember. */
int max_input_history;
int history_max_entries;
int max_input_history; /* backwards compatibility */
/* The current location of the interactive history pointer. Just makes
life easier for outside callers. */
@ -134,9 +135,7 @@ history_total_bytes ()
{
register int i, result;
result = 0;
for (i = 0; the_history && the_history[i]; i++)
for (i = result = 0; the_history && the_history[i]; i++)
result += strlen (the_history[i]->line);
return (result);
@ -217,16 +216,16 @@ history_get (offset)
is set to NULL. */
void
add_history (string)
char *string;
const char *string;
{
HIST_ENTRY *temp;
if (history_stifled && (history_length == max_input_history))
if (history_stifled && (history_length == history_max_entries))
{
register int i;
/* If the history is stifled, and history_length is zero,
and it equals max_input_history, we don't save items. */
and it equals history_max_entries, we don't save items. */
if (history_length == 0)
return;
@ -277,15 +276,15 @@ add_history (string)
HIST_ENTRY *
replace_history_entry (which, line, data)
int which;
char *line;
const char *line;
histdata_t data;
{
HIST_ENTRY *temp = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY));
HIST_ENTRY *old_value;
HIST_ENTRY *temp, *old_value;
if (which >= history_length)
return ((HIST_ENTRY *)NULL);
temp = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY));
old_value = the_history[which];
temp->line = savestring (line);
@ -303,12 +302,12 @@ remove_history (which)
int which;
{
HIST_ENTRY *return_value;
register int i;
if (which >= history_length || !history_length)
return_value = (HIST_ENTRY *)NULL;
else
{
register int i;
return_value = the_history[which];
for (i = which; i < history_length; i++)
@ -325,13 +324,13 @@ void
stifle_history (max)
int max;
{
register int i, j;
if (max < 0)
max = 0;
if (history_length > max)
{
register int i, j;
/* This loses because we cannot free the data. */
for (i = 0, j = history_length - max; i < j; i++)
{
@ -347,7 +346,7 @@ stifle_history (max)
}
history_stifled = 1;
max_input_history = max;
max_input_history = history_max_entries = max;
}
/* Stop stifling the history. This returns the previous amount the
@ -359,10 +358,10 @@ unstifle_history ()
if (history_stifled)
{
history_stifled = 0;
return (-max_input_history);
return (-history_max_entries);
}
return (max_input_history);
return (history_max_entries);
}
int

View file

@ -28,16 +28,10 @@ extern "C" {
#if defined READLINE_LIBRARY
# include "rlstdc.h"
# include "rltypedefs.h"
#else
# include <readline/rlstdc.h>
#endif
#if !defined (_FUNCTION_DEF)
# define _FUNCTION_DEF
typedef int Function ();
typedef void VFunction ();
typedef char *CPFunction ();
typedef char **CPPFunction ();
# include <readline/rltypedefs.h>
#endif
#ifdef __STDC__
@ -80,7 +74,7 @@ extern void history_set_history_state __P((HISTORY_STATE *));
/* Place STRING at the end of the history list.
The associated data field (if any) is set to NULL. */
extern void add_history __P((char *));
extern void add_history __P((const char *));
/* A reasonably useless function, only here for completeness. WHICH
is the magic number that tells us which element to delete. The
@ -90,7 +84,7 @@ extern HIST_ENTRY *remove_history __P((int));
/* Make the history entry at WHICH have LINE and DATA. This returns
the old entry so you can dispose of the data. In the case of an
invalid WHICH, a NULL pointer is returned. */
extern HIST_ENTRY *replace_history_entry __P((int, char *, histdata_t));
extern HIST_ENTRY *replace_history_entry __P((int, const char *, histdata_t));
/* Clear the history list and start over. */
extern void clear_history __P((void));
@ -152,45 +146,45 @@ extern HIST_ENTRY *next_history __P((void));
current_history () is the history entry, and the value of this function
is the offset in the line of that history entry that the string was
found in. Otherwise, nothing is changed, and a -1 is returned. */
extern int history_search __P((char *, int));
extern int history_search __P((const char *, int));
/* Search the history for STRING, starting at history_offset.
The search is anchored: matching lines must begin with string.
DIRECTION is as in history_search(). */
extern int history_search_prefix __P((char *, int));
extern int history_search_prefix __P((const char *, int));
/* Search for STRING in the history list, starting at POS, an
absolute index into the list. DIR, if negative, says to search
backwards from POS, else forwards.
Returns the absolute index of the history element where STRING
was found, or -1 otherwise. */
extern int history_search_pos __P((char *, int, int));
extern int history_search_pos __P((const char *, int, int));
/* Managing the history file. */
/* Add the contents of FILENAME to the history list, a line at a time.
If FILENAME is NULL, then read from ~/.history. Returns 0 if
successful, or errno if not. */
extern int read_history __P((char *));
extern int read_history __P((const char *));
/* Read a range of lines from FILENAME, adding them to the history list.
Start reading at the FROM'th line and end at the TO'th. If FROM
is zero, start at the beginning. If TO is less than FROM, read
until the end of the file. If FILENAME is NULL, then read from
~/.history. Returns 0 if successful, or errno if not. */
extern int read_history_range __P((char *, int, int));
extern int read_history_range __P((const char *, int, int));
/* Write the current history to FILENAME. If FILENAME is NULL,
then write the history list to ~/.history. Values returned
are as in read_history (). */
extern int write_history __P((char *));
extern int write_history __P((const char *));
/* Append NELEMENT entries to FILENAME. The entries appended are from
the end of the list minus NELEMENTs up to the end of the list. */
extern int append_history __P((int, char *));
extern int append_history __P((int, const char *));
/* Truncate the history file, leaving only the last NLINES lines. */
extern int history_truncate_file __P((char *, int));
extern int history_truncate_file __P((const char *, int));
/* History expansion. */
@ -211,7 +205,7 @@ extern int history_expand __P((char *, char **));
/* Extract a string segment consisting of the FIRST through LAST
arguments present in STRING. Arguments are broken up as in
the shell. */
extern char *history_arg_extract __P((int, int, char *));
extern char *history_arg_extract __P((int, int, const char *));
/* Return the text of the history event beginning at the current
offset into STRING. Pass STRING with *INDEX equal to the
@ -219,27 +213,31 @@ extern char *history_arg_extract __P((int, int, char *));
DELIMITING_QUOTE is a character that is allowed to end the string
specification for what to search for in addition to the normal
characters `:', ` ', `\t', `\n', and sometimes `?'. */
extern char *get_history_event __P((char *, int *, int));
extern char *get_history_event __P((const char *, int *, int));
/* Return an array of tokens, much as the shell might. The tokens are
parsed out of STRING. */
extern char **history_tokenize __P((char *));
extern char **history_tokenize __P((const char *));
/* Exported history variables. */
extern int history_base;
extern int history_length;
extern int max_input_history;
extern int history_max_entries;
extern char history_expansion_char;
extern char history_subst_char;
extern char *history_word_delimiters;
extern char history_comment_char;
extern char *history_no_expand_chars;
extern char *history_search_delimiter_chars;
extern int history_quotes_inhibit_expansion;
/* Backwards compatibility */
extern int max_input_history;
/* If set, this function is called to decide whether or not a particular
history expansion should be treated as a special case for the calling
application and not expanded. */
extern Function *history_inhibit_expansion_function;
extern rl_linebuf_func_t *history_inhibit_expansion_function;
#ifdef __cplusplus
}

View file

@ -63,7 +63,7 @@ char *history_search_delimiter_chars = (char *)NULL;
static int
history_search_internal (string, direction, anchored)
char *string;
const char *string;
int direction, anchored;
{
register int i, reverse;
@ -159,7 +159,7 @@ history_search_internal (string, direction, anchored)
/* Do a non-anchored search for STRING through the history in DIRECTION. */
int
history_search (string, direction)
char *string;
const char *string;
int direction;
{
return (history_search_internal (string, direction, NON_ANCHORED_SEARCH));
@ -168,7 +168,7 @@ history_search (string, direction)
/* Do an anchored search for string through the history in DIRECTION. */
int
history_search_prefix (string, direction)
char *string;
const char *string;
int direction;
{
return (history_search_internal (string, direction, ANCHORED_SEARCH));
@ -179,7 +179,7 @@ history_search_prefix (string, direction)
which point to begin searching. */
int
history_search_pos (string, dir, pos)
char *string;
const char *string;
int dir, pos;
{
int ret, old;

View file

@ -78,9 +78,11 @@ extern int errno;
/* Non-null means it is a pointer to a function to run while waiting for
character input. */
Function *rl_event_hook = (Function *)NULL;
rl_hook_func_t *rl_event_hook = (rl_hook_func_t *)NULL;
Function *rl_getc_function = rl_getc;
rl_getc_func_t *rl_getc_function = rl_getc;
static int _keyboard_input_timeout = 100000; /* 0.1 seconds; it's in usec */
/* **************************************************************** */
/* */
@ -169,7 +171,7 @@ rl_gather_tyi ()
FD_SET (tty, &readfds);
FD_SET (tty, &exceptfds);
timeout.tv_sec = 0;
timeout.tv_usec = 100000; /* 0.1 seconds */
timeout.tv_usec = _keyboard_input_timeout;
if (select (tty + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout) <= 0)
return; /* Nothing to read. */
#endif
@ -222,6 +224,18 @@ rl_gather_tyi ()
}
}
int
rl_set_keyboard_input_timeout (u)
int u;
{
int o;
o = _keyboard_input_timeout;
if (u > 0)
_keyboard_input_timeout = u;
return (o);
}
/* Is there input available to be read on the readline input file
descriptor? Only works if the system has select(2) or FIONREAD. */
int
@ -244,7 +258,7 @@ _rl_input_available ()
FD_SET (tty, &readfds);
FD_SET (tty, &exceptfds);
timeout.tv_sec = 0;
timeout.tv_usec = 100000; /* 0.1 seconds */
timeout.tv_usec = _keyboard_input_timeout;
return (select (tty + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout) > 0);
#endif
@ -293,6 +307,7 @@ rl_stuff_char (key)
{
key = NEWLINE;
rl_pending_input = EOF;
RL_SETSTATE (RL_STATE_INPUTPENDING);
}
ibuffer[push_index++] = key;
if (push_index >= ibuffer_len)
@ -307,6 +322,16 @@ rl_execute_next (c)
int c;
{
rl_pending_input = c;
RL_SETSTATE (RL_STATE_INPUTPENDING);
return 0;
}
/* Clear any pending input pushed with rl_execute_next() */
int
rl_clear_pending_input ()
{
rl_pending_input = 0;
RL_UNSETSTATE (RL_STATE_INPUTPENDING);
return 0;
}
@ -327,7 +352,7 @@ rl_read_key ()
if (rl_pending_input)
{
c = rl_pending_input;
rl_pending_input = 0;
rl_clear_pending_input ();
}
else
{
@ -341,6 +366,8 @@ rl_read_key ()
while (rl_event_hook && rl_get_char (&c) == 0)
{
(*rl_event_hook) ();
if (rl_done) /* XXX - experimental */
return ('\n');
rl_gather_tyi ();
}
}
@ -392,7 +419,7 @@ rl_getc (stream)
if (errno == X_EWOULDBLOCK || errno == X_EAGAIN)
{
if (unset_nodelay_mode (fileno (stream)) < 0)
if (sh_unset_nodelay_mode (fileno (stream)) < 0)
return (EOF);
continue;
}

View file

@ -55,7 +55,7 @@
unsigned char *_rl_isearch_terminators = (unsigned char *)NULL;
/* Variables imported from other files in the readline library. */
extern HIST_ENTRY *saved_line_for_history;
extern HIST_ENTRY *_rl_saved_line_for_history;
/* Forward declarations */
static int rl_search_history __P((int, int));
@ -64,6 +64,8 @@ static int rl_search_history __P((int, int));
identical lines many times in a row. */
static char *prev_line_found;
static unsigned char *default_isearch_terminators = "\033\012";
/* Search backwards through the history looking for a string which is typed
interactively. Start with the current line. */
int
@ -176,6 +178,7 @@ rl_search_history (direction, invoking_key)
been set, we use that value, otherwise we use ESC and C-J. */
unsigned char *isearch_terminators;
RL_SETSTATE(RL_STATE_ISEARCH);
orig_point = rl_point;
last_found_line = orig_line = where_history ();
reverse = direction < 0;
@ -183,10 +186,10 @@ rl_search_history (direction, invoking_key)
allocated_line = (char *)NULL;
isearch_terminators = _rl_isearch_terminators ? _rl_isearch_terminators
: (unsigned char *)"\033\012";
: default_isearch_terminators;
/* Create an arrary of pointers to the lines that we want to search. */
maybe_replace_line ();
rl_maybe_replace_line ();
i = 0;
if (hlist)
for (i = 0; hlist[i]; i++);
@ -197,8 +200,8 @@ rl_search_history (direction, invoking_key)
for (i = 0; i < hlen; i++)
lines[i] = hlist[i]->line;
if (saved_line_for_history)
lines[i] = saved_line_for_history->line;
if (_rl_saved_line_for_history)
lines[i] = _rl_saved_line_for_history->line;
else
{
/* Keep track of this so we can free it. */
@ -232,10 +235,12 @@ rl_search_history (direction, invoking_key)
found = failed = 0;
for (;;)
{
Function *f = (Function *)NULL;
rl_command_func_t *f = (rl_command_func_t *)NULL;
/* Read a key and decide how to proceed. */
RL_SETSTATE(RL_STATE_MOREINPUT);
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
if (_rl_keymap[c].type == ISFUNC)
{
@ -273,6 +278,8 @@ rl_search_history (direction, invoking_key)
if (c >= 0 && (CTRL_CHAR (c) || META_CHAR (c) || c == RUBOUT) && c != CTRL ('G'))
{
/* This sets rl_pending_input to c; it will be picked up the next
time rl_read_key is called. */
rl_execute_next (c);
break;
}
@ -287,7 +294,7 @@ rl_search_history (direction, invoking_key)
else if (line_index != sline_len)
++line_index;
else
ding ();
rl_ding ();
break;
/* switch directions */
@ -305,13 +312,14 @@ rl_search_history (direction, invoking_key)
if (allocated_line)
free (allocated_line);
free (lines);
RL_UNSETSTATE(RL_STATE_ISEARCH);
return 0;
#if 0
/* delete character from search string. */
case -3:
if (search_string_index == 0)
ding ();
rl_ding ();
else
{
search_string[--search_string_index] = '\0';
@ -384,7 +392,7 @@ rl_search_history (direction, invoking_key)
if (failed)
{
/* We cannot find the search string. Ding the bell. */
ding ();
rl_ding ();
i = last_found_line;
continue; /* XXX - was break */
}
@ -438,5 +446,7 @@ rl_search_history (direction, invoking_key)
free (allocated_line);
free (lines);
RL_UNSETSTATE(RL_STATE_ISEARCH);
return 0;
}

View file

@ -61,7 +61,7 @@ rl_make_bare_keymap ()
for (i = 0; i < KEYMAP_SIZE; i++)
{
keymap[i].type = ISFUNC;
keymap[i].function = (Function *)NULL;
keymap[i].function = (rl_command_func_t *)NULL;
}
for (i = 'A'; i < ('Z' + 1); i++)

View file

@ -30,17 +30,11 @@ extern "C" {
#if defined (READLINE_LIBRARY)
# include "rlstdc.h"
# include "chardefs.h"
# include "rltypedefs.h"
#else
# include <readline/rlstdc.h>
# include <readline/chardefs.h>
#endif
#if !defined (_FUNCTION_DEF)
# define _FUNCTION_DEF
typedef int Function ();
typedef void VFunction ();
typedef char *CPFunction ();
typedef char **CPPFunction ();
# include <readline/rltypedefs.h>
#endif
/* A keymap contains one entry for each key in the ASCII set.
@ -50,7 +44,7 @@ typedef char **CPPFunction ();
TYPE says which kind of thing FUNCTION is. */
typedef struct _keymap_entry {
char type;
Function *function;
rl_command_func_t *function;
} KEYMAP_ENTRY;
/* This must be large enough to hold bindings for all of the characters
@ -59,7 +53,7 @@ typedef struct _keymap_entry {
#define KEYMAP_SIZE 256
/* I wanted to make the above structure contain a union of:
union { Function *function; struct _keymap_entry *keymap; } value;
union { rl_command_func_t *function; struct _keymap_entry *keymap; } value;
but this made it impossible for me to create a static array.
Maybe I need C lessons. */
@ -93,7 +87,7 @@ extern void rl_discard_keymap __P((Keymap));
/* Return the keymap corresponding to a given name. Names look like
`emacs' or `emacs-meta' or `vi-insert'. */
extern Keymap rl_get_keymap_by_name __P((char *));
extern Keymap rl_get_keymap_by_name __P((const char *));
/* Return the current keymap. */
extern Keymap rl_get_keymap __P((void));

View file

@ -264,7 +264,7 @@ rl_backward_kill_line (direction, ignore)
else
{
if (!rl_point)
ding ();
rl_ding ();
else
{
rl_beg_of_line (1, ignore);
@ -299,7 +299,7 @@ rl_unix_word_rubout (count, key)
int orig_point;
if (rl_point == 0)
ding ();
rl_ding ();
else
{
orig_point = rl_point;
@ -331,7 +331,7 @@ rl_unix_line_discard (count, key)
int count, key;
{
if (rl_point == 0)
ding ();
rl_ding ();
else
{
rl_kill_text (rl_point, 0);
@ -512,14 +512,14 @@ rl_yank_nth_arg_internal (count, ignore, history_skip)
if (entry == 0)
{
ding ();
rl_ding ();
return -1;
}
arg = history_arg_extract (count, count, entry->line);
if (!arg || !*arg)
{
ding ();
rl_ding ();
return -1;
}
@ -592,7 +592,7 @@ rl_yank_last_arg (count, key)
}
/* A special paste command for users of Cygnus's cygwin32. */
#if defined (__CYGWIN32__)
#if defined (__CYGWIN__)
#include <windows.h>
int
@ -625,4 +625,4 @@ rl_paste_from_clipboard (count, key)
}
return (0);
}
#endif /* __CYGWIN32__ */
#endif /* __CYGWIN__ */

View file

@ -57,12 +57,12 @@
/* */
/* **************************************************************** */
/* Non-zero means to save keys that we dispatch on in a kbd macro. */
int _rl_defining_kbd_macro = 0;
/* The currently executing macro string. If this is non-zero,
then it is a malloc ()'ed string where input is coming from. */
char *_rl_executing_macro = (char *)NULL;
char *rl_executing_macro = (char *)NULL;
/* Non-zero means to save keys that we dispatch on in a kbd macro. */
int _rl_defining_kbd_macro = 0;
/* The offset in the above string to the next character to be read. */
static int executing_macro_index;
@ -95,8 +95,9 @@ _rl_with_macro_input (string)
char *string;
{
_rl_push_executing_macro ();
_rl_executing_macro = string;
rl_executing_macro = string;
executing_macro_index = 0;
RL_SETSTATE(RL_STATE_MACROINPUT);
}
/* Return the next character available from a macro, or 0 if
@ -104,16 +105,16 @@ _rl_with_macro_input (string)
int
_rl_next_macro_key ()
{
if (_rl_executing_macro == 0)
if (rl_executing_macro == 0)
return (0);
if (_rl_executing_macro[executing_macro_index] == 0)
if (rl_executing_macro[executing_macro_index] == 0)
{
_rl_pop_executing_macro ();
return (_rl_next_macro_key ());
}
return (_rl_executing_macro[executing_macro_index++]);
return (rl_executing_macro[executing_macro_index++]);
}
/* Save the currently executing macro on a stack of saved macros. */
@ -125,7 +126,7 @@ _rl_push_executing_macro ()
saver = (struct saved_macro *)xmalloc (sizeof (struct saved_macro));
saver->next = macro_list;
saver->sindex = executing_macro_index;
saver->string = _rl_executing_macro;
saver->string = rl_executing_macro;
macro_list = saver;
}
@ -137,20 +138,21 @@ _rl_pop_executing_macro ()
{
struct saved_macro *macro;
if (_rl_executing_macro)
free (_rl_executing_macro);
_rl_executing_macro = (char *)NULL;
FREE (rl_executing_macro);
rl_executing_macro = (char *)NULL;
executing_macro_index = 0;
if (macro_list)
{
macro = macro_list;
_rl_executing_macro = macro_list->string;
rl_executing_macro = macro_list->string;
executing_macro_index = macro_list->sindex;
macro_list = macro_list->next;
free (macro);
}
if (rl_executing_macro == 0)
RL_UNSETSTATE(RL_STATE_MACROINPUT);
}
/* Add a character to the macro being built. */
@ -180,14 +182,12 @@ _rl_kill_kbd_macro ()
}
current_macro_size = current_macro_index = 0;
if (_rl_executing_macro)
{
free (_rl_executing_macro);
_rl_executing_macro = (char *) NULL;
}
FREE (rl_executing_macro);
rl_executing_macro = (char *) NULL;
executing_macro_index = 0;
_rl_defining_kbd_macro = 0;
RL_UNSETSTATE(RL_STATE_MACRODEF);
}
/* Begin defining a keyboard macro.
@ -215,6 +215,7 @@ rl_start_kbd_macro (ignore1, ignore2)
current_macro_index = 0;
_rl_defining_kbd_macro = 1;
RL_SETSTATE(RL_STATE_MACRODEF);
return 0;
}
@ -235,6 +236,7 @@ rl_end_kbd_macro (count, ignore)
current_macro[current_macro_index] = '\0';
_rl_defining_kbd_macro = 0;
RL_UNSETSTATE(RL_STATE_MACRODEF);
return (rl_call_last_kbd_macro (--count, 0));
}
@ -250,7 +252,7 @@ rl_call_last_kbd_macro (count, ignore)
if (_rl_defining_kbd_macro)
{
ding (); /* no recursive macros */
rl_ding (); /* no recursive macros */
current_macro[--current_macro_index] = '\0'; /* erase this char */
return 0;
}

View file

@ -105,9 +105,9 @@ _rl_init_eightbit ()
/* We don't have setlocale. Finesse it. Check the environment for the
appropriate variables and set eight-bit mode if they have the right
values. */
lspec = get_env_value ("LC_ALL");
if (lspec == 0) lspec = get_env_value ("LC_CTYPE");
if (lspec == 0) lspec = get_env_value ("LANG");
lspec = sh_get_env_value ("LC_ALL");
if (lspec == 0) lspec = sh_get_env_value ("LC_CTYPE");
if (lspec == 0) lspec = sh_get_env_value ("LANG");
if (lspec == 0 || (t = normalize_codeset (lspec)) == 0)
return (0);
for (i = 0; t && legal_lang_values[i]; i++)

View file

@ -64,6 +64,8 @@ int rl_blink_matching_paren = 1;
int rl_blink_matching_paren = 0;
#endif /* !HAVE_SELECT */
static int _paren_blink_usec = 500000;
/* Change emacs_standard_keymap to have bindings for paren matching when
ON_OR_OFF is 1, change them back to self_insert when ON_OR_OFF == 0. */
void
@ -84,6 +86,18 @@ _rl_enable_paren_matching (on_or_off)
}
}
int
rl_set_paren_blink_timeout (u)
int u;
{
int o;
o = _paren_blink_usec;
if (u > 0)
_paren_blink_usec = u;
return (o);
}
int
rl_insert_close (count, invoking_key)
int count, invoking_key;
@ -109,7 +123,7 @@ rl_insert_close (count, invoking_key)
FD_ZERO (&readfds);
FD_SET (fileno (rl_instream), &readfds);
timer.tv_sec = 0;
timer.tv_usec = 500000;
timer.tv_usec = _paren_blink_usec;
orig_point = rl_point;
rl_point = match_point;

View file

@ -67,7 +67,7 @@
#include "xmalloc.h"
#ifndef RL_LIBRARY_VERSION
# define RL_LIBRARY_VERSION "4.1"
# define RL_LIBRARY_VERSION "4.2"
#endif
/* Evaluates its arguments multiple times. */
@ -90,8 +90,9 @@ static void readline_default_bindings __P((void));
/* */
/* **************************************************************** */
char *rl_library_version = RL_LIBRARY_VERSION;
const char *rl_library_version = RL_LIBRARY_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.
@ -121,8 +122,13 @@ 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;
@ -137,7 +143,7 @@ int rl_end;
int rl_done;
/* The last function executed by readline. */
Function *rl_last_func = (Function *)NULL;
rl_command_func_t *rl_last_func = (rl_command_func_t *)NULL;
/* Top level environment for readline_internal (). */
procenv_t readline_top_level;
@ -153,7 +159,7 @@ FILE *rl_outstream = (FILE *)NULL;
int readline_echoing_p = 1;
/* Current prompt. */
char *rl_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
@ -165,12 +171,12 @@ 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. */
Function *rl_startup_hook = (Function *)NULL;
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. */
Function *rl_pre_input_hook = (Function *)NULL;
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;
@ -183,7 +189,7 @@ int _rl_eof_char = CTRL ('D');
int rl_pending_input = 0;
/* Pointer to a useful terminal name. */
char *rl_terminal_name = (char *)NULL;
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;
@ -243,24 +249,37 @@ int _rl_output_meta_chars = 0;
/* 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_visible_prompt_length = (rl_prompt && *rl_prompt)
? rl_expand_prompt (rl_prompt)
: 0;
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)
char *prompt;
const char *prompt;
{
char *value;
rl_prompt = prompt;
/* If we are at EOF return a NULL string. */
if (rl_pending_input == EOF)
{
rl_pending_input = 0;
rl_clear_pending_input ();
return ((char *)NULL);
}
rl_visible_prompt_length = rl_expand_prompt (rl_prompt);
rl_set_prompt (prompt);
rl_initialize ();
(*rl_prep_term_function) (_rl_meta_flag);
@ -348,7 +367,7 @@ readline_internal_teardown (eof)
/* At any rate, it is highly likely that this line has an undo list. Get
rid of it now. */
if (rl_undo_list)
free_undo_list ();
rl_free_undo_list ();
return (eof ? (char *)NULL : savestring (the_line));
}
@ -384,7 +403,9 @@ readline_internal_charloop ()
rl_key_sequence_length = 0;
}
RL_SETSTATE(RL_STATE_READCMD);
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_READCMD);
/* EOF typed to a non-blank line is a <NL>. */
if (c == EOF && rl_end)
@ -395,6 +416,7 @@ readline_internal_charloop ()
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;
@ -491,7 +513,7 @@ _rl_dispatch (key, map)
{
int r, newkey;
char *macro;
Function *func;
rl_command_func_t *func;
if (META_CHAR (key) && _rl_convert_meta_chars_to_ascii)
{
@ -505,7 +527,7 @@ _rl_dispatch (key, map)
return (_rl_dispatch (key, map));
}
else
ding ();
rl_ding ();
return 0;
}
@ -517,7 +539,7 @@ _rl_dispatch (key, map)
{
case ISFUNC:
func = map[key].function;
if (func != (Function *)NULL)
if (func)
{
/* Special case rl_do_lowercase_version (). */
if (func == rl_do_lowercase_version)
@ -530,13 +552,15 @@ _rl_dispatch (key, map)
#endif
rl_dispatching = 1;
RL_SETSTATE(RL_STATE_DISPATCHING);
r = (*map[key].function)(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 && map[key].function != rl_digit_argument)
if (rl_pending_input == 0 && map[key].function != rl_digit_argument)
rl_last_func = map[key].function;
}
else
@ -547,10 +571,18 @@ _rl_dispatch (key, map)
break;
case ISKMAP:
if (map[key].function != (Function *)NULL)
if (map[key].function != 0)
{
rl_key_sequence_length++;
if (key == ESC)
RL_SETSTATE(RL_STATE_METANEXT);
RL_SETSTATE(RL_STATE_MOREINPUT);
newkey = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
if (key == ESC)
RL_UNSETSTATE(RL_STATE_METANEXT);
r = _rl_dispatch (newkey, FUNCTION_TO_KEYMAP (map, key));
}
else
@ -561,7 +593,7 @@ _rl_dispatch (key, map)
break;
case ISMACR:
if (map[key].function != (Function *)NULL)
if (map[key].function != 0)
{
macro = savestring ((char *)map[key].function);
_rl_with_macro_input (macro);
@ -591,8 +623,11 @@ rl_initialize ()
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);
}
/* Initalize the current line information. */
@ -600,6 +635,7 @@ rl_initialize ()
/* 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. */
start_using_history ();
@ -608,7 +644,7 @@ rl_initialize ()
rl_reset_line_state ();
/* No such function typed yet. */
rl_last_func = (Function *)NULL;
rl_last_func = (rl_command_func_t *)NULL;
/* Parsing of key-bindings begins in an enabled state. */
_rl_parsing_conditionalized_out = 0;
@ -658,8 +694,10 @@ readline_initialize_everything ()
#endif
#endif
/* Find out if we are running in Emacs. */
running_in_emacs = get_env_value ("EMACS") != (char *)0;
#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)
@ -679,7 +717,9 @@ readline_initialize_everything ()
rl_line_buffer = xmalloc (rl_line_buffer_len = DEFAULT_BUFFER_SIZE);
/* Initialize the terminal interface. */
_rl_init_terminal_io ((char *)NULL);
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 ();
@ -696,8 +736,8 @@ readline_initialize_everything ()
/* XXX */
if (_rl_horizontal_scroll_mode && _rl_term_autowrap)
{
screenwidth--;
screenchars -= screenheight;
_rl_screenwidth--;
_rl_screenchars -= _rl_screenheight;
}
/* Override the effect of any `set keymap' assignments in the
@ -723,13 +763,13 @@ readline_initialize_everything ()
static void
readline_default_bindings ()
{
rltty_set_default_bindings (_rl_keymap);
rl_tty_set_default_bindings (_rl_keymap);
}
static void
bind_arrow_keys_internal ()
{
Function *f;
rl_command_func_t *f;
#if defined (__MSDOS__)
f = rl_function_of_keyseq ("\033[0A", _rl_keymap, (int *)NULL);
@ -797,19 +837,23 @@ rl_digit_loop ()
rl_save_prompt ();
RL_SETSTATE(RL_STATE_NUMERICARG);
sawminus = sawdigits = 0;
while (1)
{
if (rl_numeric_arg > 1000000)
{
sawdigits = rl_explicit_arg = rl_numeric_arg = 0;
ding ();
rl_ding ();
rl_restore_prompt ();
rl_clear_message ();
RL_UNSETSTATE(RL_STATE_NUMERICARG);
return 1;
}
rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg);
RL_SETSTATE(RL_STATE_MOREINPUT);
key = c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
/* If we see a key bound to `universal-argument' after seeing digits,
it ends the argument but is otherwise ignored. */
@ -823,9 +867,12 @@ rl_digit_loop ()
}
else
{
RL_SETSTATE(RL_STATE_MOREINPUT);
key = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
rl_restore_prompt ();
rl_clear_message ();
RL_UNSETSTATE(RL_STATE_NUMERICARG);
return (_rl_dispatch (key, _rl_keymap));
}
}
@ -849,10 +896,12 @@ rl_digit_loop ()
rl_explicit_arg = 1;
rl_restore_prompt ();
rl_clear_message ();
RL_UNSETSTATE(RL_STATE_NUMERICARG);
return (_rl_dispatch (key, _rl_keymap));
}
}
RL_UNSETSTATE(RL_STATE_NUMERICARG);
return 0;
}
@ -861,7 +910,7 @@ int
rl_digit_argument (ignore, key)
int ignore, key;
{
rl_pending_input = key;
rl_execute_next (key);
return (rl_digit_loop ());
}
@ -869,7 +918,7 @@ rl_digit_argument (ignore, key)
int
rl_discard_argument ()
{
ding ();
rl_ding ();
rl_clear_message ();
_rl_init_argument ();
return 0;
@ -906,7 +955,7 @@ rl_universal_argument (count, key)
function. */
int
rl_insert_text (string)
char *string;
const char *string;
{
register int i, l = strlen (string);
@ -999,7 +1048,7 @@ _rl_fix_point (fix_mark_too)
void
_rl_replace_text (text, start, end)
char *text;
const char *text;
int start, end;
{
rl_begin_undo_group ();
@ -1053,7 +1102,7 @@ rl_forward (count, key)
{
int end = rl_point + count;
#if defined (VI_MODE)
int lend = rl_end - (rl_editing_mode == vi_mode);
int lend = rl_end > 0 ? rl_end - (rl_editing_mode == vi_mode) : rl_end;
#else
int lend = rl_end;
#endif
@ -1061,7 +1110,7 @@ rl_forward (count, key)
if (end > lend)
{
rl_point = lend;
ding ();
rl_ding ();
}
else
rl_point = end;
@ -1085,7 +1134,7 @@ rl_backward (count, key)
if (rl_point < count)
{
rl_point = 0;
ding ();
rl_ding ();
}
else
rl_point -= count;
@ -1132,12 +1181,12 @@ rl_forward_word (count, key)
/* If we are not in a word, move forward until we are in one.
Then, move forward until we hit a non-alphabetic character. */
c = the_line[rl_point];
if (alphabetic (c) == 0)
if (rl_alphabetic (c) == 0)
{
while (++rl_point < rl_end)
{
c = the_line[rl_point];
if (alphabetic (c))
if (rl_alphabetic (c))
break;
}
}
@ -1146,7 +1195,7 @@ rl_forward_word (count, key)
while (++rl_point < rl_end)
{
c = the_line[rl_point];
if (alphabetic (c) == 0)
if (rl_alphabetic (c) == 0)
break;
}
--count;
@ -1176,12 +1225,12 @@ rl_backward_word (count, key)
just before point. */
c = the_line[rl_point - 1];
if (alphabetic (c) == 0)
if (rl_alphabetic (c) == 0)
{
while (--rl_point)
{
c = the_line[rl_point - 1];
if (alphabetic (c))
if (rl_alphabetic (c))
break;
}
}
@ -1189,7 +1238,7 @@ rl_backward_word (count, key)
while (rl_point)
{
c = the_line[rl_point - 1];
if (alphabetic (c) == 0)
if (rl_alphabetic (c) == 0)
break;
else
--rl_point;
@ -1245,7 +1294,9 @@ rl_arrow_keys (count, c)
{
int ch;
RL_SETSTATE(RL_STATE_MOREINPUT);
ch = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
switch (_rl_to_upper (ch))
{
@ -1266,7 +1317,7 @@ rl_arrow_keys (count, c)
break;
default:
ding ();
rl_ding ();
}
return 0;
}
@ -1352,7 +1403,11 @@ rl_quoted_insert (count, key)
#if defined (HANDLE_SIGNALS)
_rl_disable_tty_signals ();
#endif
RL_SETSTATE(RL_STATE_MOREINPUT);
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
#if defined (HANDLE_SIGNALS)
_rl_restore_tty_signals ();
#endif
@ -1376,6 +1431,7 @@ rl_newline (count, key)
int count, key;
{
rl_done = 1;
RL_SETSTATE(RL_STATE_DONE);
#if defined (VI_MODE)
if (rl_editing_mode == vi_mode)
@ -1386,7 +1442,7 @@ rl_newline (count, key)
#endif /* VI_MODE */
/* If we've been asked to erase empty lines, suppress the final update,
since _rl_update_final calls crlf(). */
since _rl_update_final calls rl_crlf(). */
if (rl_erase_empty_line && rl_point == 0 && rl_end == 0)
return 0;
@ -1419,7 +1475,7 @@ rl_rubout (count, key)
if (!rl_point)
{
ding ();
rl_ding ();
return -1;
}
@ -1455,7 +1511,7 @@ rl_delete (count, key)
if (rl_point == rl_end)
{
ding ();
rl_ding ();
return -1;
}
@ -1611,11 +1667,11 @@ rl_change_case (count, op)
case CapCase:
the_line[start] = (inword == 0) ? _rl_to_upper (c) : _rl_to_lower (c);
inword = alphabetic (the_line[start]);
inword = rl_alphabetic (the_line[start]);
break;
default:
ding ();
rl_ding ();
return -1;
}
}
@ -1654,7 +1710,7 @@ rl_transpose_words (count, key)
/* Do some check to make sure that there really are two words. */
if ((w1_beg == w2_beg) || (w2_beg < w1_end))
{
ding ();
rl_ding ();
rl_point = orig_point;
return -1;
}
@ -1702,7 +1758,7 @@ rl_transpose_chars (count, key)
if (!rl_point || rl_end < 2)
{
ding ();
rl_ding ();
return -1;
}
@ -1746,7 +1802,7 @@ _rl_char_search_internal (count, dir, schar)
{
if ((dir < 0 && pos <= 0) || (dir > 0 && pos >= rl_end))
{
ding ();
rl_ding ();
return -1;
}
@ -1777,7 +1833,10 @@ _rl_char_search (count, fdir, bdir)
{
int c;
RL_SETSTATE(RL_STATE_MOREINPUT);
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
if (count < 0)
return (_rl_char_search_internal (-count, bdir, c));
else
@ -1810,17 +1869,17 @@ rl_backward_char_search (count, key)
/* While we are editing the history, this is the saved
version of the original line. */
HIST_ENTRY *saved_line_for_history = (HIST_ENTRY *)NULL;
HIST_ENTRY *_rl_saved_line_for_history = (HIST_ENTRY *)NULL;
/* Set the history pointer back to the last entry in the history. */
static void
start_using_history ()
{
using_history ();
if (saved_line_for_history)
_rl_free_history_entry (saved_line_for_history);
if (_rl_saved_line_for_history)
_rl_free_history_entry (_rl_saved_line_for_history);
saved_line_for_history = (HIST_ENTRY *)NULL;
_rl_saved_line_for_history = (HIST_ENTRY *)NULL;
}
/* Free the contents (and containing structure) of a HIST_ENTRY. */
@ -1837,7 +1896,7 @@ _rl_free_history_entry (entry)
/* Perhaps put back the current line if it has changed. */
int
maybe_replace_line ()
rl_maybe_replace_line ()
{
HIST_ENTRY *temp;
@ -1852,43 +1911,54 @@ maybe_replace_line ()
return 0;
}
/* Put back the saved_line_for_history if there is one. */
/* Restore the _rl_saved_line_for_history if there is one. */
int
maybe_unsave_line ()
rl_maybe_unsave_line ()
{
int line_len;
if (saved_line_for_history)
if (_rl_saved_line_for_history)
{
line_len = strlen (saved_line_for_history->line);
line_len = strlen (_rl_saved_line_for_history->line);
if (line_len >= rl_line_buffer_len)
rl_extend_line_buffer (line_len);
strcpy (the_line, saved_line_for_history->line);
rl_undo_list = (UNDO_LIST *)saved_line_for_history->data;
_rl_free_history_entry (saved_line_for_history);
saved_line_for_history = (HIST_ENTRY *)NULL;
strcpy (the_line, _rl_saved_line_for_history->line);
rl_undo_list = (UNDO_LIST *)_rl_saved_line_for_history->data;
_rl_free_history_entry (_rl_saved_line_for_history);
_rl_saved_line_for_history = (HIST_ENTRY *)NULL;
rl_end = rl_point = strlen (the_line);
}
else
ding ();
rl_ding ();
return 0;
}
/* Save the current line in saved_line_for_history. */
/* Save the current line in _rl_saved_line_for_history. */
int
maybe_save_line ()
rl_maybe_save_line ()
{
if (saved_line_for_history == 0)
if (_rl_saved_line_for_history == 0)
{
saved_line_for_history = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY));
saved_line_for_history->line = savestring (the_line);
saved_line_for_history->data = (char *)rl_undo_list;
_rl_saved_line_for_history = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY));
_rl_saved_line_for_history->line = savestring (the_line);
_rl_saved_line_for_history->data = (char *)rl_undo_list;
}
return 0;
}
int
_rl_free_saved_history_line ()
{
if (_rl_saved_line_for_history)
{
_rl_free_history_entry (_rl_saved_line_for_history);
_rl_saved_line_for_history = (HIST_ENTRY *)NULL;
}
return 0;
}
/* **************************************************************** */
/* */
/* History Commands */
@ -1908,9 +1978,9 @@ int
rl_end_of_history (count, key)
int count, key;
{
maybe_replace_line ();
rl_maybe_replace_line ();
using_history ();
maybe_unsave_line ();
rl_maybe_unsave_line ();
return 0;
}
@ -1928,7 +1998,7 @@ rl_get_next_history (count, key)
if (count == 0)
return 0;
maybe_replace_line ();
rl_maybe_replace_line ();
temp = (HIST_ENTRY *)NULL;
while (count)
@ -1940,7 +2010,7 @@ rl_get_next_history (count, key)
}
if (temp == 0)
maybe_unsave_line ();
rl_maybe_unsave_line ();
else
{
line_len = strlen (temp->line);
@ -1975,10 +2045,10 @@ rl_get_previous_history (count, key)
return 0;
/* If we don't have a line saved, then save this one. */
maybe_save_line ();
rl_maybe_save_line ();
/* If the current line has changed, save the changes. */
maybe_replace_line ();
rl_maybe_replace_line ();
temp = old_temp = (HIST_ENTRY *)NULL;
while (count)
@ -1997,7 +2067,7 @@ rl_get_previous_history (count, key)
temp = old_temp;
if (temp == 0)
ding ();
rl_ding ();
else
{
line_len = strlen (temp->line);
@ -2053,7 +2123,7 @@ rl_exchange_point_and_mark (count, key)
if (rl_mark == -1)
{
ding ();
rl_ding ();
return -1;
}
else

View file

@ -60,8 +60,8 @@ extern UNDO_LIST *rl_undo_list;
/* The data structure for mapping textual names to code addresses. */
typedef struct _funmap {
char *name;
Function *function;
const char *name;
rl_command_func_t *function;
} FUNMAP;
extern FUNMAP **funmap;
@ -155,8 +155,8 @@ extern int rl_yank __P((int, int));
extern int rl_yank_pop __P((int, int));
extern int rl_yank_nth_arg __P((int, int));
extern int rl_yank_last_arg __P((int, int));
/* Not available unless __CYGWIN32__ is defined. */
#ifdef __CYGWIN32__
/* Not available unless __CYGWIN__ is defined. */
#ifdef __CYGWIN__
extern int rl_paste_from_clipboard __P((int, int));
#endif
@ -196,7 +196,7 @@ extern int rl_noninc_reverse_search_again __P((int, int));
extern int rl_insert_close __P((int, int));
/* Not available unless READLINE_CALLBACKS is defined. */
extern void rl_callback_handler_install __P((char *, VFunction *));
extern void rl_callback_handler_install __P((const char *, rl_vcpfunc_t *));
extern void rl_callback_read_char __P((void));
extern void rl_callback_handler_remove __P((void));
@ -260,43 +260,47 @@ extern int rl_vi_eword __P((int, int));
/* Readline functions. */
/* Read a line of input. Prompt with PROMPT. A NULL PROMPT means none. */
extern char *readline __P((char *));
extern char *readline __P((const char *));
extern int rl_set_prompt __P((const char *));
extern int rl_expand_prompt __P((char *));
extern int rl_initialize __P((void));
/* Undocumented; unused by readline */
extern int rl_discard_argument __P((void));
/* Utility functions to bind keys to readline commands. */
extern int rl_add_defun __P((char *, Function *, int));
extern int rl_bind_key __P((int, Function *));
extern int rl_bind_key_in_map __P((int, Function *, Keymap));
extern int rl_add_defun __P((const char *, rl_command_func_t *, int));
extern int rl_bind_key __P((int, rl_command_func_t *));
extern int rl_bind_key_in_map __P((int, rl_command_func_t *, Keymap));
extern int rl_unbind_key __P((int));
extern int rl_unbind_key_in_map __P((int, Keymap));
extern int rl_unbind_function_in_map __P((Function *, Keymap));
extern int rl_unbind_command_in_map __P((char *, Keymap));
extern int rl_set_key __P((char *, Function *, Keymap));
extern int rl_generic_bind __P((int, char *, char *, Keymap));
extern int rl_variable_bind __P((char *, char *));
extern int rl_unbind_function_in_map __P((rl_command_func_t *, Keymap));
extern int rl_unbind_command_in_map __P((const char *, Keymap));
extern int rl_set_key __P((const char *, rl_command_func_t *, Keymap));
extern int rl_generic_bind __P((int, const char *, char *, Keymap));
extern int rl_variable_bind __P((const char *, const char *));
/* Backwards compatibility, use rl_generic_bind instead. */
extern int rl_macro_bind __P((char *, char *, Keymap));
extern int rl_macro_bind __P((const char *, const char *, Keymap));
/* Undocumented in the texinfo manual; not really useful to programs. */
extern int rl_translate_keyseq __P((char *, char *, int *));
extern int rl_translate_keyseq __P((const char *, char *, int *));
extern char *rl_untranslate_keyseq __P((int));
extern Function *rl_named_function __P((char *));
extern Function *rl_function_of_keyseq __P((char *, Keymap, int *));
extern rl_command_func_t *rl_named_function __P((const char *));
extern rl_command_func_t *rl_function_of_keyseq __P((const char *, Keymap, int *));
extern void rl_list_funmap_names __P((void));
extern char **rl_invoking_keyseqs_in_map __P((Function *, Keymap));
extern char **rl_invoking_keyseqs __P((Function *));
extern char **rl_invoking_keyseqs_in_map __P((rl_command_func_t *, Keymap));
extern char **rl_invoking_keyseqs __P((rl_command_func_t *));
extern void rl_function_dumper __P((int));
extern void rl_macro_dumper __P((int));
extern void rl_variable_dumper __P((int));
extern int rl_read_init_file __P((char *));
extern int rl_read_init_file __P((const char *));
extern int rl_parse_and_bind __P((char *));
/* Functions for manipulating keymaps. */
@ -305,24 +309,27 @@ extern Keymap rl_copy_keymap __P((Keymap));
extern Keymap rl_make_keymap __P((void));
extern void rl_discard_keymap __P((Keymap));
extern Keymap rl_get_keymap_by_name __P((char *));
extern Keymap rl_get_keymap_by_name __P((const char *));
extern char *rl_get_keymap_name __P((Keymap));
extern void rl_set_keymap __P((Keymap));
extern Keymap rl_get_keymap __P((void));
/* Undocumented; used internally only. */
extern void rl_set_keymap_from_edit_mode __P((void));
extern char *rl_get_keymap_name_from_edit_mode __P((void));
/* Functions for manipulating the funmap, which maps command names to functions. */
extern int rl_add_funmap_entry __P((char *, Function *));
extern int rl_add_funmap_entry __P((const char *, rl_command_func_t *));
extern const char **rl_funmap_names __P((void));
/* Undocumented, only used internally -- there is only one funmap, and this
function may be called only once. */
extern void rl_initialize_funmap __P((void));
extern char **rl_funmap_names __P((void));
/* Utility functions for managing keyboard macros. */
extern void rl_push_macro_input __P((char *));
/* Functions for undoing, from undo.c */
extern void rl_add_undo __P((enum undo_code, int, int, char *));
extern void free_undo_list __P((void));
extern void rl_free_undo_list __P((void));
extern int rl_do_undo __P((void));
extern int rl_begin_undo_group __P((void));
extern int rl_end_undo_group __P((void));
@ -335,6 +342,7 @@ extern int rl_on_new_line_with_prompt __P((void));
extern int rl_forced_update_display __P((void));
extern int rl_clear_message __P((void));
extern int rl_reset_line_state __P((void));
extern int rl_crlf __P((void));
#if (defined (__STDC__) || defined (__cplusplus)) && defined (USE_VARARGS) && defined (PREFER_STDARG)
extern int rl_message (const char *, ...);
@ -342,17 +350,17 @@ extern int rl_message (const char *, ...);
extern int rl_message ();
#endif
/* Undocumented in texinfo manual. */
extern int rl_show_char __P((int));
/* Undocumented in texinfo manual. */
extern int rl_character_len __P((int, int));
extern int crlf __P((void));
/* Save and restore internal prompt redisplay information. */
extern void rl_save_prompt __P((void));
extern void rl_restore_prompt __P((void));
/* Modifying text. */
extern int rl_insert_text __P((char *));
extern int rl_insert_text __P((const char *));
extern int rl_delete_text __P((int, int));
extern int rl_kill_text __P((int, int));
extern char *rl_copy_text __P((int, int));
@ -360,20 +368,25 @@ extern char *rl_copy_text __P((int, int));
/* Terminal and tty mode management. */
extern void rl_prep_terminal __P((int));
extern void rl_deprep_terminal __P((void));
extern void rltty_set_default_bindings __P((Keymap));
extern void rl_tty_set_default_bindings __P((Keymap));
extern int rl_reset_terminal __P((char *));
extern int rl_reset_terminal __P((const char *));
extern void rl_resize_terminal __P((void));
/* `Public' utility functions . */
extern void rl_extend_line_buffer __P((int));
extern int ding __P((void));
extern void rl_set_screen_size __P((int, int));
extern void rl_get_screen_size __P((int *, int *));
/* Functions for character input. */
extern int rl_stuff_char __P((int));
extern int rl_execute_next __P((int));
extern int rl_clear_pending_input __P((void));
extern int rl_read_key __P((void));
extern int rl_getc __P((FILE *));
extern int rl_set_keyboard_input_timeout __P((int));
/* `Public' utility functions . */
extern void rl_extend_line_buffer __P((int));
extern int rl_ding __P((void));
extern int rl_alphabetic __P((int));
/* Readline signal handling, from signals.c */
extern int rl_set_signals __P((void));
@ -383,19 +396,36 @@ extern void rl_reset_after_signal __P((void));
extern void rl_free_line_state __P((void));
/* Undocumented. */
extern int rl_expand_prompt __P((char *));
extern int rl_set_paren_blink_timeout __P((int));
extern int maybe_save_line __P((void));
extern int maybe_unsave_line __P((void));
extern int maybe_replace_line __P((void));
/* Undocumented. */
extern int rl_maybe_save_line __P((void));
extern int rl_maybe_unsave_line __P((void));
extern int rl_maybe_replace_line __P((void));
/* Completion functions. */
extern int rl_complete_internal __P((int));
extern void rl_display_match_list __P((char **, int, int));
extern char **completion_matches __P((char *, CPFunction *));
extern char *username_completion_function __P((char *, int));
extern char *filename_completion_function __P((char *, int));
extern char **rl_completion_matches __P((const char *, rl_compentry_func_t *));
extern char *rl_username_completion_function __P((const char *, int));
extern char *rl_filename_completion_function __P((const char *, int));
#if 0
/* Backwards compatibility (compat.c). These will go away sometime. */
extern void free_undo_list __P((void));
extern int maybe_save_line __P((void));
extern int maybe_unsave_line __P((void));
extern int maybe_replace_line __P((void));
extern int ding __P((void));
extern int alphabetic __P((int));
extern int crlf __P((void));
extern char **completion_matches __P((char *, rl_compentry_func_t *));
extern char *username_completion_function __P((const char *, int));
extern char *filename_completion_function __P((const char *, int));
#endif
/* **************************************************************** */
/* */
@ -404,14 +434,21 @@ extern char *filename_completion_function __P((char *, int));
/* **************************************************************** */
/* The version of this incarnation of the readline library. */
extern char *rl_library_version;
extern const char *rl_library_version;
/* True if this is real GNU readline. */
extern int rl_gnu_readline_p;
/* Flags word encapsulating the current readline state. */
extern int rl_readline_state;
/* Says which editing mode readline is currently using. 1 means emacs mode;
0 means vi mode. */
extern int rl_editing_mode;
/* The name of the calling program. You should initialize this to
whatever was in argv[0]. It is used when parsing conditionals. */
extern char *rl_readline_name;
extern const char *rl_readline_name;
/* The prompt readline uses. This is set from the argument to
readline (), and should not be assigned to directly. */
@ -421,7 +458,8 @@ extern char *rl_prompt;
extern char *rl_line_buffer;
/* The location of point, and end. */
extern int rl_point, rl_end;
extern int rl_point;
extern int rl_end;
/* The mark, or saved cursor position. */
extern int rl_mark;
@ -438,29 +476,44 @@ extern int rl_pending_input;
or directly from an application. */
extern int rl_dispatching;
/* Non-zero if the user typed a numeric argument before executing the
current function. */
extern int rl_explicit_arg;
/* The current value of the numeric argument specified by the user. */
extern int rl_numeric_arg;
/* The address of the last command function Readline executed. */
extern rl_command_func_t *rl_last_func;
/* The name of the terminal to use. */
extern char *rl_terminal_name;
extern const char *rl_terminal_name;
/* The input and output streams. */
extern FILE *rl_instream, *rl_outstream;
extern FILE *rl_instream;
extern FILE *rl_outstream;
/* If non-zero, then this is the address of a function to call just
before readline_internal () prints the first prompt. */
extern Function *rl_startup_hook;
extern rl_hook_func_t *rl_startup_hook;
/* 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. */
extern Function *rl_pre_input_hook;
extern rl_hook_func_t *rl_pre_input_hook;
/* The address of a function to call periodically while Readline is
awaiting character input, or NULL, for no event handling. */
extern Function *rl_event_hook;
extern rl_hook_func_t *rl_event_hook;
extern Function *rl_getc_function;
extern VFunction *rl_redisplay_function;
extern VFunction *rl_prep_term_function;
extern VFunction *rl_deprep_term_function;
/* The address of the function to call to fetch a character from the current
Readline input stream */
extern rl_getc_func_t *rl_getc_function;
extern rl_voidfunc_t *rl_redisplay_function;
extern rl_vintfunc_t *rl_prep_term_function;
extern rl_voidfunc_t *rl_deprep_term_function;
/* Dispatch variables. */
extern Keymap rl_executing_keymap;
@ -481,6 +534,9 @@ extern int rl_already_prompted;
up to a character bound to accept-line. */
extern int rl_num_chars_to_read;
/* The text of a currently-executing keyboard macro. */
extern char *rl_executing_macro;
/* Variables to control readline signal handling. */
/* If non-zero, readline will install its own signal handlers for
SIGINT, SIGTERM, SIGQUIT, SIGALRM, SIGTSTP, SIGTTIN, and SIGTTOU. */
@ -497,7 +553,7 @@ extern int rl_catch_sigwinch;
/* Pointer to the generator function for completion_matches ().
NULL means to use filename_entry_function (), the default filename
completer. */
extern Function *rl_completion_entry_function;
extern rl_compentry_func_t *rl_completion_entry_function;
/* If rl_ignore_some_completions_function is non-NULL it is the address
of a function to call after all of the possible matches have been
@ -505,7 +561,7 @@ extern Function *rl_completion_entry_function;
The function is called with one argument; a NULL terminated array
of (char *). If your function removes any of the elements, they
must be free()'ed. */
extern Function *rl_ignore_some_completions_function;
extern rl_compignore_func_t *rl_ignore_some_completions_function;
/* Pointer to alternative function to create matches.
Function is called with TEXT, START, and END.
@ -514,39 +570,50 @@ extern Function *rl_ignore_some_completions_function;
If this function exists and returns NULL then call the value of
rl_completion_entry_function to try to match, otherwise use the
array of strings returned. */
extern CPPFunction *rl_attempted_completion_function;
extern rl_completion_func_t *rl_attempted_completion_function;
/* The basic list of characters that signal a break between words for the
completer routine. The initial contents of this variable is what
breaks words in the shell, i.e. "n\"\\'`@$>". */
extern char *rl_basic_word_break_characters;
extern const char *rl_basic_word_break_characters;
/* The list of characters that signal a break between words for
rl_complete_internal. The default list is the contents of
rl_basic_word_break_characters. */
extern char *rl_completer_word_break_characters;
extern const char *rl_completer_word_break_characters;
/* List of characters which can be used to quote a substring of the line.
Completion occurs on the entire substring, and within the substring
rl_completer_word_break_characters are treated as any other character,
unless they also appear within this list. */
extern char *rl_completer_quote_characters;
extern const char *rl_completer_quote_characters;
/* List of quote characters which cause a word break. */
extern char *rl_basic_quote_characters;
extern const char *rl_basic_quote_characters;
/* List of characters that need to be quoted in filenames by the completer. */
extern char *rl_filename_quote_characters;
extern const char *rl_filename_quote_characters;
/* List of characters that are word break characters, but should be left
in TEXT when it is passed to the completion function. The shell uses
this to help determine what kind of completing to do. */
extern char *rl_special_prefixes;
extern const char *rl_special_prefixes;
/* If non-zero, then this is the address of a function to call when
completing on a directory name. The function is called with
the address of a string (the current directory name) as an arg. */
extern Function *rl_directory_completion_hook;
the address of a string (the current directory name) as an arg. It
changes what is displayed when the possible completions are printed
or inserted. */
extern rl_icppfunc_t *rl_directory_completion_hook;
/* If non-zero, this is the address of a function to call when completing
a directory name. This function takes the address of the directory name
to be modified as an argument. Unlike rl_directory_completion_hook, it
only modifies the directory name used in opendir(2), not what is displayed
when the possible completions are printed or inserted. It is called
before rl_directory_completion_hook. I'm not happy with how this works
yet, so it's undocumented. */
extern rl_icppfunc_t *rl_directory_rewrite_hook;
/* Backwards compatibility with previous versions of readline. */
#define rl_symbolic_link_hook rl_directory_completion_hook
@ -558,7 +625,7 @@ extern Function *rl_directory_completion_hook;
where MATCHES is the array of strings that matched, NUM_MATCHES is the
number of strings in that array, and MAX_LENGTH is the length of the
longest string in that array. */
extern VFunction *rl_completion_display_matches_hook;
extern rl_compdisp_func_t *rl_completion_display_matches_hook;
/* Non-zero means that the results of the matches are to be treated
as filenames. This is ALWAYS zero on entry, and can only be changed
@ -576,17 +643,17 @@ extern int rl_filename_quoting_desired;
Called with the text to quote, the type of match found (single or multiple)
and a pointer to the quoting character to be used, which the function can
reset if desired. */
extern CPFunction *rl_filename_quoting_function;
extern rl_quote_func_t *rl_filename_quoting_function;
/* Function to call to remove quoting characters from a filename. Called
before completion is attempted, so the embedded quotes do not interfere
with matching names in the file system. */
extern CPFunction *rl_filename_dequoting_function;
extern rl_dequote_func_t *rl_filename_dequoting_function;
/* Function to call to decide whether or not a word break character is
quoted. If a character is quoted, it does not break words for the
completer. */
extern Function *rl_char_is_quoted_p;
extern rl_linebuf_func_t *rl_char_is_quoted_p;
/* Non-zero means to suppress normal filename completion after the
user-specified completion function has been called. */
@ -623,9 +690,33 @@ extern int rl_inhibit_completion;
#define SINGLE_MATCH 1
#define MULT_MATCH 2
#if !defined (savestring)
extern char *savestring __P((char *)); /* XXX backwards compatibility */
#endif
/* Possible state values for rl_readline_state */
#define RL_STATE_NONE 0x00000 /* no state; before first call */
#define RL_STATE_INITIALIZING 0x00001 /* initializing */
#define RL_STATE_INITIALIZED 0x00002 /* initialization done */
#define RL_STATE_TERMPREPPED 0x00004 /* terminal is prepped */
#define RL_STATE_READCMD 0x00008 /* reading a command key */
#define RL_STATE_METANEXT 0x00010 /* reading input after ESC */
#define RL_STATE_DISPATCHING 0x00020 /* dispatching to a command */
#define RL_STATE_MOREINPUT 0x00040 /* reading more input in a command function */
#define RL_STATE_ISEARCH 0x00080 /* doing incremental search */
#define RL_STATE_NSEARCH 0x00100 /* doing non-inc search */
#define RL_STATE_SEARCH 0x00200 /* doing a history search */
#define RL_STATE_NUMERICARG 0x00400 /* reading numeric argument */
#define RL_STATE_MACROINPUT 0x00800 /* getting input from a macro */
#define RL_STATE_MACRODEF 0x01000 /* defining keyboard macro */
#define RL_STATE_OVERWRITE 0x02000 /* overwrite mode */
#define RL_STATE_COMPLETING 0x04000 /* doing completion */
#define RL_STATE_SIGHANDLER 0x08000 /* in readline sighandler */
#define RL_STATE_UNDOING 0x10000 /* doing an undo */
#define RL_STATE_INPUTPENDING 0x20000 /* rl_execute_next called */
#define RL_STATE_DONE 0x80000 /* done; accepted line */
#define RL_SETSTATE(x) (rl_readline_state |= (x))
#define RL_UNSETSTATE(x) (rl_readline_state &= ~(x))
#define RL_ISSTATE(x) (rl_readline_state & (x))
#ifdef __cplusplus
}

View file

@ -30,6 +30,8 @@
# include "config.h"
#endif
#include "rlstdc.h"
#if defined (_POSIX_VERSION) && !defined (TERMIOS_MISSING)
# define TERMIOS_TTY_DRIVER
#else
@ -71,7 +73,8 @@ extern char *strchr (), *strrchr ();
#define _rl_stricmp strcasecmp
#define _rl_strnicmp strncasecmp
#else
extern int _rl_stricmp (), _rl_strnicmp ();
extern int _rl_stricmp __P((char *, char *);
extern int _rl_strnicmp __P((char *, char *));
#endif
#if !defined (emacs_mode)
@ -87,14 +90,14 @@ extern int _rl_stricmp (), _rl_strnicmp ();
This is not what is wanted. */
#if defined (CRAY)
# define FUNCTION_TO_KEYMAP(map, key) (Keymap)((int)map[key].function)
# define KEYMAP_TO_FUNCTION(data) (Function *)((int)(data))
# define KEYMAP_TO_FUNCTION(data) (rl_command_func_t *)((int)(data))
#else
# define FUNCTION_TO_KEYMAP(map, key) (Keymap)(map[key].function)
# define KEYMAP_TO_FUNCTION(data) (Function *)(data)
# define KEYMAP_TO_FUNCTION(data) (rl_command_func_t *)(data)
#endif
#ifndef savestring
extern char *xmalloc ();
extern char *xmalloc __P((int));
#define savestring(x) strcpy (xmalloc (1 + strlen (x)), (x))
#endif

View file

@ -35,7 +35,7 @@
*************************************************************************/
/* terminal.c */
extern char *rl_get_termcap __P((char *));
extern char *rl_get_termcap __P((const char *));
/*************************************************************************
* *
@ -51,12 +51,8 @@ extern int rl_visible_stats;
/* readline.c */
extern int rl_line_buffer_len;
extern int rl_numeric_arg;
extern int rl_arg_sign;
extern int rl_explicit_arg;
extern int rl_editing_mode;
extern int rl_visible_prompt_length;
extern Function *rl_last_func;
extern int readline_echoing_p;
extern int rl_key_sequence_length;
@ -91,7 +87,7 @@ extern void _rl_set_screen_size __P((int, int));
extern int _rl_fix_last_undo_of_type __P((int, int, int));
/* util.c */
extern char *_rl_savestring __P((char *));
extern char *_rl_savestring __P((const char *));
/*************************************************************************
* *
@ -118,11 +114,11 @@ extern int readline_internal_char __P((void));
#endif /* READLINE_CALLBACKS */
/* bind.c */
extern void _rl_bind_if_unbound __P((char *, Function *));
extern void _rl_bind_if_unbound __P((const char *, rl_command_func_t *));
/* display.c */
extern char *_rl_strip_prompt __P((char *));
extern void _rl_move_cursor_relative __P((int, char *));
extern void _rl_move_cursor_relative __P((int, const char *));
extern void _rl_move_vert __P((int));
extern void _rl_save_prompt __P((void));
extern void _rl_restore_prompt __P((void));
@ -134,7 +130,7 @@ extern void _rl_update_final __P((void));
extern void _rl_redisplay_after_sigwinch __P((void));
extern void _rl_clean_up_for_exit __P((void));
extern void _rl_erase_entire_line __P((void));
extern int _rl_currentb_display_line __P((void));
extern int _rl_current_display_line __P((void));
/* input.c */
extern int _rl_any_typein __P((void));
@ -161,9 +157,10 @@ extern void _rl_set_the_line __P((void));
extern int _rl_dispatch __P((int, Keymap));
extern int _rl_init_argument __P((void));
extern void _rl_fix_point __P((int));
extern void _rl_replace_text __P((char *, int, int));
extern void _rl_replace_text __P((const char *, int, int));
extern int _rl_char_search_internal __P((int, int, int));
extern int _rl_set_mark_at_pos __P((int));
extern int _rl_free_saved_history_line __P((void));
/* rltty.c */
extern int _rl_disable_tty_signals __P((void));
@ -171,21 +168,22 @@ extern int _rl_restore_tty_signals __P((void));
/* terminal.c */
extern void _rl_get_screen_size __P((int, int));
extern int _rl_init_terminal_io __P((char *));
extern int _rl_init_terminal_io __P((const char *));
#ifdef _MINIX
extern void _rl_output_character_function __P((int));
#else
extern int _rl_output_character_function __P((int));
#endif
extern void _rl_output_some_chars __P((char *, int));
extern void _rl_output_some_chars __P((const char *, int));
extern int _rl_backspace __P((int));
extern void _rl_enable_meta_key __P((void));
extern void _rl_control_keypad __P((int));
/* util.c */
extern int alphabetic __P((int));
extern int rl_alphabetic __P((int));
extern int _rl_abort_internal __P((void));
extern char *_rl_strindex __P((char *, char *));
extern char *_rl_strindex __P((const char *, const char *));
extern char *_rl_strpbrk __P((const char *, const char *));
extern int _rl_qsort_string_compare __P((char **, char **));
extern int (_rl_uppercase_p) __P((int));
extern int (_rl_lowercase_p) __P((int));
@ -206,6 +204,10 @@ extern void _rl_vi_done_inserting __P((void));
* Undocumented private variables *
*************************************************************************/
/* bind.c */
extern const char *_rl_possible_control_prefixes[];
extern const char *_rl_possible_meta_prefixes[];
/* complete.c */
extern int _rl_complete_show_all;
extern int _rl_complete_mark_directories;
@ -218,10 +220,6 @@ extern int _rl_last_c_pos;
extern int _rl_suppress_redisplay;
extern char *rl_display_prompt;
/* funmap.c */
extern char *possible_control_prefixes[];
extern char *possible_meta_prefixes[];
/* isearch.c */
extern unsigned char *_rl_isearch_terminators;
@ -248,20 +246,20 @@ extern procenv_t readline_top_level;
/* terminal.c */
extern int _rl_enable_keypad;
extern int _rl_enable_meta;
extern char *term_clreol;
extern char *term_clrpag;
extern char *term_im;
extern char *term_ic;
extern char *term_ei;
extern char *term_DC;
extern char *term_up;
extern char *term_dc;
extern char *term_cr;
extern char *term_IC;
extern int screenheight;
extern int screenwidth;
extern int screenchars;
extern int terminal_can_insert;
extern char *_rl_term_clreol;
extern char *_rl_term_clrpag;
extern char *_rl_term_im;
extern char *_rl_term_ic;
extern char *_rl_term_ei;
extern char *_rl_term_DC;
extern char *_rl_term_up;
extern char *_rl_term_dc;
extern char *_rl_term_cr;
extern char *_rl_term_IC;
extern int _rl_screenheight;
extern int _rl_screenwidth;
extern int _rl_screenchars;
extern int _rl_terminal_can_insert;
extern int _rl_term_autowrap;
/* undo.c */

View file

@ -25,10 +25,10 @@
#include "rlstdc.h"
extern char *single_quote __P((char *));
extern void set_lines_and_columns __P((int, int));
extern char *get_env_value __P((char *));
extern char *get_home_dir __P((void));
extern int unset_nodelay_mode __P((int));
extern char *sh_single_quote __P((char *));
extern void sh_set_lines_and_columns __P((int, int));
extern char *sh_get_env_value __P((const char *));
extern char *sh_get_home_dir __P((void));
extern int sh_unset_nodelay_mode __P((int));
#endif /* _RL_SHELL_H_ */

View file

@ -36,4 +36,16 @@
# endif
#endif
#if !defined (__STDC__) && !defined (__cplusplus)
# if defined (__GNUC__) /* gcc with -traditional */
# if !defined (const)
# define const __const
# endif /* !const */
# else /* !__GNUC__ */
# if !defined (const)
# define const
# endif /* !const */
# endif /* !__GNUC__ */
#endif /* !__STDC__ && !__cplusplus */
#endif /* !_RL_STDC_H_ */

View file

@ -49,8 +49,8 @@
extern int errno;
#endif /* !errno */
VFunction *rl_prep_term_function = rl_prep_terminal;
VFunction *rl_deprep_term_function = rl_deprep_terminal;
rl_vintfunc_t *rl_prep_term_function = rl_prep_terminal;
rl_voidfunc_t *rl_deprep_term_function = rl_deprep_terminal;
/* **************************************************************** */
/* */
@ -190,7 +190,7 @@ save_tty_chars (tiop)
_rl_tty_chars.t_intr = tiop->tchars.t_intrc;
_rl_tty_chars.t_quit = tiop->tchars.t_quitc;
_rl_tty_chars.t_start = tiop->tchars.t_startc;
_rl_tty_chars.t_stop = tiop->tchars.t_stopc
_rl_tty_chars.t_stop = tiop->tchars.t_stopc;
_rl_tty_chars.t_eof = tiop->tchars.t_eofc;
_rl_tty_chars.t_eol = '\n';
_rl_tty_chars.t_eol2 = tiop->tchars.t_brkc;
@ -218,22 +218,23 @@ get_tty_settings (tty, tiop)
tiop->flags = tiop->lflag = 0;
ioctl (tty, TIOCGETP, &(tiop->sgttyb));
if (ioctl (tty, TIOCGETP, &(tiop->sgttyb)) < 0)
return -1;
tiop->flags |= SGTTY_SET;
#if defined (TIOCLGET)
ioctl (tty, TIOCLGET, &(tiop->lflag));
tiop->flags |= LFLAG_SET;
if (ioctl (tty, TIOCLGET, &(tiop->lflag)) == 0)
tiop->flags |= LFLAG_SET;
#endif
#if defined (TIOCGETC)
ioctl (tty, TIOCGETC, &(tiop->tchars));
tiop->flags |= TCHARS_SET;
if (ioctl (tty, TIOCGETC, &(tiop->tchars)) == 0)
tiop->flags |= TCHARS_SET;
#endif
#if defined (TIOCGLTC)
ioctl (tty, TIOCGLTC, &(tiop->ltchars));
tiop->flags |= LTCHARS_SET;
if (ioctl (tty, TIOCGLTC, &(tiop->ltchars)) == 0)
tiop->flags |= LTCHARS_SET;
#endif
return 0;
@ -279,23 +280,23 @@ set_tty_settings (tty, tiop)
}
static void
prepare_terminal_settings (meta_flag, otio, tiop)
prepare_terminal_settings (meta_flag, oldtio, tiop)
int meta_flag;
TIOTYPE otio, *tiop;
TIOTYPE oldtio, *tiop;
{
readline_echoing_p = (otio.sgttyb.sg_flags & ECHO);
readline_echoing_p = (oldtio.sgttyb.sg_flags & ECHO);
/* Copy the original settings to the structure we're going to use for
our settings. */
tiop->sgttyb = otio.sgttyb;
tiop->lflag = otio.lflag;
tiop->sgttyb = oldtio.sgttyb;
tiop->lflag = oldtio.lflag;
#if defined (TIOCGETC)
tiop->tchars = otio.tchars;
tiop->tchars = oldtio.tchars;
#endif
#if defined (TIOCGLTC)
tiop->ltchars = otio.ltchars;
tiop->ltchars = oldtio.ltchars;
#endif
tiop->flags = otio.flags;
tiop->flags = oldtio.flags;
/* First, the basic settings to put us into character-at-a-time, no-echo
input mode. */
@ -308,8 +309,8 @@ prepare_terminal_settings (meta_flag, otio, tiop)
#if !defined (ANYP)
# define ANYP (EVENP | ODDP)
#endif
if (((otio.sgttyb.sg_flags & ANYP) == ANYP) ||
((otio.sgttyb.sg_flags & ANYP) == 0))
if (((oldtio.sgttyb.sg_flags & ANYP) == ANYP) ||
((oldtio.sgttyb.sg_flags & ANYP) == 0))
{
tiop->sgttyb.sg_flags |= ANYP;
@ -328,13 +329,13 @@ prepare_terminal_settings (meta_flag, otio, tiop)
tiop->tchars.t_startc = -1; /* C-q */
/* If there is an XON character, bind it to restart the output. */
if (otio.tchars.t_startc != -1)
rl_bind_key (otio.tchars.t_startc, rl_restart_output);
if (oldtio.tchars.t_startc != -1)
rl_bind_key (oldtio.tchars.t_startc, rl_restart_output);
# endif /* USE_XON_XOFF */
/* If there is an EOF char, bind _rl_eof_char to it. */
if (otio.tchars.t_eofc != -1)
_rl_eof_char = otio.tchars.t_eofc;
if (oldtio.tchars.t_eofc != -1)
_rl_eof_char = oldtio.tchars.t_eofc;
# if defined (NO_KILL_INTR)
/* Get rid of terminal-generated SIGQUIT and SIGINT. */
@ -373,7 +374,7 @@ prepare_terminal_settings (meta_flag, otio, tiop)
# define TIOTYPE struct termio
# define DRAIN_OUTPUT(fd)
# define GETATTR(tty, tiop) (ioctl (tty, TCGETA, tiop))
# define SETATTR(tty, tiop) (ioctl (tty, TCSETA, tiop))
# define SETATTR(tty, tiop) (ioctl (tty, TCSETAW, tiop))
#endif /* !TERMIOS_TTY_DRIVER */
static TIOTYPE otio;
@ -545,16 +546,16 @@ set_tty_settings (tty, tiop)
}
static void
prepare_terminal_settings (meta_flag, otio, tiop)
prepare_terminal_settings (meta_flag, oldtio, tiop)
int meta_flag;
TIOTYPE otio, *tiop;
TIOTYPE oldtio, *tiop;
{
readline_echoing_p = (otio.c_lflag & ECHO);
readline_echoing_p = (oldtio.c_lflag & ECHO);
tiop->c_lflag &= ~(ICANON | ECHO);
if ((unsigned char) otio.c_cc[VEOF] != (unsigned char) _POSIX_VDISABLE)
_rl_eof_char = otio.c_cc[VEOF];
if ((unsigned char) oldtio.c_cc[VEOF] != (unsigned char) _POSIX_VDISABLE)
_rl_eof_char = oldtio.c_cc[VEOF];
#if defined (USE_XON_XOFF)
#if defined (IXANY)
@ -585,7 +586,7 @@ prepare_terminal_settings (meta_flag, otio, tiop)
if (OUTPUT_BEING_FLUSHED (tiop))
{
tiop->c_lflag &= ~FLUSHO;
otio.c_lflag &= ~FLUSHO;
oldtio.c_lflag &= ~FLUSHO;
}
#endif
@ -645,6 +646,7 @@ rl_prep_terminal (meta_flag)
fflush (rl_outstream);
terminal_prepped = 1;
RL_SETSTATE(RL_STATE_TERMPREPPED);
release_sigint ();
}
@ -675,6 +677,7 @@ rl_deprep_terminal ()
}
terminal_prepped = 0;
RL_UNSETSTATE(RL_STATE_TERMPREPPED);
release_sigint ();
}
@ -751,6 +754,9 @@ rl_stop_output (count, key)
/* Default Key Bindings */
/* */
/* **************************************************************** */
/* Set the system's default editing characters to their readline equivalents
in KMAP. Should be static, now that we have rl_tty_set_default_bindings. */
void
rltty_set_default_bindings (kmap)
Keymap kmap;
@ -815,6 +821,15 @@ rltty_set_default_bindings (kmap)
#endif /* !NEW_TTY_DRIVER */
}
/* New public way to set the system default editing chars to their readline
equivalents. */
void
rl_tty_set_default_bindings (kmap)
Keymap kmap;
{
rltty_set_default_bindings (kmap);
}
#if defined (HANDLE_SIGNALS)
#if defined (NEW_TTY_DRIVER)

88
lib/readline/rltypedefs.h Normal file
View file

@ -0,0 +1,88 @@
/* rltypedefs.h -- Type declarations for readline functions. */
/* Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
The GNU Readline Library 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 2, or
(at your option) any later version.
The GNU Readline Library 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.
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#ifndef _RL_TYPEDEFS_H_
#define _RL_TYPEDEFS_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Old-style */
#if !defined (_FUNCTION_DEF)
# define _FUNCTION_DEF
typedef int Function ();
typedef void VFunction ();
typedef char *CPFunction ();
typedef char **CPPFunction ();
#endif /* _FUNCTION_DEF */
/* New style. */
#if !defined (_RL_FUNCTION_TYPEDEF)
# define _RL_FUNCTION_TYPEDEF
/* Bindable functions */
typedef int rl_command_func_t __P((int, int));
/* Typedefs for the completion system */
typedef char *rl_compentry_func_t __P((const char *, int));
typedef char **rl_completion_func_t __P((const char *, int, int));
typedef char *rl_quote_func_t __P((char *, int, char *));
typedef char *rl_dequote_func_t __P((char *, int));
typedef int rl_compignore_func_t __P((char **));
typedef void rl_compdisp_func_t __P((char **, int, int));
/* Type for input and pre-read hook functions like rl_event_hook */
typedef int rl_hook_func_t __P((void));
/* Input function type */
typedef int rl_getc_func_t __P((FILE *));
/* Generic function that takes a character buffer (which could be the readline
line buffer) and an index into it (which could be rl_point) and returns
an int. */
typedef int rl_linebuf_func_t __P((char *, int));
/* `Generic' function pointer typedefs */
typedef int rl_intfunc_t __P((int));
#define rl_ivoidfunc_t rl_hook_func_t
typedef int rl_icpfunc_t __P((char *));
typedef int rl_icppfunc_t __P((char **));
typedef void rl_voidfunc_t __P((void));
typedef void rl_vintfunc_t __P((int));
typedef void rl_vcpfunc_t __P((char *));
typedef void rl_vcppfunc_t __P((char **));
#endif /* _RL_FUNCTION_TYPEDEF */
#ifdef __cplusplus
}
#endif
#endif /* _RL_TYPEDEFS_H_ */

View file

@ -27,7 +27,7 @@ extern char *xmalloc ();
all `public' readline header files. */
char *
savestring (s)
char *s;
const char *s;
{
return ((char *)strcpy (xmalloc (1 + (int)strlen (s)), (s)));
}

View file

@ -51,7 +51,7 @@
#endif
#define abs(x) (((x) >= 0) ? (x) : -(x))
extern HIST_ENTRY *saved_line_for_history;
extern HIST_ENTRY *_rl_saved_line_for_history;
/* Functions imported from the rest of the library. */
extern int _rl_free_history_entry __P((HIST_ENTRY *));
@ -83,9 +83,9 @@ make_history_line_current (entry)
rl_undo_list = (UNDO_LIST *)entry->data;
rl_end = line_len;
if (saved_line_for_history)
_rl_free_history_entry (saved_line_for_history);
saved_line_for_history = (HIST_ENTRY *)NULL;
if (_rl_saved_line_for_history)
_rl_free_history_entry (_rl_saved_line_for_history);
_rl_saved_line_for_history = (HIST_ENTRY *)NULL;
}
/* Search the history list for STRING starting at absolute history position
@ -100,13 +100,19 @@ noninc_search_from_pos (string, pos, dir)
{
int ret, old;
old = where_history ();
history_set_pos (pos);
if (pos < 0)
return -1;
old = where_history ();
if (history_set_pos (pos) == 0)
return -1;
RL_SETSTATE(RL_STATE_SEARCH);
if (*string == '^')
ret = history_search_prefix (string + 1, dir);
else
ret = history_search (string, dir);
RL_UNSETSTATE(RL_STATE_SEARCH);
if (ret != -1)
ret = where_history ();
@ -128,7 +134,7 @@ noninc_dosearch (string, dir)
if (string == 0 || *string == '\0' || noninc_history_pos < 0)
{
ding ();
rl_ding ();
return;
}
@ -136,10 +142,10 @@ noninc_dosearch (string, dir)
if (pos == -1)
{
/* Search failed, current history position unchanged. */
maybe_unsave_line ();
rl_maybe_unsave_line ();
rl_clear_message ();
rl_point = 0;
ding ();
rl_ding ();
return;
}
@ -172,7 +178,7 @@ noninc_search (dir, pchar)
int saved_point, c;
char *p;
maybe_save_line ();
rl_maybe_save_line ();
saved_point = rl_point;
/* Use the line buffer to read the search string. */
@ -183,18 +189,26 @@ noninc_search (dir, pchar)
rl_message (p, 0, 0);
free (p);
#define SEARCH_RETURN rl_restore_prompt (); return
#define SEARCH_RETURN rl_restore_prompt (); RL_UNSETSTATE(RL_STATE_NSEARCH); return
RL_SETSTATE(RL_STATE_NSEARCH);
/* Read the search string. */
while (c = rl_read_key ())
while (1)
{
RL_SETSTATE(RL_STATE_MOREINPUT);
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
if (c == 0)
break;
switch (c)
{
case CTRL('H'):
case RUBOUT:
if (rl_point == 0)
{
maybe_unsave_line ();
rl_maybe_unsave_line ();
rl_clear_message ();
rl_point = saved_point;
SEARCH_RETURN;
@ -218,10 +232,10 @@ noninc_search (dir, pchar)
case CTRL('C'):
case CTRL('G'):
maybe_unsave_line ();
rl_maybe_unsave_line ();
rl_clear_message ();
rl_point = saved_point;
ding ();
rl_ding ();
SEARCH_RETURN;
default:
@ -239,7 +253,7 @@ noninc_search (dir, pchar)
{
if (!noninc_search_string)
{
ding ();
rl_ding ();
SEARCH_RETURN;
}
}
@ -253,6 +267,7 @@ noninc_search (dir, pchar)
rl_restore_prompt ();
noninc_dosearch (noninc_search_string, dir);
RL_UNSETSTATE(RL_STATE_NSEARCH);
}
/* Search forward through the history list for a string. If the vi-mode
@ -283,7 +298,7 @@ rl_noninc_forward_search_again (count, key)
{
if (!noninc_search_string)
{
ding ();
rl_ding ();
return (-1);
}
noninc_dosearch (noninc_search_string, 1);
@ -298,7 +313,7 @@ rl_noninc_reverse_search_again (count, key)
{
if (!noninc_search_string)
{
ding ();
rl_ding ();
return (-1);
}
noninc_dosearch (noninc_search_string, -1);
@ -312,7 +327,7 @@ rl_history_search_internal (count, dir)
HIST_ENTRY *temp;
int ret, oldpos;
maybe_save_line ();
rl_maybe_save_line ();
temp = (HIST_ENTRY *)NULL;
/* Search COUNT times through the history for a line whose prefix
@ -341,8 +356,8 @@ rl_history_search_internal (count, dir)
/* If we didn't find anything at all, return. */
if (temp == 0)
{
maybe_unsave_line ();
ding ();
rl_maybe_unsave_line ();
rl_ding ();
/* If you don't want the saved history line (last match) to show up
in the line buffer after the search fails, change the #if 0 to
#if 1 */
@ -353,7 +368,7 @@ rl_history_search_internal (count, dir)
rl_line_buffer[rl_end] = '\0';
}
#else
rl_point = rl_history_search_len; /* maybe_unsave_line changes it */
rl_point = rl_history_search_len; /* rl_maybe_unsave_line changes it */
#endif
return 1;
}
@ -382,6 +397,7 @@ rl_history_search_reinit ()
strncpy (history_search_string + 1, rl_line_buffer, rl_point);
history_search_string[rl_point + 1] = '\0';
}
_rl_free_saved_history_line ();
}
/* Search forward in the history for the string of characters

View file

@ -49,11 +49,12 @@
#include <stdio.h>
#include "rlstdc.h"
#include "rlshell.h"
#include "xmalloc.h"
#if !defined (HAVE_GETPW_DECLS)
extern struct passwd *getpwuid ();
extern struct passwd *getpwuid __P((uid_t));
#endif /* !HAVE_GETPW_DECLS */
#ifndef NULL
@ -65,7 +66,7 @@ extern struct passwd *getpwuid ();
/* Does shell-like quoting using single quotes. */
char *
single_quote (string)
sh_single_quote (string)
char *string;
{
register int c;
@ -96,7 +97,7 @@ single_quote (string)
/* Set the environment variables LINES and COLUMNS to lines and cols,
respectively. */
void
set_lines_and_columns (lines, cols)
sh_set_lines_and_columns (lines, cols)
int lines, cols;
{
char *b;
@ -121,14 +122,14 @@ set_lines_and_columns (lines, cols)
}
char *
get_env_value (varname)
char *varname;
sh_get_env_value (varname)
const char *varname;
{
return ((char *)getenv (varname));
}
char *
get_home_dir ()
sh_get_home_dir ()
{
char *home_dir;
struct passwd *entry;
@ -147,7 +148,7 @@ get_home_dir ()
#endif
int
unset_nodelay_mode (fd)
sh_unset_nodelay_mode (fd)
int fd;
{
int flags, bflags;

View file

@ -61,7 +61,7 @@
# define SIGHANDLER_RETURN return (0)
#endif
/* This typedef is equivalant to the one for Function; it allows us
/* This typedef is equivalent to the one for Function; it allows us
to say SigHandler *foo = signal (SIGKILL, SIG_IGN); */
typedef RETSIGTYPE SigHandler ();
@ -119,6 +119,8 @@ rl_signal_handler (sig)
# endif /* !HAVE_BSD_SIGNALS */
#endif /* !HAVE_POSIX_SIGNALS */
RL_SETSTATE(RL_STATE_SIGHANDLER);
#if !defined (HAVE_BSD_SIGNALS) && !defined (HAVE_POSIX_SIGNALS)
/* Since the signal will not be blocked while we are in the signal
handler, ignore it until rl_clear_signals resets the catcher. */
@ -169,6 +171,7 @@ rl_signal_handler (sig)
rl_reset_after_signal ();
}
RL_UNSETSTATE(RL_STATE_SIGHANDLER);
SIGHANDLER_RETURN;
}
@ -189,6 +192,7 @@ rl_sigwinch_handler (sig)
rl_set_sighandler (SIGWINCH, rl_sigwinch_handler, &dummy_winch);
#endif
RL_SETSTATE(RL_STATE_SIGHANDLER);
rl_resize_terminal ();
/* If another sigwinch handler has been installed, call it. */
@ -196,6 +200,7 @@ rl_sigwinch_handler (sig)
if (oh && oh != (SigHandler *)SIG_IGN && oh != (SigHandler *)SIG_DFL)
(*oh) (sig);
RL_UNSETSTATE(RL_STATE_SIGHANDLER);
SIGHANDLER_RETURN;
}
#endif /* SIGWINCH */
@ -358,7 +363,7 @@ rl_cleanup_after_signal ()
_rl_clean_up_for_exit ();
(*rl_deprep_term_function) ();
rl_clear_signals ();
rl_pending_input = 0;
rl_clear_pending_input ();
}
/* Reset the terminal and readline state after a signal handler returns. */
@ -378,7 +383,7 @@ rl_free_line_state ()
{
register HIST_ENTRY *entry;
free_undo_list ();
rl_free_undo_list ();
entry = current_history ();
if (entry)

View file

@ -76,9 +76,6 @@ static char *term_string_buffer = (char *)NULL;
static int tcap_initialized;
/* Non-zero means this terminal can't really do anything. */
static int dumb_term;
#if !defined (__linux__)
# if defined (__EMX__) || defined (NEED_EXTERN_PC)
extern
@ -87,27 +84,36 @@ char PC, *BC, *UP;
#endif /* __linux__ */
/* Some strings to control terminal actions. These are output by tputs (). */
char *term_goto, *term_clreol, *term_cr, *term_clrpag, *term_backspace;
char *term_pc;
char *_rl_term_clreol;
char *_rl_term_clrpag;
char *_rl_term_cr;
char *_rl_term_backspace;
char *_rl_term_goto;
char *_rl_term_pc;
/* Non-zero if we determine that the terminal can do character insertion. */
int terminal_can_insert = 0;
int _rl_terminal_can_insert = 0;
/* How to insert characters. */
char *term_im, *term_ei, *term_ic, *term_ip, *term_IC;
char *_rl_term_im;
char *_rl_term_ei;
char *_rl_term_ic;
char *_rl_term_ip;
char *_rl_term_IC;
/* How to delete characters. */
char *term_dc, *term_DC;
char *_rl_term_dc;
char *_rl_term_DC;
#if defined (HACK_TERMCAP_MOTION)
char *term_forward_char;
char *_rl_term_forward_char;
#endif /* HACK_TERMCAP_MOTION */
/* How to go up a line. */
char *term_up;
char *_rl_term_up;
/* A visible bell, if the terminal can be made to flash the screen. */
static char *visible_bell;
/* A visible bell; char if the terminal can be made to flash the screen. */
static char *_rl_visible_bell;
/* Non-zero means the terminal can auto-wrap lines. */
int _rl_term_autowrap;
@ -116,20 +122,26 @@ int _rl_term_autowrap;
static int term_has_meta;
/* The sequences to write to turn on and off the meta key, if this
terminal has one. */
static char *term_mm, *term_mo;
terminal has one. */
static char *_rl_term_mm;
static char *_rl_term_mo;
/* The key sequences output by the arrow keys, if this terminal has any. */
static char *term_ku, *term_kd, *term_kr, *term_kl;
static char *_rl_term_ku;
static char *_rl_term_kd;
static char *_rl_term_kr;
static char *_rl_term_kl;
/* How to initialize and reset the arrow keys, if this terminal has any. */
static char *term_ks, *term_ke;
static char *_rl_term_ks;
static char *_rl_term_ke;
/* The key sequences sent by the Home and End keys, if any. */
static char *term_kh, *term_kH;
static char *_rl_term_kh;
static char *_rl_term_kH;
/* Variables that hold the screen dimensions, used by the display code. */
int screenwidth, screenheight, screenchars;
int _rl_screenwidth, _rl_screenheight, _rl_screenchars;
/* Non-zero means the user wants to enable the keypad. */
int _rl_enable_keypad;
@ -169,72 +181,92 @@ _rl_get_screen_size (tty, ignore_env)
#if defined (TIOCGWINSZ)
if (ioctl (tty, TIOCGWINSZ, &window_size) == 0)
{
screenwidth = (int) window_size.ws_col;
screenheight = (int) window_size.ws_row;
_rl_screenwidth = (int) window_size.ws_col;
_rl_screenheight = (int) window_size.ws_row;
}
#endif /* TIOCGWINSZ */
#if defined (__EMX__)
_emx_get_screensize (&screenwidth, &screenheight);
_emx_get_screensize (&_rl_screenwidth, &_rl_screenheight);
#endif
/* Environment variable COLUMNS overrides setting of "co" if IGNORE_ENV
is unset. */
if (screenwidth <= 0)
if (_rl_screenwidth <= 0)
{
if (ignore_env == 0 && (ss = get_env_value ("COLUMNS")))
screenwidth = atoi (ss);
if (ignore_env == 0 && (ss = sh_get_env_value ("COLUMNS")))
_rl_screenwidth = atoi (ss);
#if !defined (__DJGPP__)
if (screenwidth <= 0 && term_string_buffer)
screenwidth = tgetnum ("co");
if (_rl_screenwidth <= 0 && term_string_buffer)
_rl_screenwidth = tgetnum ("co");
#endif
}
/* Environment variable LINES overrides setting of "li" if IGNORE_ENV
is unset. */
if (screenheight <= 0)
if (_rl_screenheight <= 0)
{
if (ignore_env == 0 && (ss = get_env_value ("LINES")))
screenheight = atoi (ss);
if (ignore_env == 0 && (ss = sh_get_env_value ("LINES")))
_rl_screenheight = atoi (ss);
#if !defined (__DJGPP__)
if (screenheight <= 0 && term_string_buffer)
screenheight = tgetnum ("li");
if (_rl_screenheight <= 0 && term_string_buffer)
_rl_screenheight = tgetnum ("li");
#endif
}
/* If all else fails, default to 80x24 terminal. */
if (screenwidth <= 1)
screenwidth = 80;
if (_rl_screenwidth <= 1)
_rl_screenwidth = 80;
if (screenheight <= 0)
screenheight = 24;
if (_rl_screenheight <= 0)
_rl_screenheight = 24;
/* If we're being compiled as part of bash, set the environment
variables $LINES and $COLUMNS to new values. Otherwise, just
do a pair of putenv () or setenv () calls. */
set_lines_and_columns (screenheight, screenwidth);
sh_set_lines_and_columns (_rl_screenheight, _rl_screenwidth);
if (_rl_term_autowrap == 0)
screenwidth--;
_rl_screenwidth--;
screenchars = screenwidth * screenheight;
_rl_screenchars = _rl_screenwidth * _rl_screenheight;
}
void
_rl_set_screen_size (rows, cols)
int rows, cols;
{
screenheight = rows;
screenwidth = cols;
if (rows == 0 || cols == 0)
return;
_rl_screenheight = rows;
_rl_screenwidth = cols;
if (_rl_term_autowrap == 0)
screenwidth--;
_rl_screenwidth--;
screenchars = screenwidth * screenheight;
_rl_screenchars = _rl_screenwidth * _rl_screenheight;
}
void
rl_set_screen_size (rows, cols)
int rows, cols;
{
_rl_set_screen_size (rows, cols);
}
void
rl_get_screen_size (rows, cols)
int *rows, *cols;
{
if (rows)
*rows = _rl_screenheight;
if (cols)
*cols = _rl_screenwidth;
}
void
rl_resize_terminal ()
{
@ -246,7 +278,7 @@ rl_resize_terminal ()
}
struct _tc_string {
char *tc_var;
const char *tc_var;
char **tc_value;
};
@ -254,32 +286,32 @@ struct _tc_string {
search algorithm to something smarter. */
static struct _tc_string tc_strings[] =
{
{ "DC", &term_DC },
{ "IC", &term_IC },
{ "ce", &term_clreol },
{ "cl", &term_clrpag },
{ "cr", &term_cr },
{ "dc", &term_dc },
{ "ei", &term_ei },
{ "ic", &term_ic },
{ "im", &term_im },
{ "kd", &term_kd },
{ "kh", &term_kh }, /* home */
{ "kH", &term_kH }, /* end */
{ "kl", &term_kl },
{ "kr", &term_kr },
{ "ku", &term_ku },
{ "ks", &term_ks },
{ "ke", &term_ke },
{ "le", &term_backspace },
{ "mm", &term_mm },
{ "mo", &term_mo },
{ "DC", &_rl_term_DC },
{ "IC", &_rl_term_IC },
{ "ce", &_rl_term_clreol },
{ "cl", &_rl_term_clrpag },
{ "cr", &_rl_term_cr },
{ "dc", &_rl_term_dc },
{ "ei", &_rl_term_ei },
{ "ic", &_rl_term_ic },
{ "im", &_rl_term_im },
{ "kd", &_rl_term_kd },
{ "kh", &_rl_term_kh }, /* home */
{ "kH", &_rl_term_kH }, /* end */
{ "kl", &_rl_term_kl },
{ "kr", &_rl_term_kr },
{ "ku", &_rl_term_ku },
{ "ks", &_rl_term_ks },
{ "ke", &_rl_term_ke },
{ "le", &_rl_term_backspace },
{ "mm", &_rl_term_mm },
{ "mo", &_rl_term_mo },
#if defined (HACK_TERMCAP_MOTION)
{ "nd", &term_forward_char },
{ "nd", &_rl_term_forward_char },
#endif
{ "pc", &term_pc },
{ "up", &term_up },
{ "vb", &visible_bell },
{ "pc", &_rl_term_pc },
{ "up", &_rl_term_up },
{ "vb", &_rl_visible_bell },
};
#define NUM_TC_STRINGS (sizeof (tc_strings) / sizeof (struct _tc_string))
@ -304,16 +336,17 @@ get_term_capabilities (bp)
int
_rl_init_terminal_io (terminal_name)
char *terminal_name;
const char *terminal_name;
{
char *term, *buffer;
const char *term;
char *buffer;
int tty, tgetent_ret;
Keymap xkeymap;
term = terminal_name ? terminal_name : get_env_value ("TERM");
term_clrpag = term_cr = term_clreol = (char *)NULL;
term = terminal_name ? terminal_name : sh_get_env_value ("TERM");
_rl_term_clrpag = _rl_term_cr = _rl_term_clreol = (char *)NULL;
tty = rl_instream ? fileno (rl_instream) : 0;
screenwidth = screenheight = 0;
_rl_screenwidth = _rl_screenheight = 0;
if (term == 0)
term = "dumb";
@ -344,41 +377,40 @@ _rl_init_terminal_io (terminal_name)
FREE (term_buffer);
buffer = term_buffer = term_string_buffer = (char *)NULL;
dumb_term = 1;
_rl_term_autowrap = 0; /* used by _rl_get_screen_size */
#if defined (__EMX__)
_emx_get_screensize (&screenwidth, &screenheight);
screenwidth--;
_emx_get_screensize (&_rl_screenwidth, &_rl_screenheight);
_rl_screenwidth--;
#else /* !__EMX__ */
_rl_get_screen_size (tty, 0);
#endif /* !__EMX__ */
/* Defaults. */
if (screenwidth <= 0 || screenheight <= 0)
if (_rl_screenwidth <= 0 || _rl_screenheight <= 0)
{
screenwidth = 79;
screenheight = 24;
_rl_screenwidth = 79;
_rl_screenheight = 24;
}
/* Everything below here is used by the redisplay code (tputs). */
screenchars = screenwidth * screenheight;
term_cr = "\r";
term_im = term_ei = term_ic = term_IC = (char *)NULL;
term_up = term_dc = term_DC = visible_bell = (char *)NULL;
term_ku = term_kd = term_kl = term_kr = (char *)NULL;
term_mm = term_mo = (char *)NULL;
_rl_screenchars = _rl_screenwidth * _rl_screenheight;
_rl_term_cr = "\r";
_rl_term_im = _rl_term_ei = _rl_term_ic = _rl_term_IC = (char *)NULL;
_rl_term_up = _rl_term_dc = _rl_term_DC = _rl_visible_bell = (char *)NULL;
_rl_term_ku = _rl_term_kd = _rl_term_kl = _rl_term_kr = (char *)NULL;
_rl_term_mm = _rl_term_mo = (char *)NULL;
#if defined (HACK_TERMCAP_MOTION)
term_forward_char = (char *)NULL;
#endif
terminal_can_insert = term_has_meta = 0;
_rl_terminal_can_insert = term_has_meta = 0;
/* Reasonable defaults for tgoto(). Readline currently only uses
tgoto if term_IC or term_DC is defined, but just in case we
tgoto if _rl_term_IC or _rl_term_DC is defined, but just in case we
change that later... */
PC = '\0';
BC = term_backspace = "\b";
UP = term_up;
BC = _rl_term_backspace = "\b";
UP = _rl_term_up;
return 0;
}
@ -387,12 +419,12 @@ _rl_init_terminal_io (terminal_name)
/* Set up the variables that the termcap library expects the application
to provide. */
PC = term_pc ? *term_pc : 0;
BC = term_backspace;
UP = term_up;
PC = _rl_term_pc ? *_rl_term_pc : 0;
BC = _rl_term_backspace;
UP = _rl_term_up;
if (!term_cr)
term_cr = "\r";
if (!_rl_term_cr)
_rl_term_cr = "\r";
_rl_term_autowrap = tgetflag ("am") && tgetflag ("xn");
@ -402,36 +434,36 @@ _rl_init_terminal_io (terminal_name)
character insertion if *any one of* the capabilities `IC',
`im', `ic' or `ip' is provided." But we can't do anything if
only `ip' is provided, so... */
terminal_can_insert = (term_IC || term_im || term_ic);
_rl_terminal_can_insert = (_rl_term_IC || _rl_term_im || _rl_term_ic);
/* Check to see if this terminal has a meta key and clear the capability
variables if there is none. */
term_has_meta = (tgetflag ("km") || tgetflag ("MT"));
if (!term_has_meta)
term_mm = term_mo = (char *)NULL;
_rl_term_mm = _rl_term_mo = (char *)NULL;
/* Attempt to find and bind the arrow keys. Do not override already
bound keys in an overzealous attempt, however. */
xkeymap = _rl_keymap;
_rl_keymap = emacs_standard_keymap;
_rl_bind_if_unbound (term_ku, rl_get_previous_history);
_rl_bind_if_unbound (term_kd, rl_get_next_history);
_rl_bind_if_unbound (term_kr, rl_forward);
_rl_bind_if_unbound (term_kl, rl_backward);
_rl_bind_if_unbound (_rl_term_ku, rl_get_previous_history);
_rl_bind_if_unbound (_rl_term_kd, rl_get_next_history);
_rl_bind_if_unbound (_rl_term_kr, rl_forward);
_rl_bind_if_unbound (_rl_term_kl, rl_backward);
_rl_bind_if_unbound (term_kh, rl_beg_of_line); /* Home */
_rl_bind_if_unbound (term_kH, rl_end_of_line); /* End */
_rl_bind_if_unbound (_rl_term_kh, rl_beg_of_line); /* Home */
_rl_bind_if_unbound (_rl_term_kH, rl_end_of_line); /* End */
#if defined (VI_MODE)
_rl_keymap = vi_movement_keymap;
_rl_bind_if_unbound (term_ku, rl_get_previous_history);
_rl_bind_if_unbound (term_kd, rl_get_next_history);
_rl_bind_if_unbound (term_kr, rl_forward);
_rl_bind_if_unbound (term_kl, rl_backward);
_rl_bind_if_unbound (_rl_term_ku, rl_get_previous_history);
_rl_bind_if_unbound (_rl_term_kd, rl_get_next_history);
_rl_bind_if_unbound (_rl_term_kr, rl_forward);
_rl_bind_if_unbound (_rl_term_kl, rl_backward);
_rl_bind_if_unbound (term_kh, rl_beg_of_line); /* Home */
_rl_bind_if_unbound (term_kH, rl_end_of_line); /* End */
_rl_bind_if_unbound (_rl_term_kh, rl_beg_of_line); /* Home */
_rl_bind_if_unbound (_rl_term_kH, rl_end_of_line); /* End */
#endif /* VI_MODE */
_rl_keymap = xkeymap;
@ -441,7 +473,7 @@ _rl_init_terminal_io (terminal_name)
char *
rl_get_termcap (cap)
char *cap;
const char *cap;
{
register int i;
@ -459,7 +491,7 @@ rl_get_termcap (cap)
has changed. */
int
rl_reset_terminal (terminal_name)
char *terminal_name;
const char *terminal_name;
{
_rl_init_terminal_io (terminal_name);
return 0;
@ -485,7 +517,7 @@ _rl_output_character_function (c)
/* Write COUNT characters from STRING to the output stream. */
void
_rl_output_some_chars (string, count)
char *string;
const char *string;
int count;
{
fwrite (string, 1, count, _rl_out_stream);
@ -498,9 +530,9 @@ _rl_backspace (count)
{
register int i;
if (term_backspace)
if (_rl_term_backspace)
for (i = 0; i < count; i++)
tputs (term_backspace, 1, _rl_output_character_function);
tputs (_rl_term_backspace, 1, _rl_output_character_function);
else
for (i = 0; i < count; i++)
putc ('\b', _rl_out_stream);
@ -509,11 +541,11 @@ _rl_backspace (count)
/* Move to the start of the next line. */
int
crlf ()
rl_crlf ()
{
#if defined (NEW_TTY_DRIVER)
if (term_cr)
tputs (term_cr, 1, _rl_output_character_function);
if (_rl_term_cr)
tputs (_rl_term_cr, 1, _rl_output_character_function);
#endif /* NEW_TTY_DRIVER */
putc ('\n', _rl_out_stream);
return 0;
@ -521,7 +553,7 @@ crlf ()
/* Ring the terminal bell. */
int
ding ()
rl_ding ()
{
if (readline_echoing_p)
{
@ -531,9 +563,9 @@ ding ()
default:
break;
case VISIBLE_BELL:
if (visible_bell)
if (_rl_visible_bell)
{
tputs (visible_bell, 1, _rl_output_character_function);
tputs (_rl_visible_bell, 1, _rl_output_character_function);
break;
}
/* FALLTHROUGH */
@ -557,8 +589,8 @@ void
_rl_enable_meta_key ()
{
#if !defined (__DJGPP__)
if (term_has_meta && term_mm)
tputs (term_mm, 1, _rl_output_character_function);
if (term_has_meta && _rl_term_mm)
tputs (_rl_term_mm, 1, _rl_output_character_function);
#endif
}
@ -567,9 +599,9 @@ _rl_control_keypad (on)
int on;
{
#if !defined (__DJGPP__)
if (on && term_ks)
tputs (term_ks, 1, _rl_output_character_function);
else if (!on && term_ke)
tputs (term_ke, 1, _rl_output_character_function);
if (on && _rl_term_ks)
tputs (_rl_term_ks, 1, _rl_output_character_function);
else if (!on && _rl_term_ke)
tputs (_rl_term_ke, 1, _rl_output_character_function);
#endif
}

View file

@ -50,16 +50,13 @@
#if defined (TEST) || defined (STATIC_MALLOC)
static char *xmalloc (), *xrealloc ();
#else
# if defined __STDC__
extern char *xmalloc (int);
extern char *xrealloc (void *, int);
# else
extern char *xmalloc (), *xrealloc ();
# endif /* !__STDC__ */
extern char *xmalloc __P((int));
extern char *xrealloc __P((void *, int));
#endif /* TEST || STATIC_MALLOC */
#if !defined (HAVE_GETPW_DECLS)
extern struct passwd *getpwuid (), *getpwnam ();
extern struct passwd *getpwuid __P((uid_t));
extern struct passwd *getpwnam __P((const char *));
#endif /* !HAVE_GETPW_DECLS */
#if !defined (savestring)
@ -80,42 +77,42 @@ extern char *strcpy ();
/* If being compiled as part of bash, these will be satisfied from
variables.o. If being compiled as part of readline, they will
be satisfied from shell.o. */
extern char *get_home_dir __P((void));
extern char *get_env_value __P((char *));
extern char *sh_get_home_dir __P((void));
extern char *sh_get_env_value __P((const char *));
/* The default value of tilde_additional_prefixes. This is set to
whitespace preceding a tilde so that simple programs which do not
perform any word separation get desired behaviour. */
static char *default_prefixes[] =
{ " ~", "\t~", (char *)NULL };
static const char *default_prefixes[] =
{ " ~", "\t~", (const char *)NULL };
/* The default value of tilde_additional_suffixes. This is set to
whitespace or newline so that simple programs which do not
perform any word separation get desired behaviour. */
static char *default_suffixes[] =
{ " ", "\n", (char *)NULL };
static const char *default_suffixes[] =
{ " ", "\n", (const char *)NULL };
/* If non-null, this contains the address of a function that the application
wants called before trying the standard tilde expansions. The function
is called with the text sans tilde, and returns a malloc()'ed string
which is the expansion, or a NULL pointer if the expansion fails. */
CPFunction *tilde_expansion_preexpansion_hook = (CPFunction *)NULL;
tilde_hook_func_t *tilde_expansion_preexpansion_hook = (tilde_hook_func_t *)NULL;
/* If non-null, this contains the address of a function to call if the
standard meaning for expanding a tilde fails. The function is called
with the text (sans tilde, as in "foo"), and returns a malloc()'ed string
which is the expansion, or a NULL pointer if there is no expansion. */
CPFunction *tilde_expansion_failure_hook = (CPFunction *)NULL;
tilde_hook_func_t *tilde_expansion_failure_hook = (tilde_hook_func_t *)NULL;
/* When non-null, this is a NULL terminated array of strings which
are duplicates for a tilde prefix. Bash uses this to expand
`=~' and `:~'. */
char **tilde_additional_prefixes = default_prefixes;
char **tilde_additional_prefixes = (char **)default_prefixes;
/* When non-null, this is a NULL terminated array of strings which match
the end of a username, instead of just "/". Bash sets this to
`:' and `=~'. */
char **tilde_additional_suffixes = default_suffixes;
char **tilde_additional_suffixes = (char **)default_suffixes;
/* Find the start of a tilde expansion in STRING, and return the index of
the tilde which starts the expansion. Place the length of the text
@ -186,7 +183,7 @@ tilde_find_suffix (string)
/* Return a new string which is the result of tilde expanding STRING. */
char *
tilde_expand (string)
char *string;
const char *string;
{
char *result;
int result_size, result_index;
@ -235,9 +232,9 @@ tilde_expand (string)
free (tilde_word);
len = strlen (expansion);
#ifdef __CYGWIN32__
#ifdef __CYGWIN__
/* Fix for Cygwin to prevent ~user/xxx from expanding to //xxx when
$HOME for `user' is /. On cygwin, // denotes a network drive. */
$HOME for `user' is /. On cygwin, // denotes a network drive. */
if (len > 1 || *expansion != '/' || *string != '/')
#endif
{
@ -303,7 +300,7 @@ glue_prefix_and_suffix (prefix, suffix, suffind)
This always returns a newly-allocated string, never static storage. */
char *
tilde_expand_word (filename)
char *filename;
const char *filename;
{
char *dirname, *expansion, *username;
int user_len;
@ -321,12 +318,12 @@ tilde_expand_word (filename)
if (filename[1] == '\0' || filename[1] == '/')
{
/* Prefix $HOME to the rest of the string. */
expansion = get_env_value ("HOME");
expansion = sh_get_env_value ("HOME");
/* If there is no HOME variable, look up the directory in
the password database. */
if (expansion == 0)
expansion = get_home_dir ();
expansion = sh_get_home_dir ();
return (glue_prefix_and_suffix (expansion, filename, 1));
}

View file

@ -40,26 +40,31 @@ extern "C" {
# endif
#endif
/* Function pointers can be declared as (Function *)foo. */
#if !defined (_FUNCTION_DEF)
# define _FUNCTION_DEF
typedef int Function ();
typedef void VFunction ();
typedef char *CPFunction ();
typedef char **CPPFunction ();
#endif /* _FUNCTION_DEF */
#if !defined (__STDC__) && !defined (__cplusplus)
# if defined (__GNUC__) /* gcc with -traditional */
# if !defined (const)
# define const __const
# endif /* !const */
# else /* !__GNUC__ */
# if !defined (const)
# define const
# endif /* !const */
# endif /* !__GNUC__ */
#endif /* !__STDC__ && !__cplusplus */
typedef char *tilde_hook_func_t __P((char *));
/* If non-null, this contains the address of a function that the application
wants called before trying the standard tilde expansions. The function
is called with the text sans tilde, and returns a malloc()'ed string
which is the expansion, or a NULL pointer if the expansion fails. */
extern CPFunction *tilde_expansion_preexpansion_hook;
extern tilde_hook_func_t *tilde_expansion_preexpansion_hook;
/* If non-null, this contains the address of a function to call if the
standard meaning for expanding a tilde fails. The function is called
with the text (sans tilde, as in "foo"), and returns a malloc()'ed string
which is the expansion, or a NULL pointer if there is no expansion. */
extern CPFunction *tilde_expansion_failure_hook;
extern tilde_hook_func_t *tilde_expansion_failure_hook;
/* When non-null, this is a NULL terminated array of strings which
are duplicates for a tilde prefix. Bash uses this to expand
@ -72,11 +77,11 @@ extern char **tilde_additional_prefixes;
extern char **tilde_additional_suffixes;
/* Return a new string which is the result of tilde expanding STRING. */
extern char *tilde_expand __P((char *));
extern char *tilde_expand __P((const char *));
/* Do the work of tilde expansion on FILENAME. FILENAME starts with a
tilde. If there is no expansion, call tilde_expansion_failure_hook. */
extern char *tilde_expand_word __P((char *));
extern char *tilde_expand_word __P((const char *));
#ifdef __cplusplus
}

View file

@ -86,7 +86,7 @@ rl_add_undo (what, start, end, text)
/* Free the existing undo list. */
void
free_undo_list ()
rl_free_undo_list ()
{
while (rl_undo_list)
{
@ -107,17 +107,18 @@ int
rl_do_undo ()
{
UNDO_LIST *release;
int waiting_for_begin = 0;
int start, end;
int waiting_for_begin, start, end;
#define TRANS(i) ((i) == -1 ? rl_point : ((i) == -2 ? rl_end : (i)))
start = end = waiting_for_begin = 0;
do
{
if (!rl_undo_list)
return (0);
_rl_doing_an_undo = 1;
RL_SETSTATE(RL_STATE_UNDOING);
/* To better support vi-mode, a start or end value of -1 means
rl_point, and a value of -2 means rl_end. */
@ -152,11 +153,12 @@ rl_do_undo ()
if (waiting_for_begin)
waiting_for_begin--;
else
ding ();
rl_ding ();
break;
}
_rl_doing_an_undo = 0;
RL_UNSETSTATE(RL_STATE_UNDOING);
release = rl_undo_list;
rl_undo_list = rl_undo_list->next;
@ -231,7 +233,7 @@ rl_revert_line (count, key)
int count, key;
{
if (!rl_undo_list)
ding ();
rl_ding ();
else
{
while (rl_undo_list)
@ -254,7 +256,7 @@ rl_undo_command (count, key)
count--;
else
{
ding ();
rl_ding ();
break;
}
}

View file

@ -67,10 +67,10 @@
in words, or 1 if it is. */
int _rl_allow_pathname_alphabetic_chars = 0;
static char *pathname_alphabetic_chars = "/-_=~.#$";
static const char *pathname_alphabetic_chars = "/-_=~.#$";
int
alphabetic (c)
rl_alphabetic (c)
int c;
{
if (ALPHABETIC (c))
@ -84,16 +84,16 @@ alphabetic (c)
int
_rl_abort_internal ()
{
ding ();
rl_ding ();
rl_clear_message ();
_rl_init_argument ();
rl_pending_input = 0;
rl_clear_pending_input ();
_rl_defining_kbd_macro = 0;
while (_rl_executing_macro)
while (rl_executing_macro)
_rl_pop_executing_macro ();
rl_last_func = (Function *)NULL;
rl_last_func = (rl_command_func_t *)NULL;
longjmp (readline_top_level, 1);
return (0);
}
@ -113,7 +113,7 @@ rl_tty_status (count, key)
ioctl (1, TIOCSTAT, (char *)0);
rl_refresh_line (count, key);
#else
ding ();
rl_ding ();
#endif
return 0;
}
@ -215,13 +215,32 @@ rl_tilde_expand (ignore, key)
match in s1. The compare is case insensitive. */
char *
_rl_strindex (s1, s2)
register char *s1, *s2;
register const char *s1, *s2;
{
register int i, l, len;
for (i = 0, l = strlen (s2), len = strlen (s1); (len - i) >= l; i++)
if (_rl_strnicmp (s1 + i, s2, l) == 0)
return (s1 + i);
return ((char *) (s1 + i));
return ((char *)NULL);
}
/* Find the first occurrence in STRING1 of any character from STRING2.
Return a pointer to the character in STRING1. */
char *
_rl_strpbrk (string1, string2)
const char *string1, *string2;
{
register const char *scan;
for (; *string1; string1++)
{
for (scan = string2; *scan; scan++)
{
if (*string1 == *scan)
return ((char *)string1);
}
}
return ((char *)NULL);
}
@ -345,7 +364,7 @@ _rl_digit_value (c)
#undef _rl_savestring
char *
_rl_savestring (s)
char *s;
const char *s;
{
return ((char *)strcpy (xmalloc (1 + (int)strlen (s)), (s)));
return (strcpy (xmalloc (1 + (int)strlen (s)), (s)));
}

File diff suppressed because it is too large Load diff

View file

@ -81,7 +81,7 @@
static int _rl_vi_doing_insert;
/* Command keys which do movement for xxx_to commands. */
static char *vi_motion = " hl^$0ftFt;,%wbeWBE|";
static const char *vi_motion = " hl^$0ftFt;,%wbeWBE|";
/* Keymap used for vi replace characters. Created dynamically since
rarely used. */
@ -109,7 +109,7 @@ static int _rl_vi_last_key_before_insert;
static int vi_redoing;
/* Text modification commands. These are the `redoable' commands. */
static char *vi_textmod = "_*\\AaIiCcDdPpYyRrSsXx~";
static const char *vi_textmod = "_*\\AaIiCcDdPpYyRrSsXx~";
/* Arrays for the saved marks. */
static int vi_mark_chars[27];
@ -274,7 +274,7 @@ rl_vi_search (count, key)
break;
default:
ding ();
rl_ding ();
break;
}
return (0);
@ -330,7 +330,7 @@ rl_vi_prev_word (count, key)
if (rl_point == 0)
{
ding ();
rl_ding ();
return (0);
}
@ -352,7 +352,7 @@ rl_vi_next_word (count, key)
if (rl_point >= (rl_end - 1))
{
ding ();
rl_ding ();
return (0);
}
@ -370,7 +370,7 @@ rl_vi_end_word (count, key)
{
if (count < 0)
{
ding ();
rl_ding ();
return -1;
}
@ -744,7 +744,9 @@ rl_vi_domove (key, nextkey)
int old_end;
rl_mark = rl_point;
RL_SETSTATE(RL_STATE_MOREINPUT);
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
*nextkey = c;
if (!member (c, vi_motion))
@ -755,7 +757,9 @@ rl_vi_domove (key, nextkey)
rl_numeric_arg = _rl_digit_value (c);
rl_digit_loop1 ();
rl_numeric_arg *= save;
RL_SETSTATE(RL_STATE_MOREINPUT);
c = rl_read_key (); /* real command */
RL_UNSETSTATE(RL_STATE_MOREINPUT);
*nextkey = c;
}
else if (key == c && (key == 'd' || key == 'y' || key == 'c'))
@ -825,16 +829,28 @@ rl_vi_domove (key, nextkey)
}
/* A simplified loop for vi. Don't dispatch key at end.
Don't recognize minus sign? */
Don't recognize minus sign?
Should this do rl_save_prompt/rl_restore_prompt? */
static int
rl_digit_loop1 ()
{
int key, c;
RL_SETSTATE(RL_STATE_NUMERICARG);
while (1)
{
if (rl_numeric_arg > 1000000)
{
rl_explicit_arg = rl_numeric_arg = 0;
rl_ding ();
rl_clear_message ();
RL_UNSETSTATE(RL_STATE_NUMERICARG);
return 1;
}
rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg, 0);
RL_SETSTATE(RL_STATE_MOREINPUT);
key = c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
if (_rl_keymap[c].type == ISFUNC &&
_rl_keymap[c].function == rl_universal_argument)
@ -859,6 +875,8 @@ rl_digit_loop1 ()
break;
}
}
RL_UNSETSTATE(RL_STATE_NUMERICARG);
return (0);
}
@ -875,7 +893,7 @@ rl_vi_delete_to (count, key)
if (rl_vi_domove (key, &c))
{
ding ();
rl_ding ();
return -1;
}
@ -903,7 +921,7 @@ rl_vi_change_to (count, key)
if (rl_vi_domove (key, &c))
{
ding ();
rl_ding ();
return -1;
}
@ -953,7 +971,7 @@ rl_vi_yank_to (count, key)
if (rl_vi_domove (key, &c))
{
ding ();
rl_ding ();
return -1;
}
@ -979,7 +997,7 @@ rl_vi_delete (count, key)
if (rl_end == 0)
{
ding ();
rl_ding ();
return -1;
}
@ -1026,7 +1044,11 @@ rl_vi_char_search (count, key)
if (vi_redoing)
target = _rl_vi_last_search_char;
else
_rl_vi_last_search_char = target = (*rl_getc_function) (rl_instream);
{
RL_SETSTATE(RL_STATE_MOREINPUT);
_rl_vi_last_search_char = target = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
}
switch (key)
{
@ -1068,7 +1090,7 @@ rl_vi_match (ignore, key)
if (brack <= 0)
{
rl_point = pos;
ding ();
rl_ding ();
return -1;
}
}
@ -1089,7 +1111,7 @@ rl_vi_match (ignore, key)
}
else
{
ding ();
rl_ding ();
return -1;
}
}
@ -1108,7 +1130,7 @@ rl_vi_match (ignore, key)
}
else
{
ding ();
rl_ding ();
return -1;
}
}
@ -1142,7 +1164,11 @@ rl_vi_change_char (count, key)
if (vi_redoing)
c = _rl_vi_last_replacement;
else
_rl_vi_last_replacement = c = (*rl_getc_function) (rl_instream);
{
RL_SETSTATE(RL_STATE_MOREINPUT);
_rl_vi_last_replacement = c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
}
if (c == '\033' || c == CTRL ('C'))
return -1;
@ -1238,7 +1264,7 @@ rl_vi_overstrike_delete (count, key)
{
if (vi_replace_count == 0)
{
ding ();
rl_ding ();
break;
}
s = rl_point;
@ -1308,7 +1334,7 @@ rl_vi_possible_completions()
}
else if (rl_line_buffer[rl_point - 1] == ';')
{
ding ();
rl_ding ();
return (0);
}
@ -1326,10 +1352,13 @@ rl_vi_set_mark (count, key)
{
int ch;
RL_SETSTATE(RL_STATE_MOREINPUT);
ch = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
if (_rl_lowercase_p (ch) == 0)
{
ding ();
rl_ding ();
return -1;
}
ch -= 'a';
@ -1343,7 +1372,10 @@ rl_vi_goto_mark (count, key)
{
int ch;
RL_SETSTATE(RL_STATE_MOREINPUT);
ch = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
if (ch == '`')
{
rl_point = rl_mark;
@ -1351,14 +1383,14 @@ rl_vi_goto_mark (count, key)
}
else if (_rl_lowercase_p (ch) == 0)
{
ding ();
rl_ding ();
return -1;
}
ch -= 'a';
if (vi_mark_chars[ch] == -1)
{
ding ();
rl_ding ();
return -1;
}
rl_point = vi_mark_chars[ch];

View file

@ -64,7 +64,9 @@ LIBRARY_NAME = libsh.a
CSOURCES = clktck.c clock.c getcwd.c getenv.c oslib.c setlinebuf.c \
strcasecmp.c strerror.c strtod.c strtol.c strtoul.c \
vprint.c itos.c rename.c zread.c zwrite.c shtty.c \
inet_aton.c netopen.c strpbrk.c timeval.c makepath.c
inet_aton.c netopen.c strpbrk.c timeval.c makepath.c pathcanon.c \
pathphys.c tmpfile.c stringlist.c stringvec.c spell.c \
shquote.c strtrans.c strindex.c
# The header files for this library.
HSOURCES =
@ -73,7 +75,9 @@ HSOURCES =
OBJECTS = clktck.o clock.o getcwd.o getenv.o oslib.o setlinebuf.o \
strcasecmp.o strerror.o strtod.o strtol.o strtoul.o \
vprint.o itos.o rename.o zread.o zwrite.o shtty.o \
inet_aton.o netopen.o strpbrk.o timeval.o makepath.o
inet_aton.o netopen.o strpbrk.o timeval.o makepath.o pathcanon.o \
pathphys.o tmpfile.o stringlist.o stringvec.o spell.o shquote.o \
strtrans.o strindex.o
SUPPORT = Makefile
@ -108,20 +112,29 @@ getcwd.o: getcwd.c
getenv.o: getenv.c
inet_aton.o: inet_aton.c
itos.o: itos.c
makepath.o: makepath.c
netopen.o: netopen.c
oslib.o: oslib.c
pathcanon.o: pathcanon.c
pathphys.o: pathphys.c
rename.o: rename.c
setlinebuf.o: setlinebuf.c
shquote.o: shquote.c
shtty.o: shtty.c
spell.o: spell.c
strcasecmp.o: strcasecmp.c
strerror.o: strerror.c
strindex.o: strindex.c
stringlist.o: stringlist.c
stringvec.o: stringvec.c
strpbrk.o: strpbrk.c
strtod.o: strtod.c
strtol.o: strtol.c
strtoul.o: strtoul.c
strtrans.o: strtrans.c
times.o: times.c
timeval.o: timeval.c
tmpfile.o: tmpfile.c
vprint.o: vprint.c
zread.o: zread.c
zwrite.o: zwrite.c
@ -133,20 +146,29 @@ getcwd.o: ${BUILD_DIR}/config.h
getenv.o: ${BUILD_DIR}/config.h
inet_aton.o: ${BUILD_DIR}/config.h
itos.o: ${BUILD_DIR}/config.h
makepath.o: ${BUILD_DIR}/config.h
netopen.o: ${BUILD_DIR}/config.h
oslib.o: ${BUILD_DIR}/config.h
pathcanon.o: ${BUILD_DIR}/config.h
pathphys.o: ${BUILD_DIR}/config.h
rename.o: ${BUILD_DIR}/config.h
setlinebuf.o: ${BUILD_DIR}/config.h
shquote.o: ${BUILD_DIR}/config.h
shtty.o: ${BUILD_DIR}/config.h
spell.o: ${BUILD_DIR}/config.h
strcasecmp.o: ${BUILD_DIR}/config.h
strerror.o: ${BUILD_DIR}/config.h
strindex.o: ${BUILD_DIR}/config.h
stringlist.o: ${BUILD_DIR}/config.h
stringvec.o: ${BUILD_DIR}/config.h
strpbrk.o: ${BUILD_DIR}/config.h
strtod.o: ${BUILD_DIR}/config.h
strtol.o: ${BUILD_DIR}/config.h
strtoul.o: ${BUILD_DIR}/config.h
strtrans.o: ${BUILD_DIR}/config.h
times.o: ${BUILD_DIR}/config.h
timeval.o: ${BUILD_DIR}/config.h
tmpfile.o: ${BUILD_DIR}/config.h
vprint.o: ${BUILD_DIR}/config.h
zread.o: ${BUILD_DIR}/config.h
zwrite.o: ${BUILD_DIR}/config.h
@ -158,7 +180,7 @@ getcwd.o: ${BASHINCDIR}/posixstat.h ${BASHINCDIR}/posixdir.h
getcwd.o: ${BASHINCDIR}/memalloc.h ${BASHINCDIR}/ansi_stdlib.h
getenv.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
getenv.o: ${topdir}/shell.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
getenv.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
getenv.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
getenv.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h
getenv.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
@ -170,7 +192,7 @@ inet_aton.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
inet_aton.o: ${BASHINCDIR}/stdc.h
itos.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
itos.o: ${topdir}/shell.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
itos.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
itos.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
itos.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h
itos.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
@ -178,10 +200,19 @@ itos.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
itos.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
itos.o: ${topdir}/pathnames.h ${topdir}/externs.h
makepath.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
makepath.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
makepath.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
makepath.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h
makepath.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
makepath.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
makepath.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
makepath.o: ${topdir}/pathnames.h ${topdir}/externs.h
netopen.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
oslib.o: ${topdir}/bashtypes.h ${topdir}/bashansi.h ${BASHINCDIR}/maxpath.h
oslib.o: ${topdir}/shell.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
oslib.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
oslib.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
oslib.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h
oslib.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
@ -191,15 +222,42 @@ oslib.o: ${topdir}/pathnames.h ${topdir}/externs.h
oslib.o: ${BASHINCDIR}/posixstat.h ${BASHINCDIR}/filecntl.h
oslib.o: ${BASHINCDIR}/ansi_stdlib.h
pathcanon.o: ${topdir}/bashtypes.h ${topdir}/bashansi.h ${BASHINCDIR}/maxpath.h
pathcanon.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
pathcanon.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
pathcanon.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h
pathcanon.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
pathcanon.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
pathcanon.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
pathcanon.o: ${topdir}/pathnames.h ${topdir}/externs.h
pathcanon.o: ${BASHINCDIR}/posixstat.h ${BASHINCDIR}/filecntl.h
pathcanon.o: ${BASHINCDIR}/ansi_stdlib.h
pathphys.o: ${topdir}/bashtypes.h ${topdir}/bashansi.h ${BASHINCDIR}/maxpath.h
pathphys.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
pathphys.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
pathphys.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h
pathphys.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
pathphys.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
pathphys.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
pathphys.o: ${topdir}/pathnames.h ${topdir}/externs.h
pathphys.o: ${BASHINCDIR}/posixstat.h ${BASHINCDIR}/filecntl.h
pathphys.o: ${BASHINCDIR}/ansi_stdlib.h
rename.o: ${topdir}/bashtypes.h ${BASHINCDIR}/stdc.h
shtty.o: ${BASHINCDIR}/shtty.h
shtty.o: ${BASHINCDIR}/stdc.h
strcasecmp.o: ${BASHINCDIR}/stdc.h ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
spell.o: ${topdir}/bashtypes.h
spell.o: ${BASHINCDIR}/posixstat.h ${BASHINCDIR}/posixdir.h
spell.o: ${BASHINCDIR}/ansi_stdlib.h
strcasecmp.o: ${BASHINCDIR}/stdc.h ${topdir}/bashansi.h
strcasecmp.o: ${BASHINCDIR}/ansi_stdlib.h
strerror.o: ${topdir}/bashtypes.h
strerror.o: ${topdir}/shell.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
strerror.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
strerror.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
strerror.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h
strerror.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
@ -207,6 +265,27 @@ strerror.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
strerror.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
strerror.o: ${topdir}/pathnames.h ${topdir}/externs.h
strindex.o: ${BASHINCDIR}/stdc.h ${topdir}/bashansi.h
strindex.o: ${BASHINCDIR}/ansi_stdlib.h
stringlist.o: ${topdir}/bashansi.h
stringlist.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
stringlist.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
stringlist.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h
stringlist.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
stringlist.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
stringlist.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
stringlist.o: ${topdir}/pathnames.h ${topdir}/externs.h
stringvec.o: ${topdir}/bashansi.h
stringvec.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
stringvec.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
stringvec.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h
stringvec.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
stringvec.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
stringvec.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
stringvec.o: ${topdir}/pathnames.h ${topdir}/externs.h
strpbrk.o: ${BASHINCDIR}/stdc.h
strtod.o: ${topdir}/bashansi.h
@ -218,9 +297,23 @@ strtol.o: ${BASHINCDIR}/ansi_stdlib.h
strtoul.o: ${topdir}/bashansi.h
strtoul.o: ${BASHINCDIR}/ansi_stdlib.h
strtrans.o: ${topdir}/bashansi.h
strtrans.o: ${BASHINCDIR}/ansi_stdlib.h
strtrans.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
strtrans.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
strtrans.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h
strtrans.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
strtrans.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
strtrans.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
strtrans.o: ${topdir}/pathnames.h ${topdir}/externs.h
times.o: ${BASHINCDIR}/systimes.h
times.o: ${BASHINCDIR}/posixtime.h
timeval.o: ${BASHINCDIR}/posixtime.h
tmpfile.o: ${topdir}/bashtypes.h
tmpfile.o: ${BASHINCDIR}/posixstat.h
tmpfile.o: ${BASHINCDIR}/filecntl.h
clock.o: ${BASHINCDIR}/posixtime.h

View file

@ -68,7 +68,7 @@ sh_makepath (path, dir, flags)
int flags;
{
int dirlen, pathlen;
char *ret, *xpath;
char *ret, *xpath, *r, *s;
if (path == 0 || *path == '\0')
{
@ -102,14 +102,15 @@ sh_makepath (path, dir, flags)
dirlen -= 2;
}
ret = xmalloc (2 + dirlen + pathlen);
strcpy (ret, xpath);
if (xpath[pathlen - 1] != '/')
{
ret[pathlen++] = '/';
ret[pathlen] = '\0';
}
strcpy (ret + pathlen, dir);
r = ret = xmalloc (2 + dirlen + pathlen);
s = xpath;
while (*s)
*r++ = *s++;
if (s[-1] != '/')
*r++ = '/';
s = dir;
while (*r++ = *s++)
;
if (xpath != path)
free (xpath);
return (ret);

View file

@ -97,8 +97,9 @@ _getaddr (host, ap)
/* Return 1 if SERV is a valid port number and stuff the converted value into
PP in network byte order. */
static int
_getserv (serv, pp)
_getserv (serv, proto, pp)
char *serv;
int proto;
unsigned short *pp;
{
long l;
@ -115,7 +116,20 @@ _getserv (serv, pp)
return 1;
}
else
#if defined (HAVE_GETSERVBYNAME)
{
struct servent *se;
se = getservbyname (serv, (proto == 't') ? "tcp" : "udp");
if (se == 0)
return 0;
if (pp)
*pp = se->s_port; /* ports returned in network byte order */
return 1;
}
#else /* !HAVE_GETSERVBYNAME */
return 0;
#endif /* !HAVE_GETSERVBYNAME */
}
static int
@ -126,18 +140,20 @@ _netopen(host, serv, typ)
struct in_addr ina;
struct sockaddr_in sin;
unsigned short p;
int s;
int s, e;
char **cp;
if (_getaddr(host, &ina) == 0)
{
internal_error ("%s: host unknown", host);
errno = EINVAL;
return -1;
}
if (_getserv(serv, &p) == 0)
if (_getserv(serv, typ, &p) == 0)
{
internal_error("%s: invalid service", serv);
errno = EINVAL;
return -1;
}
@ -155,8 +171,10 @@ _netopen(host, serv, typ)
if (connect (s, (struct sockaddr *)&sin, sizeof (sin)) < 0)
{
e = errno;
sys_error("connect");
close(s);
errno = e;
return (-1);
}

195
lib/sh/pathcanon.c Normal file
View file

@ -0,0 +1,195 @@
/* pathcanon.c -- Canonicalize and manipulate pathnames. */
/* Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash 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 2, or (at your option) any later
version.
Bash 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 Bash; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include "config.h"
#include "bashtypes.h"
#ifndef _MINIX
# include <sys/param.h>
#endif
#include "posixstat.h"
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include "filecntl.h"
#include "bashansi.h"
#include <stdio.h>
#include "shell.h"
#include "maxpath.h"
/* Return 1 if PATH corresponds to a directory. A function for debugging. */
static int
_path_isdir (path)
char *path;
{
int l;
struct stat sb;
l = stat (path, &sb) == 0 && S_ISDIR (sb.st_mode);
return l;
}
/* Canonicalize PATH, and return a new path. The new path differs from PATH
in that:
Multple `/'s are collapsed to a single `/'.
Leading `./'s and trailing `/.'s are removed.
Trailing `/'s are removed.
Non-leading `../'s and trailing `..'s are handled by removing
portions of the path. */
/* Look for ROOTEDPATH, PATHSEP, DIRSEP, and ISDIRSEP in ../../general.h */
#define DOUBLE_SLASH(p) ((p[0] == '/') && (p[1] == '/') && p[2] != '/')
char *
sh_canonpath (path, flags)
char *path;
int flags;
{
char stub_char;
char *result, *p, *q, *base, *dotdot;
int rooted, double_slash_path;
/* The result cannot be larger than the input PATH. */
result = (flags & PATH_NOALLOC) ? path : savestring (path);
/* POSIX.2 says to leave a leading `//' alone. On cygwin, we skip over any
leading `x:' (dos drive name). */
if (rooted = ROOTEDPATH(path))
{
stub_char = DIRSEP;
#if defined (__CYGWIN__)
base = (isalpha(result[0]) && result[1] == ':') ? result + 3 : result + 1;
#else
base = result + 1;
#endif
double_slash_path = DOUBLE_SLASH (path);
base += double_slash_path;
}
else
{
stub_char = '.';
#if defined (__CYGWIN__)
base = (isalpha(result[0]) && result[1] == ':') ? result + 2 : result;
#else
base = result;
#endif
}
/*
* invariants:
* base points to the portion of the path we want to modify
* p points at beginning of path element we're considering.
* q points just past the last path element we wrote (no slash).
* dotdot points just past the point where .. cannot backtrack
* any further (no slash).
*/
p = q = dotdot = base;
while (*p)
{
if (ISDIRSEP(p[0])) /* null element */
p++;
else if(p[0] == '.' && PATHSEP(p[1])) /* . and ./ */
p += 1; /* don't count the separator in case it is nul */
else if (p[0] == '.' && p[1] == '.' && PATHSEP(p[2])) /* .. and ../ */
{
p += 2; /* skip `..' */
if (q > dotdot) /* can backtrack */
{
if (flags & PATH_CHECKDOTDOT)
{
char c;
/* Make sure what we have so far corresponds to a valid
path before we chop some of it off. */
c = *q;
*q = '\0';
if (_path_isdir (result) == 0)
{
if ((flags & PATH_NOALLOC) == 0)
free (result);
return ((char *)NULL);
}
*q = c;
}
while (--q > dotdot && ISDIRSEP(*q) == 0)
;
}
else if (rooted == 0)
{
/* /.. is / but ./../ is .. */
if (q != base)
*q++ = DIRSEP;
*q++ = '.';
*q++ = '.';
dotdot = q;
}
}
else /* real path element */
{
/* add separator if not at start of work portion of result */
if (q != base)
*q++ = DIRSEP;
while (*p && (ISDIRSEP(*p) == 0))
*q++ = *p++;
/* Check here for a valid directory with _path_isdir. */
if (flags & PATH_CHECKEXISTS)
{
char c;
/* Make sure what we have so far corresponds to a valid
path before we chop some of it off. */
c = *q;
*q = '\0';
if (_path_isdir (result) == 0)
{
if ((flags & PATH_NOALLOC) == 0)
free (result);
return ((char *)NULL);
}
*q = c;
}
}
}
/* Empty string is really ``.'' or `/', depending on what we started with. */
if (q == result)
*q++ = stub_char;
*q = '\0';
/* If the result starts with `//', but the original path does not, we
can turn the // into /. Because of how we set `base', this should never
be true, but it's a sanity check. */
if (DOUBLE_SLASH(result) && double_slash_path == 0)
{
if (result[2] == '\0') /* short-circuit for bare `//' */
result[1] = '\0';
else
strcpy (result, result + 1);
}
return (result);
}

256
lib/sh/pathphys.c Normal file
View file

@ -0,0 +1,256 @@
/* pathphys.c -- Return pathname with all symlinks expanded. */
/* Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash 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 2, or (at your option) any later
version.
Bash 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 Bash; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include "config.h"
#include "bashtypes.h"
#ifndef _MINIX
# include <sys/param.h>
#endif
#include "posixstat.h"
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include "filecntl.h"
#include "bashansi.h"
#include <stdio.h>
#include <errno.h>
#include "shell.h"
#include "maxpath.h"
#if !defined (MAXSYMLINKS)
# define MAXSYMLINKS 32
#endif
#if !defined (errno)
extern int errno;
#endif /* !errno */
extern char *get_working_directory __P((char *));
static int
_path_readlink (path, buf, bufsiz)
char *path;
char *buf;
int bufsiz;
{
#ifdef HAVE_READLINK
return readlink (path, buf, bufsiz);
#else
errno = EINVAL;
return -1;
#endif
}
/* Look for ROOTEDPATH, PATHSEP, DIRSEP, and ISDIRSEP in ../../general.h */
#define DOUBLE_SLASH(p) ((p[0] == '/') && (p[1] == '/') && p[2] != '/')
/*
* Return PATH with all symlinks expanded in newly-allocated memory.
* This always gets a full pathname.
*/
char *
sh_physpath (path, flags)
char *path;
int flags;
{
char tbuf[PATH_MAX+1], linkbuf[PATH_MAX+1];
char *result, *p, *q, *qsave, *qbase, *workpath;
int double_slash_path, linklen, nlink;
nlink = 0;
q = result = xmalloc (PATH_MAX + 1);
workpath = xmalloc (PATH_MAX + 1);
strcpy (workpath, path);
/* This always gets an absolute pathname. */
/* POSIX.2 says to leave a leading `//' alone. On cygwin, we skip over any
leading `x:' (dos drive name). */
#if defined (__CYGWIN__)
qbase = (isalpha(workpath[0]) && workpath[1] == ':') ? workpath + 3 : workpath + 1;
#else
qbase = workpath + 1;
#endif
double_slash_path = DOUBLE_SLASH (workpath);
qbase += double_slash_path;
for (p = workpath; p < qbase; )
*q++ = *p++;
qbase = q;
/*
* invariants:
* qbase points to the portion of the result path we want to modify
* p points at beginning of path element we're considering.
* q points just past the last path element we wrote (no slash).
*
* XXX -- need to fix error checking for too-long pathnames
*/
while (*p)
{
if (ISDIRSEP(p[0])) /* null element */
p++;
else if(p[0] == '.' && PATHSEP(p[1])) /* . and ./ */
p += 1; /* don't count the separator in case it is nul */
else if (p[0] == '.' && p[1] == '.' && PATHSEP(p[2])) /* .. and ../ */
{
p += 2; /* skip `..' */
if (q > qbase)
{
while (--q > qbase && ISDIRSEP(*q) == 0)
;
}
}
else /* real path element */
{
/* add separator if not at start of work portion of result */
qsave = q;
if (q != qbase)
*q++ = DIRSEP;
while (*p && (ISDIRSEP(*p) == 0))
*q++ = *p++;
*q = '\0';
linklen = _path_readlink (result, linkbuf, PATH_MAX);
if (linklen < 0) /* if errno == EINVAL, it's not a symlink */
{
if (errno != EINVAL)
goto error;
continue;
}
/* It's a symlink, and the value is in LINKBUF. */
nlink++;
if (nlink > MAXSYMLINKS)
{
#ifdef ELOOP
errno = ELOOP;
#endif
error:
free (result);
free (workpath);
return ((char *)NULL);
}
linkbuf[linklen] = '\0';
/* Form the new pathname by copying the link value to a temporary
buffer and appending the rest of `workpath'. Reset p to point
to the start of the rest of the path. If the link value is an
absolute pathname, reset p, q, and qbase. If not, reset p
and q. */
strcpy (tbuf, linkbuf);
tbuf[linklen] = '/';
strcpy (tbuf + linklen, p);
strcpy (workpath, tbuf);
if (ABSPATH(linkbuf))
{
q = result;
/* Duplicating some code here... */
#if defined (__CYGWIN__)
qbase = (isalpha(workpath[0]) && workpath[1] == ':') ? workpath + 3 : workpath + 1;
#else
qbase = workpath + 1;
#endif
double_slash_path = DOUBLE_SLASH (workpath);
qbase += double_slash_path;
for (p = workpath; p < qbase; )
*q++ = *p++;
qbase = q;
}
else
{
p = workpath;
q = qsave;
}
}
}
*q = '\0';
free (workpath);
/* If the result starts with `//', but the original path does not, we
can turn the // into /. Because of how we set `qbase', this should never
be true, but it's a sanity check. */
if (DOUBLE_SLASH(result) && double_slash_path == 0)
{
if (result[2] == '\0') /* short-circuit for bare `//' */
result[1] = '\0';
else
strcpy (result, result + 1);
}
return (result);
}
char *
sh_realpath (pathname, resolved)
const char *pathname;
char *resolved;
{
char *tdir, *wd;
if (pathname == 0 || *pathname == '\0')
{
errno = (pathname == 0) ? EINVAL : ENOENT;
return ((char *)NULL);
}
if (ABSPATH (pathname) == 0)
{
wd = get_working_directory ("sh_realpath");
if (wd == 0)
return ((char *)NULL);
tdir = sh_makepath ((char *)pathname, wd, 0);
free (wd);
}
else
tdir = savestring (pathname);
wd = sh_physpath (tdir, 0);
free (tdir);
if (resolved == 0)
return (wd);
if (wd)
{
strncpy (resolved, wd, PATH_MAX - 1);
resolved[PATH_MAX - 1] = '\0';
return resolved;
}
else
{
resolved[0] = '\0';
return wd;
}
}

View file

@ -27,9 +27,7 @@
#include <stdio.h>
#if !defined(slashify_in_quotes)
# define slashify_in_quotes "\\`$\"\n"
#endif
#include "syntax.h"
extern char *xmalloc ();
@ -42,7 +40,7 @@ extern char *xmalloc ();
/* Return a new string which is the single-quoted version of STRING.
Used by alias and trap, among others. */
char *
single_quote (string)
sh_single_quote (string)
char *string;
{
register int c;
@ -72,7 +70,7 @@ single_quote (string)
/* Quote STRING using double quotes. Return a new string. */
char *
double_quote (string)
sh_double_quote (string)
char *string;
{
register int c;
@ -84,18 +82,10 @@ double_quote (string)
for (s = string; s && (c = *s); s++)
{
switch (c)
{
case '"':
case '$':
case '`':
case '\\':
case '\n': /* XXX */
*r++ = '\\';
default:
*r++ = c;
break;
}
if (sh_syntaxtab[c] & CBSDQUOTE)
*r++ = '\\';
*r++ = c;
}
*r++ = '"';
@ -107,7 +97,7 @@ double_quote (string)
/* Remove backslashes that are quoting characters that are special between
double quotes. Return a new string. */
char *
un_double_quote (string)
sh_un_double_quote (string)
char *string;
{
register int c, pass_next;
@ -123,7 +113,7 @@ un_double_quote (string)
pass_next = 0;
continue;
}
if (c == '\\' && strchr (slashify_in_quotes, s[1]))
if (c == '\\' && (sh_syntaxtab[s[1]] & CBSDQUOTE))
{
pass_next = 1;
continue;
@ -138,7 +128,7 @@ un_double_quote (string)
/* Quote special characters in STRING using backslashes. Return a new
string. */
char *
backslash_quote (string)
sh_backslash_quote (string)
char *string;
{
int c;
@ -182,8 +172,33 @@ backslash_quote (string)
return (result);
}
#if defined (PROMPT_STRING_DECODE)
/* Quote characters that get special treatment when in double quotes in STRING
using backslashes. Return a new string. */
char *
sh_backslash_quote_for_double_quotes (string)
char *string;
{
int c;
char *result, *r, *s;
result = xmalloc (2 * strlen (string) + 1);
for (r = result, s = string; s && (c = *s); s++)
{
if (sh_syntaxtab[c] & CBSDQUOTE)
*r++ = '\\';
*r++ = c;
}
*r = '\0';
return (result);
}
#endif /* PROMPT_STRING_DECODE */
int
contains_shell_metas (string)
sh_contains_shell_metas (string)
char *string;
{
char *s;

186
lib/sh/spell.c Normal file
View file

@ -0,0 +1,186 @@
/* spell.c -- spelling correction for pathnames. */
/* Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash 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 2, or (at your option) any later
version.
Bash 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 Bash; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include <config.h>
#if defined (HAVE_UNISTD_H)
# ifdef _MINIX
# include <sys/types.h>
# endif
# include <unistd.h>
#endif
#include <bashtypes.h>
#include <posixdir.h>
#include <posixstat.h>
#ifndef _MINIX
#include <sys/param.h>
#endif
#include <stdio.h>
#include <bashansi.h>
#include <maxpath.h>
static int mindist (), spdist ();
/*
* `spname' and its helpers are inspired by the code in "The UNIX
* Programming Environment", Kernighan & Pike, Prentice-Hall 1984,
* pages 209 - 213.
*/
/*
* `spname' -- return a correctly spelled filename
*
* int spname(char * oldname, char * newname)
* Returns: -1 if no reasonable match found
* 0 if exact match found
* 1 if corrected
* Stores corrected name in `newname'.
*/
int
spname(oldname, newname)
char *oldname;
char *newname;
{
char *op, *np, *p;
char guess[PATH_MAX + 1], best[PATH_MAX + 1];
op = oldname;
np = newname;
for (;;)
{
while (*op == '/') /* Skip slashes */
*np++ = *op++;
*np = '\0';
if (*op == '\0') /* Exact or corrected */
{
/* `.' is rarely the right thing. */
if (oldname[1] == '\0' && newname[1] == '\0' &&
oldname[0] != '.' && newname[0] == '.')
return -1;
return strcmp(oldname, newname) != 0;
}
/* Copy next component into guess */
for (p = guess; *op != '/' && *op != '\0'; op++)
if (p < guess + PATH_MAX)
*p++ = *op;
*p = '\0';
if (mindist(newname, guess, best) >= 3)
return -1; /* Hopeless */
/*
* Add to end of newname
*/
for (p = best; *np = *p++; np++)
;
}
}
/*
* Search directory for a guess
*/
static int
mindist(dir, guess, best)
char *dir;
char *guess;
char *best;
{
DIR *fd;
struct dirent *dp;
int dist, x;
dist = 3; /* Worst distance */
if (*dir == '\0')
dir = ".";
if ((fd = opendir(dir)) == NULL)
return dist;
while ((dp = readdir(fd)) != NULL)
{
/*
* Look for a better guess. If the new guess is as
* good as the current one, we take it. This way,
* any single character match will be a better match
* than ".".
*/
x = spdist(dp->d_name, guess);
if (x <= dist && x != 3)
{
strcpy(best, dp->d_name);
dist = x;
if (dist == 0) /* Exact match */
break;
}
}
(void)closedir(fd);
/* Don't return `.' */
if (best[0] == '.' && best[1] == '\0')
dist = 3;
return dist;
}
/*
* `spdist' -- return the "distance" between two names.
*
* int spname(char * oldname, char * newname)
* Returns: 0 if strings are identical
* 1 if two characters are transposed
* 2 if one character is wrong, added or deleted
* 3 otherwise
*/
static int
spdist(cur, new)
char *cur, *new;
{
while (*cur == *new)
{
if (*cur == '\0')
return 0; /* Exact match */
cur++;
new++;
}
if (*cur)
{
if (*new)
{
if (cur[1] && new[1] && cur[0] == new[1] && cur[1] == new[0] && strcmp (cur + 2, new + 2) == 0)
return 1; /* Transposition */
if (strcmp (cur + 1, new + 1) == 0)
return 2; /* One character mismatch */
}
if (strcmp(&cur[1], &new[0]) == 0)
return 2; /* Extra character */
}
if (*new && strcmp(cur, new + 1) == 0)
return 2; /* Missing character */
return 3;
}

View file

@ -79,7 +79,7 @@ strcasecmp (string1, string2)
while ((r = to_lower (*s1) - to_lower (*s2)) == 0)
{
if (*s1++ == '\0')
return 0;
return 0;
s2++;
}

52
lib/sh/strindex.c Normal file
View file

@ -0,0 +1,52 @@
/* strindex.c - Find if one string appears as a substring of another string,
without regard to case. */
/* Copyright (C) 2000
Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash 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 2, or (at your option) any later
version.
Bash 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 Bash; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include <config.h>
#include "bashansi.h"
#include <ctype.h>
#include <stdc.h>
#ifndef to_upper
# define to_upper(c) (islower(c) ? toupper(c) : (c))
# define to_lower(c) (isupper(c) ? tolower(c) : (c))
#endif
/* Determine if s2 occurs in s1. If so, return a pointer to the
match in s1. The compare is case insensitive. This is a
case-insensitive strstr(3). */
char *
strindex (s1, s2)
const char *s1;
const char *s2;
{
register int i, l, len, c;
c = to_upper (s2[0]);
len = strlen (s1);
l = strlen (s2);
for (i = 0; (len - i) >= l; i++)
if ((to_upper (s1[i]) == c) && (strncasecmp (s1 + i, s2, l) == 0))
return ((char *)s1 + i);
return ((char *)0);
}

248
lib/sh/stringlist.c Normal file
View file

@ -0,0 +1,248 @@
/* stringlist.c - functions to handle a generic `list of strings' structure */
/* Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash 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 2, or (at your option) any later
version.
Bash 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 Bash; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include <config.h>
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include <stdio.h>
#include "bashansi.h"
#include "shell.h"
#ifdef STRDUP
# undef STRDUP
#endif
#define STRDUP(x) ((x) ? savestring (x) : (char *)NULL)
/* Allocate a new STRINGLIST, with room for N strings. */
STRINGLIST *
alloc_stringlist (n)
int n;
{
STRINGLIST *ret;
register int i;
ret = (STRINGLIST *)xmalloc (sizeof (STRINGLIST));
if (n)
{
ret->list = alloc_array (n+1);
ret->list_size = n;
for (i = 0; i < n; i++)
ret->list[i] = (char *)NULL;
}
else
{
ret->list = (char **)NULL;
ret->list_size = 0;
}
ret->list_len = 0;
return ret;
}
STRINGLIST *
realloc_stringlist (sl, n)
STRINGLIST *sl;
int n;
{
register int i;
if (n > sl->list_size)
{
sl->list = (char **)xrealloc (sl->list, (n+1) * sizeof (char *));
for (i = sl->list_size; i <= n; i++)
sl->list[i] = (char *)NULL;
sl->list_size = n;
}
return sl;
}
void
free_stringlist (sl)
STRINGLIST *sl;
{
if (sl == 0)
return;
if (sl->list)
free_array (sl->list);
free (sl);
}
STRINGLIST *
copy_stringlist (sl)
STRINGLIST *sl;
{
STRINGLIST *new;
register int i;
new = alloc_stringlist (sl->list_size);
/* I'd like to use copy_array, but that doesn't copy everything. */
if (sl->list)
{
for (i = 0; i < sl->list_size; i++)
new->list[i] = STRDUP (sl->list[i]);
}
new->list_size = sl->list_size;
new->list_len = sl->list_len;
/* just being careful */
if (new->list)
new->list[new->list_len] = (char *)NULL;
return new;
}
/* Return a new STRINGLIST with everything from M1 and M2. */
STRINGLIST *
merge_stringlists (m1, m2)
STRINGLIST *m1, *m2;
{
STRINGLIST *sl;
int i, n, l1, l2;
l1 = m1 ? m1->list_len : 0;
l2 = m2 ? m2->list_len : 0;
sl = alloc_stringlist (l1 + l2 + 1);
for (i = n = 0; i < l1; i++, n++)
sl->list[n] = STRDUP (m1->list[i]);
for (i = 0; i < l2; i++, n++)
sl->list[n] = STRDUP (m2->list[i]);
sl->list_len = n;
sl->list[n] = (char *)NULL;
}
/* Make STRINGLIST M1 contain everything in M1 and M2. */
STRINGLIST *
append_stringlist (m1, m2)
STRINGLIST *m1, *m2;
{
register int i, n, len1, len2;
if (m1 == 0)
{
m1 = copy_stringlist (m2);
return m1;
}
len1 = m1->list_len;
len2 = m2 ? m2->list_len : 0;
if (len2)
{
m1 = realloc_stringlist (m1, len1 + len2 + 1);
for (i = 0, n = len1; i < len2; i++, n++)
m1->list[n] = STRDUP (m2->list[i]);
m1->list[n] = (char *)NULL;
m1->list_len = n;
}
return m1;
}
STRINGLIST *
prefix_suffix_stringlist (sl, prefix, suffix)
STRINGLIST *sl;
char *prefix, *suffix;
{
int plen, slen, tlen, llen, i;
char *t;
if (sl == 0 || sl->list == 0 || sl->list_len == 0)
return sl;
plen = STRLEN (prefix);
slen = STRLEN (suffix);
if (plen == 0 && slen == 0)
return (sl);
for (i = 0; i < sl->list_len; i++)
{
llen = STRLEN (sl->list[i]);
tlen = plen + llen + slen + 1;
t = xmalloc (tlen + 1);
if (plen)
strcpy (t, prefix);
strcpy (t + plen, sl->list[i]);
if (slen)
strcpy (t + plen + llen, suffix);
free (sl->list[i]);
sl->list[i] = t;
}
return (sl);
}
void
print_stringlist (sl, prefix)
STRINGLIST *sl;
char *prefix;
{
register int i;
if (sl == 0)
return;
for (i = 0; i < sl->list_len; i++)
printf ("%s%s\n", prefix ? prefix : "", sl->list[i]);
}
void
sort_stringlist (sl)
STRINGLIST *sl;
{
if (sl == 0 || sl->list_len == 0 || sl->list == 0)
return;
sort_char_array (sl->list);
}
STRINGLIST *
word_list_to_stringlist (list, copy, starting_index, ip)
WORD_LIST *list;
int copy, starting_index, *ip;
{
STRINGLIST *ret;
int slen, len;
slen = list_length (list);
ret = (STRINGLIST *)xmalloc (sizeof (STRINGLIST));
ret->list = word_list_to_argv (list, copy, starting_index, &len);
ret->list_size = slen + starting_index;
ret->list_len = len;
if (ip)
*ip = len;
return ret;
}
WORD_LIST *
stringlist_to_word_list (sl, copy, starting_index)
STRINGLIST *sl;
int copy, starting_index;
{
WORD_LIST *list;
if (sl == 0 || sl->list == 0)
return ((WORD_LIST *)NULL);
list = argv_to_word_list (sl->list, copy, starting_index);
return list;
}

141
lib/sh/stringvec.c Normal file
View file

@ -0,0 +1,141 @@
/* stringvec.c - function for managing arrays of strings. */
/* Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash 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 2, or (at your option) any later
version.
Bash 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 Bash; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include "config.h"
#include "bashtypes.h"
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include "bashansi.h"
#include <stdio.h>
#include <ctype.h>
#include "shell.h"
#ifdef INCLUDE_UNUSED
/* Find NAME in ARRAY. Return the index of NAME, or -1 if not present.
ARRAY should be NULL terminated. */
int
find_name_in_array (name, array)
char *name, **array;
{
int i;
for (i = 0; array[i]; i++)
if (STREQ (name, array[i]))
return (i);
return (-1);
}
#endif
/* Allocate an array of strings with room for N members. */
char **
alloc_array (n)
int n;
{
return ((char **)xmalloc ((n) * sizeof (char *)));
}
/* Return the length of ARRAY, a NULL terminated array of char *. */
int
array_len (array)
char **array;
{
register int i;
for (i = 0; array[i]; i++);
return (i);
}
/* Free the contents of ARRAY, a NULL terminated array of char *. */
void
free_array_members (array)
char **array;
{
register int i;
if (array == 0)
return;
for (i = 0; array[i]; i++)
free (array[i]);
}
void
free_array (array)
char **array;
{
if (array == 0)
return;
free_array_members (array);
free (array);
}
/* Allocate and return a new copy of ARRAY and its contents. */
char **
copy_array (array)
char **array;
{
register int i;
int len;
char **new_array;
len = array_len (array);
new_array = (char **)xmalloc ((len + 1) * sizeof (char *));
for (i = 0; array[i]; i++)
new_array[i] = savestring (array[i]);
new_array[i] = (char *)NULL;
return (new_array);
}
/* Comparison routine for use with qsort() on arrays of strings. Uses
strcoll(3) if available, otherwise it uses strcmp(3). */
int
qsort_string_compare (s1, s2)
register char **s1, **s2;
{
#if defined (HAVE_STRCOLL)
return (strcoll (*s1, *s2));
#else /* !HAVE_STRCOLL */
int result;
if ((result = **s1 - **s2) == 0)
result = strcmp (*s1, *s2);
return (result);
#endif /* !HAVE_STRCOLL */
}
/* Sort ARRAY, a null terminated array of pointers to strings. */
void
sort_char_array (array)
char **array;
{
qsort (array, array_len (array), sizeof (char *),
(Function *)qsort_string_compare);
}

View file

@ -204,8 +204,8 @@ noconv:
if (save - nptr >= 2 && toupper (save[-1]) == 'X' && save[-2] == '0')
*endptr = (char *) &save[-1];
else
/* There was no number to convert. */
*endptr = (char *) nptr;
/* There was no number to convert. */
*endptr = (char *) nptr;
}
return 0L;

205
lib/sh/strtrans.c Normal file
View file

@ -0,0 +1,205 @@
/* strtrans.c - Translate and untranslate strings with ANSI-C escape
sequences. */
/* Copyright (C) 2000
Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash 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 2, or (at your option) any later
version.
Bash 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 Bash; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include <config.h>
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include "bashansi.h"
#include <stdio.h>
#include <ctype.h>
#include "shell.h"
#ifdef ESC
#undef ESC
#endif
#define ESC '\033' /* ASCII */
#ifndef ISOCTAL
#define ISOCTAL(c) ((c) >= '0' && (c) <= '7')
#endif
#ifndef OCTVALUE
#define OCTVALUE(c) ((c) - '0')
#endif
#ifndef isxdigit
# define isxdigit(c) (isdigit((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
#endif
#define HEXVALUE(c) \
((c) >= 'a' && (c) <= 'f' ? (c)-'a'+10 : (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
/* Convert STRING by expanding the escape sequences specified by the
ANSI C standard. If SAWC is non-null, recognize `\c' and use that
as a string terminator. If we see \c, set *SAWC to 1 before
returning. LEN is the length of STRING. FOR_ECHO is a flag that
means, if non-zero, that we're translating a string for `echo -e',
and therefore should not treat a single quote as a character that
may be escaped with a backslash. */
char *
ansicstr (string, len, for_echo, sawc, rlen)
char *string;
int len, for_echo, *sawc, *rlen;
{
int c, temp;
char *ret, *r, *s;
if (string == 0 || *string == '\0')
return ((char *)NULL);
ret = xmalloc (len + 1);
for (r = ret, s = string; s && *s; )
{
c = *s++;
if (c != '\\' || *s == '\0')
*r++ = c;
else
{
switch (c = *s++)
{
#if defined (__STDC__)
case 'a': c = '\a'; break;
case 'v': c = '\v'; break;
#else
case 'a': c = '\007'; break;
case 'v': c = (int) 0x0B; break;
#endif
case 'b': c = '\b'; break;
case 'e': case 'E': /* ESC -- non-ANSI */
c = ESC; break;
case 'f': c = '\f'; break;
case 'n': c = '\n'; break;
case 'r': c = '\r'; break;
case 't': c = '\t'; break;
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
for (temp = 2, c -= '0'; ISOCTAL (*s) && temp--; s++)
c = (c * 8) + OCTVALUE (*s);
break;
case 'x': /* Hex digit -- non-ANSI */
for (temp = 3, c = 0; isxdigit (*s) && temp--; s++)
c = (c * 16) + HEXVALUE (*s);
/* \x followed by non-hex digits is passed through unchanged */
if (temp == 3)
{
*r++ = '\\';
c = 'x';
}
break;
case '\\':
break;
case '\'':
if (for_echo)
*r++ = '\\';
break;
case 'c':
if (sawc)
{
*sawc = 1;
*r = '\0';
if (rlen)
*rlen = r - ret;
return ret;
}
default: *r++ = '\\'; break;
}
*r++ = c;
}
}
*r = '\0';
if (rlen)
*rlen = r - ret;
return ret;
}
/* Take a string STR, possibly containing non-printing characters, and turn it
into a $'...' ANSI-C style quoted string. Returns a new string. */
char *
ansic_quote (str, flags, rlen)
char *str;
int flags, *rlen;
{
char *r, *ret, *s, obuf[8];
int l, c, rsize, t;
if (str == 0 || *str == 0)
return ((char *)0);
l = strlen (str);
rsize = 2 * l + 4;
r = ret = xmalloc (rsize);
*r++ = '$';
*r++ = '\'';
for (s = str, l = 0; *s; s++)
{
c = *(unsigned char *)s;
l = 1; /* 1 == add backslash; 0 == no backslash */
switch (c)
{
case ESC: c = 'E'; break;
#ifdef __STDC__
case '\a': c = 'a'; break;
case '\v': c = 'v'; break;
#else
case '\007': c = 'a'; break;
case 0x0b: c = 'v'; break;
#endif
case '\b': c = 'b'; break;
case '\f': c = 'f'; break;
case '\n': c = 'n'; break;
case '\r': c = 'r'; break;
case '\t': c = 't'; break;
case '\\':
case '\'':
break;
default:
if (isprint (c) == 0)
{
sprintf (obuf, "\\%.3o", c);
t = r - ret;
RESIZE_MALLOCED_BUFFER (ret, t, 5, rsize, 16);
r = ret + t; /* in case reallocated */
for (t = 0; t < 4; t++)
*r++ = obuf[t];
continue;
}
l = 0;
break;
}
if (l)
*r++ = '\\';
*r++ = c;
}
*r++ = '\'';
*r = '\0';
if (rlen)
*rlen = r - ret;
return ret;
}

View file

@ -60,7 +60,7 @@ times(tms)
if (gettimeofday(&tv, (struct timezone *) 0) < 0)
return ((clock_t)-1);
rv = (clock_t)(CONVTCK(tv));
rv = (clock_t)(CONVTCK(tv));
#else /* !HAVE_GETRUSAGE */
if (clk_tck == -1)
clk_tck = get_clk_tck();

183
lib/sh/tmpfile.c Normal file
View file

@ -0,0 +1,183 @@
/*
* tmpfile.c - functions to create and safely open temp files for the shell.
*/
/* Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash 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 2, or (at your option)
any later version.
Bash 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 Bash; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include <config.h>
#include <bashtypes.h>
#include <posixstat.h>
#include <filecntl.h>
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include <stdio.h>
#include <errno.h>
#include <shell.h>
#ifndef errno
extern int errno;
#endif
#define BASEOPENFLAGS (O_CREAT | O_TRUNC | O_EXCL)
#define DEFAULT_TMPDIR "." /* bogus default, should be changed */
#define DEFAULT_NAMEROOT "shtmp"
extern int dollar_dollar_pid;
static char *sys_tmpdir = (char *)NULL;
static int ntmpfiles;
static int tmpnamelen = -1;
static unsigned long filenum = 1L;
static char *
get_sys_tmpdir ()
{
struct stat sb;
if (sys_tmpdir)
return sys_tmpdir;
sys_tmpdir = "/tmp";
if (stat (sys_tmpdir, &sb) == 0)
return sys_tmpdir;
sys_tmpdir = "/var/tmp";
if (stat (sys_tmpdir, &sb) == 0)
return sys_tmpdir;
sys_tmpdir = "/usr/tmp";
if (stat (sys_tmpdir, &sb) == 0)
return sys_tmpdir;
#ifdef P_tmpdir
sys_tmpdir = P_tmpdir;
#else
sys_tmpdir = DEFAULT_TMPDIR;
#endif
return sys_tmpdir;
}
static char *
get_tmpdir (flags)
int flags;
{
char *tdir;
tdir = (flags & MT_USETMPDIR) ? get_string_value ("TMPDIR") : (char *)NULL;
if (tdir == 0)
tdir = get_sys_tmpdir ();
#if defined (HAVE_PATHCONF) && defined (_PC_NAME_MAX)
if (tmpnamelen == -1)
tmpnamelen = pathconf (tdir, _PC_NAME_MAX);
#else
tmpnamelen = 0;
#endif
return tdir;
}
char *
sh_mktmpname (nameroot, flags)
char *nameroot;
int flags;
{
char *filename, *tdir;
struct stat sb;
int r, tdlen;
filename = xmalloc (PATH_MAX + 1);
tdir = get_tmpdir (flags);
tdlen = strlen (tdir);
if (nameroot == 0)
nameroot = DEFAULT_NAMEROOT;
while (1)
{
filenum *= (int)time ((time_t *)0) * dollar_dollar_pid *
((flags & MT_USERANDOM) ? get_random_number () : ntmpfiles++);
sprintf (filename, "%s/%s-%lu", tdir, nameroot, filenum);
if (tmpnamelen > 0 && tmpnamelen < 32)
filename[tdlen + 1 + tmpnamelen] = '\0';
#ifdef HAVE_LSTAT
r = lstat (filename, &sb);
#else
r = stat (filename, &sb);
#endif
if (r < 0 && errno == ENOENT)
break;
}
return filename;
}
int
sh_mktmpfd (nameroot, flags, namep)
char *nameroot;
int flags;
char **namep;
{
char *filename, *tdir;
int fd, tdlen;
filename = xmalloc (PATH_MAX + 1);
tdir = get_tmpdir (flags);
tdlen = strlen (tdir);
if (nameroot == 0)
nameroot = DEFAULT_NAMEROOT;
do
{
filenum *= (int)time ((time_t *)0) * dollar_dollar_pid *
((flags & MT_USERANDOM) ? get_random_number () : ntmpfiles++);
sprintf (filename, "%s/%s-%lu", tdir, nameroot, filenum);
if (tmpnamelen > 0 && tmpnamelen < 32)
filename[tdlen + 1 + tmpnamelen] = '\0';
fd = open (filename, BASEOPENFLAGS | ((flags & MT_READWRITE) ? O_RDWR : O_WRONLY), 0600);
}
while (fd < 0 && errno == EEXIST);
if (namep)
*namep = filename;
else
free (filename);
return fd;
}
FILE *
sh_mktmpfp (nameroot, flags, namep)
char *nameroot;
int flags;
char **namep;
{
int fd;
fd = sh_mktmpfd (nameroot, flags, namep);
return ((fd >= 0) ? (fdopen (fd, (flags & MT_READWRITE) ? "w+" : "w")) : (FILE *)NULL);
}

View file

@ -69,7 +69,7 @@ zread1 (fd, buf, len)
{
r = read (fd, buf, len);
if (r >= 0)
return r;
return r;
if (r == -1 && errno == EINTR)
{
if (++nintr > NUM_INTR)

View file

@ -49,6 +49,7 @@ zwrite (fd, buf, nb)
n -= i;
if (n <= 0)
return nb;
buf += i;
}
else if (i == 0)
{

View file

@ -50,16 +50,13 @@
#if defined (TEST) || defined (STATIC_MALLOC)
static char *xmalloc (), *xrealloc ();
#else
# if defined __STDC__
extern char *xmalloc (int);
extern char *xrealloc (void *, int);
# else
extern char *xmalloc (), *xrealloc ();
# endif /* !__STDC__ */
extern char *xmalloc __P((int));
extern char *xrealloc __P((void *, int));
#endif /* TEST || STATIC_MALLOC */
#if !defined (HAVE_GETPW_DECLS)
extern struct passwd *getpwuid (), *getpwnam ();
extern struct passwd *getpwuid __P((uid_t));
extern struct passwd *getpwnam __P((const char *));
#endif /* !HAVE_GETPW_DECLS */
#if !defined (savestring)
@ -80,42 +77,42 @@ extern char *strcpy ();
/* If being compiled as part of bash, these will be satisfied from
variables.o. If being compiled as part of readline, they will
be satisfied from shell.o. */
extern char *get_home_dir __P((void));
extern char *get_env_value __P((char *));
extern char *sh_get_home_dir __P((void));
extern char *sh_get_env_value __P((const char *));
/* The default value of tilde_additional_prefixes. This is set to
whitespace preceding a tilde so that simple programs which do not
perform any word separation get desired behaviour. */
static char *default_prefixes[] =
{ " ~", "\t~", (char *)NULL };
static const char *default_prefixes[] =
{ " ~", "\t~", (const char *)NULL };
/* The default value of tilde_additional_suffixes. This is set to
whitespace or newline so that simple programs which do not
perform any word separation get desired behaviour. */
static char *default_suffixes[] =
{ " ", "\n", (char *)NULL };
static const char *default_suffixes[] =
{ " ", "\n", (const char *)NULL };
/* If non-null, this contains the address of a function that the application
wants called before trying the standard tilde expansions. The function
is called with the text sans tilde, and returns a malloc()'ed string
which is the expansion, or a NULL pointer if the expansion fails. */
CPFunction *tilde_expansion_preexpansion_hook = (CPFunction *)NULL;
tilde_hook_func_t *tilde_expansion_preexpansion_hook = (tilde_hook_func_t *)NULL;
/* If non-null, this contains the address of a function to call if the
standard meaning for expanding a tilde fails. The function is called
with the text (sans tilde, as in "foo"), and returns a malloc()'ed string
which is the expansion, or a NULL pointer if there is no expansion. */
CPFunction *tilde_expansion_failure_hook = (CPFunction *)NULL;
tilde_hook_func_t *tilde_expansion_failure_hook = (tilde_hook_func_t *)NULL;
/* When non-null, this is a NULL terminated array of strings which
are duplicates for a tilde prefix. Bash uses this to expand
`=~' and `:~'. */
char **tilde_additional_prefixes = default_prefixes;
char **tilde_additional_prefixes = (char **)default_prefixes;
/* When non-null, this is a NULL terminated array of strings which match
the end of a username, instead of just "/". Bash sets this to
`:' and `=~'. */
char **tilde_additional_suffixes = default_suffixes;
char **tilde_additional_suffixes = (char **)default_suffixes;
/* Find the start of a tilde expansion in STRING, and return the index of
the tilde which starts the expansion. Place the length of the text
@ -186,7 +183,7 @@ tilde_find_suffix (string)
/* Return a new string which is the result of tilde expanding STRING. */
char *
tilde_expand (string)
char *string;
const char *string;
{
char *result;
int result_size, result_index;
@ -235,9 +232,9 @@ tilde_expand (string)
free (tilde_word);
len = strlen (expansion);
#ifdef __CYGWIN32__
#ifdef __CYGWIN__
/* Fix for Cygwin to prevent ~user/xxx from expanding to //xxx when
$HOME for `user' is /. On cygwin, // denotes a network drive. */
$HOME for `user' is /. On cygwin, // denotes a network drive. */
if (len > 1 || *expansion != '/' || *string != '/')
#endif
{
@ -303,7 +300,7 @@ glue_prefix_and_suffix (prefix, suffix, suffind)
This always returns a newly-allocated string, never static storage. */
char *
tilde_expand_word (filename)
char *filename;
const char *filename;
{
char *dirname, *expansion, *username;
int user_len;
@ -321,12 +318,12 @@ tilde_expand_word (filename)
if (filename[1] == '\0' || filename[1] == '/')
{
/* Prefix $HOME to the rest of the string. */
expansion = get_env_value ("HOME");
expansion = sh_get_env_value ("HOME");
/* If there is no HOME variable, look up the directory in
the password database. */
if (expansion == 0)
expansion = get_home_dir ();
expansion = sh_get_home_dir ();
return (glue_prefix_and_suffix (expansion, filename, 1));
}

View file

@ -40,26 +40,31 @@ extern "C" {
# endif
#endif
/* Function pointers can be declared as (Function *)foo. */
#if !defined (_FUNCTION_DEF)
# define _FUNCTION_DEF
typedef int Function ();
typedef void VFunction ();
typedef char *CPFunction ();
typedef char **CPPFunction ();
#endif /* _FUNCTION_DEF */
#if !defined (__STDC__) && !defined (__cplusplus)
# if defined (__GNUC__) /* gcc with -traditional */
# if !defined (const)
# define const __const
# endif /* !const */
# else /* !__GNUC__ */
# if !defined (const)
# define const
# endif /* !const */
# endif /* !__GNUC__ */
#endif /* !__STDC__ && !__cplusplus */
typedef char *tilde_hook_func_t __P((char *));
/* If non-null, this contains the address of a function that the application
wants called before trying the standard tilde expansions. The function
is called with the text sans tilde, and returns a malloc()'ed string
which is the expansion, or a NULL pointer if the expansion fails. */
extern CPFunction *tilde_expansion_preexpansion_hook;
extern tilde_hook_func_t *tilde_expansion_preexpansion_hook;
/* If non-null, this contains the address of a function to call if the
standard meaning for expanding a tilde fails. The function is called
with the text (sans tilde, as in "foo"), and returns a malloc()'ed string
which is the expansion, or a NULL pointer if there is no expansion. */
extern CPFunction *tilde_expansion_failure_hook;
extern tilde_hook_func_t *tilde_expansion_failure_hook;
/* When non-null, this is a NULL terminated array of strings which
are duplicates for a tilde prefix. Bash uses this to expand
@ -72,11 +77,11 @@ extern char **tilde_additional_prefixes;
extern char **tilde_additional_suffixes;
/* Return a new string which is the result of tilde expanding STRING. */
extern char *tilde_expand __P((char *));
extern char *tilde_expand __P((const char *));
/* Do the work of tilde expansion on FILENAME. FILENAME starts with a
tilde. If there is no expansion, call tilde_expansion_failure_hook. */
extern char *tilde_expand_word __P((char *));
extern char *tilde_expand_word __P((const char *));
#ifdef __cplusplus
}