Imported from ../bash-3.1.tar.gz.
This commit is contained in:
parent
eb87367179
commit
95732b497d
267 changed files with 24541 additions and 18843 deletions
|
|
@ -4,7 +4,7 @@
|
|||
# #
|
||||
####################################################################
|
||||
#
|
||||
# Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1996-2005 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* glob.c -- file-name wildcard pattern matching for Bash.
|
||||
|
||||
Copyright (C) 1985-2002 Free Software Foundation, Inc.
|
||||
Copyright (C) 1985-2005 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -66,6 +66,12 @@
|
|||
# define FREE(x) if (x) free (x)
|
||||
#endif
|
||||
|
||||
/* Don't try to alloca() more than this much memory for `struct globval'
|
||||
in glob_vector() */
|
||||
#ifndef ALLOCA_MAX
|
||||
# define ALLOCA_MAX 100000
|
||||
#endif
|
||||
|
||||
extern void throw_to_top_level __P((void));
|
||||
extern int test_eaccess __P((char *, int));
|
||||
|
||||
|
|
@ -127,13 +133,13 @@ glob_pattern_p (pattern)
|
|||
int r;
|
||||
|
||||
if (MB_CUR_MAX == 1)
|
||||
return (internal_glob_pattern_p (pattern));
|
||||
return (internal_glob_pattern_p ((unsigned char *)pattern));
|
||||
|
||||
/* Convert strings to wide chars, and call the multibyte version. */
|
||||
n = xdupmbstowcs (&wpattern, NULL, pattern);
|
||||
if (n == (size_t)-1)
|
||||
/* Oops. Invalid multibyte sequence. Try it as single-byte sequence. */
|
||||
return (internal_glob_pattern_p (pattern));
|
||||
return (internal_glob_pattern_p ((unsigned char *)pattern));
|
||||
|
||||
r = internal_glob_wpattern_p (wpattern);
|
||||
free (wpattern);
|
||||
|
|
@ -347,10 +353,14 @@ glob_vector (pat, dir, flags)
|
|||
register char **name_vector;
|
||||
register unsigned int i;
|
||||
int mflags; /* Flags passed to strmatch (). */
|
||||
int nalloca;
|
||||
struct globval *firstmalloc, *tmplink;
|
||||
|
||||
lastlink = 0;
|
||||
count = lose = skip = 0;
|
||||
|
||||
firstmalloc = 0;
|
||||
|
||||
/* If PAT is empty, skip the loop, but return one (empty) filename. */
|
||||
if (pat == 0 || *pat == '\0')
|
||||
{
|
||||
|
|
@ -488,8 +498,18 @@ glob_vector (pat, dir, flags)
|
|||
|
||||
if (strmatch (pat, dp->d_name, mflags) != FNM_NOMATCH)
|
||||
{
|
||||
if (nalloca < ALLOCA_MAX)
|
||||
{
|
||||
nextlink = (struct globval *) alloca (sizeof (struct globval));
|
||||
nalloca += sizeof (struct globval);
|
||||
}
|
||||
else
|
||||
{
|
||||
nextlink = (struct globval *) malloc (sizeof (struct globval));
|
||||
if (firstmalloc == 0)
|
||||
firstmalloc = nextlink;
|
||||
}
|
||||
nextname = (char *) malloc (D_NAMLEN (dp) + 1);
|
||||
nextlink = (struct globval *) alloca (sizeof (struct globval));
|
||||
if (nextlink == 0 || nextname == 0)
|
||||
{
|
||||
lose = 1;
|
||||
|
|
@ -515,11 +535,20 @@ glob_vector (pat, dir, flags)
|
|||
/* Have we run out of memory? */
|
||||
if (lose)
|
||||
{
|
||||
tmplink = 0;
|
||||
|
||||
/* Here free the strings we have got. */
|
||||
while (lastlink)
|
||||
{
|
||||
if (firstmalloc)
|
||||
{
|
||||
if (lastlink == firstmalloc)
|
||||
firstmalloc = 0;
|
||||
tmplink = lastlink;
|
||||
}
|
||||
free (lastlink->name);
|
||||
lastlink = lastlink->next;
|
||||
FREE (tmplink);
|
||||
}
|
||||
|
||||
QUIT;
|
||||
|
|
@ -528,13 +557,29 @@ glob_vector (pat, dir, flags)
|
|||
}
|
||||
|
||||
/* Copy the name pointers from the linked list into the vector. */
|
||||
for (i = 0; i < count; ++i)
|
||||
for (tmplink = lastlink, i = 0; i < count; ++i)
|
||||
{
|
||||
name_vector[i] = lastlink->name;
|
||||
lastlink = lastlink->next;
|
||||
name_vector[i] = tmplink->name;
|
||||
tmplink = tmplink->next;
|
||||
}
|
||||
|
||||
name_vector[count] = NULL;
|
||||
|
||||
/* If we allocated some of the struct globvals, free them now. */
|
||||
if (firstmalloc)
|
||||
{
|
||||
tmplink = 0;
|
||||
while (lastlink)
|
||||
{
|
||||
tmplink = lastlink;
|
||||
if (lastlink == firstmalloc)
|
||||
lastlink = firstmalloc = 0;
|
||||
else
|
||||
lastlink = lastlink->next;
|
||||
free (tmplink);
|
||||
}
|
||||
}
|
||||
|
||||
return (name_vector);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 1991-2002 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1991-2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 1991-2004 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1991-2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
|
|
@ -358,7 +358,7 @@ BRACKMATCH (p, test, flags)
|
|||
{
|
||||
bcopy (p + 1, ccname, (close - p - 1) * sizeof (CHAR));
|
||||
*(ccname + (close - p - 1)) = L('\0');
|
||||
pc = IS_CCLASS (test, ccname);
|
||||
pc = IS_CCLASS (test, (XCHAR *)ccname);
|
||||
}
|
||||
if (pc == -1)
|
||||
pc = 0;
|
||||
|
|
@ -522,11 +522,11 @@ PATSCAN (string, end, delim)
|
|||
CHAR *string, *end;
|
||||
INT delim;
|
||||
{
|
||||
int pnest, bnest;
|
||||
int pnest, bnest, skip;
|
||||
INT cchar;
|
||||
CHAR *s, c, *bfirst;
|
||||
|
||||
pnest = bnest = 0;
|
||||
pnest = bnest = skip = 0;
|
||||
cchar = 0;
|
||||
bfirst = NULL;
|
||||
|
||||
|
|
@ -534,8 +534,17 @@ PATSCAN (string, end, delim)
|
|||
{
|
||||
if (s >= end)
|
||||
return (s);
|
||||
if (skip)
|
||||
{
|
||||
skip = 0;
|
||||
continue;
|
||||
}
|
||||
switch (c)
|
||||
{
|
||||
case L('\\'):
|
||||
skip = 1;
|
||||
break;
|
||||
|
||||
case L('\0'):
|
||||
return ((CHAR *)NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* strmatch.c -- ksh-like extended pattern matching for the shell and filename
|
||||
globbing. */
|
||||
|
||||
/* Copyright (C) 1991-2002 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1991-2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
|
|
@ -93,14 +93,16 @@ collequiv (c1, c2)
|
|||
|
||||
static int
|
||||
collsym (s, len)
|
||||
char *s;
|
||||
CHAR *s;
|
||||
int len;
|
||||
{
|
||||
register struct _collsym *csp;
|
||||
char *x;
|
||||
|
||||
x = (char *)s;
|
||||
for (csp = posix_collsyms; csp->name; csp++)
|
||||
{
|
||||
if (STREQN(csp->name, s, len) && csp->name[len] == '\0')
|
||||
if (STREQN(csp->name, x, len) && csp->name[len] == '\0')
|
||||
return (csp->code);
|
||||
}
|
||||
if (len == 1)
|
||||
|
|
@ -366,7 +368,7 @@ xstrmatch (pattern, string, flags)
|
|||
wchar_t *wpattern, *wstring;
|
||||
|
||||
if (MB_CUR_MAX == 1)
|
||||
return (internal_strmatch (pattern, string, flags));
|
||||
return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags));
|
||||
|
||||
n = xdupmbstowcs (&wpattern, NULL, pattern);
|
||||
if (n == (size_t)-1 || n == (size_t)-2)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* xmbsrtowcs.c -- replacement function for mbsrtowcs */
|
||||
|
||||
/* Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 2002-2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ xmbsrtowcs (dest, src, len, pstate)
|
|||
ps = &local_state;
|
||||
}
|
||||
|
||||
n = strlen(*src);
|
||||
n = strlen (*src);
|
||||
|
||||
if (dest == NULL)
|
||||
{
|
||||
|
|
@ -62,19 +62,22 @@ xmbsrtowcs (dest, src, len, pstate)
|
|||
const char *mbs;
|
||||
mbstate_t psbuf;
|
||||
|
||||
/* It doesn't matter if malloc fails here, since mbsrtowcs should do
|
||||
the right thing with a NULL first argument. */
|
||||
wsbuf = (wchar_t *) malloc ((n + 1) * sizeof(wchar_t));
|
||||
mbs = *src;
|
||||
psbuf = *ps;
|
||||
|
||||
wclength = mbsrtowcs (wsbuf, &mbs, n, &psbuf);
|
||||
|
||||
free (wsbuf);
|
||||
if (wsbuf)
|
||||
free (wsbuf);
|
||||
return wclength;
|
||||
}
|
||||
|
||||
for (wclength = 0; wclength < len; wclength++, dest++)
|
||||
{
|
||||
if(mbsinit(ps))
|
||||
if (mbsinit(ps))
|
||||
{
|
||||
if (**src == '\0')
|
||||
{
|
||||
|
|
@ -166,10 +169,11 @@ xdupmbstowcs (destp, indicesp, src)
|
|||
|
||||
p = src;
|
||||
wcnum = 0;
|
||||
do {
|
||||
do
|
||||
{
|
||||
size_t mblength; /* Byte length of one multibyte character. */
|
||||
|
||||
if(mbsinit (&state))
|
||||
if (mbsinit (&state))
|
||||
{
|
||||
if (*p == '\0')
|
||||
{
|
||||
|
|
@ -230,7 +234,8 @@ xdupmbstowcs (destp, indicesp, src)
|
|||
wsbuf[wcnum - 1] = wc;
|
||||
indices[wcnum - 1] = (char *)p;
|
||||
p += mblength;
|
||||
} while (MB_NULLWCH (wc) == 0);
|
||||
}
|
||||
while (MB_NULLWCH (wc) == 0);
|
||||
|
||||
/* Return the length of the wide character string, not including `\0'. */
|
||||
*destp = wsbuf;
|
||||
|
|
|
|||
|
|
@ -51,12 +51,14 @@ RANLIB = @RANLIB@
|
|||
YACC = @INTLBISON@ -y -d
|
||||
YFLAGS = --name-prefix=__gettext
|
||||
|
||||
LOCAL_DEFS = @LOCAL_DEFS@
|
||||
|
||||
DEFS = -DLOCALEDIR=\"$(localedir)\" -DLOCALE_ALIAS_PATH=\"$(aliaspath)\" \
|
||||
-DLIBDIR=\"$(prefix)/libdata\" -DIN_LIBINTL \
|
||||
-DENABLE_RELOCATABLE=1 -DIN_LIBRARY -DINSTALLDIR=\"$(libdir)\" -DNO_XMALLOC \
|
||||
-Dset_relocation_prefix=libintl_set_relocation_prefix \
|
||||
-Drelocate=libintl_relocate \
|
||||
-DDEPENDS_ON_LIBICONV=1 @DEFS@
|
||||
-DDEPENDS_ON_LIBICONV=1 @DEFS@ @LOCAL_DEFS@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CFLAGS = @CFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
|
|
|
|||
|
|
@ -134,6 +134,10 @@ extern int errno;
|
|||
|
||||
/* @@ end of prolog @@ */
|
||||
|
||||
#if defined (SHELL) && !defined (HAVE_GETCWD)
|
||||
# define HAVE_GETCWD
|
||||
#endif
|
||||
|
||||
#ifdef _LIBC
|
||||
/* Rename the non ANSI C functions. This is required by the standard
|
||||
because some ANSI C functions will require linking with this object
|
||||
|
|
@ -417,6 +421,10 @@ static int enable_secure;
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_RAISE
|
||||
# define raise(x) kill (getpid (), (x))
|
||||
#endif
|
||||
|
||||
/* Get the function to evaluate the plural expression. */
|
||||
#include "eval-plural.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# Skeleton Makefile for the GNU malloc code
|
||||
#
|
||||
#
|
||||
# Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1996-2005 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -115,6 +115,7 @@ malloc.o: $(BUILD_DIR)/config.h $(topdir)/bashtypes.h getpagesize.h
|
|||
xmalloc.o: $(BUILD_DIR)/config.h $(BASHINCDIR)/ansi_stdlib.h
|
||||
trace.o: ${BUILD_DIR}/config.h
|
||||
table.o: ${BUILD_DIR}/config.h
|
||||
watch.o: ${BUILD_DIR}/config.h
|
||||
|
||||
malloc.o: ${srcdir}/imalloc.h ${srcdir}/mstats.h
|
||||
malloc.o: ${srcdir}/table.h ${srcdir}/watch.h
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* malloc.c - dynamic memory allocation for bash. */
|
||||
|
||||
/* Copyright (C) 1985-2003 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1985-2005 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -221,7 +221,7 @@ typedef union _malloc_guard {
|
|||
|
||||
static union mhead *nextf[NBUCKETS];
|
||||
|
||||
/* busy[i] is nonzero while allocation of block size i is in progress. */
|
||||
/* busy[i] is nonzero while allocation or free of block size i is in progress. */
|
||||
|
||||
static char busy[NBUCKETS];
|
||||
|
||||
|
|
@ -246,7 +246,7 @@ static unsigned long binsizes[NBUCKETS] = {
|
|||
static PTR_T internal_malloc __P((size_t, const char *, int, int));
|
||||
static PTR_T internal_realloc __P((PTR_T, size_t, const char *, int, int));
|
||||
static void internal_free __P((PTR_T, const char *, int, int));
|
||||
static PTR_T internal_memalign __P((unsigned int, size_t, const char *, int, int));
|
||||
static PTR_T internal_memalign __P((size_t, size_t, const char *, int, int));
|
||||
#ifndef NO_CALLOC
|
||||
static PTR_T internal_calloc __P((size_t, size_t, const char *, int, int));
|
||||
static void internal_cfree __P((PTR_T, const char *, int, int));
|
||||
|
|
@ -323,7 +323,8 @@ xbotch (mem, e, s, file, line)
|
|||
|
||||
/* Coalesce two adjacent free blocks off the free list for size NU - 1,
|
||||
as long as we can find two adjacent free blocks. nextf[NU -1] is
|
||||
assumed to not be busy; the caller (morecore()) checks for this. */
|
||||
assumed to not be busy; the caller (morecore()) checks for this.
|
||||
BUSY[NU] must be set to 1. */
|
||||
static void
|
||||
bcoalesce (nu)
|
||||
register int nu;
|
||||
|
|
@ -333,9 +334,10 @@ bcoalesce (nu)
|
|||
unsigned long siz;
|
||||
|
||||
nbuck = nu - 1;
|
||||
if (nextf[nbuck] == 0)
|
||||
if (nextf[nbuck] == 0 || busy[nbuck])
|
||||
return;
|
||||
|
||||
busy[nbuck] = 1;
|
||||
siz = binsize (nbuck);
|
||||
|
||||
mp2 = mp1 = nextf[nbuck];
|
||||
|
|
@ -346,22 +348,27 @@ bcoalesce (nu)
|
|||
mp1 = mp;
|
||||
mp = CHAIN (mp);
|
||||
}
|
||||
|
||||
if (mp == 0)
|
||||
return;
|
||||
{
|
||||
busy[nbuck] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* OK, now we have mp1 pointing to the block we want to add to nextf[NU].
|
||||
CHAIN(mp2) must equal mp1. Check that mp1 and mp are adjacent. */
|
||||
if (mp2 != mp1 && CHAIN(mp2) != mp1)
|
||||
xbotch ((PTR_T)0, 0, "bcoalesce: CHAIN(mp2) != mp1", (char *)NULL, 0);
|
||||
{
|
||||
busy[nbuck] = 0;
|
||||
xbotch ((PTR_T)0, 0, "bcoalesce: CHAIN(mp2) != mp1", (char *)NULL, 0);
|
||||
}
|
||||
|
||||
#ifdef MALLOC_DEBUG
|
||||
if (CHAIN (mp1) != (union mhead *)((char *)mp1 + siz))
|
||||
return; /* not adjacent */
|
||||
#endif
|
||||
|
||||
#ifdef MALLOC_STATS
|
||||
_mstats.tbcoalesce++;
|
||||
_mstats.ncoalesce[nbuck]++;
|
||||
{
|
||||
busy[nbuck] = 0;
|
||||
return; /* not adjacent */
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Since they are adjacent, remove them from the free list */
|
||||
|
|
@ -369,6 +376,12 @@ bcoalesce (nu)
|
|||
nextf[nbuck] = CHAIN (mp);
|
||||
else
|
||||
CHAIN (mp2) = CHAIN (mp);
|
||||
busy[nbuck] = 0;
|
||||
|
||||
#ifdef MALLOC_STATS
|
||||
_mstats.tbcoalesce++;
|
||||
_mstats.ncoalesce[nbuck]++;
|
||||
#endif
|
||||
|
||||
/* And add the combined two blocks to nextf[NU]. */
|
||||
mp1->mh_alloc = ISFREE;
|
||||
|
|
@ -380,7 +393,7 @@ bcoalesce (nu)
|
|||
/* Split a block at index > NU (but less than SPLIT_MAX) into a set of
|
||||
blocks of the correct size, and attach them to nextf[NU]. nextf[NU]
|
||||
is assumed to be empty. Must be called with signals blocked (e.g.,
|
||||
by morecore()). */
|
||||
by morecore()). BUSY[NU] must be set to 1. */
|
||||
static void
|
||||
bsplit (nu)
|
||||
register int nu;
|
||||
|
|
@ -416,6 +429,12 @@ bsplit (nu)
|
|||
/* XXX might want to split only if nextf[nbuck] has >= 2 blocks free
|
||||
and nbuck is below some threshold. */
|
||||
|
||||
/* Remove the block from the chain of larger blocks. */
|
||||
busy[nbuck] = 1;
|
||||
mp = nextf[nbuck];
|
||||
nextf[nbuck] = CHAIN (mp);
|
||||
busy[nbuck] = 0;
|
||||
|
||||
#ifdef MALLOC_STATS
|
||||
_mstats.tbsplit++;
|
||||
_mstats.nsplit[nbuck]++;
|
||||
|
|
@ -425,10 +444,6 @@ bsplit (nu)
|
|||
siz = binsize (nu);
|
||||
nblks = binsize (nbuck) / siz;
|
||||
|
||||
/* Remove the block from the chain of larger blocks. */
|
||||
mp = nextf[nbuck];
|
||||
nextf[nbuck] = CHAIN (mp);
|
||||
|
||||
/* Split the block and put it on the requested chain. */
|
||||
nextf[nu] = mp;
|
||||
while (1)
|
||||
|
|
@ -442,6 +457,49 @@ bsplit (nu)
|
|||
CHAIN (mp) = 0;
|
||||
}
|
||||
|
||||
/* Take the memory block MP and add it to a chain < NU. NU is the right bucket,
|
||||
but is busy. This avoids memory orphaning. */
|
||||
static void
|
||||
xsplit (mp, nu)
|
||||
union mhead *mp;
|
||||
int nu;
|
||||
{
|
||||
union mhead *nh;
|
||||
int nbuck, nblks, split_max;
|
||||
unsigned long siz;
|
||||
|
||||
nbuck = nu - 1;
|
||||
while (nbuck >= SPLIT_MIN && busy[nbuck])
|
||||
nbuck--;
|
||||
if (nbuck < SPLIT_MIN)
|
||||
return;
|
||||
|
||||
#ifdef MALLOC_STATS
|
||||
_mstats.tbsplit++;
|
||||
_mstats.nsplit[nu]++;
|
||||
#endif
|
||||
|
||||
/* Figure out how many blocks we'll get. */
|
||||
siz = binsize (nu); /* original block size */
|
||||
nblks = siz / binsize (nbuck); /* should be 2 most of the time */
|
||||
|
||||
/* And add it to nextf[nbuck] */
|
||||
siz = binsize (nbuck); /* XXX - resetting here */
|
||||
nh = mp;
|
||||
while (1)
|
||||
{
|
||||
mp->mh_alloc = ISFREE;
|
||||
mp->mh_index = nbuck;
|
||||
if (--nblks <= 0) break;
|
||||
CHAIN (mp) = (union mhead *)((char *)mp + siz);
|
||||
mp = (union mhead *)((char *)mp + siz);
|
||||
}
|
||||
busy[nbuck] = 1;
|
||||
CHAIN (mp) = nextf[nbuck];
|
||||
nextf[nbuck] = nh;
|
||||
busy[nbuck] = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
block_signals (setp, osetp)
|
||||
sigset_t *setp, *osetp;
|
||||
|
|
@ -490,9 +548,10 @@ lesscore (nu) /* give system back some memory */
|
|||
_mstats.nlesscore[nu]++;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* Ask system for more memory; add to NEXTF[NU]. BUSY[NU] must be set to 1. */
|
||||
static void
|
||||
morecore (nu) /* ask system for more memory */
|
||||
morecore (nu)
|
||||
register int nu; /* size index to get more of */
|
||||
{
|
||||
register union mhead *mp;
|
||||
|
|
@ -531,7 +590,7 @@ morecore (nu) /* ask system for more memory */
|
|||
}
|
||||
|
||||
/* Try to coalesce two adjacent blocks from the free list on nextf[nu - 1],
|
||||
if we can, and we're withing the range of the block coalescing limits. */
|
||||
if we can, and we're within the range of the block coalescing limits. */
|
||||
if (nu >= COMBINE_MIN && nu < COMBINE_MAX && busy[nu - 1] == 0 && nextf[nu - 1])
|
||||
{
|
||||
bcoalesce (nu);
|
||||
|
|
@ -852,9 +911,8 @@ internal_free (mem, file, line, flags)
|
|||
{
|
||||
/* If above LESSCORE_FRC, give back unconditionally. This should be set
|
||||
high enough to be infrequently encountered. If between LESSCORE_MIN
|
||||
and LESSCORE_FRC, call lesscore if the bucket is marked as busy (in
|
||||
which case we would punt below and leak memory) or if there's already
|
||||
a block on the free list. */
|
||||
and LESSCORE_FRC, call lesscore if the bucket is marked as busy or if
|
||||
there's already a block on the free list. */
|
||||
if ((nunits >= LESSCORE_FRC) || busy[nunits] || nextf[nunits] != 0)
|
||||
{
|
||||
lesscore (nunits);
|
||||
|
|
@ -869,11 +927,14 @@ internal_free (mem, file, line, flags)
|
|||
#endif
|
||||
|
||||
ASSERT (nunits < NBUCKETS);
|
||||
p->mh_alloc = ISFREE;
|
||||
|
||||
if (busy[nunits] == 1)
|
||||
return; /* this is bogus, but at least it won't corrupt the chains */
|
||||
{
|
||||
xsplit (p, nunits); /* split block and add to different chain */
|
||||
goto free_return;
|
||||
}
|
||||
|
||||
p->mh_alloc = ISFREE;
|
||||
/* Protect against signal handlers calling malloc. */
|
||||
busy[nunits] = 1;
|
||||
/* Put this block on the free list. */
|
||||
|
|
@ -1026,7 +1087,7 @@ internal_realloc (mem, n, file, line, flags)
|
|||
|
||||
static PTR_T
|
||||
internal_memalign (alignment, size, file, line, flags)
|
||||
unsigned int alignment;
|
||||
size_t alignment;
|
||||
size_t size;
|
||||
const char *file;
|
||||
int line, flags;
|
||||
|
|
@ -1145,7 +1206,7 @@ sh_free (mem, file, line)
|
|||
|
||||
PTR_T
|
||||
sh_memalign (alignment, size, file, line)
|
||||
unsigned int alignment;
|
||||
size_t alignment;
|
||||
size_t size;
|
||||
const char *file;
|
||||
int line;
|
||||
|
|
@ -1212,7 +1273,7 @@ free (mem)
|
|||
|
||||
PTR_T
|
||||
memalign (alignment, size)
|
||||
unsigned int alignment;
|
||||
size_t alignment;
|
||||
size_t size;
|
||||
{
|
||||
return internal_memalign (alignment, size, (char *)NULL, 0, 0);
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ extern PTR_T sh_malloc __P((size_t, const char *, int));
|
|||
extern PTR_T sh_realloc __P((PTR_T, size_t, const char *, int));
|
||||
extern void sh_free __P((PTR_T, const char *, int));
|
||||
|
||||
extern PTR_T sh_memalign __P((unsigned int, size_t, const char *, int));
|
||||
extern PTR_T sh_memalign __P((size_t, size_t, const char *, int));
|
||||
|
||||
extern PTR_T sh_calloc __P((size_t, size_t, const char *, int));
|
||||
extern void sh_cfree __P((PTR_T, const char *, int));
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@
|
|||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "imalloc.h"
|
||||
|
||||
|
|
@ -29,10 +32,10 @@ extern int malloc_trace;
|
|||
|
||||
static int _mtrace_verbose = 0;
|
||||
|
||||
extern FILE *_imalloc_fopen __P((char *, char *, char *, char *, size_t));
|
||||
|
||||
#ifdef MALLOC_TRACE
|
||||
|
||||
extern FILE *_imalloc_fopen __P((char *, char *, char *, char *, size_t));
|
||||
|
||||
FILE *_mtrace_fp = NULL;
|
||||
extern char _malloc_trace_buckets[];
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
# #
|
||||
#############################################################################
|
||||
|
||||
# Copyright (C) 1994 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1994-2005 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* bind.c -- key binding and startup file support for the readline library. */
|
||||
|
||||
/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2005 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.
|
||||
|
|
@ -77,6 +77,9 @@ static char *_rl_read_file PARAMS((char *, size_t *));
|
|||
static void _rl_init_file_error PARAMS((const char *));
|
||||
static int _rl_read_init_file PARAMS((const char *, int));
|
||||
static int glean_key_from_name PARAMS((char *));
|
||||
static int find_boolean_var PARAMS((const char *));
|
||||
|
||||
static char *_rl_get_string_variable_value PARAMS((const char *));
|
||||
static int substring_member_of_array PARAMS((char *, const char **));
|
||||
|
||||
static int currently_reading_init_file;
|
||||
|
|
@ -341,7 +344,7 @@ rl_generic_bind (type, keyseq, data, map)
|
|||
k.function = 0;
|
||||
|
||||
/* If no keys to bind to, exit right away. */
|
||||
if (!keyseq || !*keyseq)
|
||||
if (keyseq == 0 || *keyseq == 0)
|
||||
{
|
||||
if (type == ISMACR)
|
||||
free (data);
|
||||
|
|
@ -369,7 +372,7 @@ rl_generic_bind (type, keyseq, data, map)
|
|||
if (ic < 0 || ic >= KEYMAP_SIZE)
|
||||
return -1;
|
||||
|
||||
if (_rl_convert_meta_chars_to_ascii && META_CHAR (ic))
|
||||
if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii)
|
||||
{
|
||||
ic = UNMETA (ic);
|
||||
if (map[ESC].type == ISKMAP)
|
||||
|
|
@ -460,7 +463,14 @@ rl_translate_keyseq (seq, array, len)
|
|||
else if (c == 'M')
|
||||
{
|
||||
i++;
|
||||
array[l++] = ESC; /* ESC is meta-prefix */
|
||||
/* XXX - should obey convert-meta setting? */
|
||||
if (_rl_convert_meta_chars_to_ascii && _rl_keymap[ESC].type == ISKMAP)
|
||||
array[l++] = ESC; /* ESC is meta-prefix */
|
||||
else
|
||||
{
|
||||
i++;
|
||||
array[l++] = META (seq[i]);
|
||||
}
|
||||
}
|
||||
else if (c == 'C')
|
||||
{
|
||||
|
|
@ -1185,9 +1195,9 @@ rl_parse_and_bind (string)
|
|||
/* If this is a command to set a variable, then do that. */
|
||||
if (_rl_stricmp (string, "set") == 0)
|
||||
{
|
||||
char *var = string + i;
|
||||
char *value;
|
||||
char *var, *value, *e;
|
||||
|
||||
var = string + i;
|
||||
/* Make VAR point to start of variable name. */
|
||||
while (*var && whitespace (*var)) var++;
|
||||
|
||||
|
|
@ -1198,6 +1208,20 @@ rl_parse_and_bind (string)
|
|||
*value++ = '\0';
|
||||
while (*value && whitespace (*value)) value++;
|
||||
|
||||
/* Strip trailing whitespace from values to boolean variables. Temp
|
||||
fix until I get a real quoted-string parser here. */
|
||||
i = find_boolean_var (var);
|
||||
if (i >= 0)
|
||||
{
|
||||
/* remove trailing whitespace */
|
||||
e = value + strlen (value) - 1;
|
||||
while (e >= value && whitespace (*e))
|
||||
e--;
|
||||
e++; /* skip back to whitespace or EOS */
|
||||
if (*e && e >= value)
|
||||
*e = '\0';
|
||||
}
|
||||
|
||||
rl_variable_bind (var, value);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1218,8 +1242,9 @@ rl_parse_and_bind (string)
|
|||
the quoted string delimiter, like the shell. */
|
||||
if (*funname == '\'' || *funname == '"')
|
||||
{
|
||||
int delimiter = string[i++], passc;
|
||||
int delimiter, passc;
|
||||
|
||||
delimiter = string[i++];
|
||||
for (passc = 0; c = string[i]; i++)
|
||||
{
|
||||
if (passc)
|
||||
|
|
@ -1355,6 +1380,7 @@ static struct {
|
|||
int *value;
|
||||
int flags;
|
||||
} boolean_varlist [] = {
|
||||
{ "bind-tty-special-chars", &_rl_bind_stty_chars, 0 },
|
||||
{ "blink-matching-paren", &rl_blink_matching_paren, V_SPECIAL },
|
||||
{ "byte-oriented", &rl_byte_oriented, 0 },
|
||||
{ "completion-ignore-case", &_rl_completion_case_fold, 0 },
|
||||
|
|
@ -1468,13 +1494,34 @@ find_string_var (name)
|
|||
values result in 0 (false). */
|
||||
static int
|
||||
bool_to_int (value)
|
||||
char *value;
|
||||
const char *value;
|
||||
{
|
||||
return (value == 0 || *value == '\0' ||
|
||||
(_rl_stricmp (value, "on") == 0) ||
|
||||
(value[0] == '1' && value[1] == '\0'));
|
||||
}
|
||||
|
||||
char *
|
||||
rl_variable_value (name)
|
||||
const char *name;
|
||||
{
|
||||
register int i;
|
||||
int v;
|
||||
char *ret;
|
||||
|
||||
/* Check for simple variables first. */
|
||||
i = find_boolean_var (name);
|
||||
if (i >= 0)
|
||||
return (*boolean_varlist[i].value ? "on" : "off");
|
||||
|
||||
i = find_string_var (name);
|
||||
if (i >= 0)
|
||||
return (_rl_get_string_variable_value (string_varlist[i].name));
|
||||
|
||||
/* Unknown variable names return NULL. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
rl_variable_bind (name, value)
|
||||
const char *name, *value;
|
||||
|
|
@ -2117,12 +2164,68 @@ rl_dump_macros (count, key)
|
|||
return (0);
|
||||
}
|
||||
|
||||
static char *
|
||||
_rl_get_string_variable_value (name)
|
||||
const char *name;
|
||||
{
|
||||
static char numbuf[32];
|
||||
char *ret;
|
||||
int n;
|
||||
|
||||
if (_rl_stricmp (name, "bell-style") == 0)
|
||||
{
|
||||
switch (_rl_bell_preference)
|
||||
{
|
||||
case NO_BELL:
|
||||
return "none";
|
||||
case VISIBLE_BELL:
|
||||
return "visible";
|
||||
case AUDIBLE_BELL:
|
||||
default:
|
||||
return "audible";
|
||||
}
|
||||
}
|
||||
else if (_rl_stricmp (name, "comment-begin") == 0)
|
||||
return (_rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT);
|
||||
else if (_rl_stricmp (name, "completion-query-items") == 0)
|
||||
{
|
||||
sprintf (numbuf, "%d", rl_completion_query_items);
|
||||
return (numbuf);
|
||||
}
|
||||
else if (_rl_stricmp (name, "editing-mode") == 0)
|
||||
return (rl_get_keymap_name_from_edit_mode ());
|
||||
else if (_rl_stricmp (name, "isearch-terminators") == 0)
|
||||
{
|
||||
if (_rl_isearch_terminators == 0)
|
||||
return 0;
|
||||
ret = _rl_untranslate_macro_value (_rl_isearch_terminators);
|
||||
if (ret)
|
||||
{
|
||||
strncpy (numbuf, ret, sizeof (numbuf) - 1);
|
||||
free (ret);
|
||||
numbuf[sizeof(numbuf) - 1] = '\0';
|
||||
}
|
||||
else
|
||||
numbuf[0] = '\0';
|
||||
return numbuf;
|
||||
}
|
||||
else if (_rl_stricmp (name, "keymap") == 0)
|
||||
{
|
||||
ret = rl_get_keymap_name (_rl_keymap);
|
||||
if (ret == 0)
|
||||
ret = rl_get_keymap_name_from_edit_mode ();
|
||||
return (ret ? ret : "none");
|
||||
}
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
rl_variable_dumper (print_readably)
|
||||
int print_readably;
|
||||
{
|
||||
int i;
|
||||
const char *kname;
|
||||
char *v;
|
||||
|
||||
for (i = 0; boolean_varlist[i].name; i++)
|
||||
{
|
||||
|
|
@ -2134,63 +2237,16 @@ rl_variable_dumper (print_readably)
|
|||
*boolean_varlist[i].value ? "on" : "off");
|
||||
}
|
||||
|
||||
/* bell-style */
|
||||
switch (_rl_bell_preference)
|
||||
for (i = 0; string_varlist[i].name; i++)
|
||||
{
|
||||
case NO_BELL:
|
||||
kname = "none"; break;
|
||||
case VISIBLE_BELL:
|
||||
kname = "visible"; break;
|
||||
case AUDIBLE_BELL:
|
||||
default:
|
||||
kname = "audible"; break;
|
||||
}
|
||||
if (print_readably)
|
||||
fprintf (rl_outstream, "set bell-style %s\n", kname);
|
||||
else
|
||||
fprintf (rl_outstream, "bell-style is set to `%s'\n", kname);
|
||||
|
||||
/* comment-begin */
|
||||
if (print_readably)
|
||||
fprintf (rl_outstream, "set comment-begin %s\n", _rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT);
|
||||
else
|
||||
fprintf (rl_outstream, "comment-begin is set to `%s'\n", _rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT);
|
||||
|
||||
/* completion-query-items */
|
||||
if (print_readably)
|
||||
fprintf (rl_outstream, "set completion-query-items %d\n", rl_completion_query_items);
|
||||
else
|
||||
fprintf (rl_outstream, "completion-query-items is set to `%d'\n", rl_completion_query_items);
|
||||
|
||||
/* editing-mode */
|
||||
if (print_readably)
|
||||
fprintf (rl_outstream, "set editing-mode %s\n", (rl_editing_mode == emacs_mode) ? "emacs" : "vi");
|
||||
else
|
||||
fprintf (rl_outstream, "editing-mode is set to `%s'\n", (rl_editing_mode == emacs_mode) ? "emacs" : "vi");
|
||||
|
||||
/* isearch-terminators */
|
||||
if (_rl_isearch_terminators)
|
||||
{
|
||||
char *disp;
|
||||
|
||||
disp = _rl_untranslate_macro_value (_rl_isearch_terminators);
|
||||
|
||||
v = _rl_get_string_variable_value (string_varlist[i].name);
|
||||
if (v == 0) /* _rl_isearch_terminators can be NULL */
|
||||
continue;
|
||||
if (print_readably)
|
||||
fprintf (rl_outstream, "set isearch-terminators \"%s\"\n", disp);
|
||||
fprintf (rl_outstream, "set %s %s\n", string_varlist[i].name, v);
|
||||
else
|
||||
fprintf (rl_outstream, "isearch-terminators is set to \"%s\"\n", disp);
|
||||
|
||||
free (disp);
|
||||
fprintf (rl_outstream, "%s is set to `%s'\n", string_varlist[i].name, v);
|
||||
}
|
||||
|
||||
/* keymap */
|
||||
kname = rl_get_keymap_name (_rl_keymap);
|
||||
if (kname == 0)
|
||||
kname = rl_get_keymap_name_from_edit_mode ();
|
||||
if (print_readably)
|
||||
fprintf (rl_outstream, "set keymap %s\n", kname ? kname : "none");
|
||||
else
|
||||
fprintf (rl_outstream, "keymap is set to `%s'\n", kname ? kname : "none");
|
||||
}
|
||||
|
||||
/* Print all of the current variables and their values to
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* callback.c -- functions to use readline as an X `callback' mechanism. */
|
||||
|
||||
/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2005 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.
|
||||
|
|
@ -44,9 +44,14 @@
|
|||
#include "readline.h"
|
||||
#include "rlprivate.h"
|
||||
|
||||
/* Private data for callback registration functions. See comments in
|
||||
rl_callback_read_char for more details. */
|
||||
_rl_callback_func_t *_rl_callback_func = 0;
|
||||
_rl_callback_generic_arg *_rl_callback_data = 0;
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* Callback Readline Functions */
|
||||
/* Callback Readline Functions */
|
||||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
|
|
@ -72,7 +77,8 @@ _rl_callback_newline ()
|
|||
{
|
||||
in_handler = 1;
|
||||
|
||||
(*rl_prep_term_function) (_rl_meta_flag);
|
||||
if (rl_prep_term_function)
|
||||
(*rl_prep_term_function) (_rl_meta_flag);
|
||||
|
||||
#if defined (HANDLE_SIGNALS)
|
||||
rl_set_signals ();
|
||||
|
|
@ -89,6 +95,7 @@ rl_callback_handler_install (prompt, linefunc)
|
|||
rl_vcpfunc_t *linefunc;
|
||||
{
|
||||
rl_set_prompt (prompt);
|
||||
RL_SETSTATE (RL_STATE_CALLBACK);
|
||||
rl_linefunc = linefunc;
|
||||
_rl_callback_newline ();
|
||||
}
|
||||
|
|
@ -98,7 +105,8 @@ void
|
|||
rl_callback_read_char ()
|
||||
{
|
||||
char *line;
|
||||
int eof;
|
||||
int eof, jcode;
|
||||
static procenv_t olevel;
|
||||
|
||||
if (rl_linefunc == NULL)
|
||||
{
|
||||
|
|
@ -106,7 +114,79 @@ rl_callback_read_char ()
|
|||
abort ();
|
||||
}
|
||||
|
||||
eof = readline_internal_char ();
|
||||
memcpy ((void *)olevel, (void *)readline_top_level, sizeof (procenv_t));
|
||||
jcode = setjmp (readline_top_level);
|
||||
if (jcode)
|
||||
{
|
||||
(*rl_redisplay_function) ();
|
||||
_rl_want_redisplay = 0;
|
||||
memcpy ((void *)readline_top_level, (void *)olevel, sizeof (procenv_t));
|
||||
return;
|
||||
}
|
||||
|
||||
if (RL_ISSTATE (RL_STATE_ISEARCH))
|
||||
{
|
||||
eof = _rl_isearch_callback (_rl_iscxt);
|
||||
if (eof == 0 && (RL_ISSTATE (RL_STATE_ISEARCH) == 0) && RL_ISSTATE (RL_STATE_INPUTPENDING))
|
||||
rl_callback_read_char ();
|
||||
|
||||
return;
|
||||
}
|
||||
else if (RL_ISSTATE (RL_STATE_NSEARCH))
|
||||
{
|
||||
eof = _rl_nsearch_callback (_rl_nscxt);
|
||||
return;
|
||||
}
|
||||
else if (RL_ISSTATE (RL_STATE_NUMERICARG))
|
||||
{
|
||||
eof = _rl_arg_callback (_rl_argcxt);
|
||||
if (eof == 0 && (RL_ISSTATE (RL_STATE_NUMERICARG) == 0) && RL_ISSTATE (RL_STATE_INPUTPENDING))
|
||||
rl_callback_read_char ();
|
||||
/* XXX - this should handle _rl_last_command_was_kill better */
|
||||
else if (RL_ISSTATE (RL_STATE_NUMERICARG) == 0)
|
||||
_rl_internal_char_cleanup ();
|
||||
|
||||
return;
|
||||
}
|
||||
else if (RL_ISSTATE (RL_STATE_MULTIKEY))
|
||||
{
|
||||
eof = _rl_dispatch_callback (_rl_kscxt); /* For now */
|
||||
while ((eof == -1 || eof == -2) && RL_ISSTATE (RL_STATE_MULTIKEY) && _rl_kscxt && (_rl_kscxt->flags & KSEQ_DISPATCHED))
|
||||
eof = _rl_dispatch_callback (_rl_kscxt);
|
||||
if (RL_ISSTATE (RL_STATE_MULTIKEY) == 0)
|
||||
{
|
||||
_rl_internal_char_cleanup ();
|
||||
_rl_want_redisplay = 1;
|
||||
}
|
||||
}
|
||||
else if (_rl_callback_func)
|
||||
{
|
||||
/* This allows functions that simply need to read an additional character
|
||||
(like quoted-insert) to register a function to be called when input is
|
||||
available. _rl_callback_data is simply a pointer to a struct that has
|
||||
the argument count originally passed to the registering function and
|
||||
space for any additional parameters. */
|
||||
eof = (*_rl_callback_func) (_rl_callback_data);
|
||||
/* If the function `deregisters' itself, make sure the data is cleaned
|
||||
up. */
|
||||
if (_rl_callback_func == 0)
|
||||
{
|
||||
if (_rl_callback_data)
|
||||
{
|
||||
_rl_callback_data_dispose (_rl_callback_data);
|
||||
_rl_callback_data = 0;
|
||||
}
|
||||
_rl_internal_char_cleanup ();
|
||||
}
|
||||
}
|
||||
else
|
||||
eof = readline_internal_char ();
|
||||
|
||||
if (rl_done == 0 && _rl_want_redisplay)
|
||||
{
|
||||
(*rl_redisplay_function) ();
|
||||
_rl_want_redisplay = 0;
|
||||
}
|
||||
|
||||
/* We loop in case some function has pushed input back with rl_execute_next. */
|
||||
for (;;)
|
||||
|
|
@ -115,7 +195,8 @@ rl_callback_read_char ()
|
|||
{
|
||||
line = readline_internal_teardown (eof);
|
||||
|
||||
(*rl_deprep_term_function) ();
|
||||
if (rl_deprep_term_function)
|
||||
(*rl_deprep_term_function) ();
|
||||
#if defined (HANDLE_SIGNALS)
|
||||
rl_clear_signals ();
|
||||
#endif
|
||||
|
|
@ -131,10 +212,10 @@ rl_callback_read_char ()
|
|||
if (in_handler == 0 && rl_linefunc)
|
||||
_rl_callback_newline ();
|
||||
}
|
||||
if (rl_pending_input || _rl_pushed_input_available ())
|
||||
if (rl_pending_input || _rl_pushed_input_available () || RL_ISSTATE (RL_STATE_MACROINPUT))
|
||||
eof = readline_internal_char ();
|
||||
else
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -143,14 +224,37 @@ void
|
|||
rl_callback_handler_remove ()
|
||||
{
|
||||
rl_linefunc = NULL;
|
||||
RL_UNSETSTATE (RL_STATE_CALLBACK);
|
||||
if (in_handler)
|
||||
{
|
||||
in_handler = 0;
|
||||
(*rl_deprep_term_function) ();
|
||||
if (rl_deprep_term_function)
|
||||
(*rl_deprep_term_function) ();
|
||||
#if defined (HANDLE_SIGNALS)
|
||||
rl_clear_signals ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
_rl_callback_generic_arg *
|
||||
_rl_callback_data_alloc (count)
|
||||
int count;
|
||||
{
|
||||
_rl_callback_generic_arg *arg;
|
||||
|
||||
arg = (_rl_callback_generic_arg *)xmalloc (sizeof (_rl_callback_generic_arg));
|
||||
arg->count = count;
|
||||
|
||||
arg->i1 = arg->i2 = 0;
|
||||
|
||||
return arg;
|
||||
}
|
||||
|
||||
void _rl_callback_data_dispose (arg)
|
||||
_rl_callback_generic_arg *arg;
|
||||
{
|
||||
if (arg)
|
||||
free (arg);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -86,6 +86,8 @@
|
|||
/* Some systems define these; we want our definitions. */
|
||||
#undef ISPRINT
|
||||
|
||||
/* Beware: these only work with single-byte ASCII characters. */
|
||||
|
||||
#define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
|
||||
#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
|
||||
#define ISDIGIT(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* complete.c -- filename completion for readline. */
|
||||
|
||||
/* Copyright (C) 1987-2004 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2005 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.
|
||||
|
|
@ -48,7 +48,9 @@
|
|||
extern int errno;
|
||||
#endif /* !errno */
|
||||
|
||||
#if defined (HAVE_PWD_H)
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
#include "posixdir.h"
|
||||
#include "posixstat.h"
|
||||
|
|
@ -79,9 +81,9 @@ typedef int QSFUNC ();
|
|||
|
||||
/* Most systems don't declare getpwent in <pwd.h> if _POSIX_SOURCE is
|
||||
defined. */
|
||||
#if !defined (HAVE_GETPW_DECLS) || defined (_POSIX_SOURCE)
|
||||
#if defined (HAVE_GETPWENT) && (!defined (HAVE_GETPW_DECLS) || defined (_POSIX_SOURCE))
|
||||
extern struct passwd *getpwent PARAMS((void));
|
||||
#endif /* !HAVE_GETPW_DECLS || _POSIX_SOURCE */
|
||||
#endif /* HAVE_GETPWENT && (!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.
|
||||
|
|
@ -206,7 +208,8 @@ int rl_completion_type = 0;
|
|||
|
||||
/* Up to this many items will be displayed in response to a
|
||||
possible-completions call. After that, we ask the user if
|
||||
she is sure she wants to see them all. */
|
||||
she is sure she wants to see them all. A negative value means
|
||||
don't ask. */
|
||||
int rl_completion_query_items = 100;
|
||||
|
||||
int _rl_page_completions = 1;
|
||||
|
|
@ -621,6 +624,8 @@ fnprint (to_print)
|
|||
mbstate_t ps;
|
||||
const char *end;
|
||||
size_t tlen;
|
||||
int width, w;
|
||||
wchar_t wc;
|
||||
|
||||
end = to_print + strlen (to_print) + 1;
|
||||
memset (&ps, 0, sizeof (mbstate_t));
|
||||
|
|
@ -653,21 +658,28 @@ fnprint (to_print)
|
|||
else
|
||||
{
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
tlen = mbrlen (s, end - s, &ps);
|
||||
tlen = mbrtowc (&wc, s, end - s, &ps);
|
||||
if (MB_INVALIDCH (tlen))
|
||||
{
|
||||
tlen = 1;
|
||||
width = 1;
|
||||
memset (&ps, 0, sizeof (mbstate_t));
|
||||
}
|
||||
else if (MB_NULLWCH (tlen))
|
||||
break;
|
||||
else
|
||||
{
|
||||
w = wcwidth (wc);
|
||||
width = (w >= 0) ? w : 1;
|
||||
}
|
||||
fwrite (s, 1, tlen, rl_outstream);
|
||||
s += tlen;
|
||||
printed_len += width;
|
||||
#else
|
||||
putc (*s, rl_outstream);
|
||||
s++;
|
||||
#endif
|
||||
printed_len++;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -683,7 +695,7 @@ print_filename (to_print, full_pathname)
|
|||
char *to_print, *full_pathname;
|
||||
{
|
||||
int printed_len, extension_char, slen, tlen;
|
||||
char *s, c, *new_full_pathname;
|
||||
char *s, c, *new_full_pathname, *dn;
|
||||
|
||||
extension_char = 0;
|
||||
printed_len = fnprint (to_print);
|
||||
|
|
@ -708,7 +720,17 @@ print_filename (to_print, full_pathname)
|
|||
files in the root directory. If we pass a null string to the
|
||||
bash directory completion hook, for example, it will expand it
|
||||
to the current directory. We just want the `/'. */
|
||||
s = tilde_expand (full_pathname && *full_pathname ? full_pathname : "/");
|
||||
if (full_pathname == 0 || *full_pathname == 0)
|
||||
dn = "/";
|
||||
else if (full_pathname[0] != '/')
|
||||
dn = full_pathname;
|
||||
else if (full_pathname[1] == 0)
|
||||
dn = "//"; /* restore trailing slash to `//' */
|
||||
else if (full_pathname[1] == '/' && full_pathname[2] == 0)
|
||||
dn = "/"; /* don't turn /// into // */
|
||||
else
|
||||
dn = full_pathname;
|
||||
s = tilde_expand (dn);
|
||||
if (rl_directory_completion_hook)
|
||||
(*rl_directory_completion_hook) (&s);
|
||||
|
||||
|
|
@ -716,6 +738,10 @@ print_filename (to_print, full_pathname)
|
|||
tlen = strlen (to_print);
|
||||
new_full_pathname = (char *)xmalloc (slen + tlen + 2);
|
||||
strcpy (new_full_pathname, s);
|
||||
if (s[slen - 1] == '/')
|
||||
slen--;
|
||||
else
|
||||
new_full_pathname[slen] = '/';
|
||||
new_full_pathname[slen] = '/';
|
||||
strcpy (new_full_pathname + slen + 1, to_print);
|
||||
|
||||
|
|
@ -807,14 +833,7 @@ _rl_find_completion_word (fp, dp)
|
|||
quote substrings for the completer. Try to find the start
|
||||
of an unclosed quoted substring. */
|
||||
/* FOUND_QUOTE is set so we know what kind of quotes we found. */
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
for (scan = pass_next = 0; scan < end;
|
||||
scan = ((MB_CUR_MAX == 1 || rl_byte_oriented)
|
||||
? (scan + 1)
|
||||
: _rl_find_next_mbchar (rl_line_buffer, scan, 1, MB_FIND_ANY)))
|
||||
#else
|
||||
for (scan = pass_next = 0; scan < end; scan++)
|
||||
#endif
|
||||
for (scan = pass_next = 0; scan < end; scan = MB_NEXTCHAR (rl_line_buffer, scan, 1, MB_FIND_ANY))
|
||||
{
|
||||
if (pass_next)
|
||||
{
|
||||
|
|
@ -864,11 +883,7 @@ _rl_find_completion_word (fp, dp)
|
|||
/* We didn't find an unclosed quoted substring upon which to do
|
||||
completion, so use the word break characters to find the
|
||||
substring on which to complete. */
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
while (rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_ANY))
|
||||
#else
|
||||
while (--rl_point)
|
||||
#endif
|
||||
while (rl_point = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_ANY))
|
||||
{
|
||||
scan = rl_line_buffer[rl_point];
|
||||
|
||||
|
|
@ -1151,7 +1166,7 @@ compute_lcd_of_matches (match_list, matches, text)
|
|||
rl_completion_found_quote &&
|
||||
rl_filename_quoting_desired)
|
||||
{
|
||||
dtext = (*rl_filename_dequoting_function) (text, rl_completion_quote_character);
|
||||
dtext = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
|
||||
text = dtext;
|
||||
}
|
||||
|
||||
|
|
@ -1397,7 +1412,7 @@ display_matches (matches)
|
|||
|
||||
/* If there are many items, then ask the user if she really wants to
|
||||
see them all. */
|
||||
if (len >= rl_completion_query_items)
|
||||
if (rl_completion_query_items > 0 && len >= rl_completion_query_items)
|
||||
{
|
||||
rl_crlf ();
|
||||
fprintf (rl_outstream, "Display all %d possibilities? (y or n)", len);
|
||||
|
|
@ -1534,7 +1549,7 @@ append_to_match (text, delimiter, quote_char, nontrivial_match)
|
|||
: stat (filename, &finfo);
|
||||
if (s == 0 && S_ISDIR (finfo.st_mode))
|
||||
{
|
||||
if (_rl_complete_mark_directories)
|
||||
if (_rl_complete_mark_directories /* && rl_completion_suppress_append == 0 */)
|
||||
{
|
||||
/* This is clumsy. Avoid putting in a double slash if point
|
||||
is at the end of the line and the previous character is a
|
||||
|
|
@ -1848,16 +1863,20 @@ rl_username_completion_function (text, state)
|
|||
setpwent ();
|
||||
}
|
||||
|
||||
#if defined (HAVE_GETPWENT)
|
||||
while (entry = getpwent ())
|
||||
{
|
||||
/* Null usernames should result in all users as possible completions. */
|
||||
if (namelen == 0 || (STREQN (username, entry->pw_name, namelen)))
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (entry == 0)
|
||||
{
|
||||
#if defined (HAVE_GETPWENT)
|
||||
endpwent ();
|
||||
#endif
|
||||
return ((char *)NULL);
|
||||
}
|
||||
else
|
||||
|
|
@ -2169,9 +2188,11 @@ rl_menu_complete (count, ignore)
|
|||
return (0);
|
||||
}
|
||||
|
||||
match_list_index = (match_list_index + count) % match_list_size;
|
||||
match_list_index += count;
|
||||
if (match_list_index < 0)
|
||||
match_list_index += match_list_size;
|
||||
else
|
||||
match_list_index %= match_list_size;
|
||||
|
||||
if (match_list_index == 0 && match_list_size > 1)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* display.c -- readline redisplay facility. */
|
||||
|
||||
/* Copyright (C) 1987-2004 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2005 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.
|
||||
|
|
@ -118,16 +118,24 @@ rl_voidfunc_t *rl_redisplay_function = rl_redisplay;
|
|||
int rl_display_fixed = 0;
|
||||
|
||||
int _rl_suppress_redisplay = 0;
|
||||
int _rl_want_redisplay = 0;
|
||||
|
||||
/* The stuff that gets printed out before the actual text of the line.
|
||||
This is usually pointing to rl_prompt. */
|
||||
char *rl_display_prompt = (char *)NULL;
|
||||
|
||||
/* Pseudo-global variables declared here. */
|
||||
|
||||
/* The visible cursor position. If you print some text, adjust this. */
|
||||
/* NOTE: _rl_last_c_pos is used as a buffer index when not in a locale
|
||||
supporting multibyte characters, and an absolute cursor position when
|
||||
in such a locale. This is an artifact of the donated multibyte support.
|
||||
Care must be taken when modifying its value. */
|
||||
int _rl_last_c_pos = 0;
|
||||
int _rl_last_v_pos = 0;
|
||||
|
||||
static int cpos_adjusted;
|
||||
|
||||
/* Number of lines currently on screen minus 1. */
|
||||
int _rl_vis_botlin = 0;
|
||||
|
||||
|
|
@ -180,6 +188,18 @@ static int prompt_last_screen_line;
|
|||
|
||||
static int prompt_physical_chars;
|
||||
|
||||
/* Variables to save and restore prompt and display information. */
|
||||
|
||||
/* These are getting numerous enough that it's time to create a struct. */
|
||||
|
||||
static char *saved_local_prompt;
|
||||
static char *saved_local_prefix;
|
||||
static int saved_last_invisible;
|
||||
static int saved_visible_length;
|
||||
static int saved_prefix_length;
|
||||
static int saved_invis_chars_first_line;
|
||||
static int saved_physical_chars;
|
||||
|
||||
/* 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
|
||||
|
|
@ -236,7 +256,8 @@ expand_prompt (pmt, lp, lip, niflp, vlp)
|
|||
else if (ignoring && *p == RL_PROMPT_END_IGNORE)
|
||||
{
|
||||
ignoring = 0;
|
||||
last = r - ret - 1;
|
||||
if (p[-1] != RL_PROMPT_START_IGNORE)
|
||||
last = r - ret - 1;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
|
|
@ -335,7 +356,8 @@ rl_expand_prompt (prompt)
|
|||
FREE (local_prompt_prefix);
|
||||
|
||||
local_prompt = local_prompt_prefix = (char *)0;
|
||||
prompt_last_invisible = prompt_visible_length = 0;
|
||||
prompt_last_invisible = prompt_invis_chars_first_line = 0;
|
||||
prompt_visible_length = prompt_physical_chars = 0;
|
||||
|
||||
if (prompt == 0 || *prompt == 0)
|
||||
return (0);
|
||||
|
|
@ -423,7 +445,7 @@ rl_redisplay ()
|
|||
{
|
||||
register int in, out, c, linenum, cursor_linenum;
|
||||
register char *line;
|
||||
int c_pos, inv_botlin, lb_botlin, lb_linenum;
|
||||
int c_pos, inv_botlin, lb_botlin, lb_linenum, o_cpos;
|
||||
int newlines, lpos, temp, modmark, n0, num;
|
||||
char *prompt_this_line;
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
|
|
@ -440,7 +462,7 @@ rl_redisplay ()
|
|||
if (!rl_display_prompt)
|
||||
rl_display_prompt = "";
|
||||
|
||||
if (invisible_line == 0)
|
||||
if (invisible_line == 0 || vis_lbreaks == 0)
|
||||
{
|
||||
init_line_structures (0);
|
||||
rl_on_new_line ();
|
||||
|
|
@ -833,7 +855,7 @@ rl_redisplay ()
|
|||
|
||||
if (_rl_horizontal_scroll_mode == 0 && _rl_term_up && *_rl_term_up)
|
||||
{
|
||||
int nleft, pos, changed_screen_line;
|
||||
int nleft, pos, changed_screen_line, tx;
|
||||
|
||||
if (!rl_display_fixed || forced_display)
|
||||
{
|
||||
|
|
@ -864,9 +886,26 @@ rl_redisplay ()
|
|||
/* For each line in the buffer, do the updating display. */
|
||||
for (linenum = 0; linenum <= inv_botlin; linenum++)
|
||||
{
|
||||
o_cpos = _rl_last_c_pos;
|
||||
cpos_adjusted = 0;
|
||||
update_line (VIS_LINE(linenum), INV_LINE(linenum), linenum,
|
||||
VIS_LLEN(linenum), INV_LLEN(linenum), inv_botlin);
|
||||
|
||||
/* update_line potentially changes _rl_last_c_pos, but doesn't
|
||||
take invisible characters into account, since _rl_last_c_pos
|
||||
is an absolute cursor position in a multibyte locale. See
|
||||
if compensating here is the right thing, or if we have to
|
||||
change update_line itself. There is one case in which
|
||||
update_line adjusts _rl_last_c_pos itself (so it can pass
|
||||
_rl_move_cursor_relative accurate values); it communicates
|
||||
this back by setting cpos_adjusted */
|
||||
if (linenum == 0 && (MB_CUR_MAX > 1 && rl_byte_oriented == 0) &&
|
||||
cpos_adjusted == 0 &&
|
||||
_rl_last_c_pos != o_cpos &&
|
||||
_rl_last_c_pos > wrap_offset &&
|
||||
o_cpos < prompt_last_invisible)
|
||||
_rl_last_c_pos -= wrap_offset;
|
||||
|
||||
/* If this is the line with the prompt, we might need to
|
||||
compensate for invisible characters in the new line. Do
|
||||
this only if there is not more than one new line (which
|
||||
|
|
@ -878,7 +917,10 @@ rl_redisplay ()
|
|||
(wrap_offset > visible_wrap_offset) &&
|
||||
(_rl_last_c_pos < visible_first_line_len))
|
||||
{
|
||||
nleft = _rl_screenwidth + wrap_offset - _rl_last_c_pos;
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
nleft = _rl_screenwidth - _rl_last_c_pos;
|
||||
else
|
||||
nleft = _rl_screenwidth + wrap_offset - _rl_last_c_pos;
|
||||
if (nleft)
|
||||
_rl_clear_to_eol (nleft);
|
||||
}
|
||||
|
|
@ -914,7 +956,7 @@ rl_redisplay ()
|
|||
the physical cursor position on the screen stays the same,
|
||||
but the buffer position needs to be adjusted to account
|
||||
for invisible characters. */
|
||||
if (cursor_linenum == 0 && wrap_offset)
|
||||
if ((MB_CUR_MAX == 1 || rl_byte_oriented) && cursor_linenum == 0 && wrap_offset)
|
||||
_rl_last_c_pos += wrap_offset;
|
||||
}
|
||||
|
||||
|
|
@ -935,7 +977,7 @@ rl_redisplay ()
|
|||
#endif
|
||||
_rl_output_some_chars (local_prompt, nleft);
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
_rl_last_c_pos = _rl_col_width (local_prompt, 0, nleft);
|
||||
_rl_last_c_pos = _rl_col_width (local_prompt, 0, nleft) - wrap_offset;
|
||||
else
|
||||
_rl_last_c_pos = nleft;
|
||||
}
|
||||
|
|
@ -947,18 +989,31 @@ rl_redisplay ()
|
|||
start of the line and the cursor position. */
|
||||
nleft = c_pos - pos;
|
||||
|
||||
/* NLEFT is now a number of characters in a buffer. When in a
|
||||
multibyte locale, however, _rl_last_c_pos is an absolute cursor
|
||||
position that doesn't take invisible characters in the prompt
|
||||
into account. We use a fudge factor to compensate. */
|
||||
|
||||
/* Since _rl_backspace() doesn't know about invisible characters in the
|
||||
prompt, and there's no good way to tell it, we compensate for
|
||||
those characters here and call _rl_backspace() directly. */
|
||||
if (wrap_offset && cursor_linenum == 0 && nleft < _rl_last_c_pos)
|
||||
{
|
||||
_rl_backspace (_rl_last_c_pos - nleft);
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
_rl_last_c_pos = _rl_col_width (&visible_line[pos], 0, nleft);
|
||||
tx = _rl_col_width (&visible_line[pos], 0, nleft) - visible_wrap_offset;
|
||||
else
|
||||
_rl_last_c_pos = nleft;
|
||||
tx = nleft;
|
||||
if (_rl_last_c_pos > tx)
|
||||
{
|
||||
_rl_backspace (_rl_last_c_pos - tx); /* XXX */
|
||||
_rl_last_c_pos = tx;
|
||||
}
|
||||
}
|
||||
|
||||
/* We need to note that in a multibyte locale we are dealing with
|
||||
_rl_last_c_pos as an absolute cursor position, but moving to a
|
||||
point specified by a buffer position (NLEFT) that doesn't take
|
||||
invisible characters into account. */
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
_rl_move_cursor_relative (nleft, &invisible_line[pos]);
|
||||
else if (nleft != _rl_last_c_pos)
|
||||
|
|
@ -1117,7 +1172,10 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
|
|||
the exact cursor position and cut-and-paste with certain terminal
|
||||
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 (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
temp = _rl_last_c_pos;
|
||||
else
|
||||
temp = _rl_last_c_pos - W_OFFSET(_rl_last_v_pos, visible_wrap_offset);
|
||||
if (temp == _rl_screenwidth && _rl_term_autowrap && !_rl_horizontal_scroll_mode
|
||||
&& _rl_last_v_pos == current_line - 1)
|
||||
{
|
||||
|
|
@ -1182,7 +1240,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
|
|||
putc (new[0], rl_outstream);
|
||||
else
|
||||
putc (' ', rl_outstream);
|
||||
_rl_last_c_pos = 1; /* XXX */
|
||||
_rl_last_c_pos = 1;
|
||||
_rl_last_v_pos++;
|
||||
if (old[0] && new[0])
|
||||
old[0] = new[0];
|
||||
|
|
@ -1323,7 +1381,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
|
|||
if (_rl_last_v_pos != current_line)
|
||||
{
|
||||
_rl_move_vert (current_line);
|
||||
if (current_line == 0 && visible_wrap_offset)
|
||||
if ((MB_CUR_MAX == 1 || rl_byte_oriented) && current_line == 0 && visible_wrap_offset)
|
||||
_rl_last_c_pos += visible_wrap_offset;
|
||||
}
|
||||
|
||||
|
|
@ -1352,7 +1410,12 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
|
|||
#endif
|
||||
_rl_output_some_chars (local_prompt, lendiff);
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
_rl_last_c_pos = _rl_col_width (local_prompt, 0, lendiff);
|
||||
{
|
||||
/* We take wrap_offset into account here so we can pass correct
|
||||
information to _rl_move_cursor_relative. */
|
||||
_rl_last_c_pos = _rl_col_width (local_prompt, 0, lendiff) - wrap_offset;
|
||||
cpos_adjusted = 1;
|
||||
}
|
||||
else
|
||||
_rl_last_c_pos = lendiff;
|
||||
}
|
||||
|
|
@ -1414,7 +1477,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
|
|||
insert_some_chars (nfd, lendiff, col_lendiff);
|
||||
_rl_last_c_pos += col_lendiff;
|
||||
}
|
||||
else if (*ols == 0 && lendiff > 0)
|
||||
else if ((MB_CUR_MAX == 1 || rl_byte_oriented != 0) && *ols == 0 && lendiff > 0)
|
||||
{
|
||||
/* At the end of a line the characters do not have to
|
||||
be "inserted". They can just be placed on the screen. */
|
||||
|
|
@ -1453,6 +1516,10 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
|
|||
/* cannot insert chars, write to EOL */
|
||||
_rl_output_some_chars (nfd, temp);
|
||||
_rl_last_c_pos += col_temp;
|
||||
/* If we're in a multibyte locale and were before the last invisible
|
||||
char in the current line (which implies we just output some invisible
|
||||
characters) we need to adjust _rl_last_c_pos, since it represents
|
||||
a physical character position. */
|
||||
}
|
||||
}
|
||||
else /* Delete characters from line. */
|
||||
|
|
@ -1484,7 +1551,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin)
|
|||
if (temp > 0)
|
||||
{
|
||||
_rl_output_some_chars (nfd, temp);
|
||||
_rl_last_c_pos += col_temp;
|
||||
_rl_last_c_pos += col_temp; /* XXX */
|
||||
}
|
||||
lendiff = (oe - old) - (ne - new);
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
|
|
@ -1546,7 +1613,7 @@ rl_on_new_line_with_prompt ()
|
|||
|
||||
l = strlen (prompt_last_line);
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
_rl_last_c_pos = _rl_col_width (prompt_last_line, 0, l);
|
||||
_rl_last_c_pos = _rl_col_width (prompt_last_line, 0, l); /* XXX */
|
||||
else
|
||||
_rl_last_c_pos = l;
|
||||
|
||||
|
|
@ -1595,6 +1662,8 @@ rl_forced_update_display ()
|
|||
}
|
||||
|
||||
/* Move the cursor from _rl_last_c_pos to NEW, which are buffer indices.
|
||||
(Well, when we don't have multibyte characters, _rl_last_c_pos is a
|
||||
buffer index.)
|
||||
DATA is the contents of the screen line of interest; i.e., where
|
||||
the movement is being done. */
|
||||
void
|
||||
|
|
@ -1603,28 +1672,40 @@ _rl_move_cursor_relative (new, data)
|
|||
const char *data;
|
||||
{
|
||||
register int i;
|
||||
int woff; /* number of invisible chars on current line */
|
||||
int cpos, dpos; /* current and desired cursor positions */
|
||||
|
||||
/* If we don't have to do anything, then return. */
|
||||
woff = W_OFFSET (_rl_last_v_pos, wrap_offset);
|
||||
cpos = _rl_last_c_pos;
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
/* If we have multibyte characters, NEW is indexed by the buffer point in
|
||||
a multibyte string, but _rl_last_c_pos is the display position. In
|
||||
this case, NEW's display position is not obvious and must be
|
||||
calculated. */
|
||||
if (MB_CUR_MAX == 1 || rl_byte_oriented)
|
||||
calculated. We need to account for invisible characters in this line,
|
||||
as long as we are past them and they are counted by _rl_col_width. */
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
if (_rl_last_c_pos == new)
|
||||
return;
|
||||
dpos = _rl_col_width (data, 0, new);
|
||||
if (dpos > woff)
|
||||
dpos -= woff;
|
||||
}
|
||||
else if (_rl_last_c_pos == _rl_col_width (data, 0, new))
|
||||
return;
|
||||
#else
|
||||
if (_rl_last_c_pos == new) return;
|
||||
else
|
||||
#endif
|
||||
dpos = new;
|
||||
|
||||
/* If we don't have to do anything, then return. */
|
||||
if (cpos == dpos)
|
||||
return;
|
||||
|
||||
/* It may be faster to output a CR, and then move forwards instead
|
||||
of moving backwards. */
|
||||
/* i == current physical cursor position. */
|
||||
i = _rl_last_c_pos - W_OFFSET(_rl_last_v_pos, visible_wrap_offset);
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
i = _rl_last_c_pos;
|
||||
else
|
||||
#endif
|
||||
i = _rl_last_c_pos - woff;
|
||||
if (new == 0 || CR_FASTER (new, _rl_last_c_pos) ||
|
||||
(_rl_term_autowrap && i == _rl_screenwidth))
|
||||
{
|
||||
|
|
@ -1633,10 +1714,10 @@ _rl_move_cursor_relative (new, data)
|
|||
#else
|
||||
tputs (_rl_term_cr, 1, _rl_output_character_function);
|
||||
#endif /* !__MSDOS__ */
|
||||
_rl_last_c_pos = 0;
|
||||
cpos = _rl_last_c_pos = 0;
|
||||
}
|
||||
|
||||
if (_rl_last_c_pos < new)
|
||||
if (cpos < dpos)
|
||||
{
|
||||
/* Move the cursor forward. We do it by printing the command
|
||||
to move the cursor forward if there is one, else print that
|
||||
|
|
@ -1650,31 +1731,11 @@ _rl_move_cursor_relative (new, data)
|
|||
#if defined (HACK_TERMCAP_MOTION)
|
||||
if (_rl_term_forward_char)
|
||||
{
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
int width;
|
||||
width = _rl_col_width (data, _rl_last_c_pos, new);
|
||||
for (i = 0; i < width; i++)
|
||||
tputs (_rl_term_forward_char, 1, _rl_output_character_function);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = _rl_last_c_pos; i < new; i++)
|
||||
tputs (_rl_term_forward_char, 1, _rl_output_character_function);
|
||||
}
|
||||
}
|
||||
else if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
tputs (_rl_term_cr, 1, _rl_output_character_function);
|
||||
for (i = 0; i < new; i++)
|
||||
putc (data[i], rl_outstream);
|
||||
for (i = cpos; i < dpos; i++)
|
||||
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);
|
||||
|
||||
#else /* !HACK_TERMCAP_MOTION */
|
||||
|
||||
#endif /* HACK_TERMCAP_MOTION */
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
tputs (_rl_term_cr, 1, _rl_output_character_function);
|
||||
|
|
@ -1682,32 +1743,20 @@ _rl_move_cursor_relative (new, data)
|
|||
putc (data[i], rl_outstream);
|
||||
}
|
||||
else
|
||||
for (i = _rl_last_c_pos; i < new; i++)
|
||||
for (i = cpos; i < new; i++)
|
||||
putc (data[i], rl_outstream);
|
||||
|
||||
#endif /* !HACK_TERMCAP_MOTION */
|
||||
|
||||
}
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
/* NEW points to the buffer point, but _rl_last_c_pos is the display point.
|
||||
The byte length of the string is probably bigger than the column width
|
||||
of the string, which means that if NEW == _rl_last_c_pos, then NEW's
|
||||
display point is less than _rl_last_c_pos. */
|
||||
else if (_rl_last_c_pos >= new)
|
||||
#else
|
||||
else if (_rl_last_c_pos > new)
|
||||
#endif
|
||||
{
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
_rl_backspace (_rl_last_c_pos - _rl_col_width (data, 0, new));
|
||||
else
|
||||
_rl_backspace (_rl_last_c_pos - new);
|
||||
}
|
||||
else if (cpos > dpos)
|
||||
_rl_backspace (cpos - dpos);
|
||||
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
_rl_last_c_pos = _rl_col_width (data, 0, new);
|
||||
else
|
||||
_rl_last_c_pos = new;
|
||||
_rl_last_c_pos = dpos;
|
||||
}
|
||||
|
||||
/* PWP: move the cursor up or down. */
|
||||
|
|
@ -1796,9 +1845,9 @@ rl_character_len (c, pos)
|
|||
|
||||
return ((ISPRINT (uc)) ? 1 : 2);
|
||||
}
|
||||
|
||||
/* How to print things in the "echo-area". The prompt is treated as a
|
||||
mini-modeline. */
|
||||
static int msg_saved_prompt = 0;
|
||||
|
||||
#if defined (USE_VARARGS)
|
||||
int
|
||||
|
|
@ -1829,8 +1878,19 @@ rl_message (va_alist)
|
|||
#endif
|
||||
va_end (args);
|
||||
|
||||
if (saved_local_prompt == 0)
|
||||
{
|
||||
rl_save_prompt ();
|
||||
msg_saved_prompt = 1;
|
||||
}
|
||||
rl_display_prompt = msg_buf;
|
||||
local_prompt = expand_prompt (msg_buf, &prompt_visible_length,
|
||||
&prompt_last_invisible,
|
||||
&prompt_invis_chars_first_line,
|
||||
&prompt_physical_chars);
|
||||
local_prompt_prefix = (char *)NULL;
|
||||
(*rl_redisplay_function) ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else /* !USE_VARARGS */
|
||||
|
|
@ -1840,8 +1900,20 @@ rl_message (format, arg1, arg2)
|
|||
{
|
||||
sprintf (msg_buf, format, arg1, arg2);
|
||||
msg_buf[sizeof(msg_buf) - 1] = '\0'; /* overflow? */
|
||||
|
||||
rl_display_prompt = msg_buf;
|
||||
if (saved_local_prompt == 0)
|
||||
{
|
||||
rl_save_prompt ();
|
||||
msg_saved_prompt = 1;
|
||||
}
|
||||
local_prompt = expand_prompt (msg_buf, &prompt_visible_length,
|
||||
&prompt_last_invisible,
|
||||
&prompt_invis_chars_first_line,
|
||||
&prompt_physical_chars);
|
||||
local_prompt_prefix = (char *)NULL;
|
||||
(*rl_redisplay_function) ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* !USE_VARARGS */
|
||||
|
|
@ -1851,6 +1923,11 @@ int
|
|||
rl_clear_message ()
|
||||
{
|
||||
rl_display_prompt = rl_prompt;
|
||||
if (msg_saved_prompt)
|
||||
{
|
||||
rl_restore_prompt ();
|
||||
msg_saved_prompt = 0;
|
||||
}
|
||||
(*rl_redisplay_function) ();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1865,27 +1942,19 @@ rl_reset_line_state ()
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* These are getting numerous enough that it's time to create a struct. */
|
||||
|
||||
static char *saved_local_prompt;
|
||||
static char *saved_local_prefix;
|
||||
static int saved_last_invisible;
|
||||
static int saved_visible_length;
|
||||
static int saved_invis_chars_first_line;
|
||||
static int saved_physical_chars;
|
||||
|
||||
void
|
||||
rl_save_prompt ()
|
||||
{
|
||||
saved_local_prompt = local_prompt;
|
||||
saved_local_prefix = local_prompt_prefix;
|
||||
saved_prefix_length = prompt_prefix_length;
|
||||
saved_last_invisible = prompt_last_invisible;
|
||||
saved_visible_length = prompt_visible_length;
|
||||
saved_invis_chars_first_line = prompt_invis_chars_first_line;
|
||||
saved_physical_chars = prompt_physical_chars;
|
||||
|
||||
local_prompt = local_prompt_prefix = (char *)0;
|
||||
prompt_last_invisible = prompt_visible_length = 0;
|
||||
prompt_last_invisible = prompt_visible_length = prompt_prefix_length = 0;
|
||||
prompt_invis_chars_first_line = prompt_physical_chars = 0;
|
||||
}
|
||||
|
||||
|
|
@ -1897,10 +1966,16 @@ rl_restore_prompt ()
|
|||
|
||||
local_prompt = saved_local_prompt;
|
||||
local_prompt_prefix = saved_local_prefix;
|
||||
prompt_prefix_length = saved_prefix_length;
|
||||
prompt_last_invisible = saved_last_invisible;
|
||||
prompt_visible_length = saved_visible_length;
|
||||
prompt_invis_chars_first_line = saved_invis_chars_first_line;
|
||||
prompt_physical_chars = saved_physical_chars;
|
||||
|
||||
/* can test saved_local_prompt to see if prompt info has been saved. */
|
||||
saved_local_prompt = saved_local_prefix = (char *)0;
|
||||
saved_last_invisible = saved_visible_length = saved_prefix_length = 0;
|
||||
saved_invis_chars_first_line = saved_physical_chars = 0;
|
||||
}
|
||||
|
||||
char *
|
||||
|
|
@ -1934,6 +2009,8 @@ _rl_make_prompt_for_search (pchar)
|
|||
prompt_visible_length = saved_visible_length + 1;
|
||||
}
|
||||
|
||||
prompt_physical_chars = saved_physical_chars + 1;
|
||||
|
||||
return pmt;
|
||||
}
|
||||
|
||||
|
|
@ -1994,6 +2071,9 @@ insert_some_chars (string, count, col)
|
|||
char *string;
|
||||
int count, col;
|
||||
{
|
||||
#if defined (__MSDOS__) || defined (__MINGW32__)
|
||||
_rl_output_some_chars (string, count);
|
||||
#else
|
||||
/* DEBUGGING */
|
||||
if (MB_CUR_MAX == 1 || rl_byte_oriented)
|
||||
if (count != col)
|
||||
|
|
@ -2032,6 +2112,7 @@ insert_some_chars (string, count, col)
|
|||
if (_rl_term_ei && *_rl_term_ei)
|
||||
tputs (_rl_term_ei, 1, _rl_output_character_function);
|
||||
}
|
||||
#endif /* __MSDOS__ || __MINGW32__ */
|
||||
}
|
||||
|
||||
/* Delete COUNT characters from the display line. */
|
||||
|
|
@ -2042,6 +2123,7 @@ delete_chars (count)
|
|||
if (count > _rl_screenwidth) /* XXX */
|
||||
return;
|
||||
|
||||
#if !defined (__MSDOS__) && !defined (__MINGW32__)
|
||||
if (_rl_term_DC && *_rl_term_DC)
|
||||
{
|
||||
char *buffer;
|
||||
|
|
@ -2054,6 +2136,7 @@ delete_chars (count)
|
|||
while (count--)
|
||||
tputs (_rl_term_dc, 1, _rl_output_character_function);
|
||||
}
|
||||
#endif /* !__MSDOS__ && !__MINGW32__ */
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -2109,18 +2192,10 @@ static void
|
|||
redraw_prompt (t)
|
||||
char *t;
|
||||
{
|
||||
char *oldp, *oldl, *oldlprefix;
|
||||
int oldlen, oldlast, oldplen, oldninvis, oldphyschars;
|
||||
char *oldp;
|
||||
|
||||
/* Geez, I should make this a struct. */
|
||||
oldp = rl_display_prompt;
|
||||
oldl = local_prompt;
|
||||
oldlprefix = local_prompt_prefix;
|
||||
oldlen = prompt_visible_length;
|
||||
oldplen = prompt_prefix_length;
|
||||
oldlast = prompt_last_invisible;
|
||||
oldninvis = prompt_invis_chars_first_line;
|
||||
oldphyschars = prompt_physical_chars;
|
||||
rl_save_prompt ();
|
||||
|
||||
rl_display_prompt = t;
|
||||
local_prompt = expand_prompt (t, &prompt_visible_length,
|
||||
|
|
@ -2128,16 +2203,11 @@ redraw_prompt (t)
|
|||
&prompt_invis_chars_first_line,
|
||||
&prompt_physical_chars);
|
||||
local_prompt_prefix = (char *)NULL;
|
||||
|
||||
rl_forced_update_display ();
|
||||
|
||||
rl_display_prompt = oldp;
|
||||
local_prompt = oldl;
|
||||
local_prompt_prefix = oldlprefix;
|
||||
prompt_visible_length = oldlen;
|
||||
prompt_prefix_length = oldplen;
|
||||
prompt_last_invisible = oldlast;
|
||||
prompt_invis_chars_first_line = oldninvis;
|
||||
prompt_physical_chars = oldphyschars;
|
||||
rl_restore_prompt();
|
||||
}
|
||||
|
||||
/* Redisplay the current line after a SIGWINCH is received. */
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
@ifinfo
|
||||
This document describes the GNU Readline Library, a utility for aiding
|
||||
in the consitency of user interface across discrete programs that need
|
||||
in the consistency of user interface across discrete programs that need
|
||||
to provide a command line interface.
|
||||
|
||||
Copyright (C) 1988-2004 Free Software Foundation, Inc.
|
||||
Copyright (C) 1988-2005 Free Software Foundation, Inc.
|
||||
|
||||
Permission is granted to make and distribute verbatim copies of
|
||||
this manual provided the copyright notice and this permission notice
|
||||
|
|
@ -284,6 +284,8 @@ negative argument.
|
|||
|
||||
A command function should return 0 if its action completes successfully,
|
||||
and a non-zero value if some error occurs.
|
||||
This is the convention obeyed by all of the builtin Readline bindable
|
||||
command functions.
|
||||
|
||||
@node Readline Variables
|
||||
@section Readline Variables
|
||||
|
|
@ -398,6 +400,12 @@ The stdio stream to which Readline performs output.
|
|||
If @code{NULL}, Readline defaults to @var{stdout}.
|
||||
@end deftypevar
|
||||
|
||||
@deftypevar int rl_prefer_env_winsize
|
||||
If non-zero, Readline gives values found in the @env{LINES} and
|
||||
@env{COLUMNS} environment variables greater precedence than values fetched
|
||||
from the kernel when computing the screen dimensions.
|
||||
@end deftypevar
|
||||
|
||||
@deftypevar {rl_command_func_t *} rl_last_func
|
||||
The address of the last command function Readline executed. May be used to
|
||||
test whether or not a function is being executed twice in succession, for
|
||||
|
|
@ -909,10 +917,14 @@ possibly containing conversion specifications such as @samp{%d}, and
|
|||
any additional arguments necessary to satisfy the conversion specifications.
|
||||
The resulting string is displayed in the @dfn{echo area}. The echo area
|
||||
is also used to display numeric arguments and search strings.
|
||||
You should call @code{rl_save_prompt} to save the prompt information
|
||||
before calling this function.
|
||||
@end deftypefun
|
||||
|
||||
@deftypefun int rl_clear_message (void)
|
||||
Clear the message in the echo area.
|
||||
Clear the message in the echo area. If the prompt was saved with a call to
|
||||
@code{rl_save_prompt} before the last call to @code{rl_message},
|
||||
call @code{rl_restore_prompt} before calling this function.
|
||||
@end deftypefun
|
||||
|
||||
@deftypefun void rl_save_prompt (void)
|
||||
|
|
@ -923,6 +935,9 @@ displaying a new message in the message area with @code{rl_message()}.
|
|||
@deftypefun void rl_restore_prompt (void)
|
||||
Restore the local Readline prompt display state saved by the most
|
||||
recent call to @code{rl_save_prompt}.
|
||||
if @code{rl_save_prompt} was called to save the prompt before a call
|
||||
to @code{rl_message}, this function should be called before the
|
||||
corresponding call to @code{rl_clear_message}.
|
||||
@end deftypefun
|
||||
|
||||
@deftypefun int rl_expand_prompt (char *prompt)
|
||||
|
|
@ -1149,6 +1164,11 @@ This behaves as if the readline command
|
|||
file (@pxref{Readline Init File Syntax}).
|
||||
@end deftypefun
|
||||
|
||||
@deftypefun {char *} rl_variable_value (const char *variable)
|
||||
Return a string representing the value of the Readline variable @var{variable}.
|
||||
For boolean variables, this string is either @samp{on} or @samp{off}.
|
||||
@end deftypefun
|
||||
|
||||
@deftypefun void rl_variable_dumper (int readable)
|
||||
Print the readline variable names and their current values
|
||||
to @code{rl_outstream}.
|
||||
|
|
@ -1378,7 +1398,8 @@ Update Readline's internal screen size by reading values from the kernel.
|
|||
|
||||
@deftypefun void rl_set_screen_size (int rows, int cols)
|
||||
Set Readline's idea of the terminal size to @var{rows} rows and
|
||||
@var{cols} columns.
|
||||
@var{cols} columns. If either @var{rows} or @var{columns} is less than
|
||||
or equal to 0, Readline's idea of that terminal dimension is unchanged.
|
||||
@end deftypefun
|
||||
|
||||
If an application does not want to install a @code{SIGWINCH} handler, but
|
||||
|
|
@ -1390,6 +1411,10 @@ Return Readline's idea of the terminal's size in the
|
|||
variables pointed to by the arguments.
|
||||
@end deftypefun
|
||||
|
||||
@deftypefun void rl_reset_screen_size (void)
|
||||
Cause Readline to reobtain the screen size and recalculate its dimensions.
|
||||
@end deftypefun
|
||||
|
||||
The following functions install and remove Readline's signal handlers.
|
||||
|
||||
@deftypefun int rl_set_signals (void)
|
||||
|
|
@ -1707,8 +1732,9 @@ shell variables and hostnames.
|
|||
|
||||
@deftypevar int rl_completion_query_items
|
||||
Up to this many items will be displayed in response to a
|
||||
possible-completions call. After that, we ask the user if she is sure
|
||||
she wants to see them all. The default value is 100.
|
||||
possible-completions call. After that, readline asks the user if she is sure
|
||||
she wants to see them all. The default value is 100. A negative value
|
||||
indicates that Readline should never ask the user.
|
||||
@end deftypevar
|
||||
|
||||
@deftypevar {int} rl_completion_append_character
|
||||
|
|
@ -2237,7 +2263,7 @@ too_dangerous (caller)
|
|||
char *caller;
|
||||
@{
|
||||
fprintf (stderr,
|
||||
"%s: Too dangerous for me to distribute.\n"
|
||||
"%s: Too dangerous for me to distribute.\n",
|
||||
caller);
|
||||
fprintf (stderr, "Write it yourself.\n");
|
||||
@}
|
||||
|
|
|
|||
|
|
@ -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-2004 Free Software Foundation, Inc.
|
||||
Copyright (C) 1988-2005 Free Software Foundation, Inc.
|
||||
|
||||
Authored by Brian Fox and Chet Ramey.
|
||||
|
||||
|
|
@ -383,7 +383,11 @@ set editing-mode vi
|
|||
@end example
|
||||
|
||||
Variable names and values, where appropriate, are recognized without regard
|
||||
to case.
|
||||
to case. Unrecognized variable names are ignored.
|
||||
|
||||
Boolean variables (those that can be set to on or off) are set to on if
|
||||
the value is null or empty, @var{on} (case-insensitive), or 1. Any other
|
||||
value results in the variable being set to off.
|
||||
|
||||
@ifset BashFeatures
|
||||
The @w{@code{bind -V}} command lists the current Readline variable names
|
||||
|
|
@ -404,6 +408,12 @@ If set to @samp{none}, Readline never rings the bell. If set to
|
|||
If set to @samp{audible} (the default), Readline attempts to ring
|
||||
the terminal's bell.
|
||||
|
||||
@item bind-tty-special-chars
|
||||
@vindex bind-tty-special-chars
|
||||
If set to @samp{on}, Readline attempts to bind the control characters
|
||||
treated specially by the kernel's terminal driver to their Readline
|
||||
equivalents.
|
||||
|
||||
@item comment-begin
|
||||
@vindex comment-begin
|
||||
The string to insert at the beginning of the line when the
|
||||
|
|
@ -423,6 +433,7 @@ 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.
|
||||
This variable must be set to an integer value greater than or equal to 0.
|
||||
A negative value means Readline should never ask.
|
||||
The default limit is @code{100}.
|
||||
|
||||
@item convert-meta
|
||||
|
|
@ -456,10 +467,11 @@ arrow keys. The default is @samp{off}.
|
|||
If set to @samp{on}, tilde expansion is performed when Readline
|
||||
attempts word completion. The default is @samp{off}.
|
||||
|
||||
@item history-preserve-point
|
||||
@vindex history-preserve-point
|
||||
If set to @samp{on}, the history code attempts to place point at the
|
||||
same location on each history line retrieved with @code{previous-history}
|
||||
or @code{next-history}.
|
||||
or @code{next-history}. The default is @samp{off}.
|
||||
|
||||
@item horizontal-scroll-mode
|
||||
@vindex horizontal-scroll-mode
|
||||
|
|
@ -1012,6 +1024,8 @@ 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.
|
||||
Once the argument @var{n} is computed, the argument is extracted
|
||||
as if the @samp{!@var{n}} history expansion had been specified.
|
||||
|
||||
@item yank-last-arg (M-. or M-_)
|
||||
Insert last argument to the previous command (the last word of the
|
||||
|
|
@ -1019,6 +1033,8 @@ previous history entry). With an
|
|||
argument, behave exactly like @code{yank-nth-arg}.
|
||||
Successive calls to @code{yank-last-arg} move back through the history
|
||||
list, inserting the last argument of each line in turn.
|
||||
The history expansion facilities are used to extract the last argument,
|
||||
as if the @samp{!$} history expansion had been specified.
|
||||
|
||||
@end ftable
|
||||
|
||||
|
|
@ -1530,7 +1546,7 @@ special variable as delimiters.
|
|||
Shell quoting is honored.
|
||||
Each word is then expanded using
|
||||
brace expansion, tilde expansion, parameter and variable expansion,
|
||||
command substitution, arithmetic expansion, and pathname expansion,
|
||||
command substitution, and arithmetic expansion,
|
||||
as described above (@pxref{Shell Expansions}).
|
||||
The results are split using the rules described above
|
||||
(@pxref{Word Splitting}).
|
||||
|
|
@ -1693,6 +1709,12 @@ shell functions specified with @option{-F}.
|
|||
@item nospace
|
||||
Tell Readline not to append a space (the default) to words completed at
|
||||
the end of the line.
|
||||
|
||||
@item plusdirs
|
||||
After any matches defined by the compspec are generated,
|
||||
directory name completion is attempted and any
|
||||
matches are added to the results of the other actions.
|
||||
|
||||
@end table
|
||||
|
||||
@item -A @var{action}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ This manual describes the end user interface of the GNU Readline Library
|
|||
consistency of user interface across discrete programs which provide
|
||||
a command line interface.
|
||||
|
||||
Copyright @copyright{} 1988-2004 Free Software Foundation, Inc.
|
||||
Copyright @copyright{} 1988-2005 Free Software Foundation, Inc.
|
||||
|
||||
Permission is granted to make and distribute verbatim copies of
|
||||
this manual provided the copyright notice and this permission notice
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
@ignore
|
||||
Copyright (C) 1988-2004 Free Software Foundation, Inc.
|
||||
Copyright (C) 1988-2005 Free Software Foundation, Inc.
|
||||
@end ignore
|
||||
|
||||
@set EDITION 5.0
|
||||
@set VERSION 5.0
|
||||
@set UPDATED 28 January 2004
|
||||
@set UPDATED-MONTH January 2004
|
||||
@set EDITION 5.1-beta1
|
||||
@set VERSION 5.1-beta1
|
||||
@set UPDATED 11 November 2005
|
||||
@set UPDATED-MONTH November 2005
|
||||
|
||||
@set LASTCHANGE Wed Jan 28 15:46:54 EST 2004
|
||||
@set LASTCHANGE Fri Nov 11 19:50:51 EST 2005
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@
|
|||
# include <readline/history.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
|
|
|
|||
|
|
@ -31,12 +31,19 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "posixstat.h"
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
extern void exit();
|
||||
#endif
|
||||
|
||||
#if defined (READLINE_LIBRARY)
|
||||
# include "posixstat.h"
|
||||
# include "readline.h"
|
||||
# include "history.h"
|
||||
#else
|
||||
# include <sys/stat.h>
|
||||
# include <readline/readline.h>
|
||||
# include <readline/history.h>
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -40,6 +40,12 @@
|
|||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
extern void exit();
|
||||
#endif
|
||||
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -31,6 +31,12 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
extern void exit();
|
||||
#endif
|
||||
|
||||
#ifdef READLINE_LIBRARY
|
||||
# include "readline.h"
|
||||
# include "history.h"
|
||||
|
|
|
|||
|
|
@ -176,6 +176,7 @@ static FUNMAP default_funmap[] = {
|
|||
{ "vi-put", rl_vi_put },
|
||||
{ "vi-redo", rl_vi_redo },
|
||||
{ "vi-replace", rl_vi_replace },
|
||||
{ "vi-rubout", rl_vi_rubout },
|
||||
{ "vi-search", rl_vi_search },
|
||||
{ "vi-search-again", rl_vi_search_again },
|
||||
{ "vi-set-mark", rl_vi_set_mark },
|
||||
|
|
|
|||
|
|
@ -206,23 +206,24 @@ get_history_event (string, caller_index, delimiting_quote)
|
|||
|
||||
/* Only a closing `?' or a newline delimit a substring search string. */
|
||||
for (local_index = i; c = string[i]; i++)
|
||||
{
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
int v;
|
||||
mbstate_t ps;
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
int v;
|
||||
mbstate_t ps;
|
||||
|
||||
memset (&ps, 0, sizeof (mbstate_t));
|
||||
/* These produce warnings because we're passing a const string to a
|
||||
function that takes a non-const string. */
|
||||
_rl_adjust_point ((char *)string, i, &ps);
|
||||
if ((v = _rl_get_char_len ((char *)string + i, &ps)) > 1)
|
||||
{
|
||||
i += v - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
memset (&ps, 0, sizeof (mbstate_t));
|
||||
/* These produce warnings because we're passing a const string to a
|
||||
function that takes a non-const string. */
|
||||
_rl_adjust_point ((char *)string, i, &ps);
|
||||
if ((v = _rl_get_char_len ((char *)string + i, &ps)) > 1)
|
||||
{
|
||||
i += v - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* HANDLE_MULTIBYTE */
|
||||
if ((!substring_okay && (whitespace (c) || c == ':' ||
|
||||
(history_search_delimiter_chars && member (c, history_search_delimiter_chars)) ||
|
||||
|
|
@ -230,6 +231,7 @@ get_history_event (string, caller_index, delimiting_quote)
|
|||
string[i] == '\n' ||
|
||||
(substring_okay && string[i] == '?'))
|
||||
break;
|
||||
}
|
||||
|
||||
which = i - local_index;
|
||||
temp = (char *)xmalloc (1 + which);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* history.c -- standalone history library */
|
||||
|
||||
/* Copyright (C) 1989-2003 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1989-2005 Free Software Foundation, Inc.
|
||||
|
||||
This file contains the GNU History Library (the Library), a set of
|
||||
routines for managing the text of previously typed lines.
|
||||
|
|
@ -204,7 +204,7 @@ history_get (offset)
|
|||
int local_index;
|
||||
|
||||
local_index = offset - history_base;
|
||||
return (local_index >= history_length || local_index < 0 || !the_history)
|
||||
return (local_index >= history_length || local_index < 0 || the_history == 0)
|
||||
? (HIST_ENTRY *)NULL
|
||||
: the_history[local_index];
|
||||
}
|
||||
|
|
@ -340,7 +340,7 @@ replace_history_entry (which, line, data)
|
|||
{
|
||||
HIST_ENTRY *temp, *old_value;
|
||||
|
||||
if (which >= history_length)
|
||||
if (which < 0 || which >= history_length)
|
||||
return ((HIST_ENTRY *)NULL);
|
||||
|
||||
temp = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY));
|
||||
|
|
@ -364,17 +364,15 @@ remove_history (which)
|
|||
HIST_ENTRY *return_value;
|
||||
register int i;
|
||||
|
||||
if (which >= history_length || !history_length)
|
||||
return_value = (HIST_ENTRY *)NULL;
|
||||
else
|
||||
{
|
||||
return_value = the_history[which];
|
||||
if (which < 0 || which >= history_length || history_length == 0 || the_history == 0)
|
||||
return ((HIST_ENTRY *)NULL);
|
||||
|
||||
for (i = which; i < history_length; i++)
|
||||
the_history[i] = the_history[i + 1];
|
||||
return_value = the_history[which];
|
||||
|
||||
history_length--;
|
||||
}
|
||||
for (i = which; i < history_length; i++)
|
||||
the_history[i] = the_history[i + 1];
|
||||
|
||||
history_length--;
|
||||
|
||||
return (return_value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* input.c -- character input functions for readline. */
|
||||
|
||||
/* Copyright (C) 1994 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1994-2005 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.
|
||||
|
|
@ -444,6 +444,10 @@ rl_getc (stream)
|
|||
|
||||
while (1)
|
||||
{
|
||||
#if defined (__MINGW32__)
|
||||
if (isatty (fileno (stream)))
|
||||
return (getch ());
|
||||
#endif
|
||||
result = read (fileno (stream), &c, sizeof (unsigned char));
|
||||
|
||||
if (result == sizeof (unsigned char))
|
||||
|
|
@ -519,6 +523,12 @@ _rl_read_mbchar (mbchar, size)
|
|||
ps = ps_back;
|
||||
continue;
|
||||
}
|
||||
else if (mbchar_bytes_length == 0)
|
||||
{
|
||||
mbchar[0] = '\0'; /* null wide character */
|
||||
mb_len = 1;
|
||||
break;
|
||||
}
|
||||
else if (mbchar_bytes_length > (size_t)(0))
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
|
||||
|
||||
This file contains the Readline Library (the Library), a set of
|
||||
routines for providing Emacs style line input to programs that ask
|
||||
|
|
@ -56,12 +56,17 @@
|
|||
/* Variables exported to other files in the readline library. */
|
||||
char *_rl_isearch_terminators = (char *)NULL;
|
||||
|
||||
_rl_search_cxt *_rl_iscxt = 0;
|
||||
|
||||
/* Variables imported from other files in the readline library. */
|
||||
extern HIST_ENTRY *_rl_saved_line_for_history;
|
||||
|
||||
/* Forward declarations */
|
||||
static int rl_search_history PARAMS((int, int));
|
||||
|
||||
static _rl_search_cxt *_rl_isearch_init PARAMS((int));
|
||||
static void _rl_isearch_fini PARAMS((_rl_search_cxt *));
|
||||
static int _rl_isearch_cleanup PARAMS((_rl_search_cxt *, int));
|
||||
|
||||
/* Last line found by the current incremental search, so we don't `find'
|
||||
identical lines many times in a row. */
|
||||
static char *prev_line_found;
|
||||
|
|
@ -72,6 +77,57 @@ static int last_isearch_string_len;
|
|||
|
||||
static char *default_isearch_terminators = "\033\012";
|
||||
|
||||
_rl_search_cxt *
|
||||
_rl_scxt_alloc (type, flags)
|
||||
int type, flags;
|
||||
{
|
||||
_rl_search_cxt *cxt;
|
||||
|
||||
cxt = (_rl_search_cxt *)xmalloc (sizeof (_rl_search_cxt));
|
||||
|
||||
cxt->type = type;
|
||||
cxt->sflags = flags;
|
||||
|
||||
cxt->search_string = 0;
|
||||
cxt->search_string_size = cxt->search_string_index = 0;
|
||||
|
||||
cxt->lines = 0;
|
||||
cxt->allocated_line = 0;
|
||||
cxt->hlen = cxt->hindex = 0;
|
||||
|
||||
cxt->save_point = rl_point;
|
||||
cxt->save_mark = rl_mark;
|
||||
cxt->save_line = where_history ();
|
||||
cxt->last_found_line = cxt->save_line;
|
||||
cxt->prev_line_found = 0;
|
||||
|
||||
cxt->save_undo_list = 0;
|
||||
|
||||
cxt->history_pos = 0;
|
||||
cxt->direction = 0;
|
||||
|
||||
cxt->lastc = 0;
|
||||
|
||||
cxt->sline = 0;
|
||||
cxt->sline_len = cxt->sline_index = 0;
|
||||
|
||||
cxt->search_terminators = 0;
|
||||
|
||||
return cxt;
|
||||
}
|
||||
|
||||
void
|
||||
_rl_scxt_dispose (cxt, flags)
|
||||
_rl_search_cxt *cxt;
|
||||
int flags;
|
||||
{
|
||||
FREE (cxt->search_string);
|
||||
FREE (cxt->allocated_line);
|
||||
FREE (cxt->lines);
|
||||
|
||||
free (cxt);
|
||||
}
|
||||
|
||||
/* Search backwards through the history looking for a string which is typed
|
||||
interactively. Start with the current line. */
|
||||
int
|
||||
|
|
@ -92,7 +148,7 @@ rl_forward_search_history (sign, key)
|
|||
|
||||
/* Display the current state of the search in the echo-area.
|
||||
SEARCH_STRING contains the string that is being searched for,
|
||||
DIRECTION is zero for forward, or 1 for reverse,
|
||||
DIRECTION is zero for forward, or non-zero for reverse,
|
||||
WHERE is the history list number of the current line. If it is
|
||||
-1, then this line is the starting one. */
|
||||
static void
|
||||
|
|
@ -140,6 +196,418 @@ rl_display_search (search_string, reverse_p, where)
|
|||
(*rl_redisplay_function) ();
|
||||
}
|
||||
|
||||
static _rl_search_cxt *
|
||||
_rl_isearch_init (direction)
|
||||
int direction;
|
||||
{
|
||||
_rl_search_cxt *cxt;
|
||||
register int i;
|
||||
HIST_ENTRY **hlist;
|
||||
|
||||
cxt = _rl_scxt_alloc (RL_SEARCH_ISEARCH, 0);
|
||||
if (direction < 0)
|
||||
cxt->sflags |= SF_REVERSE;
|
||||
|
||||
cxt->search_terminators = _rl_isearch_terminators ? _rl_isearch_terminators
|
||||
: default_isearch_terminators;
|
||||
|
||||
/* Create an arrary of pointers to the lines that we want to search. */
|
||||
hlist = history_list ();
|
||||
rl_maybe_replace_line ();
|
||||
i = 0;
|
||||
if (hlist)
|
||||
for (i = 0; hlist[i]; i++);
|
||||
|
||||
/* Allocate space for this many lines, +1 for the current input line,
|
||||
and remember those lines. */
|
||||
cxt->lines = (char **)xmalloc ((1 + (cxt->hlen = i)) * sizeof (char *));
|
||||
for (i = 0; i < cxt->hlen; i++)
|
||||
cxt->lines[i] = hlist[i]->line;
|
||||
|
||||
if (_rl_saved_line_for_history)
|
||||
cxt->lines[i] = _rl_saved_line_for_history->line;
|
||||
else
|
||||
{
|
||||
/* Keep track of this so we can free it. */
|
||||
cxt->allocated_line = (char *)xmalloc (1 + strlen (rl_line_buffer));
|
||||
strcpy (cxt->allocated_line, &rl_line_buffer[0]);
|
||||
cxt->lines[i] = cxt->allocated_line;
|
||||
}
|
||||
|
||||
cxt->hlen++;
|
||||
|
||||
/* The line where we start the search. */
|
||||
cxt->history_pos = cxt->save_line;
|
||||
|
||||
rl_save_prompt ();
|
||||
|
||||
/* Initialize search parameters. */
|
||||
cxt->search_string = (char *)xmalloc (cxt->search_string_size = 128);
|
||||
cxt->search_string[cxt->search_string_index = 0] = '\0';
|
||||
|
||||
/* Normalize DIRECTION into 1 or -1. */
|
||||
cxt->direction = (direction >= 0) ? 1 : -1;
|
||||
|
||||
cxt->sline = rl_line_buffer;
|
||||
cxt->sline_len = strlen (cxt->sline);
|
||||
cxt->sline_index = rl_point;
|
||||
|
||||
_rl_iscxt = cxt; /* save globally */
|
||||
|
||||
return cxt;
|
||||
}
|
||||
|
||||
static void
|
||||
_rl_isearch_fini (cxt)
|
||||
_rl_search_cxt *cxt;
|
||||
{
|
||||
/* First put back the original state. */
|
||||
strcpy (rl_line_buffer, cxt->lines[cxt->save_line]);
|
||||
|
||||
rl_restore_prompt ();
|
||||
|
||||
/* Save the search string for possible later use. */
|
||||
FREE (last_isearch_string);
|
||||
last_isearch_string = cxt->search_string;
|
||||
last_isearch_string_len = cxt->search_string_index;
|
||||
cxt->search_string = 0;
|
||||
|
||||
if (cxt->last_found_line < cxt->save_line)
|
||||
rl_get_previous_history (cxt->save_line - cxt->last_found_line, 0);
|
||||
else
|
||||
rl_get_next_history (cxt->last_found_line - cxt->save_line, 0);
|
||||
|
||||
/* If the string was not found, put point at the end of the last matching
|
||||
line. If last_found_line == orig_line, we didn't find any matching
|
||||
history lines at all, so put point back in its original position. */
|
||||
if (cxt->sline_index < 0)
|
||||
{
|
||||
if (cxt->last_found_line == cxt->save_line)
|
||||
cxt->sline_index = cxt->save_point;
|
||||
else
|
||||
cxt->sline_index = strlen (rl_line_buffer);
|
||||
rl_mark = cxt->save_mark;
|
||||
}
|
||||
|
||||
rl_point = cxt->sline_index;
|
||||
/* Don't worry about where to put the mark here; rl_get_previous_history
|
||||
and rl_get_next_history take care of it. */
|
||||
|
||||
rl_clear_message ();
|
||||
}
|
||||
|
||||
int
|
||||
_rl_search_getchar (cxt)
|
||||
_rl_search_cxt *cxt;
|
||||
{
|
||||
int c;
|
||||
|
||||
/* Read a key and decide how to proceed. */
|
||||
RL_SETSTATE(RL_STATE_MOREINPUT);
|
||||
c = cxt->lastc = rl_read_key ();
|
||||
RL_UNSETSTATE(RL_STATE_MOREINPUT);
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
c = cxt->lastc = _rl_read_mbstring (cxt->lastc, cxt->mb, MB_LEN_MAX);
|
||||
#endif
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/* Process just-read character C according to isearch context CXT. Return
|
||||
-1 if the caller should just free the context and return, 0 if we should
|
||||
break out of the loop, and 1 if we should continue to read characters. */
|
||||
int
|
||||
_rl_isearch_dispatch (cxt, c)
|
||||
_rl_search_cxt *cxt;
|
||||
int c;
|
||||
{
|
||||
int n, wstart, wlen, limit, cval;
|
||||
rl_command_func_t *f;
|
||||
|
||||
f = (rl_command_func_t *)NULL;
|
||||
|
||||
/* Translate the keys we do something with to opcodes. */
|
||||
if (c >= 0 && _rl_keymap[c].type == ISFUNC)
|
||||
{
|
||||
f = _rl_keymap[c].function;
|
||||
|
||||
if (f == rl_reverse_search_history)
|
||||
cxt->lastc = (cxt->sflags & SF_REVERSE) ? -1 : -2;
|
||||
else if (f == rl_forward_search_history)
|
||||
cxt->lastc = (cxt->sflags & SF_REVERSE) ? -2 : -1;
|
||||
else if (f == rl_rubout)
|
||||
cxt->lastc = -3;
|
||||
else if (c == CTRL ('G'))
|
||||
cxt->lastc = -4;
|
||||
else if (c == CTRL ('W')) /* XXX */
|
||||
cxt->lastc = -5;
|
||||
else if (c == CTRL ('Y')) /* XXX */
|
||||
cxt->lastc = -6;
|
||||
}
|
||||
|
||||
/* The characters in isearch_terminators (set from the user-settable
|
||||
variable isearch-terminators) are used to terminate the search but
|
||||
not subsequently execute the character as a command. The default
|
||||
value is "\033\012" (ESC and C-J). */
|
||||
if (strchr (cxt->search_terminators, cxt->lastc))
|
||||
{
|
||||
/* ESC still terminates the search, but if there is pending
|
||||
input or if input arrives within 0.1 seconds (on systems
|
||||
with select(2)) it is used as a prefix character
|
||||
with rl_execute_next. WATCH OUT FOR THIS! This is intended
|
||||
to allow the arrow keys to be used like ^F and ^B are used
|
||||
to terminate the search and execute the movement command.
|
||||
XXX - since _rl_input_available depends on the application-
|
||||
settable keyboard timeout value, this could alternatively
|
||||
use _rl_input_queued(100000) */
|
||||
if (cxt->lastc == ESC && _rl_input_available ())
|
||||
rl_execute_next (ESC);
|
||||
return (0);
|
||||
}
|
||||
|
||||
#define ENDSRCH_CHAR(c) \
|
||||
((CTRL_CHAR (c) || META_CHAR (c) || (c) == RUBOUT) && ((c) != CTRL ('G')))
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
if (cxt->lastc >= 0 && (cxt->mb[0] && cxt->mb[1] == '\0') && ENDSRCH_CHAR (cxt->lastc))
|
||||
{
|
||||
/* This sets rl_pending_input to c; it will be picked up the next
|
||||
time rl_read_key is called. */
|
||||
rl_execute_next (cxt->lastc);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (cxt->lastc >= 0 && ENDSRCH_CHAR (cxt->lastc))
|
||||
{
|
||||
/* This sets rl_pending_input to LASTC; it will be picked up the next
|
||||
time rl_read_key is called. */
|
||||
rl_execute_next (cxt->lastc);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Now dispatch on the character. `Opcodes' affect the search string or
|
||||
state. Other characters are added to the string. */
|
||||
switch (cxt->lastc)
|
||||
{
|
||||
/* search again */
|
||||
case -1:
|
||||
if (cxt->search_string_index == 0)
|
||||
{
|
||||
if (last_isearch_string)
|
||||
{
|
||||
cxt->search_string_size = 64 + last_isearch_string_len;
|
||||
cxt->search_string = (char *)xrealloc (cxt->search_string, cxt->search_string_size);
|
||||
strcpy (cxt->search_string, last_isearch_string);
|
||||
cxt->search_string_index = last_isearch_string_len;
|
||||
rl_display_search (cxt->search_string, (cxt->sflags & SF_REVERSE), -1);
|
||||
break;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
else if (cxt->sflags & SF_REVERSE)
|
||||
cxt->sline_index--;
|
||||
else if (cxt->sline_index != cxt->sline_len)
|
||||
cxt->sline_index++;
|
||||
else
|
||||
rl_ding ();
|
||||
break;
|
||||
|
||||
/* switch directions */
|
||||
case -2:
|
||||
cxt->direction = -cxt->direction;
|
||||
if (cxt->direction < 0)
|
||||
cxt->sflags |= SF_REVERSE;
|
||||
else
|
||||
cxt->sflags &= ~SF_REVERSE;
|
||||
break;
|
||||
|
||||
/* delete character from search string. */
|
||||
case -3: /* C-H, DEL */
|
||||
/* This is tricky. To do this right, we need to keep a
|
||||
stack of search positions for the current search, with
|
||||
sentinels marking the beginning and end. But this will
|
||||
do until we have a real isearch-undo. */
|
||||
if (cxt->search_string_index == 0)
|
||||
rl_ding ();
|
||||
else
|
||||
cxt->search_string[--cxt->search_string_index] = '\0';
|
||||
break;
|
||||
|
||||
case -4: /* C-G, abort */
|
||||
rl_replace_line (cxt->lines[cxt->save_line], 0);
|
||||
rl_point = cxt->save_point;
|
||||
rl_mark = cxt->save_mark;
|
||||
rl_restore_prompt();
|
||||
rl_clear_message ();
|
||||
|
||||
return -1;
|
||||
|
||||
case -5: /* C-W */
|
||||
/* skip over portion of line we already matched and yank word */
|
||||
wstart = rl_point + cxt->search_string_index;
|
||||
if (wstart >= rl_end)
|
||||
{
|
||||
rl_ding ();
|
||||
break;
|
||||
}
|
||||
|
||||
/* if not in a word, move to one. */
|
||||
cval = _rl_char_value (rl_line_buffer, wstart);
|
||||
if (_rl_walphabetic (cval) == 0)
|
||||
{
|
||||
rl_ding ();
|
||||
break;
|
||||
}
|
||||
n = MB_NEXTCHAR (rl_line_buffer, wstart, 1, MB_FIND_NONZERO);;
|
||||
while (n < rl_end)
|
||||
{
|
||||
cval = _rl_char_value (rl_line_buffer, n);
|
||||
if (_rl_walphabetic (cval) == 0)
|
||||
break;
|
||||
n = MB_NEXTCHAR (rl_line_buffer, n, 1, MB_FIND_NONZERO);;
|
||||
}
|
||||
wlen = n - wstart + 1;
|
||||
if (cxt->search_string_index + wlen + 1 >= cxt->search_string_size)
|
||||
{
|
||||
cxt->search_string_size += wlen + 1;
|
||||
cxt->search_string = (char *)xrealloc (cxt->search_string, cxt->search_string_size);
|
||||
}
|
||||
for (; wstart < n; wstart++)
|
||||
cxt->search_string[cxt->search_string_index++] = rl_line_buffer[wstart];
|
||||
cxt->search_string[cxt->search_string_index] = '\0';
|
||||
break;
|
||||
|
||||
case -6: /* C-Y */
|
||||
/* skip over portion of line we already matched and yank rest */
|
||||
wstart = rl_point + cxt->search_string_index;
|
||||
if (wstart >= rl_end)
|
||||
{
|
||||
rl_ding ();
|
||||
break;
|
||||
}
|
||||
n = rl_end - wstart + 1;
|
||||
if (cxt->search_string_index + n + 1 >= cxt->search_string_size)
|
||||
{
|
||||
cxt->search_string_size += n + 1;
|
||||
cxt->search_string = (char *)xrealloc (cxt->search_string, cxt->search_string_size);
|
||||
}
|
||||
for (n = wstart; n < rl_end; n++)
|
||||
cxt->search_string[cxt->search_string_index++] = rl_line_buffer[n];
|
||||
cxt->search_string[cxt->search_string_index] = '\0';
|
||||
break;
|
||||
|
||||
/* Add character to search string and continue search. */
|
||||
default:
|
||||
if (cxt->search_string_index + 2 >= cxt->search_string_size)
|
||||
{
|
||||
cxt->search_string_size += 128;
|
||||
cxt->search_string = (char *)xrealloc (cxt->search_string, cxt->search_string_size);
|
||||
}
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
int j, l;
|
||||
for (j = 0, l = strlen (cxt->mb); j < l; )
|
||||
cxt->search_string[cxt->search_string_index++] = cxt->mb[j++];
|
||||
}
|
||||
else
|
||||
#endif
|
||||
cxt->search_string[cxt->search_string_index++] = c;
|
||||
cxt->search_string[cxt->search_string_index] = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
for (cxt->sflags &= ~(SF_FOUND|SF_FAILED);; )
|
||||
{
|
||||
limit = cxt->sline_len - cxt->search_string_index + 1;
|
||||
|
||||
/* Search the current line. */
|
||||
while ((cxt->sflags & SF_REVERSE) ? (cxt->sline_index >= 0) : (cxt->sline_index < limit))
|
||||
{
|
||||
if (STREQN (cxt->search_string, cxt->sline + cxt->sline_index, cxt->search_string_index))
|
||||
{
|
||||
cxt->sflags |= SF_FOUND;
|
||||
break;
|
||||
}
|
||||
else
|
||||
cxt->sline_index += cxt->direction;
|
||||
}
|
||||
if (cxt->sflags & SF_FOUND)
|
||||
break;
|
||||
|
||||
/* Move to the next line, but skip new copies of the line
|
||||
we just found and lines shorter than the string we're
|
||||
searching for. */
|
||||
do
|
||||
{
|
||||
/* Move to the next line. */
|
||||
cxt->history_pos += cxt->direction;
|
||||
|
||||
/* At limit for direction? */
|
||||
if ((cxt->sflags & SF_REVERSE) ? (cxt->history_pos < 0) : (cxt->history_pos == cxt->hlen))
|
||||
{
|
||||
cxt->sflags |= SF_FAILED;
|
||||
break;
|
||||
}
|
||||
|
||||
/* We will need these later. */
|
||||
cxt->sline = cxt->lines[cxt->history_pos];
|
||||
cxt->sline_len = strlen (cxt->sline);
|
||||
}
|
||||
while ((cxt->prev_line_found && STREQ (cxt->prev_line_found, cxt->lines[cxt->history_pos])) ||
|
||||
(cxt->search_string_index > cxt->sline_len));
|
||||
|
||||
if (cxt->sflags & SF_FAILED)
|
||||
break;
|
||||
|
||||
/* Now set up the line for searching... */
|
||||
cxt->sline_index = (cxt->sflags & SF_REVERSE) ? cxt->sline_len - cxt->search_string_index : 0;
|
||||
}
|
||||
|
||||
if (cxt->sflags & SF_FAILED)
|
||||
{
|
||||
/* We cannot find the search string. Ding the bell. */
|
||||
rl_ding ();
|
||||
cxt->history_pos = cxt->last_found_line;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* We have found the search string. Just display it. But don't
|
||||
actually move there in the history list until the user accepts
|
||||
the location. */
|
||||
if (cxt->sflags & SF_FOUND)
|
||||
{
|
||||
cxt->prev_line_found = cxt->lines[cxt->history_pos];
|
||||
rl_replace_line (cxt->lines[cxt->history_pos], 0);
|
||||
rl_point = cxt->sline_index;
|
||||
cxt->last_found_line = cxt->history_pos;
|
||||
rl_display_search (cxt->search_string, (cxt->sflags & SF_REVERSE), (cxt->history_pos == cxt->save_line) ? -1 : cxt->history_pos);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
_rl_isearch_cleanup (cxt, r)
|
||||
_rl_search_cxt *cxt;
|
||||
int r;
|
||||
{
|
||||
if (r >= 0)
|
||||
_rl_isearch_fini (cxt);
|
||||
_rl_scxt_dispose (cxt, 0);
|
||||
_rl_iscxt = 0;
|
||||
|
||||
RL_UNSETSTATE(RL_STATE_ISEARCH);
|
||||
|
||||
return (r != 0);
|
||||
}
|
||||
|
||||
/* Search through the history looking for an interactively typed string.
|
||||
This is analogous to i-search. We start the search in the current line.
|
||||
DIRECTION is which direction to search; >= 0 means forward, < 0 means
|
||||
|
|
@ -148,413 +616,51 @@ static int
|
|||
rl_search_history (direction, invoking_key)
|
||||
int direction, invoking_key;
|
||||
{
|
||||
/* The string that the user types in to search for. */
|
||||
char *search_string;
|
||||
|
||||
/* The current length of SEARCH_STRING. */
|
||||
int search_string_index;
|
||||
|
||||
/* The amount of space that SEARCH_STRING has allocated to it. */
|
||||
int search_string_size;
|
||||
|
||||
/* The list of lines to search through. */
|
||||
char **lines, *allocated_line;
|
||||
|
||||
/* The length of LINES. */
|
||||
int hlen;
|
||||
|
||||
/* Where we get LINES from. */
|
||||
HIST_ENTRY **hlist;
|
||||
|
||||
register int i;
|
||||
int orig_point, orig_mark, orig_line, last_found_line;
|
||||
int c, found, failed, sline_len;
|
||||
int n, wstart, wlen;
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
char mb[MB_LEN_MAX];
|
||||
#endif
|
||||
|
||||
/* The line currently being searched. */
|
||||
char *sline;
|
||||
|
||||
/* Offset in that line. */
|
||||
int line_index;
|
||||
|
||||
/* Non-zero if we are doing a reverse search. */
|
||||
int reverse;
|
||||
|
||||
/* The list of characters which terminate the search, but are not
|
||||
subsequently executed. If the variable isearch-terminators has
|
||||
been set, we use that value, otherwise we use ESC and C-J. */
|
||||
char *isearch_terminators;
|
||||
_rl_search_cxt *cxt; /* local for now, but saved globally */
|
||||
int c, r;
|
||||
|
||||
RL_SETSTATE(RL_STATE_ISEARCH);
|
||||
orig_point = rl_point;
|
||||
orig_mark = rl_mark;
|
||||
last_found_line = orig_line = where_history ();
|
||||
reverse = direction < 0;
|
||||
hlist = history_list ();
|
||||
allocated_line = (char *)NULL;
|
||||
cxt = _rl_isearch_init (direction);
|
||||
|
||||
isearch_terminators = _rl_isearch_terminators ? _rl_isearch_terminators
|
||||
: default_isearch_terminators;
|
||||
rl_display_search (cxt->search_string, (cxt->sflags & SF_REVERSE), -1);
|
||||
|
||||
/* Create an arrary of pointers to the lines that we want to search. */
|
||||
rl_maybe_replace_line ();
|
||||
i = 0;
|
||||
if (hlist)
|
||||
for (i = 0; hlist[i]; i++);
|
||||
/* If we are using the callback interface, all we do is set up here and
|
||||
return. The key is that we leave RL_STATE_ISEARCH set. */
|
||||
if (RL_ISSTATE (RL_STATE_CALLBACK))
|
||||
return (0);
|
||||
|
||||
/* Allocate space for this many lines, +1 for the current input line,
|
||||
and remember those lines. */
|
||||
lines = (char **)xmalloc ((1 + (hlen = i)) * sizeof (char *));
|
||||
for (i = 0; i < hlen; i++)
|
||||
lines[i] = hlist[i]->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. */
|
||||
allocated_line = (char *)xmalloc (1 + strlen (rl_line_buffer));
|
||||
strcpy (allocated_line, &rl_line_buffer[0]);
|
||||
lines[i] = allocated_line;
|
||||
}
|
||||
|
||||
hlen++;
|
||||
|
||||
/* The line where we start the search. */
|
||||
i = orig_line;
|
||||
|
||||
rl_save_prompt ();
|
||||
|
||||
/* Initialize search parameters. */
|
||||
search_string = (char *)xmalloc (search_string_size = 128);
|
||||
*search_string = '\0';
|
||||
search_string_index = 0;
|
||||
prev_line_found = (char *)0; /* XXX */
|
||||
|
||||
/* Normalize DIRECTION into 1 or -1. */
|
||||
direction = (direction >= 0) ? 1 : -1;
|
||||
|
||||
rl_display_search (search_string, reverse, -1);
|
||||
|
||||
sline = rl_line_buffer;
|
||||
sline_len = strlen (sline);
|
||||
line_index = rl_point;
|
||||
|
||||
found = failed = 0;
|
||||
r = -1;
|
||||
for (;;)
|
||||
{
|
||||
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 defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
c = _rl_read_mbstring (c, mb, MB_LEN_MAX);
|
||||
#endif
|
||||
|
||||
/* Translate the keys we do something with to opcodes. */
|
||||
if (c >= 0 && _rl_keymap[c].type == ISFUNC)
|
||||
{
|
||||
f = _rl_keymap[c].function;
|
||||
|
||||
if (f == rl_reverse_search_history)
|
||||
c = reverse ? -1 : -2;
|
||||
else if (f == rl_forward_search_history)
|
||||
c = !reverse ? -1 : -2;
|
||||
else if (f == rl_rubout)
|
||||
c = -3;
|
||||
else if (c == CTRL ('G'))
|
||||
c = -4;
|
||||
else if (c == CTRL ('W')) /* XXX */
|
||||
c = -5;
|
||||
else if (c == CTRL ('Y')) /* XXX */
|
||||
c = -6;
|
||||
}
|
||||
|
||||
/* The characters in isearch_terminators (set from the user-settable
|
||||
variable isearch-terminators) are used to terminate the search but
|
||||
not subsequently execute the character as a command. The default
|
||||
value is "\033\012" (ESC and C-J). */
|
||||
if (strchr (isearch_terminators, c))
|
||||
{
|
||||
/* ESC still terminates the search, but if there is pending
|
||||
input or if input arrives within 0.1 seconds (on systems
|
||||
with select(2)) it is used as a prefix character
|
||||
with rl_execute_next. WATCH OUT FOR THIS! This is intended
|
||||
to allow the arrow keys to be used like ^F and ^B are used
|
||||
to terminate the search and execute the movement command.
|
||||
XXX - since _rl_input_available depends on the application-
|
||||
settable keyboard timeout value, this could alternatively
|
||||
use _rl_input_queued(100000) */
|
||||
if (c == ESC && _rl_input_available ())
|
||||
rl_execute_next (ESC);
|
||||
break;
|
||||
}
|
||||
|
||||
#define ENDSRCH_CHAR(c) \
|
||||
((CTRL_CHAR (c) || META_CHAR (c) || (c) == RUBOUT) && ((c) != CTRL ('G')))
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
if (c >= 0 && strlen (mb) == 1 && ENDSRCH_CHAR (c))
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (c >= 0 && ENDSRCH_CHAR (c))
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case -1:
|
||||
if (search_string_index == 0)
|
||||
{
|
||||
if (last_isearch_string)
|
||||
{
|
||||
search_string_size = 64 + last_isearch_string_len;
|
||||
search_string = (char *)xrealloc (search_string, search_string_size);
|
||||
strcpy (search_string, last_isearch_string);
|
||||
search_string_index = last_isearch_string_len;
|
||||
rl_display_search (search_string, reverse, -1);
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (reverse)
|
||||
--line_index;
|
||||
else if (line_index != sline_len)
|
||||
++line_index;
|
||||
else
|
||||
rl_ding ();
|
||||
break;
|
||||
|
||||
/* switch directions */
|
||||
case -2:
|
||||
direction = -direction;
|
||||
reverse = direction < 0;
|
||||
break;
|
||||
|
||||
/* delete character from search string. */
|
||||
case -3: /* C-H, DEL */
|
||||
/* This is tricky. To do this right, we need to keep a
|
||||
stack of search positions for the current search, with
|
||||
sentinels marking the beginning and end. But this will
|
||||
do until we have a real isearch-undo. */
|
||||
if (search_string_index == 0)
|
||||
rl_ding ();
|
||||
else
|
||||
search_string[--search_string_index] = '\0';
|
||||
|
||||
break;
|
||||
|
||||
case -4: /* C-G */
|
||||
rl_replace_line (lines[orig_line], 0);
|
||||
rl_point = orig_point;
|
||||
rl_mark = orig_mark;
|
||||
rl_restore_prompt();
|
||||
rl_clear_message ();
|
||||
if (allocated_line)
|
||||
free (allocated_line);
|
||||
free (lines);
|
||||
RL_UNSETSTATE(RL_STATE_ISEARCH);
|
||||
return 0;
|
||||
|
||||
case -5: /* C-W */
|
||||
/* skip over portion of line we already matched */
|
||||
wstart = rl_point + search_string_index;
|
||||
if (wstart >= rl_end)
|
||||
{
|
||||
rl_ding ();
|
||||
break;
|
||||
}
|
||||
|
||||
/* if not in a word, move to one. */
|
||||
if (rl_alphabetic(rl_line_buffer[wstart]) == 0)
|
||||
{
|
||||
rl_ding ();
|
||||
break;
|
||||
}
|
||||
n = wstart;
|
||||
while (n < rl_end && rl_alphabetic(rl_line_buffer[n]))
|
||||
n++;
|
||||
wlen = n - wstart + 1;
|
||||
if (search_string_index + wlen + 1 >= search_string_size)
|
||||
{
|
||||
search_string_size += wlen + 1;
|
||||
search_string = (char *)xrealloc (search_string, search_string_size);
|
||||
}
|
||||
for (; wstart < n; wstart++)
|
||||
search_string[search_string_index++] = rl_line_buffer[wstart];
|
||||
search_string[search_string_index] = '\0';
|
||||
break;
|
||||
|
||||
case -6: /* C-Y */
|
||||
/* skip over portion of line we already matched */
|
||||
wstart = rl_point + search_string_index;
|
||||
if (wstart >= rl_end)
|
||||
{
|
||||
rl_ding ();
|
||||
break;
|
||||
}
|
||||
n = rl_end - wstart + 1;
|
||||
if (search_string_index + n + 1 >= search_string_size)
|
||||
{
|
||||
search_string_size += n + 1;
|
||||
search_string = (char *)xrealloc (search_string, search_string_size);
|
||||
}
|
||||
for (n = wstart; n < rl_end; n++)
|
||||
search_string[search_string_index++] = rl_line_buffer[n];
|
||||
search_string[search_string_index] = '\0';
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Add character to search string and continue search. */
|
||||
if (search_string_index + 2 >= search_string_size)
|
||||
{
|
||||
search_string_size += 128;
|
||||
search_string = (char *)xrealloc (search_string, search_string_size);
|
||||
}
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
int j, l;
|
||||
for (j = 0, l = strlen (mb); j < l; )
|
||||
search_string[search_string_index++] = mb[j++];
|
||||
}
|
||||
else
|
||||
#endif
|
||||
search_string[search_string_index++] = c;
|
||||
search_string[search_string_index] = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
for (found = failed = 0;;)
|
||||
{
|
||||
int limit = sline_len - search_string_index + 1;
|
||||
|
||||
/* Search the current line. */
|
||||
while (reverse ? (line_index >= 0) : (line_index < limit))
|
||||
{
|
||||
if (STREQN (search_string, sline + line_index, search_string_index))
|
||||
{
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
else
|
||||
line_index += direction;
|
||||
}
|
||||
if (found)
|
||||
break;
|
||||
|
||||
/* Move to the next line, but skip new copies of the line
|
||||
we just found and lines shorter than the string we're
|
||||
searching for. */
|
||||
do
|
||||
{
|
||||
/* Move to the next line. */
|
||||
i += direction;
|
||||
|
||||
/* At limit for direction? */
|
||||
if (reverse ? (i < 0) : (i == hlen))
|
||||
{
|
||||
failed++;
|
||||
break;
|
||||
}
|
||||
|
||||
/* We will need these later. */
|
||||
sline = lines[i];
|
||||
sline_len = strlen (sline);
|
||||
}
|
||||
while ((prev_line_found && STREQ (prev_line_found, lines[i])) ||
|
||||
(search_string_index > sline_len));
|
||||
|
||||
if (failed)
|
||||
break;
|
||||
|
||||
/* Now set up the line for searching... */
|
||||
line_index = reverse ? sline_len - search_string_index : 0;
|
||||
}
|
||||
|
||||
if (failed)
|
||||
{
|
||||
/* We cannot find the search string. Ding the bell. */
|
||||
rl_ding ();
|
||||
i = last_found_line;
|
||||
continue; /* XXX - was break */
|
||||
}
|
||||
|
||||
/* We have found the search string. Just display it. But don't
|
||||
actually move there in the history list until the user accepts
|
||||
the location. */
|
||||
if (found)
|
||||
{
|
||||
prev_line_found = lines[i];
|
||||
rl_replace_line (lines[i], 0);
|
||||
rl_point = line_index;
|
||||
last_found_line = i;
|
||||
rl_display_search (search_string, reverse, (i == orig_line) ? -1 : i);
|
||||
}
|
||||
c = _rl_search_getchar (cxt);
|
||||
/* We might want to handle EOF here (c == 0) */
|
||||
r = _rl_isearch_dispatch (cxt, cxt->lastc);
|
||||
if (r <= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* The searching is over. The user may have found the string that she
|
||||
was looking for, or else she may have exited a failing search. If
|
||||
LINE_INDEX is -1, then that shows that the string searched for was
|
||||
not found. We use this to determine where to place rl_point. */
|
||||
|
||||
/* First put back the original state. */
|
||||
strcpy (rl_line_buffer, lines[orig_line]);
|
||||
|
||||
rl_restore_prompt ();
|
||||
|
||||
/* Save the search string for possible later use. */
|
||||
FREE (last_isearch_string);
|
||||
last_isearch_string = search_string;
|
||||
last_isearch_string_len = search_string_index;
|
||||
|
||||
if (last_found_line < orig_line)
|
||||
rl_get_previous_history (orig_line - last_found_line, 0);
|
||||
else
|
||||
rl_get_next_history (last_found_line - orig_line, 0);
|
||||
|
||||
/* If the string was not found, put point at the end of the last matching
|
||||
line. If last_found_line == orig_line, we didn't find any matching
|
||||
history lines at all, so put point back in its original position. */
|
||||
if (line_index < 0)
|
||||
{
|
||||
if (last_found_line == orig_line)
|
||||
line_index = orig_point;
|
||||
else
|
||||
line_index = strlen (rl_line_buffer);
|
||||
rl_mark = orig_mark;
|
||||
}
|
||||
|
||||
rl_point = line_index;
|
||||
/* Don't worry about where to put the mark here; rl_get_previous_history
|
||||
and rl_get_next_history take care of it. */
|
||||
|
||||
rl_clear_message ();
|
||||
|
||||
FREE (allocated_line);
|
||||
free (lines);
|
||||
|
||||
RL_UNSETSTATE(RL_STATE_ISEARCH);
|
||||
|
||||
return 0;
|
||||
return (_rl_isearch_cleanup (cxt, r));
|
||||
}
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
/* Called from the callback functions when we are ready to read a key. The
|
||||
callback functions know to call this because RL_ISSTATE(RL_STATE_ISEARCH).
|
||||
If _rl_isearch_dispatch finishes searching, this function is responsible
|
||||
for turning off RL_STATE_ISEARCH, which it does using _rl_isearch_cleanup. */
|
||||
int
|
||||
_rl_isearch_callback (cxt)
|
||||
_rl_search_cxt *cxt;
|
||||
{
|
||||
int c, r;
|
||||
|
||||
c = _rl_search_getchar (cxt);
|
||||
/* We might want to handle EOF here */
|
||||
r = _rl_isearch_dispatch (cxt, cxt->lastc);
|
||||
|
||||
return (r <= 0) ? _rl_isearch_cleanup (cxt, r) : 0;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -100,6 +100,8 @@ _rl_with_macro_input (string)
|
|||
int
|
||||
_rl_next_macro_key ()
|
||||
{
|
||||
int c;
|
||||
|
||||
if (rl_executing_macro == 0)
|
||||
return (0);
|
||||
|
||||
|
|
@ -109,7 +111,14 @@ _rl_next_macro_key ()
|
|||
return (_rl_next_macro_key ());
|
||||
}
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
c = rl_executing_macro[executing_macro_index++];
|
||||
if (RL_ISSTATE (RL_STATE_CALLBACK) && RL_ISSTATE (RL_STATE_READCMD) && rl_executing_macro[executing_macro_index] == 0)
|
||||
_rl_pop_executing_macro ();
|
||||
return c;
|
||||
#else
|
||||
return (rl_executing_macro[executing_macro_index++]);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Save the currently executing macro on a stack of saved macros. */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* mbutil.c -- readline multibyte character utility functions */
|
||||
|
||||
/* Copyright (C) 2001-2004 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 2001-2005 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.
|
||||
|
|
@ -77,18 +77,20 @@ _rl_find_next_mbchar_internal (string, seed, count, find_non_zero)
|
|||
char *string;
|
||||
int seed, count, find_non_zero;
|
||||
{
|
||||
size_t tmp = 0;
|
||||
size_t tmp;
|
||||
mbstate_t ps;
|
||||
int point = 0;
|
||||
int point;
|
||||
wchar_t wc;
|
||||
|
||||
tmp = 0;
|
||||
|
||||
memset(&ps, 0, sizeof (mbstate_t));
|
||||
if (seed < 0)
|
||||
seed = 0;
|
||||
if (count <= 0)
|
||||
return seed;
|
||||
|
||||
point = seed + _rl_adjust_point(string, seed, &ps);
|
||||
point = seed + _rl_adjust_point (string, seed, &ps);
|
||||
/* if this is true, means that seed was not pointed character
|
||||
started byte. So correct the point and consume count */
|
||||
if (seed < point)
|
||||
|
|
@ -134,7 +136,8 @@ _rl_find_next_mbchar_internal (string, seed, count, find_non_zero)
|
|||
break;
|
||||
}
|
||||
}
|
||||
return point;
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -313,6 +316,28 @@ _rl_is_mbchar_matched (string, seed, end, mbchar, length)
|
|||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
wchar_t
|
||||
_rl_char_value (buf, ind)
|
||||
char *buf;
|
||||
int ind;
|
||||
{
|
||||
size_t tmp;
|
||||
wchar_t wc;
|
||||
mbstate_t ps;
|
||||
int l;
|
||||
|
||||
if (MB_LEN_MAX == 1 || rl_byte_oriented)
|
||||
return ((wchar_t) buf[ind]);
|
||||
l = strlen (buf);
|
||||
if (ind >= l - 1)
|
||||
return ((wchar_t) buf[ind]);
|
||||
memset (&ps, 0, sizeof (mbstate_t));
|
||||
tmp = mbrtowc (&wc, buf + ind, l - ind, &ps);
|
||||
if (MB_INVALIDCH (tmp) || MB_NULLWCH (tmp))
|
||||
return ((wchar_t) buf[ind]);
|
||||
return wc;
|
||||
}
|
||||
#endif /* HANDLE_MULTIBYTE */
|
||||
|
||||
/* Find next `count' characters started byte point of the specified seed.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* misc.c -- miscellaneous bindable readline functions. */
|
||||
|
||||
/* Copyright (C) 1987-2004 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2005 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.
|
||||
|
|
@ -63,6 +63,8 @@ void _rl_free_history_entry PARAMS((HIST_ENTRY *));
|
|||
to preserve the value of rl_point from line to line. */
|
||||
int _rl_history_preserve_point = 0;
|
||||
|
||||
_rl_arg_cxt _rl_argcxt;
|
||||
|
||||
/* Saved target point for when _rl_history_preserve_point is set. Special
|
||||
value of -1 means that point is at the end of the line. */
|
||||
int _rl_history_saved_point = -1;
|
||||
|
|
@ -73,77 +75,74 @@ int _rl_history_saved_point = -1;
|
|||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
/* Handle C-u style numeric args, as well as M--, and M-digits. */
|
||||
static int
|
||||
rl_digit_loop ()
|
||||
int
|
||||
_rl_arg_overflow ()
|
||||
{
|
||||
int key, c, sawminus, sawdigits;
|
||||
|
||||
rl_save_prompt ();
|
||||
|
||||
RL_SETSTATE(RL_STATE_NUMERICARG);
|
||||
sawminus = sawdigits = 0;
|
||||
while (1)
|
||||
if (rl_numeric_arg > 1000000)
|
||||
{
|
||||
if (rl_numeric_arg > 1000000)
|
||||
_rl_argcxt = 0;
|
||||
rl_explicit_arg = rl_numeric_arg = 0;
|
||||
rl_ding ();
|
||||
rl_restore_prompt ();
|
||||
rl_clear_message ();
|
||||
RL_UNSETSTATE(RL_STATE_NUMERICARG);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
_rl_arg_init ()
|
||||
{
|
||||
rl_save_prompt ();
|
||||
_rl_argcxt = 0;
|
||||
RL_SETSTATE(RL_STATE_NUMERICARG);
|
||||
}
|
||||
|
||||
int
|
||||
_rl_arg_getchar ()
|
||||
{
|
||||
int c;
|
||||
|
||||
rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg);
|
||||
RL_SETSTATE(RL_STATE_MOREINPUT);
|
||||
c = rl_read_key ();
|
||||
RL_UNSETSTATE(RL_STATE_MOREINPUT);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/* Process C as part of the current numeric argument. Return -1 if the
|
||||
argument should be aborted, 0 if we should not read any more chars, and
|
||||
1 if we should continue to read chars. */
|
||||
int
|
||||
_rl_arg_dispatch (cxt, c)
|
||||
_rl_arg_cxt cxt;
|
||||
int c;
|
||||
{
|
||||
int key, r;
|
||||
|
||||
key = c;
|
||||
|
||||
/* If we see a key bound to `universal-argument' after seeing digits,
|
||||
it ends the argument but is otherwise ignored. */
|
||||
if (_rl_keymap[c].type == ISFUNC && _rl_keymap[c].function == rl_universal_argument)
|
||||
{
|
||||
if ((cxt & NUM_SAWDIGITS) == 0)
|
||||
{
|
||||
sawdigits = rl_explicit_arg = rl_numeric_arg = 0;
|
||||
rl_ding ();
|
||||
rl_restore_prompt ();
|
||||
rl_clear_message ();
|
||||
RL_UNSETSTATE(RL_STATE_NUMERICARG);
|
||||
rl_numeric_arg *= 4;
|
||||
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 (c < 0)
|
||||
{
|
||||
_rl_abort_internal ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If we see a key bound to `universal-argument' after seeing digits,
|
||||
it ends the argument but is otherwise ignored. */
|
||||
if (_rl_keymap[c].type == ISFUNC &&
|
||||
_rl_keymap[c].function == rl_universal_argument)
|
||||
{
|
||||
if (sawdigits == 0)
|
||||
{
|
||||
rl_numeric_arg *= 4;
|
||||
continue;
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
c = UNMETA (c);
|
||||
|
||||
if (_rl_digit_p (c))
|
||||
{
|
||||
rl_numeric_arg = rl_explicit_arg ? (rl_numeric_arg * 10) + c - '0' : c - '0';
|
||||
sawdigits = rl_explicit_arg = 1;
|
||||
}
|
||||
else if (c == '-' && rl_explicit_arg == 0)
|
||||
{
|
||||
rl_numeric_arg = sawminus = 1;
|
||||
rl_arg_sign = -1;
|
||||
}
|
||||
else if (RL_ISSTATE (RL_STATE_CALLBACK))
|
||||
{
|
||||
_rl_argcxt |= NUM_READONE;
|
||||
return 0; /* XXX */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Make M-- command equivalent to M--1 command. */
|
||||
if (sawminus && rl_numeric_arg == 1 && rl_explicit_arg == 0)
|
||||
rl_explicit_arg = 1;
|
||||
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);
|
||||
|
|
@ -151,35 +150,96 @@ rl_digit_loop ()
|
|||
}
|
||||
}
|
||||
|
||||
/*NOTREACHED*/
|
||||
c = UNMETA (c);
|
||||
|
||||
if (_rl_digit_p (c))
|
||||
{
|
||||
r = _rl_digit_value (c);
|
||||
rl_numeric_arg = rl_explicit_arg ? (rl_numeric_arg * 10) + r : r;
|
||||
rl_explicit_arg = 1;
|
||||
_rl_argcxt |= NUM_SAWDIGITS;
|
||||
}
|
||||
else if (c == '-' && rl_explicit_arg == 0)
|
||||
{
|
||||
rl_numeric_arg = 1;
|
||||
_rl_argcxt |= NUM_SAWMINUS;
|
||||
rl_arg_sign = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Make M-- command equivalent to M--1 command. */
|
||||
if ((_rl_argcxt & NUM_SAWMINUS) && rl_numeric_arg == 1 && rl_explicit_arg == 0)
|
||||
rl_explicit_arg = 1;
|
||||
rl_restore_prompt ();
|
||||
rl_clear_message ();
|
||||
RL_UNSETSTATE(RL_STATE_NUMERICARG);
|
||||
|
||||
r = _rl_dispatch (key, _rl_keymap);
|
||||
if (RL_ISSTATE (RL_STATE_CALLBACK))
|
||||
{
|
||||
/* At worst, this will cause an extra redisplay. Otherwise,
|
||||
we have to wait until the next character comes in. */
|
||||
if (rl_done == 0)
|
||||
(*rl_redisplay_function) ();
|
||||
r = 0;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Add the current digit to the argument in progress. */
|
||||
/* Handle C-u style numeric args, as well as M--, and M-digits. */
|
||||
static int
|
||||
rl_digit_loop ()
|
||||
{
|
||||
int c, r;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (_rl_arg_overflow ())
|
||||
return 1;
|
||||
|
||||
c = _rl_arg_getchar ();
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
_rl_abort_internal ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
r = _rl_arg_dispatch (_rl_argcxt, c);
|
||||
if (r <= 0 || (RL_ISSTATE (RL_STATE_NUMERICARG) == 0))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a default argument. */
|
||||
void
|
||||
_rl_reset_argument ()
|
||||
{
|
||||
rl_numeric_arg = rl_arg_sign = 1;
|
||||
rl_explicit_arg = 0;
|
||||
_rl_argcxt = 0;
|
||||
}
|
||||
|
||||
/* Start a numeric argument with initial value KEY */
|
||||
int
|
||||
rl_digit_argument (ignore, key)
|
||||
int ignore, key;
|
||||
{
|
||||
rl_execute_next (key);
|
||||
return (rl_digit_loop ());
|
||||
}
|
||||
|
||||
/* What to do when you abort reading an argument. */
|
||||
int
|
||||
rl_discard_argument ()
|
||||
{
|
||||
rl_ding ();
|
||||
rl_clear_message ();
|
||||
_rl_init_argument ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Create a default argument. */
|
||||
int
|
||||
_rl_init_argument ()
|
||||
{
|
||||
rl_numeric_arg = rl_arg_sign = 1;
|
||||
rl_explicit_arg = 0;
|
||||
return 0;
|
||||
_rl_arg_init ();
|
||||
if (RL_ISSTATE (RL_STATE_CALLBACK))
|
||||
{
|
||||
_rl_arg_dispatch (_rl_argcxt, key);
|
||||
rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
rl_execute_next (key);
|
||||
return (rl_digit_loop ());
|
||||
}
|
||||
}
|
||||
|
||||
/* C-u, universal argument. Multiply the current argument by 4.
|
||||
|
|
@ -189,8 +249,43 @@ int
|
|||
rl_universal_argument (count, key)
|
||||
int count, key;
|
||||
{
|
||||
_rl_arg_init ();
|
||||
rl_numeric_arg *= 4;
|
||||
return (rl_digit_loop ());
|
||||
|
||||
return (RL_ISSTATE (RL_STATE_CALLBACK) ? 0 : rl_digit_loop ());
|
||||
}
|
||||
|
||||
int
|
||||
_rl_arg_callback (cxt)
|
||||
_rl_arg_cxt cxt;
|
||||
{
|
||||
int c, r;
|
||||
|
||||
c = _rl_arg_getchar ();
|
||||
|
||||
if (_rl_argcxt & NUM_READONE)
|
||||
{
|
||||
_rl_argcxt &= ~NUM_READONE;
|
||||
rl_restore_prompt ();
|
||||
rl_clear_message ();
|
||||
RL_UNSETSTATE(RL_STATE_NUMERICARG);
|
||||
rl_execute_next (c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = _rl_arg_dispatch (cxt, c);
|
||||
return (r != 1);
|
||||
}
|
||||
|
||||
/* What to do when you abort reading an argument. */
|
||||
int
|
||||
rl_discard_argument ()
|
||||
{
|
||||
rl_ding ();
|
||||
rl_clear_message ();
|
||||
_rl_reset_argument ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* **************************************************************** */
|
||||
|
|
@ -225,8 +320,10 @@ _rl_free_history_entry (entry)
|
|||
{
|
||||
if (entry == 0)
|
||||
return;
|
||||
if (entry->line)
|
||||
free (entry->line);
|
||||
|
||||
FREE (entry->line);
|
||||
FREE (entry->timestamp);
|
||||
|
||||
free (entry);
|
||||
}
|
||||
|
||||
|
|
@ -242,6 +339,7 @@ rl_maybe_replace_line ()
|
|||
{
|
||||
temp = replace_history_entry (where_history (), rl_line_buffer, (histdata_t)rl_undo_list);
|
||||
free (temp->line);
|
||||
FREE (temp->timestamp);
|
||||
free (temp);
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -274,6 +372,7 @@ rl_maybe_save_line ()
|
|||
{
|
||||
_rl_saved_line_for_history = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY));
|
||||
_rl_saved_line_for_history->line = savestring (rl_line_buffer);
|
||||
_rl_saved_line_for_history->timestamp = (char *)NULL;
|
||||
_rl_saved_line_for_history->data = (char *)rl_undo_list;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* readline.c -- a general facility for reading lines of input
|
||||
with emacs style editing and completion. */
|
||||
|
||||
/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2005 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.
|
||||
|
|
@ -68,11 +68,11 @@
|
|||
#include "xmalloc.h"
|
||||
|
||||
#ifndef RL_LIBRARY_VERSION
|
||||
# define RL_LIBRARY_VERSION "5.0"
|
||||
# define RL_LIBRARY_VERSION "5.1"
|
||||
#endif
|
||||
|
||||
#ifndef RL_READLINE_VERSION
|
||||
# define RL_READLINE_VERSION 0x0500
|
||||
# define RL_READLINE_VERSION 0x0501
|
||||
#endif
|
||||
|
||||
extern void _rl_free_history_entry PARAMS((HIST_ENTRY *));
|
||||
|
|
@ -87,6 +87,9 @@ static void bind_arrow_keys PARAMS((void));
|
|||
static void readline_default_bindings PARAMS((void));
|
||||
static void reset_default_bindings PARAMS((void));
|
||||
|
||||
static int _rl_subseq_result PARAMS((int, Keymap, int, int));
|
||||
static int _rl_subseq_getchar PARAMS((int));
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* Line editing input utility */
|
||||
|
|
@ -104,6 +107,7 @@ int rl_gnu_readline_p = 1;
|
|||
By default, it is the standard emacs keymap. */
|
||||
Keymap _rl_keymap = emacs_standard_keymap;
|
||||
|
||||
|
||||
/* The current style of editing. */
|
||||
int rl_editing_mode = emacs_mode;
|
||||
|
||||
|
|
@ -219,6 +223,9 @@ char *_rl_comment_begin;
|
|||
/* Keymap holding the function currently being executed. */
|
||||
Keymap rl_executing_keymap;
|
||||
|
||||
/* Keymap we're currently using to dispatch. */
|
||||
Keymap _rl_dispatching_keymap;
|
||||
|
||||
/* Non-zero means to erase entire line, including prompt, on empty input lines. */
|
||||
int rl_erase_empty_line = 0;
|
||||
|
||||
|
|
@ -230,6 +237,9 @@ int rl_num_chars_to_read;
|
|||
char *rl_line_buffer = (char *)NULL;
|
||||
int rl_line_buffer_len = 0;
|
||||
|
||||
/* Key sequence `contexts' */
|
||||
_rl_keyseq_cxt *_rl_kscxt = 0;
|
||||
|
||||
/* Forward declarations used by the display, termcap, and history code. */
|
||||
|
||||
/* **************************************************************** */
|
||||
|
|
@ -251,6 +261,10 @@ int _rl_convert_meta_chars_to_ascii = 1;
|
|||
rather than as a meta-prefixed escape sequence. */
|
||||
int _rl_output_meta_chars = 0;
|
||||
|
||||
/* Non-zero means to look at the termios special characters and bind
|
||||
them to equivalent readline functions at startup. */
|
||||
int _rl_bind_stty_chars = 1;
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* Top Level Functions */
|
||||
|
|
@ -291,14 +305,16 @@ readline (prompt)
|
|||
rl_set_prompt (prompt);
|
||||
|
||||
rl_initialize ();
|
||||
(*rl_prep_term_function) (_rl_meta_flag);
|
||||
if (rl_prep_term_function)
|
||||
(*rl_prep_term_function) (_rl_meta_flag);
|
||||
|
||||
#if defined (HANDLE_SIGNALS)
|
||||
rl_set_signals ();
|
||||
#endif
|
||||
|
||||
value = readline_internal ();
|
||||
(*rl_deprep_term_function) ();
|
||||
if (rl_deprep_term_function)
|
||||
(*rl_deprep_term_function) ();
|
||||
|
||||
#if defined (HANDLE_SIGNALS)
|
||||
rl_clear_signals ();
|
||||
|
|
@ -388,6 +404,36 @@ readline_internal_teardown (eof)
|
|||
return (eof ? (char *)NULL : savestring (the_line));
|
||||
}
|
||||
|
||||
void
|
||||
_rl_internal_char_cleanup ()
|
||||
{
|
||||
#if defined (VI_MODE)
|
||||
/* In vi mode, when you exit insert mode, the cursor moves back
|
||||
over the previous character. We explicitly check for that here. */
|
||||
if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap)
|
||||
rl_vi_check ();
|
||||
#endif /* VI_MODE */
|
||||
|
||||
if (rl_num_chars_to_read && rl_end >= rl_num_chars_to_read)
|
||||
{
|
||||
(*rl_redisplay_function) ();
|
||||
_rl_want_redisplay = 0;
|
||||
rl_newline (1, '\n');
|
||||
}
|
||||
|
||||
if (rl_done == 0)
|
||||
{
|
||||
(*rl_redisplay_function) ();
|
||||
_rl_want_redisplay = 0;
|
||||
}
|
||||
|
||||
/* If the application writer has told us to erase the entire line if
|
||||
the only character typed was something bound to rl_newline, do so. */
|
||||
if (rl_erase_empty_line && rl_done && rl_last_func == rl_newline &&
|
||||
rl_point == 0 && rl_end == 0)
|
||||
_rl_erase_entire_line ();
|
||||
}
|
||||
|
||||
STATIC_CALLBACK int
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
readline_internal_char ()
|
||||
|
|
@ -410,12 +456,21 @@ readline_internal_charloop ()
|
|||
code = setjmp (readline_top_level);
|
||||
|
||||
if (code)
|
||||
(*rl_redisplay_function) ();
|
||||
{
|
||||
(*rl_redisplay_function) ();
|
||||
_rl_want_redisplay = 0;
|
||||
/* If we get here, we're not being called from something dispatched
|
||||
from _rl_callback_read_char(), which sets up its own value of
|
||||
readline_top_level (saving and restoring the old, of course), so
|
||||
we can just return here. */
|
||||
if (RL_ISSTATE (RL_STATE_CALLBACK))
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (rl_pending_input == 0)
|
||||
{
|
||||
/* Then initialize the argument and number of keys read. */
|
||||
_rl_init_argument ();
|
||||
_rl_reset_argument ();
|
||||
rl_key_sequence_length = 0;
|
||||
}
|
||||
|
||||
|
|
@ -449,27 +504,7 @@ readline_internal_charloop ()
|
|||
if (rl_pending_input == 0 && lk == _rl_last_command_was_kill)
|
||||
_rl_last_command_was_kill = 0;
|
||||
|
||||
#if defined (VI_MODE)
|
||||
/* In vi mode, when you exit insert mode, the cursor moves back
|
||||
over the previous character. We explicitly check for that here. */
|
||||
if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap)
|
||||
rl_vi_check ();
|
||||
#endif /* VI_MODE */
|
||||
|
||||
if (rl_num_chars_to_read && rl_end >= rl_num_chars_to_read)
|
||||
{
|
||||
(*rl_redisplay_function) ();
|
||||
rl_newline (1, '\n');
|
||||
}
|
||||
|
||||
if (rl_done == 0)
|
||||
(*rl_redisplay_function) ();
|
||||
|
||||
/* If the application writer has told us to erase the entire line if
|
||||
the only character typed was something bound to rl_newline, do so. */
|
||||
if (rl_erase_empty_line && rl_done && rl_last_func == rl_newline &&
|
||||
rl_point == 0 && rl_end == 0)
|
||||
_rl_erase_entire_line ();
|
||||
_rl_internal_char_cleanup ();
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
return 0;
|
||||
|
|
@ -519,6 +554,107 @@ _rl_set_the_line ()
|
|||
the_line = rl_line_buffer;
|
||||
}
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
_rl_keyseq_cxt *
|
||||
_rl_keyseq_cxt_alloc ()
|
||||
{
|
||||
_rl_keyseq_cxt *cxt;
|
||||
|
||||
cxt = (_rl_keyseq_cxt *)xmalloc (sizeof (_rl_keyseq_cxt));
|
||||
|
||||
cxt->flags = cxt->subseq_arg = cxt->subseq_retval = 0;
|
||||
|
||||
cxt->okey = 0;
|
||||
cxt->ocxt = _rl_kscxt;
|
||||
cxt->childval = 42; /* sentinel value */
|
||||
|
||||
return cxt;
|
||||
}
|
||||
|
||||
void
|
||||
_rl_keyseq_cxt_dispose (cxt)
|
||||
_rl_keyseq_cxt *cxt;
|
||||
{
|
||||
free (cxt);
|
||||
}
|
||||
|
||||
void
|
||||
_rl_keyseq_chain_dispose ()
|
||||
{
|
||||
_rl_keyseq_cxt *cxt;
|
||||
|
||||
while (_rl_kscxt)
|
||||
{
|
||||
cxt = _rl_kscxt;
|
||||
_rl_kscxt = _rl_kscxt->ocxt;
|
||||
_rl_keyseq_cxt_dispose (cxt);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
_rl_subseq_getchar (key)
|
||||
int key;
|
||||
{
|
||||
int k;
|
||||
|
||||
if (key == ESC)
|
||||
RL_SETSTATE(RL_STATE_METANEXT);
|
||||
RL_SETSTATE(RL_STATE_MOREINPUT);
|
||||
k = rl_read_key ();
|
||||
RL_UNSETSTATE(RL_STATE_MOREINPUT);
|
||||
if (key == ESC)
|
||||
RL_UNSETSTATE(RL_STATE_METANEXT);
|
||||
|
||||
return k;
|
||||
}
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
int
|
||||
_rl_dispatch_callback (cxt)
|
||||
_rl_keyseq_cxt *cxt;
|
||||
{
|
||||
int nkey, r;
|
||||
|
||||
/* For now */
|
||||
#if 1
|
||||
/* The first time this context is used, we want to read input and dispatch
|
||||
on it. When traversing the chain of contexts back `up', we want to use
|
||||
the value from the next context down. We're simulating recursion using
|
||||
a chain of contexts. */
|
||||
if ((cxt->flags & KSEQ_DISPATCHED) == 0)
|
||||
{
|
||||
nkey = _rl_subseq_getchar (cxt->okey);
|
||||
r = _rl_dispatch_subseq (nkey, cxt->dmap, cxt->subseq_arg);
|
||||
cxt->flags |= KSEQ_DISPATCHED;
|
||||
}
|
||||
else
|
||||
r = cxt->childval;
|
||||
#else
|
||||
r = _rl_dispatch_subseq (nkey, cxt->dmap, cxt->subseq_arg);
|
||||
#endif
|
||||
|
||||
/* For now */
|
||||
r = _rl_subseq_result (r, cxt->oldmap, cxt->okey, (cxt->flags & KSEQ_SUBSEQ));
|
||||
|
||||
if (r == 0) /* success! */
|
||||
{
|
||||
_rl_keyseq_chain_dispose ();
|
||||
RL_UNSETSTATE (RL_STATE_MULTIKEY);
|
||||
return r;
|
||||
}
|
||||
|
||||
if (r != -3) /* magic value that says we added to the chain */
|
||||
_rl_kscxt = cxt->ocxt;
|
||||
if (_rl_kscxt)
|
||||
_rl_kscxt->childval = r;
|
||||
if (r != -3)
|
||||
_rl_keyseq_cxt_dispose (cxt);
|
||||
|
||||
return r;
|
||||
}
|
||||
#endif /* READLINE_CALLBACKS */
|
||||
|
||||
/* Do the command associated with KEY in MAP.
|
||||
If the associated command is really a keymap, then read
|
||||
another key, and dispatch into that map. */
|
||||
|
|
@ -527,6 +663,7 @@ _rl_dispatch (key, map)
|
|||
register int key;
|
||||
Keymap map;
|
||||
{
|
||||
_rl_dispatching_keymap = map;
|
||||
return _rl_dispatch_subseq (key, map, 0);
|
||||
}
|
||||
|
||||
|
|
@ -539,6 +676,9 @@ _rl_dispatch_subseq (key, map, got_subseq)
|
|||
int r, newkey;
|
||||
char *macro;
|
||||
rl_command_func_t *func;
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
_rl_keyseq_cxt *cxt;
|
||||
#endif
|
||||
|
||||
if (META_CHAR (key) && _rl_convert_meta_chars_to_ascii)
|
||||
{
|
||||
|
|
@ -572,10 +712,6 @@ _rl_dispatch_subseq (key, map, got_subseq)
|
|||
|
||||
rl_executing_keymap = map;
|
||||
|
||||
#if 0
|
||||
_rl_suppress_redisplay = (map[key].function == rl_insert) && _rl_input_available ();
|
||||
#endif
|
||||
|
||||
rl_dispatching = 1;
|
||||
RL_SETSTATE(RL_STATE_DISPATCHING);
|
||||
r = (*map[key].function)(rl_numeric_arg * rl_arg_sign, key);
|
||||
|
|
@ -607,6 +743,10 @@ _rl_dispatch_subseq (key, map, got_subseq)
|
|||
}
|
||||
else
|
||||
{
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
RL_UNSETSTATE (RL_STATE_MULTIKEY);
|
||||
_rl_keyseq_chain_dispose ();
|
||||
#endif
|
||||
_rl_abort_internal ();
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -628,58 +768,43 @@ _rl_dispatch_subseq (key, map, got_subseq)
|
|||
#endif
|
||||
|
||||
rl_key_sequence_length++;
|
||||
_rl_dispatching_keymap = FUNCTION_TO_KEYMAP (map, key);
|
||||
|
||||
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);
|
||||
/* Allocate new context here. Use linked contexts (linked through
|
||||
cxt->ocxt) to simulate recursion */
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
if (RL_ISSTATE (RL_STATE_CALLBACK))
|
||||
{
|
||||
/* Return 0 only the first time, to indicate success to
|
||||
_rl_callback_read_char. The rest of the time, we're called
|
||||
from _rl_dispatch_callback, so we return 3 to indicate
|
||||
special handling is necessary. */
|
||||
r = RL_ISSTATE (RL_STATE_MULTIKEY) ? -3 : 0;
|
||||
cxt = _rl_keyseq_cxt_alloc ();
|
||||
|
||||
if (got_subseq)
|
||||
cxt->flags |= KSEQ_SUBSEQ;
|
||||
cxt->okey = key;
|
||||
cxt->oldmap = map;
|
||||
cxt->dmap = _rl_dispatching_keymap;
|
||||
cxt->subseq_arg = got_subseq || cxt->dmap[ANYOTHERKEY].function;
|
||||
|
||||
RL_SETSTATE (RL_STATE_MULTIKEY);
|
||||
_rl_kscxt = cxt;
|
||||
|
||||
return r; /* don't indicate immediate success */
|
||||
}
|
||||
#endif
|
||||
|
||||
newkey = _rl_subseq_getchar (key);
|
||||
if (newkey < 0)
|
||||
{
|
||||
_rl_abort_internal ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
r = _rl_dispatch_subseq (newkey, FUNCTION_TO_KEYMAP (map, key), got_subseq || map[ANYOTHERKEY].function);
|
||||
|
||||
if (r == -2)
|
||||
/* We didn't match anything, and the keymap we're indexed into
|
||||
shadowed a function previously bound to that prefix. Call
|
||||
the function. The recursive call to _rl_dispatch_subseq has
|
||||
already taken care of pushing any necessary input back onto
|
||||
the input queue with _rl_unget_char. */
|
||||
{
|
||||
#if 0
|
||||
r = _rl_dispatch (ANYOTHERKEY, FUNCTION_TO_KEYMAP (map, key));
|
||||
#else
|
||||
/* XXX - experimental code -- might never be executed. Save
|
||||
for later. */
|
||||
Keymap m = FUNCTION_TO_KEYMAP (map, key);
|
||||
int type = m[ANYOTHERKEY].type;
|
||||
func = m[ANYOTHERKEY].function;
|
||||
if (type == ISFUNC && func == rl_do_lowercase_version)
|
||||
r = _rl_dispatch (_rl_to_lower (key), map);
|
||||
else
|
||||
r = _rl_dispatch (ANYOTHERKEY, m);
|
||||
#endif
|
||||
}
|
||||
else if (r && map[ANYOTHERKEY].function)
|
||||
{
|
||||
/* We didn't match (r is probably -1), so return something to
|
||||
tell the caller that it should try ANYOTHERKEY for an
|
||||
overridden function. */
|
||||
_rl_unget_char (key);
|
||||
return -2;
|
||||
}
|
||||
else if (r && got_subseq)
|
||||
{
|
||||
/* OK, back up the chain. */
|
||||
_rl_unget_char (key);
|
||||
return -1;
|
||||
}
|
||||
r = _rl_dispatch_subseq (newkey, _rl_dispatching_keymap, got_subseq || map[ANYOTHERKEY].function);
|
||||
return _rl_subseq_result (r, map, key, got_subseq);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -703,9 +828,69 @@ _rl_dispatch_subseq (key, map, got_subseq)
|
|||
_rl_vi_textmod_command (key))
|
||||
_rl_vi_set_last (key, rl_numeric_arg, rl_arg_sign);
|
||||
#endif
|
||||
|
||||
return (r);
|
||||
}
|
||||
|
||||
static int
|
||||
_rl_subseq_result (r, map, key, got_subseq)
|
||||
int r;
|
||||
Keymap map;
|
||||
int key, got_subseq;
|
||||
{
|
||||
Keymap m;
|
||||
int type, nt;
|
||||
rl_command_func_t *func, *nf;
|
||||
|
||||
if (r == -2)
|
||||
/* We didn't match anything, and the keymap we're indexed into
|
||||
shadowed a function previously bound to that prefix. Call
|
||||
the function. The recursive call to _rl_dispatch_subseq has
|
||||
already taken care of pushing any necessary input back onto
|
||||
the input queue with _rl_unget_char. */
|
||||
{
|
||||
m = _rl_dispatching_keymap;
|
||||
type = m[ANYOTHERKEY].type;
|
||||
func = m[ANYOTHERKEY].function;
|
||||
if (type == ISFUNC && func == rl_do_lowercase_version)
|
||||
r = _rl_dispatch (_rl_to_lower (key), map);
|
||||
else if (type == ISFUNC && func == rl_insert)
|
||||
{
|
||||
/* If the function that was shadowed was self-insert, we
|
||||
somehow need a keymap with map[key].func == self-insert.
|
||||
Let's use this one. */
|
||||
nt = m[key].type;
|
||||
nf = m[key].function;
|
||||
|
||||
m[key].type = type;
|
||||
m[key].function = func;
|
||||
r = _rl_dispatch (key, m);
|
||||
m[key].type = nt;
|
||||
m[key].function = nf;
|
||||
}
|
||||
else
|
||||
r = _rl_dispatch (ANYOTHERKEY, m);
|
||||
}
|
||||
else if (r && map[ANYOTHERKEY].function)
|
||||
{
|
||||
/* We didn't match (r is probably -1), so return something to
|
||||
tell the caller that it should try ANYOTHERKEY for an
|
||||
overridden function. */
|
||||
_rl_unget_char (key);
|
||||
_rl_dispatching_keymap = map;
|
||||
return -2;
|
||||
}
|
||||
else if (r && got_subseq)
|
||||
{
|
||||
/* OK, back up the chain. */
|
||||
_rl_unget_char (key);
|
||||
_rl_dispatching_keymap = map;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* Initializations */
|
||||
|
|
@ -863,7 +1048,8 @@ readline_initialize_everything ()
|
|||
static void
|
||||
readline_default_bindings ()
|
||||
{
|
||||
rl_tty_set_default_bindings (_rl_keymap);
|
||||
if (_rl_bind_stty_chars)
|
||||
rl_tty_set_default_bindings (_rl_keymap);
|
||||
}
|
||||
|
||||
/* Reset the default bindings for the terminal special characters we're
|
||||
|
|
@ -871,8 +1057,11 @@ readline_default_bindings ()
|
|||
static void
|
||||
reset_default_bindings ()
|
||||
{
|
||||
rl_tty_unset_default_bindings (_rl_keymap);
|
||||
rl_tty_set_default_bindings (_rl_keymap);
|
||||
if (_rl_bind_stty_chars)
|
||||
{
|
||||
rl_tty_unset_default_bindings (_rl_keymap);
|
||||
rl_tty_set_default_bindings (_rl_keymap);
|
||||
}
|
||||
}
|
||||
|
||||
/* Bind some common arrow key sequences in MAP. */
|
||||
|
|
@ -906,6 +1095,13 @@ bind_arrow_keys_internal (map)
|
|||
rl_bind_keyseq_if_unbound ("\033OH", rl_beg_of_line);
|
||||
rl_bind_keyseq_if_unbound ("\033OF", rl_end_of_line);
|
||||
|
||||
#if defined (__MINGW32__)
|
||||
rl_bind_keyseq_if_unbound ("\340H", rl_get_previous_history);
|
||||
rl_bind_keyseq_if_unbound ("\340P", rl_get_next_history);
|
||||
rl_bind_keyseq_if_unbound ("\340M", rl_forward_char);
|
||||
rl_bind_keyseq_if_unbound ("\340K", rl_backward_char);
|
||||
#endif
|
||||
|
||||
_rl_keymap = xkeymap;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* Readline.h -- the names of functions callable from within readline. */
|
||||
|
||||
/* Copyright (C) 1987-2004 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2005 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.
|
||||
|
|
@ -40,9 +40,9 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
/* Hex-encoded Readline version number. */
|
||||
#define RL_READLINE_VERSION 0x0500 /* Readline 5.0 */
|
||||
#define RL_READLINE_VERSION 0x0501 /* Readline 5.1 */
|
||||
#define RL_VERSION_MAJOR 5
|
||||
#define RL_VERSION_MINOR 0
|
||||
#define RL_VERSION_MINOR 1
|
||||
|
||||
/* Readline data structures. */
|
||||
|
||||
|
|
@ -241,6 +241,7 @@ extern int rl_vi_column PARAMS((int, int));
|
|||
extern int rl_vi_delete_to PARAMS((int, int));
|
||||
extern int rl_vi_change_to PARAMS((int, int));
|
||||
extern int rl_vi_yank_to PARAMS((int, int));
|
||||
extern int rl_vi_rubout PARAMS((int, int));
|
||||
extern int rl_vi_delete PARAMS((int, int));
|
||||
extern int rl_vi_back_to_indent PARAMS((int, int));
|
||||
extern int rl_vi_first_print PARAMS((int, int));
|
||||
|
|
@ -302,6 +303,8 @@ extern int rl_bind_keyseq_in_map PARAMS((const char *, rl_command_func_t *, Keym
|
|||
extern int rl_bind_keyseq_if_unbound PARAMS((const char *, rl_command_func_t *));
|
||||
extern int rl_bind_keyseq_if_unbound_in_map PARAMS((const char *, rl_command_func_t *, Keymap));
|
||||
extern int rl_generic_bind PARAMS((int, const char *, char *, Keymap));
|
||||
|
||||
extern char *rl_variable_value PARAMS((const char *));
|
||||
extern int rl_variable_bind PARAMS((const char *, const char *));
|
||||
|
||||
/* Backwards compatibility, use rl_bind_keyseq_in_map instead. */
|
||||
|
|
@ -401,6 +404,7 @@ extern int rl_reset_terminal PARAMS((const char *));
|
|||
extern void rl_resize_terminal PARAMS((void));
|
||||
extern void rl_set_screen_size PARAMS((int, int));
|
||||
extern void rl_get_screen_size PARAMS((int *, int *));
|
||||
extern void rl_reset_screen_size PARAMS((void));
|
||||
|
||||
extern char *rl_get_termcap PARAMS((const char *));
|
||||
|
||||
|
|
@ -528,6 +532,11 @@ extern const char *rl_terminal_name;
|
|||
extern FILE *rl_instream;
|
||||
extern FILE *rl_outstream;
|
||||
|
||||
/* If non-zero, Readline gives values of LINES and COLUMNS from the environment
|
||||
greater precedence than values fetched from the kernel when computing the
|
||||
screen dimensions. */
|
||||
extern int rl_prefer_env_winsize;
|
||||
|
||||
/* If non-zero, then this is the address of a function to call just
|
||||
before readline_internal () prints the first prompt. */
|
||||
extern rl_hook_func_t *rl_startup_hook;
|
||||
|
|
@ -759,29 +768,33 @@ extern int rl_inhibit_completion;
|
|||
#define MULT_MATCH 2
|
||||
|
||||
/* Possible state values for rl_readline_state */
|
||||
#define RL_STATE_NONE 0x00000 /* no state; before first call */
|
||||
#define RL_STATE_NONE 0x000000 /* 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_TTYCSAVED 0x40000 /* tty special chars saved */
|
||||
#define RL_STATE_INITIALIZING 0x000001 /* initializing */
|
||||
#define RL_STATE_INITIALIZED 0x000002 /* initialization done */
|
||||
#define RL_STATE_TERMPREPPED 0x000004 /* terminal is prepped */
|
||||
#define RL_STATE_READCMD 0x000008 /* reading a command key */
|
||||
#define RL_STATE_METANEXT 0x000010 /* reading input after ESC */
|
||||
#define RL_STATE_DISPATCHING 0x000020 /* dispatching to a command */
|
||||
#define RL_STATE_MOREINPUT 0x000040 /* reading more input in a command function */
|
||||
#define RL_STATE_ISEARCH 0x000080 /* doing incremental search */
|
||||
#define RL_STATE_NSEARCH 0x000100 /* doing non-inc search */
|
||||
#define RL_STATE_SEARCH 0x000200 /* doing a history search */
|
||||
#define RL_STATE_NUMERICARG 0x000400 /* reading numeric argument */
|
||||
#define RL_STATE_MACROINPUT 0x000800 /* getting input from a macro */
|
||||
#define RL_STATE_MACRODEF 0x001000 /* defining keyboard macro */
|
||||
#define RL_STATE_OVERWRITE 0x002000 /* overwrite mode */
|
||||
#define RL_STATE_COMPLETING 0x004000 /* doing completion */
|
||||
#define RL_STATE_SIGHANDLER 0x008000 /* in readline sighandler */
|
||||
#define RL_STATE_UNDOING 0x010000 /* doing an undo */
|
||||
#define RL_STATE_INPUTPENDING 0x020000 /* rl_execute_next called */
|
||||
#define RL_STATE_TTYCSAVED 0x040000 /* tty special chars saved */
|
||||
#define RL_STATE_CALLBACK 0x080000 /* using the callback interface */
|
||||
#define RL_STATE_VIMOTION 0x100000 /* reading vi motion arg */
|
||||
#define RL_STATE_MULTIKEY 0x200000 /* reading multiple-key command */
|
||||
#define RL_STATE_VICMDONCE 0x400000 /* entered vi command mode at least once */
|
||||
|
||||
#define RL_STATE_DONE 0x80000 /* done; accepted line */
|
||||
#define RL_STATE_DONE 0x800000 /* done; accepted line */
|
||||
|
||||
#define RL_SETSTATE(x) (rl_readline_state |= (x))
|
||||
#define RL_UNSETSTATE(x) (rl_readline_state &= ~(x))
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
for readline. This should be included after any files that define
|
||||
system-specific constants like _POSIX_VERSION or USG. */
|
||||
|
||||
/* Copyright (C) 1987,1989 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
|
||||
|
||||
This file contains the Readline Library (the Library), a set of
|
||||
routines for providing Emacs style line input to programs that ask
|
||||
|
|
@ -38,7 +38,11 @@
|
|||
# if defined (HAVE_TERMIO_H)
|
||||
# define TERMIO_TTY_DRIVER
|
||||
# else
|
||||
# define NEW_TTY_DRIVER
|
||||
# if !defined (__MINGW32__)
|
||||
# define NEW_TTY_DRIVER
|
||||
# else
|
||||
# define NO_TTY_DRIVER
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -97,6 +97,21 @@ extern int _rl_read_mbstring PARAMS((int, char *, int));
|
|||
|
||||
extern int _rl_is_mbchar_matched PARAMS((char *, int, int, char *, int));
|
||||
|
||||
extern wchar_t _rl_char_value PARAMS((char *, int));
|
||||
extern int _rl_walphabetic PARAMS((wchar_t));
|
||||
|
||||
#define _rl_to_wupper(wc) (iswlower (wc) ? towupper (wc) : (wc))
|
||||
#define _rl_to_wlower(wc) (iswupper (wc) ? towlower (wc) : (wc))
|
||||
|
||||
#define MB_NEXTCHAR(b,s,c,f) \
|
||||
((MB_CUR_MAX > 1 && rl_byte_oriented == 0) \
|
||||
? _rl_find_next_mbchar ((b), (s), (c), (f)) \
|
||||
: ((s) + (c)))
|
||||
#define MB_PREVCHAR(b,s,f) \
|
||||
((MB_CUR_MAX > 1 && rl_byte_oriented == 0) \
|
||||
? _rl_find_prev_mbchar ((b), (s), (f)) \
|
||||
: ((s) - 1))
|
||||
|
||||
#define MB_INVALIDCH(x) ((x) == (size_t)-1 || (x) == (size_t)-2)
|
||||
#define MB_NULLWCH(x) ((x) == 0)
|
||||
|
||||
|
|
@ -111,6 +126,16 @@ extern int _rl_is_mbchar_matched PARAMS((char *, int, int, char *, int));
|
|||
#define _rl_find_prev_mbchar(b, i, f) (((i) == 0) ? (i) : ((i) - 1))
|
||||
#define _rl_find_next_mbchar(b, i1, i2, f) ((i1) + (i2))
|
||||
|
||||
#define _rl_char_value(buf,ind) ((buf)[(ind)])
|
||||
|
||||
#define _rl_walphabetic(c) (rl_alphabetic (c))
|
||||
|
||||
#define _rl_to_wupper(c) (_rl_to_upper (c))
|
||||
#define _rl_to_wlower(c) (_rl_to_lower (c))
|
||||
|
||||
#define MB_NEXTCHAR(b,s,c,f) ((s) + (c))
|
||||
#define MB_PREVCHAR(b,s,f) ((s) - 1)
|
||||
|
||||
#define MB_INVALIDCH(x) (0)
|
||||
#define MB_NULLWCH(x) (0)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* rlprivate.h -- functions and variables global to the readline library,
|
||||
but not intended for use by applications. */
|
||||
|
||||
/* Copyright (C) 1999-2004 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1999-2005 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.
|
||||
|
|
@ -28,6 +28,95 @@
|
|||
#include "rlstdc.h"
|
||||
#include "posixjmp.h" /* defines procenv_t */
|
||||
|
||||
/*************************************************************************
|
||||
* *
|
||||
* Global structs undocumented in texinfo manual and not in readline.h *
|
||||
* *
|
||||
*************************************************************************/
|
||||
/* search types */
|
||||
#define RL_SEARCH_ISEARCH 0x01 /* incremental search */
|
||||
#define RL_SEARCH_NSEARCH 0x02 /* non-incremental search */
|
||||
#define RL_SEARCH_CSEARCH 0x04 /* intra-line char search */
|
||||
|
||||
/* search flags */
|
||||
#define SF_REVERSE 0x01
|
||||
#define SF_FOUND 0x02
|
||||
#define SF_FAILED 0x04
|
||||
|
||||
typedef struct __rl_search_context
|
||||
{
|
||||
int type;
|
||||
int sflags;
|
||||
|
||||
char *search_string;
|
||||
int search_string_index;
|
||||
int search_string_size;
|
||||
|
||||
char **lines;
|
||||
char *allocated_line;
|
||||
int hlen;
|
||||
int hindex;
|
||||
|
||||
int save_point;
|
||||
int save_mark;
|
||||
int save_line;
|
||||
int last_found_line;
|
||||
char *prev_line_found;
|
||||
|
||||
UNDO_LIST *save_undo_list;
|
||||
|
||||
int history_pos;
|
||||
int direction;
|
||||
|
||||
int lastc;
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
char mb[MB_LEN_MAX];
|
||||
#endif
|
||||
|
||||
char *sline;
|
||||
int sline_len;
|
||||
int sline_index;
|
||||
|
||||
char *search_terminators;
|
||||
} _rl_search_cxt;
|
||||
|
||||
/* Callback data for reading numeric arguments */
|
||||
#define NUM_SAWMINUS 0x01
|
||||
#define NUM_SAWDIGITS 0x02
|
||||
#define NUM_READONE 0x04
|
||||
|
||||
typedef int _rl_arg_cxt;
|
||||
|
||||
/* A context for reading key sequences longer than a single character when
|
||||
using the callback interface. */
|
||||
#define KSEQ_DISPATCHED 0x01
|
||||
#define KSEQ_SUBSEQ 0x02
|
||||
#define KSEQ_RECURSIVE 0x04
|
||||
|
||||
typedef struct __rl_keyseq_context
|
||||
{
|
||||
int flags;
|
||||
int subseq_arg;
|
||||
int subseq_retval; /* XXX */
|
||||
Keymap dmap;
|
||||
|
||||
Keymap oldmap;
|
||||
int okey;
|
||||
struct __rl_keyseq_context *ocxt;
|
||||
int childval;
|
||||
} _rl_keyseq_cxt;
|
||||
|
||||
/* fill in more as needed */
|
||||
/* `Generic' callback data and functions */
|
||||
typedef struct __rl_callback_generic_arg
|
||||
{
|
||||
int count;
|
||||
int i1, i2;
|
||||
/* add here as needed */
|
||||
} _rl_callback_generic_arg;
|
||||
|
||||
typedef int _rl_callback_func_t PARAMS((_rl_callback_generic_arg *));
|
||||
|
||||
/*************************************************************************
|
||||
* *
|
||||
* Global functions undocumented in texinfo manual and not in readline.h *
|
||||
|
|
@ -54,6 +143,8 @@ extern int readline_echoing_p;
|
|||
extern int rl_key_sequence_length;
|
||||
extern int rl_byte_oriented;
|
||||
|
||||
extern _rl_keyseq_cxt *_rl_kscxt;
|
||||
|
||||
/* display.c */
|
||||
extern int rl_display_fixed;
|
||||
|
||||
|
|
@ -100,6 +191,16 @@ extern void readline_internal_setup PARAMS((void));
|
|||
extern char *readline_internal_teardown PARAMS((int));
|
||||
extern int readline_internal_char PARAMS((void));
|
||||
|
||||
extern _rl_keyseq_cxt *_rl_keyseq_cxt_alloc PARAMS((void));
|
||||
extern void _rl_keyseq_cxt_dispose PARAMS((_rl_keyseq_cxt *));
|
||||
extern void _rl_keyseq_chain_dispose PARAMS((void));
|
||||
|
||||
extern int _rl_dispatch_callback PARAMS((_rl_keyseq_cxt *));
|
||||
|
||||
/* callback.c */
|
||||
extern _rl_callback_generic_arg *_rl_callback_data_alloc PARAMS((int));
|
||||
extern void _rl_callback_data_dispose PARAMS((_rl_callback_generic_arg *));
|
||||
|
||||
#endif /* READLINE_CALLBACKS */
|
||||
|
||||
/* bind.c */
|
||||
|
|
@ -132,6 +233,15 @@ extern void _rl_insert_typein PARAMS((int));
|
|||
extern int _rl_unget_char PARAMS((int));
|
||||
extern int _rl_pushed_input_available PARAMS((void));
|
||||
|
||||
/* isearch.c */
|
||||
extern _rl_search_cxt *_rl_scxt_alloc PARAMS((int, int));
|
||||
extern void _rl_scxt_dispose PARAMS((_rl_search_cxt *, int));
|
||||
|
||||
extern int _rl_isearch_dispatch PARAMS((_rl_search_cxt *, int));
|
||||
extern int _rl_isearch_callback PARAMS((_rl_search_cxt *));
|
||||
|
||||
extern int _rl_search_getchar PARAMS((_rl_search_cxt *));
|
||||
|
||||
/* macro.c */
|
||||
extern void _rl_with_macro_input PARAMS((char *));
|
||||
extern int _rl_next_macro_key PARAMS((void));
|
||||
|
|
@ -141,7 +251,12 @@ extern void _rl_add_macro_char PARAMS((int));
|
|||
extern void _rl_kill_kbd_macro PARAMS((void));
|
||||
|
||||
/* misc.c */
|
||||
extern int _rl_init_argument PARAMS((void));
|
||||
extern int _rl_arg_overflow PARAMS((void));
|
||||
extern void _rl_arg_init PARAMS((void));
|
||||
extern int _rl_arg_getchar PARAMS((void));
|
||||
extern int _rl_arg_callback PARAMS((_rl_arg_cxt));
|
||||
extern void _rl_reset_argument PARAMS((void));
|
||||
|
||||
extern void _rl_start_using_history PARAMS((void));
|
||||
extern int _rl_free_saved_history_line PARAMS((void));
|
||||
extern void _rl_set_insert_mode PARAMS((int, int));
|
||||
|
|
@ -157,11 +272,15 @@ extern void _rl_init_line_state PARAMS((void));
|
|||
extern void _rl_set_the_line PARAMS((void));
|
||||
extern int _rl_dispatch PARAMS((int, Keymap));
|
||||
extern int _rl_dispatch_subseq PARAMS((int, Keymap, int));
|
||||
extern void _rl_internal_char_cleanup PARAMS((void));
|
||||
|
||||
/* rltty.c */
|
||||
extern int _rl_disable_tty_signals PARAMS((void));
|
||||
extern int _rl_restore_tty_signals PARAMS((void));
|
||||
|
||||
/* search.c */
|
||||
extern int _rl_nsearch_callback PARAMS((_rl_search_cxt *));
|
||||
|
||||
/* terminal.c */
|
||||
extern void _rl_get_screen_size PARAMS((int, int));
|
||||
extern int _rl_init_terminal_io PARAMS((const char *));
|
||||
|
|
@ -217,6 +336,10 @@ extern void _rl_vi_done_inserting PARAMS((void));
|
|||
extern const char *_rl_possible_control_prefixes[];
|
||||
extern const char *_rl_possible_meta_prefixes[];
|
||||
|
||||
/* callback.c */
|
||||
extern _rl_callback_func_t *_rl_callback_func;
|
||||
extern _rl_callback_generic_arg *_rl_callback_data;
|
||||
|
||||
/* complete.c */
|
||||
extern int _rl_complete_show_all;
|
||||
extern int _rl_complete_show_unmodified;
|
||||
|
|
@ -231,11 +354,14 @@ extern int _rl_page_completions;
|
|||
extern int _rl_vis_botlin;
|
||||
extern int _rl_last_c_pos;
|
||||
extern int _rl_suppress_redisplay;
|
||||
extern int _rl_want_redisplay;
|
||||
extern char *rl_display_prompt;
|
||||
|
||||
/* isearch.c */
|
||||
extern char *_rl_isearch_terminators;
|
||||
|
||||
extern _rl_search_cxt *_rl_iscxt;
|
||||
|
||||
/* macro.c */
|
||||
extern char *_rl_executing_macro;
|
||||
|
||||
|
|
@ -243,6 +369,8 @@ extern char *_rl_executing_macro;
|
|||
extern int _rl_history_preserve_point;
|
||||
extern int _rl_history_saved_point;
|
||||
|
||||
extern _rl_arg_cxt _rl_argcxt;
|
||||
|
||||
/* readline.c */
|
||||
extern int _rl_horizontal_scroll_mode;
|
||||
extern int _rl_mark_modified_lines;
|
||||
|
|
@ -250,6 +378,7 @@ extern int _rl_bell_preference;
|
|||
extern int _rl_meta_flag;
|
||||
extern int _rl_convert_meta_chars_to_ascii;
|
||||
extern int _rl_output_meta_chars;
|
||||
extern int _rl_bind_stty_chars;
|
||||
extern char *_rl_comment_begin;
|
||||
extern unsigned char _rl_parsing_conditionalized_out;
|
||||
extern Keymap _rl_keymap;
|
||||
|
|
@ -259,6 +388,9 @@ extern int _rl_last_command_was_kill;
|
|||
extern int _rl_eof_char;
|
||||
extern procenv_t readline_top_level;
|
||||
|
||||
/* search.c */
|
||||
extern _rl_search_cxt *_rl_nscxt;
|
||||
|
||||
/* terminal.c */
|
||||
extern int _rl_enable_keypad;
|
||||
extern int _rl_enable_meta;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* rltty.c -- functions to prepare and restore the terminal for readline's
|
||||
use. */
|
||||
|
||||
/* Copyright (C) 1992 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1992-2005 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.
|
||||
|
|
@ -152,7 +152,9 @@ set_winsize (tty)
|
|||
#endif /* TIOCGWINSZ */
|
||||
}
|
||||
|
||||
#if defined (NEW_TTY_DRIVER)
|
||||
#if defined (NO_TTY_DRIVER)
|
||||
/* Nothing */
|
||||
#elif defined (NEW_TTY_DRIVER)
|
||||
|
||||
/* Values for the `flags' field of a struct bsdtty. This tells which
|
||||
elements of the struct bsdtty have been fetched from the system and
|
||||
|
|
@ -233,6 +235,7 @@ get_tty_settings (tty, tiop)
|
|||
|
||||
tiop->flags = tiop->lflag = 0;
|
||||
|
||||
errno = 0;
|
||||
if (ioctl (tty, TIOCGETP, &(tiop->sgttyb)) < 0)
|
||||
return -1;
|
||||
tiop->flags |= SGTTY_SET;
|
||||
|
|
@ -518,6 +521,7 @@ get_tty_settings (tty, tiop)
|
|||
{
|
||||
set_winsize (tty);
|
||||
|
||||
errno = 0;
|
||||
if (_get_tty_settings (tty, tiop) < 0)
|
||||
return -1;
|
||||
|
||||
|
|
@ -631,9 +635,23 @@ prepare_terminal_settings (meta_flag, oldtio, tiop)
|
|||
|
||||
#endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */
|
||||
}
|
||||
#endif /* NEW_TTY_DRIVER */
|
||||
#endif /* !NEW_TTY_DRIVER */
|
||||
|
||||
/* Put the terminal in CBREAK mode so that we can detect key presses. */
|
||||
#if defined (NO_TTY_DRIVER)
|
||||
void
|
||||
rl_prep_terminal (meta_flag)
|
||||
int meta_flag;
|
||||
{
|
||||
readline_echoing_p = 1;
|
||||
}
|
||||
|
||||
void
|
||||
rl_deprep_terminal ()
|
||||
{
|
||||
}
|
||||
|
||||
#else /* ! NO_TTY_DRIVER */
|
||||
void
|
||||
rl_prep_terminal (meta_flag)
|
||||
int meta_flag;
|
||||
|
|
@ -651,16 +669,43 @@ rl_prep_terminal (meta_flag)
|
|||
|
||||
if (get_tty_settings (tty, &tio) < 0)
|
||||
{
|
||||
#if defined (ENOTSUP)
|
||||
/* MacOS X, at least, lies about the value of errno if tcgetattr fails. */
|
||||
if (errno == ENOTTY || errno == ENOTSUP)
|
||||
#else
|
||||
if (errno == ENOTTY)
|
||||
#endif
|
||||
readline_echoing_p = 1; /* XXX */
|
||||
release_sigint ();
|
||||
return;
|
||||
}
|
||||
|
||||
otio = tio;
|
||||
|
||||
rl_tty_unset_default_bindings (_rl_keymap);
|
||||
if (_rl_bind_stty_chars)
|
||||
{
|
||||
#if defined (VI_MODE)
|
||||
/* If editing in vi mode, make sure we restore the bindings in the
|
||||
insertion keymap no matter what keymap we ended up in. */
|
||||
if (rl_editing_mode == vi_mode)
|
||||
rl_tty_unset_default_bindings (vi_insertion_keymap);
|
||||
else
|
||||
#endif
|
||||
rl_tty_unset_default_bindings (_rl_keymap);
|
||||
}
|
||||
save_tty_chars (&otio);
|
||||
RL_SETSTATE(RL_STATE_TTYCSAVED);
|
||||
_rl_bind_tty_special_chars (_rl_keymap, tio);
|
||||
if (_rl_bind_stty_chars)
|
||||
{
|
||||
#if defined (VI_MODE)
|
||||
/* If editing in vi mode, make sure we set the bindings in the
|
||||
insertion keymap no matter what keymap we ended up in. */
|
||||
if (rl_editing_mode == vi_mode)
|
||||
_rl_bind_tty_special_chars (vi_insertion_keymap, tio);
|
||||
else
|
||||
#endif
|
||||
_rl_bind_tty_special_chars (_rl_keymap, tio);
|
||||
}
|
||||
|
||||
prepare_terminal_settings (meta_flag, otio, &tio);
|
||||
|
||||
|
|
@ -710,6 +755,7 @@ rl_deprep_terminal ()
|
|||
|
||||
release_sigint ();
|
||||
}
|
||||
#endif /* !NO_TTY_DRIVER */
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
|
|
@ -721,6 +767,10 @@ int
|
|||
rl_restart_output (count, key)
|
||||
int count, key;
|
||||
{
|
||||
#if defined (__MINGW32__)
|
||||
return 0;
|
||||
#else /* !__MING32__ */
|
||||
|
||||
int fildes = fileno (rl_outstream);
|
||||
#if defined (TIOCSTART)
|
||||
#if defined (apollo)
|
||||
|
|
@ -748,12 +798,17 @@ rl_restart_output (count, key)
|
|||
#endif /* !TIOCSTART */
|
||||
|
||||
return 0;
|
||||
#endif /* !__MINGW32__ */
|
||||
}
|
||||
|
||||
int
|
||||
rl_stop_output (count, key)
|
||||
int count, key;
|
||||
{
|
||||
#if defined (__MINGW32__)
|
||||
return 0;
|
||||
#else
|
||||
|
||||
int fildes = fileno (rl_instream);
|
||||
|
||||
#if defined (TIOCSTOP)
|
||||
|
|
@ -776,6 +831,7 @@ rl_stop_output (count, key)
|
|||
#endif /* !TIOCSTOP */
|
||||
|
||||
return 0;
|
||||
#endif /* !__MINGW32__ */
|
||||
}
|
||||
|
||||
/* **************************************************************** */
|
||||
|
|
@ -784,9 +840,16 @@ rl_stop_output (count, key)
|
|||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
#if !defined (NO_TTY_DRIVER)
|
||||
#define SET_SPECIAL(sc, func) set_special_char(kmap, &ttybuff, sc, func)
|
||||
#endif
|
||||
|
||||
#if defined (NEW_TTY_DRIVER)
|
||||
#if defined (NO_TTY_DRIVER)
|
||||
|
||||
#define SET_SPECIAL(sc, func)
|
||||
#define RESET_SPECIAL(c)
|
||||
|
||||
#elif defined (NEW_TTY_DRIVER)
|
||||
static void
|
||||
set_special_char (kmap, tiop, sc, func)
|
||||
Keymap kmap;
|
||||
|
|
@ -867,6 +930,7 @@ void
|
|||
rltty_set_default_bindings (kmap)
|
||||
Keymap kmap;
|
||||
{
|
||||
#if !defined (NO_TTY_DRIVER)
|
||||
TIOTYPE ttybuff;
|
||||
int tty;
|
||||
static int called = 0;
|
||||
|
|
@ -875,6 +939,7 @@ rltty_set_default_bindings (kmap)
|
|||
|
||||
if (get_tty_settings (tty, &ttybuff) == 0)
|
||||
_rl_bind_tty_special_chars (kmap, ttybuff);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* New public way to set the system default editing chars to their readline
|
||||
|
|
@ -912,7 +977,7 @@ rl_tty_unset_default_bindings (kmap)
|
|||
|
||||
#if defined (HANDLE_SIGNALS)
|
||||
|
||||
#if defined (NEW_TTY_DRIVER)
|
||||
#if defined (NEW_TTY_DRIVER) || defined (NO_TTY_DRIVER)
|
||||
int
|
||||
_rl_disable_tty_signals ()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* search.c - code for non-incremental searching in emacs and vi modes. */
|
||||
|
||||
/* Copyright (C) 1992 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1992-2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the Readline Library (the Library), a set of
|
||||
routines for providing Emacs style line input to programs that ask
|
||||
|
|
@ -53,6 +53,8 @@
|
|||
#endif
|
||||
#define abs(x) (((x) >= 0) ? (x) : -(x))
|
||||
|
||||
_rl_search_cxt *_rl_nscxt = 0;
|
||||
|
||||
extern HIST_ENTRY *_rl_saved_line_for_history;
|
||||
|
||||
/* Functions imported from the rest of the library. */
|
||||
|
|
@ -68,13 +70,19 @@ static int rl_history_search_pos;
|
|||
static char *history_search_string;
|
||||
static int history_string_size;
|
||||
|
||||
static UNDO_LIST *noninc_saved_undo_list;
|
||||
static void make_history_line_current PARAMS((HIST_ENTRY *));
|
||||
static int noninc_search_from_pos PARAMS((char *, int, int));
|
||||
static void noninc_dosearch PARAMS((char *, int));
|
||||
static void noninc_search PARAMS((int, int));
|
||||
static int noninc_dosearch PARAMS((char *, int));
|
||||
static int noninc_search PARAMS((int, int));
|
||||
static int rl_history_search_internal PARAMS((int, int));
|
||||
static void rl_history_search_reinit PARAMS((void));
|
||||
|
||||
static _rl_search_cxt *_rl_nsearch_init PARAMS((int, int));
|
||||
static int _rl_nsearch_cleanup PARAMS((_rl_search_cxt *, int));
|
||||
static void _rl_nsearch_abort PARAMS((_rl_search_cxt *));
|
||||
static int _rl_nsearch_dispatch PARAMS((_rl_search_cxt *, int));
|
||||
|
||||
/* Make the data from the history entry ENTRY be the contents of the
|
||||
current line. This doesn't do anything with rl_point; the caller
|
||||
must set it. */
|
||||
|
|
@ -82,12 +90,15 @@ static void
|
|||
make_history_line_current (entry)
|
||||
HIST_ENTRY *entry;
|
||||
{
|
||||
#if 0
|
||||
rl_replace_line (entry->line, 1);
|
||||
rl_undo_list = (UNDO_LIST *)entry->data;
|
||||
#else
|
||||
_rl_replace_text (entry->line, 0, rl_end);
|
||||
_rl_fix_point (1);
|
||||
#if defined (VI_MODE)
|
||||
if (rl_editing_mode == vi_mode)
|
||||
/* POSIX.2 says that the `U' command doesn't affect the copy of any
|
||||
command lines to the edit line. We're going to implement that by
|
||||
making the undo list start after the matching line is copied to the
|
||||
current editing buffer. */
|
||||
rl_free_undo_list ();
|
||||
#endif
|
||||
|
||||
if (_rl_saved_line_for_history)
|
||||
|
|
@ -130,8 +141,8 @@ noninc_search_from_pos (string, pos, dir)
|
|||
|
||||
/* Search for a line in the history containing STRING. If DIR is < 0, the
|
||||
search is backwards through previous entries, else through subsequent
|
||||
entries. */
|
||||
static void
|
||||
entries. Returns 1 if the search was successful, 0 otherwise. */
|
||||
static int
|
||||
noninc_dosearch (string, dir)
|
||||
char *string;
|
||||
int dir;
|
||||
|
|
@ -142,7 +153,7 @@ noninc_dosearch (string, dir)
|
|||
if (string == 0 || *string == '\0' || noninc_history_pos < 0)
|
||||
{
|
||||
rl_ding ();
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pos = noninc_search_from_pos (string, noninc_history_pos + dir, dir);
|
||||
|
|
@ -153,7 +164,7 @@ noninc_dosearch (string, dir)
|
|||
rl_clear_message ();
|
||||
rl_point = 0;
|
||||
rl_ding ();
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
noninc_history_pos = pos;
|
||||
|
|
@ -164,7 +175,7 @@ noninc_dosearch (string, dir)
|
|||
#if defined (VI_MODE)
|
||||
if (rl_editing_mode != vi_mode)
|
||||
#endif
|
||||
history_set_pos (oldpos);
|
||||
history_set_pos (oldpos);
|
||||
|
||||
make_history_line_current (entry);
|
||||
|
||||
|
|
@ -172,27 +183,24 @@ noninc_dosearch (string, dir)
|
|||
rl_mark = rl_end;
|
||||
|
||||
rl_clear_message ();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Search non-interactively through the history list. DIR < 0 means to
|
||||
search backwards through the history of previous commands; otherwise
|
||||
the search is for commands subsequent to the current position in the
|
||||
history list. PCHAR is the character to use for prompting when reading
|
||||
the search string; if not specified (0), it defaults to `:'. */
|
||||
static void
|
||||
noninc_search (dir, pchar)
|
||||
int dir;
|
||||
int pchar;
|
||||
static _rl_search_cxt *
|
||||
_rl_nsearch_init (dir, pchar)
|
||||
int dir, pchar;
|
||||
{
|
||||
int saved_point, saved_mark, c;
|
||||
_rl_search_cxt *cxt;
|
||||
char *p;
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
char mb[MB_LEN_MAX];
|
||||
#endif
|
||||
|
||||
cxt = _rl_scxt_alloc (RL_SEARCH_NSEARCH, 0);
|
||||
if (dir < 0)
|
||||
cxt->sflags |= SF_REVERSE; /* not strictly needed */
|
||||
|
||||
cxt->direction = dir;
|
||||
cxt->history_pos = cxt->save_line;
|
||||
|
||||
rl_maybe_save_line ();
|
||||
saved_point = rl_point;
|
||||
saved_mark = rl_mark;
|
||||
|
||||
/* Clear the undo list, since reading the search string should create its
|
||||
own undo list, and the whole list will end up being freed when we
|
||||
|
|
@ -207,99 +215,169 @@ noninc_search (dir, pchar)
|
|||
rl_message (p, 0, 0);
|
||||
free (p);
|
||||
|
||||
#define SEARCH_RETURN rl_restore_prompt (); RL_UNSETSTATE(RL_STATE_NSEARCH); return
|
||||
|
||||
RL_SETSTATE(RL_STATE_NSEARCH);
|
||||
/* Read the search string. */
|
||||
while (1)
|
||||
{
|
||||
RL_SETSTATE(RL_STATE_MOREINPUT);
|
||||
c = rl_read_key ();
|
||||
RL_UNSETSTATE(RL_STATE_MOREINPUT);
|
||||
|
||||
_rl_nscxt = cxt;
|
||||
|
||||
return cxt;
|
||||
}
|
||||
|
||||
static int
|
||||
_rl_nsearch_cleanup (cxt, r)
|
||||
_rl_search_cxt *cxt;
|
||||
int r;
|
||||
{
|
||||
_rl_scxt_dispose (cxt, 0);
|
||||
_rl_nscxt = 0;
|
||||
|
||||
RL_UNSETSTATE(RL_STATE_NSEARCH);
|
||||
|
||||
return (r != 1);
|
||||
}
|
||||
|
||||
static void
|
||||
_rl_nsearch_abort (cxt)
|
||||
_rl_search_cxt *cxt;
|
||||
{
|
||||
rl_maybe_unsave_line ();
|
||||
rl_clear_message ();
|
||||
rl_point = cxt->save_point;
|
||||
rl_mark = cxt->save_mark;
|
||||
rl_restore_prompt ();
|
||||
|
||||
RL_UNSETSTATE (RL_STATE_NSEARCH);
|
||||
}
|
||||
|
||||
/* Process just-read character C according to search context CXT. Return -1
|
||||
if the caller should abort the search, 0 if we should break out of the
|
||||
loop, and 1 if we should continue to read characters. */
|
||||
static int
|
||||
_rl_nsearch_dispatch (cxt, c)
|
||||
_rl_search_cxt *cxt;
|
||||
int c;
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case CTRL('W'):
|
||||
rl_unix_word_rubout (1, c);
|
||||
break;
|
||||
|
||||
case CTRL('U'):
|
||||
rl_unix_line_discard (1, c);
|
||||
break;
|
||||
|
||||
case RETURN:
|
||||
case NEWLINE:
|
||||
return 0;
|
||||
|
||||
case CTRL('H'):
|
||||
case RUBOUT:
|
||||
if (rl_point == 0)
|
||||
{
|
||||
_rl_nsearch_abort (cxt);
|
||||
return -1;
|
||||
}
|
||||
_rl_rubout_char (1, c);
|
||||
break;
|
||||
|
||||
case CTRL('C'):
|
||||
case CTRL('G'):
|
||||
rl_ding ();
|
||||
_rl_nsearch_abort (cxt);
|
||||
return -1;
|
||||
|
||||
default:
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
c = _rl_read_mbstring (c, mb, MB_LEN_MAX);
|
||||
rl_insert_text (cxt->mb);
|
||||
else
|
||||
#endif
|
||||
|
||||
if (c == 0)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case CTRL('H'):
|
||||
case RUBOUT:
|
||||
if (rl_point == 0)
|
||||
{
|
||||
rl_maybe_unsave_line ();
|
||||
rl_clear_message ();
|
||||
rl_point = saved_point;
|
||||
rl_mark = saved_mark;
|
||||
SEARCH_RETURN;
|
||||
}
|
||||
_rl_rubout_char (1, c);
|
||||
break;
|
||||
|
||||
case CTRL('W'):
|
||||
rl_unix_word_rubout (1, c);
|
||||
break;
|
||||
|
||||
case CTRL('U'):
|
||||
rl_unix_line_discard (1, c);
|
||||
break;
|
||||
|
||||
case RETURN:
|
||||
case NEWLINE:
|
||||
goto dosearch;
|
||||
/* NOTREACHED */
|
||||
break;
|
||||
|
||||
case CTRL('C'):
|
||||
case CTRL('G'):
|
||||
rl_maybe_unsave_line ();
|
||||
rl_clear_message ();
|
||||
rl_point = saved_point;
|
||||
rl_mark = saved_mark;
|
||||
rl_ding ();
|
||||
SEARCH_RETURN;
|
||||
|
||||
default:
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
rl_insert_text (mb);
|
||||
else
|
||||
#endif
|
||||
_rl_insert_char (1, c);
|
||||
break;
|
||||
}
|
||||
(*rl_redisplay_function) ();
|
||||
_rl_insert_char (1, c);
|
||||
break;
|
||||
}
|
||||
|
||||
dosearch:
|
||||
rl_mark = saved_mark;
|
||||
(*rl_redisplay_function) ();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Perform one search according to CXT, using NONINC_SEARCH_STRING. Return
|
||||
-1 if the search should be aborted, any other value means to clean up
|
||||
using _rl_nsearch_cleanup (). Returns 1 if the search was successful,
|
||||
0 otherwise. */
|
||||
static int
|
||||
_rl_nsearch_dosearch (cxt)
|
||||
_rl_search_cxt *cxt;
|
||||
{
|
||||
rl_mark = cxt->save_mark;
|
||||
|
||||
/* If rl_point == 0, we want to re-use the previous search string and
|
||||
start from the saved history position. If there's no previous search
|
||||
string, punt. */
|
||||
if (rl_point == 0)
|
||||
{
|
||||
if (!noninc_search_string)
|
||||
if (noninc_search_string == 0)
|
||||
{
|
||||
rl_ding ();
|
||||
SEARCH_RETURN;
|
||||
rl_restore_prompt ();
|
||||
RL_UNSETSTATE (RL_STATE_NSEARCH);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We want to start the search from the current history position. */
|
||||
noninc_history_pos = where_history ();
|
||||
noninc_history_pos = cxt->save_line;
|
||||
FREE (noninc_search_string);
|
||||
noninc_search_string = savestring (rl_line_buffer);
|
||||
|
||||
/* If we don't want the subsequent undo list generated by the search
|
||||
matching a history line to include the contents of the search string,
|
||||
we need to clear rl_line_buffer here. For now, we just clear the
|
||||
undo list generated by reading the search string. (If the search
|
||||
fails, the old undo list will be restored by rl_maybe_unsave_line.) */
|
||||
rl_free_undo_list ();
|
||||
}
|
||||
|
||||
rl_restore_prompt ();
|
||||
noninc_dosearch (noninc_search_string, dir);
|
||||
RL_UNSETSTATE(RL_STATE_NSEARCH);
|
||||
return (noninc_dosearch (noninc_search_string, cxt->direction));
|
||||
}
|
||||
|
||||
/* Search non-interactively through the history list. DIR < 0 means to
|
||||
search backwards through the history of previous commands; otherwise
|
||||
the search is for commands subsequent to the current position in the
|
||||
history list. PCHAR is the character to use for prompting when reading
|
||||
the search string; if not specified (0), it defaults to `:'. */
|
||||
static int
|
||||
noninc_search (dir, pchar)
|
||||
int dir;
|
||||
int pchar;
|
||||
{
|
||||
_rl_search_cxt *cxt;
|
||||
int c, r;
|
||||
|
||||
cxt = _rl_nsearch_init (dir, pchar);
|
||||
|
||||
if (RL_ISSTATE (RL_STATE_CALLBACK))
|
||||
return (0);
|
||||
|
||||
/* Read the search string. */
|
||||
r = 0;
|
||||
while (1)
|
||||
{
|
||||
c = _rl_search_getchar (cxt);
|
||||
|
||||
if (c == 0)
|
||||
break;
|
||||
|
||||
r = _rl_nsearch_dispatch (cxt, c);
|
||||
if (r < 0)
|
||||
return 1;
|
||||
else if (r == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
r = _rl_nsearch_dosearch (cxt);
|
||||
return ((r >= 0) ? _rl_nsearch_cleanup (cxt, r) : (r != 1));
|
||||
}
|
||||
|
||||
/* Search forward through the history list for a string. If the vi-mode
|
||||
|
|
@ -308,8 +386,7 @@ int
|
|||
rl_noninc_forward_search (count, key)
|
||||
int count, key;
|
||||
{
|
||||
noninc_search (1, (key == '?') ? '?' : 0);
|
||||
return 0;
|
||||
return noninc_search (1, (key == '?') ? '?' : 0);
|
||||
}
|
||||
|
||||
/* Reverse search the history list for a string. If the vi-mode code
|
||||
|
|
@ -318,8 +395,7 @@ int
|
|||
rl_noninc_reverse_search (count, key)
|
||||
int count, key;
|
||||
{
|
||||
noninc_search (-1, (key == '/') ? '/' : 0);
|
||||
return 0;
|
||||
return noninc_search (-1, (key == '/') ? '/' : 0);
|
||||
}
|
||||
|
||||
/* Search forward through the history list for the last string searched
|
||||
|
|
@ -328,13 +404,15 @@ int
|
|||
rl_noninc_forward_search_again (count, key)
|
||||
int count, key;
|
||||
{
|
||||
int r;
|
||||
|
||||
if (!noninc_search_string)
|
||||
{
|
||||
rl_ding ();
|
||||
return (-1);
|
||||
}
|
||||
noninc_dosearch (noninc_search_string, 1);
|
||||
return 0;
|
||||
r = noninc_dosearch (noninc_search_string, 1);
|
||||
return (r != 1);
|
||||
}
|
||||
|
||||
/* Reverse search in the history list for the last string searched
|
||||
|
|
@ -343,15 +421,34 @@ int
|
|||
rl_noninc_reverse_search_again (count, key)
|
||||
int count, key;
|
||||
{
|
||||
int r;
|
||||
|
||||
if (!noninc_search_string)
|
||||
{
|
||||
rl_ding ();
|
||||
return (-1);
|
||||
}
|
||||
noninc_dosearch (noninc_search_string, -1);
|
||||
return 0;
|
||||
r = noninc_dosearch (noninc_search_string, -1);
|
||||
return (r != 1);
|
||||
}
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
int
|
||||
_rl_nsearch_callback (cxt)
|
||||
_rl_search_cxt *cxt;
|
||||
{
|
||||
int c, r;
|
||||
|
||||
c = _rl_search_getchar (cxt);
|
||||
r = _rl_nsearch_dispatch (cxt, c);
|
||||
if (r != 0)
|
||||
return 1;
|
||||
|
||||
r = _rl_nsearch_dosearch (cxt);
|
||||
return ((r >= 0) ? _rl_nsearch_cleanup (cxt, r) : (r != 1));
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
rl_history_search_internal (count, dir)
|
||||
int count, dir;
|
||||
|
|
|
|||
|
|
@ -48,8 +48,12 @@
|
|||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_FCNTL_H)
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#if defined (HAVE_PWD_H)
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -57,9 +61,9 @@
|
|||
#include "rlshell.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
#if !defined (HAVE_GETPW_DECLS)
|
||||
#if defined (HAVE_GETPWUID) && !defined (HAVE_GETPW_DECLS)
|
||||
extern struct passwd *getpwuid PARAMS((uid_t));
|
||||
#endif /* !HAVE_GETPW_DECLS */
|
||||
#endif /* HAVE_GETPWUID && !HAVE_GETPW_DECLS */
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL 0
|
||||
|
|
@ -122,16 +126,7 @@ sh_set_lines_and_columns (lines, cols)
|
|||
{
|
||||
char *b;
|
||||
|
||||
#if defined (HAVE_PUTENV)
|
||||
b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("LINES=") + 1);
|
||||
sprintf (b, "LINES=%d", lines);
|
||||
putenv (b);
|
||||
|
||||
b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("COLUMNS=") + 1);
|
||||
sprintf (b, "COLUMNS=%d", cols);
|
||||
putenv (b);
|
||||
#else /* !HAVE_PUTENV */
|
||||
# if defined (HAVE_SETENV)
|
||||
#if defined (HAVE_SETENV)
|
||||
b = (char *)xmalloc (INT_STRLEN_BOUND (int) + 1);
|
||||
sprintf (b, "%d", lines);
|
||||
setenv ("LINES", b, 1);
|
||||
|
|
@ -141,8 +136,17 @@ sh_set_lines_and_columns (lines, cols)
|
|||
sprintf (b, "%d", cols);
|
||||
setenv ("COLUMNS", b, 1);
|
||||
free (b);
|
||||
# endif /* HAVE_SETENV */
|
||||
#endif /* !HAVE_PUTENV */
|
||||
#else /* !HAVE_SETENV */
|
||||
# if defined (HAVE_PUTENV)
|
||||
b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("LINES=") + 1);
|
||||
sprintf (b, "LINES=%d", lines);
|
||||
putenv (b);
|
||||
|
||||
b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("COLUMNS=") + 1);
|
||||
sprintf (b, "COLUMNS=%d", cols);
|
||||
putenv (b);
|
||||
# endif /* HAVE_PUTENV */
|
||||
#endif /* !HAVE_SETENV */
|
||||
}
|
||||
|
||||
char *
|
||||
|
|
@ -159,9 +163,11 @@ sh_get_home_dir ()
|
|||
struct passwd *entry;
|
||||
|
||||
home_dir = (char *)NULL;
|
||||
#if defined (HAVE_GETPWUID)
|
||||
entry = getpwuid (getuid ());
|
||||
if (entry)
|
||||
home_dir = entry->pw_dir;
|
||||
#endif
|
||||
return (home_dir);
|
||||
}
|
||||
|
||||
|
|
@ -175,6 +181,7 @@ int
|
|||
sh_unset_nodelay_mode (fd)
|
||||
int fd;
|
||||
{
|
||||
#if defined (HAVE_FCNTL)
|
||||
int flags, bflags;
|
||||
|
||||
if ((flags = fcntl (fd, F_GETFL, 0)) < 0)
|
||||
|
|
@ -195,6 +202,7 @@ sh_unset_nodelay_mode (fd)
|
|||
flags &= ~bflags;
|
||||
return (fcntl (fd, F_SETFL, flags));
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* signals.c -- signal handling support for readline. */
|
||||
|
||||
/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2005 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.
|
||||
|
|
@ -131,7 +131,11 @@ rl_signal_handler (sig)
|
|||
#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. */
|
||||
# if defined (SIGALRM)
|
||||
if (sig == SIGINT || sig == SIGALRM)
|
||||
# else
|
||||
if (sig == SIGINT)
|
||||
# endif
|
||||
rl_set_sighandler (sig, SIG_IGN, &dummy_cxt);
|
||||
#endif /* !HAVE_BSD_SIGNALS && !HAVE_POSIX_SIGNALS */
|
||||
|
||||
|
|
@ -141,14 +145,18 @@ rl_signal_handler (sig)
|
|||
rl_free_line_state ();
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case SIGTERM:
|
||||
#if defined (SIGTSTP)
|
||||
case SIGTSTP:
|
||||
case SIGTTOU:
|
||||
case SIGTTIN:
|
||||
#endif /* SIGTSTP */
|
||||
#if defined (SIGALRM)
|
||||
case SIGALRM:
|
||||
case SIGTERM:
|
||||
#endif
|
||||
#if defined (SIGQUIT)
|
||||
case SIGQUIT:
|
||||
#endif
|
||||
rl_cleanup_after_signal ();
|
||||
|
||||
#if defined (HAVE_POSIX_SIGNALS)
|
||||
|
|
@ -164,7 +172,11 @@ rl_signal_handler (sig)
|
|||
signal (sig, SIG_ACK);
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_KILL)
|
||||
kill (getpid (), sig);
|
||||
#else
|
||||
raise (sig); /* assume we have raise */
|
||||
#endif
|
||||
|
||||
/* Let the signal that we just sent through. */
|
||||
#if defined (HAVE_POSIX_SIGNALS)
|
||||
|
|
@ -281,8 +293,11 @@ rl_set_signals ()
|
|||
{
|
||||
rl_maybe_set_sighandler (SIGINT, rl_signal_handler, &old_int);
|
||||
rl_maybe_set_sighandler (SIGTERM, rl_signal_handler, &old_term);
|
||||
#if defined (SIGQUIT)
|
||||
rl_maybe_set_sighandler (SIGQUIT, rl_signal_handler, &old_quit);
|
||||
#endif
|
||||
|
||||
#if defined (SIGALRM)
|
||||
oh = rl_set_sighandler (SIGALRM, rl_signal_handler, &old_alrm);
|
||||
if (oh == (SigHandler *)SIG_IGN)
|
||||
rl_sigaction (SIGALRM, &old_alrm, &dummy);
|
||||
|
|
@ -294,6 +309,7 @@ rl_set_signals ()
|
|||
if (oh != (SigHandler *)SIG_DFL && (old_alrm.sa_flags & SA_RESTART))
|
||||
rl_sigaction (SIGALRM, &old_alrm, &dummy);
|
||||
#endif /* HAVE_POSIX_SIGNALS */
|
||||
#endif /* SIGALRM */
|
||||
|
||||
#if defined (SIGTSTP)
|
||||
rl_maybe_set_sighandler (SIGTSTP, rl_signal_handler, &old_tstp);
|
||||
|
|
@ -332,8 +348,12 @@ rl_clear_signals ()
|
|||
|
||||
rl_sigaction (SIGINT, &old_int, &dummy);
|
||||
rl_sigaction (SIGTERM, &old_term, &dummy);
|
||||
#if defined (SIGQUIT)
|
||||
rl_sigaction (SIGQUIT, &old_quit, &dummy);
|
||||
#endif
|
||||
#if defined (SIGALRM)
|
||||
rl_sigaction (SIGALRM, &old_alrm, &dummy);
|
||||
#endif
|
||||
|
||||
#if defined (SIGTSTP)
|
||||
rl_sigaction (SIGTSTP, &old_tstp, &dummy);
|
||||
|
|
@ -368,7 +388,8 @@ void
|
|||
rl_cleanup_after_signal ()
|
||||
{
|
||||
_rl_clean_up_for_exit ();
|
||||
(*rl_deprep_term_function) ();
|
||||
if (rl_deprep_term_function)
|
||||
(*rl_deprep_term_function) ();
|
||||
rl_clear_signals ();
|
||||
rl_clear_pending_input ();
|
||||
}
|
||||
|
|
@ -377,7 +398,8 @@ rl_cleanup_after_signal ()
|
|||
void
|
||||
rl_reset_after_signal ()
|
||||
{
|
||||
(*rl_prep_term_function) (_rl_meta_flag);
|
||||
if (rl_prep_term_function)
|
||||
(*rl_prep_term_function) (_rl_meta_flag);
|
||||
rl_set_signals ();
|
||||
}
|
||||
|
||||
|
|
@ -398,7 +420,7 @@ rl_free_line_state ()
|
|||
|
||||
_rl_kill_kbd_macro ();
|
||||
rl_clear_message ();
|
||||
_rl_init_argument ();
|
||||
_rl_reset_argument ();
|
||||
}
|
||||
|
||||
#endif /* HANDLE_SIGNALS */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* terminal.c -- controlling the terminal with termcap. */
|
||||
|
||||
/* Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1996-2005 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.
|
||||
|
|
@ -69,6 +69,8 @@
|
|||
#define CUSTOM_REDISPLAY_FUNC() (rl_redisplay_function != rl_redisplay)
|
||||
#define CUSTOM_INPUT_FUNC() (rl_getc_function != rl_getc)
|
||||
|
||||
int rl_prefer_env_winsize;
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* Terminal and Termcap */
|
||||
|
|
@ -145,6 +147,9 @@ static char *_rl_term_kh;
|
|||
static char *_rl_term_kH;
|
||||
static char *_rl_term_at7; /* @7 */
|
||||
|
||||
/* Delete key */
|
||||
static char *_rl_term_kD;
|
||||
|
||||
/* Insert key */
|
||||
static char *_rl_term_kI;
|
||||
|
||||
|
|
@ -191,12 +196,14 @@ _rl_get_screen_size (tty, ignore_env)
|
|||
#if defined (TIOCGWINSZ)
|
||||
struct winsize window_size;
|
||||
#endif /* TIOCGWINSZ */
|
||||
int wr, wc;
|
||||
|
||||
wr = wc = -1;
|
||||
#if defined (TIOCGWINSZ)
|
||||
if (ioctl (tty, TIOCGWINSZ, &window_size) == 0)
|
||||
{
|
||||
_rl_screenwidth = (int) window_size.ws_col;
|
||||
_rl_screenheight = (int) window_size.ws_row;
|
||||
wc = (int) window_size.ws_col;
|
||||
wr = (int) window_size.ws_row;
|
||||
}
|
||||
#endif /* TIOCGWINSZ */
|
||||
|
||||
|
|
@ -204,13 +211,25 @@ _rl_get_screen_size (tty, ignore_env)
|
|||
_emx_get_screensize (&_rl_screenwidth, &_rl_screenheight);
|
||||
#endif
|
||||
|
||||
if (ignore_env || rl_prefer_env_winsize == 0)
|
||||
{
|
||||
_rl_screenwidth = wc;
|
||||
_rl_screenheight = wr;
|
||||
}
|
||||
else
|
||||
_rl_screenwidth = _rl_screenheight = -1;
|
||||
|
||||
/* Environment variable COLUMNS overrides setting of "co" if IGNORE_ENV
|
||||
is unset. */
|
||||
is unset. If we prefer the environment, check it first before
|
||||
assigning the value returned by the kernel. */
|
||||
if (_rl_screenwidth <= 0)
|
||||
{
|
||||
if (ignore_env == 0 && (ss = sh_get_env_value ("COLUMNS")))
|
||||
_rl_screenwidth = atoi (ss);
|
||||
|
||||
if (_rl_screenwidth <= 0)
|
||||
_rl_screenwidth = wc;
|
||||
|
||||
#if !defined (__DJGPP__)
|
||||
if (_rl_screenwidth <= 0 && term_string_buffer)
|
||||
_rl_screenwidth = tgetnum ("co");
|
||||
|
|
@ -224,6 +243,9 @@ _rl_get_screen_size (tty, ignore_env)
|
|||
if (ignore_env == 0 && (ss = sh_get_env_value ("LINES")))
|
||||
_rl_screenheight = atoi (ss);
|
||||
|
||||
if (_rl_screenheight <= 0)
|
||||
_rl_screenheight = wr;
|
||||
|
||||
#if !defined (__DJGPP__)
|
||||
if (_rl_screenheight <= 0 && term_string_buffer)
|
||||
_rl_screenheight = tgetnum ("li");
|
||||
|
|
@ -252,16 +274,17 @@ void
|
|||
_rl_set_screen_size (rows, cols)
|
||||
int rows, cols;
|
||||
{
|
||||
if (rows == 0 || cols == 0)
|
||||
return;
|
||||
if (rows > 0)
|
||||
_rl_screenheight = rows;
|
||||
if (cols > 0)
|
||||
{
|
||||
_rl_screenwidth = cols;
|
||||
if (_rl_term_autowrap == 0)
|
||||
_rl_screenwidth--;
|
||||
}
|
||||
|
||||
_rl_screenheight = rows;
|
||||
_rl_screenwidth = cols;
|
||||
|
||||
if (_rl_term_autowrap == 0)
|
||||
_rl_screenwidth--;
|
||||
|
||||
_rl_screenchars = _rl_screenwidth * _rl_screenheight;
|
||||
if (rows > 0 || cols > 0)
|
||||
_rl_screenchars = _rl_screenwidth * _rl_screenheight;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -280,6 +303,12 @@ rl_get_screen_size (rows, cols)
|
|||
if (cols)
|
||||
*cols = _rl_screenwidth;
|
||||
}
|
||||
|
||||
void
|
||||
rl_reset_screen_size ()
|
||||
{
|
||||
_rl_get_screen_size (fileno (rl_instream), 0);
|
||||
}
|
||||
|
||||
void
|
||||
rl_resize_terminal ()
|
||||
|
|
@ -313,6 +342,7 @@ static struct _tc_string tc_strings[] =
|
|||
{ "ei", &_rl_term_ei },
|
||||
{ "ic", &_rl_term_ic },
|
||||
{ "im", &_rl_term_im },
|
||||
{ "kD", &_rl_term_kD }, /* delete */
|
||||
{ "kH", &_rl_term_kH }, /* home down ?? */
|
||||
{ "kI", &_rl_term_kI }, /* insert */
|
||||
{ "kd", &_rl_term_kd },
|
||||
|
|
@ -363,7 +393,6 @@ _rl_init_terminal_io (terminal_name)
|
|||
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;
|
||||
_rl_screenwidth = _rl_screenheight = 0;
|
||||
|
||||
if (term == 0)
|
||||
term = "dumb";
|
||||
|
|
@ -396,12 +425,17 @@ _rl_init_terminal_io (terminal_name)
|
|||
|
||||
_rl_term_autowrap = 0; /* used by _rl_get_screen_size */
|
||||
|
||||
/* Allow calling application to set default height and width, using
|
||||
rl_set_screen_size */
|
||||
if (_rl_screenwidth <= 0 || _rl_screenheight <= 0)
|
||||
{
|
||||
#if defined (__EMX__)
|
||||
_emx_get_screensize (&_rl_screenwidth, &_rl_screenheight);
|
||||
_rl_screenwidth--;
|
||||
_emx_get_screensize (&_rl_screenwidth, &_rl_screenheight);
|
||||
_rl_screenwidth--;
|
||||
#else /* !__EMX__ */
|
||||
_rl_get_screen_size (tty, 0);
|
||||
_rl_get_screen_size (tty, 0);
|
||||
#endif /* !__EMX__ */
|
||||
}
|
||||
|
||||
/* Defaults. */
|
||||
if (_rl_screenwidth <= 0 || _rl_screenheight <= 0)
|
||||
|
|
@ -416,7 +450,7 @@ _rl_init_terminal_io (terminal_name)
|
|||
_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_kh = _rl_term_kH = _rl_term_kI = (char *)NULL;
|
||||
_rl_term_kh = _rl_term_kH = _rl_term_kI = _rl_term_kD = (char *)NULL;
|
||||
_rl_term_ks = _rl_term_ke = _rl_term_at7 = (char *)NULL;
|
||||
_rl_term_mm = _rl_term_mo = (char *)NULL;
|
||||
_rl_term_ve = _rl_term_vs = (char *)NULL;
|
||||
|
|
@ -448,7 +482,10 @@ _rl_init_terminal_io (terminal_name)
|
|||
|
||||
_rl_term_autowrap = tgetflag ("am") && tgetflag ("xn");
|
||||
|
||||
_rl_get_screen_size (tty, 0);
|
||||
/* Allow calling application to set default height and width, using
|
||||
rl_set_screen_size */
|
||||
if (_rl_screenwidth <= 0 || _rl_screenheight <= 0)
|
||||
_rl_get_screen_size (tty, 0);
|
||||
|
||||
/* "An application program can assume that the terminal can do
|
||||
character insertion if *any one of* the capabilities `IC',
|
||||
|
|
@ -493,6 +530,8 @@ bind_termcap_arrow_keys (map)
|
|||
rl_bind_keyseq_if_unbound (_rl_term_kh, rl_beg_of_line); /* Home */
|
||||
rl_bind_keyseq_if_unbound (_rl_term_at7, rl_end_of_line); /* End */
|
||||
|
||||
rl_bind_keyseq_if_unbound (_rl_term_kD, rl_delete);
|
||||
|
||||
_rl_keymap = xkeymap;
|
||||
}
|
||||
|
||||
|
|
@ -518,6 +557,7 @@ int
|
|||
rl_reset_terminal (terminal_name)
|
||||
const char *terminal_name;
|
||||
{
|
||||
_rl_screenwidth = _rl_screenheight = 0;
|
||||
_rl_init_terminal_io (terminal_name);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* text.c -- text handling commands for readline. */
|
||||
|
||||
/* Copyright (C) 1987-2004 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2005 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.
|
||||
|
|
@ -62,6 +62,11 @@
|
|||
static int rl_change_case PARAMS((int, int));
|
||||
static int _rl_char_search PARAMS((int, int, int));
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
static int _rl_insert_next_callback PARAMS((_rl_callback_generic_arg *));
|
||||
static int _rl_char_search_callback PARAMS((_rl_callback_generic_arg *));
|
||||
#endif
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* Insert and Delete */
|
||||
|
|
@ -420,8 +425,7 @@ rl_end_of_line (count, key)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* XXX - these might need changes for multibyte characters */
|
||||
/* Move forward a word. We do what Emacs does. */
|
||||
/* Move forward a word. We do what Emacs does. Handles multibyte chars. */
|
||||
int
|
||||
rl_forward_word (count, key)
|
||||
int count, key;
|
||||
|
|
@ -438,68 +442,80 @@ 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 = rl_line_buffer[rl_point];
|
||||
if (rl_alphabetic (c) == 0)
|
||||
c = _rl_char_value (rl_line_buffer, rl_point);
|
||||
|
||||
if (_rl_walphabetic (c) == 0)
|
||||
{
|
||||
while (++rl_point < rl_end)
|
||||
rl_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
|
||||
while (rl_point < rl_end)
|
||||
{
|
||||
c = rl_line_buffer[rl_point];
|
||||
if (rl_alphabetic (c))
|
||||
c = _rl_char_value (rl_line_buffer, rl_point);
|
||||
if (_rl_walphabetic (c))
|
||||
break;
|
||||
rl_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
|
||||
}
|
||||
}
|
||||
|
||||
if (rl_point == rl_end)
|
||||
return 0;
|
||||
|
||||
while (++rl_point < rl_end)
|
||||
rl_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
|
||||
while (rl_point < rl_end)
|
||||
{
|
||||
c = rl_line_buffer[rl_point];
|
||||
if (rl_alphabetic (c) == 0)
|
||||
c = _rl_char_value (rl_line_buffer, rl_point);
|
||||
if (_rl_walphabetic (c) == 0)
|
||||
break;
|
||||
rl_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
|
||||
}
|
||||
|
||||
--count;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Move backward a word. We do what Emacs does. */
|
||||
/* Move backward a word. We do what Emacs does. Handles multibyte chars. */
|
||||
int
|
||||
rl_backward_word (count, key)
|
||||
int count, key;
|
||||
{
|
||||
int c;
|
||||
int c, p;
|
||||
|
||||
if (count < 0)
|
||||
return (rl_forward_word (-count, key));
|
||||
|
||||
while (count)
|
||||
{
|
||||
if (!rl_point)
|
||||
if (rl_point == 0)
|
||||
return 0;
|
||||
|
||||
/* Like rl_forward_word (), except that we look at the characters
|
||||
just before point. */
|
||||
|
||||
c = rl_line_buffer[rl_point - 1];
|
||||
if (rl_alphabetic (c) == 0)
|
||||
p = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO);
|
||||
c = _rl_char_value (rl_line_buffer, p);
|
||||
|
||||
if (_rl_walphabetic (c) == 0)
|
||||
{
|
||||
while (--rl_point)
|
||||
rl_point = p;
|
||||
while (rl_point > 0)
|
||||
{
|
||||
c = rl_line_buffer[rl_point - 1];
|
||||
if (rl_alphabetic (c))
|
||||
p = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO);
|
||||
c = _rl_char_value (rl_line_buffer, p);
|
||||
if (_rl_walphabetic (c))
|
||||
break;
|
||||
rl_point = p;
|
||||
}
|
||||
}
|
||||
|
||||
while (rl_point)
|
||||
{
|
||||
c = rl_line_buffer[rl_point - 1];
|
||||
if (rl_alphabetic (c) == 0)
|
||||
p = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO);
|
||||
c = _rl_char_value (rl_line_buffer, p);
|
||||
if (_rl_walphabetic (c) == 0)
|
||||
break;
|
||||
else
|
||||
--rl_point;
|
||||
rl_point = p;
|
||||
}
|
||||
|
||||
--count;
|
||||
|
|
@ -756,10 +772,8 @@ _rl_insert_char (count, c)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX == 1 || rl_byte_oriented)
|
||||
{
|
||||
#endif
|
||||
/* We are inserting a single character.
|
||||
If there is pending input, then make a string of all of the
|
||||
pending characters that are bound to rl_insert, and insert
|
||||
|
|
@ -775,8 +789,8 @@ _rl_insert_char (count, c)
|
|||
str[0] = c;
|
||||
rl_insert_text (str);
|
||||
}
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
}
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
else
|
||||
{
|
||||
rl_insert_text (incoming);
|
||||
|
|
@ -833,27 +847,63 @@ rl_insert (count, c)
|
|||
}
|
||||
|
||||
/* Insert the next typed character verbatim. */
|
||||
int
|
||||
rl_quoted_insert (count, key)
|
||||
int count, key;
|
||||
static int
|
||||
_rl_insert_next (count)
|
||||
int count;
|
||||
{
|
||||
int c;
|
||||
|
||||
#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 ();
|
||||
if (RL_ISSTATE (RL_STATE_CALLBACK) == 0)
|
||||
_rl_restore_tty_signals ();
|
||||
#endif
|
||||
|
||||
return (_rl_insert_char (count, c));
|
||||
}
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
static int
|
||||
_rl_insert_next_callback (data)
|
||||
_rl_callback_generic_arg *data;
|
||||
{
|
||||
int count;
|
||||
|
||||
count = data->count;
|
||||
|
||||
/* Deregister function, let rl_callback_read_char deallocate data */
|
||||
_rl_callback_func = 0;
|
||||
_rl_want_redisplay = 1;
|
||||
|
||||
return _rl_insert_next (count);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
rl_quoted_insert (count, key)
|
||||
int count, key;
|
||||
{
|
||||
/* Let's see...should the callback interface futz with signal handling? */
|
||||
#if defined (HANDLE_SIGNALS)
|
||||
if (RL_ISSTATE (RL_STATE_CALLBACK) == 0)
|
||||
_rl_disable_tty_signals ();
|
||||
#endif
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
if (RL_ISSTATE (RL_STATE_CALLBACK))
|
||||
{
|
||||
_rl_callback_data = _rl_callback_data_alloc (count);
|
||||
_rl_callback_func = _rl_insert_next_callback;
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
return _rl_insert_next (count);
|
||||
}
|
||||
|
||||
/* Insert a tab character. */
|
||||
int
|
||||
rl_tab_insert (count, key)
|
||||
|
|
@ -988,43 +1038,17 @@ _rl_rubout_char (count, key)
|
|||
return -1;
|
||||
}
|
||||
|
||||
orig_point = rl_point;
|
||||
if (count > 1 || rl_explicit_arg)
|
||||
{
|
||||
orig_point = rl_point;
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
rl_backward_char (count, key);
|
||||
else
|
||||
#endif
|
||||
rl_backward_byte (count, key);
|
||||
rl_backward_char (count, key);
|
||||
rl_kill_text (orig_point, rl_point);
|
||||
}
|
||||
else
|
||||
else if (MB_CUR_MAX == 1 || rl_byte_oriented)
|
||||
{
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX == 1 || rl_byte_oriented)
|
||||
{
|
||||
#endif
|
||||
c = rl_line_buffer[--rl_point];
|
||||
rl_delete_text (rl_point, rl_point + 1);
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
}
|
||||
else
|
||||
{
|
||||
int orig_point;
|
||||
|
||||
orig_point = rl_point;
|
||||
rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO);
|
||||
c = rl_line_buffer[rl_point];
|
||||
rl_delete_text (rl_point, orig_point);
|
||||
}
|
||||
#endif /* HANDLE_MULTIBYTE */
|
||||
|
||||
/* I don't think that the hack for end of line is needed for
|
||||
multibyte chars. */
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX == 1 || rl_byte_oriented)
|
||||
#endif
|
||||
c = rl_line_buffer[--rl_point];
|
||||
rl_delete_text (rl_point, orig_point);
|
||||
/* The erase-at-end-of-line hack is of questionable merit now. */
|
||||
if (rl_point == rl_end && ISPRINT (c) && _rl_last_c_pos)
|
||||
{
|
||||
int l;
|
||||
|
|
@ -1032,6 +1056,11 @@ _rl_rubout_char (count, key)
|
|||
_rl_erase_at_end_of_line (l);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO);
|
||||
rl_delete_text (rl_point, orig_point);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1056,11 +1085,9 @@ rl_delete (count, key)
|
|||
if (count > 1 || rl_explicit_arg)
|
||||
{
|
||||
int orig_point = rl_point;
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
rl_forward_char (count, key);
|
||||
else
|
||||
#endif
|
||||
rl_forward_byte (count, key);
|
||||
|
||||
r = rl_kill_text (orig_point, rl_point);
|
||||
|
|
@ -1070,11 +1097,8 @@ rl_delete (count, key)
|
|||
else
|
||||
{
|
||||
int new_point;
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
new_point = _rl_find_next_mbchar (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
|
||||
else
|
||||
new_point = rl_point + 1;
|
||||
|
||||
|
||||
new_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
|
||||
return (rl_delete_text (rl_point, new_point));
|
||||
}
|
||||
}
|
||||
|
|
@ -1113,6 +1137,10 @@ rl_delete_horizontal_space (count, ignore)
|
|||
rl_delete_text (start, rl_point);
|
||||
rl_point = start;
|
||||
}
|
||||
|
||||
if (rl_point < 0)
|
||||
rl_point = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1206,42 +1234,80 @@ static int
|
|||
rl_change_case (count, op)
|
||||
int count, op;
|
||||
{
|
||||
register int start, end;
|
||||
int inword, c;
|
||||
int start, next, end;
|
||||
int inword, c, nc, nop;
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
wchar_t wc, nwc;
|
||||
char mb[MB_LEN_MAX+1];
|
||||
int mblen, p;
|
||||
mbstate_t ps;
|
||||
#endif
|
||||
|
||||
start = rl_point;
|
||||
rl_forward_word (count, 0);
|
||||
end = rl_point;
|
||||
|
||||
if (op != UpCase && op != DownCase && op != CapCase)
|
||||
{
|
||||
rl_ding ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (count < 0)
|
||||
SWAP (start, end);
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
memset (&ps, 0, sizeof (mbstate_t));
|
||||
#endif
|
||||
|
||||
/* We are going to modify some text, so let's prepare to undo it. */
|
||||
rl_modifying (start, end);
|
||||
|
||||
for (inword = 0; start < end; start++)
|
||||
inword = 0;
|
||||
while (start < end)
|
||||
{
|
||||
c = rl_line_buffer[start];
|
||||
switch (op)
|
||||
c = _rl_char_value (rl_line_buffer, start);
|
||||
/* This assumes that the upper and lower case versions are the same width. */
|
||||
next = MB_NEXTCHAR (rl_line_buffer, start, 1, MB_FIND_NONZERO);
|
||||
|
||||
if (_rl_walphabetic (c) == 0)
|
||||
{
|
||||
case UpCase:
|
||||
rl_line_buffer[start] = _rl_to_upper (c);
|
||||
break;
|
||||
|
||||
case DownCase:
|
||||
rl_line_buffer[start] = _rl_to_lower (c);
|
||||
break;
|
||||
|
||||
case CapCase:
|
||||
rl_line_buffer[start] = (inword == 0) ? _rl_to_upper (c) : _rl_to_lower (c);
|
||||
inword = rl_alphabetic (rl_line_buffer[start]);
|
||||
break;
|
||||
|
||||
default:
|
||||
rl_ding ();
|
||||
return -1;
|
||||
inword = 0;
|
||||
start = next;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (op == CapCase)
|
||||
{
|
||||
nop = inword ? DownCase : UpCase;
|
||||
inword = 1;
|
||||
}
|
||||
else
|
||||
nop = op;
|
||||
if (MB_CUR_MAX == 1 || rl_byte_oriented || isascii (c))
|
||||
{
|
||||
nc = (nop == UpCase) ? _rl_to_upper (c) : _rl_to_lower (c);
|
||||
rl_line_buffer[start] = nc;
|
||||
}
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
else
|
||||
{
|
||||
mbrtowc (&wc, rl_line_buffer + start, end - start, &ps);
|
||||
nwc = (nop == UpCase) ? _rl_to_wupper (wc) : _rl_to_wlower (wc);
|
||||
if (nwc != wc) /* just skip unchanged characters */
|
||||
{
|
||||
mblen = wcrtomb (mb, nwc, &ps);
|
||||
if (mblen > 0)
|
||||
mb[mblen] = '\0';
|
||||
/* Assume the same width */
|
||||
strncpy (rl_line_buffer + start, mb, mblen);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
start = next;
|
||||
}
|
||||
|
||||
rl_point = end;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1321,11 +1387,11 @@ rl_transpose_chars (count, key)
|
|||
{
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
char *dummy;
|
||||
int i, prev_point;
|
||||
int i;
|
||||
#else
|
||||
char dummy[2];
|
||||
#endif
|
||||
int char_length;
|
||||
int char_length, prev_point;
|
||||
|
||||
if (count == 0)
|
||||
return 0;
|
||||
|
|
@ -1340,20 +1406,12 @@ rl_transpose_chars (count, key)
|
|||
|
||||
if (rl_point == rl_end)
|
||||
{
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO);
|
||||
else
|
||||
--rl_point;
|
||||
rl_point = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO);
|
||||
count = 1;
|
||||
}
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
prev_point = rl_point;
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO);
|
||||
else
|
||||
#endif
|
||||
rl_point--;
|
||||
rl_point = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO);
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
char_length = prev_point - rl_point;
|
||||
|
|
@ -1487,10 +1545,33 @@ _rl_char_search (count, fdir, bdir)
|
|||
}
|
||||
#endif /* !HANDLE_MULTIBYTE */
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
static int
|
||||
_rl_char_search_callback (data)
|
||||
_rl_callback_generic_arg *data;
|
||||
{
|
||||
_rl_callback_func = 0;
|
||||
_rl_want_redisplay = 1;
|
||||
|
||||
return (_rl_char_search (data->count, data->i1, data->i2));
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
rl_char_search (count, key)
|
||||
int count, key;
|
||||
{
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
if (RL_ISSTATE (RL_STATE_CALLBACK))
|
||||
{
|
||||
_rl_callback_data = _rl_callback_data_alloc (count);
|
||||
_rl_callback_data->i1 = FFIND;
|
||||
_rl_callback_data->i2 = BFIND;
|
||||
_rl_callback_func = _rl_char_search_callback;
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (_rl_char_search (count, FFIND, BFIND));
|
||||
}
|
||||
|
||||
|
|
@ -1498,6 +1579,17 @@ int
|
|||
rl_backward_char_search (count, key)
|
||||
int count, key;
|
||||
{
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
if (RL_ISSTATE (RL_STATE_CALLBACK))
|
||||
{
|
||||
_rl_callback_data = _rl_callback_data_alloc (count);
|
||||
_rl_callback_data->i1 = BFIND;
|
||||
_rl_callback_data->i2 = FFIND;
|
||||
_rl_callback_func = _rl_char_search_callback;
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (_rl_char_search (count, BFIND, FFIND));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,9 @@
|
|||
#endif /* HAVE_STDLIB_H */
|
||||
|
||||
#include <sys/types.h>
|
||||
#if defined (HAVE_PWD_H)
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
#include "tilde.h"
|
||||
|
||||
|
|
@ -54,8 +56,12 @@ static void *xmalloc (), *xrealloc ();
|
|||
#endif /* TEST || STATIC_MALLOC */
|
||||
|
||||
#if !defined (HAVE_GETPW_DECLS)
|
||||
# if defined (HAVE_GETPWUID)
|
||||
extern struct passwd *getpwuid PARAMS((uid_t));
|
||||
# endif
|
||||
# if defined (HAVE_GETPWNAM)
|
||||
extern struct passwd *getpwnam PARAMS((const char *));
|
||||
# endif
|
||||
#endif /* !HAVE_GETPW_DECLS */
|
||||
|
||||
#if !defined (savestring)
|
||||
|
|
@ -277,6 +283,39 @@ isolate_tilde_prefix (fname, lenp)
|
|||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Public function to scan a string (FNAME) beginning with a tilde and find
|
||||
the portion of the string that should be passed to the tilde expansion
|
||||
function. Right now, it just calls tilde_find_suffix and allocates new
|
||||
memory, but it can be expanded to do different things later. */
|
||||
char *
|
||||
tilde_find_word (fname, flags, lenp)
|
||||
const char *fname;
|
||||
int flags, *lenp;
|
||||
{
|
||||
int x;
|
||||
char *r;
|
||||
|
||||
x = tilde_find_suffix (fname);
|
||||
if (x == 0)
|
||||
{
|
||||
r = savestring (fname);
|
||||
if (lenp)
|
||||
*lenp = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = (char *)xmalloc (1 + x);
|
||||
strncpy (r, fname, x);
|
||||
r[x] = '\0';
|
||||
if (lenp)
|
||||
*lenp = x;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Return a string that is PREFIX concatenated with SUFFIX starting at
|
||||
SUFFIND. */
|
||||
static char *
|
||||
|
|
@ -347,7 +386,11 @@ tilde_expand_word (filename)
|
|||
/* No preexpansion hook, or the preexpansion hook failed. Look in the
|
||||
password database. */
|
||||
dirname = (char *)NULL;
|
||||
#if defined (HAVE_GETPWNAM)
|
||||
user_entry = getpwnam (username);
|
||||
#else
|
||||
user_entry = 0;
|
||||
#endif
|
||||
if (user_entry == 0)
|
||||
{
|
||||
/* If the calling program has a special syntax for expanding tildes,
|
||||
|
|
@ -372,8 +415,9 @@ tilde_expand_word (filename)
|
|||
free (username);
|
||||
dirname = glue_prefix_and_suffix (user_entry->pw_dir, filename, user_len);
|
||||
}
|
||||
|
||||
#if defined (HAVE_GETPWENT)
|
||||
endpwent ();
|
||||
#endif
|
||||
return (dirname);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,9 @@ extern char *tilde_expand PARAMS((const char *));
|
|||
tilde. If there is no expansion, call tilde_expansion_failure_hook. */
|
||||
extern char *tilde_expand_word PARAMS((const char *));
|
||||
|
||||
/* Find the portion of the string beginning with ~ that should be expanded. */
|
||||
extern char *tilde_find_word PARAMS((const char *, int, int *));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -237,7 +237,12 @@ rl_revert_line (count, key)
|
|||
{
|
||||
while (rl_undo_list)
|
||||
rl_do_undo ();
|
||||
#if defined (VI_MODE)
|
||||
if (rl_editing_mode == vi_mode)
|
||||
rl_point = rl_mark = 0; /* rl_end should be set correctly */
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* util.c -- readline utility functions */
|
||||
|
||||
/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2005 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.
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
|
||||
/* System-specific feature definitions and include files. */
|
||||
#include "rldefs.h"
|
||||
#include "rlmbutil.h"
|
||||
|
||||
#if defined (TIOCSTAT_IN_SYS_IOCTL)
|
||||
# include <sys/ioctl.h>
|
||||
|
|
@ -78,13 +79,29 @@ rl_alphabetic (c)
|
|||
strchr (pathname_alphabetic_chars, c) != NULL);
|
||||
}
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
int
|
||||
_rl_walphabetic (wc)
|
||||
wchar_t wc;
|
||||
{
|
||||
int c;
|
||||
|
||||
if (iswalnum (wc))
|
||||
return (1);
|
||||
|
||||
c = wc & 0177;
|
||||
return (_rl_allow_pathname_alphabetic_chars &&
|
||||
strchr (pathname_alphabetic_chars, c) != NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* How to abort things. */
|
||||
int
|
||||
_rl_abort_internal ()
|
||||
{
|
||||
rl_ding ();
|
||||
rl_clear_message ();
|
||||
_rl_init_argument ();
|
||||
_rl_reset_argument ();
|
||||
rl_clear_pending_input ();
|
||||
|
||||
RL_UNSETSTATE (RL_STATE_MACRODEF);
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ KEYMAP_ENTRY_ARRAY vi_movement_keymap = {
|
|||
{ ISFUNC, rl_revert_line }, /* U */
|
||||
{ ISFUNC, (rl_command_func_t *)0x0 }, /* V */
|
||||
{ ISFUNC, rl_vi_next_word }, /* W */
|
||||
{ ISFUNC, rl_rubout }, /* X */
|
||||
{ ISFUNC, rl_vi_rubout }, /* X */
|
||||
{ ISFUNC, rl_vi_yank_to }, /* Y */
|
||||
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Z */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* vi_mode.c -- A vi emulation mode for Bash.
|
||||
Derived from code written by Jeff Sparkes (jsparkes@bnr.ca). */
|
||||
|
||||
/* Copyright (C) 1987-2004 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2005 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.
|
||||
|
|
@ -90,6 +90,7 @@ static int _rl_vi_last_arg_sign = 1;
|
|||
static int _rl_vi_last_motion;
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
static char _rl_vi_last_search_mbchar[MB_LEN_MAX];
|
||||
static int _rl_vi_last_search_mblen;
|
||||
#else
|
||||
static int _rl_vi_last_search_char;
|
||||
#endif
|
||||
|
|
@ -107,8 +108,22 @@ static int vi_mark_chars['z' - 'a' + 1];
|
|||
|
||||
static void _rl_vi_stuff_insert PARAMS((int));
|
||||
static void _rl_vi_save_insert PARAMS((UNDO_LIST *));
|
||||
|
||||
static int _rl_vi_arg_dispatch PARAMS((int));
|
||||
static int rl_digit_loop1 PARAMS((void));
|
||||
|
||||
static int _rl_vi_set_mark PARAMS((void));
|
||||
static int _rl_vi_goto_mark PARAMS((void));
|
||||
|
||||
static int _rl_vi_callback_getchar PARAMS((char *, int));
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
static int _rl_vi_callback_set_mark PARAMS((_rl_callback_generic_arg *));
|
||||
static int _rl_vi_callback_goto_mark PARAMS((_rl_callback_generic_arg *));
|
||||
static int _rl_vi_callback_change_char PARAMS((_rl_callback_generic_arg *));
|
||||
static int _rl_vi_callback_char_search PARAMS((_rl_callback_generic_arg *));
|
||||
#endif
|
||||
|
||||
void
|
||||
_rl_vi_initialize_line ()
|
||||
{
|
||||
|
|
@ -116,6 +131,8 @@ _rl_vi_initialize_line ()
|
|||
|
||||
for (i = 0; i < sizeof (vi_mark_chars) / sizeof (int); i++)
|
||||
vi_mark_chars[i] = -1;
|
||||
|
||||
RL_UNSETSTATE(RL_STATE_VICMDONCE);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -671,6 +688,13 @@ rl_vi_movement_mode (count, key)
|
|||
|
||||
_rl_keymap = vi_movement_keymap;
|
||||
_rl_vi_done_inserting ();
|
||||
|
||||
/* This is how POSIX.2 says `U' should behave -- everything up until the
|
||||
first time you go into command mode should not be undone. */
|
||||
if (RL_ISSTATE (RL_STATE_VICMDONCE) == 0)
|
||||
rl_free_undo_list ();
|
||||
|
||||
RL_SETSTATE (RL_STATE_VICMDONCE);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -840,7 +864,9 @@ rl_vi_domove (key, nextkey)
|
|||
save = rl_numeric_arg;
|
||||
rl_numeric_arg = _rl_digit_value (c);
|
||||
rl_explicit_arg = 1;
|
||||
RL_SETSTATE (RL_STATE_NUMERICARG|RL_STATE_VIMOTION);
|
||||
rl_digit_loop1 ();
|
||||
RL_UNSETSTATE (RL_STATE_VIMOTION);
|
||||
rl_numeric_arg *= save;
|
||||
RL_SETSTATE(RL_STATE_MOREINPUT);
|
||||
c = rl_read_key (); /* real command */
|
||||
|
|
@ -913,52 +939,59 @@ rl_vi_domove (key, nextkey)
|
|||
return (0);
|
||||
}
|
||||
|
||||
/* Process C as part of the current numeric argument. Return -1 if the
|
||||
argument should be aborted, 0 if we should not read any more chars, and
|
||||
1 if we should continue to read chars. */
|
||||
static int
|
||||
_rl_vi_arg_dispatch (c)
|
||||
int c;
|
||||
{
|
||||
int key;
|
||||
|
||||
key = c;
|
||||
if (c >= 0 && _rl_keymap[c].type == ISFUNC && _rl_keymap[c].function == rl_universal_argument)
|
||||
{
|
||||
rl_numeric_arg *= 4;
|
||||
return 1;
|
||||
}
|
||||
|
||||
c = UNMETA (c);
|
||||
|
||||
if (_rl_digit_p (c))
|
||||
{
|
||||
if (rl_explicit_arg)
|
||||
rl_numeric_arg = (rl_numeric_arg * 10) + _rl_digit_value (c);
|
||||
else
|
||||
rl_numeric_arg = _rl_digit_value (c);
|
||||
rl_explicit_arg = 1;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
rl_clear_message ();
|
||||
rl_stuff_char (key);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* A simplified loop for vi. Don't dispatch key at end.
|
||||
Don't recognize minus sign?
|
||||
Should this do rl_save_prompt/rl_restore_prompt? */
|
||||
static int
|
||||
rl_digit_loop1 ()
|
||||
{
|
||||
int key, c;
|
||||
int c, r;
|
||||
|
||||
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);
|
||||
RL_SETSTATE(RL_STATE_MOREINPUT);
|
||||
key = c = rl_read_key ();
|
||||
RL_UNSETSTATE(RL_STATE_MOREINPUT);
|
||||
if (_rl_arg_overflow ())
|
||||
return 1;
|
||||
|
||||
if (c >= 0 && _rl_keymap[c].type == ISFUNC &&
|
||||
_rl_keymap[c].function == rl_universal_argument)
|
||||
{
|
||||
rl_numeric_arg *= 4;
|
||||
continue;
|
||||
}
|
||||
c = _rl_arg_getchar ();
|
||||
|
||||
c = UNMETA (c);
|
||||
if (_rl_digit_p (c))
|
||||
{
|
||||
if (rl_explicit_arg)
|
||||
rl_numeric_arg = (rl_numeric_arg * 10) + _rl_digit_value (c);
|
||||
else
|
||||
rl_numeric_arg = _rl_digit_value (c);
|
||||
rl_explicit_arg = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
rl_clear_message ();
|
||||
rl_stuff_char (key);
|
||||
break;
|
||||
}
|
||||
r = _rl_vi_arg_dispatch (c);
|
||||
if (r <= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
RL_UNSETSTATE(RL_STATE_NUMERICARG);
|
||||
|
|
@ -1048,8 +1081,9 @@ int
|
|||
rl_vi_yank_to (count, key)
|
||||
int count, key;
|
||||
{
|
||||
int c, save = rl_point;
|
||||
int c, save;
|
||||
|
||||
save = rl_point;
|
||||
if (_rl_uppercase_p (key))
|
||||
rl_stuff_char ('$');
|
||||
|
||||
|
|
@ -1073,12 +1107,46 @@ rl_vi_yank_to (count, key)
|
|||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
rl_vi_rubout (count, key)
|
||||
int count, key;
|
||||
{
|
||||
int p, opoint;
|
||||
|
||||
if (count < 0)
|
||||
return (rl_vi_delete (-count, key));
|
||||
|
||||
if (rl_point == 0)
|
||||
{
|
||||
rl_ding ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
opoint = rl_point;
|
||||
if (count > 1 && MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
rl_backward_char (count, key);
|
||||
else if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO);
|
||||
else
|
||||
rl_point -= count;
|
||||
|
||||
if (rl_point < 0)
|
||||
rl_point = 0;
|
||||
|
||||
rl_kill_text (rl_point, opoint);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
rl_vi_delete (count, key)
|
||||
int count, key;
|
||||
{
|
||||
int end;
|
||||
|
||||
if (count < 0)
|
||||
return (rl_vi_rubout (-count, key));
|
||||
|
||||
if (rl_end == 0)
|
||||
{
|
||||
rl_ding ();
|
||||
|
|
@ -1097,6 +1165,7 @@ rl_vi_delete (count, key)
|
|||
|
||||
if (rl_point > 0 && rl_point == rl_end)
|
||||
rl_backward_char (1, key);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -1117,64 +1186,102 @@ rl_vi_first_print (count, key)
|
|||
return (rl_vi_back_to_indent (1, key));
|
||||
}
|
||||
|
||||
static int _rl_cs_dir, _rl_cs_orig_dir;
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
static int
|
||||
_rl_vi_callback_char_search (data)
|
||||
_rl_callback_generic_arg *data;
|
||||
{
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
_rl_vi_last_search_mblen = _rl_read_mbchar (_rl_vi_last_search_mbchar, MB_LEN_MAX);
|
||||
#else
|
||||
RL_SETSTATE(RL_STATE_MOREINPUT);
|
||||
_rl_vi_last_search_char = rl_read_key ();
|
||||
RL_UNSETSTATE(RL_STATE_MOREINPUT);
|
||||
#endif
|
||||
|
||||
_rl_callback_func = 0;
|
||||
_rl_want_redisplay = 1;
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
return (_rl_char_search_internal (data->count, _rl_cs_dir, _rl_vi_last_search_mbchar, _rl_vi_last_search_mblen));
|
||||
#else
|
||||
return (_rl_char_search_internal (data->count, _rl_cs_dir, _rl_vi_last_search_char));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
rl_vi_char_search (count, key)
|
||||
int count, key;
|
||||
{
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
static char *target;
|
||||
static int mb_len;
|
||||
static int tlen;
|
||||
#else
|
||||
static char target;
|
||||
#endif
|
||||
static int orig_dir, dir;
|
||||
|
||||
if (key == ';' || key == ',')
|
||||
dir = key == ';' ? orig_dir : -orig_dir;
|
||||
_rl_cs_dir = (key == ';') ? _rl_cs_orig_dir : -_rl_cs_orig_dir;
|
||||
else
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case 't':
|
||||
_rl_cs_orig_dir = _rl_cs_dir = FTO;
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
_rl_cs_orig_dir = _rl_cs_dir = BTO;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
_rl_cs_orig_dir = _rl_cs_dir = FFIND;
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
_rl_cs_orig_dir = _rl_cs_dir = BFIND;
|
||||
break;
|
||||
}
|
||||
|
||||
if (vi_redoing)
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
target = _rl_vi_last_search_mbchar;
|
||||
#else
|
||||
target = _rl_vi_last_search_char;
|
||||
{
|
||||
/* set target and tlen below */
|
||||
}
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
else if (RL_ISSTATE (RL_STATE_CALLBACK))
|
||||
{
|
||||
_rl_callback_data = _rl_callback_data_alloc (count);
|
||||
_rl_callback_data->i1 = _rl_cs_dir;
|
||||
_rl_callback_func = _rl_vi_callback_char_search;
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
mb_len = _rl_read_mbchar (_rl_vi_last_search_mbchar, MB_LEN_MAX);
|
||||
target = _rl_vi_last_search_mbchar;
|
||||
_rl_vi_last_search_mblen = _rl_read_mbchar (_rl_vi_last_search_mbchar, MB_LEN_MAX);
|
||||
#else
|
||||
RL_SETSTATE(RL_STATE_MOREINPUT);
|
||||
_rl_vi_last_search_char = target = rl_read_key ();
|
||||
_rl_vi_last_search_char = rl_read_key ();
|
||||
RL_UNSETSTATE(RL_STATE_MOREINPUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case 't':
|
||||
orig_dir = dir = FTO;
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
orig_dir = dir = BTO;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
orig_dir = dir = FFIND;
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
orig_dir = dir = BFIND;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
return (_rl_char_search_internal (count, dir, target, mb_len));
|
||||
target = _rl_vi_last_search_mbchar;
|
||||
tlen = _rl_vi_last_search_mblen;
|
||||
#else
|
||||
return (_rl_char_search_internal (count, dir, target));
|
||||
target = _rl_vi_last_search_char;
|
||||
#endif
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
return (_rl_char_search_internal (count, _rl_cs_dir, target, tlen));
|
||||
#else
|
||||
return (_rl_char_search_internal (count, _rl_cs_dir, target));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -1285,25 +1392,12 @@ rl_vi_bracktype (c)
|
|||
}
|
||||
}
|
||||
|
||||
/* XXX - think about reading an entire mbchar with _rl_read_mbchar and
|
||||
inserting it in one bunch instead of the loop below (like in
|
||||
rl_vi_char_search or _rl_vi_change_mbchar_case). Set c to mbchar[0]
|
||||
for test against 033 or ^C. Make sure that _rl_read_mbchar does
|
||||
this right. */
|
||||
int
|
||||
rl_vi_change_char (count, key)
|
||||
int count, key;
|
||||
static int
|
||||
_rl_vi_change_char (count, c, mb)
|
||||
int count, c;
|
||||
char *mb;
|
||||
{
|
||||
int c, p;
|
||||
|
||||
if (vi_redoing)
|
||||
c = _rl_vi_last_replacement;
|
||||
else
|
||||
{
|
||||
RL_SETSTATE(RL_STATE_MOREINPUT);
|
||||
_rl_vi_last_replacement = c = rl_read_key ();
|
||||
RL_UNSETSTATE(RL_STATE_MOREINPUT);
|
||||
}
|
||||
int p;
|
||||
|
||||
if (c == '\033' || c == CTRL ('C'))
|
||||
return -1;
|
||||
|
|
@ -1313,31 +1407,87 @@ rl_vi_change_char (count, key)
|
|||
{
|
||||
p = rl_point;
|
||||
rl_vi_delete (1, c);
|
||||
if (rl_point < p) /* Did we retreat at EOL? */
|
||||
rl_point++;
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
if (rl_point < p) /* Did we retreat at EOL? */
|
||||
rl_point++;
|
||||
while (_rl_insert_char (1, c))
|
||||
{
|
||||
RL_SETSTATE (RL_STATE_MOREINPUT);
|
||||
c = rl_read_key ();
|
||||
RL_UNSETSTATE (RL_STATE_MOREINPUT);
|
||||
}
|
||||
}
|
||||
rl_insert_text (mb);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (rl_point < p) /* Did we retreat at EOL? */
|
||||
rl_point++;
|
||||
_rl_insert_char (1, c);
|
||||
}
|
||||
_rl_insert_char (1, c);
|
||||
}
|
||||
|
||||
/* The cursor shall be left on the last character changed. */
|
||||
rl_backward_char (1, c);
|
||||
|
||||
rl_end_undo_group ();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_rl_vi_callback_getchar (mb, mblen)
|
||||
char *mb;
|
||||
int mblen;
|
||||
{
|
||||
int c;
|
||||
|
||||
RL_SETSTATE(RL_STATE_MOREINPUT);
|
||||
c = rl_read_key ();
|
||||
RL_UNSETSTATE(RL_STATE_MOREINPUT);
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
c = _rl_read_mbstring (c, mb, mblen);
|
||||
#endif
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
static int
|
||||
_rl_vi_callback_change_char (data)
|
||||
_rl_callback_generic_arg *data;
|
||||
{
|
||||
int c;
|
||||
char mb[MB_LEN_MAX];
|
||||
|
||||
_rl_vi_last_replacement = c = _rl_vi_callback_getchar (mb, MB_LEN_MAX);
|
||||
|
||||
_rl_callback_func = 0;
|
||||
_rl_want_redisplay = 1;
|
||||
|
||||
return (_rl_vi_change_char (data->count, c, mb));
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
rl_vi_change_char (count, key)
|
||||
int count, key;
|
||||
{
|
||||
int c;
|
||||
char mb[MB_LEN_MAX];
|
||||
|
||||
if (vi_redoing)
|
||||
{
|
||||
c = _rl_vi_last_replacement;
|
||||
mb[0] = c;
|
||||
mb[1] = '\0';
|
||||
}
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
else if (RL_ISSTATE (RL_STATE_CALLBACK))
|
||||
{
|
||||
_rl_callback_data = _rl_callback_data_alloc (count);
|
||||
_rl_callback_func = _rl_vi_callback_change_char;
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
_rl_vi_last_replacement = c = _rl_vi_callback_getchar (mb, MB_LEN_MAX);
|
||||
|
||||
return (_rl_vi_change_char (count, c, mb));
|
||||
}
|
||||
|
||||
int
|
||||
rl_vi_subst (count, key)
|
||||
int count, key;
|
||||
|
|
@ -1460,9 +1610,8 @@ rl_vi_possible_completions()
|
|||
#endif
|
||||
|
||||
/* Functions to save and restore marks. */
|
||||
int
|
||||
rl_vi_set_mark (count, key)
|
||||
int count, key;
|
||||
static int
|
||||
_rl_vi_set_mark ()
|
||||
{
|
||||
int ch;
|
||||
|
||||
|
|
@ -1480,9 +1629,36 @@ rl_vi_set_mark (count, key)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
static int
|
||||
_rl_vi_callback_set_mark (data)
|
||||
_rl_callback_generic_arg *data;
|
||||
{
|
||||
_rl_callback_func = 0;
|
||||
_rl_want_redisplay = 1;
|
||||
|
||||
return (_rl_vi_set_mark ());
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
rl_vi_goto_mark (count, key)
|
||||
rl_vi_set_mark (count, key)
|
||||
int count, key;
|
||||
{
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
if (RL_ISSTATE (RL_STATE_CALLBACK))
|
||||
{
|
||||
_rl_callback_data = 0;
|
||||
_rl_callback_func = _rl_vi_callback_set_mark;
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (_rl_vi_set_mark ());
|
||||
}
|
||||
|
||||
static int
|
||||
_rl_vi_goto_mark ()
|
||||
{
|
||||
int ch;
|
||||
|
||||
|
|
@ -1511,4 +1687,31 @@ rl_vi_goto_mark (count, key)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
static int
|
||||
_rl_vi_callback_goto_mark (data)
|
||||
_rl_callback_generic_arg *data;
|
||||
{
|
||||
_rl_callback_func = 0;
|
||||
_rl_want_redisplay = 1;
|
||||
|
||||
return (_rl_vi_goto_mark ());
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
rl_vi_goto_mark (count, key)
|
||||
int count, key;
|
||||
{
|
||||
#if defined (READLINE_CALLBACKS)
|
||||
if (RL_ISSTATE (RL_STATE_CALLBACK))
|
||||
{
|
||||
_rl_callback_data = 0;
|
||||
_rl_callback_func = _rl_vi_callback_goto_mark;
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (_rl_vi_goto_mark ());
|
||||
}
|
||||
#endif /* VI_MODE */
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# Makefile for the Bash library
|
||||
#
|
||||
#
|
||||
# Copyright (C) 1998-2002 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1998-2005 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -86,21 +86,21 @@ CSOURCES = clktck.c clock.c getcwd.c getenv.c oslib.c setlinebuf.c \
|
|||
inet_aton.c netconn.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 snprintf.c mailstat.c \
|
||||
fmtulong.c fmtullong.c fmtumax.c shmatch.c \
|
||||
fmtulong.c fmtullong.c fmtumax.c shmatch.c strnlen.c \
|
||||
strtoll.c strtoull.c strtoimax.c strtoumax.c memset.c strstr.c \
|
||||
mktime.c strftime.c xstrchr.c zcatfd.c
|
||||
mktime.c strftime.c xstrchr.c zcatfd.c winsize.c
|
||||
|
||||
# The header files for this library.
|
||||
HSOURCES =
|
||||
|
||||
# The object files contained in $(LIBRARY_NAME)
|
||||
LIBOBJS = @LIBOBJS@
|
||||
OBJECTS = clktck.o clock.o getenv.o oslib.o setlinebuf.o \
|
||||
OBJECTS = clktck.o clock.o getenv.o oslib.o setlinebuf.o strnlen.o \
|
||||
itos.o zread.o zwrite.o shtty.o shmatch.o \
|
||||
netconn.o netopen.o timeval.o makepath.o pathcanon.o \
|
||||
pathphys.o tmpfile.o stringlist.o stringvec.o spell.o shquote.o \
|
||||
strtrans.o strindex.o snprintf.o mailstat.o fmtulong.o \
|
||||
fmtullong.o fmtumax.o xstrchr.o zcatfd.o ${LIBOBJS}
|
||||
fmtullong.o fmtumax.o xstrchr.o zcatfd.o winsize.o ${LIBOBJS}
|
||||
|
||||
SUPPORT = Makefile
|
||||
|
||||
|
|
@ -162,6 +162,7 @@ strftime.o: strftime.c
|
|||
strindex.o: strindex.c
|
||||
stringlist.o: stringlist.c
|
||||
stringvec.o: stringvec.c
|
||||
strnlen.o: strnlen.c
|
||||
strpbrk.o: strpbrk.c
|
||||
strtod.o: strtod.c
|
||||
strtoimax.o: strtoimax.c
|
||||
|
|
@ -218,6 +219,7 @@ strftime.o: ${BUILD_DIR}/config.h
|
|||
strindex.o: ${BUILD_DIR}/config.h
|
||||
stringlist.o: ${BUILD_DIR}/config.h
|
||||
stringvec.o: ${BUILD_DIR}/config.h
|
||||
strnlen.o: ${BUILD_DIR}/config.h
|
||||
strpbrk.o: ${BUILD_DIR}/config.h
|
||||
strtod.o: ${BUILD_DIR}/config.h
|
||||
strtoimax.o: ${BUILD_DIR}/config.h
|
||||
|
|
@ -372,6 +374,8 @@ stringvec.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
|
|||
stringvec.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
|
||||
stringvec.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h ${BUILD_DIR}/version.h
|
||||
|
||||
strnlen.o: ${BASHINCDIR}/stdc.h
|
||||
|
||||
strpbrk.o: ${BASHINCDIR}/stdc.h
|
||||
|
||||
strtod.o: ${topdir}/bashansi.h
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ putenv (str)
|
|||
value = name + offset + 1;
|
||||
|
||||
/* XXX - should we worry about readonly here? */
|
||||
var = bind_variable (name, value);
|
||||
var = bind_variable (name, value, 0);
|
||||
if (var == 0)
|
||||
{
|
||||
errno = EINVAL;
|
||||
|
|
@ -175,7 +175,7 @@ setenv (name, value, rewrite)
|
|||
var = find_variable (name);
|
||||
|
||||
if (var == 0)
|
||||
var = bind_variable (name, v);
|
||||
var = bind_variable (name, v, 0);
|
||||
|
||||
if (var == 0)
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* netconn.c -- is a particular file descriptor a network connection?. */
|
||||
|
||||
/* Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 2002-2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
|
|
@ -52,8 +52,8 @@ isnetconn (fd)
|
|||
|
||||
l = sizeof(sa);
|
||||
rv = getpeername(fd, &sa, &l);
|
||||
/* Solaris 2.5 getpeername() returns EINVAL if the fd is not a socket. */
|
||||
return ((rv < 0 && (errno == ENOTSOCK || errno == EINVAL)) ? 0 : 1);
|
||||
/* Posix.2 says getpeername can return these errors. */
|
||||
return ((rv < 0 && (errno == ENOTSOCK || errno == ENOTCONN || errno == EINVAL)) ? 0 : 1);
|
||||
#else /* !HAVE_GETPEERNAME || SVR4_2 || __BEOS__ */
|
||||
# if defined (SVR4) || defined (SVR4_2)
|
||||
/* Sockets on SVR4 and SVR4.2 are character special (streams) devices. */
|
||||
|
|
|
|||
|
|
@ -75,10 +75,11 @@ static int
|
|||
_path_isdir (path)
|
||||
char *path;
|
||||
{
|
||||
int l, x;
|
||||
int l;
|
||||
struct stat sb;
|
||||
|
||||
/* This should leave errno set to the correct value. */
|
||||
errno = 0;
|
||||
l = stat (path, &sb) == 0 && S_ISDIR (sb.st_mode);
|
||||
#if defined (__CYGWIN__)
|
||||
if (l == 0)
|
||||
|
|
|
|||
|
|
@ -285,6 +285,7 @@ sh_realpath (pathname, resolved)
|
|||
{
|
||||
strncpy (resolved, wd, PATH_MAX - 1);
|
||||
resolved[PATH_MAX - 1] = '\0';
|
||||
free (wd);
|
||||
return resolved;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
#include "variables.h"
|
||||
#include "externs.h"
|
||||
|
||||
extern int glob_ignore_case;
|
||||
extern int glob_ignore_case, match_ignore_case;
|
||||
|
||||
int
|
||||
sh_regmatch (string, pattern, flags)
|
||||
|
|
@ -65,7 +65,7 @@ sh_regmatch (string, pattern, flags)
|
|||
#endif
|
||||
|
||||
rflags = REG_EXTENDED;
|
||||
if (glob_ignore_case)
|
||||
if (glob_ignore_case || match_ignore_case)
|
||||
rflags |= REG_ICASE;
|
||||
#if !defined (ARRAY_VARS)
|
||||
rflags |= REG_NOSUB;
|
||||
|
|
|
|||
|
|
@ -81,7 +81,8 @@ sh_double_quote (string)
|
|||
|
||||
for (s = string; s && (c = *s); s++)
|
||||
{
|
||||
if (sh_syntaxtab[c] & CBSDQUOTE)
|
||||
/* Backslash-newline disappears within double quotes, so don't add one. */
|
||||
if ((sh_syntaxtab[c] & CBSDQUOTE) && c != '\n')
|
||||
*r++ = '\\';
|
||||
else if (c == CTLESC || c == CTLNUL)
|
||||
*r++ = CTLESC; /* could be '\\'? */
|
||||
|
|
@ -95,6 +96,32 @@ sh_double_quote (string)
|
|||
return (result);
|
||||
}
|
||||
|
||||
/* Turn S into a simple double-quoted string. If FLAGS is non-zero, quote
|
||||
double quote characters in S with backslashes. */
|
||||
char *
|
||||
sh_mkdoublequoted (s, slen, flags)
|
||||
const char *s;
|
||||
int slen, flags;
|
||||
{
|
||||
char *r, *ret;
|
||||
int rlen;
|
||||
|
||||
rlen = (flags == 0) ? slen + 3 : (2 * slen) + 1;
|
||||
ret = r = (char *)xmalloc (rlen);
|
||||
|
||||
*r++ = '"';
|
||||
while (*s)
|
||||
{
|
||||
if (flags && *s == '"')
|
||||
*r++ = '\\';
|
||||
*r++ = *s++;
|
||||
}
|
||||
*r++ = '"';
|
||||
*r = '\0';
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Remove backslashes that are quoting characters that are special between
|
||||
double quotes. Return a new string. XXX - should this handle CTLESC
|
||||
and CTLNUL? */
|
||||
|
|
@ -128,7 +155,11 @@ sh_un_double_quote (string)
|
|||
}
|
||||
|
||||
/* Quote special characters in STRING using backslashes. Return a new
|
||||
string. */
|
||||
string. NOTE: if the string is to be further expanded, we need a
|
||||
way to protect the CTLESC and CTLNUL characters. As I write this,
|
||||
the current callers will never cause the string to be expanded without
|
||||
going through the shell parser, which will protect the internal
|
||||
quoting characters. */
|
||||
char *
|
||||
sh_backslash_quote (string)
|
||||
char *string;
|
||||
|
|
@ -160,11 +191,12 @@ sh_backslash_quote (string)
|
|||
*r++ = '\\';
|
||||
*r++ = c;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case CTLESC: case CTLNUL: /* internal quoting characters */
|
||||
*r++ = CTLESC; /* could be '\\'? */
|
||||
*r++ = c;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case '#': /* comment char */
|
||||
if (s == string)
|
||||
|
|
|
|||
|
|
@ -372,10 +372,27 @@ static void xfree __P((void *));
|
|||
|
||||
/* if width and prec. in the args */
|
||||
#define STAR_ARGS(p) \
|
||||
do { \
|
||||
if ((p)->flags & PF_STAR_W) \
|
||||
(p)->width = GETARG (int); \
|
||||
{ \
|
||||
(p)->width = GETARG (int); \
|
||||
if ((p)->width < 0) \
|
||||
{ \
|
||||
(p)->flags |= PF_LADJUST; \
|
||||
(p)->justify = LEFT; \
|
||||
(p)->width = -(p)->width; \
|
||||
} \
|
||||
} \
|
||||
if ((p)->flags & PF_STAR_P) \
|
||||
(p)->precision = GETARG (int)
|
||||
{ \
|
||||
(p)->precision = GETARG (int); \
|
||||
if ((p)->precision < 0) \
|
||||
{ \
|
||||
(p)->flags &= ~PF_STAR_P; \
|
||||
(p)->precision = NOT_FOUND; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#if defined (HAVE_LOCALE_H)
|
||||
# define GETLOCALEDATA(d, t, g) \
|
||||
|
|
@ -915,7 +932,7 @@ floating(p, d)
|
|||
char *tmp, *tmp2, *t;
|
||||
int i;
|
||||
|
||||
if (chkinfnan(p, d, 1) || chkinfnan(p, d, 2))
|
||||
if (d != 0 && (chkinfnan(p, d, 1) || chkinfnan(p, d, 2)))
|
||||
return; /* already printed nan or inf */
|
||||
|
||||
GETLOCALEDATA(decpoint, thoussep, grouping);
|
||||
|
|
@ -936,8 +953,8 @@ floating(p, d)
|
|||
PUT_SPACE(d, p, 0.);
|
||||
|
||||
while (*tmp)
|
||||
{ /* the integral */
|
||||
PUT_CHAR(*tmp, p);
|
||||
{
|
||||
PUT_CHAR(*tmp, p); /* the integral */
|
||||
tmp++;
|
||||
}
|
||||
FREE (t);
|
||||
|
|
@ -1010,7 +1027,7 @@ exponent(p, d)
|
|||
PUT_CHAR('E', p);
|
||||
|
||||
/* the sign of the exp */
|
||||
if (j > 0)
|
||||
if (j >= 0)
|
||||
PUT_CHAR('+', p);
|
||||
else
|
||||
{
|
||||
|
|
@ -1150,6 +1167,7 @@ vsnprintf_internal(data, string, length, format, args)
|
|||
wint_t wc;
|
||||
#endif
|
||||
const char *convstart;
|
||||
int negprec;
|
||||
|
||||
/* Sanity check, the string length must be >= 0. C99 actually says that
|
||||
LENGTH can be zero here, in the case of snprintf/vsnprintf (it's never
|
||||
|
|
@ -1165,6 +1183,7 @@ vsnprintf_internal(data, string, length, format, args)
|
|||
decpoint = thoussep = 0;
|
||||
grouping = 0;
|
||||
|
||||
negprec = 0;
|
||||
for (; c = *(data->pf); data->pf++)
|
||||
{
|
||||
if (c != '%')
|
||||
|
|
@ -1221,16 +1240,24 @@ vsnprintf_internal(data, string, length, format, args)
|
|||
data->flags |= PF_STAR_W;
|
||||
continue;
|
||||
case '-':
|
||||
data->flags |= PF_LADJUST;
|
||||
data->justify = LEFT;
|
||||
if ((data->flags & PF_DOT) == 0)
|
||||
{
|
||||
data->flags |= PF_LADJUST;
|
||||
data->justify = LEFT;
|
||||
}
|
||||
else
|
||||
negprec = 1;
|
||||
continue;
|
||||
case ' ':
|
||||
if ((data->flags & PF_PLUS) == 0)
|
||||
data->flags |= PF_SPACE;
|
||||
continue;
|
||||
case '+':
|
||||
data->flags |= PF_PLUS;
|
||||
data->justify = RIGHT;
|
||||
if ((data->flags & PF_DOT) == 0)
|
||||
{
|
||||
data->flags |= PF_PLUS;
|
||||
data->justify = RIGHT;
|
||||
}
|
||||
continue;
|
||||
case '\'':
|
||||
data->flags |= PF_THOUSANDS;
|
||||
|
|
@ -1250,7 +1277,7 @@ vsnprintf_internal(data, string, length, format, args)
|
|||
if (n < 0)
|
||||
n = 0;
|
||||
if (data->flags & PF_DOT)
|
||||
data->precision = n;
|
||||
data->precision = negprec ? NOT_FOUND : n;
|
||||
else
|
||||
data->width = n;
|
||||
continue;
|
||||
|
|
@ -1507,11 +1534,21 @@ ldfallback (data, fs, fe, ld)
|
|||
char fmtbuf[FALLBACK_FMTSIZE], *obuf;
|
||||
int fl;
|
||||
|
||||
obuf = (char *)xmalloc(LFALLBACK_BASE + (data->precision < 6 ? 6 : data->precision) + 2);
|
||||
fl = LFALLBACK_BASE + (data->precision < 6 ? 6 : data->precision) + 2;
|
||||
obuf = (char *)xmalloc (fl);
|
||||
fl = fe - fs + 1;
|
||||
strncpy (fmtbuf, fs, fl);
|
||||
fmtbuf[fl] = '\0';
|
||||
sprintf (obuf, fmtbuf, ld);
|
||||
|
||||
if ((data->flags & PF_STAR_W) && (data->flags & PF_STAR_P))
|
||||
sprintf (obuf, fmtbuf, data->width, data->precision, ld);
|
||||
else if (data->flags & PF_STAR_W)
|
||||
sprintf (obuf, fmtbuf, data->width, ld);
|
||||
else if (data->flags & PF_STAR_P)
|
||||
sprintf (obuf, fmtbuf, data->precision, ld);
|
||||
else
|
||||
sprintf (obuf, fmtbuf, ld);
|
||||
|
||||
for (x = obuf; *x; x++)
|
||||
PUT_CHAR (*x, data);
|
||||
xfree (obuf);
|
||||
|
|
@ -1533,7 +1570,16 @@ dfallback (data, fs, fe, d)
|
|||
fl = fe - fs + 1;
|
||||
strncpy (fmtbuf, fs, fl);
|
||||
fmtbuf[fl] = '\0';
|
||||
sprintf (obuf, fmtbuf, d);
|
||||
|
||||
if ((data->flags & PF_STAR_W) && (data->flags & PF_STAR_P))
|
||||
sprintf (obuf, fmtbuf, data->width, data->precision, d);
|
||||
else if (data->flags & PF_STAR_W)
|
||||
sprintf (obuf, fmtbuf, data->width, d);
|
||||
else if (data->flags & PF_STAR_P)
|
||||
sprintf (obuf, fmtbuf, data->precision, d);
|
||||
else
|
||||
sprintf (obuf, fmtbuf, d);
|
||||
|
||||
for (x = obuf; *x; x++)
|
||||
PUT_CHAR (*x, data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,15 +80,21 @@
|
|||
|
||||
#undef strchr /* avoid AIX weirdness */
|
||||
|
||||
#if defined (SHELL)
|
||||
extern char *get_string_value (const char *);
|
||||
#endif
|
||||
|
||||
extern void tzset(void);
|
||||
static int weeknumber(const struct tm *timeptr, int firstweekday);
|
||||
static int iso8601wknum(const struct tm *timeptr);
|
||||
|
||||
#ifndef inline
|
||||
#ifdef __GNUC__
|
||||
#define inline __inline__
|
||||
#else
|
||||
#define inline /**/
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define range(low, item, hi) max(low, min(item, hi))
|
||||
|
||||
|
|
@ -98,8 +104,12 @@ extern int daylight;
|
|||
#if defined(SOLARIS) || defined(mips) || defined (M_UNIX)
|
||||
extern long int timezone, altzone;
|
||||
#else
|
||||
# if defined (HPUX)
|
||||
extern long int timezone;
|
||||
# else
|
||||
extern int timezone, altzone;
|
||||
#endif
|
||||
# endif /* !HPUX */
|
||||
#endif /* !SOLARIS && !mips && !M_UNIX */
|
||||
#endif
|
||||
|
||||
#undef min /* just in case */
|
||||
|
|
@ -480,8 +490,13 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
|
|||
* Systems with tzname[] probably have timezone as
|
||||
* secs west of GMT. Convert to mins east of GMT.
|
||||
*/
|
||||
# ifdef HPUX
|
||||
off = -timezone / 60;
|
||||
# else
|
||||
off = -(daylight ? timezone : altzone) / 60;
|
||||
# endif /* !HPUX */
|
||||
#else /* !HAVE_TZNAME */
|
||||
gettimeofday(& tv, & zone);
|
||||
off = -zone.tz_minuteswest;
|
||||
#endif /* !HAVE_TZNAME */
|
||||
#endif /* !HAVE_TM_ZONE */
|
||||
|
|
|
|||
45
lib/sh/strnlen.c
Normal file
45
lib/sh/strnlen.c
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
|
||||
This program 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.
|
||||
|
||||
This program 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 this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if !defined (HAVE_STRNLEN)
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdc.h>
|
||||
|
||||
/* Find the length of S, but scan at most MAXLEN characters. If no '\0'
|
||||
terminator is found within the first MAXLEN characters, return MAXLEN. */
|
||||
size_t
|
||||
strnlen (s, maxlen)
|
||||
register const char *s;
|
||||
size_t maxlen;
|
||||
{
|
||||
register const char *e;
|
||||
size_t n;
|
||||
|
||||
for (e = s, n = 0; *e && n < maxlen; e++, n++)
|
||||
;
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* Convert string representation of a number into an intmax_t value.
|
||||
Copyright 1999, 2001 Free Software Foundation, Inc.
|
||||
Copyright 1999-2005 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -48,6 +48,10 @@ extern long strtol __P((const char *, char **, int));
|
|||
extern long long strtoll __P((const char *, char **, int));
|
||||
#endif
|
||||
|
||||
#ifdef strtoimax
|
||||
#undef strtoimax
|
||||
#endif
|
||||
|
||||
intmax_t
|
||||
strtoimax (ptr, endptr, base)
|
||||
const char *ptr;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* Convert string representation of a number into an uintmax_t value.
|
||||
Copyright 1999, 2001 Free Software Foundation, Inc.
|
||||
Copyright 1999-2005 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -48,6 +48,10 @@ extern unsigned long strtoul __P((const char *, char **, int));
|
|||
extern unsigned long long strtoull __P((const char *, char **, int));
|
||||
#endif
|
||||
|
||||
#ifdef strtoumax
|
||||
#undef strtoumax
|
||||
#endif
|
||||
|
||||
uintmax_t
|
||||
strtoumax (ptr, endptr, base)
|
||||
const char *ptr;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@
|
|||
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.
|
||||
If (FLAGS&2) is non-zero, we're expanding for the parser and want to
|
||||
quote CTLESC and CTLNUL with CTLESC */
|
||||
quote CTLESC and CTLNUL with CTLESC. If (flags&4) is non-zero, we want
|
||||
to remove the backslash before any unrecognized escape sequence. */
|
||||
char *
|
||||
ansicstr (string, len, flags, sawc, rlen)
|
||||
char *string;
|
||||
|
|
@ -141,7 +142,10 @@ ansicstr (string, len, flags, sawc, rlen)
|
|||
break;
|
||||
}
|
||||
/*FALLTHROUGH*/
|
||||
default: *r++ = '\\'; break;
|
||||
default:
|
||||
if ((flags & 4) == 0)
|
||||
*r++ = '\\';
|
||||
break;
|
||||
}
|
||||
if ((flags & 2) && (c == CTLESC || c == CTLNUL))
|
||||
*r++ = CTLESC;
|
||||
|
|
|
|||
82
lib/sh/winsize.c
Normal file
82
lib/sh/winsize.c
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/* Handle window size changes and information. */
|
||||
|
||||
/* Copyright (C) 2005 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 <stdc.h>
|
||||
|
||||
#include "bashtypes.h"
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#if !defined (STRUCT_WINSIZE_IN_SYS_IOCTL)
|
||||
/* For struct winsize on SCO */
|
||||
/* sys/ptem.h has winsize but needs mblk_t from sys/stream.h */
|
||||
# if defined (HAVE_SYS_PTEM_H) && defined (TIOCGWINSZ) && defined (SIGWINCH)
|
||||
# if defined (HAVE_SYS_STREAM_H)
|
||||
# include <sys/stream.h>
|
||||
# endif
|
||||
# include <sys/ptem.h>
|
||||
# endif /* HAVE_SYS_PTEM_H && TIOCGWINSZ && SIGWINCH */
|
||||
#endif /* !STRUCT_WINSIZE_IN_SYS_IOCTL */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Return the fd from which we are actually getting input. */
|
||||
#define input_tty() (shell_tty != -1) ? shell_tty : fileno (stderr)
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif /* !errno */
|
||||
|
||||
extern int shell_tty;
|
||||
|
||||
#if defined (READLINE)
|
||||
extern void rl_set_screen_size __P((int, int));
|
||||
#endif
|
||||
|
||||
void
|
||||
get_new_window_size (from_sig, rp, cp)
|
||||
int from_sig;
|
||||
int *rp, *cp;
|
||||
{
|
||||
#if defined (TIOCGWINSZ)
|
||||
struct winsize win;
|
||||
int tty;
|
||||
|
||||
tty = input_tty ();
|
||||
if (tty >= 0 && (ioctl (tty, TIOCGWINSZ, &win) == 0) &&
|
||||
win.ws_row > 0 && win.ws_col > 0)
|
||||
{
|
||||
sh_set_lines_and_columns (win.ws_row, win.ws_col);
|
||||
#if defined (READLINE)
|
||||
rl_set_screen_size (win.ws_row, win.ws_col);
|
||||
if (rp)
|
||||
*rp = win.ws_row;
|
||||
if (cp)
|
||||
*cp = win.ws_col;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -124,9 +124,13 @@ zsyncfd (fd)
|
|||
int fd;
|
||||
{
|
||||
off_t off;
|
||||
int r;
|
||||
|
||||
off = lused - lind;
|
||||
r = 0;
|
||||
if (off > 0)
|
||||
lseek (fd, -off, SEEK_CUR);
|
||||
lused = lind = 0;
|
||||
r = lseek (fd, -off, SEEK_CUR);
|
||||
|
||||
if (r >= 0)
|
||||
lused = lind = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
# #
|
||||
####################################################################
|
||||
|
||||
# Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1996-2005 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
# #
|
||||
####################################################################
|
||||
|
||||
# Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1996-2005 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
clean distclean mostlyclean maintainer-clean:
|
||||
rm -f tilde.??
|
||||
|
||||
all:
|
||||
cp tilde.texi tilde.info
|
||||
|
|
@ -43,7 +43,9 @@
|
|||
#endif /* HAVE_STDLIB_H */
|
||||
|
||||
#include <sys/types.h>
|
||||
#if defined (HAVE_PWD_H)
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
#include "tilde.h"
|
||||
|
||||
|
|
@ -54,8 +56,12 @@ static void *xmalloc (), *xrealloc ();
|
|||
#endif /* TEST || STATIC_MALLOC */
|
||||
|
||||
#if !defined (HAVE_GETPW_DECLS)
|
||||
# if defined (HAVE_GETPWUID)
|
||||
extern struct passwd *getpwuid PARAMS((uid_t));
|
||||
# endif
|
||||
# if defined (HAVE_GETPWNAM)
|
||||
extern struct passwd *getpwnam PARAMS((const char *));
|
||||
# endif
|
||||
#endif /* !HAVE_GETPW_DECLS */
|
||||
|
||||
#if !defined (savestring)
|
||||
|
|
@ -277,6 +283,39 @@ isolate_tilde_prefix (fname, lenp)
|
|||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Public function to scan a string (FNAME) beginning with a tilde and find
|
||||
the portion of the string that should be passed to the tilde expansion
|
||||
function. Right now, it just calls tilde_find_suffix and allocates new
|
||||
memory, but it can be expanded to do different things later. */
|
||||
char *
|
||||
tilde_find_word (fname, flags, lenp)
|
||||
const char *fname;
|
||||
int flags, *lenp;
|
||||
{
|
||||
int x;
|
||||
char *r;
|
||||
|
||||
x = tilde_find_suffix (fname);
|
||||
if (x == 0)
|
||||
{
|
||||
r = savestring (fname);
|
||||
if (lenp)
|
||||
*lenp = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = (char *)xmalloc (1 + x);
|
||||
strncpy (r, fname, x);
|
||||
r[x] = '\0';
|
||||
if (lenp)
|
||||
*lenp = x;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Return a string that is PREFIX concatenated with SUFFIX starting at
|
||||
SUFFIND. */
|
||||
static char *
|
||||
|
|
@ -347,7 +386,11 @@ tilde_expand_word (filename)
|
|||
/* No preexpansion hook, or the preexpansion hook failed. Look in the
|
||||
password database. */
|
||||
dirname = (char *)NULL;
|
||||
#if defined (HAVE_GETPWNAM)
|
||||
user_entry = getpwnam (username);
|
||||
#else
|
||||
user_entry = 0;
|
||||
#endif
|
||||
if (user_entry == 0)
|
||||
{
|
||||
/* If the calling program has a special syntax for expanding tildes,
|
||||
|
|
@ -372,8 +415,9 @@ tilde_expand_word (filename)
|
|||
free (username);
|
||||
dirname = glue_prefix_and_suffix (user_entry->pw_dir, filename, user_len);
|
||||
}
|
||||
|
||||
#if defined (HAVE_GETPWENT)
|
||||
endpwent ();
|
||||
#endif
|
||||
return (dirname);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,9 @@ extern char *tilde_expand PARAMS((const char *));
|
|||
tilde. If there is no expansion, call tilde_expansion_failure_hook. */
|
||||
extern char *tilde_expand_word PARAMS((const char *));
|
||||
|
||||
/* Find the portion of the string beginning with ~ that should be expanded. */
|
||||
extern char *tilde_find_word PARAMS((const char *, int, int *));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue