diff options
author | Chet Ramey <chet.ramey@case.edu> | 2011-12-29 13:10:02 -0500 |
---|---|---|
committer | Chet Ramey <chet.ramey@case.edu> | 2011-12-29 13:10:02 -0500 |
commit | b878ffd656187fc16c92a0c01b236bb6bf1ffcfc (patch) | |
tree | 93d11bd5a8bf5b76eea33f08cc79fde41c495ad0 /lib | |
parent | 51f7ea3672c1c9a6a59137292bc67b4b0626c060 (diff) | |
download | bash-b878ffd656187fc16c92a0c01b236bb6bf1ffcfc.tar.gz |
bash-20110622 remove leftover and stray files
Diffstat (limited to 'lib')
-rw-r--r-- | lib/glob/gmisc.c~ | 344 | ||||
-rw-r--r-- | lib/glob/sm_loop.c~ | 772 | ||||
-rw-r--r-- | lib/glob/smatch.c~ | 409 | ||||
-rw-r--r-- | lib/readline/#rlprivate.h# | 507 | ||||
-rw-r--r-- | lib/readline/bind.c~ | 2417 | ||||
-rw-r--r-- | lib/readline/display.c~ | 2738 | ||||
-rw-r--r-- | lib/readline/doc/Makefile.old | 76 | ||||
-rw-r--r-- | lib/readline/doc/readline.3~ | 1381 | ||||
-rw-r--r-- | lib/readline/doc/rluser.texi~ | 2054 | ||||
-rw-r--r-- | lib/readline/funmap.c~ | 263 | ||||
-rw-r--r-- | lib/readline/histfile.c~ | 581 | ||||
-rw-r--r-- | lib/readline/input.c~ | 610 | ||||
-rw-r--r-- | lib/readline/readline.h~ | 893 | ||||
-rw-r--r-- | lib/readline/rlprivate.h~ | 506 | ||||
-rw-r--r-- | lib/readline/rlstdc.h~ | 45 | ||||
-rw-r--r-- | lib/readline/rltty.c~ | 975 | ||||
-rw-r--r-- | lib/readline/rltypedefs.h~ | 93 | ||||
-rw-r--r-- | lib/readline/search.c~ | 590 | ||||
-rw-r--r-- | lib/readline/shell.c~ | 212 | ||||
-rw-r--r-- | lib/readline/signals.c~ | 678 | ||||
-rw-r--r-- | lib/readline/terminal.c~ | 737 |
21 files changed, 0 insertions, 16881 deletions
diff --git a/lib/glob/gmisc.c~ b/lib/glob/gmisc.c~ deleted file mode 100644 index 05327d15..00000000 --- a/lib/glob/gmisc.c~ +++ /dev/null @@ -1,344 +0,0 @@ -/* gmisc.c -- miscellaneous pattern matching utility functions for Bash. - - Copyright (C) 2010 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <config.h> - -#include "bashtypes.h" - -#if defined (HAVE_UNISTD_H) -# include <unistd.h> -#endif - -#include "bashansi.h" -#include "shmbutil.h" - -#include "stdc.h" - -#ifndef LPAREN -# define LPAREN '(' -#endif -#ifndef RPAREN -# define RPAREN ')' -#endif - -#if defined (HANDLE_MULTIBYTE) -#define WLPAREN L'(' -#define WRPAREN L')' - -/* Return 1 of the first character of WSTRING could match the first - character of pattern WPAT. Wide character version. */ -int -match_pattern_wchar (wpat, wstring) - wchar_t *wpat, *wstring; -{ - wchar_t wc; - - if (*wstring == 0) - return (0); - - switch (wc = *wpat++) - { - default: - return (*wstring == wc); - case L'\\': - return (*wstring == *wpat); - case L'?': - return (*wpat == WLPAREN ? 1 : (*wstring != L'\0')); - case L'*': - return (1); - case L'+': - case L'!': - case L'@': - return (*wpat == WLPAREN ? 1 : (*wstring == wc)); - case L'[': - return (*wstring != L'\0'); - } -} - -int -wmatchlen (wpat, wmax) - wchar_t *wpat; - size_t wmax; -{ - wchar_t wc; - int matlen, bracklen, t, in_cclass, in_collsym, in_equiv; - - if (*wpat == 0) - return (0); - - matlen = in_cclass = in_collsym = in_equiv = 0; - while (wc = *wpat++) - { - switch (wc) - { - default: - matlen++; - break; - case L'\\': - if (*wpat == 0) - return ++matlen; - else - { - matlen++; - wpat++; - } - break; - case L'?': - if (*wpat == WLPAREN) - return (matlen = -1); /* XXX for now */ - else - matlen++; - break; - case L'*': - return (matlen = -1); - case L'+': - case L'!': - case L'@': - if (*wpat == WLPAREN) - return (matlen = -1); /* XXX for now */ - else - matlen++; - break; - case L'[': - /* scan for ending `]', skipping over embedded [:...:] */ - bracklen = 1; - wc = *wpat++; - do - { - if (wc == 0) - { - wpat--; /* back up to NUL */ - matlen += bracklen; - goto bad_bracket; - } - else if (wc == L'\\') - { - /* *wpat == backslash-escaped character */ - bracklen++; - /* If the backslash or backslash-escape ends the string, - bail. The ++wpat skips over the backslash escape */ - if (*wpat == 0 || *++wpat == 0) - { - matlen += bracklen; - goto bad_bracket; - } - } - else if (wc == L'[' && *wpat == L':') /* character class */ - { - wpat++; - in_cclass = 1; - } - else if (in_cclass && wc == L':' && *wpat == L']') - { - wpat++; - in_cclass = 0; - } - else if (wc == L'[' && *wpat == L'.') /* collating symbol */ - { - wpat++; - if (*wpat == L']') /* right bracket can appear as collating symbol */ - wpat++; - in_collsym = 1; - } - else if (in_collsym && wc == L'.' && *wpat == L']') - { - wpat++; - in_collsym = 0; - } - else if (wc == L'[' && *wpat == L'=') /* equivalence class */ - { - wpat++; - if (*wpat == L']') /* right bracket can appear as equivalence class */ - wpat++; - in_equiv = 1; - } - else if (in_equiv && wc == L'=' && *wpat == L']') - { - wpat++; - in_equiv = 0; - } - } - while ((wc = *wpat++) != L']'); - matlen++; /* bracket expression can only match one char */ -bad_bracket: - break; - } - } - - return matlen; -} -#endif - -/* Return 1 of the first character of STRING could match the first - character of pattern PAT. Used to avoid n2 calls to strmatch(). */ -int -match_pattern_char (pat, string) - char *pat, *string; -{ - char c; - - if (*string == 0) - return (0); - - switch (c = *pat++) - { - default: - return (*string == c); - case '\\': - return (*string == *pat); - case '?': - return (*pat == LPAREN ? 1 : (*string != '\0')); - case '*': - return (1); - case '+': - case '!': - case '@': - return (*pat == LPAREN ? 1 : (*string == c)); - case '[': - return (*string != '\0'); - } -} - -int -umatchlen (pat, max) - char *pat; - size_t max; -{ - char c; - int matlen, bracklen, t, in_cclass, in_collsym, in_equiv; - - if (*pat == 0) - return (0); - - matlen = in_cclass = in_collsym = in_equiv = 0; - while (c = *pat++) - { - switch (c) - { - default: - matlen++; - break; - case '\\': - if (*pat == 0) - return ++matlen; - else - { - matlen++; - pat++; - } - break; - case '?': - if (*pat == LPAREN) - return (matlen = -1); /* XXX for now */ - else - matlen++; - break; - case '*': - return (matlen = -1); - case '+': - case '!': - case '@': - if (*pat == LPAREN) - return (matlen = -1); /* XXX for now */ - else - matlen++; - break; - case '[': - /* scan for ending `]', skipping over embedded [:...:] */ - bracklen = 1; - c = *pat++; - do - { - if (c == 0) - { - pat--; /* back up to NUL */ - matlen += bracklen; - goto bad_bracket; - } - else if (c == '\\') - { - /* *pat == backslash-escaped character */ - bracklen++; - /* If the backslash or backslash-escape ends the string, - bail. The ++pat skips over the backslash escape */ - if (*pat == 0 || *++pat == 0) - { - matlen += bracklen; - goto bad_bracket; - } - } - else if (c == '[' && *pat == ':') /* character class */ - { - pat++; - bracklen++; - in_cclass = 1; - } - else if (in_cclass && c == ':' && *pat == ']') - { - pat++; - bracklen++; - in_cclass = 0; - } - else if (c == '[' && *pat == '.') /* collating symbol */ - { - pat++; - bracklen++; - if (*pat == ']') /* right bracket can appear as collating symbol */ - { - pat++; - bracklen++; - } - in_collsym = 1; - } - else if (in_collsym && c == '.' && *pat == ']') - { - pat++; - bracklen++; - in_collsym = 0; - } - else if (c == '[' && *pat == '=') /* equivalence class */ - { - pat++; - bracklen++; - if (*pat == ']') /* right bracket can appear as equivalence class */ - { - pat++; - bracklen++; - } - in_equiv = 1; - } - else if (in_equiv && c == '=' && *pat == ']') - { - pat++; - bracklen++; - in_equiv = 0; - } - else - bracklen++; - } - while ((c = *pat++) != ']'); - matlen++; /* bracket expression can only match one char */ -bad_bracket: - break; - } - } - - return matlen; -} diff --git a/lib/glob/sm_loop.c~ b/lib/glob/sm_loop.c~ deleted file mode 100644 index 54320111..00000000 --- a/lib/glob/sm_loop.c~ +++ /dev/null @@ -1,772 +0,0 @@ -/* Copyright (C) 1991-2006 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>. -*/ - -int FCT __P((CHAR *, CHAR *, int)); - -static int GMATCH __P((CHAR *, CHAR *, CHAR *, CHAR *, int)); -static CHAR *PARSE_COLLSYM __P((CHAR *, INT *)); -static CHAR *BRACKMATCH __P((CHAR *, U_CHAR, int)); -static int EXTMATCH __P((INT, CHAR *, CHAR *, CHAR *, CHAR *, int)); -static CHAR *PATSCAN __P((CHAR *, CHAR *, INT)); - -int -FCT (pattern, string, flags) - CHAR *pattern; - CHAR *string; - int flags; -{ - CHAR *se, *pe; - - if (string == 0 || pattern == 0) - return FNM_NOMATCH; - - se = string + STRLEN ((XCHAR *)string); - pe = pattern + STRLEN ((XCHAR *)pattern); - - return (GMATCH (string, se, pattern, pe, flags)); -} - -/* Match STRING against the filename pattern PATTERN, returning zero if - it matches, FNM_NOMATCH if not. */ -static int -GMATCH (string, se, pattern, pe, flags) - CHAR *string, *se; - CHAR *pattern, *pe; - int flags; -{ - CHAR *p, *n; /* pattern, string */ - INT c; /* current pattern character - XXX U_CHAR? */ - INT sc; /* current string character - XXX U_CHAR? */ - - p = pattern; - n = string; - - if (string == 0 || pattern == 0) - return FNM_NOMATCH; - -#if DEBUG_MATCHING -fprintf(stderr, "gmatch: string = %s; se = %s\n", string, se); -fprintf(stderr, "gmatch: pattern = %s; pe = %s\n", pattern, pe); -#endif - - while (p < pe) - { - c = *p++; - c = FOLD (c); - - sc = n < se ? *n : '\0'; - -#ifdef EXTENDED_GLOB - /* EXTMATCH () will handle recursively calling GMATCH, so we can - just return what EXTMATCH() returns. */ - if ((flags & FNM_EXTMATCH) && *p == L('(') && - (c == L('+') || c == L('*') || c == L('?') || c == L('@') || c == L('!'))) /* ) */ - { - int lflags; - /* If we're not matching the start of the string, we're not - concerned about the special cases for matching `.' */ - lflags = (n == string) ? flags : (flags & ~FNM_PERIOD); - return (EXTMATCH (c, n, se, p, pe, lflags)); - } -#endif /* EXTENDED_GLOB */ - - switch (c) - { - case L('?'): /* Match single character */ - if (sc == '\0') - return FNM_NOMATCH; - else if ((flags & FNM_PATHNAME) && sc == L('/')) - /* If we are matching a pathname, `?' can never match a `/'. */ - return FNM_NOMATCH; - else if ((flags & FNM_PERIOD) && sc == L('.') && - (n == string || ((flags & FNM_PATHNAME) && n[-1] == L('/')))) - /* `?' cannot match a `.' if it is the first character of the - string or if it is the first character following a slash and - we are matching a pathname. */ - return FNM_NOMATCH; - break; - - case L('\\'): /* backslash escape removes special meaning */ - if (p == pe) - return FNM_NOMATCH; - - if ((flags & FNM_NOESCAPE) == 0) - { - c = *p++; - /* A trailing `\' cannot match. */ - if (p > pe) - return FNM_NOMATCH; - c = FOLD (c); - } - if (FOLD (sc) != (U_CHAR)c) - return FNM_NOMATCH; - break; - - case '*': /* Match zero or more characters */ - if (p == pe) - return 0; - - if ((flags & FNM_PERIOD) && sc == L('.') && - (n == string || ((flags & FNM_PATHNAME) && n[-1] == L('/')))) - /* `*' cannot match a `.' if it is the first character of the - string or if it is the first character following a slash and - we are matching a pathname. */ - return FNM_NOMATCH; - - /* Collapse multiple consecutive `*' and `?', but make sure that - one character of the string is consumed for each `?'. */ - for (c = *p++; (c == L('?') || c == L('*')); c = *p++) - { - if ((flags & FNM_PATHNAME) && sc == L('/')) - /* A slash does not match a wildcard under FNM_PATHNAME. */ - return FNM_NOMATCH; -#ifdef EXTENDED_GLOB - else if ((flags & FNM_EXTMATCH) && c == L('?') && *p == L('(')) /* ) */ - { - CHAR *newn; - for (newn = n; newn < se; ++newn) - { - if (EXTMATCH (c, newn, se, p, pe, flags) == 0) - return (0); - } - /* We didn't match. If we have a `?(...)', that's failure. */ - return FNM_NOMATCH; - } -#endif - else if (c == L('?')) - { - if (sc == L('\0')) - return FNM_NOMATCH; - /* One character of the string is consumed in matching - this ? wildcard, so *??? won't match if there are - fewer than three characters. */ - n++; - sc = n < se ? *n : '\0'; - } - -#ifdef EXTENDED_GLOB - /* Handle ******(patlist) */ - if ((flags & FNM_EXTMATCH) && c == L('*') && *p == L('(')) /*)*/ - { - CHAR *newn; - /* We need to check whether or not the extended glob - pattern matches the remainder of the string. - If it does, we match the entire pattern. */ - for (newn = n; newn < se; ++newn) - { - if (EXTMATCH (c, newn, se, p, pe, flags) == 0) - return (0); - } - /* We didn't match the extended glob pattern, but - that's OK, since we can match 0 or more occurrences. - We need to skip the glob pattern and see if we - match the rest of the string. */ - newn = PATSCAN (p + 1, pe, 0); - /* If NEWN is 0, we have an ill-formed pattern. */ - p = newn ? newn : pe; - } -#endif - if (p == pe) - break; - } - - /* If we've hit the end of the pattern and the last character of - the pattern was handled by the loop above, we've succeeded. - Otherwise, we need to match that last character. */ - if (p == pe && (c == L('?') || c == L('*'))) - return (0); - - /* General case, use recursion. */ - { - U_CHAR c1; - - c1 = ((flags & FNM_NOESCAPE) == 0 && c == L('\\')) ? *p : c; - c1 = FOLD (c1); - for (--p; n < se; ++n) - { - /* Only call strmatch if the first character indicates a - possible match. We can check the first character if - we're not doing an extended glob match. */ - if ((flags & FNM_EXTMATCH) == 0 && c != L('[') && FOLD (*n) != c1) /*]*/ - continue; - - /* If we're doing an extended glob match and the pattern is not - one of the extended glob patterns, we can check the first - character. */ - if ((flags & FNM_EXTMATCH) && p[1] != L('(') && /*)*/ - STRCHR (L("?*+@!"), *p) == 0 && c != L('[') && FOLD (*n) != c1) /*]*/ - continue; - - /* Otherwise, we just recurse. */ - if (GMATCH (n, se, p, pe, flags & ~FNM_PERIOD) == 0) - return (0); - } - return FNM_NOMATCH; - } - - case L('['): - { - if (sc == L('\0') || n == se) - return FNM_NOMATCH; - - /* A character class cannot match a `.' if it is the first - character of the string or if it is the first character - following a slash and we are matching a pathname. */ - if ((flags & FNM_PERIOD) && sc == L('.') && - (n == string || ((flags & FNM_PATHNAME) && n[-1] == L('/')))) - return (FNM_NOMATCH); - - p = BRACKMATCH (p, sc, flags); - if (p == 0) - return FNM_NOMATCH; - } - break; - - default: - if ((U_CHAR)c != FOLD (sc)) - return (FNM_NOMATCH); - } - - ++n; - } - - if (n == se) - return (0); - - if ((flags & FNM_LEADING_DIR) && *n == L('/')) - /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */ - return 0; - - return (FNM_NOMATCH); -} - -/* Parse a bracket expression collating symbol ([.sym.]) starting at P, find - the value of the symbol, and move P past the collating symbol expression. - The value is returned in *VP, if VP is not null. */ -static CHAR * -PARSE_COLLSYM (p, vp) - CHAR *p; - INT *vp; -{ - register int pc; - INT val; - - p++; /* move past the `.' */ - - for (pc = 0; p[pc]; pc++) - if (p[pc] == L('.') && p[pc+1] == L(']')) - break; - val = COLLSYM (p, pc); - if (vp) - *vp = val; - return (p + pc + 2); -} - -/* Use prototype definition here because of type promotion. */ -static CHAR * -#if defined (PROTOTYPES) -BRACKMATCH (CHAR *p, U_CHAR test, int flags) -#else -BRACKMATCH (p, test, flags) - CHAR *p; - U_CHAR test; - int flags; -#endif -{ - register CHAR cstart, cend, c; - register int not; /* Nonzero if the sense of the character class is inverted. */ - int brcnt, forcecoll;; - INT pc; - CHAR *savep; - - test = FOLD (test); - - savep = p; - - /* POSIX.2 3.13.1 says that an exclamation mark (`!') shall replace the - circumflex (`^') in its role in a `nonmatching list'. A bracket - expression starting with an unquoted circumflex character produces - unspecified results. This implementation treats the two identically. */ - if (not = (*p == L('!') || *p == L('^'))) - ++p; - - c = *p++; - for (;;) - { - /* Initialize cstart and cend in case `-' is the last - character of the pattern. */ - cstart = cend = c; - forcecoll = 0; - - /* POSIX.2 equivalence class: [=c=]. See POSIX.2 2.8.3.2. Find - the end of the equivalence class, move the pattern pointer past - it, and check for equivalence. XXX - this handles only - single-character equivalence classes, which is wrong, or at - least incomplete. */ - if (c == L('[') && *p == L('=') && p[2] == L('=') && p[3] == L(']')) - { - pc = FOLD (p[1]); - p += 4; - if (COLLEQUIV (test, pc)) - { -/*[*/ /* Move past the closing `]', since the first thing we do at - the `matched:' label is back p up one. */ - p++; - goto matched; - } - else - { - c = *p++; - if (c == L('\0')) - return ((test == L('[')) ? savep : (CHAR *)0); /*]*/ - c = FOLD (c); - continue; - } - } - - /* POSIX.2 character class expression. See POSIX.2 2.8.3.2. */ - if (c == L('[') && *p == L(':')) - { - CHAR *close, *ccname; - - pc = 0; /* make sure invalid char classes don't match. */ - /* Find end of character class name */ - for (close = p + 1; *close != '\0'; close++) - if (*close == L(':') && *(close+1) == L(']')) - break; - - if (*close != L('\0')) - { - ccname = (CHAR *)malloc ((close - p) * sizeof (CHAR)); - if (ccname == 0) - pc = 0; - else - { - bcopy (p + 1, ccname, (close - p - 1) * sizeof (CHAR)); - *(ccname + (close - p - 1)) = L('\0'); - pc = IS_CCLASS (test, (XCHAR *)ccname); - } - if (pc == -1) - pc = 0; - else - p = close + 2; - - free (ccname); - } - - if (pc) - { -/*[*/ /* Move past the closing `]', since the first thing we do at - the `matched:' label is back p up one. */ - p++; - goto matched; - } - else - { - /* continue the loop here, since this expression can't be - the first part of a range expression. */ - c = *p++; - if (c == L('\0')) - return ((test == L('[')) ? savep : (CHAR *)0); - else if (c == L(']')) - break; - c = FOLD (c); - continue; - } - } - - /* POSIX.2 collating symbols. See POSIX.2 2.8.3.2. Find the end of - the symbol name, make sure it is terminated by `.]', translate - the name to a character using the external table, and do the - comparison. */ - if (c == L('[') && *p == L('.')) - { - p = PARSE_COLLSYM (p, &pc); - /* An invalid collating symbol cannot be the first point of a - range. If it is, we set cstart to one greater than `test', - so any comparisons later will fail. */ - cstart = (pc == INVALID) ? test + 1 : pc; - forcecoll = 1; - } - - if (!(flags & FNM_NOESCAPE) && c == L('\\')) - { - if (*p == '\0') - return (CHAR *)0; - cstart = cend = *p++; - } - - cstart = cend = FOLD (cstart); - - /* POSIX.2 2.8.3.1.2 says: `An expression containing a `[' that - is not preceded by a backslash and is not part of a bracket - expression produces undefined results.' This implementation - treats the `[' as just a character to be matched if there is - not a closing `]'. */ - if (c == L('\0')) - return ((test == L('[')) ? savep : (CHAR *)0); - - c = *p++; - c = FOLD (c); - - if ((flags & FNM_PATHNAME) && c == L('/')) - /* [/] can never match when matching a pathname. */ - return (CHAR *)0; - - /* This introduces a range, unless the `-' is the last - character of the class. Find the end of the range - and move past it. */ - if (c == L('-') && *p != L(']')) - { - cend = *p++; - if (!(flags & FNM_NOESCAPE) && cend == L('\\')) - cend = *p++; - if (cend == L('\0')) - return (CHAR *)0; - if (cend == L('[') && *p == L('.')) - { - p = PARSE_COLLSYM (p, &pc); - /* An invalid collating symbol cannot be the second part of a - range expression. If we get one, we set cend to one fewer - than the test character to make sure the range test fails. */ - cend = (pc == INVALID) ? test - 1 : pc; - forcecoll = 1; - } - cend = FOLD (cend); - - c = *p++; - - /* POSIX.2 2.8.3.2: ``The ending range point shall collate - equal to or higher than the starting range point; otherwise - the expression shall be treated as invalid.'' Note that this - applies to only the range expression; the rest of the bracket - expression is still checked for matches. */ - if (RANGECMP (cstart, cend, forcecoll) > 0) - { - if (c == L(']')) - break; - c = FOLD (c); - continue; - } - } - - if (RANGECMP (test, cstart, forcecoll) >= 0 && RANGECMP (test, cend, forcecoll) <= 0) - goto matched; - - if (c == L(']')) - break; - } - /* No match. */ - return (!not ? (CHAR *)0 : p); - -matched: - /* Skip the rest of the [...] that already matched. */ - c = *--p; - brcnt = 1; - while (brcnt > 0) - { - /* A `[' without a matching `]' is just another character to match. */ - if (c == L('\0')) - return ((test == L('[')) ? savep : (CHAR *)0); - - c = *p++; - if (c == L('[') && (*p == L('=') || *p == L(':') || *p == L('.'))) - brcnt++; - else if (c == L(']')) - brcnt--; - else if (!(flags & FNM_NOESCAPE) && c == L('\\')) - { - if (*p == '\0') - return (CHAR *)0; - /* XXX 1003.2d11 is unclear if this is right. */ - ++p; - } - } - return (not ? (CHAR *)0 : p); -} - -#if defined (EXTENDED_GLOB) -/* ksh-like extended pattern matching: - - [?*+@!](pat-list) - - where pat-list is a list of one or patterns separated by `|'. Operation - is as follows: - - ?(patlist) match zero or one of the given patterns - *(patlist) match zero or more of the given patterns - +(patlist) match one or more of the given patterns - @(patlist) match exactly one of the given patterns - !(patlist) match anything except one of the given patterns -*/ - -/* Scan a pattern starting at STRING and ending at END, keeping track of - embedded () and []. If DELIM is 0, we scan until a matching `)' - because we're scanning a `patlist'. Otherwise, we scan until we see - DELIM. In all cases, we never scan past END. The return value is the - first character after the matching DELIM. */ -static CHAR * -PATSCAN (string, end, delim) - CHAR *string, *end; - INT delim; -{ - int pnest, bnest, skip; - INT cchar; - CHAR *s, c, *bfirst; - - pnest = bnest = skip = 0; - cchar = 0; - bfirst = NULL; - - for (s = string; c = *s; s++) - { - if (s >= end) - return (s); - if (skip) - { - skip = 0; - continue; - } - switch (c) - { - case L('\\'): - skip = 1; - break; - - case L('\0'): - return ((CHAR *)NULL); - - /* `[' is not special inside a bracket expression, but it may - introduce one of the special POSIX bracket expressions - ([.SYM.], [=c=], [: ... :]) that needs special handling. */ - case L('['): - if (bnest == 0) - { - bfirst = s + 1; - if (*bfirst == L('!') || *bfirst == L('^')) - bfirst++; - bnest++; - } - else if (s[1] == L(':') || s[1] == L('.') || s[1] == L('=')) - cchar = s[1]; - break; - - /* `]' is not special if it's the first char (after a leading `!' - or `^') in a bracket expression or if it's part of one of the - special POSIX bracket expressions ([.SYM.], [=c=], [: ... :]) */ - case L(']'): - if (bnest) - { - if (cchar && s[-1] == cchar) - cchar = 0; - else if (s != bfirst) - { - bnest--; - bfirst = 0; - } - } - break; - - case L('('): - if (bnest == 0) - pnest++; - break; - - case L(')'): - if (bnest == 0 && pnest-- <= 0) - return ++s; - break; - - case L('|'): - if (bnest == 0 && pnest == 0 && delim == L('|')) - return ++s; - break; - } - } - - return (NULL); -} - -/* Return 0 if dequoted pattern matches S in the current locale. */ -static int -STRCOMPARE (p, pe, s, se) - CHAR *p, *pe, *s, *se; -{ - int ret; - CHAR c1, c2; - - c1 = *pe; - c2 = *se; - - *pe = *se = '\0'; -#if HAVE_MULTIBYTE || defined (HAVE_STRCOLL) - ret = STRCOLL ((XCHAR *)p, (XCHAR *)s); -#else - ret = STRCMP ((XCHAR *)p, (XCHAR *)s); -#endif - - *pe = c1; - *se = c2; - - return (ret == 0 ? ret : FNM_NOMATCH); -} - -/* Match a ksh extended pattern specifier. Return FNM_NOMATCH on failure or - 0 on success. This is handed the entire rest of the pattern and string - the first time an extended pattern specifier is encountered, so it calls - gmatch recursively. */ -static int -EXTMATCH (xc, s, se, p, pe, flags) - INT xc; /* select which operation */ - CHAR *s, *se; - CHAR *p, *pe; - int flags; -{ - CHAR *prest; /* pointer to rest of pattern */ - CHAR *psub; /* pointer to sub-pattern */ - CHAR *pnext; /* pointer to next sub-pattern */ - CHAR *srest; /* pointer to rest of string */ - int m1, m2, xflags; /* xflags = flags passed to recursive matches */ - -#if DEBUG_MATCHING -fprintf(stderr, "extmatch: xc = %c\n", xc); -fprintf(stderr, "extmatch: s = %s; se = %s\n", s, se); -fprintf(stderr, "extmatch: p = %s; pe = %s\n", p, pe); -fprintf(stderr, "extmatch: flags = %d\n", flags); -#endif - - prest = PATSCAN (p + (*p == L('(')), pe, 0); /* ) */ - if (prest == 0) - /* If PREST is 0, we failed to scan a valid pattern. In this - case, we just want to compare the two as strings. */ - return (STRCOMPARE (p - 1, pe, s, se)); - - switch (xc) - { - case L('+'): /* match one or more occurrences */ - case L('*'): /* match zero or more occurrences */ - /* If we can get away with no matches, don't even bother. Just - call GMATCH on the rest of the pattern and return success if - it succeeds. */ - if (xc == L('*') && (GMATCH (s, se, prest, pe, flags) == 0)) - return 0; - - /* OK, we have to do this the hard way. First, we make sure one of - the subpatterns matches, then we try to match the rest of the - string. */ - for (psub = p + 1; ; psub = pnext) - { - pnext = PATSCAN (psub, pe, L('|')); - for (srest = s; srest <= se; srest++) - { - /* Match this substring (S -> SREST) against this - subpattern (psub -> pnext - 1) */ - m1 = GMATCH (s, srest, psub, pnext - 1, flags) == 0; - /* OK, we matched a subpattern, so make sure the rest of the - string matches the rest of the pattern. Also handle - multiple matches of the pattern. */ - if (m1) - { - /* if srest > s, we are not at start of string */ - xflags = (srest > s) ? (flags & ~FNM_PERIOD) : flags; - m2 = (GMATCH (srest, se, prest, pe, xflags) == 0) || - (s != srest && GMATCH (srest, se, p - 1, pe, xflags) == 0); - } - if (m1 && m2) - return (0); - } - if (pnext == prest) - break; - } - return (FNM_NOMATCH); - - case L('?'): /* match zero or one of the patterns */ - case L('@'): /* match one (or more) of the patterns */ - /* If we can get away with no matches, don't even bother. Just - call gmatch on the rest of the pattern and return success if - it succeeds. */ - if (xc == L('?') && (GMATCH (s, se, prest, pe, flags) == 0)) - return 0; - - /* OK, we have to do this the hard way. First, we see if one of - the subpatterns matches, then, if it does, we try to match the - rest of the string. */ - for (psub = p + 1; ; psub = pnext) - { - pnext = PATSCAN (psub, pe, L('|')); - srest = (prest == pe) ? se : s; - for ( ; srest <= se; srest++) - { - /* if srest > s, we are not at start of string */ - xflags = (srest > s) ? (flags & ~FNM_PERIOD) : flags; - if (GMATCH (s, srest, psub, pnext - 1, flags) == 0 && - GMATCH (srest, se, prest, pe, xflags) == 0) - return (0); - } - if (pnext == prest) - break; - } - return (FNM_NOMATCH); - - case '!': /* match anything *except* one of the patterns */ - for (srest = s; srest <= se; srest++) - { - m1 = 0; - for (psub = p + 1; ; psub = pnext) - { - pnext = PATSCAN (psub, pe, L('|')); - /* If one of the patterns matches, just bail immediately. */ - if (m1 = (GMATCH (s, srest, psub, pnext - 1, flags) == 0)) - break; - if (pnext == prest) - break; - } - /* if srest > s, we are not at start of string */ - xflags = (srest > s) ? (flags & ~FNM_PERIOD) : flags; - if (m1 == 0 && GMATCH (srest, se, prest, pe, xflags) == 0) - return (0); - } - return (FNM_NOMATCH); - } - - return (FNM_NOMATCH); -} -#endif /* EXTENDED_GLOB */ - -#undef IS_CCLASS -#undef FOLD -#undef CHAR -#undef U_CHAR -#undef XCHAR -#undef INT -#undef INVALID -#undef FCT -#undef GMATCH -#undef COLLSYM -#undef PARSE_COLLSYM -#undef PATSCAN -#undef STRCOMPARE -#undef EXTMATCH -#undef BRACKMATCH -#undef STRCHR -#undef STRCOLL -#undef STRLEN -#undef STRCMP -#undef COLLEQUIV -#undef RANGECMP -#undef L diff --git a/lib/glob/smatch.c~ b/lib/glob/smatch.c~ deleted file mode 100644 index adc13cd0..00000000 --- a/lib/glob/smatch.c~ +++ /dev/null @@ -1,409 +0,0 @@ -/* strmatch.c -- ksh-like extended pattern matching for the shell and filename - globbing. */ - -/* Copyright (C) 1991-2011 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <config.h> - -#include <stdio.h> /* for debugging */ - -#include "strmatch.h" -#include <chartypes.h> - -#include "bashansi.h" -#include "shmbutil.h" -#include "xmalloc.h" - -/* First, compile `sm_loop.c' for single-byte characters. */ -#define CHAR unsigned char -#define U_CHAR unsigned char -#define XCHAR char -#define INT int -#define L(CS) CS -#define INVALID -1 - -#undef STREQ -#undef STREQN -#define STREQ(a, b) ((a)[0] == (b)[0] && strcmp(a, b) == 0) -#define STREQN(a, b, n) ((a)[0] == (b)[0] && strncmp(a, b, n) == 0) - -int glob_asciirange = 0; - -/* We use strcoll(3) for range comparisons in bracket expressions, - even though it can have unwanted side effects in locales - other than POSIX or US. For instance, in the de locale, [A-Z] matches - all characters. */ - -#if defined (HAVE_STRCOLL) -/* Helper function for collating symbol equivalence. */ -static int -rangecmp (c1, c2, forcecoll) - int c1, c2; - int forcecoll; -{ - static char s1[2] = { ' ', '\0' }; - static char s2[2] = { ' ', '\0' }; - int ret; - - /* Eight bits only. Period. */ - c1 &= 0xFF; - c2 &= 0xFF; - - if (c1 == c2) - return (0); - - if (forcecoll == 0 && glob_asciirange) - return (c1 - c2); - - s1[0] = c1; - s2[0] = c2; - - if ((ret = strcoll (s1, s2)) != 0) - return ret; - return (c1 - c2); -} -#else /* !HAVE_STRCOLL */ -# define rangecmp(c1, c2, f) ((int)(c1) - (int)(c2)) -#endif /* !HAVE_STRCOLL */ - -#if defined (HAVE_STRCOLL) -static int -collequiv (c1, c2) - int c1, c2; -{ - return (rangecmp (c1, c2, 1) == 0); -} -#else -# define collequiv(c1, c2) ((c1) == (c2)) -#endif - -#define _COLLSYM _collsym -#define __COLLSYM __collsym -#define POSIXCOLL posix_collsyms -#include "collsyms.h" - -static int -collsym (s, len) - CHAR *s; - int len; -{ - register struct _collsym *csp; - char *x; - - x = (char *)s; - for (csp = posix_collsyms; csp->name; csp++) - { - if (STREQN(csp->name, x, len) && csp->name[len] == '\0') - return (csp->code); - } - if (len == 1) - return s[0]; - return INVALID; -} - -/* unibyte character classification */ -#if !defined (isascii) && !defined (HAVE_ISASCII) -# define isascii(c) ((unsigned int)(c) <= 0177) -#endif - -enum char_class - { - CC_NO_CLASS = 0, - CC_ASCII, CC_ALNUM, CC_ALPHA, CC_BLANK, CC_CNTRL, CC_DIGIT, CC_GRAPH, - CC_LOWER, CC_PRINT, CC_PUNCT, CC_SPACE, CC_UPPER, CC_WORD, CC_XDIGIT - }; - -static char const *const cclass_name[] = - { - "", - "ascii", "alnum", "alpha", "blank", "cntrl", "digit", "graph", - "lower", "print", "punct", "space", "upper", "word", "xdigit" - }; - -#define N_CHAR_CLASS (sizeof(cclass_name) / sizeof (cclass_name[0])) - -static int -is_cclass (c, name) - int c; - const char *name; -{ - enum char_class char_class = CC_NO_CLASS; - int i, result; - - for (i = 1; i < N_CHAR_CLASS; i++) - { - if (STREQ (name, cclass_name[i])) - { - char_class = (enum char_class)i; - break; - } - } - - if (char_class == 0) - return -1; - - switch (char_class) - { - case CC_ASCII: - result = isascii (c); - break; - case CC_ALNUM: - result = ISALNUM (c); - break; - case CC_ALPHA: - result = ISALPHA (c); - break; - case CC_BLANK: - result = ISBLANK (c); - break; - case CC_CNTRL: - result = ISCNTRL (c); - break; - case CC_DIGIT: - result = ISDIGIT (c); - break; - case CC_GRAPH: - result = ISGRAPH (c); - break; - case CC_LOWER: - result = ISLOWER (c); - break; - case CC_PRINT: - result = ISPRINT (c); - break; - case CC_PUNCT: - result = ISPUNCT (c); - break; - case CC_SPACE: - result = ISSPACE (c); - break; - case CC_UPPER: - result = ISUPPER (c); - break; - case CC_WORD: - result = (ISALNUM (c) || c == '_'); - break; - case CC_XDIGIT: - result = ISXDIGIT (c); - break; - default: - result = -1; - break; - } - - return result; -} - -/* Now include `sm_loop.c' for single-byte characters. */ -/* The result of FOLD is an `unsigned char' */ -# define FOLD(c) ((flags & FNM_CASEFOLD) \ - ? TOLOWER ((unsigned char)c) \ - : ((unsigned char)c)) - -#define FCT internal_strmatch -#define GMATCH gmatch -#define COLLSYM collsym -#define PARSE_COLLSYM parse_collsym -#define BRACKMATCH brackmatch -#define PATSCAN patscan -#define STRCOMPARE strcompare -#define EXTMATCH extmatch -#define STRCHR(S, C) strchr((S), (C)) -#define STRCOLL(S1, S2) strcoll((S1), (S2)) -#define STRLEN(S) strlen(S) -#define STRCMP(S1, S2) strcmp((S1), (S2)) -#define RANGECMP(C1, C2, F) rangecmp((C1), (C2), (F)) -#define COLLEQUIV(C1, C2) collequiv((C1), (C2)) -#define CTYPE_T enum char_class -#define IS_CCLASS(C, S) is_cclass((C), (S)) -#include "sm_loop.c" - -#if HANDLE_MULTIBYTE - -# define CHAR wchar_t -# define U_CHAR wint_t -# define XCHAR wchar_t -# define INT wint_t -# define L(CS) L##CS -# define INVALID WEOF - -# undef STREQ -# undef STREQN -# define STREQ(s1, s2) ((wcscmp (s1, s2) == 0)) -# define STREQN(a, b, n) ((a)[0] == (b)[0] && wcsncmp(a, b, n) == 0) - -extern char *mbsmbchar __P((const char *)); - -static int -rangecmp_wc (c1, c2, forcecoll) - wint_t c1, c2; - int forcecoll; -{ - static wchar_t s1[2] = { L' ', L'\0' }; - static wchar_t s2[2] = { L' ', L'\0' }; - - if (c1 == c2) - return 0; - - if (forcecoll == 0 && glob_asciirange && c1 <= UCHAR_MAX && c2 <= UCHAR_MAX) - return ((int)(c1 - c2)); - - s1[0] = c1; - s2[0] = c2; - - return (wcscoll (s1, s2)); -} - -static int -collequiv_wc (c, equiv) - wint_t c, equiv; -{ - return (c == equiv); -} - -/* Helper function for collating symbol. */ -# define _COLLSYM _collwcsym -# define __COLLSYM __collwcsym -# define POSIXCOLL posix_collwcsyms -# include "collsyms.h" - -static wint_t -collwcsym (s, len) - wchar_t *s; - int len; -{ - register struct _collwcsym *csp; - - for (csp = posix_collwcsyms; csp->name; csp++) - { - if (STREQN(csp->name, s, len) && csp->name[len] == L'\0') - return (csp->code); - } - if (len == 1) - return s[0]; - return INVALID; -} - -static int -is_wcclass (wc, name) - wint_t wc; - wchar_t *name; -{ - char *mbs; - mbstate_t state; - size_t mbslength; - wctype_t desc; - int want_word; - - if ((wctype ("ascii") == (wctype_t)0) && (wcscmp (name, L"ascii") == 0)) - { - int c; - - if ((c = wctob (wc)) == EOF) - return 0; - else - return (c <= 0x7F); - } - - want_word = (wcscmp (name, L"word") == 0); - if (want_word) - name = L"alnum"; - - memset (&state, '\0', sizeof (mbstate_t)); - mbs = (char *) malloc (wcslen(name) * MB_CUR_MAX + 1); - mbslength = wcsrtombs (mbs, (const wchar_t **)&name, (wcslen(name) * MB_CUR_MAX + 1), &state); - - if (mbslength == (size_t)-1 || mbslength == (size_t)-2) - { - free (mbs); - return -1; - } - desc = wctype (mbs); - free (mbs); - - if (desc == (wctype_t)0) - return -1; - - if (want_word) - return (iswctype (wc, desc) || wc == L'_'); - else - return (iswctype (wc, desc)); -} - -/* Now include `sm_loop.c' for multibyte characters. */ -#define FOLD(c) ((flags & FNM_CASEFOLD) && iswupper (c) ? towlower (c) : (c)) -#define FCT internal_wstrmatch -#define GMATCH gmatch_wc -#define COLLSYM collwcsym -#define PARSE_COLLSYM parse_collwcsym -#define BRACKMATCH brackmatch_wc -#define PATSCAN patscan_wc -#define STRCOMPARE wscompare -#define EXTMATCH extmatch_wc -#define STRCHR(S, C) wcschr((S), (C)) -#define STRCOLL(S1, S2) wcscoll((S1), (S2)) -#define STRLEN(S) wcslen(S) -#define STRCMP(S1, S2) wcscmp((S1), (S2)) -#define RANGECMP(C1, C2, F) rangecmp_wc((C1), (C2), (F)) -#define COLLEQUIV(C1, C2) collequiv_wc((C1), (C2)) -#define CTYPE_T enum char_class -#define IS_CCLASS(C, S) is_wcclass((C), (S)) -#include "sm_loop.c" - -#endif /* HAVE_MULTIBYTE */ - -int -xstrmatch (pattern, string, flags) - char *pattern; - char *string; - int flags; -{ -#if HANDLE_MULTIBYTE - int ret; - size_t n; - wchar_t *wpattern, *wstring; - size_t plen, slen, mplen, mslen; - - if (mbsmbchar (string) == 0 && mbsmbchar (pattern) == 0) - return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags)); - - if (MB_CUR_MAX == 1) - return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags)); - - n = xdupmbstowcs (&wpattern, NULL, pattern); - if (n == (size_t)-1 || n == (size_t)-2) - return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags)); - - n = xdupmbstowcs (&wstring, NULL, string); - if (n == (size_t)-1 || n == (size_t)-2) - { - free (wpattern); - return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags)); - } - - ret = internal_wstrmatch (wpattern, wstring, flags); - - free (wpattern); - free (wstring); - - return ret; -#else - return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags)); -#endif /* !HANDLE_MULTIBYTE */ -} diff --git a/lib/readline/#rlprivate.h# b/lib/readline/#rlprivate.h# deleted file mode 100644 index fb04b9a2..00000000 --- a/lib/readline/#rlprivate.h# +++ /dev/null @@ -1,507 +0,0 @@ -/* rlprivate.h -- functions and variables global to the readline library, - but not intended for use by applications. */ - -/* Copyright (C) 1999-2010 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library (Readline), a library - for reading lines of text with interactive input and history editing. - - Readline 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 3 of the License, or - (at your option) any later version. - - Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>. -*/ - -#if !defined (_RL_PRIVATE_H_) -#define _RL_PRIVATE_H_ - -#include "rlconf.h" /* for VISIBLE_STATS */ -#include "rlstdc.h" -#include "posixjmp.h" /* defines procenv_t */ - -/************************************************************************* - * * - * Convenience definitions * - * * - *************************************************************************/ - -#define EMACS_MODE() (rl_editing_mode == emacs_mode) -#define VI_COMMAND_MODE() (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap) -#define VI_INSERT_MODE() (rl_editing_mode == vi_mode && _rl_keymap == vi_insertion_keymap) - -#define RL_CHECK_SIGNALS() \ - do { \ - if (_rl_caught_signal) _rl_signal_handler (_rl_caught_signal); \ - } while (0) - -/************************************************************************* - * * - * 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 -#define SF_CHGKMAP 0x08 - -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; - - Keymap keymap; /* used when dispatching commands in search string */ - Keymap okeymap; /* original keymap */ - - 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; - -/* vi-mode commands that use result of motion command to define boundaries */ -#define VIM_DELETE 0x01 -#define VIM_CHANGE 0x02 -#define VIM_YANK 0x04 - -/* various states for vi-mode commands that use motion commands. reflects - RL_READLINE_STATE */ -#define VMSTATE_READ 0x01 -#define VMSTATE_NUMARG 0x02 - -typedef struct __rl_vimotion_context -{ - int op; - int state; - int flags; /* reserved */ - _rl_arg_cxt ncxt; - int numeric_arg; - int start, end; /* rl_point, rl_end */ - int key, motion; /* initial key, motion command */ -} _rl_vimotion_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 * - * * - *************************************************************************/ - -/************************************************************************* - * * - * Global variables undocumented in texinfo manual and not in readline.h * - * * - *************************************************************************/ - -/* complete.c */ -extern int rl_complete_with_tilde_expansion; -#if defined (VISIBLE_STATS) -extern int rl_visible_stats; -#endif /* VISIBLE_STATS */ - -/* readline.c */ -extern int rl_line_buffer_len; -extern int rl_arg_sign; -extern int rl_visible_prompt_length; -extern int rl_key_sequence_length; -extern int rl_byte_oriented; - -/* display.c */ -extern int rl_display_fixed; - -/* parens.c */ -extern int rl_blink_matching_paren; - -/************************************************************************* - * * - * Global functions and variables unsed and undocumented * - * * - *************************************************************************/ - -/* kill.c */ -extern int rl_set_retained_kills PARAMS((int)); - -/* terminal.c */ -extern void _rl_set_screen_size PARAMS((int, int)); - -/* undo.c */ -extern int _rl_fix_last_undo_of_type PARAMS((int, int, int)); - -/* util.c */ -extern char *_rl_savestring PARAMS((const char *)); - -/************************************************************************* - * * - * Functions and variables private to the readline library * - * * - *************************************************************************/ - -/* NOTE: Functions and variables prefixed with `_rl_' are - pseudo-global: they are global so they can be shared - between files in the readline library, but are not intended - to be visible to readline callers. */ - -/************************************************************************* - * Undocumented private functions * - *************************************************************************/ - -#if defined(READLINE_CALLBACKS) - -/* readline.c */ -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 */ - -/* complete.c */ -extern void _rl_reset_completion_state PARAMS((void)); -extern char _rl_find_completion_word PARAMS((int *, int *)); -extern void _rl_free_match_list PARAMS((char **)); - -/* display.c */ -extern char *_rl_strip_prompt PARAMS((char *)); -extern void _rl_move_cursor_relative PARAMS((int, const char *)); -extern void _rl_move_vert PARAMS((int)); -extern void _rl_save_prompt PARAMS((void)); -extern void _rl_restore_prompt PARAMS((void)); -extern char *_rl_make_prompt_for_search PARAMS((int)); -extern void _rl_erase_at_end_of_line PARAMS((int)); -extern void _rl_clear_to_eol PARAMS((int)); -extern void _rl_clear_screen PARAMS((void)); -extern void _rl_update_final PARAMS((void)); -extern void _rl_redisplay_after_sigwinch PARAMS((void)); -extern void _rl_clean_up_for_exit PARAMS((void)); -extern void _rl_erase_entire_line PARAMS((void)); -extern int _rl_current_display_line PARAMS((void)); - -/* input.c */ -extern int _rl_any_typein PARAMS((void)); -extern int _rl_input_available PARAMS((void)); -extern int _rl_input_queued PARAMS((int)); -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)); -extern void _rl_push_executing_macro PARAMS((void)); -extern void _rl_pop_executing_macro PARAMS((void)); -extern void _rl_add_macro_char PARAMS((int)); -extern void _rl_kill_kbd_macro PARAMS((void)); - -/* misc.c */ -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)); - -extern void _rl_revert_all_lines PARAMS((void)); - -/* nls.c */ -extern int _rl_init_eightbit PARAMS((void)); - -/* parens.c */ -extern void _rl_enable_paren_matching PARAMS((int)); - -/* readline.c */ -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 *)); - -/* signals.c */ -extern void _rl_signal_handler PARAMS((int)); - -extern void _rl_block_sigint PARAMS((void)); -extern void _rl_release_sigint PARAMS((void)); -extern void _rl_block_sigwinch PARAMS((void)); -extern void _rl_release_sigwinch PARAMS((void)); - -/* terminal.c */ -extern void _rl_get_screen_size PARAMS((int, int)); -e -extern int _rl_init_terminal_io PARAMS((const char *)); -#ifdef _MINIX -extern void _rl_output_character_function PARAMS((int)); -#else -extern int _rl_output_character_function PARAMS((int)); -#endif -extern void _rl_output_some_chars PARAMS((const char *, int)); -extern int _rl_backspace PARAMS((int)); -extern void _rl_enable_meta_key PARAMS((void)); -extern void _rl_control_keypad PARAMS((int)); -extern void _rl_set_cursor PARAMS((int, int)); - -/* text.c */ -extern void _rl_fix_point PARAMS((int)); -extern int _rl_replace_text PARAMS((const char *, int, int)); -extern int _rl_forward_char_internal PARAMS((int)); -extern int _rl_insert_char PARAMS((int, int)); -extern int _rl_overwrite_char PARAMS((int, int)); -extern int _rl_overwrite_rubout PARAMS((int, int)); -extern int _rl_rubout_char PARAMS((int, int)); -#if defined (HANDLE_MULTIBYTE) -extern int _rl_char_search_internal PARAMS((int, int, char *, int)); -#else -extern int _rl_char_search_internal PARAMS((int, int, int)); -#endif -extern int _rl_set_mark_at_pos PARAMS((int)); - -/* undo.c */ -extern UNDO_LIST *_rl_copy_undo_entry PARAMS((UNDO_LIST *)); -extern UNDO_LIST *_rl_copy_undo_list PARAMS((UNDO_LIST *)); - -/* util.c */ -#if defined (USE_VARARGS) && defined (PREFER_STDARG) -extern void _rl_ttymsg (const char *, ...) __attribute__((__format__ (printf, 1, 2))); -extern void _rl_errmsg (const char *, ...) __attribute__((__format__ (printf, 1, 2))); -extern void _rl_trace (const char *, ...) __attribute__((__format__ (printf, 1, 2))); -#else -extern void _rl_ttymsg (); -extern void _rl_errmsg (); -extern void _rl_trace (); -#endif - -extern int _rl_tropen PARAMS((void)); - -extern int _rl_abort_internal PARAMS((void)); -extern int _rl_null_function PARAMS((int, int)); -extern char *_rl_strindex PARAMS((const char *, const char *)); -extern int _rl_qsort_string_compare PARAMS((char **, char **)); -extern int (_rl_uppercase_p) PARAMS((int)); -extern int (_rl_lowercase_p) PARAMS((int)); -extern int (_rl_pure_alphabetic) PARAMS((int)); -extern int (_rl_digit_p) PARAMS((int)); -extern int (_rl_to_lower) PARAMS((int)); -extern int (_rl_to_upper) PARAMS((int)); -extern int (_rl_digit_value) PARAMS((int)); - -/* vi_mode.c */ -extern void _rl_vi_initialize_line PARAMS((void)); -extern void _rl_vi_reset_last PARAMS((void)); -extern void _rl_vi_set_last PARAMS((int, int, int)); -extern int _rl_vi_textmod_command PARAMS((int)); -extern void _rl_vi_done_inserting PARAMS((void)); -extern int _rl_vi_domove_callback PARAMS((_rl_vimotion_cxt *)); - -/************************************************************************* - * Undocumented private variables * - *************************************************************************/ - -/* bind.c */ -extern const char * const _rl_possible_control_prefixes[]; -extern const char * const _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; -extern int _rl_complete_mark_directories; -extern int _rl_complete_mark_symlink_dirs; -extern int _rl_completion_prefix_display_length; -extern int _rl_completion_columns; -extern int _rl_print_completions_horizontally; -extern int _rl_completion_case_fold; -extern int _rl_completion_case_map; -extern int _rl_match_hidden_files; -extern int _rl_page_completions; -extern int _rl_skip_completed_text; -extern int _rl_menu_complete_prefix_first; - -/* display.c */ -extern int _rl_vis_botlin; -extern int _rl_last_c_pos; -extern int _rl_suppress_redisplay; -extern int _rl_want_redisplay; - -/* isearch.c */ -extern char *_rl_isearch_terminators; - -extern _rl_search_cxt *_rl_iscxt; - -/* macro.c */ -extern char *_rl_executing_macro; - -/* misc.c */ -extern int _rl_history_preserve_point; -extern int _rl_history_saved_point; - -extern _rl_arg_cxt _rl_argcxt; - -/* readline.c */ -extern int _rl_echoing_p; -extern int _rl_horizontal_scroll_mode; -extern int _rl_mark_modified_lines; -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 int _rl_revert_all_at_newline; -extern int _rl_echo_control_chars; -extern char *_rl_comment_begin; -extern unsigned char _rl_parsing_conditionalized_out; -extern Keymap _rl_keymap; -extern FILE *_rl_in_stream; -extern FILE *_rl_out_stream; -extern int _rl_last_command_was_kill; -extern int _rl_eof_char; -extern procenv_t _rl_top_level; -extern _rl_keyseq_cxt *_rl_kscxt; - -/* search.c */ -extern _rl_search_cxt *_rl_nscxt; - -/* signals.c */ -extern int _rl_interrupt_immediately; -extern int volatile _rl_caught_signal; - -extern int _rl_echoctl; - -extern int _rl_intr_char; -extern int _rl_quit_char; -extern int _rl_susp_char; - -/* terminal.c */ -extern int _rl_enable_keypad; -extern int _rl_enable_meta; -extern char *_rl_term_clreol; -extern char *_rl_term_clrpag; -extern char *_rl_term_im; -extern char *_rl_term_ic; -extern char *_rl_term_ei; -extern char *_rl_term_DC; -extern char *_rl_term_up; -extern char *_rl_term_dc; -extern char *_rl_term_cr; -extern char *_rl_term_IC; -extern char *_rl_term_forward_char; -extern int _rl_screenheight; -extern int _rl_screenwidth; -extern int _rl_screenchars; -extern int _rl_terminal_can_insert; -extern int _rl_term_autowrap; - -/* undo.c */ -extern int _rl_doing_an_undo; -extern int _rl_undo_group_level; - -/* vi_mode.c */ -extern int _rl_vi_last_command; -extern _rl_vimotion_cxt *_rl_vimvcxt; - -#endif /* _RL_PRIVATE_H_ */ diff --git a/lib/readline/bind.c~ b/lib/readline/bind.c~ deleted file mode 100644 index d65ef261..00000000 --- a/lib/readline/bind.c~ +++ /dev/null @@ -1,2417 +0,0 @@ -/* bind.c -- key binding and startup file support for the readline library. */ - -/* Copyright (C) 1987-2010 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library (Readline), a library - for reading lines of text with interactive input and history editing. - - Readline 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 3 of the License, or - (at your option) any later version. - - Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>. -*/ - -#define READLINE_LIBRARY - -#if defined (__TANDEM) -# include <floss.h> -#endif - -#if defined (HAVE_CONFIG_H) -# include <config.h> -#endif - -#include <stdio.h> -#include <sys/types.h> -#include <fcntl.h> -#if defined (HAVE_SYS_FILE_H) -# include <sys/file.h> -#endif /* HAVE_SYS_FILE_H */ - -#if defined (HAVE_UNISTD_H) -# include <unistd.h> -#endif /* HAVE_UNISTD_H */ - -#if defined (HAVE_STDLIB_H) -# include <stdlib.h> -#else -# include "ansi_stdlib.h" -#endif /* HAVE_STDLIB_H */ - -#include <errno.h> - -#if !defined (errno) -extern int errno; -#endif /* !errno */ - -#include "posixstat.h" - -/* System-specific feature definitions and include files. */ -#include "rldefs.h" - -/* Some standard library routines. */ -#include "readline.h" -#include "history.h" - -#include "rlprivate.h" -#include "rlshell.h" -#include "xmalloc.h" - -#if !defined (strchr) && !defined (__STDC__) -extern char *strchr (), *strrchr (); -#endif /* !strchr && !__STDC__ */ - -/* Variables exported by this file. */ -Keymap rl_binding_keymap; - -static int _rl_skip_to_delim PARAMS((char *, int, int)); - -static char *_rl_read_file PARAMS((char *, size_t *)); -static void _rl_init_file_error PARAMS((const char *)); -static int _rl_read_init_file PARAMS((const char *, int)); -static int glean_key_from_name PARAMS((char *)); - -static int find_boolean_var PARAMS((const char *)); -static int find_string_var PARAMS((const char *)); - -static char *_rl_get_string_variable_value PARAMS((const char *)); -static int substring_member_of_array PARAMS((const char *, const char * const *)); - -static int currently_reading_init_file; - -/* used only in this file */ -static int _rl_prefer_visible_bell = 1; - -/* **************************************************************** */ -/* */ -/* Binding keys */ -/* */ -/* **************************************************************** */ - -/* rl_add_defun (char *name, rl_command_func_t *function, int key) - Add NAME to the list of named functions. Make FUNCTION be the function - that gets called. If KEY is not -1, then bind it. */ -int -rl_add_defun (name, function, key) - const char *name; - rl_command_func_t *function; - int key; -{ - if (key != -1) - rl_bind_key (key, function); - rl_add_funmap_entry (name, function); - return 0; -} - -/* Bind KEY to FUNCTION. Returns non-zero if KEY is out of range. */ -int -rl_bind_key (key, function) - int key; - rl_command_func_t *function; -{ - if (key < 0) - return (key); - - if (META_CHAR (key) && _rl_convert_meta_chars_to_ascii) - { - if (_rl_keymap[ESC].type == ISKMAP) - { - Keymap escmap; - - escmap = FUNCTION_TO_KEYMAP (_rl_keymap, ESC); - key = UNMETA (key); - escmap[key].type = ISFUNC; - escmap[key].function = function; - return (0); - } - return (key); - } - - _rl_keymap[key].type = ISFUNC; - _rl_keymap[key].function = function; - rl_binding_keymap = _rl_keymap; - return (0); -} - -/* Bind KEY to FUNCTION in MAP. Returns non-zero in case of invalid - KEY. */ -int -rl_bind_key_in_map (key, function, map) - int key; - rl_command_func_t *function; - Keymap map; -{ - int result; - Keymap oldmap; - - oldmap = _rl_keymap; - _rl_keymap = map; - result = rl_bind_key (key, function); - _rl_keymap = oldmap; - return (result); -} - -/* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. Right - now, this is always used to attempt to bind the arrow keys, hence the - check for rl_vi_movement_mode. */ -int -rl_bind_key_if_unbound_in_map (key, default_func, kmap) - int key; - rl_command_func_t *default_func; - Keymap kmap; -{ - char keyseq[2]; - - keyseq[0] = (unsigned char)key; - keyseq[1] = '\0'; - return (rl_bind_keyseq_if_unbound_in_map (keyseq, default_func, kmap)); -} - -int -rl_bind_key_if_unbound (key, default_func) - int key; - rl_command_func_t *default_func; -{ - char keyseq[2]; - - keyseq[0] = (unsigned char)key; - keyseq[1] = '\0'; - return (rl_bind_keyseq_if_unbound_in_map (keyseq, default_func, _rl_keymap)); -} - -/* Make KEY do nothing in the currently selected keymap. - Returns non-zero in case of error. */ -int -rl_unbind_key (key) - int key; -{ - return (rl_bind_key (key, (rl_command_func_t *)NULL)); -} - -/* Make KEY do nothing in MAP. - Returns non-zero in case of error. */ -int -rl_unbind_key_in_map (key, map) - int key; - Keymap map; -{ - return (rl_bind_key_in_map (key, (rl_command_func_t *)NULL, map)); -} - -/* Unbind all keys bound to FUNCTION in MAP. */ -int -rl_unbind_function_in_map (func, map) - rl_command_func_t *func; - Keymap map; -{ - register int i, rval; - - for (i = rval = 0; i < KEYMAP_SIZE; i++) - { - if (map[i].type == ISFUNC && map[i].function == func) - { - map[i].function = (rl_command_func_t *)NULL; - rval = 1; - } - } - return rval; -} - -int -rl_unbind_command_in_map (command, map) - const char *command; - Keymap map; -{ - rl_command_func_t *func; - - func = rl_named_function (command); - if (func == 0) - return 0; - return (rl_unbind_function_in_map (func, map)); -} - -/* Bind the key sequence represented by the string KEYSEQ to - FUNCTION, starting in the current keymap. This makes new - keymaps as necessary. */ -int -rl_bind_keyseq (keyseq, function) - const char *keyseq; - rl_command_func_t *function; -{ - return (rl_generic_bind (ISFUNC, keyseq, (char *)function, _rl_keymap)); -} - -/* Bind the key sequence represented by the string KEYSEQ to - FUNCTION. This makes new keymaps as necessary. The initial - place to do bindings is in MAP. */ -int -rl_bind_keyseq_in_map (keyseq, function, map) - const char *keyseq; - rl_command_func_t *function; - Keymap map; -{ - return (rl_generic_bind (ISFUNC, keyseq, (char *)function, map)); -} - -/* Backwards compatibility; equivalent to rl_bind_keyseq_in_map() */ -int -rl_set_key (keyseq, function, map) - const char *keyseq; - rl_command_func_t *function; - Keymap map; -{ - return (rl_generic_bind (ISFUNC, keyseq, (char *)function, map)); -} - -/* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. Right - now, this is always used to attempt to bind the arrow keys, hence the - check for rl_vi_movement_mode. */ -int -rl_bind_keyseq_if_unbound_in_map (keyseq, default_func, kmap) - const char *keyseq; - rl_command_func_t *default_func; - Keymap kmap; -{ - rl_command_func_t *func; - - if (keyseq) - { - func = rl_function_of_keyseq (keyseq, kmap, (int *)NULL); -#if defined (VI_MODE) - if (!func || func == rl_do_lowercase_version || func == rl_vi_movement_mode) -#else - if (!func || func == rl_do_lowercase_version) -#endif - return (rl_bind_keyseq_in_map (keyseq, default_func, kmap)); - else - return 1; - } - return 0; -} - -int -rl_bind_keyseq_if_unbound (keyseq, default_func) - const char *keyseq; - rl_command_func_t *default_func; -{ - return (rl_bind_keyseq_if_unbound_in_map (keyseq, default_func, _rl_keymap)); -} - -/* Bind the key sequence represented by the string KEYSEQ to - the string of characters MACRO. This makes new keymaps as - necessary. The initial place to do bindings is in MAP. */ -int -rl_macro_bind (keyseq, macro, map) - const char *keyseq, *macro; - Keymap map; -{ - char *macro_keys; - int macro_keys_len; - - macro_keys = (char *)xmalloc ((2 * strlen (macro)) + 1); - - if (rl_translate_keyseq (macro, macro_keys, ¯o_keys_len)) - { - xfree (macro_keys); - return -1; - } - rl_generic_bind (ISMACR, keyseq, macro_keys, map); - return 0; -} - -/* Bind the key sequence represented by the string KEYSEQ to - the arbitrary pointer DATA. TYPE says what kind of data is - pointed to by DATA, right now this can be a function (ISFUNC), - a macro (ISMACR), or a keymap (ISKMAP). This makes new keymaps - as necessary. The initial place to do bindings is in MAP. */ -int -rl_generic_bind (type, keyseq, data, map) - int type; - const char *keyseq; - char *data; - Keymap map; -{ - char *keys; - int keys_len; - register int i; - KEYMAP_ENTRY k; - - k.function = 0; - - /* If no keys to bind to, exit right away. */ - if (keyseq == 0 || *keyseq == 0) - { - if (type == ISMACR) - xfree (data); - return -1; - } - - keys = (char *)xmalloc (1 + (2 * strlen (keyseq))); - - /* Translate the ASCII representation of KEYSEQ into an array of - characters. Stuff the characters into KEYS, and the length of - KEYS into KEYS_LEN. */ - if (rl_translate_keyseq (keyseq, keys, &keys_len)) - { - xfree (keys); - return -1; - } - - /* Bind keys, making new keymaps as necessary. */ - for (i = 0; i < keys_len; i++) - { - unsigned char uc = keys[i]; - int ic; - - ic = uc; - if (ic < 0 || ic >= KEYMAP_SIZE) - { - xfree (keys); - return -1; - } - - if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii) - { - ic = UNMETA (ic); - if (map[ESC].type == ISKMAP) - map = FUNCTION_TO_KEYMAP (map, ESC); - } - - if ((i + 1) < keys_len) - { - if (map[ic].type != ISKMAP) - { - /* We allow subsequences of keys. If a keymap is being - created that will `shadow' an existing function or macro - key binding, we save that keybinding into the ANYOTHERKEY - index in the new map. The dispatch code will look there - to find the function to execute if the subsequence is not - matched. ANYOTHERKEY was chosen to be greater than - UCHAR_MAX. */ - k = map[ic]; - - map[ic].type = ISKMAP; - map[ic].function = KEYMAP_TO_FUNCTION (rl_make_bare_keymap()); - } - map = FUNCTION_TO_KEYMAP (map, ic); - /* The dispatch code will return this function if no matching - key sequence is found in the keymap. This (with a little - help from the dispatch code in readline.c) allows `a' to be - mapped to something, `abc' to be mapped to something else, - and the function bound to `a' to be executed when the user - types `abx', leaving `bx' in the input queue. */ - if (k.function && ((k.type == ISFUNC && k.function != rl_do_lowercase_version) || k.type == ISMACR)) - { - map[ANYOTHERKEY] = k; - k.function = 0; - } - } - else - { - if (map[ic].type == ISMACR) - xfree ((char *)map[ic].function); - else if (map[ic].type == ISKMAP) - { - map = FUNCTION_TO_KEYMAP (map, ic); - ic = ANYOTHERKEY; - /* If we're trying to override a keymap with a null function - (e.g., trying to unbind it), we can't use a null pointer - here because that's indistinguishable from having not been - overridden. We use a special bindable function that does - nothing. */ - if (type == ISFUNC && data == 0) - data = (char *)_rl_null_function; - } - - map[ic].function = KEYMAP_TO_FUNCTION (data); - map[ic].type = type; - } - - rl_binding_keymap = map; - } - xfree (keys); - return 0; -} - -/* Translate the ASCII representation of SEQ, stuffing the values into ARRAY, - an array of characters. LEN gets the final length of ARRAY. Return - non-zero if there was an error parsing SEQ. */ -int -rl_translate_keyseq (seq, array, len) - const char *seq; - char *array; - int *len; -{ - register int i, c, l, temp; - - for (i = l = 0; c = seq[i]; i++) - { - if (c == '\\') - { - c = seq[++i]; - - if (c == 0) - break; - - /* Handle \C- and \M- prefixes. */ - if ((c == 'C' || c == 'M') && seq[i + 1] == '-') - { - /* Handle special case of backwards define. */ - if (strncmp (&seq[i], "C-\\M-", 5) == 0) - { - array[l++] = ESC; /* ESC is meta-prefix */ - i += 5; - array[l++] = CTRL (_rl_to_upper (seq[i])); - if (seq[i] == '\0') - i--; - } - else if (c == 'M') - { - i++; /* seq[i] == '-' */ - /* XXX - obey convert-meta setting */ - if (_rl_convert_meta_chars_to_ascii && _rl_keymap[ESC].type == ISKMAP) - array[l++] = ESC; /* ESC is meta-prefix */ - else if (seq[i+1] == '\\' && seq[i+2] == 'C' && seq[i+3] == '-') - { - i += 4; - temp = (seq[i] == '?') ? RUBOUT : CTRL (_rl_to_upper (seq[i])); - array[l++] = META (temp); - } - else - { - /* This doesn't yet handle things like \M-\a, which may - or may not have any reasonable meaning. You're - probably better off using straight octal or hex. */ - i++; - array[l++] = META (seq[i]); - } - } - else if (c == 'C') - { - i += 2; - /* Special hack for C-?... */ - array[l++] = (seq[i] == '?') ? RUBOUT : CTRL (_rl_to_upper (seq[i])); - } - continue; - } - - /* Translate other backslash-escaped characters. These are the - same escape sequences that bash's `echo' and `printf' builtins - handle, with the addition of \d -> RUBOUT. A backslash - preceding a character that is not special is stripped. */ - switch (c) - { - case 'a': - array[l++] = '\007'; - break; - case 'b': - array[l++] = '\b'; - break; - case 'd': - array[l++] = RUBOUT; /* readline-specific */ - break; - case 'e': - array[l++] = ESC; - break; - case 'f': - array[l++] = '\f'; - break; - case 'n': - array[l++] = NEWLINE; - break; - case 'r': - array[l++] = RETURN; - break; - case 't': - array[l++] = TAB; - break; - case 'v': - array[l++] = 0x0B; - break; - case '\\': - array[l++] = '\\'; - break; - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - i++; - for (temp = 2, c -= '0'; ISOCTAL (seq[i]) && temp--; i++) - c = (c * 8) + OCTVALUE (seq[i]); - i--; /* auto-increment in for loop */ - array[l++] = c & largest_char; - break; - case 'x': - i++; - for (temp = 2, c = 0; ISXDIGIT ((unsigned char)seq[i]) && temp--; i++) - c = (c * 16) + HEXVALUE (seq[i]); - if (temp == 2) - c = 'x'; - i--; /* auto-increment in for loop */ - array[l++] = c & largest_char; - break; - default: /* backslashes before non-special chars just add the char */ - array[l++] = c; - break; /* the backslash is stripped */ - } - continue; - } - - array[l++] = c; - } - - *len = l; - array[l] = '\0'; - return (0); -} - -char * -rl_untranslate_keyseq (seq) - int seq; -{ - static char kseq[16]; - int i, c; - - i = 0; - c = seq; - if (META_CHAR (c)) - { - kseq[i++] = '\\'; - kseq[i++] = 'M'; - kseq[i++] = '-'; - c = UNMETA (c); - } - else if (c == ESC) - { - kseq[i++] = '\\'; - c = 'e'; - } - else if (CTRL_CHAR (c)) - { - kseq[i++] = '\\'; - kseq[i++] = 'C'; - kseq[i++] = '-'; - c = _rl_to_lower (UNCTRL (c)); - } - else if (c == RUBOUT) - { - kseq[i++] = '\\'; - kseq[i++] = 'C'; - kseq[i++] = '-'; - c = '?'; - } - - if (c == ESC) - { - kseq[i++] = '\\'; - c = 'e'; - } - else if (c == '\\' || c == '"') - { - kseq[i++] = '\\'; - } - - kseq[i++] = (unsigned char) c; - kseq[i] = '\0'; - return kseq; -} - -static char * -_rl_untranslate_macro_value (seq) - char *seq; -{ - char *ret, *r, *s; - int c; - - r = ret = (char *)xmalloc (7 * strlen (seq) + 1); - for (s = seq; *s; s++) - { - c = *s; - if (META_CHAR (c)) - { - *r++ = '\\'; - *r++ = 'M'; - *r++ = '-'; - c = UNMETA (c); - } - else if (c == ESC) - { - *r++ = '\\'; - c = 'e'; - } - else if (CTRL_CHAR (c)) - { - *r++ = '\\'; - *r++ = 'C'; - *r++ = '-'; - c = _rl_to_lower (UNCTRL (c)); - } - else if (c == RUBOUT) - { - *r++ = '\\'; - *r++ = 'C'; - *r++ = '-'; - c = '?'; - } - - if (c == ESC) - { - *r++ = '\\'; - c = 'e'; - } - else if (c == '\\' || c == '"') - *r++ = '\\'; - - *r++ = (unsigned char)c; - } - *r = '\0'; - return ret; -} - -/* Return a pointer to the function that STRING represents. - If STRING doesn't have a matching function, then a NULL pointer - is returned. */ -rl_command_func_t * -rl_named_function (string) - const char *string; -{ - register int i; - - rl_initialize_funmap (); - - for (i = 0; funmap[i]; i++) - if (_rl_stricmp (funmap[i]->name, string) == 0) - return (funmap[i]->function); - return ((rl_command_func_t *)NULL); -} - -/* Return the function (or macro) definition which would be invoked via - KEYSEQ if executed in MAP. If MAP is NULL, then the current keymap is - used. TYPE, if non-NULL, is a pointer to an int which will receive the - type of the object pointed to. One of ISFUNC (function), ISKMAP (keymap), - or ISMACR (macro). */ -rl_command_func_t * -rl_function_of_keyseq (keyseq, map, type) - const char *keyseq; - Keymap map; - int *type; -{ - register int i; - - if (map == 0) - map = _rl_keymap; - - for (i = 0; keyseq && keyseq[i]; i++) - { - unsigned char ic = keyseq[i]; - - if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii) - { - if (map[ESC].type == ISKMAP) - { - map = FUNCTION_TO_KEYMAP (map, ESC); - ic = UNMETA (ic); - } - /* XXX - should we just return NULL here, since this obviously - doesn't match? */ - else - { - if (type) - *type = map[ESC].type; - - return (map[ESC].function); - } - } - - if (map[ic].type == ISKMAP) - { - /* If this is the last key in the key sequence, return the - map. */ - if (keyseq[i + 1] == '\0') - { - if (type) - *type = ISKMAP; - - return (map[ic].function); - } - else - map = FUNCTION_TO_KEYMAP (map, ic); - } - /* If we're not at the end of the key sequence, and the current key - is bound to something other than a keymap, then the entire key - sequence is not bound. */ - else if (map[ic].type != ISKMAP && keyseq[i+1]) - return ((rl_command_func_t *)NULL); - else /* map[ic].type != ISKMAP && keyseq[i+1] == 0 */ - { - if (type) - *type = map[ic].type; - - return (map[ic].function); - } - } - return ((rl_command_func_t *) NULL); -} - -/* The last key bindings file read. */ -static char *last_readline_init_file = (char *)NULL; - -/* The file we're currently reading key bindings from. */ -static const char *current_readline_init_file; -static int current_readline_init_include_level; -static int current_readline_init_lineno; - -/* Read FILENAME into a locally-allocated buffer and return the buffer. - The size of the buffer is returned in *SIZEP. Returns NULL if any - errors were encountered. */ -static char * -_rl_read_file (filename, sizep) - char *filename; - size_t *sizep; -{ - struct stat finfo; - size_t file_size; - char *buffer; - int i, file; - - if ((stat (filename, &finfo) < 0) || (file = open (filename, O_RDONLY, 0666)) < 0) - return ((char *)NULL); - - file_size = (size_t)finfo.st_size; - - /* check for overflow on very large files */ - if (file_size != finfo.st_size || file_size + 1 < file_size) - { - if (file >= 0) - close (file); -#if defined (EFBIG) - errno = EFBIG; -#endif - return ((char *)NULL); - } - - /* Read the file into BUFFER. */ - buffer = (char *)xmalloc (file_size + 1); - i = read (file, buffer, file_size); - close (file); - - if (i < 0) - { - xfree (buffer); - return ((char *)NULL); - } - - RL_CHECK_SIGNALS (); - - buffer[i] = '\0'; - if (sizep) - *sizep = i; - - return (buffer); -} - -/* Re-read the current keybindings file. */ -int -rl_re_read_init_file (count, ignore) - int count, ignore; -{ - int r; - r = rl_read_init_file ((const char *)NULL); - rl_set_keymap_from_edit_mode (); - return r; -} - -/* Do key bindings from a file. If FILENAME is NULL it defaults - to the first non-null filename from this list: - 1. the filename used for the previous call - 2. the value of the shell variable `INPUTRC' - 3. ~/.inputrc - 4. /etc/inputrc - If the file existed and could be opened and read, 0 is returned, - otherwise errno is returned. */ -int -rl_read_init_file (filename) - const char *filename; -{ - /* Default the filename. */ - if (filename == 0) - filename = last_readline_init_file; - if (filename == 0) - filename = sh_get_env_value ("INPUTRC"); - if (filename == 0 || *filename == 0) - { - filename = DEFAULT_INPUTRC; - /* Try to read DEFAULT_INPUTRC; fall back to SYS_INPUTRC on failure */ - if (_rl_read_init_file (filename, 0) == 0) - return 0; - filename = SYS_INPUTRC; - } - -#if defined (__MSDOS__) - if (_rl_read_init_file (filename, 0) == 0) - return 0; - filename = "~/_inputrc"; -#endif - return (_rl_read_init_file (filename, 0)); -} - -static int -_rl_read_init_file (filename, include_level) - const char *filename; - int include_level; -{ - register int i; - char *buffer, *openname, *line, *end; - size_t file_size; - - current_readline_init_file = filename; - current_readline_init_include_level = include_level; - - openname = tilde_expand (filename); - buffer = _rl_read_file (openname, &file_size); - xfree (openname); - - RL_CHECK_SIGNALS (); - if (buffer == 0) - return (errno); - - if (include_level == 0 && filename != last_readline_init_file) - { - FREE (last_readline_init_file); - last_readline_init_file = savestring (filename); - } - - currently_reading_init_file = 1; - - /* Loop over the lines in the file. Lines that start with `#' are - comments; all other lines are commands for readline initialization. */ - current_readline_init_lineno = 1; - line = buffer; - end = buffer + file_size; - while (line < end) - { - /* Find the end of this line. */ - for (i = 0; line + i != end && line[i] != '\n'; i++); - -#if defined (__CYGWIN__) - /* ``Be liberal in what you accept.'' */ - if (line[i] == '\n' && line[i-1] == '\r') - line[i - 1] = '\0'; -#endif - - /* Mark end of line. */ - line[i] = '\0'; - - /* Skip leading whitespace. */ - while (*line && whitespace (*line)) - { - line++; - i--; - } - - /* If the line is not a comment, then parse it. */ - if (*line && *line != '#') - rl_parse_and_bind (line); - - /* Move to the next line. */ - line += i + 1; - current_readline_init_lineno++; - } - - xfree (buffer); - currently_reading_init_file = 0; - return (0); -} - -static void -_rl_init_file_error (msg) - const char *msg; -{ - if (currently_reading_init_file) - _rl_errmsg ("%s: line %d: %s\n", current_readline_init_file, - current_readline_init_lineno, msg); - else - _rl_errmsg ("%s", msg); -} - -/* **************************************************************** */ -/* */ -/* Parser Directives */ -/* */ -/* **************************************************************** */ - -typedef int _rl_parser_func_t PARAMS((char *)); - -/* Things that mean `Control'. */ -const char * const _rl_possible_control_prefixes[] = { - "Control-", "C-", "CTRL-", (const char *)NULL -}; - -const char * const _rl_possible_meta_prefixes[] = { - "Meta", "M-", (const char *)NULL -}; - -/* Conditionals. */ - -/* Calling programs set this to have their argv[0]. */ -const char *rl_readline_name = "other"; - -/* Stack of previous values of parsing_conditionalized_out. */ -static unsigned char *if_stack = (unsigned char *)NULL; -static int if_stack_depth; -static int if_stack_size; - -/* Push _rl_parsing_conditionalized_out, and set parser state based - on ARGS. */ -static int -parser_if (args) - char *args; -{ - register int i; - - /* Push parser state. */ - if (if_stack_depth + 1 >= if_stack_size) - { - if (!if_stack) - if_stack = (unsigned char *)xmalloc (if_stack_size = 20); - else - if_stack = (unsigned char *)xrealloc (if_stack, if_stack_size += 20); - } - if_stack[if_stack_depth++] = _rl_parsing_conditionalized_out; - - /* If parsing is turned off, then nothing can turn it back on except - for finding the matching endif. In that case, return right now. */ - if (_rl_parsing_conditionalized_out) - return 0; - - /* Isolate first argument. */ - for (i = 0; args[i] && !whitespace (args[i]); i++); - - if (args[i]) - args[i++] = '\0'; - - /* Handle "$if term=foo" and "$if mode=emacs" constructs. If this - isn't term=foo, or mode=emacs, then check to see if the first - word in ARGS is the same as the value stored in rl_readline_name. */ - if (rl_terminal_name && _rl_strnicmp (args, "term=", 5) == 0) - { - char *tem, *tname; - - /* Terminals like "aaa-60" are equivalent to "aaa". */ - tname = savestring (rl_terminal_name); - tem = strchr (tname, '-'); - if (tem) - *tem = '\0'; - - /* Test the `long' and `short' forms of the terminal name so that - if someone has a `sun-cmd' and does not want to have bindings - that will be executed if the terminal is a `sun', they can put - `$if term=sun-cmd' into their .inputrc. */ - _rl_parsing_conditionalized_out = _rl_stricmp (args + 5, tname) && - _rl_stricmp (args + 5, rl_terminal_name); - xfree (tname); - } -#if defined (VI_MODE) - else if (_rl_strnicmp (args, "mode=", 5) == 0) - { - int mode; - - if (_rl_stricmp (args + 5, "emacs") == 0) - mode = emacs_mode; - else if (_rl_stricmp (args + 5, "vi") == 0) - mode = vi_mode; - else - mode = no_mode; - - _rl_parsing_conditionalized_out = mode != rl_editing_mode; - } -#endif /* VI_MODE */ - /* Check to see if the first word in ARGS is the same as the - value stored in rl_readline_name. */ - else if (_rl_stricmp (args, rl_readline_name) == 0) - _rl_parsing_conditionalized_out = 0; - else - _rl_parsing_conditionalized_out = 1; - return 0; -} - -/* Invert the current parser state if there is anything on the stack. */ -static int -parser_else (args) - char *args; -{ - register int i; - - if (if_stack_depth == 0) - { - _rl_init_file_error ("$else found without matching $if"); - return 0; - } - -#if 0 - /* Check the previous (n - 1) levels of the stack to make sure that - we haven't previously turned off parsing. */ - for (i = 0; i < if_stack_depth - 1; i++) -#else - /* Check the previous (n) levels of the stack to make sure that - we haven't previously turned off parsing. */ - for (i = 0; i < if_stack_depth; i++) -#endif - if (if_stack[i] == 1) - return 0; - - /* Invert the state of parsing if at top level. */ - _rl_parsing_conditionalized_out = !_rl_parsing_conditionalized_out; - return 0; -} - -/* Terminate a conditional, popping the value of - _rl_parsing_conditionalized_out from the stack. */ -static int -parser_endif (args) - char *args; -{ - if (if_stack_depth) - _rl_parsing_conditionalized_out = if_stack[--if_stack_depth]; - else - _rl_init_file_error ("$endif without matching $if"); - return 0; -} - -static int -parser_include (args) - char *args; -{ - const char *old_init_file; - char *e; - int old_line_number, old_include_level, r; - - if (_rl_parsing_conditionalized_out) - return (0); - - old_init_file = current_readline_init_file; - old_line_number = current_readline_init_lineno; - old_include_level = current_readline_init_include_level; - - e = strchr (args, '\n'); - if (e) - *e = '\0'; - r = _rl_read_init_file ((const char *)args, old_include_level + 1); - - current_readline_init_file = old_init_file; - current_readline_init_lineno = old_line_number; - current_readline_init_include_level = old_include_level; - - return r; -} - -/* Associate textual names with actual functions. */ -static const struct { - const char * const name; - _rl_parser_func_t *function; -} parser_directives [] = { - { "if", parser_if }, - { "endif", parser_endif }, - { "else", parser_else }, - { "include", parser_include }, - { (char *)0x0, (_rl_parser_func_t *)0x0 } -}; - -/* Handle a parser directive. STATEMENT is the line of the directive - without any leading `$'. */ -static int -handle_parser_directive (statement) - char *statement; -{ - register int i; - char *directive, *args; - - /* Isolate the actual directive. */ - - /* Skip whitespace. */ - for (i = 0; whitespace (statement[i]); i++); - - directive = &statement[i]; - - for (; statement[i] && !whitespace (statement[i]); i++); - - if (statement[i]) - statement[i++] = '\0'; - - for (; statement[i] && whitespace (statement[i]); i++); - - args = &statement[i]; - - /* Lookup the command, and act on it. */ - for (i = 0; parser_directives[i].name; i++) - if (_rl_stricmp (directive, parser_directives[i].name) == 0) - { - (*parser_directives[i].function) (args); - return (0); - } - - /* display an error message about the unknown parser directive */ - _rl_init_file_error ("unknown parser directive"); - return (1); -} - -/* Start at STRING[START] and look for DELIM. Return I where STRING[I] == - DELIM or STRING[I] == 0. DELIM is usually a double quote. */ -static int -_rl_skip_to_delim (string, start, delim) - char *string; - int start, delim; -{ - int i, c, passc; - - for (i = start,passc = 0; c = string[i]; i++) - { - if (passc) - { - passc = 0; - if (c == 0) - break; - continue; - } - - if (c == '\\') - { - passc = 1; - continue; - } - - if (c == delim) - break; - } - - return i; -} - -/* Read the binding command from STRING and perform it. - A key binding command looks like: Keyname: function-name\0, - a variable binding command looks like: set variable value. - A new-style keybinding looks like "\C-x\C-x": exchange-point-and-mark. */ -int -rl_parse_and_bind (string) - char *string; -{ - char *funname, *kname; - register int c, i; - int key, equivalency; - - while (string && whitespace (*string)) - string++; - - if (string == 0 || *string == 0 || *string == '#') - return 0; - - /* If this is a parser directive, act on it. */ - if (*string == '$') - { - handle_parser_directive (&string[1]); - return 0; - } - - /* If we aren't supposed to be parsing right now, then we're done. */ - if (_rl_parsing_conditionalized_out) - return 0; - - i = 0; - /* If this keyname is a complex key expression surrounded by quotes, - advance to after the matching close quote. This code allows the - backslash to quote characters in the key expression. */ - if (*string == '"') - { - i = _rl_skip_to_delim (string, 1, '"'); - - /* If we didn't find a closing quote, abort the line. */ - if (string[i] == '\0') - { - _rl_init_file_error ("no closing `\"' in key binding"); - return 1; - } - else - i++; /* skip past closing double quote */ - } - - /* Advance to the colon (:) or whitespace which separates the two objects. */ - for (; (c = string[i]) && c != ':' && c != ' ' && c != '\t'; i++ ); - - equivalency = (c == ':' && string[i + 1] == '='); - - /* Mark the end of the command (or keyname). */ - if (string[i]) - string[i++] = '\0'; - - /* If doing assignment, skip the '=' sign as well. */ - if (equivalency) - string[i++] = '\0'; - - /* If this is a command to set a variable, then do that. */ - if (_rl_stricmp (string, "set") == 0) - { - char *var, *value, *e; - - var = string + i; - /* Make VAR point to start of variable name. */ - while (*var && whitespace (*var)) var++; - - /* Make VALUE point to start of value string. */ - value = var; - while (*value && whitespace (*value) == 0) value++; - if (*value) - *value++ = '\0'; - while (*value && whitespace (*value)) value++; - - /* Strip trailing whitespace from values of boolean variables. */ - if (find_boolean_var (var) >= 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'; - } - else if ((i = find_string_var (var)) >= 0) - { - } - - rl_variable_bind (var, value); - return 0; - } - - /* Skip any whitespace between keyname and funname. */ - for (; string[i] && whitespace (string[i]); i++); - funname = &string[i]; - - /* Now isolate funname. - For straight function names just look for whitespace, since - that will signify the end of the string. But this could be a - macro definition. In that case, the string is quoted, so skip - to the matching delimiter. We allow the backslash to quote the - delimiter characters in the macro body. */ - /* This code exists to allow whitespace in macro expansions, which - would otherwise be gobbled up by the next `for' loop.*/ - /* XXX - it may be desirable to allow backslash quoting only if " is - the quoted string delimiter, like the shell. */ - if (*funname == '\'' || *funname == '"') - { - int delimiter, passc; - - delimiter = string[i++]; - for (passc = 0; c = string[i]; i++) - { - if (passc) - { - passc = 0; - continue; - } - - if (c == '\\') - { - passc = 1; - continue; - } - - if (c == delimiter) - break; - } - if (c) - i++; - } - - /* Advance to the end of the string. */ - for (; string[i] && !whitespace (string[i]); i++); - - /* No extra whitespace at the end of the string. */ - string[i] = '\0'; - - /* Handle equivalency bindings here. Make the left-hand side be exactly - whatever the right-hand evaluates to, including keymaps. */ - if (equivalency) - { - return 0; - } - - /* If this is a new-style key-binding, then do the binding with - rl_bind_keyseq (). Otherwise, let the older code deal with it. */ - if (*string == '"') - { - char *seq; - register int j, k, passc; - - seq = (char *)xmalloc (1 + strlen (string)); - for (j = 1, k = passc = 0; string[j]; j++) - { - /* Allow backslash to quote characters, but leave them in place. - This allows a string to end with a backslash quoting another - backslash, or with a backslash quoting a double quote. The - backslashes are left in place for rl_translate_keyseq (). */ - if (passc || (string[j] == '\\')) - { - seq[k++] = string[j]; - passc = !passc; - continue; - } - - if (string[j] == '"') - break; - - seq[k++] = string[j]; - } - seq[k] = '\0'; - - /* Binding macro? */ - if (*funname == '\'' || *funname == '"') - { - j = strlen (funname); - - /* Remove the delimiting quotes from each end of FUNNAME. */ - if (j && funname[j - 1] == *funname) - funname[j - 1] = '\0'; - - rl_macro_bind (seq, &funname[1], _rl_keymap); - } - else - rl_bind_keyseq (seq, rl_named_function (funname)); - - xfree (seq); - return 0; - } - - /* Get the actual character we want to deal with. */ - kname = strrchr (string, '-'); - if (!kname) - kname = string; - else - kname++; - - key = glean_key_from_name (kname); - - /* Add in control and meta bits. */ - if (substring_member_of_array (string, _rl_possible_control_prefixes)) - key = CTRL (_rl_to_upper (key)); - - if (substring_member_of_array (string, _rl_possible_meta_prefixes)) - key = META (key); - - /* Temporary. Handle old-style keyname with macro-binding. */ - if (*funname == '\'' || *funname == '"') - { - char useq[2]; - int fl = strlen (funname); - - useq[0] = key; useq[1] = '\0'; - if (fl && funname[fl - 1] == *funname) - funname[fl - 1] = '\0'; - - rl_macro_bind (useq, &funname[1], _rl_keymap); - } -#if defined (PREFIX_META_HACK) - /* Ugly, but working hack to keep prefix-meta around. */ - else if (_rl_stricmp (funname, "prefix-meta") == 0) - { - char seq[2]; - - seq[0] = key; - seq[1] = '\0'; - rl_generic_bind (ISKMAP, seq, (char *)emacs_meta_keymap, _rl_keymap); - } -#endif /* PREFIX_META_HACK */ - else - rl_bind_key (key, rl_named_function (funname)); - return 0; -} - -/* Simple structure for boolean readline variables (i.e., those that can - have one of two values; either "On" or 1 for truth, or "Off" or 0 for - false. */ - -#define V_SPECIAL 0x1 - -static const struct { - const char * const name; - 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 }, - { "completion-map-case", &_rl_completion_case_map, 0 }, - { "convert-meta", &_rl_convert_meta_chars_to_ascii, 0 }, - { "disable-completion", &rl_inhibit_completion, 0 }, - { "echo-control-characters", &_rl_echo_control_chars, 0 }, - { "enable-keypad", &_rl_enable_keypad, 0 }, - { "enable-meta-key", &_rl_enable_meta, 0 }, - { "expand-tilde", &rl_complete_with_tilde_expansion, 0 }, - { "history-preserve-point", &_rl_history_preserve_point, 0 }, - { "horizontal-scroll-mode", &_rl_horizontal_scroll_mode, 0 }, - { "input-meta", &_rl_meta_flag, 0 }, - { "mark-directories", &_rl_complete_mark_directories, 0 }, - { "mark-modified-lines", &_rl_mark_modified_lines, 0 }, - { "mark-symlinked-directories", &_rl_complete_mark_symlink_dirs, 0 }, - { "match-hidden-files", &_rl_match_hidden_files, 0 }, - { "menu-complete-display-prefix", &_rl_menu_complete_prefix_first, 0 }, - { "meta-flag", &_rl_meta_flag, 0 }, - { "output-meta", &_rl_output_meta_chars, 0 }, - { "page-completions", &_rl_page_completions, 0 }, - { "prefer-visible-bell", &_rl_prefer_visible_bell, V_SPECIAL }, - { "print-completions-horizontally", &_rl_print_completions_horizontally, 0 }, - { "revert-all-at-newline", &_rl_revert_all_at_newline, 0 }, - { "show-all-if-ambiguous", &_rl_complete_show_all, 0 }, - { "show-all-if-unmodified", &_rl_complete_show_unmodified, 0 }, - { "skip-completed-text", &_rl_skip_completed_text, 0 }, -#if defined (VISIBLE_STATS) - { "visible-stats", &rl_visible_stats, 0 }, -#endif /* VISIBLE_STATS */ - { (char *)NULL, (int *)NULL, 0 } -}; - -static int -find_boolean_var (name) - const char *name; -{ - register int i; - - for (i = 0; boolean_varlist[i].name; i++) - if (_rl_stricmp (name, boolean_varlist[i].name) == 0) - return i; - return -1; -} - -/* Hooks for handling special boolean variables, where a - function needs to be called or another variable needs - to be changed when they're changed. */ -static void -hack_special_boolean_var (i) - int i; -{ - const char *name; - - name = boolean_varlist[i].name; - - if (_rl_stricmp (name, "blink-matching-paren") == 0) - _rl_enable_paren_matching (rl_blink_matching_paren); - else if (_rl_stricmp (name, "prefer-visible-bell") == 0) - { - if (_rl_prefer_visible_bell) - _rl_bell_preference = VISIBLE_BELL; - else - _rl_bell_preference = AUDIBLE_BELL; - } -} - -typedef int _rl_sv_func_t PARAMS((const char *)); - -/* These *must* correspond to the array indices for the appropriate - string variable. (Though they're not used right now.) */ -#define V_BELLSTYLE 0 -#define V_COMBEGIN 1 -#define V_EDITMODE 2 -#define V_ISRCHTERM 3 -#define V_KEYMAP 4 - -#define V_STRING 1 -#define V_INT 2 - -/* Forward declarations */ -static int sv_bell_style PARAMS((const char *)); -static int sv_combegin PARAMS((const char *)); -static int sv_dispprefix PARAMS((const char *)); -static int sv_compquery PARAMS((const char *)); -static int sv_compwidth PARAMS((const char *)); -static int sv_editmode PARAMS((const char *)); -static int sv_histsize PARAMS((const char *)); -static int sv_isrchterm PARAMS((const char *)); -static int sv_keymap PARAMS((const char *)); - -static const struct { - const char * const name; - int flags; - _rl_sv_func_t *set_func; -} string_varlist[] = { - { "bell-style", V_STRING, sv_bell_style }, - { "comment-begin", V_STRING, sv_combegin }, - { "completion-display-width", V_INT, sv_compwidth }, - { "completion-prefix-display-length", V_INT, sv_dispprefix }, - { "completion-query-items", V_INT, sv_compquery }, - { "editing-mode", V_STRING, sv_editmode }, - { "history-size", V_INT, sv_histsize }, - { "isearch-terminators", V_STRING, sv_isrchterm }, - { "keymap", V_STRING, sv_keymap }, - { (char *)NULL, 0, (_rl_sv_func_t *)0 } -}; - -static int -find_string_var (name) - const char *name; -{ - register int i; - - for (i = 0; string_varlist[i].name; i++) - if (_rl_stricmp (name, string_varlist[i].name) == 0) - return i; - return -1; -} - -/* A boolean value that can appear in a `set variable' command is true if - the value is null or empty, `on' (case-insenstive), or "1". Any other - values result in 0 (false). */ -static int -bool_to_int (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; - - /* 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; -{ - register int i; - int v; - - /* Check for simple variables first. */ - i = find_boolean_var (name); - if (i >= 0) - { - *boolean_varlist[i].value = bool_to_int (value); - if (boolean_varlist[i].flags & V_SPECIAL) - hack_special_boolean_var (i); - return 0; - } - - i = find_string_var (name); - - /* For the time being, unknown variable names or string names without a - handler function are simply ignored. */ - if (i < 0 || string_varlist[i].set_func == 0) - return 0; - - v = (*string_varlist[i].set_func) (value); - return v; -} - -static int -sv_editmode (value) - const char *value; -{ - if (_rl_strnicmp (value, "vi", 2) == 0) - { -#if defined (VI_MODE) - _rl_keymap = vi_insertion_keymap; - rl_editing_mode = vi_mode; -#endif /* VI_MODE */ - return 0; - } - else if (_rl_strnicmp (value, "emacs", 5) == 0) - { - _rl_keymap = emacs_standard_keymap; - rl_editing_mode = emacs_mode; - return 0; - } - return 1; -} - -static int -sv_combegin (value) - const char *value; -{ - if (value && *value) - { - FREE (_rl_comment_begin); - _rl_comment_begin = savestring (value); - return 0; - } - return 1; -} - -static int -sv_dispprefix (value) - const char *value; -{ - int nval = 0; - - if (value && *value) - { - nval = atoi (value); - if (nval < 0) - nval = 0; - } - _rl_completion_prefix_display_length = nval; - return 0; -} - -static int -sv_compquery (value) - const char *value; -{ - int nval = 100; - - if (value && *value) - { - nval = atoi (value); - if (nval < 0) - nval = 0; - } - rl_completion_query_items = nval; - return 0; -} - -static int -sv_compwidth (value) - const char *value; -{ - int nval = -1; - - if (value && *value) - nval = atoi (value); - - _rl_completion_columns = nval; - return 0; -} - -static int -sv_histsize (value) - const char *value; -{ - int nval = 500; - - if (value && *value) - { - nval = atoi (value); - if (nval < 0) - return 1; - } - stifle_history (nval); - return 0; -} - -static int -sv_keymap (value) - const char *value; -{ - Keymap kmap; - - kmap = rl_get_keymap_by_name (value); - if (kmap) - { - rl_set_keymap (kmap); - return 0; - } - return 1; -} - -static int -sv_bell_style (value) - const char *value; -{ - if (value == 0 || *value == '\0') - _rl_bell_preference = AUDIBLE_BELL; - else if (_rl_stricmp (value, "none") == 0 || _rl_stricmp (value, "off") == 0) - _rl_bell_preference = NO_BELL; - else if (_rl_stricmp (value, "audible") == 0 || _rl_stricmp (value, "on") == 0) - _rl_bell_preference = AUDIBLE_BELL; - else if (_rl_stricmp (value, "visible") == 0) - _rl_bell_preference = VISIBLE_BELL; - else - return 1; - return 0; -} - -static int -sv_isrchterm (value) - const char *value; -{ - int beg, end, delim; - char *v; - - if (value == 0) - return 1; - - /* Isolate the value and translate it into a character string. */ - v = savestring (value); - FREE (_rl_isearch_terminators); - if (v[0] == '"' || v[0] == '\'') - { - delim = v[0]; - for (beg = end = 1; v[end] && v[end] != delim; end++) - ; - } - else - { - for (beg = end = 0; whitespace (v[end]) == 0; end++) - ; - } - - v[end] = '\0'; - - /* The value starts at v + beg. Translate it into a character string. */ - _rl_isearch_terminators = (char *)xmalloc (2 * strlen (v) + 1); - rl_translate_keyseq (v + beg, _rl_isearch_terminators, &end); - _rl_isearch_terminators[end] = '\0'; - - xfree (v); - return 0; -} - -/* Return the character which matches NAME. - For example, `Space' returns ' '. */ - -typedef struct { - const char * const name; - int value; -} assoc_list; - -static const assoc_list name_key_alist[] = { - { "DEL", 0x7f }, - { "ESC", '\033' }, - { "Escape", '\033' }, - { "LFD", '\n' }, - { "Newline", '\n' }, - { "RET", '\r' }, - { "Return", '\r' }, - { "Rubout", 0x7f }, - { "SPC", ' ' }, - { "Space", ' ' }, - { "Tab", 0x09 }, - { (char *)0x0, 0 } -}; - -static int -glean_key_from_name (name) - char *name; -{ - register int i; - - for (i = 0; name_key_alist[i].name; i++) - if (_rl_stricmp (name, name_key_alist[i].name) == 0) - return (name_key_alist[i].value); - - return (*(unsigned char *)name); /* XXX was return (*name) */ -} - -/* Auxiliary functions to manage keymaps. */ -static const struct { - const char * const name; - Keymap map; -} keymap_names[] = { - { "emacs", emacs_standard_keymap }, - { "emacs-standard", emacs_standard_keymap }, - { "emacs-meta", emacs_meta_keymap }, - { "emacs-ctlx", emacs_ctlx_keymap }, -#if defined (VI_MODE) - { "vi", vi_movement_keymap }, - { "vi-move", vi_movement_keymap }, - { "vi-command", vi_movement_keymap }, - { "vi-insert", vi_insertion_keymap }, -#endif /* VI_MODE */ - { (char *)0x0, (Keymap)0x0 } -}; - -Keymap -rl_get_keymap_by_name (name) - const char *name; -{ - register int i; - - for (i = 0; keymap_names[i].name; i++) - if (_rl_stricmp (name, keymap_names[i].name) == 0) - return (keymap_names[i].map); - return ((Keymap) NULL); -} - -char * -rl_get_keymap_name (map) - Keymap map; -{ - register int i; - for (i = 0; keymap_names[i].name; i++) - if (map == keymap_names[i].map) - return ((char *)keymap_names[i].name); - return ((char *)NULL); -} - -void -rl_set_keymap (map) - Keymap map; -{ - if (map) - _rl_keymap = map; -} - -Keymap -rl_get_keymap () -{ - return (_rl_keymap); -} - -void -rl_set_keymap_from_edit_mode () -{ - if (rl_editing_mode == emacs_mode) - _rl_keymap = emacs_standard_keymap; -#if defined (VI_MODE) - else if (rl_editing_mode == vi_mode) - _rl_keymap = vi_insertion_keymap; -#endif /* VI_MODE */ -} - -char * -rl_get_keymap_name_from_edit_mode () -{ - if (rl_editing_mode == emacs_mode) - return "emacs"; -#if defined (VI_MODE) - else if (rl_editing_mode == vi_mode) - return "vi"; -#endif /* VI_MODE */ - else - return "none"; -} - -/* **************************************************************** */ -/* */ -/* Key Binding and Function Information */ -/* */ -/* **************************************************************** */ - -/* Each of the following functions produces information about the - state of keybindings and functions known to Readline. The info - is always printed to rl_outstream, and in such a way that it can - be read back in (i.e., passed to rl_parse_and_bind ()). */ - -/* Print the names of functions known to Readline. */ -void -rl_list_funmap_names () -{ - register int i; - const char **funmap_names; - - funmap_names = rl_funmap_names (); - - if (!funmap_names) - return; - - for (i = 0; funmap_names[i]; i++) - fprintf (rl_outstream, "%s\n", funmap_names[i]); - - xfree (funmap_names); -} - -static char * -_rl_get_keyname (key) - int key; -{ - char *keyname; - int i, c; - - keyname = (char *)xmalloc (8); - - c = key; - /* Since this is going to be used to write out keysequence-function - pairs for possible inclusion in an inputrc file, we don't want to - do any special meta processing on KEY. */ - -#if 1 - /* XXX - Experimental */ - /* We might want to do this, but the old version of the code did not. */ - - /* If this is an escape character, we don't want to do any more processing. - Just add the special ESC key sequence and return. */ - if (c == ESC) - { - keyname[0] = '\\'; - keyname[1] = 'e'; - keyname[2] = '\0'; - return keyname; - } -#endif - - /* RUBOUT is translated directly into \C-? */ - if (key == RUBOUT) - { - keyname[0] = '\\'; - keyname[1] = 'C'; - keyname[2] = '-'; - keyname[3] = '?'; - keyname[4] = '\0'; - return keyname; - } - - i = 0; - /* Now add special prefixes needed for control characters. This can - potentially change C. */ - if (CTRL_CHAR (c)) - { - keyname[i++] = '\\'; - keyname[i++] = 'C'; - keyname[i++] = '-'; - c = _rl_to_lower (UNCTRL (c)); - } - - /* XXX experimental code. Turn the characters that are not ASCII or - ISO Latin 1 (128 - 159) into octal escape sequences (\200 - \237). - This changes C. */ - if (c >= 128 && c <= 159) - { - keyname[i++] = '\\'; - keyname[i++] = '2'; - c -= 128; - keyname[i++] = (c / 8) + '0'; - c = (c % 8) + '0'; - } - - /* Now, if the character needs to be quoted with a backslash, do that. */ - if (c == '\\' || c == '"') - keyname[i++] = '\\'; - - /* Now add the key, terminate the string, and return it. */ - keyname[i++] = (char) c; - keyname[i] = '\0'; - - return keyname; -} - -/* Return a NULL terminated array of strings which represent the key - sequences that are used to invoke FUNCTION in MAP. */ -char ** -rl_invoking_keyseqs_in_map (function, map) - rl_command_func_t *function; - Keymap map; -{ - register int key; - char **result; - int result_index, result_size; - - result = (char **)NULL; - result_index = result_size = 0; - - for (key = 0; key < KEYMAP_SIZE; key++) - { - switch (map[key].type) - { - case ISMACR: - /* Macros match, if, and only if, the pointers are identical. - Thus, they are treated exactly like functions in here. */ - case ISFUNC: - /* If the function in the keymap is the one we are looking for, - then add the current KEY to the list of invoking keys. */ - if (map[key].function == function) - { - char *keyname; - - keyname = _rl_get_keyname (key); - - if (result_index + 2 > result_size) - { - result_size += 10; - result = (char **)xrealloc (result, result_size * sizeof (char *)); - } - - result[result_index++] = keyname; - result[result_index] = (char *)NULL; - } - break; - - case ISKMAP: - { - char **seqs; - register int i; - - /* Find the list of keyseqs in this map which have FUNCTION as - their target. Add the key sequences found to RESULT. */ - if (map[key].function) - seqs = - rl_invoking_keyseqs_in_map (function, FUNCTION_TO_KEYMAP (map, key)); - else - break; - - if (seqs == 0) - break; - - for (i = 0; seqs[i]; i++) - { - char *keyname = (char *)xmalloc (6 + strlen (seqs[i])); - - if (key == ESC) - { - /* If ESC is the meta prefix and we're converting chars - with the eighth bit set to ESC-prefixed sequences, then - we can use \M-. Otherwise we need to use the sequence - for ESC. */ - if (_rl_convert_meta_chars_to_ascii && map[ESC].type == ISKMAP) - sprintf (keyname, "\\M-"); - else - sprintf (keyname, "\\e"); - } - else if (CTRL_CHAR (key)) - sprintf (keyname, "\\C-%c", _rl_to_lower (UNCTRL (key))); - else if (key == RUBOUT) - sprintf (keyname, "\\C-?"); - else if (key == '\\' || key == '"') - { - keyname[0] = '\\'; - keyname[1] = (char) key; - keyname[2] = '\0'; - } - else - { - keyname[0] = (char) key; - keyname[1] = '\0'; - } - - strcat (keyname, seqs[i]); - xfree (seqs[i]); - - if (result_index + 2 > result_size) - { - result_size += 10; - result = (char **)xrealloc (result, result_size * sizeof (char *)); - } - - result[result_index++] = keyname; - result[result_index] = (char *)NULL; - } - - xfree (seqs); - } - break; - } - } - return (result); -} - -/* Return a NULL terminated array of strings which represent the key - sequences that can be used to invoke FUNCTION using the current keymap. */ -char ** -rl_invoking_keyseqs (function) - rl_command_func_t *function; -{ - return (rl_invoking_keyseqs_in_map (function, _rl_keymap)); -} - -/* Print all of the functions and their bindings to rl_outstream. If - PRINT_READABLY is non-zero, then print the output in such a way - that it can be read back in. */ -void -rl_function_dumper (print_readably) - int print_readably; -{ - register int i; - const char **names; - const char *name; - - names = rl_funmap_names (); - - fprintf (rl_outstream, "\n"); - - for (i = 0; name = names[i]; i++) - { - rl_command_func_t *function; - char **invokers; - - function = rl_named_function (name); - invokers = rl_invoking_keyseqs_in_map (function, _rl_keymap); - - if (print_readably) - { - if (!invokers) - fprintf (rl_outstream, "# %s (not bound)\n", name); - else - { - register int j; - - for (j = 0; invokers[j]; j++) - { - fprintf (rl_outstream, "\"%s\": %s\n", - invokers[j], name); - xfree (invokers[j]); - } - - xfree (invokers); - } - } - else - { - if (!invokers) - fprintf (rl_outstream, "%s is not bound to any keys\n", - name); - else - { - register int j; - - fprintf (rl_outstream, "%s can be found on ", name); - - for (j = 0; invokers[j] && j < 5; j++) - { - fprintf (rl_outstream, "\"%s\"%s", invokers[j], - invokers[j + 1] ? ", " : ".\n"); - } - - if (j == 5 && invokers[j]) - fprintf (rl_outstream, "...\n"); - - for (j = 0; invokers[j]; j++) - xfree (invokers[j]); - - xfree (invokers); - } - } - } - - xfree (names); -} - -/* Print all of the current functions and their bindings to - rl_outstream. If an explicit argument is given, then print - the output in such a way that it can be read back in. */ -int -rl_dump_functions (count, key) - int count, key; -{ - if (rl_dispatching) - fprintf (rl_outstream, "\r\n"); - rl_function_dumper (rl_explicit_arg); - rl_on_new_line (); - return (0); -} - -static void -_rl_macro_dumper_internal (print_readably, map, prefix) - int print_readably; - Keymap map; - char *prefix; -{ - register int key; - char *keyname, *out; - int prefix_len; - - for (key = 0; key < KEYMAP_SIZE; key++) - { - switch (map[key].type) - { - case ISMACR: - keyname = _rl_get_keyname (key); - out = _rl_untranslate_macro_value ((char *)map[key].function); - - if (print_readably) - fprintf (rl_outstream, "\"%s%s\": \"%s\"\n", prefix ? prefix : "", - keyname, - out ? out : ""); - else - fprintf (rl_outstream, "%s%s outputs %s\n", prefix ? prefix : "", - keyname, - out ? out : ""); - xfree (keyname); - xfree (out); - break; - case ISFUNC: - break; - case ISKMAP: - prefix_len = prefix ? strlen (prefix) : 0; - if (key == ESC) - { - keyname = (char *)xmalloc (3 + prefix_len); - if (prefix) - strcpy (keyname, prefix); - keyname[prefix_len] = '\\'; - keyname[prefix_len + 1] = 'e'; - keyname[prefix_len + 2] = '\0'; - } - else - { - keyname = _rl_get_keyname (key); - if (prefix) - { - out = (char *)xmalloc (strlen (keyname) + prefix_len + 1); - strcpy (out, prefix); - strcpy (out + prefix_len, keyname); - xfree (keyname); - keyname = out; - } - } - - _rl_macro_dumper_internal (print_readably, FUNCTION_TO_KEYMAP (map, key), keyname); - xfree (keyname); - break; - } - } -} - -void -rl_macro_dumper (print_readably) - int print_readably; -{ - _rl_macro_dumper_internal (print_readably, _rl_keymap, (char *)NULL); -} - -int -rl_dump_macros (count, key) - int count, key; -{ - if (rl_dispatching) - fprintf (rl_outstream, "\r\n"); - rl_macro_dumper (rl_explicit_arg); - rl_on_new_line (); - return (0); -} - -static char * -_rl_get_string_variable_value (name) - const char *name; -{ - static char numbuf[32]; - char *ret; - - 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-display-width") == 0) - { - sprintf (numbuf, "%d", _rl_completion_columns); - return (numbuf); - } - else if (_rl_stricmp (name, "completion-prefix-display-length") == 0) - { - sprintf (numbuf, "%d", _rl_completion_prefix_display_length); - return (numbuf); - } - 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, "history-size") == 0) - { - sprintf (numbuf, "%d", history_is_stifled() ? history_max_entries : 0); - return (numbuf); - } - 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); - xfree (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; - char *v; - - for (i = 0; boolean_varlist[i].name; i++) - { - if (print_readably) - fprintf (rl_outstream, "set %s %s\n", boolean_varlist[i].name, - *boolean_varlist[i].value ? "on" : "off"); - else - fprintf (rl_outstream, "%s is set to `%s'\n", boolean_varlist[i].name, - *boolean_varlist[i].value ? "on" : "off"); - } - - for (i = 0; string_varlist[i].name; i++) - { - 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 %s %s\n", string_varlist[i].name, v); - else - fprintf (rl_outstream, "%s is set to `%s'\n", string_varlist[i].name, v); - } -} - -/* Print all of the current variables and their values to - rl_outstream. If an explicit argument is given, then print - the output in such a way that it can be read back in. */ -int -rl_dump_variables (count, key) - int count, key; -{ - if (rl_dispatching) - fprintf (rl_outstream, "\r\n"); - rl_variable_dumper (rl_explicit_arg); - rl_on_new_line (); - return (0); -} - -/* Return non-zero if any members of ARRAY are a substring in STRING. */ -static int -substring_member_of_array (string, array) - const char *string; - const char * const *array; -{ - while (*array) - { - if (_rl_strindex (string, *array)) - return (1); - array++; - } - return (0); -} diff --git a/lib/readline/display.c~ b/lib/readline/display.c~ deleted file mode 100644 index 59db681b..00000000 --- a/lib/readline/display.c~ +++ /dev/null @@ -1,2738 +0,0 @@ -/* display.c -- readline redisplay facility. */ - -/* Copyright (C) 1987-2009 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library (Readline), a library - for reading lines of text with interactive input and history editing. - - Readline 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 3 of the License, or - (at your option) any later version. - - Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>. -*/ - -#define READLINE_LIBRARY - -#if defined (HAVE_CONFIG_H) -# include <config.h> -#endif - -#include <sys/types.h> - -#if defined (HAVE_UNISTD_H) -# include <unistd.h> -#endif /* HAVE_UNISTD_H */ - -#include "posixstat.h" - -#if defined (HAVE_STDLIB_H) -# include <stdlib.h> -#else -# include "ansi_stdlib.h" -#endif /* HAVE_STDLIB_H */ - -#include <stdio.h> - -#ifdef __MSDOS__ -# include <pc.h> -#endif - -/* System-specific feature definitions and include files. */ -#include "rldefs.h" -#include "rlmbutil.h" - -/* Termcap library stuff. */ -#include "tcap.h" - -/* Some standard library routines. */ -#include "readline.h" -#include "history.h" - -#include "rlprivate.h" -#include "xmalloc.h" - -#if !defined (strchr) && !defined (__STDC__) -extern char *strchr (), *strrchr (); -#endif /* !strchr && !__STDC__ */ - -static void update_line PARAMS((char *, char *, int, int, int, int)); -static void space_to_eol PARAMS((int)); -static void delete_chars PARAMS((int)); -static void insert_some_chars PARAMS((char *, int, int)); -static void cr PARAMS((void)); - -/* State of visible and invisible lines. */ -struct line_state - { - char *line; - int *lbreaks; - int lbsize; -#if defined (HANDLE_MULTIBYTE) - int *wrapped_line; - int wbsize; -#endif - }; - -/* The line display buffers. One is the line currently displayed on - the screen. The other is the line about to be displayed. */ -static struct line_state line_state_array[2]; -static struct line_state *line_state_visible = &line_state_array[0]; -static struct line_state *line_state_invisible = &line_state_array[1]; -static int line_structures_initialized = 0; - -/* Backwards-compatible names. */ -#define inv_lbreaks (line_state_invisible->lbreaks) -#define inv_lbsize (line_state_invisible->lbsize) -#define vis_lbreaks (line_state_visible->lbreaks) -#define vis_lbsize (line_state_visible->lbsize) - -#define visible_line (line_state_visible->line) -#define invisible_line (line_state_invisible->line) - -#if defined (HANDLE_MULTIBYTE) -static int _rl_col_width PARAMS((const char *, int, int, int)); -#else -# define _rl_col_width(l, s, e, f) (((e) <= (s)) ? 0 : (e) - (s)) -#endif - -/* Heuristic used to decide whether it is faster to move from CUR to NEW - by backing up or outputting a carriage return and moving forward. CUR - and NEW are either both buffer positions or absolute screen positions. */ -#define CR_FASTER(new, cur) (((new) + 1) < ((cur) - (new))) - -/* _rl_last_c_pos is an absolute cursor position in multibyte locales and a - buffer index in others. This macro is used when deciding whether the - current cursor position is in the middle of a prompt string containing - invisible characters. XXX - might need to take `modmark' into account. */ -#define PROMPT_ENDING_INDEX \ - ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) ? prompt_physical_chars : prompt_last_invisible+1) - - -/* **************************************************************** */ -/* */ -/* Display stuff */ -/* */ -/* **************************************************************** */ - -/* This is the stuff that is hard for me. I never seem to write good - display routines in C. Let's see how I do this time. */ - -/* (PWP) Well... Good for a simple line updater, but totally ignores - the problems of input lines longer than the screen width. - - update_line and the code that calls it makes a multiple line, - automatically wrapping line update. Careful attention needs - to be paid to the vertical position variables. */ - -/* Keep two buffers; one which reflects the current contents of the - screen, and the other to draw what we think the new contents should - be. Then compare the buffers, and make whatever changes to the - screen itself that we should. Finally, make the buffer that we - just drew into be the one which reflects the current contents of the - screen, and place the cursor where it belongs. - - Commands that want to can fix the display themselves, and then let - this function know that the display has been fixed by setting the - RL_DISPLAY_FIXED variable. This is good for efficiency. */ - -/* Application-specific redisplay function. */ -rl_voidfunc_t *rl_redisplay_function = rl_redisplay; - -/* Global variables declared here. */ -/* What YOU turn on when you have handled all redisplay yourself. */ -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; -static int cpos_buffer_position; -static int prompt_multibyte_chars; - -/* Number of lines currently on screen minus 1. */ -int _rl_vis_botlin = 0; - -/* Variables used only in this file. */ -/* The last left edge of text that was displayed. This is used when - doing horizontal scrolling. It shifts in thirds of a screenwidth. */ -static int last_lmargin; - -/* A buffer for `modeline' messages. */ -static char *msg_buf = 0; -static int msg_bufsiz = 0; - -/* Non-zero forces the redisplay even if we thought it was unnecessary. */ -static int forced_display; - -/* Default and initial buffer size. Can grow. */ -static int line_size = 1024; - -/* Variables to keep track of the expanded prompt string, which may - include invisible characters. */ - -static char *local_prompt, *local_prompt_prefix; -static int local_prompt_len; -static int prompt_visible_length, prompt_prefix_length; - -/* The number of invisible characters in the line currently being - displayed on the screen. */ -static int visible_wrap_offset; - -/* The number of invisible characters in the prompt string. Static so it - can be shared between rl_redisplay and update_line */ -static int wrap_offset; - -/* The index of the last invisible character in the prompt string. */ -static int prompt_last_invisible; - -/* The length (buffer offset) of the first line of the last (possibly - multi-line) buffer displayed on the screen. */ -static int visible_first_line_len; - -/* Number of invisible characters on the first physical line of the prompt. - Only valid when the number of physical characters in the prompt exceeds - (or is equal to) _rl_screenwidth. */ -static int prompt_invis_chars_first_line; - -static int prompt_last_screen_line; - -static int prompt_physical_chars; - -/* set to a non-zero value by rl_redisplay if we are marking modified history - lines and the current line is so marked. */ -static int modmark; - -/* 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_local_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 - index of the last invisible character in the returned string. NIFLP, - if non-zero, is a place to store the number of invisible characters in - the first prompt line. The previous are used as byte counts -- indexes - into a character buffer. */ - -/* Current implementation: - \001 (^A) start non-visible characters - \002 (^B) end non-visible characters - all characters except \001 and \002 (following a \001) are copied to - the returned string; all characters except those between \001 and - \002 are assumed to be `visible'. */ - -static char * -expand_prompt (pmt, lp, lip, niflp, vlp) - char *pmt; - int *lp, *lip, *niflp, *vlp; -{ - char *r, *ret, *p, *igstart; - int l, rl, last, ignoring, ninvis, invfl, invflset, ind, pind, physchars; - - /* Short-circuit if we can. */ - if ((MB_CUR_MAX <= 1 || rl_byte_oriented) && strchr (pmt, RL_PROMPT_START_IGNORE) == 0) - { - r = savestring (pmt); - if (lp) - *lp = strlen (r); - if (lip) - *lip = 0; - if (niflp) - *niflp = 0; - if (vlp) - *vlp = lp ? *lp : strlen (r); - return r; - } - - l = strlen (pmt); - r = ret = (char *)xmalloc (l + 1); - - invfl = 0; /* invisible chars in first line of prompt */ - invflset = 0; /* we only want to set invfl once */ - - igstart = 0; - for (rl = ignoring = last = ninvis = physchars = 0, p = pmt; p && *p; p++) - { - /* This code strips the invisible character string markers - RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE */ - if (ignoring == 0 && *p == RL_PROMPT_START_IGNORE) /* XXX - check ignoring? */ - { - ignoring = 1; - igstart = p; - continue; - } - else if (ignoring && *p == RL_PROMPT_END_IGNORE) - { - ignoring = 0; - if (p != (igstart + 1)) - last = r - ret - 1; - continue; - } - else - { -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - pind = p - pmt; - ind = _rl_find_next_mbchar (pmt, pind, 1, MB_FIND_NONZERO); - l = ind - pind; - while (l--) - *r++ = *p++; - if (!ignoring) - { - /* rl ends up being assigned to prompt_visible_length, - which is the number of characters in the buffer that - contribute to characters on the screen, which might - not be the same as the number of physical characters - on the screen in the presence of multibyte characters */ - rl += ind - pind; - physchars += _rl_col_width (pmt, pind, ind, 0); - } - else - ninvis += ind - pind; - p--; /* compensate for later increment */ - } - else -#endif - { - *r++ = *p; - if (!ignoring) - { - rl++; /* visible length byte counter */ - physchars++; - } - else - ninvis++; /* invisible chars byte counter */ - } - - if (invflset == 0 && rl >= _rl_screenwidth) - { - invfl = ninvis; - invflset = 1; - } - } - } - - if (rl < _rl_screenwidth) - invfl = ninvis; - - *r = '\0'; - if (lp) - *lp = rl; - if (lip) - *lip = last; - if (niflp) - *niflp = invfl; - if (vlp) - *vlp = physchars; - return ret; -} - -/* Just strip out RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE from - PMT and return the rest of PMT. */ -char * -_rl_strip_prompt (pmt) - char *pmt; -{ - char *ret; - - ret = expand_prompt (pmt, (int *)NULL, (int *)NULL, (int *)NULL, (int *)NULL); - return ret; -} - -/* - * Expand the prompt string into the various display components, if - * necessary. - * - * local_prompt = expanded last line of string in rl_display_prompt - * (portion after the final newline) - * local_prompt_prefix = portion before last newline of rl_display_prompt, - * expanded via expand_prompt - * prompt_visible_length = number of visible characters in local_prompt - * prompt_prefix_length = number of visible characters in local_prompt_prefix - * - * This function is called once per call to readline(). It may also be - * called arbitrarily to expand the primary prompt. - * - * The return value is the number of visible characters on the last line - * of the (possibly multi-line) prompt. - */ -int -rl_expand_prompt (prompt) - char *prompt; -{ - char *p, *t; - int c; - - /* Clear out any saved values. */ - FREE (local_prompt); - FREE (local_prompt_prefix); - - local_prompt = local_prompt_prefix = (char *)0; - local_prompt_len = 0; - prompt_last_invisible = prompt_invis_chars_first_line = 0; - prompt_visible_length = prompt_physical_chars = 0; - - if (prompt == 0 || *prompt == 0) - return (0); - - p = strrchr (prompt, '\n'); - if (!p) - { - /* The prompt is only one logical line, though it might wrap. */ - local_prompt = expand_prompt (prompt, &prompt_visible_length, - &prompt_last_invisible, - &prompt_invis_chars_first_line, - &prompt_physical_chars); - local_prompt_prefix = (char *)0; - local_prompt_len = local_prompt ? strlen (local_prompt) : 0; - return (prompt_visible_length); - } - else - { - /* The prompt spans multiple lines. */ - t = ++p; - local_prompt = expand_prompt (p, &prompt_visible_length, - &prompt_last_invisible, - &prompt_invis_chars_first_line, - &prompt_physical_chars); - c = *t; *t = '\0'; - /* The portion of the prompt string up to and including the - final newline is now null-terminated. */ - local_prompt_prefix = expand_prompt (prompt, &prompt_prefix_length, - (int *)NULL, - (int *)NULL, - (int *)NULL); - *t = c; - local_prompt_len = local_prompt ? strlen (local_prompt) : 0; - return (prompt_prefix_length); - } -} - -/* Initialize the VISIBLE_LINE and INVISIBLE_LINE arrays, and their associated - arrays of line break markers. MINSIZE is the minimum size of VISIBLE_LINE - and INVISIBLE_LINE; if it is greater than LINE_SIZE, LINE_SIZE is - increased. If the lines have already been allocated, this ensures that - they can hold at least MINSIZE characters. */ -static void -init_line_structures (minsize) - int minsize; -{ - register int n; - - if (invisible_line == 0) /* initialize it */ - { - if (line_size < minsize) - line_size = minsize; - visible_line = (char *)xmalloc (line_size); - invisible_line = (char *)xmalloc (line_size); - } - else if (line_size < minsize) /* ensure it can hold MINSIZE chars */ - { - line_size *= 2; - if (line_size < minsize) - line_size = minsize; - visible_line = (char *)xrealloc (visible_line, line_size); - invisible_line = (char *)xrealloc (invisible_line, line_size); - } - - for (n = minsize; n < line_size; n++) - { - visible_line[n] = 0; - invisible_line[n] = 1; - } - - if (vis_lbreaks == 0) - { - /* should be enough. */ - inv_lbsize = vis_lbsize = 256; - -#if defined (HANDLE_MULTIBYTE) - line_state_visible->wbsize = vis_lbsize; - line_state_visible->wrapped_line = (int *)xmalloc (line_state_visible->wbsize * sizeof (int)); - - line_state_invisible->wbsize = inv_lbsize; - line_state_invisible->wrapped_line = (int *)xmalloc (line_state_invisible->wbsize * sizeof (int)); -#endif - - inv_lbreaks = (int *)xmalloc (inv_lbsize * sizeof (int)); - vis_lbreaks = (int *)xmalloc (vis_lbsize * sizeof (int)); - inv_lbreaks[0] = vis_lbreaks[0] = 0; - } - - line_structures_initialized = 1; -} - -/* Basic redisplay algorithm. */ -void -rl_redisplay () -{ - register int in, out, c, linenum, cursor_linenum; - register char *line; - int inv_botlin, lb_botlin, lb_linenum, o_cpos; - int newlines, lpos, temp, n0, num, prompt_lines_estimate; - char *prompt_this_line; -#if defined (HANDLE_MULTIBYTE) - wchar_t wc; - size_t wc_bytes; - int wc_width; - mbstate_t ps; - int _rl_wrapped_multicolumn = 0; -#endif - - if (_rl_echoing_p == 0) - return; - - /* Block keyboard interrupts because this function manipulates global - data structures. */ - _rl_block_sigint (); - RL_SETSTATE (RL_STATE_REDISPLAYING); - - if (!rl_display_prompt) - rl_display_prompt = ""; - - if (line_structures_initialized == 0) - { - init_line_structures (0); - rl_on_new_line (); - } - - /* Draw the line into the buffer. */ - cpos_buffer_position = -1; - - prompt_multibyte_chars = prompt_visible_length - prompt_physical_chars; - - line = invisible_line; - out = inv_botlin = 0; - - /* Mark the line as modified or not. We only do this for history - lines. */ - modmark = 0; - if (_rl_mark_modified_lines && current_history () && rl_undo_list) - { - line[out++] = '*'; - line[out] = '\0'; - modmark = 1; - } - - /* If someone thought that the redisplay was handled, but the currently - visible line has a different modification state than the one about - to become visible, then correct the caller's misconception. */ - if (visible_line[0] != invisible_line[0]) - rl_display_fixed = 0; - - /* If the prompt to be displayed is the `primary' readline prompt (the - one passed to readline()), use the values we have already expanded. - If not, use what's already in rl_display_prompt. WRAP_OFFSET is the - number of non-visible characters in the prompt string. */ - if (rl_display_prompt == rl_prompt || local_prompt) - { - if (local_prompt_prefix && forced_display) - _rl_output_some_chars (local_prompt_prefix, strlen (local_prompt_prefix)); - - if (local_prompt_len > 0) - { - temp = local_prompt_len + out + 2; - if (temp >= line_size) - { - line_size = (temp + 1024) - (temp % 1024); - visible_line = (char *)xrealloc (visible_line, line_size); - line = invisible_line = (char *)xrealloc (invisible_line, line_size); - } - strncpy (line + out, local_prompt, local_prompt_len); - out += local_prompt_len; - } - line[out] = '\0'; - wrap_offset = local_prompt_len - prompt_visible_length; - } - else - { - int pmtlen; - prompt_this_line = strrchr (rl_display_prompt, '\n'); - if (!prompt_this_line) - prompt_this_line = rl_display_prompt; - else - { - prompt_this_line++; - pmtlen = prompt_this_line - rl_display_prompt; /* temp var */ - if (forced_display) - { - _rl_output_some_chars (rl_display_prompt, pmtlen); - /* Make sure we are at column zero even after a newline, - regardless of the state of terminal output processing. */ - if (pmtlen < 2 || prompt_this_line[-2] != '\r') - cr (); - } - } - - prompt_physical_chars = pmtlen = strlen (prompt_this_line); - temp = pmtlen + out + 2; - if (temp >= line_size) - { - line_size = (temp + 1024) - (temp % 1024); - visible_line = (char *)xrealloc (visible_line, line_size); - line = invisible_line = (char *)xrealloc (invisible_line, line_size); - } - strncpy (line + out, prompt_this_line, pmtlen); - out += pmtlen; - line[out] = '\0'; - wrap_offset = prompt_invis_chars_first_line = 0; - } - -#define CHECK_INV_LBREAKS() \ - do { \ - if (newlines >= (inv_lbsize - 2)) \ - { \ - inv_lbsize *= 2; \ - inv_lbreaks = (int *)xrealloc (inv_lbreaks, inv_lbsize * sizeof (int)); \ - } \ - } while (0) - -#if defined (HANDLE_MULTIBYTE) -#define CHECK_LPOS() \ - do { \ - lpos++; \ - if (lpos >= _rl_screenwidth) \ - { \ - if (newlines >= (inv_lbsize - 2)) \ - { \ - inv_lbsize *= 2; \ - inv_lbreaks = (int *)xrealloc (inv_lbreaks, inv_lbsize * sizeof (int)); \ - } \ - inv_lbreaks[++newlines] = out; \ - if (newlines >= (line_state_invisible->wbsize - 1)) \ - { \ - line_state_invisible->wbsize *= 2; \ - line_state_invisible->wrapped_line = (int *)xrealloc (line_state_invisible->wrapped_line, line_state_invisible->wbsize * sizeof(int)); \ - } \ - line_state_invisible->wrapped_line[newlines] = _rl_wrapped_multicolumn; \ - lpos = 0; \ - } \ - } while (0) -#else -#define CHECK_LPOS() \ - do { \ - lpos++; \ - if (lpos >= _rl_screenwidth) \ - { \ - if (newlines >= (inv_lbsize - 2)) \ - { \ - inv_lbsize *= 2; \ - inv_lbreaks = (int *)xrealloc (inv_lbreaks, inv_lbsize * sizeof (int)); \ - } \ - inv_lbreaks[++newlines] = out; \ - lpos = 0; \ - } \ - } while (0) -#endif - - /* inv_lbreaks[i] is where line i starts in the buffer. */ - inv_lbreaks[newlines = 0] = 0; - lpos = prompt_physical_chars + modmark; - -#if defined (HANDLE_MULTIBYTE) - memset (line_state_invisible->wrapped_line, 0, line_state_invisible->wbsize * sizeof (int)); - num = 0; -#endif - - /* prompt_invis_chars_first_line is the number of invisible characters in - the first physical line of the prompt. - wrap_offset - prompt_invis_chars_first_line is the number of invis - chars on the second (or, more generally, last) line. */ - - /* This is zero-based, used to set the newlines */ - prompt_lines_estimate = lpos / _rl_screenwidth; - - /* what if lpos is already >= _rl_screenwidth before we start drawing the - contents of the command line? */ - while (lpos >= _rl_screenwidth) - { - int z; - /* fix from Darin Johnson <darin@acuson.com> for prompt string with - invisible characters that is longer than the screen width. The - prompt_invis_chars_first_line variable could be made into an array - saying how many invisible characters there are per line, but that's - probably too much work for the benefit gained. How many people have - prompts that exceed two physical lines? - Additional logic fix from Edward Catmur <ed@catmur.co.uk> */ -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0 && prompt_multibyte_chars > 0) - { - n0 = num; - temp = local_prompt_len; - while (num < temp) - { - z = _rl_col_width (local_prompt, n0, num, 1); - if (z > _rl_screenwidth) - { - num = _rl_find_prev_mbchar (local_prompt, num, MB_FIND_ANY); - break; - } - else if (z == _rl_screenwidth) - break; - num++; - } - temp = num; - } - else -#endif /* !HANDLE_MULTIBYTE */ - temp = ((newlines + 1) * _rl_screenwidth); - - /* Now account for invisible characters in the current line. */ - /* XXX - this assumes that the invisible characters may be split, but only - between the first and the last lines. */ - temp += ((local_prompt_prefix == 0) ? ((newlines == 0) ? prompt_invis_chars_first_line - : ((newlines == prompt_lines_estimate) ? wrap_offset : prompt_invis_chars_first_line)) - : ((newlines == 0) ? wrap_offset : 0)); - - inv_lbreaks[++newlines] = temp; -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0 && prompt_multibyte_chars > 0) - lpos -= _rl_col_width (local_prompt, n0, num, 1); - else -#endif - lpos -= _rl_screenwidth; - } - - prompt_last_screen_line = newlines; - - /* Draw the rest of the line (after the prompt) into invisible_line, keeping - track of where the cursor is (cpos_buffer_position), the number of the line containing - the cursor (lb_linenum), the last line number (lb_botlin and inv_botlin). - It maintains an array of line breaks for display (inv_lbreaks). - This handles expanding tabs for display and displaying meta characters. */ - lb_linenum = 0; -#if defined (HANDLE_MULTIBYTE) - in = 0; - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - memset (&ps, 0, sizeof (mbstate_t)); - /* XXX - what if wc_bytes ends up <= 0? check for MB_INVALIDCH */ - wc_bytes = mbrtowc (&wc, rl_line_buffer, rl_end, &ps); - } - else - wc_bytes = 1; - while (in < rl_end) -#else - for (in = 0; in < rl_end; in++) -#endif - { - c = (unsigned char)rl_line_buffer[in]; - -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - if (MB_INVALIDCH (wc_bytes)) - { - /* Byte sequence is invalid or shortened. Assume that the - first byte represents a character. */ - wc_bytes = 1; - /* Assume that a character occupies a single column. */ - wc_width = 1; - memset (&ps, 0, sizeof (mbstate_t)); - } - else if (MB_NULLWCH (wc_bytes)) - break; /* Found '\0' */ - else - { - temp = wcwidth (wc); - wc_width = (temp >= 0) ? temp : 1; - } - } -#endif - - if (out + 8 >= line_size) /* XXX - 8 for \t */ - { - line_size *= 2; - visible_line = (char *)xrealloc (visible_line, line_size); - invisible_line = (char *)xrealloc (invisible_line, line_size); - line = invisible_line; - } - - if (in == rl_point) - { - cpos_buffer_position = out; - lb_linenum = newlines; - } - -#if defined (HANDLE_MULTIBYTE) - if (META_CHAR (c) && _rl_output_meta_chars == 0) /* XXX - clean up */ -#else - if (META_CHAR (c)) -#endif - { - if (_rl_output_meta_chars == 0) - { - sprintf (line + out, "\\%o", c); - - if (lpos + 4 >= _rl_screenwidth) - { - temp = _rl_screenwidth - lpos; - CHECK_INV_LBREAKS (); - inv_lbreaks[++newlines] = out + temp; - lpos = 4 - temp; - } - else - lpos += 4; - - out += 4; - } - else - { - line[out++] = c; - CHECK_LPOS(); - } - } -#if defined (DISPLAY_TABS) - else if (c == '\t') - { - register int newout; - -#if 0 - newout = (out | (int)7) + 1; -#else - newout = out + 8 - lpos % 8; -#endif - temp = newout - out; - if (lpos + temp >= _rl_screenwidth) - { - register int temp2; - temp2 = _rl_screenwidth - lpos; - CHECK_INV_LBREAKS (); - inv_lbreaks[++newlines] = out + temp2; - lpos = temp - temp2; - while (out < newout) - line[out++] = ' '; - } - else - { - while (out < newout) - line[out++] = ' '; - lpos += temp; - } - } -#endif - else if (c == '\n' && _rl_horizontal_scroll_mode == 0 && _rl_term_up && *_rl_term_up) - { - line[out++] = '\0'; /* XXX - sentinel */ - CHECK_INV_LBREAKS (); - inv_lbreaks[++newlines] = out; - lpos = 0; - } - else if (CTRL_CHAR (c) || c == RUBOUT) - { - line[out++] = '^'; - CHECK_LPOS(); - line[out++] = CTRL_CHAR (c) ? UNCTRL (c) : '?'; - CHECK_LPOS(); - } - else - { -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - register int i; - - _rl_wrapped_multicolumn = 0; - - if (_rl_screenwidth < lpos + wc_width) - for (i = lpos; i < _rl_screenwidth; i++) - { - /* The space will be removed in update_line() */ - line[out++] = ' '; - _rl_wrapped_multicolumn++; - CHECK_LPOS(); - } - if (in == rl_point) - { - cpos_buffer_position = out; - lb_linenum = newlines; - } - for (i = in; i < in+wc_bytes; i++) - line[out++] = rl_line_buffer[i]; - for (i = 0; i < wc_width; i++) - CHECK_LPOS(); - } - else - { - line[out++] = c; - CHECK_LPOS(); - } -#else - line[out++] = c; - CHECK_LPOS(); -#endif - } - -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - in += wc_bytes; - /* XXX - what if wc_bytes ends up <= 0? check for MB_INVALIDCH */ - wc_bytes = mbrtowc (&wc, rl_line_buffer + in, rl_end - in, &ps); - } - else - in++; -#endif - - } - line[out] = '\0'; - if (cpos_buffer_position < 0) - { - cpos_buffer_position = out; - lb_linenum = newlines; - } - - inv_botlin = lb_botlin = newlines; - CHECK_INV_LBREAKS (); - inv_lbreaks[newlines+1] = out; - cursor_linenum = lb_linenum; - - /* CPOS_BUFFER_POSITION == position in buffer where cursor should be placed. - CURSOR_LINENUM == line number where the cursor should be placed. */ - - /* PWP: now is when things get a bit hairy. The visible and invisible - line buffers are really multiple lines, which would wrap every - (screenwidth - 1) characters. Go through each in turn, finding - the changed region and updating it. The line order is top to bottom. */ - - /* If we can move the cursor up and down, then use multiple lines, - otherwise, let long lines display in a single terminal line, and - horizontally scroll it. */ - - if (_rl_horizontal_scroll_mode == 0 && _rl_term_up && *_rl_term_up) - { - int nleft, pos, changed_screen_line, tx; - - if (!rl_display_fixed || forced_display) - { - forced_display = 0; - - /* If we have more than a screenful of material to display, then - only display a screenful. We should display the last screen, - not the first. */ - if (out >= _rl_screenchars) - { - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - out = _rl_find_prev_mbchar (line, _rl_screenchars, MB_FIND_ANY); - else - out = _rl_screenchars - 1; - } - - /* The first line is at character position 0 in the buffer. The - second and subsequent lines start at inv_lbreaks[N], offset by - OFFSET (which has already been calculated above). */ - -#define INVIS_FIRST() (prompt_physical_chars > _rl_screenwidth ? prompt_invis_chars_first_line : wrap_offset) -#define WRAP_OFFSET(line, offset) ((line == 0) \ - ? (offset ? INVIS_FIRST() : 0) \ - : ((line == prompt_last_screen_line) ? wrap_offset-prompt_invis_chars_first_line : 0)) -#define W_OFFSET(line, offset) ((line) == 0 ? offset : 0) -#define VIS_LLEN(l) ((l) > _rl_vis_botlin ? 0 : (vis_lbreaks[l+1] - vis_lbreaks[l])) -#define INV_LLEN(l) (inv_lbreaks[l+1] - inv_lbreaks[l]) -#define VIS_CHARS(line) (visible_line + vis_lbreaks[line]) -#define VIS_LINE(line) ((line) > _rl_vis_botlin) ? "" : VIS_CHARS(line) -#define INV_LINE(line) (invisible_line + inv_lbreaks[line]) - -#define OLD_CPOS_IN_PROMPT() (cpos_adjusted == 0 && \ - _rl_last_c_pos != o_cpos && \ - _rl_last_c_pos > wrap_offset && \ - o_cpos < prompt_last_invisible) - - /* For each line in the buffer, do the updating display. */ - for (linenum = 0; linenum <= inv_botlin; linenum++) - { - /* This can lead us astray if we execute a program that changes - the locale from a non-multibyte to a multibyte one. */ - 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 are several cases 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 we assume that - _rl_last_c_pos is correct (an absolute cursor position) each - time update_line is called, then we can assume in our - calculations that o_cpos does not need to be adjusted by - wrap_offset. */ - if (linenum == 0 && (MB_CUR_MAX > 1 && rl_byte_oriented == 0) && OLD_CPOS_IN_PROMPT()) - _rl_last_c_pos -= prompt_invis_chars_first_line; /* XXX - was wrap_offset */ - else if (linenum == prompt_last_screen_line && prompt_physical_chars > _rl_screenwidth && - (MB_CUR_MAX > 1 && rl_byte_oriented == 0) && - cpos_adjusted == 0 && - _rl_last_c_pos != o_cpos && - _rl_last_c_pos > (prompt_last_invisible - _rl_screenwidth - prompt_invis_chars_first_line)) - _rl_last_c_pos -= (wrap_offset-prompt_invis_chars_first_line); - - /* 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 - implies that we completely overwrite the old visible line) - and the new line is shorter than the old. Make sure we are - at the end of the new line before clearing. */ - if (linenum == 0 && - inv_botlin == 0 && _rl_last_c_pos == out && - (wrap_offset > visible_wrap_offset) && - (_rl_last_c_pos < visible_first_line_len)) - { - 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); - } -#if 0 - /* This segment is intended to handle the case where the prompt - has invisible characters on the second line and the new line - to be displayed needs to clear the rest of the old characters - out (e.g., when printing the i-search prompt). In general, - the case of the new line being shorter than the old. - Incomplete */ - else if (linenum == prompt_last_screen_line && - prompt_physical_chars > _rl_screenwidth && - wrap_offset != prompt_invis_chars_first_line && - _rl_last_c_pos == out && -#endif - - - /* Since the new first line is now visible, save its length. */ - if (linenum == 0) - visible_first_line_len = (inv_botlin > 0) ? inv_lbreaks[1] : out - wrap_offset; - } - - /* We may have deleted some lines. If so, clear the left over - blank ones at the bottom out. */ - if (_rl_vis_botlin > inv_botlin) - { - char *tt; - for (; linenum <= _rl_vis_botlin; linenum++) - { - tt = VIS_CHARS (linenum); - _rl_move_vert (linenum); - _rl_move_cursor_relative (0, tt); - _rl_clear_to_eol - ((linenum == _rl_vis_botlin) ? strlen (tt) : _rl_screenwidth); - } - } - _rl_vis_botlin = inv_botlin; - - /* CHANGED_SCREEN_LINE is set to 1 if we have moved to a - different screen line during this redisplay. */ - changed_screen_line = _rl_last_v_pos != cursor_linenum; - if (changed_screen_line) - { - _rl_move_vert (cursor_linenum); - /* If we moved up to the line with the prompt using _rl_term_up, - the physical cursor position on the screen stays the same, - but the buffer position needs to be adjusted to account - for invisible characters. */ - if ((MB_CUR_MAX == 1 || rl_byte_oriented) && cursor_linenum == 0 && wrap_offset) - _rl_last_c_pos += wrap_offset; - } - - /* We have to reprint the prompt if it contains invisible - characters, since it's not generally OK to just reprint - the characters from the current cursor position. But we - only need to reprint it if the cursor is before the last - invisible character in the prompt string. */ - nleft = prompt_visible_length + wrap_offset; - if (cursor_linenum == 0 && wrap_offset > 0 && _rl_last_c_pos > 0 && -#if 0 - _rl_last_c_pos <= PROMPT_ENDING_INDEX && local_prompt) -#else - _rl_last_c_pos < PROMPT_ENDING_INDEX && local_prompt) -#endif - { -#if defined (__MSDOS__) - putc ('\r', rl_outstream); -#else - if (_rl_term_cr) - tputs (_rl_term_cr, 1, _rl_output_character_function); -#endif - if (modmark) - _rl_output_some_chars ("*", 1); - - _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, 1) - wrap_offset + modmark; - else - _rl_last_c_pos = nleft + modmark; - } - - /* Where on that line? And where does that line start - in the buffer? */ - pos = inv_lbreaks[cursor_linenum]; - /* nleft == number of characters in the line buffer between the - start of the line and the desired cursor position. */ - nleft = cpos_buffer_position - 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) - { - /* TX == new physical cursor position in multibyte locale. */ - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - tx = _rl_col_width (&visible_line[pos], 0, nleft, 1) - visible_wrap_offset; - else - tx = nleft; - if (tx >= 0 && _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) - _rl_move_cursor_relative (nleft, &invisible_line[pos]); - } - } - else /* Do horizontal scrolling. */ - { -#define M_OFFSET(margin, offset) ((margin) == 0 ? offset : 0) - int lmargin, ndisp, nleft, phys_c_pos, t; - - /* Always at top line. */ - _rl_last_v_pos = 0; - - /* Compute where in the buffer the displayed line should start. This - will be LMARGIN. */ - - /* The number of characters that will be displayed before the cursor. */ - ndisp = cpos_buffer_position - wrap_offset; - nleft = prompt_visible_length + wrap_offset; - /* Where the new cursor position will be on the screen. This can be - longer than SCREENWIDTH; if it is, lmargin will be adjusted. */ - phys_c_pos = cpos_buffer_position - (last_lmargin ? last_lmargin : wrap_offset); - t = _rl_screenwidth / 3; - - /* If the number of characters had already exceeded the screenwidth, - last_lmargin will be > 0. */ - - /* If the number of characters to be displayed is more than the screen - width, compute the starting offset so that the cursor is about - two-thirds of the way across the screen. */ - if (phys_c_pos > _rl_screenwidth - 2) - { - lmargin = cpos_buffer_position - (2 * t); - if (lmargin < 0) - lmargin = 0; - /* If the left margin would be in the middle of a prompt with - invisible characters, don't display the prompt at all. */ - if (wrap_offset && lmargin > 0 && lmargin < nleft) - lmargin = nleft; - } - else if (ndisp < _rl_screenwidth - 2) /* XXX - was -1 */ - lmargin = 0; - else if (phys_c_pos < 1) - { - /* If we are moving back towards the beginning of the line and - the last margin is no longer correct, compute a new one. */ - lmargin = ((cpos_buffer_position - 1) / t) * t; /* XXX */ - if (wrap_offset && lmargin > 0 && lmargin < nleft) - lmargin = nleft; - } - else - lmargin = last_lmargin; - - /* If the first character on the screen isn't the first character - in the display line, indicate this with a special character. */ - if (lmargin > 0) - line[lmargin] = '<'; - - /* If SCREENWIDTH characters starting at LMARGIN do not encompass - the whole line, indicate that with a special character at the - right edge of the screen. If LMARGIN is 0, we need to take the - wrap offset into account. */ - t = lmargin + M_OFFSET (lmargin, wrap_offset) + _rl_screenwidth; - if (t < out) - line[t - 1] = '>'; - - if (rl_display_fixed == 0 || forced_display || lmargin != last_lmargin) - { - forced_display = 0; - o_cpos = _rl_last_c_pos; - cpos_adjusted = 0; - update_line (&visible_line[last_lmargin], - &invisible_line[lmargin], - 0, - _rl_screenwidth + visible_wrap_offset, - _rl_screenwidth + (lmargin ? 0 : wrap_offset), - 0); - - if ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && OLD_CPOS_IN_PROMPT()) - _rl_last_c_pos -= prompt_invis_chars_first_line; /* XXX - was wrap_offset */ - - /* If the visible new line is shorter than the old, but the number - of invisible characters is greater, and we are at the end of - the new line, we need to clear to eol. */ - t = _rl_last_c_pos - M_OFFSET (lmargin, wrap_offset); - if ((M_OFFSET (lmargin, wrap_offset) > visible_wrap_offset) && - (_rl_last_c_pos == out) && - t < visible_first_line_len) - { - nleft = _rl_screenwidth - t; - _rl_clear_to_eol (nleft); - } - visible_first_line_len = out - lmargin - M_OFFSET (lmargin, wrap_offset); - if (visible_first_line_len > _rl_screenwidth) - visible_first_line_len = _rl_screenwidth; - - _rl_move_cursor_relative (cpos_buffer_position - lmargin, &invisible_line[lmargin]); - last_lmargin = lmargin; - } - } - fflush (rl_outstream); - - /* Swap visible and non-visible lines. */ - { - struct line_state *vtemp = line_state_visible; - - line_state_visible = line_state_invisible; - line_state_invisible = vtemp; - - rl_display_fixed = 0; - /* If we are displaying on a single line, and last_lmargin is > 0, we - are not displaying any invisible characters, so set visible_wrap_offset - to 0. */ - if (_rl_horizontal_scroll_mode && last_lmargin) - visible_wrap_offset = 0; - else - visible_wrap_offset = wrap_offset; - } - - RL_UNSETSTATE (RL_STATE_REDISPLAYING); - _rl_release_sigint (); -} - -/* PWP: update_line() is based on finding the middle difference of each - line on the screen; vis: - - /old first difference - /beginning of line | /old last same /old EOL - v v v v -old: eddie> Oh, my little gruntle-buggy is to me, as lurgid as -new: eddie> Oh, my little buggy says to me, as lurgid as - ^ ^ ^ ^ - \beginning of line | \new last same \new end of line - \new first difference - - All are character pointers for the sake of speed. Special cases for - no differences, as well as for end of line additions must be handled. - - Could be made even smarter, but this works well enough */ -static void -update_line (old, new, current_line, omax, nmax, inv_botlin) - register char *old, *new; - int current_line, omax, nmax, inv_botlin; -{ - register char *ofd, *ols, *oe, *nfd, *nls, *ne; - int temp, lendiff, wsatend, od, nd, twidth, o_cpos; - int current_invis_chars; - int col_lendiff, col_temp; -#if defined (HANDLE_MULTIBYTE) - mbstate_t ps_new, ps_old; - int new_offset, old_offset; -#endif - - /* If we're at the right edge of a terminal that supports xn, we're - ready to wrap around, so do so. This fixes problems with knowing - the exact cursor position and cut-and-paste with certain terminal - emulators. In this calculation, TEMP is the physical screen - position of the cursor. */ - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - temp = _rl_last_c_pos; - else - temp = _rl_last_c_pos - WRAP_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) - { -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - wchar_t wc; - mbstate_t ps; - int tempwidth, bytes; - size_t ret; - - /* This fixes only double-column characters, but if the wrapped - character comsumes more than three columns, spaces will be - inserted in the string buffer. */ - if (current_line < line_state_visible->wbsize && line_state_visible->wrapped_line[current_line] > 0) - _rl_clear_to_eol (line_state_visible->wrapped_line[current_line]); - - memset (&ps, 0, sizeof (mbstate_t)); - ret = mbrtowc (&wc, new, MB_CUR_MAX, &ps); - if (MB_INVALIDCH (ret)) - { - tempwidth = 1; - ret = 1; - } - else if (MB_NULLWCH (ret)) - tempwidth = 0; - else - tempwidth = wcwidth (wc); - - if (tempwidth > 0) - { - int count, i; - bytes = ret; - for (count = 0; count < bytes; count++) - putc (new[count], rl_outstream); - _rl_last_c_pos = tempwidth; - _rl_last_v_pos++; - memset (&ps, 0, sizeof (mbstate_t)); - ret = mbrtowc (&wc, old, MB_CUR_MAX, &ps); - if (ret != 0 && bytes != 0) - { - if (MB_INVALIDCH (ret)) - ret = 1; - memmove (old+bytes, old+ret, strlen (old+ret)); - memcpy (old, new, bytes); - /* Fix up indices if we copy data from one line to another */ - omax += bytes - ret; - for (i = current_line+1; i < inv_botlin+1; i++) - vis_lbreaks[i] += bytes - ret; - } - } - else - { - putc (' ', rl_outstream); - _rl_last_c_pos = 1; - _rl_last_v_pos++; - if (old[0] && new[0]) - old[0] = new[0]; - } - } - else -#endif - { - if (new[0]) - putc (new[0], rl_outstream); - else - putc (' ', rl_outstream); - _rl_last_c_pos = 1; - _rl_last_v_pos++; - if (old[0] && new[0]) - old[0] = new[0]; - } - } - - - /* Find first difference. */ -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - /* See if the old line is a subset of the new line, so that the - only change is adding characters. */ - temp = (omax < nmax) ? omax : nmax; - if (memcmp (old, new, temp) == 0) /* adding at the end */ - { - ofd = old + temp; - nfd = new + temp; - } - else - { - memset (&ps_new, 0, sizeof(mbstate_t)); - memset (&ps_old, 0, sizeof(mbstate_t)); - - if (omax == nmax && STREQN (new, old, omax)) - { - ofd = old + omax; - nfd = new + nmax; - } - else - { - new_offset = old_offset = 0; - for (ofd = old, nfd = new; - (ofd - old < omax) && *ofd && - _rl_compare_chars(old, old_offset, &ps_old, new, new_offset, &ps_new); ) - { - old_offset = _rl_find_next_mbchar (old, old_offset, 1, MB_FIND_ANY); - new_offset = _rl_find_next_mbchar (new, new_offset, 1, MB_FIND_ANY); - ofd = old + old_offset; - nfd = new + new_offset; - } - } - } - } - else -#endif - for (ofd = old, nfd = new; - (ofd - old < omax) && *ofd && (*ofd == *nfd); - ofd++, nfd++) - ; - - /* Move to the end of the screen line. ND and OD are used to keep track - of the distance between ne and new and oe and old, respectively, to - move a subtraction out of each loop. */ - for (od = ofd - old, oe = ofd; od < omax && *oe; oe++, od++); - for (nd = nfd - new, ne = nfd; nd < nmax && *ne; ne++, nd++); - - /* If no difference, continue to next line. */ - if (ofd == oe && nfd == ne) - return; - - wsatend = 1; /* flag for trailing whitespace */ - -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - ols = old + _rl_find_prev_mbchar (old, oe - old, MB_FIND_ANY); - nls = new + _rl_find_prev_mbchar (new, ne - new, MB_FIND_ANY); - while ((ols > ofd) && (nls > nfd)) - { - memset (&ps_old, 0, sizeof (mbstate_t)); - memset (&ps_new, 0, sizeof (mbstate_t)); - -#if 0 - /* On advice from jir@yamato.ibm.com */ - _rl_adjust_point (old, ols - old, &ps_old); - _rl_adjust_point (new, nls - new, &ps_new); -#endif - - if (_rl_compare_chars (old, ols - old, &ps_old, new, nls - new, &ps_new) == 0) - break; - - if (*ols == ' ') - wsatend = 0; - - ols = old + _rl_find_prev_mbchar (old, ols - old, MB_FIND_ANY); - nls = new + _rl_find_prev_mbchar (new, nls - new, MB_FIND_ANY); - } - } - else - { -#endif /* HANDLE_MULTIBYTE */ - ols = oe - 1; /* find last same */ - nls = ne - 1; - while ((ols > ofd) && (nls > nfd) && (*ols == *nls)) - { - if (*ols != ' ') - wsatend = 0; - ols--; - nls--; - } -#if defined (HANDLE_MULTIBYTE) - } -#endif - - if (wsatend) - { - ols = oe; - nls = ne; - } -#if defined (HANDLE_MULTIBYTE) - /* This may not work for stateful encoding, but who cares? To handle - stateful encoding properly, we have to scan each string from the - beginning and compare. */ - else if (_rl_compare_chars (ols, 0, NULL, nls, 0, NULL) == 0) -#else - else if (*ols != *nls) -#endif - { - if (*ols) /* don't step past the NUL */ - { - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - ols = old + _rl_find_next_mbchar (old, ols - old, 1, MB_FIND_ANY); - else - ols++; - } - if (*nls) - { - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - nls = new + _rl_find_next_mbchar (new, nls - new, 1, MB_FIND_ANY); - else - nls++; - } - } - - /* count of invisible characters in the current invisible line. */ - current_invis_chars = W_OFFSET (current_line, wrap_offset); - if (_rl_last_v_pos != current_line) - { - _rl_move_vert (current_line); - if ((MB_CUR_MAX == 1 || rl_byte_oriented) && current_line == 0 && visible_wrap_offset) - _rl_last_c_pos += visible_wrap_offset; - } - - /* If this is the first line and there are invisible characters in the - prompt string, and the prompt string has not changed, and the current - cursor position is before the last invisible character in the prompt, - and the index of the character to move to is past the end of the prompt - string, then redraw the entire prompt string. We can only do this - reliably if the terminal supports a `cr' capability. - - This is not an efficiency hack -- there is a problem with redrawing - portions of the prompt string if they contain terminal escape - sequences (like drawing the `unbold' sequence without a corresponding - `bold') that manifests itself on certain terminals. */ - - lendiff = local_prompt_len; - od = ofd - old; /* index of first difference in visible line */ - if (current_line == 0 && !_rl_horizontal_scroll_mode && - _rl_term_cr && lendiff > prompt_visible_length && _rl_last_c_pos > 0 && - od >= lendiff && _rl_last_c_pos < PROMPT_ENDING_INDEX) - { -#if defined (__MSDOS__) - putc ('\r', rl_outstream); -#else - tputs (_rl_term_cr, 1, _rl_output_character_function); -#endif - if (modmark) - _rl_output_some_chars ("*", 1); - _rl_output_some_chars (local_prompt, lendiff); - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - /* 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, 1) - wrap_offset + modmark; - cpos_adjusted = 1; - } - else - _rl_last_c_pos = lendiff + modmark; - } - - o_cpos = _rl_last_c_pos; - - /* When this function returns, _rl_last_c_pos is correct, and an absolute - cursor postion in multibyte mode, but a buffer index when not in a - multibyte locale. */ - _rl_move_cursor_relative (od, old); -#if 1 -#if defined (HANDLE_MULTIBYTE) - /* We need to indicate that the cursor position is correct in the presence of - invisible characters in the prompt string. Let's see if setting this when - we make sure we're at the end of the drawn prompt string works. */ - if (current_line == 0 && MB_CUR_MAX > 1 && rl_byte_oriented == 0 && - (_rl_last_c_pos > 0 || o_cpos > 0) && - _rl_last_c_pos == prompt_physical_chars) - cpos_adjusted = 1; -#endif -#endif - - /* if (len (new) > len (old)) - lendiff == difference in buffer - col_lendiff == difference on screen - When not using multibyte characters, these are equal */ - lendiff = (nls - nfd) - (ols - ofd); - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - col_lendiff = _rl_col_width (new, nfd - new, nls - new, 1) - _rl_col_width (old, ofd - old, ols - old, 1); - else - col_lendiff = lendiff; - - /* If we are changing the number of invisible characters in a line, and - the spot of first difference is before the end of the invisible chars, - lendiff needs to be adjusted. */ - if (current_line == 0 && !_rl_horizontal_scroll_mode && - current_invis_chars != visible_wrap_offset) - { - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - lendiff += visible_wrap_offset - current_invis_chars; - col_lendiff += visible_wrap_offset - current_invis_chars; - } - else - { - lendiff += visible_wrap_offset - current_invis_chars; - col_lendiff = lendiff; - } - } - - /* Insert (diff (len (old), len (new)) ch. */ - temp = ne - nfd; - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - col_temp = _rl_col_width (new, nfd - new, ne - new, 1); - else - col_temp = temp; - - if (col_lendiff > 0) /* XXX - was lendiff */ - { - /* Non-zero if we're increasing the number of lines. */ - int gl = current_line >= _rl_vis_botlin && inv_botlin > _rl_vis_botlin; - /* If col_lendiff is > 0, implying that the new string takes up more - screen real estate than the old, but lendiff is < 0, meaning that it - takes fewer bytes, we need to just output the characters starting - from the first difference. These will overwrite what is on the - display, so there's no reason to do a smart update. This can really - only happen in a multibyte environment. */ - if (lendiff < 0) - { - _rl_output_some_chars (nfd, temp); - _rl_last_c_pos += _rl_col_width (nfd, 0, temp, 1); - /* If nfd begins before any invisible characters in the prompt, - adjust _rl_last_c_pos to account for wrap_offset and set - cpos_adjusted to let the caller know. */ - if (current_line == 0 && wrap_offset && ((nfd - new) <= prompt_last_invisible)) - { - _rl_last_c_pos -= wrap_offset; - cpos_adjusted = 1; - } - return; - } - /* Sometimes it is cheaper to print the characters rather than - use the terminal's capabilities. If we're growing the number - of lines, make sure we actually cause the new line to wrap - around on auto-wrapping terminals. */ - else if (_rl_terminal_can_insert && ((2 * col_temp) >= col_lendiff || _rl_term_IC) && (!_rl_term_autowrap || !gl)) - { - /* If lendiff > prompt_visible_length and _rl_last_c_pos == 0 and - _rl_horizontal_scroll_mode == 1, inserting the characters with - _rl_term_IC or _rl_term_ic will screw up the screen because of the - invisible characters. We need to just draw them. */ - /* The same thing happens if we're trying to draw before the last - invisible character in the prompt string or we're increasing the - number of invisible characters in the line and we're not drawing - the entire prompt string. */ - if (*ols && ((_rl_horizontal_scroll_mode && - _rl_last_c_pos == 0 && - lendiff > prompt_visible_length && - current_invis_chars > 0) == 0) && - (((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && - current_line == 0 && wrap_offset && - ((nfd - new) <= prompt_last_invisible) && - (col_lendiff < prompt_visible_length)) == 0) && - (visible_wrap_offset >= current_invis_chars)) - { - insert_some_chars (nfd, lendiff, col_lendiff); - _rl_last_c_pos += col_lendiff; - } -#if 0 /* XXX - for now */ - else if ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && _rl_last_c_pos == 0 && wrap_offset && (nfd-new) <= prompt_last_invisible && col_lendiff < prompt_visible_length && visible_wrap_offset >= current_invis_chars) - { - _rl_output_some_chars (nfd, lendiff); - _rl_last_c_pos += col_lendiff; - } -#endif - 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. */ - /* However, this screws up the rest of this block, which - assumes you've done the insert because you can. */ - _rl_output_some_chars (nfd, lendiff); - _rl_last_c_pos += col_lendiff; - } - else - { - _rl_output_some_chars (nfd, temp); - _rl_last_c_pos += col_temp; - /* If nfd begins before the last invisible character in the - prompt, adjust _rl_last_c_pos to account for wrap_offset - and set cpos_adjusted to let the caller know. */ - if ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && current_line == 0 && wrap_offset && ((nfd - new) <= prompt_last_invisible)) - { - _rl_last_c_pos -= wrap_offset; - cpos_adjusted = 1; - } - return; - } - /* Copy (new) chars to screen from first diff to last match. */ - temp = nls - nfd; - if ((temp - lendiff) > 0) - { - _rl_output_some_chars (nfd + lendiff, temp - lendiff); - /* XXX -- this bears closer inspection. Fixes a redisplay bug - reported against bash-3.0-alpha by Andreas Schwab involving - multibyte characters and prompt strings with invisible - characters, but was previously disabled. */ - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - twidth = _rl_col_width (nfd+lendiff, 0, temp-col_lendiff, 1); - else - twidth = temp - lendiff; - _rl_last_c_pos += twidth; - /* If nfd begins before the last invisible character in the - prompt, adjust _rl_last_c_pos to account for wrap_offset - and set cpos_adjusted to let the caller know. */ - if ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && current_line == 0 && wrap_offset && ((nfd - new) <= prompt_last_invisible)) - { - _rl_last_c_pos -= wrap_offset; - cpos_adjusted = 1; - } - } - } - else - { - /* 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. */ - if ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && - current_line == prompt_last_screen_line && wrap_offset && - wrap_offset != prompt_invis_chars_first_line && - ((nfd-new) < (prompt_last_invisible-(current_line*_rl_screenwidth)))) - { - _rl_last_c_pos -= wrap_offset - prompt_invis_chars_first_line; - cpos_adjusted = 1; - } - } - } - else /* Delete characters from line. */ - { - /* If possible and inexpensive to use terminal deletion, then do so. */ - if (_rl_term_dc && (2 * col_temp) >= -col_lendiff) - { - /* If all we're doing is erasing the invisible characters in the - prompt string, don't bother. It screws up the assumptions - about what's on the screen. */ - if (_rl_horizontal_scroll_mode && _rl_last_c_pos == 0 && - -lendiff == visible_wrap_offset) - col_lendiff = 0; - - if (col_lendiff) - delete_chars (-col_lendiff); /* delete (diff) characters */ - - /* Copy (new) chars to screen from first diff to last match */ - temp = nls - nfd; - if (temp > 0) - { - /* If nfd begins at the prompt, or before the invisible - characters in the prompt, we need to adjust _rl_last_c_pos - in a multibyte locale to account for the wrap offset and - set cpos_adjusted accordingly. */ - _rl_output_some_chars (nfd, temp); - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - _rl_last_c_pos += _rl_col_width (nfd, 0, temp, 1); - if (current_line == 0 && wrap_offset && ((nfd - new) <= prompt_last_invisible)) - { - _rl_last_c_pos -= wrap_offset; - cpos_adjusted = 1; - } - } - else - _rl_last_c_pos += temp; - } - } - /* Otherwise, print over the existing material. */ - else - { - if (temp > 0) - { - /* If nfd begins at the prompt, or before the invisible - characters in the prompt, we need to adjust _rl_last_c_pos - in a multibyte locale to account for the wrap offset and - set cpos_adjusted accordingly. */ - _rl_output_some_chars (nfd, temp); - _rl_last_c_pos += col_temp; /* XXX */ - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - if (current_line == 0 && wrap_offset && ((nfd - new) <= prompt_last_invisible)) - { - _rl_last_c_pos -= wrap_offset; - cpos_adjusted = 1; - } - } - } - lendiff = (oe - old) - (ne - new); - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - col_lendiff = _rl_col_width (old, 0, oe - old, 1) - _rl_col_width (new, 0, ne - new, 1); - else - col_lendiff = lendiff; - -#if 0 - if (col_lendiff) -#else - /* If we've already printed over the entire width of the screen, - including the old material, then col_lendiff doesn't matter and - space_to_eol will insert too many spaces. XXX - maybe we should - adjust col_lendiff based on the difference between _rl_last_c_pos - and _rl_screenwidth */ - if (col_lendiff && ((MB_CUR_MAX == 1 || rl_byte_oriented) || (_rl_last_c_pos < _rl_screenwidth))) -#endif - { - if (_rl_term_autowrap && current_line < inv_botlin) - space_to_eol (col_lendiff); - else - _rl_clear_to_eol (col_lendiff); - } - } - } -} - -/* Tell the update routines that we have moved onto a new (empty) line. */ -int -rl_on_new_line () -{ - if (visible_line) - visible_line[0] = '\0'; - - _rl_last_c_pos = _rl_last_v_pos = 0; - _rl_vis_botlin = last_lmargin = 0; - if (vis_lbreaks) - vis_lbreaks[0] = vis_lbreaks[1] = 0; - visible_wrap_offset = 0; - return 0; -} - -/* Tell the update routines that we have moved onto a new line with the - prompt already displayed. Code originally from the version of readline - distributed with CLISP. rl_expand_prompt must have already been called - (explicitly or implicitly). This still doesn't work exactly right. */ -int -rl_on_new_line_with_prompt () -{ - int prompt_size, i, l, real_screenwidth, newlines; - char *prompt_last_line, *lprompt; - - /* Initialize visible_line and invisible_line to ensure that they can hold - the already-displayed prompt. */ - prompt_size = strlen (rl_prompt) + 1; - init_line_structures (prompt_size); - - /* Make sure the line structures hold the already-displayed prompt for - redisplay. */ - lprompt = local_prompt ? local_prompt : rl_prompt; - strcpy (visible_line, lprompt); - strcpy (invisible_line, lprompt); - - /* If the prompt contains newlines, take the last tail. */ - prompt_last_line = strrchr (rl_prompt, '\n'); - if (!prompt_last_line) - prompt_last_line = rl_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, 1); /* XXX */ - else - _rl_last_c_pos = l; - - /* Dissect prompt_last_line into screen lines. Note that here we have - to use the real screenwidth. Readline's notion of screenwidth might be - one less, see terminal.c. */ - real_screenwidth = _rl_screenwidth + (_rl_term_autowrap ? 0 : 1); - _rl_last_v_pos = l / real_screenwidth; - /* If the prompt length is a multiple of real_screenwidth, we don't know - whether the cursor is at the end of the last line, or already at the - beginning of the next line. Output a newline just to be safe. */ - if (l > 0 && (l % real_screenwidth) == 0) - _rl_output_some_chars ("\n", 1); - last_lmargin = 0; - - newlines = 0; i = 0; - while (i <= l) - { - _rl_vis_botlin = newlines; - vis_lbreaks[newlines++] = i; - i += real_screenwidth; - } - vis_lbreaks[newlines] = l; - visible_wrap_offset = 0; - - rl_display_prompt = rl_prompt; /* XXX - make sure it's set */ - - return 0; -} - -/* Actually update the display, period. */ -int -rl_forced_update_display () -{ - register char *temp; - - if (visible_line) - { - temp = visible_line; - while (*temp) - *temp++ = '\0'; - } - rl_on_new_line (); - forced_display++; - (*rl_redisplay_function) (); - return 0; -} - -/* 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 -_rl_move_cursor_relative (new, data) - int new; - const char *data; -{ - register int i; - int woff; /* number of invisible chars on current line */ - int cpos, dpos; /* current and desired cursor positions */ - int adjust; - - woff = WRAP_OFFSET (_rl_last_v_pos, wrap_offset); - cpos = _rl_last_c_pos; - - if (cpos == 0 && cpos == new) - return; - -#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. 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) - { - adjust = 1; - /* Try to short-circuit common cases and eliminate a bunch of multibyte - character function calls. */ - /* 1. prompt string */ - if (new == local_prompt_len && memcmp (data, local_prompt, new) == 0) - { - dpos = prompt_physical_chars; - cpos_adjusted = 1; - adjust = 0; - } - /* 2. prompt_string + line contents */ - else if (new > local_prompt_len && local_prompt && memcmp (data, local_prompt, local_prompt_len) == 0) - { - dpos = prompt_physical_chars + _rl_col_width (data, local_prompt_len, new, 1); - cpos_adjusted = 1; - adjust = 0; - } - else - dpos = _rl_col_width (data, 0, new, 1); - - /* Use NEW when comparing against the last invisible character in the - prompt string, since they're both buffer indices and DPOS is a - desired display position. */ - if (adjust && ((new > prompt_last_invisible) || /* XXX - don't use woff here */ - (prompt_physical_chars >= _rl_screenwidth && - _rl_last_v_pos == prompt_last_screen_line && - wrap_offset >= woff && dpos >= woff && - new > (prompt_last_invisible-(_rl_screenwidth*_rl_last_v_pos)-wrap_offset)))) - /* XXX last comparison might need to be >= */ - { - dpos -= woff; - /* Since this will be assigned to _rl_last_c_pos at the end (more - precisely, _rl_last_c_pos == dpos when this function returns), - let the caller know. */ - cpos_adjusted = 1; - } - } - 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. */ -#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 (dpos == 0 || CR_FASTER (dpos, _rl_last_c_pos) || - (_rl_term_autowrap && i == _rl_screenwidth)) - { -#if defined (__MSDOS__) - putc ('\r', rl_outstream); -#else - tputs (_rl_term_cr, 1, _rl_output_character_function); -#endif /* !__MSDOS__ */ - cpos = _rl_last_c_pos = 0; - } - - 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 - portion of the output buffer again. Which is cheaper? */ - - /* The above comment is left here for posterity. It is faster - to print one character (non-control) than to print a control - sequence telling the terminal to move forward one character. - That kind of control is for people who don't know what the - data is underneath the cursor. */ - - /* However, we need a handle on where the current display position is - in the buffer for the immediately preceding comment to be true. - In multibyte locales, we don't currently have that info available. - Without it, we don't know where the data we have to display begins - in the buffer and we have to go back to the beginning of the screen - line. In this case, we can use the terminal sequence to move forward - if it's available. */ - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - if (_rl_term_forward_char) - { - for (i = cpos; i < dpos; i++) - tputs (_rl_term_forward_char, 1, _rl_output_character_function); - } - else - { - tputs (_rl_term_cr, 1, _rl_output_character_function); - for (i = 0; i < new; i++) - putc (data[i], rl_outstream); - } - } - else - for (i = cpos; i < new; i++) - putc (data[i], rl_outstream); - } - -#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. */ -#endif - else if (cpos > dpos) - _rl_backspace (cpos - dpos); - - _rl_last_c_pos = dpos; -} - -/* PWP: move the cursor up or down. */ -void -_rl_move_vert (to) - int to; -{ - register int delta, i; - - if (_rl_last_v_pos == to || to > _rl_screenheight) - return; - - if ((delta = to - _rl_last_v_pos) > 0) - { - for (i = 0; i < delta; i++) - putc ('\n', rl_outstream); -#if defined (__MSDOS__) - putc ('\r', rl_outstream); -#else - tputs (_rl_term_cr, 1, _rl_output_character_function); -#endif - _rl_last_c_pos = 0; - } - else - { /* delta < 0 */ -#ifdef __DJGPP__ - int row, col; - - fflush (rl_outstream); - ScreenGetCursor (&row, &col); - ScreenSetCursor (row + delta, col); - i = -delta; -#else - if (_rl_term_up && *_rl_term_up) - for (i = 0; i < -delta; i++) - tputs (_rl_term_up, 1, _rl_output_character_function); -#endif /* !__DJGPP__ */ - } - - _rl_last_v_pos = to; /* Now TO is here */ -} - -/* Physically print C on rl_outstream. This is for functions which know - how to optimize the display. Return the number of characters output. */ -int -rl_show_char (c) - int c; -{ - int n = 1; - if (META_CHAR (c) && (_rl_output_meta_chars == 0)) - { - fprintf (rl_outstream, "M-"); - n += 2; - c = UNMETA (c); - } - -#if defined (DISPLAY_TABS) - if ((CTRL_CHAR (c) && c != '\t') || c == RUBOUT) -#else - if (CTRL_CHAR (c) || c == RUBOUT) -#endif /* !DISPLAY_TABS */ - { - fprintf (rl_outstream, "C-"); - n += 2; - c = CTRL_CHAR (c) ? UNCTRL (c) : '?'; - } - - putc (c, rl_outstream); - fflush (rl_outstream); - return n; -} - -int -rl_character_len (c, pos) - register int c, pos; -{ - unsigned char uc; - - uc = (unsigned char)c; - - if (META_CHAR (uc)) - return ((_rl_output_meta_chars == 0) ? 4 : 1); - - if (uc == '\t') - { -#if defined (DISPLAY_TABS) - return (((pos | 7) + 1) - pos); -#else - return (2); -#endif /* !DISPLAY_TABS */ - } - - if (CTRL_CHAR (c) || c == RUBOUT) - return (2); - - 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 -#if defined (PREFER_STDARG) -rl_message (const char *format, ...) -#else -rl_message (va_alist) - va_dcl -#endif -{ - va_list args; -#if defined (PREFER_VARARGS) - char *format; -#endif -#if defined (HAVE_VSNPRINTF) - int bneed; -#endif - -#if defined (PREFER_STDARG) - va_start (args, format); -#else - va_start (args); - format = va_arg (args, char *); -#endif - - if (msg_buf == 0) - msg_buf = xmalloc (msg_bufsiz = 128); - -#if defined (HAVE_VSNPRINTF) - bneed = vsnprintf (msg_buf, msg_bufsiz - 1, format, args); - if (bneed >= msg_bufsiz - 1) - { - msg_bufsiz = bneed + 1; - msg_buf = xrealloc (msg_buf, msg_bufsiz); - va_end (args); - -#if defined (PREFER_STDARG) - va_start (args, format); -#else - va_start (args); - format = va_arg (args, char *); -#endif - vsnprintf (msg_buf, msg_bufsiz - 1, format, args); - } -#else - vsprintf (msg_buf, format, args); - msg_buf[msg_bufsiz - 1] = '\0'; /* overflow? */ -#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; - local_prompt_len = local_prompt ? strlen (local_prompt) : 0; - (*rl_redisplay_function) (); - - return 0; -} -#else /* !USE_VARARGS */ -int -rl_message (format, arg1, arg2) - char *format; -{ - if (msg_buf == 0) - msg_buf = xmalloc (msg_bufsiz = 128); - - sprintf (msg_buf, format, arg1, arg2); - msg_buf[msg_bufsiz - 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; - local_prompt_len = local_prompt ? strlen (local_prompt) : 0; - (*rl_redisplay_function) (); - - return 0; -} -#endif /* !USE_VARARGS */ - -/* How to clear things from the "echo-area". */ -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; -} - -int -rl_reset_line_state () -{ - rl_on_new_line (); - - rl_display_prompt = rl_prompt ? rl_prompt : ""; - forced_display = 1; - return 0; -} - -void -rl_save_prompt () -{ - saved_local_prompt = local_prompt; - saved_local_prefix = local_prompt_prefix; - saved_prefix_length = prompt_prefix_length; - saved_local_length = local_prompt_len; - 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; - local_prompt_len = 0; - prompt_last_invisible = prompt_visible_length = prompt_prefix_length = 0; - prompt_invis_chars_first_line = prompt_physical_chars = 0; -} - -void -rl_restore_prompt () -{ - FREE (local_prompt); - FREE (local_prompt_prefix); - - local_prompt = saved_local_prompt; - local_prompt_prefix = saved_local_prefix; - local_prompt_len = saved_local_length; - 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_local_length = 0; - saved_last_invisible = saved_visible_length = saved_prefix_length = 0; - saved_invis_chars_first_line = saved_physical_chars = 0; -} - -char * -_rl_make_prompt_for_search (pchar) - int pchar; -{ - int len; - char *pmt, *p; - - rl_save_prompt (); - - /* We've saved the prompt, and can do anything with the various prompt - strings we need before they're restored. We want the unexpanded - portion of the prompt string after any final newline. */ - p = rl_prompt ? strrchr (rl_prompt, '\n') : 0; - if (p == 0) - { - len = (rl_prompt && *rl_prompt) ? strlen (rl_prompt) : 0; - pmt = (char *)xmalloc (len + 2); - if (len) - strcpy (pmt, rl_prompt); - pmt[len] = pchar; - pmt[len+1] = '\0'; - } - else - { - p++; - len = strlen (p); - pmt = (char *)xmalloc (len + 2); - if (len) - strcpy (pmt, p); - pmt[len] = pchar; - pmt[len+1] = '\0'; - } - - /* will be overwritten by expand_prompt, called from rl_message */ - prompt_physical_chars = saved_physical_chars + 1; - return pmt; -} - -/* Quick redisplay hack when erasing characters at the end of the line. */ -void -_rl_erase_at_end_of_line (l) - int l; -{ - register int i; - - _rl_backspace (l); - for (i = 0; i < l; i++) - putc (' ', rl_outstream); - _rl_backspace (l); - for (i = 0; i < l; i++) - visible_line[--_rl_last_c_pos] = '\0'; - rl_display_fixed++; -} - -/* Clear to the end of the line. COUNT is the minimum - number of character spaces to clear, */ -void -_rl_clear_to_eol (count) - int count; -{ -#ifndef __MSDOS__ - if (_rl_term_clreol) - tputs (_rl_term_clreol, 1, _rl_output_character_function); - else -#endif - if (count) - space_to_eol (count); -} - -/* Clear to the end of the line using spaces. COUNT is the minimum - number of character spaces to clear, */ -static void -space_to_eol (count) - int count; -{ - register int i; - - for (i = 0; i < count; i++) - putc (' ', rl_outstream); - - _rl_last_c_pos += count; -} - -void -_rl_clear_screen () -{ -#ifndef __DJGPP__ - if (_rl_term_clrpag) - tputs (_rl_term_clrpag, 1, _rl_output_character_function); - else - rl_crlf (); -#else - ScreenClear (); - ScreenSetCursor (0, 0); -#endif /* __DJGPP__ */ -} - -/* Insert COUNT characters from STRING to the output stream at column COL. */ -static void -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) - _rl_ttymsg ("debug: insert_some_chars: count (%d) != col (%d)", count, col); - - /* If IC is defined, then we do not have to "enter" insert mode. */ - if (_rl_term_IC) - { - char *buffer; - - buffer = tgoto (_rl_term_IC, 0, col); - tputs (buffer, 1, _rl_output_character_function); - _rl_output_some_chars (string, count); - } - else - { - register int i; - - /* If we have to turn on insert-mode, then do so. */ - if (_rl_term_im && *_rl_term_im) - tputs (_rl_term_im, 1, _rl_output_character_function); - - /* If there is a special command for inserting characters, then - use that first to open up the space. */ - if (_rl_term_ic && *_rl_term_ic) - { - for (i = col; i--; ) - tputs (_rl_term_ic, 1, _rl_output_character_function); - } - - /* Print the text. */ - _rl_output_some_chars (string, count); - - /* If there is a string to turn off insert mode, we had best use - it now. */ - 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. */ -static void -delete_chars (count) - int count; -{ - if (count > _rl_screenwidth) /* XXX */ - return; - -#if !defined (__MSDOS__) && !defined (__MINGW32__) - if (_rl_term_DC && *_rl_term_DC) - { - char *buffer; - buffer = tgoto (_rl_term_DC, count, count); - tputs (buffer, count, _rl_output_character_function); - } - else - { - if (_rl_term_dc && *_rl_term_dc) - while (count--) - tputs (_rl_term_dc, 1, _rl_output_character_function); - } -#endif /* !__MSDOS__ && !__MINGW32__ */ -} - -void -_rl_update_final () -{ - int full_lines; - - full_lines = 0; - /* If the cursor is the only thing on an otherwise-blank last line, - compensate so we don't print an extra CRLF. */ - if (_rl_vis_botlin && _rl_last_c_pos == 0 && - visible_line[vis_lbreaks[_rl_vis_botlin]] == 0) - { - _rl_vis_botlin--; - full_lines = 1; - } - _rl_move_vert (_rl_vis_botlin); - /* If we've wrapped lines, remove the final xterm line-wrap flag. */ - if (full_lines && _rl_term_autowrap && (VIS_LLEN(_rl_vis_botlin) == _rl_screenwidth)) - { - char *last_line; - - last_line = &visible_line[vis_lbreaks[_rl_vis_botlin]]; - cpos_buffer_position = -1; /* don't know where we are in buffer */ - _rl_move_cursor_relative (_rl_screenwidth - 1, last_line); /* XXX */ - _rl_clear_to_eol (0); - putc (last_line[_rl_screenwidth - 1], rl_outstream); - } - _rl_vis_botlin = 0; - rl_crlf (); - fflush (rl_outstream); - rl_display_fixed++; -} - -/* Move to the start of the current line. */ -static void -cr () -{ - if (_rl_term_cr) - { -#if defined (__MSDOS__) - putc ('\r', rl_outstream); -#else - tputs (_rl_term_cr, 1, _rl_output_character_function); -#endif - _rl_last_c_pos = 0; - } -} - -/* Redraw the last line of a multi-line prompt that may possibly contain - terminal escape sequences. Called with the cursor at column 0 of the - line to draw the prompt on. */ -static void -redraw_prompt (t) - char *t; -{ - char *oldp; - - oldp = rl_display_prompt; - rl_save_prompt (); - - rl_display_prompt = t; - local_prompt = expand_prompt (t, &prompt_visible_length, - &prompt_last_invisible, - &prompt_invis_chars_first_line, - &prompt_physical_chars); - local_prompt_prefix = (char *)NULL; - local_prompt_len = local_prompt ? strlen (local_prompt) : 0; - - rl_forced_update_display (); - - rl_display_prompt = oldp; - rl_restore_prompt(); -} - -/* Redisplay the current line after a SIGWINCH is received. */ -void -_rl_redisplay_after_sigwinch () -{ - char *t; - - /* Clear the last line (assuming that the screen size change will result in - either more or fewer characters on that line only) and put the cursor at - column 0. Make sure the right thing happens if we have wrapped to a new - screen line. */ - if (_rl_term_cr) - { - _rl_move_vert (_rl_vis_botlin); - -#if defined (__MSDOS__) - putc ('\r', rl_outstream); -#else - tputs (_rl_term_cr, 1, _rl_output_character_function); -#endif - _rl_last_c_pos = 0; -#if defined (__MSDOS__) - space_to_eol (_rl_screenwidth); - putc ('\r', rl_outstream); -#else - if (_rl_term_clreol) - tputs (_rl_term_clreol, 1, _rl_output_character_function); - else - { - space_to_eol (_rl_screenwidth); - tputs (_rl_term_cr, 1, _rl_output_character_function); - } -#endif - if (_rl_last_v_pos > 0) - _rl_move_vert (0); - } - else - rl_crlf (); - - /* Redraw only the last line of a multi-line prompt. */ - t = strrchr (rl_display_prompt, '\n'); - if (t) - redraw_prompt (++t); - else - rl_forced_update_display (); -} - -void -_rl_clean_up_for_exit () -{ - if (_rl_echoing_p) - { - _rl_move_vert (_rl_vis_botlin); - _rl_vis_botlin = 0; - fflush (rl_outstream); - rl_restart_output (1, 0); - } -} - -void -_rl_erase_entire_line () -{ - cr (); - _rl_clear_to_eol (0); - cr (); - fflush (rl_outstream); -} - -/* return the `current display line' of the cursor -- the number of lines to - move up to get to the first screen line of the current readline line. */ -int -_rl_current_display_line () -{ - int ret, nleft; - - /* Find out whether or not there might be invisible characters in the - editing buffer. */ - if (rl_display_prompt == rl_prompt) - nleft = _rl_last_c_pos - _rl_screenwidth - rl_visible_prompt_length; - else - nleft = _rl_last_c_pos - _rl_screenwidth; - - if (nleft > 0) - ret = 1 + nleft / _rl_screenwidth; - else - ret = 0; - - return ret; -} - -#if defined (HANDLE_MULTIBYTE) -/* Calculate the number of screen columns occupied by STR from START to END. - In the case of multibyte characters with stateful encoding, we have to - scan from the beginning of the string to take the state into account. */ -static int -_rl_col_width (str, start, end, flags) - const char *str; - int start, end, flags; -{ - wchar_t wc; - mbstate_t ps; - int tmp, point, width, max; - - if (end <= start) - return 0; - if (MB_CUR_MAX == 1 || rl_byte_oriented) -{ -_rl_ttymsg ("_rl_col_width: called with MB_CUR_MAX == 1"); - return (end - start); -} - - memset (&ps, 0, sizeof (mbstate_t)); - - point = 0; - max = end; - - /* Try to short-circuit common cases. The adjustment to remove wrap_offset - is done by the caller. */ - /* 1. prompt string */ - if (flags && start == 0 && end == local_prompt_len && memcmp (str, local_prompt, local_prompt_len) == 0) - return (prompt_physical_chars + wrap_offset); - /* 2. prompt string + line contents */ - else if (flags && start == 0 && local_prompt_len > 0 && end > local_prompt_len && local_prompt && memcmp (str, local_prompt, local_prompt_len) == 0) - { - tmp = prompt_physical_chars + wrap_offset; - /* XXX - try to call ourselves recursively with non-prompt portion */ - tmp += _rl_col_width (str, local_prompt_len, end, flags); - return (tmp); - } - - while (point < start) - { - tmp = mbrlen (str + point, max, &ps); - if (MB_INVALIDCH ((size_t)tmp)) - { - /* In this case, the bytes are invalid or too short to compose a - multibyte character, so we assume that the first byte represents - a single character. */ - point++; - max--; - - /* Clear the state of the byte sequence, because in this case the - effect of mbstate is undefined. */ - memset (&ps, 0, sizeof (mbstate_t)); - } - else if (MB_NULLWCH (tmp)) - break; /* Found '\0' */ - else - { - point += tmp; - max -= tmp; - } - } - - /* If START is not a byte that starts a character, then POINT will be - greater than START. In this case, assume that (POINT - START) gives - a byte count that is the number of columns of difference. */ - width = point - start; - - while (point < end) - { - tmp = mbrtowc (&wc, str + point, max, &ps); - if (MB_INVALIDCH ((size_t)tmp)) - { - /* In this case, the bytes are invalid or too short to compose a - multibyte character, so we assume that the first byte represents - a single character. */ - point++; - max--; - - /* and assume that the byte occupies a single column. */ - width++; - - /* Clear the state of the byte sequence, because in this case the - effect of mbstate is undefined. */ - memset (&ps, 0, sizeof (mbstate_t)); - } - else if (MB_NULLWCH (tmp)) - break; /* Found '\0' */ - else - { - point += tmp; - max -= tmp; -#if defined (MACOSX) - if (wc >= 769 && wc <= 833) - tmp = 0; - else -#endif - tmp = wcwidth(wc); - width += (tmp >= 0) ? tmp : 1; - } - } - - width += point - end; - - return width; -} -#endif /* HANDLE_MULTIBYTE */ diff --git a/lib/readline/doc/Makefile.old b/lib/readline/doc/Makefile.old deleted file mode 100644 index 58d4dd76..00000000 --- a/lib/readline/doc/Makefile.old +++ /dev/null @@ -1,76 +0,0 @@ -# This makefile for Readline library documentation is in -*- text -*- mode. -# Emacs likes it that way. -RM = rm -f - -MAKEINFO = makeinfo -TEXI2DVI = texi2dvi -TEXI2HTML = texi2html -QUIETPS = #set this to -q to shut up dvips -DVIPS = dvips -D 300 $(QUIETPS) -o $@ # tricky - -INSTALL_DATA = cp -infodir = /usr/local/info - -RLSRC = rlman.texinfo rluser.texinfo rltech.texinfo -HISTSRC = hist.texinfo hsuser.texinfo hstech.texinfo - -DVIOBJ = readline.dvi history.dvi -INFOOBJ = readline.info history.info -PSOBJ = readline.ps history.ps -HTMLOBJ = readline.html history.html - -all: info dvi html ps -nodvi: info html - -readline.dvi: $(RLSRC) - $(TEXI2DVI) rlman.texinfo - mv rlman.dvi readline.dvi - -readline.info: $(RLSRC) - $(MAKEINFO) --no-split -o $@ rlman.texinfo - -history.dvi: ${HISTSRC} - $(TEXI2DVI) hist.texinfo - mv hist.dvi history.dvi - -history.info: ${HISTSRC} - $(MAKEINFO) --no-split -o $@ hist.texinfo - -readline.ps: readline.dvi - $(RM) $@ - $(DVIPS) readline.dvi - -history.ps: history.dvi - $(RM) $@ - $(DVIPS) history.dvi - -readline.html: ${RLSRC} - $(TEXI2HTML) rlman.texinfo - sed -e 's:rlman.html:readline.html:' -e 's:rlman_toc.html:readline_toc.html:' rlman.html > readline.html - sed -e 's:rlman.html:readline.html:' -e 's:rlman_toc.html:readline_toc.html:' rlman_toc.html > readline_toc.html - $(RM) rlman.html rlman_toc.html - -history.html: ${HISTSRC} - $(TEXI2HTML) hist.texinfo - sed -e 's:hist.html:history.html:' -e 's:hist_toc.html:history_toc.html:' hist.html > history.html - sed -e 's:hist.html:history.html:' -e 's:hist_toc.html:history_toc.html:' hist_toc.html > history_toc.html - $(RM) hist.html hist_toc.html - -info: $(INFOOBJ) -dvi: $(DVIOBJ) -ps: $(PSOBJ) -html: $(HTMLOBJ) - -clean: - $(RM) *.aux *.cp *.fn *.ky *.log *.pg *.toc *.tp *.vr *.cps *.pgs \ - *.fns *.kys *.tps *.vrs *.o core - -distclean: clean -mostlyclean: clean - -maintainer-clean: clean - $(RM) *.dvi *.info *.info-* *.ps *.html - -install: info - ${INSTALL_DATA} readline.info $(infodir)/readline.info - ${INSTALL_DATA} history.info $(infodir)/history.info diff --git a/lib/readline/doc/readline.3~ b/lib/readline/doc/readline.3~ deleted file mode 100644 index f79f4bbe..00000000 --- a/lib/readline/doc/readline.3~ +++ /dev/null @@ -1,1381 +0,0 @@ -.\" -.\" MAN PAGE COMMENTS to -.\" -.\" Chet Ramey -.\" Information Network Services -.\" Case Western Reserve University -.\" chet@ins.CWRU.Edu -.\" -.\" Last Change: Sat Aug 28 18:56:32 EDT 2010 -.\" -.TH READLINE 3 "2010 August 28" "GNU Readline 6.2" -.\" -.\" File Name macro. This used to be `.PN', for Path Name, -.\" but Sun doesn't seem to like that very much. -.\" -.de FN -\fI\|\\$1\|\fP -.. -.SH NAME -readline \- get a line from a user with editing -.SH SYNOPSIS -.LP -.nf -.ft B -#include <stdio.h> -#include <readline/readline.h> -#include <readline/history.h> -.ft -.fi -.LP -.nf -\fIchar *\fP -.br -\fBreadline\fP (\fIconst char *prompt\fP); -.fi -.SH COPYRIGHT -.if n Readline is Copyright (C) 1989\-2011 Free Software Foundation, Inc. -.if t Readline is Copyright \(co 1989\-2011 Free Software Foundation, Inc. -.SH DESCRIPTION -.LP -.B readline -will read a line from the terminal -and return it, using -.B prompt -as a prompt. If -.B prompt -is \fBNULL\fP or the empty string, no prompt is issued. -The line returned is allocated with -.IR malloc (3); -the caller must free it when finished. The line returned -has the final newline removed, so only the text of the line -remains. -.LP -.B readline -offers editing capabilities while the user is entering the -line. -By default, the line editing commands -are similar to those of emacs. -A vi\-style line editing interface is also available. -.LP -This manual page describes only the most basic use of \fBreadline\fP. -Much more functionality is available; see -\fIThe GNU Readline Library\fP and \fIThe GNU History Library\fP -for additional information. -.SH RETURN VALUE -.LP -.B readline -returns the text of the line read. A blank line -returns the empty string. If -.B EOF -is encountered while reading a line, and the line is empty, -.B NULL -is returned. If an -.B EOF -is read with a non\-empty line, it is -treated as a newline. -.SH NOTATION -.LP -An Emacs-style notation is used to denote -keystrokes. Control keys are denoted by C\-\fIkey\fR, e.g., C\-n -means Control\-N. Similarly, -.I meta -keys are denoted by M\-\fIkey\fR, so M\-x means Meta\-X. (On keyboards -without a -.I meta -key, M\-\fIx\fP means ESC \fIx\fP, i.e., press the Escape key -then the -.I x -key. This makes ESC the \fImeta prefix\fP. -The combination M\-C\-\fIx\fP means ESC\-Control\-\fIx\fP, -or press the Escape key -then hold the Control key while pressing the -.I x -key.) -.PP -Readline commands may be given numeric -.IR arguments , -which normally act as a repeat count. Sometimes, however, it is the -sign of the argument that is significant. Passing a negative argument -to a command that acts in the forward direction (e.g., \fBkill\-line\fP) -causes that command to act in a backward direction. Commands whose -behavior with arguments deviates from this are noted. -.PP -When a command is described as \fIkilling\fP text, the text -deleted is saved for possible future retrieval -(\fIyanking\fP). The killed text is saved in a -\fIkill ring\fP. Consecutive kills cause the text to be -accumulated into one unit, which can be yanked all at once. -Commands which do not kill text separate the chunks of text -on the kill ring. -.SH INITIALIZATION FILE -.LP -Readline is customized by putting commands in an initialization -file (the \fIinputrc\fP file). -The name of this file is taken from the value of the -.B INPUTRC -environment variable. If that variable is unset, the default is -.IR ~/.inputrc . -If that file does not exist or cannot be read, the ultimate default is -.IR /etc/inputrc . -When a program which uses the readline library starts up, the -init file is read, and the key bindings and variables are set. -There are only a few basic constructs allowed in the -readline init file. Blank lines are ignored. -Lines beginning with a \fB#\fP are comments. -Lines beginning with a \fB$\fP indicate conditional constructs. -Other lines denote key bindings and variable settings. -Each program using this library may add its own commands -and bindings. -.PP -For example, placing -.RS -.PP -M\-Control\-u: universal\-argument -.RE -or -.RS -C\-Meta\-u: universal\-argument -.RE -.sp -into the -.I inputrc -would make M\-C\-u execute the readline command -.IR universal\-argument . -.PP -The following symbolic character names are recognized while -processing key bindings: -.IR DEL , -.IR ESC , -.IR ESCAPE , -.IR LFD , -.IR NEWLINE , -.IR RET , -.IR RETURN , -.IR RUBOUT , -.IR SPACE , -.IR SPC , -and -.IR TAB . -.PP -In addition to command names, readline allows keys to be bound -to a string that is inserted when the key is pressed (a \fImacro\fP). -.PP -.SS Key Bindings -.PP -The syntax for controlling key bindings in the -.I inputrc -file is simple. All that is required is the name of the -command or the text of a macro and a key sequence to which -it should be bound. The name may be specified in one of two ways: -as a symbolic key name, possibly with \fIMeta\-\fP or \fIControl\-\fP -prefixes, or as a key sequence. -The name and key sequence are separated by a colon. There can be no -whitespace between the name and the colon. -.PP -When using the form \fBkeyname\fP:\^\fIfunction-name\fP or \fImacro\fP, -.I keyname -is the name of a key spelled out in English. For example: -.sp -.RS -Control\-u: universal\-argument -.br -Meta\-Rubout: backward\-kill\-word -.br -Control\-o: "> output" -.RE -.LP -In the above example, -.I C\-u -is bound to the function -.BR universal\-argument , -.I M-DEL -is bound to the function -.BR backward\-kill\-word , -and -.I C\-o -is bound to run the macro -expressed on the right hand side (that is, to insert the text -.if t \f(CW> output\fP -.if n ``> output'' -into the line). -.PP -In the second form, \fB"keyseq"\fP:\^\fIfunction\-name\fP or \fImacro\fP, -.B keyseq -differs from -.B keyname -above in that strings denoting -an entire key sequence may be specified by placing the sequence -within double quotes. Some GNU Emacs style key escapes can be -used, as in the following example, but the symbolic character names -are not recognized. -.sp -.RS -"\eC\-u": universal\-argument -.br -"\eC\-x\eC\-r": re\-read\-init\-file -.br -"\ee[11~": "Function Key 1" -.RE -.PP -In this example, -.I C-u -is again bound to the function -.BR universal\-argument . -.I "C-x C-r" -is bound to the function -.BR re\-read\-init\-file , -and -.I "ESC [ 1 1 ~" -is bound to insert the text -.if t \f(CWFunction Key 1\fP. -.if n ``Function Key 1''. -.PP -The full set of GNU Emacs style escape sequences available when specifying -key sequences is -.RS -.PD 0 -.TP -.B \eC\- -control prefix -.TP -.B \eM\- -meta prefix -.TP -.B \ee -an escape character -.TP -.B \e\e -backslash -.TP -.B \e" -literal ", a double quote -.TP -.B \e' -literal ', a single quote -.RE -.PD -.PP -In addition to the GNU Emacs style escape sequences, a second -set of backslash escapes is available: -.RS -.PD 0 -.TP -.B \ea -alert (bell) -.TP -.B \eb -backspace -.TP -.B \ed -delete -.TP -.B \ef -form feed -.TP -.B \en -newline -.TP -.B \er -carriage return -.TP -.B \et -horizontal tab -.TP -.B \ev -vertical tab -.TP -.B \e\fInnn\fP -the eight-bit character whose value is the octal value \fInnn\fP -(one to three digits) -.TP -.B \ex\fIHH\fP -the eight-bit character whose value is the hexadecimal value \fIHH\fP -(one or two hex digits) -.RE -.PD -.PP -When entering the text of a macro, single or double quotes should -be used to indicate a macro definition. Unquoted text -is assumed to be a function name. -In the macro body, the backslash escapes described above are expanded. -Backslash will quote any other character in the macro text, -including " and '. -.PP -.B Bash -allows the current readline key bindings to be displayed or modified -with the -.B bind -builtin command. The editing mode may be switched during interactive -use by using the -.B \-o -option to the -.B set -builtin command. Other programs using this library provide -similar mechanisms. The -.I inputrc -file may be edited and re-read if a program does not provide -any other means to incorporate new bindings. -.SS Variables -.PP -Readline has variables that can be used to further customize its -behavior. A variable may be set in the -.I inputrc -file with a statement of the form -.RS -.PP -\fBset\fP \fIvariable\-name\fP \fIvalue\fP -.RE -.PP -Except where noted, readline variables can take the values -.B On -or -.B Off -(without regard to case). -Unrecognized variable names are ignored. -When a variable value is read, empty or null values, "on" (case-insensitive), -and "1" are equivalent to \fBOn\fP. All other values are equivalent to -\fBOff\fP. -The variables and their default values are: -.PP -.PD 0 -.TP -.B bell\-style (audible) -Controls what happens when readline wants to ring the terminal bell. -If set to \fBnone\fP, readline never rings the bell. If set to -\fBvisible\fP, readline uses a visible bell if one is available. -If set to \fBaudible\fP, readline attempts to ring the terminal's bell. -.TP -.B bind\-tty\-special\-chars (On) -If set to \fBOn\fP, readline attempts to bind the control characters -treated specially by the kernel's terminal driver to their readline -equivalents. -.TP -.B comment\-begin (``#'') -The string that is inserted in \fBvi\fP mode when the -.B insert\-comment -command is executed. -This command is bound to -.B M\-# -in emacs mode and to -.B # -in vi command mode. -.TP -.B completion\-display\-width (-1) -The number of screen columns used to display possible matches -when performing completion. -The value is ignored if it is less than 0 or greater than the terminal -screen width. -A value of 0 will cause matches to be displayed one per line. -The default value is -1. -.TP -.B completion\-ignore\-case (Off) -If set to \fBOn\fP, readline performs filename matching and completion -in a case\-insensitive fashion. -.TP -.B completion\-map\-case (Off) -If set to \fBOn\fP, and \fBcompletion\-ignore\-case\fP is enabled, readline -treats hyphens (\fI\-\fP) and underscores (\fI_\fP) as equivalent when -performing case\-insensitive filename matching and completion. -.TP -.B completion\-prefix\-display\-length (0) -The length in characters of the common prefix of a list of possible -completions that is displayed without modification. When set to a -value greater than zero, common prefixes longer than this value are -replaced with an ellipsis when displaying possible completions. -.TP -.B completion\-query\-items (100) -This determines when the user is queried about viewing -the number of possible completions -generated by the \fBpossible\-completions\fP command. -It may be set to any integer value greater than or equal to -zero. If the number of possible completions is greater than -or equal to the value of this variable, the user is asked whether -or not he wishes to view them; otherwise they are simply listed -on the terminal. A negative value causes readline to never ask. -.TP -.B convert\-meta (On) -If set to \fBOn\fP, readline will convert characters with the -eighth bit set to an ASCII key sequence -by stripping the eighth bit and prefixing it with an -escape character (in effect, using escape as the \fImeta prefix\fP). -.TP -.B disable\-completion (Off) -If set to \fBOn\fP, readline will inhibit word completion. Completion -characters will be inserted into the line as if they had been -mapped to \fBself-insert\fP. -.TP -.B editing\-mode (emacs) -Controls whether readline begins with a set of key bindings similar -to \fIEmacs\fP or \fIvi\fP. -.B editing\-mode -can be set to either -.B emacs -or -.BR vi . -.TP -.B echo\-control\-characters (On) -When set to \fBOn\fP, on operating systems that indicate they support it, -readline echoes a character corresponding to a signal generated from the -keyboard. -.TP -.B enable\-keypad (Off) -When set to \fBOn\fP, readline will try to enable the application -keypad when it is called. Some systems need this to enable the -arrow keys. -.TP -.B enable\-meta\-key (On) -When set to \fBOn\fP, readline will try to enable any meta modifier -key the terminal claims to support when it is called. On many terminals, -the meta key is used to send eight-bit characters. -.TP -.B expand\-tilde (Off) -If set to \fBOn\fP, tilde expansion is performed when readline -attempts word completion. -.TP -.B history\-preserve\-point (Off) -If set to \fBOn\fP, the history code attempts to place point at the -same location on each history line retrieved with \fBprevious-history\fP -or \fBnext-history\fP. -.TP -.B history\-size (0) -Set the maximum number of history entries saved in the history list. If -set to zero, the number of entries in the history list is not limited. -.TP -.B horizontal\-scroll\-mode (Off) -When set to \fBOn\fP, makes readline use a single line for display, -scrolling the input horizontally on a single screen line when it -becomes longer than the screen width rather than wrapping to a new line. -.TP -.B input\-meta (Off) -If set to \fBOn\fP, readline will enable eight-bit input (that is, -it will not clear the eighth bit in the characters it reads), -regardless of what the terminal claims it can support. The name -.B meta\-flag -is a synonym for this variable. -.TP -.B isearch\-terminators (``C\-[ C\-J'') -The string of characters that should terminate an incremental -search without subsequently executing the character as a command. -If this variable has not been given a value, the characters -\fIESC\fP and \fIC\-J\fP will terminate an incremental search. -.TP -.B keymap (emacs) -Set the current readline keymap. The set of legal keymap names is -\fIemacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move, -vi-command\fP, and -.IR vi-insert . -\fIvi\fP is equivalent to \fIvi-command\fP; \fIemacs\fP is -equivalent to \fIemacs-standard\fP. The default value is -.IR emacs . -The value of -.B editing\-mode -also affects the default keymap. -.TP -.B mark\-directories (On) -If set to \fBOn\fP, completed directory names have a slash -appended. -.TP -.B mark\-modified\-lines (Off) -If set to \fBOn\fP, history lines that have been modified are displayed -with a preceding asterisk (\fB*\fP). -.TP -.B mark\-symlinked\-directories (Off) -If set to \fBOn\fP, completed names which are symbolic links to directories -have a slash appended (subject to the value of -\fBmark\-directories\fP). -.TP -.B match\-hidden\-files (On) -This variable, when set to \fBOn\fP, causes readline to match files whose -names begin with a `.' (hidden files) when performing filename -completion. -If set to \fBOff\fP, the leading `.' must be -supplied by the user in the filename to be completed. -.TP -.B menu\-complete\-display\-prefix (Off) -If set to \fBOn\fP, menu completion displays the common prefix of the -list of possible completions (which may be empty) before cycling through -the list. -.TP -.B output\-meta (Off) -If set to \fBOn\fP, readline will display characters with the -eighth bit set directly rather than as a meta-prefixed escape -sequence. -.TP -.B page\-completions (On) -If set to \fBOn\fP, readline uses an internal \fImore\fP-like pager -to display a screenful of possible completions at a time. -.TP -.B print\-completions\-horizontally (Off) -If set to \fBOn\fP, readline will display completions with matches -sorted horizontally in alphabetical order, rather than down the screen. -.TP -.B revert\-all\-at\-newline (Off) -If set to \fBOn\fP, readline will undo all changes to history lines -before returning when \fBaccept\-line\fP is executed. By default, -history lines may be modified and retain individual undo lists across -calls to \fBreadline\fP. -.TP -.B show\-all\-if\-ambiguous (Off) -This alters the default behavior of the completion functions. If -set to -.BR On , -words which have more than one possible completion cause the -matches to be listed immediately instead of ringing the bell. -.TP -.B show\-all\-if\-unmodified (Off) -This alters the default behavior of the completion functions in -a fashion similar to \fBshow\-all\-if\-ambiguous\fP. -If set to -.BR On , -words which have more than one possible completion without any -possible partial completion (the possible completions don't share -a common prefix) cause the matches to be listed immediately instead -of ringing the bell. -.TP -.B skip\-completed\-text (Off) -If set to \fBOn\fP, this alters the default completion behavior when -inserting a single match into the line. It's only active when -performing completion in the middle of a word. If enabled, readline -does not insert characters from the completion that match characters -after point in the word being completed, so portions of the word -following the cursor are not duplicated. -.TP -.B visible\-stats (Off) -If set to \fBOn\fP, a character denoting a file's type as reported -by \fIstat\fP(2) is appended to the filename when listing possible -completions. -.PD -.SS Conditional Constructs -.PP -Readline implements a facility similar in spirit to the conditional -compilation features of the C preprocessor which allows key -bindings and variable settings to be performed as the result -of tests. There are four parser directives used. -.IP \fB$if\fP -The -.B $if -construct allows bindings to be made based on the -editing mode, the terminal being used, or the application using -readline. The text of the test extends to the end of the line; -no characters are required to isolate it. -.RS -.IP \fBmode\fP -The \fBmode=\fP form of the \fB$if\fP directive is used to test -whether readline is in emacs or vi mode. -This may be used in conjunction -with the \fBset keymap\fP command, for instance, to set bindings in -the \fIemacs-standard\fP and \fIemacs-ctlx\fP keymaps only if -readline is starting out in emacs mode. -.IP \fBterm\fP -The \fBterm=\fP form may be used to include terminal-specific -key bindings, perhaps to bind the key sequences output by the -terminal's function keys. The word on the right side of the -.B = -is tested against the full name of the terminal and the portion -of the terminal name before the first \fB\-\fP. This allows -.I sun -to match both -.I sun -and -.IR sun\-cmd , -for instance. -.IP \fBapplication\fP -The \fBapplication\fP construct is used to include -application-specific settings. Each program using the readline -library sets the \fIapplication name\fP, and an initialization -file can test for a particular value. -This could be used to bind key sequences to functions useful for -a specific program. For instance, the following command adds a -key sequence that quotes the current or previous word in \fBbash\fP: -.sp 1 -.RS -.nf -\fB$if\fP Bash -# Quote the current or previous word -"\eC-xq": "\eeb\e"\eef\e"" -\fB$endif\fP -.fi -.RE -.RE -.IP \fB$endif\fP -This command, as seen in the previous example, terminates an -\fB$if\fP command. -.IP \fB$else\fP -Commands in this branch of the \fB$if\fP directive are executed if -the test fails. -.IP \fB$include\fP -This directive takes a single filename as an argument and reads commands -and bindings from that file. For example, the following directive -would read \fI/etc/inputrc\fP: -.sp 1 -.RS -.nf -\fB$include\fP \^ \fI/etc/inputrc\fP -.fi -.RE -.SH SEARCHING -.PP -Readline provides commands for searching through the command history -for lines containing a specified string. -There are two search modes: -.I incremental -and -.IR non-incremental . -.PP -Incremental searches begin before the user has finished typing the -search string. -As each character of the search string is typed, readline displays -the next entry from the history matching the string typed so far. -An incremental search requires only as many characters as needed to -find the desired history entry. -To search backward in the history for a particular string, type -\fBC\-r\fP. Typing \fBC\-s\fP searches forward through the history. -The characters present in the value of the \fBisearch-terminators\fP -variable are used to terminate an incremental search. -If that variable has not been assigned a value the \fIEscape\fP and -\fBC\-J\fP characters will terminate an incremental search. -\fBC\-G\fP will abort an incremental search and restore the original -line. -When the search is terminated, the history entry containing the -search string becomes the current line. -.PP -To find other matching entries in the history list, type \fBC\-s\fP or -\fBC\-r\fP as appropriate. -This will search backward or forward in the history for the next -line matching the search string typed so far. -Any other key sequence bound to a readline command will terminate -the search and execute that command. -For instance, a newline will terminate the search and accept -the line, thereby executing the command from the history list. -A movement command will terminate the search, make the last line found -the current line, and begin editing. -.PP -Non-incremental searches read the entire search string before starting -to search for matching history lines. The search string may be -typed by the user or be part of the contents of the current line. -.SH EDITING COMMANDS -.PP -The following is a list of the names of the commands and the default -key sequences to which they are bound. -Command names without an accompanying key sequence are unbound by default. -.PP -In the following descriptions, \fIpoint\fP refers to the current cursor -position, and \fImark\fP refers to a cursor position saved by the -\fBset\-mark\fP command. -The text between the point and mark is referred to as the \fIregion\fP. -.SS Commands for Moving -.PP -.PD 0 -.TP -.B beginning\-of\-line (C\-a) -Move to the start of the current line. -.TP -.B end\-of\-line (C\-e) -Move to the end of the line. -.TP -.B forward\-char (C\-f) -Move forward a character. -.TP -.B backward\-char (C\-b) -Move back a character. -.TP -.B forward\-word (M\-f) -Move forward to the end of the next word. Words are composed of -alphanumeric characters (letters and digits). -.TP -.B backward\-word (M\-b) -Move back to the start of the current or previous word. Words are -composed of alphanumeric characters (letters and digits). -.TP -.B clear\-screen (C\-l) -Clear the screen leaving the current line at the top of the screen. -With an argument, refresh the current line without clearing the -screen. -.TP -.B redraw\-current\-line -Refresh the current line. -.PD -.SS Commands for Manipulating the History -.PP -.PD 0 -.TP -.B accept\-line (Newline, Return) -Accept the line regardless of where the cursor is. -If this line is -non-empty, it may be added to the history list for future recall with -\fBadd_history()\fP. -If the line is a modified history line, the history line is restored to its original state. -.TP -.B previous\-history (C\-p) -Fetch the previous command from the history list, moving back in -the list. -.TP -.B next\-history (C\-n) -Fetch the next command from the history list, moving forward in the -list. -.TP -.B beginning\-of\-history (M\-<) -Move to the first line in the history. -.TP -.B end\-of\-history (M\->) -Move to the end of the input history, i.e., the line currently being -entered. -.TP -.B reverse\-search\-history (C\-r) -Search backward starting at the current line and moving `up' through -the history as necessary. This is an incremental search. -.TP -.B forward\-search\-history (C\-s) -Search forward starting at the current line and moving `down' through -the history as necessary. This is an incremental search. -.TP -.B non\-incremental\-reverse\-search\-history (M\-p) -Search backward through the history starting at the current line -using a non-incremental search for a string supplied by the user. -.TP -.B non\-incremental\-forward\-search\-history (M\-n) -Search forward through the history using a non-incremental search -for a string supplied by the user. -.TP -.B history\-search\-forward -Search forward through the history for the string of characters -between the start of the current line and the current cursor -position (the \fIpoint\fP). -This is a non-incremental search. -.TP -.B history\-search\-backward -Search backward through the history for the string of characters -between the start of the current line and the point. -This is a non-incremental search. -.TP -.B yank\-nth\-arg (M\-C\-y) -Insert the first argument to the previous command (usually -the second word on the previous line) at point. -With an argument -.IR n , -insert the \fIn\fPth word from the previous command (the words -in the previous command begin with word 0). A negative argument -inserts the \fIn\fPth word from the end of the previous command. -Once the argument \fIn\fP is computed, the argument is extracted -as if the "!\fIn\fP" history expansion had been specified. -.TP -.B -yank\-last\-arg (M\-.\^, M\-_\^) -Insert the last argument to the previous command (the last word of -the previous history entry). -With a numeric argument, behave exactly like \fByank\-nth\-arg\fP. -Successive calls to \fByank\-last\-arg\fP move back through the history -list, inserting the last word (or the word specified by the argument to -the first call) of each line in turn. -Any numeric argument supplied to these successive calls determines -the direction to move through the history. A negative argument switches -the direction through the history (back or forward). -The history expansion facilities are used to extract the last argument, -as if the "!$" history expansion had been specified. -.PD -.SS Commands for Changing Text -.PP -.PD 0 -.TP -.B delete\-char (C\-d) -Delete the character at point. If point is at the -beginning of the line, there are no characters in the line, and -the last character typed was not bound to \fBdelete\-char\fP, then return -.SM -.BR EOF . -.TP -.B backward\-delete\-char (Rubout) -Delete the character behind the cursor. When given a numeric argument, -save the deleted text on the kill ring. -.TP -.B forward\-backward\-delete\-char -Delete the character under the cursor, unless the cursor is at the -end of the line, in which case the character behind the cursor is -deleted. -.TP -.B quoted\-insert (C\-q, C\-v) -Add the next character that you type to the line verbatim. This is -how to insert characters like \fBC\-q\fP, for example. -.TP -.B tab\-insert (M-TAB) -Insert a tab character. -.TP -.B self\-insert (a,\ b,\ A,\ 1,\ !,\ ...) -Insert the character typed. -.TP -.B transpose\-chars (C\-t) -Drag the character before point forward over the character at point, -moving point forward as well. -If point is at the end of the line, then this transposes -the two characters before point. -Negative arguments have no effect. -.TP -.B transpose\-words (M\-t) -Drag the word before point past the word after point, -moving point over that word as well. -If point is at the end of the line, this transposes -the last two words on the line. -.TP -.B upcase\-word (M\-u) -Uppercase the current (or following) word. With a negative argument, -uppercase the previous word, but do not move point. -.TP -.B downcase\-word (M\-l) -Lowercase the current (or following) word. With a negative argument, -lowercase the previous word, but do not move point. -.TP -.B capitalize\-word (M\-c) -Capitalize the current (or following) word. With a negative argument, -capitalize the previous word, but do not move point. -.TP -.B overwrite\-mode -Toggle overwrite mode. With an explicit positive numeric argument, -switches to overwrite mode. With an explicit non-positive numeric -argument, switches to insert mode. This command affects only -\fBemacs\fP mode; \fBvi\fP mode does overwrite differently. -Each call to \fIreadline()\fP starts in insert mode. -In overwrite mode, characters bound to \fBself\-insert\fP replace -the text at point rather than pushing the text to the right. -Characters bound to \fBbackward\-delete\-char\fP replace the character -before point with a space. By default, this command is unbound. -.PD -.SS Killing and Yanking -.PP -.PD 0 -.TP -.B kill\-line (C\-k) -Kill the text from point to the end of the line. -.TP -.B backward\-kill\-line (C\-x Rubout) -Kill backward to the beginning of the line. -.TP -.B unix\-line\-discard (C\-u) -Kill backward from point to the beginning of the line. -The killed text is saved on the kill-ring. -.\" There is no real difference between this and backward-kill-line -.TP -.B kill\-whole\-line -Kill all characters on the current line, no matter where point is. -.TP -.B kill\-word (M\-d) -Kill from point the end of the current word, or if between -words, to the end of the next word. Word boundaries are the same as -those used by \fBforward\-word\fP. -.TP -.B backward\-kill\-word (M\-Rubout) -Kill the word behind point. -Word boundaries are the same as those used by \fBbackward\-word\fP. -.TP -.B unix\-word\-rubout (C\-w) -Kill the word behind point, using white space as a word boundary. -The killed text is saved on the kill-ring. -.TP -.B unix\-filename\-rubout -Kill the word behind point, using white space and the slash character -as the word boundaries. -The killed text is saved on the kill-ring. -.TP -.B delete\-horizontal\-space (M\-\e) -Delete all spaces and tabs around point. -.TP -.B kill\-region -Kill the text between the point and \fImark\fP (saved cursor position). -This text is referred to as the \fIregion\fP. -.TP -.B copy\-region\-as\-kill -Copy the text in the region to the kill buffer. -.TP -.B copy\-backward\-word -Copy the word before point to the kill buffer. -The word boundaries are the same as \fBbackward\-word\fP. -.TP -.B copy\-forward\-word -Copy the word following point to the kill buffer. -The word boundaries are the same as \fBforward\-word\fP. -.TP -.B yank (C\-y) -Yank the top of the kill ring into the buffer at point. -.TP -.B yank\-pop (M\-y) -Rotate the kill ring, and yank the new top. Only works following -.B yank -or -.BR yank\-pop . -.PD -.SS Numeric Arguments -.PP -.PD 0 -.TP -.B digit\-argument (M\-0, M\-1, ..., M\-\-) -Add this digit to the argument already accumulating, or start a new -argument. M\-\- starts a negative argument. -.TP -.B universal\-argument -This is another way to specify an argument. -If this command is followed by one or more digits, optionally with a -leading minus sign, those digits define the argument. -If the command is followed by digits, executing -.B universal\-argument -again ends the numeric argument, but is otherwise ignored. -As a special case, if this command is immediately followed by a -character that is neither a digit or minus sign, the argument count -for the next command is multiplied by four. -The argument count is initially one, so executing this function the -first time makes the argument count four, a second time makes the -argument count sixteen, and so on. -.PD -.SS Completing -.PP -.PD 0 -.TP -.B complete (TAB) -Attempt to perform completion on the text before point. -The actual completion performed is application-specific. -.BR Bash , -for instance, attempts completion treating the text as a variable -(if the text begins with \fB$\fP), username (if the text begins with -\fB~\fP), hostname (if the text begins with \fB@\fP), or -command (including aliases and functions) in turn. If none -of these produces a match, filename completion is attempted. -.BR Gdb , -on the other hand, -allows completion of program functions and variables, and -only attempts filename completion under certain circumstances. -.TP -.B possible\-completions (M\-?) -List the possible completions of the text before point. -When displaying completions, readline sets the number of columns used -for display to the value of \fBcompletion-display-width\fP, the value of -the environment variable -.SM -.BR COLUMNS , -or the screen width, in that order. -.TP -.B insert\-completions (M\-*) -Insert all completions of the text before point -that would have been generated by -\fBpossible\-completions\fP. -.TP -.B menu\-complete -Similar to \fBcomplete\fP, but replaces the word to be completed -with a single match from the list of possible completions. -Repeated execution of \fBmenu\-complete\fP steps through the list -of possible completions, inserting each match in turn. -At the end of the list of completions, the bell is rung -(subject to the setting of \fBbell\-style\fP) -and the original text is restored. -An argument of \fIn\fP moves \fIn\fP positions forward in the list -of matches; a negative argument may be used to move backward -through the list. -This command is intended to be bound to \fBTAB\fP, but is unbound -by default. -.TP -.B menu\-complete\-backward -Identical to \fBmenu\-complete\fP, but moves backward through the list -of possible completions, as if \fBmenu\-complete\fP had been given a -negative argument. This command is unbound by default. -.TP -.B delete\-char\-or\-list -Deletes the character under the cursor if not at the beginning or -end of the line (like \fBdelete-char\fP). -If at the end of the line, behaves identically to -\fBpossible-completions\fP. -.PD -.SS Keyboard Macros -.PP -.PD 0 -.TP -.B start\-kbd\-macro (C\-x (\^) -Begin saving the characters typed into the current keyboard macro. -.TP -.B end\-kbd\-macro (C\-x )\^) -Stop saving the characters typed into the current keyboard macro -and store the definition. -.TP -.B call\-last\-kbd\-macro (C\-x e) -Re-execute the last keyboard macro defined, by making the characters -in the macro appear as if typed at the keyboard. -.PD -.SS Miscellaneous -.PP -.PD 0 -.TP -.B re\-read\-init\-file (C\-x C\-r) -Read in the contents of the \fIinputrc\fP file, and incorporate -any bindings or variable assignments found there. -.TP -.B abort (C\-g) -Abort the current editing command and -ring the terminal's bell (subject to the setting of -.BR bell\-style ). -.TP -.B do\-uppercase\-version (M\-a, M\-b, M\-\fIx\fP, ...) -If the metafied character \fIx\fP is lowercase, run the command -that is bound to the corresponding uppercase character. -.TP -.B prefix\-meta (ESC) -Metafy the next character typed. -.SM -.B ESC -.B f -is equivalent to -.BR Meta\-f . -.TP -.B undo (C\-_, C\-x C\-u) -Incremental undo, separately remembered for each line. -.TP -.B revert\-line (M\-r) -Undo all changes made to this line. This is like executing the -.B undo -command enough times to return the line to its initial state. -.TP -.B tilde\-expand (M\-&) -Perform tilde expansion on the current word. -.TP -.B set\-mark (C\-@, M\-<space>) -Set the mark to the point. If a -numeric argument is supplied, the mark is set to that position. -.TP -.B exchange\-point\-and\-mark (C\-x C\-x) -Swap the point with the mark. The current cursor position is set to -the saved position, and the old cursor position is saved as the mark. -.TP -.B character\-search (C\-]) -A character is read and point is moved to the next occurrence of that -character. A negative count searches for previous occurrences. -.TP -.B character\-search\-backward (M\-C\-]) -A character is read and point is moved to the previous occurrence of that -character. A negative count searches for subsequent occurrences. -.TP -.B skip\-csi\-sequence -Read enough characters to consume a multi-key sequence such as those -defined for keys like Home and End. Such sequences begin with a -Control Sequence Indicator (CSI), usually ESC\-[. If this sequence is -bound to "\e[", keys producing such sequences will have no effect -unless explicitly bound to a readline command, instead of inserting -stray characters into the editing buffer. This is unbound by default, -but usually bound to ESC\-[. -.TP -.B insert\-comment (M\-#) -Without a numeric argument, the value of the readline -.B comment\-begin -variable is inserted at the beginning of the current line. -If a numeric argument is supplied, this command acts as a toggle: if -the characters at the beginning of the line do not match the value -of \fBcomment\-begin\fP, the value is inserted, otherwise -the characters in \fBcomment-begin\fP are deleted from the beginning of -the line. -In either case, the line is accepted as if a newline had been typed. -The default value of -.B comment\-begin -makes the current line a shell comment. -If a numeric argument causes the comment character to be removed, the line -will be executed by the shell. -.TP -.B dump\-functions -Print all of the functions and their key bindings to the -readline output stream. If a numeric argument is supplied, -the output is formatted in such a way that it can be made part -of an \fIinputrc\fP file. -.TP -.B dump\-variables -Print all of the settable variables and their values to the -readline output stream. If a numeric argument is supplied, -the output is formatted in such a way that it can be made part -of an \fIinputrc\fP file. -.TP -.B dump\-macros -Print all of the readline key sequences bound to macros and the -strings they output. If a numeric argument is supplied, -the output is formatted in such a way that it can be made part -of an \fIinputrc\fP file. -.TP -.B emacs\-editing\-mode (C\-e) -When in -.B vi -command mode, this causes a switch to -.B emacs -editing mode. -.TP -.B vi\-editing\-mode (M\-C\-j) -When in -.B emacs -editing mode, this causes a switch to -.B vi -editing mode. -.PD -.SH DEFAULT KEY BINDINGS -.LP -The following is a list of the default emacs and vi bindings. -Characters with the eighth bit set are written as M\-<character>, and -are referred to as -.I metafied -characters. -The printable ASCII characters not mentioned in the list of emacs -standard bindings are bound to the -.B self\-insert -function, which just inserts the given character into the input line. -In vi insertion mode, all characters not specifically mentioned are -bound to -.BR self\-insert . -Characters assigned to signal generation by -.IR stty (1) -or the terminal driver, such as C-Z or C-C, -retain that function. -Upper and lower case metafied characters are bound to the same function in -the emacs mode meta keymap. -The remaining characters are unbound, which causes readline -to ring the bell (subject to the setting of the -.B bell\-style -variable). -.SS Emacs Mode -.RS +.6i -.nf -.ta 2.5i -.sp -Emacs Standard bindings -.sp -"C-@" set-mark -"C-A" beginning-of-line -"C-B" backward-char -"C-D" delete-char -"C-E" end-of-line -"C-F" forward-char -"C-G" abort -"C-H" backward-delete-char -"C-I" complete -"C-J" accept-line -"C-K" kill-line -"C-L" clear-screen -"C-M" accept-line -"C-N" next-history -"C-P" previous-history -"C-Q" quoted-insert -"C-R" reverse-search-history -"C-S" forward-search-history -"C-T" transpose-chars -"C-U" unix-line-discard -"C-V" quoted-insert -"C-W" unix-word-rubout -"C-Y" yank -"C-]" character-search -"C-_" undo -"\^ " to "/" self-insert -"0" to "9" self-insert -":" to "~" self-insert -"C-?" backward-delete-char -.PP -Emacs Meta bindings -.sp -"M-C-G" abort -"M-C-H" backward-kill-word -"M-C-I" tab-insert -"M-C-J" vi-editing-mode -"M-C-M" vi-editing-mode -"M-C-R" revert-line -"M-C-Y" yank-nth-arg -"M-C-[" complete -"M-C-]" character-search-backward -"M-space" set-mark -"M-#" insert-comment -"M-&" tilde-expand -"M-*" insert-completions -"M--" digit-argument -"M-." yank-last-arg -"M-0" digit-argument -"M-1" digit-argument -"M-2" digit-argument -"M-3" digit-argument -"M-4" digit-argument -"M-5" digit-argument -"M-6" digit-argument -"M-7" digit-argument -"M-8" digit-argument -"M-9" digit-argument -"M-<" beginning-of-history -"M-=" possible-completions -"M->" end-of-history -"M-?" possible-completions -"M-B" backward-word -"M-C" capitalize-word -"M-D" kill-word -"M-F" forward-word -"M-L" downcase-word -"M-N" non-incremental-forward-search-history -"M-P" non-incremental-reverse-search-history -"M-R" revert-line -"M-T" transpose-words -"M-U" upcase-word -"M-Y" yank-pop -"M-\e" delete-horizontal-space -"M-~" tilde-expand -"M-C-?" backward-kill-word -"M-_" yank-last-arg -.PP -Emacs Control-X bindings -.sp -"C-XC-G" abort -"C-XC-R" re-read-init-file -"C-XC-U" undo -"C-XC-X" exchange-point-and-mark -"C-X(" start-kbd-macro -"C-X)" end-kbd-macro -"C-XE" call-last-kbd-macro -"C-XC-?" backward-kill-line -.sp -.RE -.SS VI Mode bindings -.RS +.6i -.nf -.ta 2.5i -.sp -.PP -VI Insert Mode functions -.sp -"C-D" vi-eof-maybe -"C-H" backward-delete-char -"C-I" complete -"C-J" accept-line -"C-M" accept-line -"C-R" reverse-search-history -"C-S" forward-search-history -"C-T" transpose-chars -"C-U" unix-line-discard -"C-V" quoted-insert -"C-W" unix-word-rubout -"C-Y" yank -"C-[" vi-movement-mode -"C-_" undo -"\^ " to "~" self-insert -"C-?" backward-delete-char -.PP -VI Command Mode functions -.sp -"C-D" vi-eof-maybe -"C-E" emacs-editing-mode -"C-G" abort -"C-H" backward-char -"C-J" accept-line -"C-K" kill-line -"C-L" clear-screen -"C-M" accept-line -"C-N" next-history -"C-P" previous-history -"C-Q" quoted-insert -"C-R" reverse-search-history -"C-S" forward-search-history -"C-T" transpose-chars -"C-U" unix-line-discard -"C-V" quoted-insert -"C-W" unix-word-rubout -"C-Y" yank -"C-_" vi-undo -"\^ " forward-char -"#" insert-comment -"$" end-of-line -"%" vi-match -"&" vi-tilde-expand -"*" vi-complete -"+" next-history -"," vi-char-search -"-" previous-history -"." vi-redo -"/" vi-search -"0" beginning-of-line -"1" to "9" vi-arg-digit -";" vi-char-search -"=" vi-complete -"?" vi-search -"A" vi-append-eol -"B" vi-prev-word -"C" vi-change-to -"D" vi-delete-to -"E" vi-end-word -"F" vi-char-search -"G" vi-fetch-history -"I" vi-insert-beg -"N" vi-search-again -"P" vi-put -"R" vi-replace -"S" vi-subst -"T" vi-char-search -"U" revert-line -"W" vi-next-word -"X" backward-delete-char -"Y" vi-yank-to -"\e" vi-complete -"^" vi-first-print -"_" vi-yank-arg -"`" vi-goto-mark -"a" vi-append-mode -"b" vi-prev-word -"c" vi-change-to -"d" vi-delete-to -"e" vi-end-word -"f" vi-char-search -"h" backward-char -"i" vi-insertion-mode -"j" next-history -"k" prev-history -"l" forward-char -"m" vi-set-mark -"n" vi-search-again -"p" vi-put -"r" vi-change-char -"s" vi-subst -"t" vi-char-search -"u" vi-undo -"w" vi-next-word -"x" vi-delete -"y" vi-yank-to -"|" vi-column -"~" vi-change-case -.RE -.SH "SEE ALSO" -.PD 0 -.TP -\fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey -.TP -\fIThe Gnu History Library\fP, Brian Fox and Chet Ramey -.TP -\fIbash\fP(1) -.PD -.SH FILES -.PD 0 -.TP -.FN ~/.inputrc -Individual \fBreadline\fP initialization file -.PD -.SH AUTHORS -Brian Fox, Free Software Foundation -.br -bfox@gnu.org -.PP -Chet Ramey, Case Western Reserve University -.br -chet@ins.CWRU.Edu -.SH BUG REPORTS -If you find a bug in -.B readline, -you should report it. But first, you should -make sure that it really is a bug, and that it appears in the latest -version of the -.B readline -library that you have. -.PP -Once you have determined that a bug actually exists, mail a -bug report to \fIbug\-readline\fP@\fIgnu.org\fP. -If you have a fix, you are welcome to mail that -as well! Suggestions and `philosophical' bug reports may be mailed -to \fPbug-readline\fP@\fIgnu.org\fP or posted to the Usenet -newsgroup -.BR gnu.bash.bug . -.PP -Comments and bug reports concerning -this manual page should be directed to -.IR chet@ins.CWRU.Edu . -.SH BUGS -.PP -It's too big and too slow. diff --git a/lib/readline/doc/rluser.texi~ b/lib/readline/doc/rluser.texi~ deleted file mode 100644 index e75c12c0..00000000 --- a/lib/readline/doc/rluser.texi~ +++ /dev/null @@ -1,2054 +0,0 @@ -@comment %**start of header (This is for running Texinfo on a region.) -@setfilename rluser.info -@comment %**end of header (This is for running Texinfo on a region.) - -@ignore -This file documents the end user interface to the GNU command line -editing features. It is to be an appendix to manuals for programs which -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--2011 Free Software Foundation, Inc. - -Authored by Brian Fox and Chet Ramey. - -Permission is granted to process this file through Tex and print the -results, provided the printed document carries copying permission notice -identical to this one except for the removal of this paragraph (this -paragraph not being relevant to the printed manual). - -Permission is granted to make and distribute verbatim copies of this manual -provided the copyright notice and this permission notice are preserved on -all copies. - -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided also that the -GNU Copyright statement is available to the distributee, and provided that -the entire resulting derived work is distributed under the terms of a -permission notice identical to this one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions. -@end ignore - -@comment If you are including this manual as an appendix, then set the -@comment variable readline-appendix. - -@ifclear BashFeatures -@defcodeindex bt -@end ifclear - -@node Command Line Editing -@chapter Command Line Editing - -This chapter describes the basic features of the @sc{gnu} -command line editing interface. -@ifset BashFeatures -Command line editing is provided by the Readline library, which is -used by several different programs, including Bash. -Command line editing is enabled by default when using an interactive shell, -unless the @option{--noediting} option is supplied at shell invocation. -Line editing is also used when using the @option{-e} option to the -@code{read} builtin command (@pxref{Bash Builtins}). -By default, the line editing commands are similar to those of Emacs. -A vi-style line editing interface is also available. -Line editing can be enabled at any time using the @option{-o emacs} or -@option{-o vi} options to the @code{set} builtin command -(@pxref{The Set Builtin}), or disabled using the @option{+o emacs} or -@option{+o vi} options to @code{set}. -@end ifset - -@menu -* Introduction and Notation:: Notation used in this text. -* Readline Interaction:: The minimum set of commands for editing a line. -* Readline Init File:: Customizing Readline from a user's view. -* Bindable Readline Commands:: A description of most of the Readline commands - available for binding -* Readline vi Mode:: A short description of how to make Readline - behave like the vi editor. -@ifset BashFeatures -* Programmable Completion:: How to specify the possible completions for - a specific command. -* Programmable Completion Builtins:: Builtin commands to specify how to - complete arguments for a particular command. -@end ifset -@end menu - -@node Introduction and Notation -@section Introduction to Line Editing - -The following paragraphs describe the notation used to represent -keystrokes. - -The text @kbd{C-k} is read as `Control-K' and describes the character -produced when the @key{k} key is pressed while the Control key -is depressed. - -The text @kbd{M-k} is read as `Meta-K' and describes the character -produced when the Meta key (if you have one) is depressed, and the @key{k} -key is pressed. -The Meta key is labeled @key{ALT} on many keyboards. -On keyboards with two keys labeled @key{ALT} (usually to either side of -the space bar), the @key{ALT} on the left side is generally set to -work as a Meta key. -The @key{ALT} key on the right may also be configured to work as a -Meta key or may be configured as some other modifier, such as a -Compose key for typing accented characters. - -If you do not have a Meta or @key{ALT} key, or another key working as -a Meta key, the identical keystroke can be generated by typing @key{ESC} -@emph{first}, and then typing @key{k}. -Either process is known as @dfn{metafying} the @key{k} key. - -The text @kbd{M-C-k} is read as `Meta-Control-k' and describes the -character produced by @dfn{metafying} @kbd{C-k}. - -In addition, several keys have their own names. Specifically, -@key{DEL}, @key{ESC}, @key{LFD}, @key{SPC}, @key{RET}, and @key{TAB} all -stand for themselves when seen in this text, or in an init file -(@pxref{Readline Init File}). -If your keyboard lacks a @key{LFD} key, typing @key{C-j} will -produce the desired character. -The @key{RET} key may be labeled @key{Return} or @key{Enter} on -some keyboards. - -@node Readline Interaction -@section Readline Interaction -@cindex interaction, readline - -Often during an interactive session you type in a long line of text, -only to notice that the first word on the line is misspelled. The -Readline library gives you a set of commands for manipulating the text -as you type it in, allowing you to just fix your typo, and not forcing -you to retype the majority of the line. Using these editing commands, -you move the cursor to the place that needs correction, and delete or -insert the text of the corrections. Then, when you are satisfied with -the line, you simply press @key{RET}. You do not have to be at the -end of the line to press @key{RET}; the entire line is accepted -regardless of the location of the cursor within the line. - -@menu -* Readline Bare Essentials:: The least you need to know about Readline. -* Readline Movement Commands:: Moving about the input line. -* Readline Killing Commands:: How to delete text, and how to get it back! -* Readline Arguments:: Giving numeric arguments to commands. -* Searching:: Searching through previous lines. -@end menu - -@node Readline Bare Essentials -@subsection Readline Bare Essentials -@cindex notation, readline -@cindex command editing -@cindex editing command lines - -In order to enter characters into the line, simply type them. The typed -character appears where the cursor was, and then the cursor moves one -space to the right. If you mistype a character, you can use your -erase character to back up and delete the mistyped character. - -Sometimes you may mistype a character, and -not notice the error until you have typed several other characters. In -that case, you can type @kbd{C-b} to move the cursor to the left, and then -correct your mistake. Afterwards, you can move the cursor to the right -with @kbd{C-f}. - -When you add text in the middle of a line, you will notice that characters -to the right of the cursor are `pushed over' to make room for the text -that you have inserted. Likewise, when you delete text behind the cursor, -characters to the right of the cursor are `pulled back' to fill in the -blank space created by the removal of the text. A list of the bare -essentials for editing the text of an input line follows. - -@table @asis -@item @kbd{C-b} -Move back one character. -@item @kbd{C-f} -Move forward one character. -@item @key{DEL} or @key{Backspace} -Delete the character to the left of the cursor. -@item @kbd{C-d} -Delete the character underneath the cursor. -@item @w{Printing characters} -Insert the character into the line at the cursor. -@item @kbd{C-_} or @kbd{C-x C-u} -Undo the last editing command. You can undo all the way back to an -empty line. -@end table - -@noindent -(Depending on your configuration, the @key{Backspace} key be set to -delete the character to the left of the cursor and the @key{DEL} key set -to delete the character underneath the cursor, like @kbd{C-d}, rather -than the character to the left of the cursor.) - -@node Readline Movement Commands -@subsection Readline Movement Commands - - -The above table describes the most basic keystrokes that you need -in order to do editing of the input line. For your convenience, many -other commands have been added in addition to @kbd{C-b}, @kbd{C-f}, -@kbd{C-d}, and @key{DEL}. Here are some commands for moving more rapidly -about the line. - -@table @kbd -@item C-a -Move to the start of the line. -@item C-e -Move to the end of the line. -@item M-f -Move forward a word, where a word is composed of letters and digits. -@item M-b -Move backward a word. -@item C-l -Clear the screen, reprinting the current line at the top. -@end table - -Notice how @kbd{C-f} moves forward a character, while @kbd{M-f} moves -forward a word. It is a loose convention that control keystrokes -operate on characters while meta keystrokes operate on words. - -@node Readline Killing Commands -@subsection Readline Killing Commands - -@cindex killing text -@cindex yanking text - -@dfn{Killing} text means to delete the text from the line, but to save -it away for later use, usually by @dfn{yanking} (re-inserting) -it back into the line. -(`Cut' and `paste' are more recent jargon for `kill' and `yank'.) - -If the description for a command says that it `kills' text, then you can -be sure that you can get the text back in a different (or the same) -place later. - -When you use a kill command, the text is saved in a @dfn{kill-ring}. -Any number of consecutive kills save all of the killed text together, so -that when you yank it back, you get it all. The kill -ring is not line specific; the text that you killed on a previously -typed line is available to be yanked back later, when you are typing -another line. -@cindex kill ring - -Here is the list of commands for killing text. - -@table @kbd -@item C-k -Kill the text from the current cursor position to the end of the line. - -@item M-d -Kill from the cursor to the end of the current word, or, if between -words, to the end of the next word. -Word boundaries are the same as those used by @kbd{M-f}. - -@item M-@key{DEL} -Kill from the cursor the start of the current word, or, if between -words, to the start of the previous word. -Word boundaries are the same as those used by @kbd{M-b}. - -@item C-w -Kill from the cursor to the previous whitespace. This is different than -@kbd{M-@key{DEL}} because the word boundaries differ. - -@end table - -Here is how to @dfn{yank} the text back into the line. Yanking -means to copy the most-recently-killed text from the kill buffer. - -@table @kbd -@item C-y -Yank the most recently killed text back into the buffer at the cursor. - -@item M-y -Rotate the kill-ring, and yank the new top. You can only do this if -the prior command is @kbd{C-y} or @kbd{M-y}. -@end table - -@node Readline Arguments -@subsection Readline Arguments - -You can pass numeric arguments to Readline commands. Sometimes the -argument acts as a repeat count, other times it is the @i{sign} of the -argument that is significant. If you pass a negative argument to a -command which normally acts in a forward direction, that command will -act in a backward direction. For example, to kill text back to the -start of the line, you might type @samp{M-- C-k}. - -The general way to pass numeric arguments to a command is to type meta -digits before the command. If the first `digit' typed is a minus -sign (@samp{-}), then the sign of the argument will be negative. Once -you have typed one meta digit to get the argument started, you can type -the remainder of the digits, and then the command. For example, to give -the @kbd{C-d} command an argument of 10, you could type @samp{M-1 0 C-d}, -which will delete the next ten characters on the input line. - -@node Searching -@subsection Searching for Commands in the History - -Readline provides commands for searching through the command history -@ifset BashFeatures -(@pxref{Bash History Facilities}) -@end ifset -for lines containing a specified string. -There are two search modes: @dfn{incremental} and @dfn{non-incremental}. - -Incremental searches begin before the user has finished typing the -search string. -As each character of the search string is typed, Readline displays -the next entry from the history matching the string typed so far. -An incremental search requires only as many characters as needed to -find the desired history entry. -To search backward in the history for a particular string, type -@kbd{C-r}. Typing @kbd{C-s} searches forward through the history. -The characters present in the value of the @code{isearch-terminators} variable -are used to terminate an incremental search. -If that variable has not been assigned a value, the @key{ESC} and -@kbd{C-J} characters will terminate an incremental search. -@kbd{C-g} will abort an incremental search and restore the original line. -When the search is terminated, the history entry containing the -search string becomes the current line. - -To find other matching entries in the history list, type @kbd{C-r} or -@kbd{C-s} as appropriate. -This will search backward or forward in the history for the next -entry matching the search string typed so far. -Any other key sequence bound to a Readline command will terminate -the search and execute that command. -For instance, a @key{RET} will terminate the search and accept -the line, thereby executing the command from the history list. -A movement command will terminate the search, make the last line found -the current line, and begin editing. - -Readline remembers the last incremental search string. If two -@kbd{C-r}s are typed without any intervening characters defining a new -search string, any remembered search string is used. - -Non-incremental searches read the entire search string before starting -to search for matching history lines. The search string may be -typed by the user or be part of the contents of the current line. - -@node Readline Init File -@section Readline Init File -@cindex initialization file, readline - -Although the Readline library comes with a set of Emacs-like -keybindings installed by default, it is possible to use a different set -of keybindings. -Any user can customize programs that use Readline by putting -commands in an @dfn{inputrc} file, conventionally in his home directory. -The name of this -@ifset BashFeatures -file is taken from the value of the shell variable @env{INPUTRC}. If -@end ifset -@ifclear BashFeatures -file is taken from the value of the environment variable @env{INPUTRC}. If -@end ifclear -that variable is unset, the default is @file{~/.inputrc}. If that -file does not exist or cannot be read, the ultimate default is -@file{/etc/inputrc}. - -When a program which uses the Readline library starts up, the -init file is read, and the key bindings are set. - -In addition, the @code{C-x C-r} command re-reads this init file, thus -incorporating any changes that you might have made to it. - -@menu -* Readline Init File Syntax:: Syntax for the commands in the inputrc file. - -* Conditional Init Constructs:: Conditional key bindings in the inputrc file. - -* Sample Init File:: An example inputrc file. -@end menu - -@node Readline Init File Syntax -@subsection Readline Init File Syntax - -There are only a few basic constructs allowed in the -Readline init file. Blank lines are ignored. -Lines beginning with a @samp{#} are comments. -Lines beginning with a @samp{$} indicate conditional -constructs (@pxref{Conditional Init Constructs}). Other lines -denote variable settings and key bindings. - -@table @asis -@item Variable Settings -You can modify the run-time behavior of Readline by -altering the values of variables in Readline -using the @code{set} command within the init file. -The syntax is simple: - -@example -set @var{variable} @var{value} -@end example - -@noindent -Here, for example, is how to -change from the default Emacs-like key binding to use -@code{vi} line editing commands: - -@example -set editing-mode vi -@end example - -Variable names and values, where appropriate, are recognized without regard -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 -and values. @xref{Bash Builtins}. -@end ifset - -A great deal of run-time behavior is changeable with the following -variables. - -@cindex variables, readline -@table @code - -@item bell-style -@vindex bell-style -Controls what happens when Readline wants to ring the terminal bell. -If set to @samp{none}, Readline never rings the bell. If set to -@samp{visible}, Readline uses a visible bell if one is available. -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 -@code{insert-comment} command is executed. The default value -is @code{"#"}. - -@item completion-display-width -@vindex completion-display-width -The number of screen columns used to display possible matches -when performing completion. -The value is ignored if it is less than 0 or greater than the terminal -screen width. -A value of 0 will cause matches to be displayed one per line. -The default value is -1. - -@item completion-ignore-case -@vindex completion-ignore-case -If set to @samp{on}, Readline performs filename matching and completion -in a case-insensitive fashion. -The default value is @samp{off}. - -@item completion-map-case -@vindex completion-map-case -If set to @samp{on}, and @var{completion-ignore-case} is enabled, Readline -treats hyphens (@samp{-}) and underscores (@samp{_}) as equivalent when -performing case-insensitive filename matching and completion. - -@item completion-prefix-display-length -@vindex completion-prefix-display-length -The length in characters of the common prefix of a list of possible -completions that is displayed without modification. When set to a -value greater than zero, common prefixes longer than this value are -replaced with an ellipsis when displaying possible completions. - -@item completion-query-items -@vindex completion-query-items -The number of possible completions that determines when the user is -asked whether the list of possibilities should be displayed. -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 -@vindex convert-meta -If set to @samp{on}, Readline will convert characters with the -eighth bit set to an @sc{ascii} key sequence by stripping the eighth -bit and prefixing an @key{ESC} character, converting them to a -meta-prefixed key sequence. The default value is @samp{on}. - -@item disable-completion -@vindex disable-completion -If set to @samp{On}, Readline will inhibit word completion. -Completion characters will be inserted into the line as if they had -been mapped to @code{self-insert}. The default is @samp{off}. - -@item editing-mode -@vindex editing-mode -The @code{editing-mode} variable controls which default set of -key bindings is used. By default, Readline starts up in Emacs editing -mode, where the keystrokes are most similar to Emacs. This variable can be -set to either @samp{emacs} or @samp{vi}. - -@item echo-control-characters -When set to @samp{on}, on operating systems that indicate they support it, -readline echoes a character corresponding to a signal generated from the -keyboard. The default is @samp{on}. - -@item enable-keypad -@vindex enable-keypad -When set to @samp{on}, Readline will try to enable the application -keypad when it is called. Some systems need this to enable the -arrow keys. The default is @samp{off}. - -@item enable-meta-key -When set to @samp{on}, Readline will try to enable any meta modifier -key the terminal claims to support when it is called. On many terminals, -the meta key is used to send eight-bit characters. -The default is @samp{on}. - -@item expand-tilde -@vindex expand-tilde -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 the point (the -current cursor position) at the -same location on each history line retrieved with @code{previous-history} -or @code{next-history}. The default is @samp{off}. - -@item history-size -@vindex history-size -Set the maximum number of history entries saved in the history list. If -set to zero, the number of entries in the history list is not limited. - -@item horizontal-scroll-mode -@vindex horizontal-scroll-mode -This variable can be set to either @samp{on} or @samp{off}. Setting it -to @samp{on} means that the text of the lines being edited will scroll -horizontally on a single screen line when they are longer than the width -of the screen, instead of wrapping onto a new screen line. By default, -this variable is set to @samp{off}. - -@item input-meta -@vindex input-meta -@vindex meta-flag -If set to @samp{on}, Readline will enable eight-bit input (it -will not clear the eighth bit in the characters it reads), -regardless of what the terminal claims it can support. The -default value is @samp{off}. The name @code{meta-flag} is a -synonym for this variable. - -@item isearch-terminators -@vindex isearch-terminators -The string of characters that should terminate an incremental search without -subsequently executing the character as a command (@pxref{Searching}). -If this variable has not been given a value, the characters @key{ESC} and -@kbd{C-J} will terminate an incremental search. - -@item keymap -@vindex keymap -Sets Readline's idea of the current keymap for key binding commands. -Acceptable @code{keymap} names are -@code{emacs}, -@code{emacs-standard}, -@code{emacs-meta}, -@code{emacs-ctlx}, -@code{vi}, -@code{vi-move}, -@code{vi-command}, and -@code{vi-insert}. -@code{vi} is equivalent to @code{vi-command}; @code{emacs} is -equivalent to @code{emacs-standard}. The default value is @code{emacs}. -The value of the @code{editing-mode} variable also affects the -default keymap. - -@item mark-directories -If set to @samp{on}, completed directory names have a slash -appended. The default is @samp{on}. - -@item mark-modified-lines -@vindex mark-modified-lines -This variable, when set to @samp{on}, causes Readline to display an -asterisk (@samp{*}) at the start of history lines which have been modified. -This variable is @samp{off} by default. - -@item mark-symlinked-directories -@vindex mark-symlinked-directories -If set to @samp{on}, completed names which are symbolic links -to directories have a slash appended (subject to the value of -@code{mark-directories}). -The default is @samp{off}. - -@item match-hidden-files -@vindex match-hidden-files -This variable, when set to @samp{on}, causes Readline to match files whose -names begin with a @samp{.} (hidden files) when performing filename -completion. -If set to @samp{off}, the leading @samp{.} must be -supplied by the user in the filename to be completed. -This variable is @samp{on} by default. - -@item menu-complete-display-prefix -@vindex menu-complete-display-prefix -If set to @samp{on}, menu completion displays the common prefix of the -list of possible completions (which may be empty) before cycling through -the list. The default is @samp{off}. - -@item output-meta -@vindex output-meta -If set to @samp{on}, Readline will display characters with the -eighth bit set directly rather than as a meta-prefixed escape -sequence. The default is @samp{off}. - -@item page-completions -@vindex page-completions -If set to @samp{on}, Readline uses an internal @code{more}-like pager -to display a screenful of possible completions at a time. -This variable is @samp{on} by default. - -@item print-completions-horizontally -If set to @samp{on}, Readline will display completions with matches -sorted horizontally in alphabetical order, rather than down the screen. -The default is @samp{off}. - -@item revert-all-at-newline -@vindex revert-all-at-newline -If set to @samp{on}, Readline will undo all changes to history lines -before returning when @code{accept-line} is executed. By default, -history lines may be modified and retain individual undo lists across -calls to @code{readline}. The default is @samp{off}. - -@item show-all-if-ambiguous -@vindex show-all-if-ambiguous -This alters the default behavior of the completion functions. If -set to @samp{on}, -words which have more than one possible completion cause the -matches to be listed immediately instead of ringing the bell. -The default value is @samp{off}. - -@item show-all-if-unmodified -@vindex show-all-if-unmodified -This alters the default behavior of the completion functions in -a fashion similar to @var{show-all-if-ambiguous}. -If set to @samp{on}, -words which have more than one possible completion without any -possible partial completion (the possible completions don't share -a common prefix) cause the matches to be listed immediately instead -of ringing the bell. -The default value is @samp{off}. - -@item skip-completed-text -@vindex skip-completed-text -If set to @samp{on}, this alters the default completion behavior when -inserting a single match into the line. It's only active when -performing completion in the middle of a word. If enabled, readline -does not insert characters from the completion that match characters -after point in the word being completed, so portions of the word -following the cursor are not duplicated. -For instance, if this is enabled, attempting completion when the cursor -is after the @samp{e} in @samp{Makefile} will result in @samp{Makefile} -rather than @samp{Makefilefile}, assuming there is a single possible -completion. -The default value is @samp{off}. - -@item visible-stats -@vindex visible-stats -If set to @samp{on}, a character denoting a file's type -is appended to the filename when listing possible -completions. The default is @samp{off}. - -@end table - -@item Key Bindings -The syntax for controlling key bindings in the init file is -simple. First you need to find the name of the command that you -want to change. The following sections contain tables of the command -name, the default keybinding, if any, and a short description of what -the command does. - -Once you know the name of the command, simply place on a line -in the init file the name of the key -you wish to bind the command to, a colon, and then the name of the -command. -There can be no space between the key name and the colon -- that will be -interpreted as part of the key name. -The name of the key can be expressed in different ways, depending on -what you find most comfortable. - -In addition to command names, readline allows keys to be bound -to a string that is inserted when the key is pressed (a @var{macro}). - -@ifset BashFeatures -The @w{@code{bind -p}} command displays Readline function names and -bindings in a format that can put directly into an initialization file. -@xref{Bash Builtins}. -@end ifset - -@table @asis -@item @w{@var{keyname}: @var{function-name} or @var{macro}} -@var{keyname} is the name of a key spelled out in English. For example: -@example -Control-u: universal-argument -Meta-Rubout: backward-kill-word -Control-o: "> output" -@end example - -In the above example, @kbd{C-u} is bound to the function -@code{universal-argument}, -@kbd{M-DEL} is bound to the function @code{backward-kill-word}, and -@kbd{C-o} is bound to run the macro -expressed on the right hand side (that is, to insert the text -@samp{> output} into the line). - -A number of symbolic character names are recognized while -processing this key binding syntax: -@var{DEL}, -@var{ESC}, -@var{ESCAPE}, -@var{LFD}, -@var{NEWLINE}, -@var{RET}, -@var{RETURN}, -@var{RUBOUT}, -@var{SPACE}, -@var{SPC}, -and -@var{TAB}. - -@item @w{"@var{keyseq}": @var{function-name} or @var{macro}} -@var{keyseq} differs from @var{keyname} above in that strings -denoting an entire key sequence can be specified, by placing -the key sequence in double quotes. Some @sc{gnu} Emacs style key -escapes can be used, as in the following example, but the -special character names are not recognized. - -@example -"\C-u": universal-argument -"\C-x\C-r": re-read-init-file -"\e[11~": "Function Key 1" -@end example - -In the above example, @kbd{C-u} is again bound to the function -@code{universal-argument} (just as it was in the first example), -@samp{@kbd{C-x} @kbd{C-r}} is bound to the function @code{re-read-init-file}, -and @samp{@key{ESC} @key{[} @key{1} @key{1} @key{~}} is bound to insert -the text @samp{Function Key 1}. - -@end table - -The following @sc{gnu} Emacs style escape sequences are available when -specifying key sequences: - -@table @code -@item @kbd{\C-} -control prefix -@item @kbd{\M-} -meta prefix -@item @kbd{\e} -an escape character -@item @kbd{\\} -backslash -@item @kbd{\"} -@key{"}, a double quotation mark -@item @kbd{\'} -@key{'}, a single quote or apostrophe -@end table - -In addition to the @sc{gnu} Emacs style escape sequences, a second -set of backslash escapes is available: - -@table @code -@item \a -alert (bell) -@item \b -backspace -@item \d -delete -@item \f -form feed -@item \n -newline -@item \r -carriage return -@item \t -horizontal tab -@item \v -vertical tab -@item \@var{nnn} -the eight-bit character whose value is the octal value @var{nnn} -(one to three digits) -@item \x@var{HH} -the eight-bit character whose value is the hexadecimal value @var{HH} -(one or two hex digits) -@end table - -When entering the text of a macro, single or double quotes must -be used to indicate a macro definition. -Unquoted text is assumed to be a function name. -In the macro body, the backslash escapes described above are expanded. -Backslash will quote any other character in the macro text, -including @samp{"} and @samp{'}. -For example, the following binding will make @samp{@kbd{C-x} \} -insert a single @samp{\} into the line: -@example -"\C-x\\": "\\" -@end example - -@end table - -@node Conditional Init Constructs -@subsection Conditional Init Constructs - -Readline implements a facility similar in spirit to the conditional -compilation features of the C preprocessor which allows key -bindings and variable settings to be performed as the result -of tests. There are four parser directives used. - -@table @code -@item $if -The @code{$if} construct allows bindings to be made based on the -editing mode, the terminal being used, or the application using -Readline. The text of the test extends to the end of the line; -no characters are required to isolate it. - -@table @code -@item mode -The @code{mode=} form of the @code{$if} directive is used to test -whether Readline is in @code{emacs} or @code{vi} mode. -This may be used in conjunction -with the @samp{set keymap} command, for instance, to set bindings in -the @code{emacs-standard} and @code{emacs-ctlx} keymaps only if -Readline is starting out in @code{emacs} mode. - -@item term -The @code{term=} form may be used to include terminal-specific -key bindings, perhaps to bind the key sequences output by the -terminal's function keys. The word on the right side of the -@samp{=} is tested against both the full name of the terminal and -the portion of the terminal name before the first @samp{-}. This -allows @code{sun} to match both @code{sun} and @code{sun-cmd}, -for instance. - -@item application -The @var{application} construct is used to include -application-specific settings. Each program using the Readline -library sets the @var{application name}, and you can test for -a particular value. -This could be used to bind key sequences to functions useful for -a specific program. For instance, the following command adds a -key sequence that quotes the current or previous word in Bash: -@example -$if Bash -# Quote the current or previous word -"\C-xq": "\eb\"\ef\"" -$endif -@end example -@end table - -@item $endif -This command, as seen in the previous example, terminates an -@code{$if} command. - -@item $else -Commands in this branch of the @code{$if} directive are executed if -the test fails. - -@item $include -This directive takes a single filename as an argument and reads commands -and bindings from that file. -For example, the following directive reads from @file{/etc/inputrc}: -@example -$include /etc/inputrc -@end example -@end table - -@node Sample Init File -@subsection Sample Init File - -Here is an example of an @var{inputrc} file. This illustrates key -binding, variable assignment, and conditional syntax. - -@example -@page -# This file controls the behaviour of line input editing for -# programs that use the GNU Readline library. Existing -# programs include FTP, Bash, and GDB. -# -# You can re-read the inputrc file with C-x C-r. -# Lines beginning with '#' are comments. -# -# First, include any systemwide bindings and variable -# assignments from /etc/Inputrc -$include /etc/Inputrc - -# -# Set various bindings for emacs mode. - -set editing-mode emacs - -$if mode=emacs - -Meta-Control-h: backward-kill-word Text after the function name is ignored - -# -# Arrow keys in keypad mode -# -#"\M-OD": backward-char -#"\M-OC": forward-char -#"\M-OA": previous-history -#"\M-OB": next-history -# -# Arrow keys in ANSI mode -# -"\M-[D": backward-char -"\M-[C": forward-char -"\M-[A": previous-history -"\M-[B": next-history -# -# Arrow keys in 8 bit keypad mode -# -#"\M-\C-OD": backward-char -#"\M-\C-OC": forward-char -#"\M-\C-OA": previous-history -#"\M-\C-OB": next-history -# -# Arrow keys in 8 bit ANSI mode -# -#"\M-\C-[D": backward-char -#"\M-\C-[C": forward-char -#"\M-\C-[A": previous-history -#"\M-\C-[B": next-history - -C-q: quoted-insert - -$endif - -# An old-style binding. This happens to be the default. -TAB: complete - -# Macros that are convenient for shell interaction -$if Bash -# edit the path -"\C-xp": "PATH=$@{PATH@}\e\C-e\C-a\ef\C-f" -# prepare to type a quoted word -- -# insert open and close double quotes -# and move to just after the open quote -"\C-x\"": "\"\"\C-b" -# insert a backslash (testing backslash escapes -# in sequences and macros) -"\C-x\\": "\\" -# Quote the current or previous word -"\C-xq": "\eb\"\ef\"" -# Add a binding to refresh the line, which is unbound -"\C-xr": redraw-current-line -# Edit variable on current line. -"\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y=" -$endif - -# use a visible bell if one is available -set bell-style visible - -# don't strip characters to 7 bits when reading -set input-meta on - -# allow iso-latin1 characters to be inserted rather -# than converted to prefix-meta sequences -set convert-meta off - -# display characters with the eighth bit set directly -# rather than as meta-prefixed characters -set output-meta on - -# if there are more than 150 possible completions for -# a word, ask the user if he wants to see all of them -set completion-query-items 150 - -# For FTP -$if Ftp -"\C-xg": "get \M-?" -"\C-xt": "put \M-?" -"\M-.": yank-last-arg -$endif -@end example - -@node Bindable Readline Commands -@section Bindable Readline Commands - -@menu -* Commands For Moving:: Moving about the line. -* Commands For History:: Getting at previous lines. -* Commands For Text:: Commands for changing text. -* Commands For Killing:: Commands for killing and yanking. -* Numeric Arguments:: Specifying numeric arguments, repeat counts. -* Commands For Completion:: Getting Readline to do the typing for you. -* Keyboard Macros:: Saving and re-executing typed characters -* Miscellaneous Commands:: Other miscellaneous commands. -@end menu - -This section describes Readline commands that may be bound to key -sequences. -@ifset BashFeatures -You can list your key bindings by executing -@w{@code{bind -P}} or, for a more terse format, suitable for an -@var{inputrc} file, @w{@code{bind -p}}. (@xref{Bash Builtins}.) -@end ifset -Command names without an accompanying key sequence are unbound by default. - -In the following descriptions, @dfn{point} refers to the current cursor -position, and @dfn{mark} refers to a cursor position saved by the -@code{set-mark} command. -The text between the point and mark is referred to as the @dfn{region}. - -@node Commands For Moving -@subsection Commands For Moving -@ftable @code -@item beginning-of-line (C-a) -Move to the start of the current line. - -@item end-of-line (C-e) -Move to the end of the line. - -@item forward-char (C-f) -Move forward a character. - -@item backward-char (C-b) -Move back a character. - -@item forward-word (M-f) -Move forward to the end of the next word. -Words are composed of letters and digits. - -@item backward-word (M-b) -Move back to the start of the current or previous word. -Words are composed of letters and digits. - -@ifset BashFeatures -@item shell-forward-word () -Move forward to the end of the next word. -Words are delimited by non-quoted shell metacharacters. - -@item shell-backward-word () -Move back to the start of the current or previous word. -Words are delimited by non-quoted shell metacharacters. -@end ifset - -@item clear-screen (C-l) -Clear the screen and redraw the current line, -leaving the current line at the top of the screen. - -@item redraw-current-line () -Refresh the current line. By default, this is unbound. - -@end ftable - -@node Commands For History -@subsection Commands For Manipulating The History - -@ftable @code -@item accept-line (Newline or Return) -@ifset BashFeatures -Accept the line regardless of where the cursor is. -If this line is -non-empty, add it to the history list according to the setting of -the @env{HISTCONTROL} and @env{HISTIGNORE} variables. -If this line is a modified history line, then restore the history line -to its original state. -@end ifset -@ifclear BashFeatures -Accept the line regardless of where the cursor is. -If this line is -non-empty, it may be added to the history list for future recall with -@code{add_history()}. -If this line is a modified history line, the history line is restored -to its original state. -@end ifclear - -@item previous-history (C-p) -Move `back' through the history list, fetching the previous command. - -@item next-history (C-n) -Move `forward' through the history list, fetching the next command. - -@item beginning-of-history (M-<) -Move to the first line in the history. - -@item end-of-history (M->) -Move to the end of the input history, i.e., the line currently -being entered. - -@item reverse-search-history (C-r) -Search backward starting at the current line and moving `up' through -the history as necessary. This is an incremental search. - -@item forward-search-history (C-s) -Search forward starting at the current line and moving `down' through -the the history as necessary. This is an incremental search. - -@item non-incremental-reverse-search-history (M-p) -Search backward starting at the current line and moving `up' -through the history as necessary using a non-incremental search -for a string supplied by the user. - -@item non-incremental-forward-search-history (M-n) -Search forward starting at the current line and moving `down' -through the the history as necessary using a non-incremental search -for a string supplied by the user. - -@item history-search-forward () -Search forward through the history for the string of characters -between the start of the current line and the point. -The search string must match at the beginning of a history line. -This is a non-incremental search. -By default, this command is unbound. - -@item history-search-backward () -Search backward through the history for the string of characters -between the start of the current line and the point. -The search string must match at the beginning of a history line. -This is a non-incremental search. -By default, this command is unbound. - -@item history-substr-search-forward () -Search forward through the history for the string of characters -between the start of the current line and the point. -The search string may match anywhere in a history line. -This is a non-incremental search. -By default, this command is unbound. - -@item history-substr-search-backward () -Search backward through the history for the string of characters -between the start of the current line and the point. -The search string may match anywhere in a history line. -This is a non-incremental search. -By default, this command is unbound. - -@item yank-nth-arg (M-C-y) -Insert the first argument to the previous command (usually -the second word on the previous line) at point. -With an argument @var{n}, -insert the @var{n}th word from the previous command (the words -in the previous command begin with word 0). A negative argument -inserts the @var{n}th word from the end of the previous command. -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 -previous history entry). -With a numeric argument, behave exactly like @code{yank-nth-arg}. -Successive calls to @code{yank-last-arg} move back through the history -list, inserting the last word (or the word specified by the argument to -the first call) of each line in turn. -Any numeric argument supplied to these successive calls determines -the direction to move through the history. A negative argument switches -the direction through the history (back or forward). -The history expansion facilities are used to extract the last argument, -as if the @samp{!$} history expansion had been specified. - -@end ftable - -@node Commands For Text -@subsection Commands For Changing Text - -@ftable @code -@item delete-char (C-d) -Delete the character at point. If point is at the -beginning of the line, there are no characters in the line, and -the last character typed was not bound to @code{delete-char}, then -return @sc{eof}. - -@item backward-delete-char (Rubout) -Delete the character behind the cursor. A numeric argument means -to kill the characters instead of deleting them. - -@item forward-backward-delete-char () -Delete the character under the cursor, unless the cursor is at the -end of the line, in which case the character behind the cursor is -deleted. By default, this is not bound to a key. - -@item quoted-insert (C-q or C-v) -Add the next character typed to the line verbatim. This is -how to insert key sequences like @kbd{C-q}, for example. - -@ifclear BashFeatures -@item tab-insert (M-@key{TAB}) -Insert a tab character. -@end ifclear - -@item self-insert (a, b, A, 1, !, @dots{}) -Insert yourself. - -@item transpose-chars (C-t) -Drag the character before the cursor forward over -the character at the cursor, moving the -cursor forward as well. If the insertion point -is at the end of the line, then this -transposes the last two characters of the line. -Negative arguments have no effect. - -@item transpose-words (M-t) -Drag the word before point past the word after point, -moving point past that word as well. -If the insertion point is at the end of the line, this transposes -the last two words on the line. - -@item upcase-word (M-u) -Uppercase the current (or following) word. With a negative argument, -uppercase the previous word, but do not move the cursor. - -@item downcase-word (M-l) -Lowercase the current (or following) word. With a negative argument, -lowercase the previous word, but do not move the cursor. - -@item capitalize-word (M-c) -Capitalize the current (or following) word. With a negative argument, -capitalize the previous word, but do not move the cursor. - -@item overwrite-mode () -Toggle overwrite mode. With an explicit positive numeric argument, -switches to overwrite mode. With an explicit non-positive numeric -argument, switches to insert mode. This command affects only -@code{emacs} mode; @code{vi} mode does overwrite differently. -Each call to @code{readline()} starts in insert mode. - -In overwrite mode, characters bound to @code{self-insert} replace -the text at point rather than pushing the text to the right. -Characters bound to @code{backward-delete-char} replace the character -before point with a space. - -By default, this command is unbound. - -@end ftable - -@node Commands For Killing -@subsection Killing And Yanking - -@ftable @code - -@item kill-line (C-k) -Kill the text from point to the end of the line. - -@item backward-kill-line (C-x Rubout) -Kill backward to the beginning of the line. - -@item unix-line-discard (C-u) -Kill backward from the cursor to the beginning of the current line. - -@item kill-whole-line () -Kill all characters on the current line, no matter where point is. -By default, this is unbound. - -@item kill-word (M-d) -Kill from point to the end of the current word, or if between -words, to the end of the next word. -Word boundaries are the same as @code{forward-word}. - -@item backward-kill-word (M-@key{DEL}) -Kill the word behind point. -Word boundaries are the same as @code{backward-word}. - -@ifset BashFeatures -@item shell-kill-word () -Kill from point to the end of the current word, or if between -words, to the end of the next word. -Word boundaries are the same as @code{shell-forward-word}. - -@item shell-backward-kill-word () -Kill the word behind point. -Word boundaries are the same as @code{shell-backward-word}. -@end ifset - -@item unix-word-rubout (C-w) -Kill the word behind point, using white space as a word boundary. -The killed text is saved on the kill-ring. - -@item unix-filename-rubout () -Kill the word behind point, using white space and the slash character -as the word boundaries. -The killed text is saved on the kill-ring. - -@item delete-horizontal-space () -Delete all spaces and tabs around point. By default, this is unbound. - -@item kill-region () -Kill the text in the current region. -By default, this command is unbound. - -@item copy-region-as-kill () -Copy the text in the region to the kill buffer, so it can be yanked -right away. By default, this command is unbound. - -@item copy-backward-word () -Copy the word before point to the kill buffer. -The word boundaries are the same as @code{backward-word}. -By default, this command is unbound. - -@item copy-forward-word () -Copy the word following point to the kill buffer. -The word boundaries are the same as @code{forward-word}. -By default, this command is unbound. - -@item yank (C-y) -Yank the top of the kill ring into the buffer at point. - -@item yank-pop (M-y) -Rotate the kill-ring, and yank the new top. You can only do this if -the prior command is @code{yank} or @code{yank-pop}. -@end ftable - -@node Numeric Arguments -@subsection Specifying Numeric Arguments -@ftable @code - -@item digit-argument (@kbd{M-0}, @kbd{M-1}, @dots{} @kbd{M--}) -Add this digit to the argument already accumulating, or start a new -argument. @kbd{M--} starts a negative argument. - -@item universal-argument () -This is another way to specify an argument. -If this command is followed by one or more digits, optionally with a -leading minus sign, those digits define the argument. -If the command is followed by digits, executing @code{universal-argument} -again ends the numeric argument, but is otherwise ignored. -As a special case, if this command is immediately followed by a -character that is neither a digit or minus sign, the argument count -for the next command is multiplied by four. -The argument count is initially one, so executing this function the -first time makes the argument count four, a second time makes the -argument count sixteen, and so on. -By default, this is not bound to a key. -@end ftable - -@node Commands For Completion -@subsection Letting Readline Type For You - -@ftable @code -@item complete (@key{TAB}) -Attempt to perform completion on the text before point. -The actual completion performed is application-specific. -@ifset BashFeatures -Bash attempts completion treating the text as a variable (if the -text begins with @samp{$}), username (if the text begins with -@samp{~}), hostname (if the text begins with @samp{@@}), or -command (including aliases and functions) in turn. If none -of these produces a match, filename completion is attempted. -@end ifset -@ifclear BashFeatures -The default is filename completion. -@end ifclear - -@item possible-completions (M-?) -List the possible completions of the text before point. -When displaying completions, Readline sets the number of columns used -for display to the value of @code{completion-display-width}, the value of -the environment variable @env{COLUMNS}, or the screen width, in that order. - -@item insert-completions (M-*) -Insert all completions of the text before point that would have -been generated by @code{possible-completions}. - -@item menu-complete () -Similar to @code{complete}, but replaces the word to be completed -with a single match from the list of possible completions. -Repeated execution of @code{menu-complete} steps through the list -of possible completions, inserting each match in turn. -At the end of the list of completions, the bell is rung -(subject to the setting of @code{bell-style}) -and the original text is restored. -An argument of @var{n} moves @var{n} positions forward in the list -of matches; a negative argument may be used to move backward -through the list. -This command is intended to be bound to @key{TAB}, but is unbound -by default. - -@item menu-complete-backward () -Identical to @code{menu-complete}, but moves backward through the list -of possible completions, as if @code{menu-complete} had been given a -negative argument. - -@item delete-char-or-list () -Deletes the character under the cursor if not at the beginning or -end of the line (like @code{delete-char}). -If at the end of the line, behaves identically to -@code{possible-completions}. -This command is unbound by default. - -@ifset BashFeatures -@item complete-filename (M-/) -Attempt filename completion on the text before point. - -@item possible-filename-completions (C-x /) -List the possible completions of the text before point, -treating it as a filename. - -@item complete-username (M-~) -Attempt completion on the text before point, treating -it as a username. - -@item possible-username-completions (C-x ~) -List the possible completions of the text before point, -treating it as a username. - -@item complete-variable (M-$) -Attempt completion on the text before point, treating -it as a shell variable. - -@item possible-variable-completions (C-x $) -List the possible completions of the text before point, -treating it as a shell variable. - -@item complete-hostname (M-@@) -Attempt completion on the text before point, treating -it as a hostname. - -@item possible-hostname-completions (C-x @@) -List the possible completions of the text before point, -treating it as a hostname. - -@item complete-command (M-!) -Attempt completion on the text before point, treating -it as a command name. Command completion attempts to -match the text against aliases, reserved words, shell -functions, shell builtins, and finally executable filenames, -in that order. - -@item possible-command-completions (C-x !) -List the possible completions of the text before point, -treating it as a command name. - -@item dynamic-complete-history (M-@key{TAB}) -Attempt completion on the text before point, comparing -the text against lines from the history list for possible -completion matches. - -@item dabbrev-expand () -Attempt menu completion on the text before point, comparing -the text against lines from the history list for possible -completion matches. - -@item complete-into-braces (M-@{) -Perform filename completion and insert the list of possible completions -enclosed within braces so the list is available to the shell -(@pxref{Brace Expansion}). - -@end ifset -@end ftable - -@node Keyboard Macros -@subsection Keyboard Macros -@ftable @code - -@item start-kbd-macro (C-x () -Begin saving the characters typed into the current keyboard macro. - -@item end-kbd-macro (C-x )) -Stop saving the characters typed into the current keyboard macro -and save the definition. - -@item call-last-kbd-macro (C-x e) -Re-execute the last keyboard macro defined, by making the characters -in the macro appear as if typed at the keyboard. - -@end ftable - -@node Miscellaneous Commands -@subsection Some Miscellaneous Commands -@ftable @code - -@item re-read-init-file (C-x C-r) -Read in the contents of the @var{inputrc} file, and incorporate -any bindings or variable assignments found there. - -@item abort (C-g) -Abort the current editing command and -ring the terminal's bell (subject to the setting of -@code{bell-style}). - -@item do-uppercase-version (M-a, M-b, M-@var{x}, @dots{}) -If the metafied character @var{x} is lowercase, run the command -that is bound to the corresponding uppercase character. - -@item prefix-meta (@key{ESC}) -Metafy the next character typed. This is for keyboards -without a meta key. Typing @samp{@key{ESC} f} is equivalent to typing -@kbd{M-f}. - -@item undo (C-_ or C-x C-u) -Incremental undo, separately remembered for each line. - -@item revert-line (M-r) -Undo all changes made to this line. This is like executing the @code{undo} -command enough times to get back to the beginning. - -@ifset BashFeatures -@item tilde-expand (M-&) -@end ifset -@ifclear BashFeatures -@item tilde-expand (M-~) -@end ifclear -Perform tilde expansion on the current word. - -@item set-mark (C-@@) -Set the mark to the point. If a -numeric argument is supplied, the mark is set to that position. - -@item exchange-point-and-mark (C-x C-x) -Swap the point with the mark. The current cursor position is set to -the saved position, and the old cursor position is saved as the mark. - -@item character-search (C-]) -A character is read and point is moved to the next occurrence of that -character. A negative count searches for previous occurrences. - -@item character-search-backward (M-C-]) -A character is read and point is moved to the previous occurrence -of that character. A negative count searches for subsequent -occurrences. - -@item skip-csi-sequence () -Read enough characters to consume a multi-key sequence such as those -defined for keys like Home and End. Such sequences begin with a -Control Sequence Indicator (CSI), usually ESC-[. If this sequence is -bound to "\e[", keys producing such sequences will have no effect -unless explicitly bound to a readline command, instead of inserting -stray characters into the editing buffer. This is unbound by default, -but usually bound to ESC-[. - -@item insert-comment (M-#) -Without a numeric argument, the value of the @code{comment-begin} -variable is inserted at the beginning of the current line. -If a numeric argument is supplied, this command acts as a toggle: if -the characters at the beginning of the line do not match the value -of @code{comment-begin}, the value is inserted, otherwise -the characters in @code{comment-begin} are deleted from the beginning of -the line. -In either case, the line is accepted as if a newline had been typed. -@ifset BashFeatures -The default value of @code{comment-begin} causes this command -to make the current line a shell comment. -If a numeric argument causes the comment character to be removed, the line -will be executed by the shell. -@end ifset - -@item dump-functions () -Print all of the functions and their key bindings to the -Readline output stream. If a numeric argument is supplied, -the output is formatted in such a way that it can be made part -of an @var{inputrc} file. This command is unbound by default. - -@item dump-variables () -Print all of the settable variables and their values to the -Readline output stream. If a numeric argument is supplied, -the output is formatted in such a way that it can be made part -of an @var{inputrc} file. This command is unbound by default. - -@item dump-macros () -Print all of the Readline key sequences bound to macros and the -strings they output. If a numeric argument is supplied, -the output is formatted in such a way that it can be made part -of an @var{inputrc} file. This command is unbound by default. - -@ifset BashFeatures -@item glob-complete-word (M-g) -The word before point is treated as a pattern for pathname expansion, -with an asterisk implicitly appended. This pattern is used to -generate a list of matching file names for possible completions. - -@item glob-expand-word (C-x *) -The word before point is treated as a pattern for pathname expansion, -and the list of matching file names is inserted, replacing the word. -If a numeric argument is supplied, a @samp{*} is appended before -pathname expansion. - -@item glob-list-expansions (C-x g) -The list of expansions that would have been generated by -@code{glob-expand-word} is displayed, and the line is redrawn. -If a numeric argument is supplied, a @samp{*} is appended before -pathname expansion. - -@item display-shell-version (C-x C-v) -Display version information about the current instance of Bash. - -@item shell-expand-line (M-C-e) -Expand the line as the shell does. -This performs alias and history expansion as well as all of the shell -word expansions (@pxref{Shell Expansions}). - -@item history-expand-line (M-^) -Perform history expansion on the current line. - -@item magic-space () -Perform history expansion on the current line and insert a space -(@pxref{History Interaction}). - -@item alias-expand-line () -Perform alias expansion on the current line (@pxref{Aliases}). - -@item history-and-alias-expand-line () -Perform history and alias expansion on the current line. - -@item insert-last-argument (M-. or M-_) -A synonym for @code{yank-last-arg}. - -@item operate-and-get-next (C-o) -Accept the current line for execution and fetch the next line -relative to the current line from the history for editing. Any -argument is ignored. - -@item edit-and-execute-command (C-xC-e) -Invoke an editor on the current command line, and execute the result as shell -commands. -Bash attempts to invoke -@code{$VISUAL}, @code{$EDITOR}, and @code{emacs} -as the editor, in that order. - -@end ifset - -@ifclear BashFeatures -@item emacs-editing-mode (C-e) -When in @code{vi} command mode, this causes a switch to @code{emacs} -editing mode. - -@item vi-editing-mode (M-C-j) -When in @code{emacs} editing mode, this causes a switch to @code{vi} -editing mode. - -@end ifclear - -@end ftable - -@node Readline vi Mode -@section Readline vi Mode - -While the Readline library does not have a full set of @code{vi} -editing functions, it does contain enough to allow simple editing -of the line. The Readline @code{vi} mode behaves as specified in -the @sc{posix} standard. - -@ifset BashFeatures -In order to switch interactively between @code{emacs} and @code{vi} -editing modes, use the @samp{set -o emacs} and @samp{set -o vi} -commands (@pxref{The Set Builtin}). -@end ifset -@ifclear BashFeatures -In order to switch interactively between @code{emacs} and @code{vi} -editing modes, use the command @kbd{M-C-j} (bound to emacs-editing-mode -when in @code{vi} mode and to vi-editing-mode in @code{emacs} mode). -@end ifclear -The Readline default is @code{emacs} mode. - -When you enter a line in @code{vi} mode, you are already placed in -`insertion' mode, as if you had typed an @samp{i}. Pressing @key{ESC} -switches you into `command' mode, where you can edit the text of the -line with the standard @code{vi} movement keys, move to previous -history lines with @samp{k} and subsequent lines with @samp{j}, and -so forth. - -@ifset BashFeatures -@node Programmable Completion -@section Programmable Completion -@cindex programmable completion - -When word completion is attempted for an argument to a command for -which a completion specification (a @var{compspec}) has been defined -using the @code{complete} builtin (@pxref{Programmable Completion Builtins}), -the programmable completion facilities are invoked. - -First, the command name is identified. -If a compspec has been defined for that command, the -compspec is used to generate the list of possible completions for the word. -If the command word is the empty string (completion attempted at the -beginning of an empty line), any compspec defined with -the @option{-E} option to @code{complete} is used. -If the command word is a full pathname, a compspec for the full -pathname is searched for first. -If no compspec is found for the full pathname, an attempt is made to -find a compspec for the portion following the final slash. -If those searches do not result in a compspec, any compspec defined with -the @option{-D} option to @code{complete} is used as the default. - -Once a compspec has been found, it is used to generate the list of -matching words. -If a compspec is not found, the default Bash completion -described above (@pxref{Commands For Completion}) is performed. - -First, the actions specified by the compspec are used. -Only matches which are prefixed by the word being completed are -returned. -When the @option{-f} or @option{-d} option is used for filename or -directory name completion, the shell variable @env{FIGNORE} is -used to filter the matches. -@xref{Bash Variables}, for a description of @env{FIGNORE}. - -Any completions specified by a filename expansion pattern to the -@option{-G} option are generated next. -The words generated by the pattern need not match the word being completed. -The @env{GLOBIGNORE} shell variable is not used to filter the matches, -but the @env{FIGNORE} shell variable is used. - -Next, the string specified as the argument to the @option{-W} option -is considered. -The string is first split using the characters in the @env{IFS} -special variable as delimiters. -Shell quoting is honored. -Each word is then expanded using -brace expansion, tilde expansion, parameter and variable expansion, -command substitution, and arithmetic expansion, -as described above (@pxref{Shell Expansions}). -The results are split using the rules described above -(@pxref{Word Splitting}). -The results of the expansion are prefix-matched against the word being -completed, and the matching words become the possible completions. - -After these matches have been generated, any shell function or command -specified with the @option{-F} and @option{-C} options is invoked. -When the command or function is invoked, the @env{COMP_LINE}, -@env{COMP_POINT}, @env{COMP_KEY}, and @env{COMP_TYPE} variables are -assigned values as described above (@pxref{Bash Variables}). -If a shell function is being invoked, the @env{COMP_WORDS} and -@env{COMP_CWORD} variables are also set. -When the function or command is invoked, the first argument is the -name of the command whose arguments are being completed, the -second argument is the word being completed, and the third argument -is the word preceding the word being completed on the current command line. -No filtering of the generated completions against the word being completed -is performed; the function or command has complete freedom in generating -the matches. - -Any function specified with @option{-F} is invoked first. -The function may use any of the shell facilities, including the -@code{compgen} and @code{compopt} builtins described below -(@pxref{Programmable Completion Builtins}), to generate the matches. -It must put the possible completions in the @env{COMPREPLY} array -variable. - -Next, any command specified with the @option{-C} option is invoked -in an environment equivalent to command substitution. -It should print a list of completions, one per line, to -the standard output. -Backslash may be used to escape a newline, if necessary. - -After all of the possible completions are generated, any filter -specified with the @option{-X} option is applied to the list. -The filter is a pattern as used for pathname expansion; a @samp{&} -in the pattern is replaced with the text of the word being completed. -A literal @samp{&} may be escaped with a backslash; the backslash -is removed before attempting a match. -Any completion that matches the pattern will be removed from the list. -A leading @samp{!} negates the pattern; in this case any completion -not matching the pattern will be removed. - -Finally, any prefix and suffix specified with the @option{-P} and @option{-S} -options are added to each member of the completion list, and the result is -returned to the Readline completion code as the list of possible -completions. - -If the previously-applied actions do not generate any matches, and the -@option{-o dirnames} option was supplied to @code{complete} when the -compspec was defined, directory name completion is attempted. - -If the @option{-o plusdirs} option was supplied to @code{complete} when -the compspec was defined, directory name completion is attempted and any -matches are added to the results of the other actions. - -By default, if a compspec is found, whatever it generates is returned to -the completion code as the full set of possible completions. -The default Bash completions are not attempted, and the Readline default -of filename completion is disabled. -If the @option{-o bashdefault} option was supplied to @code{complete} when -the compspec was defined, the default Bash completions are attempted -if the compspec generates no matches. -If the @option{-o default} option was supplied to @code{complete} when the -compspec was defined, Readline's default completion will be performed -if the compspec (and, if attempted, the default Bash completions) -generate no matches. - -When a compspec indicates that directory name completion is desired, -the programmable completion functions force Readline to append a slash -to completed names which are symbolic links to directories, subject to -the value of the @var{mark-directories} Readline variable, regardless -of the setting of the @var{mark-symlinked-directories} Readline variable. - -There is some support for dynamically modifying completions. This is -most useful when used in combination with a default completion specified -with @option{-D}. It's possible for shell functions executed as completion -handlers to indicate that completion should be retried by returning an -exit status of 124. If a shell function returns 124, and changes -the compspec associated with the command on which completion is being -attempted (supplied as the first argument when the function is executed), -programmable completion restarts from the beginning, with an -attempt to find a new compspec for that command. This allows a set of -completions to be built dynamically as completion is attempted, rather than -being loaded all at once. - -For instance, assuming that there is a library of compspecs, each kept in a -file corresponding to the name of the command, the following default -completion function would load completions dynamically: - -@example -_completion_loader() -@{ - . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124 -@} -complete -D -F _completion_loader -@end example - -@node Programmable Completion Builtins -@section Programmable Completion Builtins -@cindex completion builtins - -Two builtin commands are available to manipulate the programmable completion -facilities. - -@table @code -@item compgen -@btindex compgen -@example -@code{compgen [@var{option}] [@var{word}]} -@end example - -Generate possible completion matches for @var{word} according to -the @var{option}s, which may be any option accepted by the -@code{complete} -builtin with the exception of @option{-p} and @option{-r}, and write -the matches to the standard output. -When using the @option{-F} or @option{-C} options, the various shell variables -set by the programmable completion facilities, while available, will not -have useful values. - -The matches will be generated in the same way as if the programmable -completion code had generated them directly from a completion specification -with the same flags. -If @var{word} is specified, only those completions matching @var{word} -will be displayed. - -The return value is true unless an invalid option is supplied, or no -matches were generated. - -@item complete -@btindex complete -@example -@code{complete [-abcdefgjksuv] [-o @var{comp-option}] [-DE] [-A @var{action}] [-G @var{globpat}] [-W @var{wordlist}] -[-F @var{function}] [-C @var{command}] [-X @var{filterpat}] -[-P @var{prefix}] [-S @var{suffix}] @var{name} [@var{name} @dots{}]} -@code{complete -pr [-DE] [@var{name} @dots{}]} -@end example - -Specify how arguments to each @var{name} should be completed. -If the @option{-p} option is supplied, or if no options are supplied, existing -completion specifications are printed in a way that allows them to be -reused as input. -The @option{-r} option removes a completion specification for -each @var{name}, or, if no @var{name}s are supplied, all -completion specifications. -The @option{-D} option indicates that the remaining options and actions should -apply to the ``default'' command completion; that is, completion attempted -on a command for which no completion has previously been defined. -The @option{-E} option indicates that the remaining options and actions should -apply to ``empty'' command completion; that is, completion attempted on a -blank line. - -The process of applying these completion specifications when word completion -is attempted is described above (@pxref{Programmable Completion}). The -@option{-D} option takes precedence over @option{-E}. - -Other options, if specified, have the following meanings. -The arguments to the @option{-G}, @option{-W}, and @option{-X} options -(and, if necessary, the @option{-P} and @option{-S} options) -should be quoted to protect them from expansion before the -@code{complete} builtin is invoked. - - -@table @code -@item -o @var{comp-option} -The @var{comp-option} controls several aspects of the compspec's behavior -beyond the simple generation of completions. -@var{comp-option} may be one of: - -@table @code - -@item bashdefault -Perform the rest of the default Bash completions if the compspec -generates no matches. - -@item default -Use Readline's default filename completion if the compspec generates -no matches. - -@item dirnames -Perform directory name completion if the compspec generates no matches. - -@item filenames -Tell Readline that the compspec generates filenames, so it can perform any -filename-specific processing (like adding a slash to directory names -quoting special characters, or suppressing trailing spaces). -This option is intended to be used with 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} -The @var{action} may be one of the following to generate a list of possible -completions: - -@table @code -@item alias -Alias names. May also be specified as @option{-a}. - -@item arrayvar -Array variable names. - -@item binding -Readline key binding names (@pxref{Bindable Readline Commands}). - -@item builtin -Names of shell builtin commands. May also be specified as @option{-b}. - -@item command -Command names. May also be specified as @option{-c}. - -@item directory -Directory names. May also be specified as @option{-d}. - -@item disabled -Names of disabled shell builtins. - -@item enabled -Names of enabled shell builtins. - -@item export -Names of exported shell variables. May also be specified as @option{-e}. - -@item file -File names. May also be specified as @option{-f}. - -@item function -Names of shell functions. - -@item group -Group names. May also be specified as @option{-g}. - -@item helptopic -Help topics as accepted by the @code{help} builtin (@pxref{Bash Builtins}). - -@item hostname -Hostnames, as taken from the file specified by the -@env{HOSTFILE} shell variable (@pxref{Bash Variables}). - -@item job -Job names, if job control is active. May also be specified as @option{-j}. - -@item keyword -Shell reserved words. May also be specified as @option{-k}. - -@item running -Names of running jobs, if job control is active. - -@item service -Service names. May also be specified as @option{-s}. - -@item setopt -Valid arguments for the @option{-o} option to the @code{set} builtin -(@pxref{The Set Builtin}). - -@item shopt -Shell option names as accepted by the @code{shopt} builtin -(@pxref{Bash Builtins}). - -@item signal -Signal names. - -@item stopped -Names of stopped jobs, if job control is active. - -@item user -User names. May also be specified as @option{-u}. - -@item variable -Names of all shell variables. May also be specified as @option{-v}. -@end table - -@item -C @var{command} -@var{command} is executed in a subshell environment, and its output is -used as the possible completions. - -@item -F @var{function} -The shell function @var{function} is executed in the current shell -environment. -When it finishes, the possible completions are retrieved from the value -of the @env{COMPREPLY} array variable. - -@item -G @var{globpat} -The filename expansion pattern @var{globpat} is expanded to generate -the possible completions. - -@item -P @var{prefix} -@var{prefix} is added at the beginning of each possible completion -after all other options have been applied. - -@item -S @var{suffix} -@var{suffix} is appended to each possible completion -after all other options have been applied. - -@item -W @var{wordlist} -The @var{wordlist} is split using the characters in the -@env{IFS} special variable as delimiters, and each resultant word -is expanded. -The possible completions are the members of the resultant list which -match the word being completed. - -@item -X @var{filterpat} -@var{filterpat} is a pattern as used for filename expansion. -It is applied to the list of possible completions generated by the -preceding options and arguments, and each completion matching -@var{filterpat} is removed from the list. -A leading @samp{!} in @var{filterpat} negates the pattern; in this -case, any completion not matching @var{filterpat} is removed. -@end table - -The return value is true unless an invalid option is supplied, an option -other than @option{-p} or @option{-r} is supplied without a @var{name} -argument, an attempt is made to remove a completion specification for -a @var{name} for which no specification exists, or -an error occurs adding a completion specification. - -@item compopt -@btindex compopt -@example -@code{compopt} [-o @var{option}] [-DE] [+o @var{option}] [@var{name}] -@end example -Modify completion options for each @var{name} according to the -@var{option}s, or for the currently-executing completion if no @var{name}s -are supplied. -If no @var{option}s are given, display the completion options for each -@var{name} or the current completion. -The possible values of @var{option} are those valid for the @code{complete} -builtin described above. -The @option{-D} option indicates that the remaining options should -apply to the ``default'' command completion; that is, completion attempted -on a command for which no completion has previously been defined. -The @option{-E} option indicates that the remaining options should -apply to ``empty'' command completion; that is, completion attempted on a -blank line. - -The @option{-D} option takes precedence over @option{-E}. - -The return value is true unless an invalid option is supplied, an attempt -is made to modify the options for a @var{name} for which no completion -specification exists, or an output error occurs. - -@end table - -@end ifset diff --git a/lib/readline/funmap.c~ b/lib/readline/funmap.c~ deleted file mode 100644 index 86e375f6..00000000 --- a/lib/readline/funmap.c~ +++ /dev/null @@ -1,263 +0,0 @@ -/* funmap.c -- attach names to functions. */ - -/* Copyright (C) 1987-2010 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library (Readline), a library - for reading lines of text with interactive input and history editing. - - Readline 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 3 of the License, or - (at your option) any later version. - - Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>. -*/ - -#define READLINE_LIBRARY - -#if defined (HAVE_CONFIG_H) -# include <config.h> -#endif - -#if !defined (BUFSIZ) -#include <stdio.h> -#endif /* BUFSIZ */ - -#if defined (HAVE_STDLIB_H) -# include <stdlib.h> -#else -# include "ansi_stdlib.h" -#endif /* HAVE_STDLIB_H */ - -#include "rlconf.h" -#include "readline.h" - -#include "xmalloc.h" - -#ifdef __STDC__ -typedef int QSFUNC (const void *, const void *); -#else -typedef int QSFUNC (); -#endif - -extern int _rl_qsort_string_compare PARAMS((char **, char **)); - -FUNMAP **funmap; -static int funmap_size; -static int funmap_entry; - -/* After initializing the function map, this is the index of the first - program specific function. */ -int funmap_program_specific_entry_start; - -static const FUNMAP default_funmap[] = { - { "abort", rl_abort }, - { "accept-line", rl_newline }, - { "arrow-key-prefix", rl_arrow_keys }, - { "backward-byte", rl_backward_byte }, - { "backward-char", rl_backward_char }, - { "backward-delete-char", rl_rubout }, - { "backward-kill-line", rl_backward_kill_line }, - { "backward-kill-word", rl_backward_kill_word }, - { "backward-word", rl_backward_word }, - { "beginning-of-history", rl_beginning_of_history }, - { "beginning-of-line", rl_beg_of_line }, - { "call-last-kbd-macro", rl_call_last_kbd_macro }, - { "capitalize-word", rl_capitalize_word }, - { "character-search", rl_char_search }, - { "character-search-backward", rl_backward_char_search }, - { "clear-screen", rl_clear_screen }, - { "complete", rl_complete }, - { "copy-backward-word", rl_copy_backward_word }, - { "copy-forward-word", rl_copy_forward_word }, - { "copy-region-as-kill", rl_copy_region_to_kill }, - { "delete-char", rl_delete }, - { "delete-char-or-list", rl_delete_or_show_completions }, - { "delete-horizontal-space", rl_delete_horizontal_space }, - { "digit-argument", rl_digit_argument }, - { "do-lowercase-version", rl_do_lowercase_version }, - { "downcase-word", rl_downcase_word }, - { "dump-functions", rl_dump_functions }, - { "dump-macros", rl_dump_macros }, - { "dump-variables", rl_dump_variables }, - { "emacs-editing-mode", rl_emacs_editing_mode }, - { "end-kbd-macro", rl_end_kbd_macro }, - { "end-of-history", rl_end_of_history }, - { "end-of-line", rl_end_of_line }, - { "exchange-point-and-mark", rl_exchange_point_and_mark }, - { "forward-backward-delete-char", rl_rubout_or_delete }, - { "forward-byte", rl_forward_byte }, - { "forward-char", rl_forward_char }, - { "forward-search-history", rl_forward_search_history }, - { "forward-word", rl_forward_word }, - { "history-search-backward", rl_history_search_backward }, - { "history-search-forward", rl_history_search_forward }, - { "insert-comment", rl_insert_comment }, - { "insert-completions", rl_insert_completions }, - { "kill-whole-line", rl_kill_full_line }, - { "kill-line", rl_kill_line }, - { "kill-region", rl_kill_region }, - { "kill-word", rl_kill_word }, - { "menu-complete", rl_menu_complete }, - { "menu-complete-backward", rl_backward_menu_complete }, - { "next-history", rl_get_next_history }, - { "non-incremental-forward-search-history", rl_noninc_forward_search }, - { "non-incremental-reverse-search-history", rl_noninc_reverse_search }, - { "non-incremental-forward-search-history-again", rl_noninc_forward_search_again }, - { "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again }, - { "old-menu-complete", rl_old_menu_complete }, - { "overwrite-mode", rl_overwrite_mode }, -#ifdef __CYGWIN__ - { "paste-from-clipboard", rl_paste_from_clipboard }, -#endif - { "possible-completions", rl_possible_completions }, - { "previous-history", rl_get_previous_history }, - { "quoted-insert", rl_quoted_insert }, - { "re-read-init-file", rl_re_read_init_file }, - { "redraw-current-line", rl_refresh_line}, - { "reverse-search-history", rl_reverse_search_history }, - { "revert-line", rl_revert_line }, - { "self-insert", rl_insert }, - { "set-mark", rl_set_mark }, - { "skip-csi-sequence", rl_skip_csi_sequence }, - { "start-kbd-macro", rl_start_kbd_macro }, - { "tab-insert", rl_tab_insert }, - { "tilde-expand", rl_tilde_expand }, - { "transpose-chars", rl_transpose_chars }, - { "transpose-words", rl_transpose_words }, - { "tty-status", rl_tty_status }, - { "undo", rl_undo_command }, - { "universal-argument", rl_universal_argument }, - { "unix-filename-rubout", rl_unix_filename_rubout }, - { "unix-line-discard", rl_unix_line_discard }, - { "unix-word-rubout", rl_unix_word_rubout }, - { "upcase-word", rl_upcase_word }, - { "yank", rl_yank }, - { "yank-last-arg", rl_yank_last_arg }, - { "yank-nth-arg", rl_yank_nth_arg }, - { "yank-pop", rl_yank_pop }, - -#if defined (VI_MODE) - { "vi-append-eol", rl_vi_append_eol }, - { "vi-append-mode", rl_vi_append_mode }, - { "vi-arg-digit", rl_vi_arg_digit }, - { "vi-back-to-indent", rl_vi_back_to_indent }, - { "vi-backward-bigword", rl_vi_bWord }, - { "vi-backward-word", rl_vi_bword }, - { "vi-bWord", rl_vi_bWord }, - { "vi-bword", rl_vi_bword }, - { "vi-change-case", rl_vi_change_case }, - { "vi-change-char", rl_vi_change_char }, - { "vi-change-to", rl_vi_change_to }, - { "vi-char-search", rl_vi_char_search }, - { "vi-column", rl_vi_column }, - { "vi-complete", rl_vi_complete }, - { "vi-delete", rl_vi_delete }, - { "vi-delete-to", rl_vi_delete_to }, - { "vi-eWord", rl_vi_eWord }, - { "vi-editing-mode", rl_vi_editing_mode }, - { "vi-end-bigword", rl_vi_eWord }, - { "vi-end-word", rl_vi_end_word }, - { "vi-eof-maybe", rl_vi_eof_maybe }, - { "vi-eword", rl_vi_eword }, - { "vi-fWord", rl_vi_fWord }, - { "vi-fetch-history", rl_vi_fetch_history }, - { "vi-first-print", rl_vi_first_print }, - { "vi-forward-bigword", rl_vi_fWord }, - { "vi-forward-word", rl_vi_fword }, - { "vi-fword", rl_vi_fword }, - { "vi-goto-mark", rl_vi_goto_mark }, - { "vi-insert-beg", rl_vi_insert_beg }, - { "vi-insertion-mode", rl_vi_insertion_mode }, - { "vi-match", rl_vi_match }, - { "vi-movement-mode", rl_vi_movement_mode }, - { "vi-next-word", rl_vi_next_word }, - { "vi-overstrike", rl_vi_overstrike }, - { "vi-overstrike-delete", rl_vi_overstrike_delete }, - { "vi-prev-word", rl_vi_prev_word }, - { "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 }, - { "vi-subst", rl_vi_subst }, - { "vi-tilde-expand", rl_vi_tilde_expand }, - { "vi-yank-arg", rl_vi_yank_arg }, - { "vi-yank-to", rl_vi_yank_to }, -#endif /* VI_MODE */ - - {(char *)NULL, (rl_command_func_t *)NULL } -}; - -int -rl_add_funmap_entry (name, function) - const char *name; - rl_command_func_t *function; -{ - if (funmap_entry + 2 >= funmap_size) - { - funmap_size += 64; - funmap = (FUNMAP **)xrealloc (funmap, funmap_size * sizeof (FUNMAP *)); - } - - funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP)); - funmap[funmap_entry]->name = name; - funmap[funmap_entry]->function = function; - - funmap[++funmap_entry] = (FUNMAP *)NULL; - return funmap_entry; -} - -static int funmap_initialized; - -/* Make the funmap contain all of the default entries. */ -void -rl_initialize_funmap () -{ - register int i; - - if (funmap_initialized) - return; - - for (i = 0; default_funmap[i].name; i++) - rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function); - - funmap_initialized = 1; - funmap_program_specific_entry_start = i; -} - -/* Produce a NULL terminated array of known function names. The array - is sorted. The array itself is allocated, but not the strings inside. - You should free () the array when you done, but not the pointrs. */ -const char ** -rl_funmap_names () -{ - const char **result; - int result_size, result_index; - - /* Make sure that the function map has been initialized. */ - rl_initialize_funmap (); - - for (result_index = result_size = 0, result = (const char **)NULL; funmap[result_index]; result_index++) - { - if (result_index + 2 > result_size) - { - result_size += 20; - result = (const char **)xrealloc (result, result_size * sizeof (char *)); - } - - result[result_index] = funmap[result_index]->name; - result[result_index + 1] = (char *)NULL; - } - - qsort (result, result_index, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare); - return (result); -} diff --git a/lib/readline/histfile.c~ b/lib/readline/histfile.c~ deleted file mode 100644 index f3dbe7fa..00000000 --- a/lib/readline/histfile.c~ +++ /dev/null @@ -1,581 +0,0 @@ -/* histfile.c - functions to manipulate the history file. */ - -/* Copyright (C) 1989-2010 Free Software Foundation, Inc. - - This file contains the GNU History Library (History), a set of - routines for managing the text of previously typed lines. - - History 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 3 of the License, or - (at your option) any later version. - - History 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 History. If not, see <http://www.gnu.org/licenses/>. -*/ - -/* The goal is to make the implementation transparent, so that you - don't have to know what data types are used, just what functions - you can call. I think I have done that. */ - -#define READLINE_LIBRARY - -#if defined (__TANDEM) -# include <floss.h> -#endif - -#if defined (HAVE_CONFIG_H) -# include <config.h> -#endif - -#include <stdio.h> - -#include <sys/types.h> -#if ! defined (_MINIX) && defined (HAVE_SYS_FILE_H) -# include <sys/file.h> -#endif -#include "posixstat.h" -#include <fcntl.h> - -#if defined (HAVE_STDLIB_H) -# include <stdlib.h> -#else -# include "ansi_stdlib.h" -#endif /* HAVE_STDLIB_H */ - -#if defined (HAVE_UNISTD_H) -# include <unistd.h> -#endif - -#include <ctype.h> - -#if defined (__EMX__) -# undef HAVE_MMAP -#endif - -#ifdef HISTORY_USE_MMAP -# include <sys/mman.h> - -# ifdef MAP_FILE -# define MAP_RFLAGS (MAP_FILE|MAP_PRIVATE) -# define MAP_WFLAGS (MAP_FILE|MAP_SHARED) -# else -# define MAP_RFLAGS MAP_PRIVATE -# define MAP_WFLAGS MAP_SHARED -# endif - -# ifndef MAP_FAILED -# define MAP_FAILED ((void *)-1) -# endif - -#endif /* HISTORY_USE_MMAP */ - -/* If we're compiling for __EMX__ (OS/2) or __CYGWIN__ (cygwin32 environment - on win 95/98/nt), we want to open files with O_BINARY mode so that there - is no \n -> \r\n conversion performed. On other systems, we don't want to - mess around with O_BINARY at all, so we ensure that it's defined to 0. */ -#if defined (__EMX__) || defined (__CYGWIN__) -# ifndef O_BINARY -# define O_BINARY 0 -# endif -#else /* !__EMX__ && !__CYGWIN__ */ -# undef O_BINARY -# define O_BINARY 0 -#endif /* !__EMX__ && !__CYGWIN__ */ - -#include <errno.h> -#if !defined (errno) -extern int errno; -#endif /* !errno */ - -#include "history.h" -#include "histlib.h" - -#include "rlshell.h" -#include "xmalloc.h" - -/* If non-zero, we write timestamps to the history file in history_do_write() */ -int history_write_timestamps = 0; - -/* Does S look like the beginning of a history timestamp entry? Placeholder - for more extensive tests. */ -#define HIST_TIMESTAMP_START(s) (*(s) == history_comment_char && isdigit ((s)[1]) ) - -/* Return the string that should be used in the place of this - filename. This only matters when you don't specify the - filename to read_history (), or write_history (). */ -static char * -history_filename (filename) - const char *filename; -{ - char *return_val; - const char *home; - int home_len; - - return_val = filename ? savestring (filename) : (char *)NULL; - - if (return_val) - return (return_val); - - home = sh_get_env_value ("HOME"); - - if (home == 0) - return (NULL); - else - home_len = strlen (home); - - return_val = (char *)xmalloc (2 + home_len + 8); /* strlen(".history") == 8 */ - strcpy (return_val, home); - return_val[home_len] = '/'; -#if defined (__MSDOS__) - strcpy (return_val + home_len + 1, "_history"); -#else - strcpy (return_val + home_len + 1, ".history"); -#endif - - return (return_val); -} - -static char * -history_backupfile (filename) - const char *filename; -{ - char *ret; - size_t len; - - len = strlen (filename); - ret = xmalloc (len + 2); - strcpy (ret, filename); - ret[len] = '-'; - ret[len+1] = '\0'; - return ret; -} - -/* Add the contents of FILENAME to the history list, a line at a time. - If FILENAME is NULL, then read from ~/.history. Returns 0 if - successful, or errno if not. */ -int -read_history (filename) - const char *filename; -{ - return (read_history_range (filename, 0, -1)); -} - -/* Read a range of lines from FILENAME, adding them to the history list. - Start reading at the FROM'th line and end at the TO'th. If FROM - is zero, start at the beginning. If TO is less than FROM, read - until the end of the file. If FILENAME is NULL, then read from - ~/.history. Returns 0 if successful, or errno if not. */ -int -read_history_range (filename, from, to) - const char *filename; - int from, to; -{ - register char *line_start, *line_end, *p; - char *input, *buffer, *bufend, *last_ts; - int file, current_line, chars_read; - struct stat finfo; - size_t file_size; -#if defined (EFBIG) - int overflow_errno = EFBIG; -#elif defined (EOVERFLOW) - int overflow_errno = EOVERFLOW; -#else - int overflow_errno = EIO; -#endif - - buffer = last_ts = (char *)NULL; - input = history_filename (filename); - file = input ? open (input, O_RDONLY|O_BINARY, 0666) : -1; - - if ((file < 0) || (fstat (file, &finfo) == -1)) - goto error_and_exit; - - file_size = (size_t)finfo.st_size; - - /* check for overflow on very large files */ - if (file_size != finfo.st_size || file_size + 1 < file_size) - { - errno = overflow_errno; - goto error_and_exit; - } - -#ifdef HISTORY_USE_MMAP - /* We map read/write and private so we can change newlines to NULs without - affecting the underlying object. */ - buffer = (char *)mmap (0, file_size, PROT_READ|PROT_WRITE, MAP_RFLAGS, file, 0); - if ((void *)buffer == MAP_FAILED) - { - errno = overflow_errno; - goto error_and_exit; - } - chars_read = file_size; -#else - buffer = (char *)malloc (file_size + 1); - if (buffer == 0) - { - errno = overflow_errno; - goto error_and_exit; - } - - chars_read = read (file, buffer, file_size); -#endif - if (chars_read < 0) - { - error_and_exit: - if (errno != 0) - chars_read = errno; - else - chars_read = EIO; - if (file >= 0) - close (file); - - FREE (input); -#ifndef HISTORY_USE_MMAP - FREE (buffer); -#endif - - return (chars_read); - } - - close (file); - - /* Set TO to larger than end of file if negative. */ - if (to < 0) - to = chars_read; - - /* Start at beginning of file, work to end. */ - bufend = buffer + chars_read; - current_line = 0; - - /* Skip lines until we are at FROM. */ - for (line_start = line_end = buffer; line_end < bufend && current_line < from; line_end++) - if (*line_end == '\n') - { - p = line_end + 1; - /* If we see something we think is a timestamp, continue with this - line. We should check more extensively here... */ - if (HIST_TIMESTAMP_START(p) == 0) - current_line++; - line_start = p; - } - - /* If there are lines left to gobble, then gobble them now. */ - for (line_end = line_start; line_end < bufend; line_end++) - if (*line_end == '\n') - { - /* Change to allow Windows-like \r\n end of line delimiter. */ - if (line_end > line_start && line_end[-1] == '\r') - line_end[-1] = '\0'; - else - *line_end = '\0'; - - if (*line_start) - { - if (HIST_TIMESTAMP_START(line_start) == 0) - { - add_history (line_start); - if (last_ts) - { - add_history_time (last_ts); - last_ts = NULL; - } - } - else - { - last_ts = line_start; - current_line--; - } - } - - current_line++; - - if (current_line >= to) - break; - - line_start = line_end + 1; - } - - FREE (input); -#ifndef HISTORY_USE_MMAP - FREE (buffer); -#else - munmap (buffer, file_size); -#endif - - return (0); -} - -/* Truncate the history file FNAME, leaving only LINES trailing lines. - If FNAME is NULL, then use ~/.history. Returns 0 on success, errno - on failure. */ -int -history_truncate_file (fname, lines) - const char *fname; - int lines; -{ - char *buffer, *filename, *bp, *bp1; /* bp1 == bp+1 */ - int file, chars_read, rv; - struct stat finfo; - size_t file_size; - - buffer = (char *)NULL; - filename = history_filename (fname); - file = filename ? open (filename, O_RDONLY|O_BINARY, 0666) : -1; - rv = 0; - - /* Don't try to truncate non-regular files. */ - if (file == -1 || fstat (file, &finfo) == -1) - { - rv = errno; - if (file != -1) - close (file); - goto truncate_exit; - } - - if (S_ISREG (finfo.st_mode) == 0) - { - close (file); -#ifdef EFTYPE - rv = EFTYPE; -#else - rv = EINVAL; -#endif - goto truncate_exit; - } - - file_size = (size_t)finfo.st_size; - - /* check for overflow on very large files */ - if (file_size != finfo.st_size || file_size + 1 < file_size) - { - close (file); -#if defined (EFBIG) - rv = errno = EFBIG; -#elif defined (EOVERFLOW) - rv = errno = EOVERFLOW; -#else - rv = errno = EINVAL; -#endif - goto truncate_exit; - } - - buffer = (char *)malloc (file_size + 1); - if (buffer == 0) - { - close (file); - goto truncate_exit; - } - - chars_read = read (file, buffer, file_size); - close (file); - - if (chars_read <= 0) - { - rv = (chars_read < 0) ? errno : 0; - goto truncate_exit; - } - - /* Count backwards from the end of buffer until we have passed - LINES lines. bp1 is set funny initially. But since bp[1] can't - be a comment character (since it's off the end) and *bp can't be - both a newline and the history comment character, it should be OK. */ - for (bp1 = bp = buffer + chars_read - 1; lines && bp > buffer; bp--) - { - if (*bp == '\n' && HIST_TIMESTAMP_START(bp1) == 0) - lines--; - bp1 = bp; - } - - /* If this is the first line, then the file contains exactly the - number of lines we want to truncate to, so we don't need to do - anything. It's the first line if we don't find a newline between - the current value of i and 0. Otherwise, write from the start of - this line until the end of the buffer. */ - for ( ; bp > buffer; bp--) - { - if (*bp == '\n' && HIST_TIMESTAMP_START(bp1) == 0) - { - bp++; - break; - } - bp1 = bp; - } - - /* Write only if there are more lines in the file than we want to - truncate to. */ - if (bp > buffer && ((file = open (filename, O_WRONLY|O_TRUNC|O_BINARY, 0600)) != -1)) - { - write (file, bp, chars_read - (bp - buffer)); - -#if defined (__BEOS__) - /* BeOS ignores O_TRUNC. */ - ftruncate (file, chars_read - (bp - buffer)); -#endif - - close (file); - } - - truncate_exit: - - FREE (buffer); - - xfree (filename); - return rv; -} - -/* Workhorse function for writing history. Writes NELEMENT entries - from the history list to FILENAME. OVERWRITE is non-zero if you - wish to replace FILENAME with the entries. */ -static int -history_do_write (filename, nelements, overwrite) - const char *filename; - int nelements, overwrite; -{ - register int i; - char *output, *bakname; - int file, mode, rv; -#ifdef HISTORY_USE_MMAP - size_t cursize; - - mode = overwrite ? O_RDWR|O_CREAT|O_TRUNC|O_BINARY : O_RDWR|O_APPEND|O_BINARY; -#else - mode = overwrite ? O_WRONLY|O_CREAT|O_TRUNC|O_BINARY : O_WRONLY|O_APPEND|O_BINARY; -#endif - output = history_filename (filename); - bakname = output ? history_backupfile (output) : 0; - - if (output && bakname) - rename (output, bakname); - - file = output ? open (output, mode, 0600) : -1; - rv = 0; - - if (file == -1) - { - rv = errno; - if (output && bakname) - rename (bakname, output); - FREE (output); - FREE (bakname); - return (rv); - } - -#ifdef HISTORY_USE_MMAP - cursize = overwrite ? 0 : lseek (file, 0, SEEK_END); -#endif - - if (nelements > history_length) - nelements = history_length; - - /* Build a buffer of all the lines to write, and write them in one syscall. - Suggested by Peter Ho (peter@robosts.oxford.ac.uk). */ - { - HIST_ENTRY **the_history; /* local */ - register int j; - int buffer_size; - char *buffer; - - the_history = history_list (); - /* Calculate the total number of bytes to write. */ - for (buffer_size = 0, i = history_length - nelements; i < history_length; i++) -#if 0 - buffer_size += 2 + HISTENT_BYTES (the_history[i]); -#else - { - if (history_write_timestamps && the_history[i]->timestamp && the_history[i]->timestamp[0]) - buffer_size += strlen (the_history[i]->timestamp) + 1; - buffer_size += strlen (the_history[i]->line) + 1; - } -#endif - - /* Allocate the buffer, and fill it. */ -#ifdef HISTORY_USE_MMAP - if (ftruncate (file, buffer_size+cursize) == -1) - goto mmap_error; - buffer = (char *)mmap (0, buffer_size, PROT_READ|PROT_WRITE, MAP_WFLAGS, file, cursize); - if ((void *)buffer == MAP_FAILED) - { -mmap_error: - rv = errno; - close (file); - if (output && bakname) - rename (bakname, output); - FREE (output); - FREE (bakname); - return rv; - } -#else - buffer = (char *)malloc (buffer_size); - if (buffer == 0) - { - rv = errno; - close (file); - if (output && bakname) - rename (bakname, output); - FREE (output); - FREE (bakname); - return rv; - } -#endif - - for (j = 0, i = history_length - nelements; i < history_length; i++) - { - if (history_write_timestamps && the_history[i]->timestamp && the_history[i]->timestamp[0]) - { - strcpy (buffer + j, the_history[i]->timestamp); - j += strlen (the_history[i]->timestamp); - buffer[j++] = '\n'; - } - strcpy (buffer + j, the_history[i]->line); - j += strlen (the_history[i]->line); - buffer[j++] = '\n'; - } - -#ifdef HISTORY_USE_MMAP - if (msync (buffer, buffer_size, 0) != 0 || munmap (buffer, buffer_size) != 0) - rv = errno; -#else - if (write (file, buffer, buffer_size) < 0) - rv = errno; - xfree (buffer); -#endif - } - - close (file); - - if (rv != 0 && output && bakname) - rename (bakname, output); - else if (rv == 0 && bakname) - unlink (bakname); - - FREE (output); - FREE (bakname); - - return (rv); -} - -/* Append NELEMENT entries to FILENAME. The entries appended are from - the end of the list minus NELEMENTs up to the end of the list. */ -int -append_history (nelements, filename) - int nelements; - const char *filename; -{ - return (history_do_write (filename, nelements, HISTORY_APPEND)); -} - -/* Overwrite FILENAME with the current history. If FILENAME is NULL, - then write the history list to ~/.history. Values returned - are as in read_history ().*/ -int -write_history (filename) - const char *filename; -{ - return (history_do_write (filename, history_length, HISTORY_OVERWRITE)); -} diff --git a/lib/readline/input.c~ b/lib/readline/input.c~ deleted file mode 100644 index 9b3edaaa..00000000 --- a/lib/readline/input.c~ +++ /dev/null @@ -1,610 +0,0 @@ -/* input.c -- character input functions for readline. */ - -/* Copyright (C) 1994-2011 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library (Readline), a library - for reading lines of text with interactive input and history editing. - - Readline 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 3 of the License, or - (at your option) any later version. - - Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>. -*/ - -#define READLINE_LIBRARY - -#if defined (__TANDEM) -# include <floss.h> -#endif - -#if defined (HAVE_CONFIG_H) -# include <config.h> -#endif - -#include <sys/types.h> -#include <fcntl.h> -#if defined (HAVE_SYS_FILE_H) -# include <sys/file.h> -#endif /* HAVE_SYS_FILE_H */ - -#if defined (HAVE_UNISTD_H) -# include <unistd.h> -#endif /* HAVE_UNISTD_H */ - -#if defined (HAVE_STDLIB_H) -# include <stdlib.h> -#else -# include "ansi_stdlib.h" -#endif /* HAVE_STDLIB_H */ - -#include <signal.h> - -#include "posixselect.h" - -#if defined (FIONREAD_IN_SYS_IOCTL) -# include <sys/ioctl.h> -#endif - -#include <stdio.h> -#include <errno.h> - -#if !defined (errno) -extern int errno; -#endif /* !errno */ - -/* System-specific feature definitions and include files. */ -#include "rldefs.h" -#include "rlmbutil.h" - -/* Some standard library routines. */ -#include "readline.h" - -#include "rlprivate.h" -#include "rlshell.h" -#include "xmalloc.h" - -/* What kind of non-blocking I/O do we have? */ -#if !defined (O_NDELAY) && defined (O_NONBLOCK) -# define O_NDELAY O_NONBLOCK /* Posix style */ -#endif - -/* Non-null means it is a pointer to a function to run while waiting for - character input. */ -rl_hook_func_t *rl_event_hook = (rl_hook_func_t *)NULL; - -rl_getc_func_t *rl_getc_function = rl_getc; - -static int _keyboard_input_timeout = 100000; /* 0.1 seconds; it's in usec */ - -static int ibuffer_space PARAMS((void)); -static int rl_get_char PARAMS((int *)); -static int rl_gather_tyi PARAMS((void)); - -/* **************************************************************** */ -/* */ -/* Character Input Buffering */ -/* */ -/* **************************************************************** */ - -static int pop_index, push_index; -static unsigned char ibuffer[512]; -static int ibuffer_len = sizeof (ibuffer) - 1; - -#define any_typein (push_index != pop_index) - -int -_rl_any_typein () -{ - return any_typein; -} - -/* Return the amount of space available in the buffer for stuffing - characters. */ -static int -ibuffer_space () -{ - if (pop_index > push_index) - return (pop_index - push_index - 1); - else - return (ibuffer_len - (push_index - pop_index)); -} - -/* Get a key from the buffer of characters to be read. - Return the key in KEY. - Result is KEY if there was a key, or 0 if there wasn't. */ -static int -rl_get_char (key) - int *key; -{ - if (push_index == pop_index) - return (0); - - *key = ibuffer[pop_index++]; -#if 0 - if (pop_index >= ibuffer_len) -#else - if (pop_index > ibuffer_len) -#endif - pop_index = 0; - - return (1); -} - -/* Stuff KEY into the *front* of the input buffer. - Returns non-zero if successful, zero if there is - no space left in the buffer. */ -int -_rl_unget_char (key) - int key; -{ - if (ibuffer_space ()) - { - pop_index--; - if (pop_index < 0) - pop_index = ibuffer_len; - ibuffer[pop_index] = key; - return (1); - } - return (0); -} - -int -_rl_pushed_input_available () -{ - return (push_index != pop_index); -} - -/* If a character is available to be read, then read it and stuff it into - IBUFFER. Otherwise, just return. Returns number of characters read - (0 if none available) and -1 on error (EIO). */ -static int -rl_gather_tyi () -{ - int tty; - register int tem, result; - int chars_avail, k; - char input; -#if defined(HAVE_SELECT) - fd_set readfds, exceptfds; - struct timeval timeout; -#endif - - chars_avail = 0; - tty = fileno (rl_instream); - -#if defined (HAVE_SELECT) - FD_ZERO (&readfds); - FD_ZERO (&exceptfds); - FD_SET (tty, &readfds); - FD_SET (tty, &exceptfds); - USEC_TO_TIMEVAL (_keyboard_input_timeout, timeout); - result = select (tty + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout); - if (result <= 0) - return 0; /* Nothing to read. */ -#endif - - result = -1; -#if defined (FIONREAD) - errno = 0; - result = ioctl (tty, FIONREAD, &chars_avail); - if (result == -1 && errno == EIO) - return -1; -#endif - -#if defined (O_NDELAY) - if (result == -1) - { - tem = fcntl (tty, F_GETFL, 0); - - fcntl (tty, F_SETFL, (tem | O_NDELAY)); - chars_avail = read (tty, &input, 1); - - fcntl (tty, F_SETFL, tem); - if (chars_avail == -1 && errno == EAGAIN) - return 0; - if (chars_avail == 0) /* EOF */ - { - rl_stuff_char (EOF); - return (0); - } - } -#endif /* O_NDELAY */ - -#if defined (__MINGW32__) - /* Use getch/_kbhit to check for available console input, in the same way - that we read it normally. */ - chars_avail = isatty (tty) ? _kbhit () : 0; - result = 0; -#endif - - /* If there's nothing available, don't waste time trying to read - something. */ - if (chars_avail <= 0) - return 0; - - tem = ibuffer_space (); - - if (chars_avail > tem) - chars_avail = tem; - - /* One cannot read all of the available input. I can only read a single - character at a time, or else programs which require input can be - thwarted. If the buffer is larger than one character, I lose. - Damn! */ - if (tem < ibuffer_len) - chars_avail = 0; - - if (result != -1) - { - while (chars_avail--) - { - RL_CHECK_SIGNALS (); - k = (*rl_getc_function) (rl_instream); - if (rl_stuff_char (k) == 0) - break; /* some problem; no more room */ - if (k == NEWLINE || k == RETURN) - break; - } - } - else - { - if (chars_avail) - rl_stuff_char (input); - } - - return 1; -} - -int -rl_set_keyboard_input_timeout (u) - int u; -{ - int o; - - o = _keyboard_input_timeout; - if (u >= 0) - _keyboard_input_timeout = u; - return (o); -} - -/* Is there input available to be read on the readline input file - descriptor? Only works if the system has select(2) or FIONREAD. - Uses the value of _keyboard_input_timeout as the timeout; if another - readline function wants to specify a timeout and not leave it up to - the user, it should use _rl_input_queued(timeout_value_in_microseconds) - instead. */ -int -_rl_input_available () -{ -#if defined(HAVE_SELECT) - fd_set readfds, exceptfds; - struct timeval timeout; -#endif -#if !defined (HAVE_SELECT) && defined(FIONREAD) - int chars_avail; -#endif - int tty; - - tty = fileno (rl_instream); - -#if defined (HAVE_SELECT) - FD_ZERO (&readfds); - FD_ZERO (&exceptfds); - FD_SET (tty, &readfds); - FD_SET (tty, &exceptfds); - timeout.tv_sec = 0; - timeout.tv_usec = _keyboard_input_timeout; - return (select (tty + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout) > 0); -#else - -#if defined (FIONREAD) - if (ioctl (tty, FIONREAD, &chars_avail) == 0) - return (chars_avail); -#endif - -#endif - -#if defined (__MINGW32__) - if (isatty (tty)) - return (_kbhit ()); -#endif - - return 0; -} - -int -_rl_input_queued (t) - int t; -{ - int old_timeout, r; - - old_timeout = rl_set_keyboard_input_timeout (t); - r = _rl_input_available (); - rl_set_keyboard_input_timeout (old_timeout); - return r; -} - -void -_rl_insert_typein (c) - int c; -{ - int key, t, i; - char *string; - - i = key = 0; - string = (char *)xmalloc (ibuffer_len + 1); - string[i++] = (char) c; - - while ((t = rl_get_char (&key)) && - _rl_keymap[key].type == ISFUNC && - _rl_keymap[key].function == rl_insert) - string[i++] = key; - - if (t) - _rl_unget_char (key); - - string[i] = '\0'; - rl_insert_text (string); - xfree (string); -} - -/* Add KEY to the buffer of characters to be read. Returns 1 if the - character was stuffed correctly; 0 otherwise. */ -int -rl_stuff_char (key) - int key; -{ - if (ibuffer_space () == 0) - return 0; - - if (key == EOF) - { - key = NEWLINE; - rl_pending_input = EOF; - RL_SETSTATE (RL_STATE_INPUTPENDING); - } - ibuffer[push_index++] = key; -#if 0 - if (push_index >= ibuffer_len) -#else - if (push_index > ibuffer_len) -#endif - push_index = 0; - - return 1; -} - -/* Make C be the next command to be executed. */ -int -rl_execute_next (c) - int c; -{ - rl_pending_input = c; - RL_SETSTATE (RL_STATE_INPUTPENDING); - return 0; -} - -/* Clear any pending input pushed with rl_execute_next() */ -int -rl_clear_pending_input () -{ - rl_pending_input = 0; - RL_UNSETSTATE (RL_STATE_INPUTPENDING); - return 0; -} - -/* **************************************************************** */ -/* */ -/* Character Input */ -/* */ -/* **************************************************************** */ - -/* Read a key, including pending input. */ -int -rl_read_key () -{ - int c; - - rl_key_sequence_length++; - - if (rl_pending_input) - { - c = rl_pending_input; - rl_clear_pending_input (); - } - else - { - /* If input is coming from a macro, then use that. */ - if (c = _rl_next_macro_key ()) - return (c); - - /* If the user has an event function, then call it periodically. */ - if (rl_event_hook) - { - while (rl_event_hook) - { - if (rl_gather_tyi () < 0) /* XXX - EIO */ - { - rl_done = 1; - return ('\n'); - } - RL_CHECK_SIGNALS (); - if (rl_get_char (&c) != 0) - break; - if (rl_done) /* XXX - experimental */ - return ('\n'); - (*rl_event_hook) (); - } - } - else - { - if (rl_get_char (&c) == 0) - c = (*rl_getc_function) (rl_instream); - RL_CHECK_SIGNALS (); - } - } - - return (c); -} - -int -rl_getc (stream) - FILE *stream; -{ - int result; - unsigned char c; - - while (1) - { - RL_CHECK_SIGNALS (); - - /* We know at this point that _rl_caught_signal == 0 */ - -#if defined (__MINGW32__) - if (isatty (fileno (stream))) - return (getch ()); -#endif - result = read (fileno (stream), &c, sizeof (unsigned char)); - -if (_rl_caught_signal) - { -itrace("rl_getc: caught SIGWINCH: %d", _rl_caught_signal); - _rl_caught_signal = 0; - } - - if (result == sizeof (unsigned char)) - return (c); - - /* If zero characters are returned, then the file that we are - reading from is empty! Return EOF in that case. */ - if (result == 0) - return (EOF); - -#if defined (__BEOS__) - if (errno == EINTR) - continue; -#endif - -#if defined (EWOULDBLOCK) -# define X_EWOULDBLOCK EWOULDBLOCK -#else -# define X_EWOULDBLOCK -99 -#endif - -#if defined (EAGAIN) -# define X_EAGAIN EAGAIN -#else -# define X_EAGAIN -99 -#endif - - if (errno == X_EWOULDBLOCK || errno == X_EAGAIN) - { - if (sh_unset_nodelay_mode (fileno (stream)) < 0) - return (EOF); - continue; - } - -#undef X_EWOULDBLOCK -#undef X_EAGAIN - - /* If the error that we received was EINTR, then try again, - this is simply an interrupted system call to read (). - Otherwise, some error ocurred, also signifying EOF. */ - if (errno != EINTR) - return (RL_ISSTATE (RL_STATE_READCMD) ? READERR : EOF); - else if (_rl_caught_signal == SIGHUP || _rl_caught_signal == SIGTERM) - return (RL_ISSTATE (RL_STATE_READCMD) ? READERR : EOF); - else if (rl_event_hook) - (*rl_event_hook) (); - } -} - -#if defined (HANDLE_MULTIBYTE) -/* read multibyte char */ -int -_rl_read_mbchar (mbchar, size) - char *mbchar; - int size; -{ - int mb_len, c; - size_t mbchar_bytes_length; - wchar_t wc; - mbstate_t ps, ps_back; - - memset(&ps, 0, sizeof (mbstate_t)); - memset(&ps_back, 0, sizeof (mbstate_t)); - - mb_len = 0; - while (mb_len < size) - { - RL_SETSTATE(RL_STATE_MOREINPUT); - c = rl_read_key (); - RL_UNSETSTATE(RL_STATE_MOREINPUT); - - if (c < 0) - break; - - mbchar[mb_len++] = c; - - mbchar_bytes_length = mbrtowc (&wc, mbchar, mb_len, &ps); - if (mbchar_bytes_length == (size_t)(-1)) - break; /* invalid byte sequence for the current locale */ - else if (mbchar_bytes_length == (size_t)(-2)) - { - /* shorted bytes */ - 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; - } - - return mb_len; -} - -/* Read a multibyte-character string whose first character is FIRST into - the buffer MB of length MLEN. Returns the last character read, which - may be FIRST. Used by the search functions, among others. Very similar - to _rl_read_mbchar. */ -int -_rl_read_mbstring (first, mb, mlen) - int first; - char *mb; - int mlen; -{ - int i, c; - mbstate_t ps; - - c = first; - memset (mb, 0, mlen); - for (i = 0; c >= 0 && i < mlen; i++) - { - mb[i] = (char)c; - memset (&ps, 0, sizeof (mbstate_t)); - if (_rl_get_char_len (mb, &ps) == -2) - { - /* Read more for multibyte character */ - RL_SETSTATE (RL_STATE_MOREINPUT); - c = rl_read_key (); - RL_UNSETSTATE (RL_STATE_MOREINPUT); - } - else - break; - } - return c; -} -#endif /* HANDLE_MULTIBYTE */ diff --git a/lib/readline/readline.h~ b/lib/readline/readline.h~ deleted file mode 100644 index 0de168cd..00000000 --- a/lib/readline/readline.h~ +++ /dev/null @@ -1,893 +0,0 @@ -/* Readline.h -- the names of functions callable from within readline. */ - -/* Copyright (C) 1987-2011 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library (Readline), a library - for reading lines of text with interactive input and history editing. - - Readline 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 3 of the License, or - (at your option) any later version. - - Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>. -*/ - -#if !defined (_READLINE_H_) -#define _READLINE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined (READLINE_LIBRARY) -# include "rlstdc.h" -# include "rltypedefs.h" -# include "keymaps.h" -# include "tilde.h" -#else -# include <readline/rlstdc.h> -# include <readline/rltypedefs.h> -# include <readline/keymaps.h> -# include <readline/tilde.h> -#endif - -/* Hex-encoded Readline version number. */ -#define RL_READLINE_VERSION 0x0602 /* Readline 6.2 */ -#define RL_VERSION_MAJOR 6 -#define RL_VERSION_MINOR 2 - -/* Readline data structures. */ - -/* Maintaining the state of undo. We remember individual deletes and inserts - on a chain of things to do. */ - -/* The actions that undo knows how to undo. Notice that UNDO_DELETE means - to insert some text, and UNDO_INSERT means to delete some text. I.e., - the code tells undo what to undo, not how to undo it. */ -enum undo_code { UNDO_DELETE, UNDO_INSERT, UNDO_BEGIN, UNDO_END }; - -/* What an element of THE_UNDO_LIST looks like. */ -typedef struct undo_list { - struct undo_list *next; - int start, end; /* Where the change took place. */ - char *text; /* The text to insert, if undoing a delete. */ - enum undo_code what; /* Delete, Insert, Begin, End. */ -} UNDO_LIST; - -/* The current undo list for RL_LINE_BUFFER. */ -extern UNDO_LIST *rl_undo_list; - -/* The data structure for mapping textual names to code addresses. */ -typedef struct _funmap { - const char *name; - rl_command_func_t *function; -} FUNMAP; - -extern FUNMAP **funmap; - -/* **************************************************************** */ -/* */ -/* Functions available to bind to key sequences */ -/* */ -/* **************************************************************** */ - -/* Bindable commands for numeric arguments. */ -extern int rl_digit_argument PARAMS((int, int)); -extern int rl_universal_argument PARAMS((int, int)); - -/* Bindable commands for moving the cursor. */ -extern int rl_forward_byte PARAMS((int, int)); -extern int rl_forward_char PARAMS((int, int)); -extern int rl_forward PARAMS((int, int)); -extern int rl_backward_byte PARAMS((int, int)); -extern int rl_backward_char PARAMS((int, int)); -extern int rl_backward PARAMS((int, int)); -extern int rl_beg_of_line PARAMS((int, int)); -extern int rl_end_of_line PARAMS((int, int)); -extern int rl_forward_word PARAMS((int, int)); -extern int rl_backward_word PARAMS((int, int)); -extern int rl_refresh_line PARAMS((int, int)); -extern int rl_clear_screen PARAMS((int, int)); -extern int rl_skip_csi_sequence PARAMS((int, int)); -extern int rl_arrow_keys PARAMS((int, int)); - -/* Bindable commands for inserting and deleting text. */ -extern int rl_insert PARAMS((int, int)); -extern int rl_quoted_insert PARAMS((int, int)); -extern int rl_tab_insert PARAMS((int, int)); -extern int rl_newline PARAMS((int, int)); -extern int rl_do_lowercase_version PARAMS((int, int)); -extern int rl_rubout PARAMS((int, int)); -extern int rl_delete PARAMS((int, int)); -extern int rl_rubout_or_delete PARAMS((int, int)); -extern int rl_delete_horizontal_space PARAMS((int, int)); -extern int rl_delete_or_show_completions PARAMS((int, int)); -extern int rl_insert_comment PARAMS((int, int)); - -/* Bindable commands for changing case. */ -extern int rl_upcase_word PARAMS((int, int)); -extern int rl_downcase_word PARAMS((int, int)); -extern int rl_capitalize_word PARAMS((int, int)); - -/* Bindable commands for transposing characters and words. */ -extern int rl_transpose_words PARAMS((int, int)); -extern int rl_transpose_chars PARAMS((int, int)); - -/* Bindable commands for searching within a line. */ -extern int rl_char_search PARAMS((int, int)); -extern int rl_backward_char_search PARAMS((int, int)); - -/* Bindable commands for readline's interface to the command history. */ -extern int rl_beginning_of_history PARAMS((int, int)); -extern int rl_end_of_history PARAMS((int, int)); -extern int rl_get_next_history PARAMS((int, int)); -extern int rl_get_previous_history PARAMS((int, int)); - -/* Bindable commands for managing the mark and region. */ -extern int rl_set_mark PARAMS((int, int)); -extern int rl_exchange_point_and_mark PARAMS((int, int)); - -/* Bindable commands to set the editing mode (emacs or vi). */ -extern int rl_vi_editing_mode PARAMS((int, int)); -extern int rl_emacs_editing_mode PARAMS((int, int)); - -/* Bindable commands to change the insert mode (insert or overwrite) */ -extern int rl_overwrite_mode PARAMS((int, int)); - -/* Bindable commands for managing key bindings. */ -extern int rl_re_read_init_file PARAMS((int, int)); -extern int rl_dump_functions PARAMS((int, int)); -extern int rl_dump_macros PARAMS((int, int)); -extern int rl_dump_variables PARAMS((int, int)); - -/* Bindable commands for word completion. */ -extern int rl_complete PARAMS((int, int)); -extern int rl_possible_completions PARAMS((int, int)); -extern int rl_insert_completions PARAMS((int, int)); -extern int rl_old_menu_complete PARAMS((int, int)); -extern int rl_menu_complete PARAMS((int, int)); -extern int rl_backward_menu_complete PARAMS((int, int)); - -/* Bindable commands for killing and yanking text, and managing the kill ring. */ -extern int rl_kill_word PARAMS((int, int)); -extern int rl_backward_kill_word PARAMS((int, int)); -extern int rl_kill_line PARAMS((int, int)); -extern int rl_backward_kill_line PARAMS((int, int)); -extern int rl_kill_full_line PARAMS((int, int)); -extern int rl_unix_word_rubout PARAMS((int, int)); -extern int rl_unix_filename_rubout PARAMS((int, int)); -extern int rl_unix_line_discard PARAMS((int, int)); -extern int rl_copy_region_to_kill PARAMS((int, int)); -extern int rl_kill_region PARAMS((int, int)); -extern int rl_copy_forward_word PARAMS((int, int)); -extern int rl_copy_backward_word PARAMS((int, int)); -extern int rl_yank PARAMS((int, int)); -extern int rl_yank_pop PARAMS((int, int)); -extern int rl_yank_nth_arg PARAMS((int, int)); -extern int rl_yank_last_arg PARAMS((int, int)); -/* Not available unless __CYGWIN__ is defined. */ -#ifdef __CYGWIN__ -extern int rl_paste_from_clipboard PARAMS((int, int)); -#endif - -/* Bindable commands for incremental searching. */ -extern int rl_reverse_search_history PARAMS((int, int)); -extern int rl_forward_search_history PARAMS((int, int)); - -/* Bindable keyboard macro commands. */ -extern int rl_start_kbd_macro PARAMS((int, int)); -extern int rl_end_kbd_macro PARAMS((int, int)); -extern int rl_call_last_kbd_macro PARAMS((int, int)); - -/* Bindable undo commands. */ -extern int rl_revert_line PARAMS((int, int)); -extern int rl_undo_command PARAMS((int, int)); - -/* Bindable tilde expansion commands. */ -extern int rl_tilde_expand PARAMS((int, int)); - -/* Bindable terminal control commands. */ -extern int rl_restart_output PARAMS((int, int)); -extern int rl_stop_output PARAMS((int, int)); - -/* Miscellaneous bindable commands. */ -extern int rl_abort PARAMS((int, int)); -extern int rl_tty_status PARAMS((int, int)); - -/* Bindable commands for incremental and non-incremental history searching. */ -extern int rl_history_search_forward PARAMS((int, int)); -extern int rl_history_search_backward PARAMS((int, int)); -extern int rl_noninc_forward_search PARAMS((int, int)); -extern int rl_noninc_reverse_search PARAMS((int, int)); -extern int rl_noninc_forward_search_again PARAMS((int, int)); -extern int rl_noninc_reverse_search_again PARAMS((int, int)); - -/* Bindable command used when inserting a matching close character. */ -extern int rl_insert_close PARAMS((int, int)); - -/* Not available unless READLINE_CALLBACKS is defined. */ -extern void rl_callback_handler_install PARAMS((const char *, rl_vcpfunc_t *)); -extern void rl_callback_read_char PARAMS((void)); -extern void rl_callback_handler_remove PARAMS((void)); - -/* Things for vi mode. Not available unless readline is compiled -DVI_MODE. */ -/* VI-mode bindable commands. */ -extern int rl_vi_redo PARAMS((int, int)); -extern int rl_vi_undo PARAMS((int, int)); -extern int rl_vi_yank_arg PARAMS((int, int)); -extern int rl_vi_fetch_history PARAMS((int, int)); -extern int rl_vi_search_again PARAMS((int, int)); -extern int rl_vi_search PARAMS((int, int)); -extern int rl_vi_complete PARAMS((int, int)); -extern int rl_vi_tilde_expand PARAMS((int, int)); -extern int rl_vi_prev_word PARAMS((int, int)); -extern int rl_vi_next_word PARAMS((int, int)); -extern int rl_vi_end_word PARAMS((int, int)); -extern int rl_vi_insert_beg PARAMS((int, int)); -extern int rl_vi_append_mode PARAMS((int, int)); -extern int rl_vi_append_eol PARAMS((int, int)); -extern int rl_vi_eof_maybe PARAMS((int, int)); -extern int rl_vi_insertion_mode PARAMS((int, int)); -extern int rl_vi_insert_mode PARAMS((int, int)); -extern int rl_vi_movement_mode PARAMS((int, int)); -extern int rl_vi_arg_digit PARAMS((int, int)); -extern int rl_vi_change_case PARAMS((int, int)); -extern int rl_vi_put PARAMS((int, int)); -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)); -extern int rl_vi_char_search PARAMS((int, int)); -extern int rl_vi_match PARAMS((int, int)); -extern int rl_vi_change_char PARAMS((int, int)); -extern int rl_vi_subst PARAMS((int, int)); -extern int rl_vi_overstrike PARAMS((int, int)); -extern int rl_vi_overstrike_delete PARAMS((int, int)); -extern int rl_vi_replace PARAMS((int, int)); -extern int rl_vi_set_mark PARAMS((int, int)); -extern int rl_vi_goto_mark PARAMS((int, int)); - -/* VI-mode utility functions. */ -extern int rl_vi_check PARAMS((void)); -extern int rl_vi_domove PARAMS((int, int *)); -extern int rl_vi_bracktype PARAMS((int)); - -extern void rl_vi_start_inserting PARAMS((int, int, int)); - -/* VI-mode pseudo-bindable commands, used as utility functions. */ -extern int rl_vi_fWord PARAMS((int, int)); -extern int rl_vi_bWord PARAMS((int, int)); -extern int rl_vi_eWord PARAMS((int, int)); -extern int rl_vi_fword PARAMS((int, int)); -extern int rl_vi_bword PARAMS((int, int)); -extern int rl_vi_eword PARAMS((int, int)); - -/* **************************************************************** */ -/* */ -/* Well Published Functions */ -/* */ -/* **************************************************************** */ - -/* Readline functions. */ -/* Read a line of input. Prompt with PROMPT. A NULL PROMPT means none. */ -extern char *readline PARAMS((const char *)); - -extern int rl_set_prompt PARAMS((const char *)); -extern int rl_expand_prompt PARAMS((char *)); - -extern int rl_initialize PARAMS((void)); - -/* Undocumented; unused by readline */ -extern int rl_discard_argument PARAMS((void)); - -/* Utility functions to bind keys to readline commands. */ -extern int rl_add_defun PARAMS((const char *, rl_command_func_t *, int)); -extern int rl_bind_key PARAMS((int, rl_command_func_t *)); -extern int rl_bind_key_in_map PARAMS((int, rl_command_func_t *, Keymap)); -extern int rl_unbind_key PARAMS((int)); -extern int rl_unbind_key_in_map PARAMS((int, Keymap)); -extern int rl_bind_key_if_unbound PARAMS((int, rl_command_func_t *)); -extern int rl_bind_key_if_unbound_in_map PARAMS((int, rl_command_func_t *, Keymap)); -extern int rl_unbind_function_in_map PARAMS((rl_command_func_t *, Keymap)); -extern int rl_unbind_command_in_map PARAMS((const char *, Keymap)); -extern int rl_bind_keyseq PARAMS((const char *, rl_command_func_t *)); -extern int rl_bind_keyseq_in_map PARAMS((const char *, rl_command_func_t *, Keymap)); -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. */ -extern int rl_set_key PARAMS((const char *, rl_command_func_t *, Keymap)); - -/* Backwards compatibility, use rl_generic_bind instead. */ -extern int rl_macro_bind PARAMS((const char *, const char *, Keymap)); - -/* Undocumented in the texinfo manual; not really useful to programs. */ -extern int rl_translate_keyseq PARAMS((const char *, char *, int *)); -extern char *rl_untranslate_keyseq PARAMS((int)); - -extern rl_command_func_t *rl_named_function PARAMS((const char *)); -extern rl_command_func_t *rl_function_of_keyseq PARAMS((const char *, Keymap, int *)); - -extern void rl_list_funmap_names PARAMS((void)); -extern char **rl_invoking_keyseqs_in_map PARAMS((rl_command_func_t *, Keymap)); -extern char **rl_invoking_keyseqs PARAMS((rl_command_func_t *)); - -extern void rl_function_dumper PARAMS((int)); -extern void rl_macro_dumper PARAMS((int)); -extern void rl_variable_dumper PARAMS((int)); - -extern int rl_read_init_file PARAMS((const char *)); -extern int rl_parse_and_bind PARAMS((char *)); - -/* Functions for manipulating keymaps. */ -extern Keymap rl_make_bare_keymap PARAMS((void)); -extern Keymap rl_copy_keymap PARAMS((Keymap)); -extern Keymap rl_make_keymap PARAMS((void)); -extern void rl_discard_keymap PARAMS((Keymap)); - -extern Keymap rl_get_keymap_by_name PARAMS((const char *)); -extern char *rl_get_keymap_name PARAMS((Keymap)); -extern void rl_set_keymap PARAMS((Keymap)); -extern Keymap rl_get_keymap PARAMS((void)); -/* Undocumented; used internally only. */ -extern void rl_set_keymap_from_edit_mode PARAMS((void)); -extern char *rl_get_keymap_name_from_edit_mode PARAMS((void)); - -/* Functions for manipulating the funmap, which maps command names to functions. */ -extern int rl_add_funmap_entry PARAMS((const char *, rl_command_func_t *)); -extern const char **rl_funmap_names PARAMS((void)); -/* Undocumented, only used internally -- there is only one funmap, and this - function may be called only once. */ -extern void rl_initialize_funmap PARAMS((void)); - -/* Utility functions for managing keyboard macros. */ -extern void rl_push_macro_input PARAMS((char *)); - -/* Functions for undoing, from undo.c */ -extern void rl_add_undo PARAMS((enum undo_code, int, int, char *)); -extern void rl_free_undo_list PARAMS((void)); -extern int rl_do_undo PARAMS((void)); -extern int rl_begin_undo_group PARAMS((void)); -extern int rl_end_undo_group PARAMS((void)); -extern int rl_modifying PARAMS((int, int)); - -/* Functions for redisplay. */ -extern void rl_redisplay PARAMS((void)); -extern int rl_on_new_line PARAMS((void)); -extern int rl_on_new_line_with_prompt PARAMS((void)); -extern int rl_forced_update_display PARAMS((void)); -extern int rl_clear_message PARAMS((void)); -extern int rl_reset_line_state PARAMS((void)); -extern int rl_crlf PARAMS((void)); - -#if defined (USE_VARARGS) && defined (PREFER_STDARG) -extern int rl_message (const char *, ...) __attribute__((__format__ (printf, 1, 2))); -#else -extern int rl_message (); -#endif - -extern int rl_show_char PARAMS((int)); - -/* Undocumented in texinfo manual. */ -extern int rl_character_len PARAMS((int, int)); - -/* Save and restore internal prompt redisplay information. */ -extern void rl_save_prompt PARAMS((void)); -extern void rl_restore_prompt PARAMS((void)); - -/* Modifying text. */ -extern void rl_replace_line PARAMS((const char *, int)); -extern int rl_insert_text PARAMS((const char *)); -extern int rl_delete_text PARAMS((int, int)); -extern int rl_kill_text PARAMS((int, int)); -extern char *rl_copy_text PARAMS((int, int)); - -/* Terminal and tty mode management. */ -extern void rl_prep_terminal PARAMS((int)); -extern void rl_deprep_terminal PARAMS((void)); -extern void rl_tty_set_default_bindings PARAMS((Keymap)); -extern void rl_tty_unset_default_bindings PARAMS((Keymap)); - -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 *)); - -/* Functions for character input. */ -extern int rl_stuff_char PARAMS((int)); -extern int rl_execute_next PARAMS((int)); -extern int rl_clear_pending_input PARAMS((void)); -extern int rl_read_key PARAMS((void)); -extern int rl_getc PARAMS((FILE *)); -extern int rl_set_keyboard_input_timeout PARAMS((int)); - -/* `Public' utility functions . */ -extern void rl_extend_line_buffer PARAMS((int)); -extern int rl_ding PARAMS((void)); -extern int rl_alphabetic PARAMS((int)); -extern void rl_free PARAMS((void *)); - -/* Readline signal handling, from signals.c */ -extern int rl_set_signals PARAMS((void)); -extern int rl_clear_signals PARAMS((void)); -extern void rl_cleanup_after_signal PARAMS((void)); -extern void rl_reset_after_signal PARAMS((void)); -extern void rl_free_line_state PARAMS((void)); - -extern void rl_echo_signal_char PARAMS((int)); - -extern int rl_set_paren_blink_timeout PARAMS((int)); - -/* Undocumented. */ -extern int rl_maybe_save_line PARAMS((void)); -extern int rl_maybe_unsave_line PARAMS((void)); -extern int rl_maybe_replace_line PARAMS((void)); - -/* Completion functions. */ -extern int rl_complete_internal PARAMS((int)); -extern void rl_display_match_list PARAMS((char **, int, int)); - -extern char **rl_completion_matches PARAMS((const char *, rl_compentry_func_t *)); -extern char *rl_username_completion_function PARAMS((const char *, int)); -extern char *rl_filename_completion_function PARAMS((const char *, int)); - -extern int rl_completion_mode PARAMS((rl_command_func_t *)); - -#if 0 -/* Backwards compatibility (compat.c). These will go away sometime. */ -extern void free_undo_list PARAMS((void)); -extern int maybe_save_line PARAMS((void)); -extern int maybe_unsave_line PARAMS((void)); -extern int maybe_replace_line PARAMS((void)); - -extern int ding PARAMS((void)); -extern int alphabetic PARAMS((int)); -extern int crlf PARAMS((void)); - -extern char **completion_matches PARAMS((char *, rl_compentry_func_t *)); -extern char *username_completion_function PARAMS((const char *, int)); -extern char *filename_completion_function PARAMS((const char *, int)); -#endif - -/* **************************************************************** */ -/* */ -/* Well Published Variables */ -/* */ -/* **************************************************************** */ - -/* The version of this incarnation of the readline library. */ -extern const char *rl_library_version; /* e.g., "4.2" */ -extern int rl_readline_version; /* e.g., 0x0402 */ - -/* True if this is real GNU readline. */ -extern int rl_gnu_readline_p; - -/* Flags word encapsulating the current readline state. */ -extern int rl_readline_state; - -/* Says which editing mode readline is currently using. 1 means emacs mode; - 0 means vi mode. */ -extern int rl_editing_mode; - -/* Insert or overwrite mode for emacs mode. 1 means insert mode; 0 means - overwrite mode. Reset to insert mode on each input line. */ -extern int rl_insert_mode; - -/* The name of the calling program. You should initialize this to - whatever was in argv[0]. It is used when parsing conditionals. */ -extern const char *rl_readline_name; - -/* The prompt readline uses. This is set from the argument to - readline (), and should not be assigned to directly. */ -extern char *rl_prompt; - -/* The prompt string that is actually displayed by rl_redisplay. Public so - applications can more easily supply their own redisplay functions. */ -extern char *rl_display_prompt; - -/* The line buffer that is in use. */ -extern char *rl_line_buffer; - -/* The location of point, and end. */ -extern int rl_point; -extern int rl_end; - -/* The mark, or saved cursor position. */ -extern int rl_mark; - -/* Flag to indicate that readline has finished with the current input - line and should return it. */ -extern int rl_done; - -/* If set to a character value, that will be the next keystroke read. */ -extern int rl_pending_input; - -/* Non-zero if we called this function from _rl_dispatch(). It's present - so functions can find out whether they were called from a key binding - or directly from an application. */ -extern int rl_dispatching; - -/* Non-zero if the user typed a numeric argument before executing the - current function. */ -extern int rl_explicit_arg; - -/* The current value of the numeric argument specified by the user. */ -extern int rl_numeric_arg; - -/* The address of the last command function Readline executed. */ -extern rl_command_func_t *rl_last_func; - -/* The name of the terminal to use. */ -extern const char *rl_terminal_name; - -/* The input and output streams. */ -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; - -/* If non-zero, this is the address of a function to call just before - readline_internal_setup () returns and readline_internal starts - reading input characters. */ -extern rl_hook_func_t *rl_pre_input_hook; - -/* The address of a function to call periodically while Readline is - awaiting character input, or NULL, for no event handling. */ -extern rl_hook_func_t *rl_event_hook; - -/* The address of the function to call to fetch a character from the current - Readline input stream */ -extern rl_getc_func_t *rl_getc_function; - -extern rl_voidfunc_t *rl_redisplay_function; - -extern rl_vintfunc_t *rl_prep_term_function; -extern rl_voidfunc_t *rl_deprep_term_function; - -/* Dispatch variables. */ -extern Keymap rl_executing_keymap; -extern Keymap rl_binding_keymap; - -/* Display variables. */ -/* If non-zero, readline will erase the entire line, including any prompt, - if the only thing typed on an otherwise-blank line is something bound to - rl_newline. */ -extern int rl_erase_empty_line; - -/* If non-zero, the application has already printed the prompt (rl_prompt) - before calling readline, so readline should not output it the first time - redisplay is done. */ -extern int rl_already_prompted; - -/* A non-zero value means to read only this many characters rather than - up to a character bound to accept-line. */ -extern int rl_num_chars_to_read; - -/* The text of a currently-executing keyboard macro. */ -extern char *rl_executing_macro; - -/* Variables to control readline signal handling. */ -/* If non-zero, readline will install its own signal handlers for - SIGINT, SIGTERM, SIGQUIT, SIGALRM, SIGTSTP, SIGTTIN, and SIGTTOU. */ -extern int rl_catch_signals; - -/* If non-zero, readline will install a signal handler for SIGWINCH - that also attempts to call any calling application's SIGWINCH signal - handler. Note that the terminal is not cleaned up before the - application's signal handler is called; use rl_cleanup_after_signal() - to do that. */ -extern int rl_catch_sigwinch; - -/* Completion variables. */ -/* Pointer to the generator function for completion_matches (). - NULL means to use rl_filename_completion_function (), the default - filename completer. */ -extern rl_compentry_func_t *rl_completion_entry_function; - -/* Optional generator for menu completion. Default is - rl_completion_entry_function (rl_filename_completion_function). */ - extern rl_compentry_func_t *rl_menu_completion_entry_function; - -/* If rl_ignore_some_completions_function is non-NULL it is the address - of a function to call after all of the possible matches have been - generated, but before the actual completion is done to the input line. - The function is called with one argument; a NULL terminated array - of (char *). If your function removes any of the elements, they - must be free()'ed. */ -extern rl_compignore_func_t *rl_ignore_some_completions_function; - -/* Pointer to alternative function to create matches. - Function is called with TEXT, START, and END. - START and END are indices in RL_LINE_BUFFER saying what the boundaries - of TEXT are. - If this function exists and returns NULL then call the value of - rl_completion_entry_function to try to match, otherwise use the - array of strings returned. */ -extern rl_completion_func_t *rl_attempted_completion_function; - -/* The basic list of characters that signal a break between words for the - completer routine. The initial contents of this variable is what - breaks words in the shell, i.e. "n\"\\'`@$>". */ -extern const char *rl_basic_word_break_characters; - -/* The list of characters that signal a break between words for - rl_complete_internal. The default list is the contents of - rl_basic_word_break_characters. */ -extern /*const*/ char *rl_completer_word_break_characters; - -/* Hook function to allow an application to set the completion word - break characters before readline breaks up the line. Allows - position-dependent word break characters. */ -extern rl_cpvfunc_t *rl_completion_word_break_hook; - -/* List of characters which can be used to quote a substring of the line. - Completion occurs on the entire substring, and within the substring - rl_completer_word_break_characters are treated as any other character, - unless they also appear within this list. */ -extern const char *rl_completer_quote_characters; - -/* List of quote characters which cause a word break. */ -extern const char *rl_basic_quote_characters; - -/* List of characters that need to be quoted in filenames by the completer. */ -extern const char *rl_filename_quote_characters; - -/* List of characters that are word break characters, but should be left - in TEXT when it is passed to the completion function. The shell uses - this to help determine what kind of completing to do. */ -extern const char *rl_special_prefixes; - -/* If non-zero, then this is the address of a function to call when - completing on a directory name. The function is called with - the address of a string (the current directory name) as an arg. It - changes what is displayed when the possible completions are printed - or inserted. The directory completion hook should perform - any necessary dequoting. This function should return 1 if it modifies - the directory name pointer passed as an argument. If the directory - completion hook returns 0, it should not modify the directory name - pointer passed as an argument. */ -extern rl_icppfunc_t *rl_directory_completion_hook; - -/* If non-zero, this is the address of a function to call when completing - a directory name. This function takes the address of the directory name - to be modified as an argument. Unlike rl_directory_completion_hook, it - only modifies the directory name used in opendir(2), not what is displayed - when the possible completions are printed or inserted. If set, it takes - precedence over rl_directory_completion_hook. The directory rewrite - hook should perform any necessary dequoting. This function has the same - return value properties as the directory_completion_hook. - - I'm not happy with how this works yet, so it's undocumented. I'm trying - it in bash to see how well it goes. */ -extern rl_icppfunc_t *rl_directory_rewrite_hook; - -/* If non-zero, this is the address of a function to call when reading - directory entries from the filesystem for completion and comparing - them to the partial word to be completed. The function should - either return its first argument (if no conversion takes place) or - newly-allocated memory. This can, for instance, convert filenames - between character sets for comparison against what's typed at the - keyboard. The returned value is what is added to the list of - matches. The second argument is the length of the filename to be - converted. */ -extern rl_dequote_func_t *rl_filename_rewrite_hook; - -/* Backwards compatibility with previous versions of readline. */ -#define rl_symbolic_link_hook rl_directory_completion_hook - -/* If non-zero, then this is the address of a function to call when - completing a word would normally display the list of possible matches. - This function is called instead of actually doing the display. - It takes three arguments: (char **matches, int num_matches, int max_length) - where MATCHES is the array of strings that matched, NUM_MATCHES is the - number of strings in that array, and MAX_LENGTH is the length of the - longest string in that array. */ -extern rl_compdisp_func_t *rl_completion_display_matches_hook; - -/* Non-zero means that the results of the matches are to be treated - as filenames. This is ALWAYS zero on entry, and can only be changed - within a completion entry finder function. */ -extern int rl_filename_completion_desired; - -/* Non-zero means that the results of the matches are to be quoted using - double quotes (or an application-specific quoting mechanism) if the - filename contains any characters in rl_word_break_chars. This is - ALWAYS non-zero on entry, and can only be changed within a completion - entry finder function. */ -extern int rl_filename_quoting_desired; - -/* Set to a function to quote a filename in an application-specific fashion. - Called with the text to quote, the type of match found (single or multiple) - and a pointer to the quoting character to be used, which the function can - reset if desired. */ -extern rl_quote_func_t *rl_filename_quoting_function; - -/* Function to call to remove quoting characters from a filename. Called - before completion is attempted, so the embedded quotes do not interfere - with matching names in the file system. */ -extern rl_dequote_func_t *rl_filename_dequoting_function; - -/* Function to call to decide whether or not a word break character is - quoted. If a character is quoted, it does not break words for the - completer. */ -extern rl_linebuf_func_t *rl_char_is_quoted_p; - -/* Non-zero means to suppress normal filename completion after the - user-specified completion function has been called. */ -extern int rl_attempted_completion_over; - -/* Set to a character describing the type of completion being attempted by - rl_complete_internal; available for use by application completion - functions. */ -extern int rl_completion_type; - -/* Set to the last key used to invoke one of the completion functions */ -extern int rl_completion_invoking_key; - -/* 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. */ -extern int rl_completion_query_items; - -/* Character appended to completed words when at the end of the line. The - default is a space. Nothing is added if this is '\0'. */ -extern int rl_completion_append_character; - -/* If set to non-zero by an application completion function, - rl_completion_append_character will not be appended. */ -extern int rl_completion_suppress_append; - -/* Set to any quote character readline thinks it finds before any application - completion function is called. */ -extern int rl_completion_quote_character; - -/* Set to a non-zero value if readline found quoting anywhere in the word to - be completed; set before any application completion function is called. */ -extern int rl_completion_found_quote; - -/* If non-zero, the completion functions don't append any closing quote. - This is set to 0 by rl_complete_internal and may be changed by an - application-specific completion function. */ -extern int rl_completion_suppress_quote; - -/* If non-zero, readline will sort the completion matches. On by default. */ -extern int rl_sort_completion_matches; - -/* If non-zero, a slash will be appended to completed filenames that are - symbolic links to directory names, subject to the value of the - mark-directories variable (which is user-settable). This exists so - that application completion functions can override the user's preference - (set via the mark-symlinked-directories variable) if appropriate. - It's set to the value of _rl_complete_mark_symlink_dirs in - rl_complete_internal before any application-specific completion - function is called, so without that function doing anything, the user's - preferences are honored. */ -extern int rl_completion_mark_symlink_dirs; - -/* If non-zero, then disallow duplicates in the matches. */ -extern int rl_ignore_completion_duplicates; - -/* If this is non-zero, completion is (temporarily) inhibited, and the - completion character will be inserted as any other. */ -extern int rl_inhibit_completion; - -/* Input error; can be returned by (*rl_getc_function) if readline is reading - a top-level command (RL_ISSTATE (RL_STATE_READCMD)). */ -#define READERR (-2) - -/* Definitions available for use by readline clients. */ -#define RL_PROMPT_START_IGNORE '\001' -#define RL_PROMPT_END_IGNORE '\002' - -/* Possible values for do_replace argument to rl_filename_quoting_function, - called by rl_complete_internal. */ -#define NO_MATCH 0 -#define SINGLE_MATCH 1 -#define MULT_MATCH 2 - -/* Possible state values for rl_readline_state */ -#define RL_STATE_NONE 0x000000 /* no state; before first call */ - -#define RL_STATE_INITIALIZING 0x0000001 /* initializing */ -#define RL_STATE_INITIALIZED 0x0000002 /* initialization done */ -#define RL_STATE_TERMPREPPED 0x0000004 /* terminal is prepped */ -#define RL_STATE_READCMD 0x0000008 /* reading a command key */ -#define RL_STATE_METANEXT 0x0000010 /* reading input after ESC */ -#define RL_STATE_DISPATCHING 0x0000020 /* dispatching to a command */ -#define RL_STATE_MOREINPUT 0x0000040 /* reading more input in a command function */ -#define RL_STATE_ISEARCH 0x0000080 /* doing incremental search */ -#define RL_STATE_NSEARCH 0x0000100 /* doing non-inc search */ -#define RL_STATE_SEARCH 0x0000200 /* doing a history search */ -#define RL_STATE_NUMERICARG 0x0000400 /* reading numeric argument */ -#define RL_STATE_MACROINPUT 0x0000800 /* getting input from a macro */ -#define RL_STATE_MACRODEF 0x0001000 /* defining keyboard macro */ -#define RL_STATE_OVERWRITE 0x0002000 /* overwrite mode */ -#define RL_STATE_COMPLETING 0x0004000 /* doing completion */ -#define RL_STATE_SIGHANDLER 0x0008000 /* in readline sighandler */ -#define RL_STATE_UNDOING 0x0010000 /* doing an undo */ -#define RL_STATE_INPUTPENDING 0x0020000 /* rl_execute_next called */ -#define RL_STATE_TTYCSAVED 0x0040000 /* tty special chars saved */ -#define RL_STATE_CALLBACK 0x0080000 /* using the callback interface */ -#define RL_STATE_VIMOTION 0x0100000 /* reading vi motion arg */ -#define RL_STATE_MULTIKEY 0x0200000 /* reading multiple-key command */ -#define RL_STATE_VICMDONCE 0x0400000 /* entered vi command mode at least once */ -#define RL_STATE_REDISPLAYING 0x0800000 /* updating terminal display */ - -#define RL_STATE_DONE 0x1000000 /* done; accepted line */ - -#define RL_SETSTATE(x) (rl_readline_state |= (x)) -#define RL_UNSETSTATE(x) (rl_readline_state &= ~(x)) -#define RL_ISSTATE(x) (rl_readline_state & (x)) - -struct readline_state { - /* line state */ - int point; - int end; - int mark; - char *buffer; - int buflen; - UNDO_LIST *ul; - char *prompt; - - /* global state */ - int rlstate; - int done; - Keymap kmap; - - /* input state */ - rl_command_func_t *lastfunc; - int insmode; - int edmode; - int kseqlen; - FILE *inf; - FILE *outf; - int pendingin; - char *macro; - - /* signal state */ - int catchsigs; - int catchsigwinch; - - /* search state */ - - /* completion state */ - - /* options state */ - - /* reserved for future expansion, so the struct size doesn't change */ - char reserved[64]; -}; - -extern int rl_save_state PARAMS((struct readline_state *)); -extern int rl_restore_state PARAMS((struct readline_state *)); - -#ifdef __cplusplus -} -#endif - -#endif /* _READLINE_H_ */ diff --git a/lib/readline/rlprivate.h~ b/lib/readline/rlprivate.h~ deleted file mode 100644 index 384ff67c..00000000 --- a/lib/readline/rlprivate.h~ +++ /dev/null @@ -1,506 +0,0 @@ -/* rlprivate.h -- functions and variables global to the readline library, - but not intended for use by applications. */ - -/* Copyright (C) 1999-2010 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library (Readline), a library - for reading lines of text with interactive input and history editing. - - Readline 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 3 of the License, or - (at your option) any later version. - - Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>. -*/ - -#if !defined (_RL_PRIVATE_H_) -#define _RL_PRIVATE_H_ - -#include "rlconf.h" /* for VISIBLE_STATS */ -#include "rlstdc.h" -#include "posixjmp.h" /* defines procenv_t */ - -/************************************************************************* - * * - * Convenience definitions * - * * - *************************************************************************/ - -#define EMACS_MODE() (rl_editing_mode == emacs_mode) -#define VI_COMMAND_MODE() (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap) -#define VI_INSERT_MODE() (rl_editing_mode == vi_mode && _rl_keymap == vi_insertion_keymap) - -#define RL_CHECK_SIGNALS() \ - do { \ - if (_rl_caught_signal) _rl_signal_handler (_rl_caught_signal); \ - } while (0) - -/************************************************************************* - * * - * 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 -#define SF_CHGKMAP 0x08 - -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; - - Keymap keymap; /* used when dispatching commands in search string */ - Keymap okeymap; /* original keymap */ - - 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; - -/* vi-mode commands that use result of motion command to define boundaries */ -#define VIM_DELETE 0x01 -#define VIM_CHANGE 0x02 -#define VIM_YANK 0x04 - -/* various states for vi-mode commands that use motion commands. reflects - RL_READLINE_STATE */ -#define VMSTATE_READ 0x01 -#define VMSTATE_NUMARG 0x02 - -typedef struct __rl_vimotion_context -{ - int op; - int state; - int flags; /* reserved */ - _rl_arg_cxt ncxt; - int numeric_arg; - int start, end; /* rl_point, rl_end */ - int key, motion; /* initial key, motion command */ -} _rl_vimotion_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 * - * * - *************************************************************************/ - -/************************************************************************* - * * - * Global variables undocumented in texinfo manual and not in readline.h * - * * - *************************************************************************/ - -/* complete.c */ -extern int rl_complete_with_tilde_expansion; -#if defined (VISIBLE_STATS) -extern int rl_visible_stats; -#endif /* VISIBLE_STATS */ - -/* readline.c */ -extern int rl_line_buffer_len; -extern int rl_arg_sign; -extern int rl_visible_prompt_length; -extern int rl_key_sequence_length; -extern int rl_byte_oriented; - -/* display.c */ -extern int rl_display_fixed; - -/* parens.c */ -extern int rl_blink_matching_paren; - -/************************************************************************* - * * - * Global functions and variables unsed and undocumented * - * * - *************************************************************************/ - -/* kill.c */ -extern int rl_set_retained_kills PARAMS((int)); - -/* terminal.c */ -extern void _rl_set_screen_size PARAMS((int, int)); - -/* undo.c */ -extern int _rl_fix_last_undo_of_type PARAMS((int, int, int)); - -/* util.c */ -extern char *_rl_savestring PARAMS((const char *)); - -/************************************************************************* - * * - * Functions and variables private to the readline library * - * * - *************************************************************************/ - -/* NOTE: Functions and variables prefixed with `_rl_' are - pseudo-global: they are global so they can be shared - between files in the readline library, but are not intended - to be visible to readline callers. */ - -/************************************************************************* - * Undocumented private functions * - *************************************************************************/ - -#if defined(READLINE_CALLBACKS) - -/* readline.c */ -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 */ - -/* complete.c */ -extern void _rl_reset_completion_state PARAMS((void)); -extern char _rl_find_completion_word PARAMS((int *, int *)); -extern void _rl_free_match_list PARAMS((char **)); - -/* display.c */ -extern char *_rl_strip_prompt PARAMS((char *)); -extern void _rl_move_cursor_relative PARAMS((int, const char *)); -extern void _rl_move_vert PARAMS((int)); -extern void _rl_save_prompt PARAMS((void)); -extern void _rl_restore_prompt PARAMS((void)); -extern char *_rl_make_prompt_for_search PARAMS((int)); -extern void _rl_erase_at_end_of_line PARAMS((int)); -extern void _rl_clear_to_eol PARAMS((int)); -extern void _rl_clear_screen PARAMS((void)); -extern void _rl_update_final PARAMS((void)); -extern void _rl_redisplay_after_sigwinch PARAMS((void)); -extern void _rl_clean_up_for_exit PARAMS((void)); -extern void _rl_erase_entire_line PARAMS((void)); -extern int _rl_current_display_line PARAMS((void)); - -/* input.c */ -extern int _rl_any_typein PARAMS((void)); -extern int _rl_input_available PARAMS((void)); -extern int _rl_input_queued PARAMS((int)); -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)); -extern void _rl_push_executing_macro PARAMS((void)); -extern void _rl_pop_executing_macro PARAMS((void)); -extern void _rl_add_macro_char PARAMS((int)); -extern void _rl_kill_kbd_macro PARAMS((void)); - -/* misc.c */ -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)); - -extern void _rl_revert_all_lines PARAMS((void)); - -/* nls.c */ -extern int _rl_init_eightbit PARAMS((void)); - -/* parens.c */ -extern void _rl_enable_paren_matching PARAMS((int)); - -/* readline.c */ -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 *)); - -/* signals.c */ -extern void _rl_signal_handler PARAMS((int)); - -extern void _rl_block_sigint PARAMS((void)); -extern void _rl_release_sigint PARAMS((void)); -extern void _rl_block_sigwinch PARAMS((void)); -extern void _rl_release_sigwinch PARAMS((void)); - -/* terminal.c */ -extern void _rl_get_screen_size PARAMS((int, int)); -extern int _rl_init_terminal_io PARAMS((const char *)); -#ifdef _MINIX -extern void _rl_output_character_function PARAMS((int)); -#else -extern int _rl_output_character_function PARAMS((int)); -#endif -extern void _rl_output_some_chars PARAMS((const char *, int)); -extern int _rl_backspace PARAMS((int)); -extern void _rl_enable_meta_key PARAMS((void)); -extern void _rl_control_keypad PARAMS((int)); -extern void _rl_set_cursor PARAMS((int, int)); - -/* text.c */ -extern void _rl_fix_point PARAMS((int)); -extern int _rl_replace_text PARAMS((const char *, int, int)); -extern int _rl_forward_char_internal PARAMS((int)); -extern int _rl_insert_char PARAMS((int, int)); -extern int _rl_overwrite_char PARAMS((int, int)); -extern int _rl_overwrite_rubout PARAMS((int, int)); -extern int _rl_rubout_char PARAMS((int, int)); -#if defined (HANDLE_MULTIBYTE) -extern int _rl_char_search_internal PARAMS((int, int, char *, int)); -#else -extern int _rl_char_search_internal PARAMS((int, int, int)); -#endif -extern int _rl_set_mark_at_pos PARAMS((int)); - -/* undo.c */ -extern UNDO_LIST *_rl_copy_undo_entry PARAMS((UNDO_LIST *)); -extern UNDO_LIST *_rl_copy_undo_list PARAMS((UNDO_LIST *)); - -/* util.c */ -#if defined (USE_VARARGS) && defined (PREFER_STDARG) -extern void _rl_ttymsg (const char *, ...) __attribute__((__format__ (printf, 1, 2))); -extern void _rl_errmsg (const char *, ...) __attribute__((__format__ (printf, 1, 2))); -extern void _rl_trace (const char *, ...) __attribute__((__format__ (printf, 1, 2))); -#else -extern void _rl_ttymsg (); -extern void _rl_errmsg (); -extern void _rl_trace (); -#endif - -extern int _rl_tropen PARAMS((void)); - -extern int _rl_abort_internal PARAMS((void)); -extern int _rl_null_function PARAMS((int, int)); -extern char *_rl_strindex PARAMS((const char *, const char *)); -extern int _rl_qsort_string_compare PARAMS((char **, char **)); -extern int (_rl_uppercase_p) PARAMS((int)); -extern int (_rl_lowercase_p) PARAMS((int)); -extern int (_rl_pure_alphabetic) PARAMS((int)); -extern int (_rl_digit_p) PARAMS((int)); -extern int (_rl_to_lower) PARAMS((int)); -extern int (_rl_to_upper) PARAMS((int)); -extern int (_rl_digit_value) PARAMS((int)); - -/* vi_mode.c */ -extern void _rl_vi_initialize_line PARAMS((void)); -extern void _rl_vi_reset_last PARAMS((void)); -extern void _rl_vi_set_last PARAMS((int, int, int)); -extern int _rl_vi_textmod_command PARAMS((int)); -extern void _rl_vi_done_inserting PARAMS((void)); -extern int _rl_vi_domove_callback PARAMS((_rl_vimotion_cxt *)); - -/************************************************************************* - * Undocumented private variables * - *************************************************************************/ - -/* bind.c */ -extern const char * const _rl_possible_control_prefixes[]; -extern const char * const _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; -extern int _rl_complete_mark_directories; -extern int _rl_complete_mark_symlink_dirs; -extern int _rl_completion_prefix_display_length; -extern int _rl_completion_columns; -extern int _rl_print_completions_horizontally; -extern int _rl_completion_case_fold; -extern int _rl_completion_case_map; -extern int _rl_match_hidden_files; -extern int _rl_page_completions; -extern int _rl_skip_completed_text; -extern int _rl_menu_complete_prefix_first; - -/* display.c */ -extern int _rl_vis_botlin; -extern int _rl_last_c_pos; -extern int _rl_suppress_redisplay; -extern int _rl_want_redisplay; - -/* isearch.c */ -extern char *_rl_isearch_terminators; - -extern _rl_search_cxt *_rl_iscxt; - -/* macro.c */ -extern char *_rl_executing_macro; - -/* misc.c */ -extern int _rl_history_preserve_point; -extern int _rl_history_saved_point; - -extern _rl_arg_cxt _rl_argcxt; - -/* readline.c */ -extern int _rl_echoing_p; -extern int _rl_horizontal_scroll_mode; -extern int _rl_mark_modified_lines; -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 int _rl_revert_all_at_newline; -extern int _rl_echo_control_chars; -extern char *_rl_comment_begin; -extern unsigned char _rl_parsing_conditionalized_out; -extern Keymap _rl_keymap; -extern FILE *_rl_in_stream; -extern FILE *_rl_out_stream; -extern int _rl_last_command_was_kill; -extern int _rl_eof_char; -extern procenv_t _rl_top_level; -extern _rl_keyseq_cxt *_rl_kscxt; - -/* search.c */ -extern _rl_search_cxt *_rl_nscxt; - -/* signals.c */ -extern int _rl_interrupt_immediately; -extern int volatile _rl_caught_signal; - -extern int _rl_echoctl; - -extern int _rl_intr_char; -extern int _rl_quit_char; -extern int _rl_susp_char; - -/* terminal.c */ -extern int _rl_enable_keypad; -extern int _rl_enable_meta; -extern char *_rl_term_clreol; -extern char *_rl_term_clrpag; -extern char *_rl_term_im; -extern char *_rl_term_ic; -extern char *_rl_term_ei; -extern char *_rl_term_DC; -extern char *_rl_term_up; -extern char *_rl_term_dc; -extern char *_rl_term_cr; -extern char *_rl_term_IC; -extern char *_rl_term_forward_char; -extern int _rl_screenheight; -extern int _rl_screenwidth; -extern int _rl_screenchars; -extern int _rl_terminal_can_insert; -extern int _rl_term_autowrap; - -/* undo.c */ -extern int _rl_doing_an_undo; -extern int _rl_undo_group_level; - -/* vi_mode.c */ -extern int _rl_vi_last_command; -extern _rl_vimotion_cxt *_rl_vimvcxt; - -#endif /* _RL_PRIVATE_H_ */ diff --git a/lib/readline/rlstdc.h~ b/lib/readline/rlstdc.h~ deleted file mode 100644 index a6d23942..00000000 --- a/lib/readline/rlstdc.h~ +++ /dev/null @@ -1,45 +0,0 @@ -/* stdc.h -- macros to make source compile on both ANSI C and K&R C compilers. */ - -/* Copyright (C) 1993-2009 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library (Readline), a library - for reading lines of text with interactive input and history editing. - - Readline 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 3 of the License, or - (at your option) any later version. - - Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>. -*/ - -#if !defined (_RL_STDC_H_) -#define _RL_STDC_H_ - -/* Adapted from BSD /usr/include/sys/cdefs.h. */ - -/* A function can be defined using prototypes and compile on both ANSI C - and traditional C compilers with something like this: - extern char *func PARAMS((char *, char *, int)); */ - -#if !defined (PARAMS) -# if defined (__STDC__) || defined (__GNUC__) || defined (__cplusplus) -# define PARAMS(protos) protos -# else -# define PARAMS(protos) () -# endif -#endif - -#ifndef __attribute__ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) -# define __attribute__(x) -# endif -#endif - -#endif /* !_RL_STDC_H_ */ diff --git a/lib/readline/rltty.c~ b/lib/readline/rltty.c~ deleted file mode 100644 index d237b1c0..00000000 --- a/lib/readline/rltty.c~ +++ /dev/null @@ -1,975 +0,0 @@ -/* rltty.c -- functions to prepare and restore the terminal for readline's - use. */ - -/* Copyright (C) 1992-2005 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library (Readline), a library - for reading lines of text with interactive input and history editing. - - Readline 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 3 of the License, or - (at your option) any later version. - - Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>. -*/ - -#define READLINE_LIBRARY - -#if defined (HAVE_CONFIG_H) -# include <config.h> -#endif - -#include <sys/types.h> -#include <signal.h> -#include <errno.h> -#include <stdio.h> - -#if defined (HAVE_UNISTD_H) -# include <unistd.h> -#endif /* HAVE_UNISTD_H */ - -#include "rldefs.h" - -#if defined (GWINSZ_IN_SYS_IOCTL) -# include <sys/ioctl.h> -#endif /* GWINSZ_IN_SYS_IOCTL */ - -#include "rltty.h" -#include "readline.h" -#include "rlprivate.h" - -#if !defined (errno) -extern int errno; -#endif /* !errno */ - -rl_vintfunc_t *rl_prep_term_function = rl_prep_terminal; -rl_voidfunc_t *rl_deprep_term_function = rl_deprep_terminal; - -static void set_winsize PARAMS((int)); - -/* **************************************************************** */ -/* */ -/* Saving and Restoring the TTY */ -/* */ -/* **************************************************************** */ - -/* Non-zero means that the terminal is in a prepped state. */ -static int terminal_prepped; - -static _RL_TTY_CHARS _rl_tty_chars, _rl_last_tty_chars; - -/* If non-zero, means that this process has called tcflow(fd, TCOOFF) - and output is suspended. */ -#if defined (__ksr1__) -static int ksrflow; -#endif - -/* Dummy call to force a backgrounded readline to stop before it tries - to get the tty settings. */ -static void -set_winsize (tty) - int tty; -{ -#if defined (TIOCGWINSZ) - struct winsize w; - - if (ioctl (tty, TIOCGWINSZ, &w) == 0) - (void) ioctl (tty, TIOCSWINSZ, &w); -#endif /* TIOCGWINSZ */ -} - -#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 - are valid. */ -#define SGTTY_SET 0x01 -#define LFLAG_SET 0x02 -#define TCHARS_SET 0x04 -#define LTCHARS_SET 0x08 - -struct bsdtty { - struct sgttyb sgttyb; /* Basic BSD tty driver information. */ - int lflag; /* Local mode flags, like LPASS8. */ -#if defined (TIOCGETC) - struct tchars tchars; /* Terminal special characters, including ^S and ^Q. */ -#endif -#if defined (TIOCGLTC) - struct ltchars ltchars; /* 4.2 BSD editing characters */ -#endif - int flags; /* Bitmap saying which parts of the struct are valid. */ -}; - -#define TIOTYPE struct bsdtty - -static TIOTYPE otio; - -static void save_tty_chars PARAMS((TIOTYPE *)); -static int _get_tty_settings PARAMS((int, TIOTYPE *)); -static int get_tty_settings PARAMS((int, TIOTYPE *)); -static int _set_tty_settings PARAMS((int, TIOTYPE *)); -static int set_tty_settings PARAMS((int, TIOTYPE *)); - -static void prepare_terminal_settings PARAMS((int, TIOTYPE, TIOTYPE *)); - -static void set_special_char PARAMS((Keymap, TIOTYPE *, int, rl_command_func_t)); - -static void -save_tty_chars (tiop) - TIOTYPE *tiop; -{ - _rl_last_tty_chars = _rl_tty_chars; - - if (tiop->flags & SGTTY_SET) - { - _rl_tty_chars.t_erase = tiop->sgttyb.sg_erase; - _rl_tty_chars.t_kill = tiop->sgttyb.sg_kill; - } - - if (tiop->flags & TCHARS_SET) - { - _rl_intr_char = _rl_tty_chars.t_intr = tiop->tchars.t_intrc; - _rl_quit_char = _rl_tty_chars.t_quit = tiop->tchars.t_quitc; - - _rl_tty_chars.t_start = tiop->tchars.t_startc; - _rl_tty_chars.t_stop = tiop->tchars.t_stopc; - _rl_tty_chars.t_eof = tiop->tchars.t_eofc; - _rl_tty_chars.t_eol = '\n'; - _rl_tty_chars.t_eol2 = tiop->tchars.t_brkc; - } - - if (tiop->flags & LTCHARS_SET) - { - _rl_susp_char = _rl_tty_chars.t_susp = tiop->ltchars.t_suspc; - - _rl_tty_chars.t_dsusp = tiop->ltchars.t_dsuspc; - _rl_tty_chars.t_reprint = tiop->ltchars.t_rprntc; - _rl_tty_chars.t_flush = tiop->ltchars.t_flushc; - _rl_tty_chars.t_werase = tiop->ltchars.t_werasc; - _rl_tty_chars.t_lnext = tiop->ltchars.t_lnextc; - } - - _rl_tty_chars.t_status = -1; -} - -static int -get_tty_settings (tty, tiop) - int tty; - TIOTYPE *tiop; -{ - set_winsize (tty); - - tiop->flags = tiop->lflag = 0; - - errno = 0; - if (ioctl (tty, TIOCGETP, &(tiop->sgttyb)) < 0) - return -1; - tiop->flags |= SGTTY_SET; - -#if defined (TIOCLGET) - if (ioctl (tty, TIOCLGET, &(tiop->lflag)) == 0) - tiop->flags |= LFLAG_SET; -#endif - -#if defined (TIOCGETC) - if (ioctl (tty, TIOCGETC, &(tiop->tchars)) == 0) - tiop->flags |= TCHARS_SET; -#endif - -#if defined (TIOCGLTC) - if (ioctl (tty, TIOCGLTC, &(tiop->ltchars)) == 0) - tiop->flags |= LTCHARS_SET; -#endif - - return 0; -} - -static int -set_tty_settings (tty, tiop) - int tty; - TIOTYPE *tiop; -{ - if (tiop->flags & SGTTY_SET) - { - ioctl (tty, TIOCSETN, &(tiop->sgttyb)); - tiop->flags &= ~SGTTY_SET; - } - _rl_echoing_p = 1; - -#if defined (TIOCLSET) - if (tiop->flags & LFLAG_SET) - { - ioctl (tty, TIOCLSET, &(tiop->lflag)); - tiop->flags &= ~LFLAG_SET; - } -#endif - -#if defined (TIOCSETC) - if (tiop->flags & TCHARS_SET) - { - ioctl (tty, TIOCSETC, &(tiop->tchars)); - tiop->flags &= ~TCHARS_SET; - } -#endif - -#if defined (TIOCSLTC) - if (tiop->flags & LTCHARS_SET) - { - ioctl (tty, TIOCSLTC, &(tiop->ltchars)); - tiop->flags &= ~LTCHARS_SET; - } -#endif - - return 0; -} - -static void -prepare_terminal_settings (meta_flag, oldtio, tiop) - int meta_flag; - TIOTYPE oldtio, *tiop; -{ - _rl_echoing_p = (oldtio.sgttyb.sg_flags & ECHO); - _rl_echoctl = (oldtio.sgttyb.sg_flags & ECHOCTL); - - /* Copy the original settings to the structure we're going to use for - our settings. */ - tiop->sgttyb = oldtio.sgttyb; - tiop->lflag = oldtio.lflag; -#if defined (TIOCGETC) - tiop->tchars = oldtio.tchars; -#endif -#if defined (TIOCGLTC) - tiop->ltchars = oldtio.ltchars; -#endif - tiop->flags = oldtio.flags; - - /* First, the basic settings to put us into character-at-a-time, no-echo - input mode. */ - tiop->sgttyb.sg_flags &= ~(ECHO | CRMOD); - tiop->sgttyb.sg_flags |= CBREAK; - - /* If this terminal doesn't care how the 8th bit is used, then we can - use it for the meta-key. If only one of even or odd parity is - specified, then the terminal is using parity, and we cannot. */ -#if !defined (ANYP) -# define ANYP (EVENP | ODDP) -#endif - if (((oldtio.sgttyb.sg_flags & ANYP) == ANYP) || - ((oldtio.sgttyb.sg_flags & ANYP) == 0)) - { - tiop->sgttyb.sg_flags |= ANYP; - - /* Hack on local mode flags if we can. */ -#if defined (TIOCLGET) -# if defined (LPASS8) - tiop->lflag |= LPASS8; -# endif /* LPASS8 */ -#endif /* TIOCLGET */ - } - -#if defined (TIOCGETC) -# if defined (USE_XON_XOFF) - /* Get rid of terminal output start and stop characters. */ - tiop->tchars.t_stopc = -1; /* C-s */ - tiop->tchars.t_startc = -1; /* C-q */ - - /* If there is an XON character, bind it to restart the output. */ - if (oldtio.tchars.t_startc != -1) - rl_bind_key (oldtio.tchars.t_startc, rl_restart_output); -# endif /* USE_XON_XOFF */ - - /* If there is an EOF char, bind _rl_eof_char to it. */ - if (oldtio.tchars.t_eofc != -1) - _rl_eof_char = oldtio.tchars.t_eofc; - -# if defined (NO_KILL_INTR) - /* Get rid of terminal-generated SIGQUIT and SIGINT. */ - tiop->tchars.t_quitc = -1; /* C-\ */ - tiop->tchars.t_intrc = -1; /* C-c */ -# endif /* NO_KILL_INTR */ -#endif /* TIOCGETC */ - -#if defined (TIOCGLTC) - /* Make the interrupt keys go away. Just enough to make people happy. */ - tiop->ltchars.t_dsuspc = -1; /* C-y */ - tiop->ltchars.t_lnextc = -1; /* C-v */ -#endif /* TIOCGLTC */ -} - -#else /* !defined (NEW_TTY_DRIVER) */ - -#if !defined (VMIN) -# define VMIN VEOF -#endif - -#if !defined (VTIME) -# define VTIME VEOL -#endif - -#if defined (TERMIOS_TTY_DRIVER) -# define TIOTYPE struct termios -# define DRAIN_OUTPUT(fd) tcdrain (fd) -# define GETATTR(tty, tiop) (tcgetattr (tty, tiop)) -# ifdef M_UNIX -# define SETATTR(tty, tiop) (tcsetattr (tty, TCSANOW, tiop)) -# else -# define SETATTR(tty, tiop) (tcsetattr (tty, TCSADRAIN, tiop)) -# endif /* !M_UNIX */ -#else -# define TIOTYPE struct termio -# define DRAIN_OUTPUT(fd) -# define GETATTR(tty, tiop) (ioctl (tty, TCGETA, tiop)) -# define SETATTR(tty, tiop) (ioctl (tty, TCSETAW, tiop)) -#endif /* !TERMIOS_TTY_DRIVER */ - -static TIOTYPE otio; - -static void save_tty_chars PARAMS((TIOTYPE *)); -static int _get_tty_settings PARAMS((int, TIOTYPE *)); -static int get_tty_settings PARAMS((int, TIOTYPE *)); -static int _set_tty_settings PARAMS((int, TIOTYPE *)); -static int set_tty_settings PARAMS((int, TIOTYPE *)); - -static void prepare_terminal_settings PARAMS((int, TIOTYPE, TIOTYPE *)); - -static void set_special_char PARAMS((Keymap, TIOTYPE *, int, rl_command_func_t)); -static void _rl_bind_tty_special_chars PARAMS((Keymap, TIOTYPE)); - -#if defined (FLUSHO) -# define OUTPUT_BEING_FLUSHED(tp) (tp->c_lflag & FLUSHO) -#else -# define OUTPUT_BEING_FLUSHED(tp) 0 -#endif - -static void -save_tty_chars (tiop) - TIOTYPE *tiop; -{ - _rl_last_tty_chars = _rl_tty_chars; - - _rl_tty_chars.t_eof = tiop->c_cc[VEOF]; - _rl_tty_chars.t_eol = tiop->c_cc[VEOL]; -#ifdef VEOL2 - _rl_tty_chars.t_eol2 = tiop->c_cc[VEOL2]; -#endif - _rl_tty_chars.t_erase = tiop->c_cc[VERASE]; -#ifdef VWERASE - _rl_tty_chars.t_werase = tiop->c_cc[VWERASE]; -#endif - _rl_tty_chars.t_kill = tiop->c_cc[VKILL]; -#ifdef VREPRINT - _rl_tty_chars.t_reprint = tiop->c_cc[VREPRINT]; -#endif - _rl_intr_char = _rl_tty_chars.t_intr = tiop->c_cc[VINTR]; - _rl_quit_char = _rl_tty_chars.t_quit = tiop->c_cc[VQUIT]; -#ifdef VSUSP - _rl_susp_char = _rl_tty_chars.t_susp = tiop->c_cc[VSUSP]; -#endif -#ifdef VDSUSP - _rl_tty_chars.t_dsusp = tiop->c_cc[VDSUSP]; -#endif -#ifdef VSTART - _rl_tty_chars.t_start = tiop->c_cc[VSTART]; -#endif -#ifdef VSTOP - _rl_tty_chars.t_stop = tiop->c_cc[VSTOP]; -#endif -#ifdef VLNEXT - _rl_tty_chars.t_lnext = tiop->c_cc[VLNEXT]; -#endif -#ifdef VDISCARD - _rl_tty_chars.t_flush = tiop->c_cc[VDISCARD]; -#endif -#ifdef VSTATUS - _rl_tty_chars.t_status = tiop->c_cc[VSTATUS]; -#endif -} - -#if defined (_AIX) || defined (_AIX41) -/* Currently this is only used on AIX */ -static void -rltty_warning (msg) - char *msg; -{ - _rl_errmsg ("warning: %s", msg); -} -#endif - -#if defined (_AIX) -void -setopost(tp) -TIOTYPE *tp; -{ - if ((tp->c_oflag & OPOST) == 0) - { - _rl_errmsg ("warning: turning on OPOST for terminal\r"); - tp->c_oflag |= OPOST|ONLCR; - } -} -#endif - -static int -_get_tty_settings (tty, tiop) - int tty; - TIOTYPE *tiop; -{ - int ioctl_ret; - - while (1) - { - ioctl_ret = GETATTR (tty, tiop); - if (ioctl_ret < 0) - { - if (errno != EINTR) - return -1; - else - continue; - } - if (OUTPUT_BEING_FLUSHED (tiop)) - { -#if defined (FLUSHO) - _rl_errmsg ("warning: turning off output flushing"); - tiop->c_lflag &= ~FLUSHO; - break; -#else - continue; -#endif - } - break; - } - - return 0; -} - -static int -get_tty_settings (tty, tiop) - int tty; - TIOTYPE *tiop; -{ - set_winsize (tty); - - errno = 0; - if (_get_tty_settings (tty, tiop) < 0) - return -1; - -#if defined (_AIX) - setopost(tiop); -#endif - - return 0; -} - -static int -_set_tty_settings (tty, tiop) - int tty; - TIOTYPE *tiop; -{ - while (SETATTR (tty, tiop) < 0) - { - if (errno != EINTR) - return -1; - errno = 0; - } - return 0; -} - -static int -set_tty_settings (tty, tiop) - int tty; - TIOTYPE *tiop; -{ - if (_set_tty_settings (tty, tiop) < 0) - return -1; - -#if 0 - -#if defined (TERMIOS_TTY_DRIVER) -# if defined (__ksr1__) - if (ksrflow) - { - ksrflow = 0; - tcflow (tty, TCOON); - } -# else /* !ksr1 */ - tcflow (tty, TCOON); /* Simulate a ^Q. */ -# endif /* !ksr1 */ -#else - ioctl (tty, TCXONC, 1); /* Simulate a ^Q. */ -#endif /* !TERMIOS_TTY_DRIVER */ - -#endif /* 0 */ - - return 0; -} - -static void -prepare_terminal_settings (meta_flag, oldtio, tiop) - int meta_flag; - TIOTYPE oldtio, *tiop; -{ - _rl_echoing_p = (oldtio.c_lflag & ECHO); -#if defined (ECHOCTL) - _rl_echoctl = (oldtio.c_lflag & ECHOCTL); -#endif - - tiop->c_lflag &= ~(ICANON | ECHO); - - if ((unsigned char) oldtio.c_cc[VEOF] != (unsigned char) _POSIX_VDISABLE) - _rl_eof_char = oldtio.c_cc[VEOF]; - -#if defined (USE_XON_XOFF) -#if defined (IXANY) - tiop->c_iflag &= ~(IXON | IXOFF | IXANY); -#else - /* `strict' Posix systems do not define IXANY. */ - tiop->c_iflag &= ~(IXON | IXOFF); -#endif /* IXANY */ -#endif /* USE_XON_XOFF */ - - /* Only turn this off if we are using all 8 bits. */ - if (((tiop->c_cflag & CSIZE) == CS8) || meta_flag) - tiop->c_iflag &= ~(ISTRIP | INPCK); - - /* Make sure we differentiate between CR and NL on input. */ - tiop->c_iflag &= ~(ICRNL | INLCR); - -#if !defined (HANDLE_SIGNALS) - tiop->c_lflag &= ~ISIG; -#else - tiop->c_lflag |= ISIG; -#endif - - tiop->c_cc[VMIN] = 1; - tiop->c_cc[VTIME] = 0; - -#if defined (FLUSHO) - if (OUTPUT_BEING_FLUSHED (tiop)) - { - tiop->c_lflag &= ~FLUSHO; - oldtio.c_lflag &= ~FLUSHO; - } -#endif - - /* Turn off characters that we need on Posix systems with job control, - just to be sure. This includes ^Y and ^V. This should not really - be necessary. */ -#if defined (TERMIOS_TTY_DRIVER) && defined (_POSIX_VDISABLE) - -#if defined (VLNEXT) - tiop->c_cc[VLNEXT] = _POSIX_VDISABLE; -#endif - -#if defined (VDSUSP) - tiop->c_cc[VDSUSP] = _POSIX_VDISABLE; -#endif - -#endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */ -} -#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; -{ - _rl_echoing_p = 1; -} - -void -rl_deprep_terminal () -{ -} - -#else /* ! NO_TTY_DRIVER */ -void -rl_prep_terminal (meta_flag) - int meta_flag; -{ - int tty; - TIOTYPE tio; - - if (terminal_prepped) - return; - - /* Try to keep this function from being INTerrupted. */ - _rl_block_sigint (); - - tty = rl_instream ? fileno (rl_instream) : fileno (stdin); - - if (get_tty_settings (tty, &tio) < 0) - { -#if defined (ENOTSUP) - /* MacOS X and Linux, at least, lie about the value of errno if - tcgetattr fails. */ - if (errno == ENOTTY || errno == EINVAL || errno == ENOTSUP) -#else - if (errno == ENOTTY || errno == EINVAL) -#endif - _rl_echoing_p = 1; /* XXX */ - - _rl_release_sigint (); - return; - } - - otio = tio; - - 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); - 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); - - if (set_tty_settings (tty, &tio) < 0) - { - _rl_release_sigint (); - return; - } - - if (_rl_enable_keypad) - _rl_control_keypad (1); - - fflush (rl_outstream); - terminal_prepped = 1; - RL_SETSTATE(RL_STATE_TERMPREPPED); - - _rl_release_sigint (); -} - -/* Restore the terminal's normal settings and modes. */ -void -rl_deprep_terminal () -{ - int tty; - - if (!terminal_prepped) - return; - - /* Try to keep this function from being interrupted. */ - _rl_block_sigint (); - - tty = rl_instream ? fileno (rl_instream) : fileno (stdout); - - if (_rl_enable_keypad) - _rl_control_keypad (0); - - fflush (rl_outstream); - - if (set_tty_settings (tty, &otio) < 0) - { - _rl_release_sigint (); - return; - } - - terminal_prepped = 0; - RL_UNSETSTATE(RL_STATE_TERMPREPPED); - - _rl_release_sigint (); -} -#endif /* !NO_TTY_DRIVER */ - -/* **************************************************************** */ -/* */ -/* Bogus Flow Control */ -/* */ -/* **************************************************************** */ - -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) - ioctl (&fildes, TIOCSTART, 0); -#else - ioctl (fildes, TIOCSTART, 0); -#endif /* apollo */ - -#else /* !TIOCSTART */ -# if defined (TERMIOS_TTY_DRIVER) -# if defined (__ksr1__) - if (ksrflow) - { - ksrflow = 0; - tcflow (fildes, TCOON); - } -# else /* !ksr1 */ - tcflow (fildes, TCOON); /* Simulate a ^Q. */ -# endif /* !ksr1 */ -# else /* !TERMIOS_TTY_DRIVER */ -# if defined (TCXONC) - ioctl (fildes, TCXONC, TCOON); -# endif /* TCXONC */ -# endif /* !TERMIOS_TTY_DRIVER */ -#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) -# if defined (apollo) - ioctl (&fildes, TIOCSTOP, 0); -# else - ioctl (fildes, TIOCSTOP, 0); -# endif /* apollo */ -#else /* !TIOCSTOP */ -# if defined (TERMIOS_TTY_DRIVER) -# if defined (__ksr1__) - ksrflow = 1; -# endif /* ksr1 */ - tcflow (fildes, TCOOFF); -# else -# if defined (TCXONC) - ioctl (fildes, TCXONC, TCOON); -# endif /* TCXONC */ -# endif /* !TERMIOS_TTY_DRIVER */ -#endif /* !TIOCSTOP */ - - return 0; -#endif /* !__MINGW32__ */ -} - -/* **************************************************************** */ -/* */ -/* Default Key Bindings */ -/* */ -/* **************************************************************** */ - -#if !defined (NO_TTY_DRIVER) -#define SET_SPECIAL(sc, func) set_special_char(kmap, &ttybuff, sc, func) -#endif - -#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; - TIOTYPE *tiop; - int sc; - rl_command_func_t *func; -{ - if (sc != -1 && kmap[(unsigned char)sc].type == ISFUNC) - kmap[(unsigned char)sc].function = func; -} - -#define RESET_SPECIAL(c) \ - if (c != -1 && kmap[(unsigned char)c].type == ISFUNC) \ - kmap[(unsigned char)c].function = rl_insert; - -static void -_rl_bind_tty_special_chars (kmap, ttybuff) - Keymap kmap; - TIOTYPE ttybuff; -{ - if (ttybuff.flags & SGTTY_SET) - { - SET_SPECIAL (ttybuff.sgttyb.sg_erase, rl_rubout); - SET_SPECIAL (ttybuff.sgttyb.sg_kill, rl_unix_line_discard); - } - -# if defined (TIOCGLTC) - if (ttybuff.flags & LTCHARS_SET) - { - SET_SPECIAL (ttybuff.ltchars.t_werasc, rl_unix_word_rubout); - SET_SPECIAL (ttybuff.ltchars.t_lnextc, rl_quoted_insert); - } -# endif /* TIOCGLTC */ -} - -#else /* !NEW_TTY_DRIVER */ -static void -set_special_char (kmap, tiop, sc, func) - Keymap kmap; - TIOTYPE *tiop; - int sc; - rl_command_func_t *func; -{ - unsigned char uc; - - uc = tiop->c_cc[sc]; - if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) - kmap[uc].function = func; -} - -/* used later */ -#define RESET_SPECIAL(uc) \ - if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) \ - kmap[uc].function = rl_insert; - -static void -_rl_bind_tty_special_chars (kmap, ttybuff) - Keymap kmap; - TIOTYPE ttybuff; -{ - SET_SPECIAL (VERASE, rl_rubout); - SET_SPECIAL (VKILL, rl_unix_line_discard); - -# if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER) - SET_SPECIAL (VLNEXT, rl_quoted_insert); -# endif /* VLNEXT && TERMIOS_TTY_DRIVER */ - -# if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER) - SET_SPECIAL (VWERASE, rl_unix_word_rubout); -# endif /* VWERASE && TERMIOS_TTY_DRIVER */ -} - -#endif /* !NEW_TTY_DRIVER */ - -/* Set the system's default editing characters to their readline equivalents - in KMAP. Should be static, now that we have rl_tty_set_default_bindings. */ -void -rltty_set_default_bindings (kmap) - Keymap kmap; -{ -#if !defined (NO_TTY_DRIVER) - TIOTYPE ttybuff; - int tty; - - tty = fileno (rl_instream); - - 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 - equivalents. */ -void -rl_tty_set_default_bindings (kmap) - Keymap kmap; -{ - rltty_set_default_bindings (kmap); -} - -/* Rebind all of the tty special chars that readline worries about back - to self-insert. Call this before saving the current terminal special - chars with save_tty_chars(). This only works on POSIX termios or termio - systems. */ -void -rl_tty_unset_default_bindings (kmap) - Keymap kmap; -{ - /* Don't bother before we've saved the tty special chars at least once. */ - if (RL_ISSTATE(RL_STATE_TTYCSAVED) == 0) - return; - - RESET_SPECIAL (_rl_tty_chars.t_erase); - RESET_SPECIAL (_rl_tty_chars.t_kill); - -# if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER) - RESET_SPECIAL (_rl_tty_chars.t_lnext); -# endif /* VLNEXT && TERMIOS_TTY_DRIVER */ - -# if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER) - RESET_SPECIAL (_rl_tty_chars.t_werase); -# endif /* VWERASE && TERMIOS_TTY_DRIVER */ -} - -#if defined (HANDLE_SIGNALS) - -#if defined (NEW_TTY_DRIVER) || defined (NO_TTY_DRIVER) -int -_rl_disable_tty_signals () -{ - return 0; -} - -int -_rl_restore_tty_signals () -{ - return 0; -} -#else - -static TIOTYPE sigstty, nosigstty; -static int tty_sigs_disabled = 0; - -int -_rl_disable_tty_signals () -{ - if (tty_sigs_disabled) - return 0; - - if (_get_tty_settings (fileno (rl_instream), &sigstty) < 0) - return -1; - - nosigstty = sigstty; - - nosigstty.c_lflag &= ~ISIG; - nosigstty.c_iflag &= ~IXON; - - if (_set_tty_settings (fileno (rl_instream), &nosigstty) < 0) - return (_set_tty_settings (fileno (rl_instream), &sigstty)); - - tty_sigs_disabled = 1; - return 0; -} - -int -_rl_restore_tty_signals () -{ - int r; - - if (tty_sigs_disabled == 0) - return 0; - - r = _set_tty_settings (fileno (rl_instream), &sigstty); - - if (r == 0) - tty_sigs_disabled = 0; - - return r; -} -#endif /* !NEW_TTY_DRIVER */ - -#endif /* HANDLE_SIGNALS */ diff --git a/lib/readline/rltypedefs.h~ b/lib/readline/rltypedefs.h~ deleted file mode 100644 index 60f29a18..00000000 --- a/lib/readline/rltypedefs.h~ +++ /dev/null @@ -1,93 +0,0 @@ -/* rltypedefs.h -- Type declarations for readline functions. */ - -/* Copyright (C) 2000-2009 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library (Readline), a library - for reading lines of text with interactive input and history editing. - - Readline 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 3 of the License, or - (at your option) any later version. - - Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef _RL_TYPEDEFS_H_ -#define _RL_TYPEDEFS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Old-style */ - -#if !defined (_FUNCTION_DEF) -# define _FUNCTION_DEF - -typedef int Function (); -typedef void VFunction (); -typedef char *CPFunction (); -typedef char **CPPFunction (); - -#endif /* _FUNCTION_DEF */ - -/* New style. */ - -#if !defined (_RL_FUNCTION_TYPEDEF) -# define _RL_FUNCTION_TYPEDEF - -/* Bindable functions */ -typedef int rl_command_func_t PARAMS((int, int)); - -/* Typedefs for the completion system */ -typedef char *rl_compentry_func_t PARAMS((const char *, int)); -typedef char **rl_completion_func_t PARAMS((const char *, int, int)); - -typedef char *rl_quote_func_t PARAMS((char *, int, char *)); -typedef char *rl_dequote_func_t PARAMS((char *, int)); - -typedef int rl_compignore_func_t PARAMS((char **)); - -typedef void rl_compdisp_func_t PARAMS((char **, int, int)); - -/* Type for input and pre-read hook functions like rl_event_hook */ -typedef int rl_hook_func_t PARAMS((void)); - -/* Input function type */ -typedef int rl_getc_func_t PARAMS((FILE *)); - -/* Generic function that takes a character buffer (which could be the readline - line buffer) and an index into it (which could be rl_point) and returns - an int. */ -typedef int rl_linebuf_func_t PARAMS((char *, int)); - -/* `Generic' function pointer typedefs */ -typedef int rl_intfunc_t PARAMS((int)); -#define rl_ivoidfunc_t rl_hook_func_t -typedef int rl_icpfunc_t PARAMS((char *)); -typedef int rl_icppfunc_t PARAMS((char **)); - -typedef void rl_voidfunc_t PARAMS((void)); -typedef void rl_vintfunc_t PARAMS((int)); -typedef void rl_vcpfunc_t PARAMS((char *)); -typedef void rl_vcppfunc_t PARAMS((char **)); - -typedef char *rl_cpvfunc_t PARAMS((void)); -typedef char *rl_cpifunc_t PARAMS((int)); -typedef char *rl_cpcpfunc_t PARAMS((char *)); -typedef char *rl_cpcppfunc_t PARAMS((char **)); - -#endif /* _RL_FUNCTION_TYPEDEF */ - -#ifdef __cplusplus -} -#endif - -#endif /* _RL_TYPEDEFS_H_ */ diff --git a/lib/readline/search.c~ b/lib/readline/search.c~ deleted file mode 100644 index 9fcdd2fc..00000000 --- a/lib/readline/search.c~ +++ /dev/null @@ -1,590 +0,0 @@ -/* search.c - code for non-incremental searching in emacs and vi modes. */ - -/* Copyright (C) 1992-2009 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library (Readline), a library - for reading lines of text with interactive input and history editing. - - Readline 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 3 of the License, or - (at your option) any later version. - - Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>. -*/ - -#define READLINE_LIBRARY - -#if defined (HAVE_CONFIG_H) -# include <config.h> -#endif - -#include <sys/types.h> -#include <stdio.h> - -#if defined (HAVE_UNISTD_H) -# include <unistd.h> -#endif - -#if defined (HAVE_STDLIB_H) -# include <stdlib.h> -#else -# include "ansi_stdlib.h" -#endif - -#include "rldefs.h" -#include "rlmbutil.h" - -#include "readline.h" -#include "history.h" -#include "histlib.h" - -#include "rlprivate.h" -#include "xmalloc.h" - -#ifdef abs -# undef abs -#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. */ -extern int _rl_free_history_entry PARAMS((HIST_ENTRY *)); - -static char *noninc_search_string = (char *) NULL; -static int noninc_history_pos; - -static char *prev_line_found = (char *) NULL; - -static int rl_history_search_len; -static int rl_history_search_pos; -static int rl_history_search_flags; - -static char *history_search_string; -static int history_string_size; - -static void make_history_line_current PARAMS((HIST_ENTRY *)); -static int noninc_search_from_pos PARAMS((char *, 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((int)); - -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. */ -static void -make_history_line_current (entry) - HIST_ENTRY *entry; -{ - _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) - _rl_free_history_entry (_rl_saved_line_for_history); - _rl_saved_line_for_history = (HIST_ENTRY *)NULL; -} - -/* Search the history list for STRING starting at absolute history position - POS. If STRING begins with `^', the search must match STRING at the - beginning of a history line, otherwise a full substring match is performed - for STRING. DIR < 0 means to search backwards through the history list, - DIR >= 0 means to search forward. */ -static int -noninc_search_from_pos (string, pos, dir) - char *string; - int pos, dir; -{ - int ret, old; - - if (pos < 0) - return -1; - - old = where_history (); - if (history_set_pos (pos) == 0) - return -1; - - RL_SETSTATE(RL_STATE_SEARCH); - if (*string == '^') - ret = history_search_prefix (string + 1, dir); - else - ret = history_search (string, dir); - RL_UNSETSTATE(RL_STATE_SEARCH); - - if (ret != -1) - ret = where_history (); - - history_set_pos (old); - return (ret); -} - -/* Search for a line in the history containing STRING. If DIR is < 0, the - search is backwards through previous entries, else through subsequent - entries. Returns 1 if the search was successful, 0 otherwise. */ -static int -noninc_dosearch (string, dir) - char *string; - int dir; -{ - int oldpos, pos; - HIST_ENTRY *entry; - - if (string == 0 || *string == '\0' || noninc_history_pos < 0) - { - rl_ding (); - return 0; - } - - pos = noninc_search_from_pos (string, noninc_history_pos + dir, dir); - if (pos == -1) - { - /* Search failed, current history position unchanged. */ - rl_maybe_unsave_line (); - rl_clear_message (); - rl_point = 0; - rl_ding (); - return 0; - } - - noninc_history_pos = pos; - - oldpos = where_history (); - history_set_pos (noninc_history_pos); - entry = current_history (); -#if defined (VI_MODE) - if (rl_editing_mode != vi_mode) -#endif - history_set_pos (oldpos); - - make_history_line_current (entry); - - rl_point = 0; - rl_mark = rl_end; - - rl_clear_message (); - return 1; -} - -static _rl_search_cxt * -_rl_nsearch_init (dir, pchar) - int dir, pchar; -{ - _rl_search_cxt *cxt; - char *p; - - 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 (); - - /* 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 - finish reading the search string. */ - rl_undo_list = 0; - - /* Use the line buffer to read the search string. */ - rl_line_buffer[0] = 0; - rl_end = rl_point = 0; - - p = _rl_make_prompt_for_search (pchar ? pchar : ':'); - rl_message ("%s", p, 0); - xfree (p); - - RL_SETSTATE(RL_STATE_NSEARCH); - - _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) - rl_insert_text (cxt->mb); - else -#endif - _rl_insert_char (1, c); - break; - } - - (*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 == 0) - { - rl_ding (); - 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 = 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 (); - 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 - code calls this, KEY will be `?'. */ -int -rl_noninc_forward_search (count, key) - int count, key; -{ - return noninc_search (1, (key == '?') ? '?' : 0); -} - -/* Reverse search the history list for a string. If the vi-mode code - calls this, KEY will be `/'. */ -int -rl_noninc_reverse_search (count, key) - int count, key; -{ - return noninc_search (-1, (key == '/') ? '/' : 0); -} - -/* Search forward through the history list for the last string searched - for. If there is no saved search string, abort. */ -int -rl_noninc_forward_search_again (count, key) - int count, key; -{ - int r; - - if (!noninc_search_string) - { - rl_ding (); - return (-1); - } - r = noninc_dosearch (noninc_search_string, 1); - return (r != 1); -} - -/* Reverse search in the history list for the last string searched - for. If there is no saved search string, abort. */ -int -rl_noninc_reverse_search_again (count, key) - int count, key; -{ - int r; - - if (!noninc_search_string) - { - rl_ding (); - return (-1); - } - 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; -{ - HIST_ENTRY *temp; - int ret, oldpos; - char *t; - - rl_maybe_save_line (); - temp = (HIST_ENTRY *)NULL; - - /* Search COUNT times through the history for a line matching - history_search_string. If history_search_string[0] == '^', the - line must match from the start; otherwise any substring can match. - When this loop finishes, TEMP, if non-null, is the history line to - copy into the line buffer. */ - while (count) - { - ret = noninc_search_from_pos (history_search_string, rl_history_search_pos + dir, dir); - if (ret == -1) - break; - - /* Get the history entry we found. */ - rl_history_search_pos = ret; - oldpos = where_history (); - history_set_pos (rl_history_search_pos); - temp = current_history (); - history_set_pos (oldpos); - - /* Don't find multiple instances of the same line. */ - if (prev_line_found && STREQ (prev_line_found, temp->line)) - continue; - prev_line_found = temp->line; - count--; - } - - /* If we didn't find anything at all, return. */ - if (temp == 0) - { - rl_maybe_unsave_line (); - rl_ding (); - /* If you don't want the saved history line (last match) to show up - in the line buffer after the search fails, change the #if 0 to - #if 1 */ -#if 0 - if (rl_point > rl_history_search_len) - { - rl_point = rl_end = rl_history_search_len; - rl_line_buffer[rl_end] = '\0'; - rl_mark = 0; - } -#else - rl_point = rl_history_search_len; /* rl_maybe_unsave_line changes it */ - rl_mark = rl_end; -#endif - return 1; - } - - /* Copy the line we found into the current line buffer. */ - make_history_line_current (temp); - - if (rl_history_search_flags & ANCHORED_SEARCH) - rl_point = rl_history_search_len; /* easy case */ - else - { - t = strstr (rl_line_buffer, history_search_string); - rl_point = t ? (int)(t - rl_line_buffer) + rl_history_search_len : rl_end; - } - rl_mark = rl_end; - - return 0; -} - -static void -rl_history_search_reinit (flags) - int flags; -{ - int sind; - - rl_history_search_pos = where_history (); - rl_history_search_len = rl_point; - rl_history_search_flags = flags; - - prev_line_found = (char *)NULL; - if (rl_point) - { - /* Allocate enough space for anchored and non-anchored searches */ - if (rl_history_search_len >= history_string_size - 2) - { - history_string_size = rl_history_search_len + 2; - history_search_string = (char *)xrealloc (history_search_string, history_string_size); - } - sind = 0; - if (flags & ANCHORED_SEARCH) - history_search_string[sind++] = '^'; - strncpy (history_search_string + sind, rl_line_buffer, rl_point); - history_search_string[rl_point + sind] = '\0'; - } - _rl_free_saved_history_line (); -} - -/* Search forward in the history for the string of characters - from the start of the line to rl_point. This is a non-incremental - search. */ -int -rl_history_search_forward (count, ignore) - int count, ignore; -{ - if (count == 0) - return (0); - - if (rl_last_func != rl_history_search_forward && - rl_last_func != rl_history_search_backward) - rl_history_search_reinit (ANCHORED_SEARCH); - - if (rl_history_search_len == 0) - return (rl_get_next_history (count, ignore)); - return (rl_history_search_internal (abs (count), (count > 0) ? 1 : -1)); -} - -/* Search backward through the history for the string of characters - from the start of the line to rl_point. This is a non-incremental - search. */ -int -rl_history_search_backward (count, ignore) - int count, ignore; -{ - if (count == 0) - return (0); - - if (rl_last_func != rl_history_search_forward && - rl_last_func != rl_history_search_backward) - rl_history_search_reinit (ANCHORED_SEARCH); - - if (rl_history_search_len == 0) - return (rl_get_previous_history (count, ignore)); - return (rl_history_search_internal (abs (count), (count > 0) ? -1 : 1)); -} diff --git a/lib/readline/shell.c~ b/lib/readline/shell.c~ deleted file mode 100644 index 458ce52d..00000000 --- a/lib/readline/shell.c~ +++ /dev/null @@ -1,212 +0,0 @@ -/* shell.c -- readline utility functions that are normally provided by - bash when readline is linked as part of the shell. */ - -/* Copyright (C) 1997-2009 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library (Readline), a library - for reading lines of text with interactive input and history editing. - - Readline 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 3 of the License, or - (at your option) any later version. - - Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>. -*/ - -#define READLINE_LIBRARY - -#if defined (HAVE_CONFIG_H) -# include <config.h> -#endif - -#include <sys/types.h> - -#if defined (HAVE_UNISTD_H) -# include <unistd.h> -#endif /* HAVE_UNISTD_H */ - -#if defined (HAVE_STDLIB_H) -# include <stdlib.h> -#else -# include "ansi_stdlib.h" -#endif /* HAVE_STDLIB_H */ - -#if defined (HAVE_STRING_H) -# include <string.h> -#else -# include <strings.h> -#endif /* !HAVE_STRING_H */ - -#if defined (HAVE_LIMITS_H) -# 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> - -#include "rlstdc.h" -#include "rlshell.h" -#include "xmalloc.h" - -#if defined (HAVE_GETPWUID) && !defined (HAVE_GETPW_DECLS) -extern struct passwd *getpwuid PARAMS((uid_t)); -#endif /* HAVE_GETPWUID && !HAVE_GETPW_DECLS */ - -#ifndef NULL -# define NULL 0 -#endif - -#ifndef CHAR_BIT -# define CHAR_BIT 8 -#endif - -/* Nonzero if the integer type T is signed. */ -#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) - -/* Bound on length of the string representing an integer value of type T. - Subtract one for the sign bit if T is signed; - 302 / 1000 is log10 (2) rounded up; - add one for integer division truncation; - add one more for a minus sign if t is signed. */ -#define INT_STRLEN_BOUND(t) \ - ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 1000 \ - + 1 + TYPE_SIGNED (t)) - -/* All of these functions are resolved from bash if we are linking readline - as part of bash. */ - -/* Does shell-like quoting using single quotes. */ -char * -sh_single_quote (string) - char *string; -{ - register int c; - char *result, *r, *s; - - result = (char *)xmalloc (3 + (4 * strlen (string))); - r = result; - *r++ = '\''; - - for (s = string; s && (c = *s); s++) - { - *r++ = c; - - if (c == '\'') - { - *r++ = '\\'; /* insert escaped single quote */ - *r++ = '\''; - *r++ = '\''; /* start new quoted string */ - } - } - - *r++ = '\''; - *r = '\0'; - - return (result); -} - -/* Set the environment variables LINES and COLUMNS to lines and cols, - respectively. */ -void -sh_set_lines_and_columns (lines, cols) - int lines, cols; -{ - char *b; - -#if defined (HAVE_SETENV) - b = (char *)xmalloc (INT_STRLEN_BOUND (int) + 1); - sprintf (b, "%d", lines); - setenv ("LINES", b, 1); - xfree (b); - - b = (char *)xmalloc (INT_STRLEN_BOUND (int) + 1); - sprintf (b, "%d", cols); - setenv ("COLUMNS", b, 1); - xfree (b); -#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 * -sh_get_env_value (varname) - const char *varname; -{ - return ((char *)getenv (varname)); -} - -char * -sh_get_home_dir () -{ - char *home_dir; - struct passwd *entry; - - home_dir = (char *)NULL; -#if defined (HAVE_GETPWUID) -# if defined (__TANDEM) - entry = getpwnam (getlogin ()); -# else - entry = getpwuid (getuid ()); -# endif - if (entry) - home_dir = entry->pw_dir; -#endif - return (home_dir); -} - -#if !defined (O_NDELAY) -# if defined (FNDELAY) -# define O_NDELAY FNDELAY -# endif -#endif - -int -sh_unset_nodelay_mode (fd) - int fd; -{ -#if defined (HAVE_FCNTL) - int flags, bflags; - - if ((flags = fcntl (fd, F_GETFL, 0)) < 0) - return -1; - - bflags = 0; - -#ifdef O_NONBLOCK - bflags |= O_NONBLOCK; -#endif - -#ifdef O_NDELAY - bflags |= O_NDELAY; -#endif - - if (flags & bflags) - { - flags &= ~bflags; - return (fcntl (fd, F_SETFL, flags)); - } -#endif - - return 0; -} diff --git a/lib/readline/signals.c~ b/lib/readline/signals.c~ deleted file mode 100644 index ba2674ab..00000000 --- a/lib/readline/signals.c~ +++ /dev/null @@ -1,678 +0,0 @@ -/* signals.c -- signal handling support for readline. */ - -/* Copyright (C) 1987-2011 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library (Readline), a library - for reading lines of text with interactive input and history editing. - - Readline 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 3 of the License, or - (at your option) any later version. - - Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>. -*/ - -#define READLINE_LIBRARY - -#if defined (HAVE_CONFIG_H) -# include <config.h> -#endif - -#include <stdio.h> /* Just for NULL. Yuck. */ -#include <sys/types.h> -#include <signal.h> - -#if defined (HAVE_UNISTD_H) -# include <unistd.h> -#endif /* HAVE_UNISTD_H */ - -/* System-specific feature definitions and include files. */ -#include "rldefs.h" - -#if defined (GWINSZ_IN_SYS_IOCTL) -# include <sys/ioctl.h> -#endif /* GWINSZ_IN_SYS_IOCTL */ - -/* Some standard library routines. */ -#include "readline.h" -#include "history.h" - -#include "rlprivate.h" - -#if defined (HANDLE_SIGNALS) - -#if !defined (RETSIGTYPE) -# if defined (VOID_SIGHANDLER) -# define RETSIGTYPE void -# else -# define RETSIGTYPE int -# endif /* !VOID_SIGHANDLER */ -#endif /* !RETSIGTYPE */ - -#if defined (VOID_SIGHANDLER) -# define SIGHANDLER_RETURN return -#else -# define SIGHANDLER_RETURN return (0) -#endif - -/* This typedef is equivalent to the one for Function; it allows us - to say SigHandler *foo = signal (SIGKILL, SIG_IGN); */ -typedef RETSIGTYPE SigHandler (); - -#if defined (HAVE_POSIX_SIGNALS) -typedef struct sigaction sighandler_cxt; -# define rl_sigaction(s, nh, oh) sigaction(s, nh, oh) -#else -typedef struct { SigHandler *sa_handler; int sa_mask, sa_flags; } sighandler_cxt; -# define sigemptyset(m) -#endif /* !HAVE_POSIX_SIGNALS */ - -#ifndef SA_RESTART -# define SA_RESTART 0 -#endif - -static SigHandler *rl_set_sighandler PARAMS((int, SigHandler *, sighandler_cxt *)); -static void rl_maybe_set_sighandler PARAMS((int, SigHandler *, sighandler_cxt *)); - -static RETSIGTYPE rl_signal_handler PARAMS((int)); -static RETSIGTYPE _rl_handle_signal PARAMS((int)); - -/* Exported variables for use by applications. */ - -/* If non-zero, readline will install its own signal handlers for - SIGINT, SIGTERM, SIGHUP, SIGQUIT, SIGALRM, SIGTSTP, SIGTTIN, and SIGTTOU. */ -int rl_catch_signals = 1; - -/* If non-zero, readline will install a signal handler for SIGWINCH. */ -#ifdef SIGWINCH -int rl_catch_sigwinch = 1; -#else -int rl_catch_sigwinch = 0; /* for the readline state struct in readline.c */ -#endif - -/* Private variables. */ -int _rl_interrupt_immediately = 0; -int volatile _rl_caught_signal = 0; /* should be sig_atomic_t, but that requires including <signal.h> everywhere */ - -/* If non-zero, print characters corresponding to received signals as long as - the user has indicated his desire to do so (_rl_echo_control_chars). */ -int _rl_echoctl = 0; - -int _rl_intr_char = 0; -int _rl_quit_char = 0; -int _rl_susp_char = 0; - -static int signals_set_flag; -static int sigwinch_set_flag; - -/* **************************************************************** */ -/* */ -/* Signal Handling */ -/* */ -/* **************************************************************** */ - -static sighandler_cxt old_int, old_term, old_hup, old_alrm, old_quit; -#if defined (SIGTSTP) -static sighandler_cxt old_tstp, old_ttou, old_ttin; -#endif -#if defined (SIGWINCH) -static sighandler_cxt old_winch; -#endif - -/* Readline signal handler functions. */ - -/* Called from RL_CHECK_SIGNALS() macro */ -RETSIGTYPE -_rl_signal_handler (sig) - int sig; -{ - _rl_caught_signal = 0; /* XXX */ - - if (sig == SIGWINCH) - rl_resize_terminal (); - else - _rl_handle_signal (sig); - SIGHANDLER_RETURN; -} - -static RETSIGTYPE -rl_signal_handler (sig) - int sig; -{ - if (_rl_interrupt_immediately || RL_ISSTATE(RL_STATE_CALLBACK)) - { - _rl_interrupt_immediately = 0; - _rl_handle_signal (sig); - } - else - _rl_caught_signal = sig; - - SIGHANDLER_RETURN; -} - -static RETSIGTYPE -_rl_handle_signal (sig) - int sig; -{ -#if defined (HAVE_POSIX_SIGNALS) - sigset_t set; -#else /* !HAVE_POSIX_SIGNALS */ -# if defined (HAVE_BSD_SIGNALS) - long omask; -# else /* !HAVE_BSD_SIGNALS */ - sighandler_cxt dummy_cxt; /* needed for rl_set_sighandler call */ -# endif /* !HAVE_BSD_SIGNALS */ -#endif /* !HAVE_POSIX_SIGNALS */ - - RL_SETSTATE(RL_STATE_SIGHANDLER); - -#if !defined (HAVE_BSD_SIGNALS) && !defined (HAVE_POSIX_SIGNALS) - /* Since the signal will not be blocked while we are in the signal - handler, ignore it until rl_clear_signals resets the catcher. */ -# 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 */ - - switch (sig) - { - case SIGINT: - _rl_reset_completion_state (); - rl_free_line_state (); - /* FALLTHROUGH */ - - case SIGTERM: - case SIGHUP: -#if defined (SIGTSTP) - case SIGTSTP: - case SIGTTOU: - case SIGTTIN: -#endif /* SIGTSTP */ -#if defined (SIGALRM) - case SIGALRM: -#endif -#if defined (SIGQUIT) - case SIGQUIT: -#endif - rl_echo_signal_char (sig); - rl_cleanup_after_signal (); - -#if defined (HAVE_POSIX_SIGNALS) - sigemptyset (&set); - sigprocmask (SIG_BLOCK, (sigset_t *)NULL, &set); - sigdelset (&set, sig); -#else /* !HAVE_POSIX_SIGNALS */ -# if defined (HAVE_BSD_SIGNALS) - omask = sigblock (0); -# endif /* HAVE_BSD_SIGNALS */ -#endif /* !HAVE_POSIX_SIGNALS */ - -#if defined (__EMX__) - 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) - sigprocmask (SIG_SETMASK, &set, (sigset_t *)NULL); -#else /* !HAVE_POSIX_SIGNALS */ -# if defined (HAVE_BSD_SIGNALS) - sigsetmask (omask & ~(sigmask (sig))); -# endif /* HAVE_BSD_SIGNALS */ -#endif /* !HAVE_POSIX_SIGNALS */ - - rl_reset_after_signal (); - } - - RL_UNSETSTATE(RL_STATE_SIGHANDLER); - SIGHANDLER_RETURN; -} - -#if defined (SIGWINCH) -static RETSIGTYPE -rl_sigwinch_handler (sig) - int sig; -{ - SigHandler *oh; - -#if defined (MUST_REINSTALL_SIGHANDLERS) - sighandler_cxt dummy_winch; - - /* We don't want to change old_winch -- it holds the state of SIGWINCH - disposition set by the calling application. We need this state - because we call the application's SIGWINCH handler after updating - our own idea of the screen size. */ - rl_set_sighandler (SIGWINCH, rl_sigwinch_handler, &dummy_winch); -#endif - - RL_SETSTATE(RL_STATE_SIGHANDLER); - _rl_caught_signal = sig; - - /* If another sigwinch handler has been installed, call it. */ - oh = (SigHandler *)old_winch.sa_handler; - if (oh && oh != (SigHandler *)SIG_IGN && oh != (SigHandler *)SIG_DFL) - (*oh) (sig); - - RL_UNSETSTATE(RL_STATE_SIGHANDLER); - SIGHANDLER_RETURN; -} -#endif /* SIGWINCH */ - -/* Functions to manage signal handling. */ - -#if !defined (HAVE_POSIX_SIGNALS) -static int -rl_sigaction (sig, nh, oh) - int sig; - sighandler_cxt *nh, *oh; -{ - oh->sa_handler = signal (sig, nh->sa_handler); - return 0; -} -#endif /* !HAVE_POSIX_SIGNALS */ - -/* Set up a readline-specific signal handler, saving the old signal - information in OHANDLER. Return the old signal handler, like - signal(). */ -static SigHandler * -rl_set_sighandler (sig, handler, ohandler) - int sig; - SigHandler *handler; - sighandler_cxt *ohandler; -{ - sighandler_cxt old_handler; -#if defined (HAVE_POSIX_SIGNALS) - struct sigaction act; - - act.sa_handler = handler; -# if defined (SIGWINCH) - act.sa_flags = (sig == SIGWINCH) ? SA_RESTART : 0; -# else - act.sa_flags = 0; -# endif /* SIGWINCH */ - sigemptyset (&act.sa_mask); - sigemptyset (&ohandler->sa_mask); - sigaction (sig, &act, &old_handler); -#else - old_handler.sa_handler = (SigHandler *)signal (sig, handler); -#endif /* !HAVE_POSIX_SIGNALS */ - - /* XXX -- assume we have memcpy */ - /* If rl_set_signals is called twice in a row, don't set the old handler to - rl_signal_handler, because that would cause infinite recursion. */ - if (handler != rl_signal_handler || old_handler.sa_handler != rl_signal_handler) - memcpy (ohandler, &old_handler, sizeof (sighandler_cxt)); - - return (ohandler->sa_handler); -} - -static void -rl_maybe_set_sighandler (sig, handler, ohandler) - int sig; - SigHandler *handler; - sighandler_cxt *ohandler; -{ - sighandler_cxt dummy; - SigHandler *oh; - - sigemptyset (&dummy.sa_mask); - oh = rl_set_sighandler (sig, handler, ohandler); - if (oh == (SigHandler *)SIG_IGN) - rl_sigaction (sig, ohandler, &dummy); -} - -int -rl_set_signals () -{ - sighandler_cxt dummy; - SigHandler *oh; -#if defined (HAVE_POSIX_SIGNALS) - static int sigmask_set = 0; - static sigset_t bset, oset; -#endif - -#if defined (HAVE_POSIX_SIGNALS) - if (rl_catch_signals && sigmask_set == 0) - { - sigemptyset (&bset); - - sigaddset (&bset, SIGINT); - sigaddset (&bset, SIGTERM); - sigaddset (&bset, SIGHUP); -#if defined (SIGQUIT) - sigaddset (&bset, SIGQUIT); -#endif -#if defined (SIGALRM) - sigaddset (&bset, SIGALRM); -#endif -#if defined (SIGTSTP) - sigaddset (&bset, SIGTSTP); -#endif -#if defined (SIGTTIN) - sigaddset (&bset, SIGTTIN); -#endif -#if defined (SIGTTOU) - sigaddset (&bset, SIGTTOU); -#endif - sigmask_set = 1; - } -#endif /* HAVE_POSIX_SIGNALS */ - - if (rl_catch_signals && signals_set_flag == 0) - { -#if defined (HAVE_POSIX_SIGNALS) - sigemptyset (&oset); - sigprocmask (SIG_BLOCK, &bset, &oset); -#endif - - rl_maybe_set_sighandler (SIGINT, rl_signal_handler, &old_int); - rl_maybe_set_sighandler (SIGTERM, rl_signal_handler, &old_term); - rl_maybe_set_sighandler (SIGHUP, rl_signal_handler, &old_hup); -#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); -#if defined (HAVE_POSIX_SIGNALS) && defined (SA_RESTART) - /* If the application using readline has already installed a signal - handler with SA_RESTART, SIGALRM will cause reads to be restarted - automatically, so readline should just get out of the way. Since - we tested for SIG_IGN above, we can just test for SIG_DFL here. */ - 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); -#endif /* SIGTSTP */ - -#if defined (SIGTTOU) - rl_maybe_set_sighandler (SIGTTOU, rl_signal_handler, &old_ttou); -#endif /* SIGTTOU */ - -#if defined (SIGTTIN) - rl_maybe_set_sighandler (SIGTTIN, rl_signal_handler, &old_ttin); -#endif /* SIGTTIN */ - - signals_set_flag = 1; - -#if defined (HAVE_POSIX_SIGNALS) - sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL); -#endif - } - -#if defined (SIGWINCH) - if (rl_catch_sigwinch && sigwinch_set_flag == 0) - { - rl_maybe_set_sighandler (SIGWINCH, rl_sigwinch_handler, &old_winch); - sigwinch_set_flag = 1; - } -#endif /* SIGWINCH */ - - return 0; -} - -int -rl_clear_signals () -{ - sighandler_cxt dummy; - - if (rl_catch_signals && signals_set_flag == 1) - { - sigemptyset (&dummy.sa_mask); - - rl_sigaction (SIGINT, &old_int, &dummy); - rl_sigaction (SIGTERM, &old_term, &dummy); - rl_sigaction (SIGHUP, &old_hup, &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); -#endif /* SIGTSTP */ - -#if defined (SIGTTOU) - rl_sigaction (SIGTTOU, &old_ttou, &dummy); -#endif /* SIGTTOU */ - -#if defined (SIGTTIN) - rl_sigaction (SIGTTIN, &old_ttin, &dummy); -#endif /* SIGTTIN */ - - signals_set_flag = 0; - } - -#if defined (SIGWINCH) - if (rl_catch_sigwinch && sigwinch_set_flag == 1) - { - sigemptyset (&dummy.sa_mask); - rl_sigaction (SIGWINCH, &old_winch, &dummy); - sigwinch_set_flag = 0; - } -#endif - - return 0; -} - -/* Clean up the terminal and readline state after catching a signal, before - resending it to the calling application. */ -void -rl_cleanup_after_signal () -{ - _rl_clean_up_for_exit (); - if (rl_deprep_term_function) - (*rl_deprep_term_function) (); - rl_clear_pending_input (); - rl_clear_signals (); -} - -/* Reset the terminal and readline state after a signal handler returns. */ -void -rl_reset_after_signal () -{ - if (rl_prep_term_function) - (*rl_prep_term_function) (_rl_meta_flag); - rl_set_signals (); -} - -/* Free up the readline variable line state for the current line (undo list, - any partial history entry, any keyboard macros in progress, and any - numeric arguments in process) after catching a signal, before calling - rl_cleanup_after_signal(). */ -void -rl_free_line_state () -{ - register HIST_ENTRY *entry; - - rl_free_undo_list (); - - entry = current_history (); - if (entry) - entry->data = (char *)NULL; - - _rl_kill_kbd_macro (); - rl_clear_message (); - _rl_reset_argument (); -} - -#endif /* HANDLE_SIGNALS */ - -/* **************************************************************** */ -/* */ -/* SIGINT Management */ -/* */ -/* **************************************************************** */ - -#if defined (HAVE_POSIX_SIGNALS) -static sigset_t sigint_set, sigint_oset; -static sigset_t sigwinch_set, sigwinch_oset; -#else /* !HAVE_POSIX_SIGNALS */ -# if defined (HAVE_BSD_SIGNALS) -static int sigint_oldmask; -static int sigwinch_oldmask; -# endif /* HAVE_BSD_SIGNALS */ -#endif /* !HAVE_POSIX_SIGNALS */ - -static int sigint_blocked; -static int sigwinch_blocked; - -/* Cause SIGINT to not be delivered until the corresponding call to - release_sigint(). */ -void -_rl_block_sigint () -{ - if (sigint_blocked) - return; - -#if defined (HAVE_POSIX_SIGNALS) - sigemptyset (&sigint_set); - sigemptyset (&sigint_oset); - sigaddset (&sigint_set, SIGINT); - sigprocmask (SIG_BLOCK, &sigint_set, &sigint_oset); -#else /* !HAVE_POSIX_SIGNALS */ -# if defined (HAVE_BSD_SIGNALS) - sigint_oldmask = sigblock (sigmask (SIGINT)); -# else /* !HAVE_BSD_SIGNALS */ -# if defined (HAVE_USG_SIGHOLD) - sighold (SIGINT); -# endif /* HAVE_USG_SIGHOLD */ -# endif /* !HAVE_BSD_SIGNALS */ -#endif /* !HAVE_POSIX_SIGNALS */ - - sigint_blocked = 1; -} - -/* Allow SIGINT to be delivered. */ -void -_rl_release_sigint () -{ - if (sigint_blocked == 0) - return; - -#if defined (HAVE_POSIX_SIGNALS) - sigprocmask (SIG_SETMASK, &sigint_oset, (sigset_t *)NULL); -#else -# if defined (HAVE_BSD_SIGNALS) - sigsetmask (sigint_oldmask); -# else /* !HAVE_BSD_SIGNALS */ -# if defined (HAVE_USG_SIGHOLD) - sigrelse (SIGINT); -# endif /* HAVE_USG_SIGHOLD */ -# endif /* !HAVE_BSD_SIGNALS */ -#endif /* !HAVE_POSIX_SIGNALS */ - - sigint_blocked = 0; -} - -/* Cause SIGWINCH to not be delivered until the corresponding call to - release_sigwinch(). */ -void -_rl_block_sigwinch () -{ - if (sigwinch_blocked) - return; - -#if defined (HAVE_POSIX_SIGNALS) - sigemptyset (&sigwinch_set); - sigemptyset (&sigwinch_oset); - sigaddset (&sigwinch_set, SIGWINCH); - sigprocmask (SIG_BLOCK, &sigwinch_set, &sigwinch_oset); -#else /* !HAVE_POSIX_SIGNALS */ -# if defined (HAVE_BSD_SIGNALS) - sigwinch_oldmask = sigblock (sigmask (SIGWINCH)); -# else /* !HAVE_BSD_SIGNALS */ -# if defined (HAVE_USG_SIGHOLD) - sighold (SIGWINCH); -# endif /* HAVE_USG_SIGHOLD */ -# endif /* !HAVE_BSD_SIGNALS */ -#endif /* !HAVE_POSIX_SIGNALS */ - - sigwinch_blocked = 1; -} - -/* Allow SIGWINCH to be delivered. */ -void -_rl_release_sigwinch () -{ - if (sigwinch_blocked == 0) - return; - -#if defined (HAVE_POSIX_SIGNALS) - sigprocmask (SIG_SETMASK, &sigwinch_oset, (sigset_t *)NULL); -#else -# if defined (HAVE_BSD_SIGNALS) - sigsetmask (sigwinch_oldmask); -# else /* !HAVE_BSD_SIGNALS */ -# if defined (HAVE_USG_SIGHOLD) - sigrelse (SIGWINCH); -# endif /* HAVE_USG_SIGHOLD */ -# endif /* !HAVE_BSD_SIGNALS */ -#endif /* !HAVE_POSIX_SIGNALS */ - - sigwinch_blocked = 0; -} - -/* **************************************************************** */ -/* */ -/* Echoing special control characters */ -/* */ -/* **************************************************************** */ -void -rl_echo_signal_char (sig) - int sig; -{ - char cstr[3]; - int cslen, c; - - if (_rl_echoctl == 0 || _rl_echo_control_chars == 0) - return; - - switch (sig) - { - case SIGINT: c = _rl_intr_char; break; -#if defined (SIGQUIT) - case SIGQUIT: c = _rl_quit_char; break; -#endif -#if defined (SIGTSTP) - case SIGTSTP: c = _rl_susp_char; break; -#endif - default: return; - } - - if (CTRL_CHAR (c) || c == RUBOUT) - { - cstr[0] = '^'; - cstr[1] = CTRL_CHAR (c) ? UNCTRL (c) : '?'; - cstr[cslen = 2] = '\0'; - } - else - { - cstr[0] = c; - cstr[cslen = 1] = '\0'; - } - - _rl_output_some_chars (cstr, cslen); -} diff --git a/lib/readline/terminal.c~ b/lib/readline/terminal.c~ deleted file mode 100644 index 3927f229..00000000 --- a/lib/readline/terminal.c~ +++ /dev/null @@ -1,737 +0,0 @@ -/* terminal.c -- controlling the terminal with termcap. */ - -/* Copyright (C) 1996-2009 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library (Readline), a library - for reading lines of text with interactive input and history editing. - - Readline 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 3 of the License, or - (at your option) any later version. - - Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>. -*/ - -#define READLINE_LIBRARY - -#if defined (HAVE_CONFIG_H) -# include <config.h> -#endif - -#include <sys/types.h> -#include "posixstat.h" -#include <fcntl.h> -#if defined (HAVE_SYS_FILE_H) -# include <sys/file.h> -#endif /* HAVE_SYS_FILE_H */ - -#if defined (HAVE_UNISTD_H) -# include <unistd.h> -#endif /* HAVE_UNISTD_H */ - -#if defined (HAVE_STDLIB_H) -# include <stdlib.h> -#else -# include "ansi_stdlib.h" -#endif /* HAVE_STDLIB_H */ - -#if defined (HAVE_LOCALE_H) -# include <locale.h> -#endif - -#include <stdio.h> - -/* System-specific feature definitions and include files. */ -#include "rldefs.h" - -#if defined (GWINSZ_IN_SYS_IOCTL) && !defined (TIOCGWINSZ) -# include <sys/ioctl.h> -#endif /* GWINSZ_IN_SYS_IOCTL && !TIOCGWINSZ */ - -#include "rltty.h" -#include "tcap.h" - -/* Some standard library routines. */ -#include "readline.h" -#include "history.h" - -#include "rlprivate.h" -#include "rlshell.h" -#include "xmalloc.h" - -#if defined (__MINGW32__) -# include <windows.h> -# include <wincon.h> - -static void _win_get_screensize PARAMS((int *, int *)); -#endif - -#if defined (__EMX__) -static void _emx_get_screensize PARAMS((int *, int *)); -#endif - -#define CUSTOM_REDISPLAY_FUNC() (rl_redisplay_function != rl_redisplay) -#define CUSTOM_INPUT_FUNC() (rl_getc_function != rl_getc) - -/* If the calling application sets this to a non-zero value, readline will - use the $LINES and $COLUMNS environment variables to set its idea of the - window size before interrogating the kernel. */ -int rl_prefer_env_winsize = 0; - -/* **************************************************************** */ -/* */ -/* Terminal and Termcap */ -/* */ -/* **************************************************************** */ - -static char *term_buffer = (char *)NULL; -static char *term_string_buffer = (char *)NULL; - -static int tcap_initialized; - -#if !defined (__linux__) && !defined (NCURSES_VERSION) -# if defined (__EMX__) || defined (NEED_EXTERN_PC) -extern -# endif /* __EMX__ || NEED_EXTERN_PC */ -char PC, *BC, *UP; -#endif /* !__linux__ && !NCURSES_VERSION */ - -/* Some strings to control terminal actions. These are output by tputs (). */ -char *_rl_term_clreol; -char *_rl_term_clrpag; -char *_rl_term_cr; -char *_rl_term_backspace; -char *_rl_term_goto; -char *_rl_term_pc; - -/* Non-zero if we determine that the terminal can do character insertion. */ -int _rl_terminal_can_insert = 0; - -/* How to insert characters. */ -char *_rl_term_im; -char *_rl_term_ei; -char *_rl_term_ic; -char *_rl_term_ip; -char *_rl_term_IC; - -/* How to delete characters. */ -char *_rl_term_dc; -char *_rl_term_DC; - -char *_rl_term_forward_char; - -/* How to go up a line. */ -char *_rl_term_up; - -/* A visible bell; char if the terminal can be made to flash the screen. */ -static char *_rl_visible_bell; - -/* Non-zero means the terminal can auto-wrap lines. */ -int _rl_term_autowrap = -1; - -/* Non-zero means that this terminal has a meta key. */ -static int term_has_meta; - -/* The sequences to write to turn on and off the meta key, if this - terminal has one. */ -static char *_rl_term_mm; -static char *_rl_term_mo; - -/* The key sequences output by the arrow keys, if this terminal has any. */ -static char *_rl_term_ku; -static char *_rl_term_kd; -static char *_rl_term_kr; -static char *_rl_term_kl; - -/* How to initialize and reset the arrow keys, if this terminal has any. */ -static char *_rl_term_ks; -static char *_rl_term_ke; - -/* The key sequences sent by the Home and End keys, if any. */ -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; - -/* Cursor control */ -static char *_rl_term_vs; /* very visible */ -static char *_rl_term_ve; /* normal */ - -static void bind_termcap_arrow_keys PARAMS((Keymap)); - -/* Variables that hold the screen dimensions, used by the display code. */ -int _rl_screenwidth, _rl_screenheight, _rl_screenchars; - -/* Non-zero means the user wants to enable the keypad. */ -int _rl_enable_keypad; - -/* Non-zero means the user wants to enable a meta key. */ -int _rl_enable_meta = 1; - -#if defined (__EMX__) -static void -_emx_get_screensize (swp, shp) - int *swp, *shp; -{ - int sz[2]; - - _scrsize (sz); - - if (swp) - *swp = sz[0]; - if (shp) - *shp = sz[1]; -} -#endif - -#if defined (__MINGW32__) -static void -_win_get_screensize (swp, shp) - int *swp, *shp; -{ - HANDLE hConOut; - CONSOLE_SCREEN_BUFFER_INFO scr; - - hConOut = GetStdHandle (STD_OUTPUT_HANDLE); - if (hConOut != INVALID_HANDLE_VALUE) - { - if (GetConsoleScreenBufferInfo (hConOut, &scr)) - { - *swp = scr.dwSize.X; - *shp = scr.srWindow.Bottom - scr.srWindow.Top + 1; - } - } -} -#endif - -/* Get readline's idea of the screen size. TTY is a file descriptor open - to the terminal. If IGNORE_ENV is true, we do not pay attention to the - values of $LINES and $COLUMNS. The tests for TERM_STRING_BUFFER being - non-null serve to check whether or not we have initialized termcap. */ -void -_rl_get_screen_size (tty, ignore_env) - int tty, ignore_env; -{ - char *ss; -#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) - { - wc = (int) window_size.ws_col; - wr = (int) window_size.ws_row; - } -#endif /* TIOCGWINSZ */ - -#if defined (__EMX__) - _emx_get_screensize (&wc, &wr); -#elif defined (__MINGW32__) - _win_get_screensize (&wc, &wr); -#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. 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"); -#endif - } - - /* Environment variable LINES overrides setting of "li" if IGNORE_ENV - is unset. */ - if (_rl_screenheight <= 0) - { - 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"); -#endif - } - - /* If all else fails, default to 80x24 terminal. */ - if (_rl_screenwidth <= 1) - _rl_screenwidth = 80; - - if (_rl_screenheight <= 0) - _rl_screenheight = 24; - - /* If we're being compiled as part of bash, set the environment - variables $LINES and $COLUMNS to new values. Otherwise, just - do a pair of putenv () or setenv () calls. */ - sh_set_lines_and_columns (_rl_screenheight, _rl_screenwidth); - - if (_rl_term_autowrap == 0) - _rl_screenwidth--; - - _rl_screenchars = _rl_screenwidth * _rl_screenheight; -} - -void -_rl_set_screen_size (rows, cols) - int rows, cols; -{ - if (_rl_term_autowrap == -1) - _rl_init_terminal_io (rl_terminal_name); - - if (rows > 0) - _rl_screenheight = rows; - if (cols > 0) - { - _rl_screenwidth = cols; - if (_rl_term_autowrap == 0) - _rl_screenwidth--; - } - - if (rows > 0 || cols > 0) - _rl_screenchars = _rl_screenwidth * _rl_screenheight; -} - -void -rl_set_screen_size (rows, cols) - int rows, cols; -{ - _rl_set_screen_size (rows, cols); -} - -void -rl_get_screen_size (rows, cols) - int *rows, *cols; -{ - if (rows) - *rows = _rl_screenheight; - if (cols) - *cols = _rl_screenwidth; -} - -void -rl_reset_screen_size () -{ - _rl_get_screen_size (fileno (rl_instream), 0); -} - -void -_rl_sigwinch_resize_terminal () -{ - _rl_get_screen_size (fileno (rl_instream), 1); -} - -void -rl_resize_terminal () -{ - _rl_get_screen_size (fileno (rl_instream), 1); - if (_rl_echoing_p) - { - if (CUSTOM_REDISPLAY_FUNC ()) - rl_forced_update_display (); - else if (RL_ISSTATE(RL_STATE_REDISPLAYING) == 0) - _rl_redisplay_after_sigwinch (); - } -} - -struct _tc_string { - const char * const tc_var; - char **tc_value; -}; - -/* This should be kept sorted, just in case we decide to change the - search algorithm to something smarter. */ -static const struct _tc_string tc_strings[] = -{ - { "@7", &_rl_term_at7 }, - { "DC", &_rl_term_DC }, - { "IC", &_rl_term_IC }, - { "ce", &_rl_term_clreol }, - { "cl", &_rl_term_clrpag }, - { "cr", &_rl_term_cr }, - { "dc", &_rl_term_dc }, - { "ei", &_rl_term_ei }, - { "ic", &_rl_term_ic }, - { "im", &_rl_term_im }, - { "kD", &_rl_term_kD }, /* delete */ - { "kH", &_rl_term_kH }, /* home down ?? */ - { "kI", &_rl_term_kI }, /* insert */ - { "kd", &_rl_term_kd }, - { "ke", &_rl_term_ke }, /* end keypad mode */ - { "kh", &_rl_term_kh }, /* home */ - { "kl", &_rl_term_kl }, - { "kr", &_rl_term_kr }, - { "ks", &_rl_term_ks }, /* start keypad mode */ - { "ku", &_rl_term_ku }, - { "le", &_rl_term_backspace }, - { "mm", &_rl_term_mm }, - { "mo", &_rl_term_mo }, - { "nd", &_rl_term_forward_char }, - { "pc", &_rl_term_pc }, - { "up", &_rl_term_up }, - { "vb", &_rl_visible_bell }, - { "vs", &_rl_term_vs }, - { "ve", &_rl_term_ve }, -}; - -#define NUM_TC_STRINGS (sizeof (tc_strings) / sizeof (struct _tc_string)) - -/* Read the desired terminal capability strings into BP. The capabilities - are described in the TC_STRINGS table. */ -static void -get_term_capabilities (bp) - char **bp; -{ -#if !defined (__DJGPP__) /* XXX - doesn't DJGPP have a termcap library? */ - register int i; - - for (i = 0; i < NUM_TC_STRINGS; i++) - *(tc_strings[i].tc_value) = tgetstr ((char *)tc_strings[i].tc_var, bp); -#endif - tcap_initialized = 1; -} - -int -_rl_init_terminal_io (terminal_name) - const char *terminal_name; -{ - const char *term; - char *buffer; - int tty, tgetent_ret; - - 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; - - if (term == 0) - term = "dumb"; - - /* I've separated this out for later work on not calling tgetent at all - if the calling application has supplied a custom redisplay function, - (and possibly if the application has supplied a custom input function). */ - if (CUSTOM_REDISPLAY_FUNC()) - { - tgetent_ret = -1; - } - else - { - if (term_string_buffer == 0) - term_string_buffer = (char *)xmalloc(2032); - - if (term_buffer == 0) - term_buffer = (char *)xmalloc(4080); - - buffer = term_string_buffer; - - tgetent_ret = tgetent (term_buffer, term); - } - - if (tgetent_ret <= 0) - { - FREE (term_string_buffer); - FREE (term_buffer); - buffer = term_buffer = term_string_buffer = (char *)NULL; - - _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--; -#else /* !__EMX__ */ - _rl_get_screen_size (tty, 0); -#endif /* !__EMX__ */ - } - - /* Defaults. */ - if (_rl_screenwidth <= 0 || _rl_screenheight <= 0) - { - _rl_screenwidth = 79; - _rl_screenheight = 24; - } - - /* Everything below here is used by the redisplay code (tputs). */ - _rl_screenchars = _rl_screenwidth * _rl_screenheight; - _rl_term_cr = "\r"; - _rl_term_im = _rl_term_ei = _rl_term_ic = _rl_term_IC = (char *)NULL; - _rl_term_up = _rl_term_dc = _rl_term_DC = _rl_visible_bell = (char *)NULL; - _rl_term_ku = _rl_term_kd = _rl_term_kl = _rl_term_kr = (char *)NULL; - _rl_term_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; - _rl_term_forward_char = (char *)NULL; - _rl_terminal_can_insert = term_has_meta = 0; - - /* Reasonable defaults for tgoto(). Readline currently only uses - tgoto if _rl_term_IC or _rl_term_DC is defined, but just in case we - change that later... */ - PC = '\0'; - BC = _rl_term_backspace = "\b"; - UP = _rl_term_up; - - return 0; - } - - get_term_capabilities (&buffer); - - /* Set up the variables that the termcap library expects the application - to provide. */ - PC = _rl_term_pc ? *_rl_term_pc : 0; - BC = _rl_term_backspace; - UP = _rl_term_up; - - if (!_rl_term_cr) - _rl_term_cr = "\r"; - - _rl_term_autowrap = tgetflag ("am") && tgetflag ("xn"); - - /* 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', - `im', `ic' or `ip' is provided." But we can't do anything if - only `ip' is provided, so... */ - _rl_terminal_can_insert = (_rl_term_IC || _rl_term_im || _rl_term_ic); - - /* Check to see if this terminal has a meta key and clear the capability - variables if there is none. */ - term_has_meta = tgetflag ("km") != 0; - if (term_has_meta == 0) - _rl_term_mm = _rl_term_mo = (char *)NULL; - - /* Attempt to find and bind the arrow keys. Do not override already - bound keys in an overzealous attempt, however. */ - - bind_termcap_arrow_keys (emacs_standard_keymap); - -#if defined (VI_MODE) - bind_termcap_arrow_keys (vi_movement_keymap); - bind_termcap_arrow_keys (vi_insertion_keymap); -#endif /* VI_MODE */ - - return 0; -} - -/* Bind the arrow key sequences from the termcap description in MAP. */ -static void -bind_termcap_arrow_keys (map) - Keymap map; -{ - Keymap xkeymap; - - xkeymap = _rl_keymap; - _rl_keymap = map; - - rl_bind_keyseq_if_unbound (_rl_term_ku, rl_get_previous_history); - rl_bind_keyseq_if_unbound (_rl_term_kd, rl_get_next_history); - rl_bind_keyseq_if_unbound (_rl_term_kr, rl_forward_char); - rl_bind_keyseq_if_unbound (_rl_term_kl, rl_backward_char); - - 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; -} - -char * -rl_get_termcap (cap) - const char *cap; -{ - register int i; - - if (tcap_initialized == 0) - return ((char *)NULL); - for (i = 0; i < NUM_TC_STRINGS; i++) - { - if (tc_strings[i].tc_var[0] == cap[0] && strcmp (tc_strings[i].tc_var, cap) == 0) - return *(tc_strings[i].tc_value); - } - return ((char *)NULL); -} - -/* Re-initialize the terminal considering that the TERM/TERMCAP variable - has changed. */ -int -rl_reset_terminal (terminal_name) - const char *terminal_name; -{ - _rl_screenwidth = _rl_screenheight = 0; - _rl_init_terminal_io (terminal_name); - return 0; -} - -/* A function for the use of tputs () */ -#ifdef _MINIX -void -_rl_output_character_function (c) - int c; -{ - putc (c, _rl_out_stream); -} -#else /* !_MINIX */ -int -_rl_output_character_function (c) - int c; -{ - return putc (c, _rl_out_stream); -} -#endif /* !_MINIX */ - -/* Write COUNT characters from STRING to the output stream. */ -void -_rl_output_some_chars (string, count) - const char *string; - int count; -{ - fwrite (string, 1, count, _rl_out_stream); -} - -/* Move the cursor back. */ -int -_rl_backspace (count) - int count; -{ - register int i; - - if (_rl_term_backspace) - for (i = 0; i < count; i++) - tputs (_rl_term_backspace, 1, _rl_output_character_function); - else - for (i = 0; i < count; i++) - putc ('\b', _rl_out_stream); - return 0; -} - -/* Move to the start of the next line. */ -int -rl_crlf () -{ -#if defined (NEW_TTY_DRIVER) || defined (__MINT__) - if (_rl_term_cr) - tputs (_rl_term_cr, 1, _rl_output_character_function); -#endif /* NEW_TTY_DRIVER || __MINT__ */ - putc ('\n', _rl_out_stream); - return 0; -} - -/* Ring the terminal bell. */ -int -rl_ding () -{ - if (_rl_echoing_p) - { - switch (_rl_bell_preference) - { - case NO_BELL: - default: - break; - case VISIBLE_BELL: - if (_rl_visible_bell) - { - tputs (_rl_visible_bell, 1, _rl_output_character_function); - break; - } - /* FALLTHROUGH */ - case AUDIBLE_BELL: - fprintf (stderr, "\007"); - fflush (stderr); - break; - } - return (0); - } - return (-1); -} - -/* **************************************************************** */ -/* */ -/* Controlling the Meta Key and Keypad */ -/* */ -/* **************************************************************** */ - -void -_rl_enable_meta_key () -{ -#if !defined (__DJGPP__) - if (term_has_meta && _rl_term_mm) - tputs (_rl_term_mm, 1, _rl_output_character_function); -#endif -} - -void -_rl_control_keypad (on) - int on; -{ -#if !defined (__DJGPP__) - if (on && _rl_term_ks) - tputs (_rl_term_ks, 1, _rl_output_character_function); - else if (!on && _rl_term_ke) - tputs (_rl_term_ke, 1, _rl_output_character_function); -#endif -} - -/* **************************************************************** */ -/* */ -/* Controlling the Cursor */ -/* */ -/* **************************************************************** */ - -/* Set the cursor appropriately depending on IM, which is one of the - insert modes (insert or overwrite). Insert mode gets the normal - cursor. Overwrite mode gets a very visible cursor. Only does - anything if we have both capabilities. */ -void -_rl_set_cursor (im, force) - int im, force; -{ - if (_rl_term_ve && _rl_term_vs) - { - if (force || im != rl_insert_mode) - { - if (im == RL_IM_OVERWRITE) - tputs (_rl_term_vs, 1, _rl_output_character_function); - else - tputs (_rl_term_ve, 1, _rl_output_character_function); - } - } -} |