Compare commits

...

7 Commits

Author SHA1 Message Date
Elena Zannoni
b585a9fad5 import of readlilne 5.1 2006-04-20 20:05:52 +00:00
Elena Zannoni
84041b4c47 import of readline-4.3 2002-08-23 22:02:32 +00:00
Elena Zannoni
f9267e152c Import of readline 4.1 2000-07-09 16:21:23 +00:00
Elena Zannoni
a44161c313 Import of readline 4.0 2000-07-07 19:14:18 +00:00
Jason Molenda
d18570046c import gdb-1999-08-16 snapshot 1999-08-16 19:57:18 +00:00
Jason Molenda
c862e87b3e import gdb-1999-08-02 snapshot 1999-08-02 23:48:02 +00:00
Jason Molenda
c95b01a9b0 import gdb-1999-07-19 snapshot 1999-07-19 23:29:27 +00:00
147 changed files with 103985 additions and 12600 deletions

View File

@@ -75,3 +75,846 @@ examples/Makefile.in
---
configure.in
- bumped LIBVERSION up to 2.2
4/18
----
[readline-2.2 released]
4/20
----
Makefile.in
- make `libhistory.a' a dependency of `install'
- fixed a typo in the recipe for `install' that copied libreadline.a
to libhistory.old right after installing it
4/27
----
doc/Makefile.in
- install {readline,history}.info out of the source directory if
they are not found in the current (build) directory -- only an
issue if the libraries are built in a different directory than
the source directory
5/1
---
support/shobj-conf
- script from the bash distribution to do shared object and library
configuration
shlib/Makefile.in
- new directory and makefile to handle building shared versions of
libreadline and libhistory, controlled by support/shobj-conf
5/7
---
doc/Makefile.in
- set SHELL to /bin/sh, rather than relying on make to be correct
5/14
----
savestring.c
- new file, moved from shell.c, for backwards compatibility
Makefile.in, shlib/Makefile.in
- make sure savestring.c is compiled and added to libreadline and
libhistory
[THERE ARE NO MORE #ifdef SHELL LINES IN THE C SOURCE FILES.]
5/15
----
README
- updated description of shared library creation for the new scheme
[THERE ARE NO MORE #ifdef SHELL LINES IN ANY OF THE SOURCE FILES.]
Makefile.in
- bumped SHLIB_MAJOR up to 4 since we've augmented the library
API
- rlconf.h is now one of the installed headers, so applications can
find out whether things like vi-mode are available in the installed
libreadline
5/20
----
configure.in
- changed RL_LIBRARY_VERSION to 4.0 to match the version of the
installed shared libraries
6/5
---
rlstdc.h
- new file
Makefile.in
- rlstdc.h is now one of the installed headers
8/3
---
shlib/Makefile.in
- made the suffix rule that creates xx.so from xx.c write the
compiler output to `a.o', which is then mv'd to xx.so, because
some compilers (Sun WSpro 4.2, for example) don't allow any
suffixes other than `.o' for `cc -c' (not even `a.out')
9/15
----
Makefile.in
- AR and ARFLAGS are now substituted by configure, used in recipes
that build the libraries
configure.in
- use AC_CHECK_PROG to check for ar
- set ARFLAGS if it has not already been set in the environment
10/5
----
Makefile.in
- removed savestring.o from object file list
10/28
-----
shlib/Makefile.in
- don't use a fixed filename in the .c.so suffix rule to avoid
problems with parallel makes
12/21
-----
support/shlib-install
- new script to install shared readline and history libraries
shlib/Makefile.in
- changed to call shlib-install for install and uninstall targets
[readline-4.0-beta1 frozen]
12/22
-----
configure.in
- call AC_SUBST for SHOBJ_XLDFLAGS and SHLIB_LIBS
shlib/Makefile.in
- SHOBJ_XLDFLAGS and SHLIB_LIBS are now substituted by configure
- add $(SHLIB_LIBS) at end of command line that builds the shared
libraries (currently needed only by AIX 4.2)
12/31
-----
MANIFEST, MANIFEST.doc
- the TOC html files are no longer generated and no longer part of
the distribution
2/18/1999
---------
configure.in
- set MAKE_SHELL to /bin/sh and substitute into the Makefiles
Makefile.in,{doc,examples,shlib}/Makefile.in
- set SHELL from @MAKE_SHELL@
[readline-4.0 released]
3/11
----
doc/Makefile.in
- removed references to HTMLTOC, since separate HTML table-of-contents
files are no longer created
examples/Makefile.in
- remove `*.exe' in clean target for MS-DOS
Makefile.in
- make `readline' target depend on ./libreadline.a
- configure now substitutes TERMCAP_LIB into Makefile.in
- use ${TERMCAP_LIB} instead of -ltermcap in recipe for `readline'
- clean target now removes readline and readline.exe in case they
get built
configure.in
- use `pwd.exe' to set BUILD_DIR on MS-DOS DJGPP
3/15
----
support/shlib-install
- Irix 5.x and Irix 6.x should install shared libraries like Solaris 2
- changes for installing on hp-ux 1[01].x
3/23
----
configure.in
- make sure that the $CC argument to shobj-conf is quoted
4/8
---
xmalloc.h, rlprivate.h, rlshell.h
- new files
Makefile.in,shlib/Makefile.in
- add dependencies on xmalloc.h, rlshell.h
- add xmalloc.h, rlprivate.h, rlshell.h to list of header files
MANIFEST
- add xmalloc.h, rlprivate.h, rlshell.h
4/9
---
Makefile.in,shlib/Makefile.in
- add dependencies on rlprivate.h
4/13
----
doc/Makefile.in
- add variable, PSDVI, which is the desired resolution of the
generated postscript files. Set to 300 because I don't have
any 600-dpi printers
- set LANGUAGE= before calling makeinfo, so messages are in English
- add rluserman.{info,dvi,ps,html} to appropriate variables
- add rules to create rluserman.{info,dvi,ps,html}
- install and uninstall rluserman.info, but don't update the directory
file in $(infodir) yet
MANIFEST
- add doc/rluserman.{texinfo,info,dvi,ps,html}
4/30
----
configure.in
- updated library version to 4.1
5/3
---
configure.in
- SHLIB_MAJOR and SHLIB_MINOR shared library version numbers are
constructed from $LIBRARY_VERSION and substituted into Makefiles
5/5
---
support/shlib-install
- OSF/1 installs shared libraries like Solaris
Makefile.in
- broke the header file install and uninstall into two new targets:
install-headers and uninstall-headers
- install and uninstall depend on install-headers and uninstall-headers
respectively
- changed install-shared and uninstall-shared targets to depend on
install-headers and uninstall-headers, respectively, so users may
choose to install only the shared libraries. I'm not sure about
the uninstall one yet -- maybe it should check whether or not
the static libraries are installed and not remove the header files
if they are
9/3
---
configure.in, config.h.in
- added test for memmove (for later use)
- changed version to 4.1-beta1
9/13
----
examples/rlfe.c
- Per Bothner's `rlfe' readline front-end program
examples/Makefile.in
- added rules to build rlfe
9/21
----
support/shlib-install
- changes to handle FreeBSD-3.x elf or a.out shared libraries, which
have different semantics and need different naming conventions
1/24/2000
---------
doc/Makefile.in
- remove *.bt and *.bts on `make clean'
2/4
---
configure.in
- changed LIBVERSION to 4.1-beta5
3/17/2000
---------
[readline-4.1 released]
3/23
----
Makefile.in
- remove the `-t' argument to ranlib in the install recipe; some
ranlibs don't have it and attempt to create a file named `-t'
3/27
----
support/shlib-install
- install shared libraries unwritable by anyone on HP-UX
- changed symlinks to relative pathnames on all platforms
shlib/Makefile.in
- added missing `includedir' assignment, substituted by configure
Makefile.in
- added missing @SET_MAKE@ so configure can set $MAKE appropriately
configure.in
- add call to AC_PROG_MAKE_SET
8/30
----
shlib/Makefile.in
- change the soname bound into the shared libraries, so it includes
only the major version number. If it includes the minor version,
programs depending on it must be rebuilt (which may or may not be
a bad thing)
9/6
---
examples/rlfe.c
- add -l option to log input and output (-a option appends to logfile)
- add -n option to set readline application name
- add -v, -h options for version and help information
- change a few things because getopt() is now used to parse arguments
9/12
----
support/shlib-install
- fix up the libname on HPUX 11
10/18
-----
configure.in
- changed library version to 4.2-alpha
10/30
-----
configure.in
- add -fsigned-char to LOCAL_CFLAGS for Linux running on the IBM
S/390
Makefile.in
- added new file, rltypedefs.h, installed by default with `make install'
11/2
----
compat.c
- new file, with backwards-compatibility function definitions
Makefile.in,shlib/Makefile.in
- make sure that compat.o/compat.so are built and linked apppropriately
support/shobj-conf
- picked up bash version, which means that shared libs built on
linux and BSD/OS 4.x will have an soname that does not include
the minor version number
11/13
-----
examples/rlfe.c
- rlfe can perform filename completion for relative pathnames in the
inferior process's context if the OS supports /proc/PID/cwd (linux
does it OK, Solaris is slightly warped, none of the BSDs have it)
11/17/2000
----------
[readline-4.2-alpha released]
11/27
-----
Makefile.in,shlib/Makefile.in
- added dependencies for rltypedefs.h
shlib/Makefile.in
- changed dependencies on histlib.h to $(topdir)/histlib.h
1/22
----
configure.in
- changed release version to 4.2-beta
2/2
---
examples/Makefile.in
- build histexamp as part of the examples
2/5
---
doc/Makefile.in
- don't remove the dvi, postscript, html, info, and text `objects'
on a `make distclean', only on a `make maintainer-clean'
3/6
---
doc/history.{0,3}, doc/history_3.ps
- new manual page for history library
doc/Makefile.in
- rules to install and uninstall history.3 in ${man3dir}
- rules to build history.0 and history_3.ps
4/2
---
configure.in
- changed LIBVERSION to `4.2'
4/5
---
[readline-4.2 frozen]
4/9
---
[readline-4.2 released]
5/2
---
Makefile.in,{doc,examples,shlib}/Makefile.in
- added support for DESTDIR installation root prefix, to support
building packages
doc/Makefile.in
- add an info `dir' file entry for rluserman.info on `make install'
- change man1ext to `.1' and man3ext to `.3'
- install man pages with a $(man3ext) extension in the target directory
- add support for installing html documentation if `htmldir' has a
value
Makefile.in
- on `make install', install from the `shlib' directory, too
- on `make uninstall', uninstall in the `doc' and `shlib'
subdirectories, too
support/shlib-install
- add `freebsdelf*', `freebsdaout*', Hurd, `sysv4*', `sysv5*', `dgux*'
targets for symlink creation
5/7
---
configure.in, config.h.in
- check for <limits.h>, define HAVE_LIMITS_H if found
5/8
---
aclocal.m4
- pick up change to BASH_CHECK_LIB_TERMCAP that adds check for
libtinfo (termcap-specific portion of ncurses-5.2)
5/9
---
configure.in
- call AC_C_CONST to find out whether or not the compiler supports
`const'
config.h.in
- placeholder for `const' define, if any
5/10
----
configure.in
- fix AC_CHECK_PROG(ar, ...) test to specify right value for the
case where ar is not found; should produce a better error message
5/14
----
configure.in,config.h.in
- check for vsnprintf, define HAVE_VSNPRINTF if found
5/21
----
configure.in, config.h.in
- add checks for size_t, ssize_t
5/30
----
configure.in
- update autoconf to version 2.50, use in AC_PREREQ
- changed AC_INIT to new flavor
- added AC_CONFIG_SRCDIR
- AC_CONFIG_HEADER -> AC_CONFIG_HEADERS
- call AC_C_PROTOTYPES
- AC_RETSIGTYPE -> AC_TYPE_SIGNAL
8/22
----
configure.in
- updated the version number to 4.2a
Makefile.in,shlib/Makefile.in
- make sure tilde.o is built -DREADLINE_LIBRARY when being built as
part of the standalone library, so it picks up the right include
files
8/23
----
support/shlib-install
- support for Darwin/MacOS X shared library installation
9/24
----
examples/readlinebuf.h
- a new file, a C++ streambuf interface that uses readline for I/O.
Donated by Dimitris Vyzovitis <vyzo@media.mit.edu>
10/9
----
configure.in
- replaced call to BASH_HAVE_TIOCGWINSZ with AC_HEADER_TIOCGWINSZ
[readline-4.2a-beta1 frozen]
10/15
-----
configure.in, config.h.in
- check for <memory.h>, define HAVE_MEMORY_H if found
- check for <strings.h>, define HAVE_STRINGS_H if found
10/18
-----
configure.in, config.h.in
- check for isascii, define HAVE_ISASCII if found
configure.in
- changed the macro names from bash as appropriate:
BASH_SIGNAL_CHECK -> BASH_SYS_SIGNAL_VINTAGE
BASH_REINSTALL_SIGHANDLERS -> BASH_SYS_REINSTALL_SIGHANDLERS
BASH_MISC_SPEED_T -> BASH_CHECK_SPEED_T
10/22
-----
configure.in
- check for isxdigit with AC_CHECK_FUNCS
config.h.in
- new define for HAVE_ISXDIGIT
10/29
-----
configure.in, config.h.in
- check for strpbrk with AC_CHECK_FUNCS, define HAVE_STRPBRK if found
11/1
----
Makefile.in
- make sure DESTDIR is passed to install and uninstall makes in
subdirectories
- when saving old copies of installed libraries, make sure we use
DESTDIR for the old installation tree
[readline-4.2a-rc1 frozen]
11/2
----
Makefile.in, shlib/Makefile.in
- don't put -I$(includedir) into CFLAGS
11/15
-----
[readline-4.2a released]
11/20
-----
examples/rlcat.c
- new file
examples/Makefile.in
- changes for rlcat
11/28
-----
configure.in
- default TERMCAP_LIB to -lcurses if $prefer_curses == yes (as when
--with-curses is supplied)
examples/Makefile.in
- substitute @LDFLAGS@ in LDFLAGS assignment
11/29
-----
config.h.in
- add necessary defines for multibyte include files and functions
- add code to define HANDLE_MULTIBYTE if prerequisites are met
configure.in
- call BASH_CHECK_MULTIBYTE
12/14
-----
config.h.in
- add #undef PROTOTYPES, filled in by AC_C_PROTOTYPES
12/17
-----
config.h.in
- moved HANDLE_MULTIBYTE code to rlmbutil.h
rlmbutil.h, mbutil.c
- new files
Makefile.in, shlib/Makefile.in
- added rules for mbutil.c
12/20
-----
configure.in
- added --enable-shared, --enable-static options to configure to
say which libraries are built by default (both default to yes)
- if SHLIB_STATUS == 'unsupported', turn off default shared library
building
- substitute new STATIC_TARGET, SHARED_TARGET, STATIC_INSTALL_TARGET,
and SHARED_INSTALL_TARGET
Makefile.in
- `all' target now depends on (substituted) @STATIC_TARGET@ and
@SHARED_TARGET@
- `install' target now depends on (substituted) @STATIC_INSTALL_TARGET@
and @SHARED_INSTALL_TARGET@
INSTALL, README
- updated with new info about --enable-shared and --enable-static
1/10/2002
---------
configure.in
- bumped the library version number to 4.3
1/24
----
Makefile.in,shlib/Makefile.in
- changes for new file, text.c, with character and text handling
functions from readline.c
2/20
----
{configure.config.h}.in
- call AC_C_CHAR_UNSIGNED, define __CHAR_UNSIGNED__ if chars are
unsigned by default
5/20
----
doc/Makefile.in
- new maybe-clean target that removes the generated documentation if
the build directory differs from the source directory
- distclean target now depends on maybe-clean
7/17
----
[readline-4.3 released]
7/18
----
shlib/Makefile.in
- fix bad dependency: text.so: terminal.c, make it depend on text.c
8/7
---
support/shlib-install
- break `linux' out into its own stanza: it seems that linux
distributions are all moving to the following scheme:
libreadline.so.4.3 installed version
libreadline.so.4 -> libreadline.so.4.3 symlink
libreadline.so -> libreadline.so.4 symlink
10/29
-----
support/shlib-install
- change INSTALL_LINK[12] to use `&&' instead of `;' so it only
tries the link if the cd succeeds; put ${echo} in there, too
- use $LN instead of `ln -s' so it works on machines without symlinks
- change special linux stanza to use cd before ln also
- change to use $INSTALL_LINK1 and $INSTALL_LINK2 appropriately
instead of explicit commands in various stanzas
2/1
---
config.h.in
- add HAVE_MBRTOWC and HAVE_MBRLEN
- add NO_MULTIBYTE_SUPPORT for new configure argument
- add STDC_HEADERS
configure.in
- new argument --enable-multibyte (enabled by default), allows
multibyte support to be turned off even on systems that support it
- add check for ansi stdc headers with call to AC_HEADER_STDC
2/3
---
configure.in
- add call to BASH_FUNC_CTYPE_NONASCII
config.h.in
- add CTYPE_NON_ASCII
2/20
----
doc/manvers.texinfo
- renamed to version.texi to match other GNU software
- UPDATE-MONTH variable is now `UPDATED-MONTH'
doc/{hist,rlman,rluserman}.texinfo
- include version.texi
doc/{rltech,rluser,hstech,hsuser}.texi
- changed the suffix from `texinfo' to `texi'
doc/Makefile.in
- made appropriate changes for {{rl,hs}tech,{rl,hs}user}.texi
doc/{rlman,rluserman}.texinfo
- changed the suffix from `texinfo' to `texi'
doc/hist.texinfo
- renamed to history.texi to be more consistent
6/11
----
shlib/Makefile.in
- have configure substitute value of `@LDFLAGS@' into the assignment
to SHLIB_XLDFLAGS
6/16
----
configure.in
- readline and history libraries are now at version 5.0
8/18
----
support/shlib-install
- support for FreeBSD-gnu (from Robert Millan)
12/4
----
Makefile.in
- add variables for localedir and the PACKAGE_* variables, auto-set
by configure
12/9
----
Makefile.in
- use mkinstalldirs instead of mkdirs
4/22
----
Makefile.in
- separate doc install/uninstall out into two new targets:
install-doc and uninstall-doc
- make install-doc and uninstall-doc prerequisites of appropriate
install and uninstall targets
examples/rl-fgets.c
- new example from Harold Levy that wraps fgets replacement functions
that call readline in a shared library that can be interposed with
LD_PRELOAD
7/27
----
[readline-5.0 released]
11/15
-----
examples/rlfe/{ChangeLog,Makefile.in,README,config.h.in,configure,configure.in,extern.h,os.h,pty.c,rlfe.c,screen.h}
- new version of rlfe, rlfe-0.4, from Per Bothner; now a standalone
application
11/16
-----
shlib/Makefile.in
- substitute TERMCAP_LIB in from configure
configure.in
- if SHLIB_LIBS doesn't include a termcap library (curses, ncurses,
termcap, termlib), append the value of $TERMCAP_LIB to it
11/30
-----
configure.in
- take out change from 11/16; it doesn't work for some systems (e.g.,
SunOS 4.x and Solaris 2.6)
- add support for --enable-purify configure argument
- pass TERMCAP_LIB in environment when calling shobj-conf
examples/Makefile.in
- add support for building examples with purify
1/23/2005
---------
configure.in
- set BUILD_DIR to contain backslashes to escape any spaces in the
directory name -- this is what make will accept in targets and
prerequisites, so it's better than trying to use double quotes
2/25
----
configure.in
- change check for sys/ptem.h to include sys/stream.h if present, to
avoid the `present but cannot be compiled' messages on Solaris and
SVR4.2 (does anyone still use SVR4.2?)
5/7
---
configure.in
- add cross-compiling support from the bash configure.in, which cygwin
and mingw have apparently adopted
- add check for pwd.h, fcntl.h
- add checks for fcntl, kill system calls
- add checks for getpw{ent,nam,uid} C library functions
- pass a compile-time option through to Makefiles if cross-compiling
config.h.in
- add HAVE_PWD_H for <pwd.h>, HAVE_FCNTL_H for <fcntl.h>
- add HAVE_FCNTL, HAVE_KILL for respective system calls
- add HAVE_GETPW{ENT,NAM,UID} for passwd functions
Makefile.in,shlib/Makefile.in
- @CROSS_COMPILE@ is substituted into DEFS (equal to -DCROSS_COMPILING
if bash is being cross-compiled)
8/2
---
examples/Makefile.in
- use $(READLINE_LIB) instead of -lreadline to get around MacOS X 10.4's
preference for (incompatible) shared libraries over static libraries
in the load path
8/11
----
support/shobj-conf
- new variable: SHLIB_LIBPREF, prefix for shared library name (defaults
to `lib'
- new variable: SHLIB_DLLVERSION, used on Cygwin to set the library
version number
- new variable: SHLIB_DOT, separator character between library name and
suffix and version information (defaults to `.')
- new stanza for cygwin to generate windows-compatible dll
support/shlib-install
- add new option `-b bindir' for systems like cygwin/windows that
require it
- new stanza for cygwin that installs a dll into $bindir and an implied
link library into $libdir
configure.in
- substitute new variables from shobj-conf
shlib/Makefile.in
- substitute bindir, SHLIB_DOT, SHLIB_LIBPREF, SHLIB_DLLVERSION from
configure
- pass `-b $(bindir)' to shlib-install for install and uninstall targets
- library names now use $SHLIB_LIBPREF and $SHLIB_DOT
INSTALL,README
- document new SHLIB_DOT, SHLIB_LIBPREF, and SHLIB_DLLVERSION variables
10/4
----
[readline-5.1-beta1 frozen]
12/1
----
configure.in
- changed release status to `release'
[readline-5.1 frozen]

View File

@@ -1,22 +1,859 @@
This document details the changes between this version, readline-2.2.1,
This document details the changes between this version, readline-5.1,
and the previous version, readline-5.0.
1. Changes to Readline
a. Fixed a bug that caused multiliine prompts to be wrapped and displayed
incorrectly.
b. Fixed a bug that caused ^P/^N in emacs mode to fail to display the current
line correctly.
c. Fixed a problem in computing the number of invisible characters on the first
line of a prompt whose length exceeds the screen width.
d. Fixed vi-mode searching so that failure preserves the current line rather
than the last line in the history list.
e. Fixed the vi-mode `~' command (change-case) to have the correct behavior at
end-of-line when manipulating multibyte characters.
f. Fixed the vi-mode `r' command (change-char) to have the correct behavior at
end-of-line when manipulating multibyte characters.
g. Fixed multiple bugs in the redisplay of multibyte characters: displaying
prompts longer than the screen width containing multibyte characters,
h. Fix the calculation of the number of physical characters in the prompt
string when it contains multibyte characters.
i. A non-zero value for the `rl_complete_suppress_append' variable now causes
no `/' to be appended to a directory name.
j. Fixed forward-word and backward-word to work when words contained
multibyte characters.
k. Fixed a bug in finding the delimiter of a `?' substring when performing
history expansion in a locale that supports multibyte characters.
l. Fixed a memory leak caused by not freeing the timestamp in a history entry.
m. Fixed a bug that caused "\M-x" style key bindings to not obey the setting
of the `convert-meta' variable.
n. Fixed saving and restoring primary prompt when prompting for incremental
and non-incremental searches; search prompts now display multibyte
characters correctly.
o. Fixed a bug that caused keys originally bound to self-insert but shadowed
by a multi-character key sequence to not be inserted.
p. Fixed code so rl_prep_term_function and rl_deprep_term_function aren't
dereferenced if NULL (matching the documentation).
q. Extensive changes to readline to add enough state so that commands
requiring additional characters (searches, multi-key sequences, numeric
arguments, commands requiring an additional specifier character like
vi-mode change-char, etc.) work without synchronously waiting for
additional input.
r. Lots of changes so readline builds and runs on MinGW.
s. Readline no longer tries to modify the terminal settings when running in
callback mode.
t. The Readline display code no longer sets the location of the last invisible
character in the prompt if the \[\] sequence is empty.
u. The `change-case' command now correctly changes the case of multibyte
characters.
v. Changes to the shared library construction scripts to deal with Windows
DLL naming conventions for Cygwin.
w. Fixed the redisplay code to avoid core dumps resulting from a poorly-timed
SIGWINCH.
x. Fixed the non-incremental search code in vi mode to dispose of any current
undo list when copying a line from the history into the current editing
buffer.
y. Fixed a bug that caused reversing the incremental search direction to
not work correctly.
z. Fixed the vi-mode `U' command to only undo up to the first time insert mode
was entered, as Posix specifies.
aa. Fixed a bug in the vi-mode `r' command that left the cursor in the wrong
place.
bb. Fixed a redisplay bug caused by moving the cursor vertically to a line
with invisible characters in the prompt in a multibyte locale.
cc. Fixed a bug that could cause the terminal special chars to be bound in the
wrong keymap in vi mode.
2. New Features in Readline
a. The key sequence sent by the keypad `delete' key is now automatically
bound to delete-char.
b. A negative argument to menu-complete now cycles backward through the
completion list.
c. A new bindable readline variable: bind-tty-special-chars. If non-zero,
readline will bind the terminal special characters to their readline
equivalents when it's called (on by default).
d. New bindable command: vi-rubout. Saves deleted text for possible
reinsertion, as with any vi-mode `text modification' command; `X' is bound
to this in vi command mode.
e. If the rl_completion_query_items is set to a value < 0, readline never
asks the user whether or not to view the possible completions.
f. The `C-w' binding in incremental search now understands multibyte
characters.
g. New application-callable auxiliary function, rl_variable_value, returns
a string corresponding to a readline variable's value.
h. When parsing inputrc files and variable binding commands, the parser
strips trailing whitespace from values assigned to boolean variables
before checking them.
i. A new external application-controllable variable that allows the LINES
and COLUMNS environment variables to set the window size regardless of
what the kernel returns.
-------------------------------------------------------------------------------
This document details the changes between this version, readline-5.0,
and the previous version, readline-4.3.
1. Changes to Readline
a. Fixes to avoid core dumps because of null pointer references in the
multibyte character code.
b. Fix to avoid infinite recursion caused by certain key combinations.
c. Fixed a bug that caused the vi-mode `last command' to be set incorrectly.
d. Readline no longer tries to read ahead more than one line of input, even
when more is available.
e. Fixed the code that adjusts the point to not mishandle null wide
characters.
f. Fixed a bug in the history expansion `g' modifier that caused it to skip
every other match.
g. Fixed a bug that caused the prompt to overwrite previous output when the
output doesn't contain a newline and the locale supports multibyte
characters. This same change fixes the problem of readline redisplay
slowing down dramatically as the line gets longer in multibyte locales.
h. History traversal with arrow keys in vi insertion mode causes the cursor
to be placed at the end of the new line, like in emacs mode.
i. The locale initialization code does a better job of using the right
precedence and defaulting when checking the appropriate environment
variables.
j. Fixed the history word tokenizer to handle <( and >( better when used as
part of bash.
k. The overwrite mode code received several bug fixes to improve undo.
l. Many speedups to the multibyte character redisplay code.
m. The callback character reading interface should not hang waiting to read
keyboard input.
n. Fixed a bug with redoing vi-mode `s' command.
o. The code that initializes the terminal tracks changes made to the terminal
special characters with stty(1) (or equivalent), so that these changes
are reflected in the readline bindings. New application-callable function
to make it work: rl_tty_unset_default_bindings().
p. Fixed a bug that could cause garbage to be inserted in the buffer when
changing character case in vi mode when using a multibyte locale.
q. Fixed a bug in the redisplay code that caused problems on systems
supporting multibyte characters when moving between history lines when the
new line has more glyphs but fewer bytes.
r. Undo and redo now work better after exiting vi insertion mode.
s. Make sure system calls are restarted after a SIGWINCH is received using
SA_RESTART.
t. Improvements to the code that displays possible completions when using
multibyte characters.
u. Fixed a problem when parsing nested if statements in inputrc files.
v. The completer now takes multibyte characters into account when looking for
quoted substrings on which to perform completion.
w. The history search functions now perform better bounds checking on the
history list.
x. Change to history expansion functions to treat `^' as equivalent to word
one, as the documention states.
y. Some changes to the display code to improve display and redisplay of
multibyte characters.
z. Changes to speed up the multibyte character redisplay code.
aa. Fixed a bug in the vi-mode `E' command that caused it to skip over the
last character of a word if invoked while point was on the word's
next-to-last character.
bb. Fixed a bug that could cause incorrect filename quoting when
case-insensitive completion was enabled and the word being completed
contained backslashes quoting word break characters.
cc. Fixed a bug in redisplay triggered when the prompt string contains
invisible characters.
dd. Fixed some display (and other) bugs encountered in multibyte locales
when a non-ascii character was the last character on a line.
ee. Fixed some display bugs caused by multibyte characters in prompt strings.
ff. Fixed a problem with history expansion caused by non-whitespace characters
used as history word delimiters.
gg. Fixed a problem that could cause readline to refer to freed memory when
moving between history lines while doing searches.
hh. Improvements to the code that expands and displays prompt strings
containing multibyte characters.
ii. Fixed a problem with vi-mode not correctly remembering the numeric argument
to the last `c'hange command for later use with `.'.
jj. Fixed a bug in vi-mode that caused multi-digit count arguments to work
incorrectly.
kk. Fixed a problem in vi-mode that caused the last text modification command
to not be remembered across different command lines.
ll. Fixed problems with changing characters and changing case at the end of
the line.
mm. Fixed a problem with readline saving the contents of the current line
before beginning a non-interactive search.
nn. Fixed a problem with EOF detection when using rl_event_hook.
oo. Fixed a problem with the vi mode `p' and `P' commands ignoring numeric
arguments.
2. New Features in Readline
a. History expansion has a new `a' modifier equivalent to the `g' modifier
for compatibility with the BSD csh.
b. History expansion has a new `G' modifier equivalent to the BSD csh `g'
modifier, which performs a substitution once per word.
c. All non-incremental search operations may now undo the operation of
replacing the current line with the history line.
d. The text inserted by an `a' command in vi mode can be reinserted with
`.'.
e. New bindable variable, `show-all-if-unmodified'. If set, the readline
completer will list possible completions immediately if there is more
than one completion and partial completion cannot be performed.
f. There is a new application-callable `free_history_entry()' function.
g. History list entries now contain timestamp information; the history file
functions know how to read and write timestamp information associated
with each entry.
h. Four new key binding functions have been added:
rl_bind_key_if_unbound()
rl_bind_key_if_unbound_in_map()
rl_bind_keyseq_if_unbound()
rl_bind_keyseq_if_unbound_in_map()
i. New application variable, rl_completion_quote_character, set to any
quote character readline finds before it calls the application completion
function.
j. New application variable, rl_completion_suppress_quote, settable by an
application completion function. If set to non-zero, readline does not
attempt to append a closing quote to a completed word.
k. New application variable, rl_completion_found_quote, set to a non-zero
value if readline determines that the word to be completed is quoted.
Set before readline calls any application completion function.
l. New function hook, rl_completion_word_break_hook, called when readline
needs to break a line into words when completion is attempted. Allows
the word break characters to vary based on position in the line.
m. New bindable command: unix-filename-rubout. Does the same thing as
unix-word-rubout, but adds `/' to the set of word delimiters.
n. When listing completions, directories have a `/' appended if the
`mark-directories' option has been enabled.
-------------------------------------------------------------------------------
This document details the changes between this version, readline-4.3,
and the previous version, readline-4.2a.
1. Changes to Readline
a. Fixed output of comment-begin character when listing variable values.
b. Added some default key bindings for common escape sequences produced by
HOME and END keys.
c. Fixed the mark handling code to be more emacs-compatible.
d. A bug was fixed in the code that prints possible completions to keep it
from printing empty strings in certain circumstances.
e. Change the key sequence printing code to print ESC as M\- if ESC is a
meta-prefix character -- it's easier for users to understand than \e.
f. Fixed unstifle_history() to return values that match the documentation.
g. Fixed the event loop (rl_event_hook) to handle the case where the input
file descriptor is invalidated.
h. Fixed the prompt display code to work better when the application has a
custom redisplay function.
i. Changes to make reading and writing the history file a little faster, and
to cope with huge history files without calling abort(3) from xmalloc.
j. The vi-mode `S' and `s' commands are now undone correctly.
k. Fixed a problem which caused the display to be messed up when the last
line of a multi-line prompt (possibly containing invisible characters)
was longer than the screen width.
2. New Features in Readline
a. Support for key `subsequences': allows, e.g., ESC and ESC-a to both
be bound to readline functions. Now the arrow keys may be used in vi
insert mode.
b. When listing completions, and the number of lines displayed is more than
the screen length, readline uses an internal pager to display the results.
This is controlled by the `page-completions' variable (default on).
c. New code to handle editing and displaying multibyte characters.
d. The behavior introduced in bash-2.05a of deciding whether or not to
append a slash to a completed name that is a symlink to a directory has
been made optional, controlled by the `mark-symlinked-directories'
variable (default is the 2.05a behavior).
e. The `insert-comment' command now acts as a toggle if given a numeric
argument: if the first characters on the line don't specify a
comment, insert one; if they do, delete the comment text
f. New application-settable completion variable:
rl_completion_mark_symlink_dirs, allows an application's completion
function to temporarily override the user's preference for appending
slashes to names which are symlinks to directories.
g. New function available to application completion functions:
rl_completion_mode, to tell how the completion function was invoked
and decide which argument to supply to rl_complete_internal (to list
completions, etc.).
h. Readline now has an overwrite mode, toggled by the `overwrite-mode'
bindable command, which could be bound to `Insert'.
i. New application-settable completion variable:
rl_completion_suppress_append, inhibits appending of
rl_completion_append_character to completed words.
j. New key bindings when reading an incremental search string: ^W yanks
the currently-matched word out of the current line into the search
string; ^Y yanks the rest of the current line into the search string,
DEL or ^H deletes characters from the search string.
-------------------------------------------------------------------------------
This document details the changes between this version, readline-4.2a,
and the previous version, readline-4.2.
1. Changes to Readline
a. More `const' and type casting fixes.
b. Changed rl_message() to use vsnprintf(3) (if available) to fix buffer
overflow problems.
c. The completion code no longer appends a `/' or ` ' to a match when
completing a symbolic link that resolves to a directory name, unless
the match does not add anything to the word being completed. This
means that a tab will complete the word up to the full name, but not
add anything, and a subsequent tab will add a slash.
d. Fixed a trivial typo that made the vi-mode `dT' command not work.
e. Fixed the tty code so that ^S and ^Q can be inserted with rl_quoted_insert.
f. Fixed the tty code so that ^V works more than once.
g. Changed the use of __P((...)) for function prototypes to PARAMS((...))
because the use of __P in typedefs conflicted g++ and glibc.
h. The completion code now attempts to do a better job of preserving the
case of the word the user typed if ignoring case in completions.
i. Readline defaults to not echoing the input and lets the terminal
initialization code enable echoing if there is a controlling terminal.
j. The key binding code now processes only two hex digits after a `\x'
escape sequence, and the documentation was changed to note that the
octal and hex escape sequences result in an eight-bit value rather
than strict ASCII.
k. Fixed a few places where negative array subscripts could have occurred.
l. Fixed the vi-mode code to use a better method to determine the bounds of
the array used to hold the marks, and to avoid out-of-bounds references.
m. Fixed the defines in chardefs.h to work better when chars are signed.
n. Fixed configure.in to use the new names for bash autoconf macros.
o. Readline no longer attempts to define its own versions of some ctype
macros if they are implemented as functions in libc but not as macros in
<ctype.h>.
p. Fixed a problem where rl_backward could possibly set point to before
the beginning of the line.
q. Fixed Makefile to not put -I/usr/include into CFLAGS, since it can cause
include file problems.
2. New Features in Readline
a. Added extern declaration for rl_get_termcap to readline.h, making it a
public function (it was always there, just not in readline.h).
b. New #defines in readline.h: RL_READLINE_VERSION, currently 0x0402,
RL_VERSION_MAJOR, currently 4, and RL_VERSION_MINOR, currently 2.
c. New readline variable: rl_readline_version, mirrors RL_READLINE_VERSION.
d. New bindable boolean readline variable: match-hidden-files. Controls
completion of files beginning with a `.' (on Unix). Enabled by default.
e. The history expansion code now allows any character to terminate a
`:first-' modifier, like csh.
f. The incremental search code remembers the last search string and uses
it if ^R^R is typed without a search string.
h. New bindable variable `history-preserve-point'. If set, the history
code attempts to place the user at the same location on each history
line retrived with previous-history or next-history.
-------------------------------------------------------------------------------
This document details the changes between this version, readline-4.2,
and the previous version, readline-4.1.
1. Changes to Readline
a. When setting the terminal attributes on systems using `struct termio',
readline waits for output to drain before changing the attributes.
b. A fix was made to the history word tokenization code to avoid attempts to
dereference a null pointer.
c. Readline now defaults rl_terminal_name to $TERM if the calling application
has left it unset, and tries to initialize with the resultant value.
d. Instead of calling (*rl_getc_function)() directly to get input in certain
places, readline now calls rl_read_key() consistently.
e. Fixed a bug in the completion code that allowed a backslash to quote a
single quote inside a single-quoted string.
f. rl_prompt is no longer assigned directly from the argument to readline(),
but uses memory allocated by readline. This allows constant strings to
be passed to readline without problems arising when the prompt processing
code wants to modify the string.
g. Fixed a bug that caused non-interactive history searches to return the
wrong line when performing multiple searches backward for the same string.
h. Many variables, function arguments, and function return values are now
declared `const' where appropriate, to improve behavior when linking with
C++ code.
i. The control character detection code now works better on systems where
`char' is unsigned by default.
j. The vi-mode numeric argument is now capped at 999999, just like emacs mode.
k. The Function, CPFunction, CPPFunction, and VFunction typedefs have been
replaced with a set of specific prototyped typedefs, though they are
still in the readline header files for backwards compatibility.
m. Nearly all of the (undocumented) internal global variables in the library
now have an _rl_ prefix -- there were a number that did not, like
screenheight, screenwidth, alphabetic, etc.
n. The ding() convenience function has been renamed to rl_ding(), though the
old function is still defined for backwards compatibility.
o. The completion convenience functions filename_completion_function,
username_completion_function, and completion_matches now have an rl_
prefix, though the old names are still defined for backwards compatibility.
p. The functions shared by readline and bash (linkage is satisfied from bash
when compiling with bash, and internally otherwise) now have an sh_ prefix.
q. Changed the shared library creation procedure on Linux and BSD/OS 4.x so
that the `soname' contains only the major version number rather than the
major and minor numbers.
r. Fixed a redisplay bug that occurred when the prompt spanned more than one
physical line and contained invisible characters.
s. Added a missing `includedir' variable to the Makefile.
t. When installing the shared libraries, make sure symbolic links are relative.
u. Added configure test so that it can set `${MAKE}' appropriately.
v. Fixed a bug in rl_forward that could cause the point to be set to before
the beginning of the line in vi mode.
w. Fixed a bug in the callback read-char interface to make it work when a
readline function pushes some input onto the input stream with
rl_execute_next (like the incremental search functions).
x. Fixed a file descriptor leak in the history file manipulation code that
was tripped when attempting to truncate a non-regular file (like
/dev/null).
y. Changes to make all of the exported readline functions declared in
readline.h have an rl_ prefix (rltty_set_default_bindings is now
rl_tty_set_default_bindings, crlf is now rl_crlf, etc.)
z. The formatted documentation included in the base readline distribution
is no longer removed on a `make distclean'.
aa. Some changes were made to avoid gcc warnings with -Wall.
bb. rl_get_keymap_by_name now finds keymaps case-insensitively, so
`set keymap EMACS' works.
cc. The history file writing and truncation functions now return a useful
status on error.
dd. Fixed a bug that could cause applications to dereference a NULL pointer
if a NULL second argument was passed to history_expand().
ee. If a hook function assigned to rl_event_hook sets rl_done to a non-zero
value, rl_read_key() now immediately returns '\n' (which is assumed to
be bound to accept-line).
2. New Features in Readline
a. The blink timeout for paren matching is now settable by applications,
via the rl_set_paren_blink_timeout() function.
b. _rl_executing_macro has been renamed to rl_executing_macro, which means
it's now part of the public interface.
c. Readline has a new variable, rl_readline_state, which is a bitmap that
encapsulates the current state of the library; intended for use by
callbacks and hook functions.
d. rlfe has a new -l option to log input and output (-a appends to logfile),
a new -n option to set the readline application name, and -v and -h
options for version and help information.
e. rlfe can now perform filename completion for the inferior process if the
OS has a /proc/<PID>/cwd that can be read with readlink(2) to get the
inferior's current working directory.
f. A new file, rltypedefs.h, contains the new typedefs for function pointers
and is installed by `make install'.
g. New application-callable function rl_set_prompt(const char *prompt):
expands its prompt string argument and sets rl_prompt to the result.
h. New application-callable function rl_set_screen_size(int rows, int cols):
public method for applications to set readline's idea of the screen
dimensions.
i. The history example program (examples/histexamp.c) is now built as one
of the examples.
j. The documentation has been updated to cover nearly all of the public
functions and variables declared in readline.h.
k. New function, rl_get_screen_size (int *rows, int *columns), returns
readline's idea of the screen dimensions.
l. The timeout in rl_gather_tyi (readline keyboard input polling function)
is now settable via a function (rl_set_keyboard_input_timeout()).
m. Renamed the max_input_history variable to history_max_entries; the old
variable is maintained for backwards compatibility.
n. The list of characters that separate words for the history tokenizer is
now settable with a variable: history_word_delimiters. The default
value is as before.
o. There is a new history.3 manual page documenting the history library.
-------------------------------------------------------------------------------
This document details the changes between this version, readline-4.1,
and the previous version, readline-4.0.
1. Changes to Readline
a. Changed the HTML documents so that the table-of-contents is no longer
a separate file.
b. Changes to the shared object configuration for: Irix 5.x, Irix 6.x,
OSF/1.
c. The shared library major and minor versions are now constructed
automatically by configure and substituted into the makefiles.
d. It's now possible to install the shared libraries separately from the
static libraries.
e. The history library tries to truncate the history file only if it is a
regular file.
f. A bug that caused _rl_dispatch to address negative array indices on
systems with signed chars was fixed.
g. rl-yank-nth-arg now leaves the history position the same as when it was
called.
h. Changes to the completion code to handle MS-DOS drive-letter:pathname
filenames.
i. Completion is now case-insensitive by default on MS-DOS.
j. Fixes to the history file manipulation code for MS-DOS.
k. Readline attempts to bind the arrow keys to appropriate defaults on MS-DOS.
l. Some fixes were made to the redisplay code for better operation on MS-DOS.
m. The quoted-insert code will now insert tty special chars like ^C.
n. A bug was fixed that caused the display code to reference memory before
the start of the prompt string.
o. More support for __EMX__ (OS/2).
p. A bug was fixed in readline's signal handling that could cause infinite
recursion in signal handlers.
q. A bug was fixed that caused the point to be less than zero when rl_forward
was given a very large numeric argument.
r. The vi-mode code now gets characters via the application-settable value
of rl_getc_function rather than calling rl_getc directly.
s. The history file code now uses O_BINARY mode when reading and writing
the history file on cygwin32.
t. Fixed a bug in the redisplay code for lines with more than 256 line
breaks.
u. A bug was fixed which caused invisible character markers to not be
stripped from the prompt string if the terminal was in no-echo mode.
v. Readline no longer tries to get the variables it needs for redisplay
from the termcap entry if the calling application has specified its
own redisplay function. Readline treats the terminal as `dumb' in
this case.
w. Fixes to the SIGWINCH code so that a multiple-line prompt with escape
sequences is redrawn correctly.
x. Changes to the install and install-shared targets so that the libraries
and header files are installed separately.
2. New Features in Readline
a. A new Readline `user manual' is in doc/rluserman.texinfo.
b. Parentheses matching is now always compiled into readline, and enabled
or disabled when the value of the `blink-matching-paren' variable is
changed.
c. MS-DOS systems now use ~/_inputrc as the last-ditch inputrc filename.
d. MS-DOS systems now use ~/_history as the default history file.
e. history-search-{forward,backward} now leave the point at the end of the
line when the string to search for is empty, like
{reverse,forward}-search-history.
f. history-search-{forward,backward} now leave the last history line found
in the readline buffer if the second or subsequent search fails.
g. New function for use by applications: rl_on_new_line_with_prompt, used
when an application displays the prompt itself before calling readline().
h. New variable for use by applications: rl_already_prompted. An application
that displays the prompt itself before calling readline() must set this to
a non-zero value.
i. A new variable, rl_gnu_readline_p, always 1. The intent is that an
application can verify whether or not it is linked with the `real'
readline library or some substitute.
j. Per Bothner's `rlfe' (pronounced `Ralphie') readline front-end program
is included in the examples subdirectory, though it is not built
by default.
-------------------------------------------------------------------------------
This document details the changes between this version, readline-4.0,
and the previous version, readline-2.2.
1. Changes to Readline
a. The `make install' target was corrected so that it did not move the
newly-installed libreadline.a to libhistory.old
a. The version number is now 4.0, to match the major and minor version
numbers on the shared readline and history libraries. Future
releases will maintain the identical numbering.
b. The `make install' target for the documentation will now install the
info files from the source directory if they do not appear in the
build directory, since they are shipped in the readline tar file.
b. Fixed a typo in the `make install' recipe that copied libreadline.a
to libhistory.old right after installing it.
c. Fixed a problem with redisplay that showed up when the prompt string was
longer than the screen width and the prompt contained invisible characters.
c. The readline and history info files are now installed out of the source
directory if they are not found in the build directory.
d. Fixed a problem with the paren matching code -- the blink was far too
short (it's specified in microseconds, not milliseconds, Chet!).
d. The library no longer exports a function named `savestring' -- backwards
compatibility be damned.
------------------------------------------------------------------------------
e. There is no longer any #ifdef SHELL code in the source files.
f. Some changes were made to the key binding code to fix memory leaks and
better support Win32 systems.
g. Fixed a silly typo in the paren matching code -- it's microseconds, not
milliseconds.
h. The readline library should be compilable by C++ compilers.
i. The readline.h public header file now includes function prototypes for
all readline functions, and some changes were made to fix errors in the
source files uncovered by the use of prototypes.
j. The maximum numeric argument is now clamped at 1000000.
k. Fixes to rl_yank_last_arg to make it behave better.
l. Fixed a bug in the display code that caused core dumps if the prompt
string length exceeded 1024 characters.
m. The menu completion code was fixed to properly insert a single completion
if there is only one match.
n. A bug was fixed that caused the display code to improperly display tabs
after newlines.
o. A fix was made to the completion code in which a typo caused the wrong
value to be passed to the function that computed the longest common
prefix of the list of matches.
p. The completion code now checks the value of rl_filename_completion_desired,
which is set by application-supplied completion functions to indicate
that filename completion is being performed, to decide whether or not to
call an application-supplied `ignore completions' function.
q. Code was added to the history library to catch history substitutions
using `&' without a previous history substitution or search having been
performed.
2. New Features in Readline
a. There is a new script, support/shobj-conf, to do system-specific shared
object and library configuration. It generates variables for configure
to substitute into makefiles. The README file provides a detailed
explanation of the shared library creation process.
b. Shared libraries and objects are now built in the `shlib' subdirectory.
There is a shlib/Makefile.in to control the build process. `make shared'
from the top-level directory is still the right way to build shared
versions of the libraries.
c. rlconf.h is now installed, so applications can find out which features
have been compiled into the installed readline and history libraries.
d. rlstdc.h is now an installed header file.
e. Many changes to the signal handling:
o Readline now catches SIGQUIT and cleans up the tty before returning;
o A new variable, rl_catch_signals, is available to application writers
to indicate to readline whether or not it should install its own
signal handlers for SIGINT, SIGTERM, SIGQUIT, SIGALRM, SIGTSTP,
SIGTTIN, and SIGTTOU;
o A new variable, rl_catch_sigwinch, is available to application
writers to indicate to readline whether or not it should install its
own signal handler for SIGWINCH, which will chain to the calling
applications's SIGWINCH handler, if one is installed;
o There is a new function, rl_free_line_state, for application signal
handlers to call to free up the state associated with the current
line after receiving a signal;
o There is a new function, rl_cleanup_after_signal, to clean up the
display and terminal state after receiving a signal;
o There is a new function, rl_reset_after_signal, to reinitialize the
terminal and display state after an application signal handler
returns and readline continues
f. There is a new function, rl_resize_terminal, to reset readline's idea of
the screen size after a SIGWINCH.
g. New public functions: rl_save_prompt and rl_restore_prompt. These were
previously private functions with a `_' prefix. These functions are
used when an application wants to write a message to the `message area'
with rl_message and have the prompt restored correctly when the message
is erased.
h. New function hook: rl_pre_input_hook, called just before readline starts
reading input, after initialization.
i. New function hook: rl_display_matches_hook, called when readline would
display the list of completion matches. The new function
rl_display_match_list is what readline uses internally, and is available
for use by application functions called via this hook.
j. New bindable function, delete-char-or-list, like tcsh.
k. A new variable, rl_erase_empty_line, which, if set by an application using
readline, will cause readline to erase, prompt and all, lines on which the
only thing typed was a newline.
l. There is a new script, support/shlib-install, to install and uninstall
the shared readline and history libraries.
m. A new bindable variable, `isearch-terminators', which is a string
containing the set of characters that should terminate an incremental
search without being executed as a command.
n. A new bindable function, forward-backward-delete-char.
-------------------------------------------------------------------------------
This document details the changes between this version, readline-2.2,
and the previous version, readline-2.1.

View File

@@ -2,7 +2,7 @@
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
59 Temple Place, Suite 330, Boston, MA 02111 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@@ -305,7 +305,7 @@ the "copyright" line and a pointer to where the full notice is found.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
Also add information on how to contact you by electronic and paper mail.

View File

@@ -1,73 +1,81 @@
Basic Installation
==================
These are generic installation instructions.
These are installation instructions for Readline-5.1.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, a file
`config.cache' that saves the results of its tests to speed up
reconfiguring, and a file `config.log' containing compiler output
(useful mainly for debugging `configure').
The simplest way to compile readline is:
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If at some point `config.cache'
contains results you don't want to keep, you may remove or edit it.
The file `configure.in' is used to create `configure' by a program
called `autoconf'. You only need `configure.in' if you want to change
it or regenerate `configure' using a newer version of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system. If you're
1. `cd' to the directory containing the readline source code and type
`./configure' to configure readline for your system. If you're
using `csh' on an old version of System V, you might need to type
`sh ./configure' instead to prevent `csh' from trying to execute
`configure' itself.
Running `configure' takes awhile. While running, it prints some
Running `configure' takes some time. While running, it prints some
messages telling which features it is checking for.
2. Type `make' to compile the package.
2. Type `make' to compile readline and build the static readline
and history libraries. If supported, the shared readline and history
libraries will be built also. See below for instructions on compiling
the other parts of the distribution. Typing `make everything' will
cause the static and shared libraries (if supported) and the example
programs to be built.
3. Optionally, type `make check' to run any self-tests that come with
the package.
3. Type `make install' to install the static readline and history
libraries, the readline include files, the documentation, and, if
supported, the shared readline and history libraries.
4. Type `make install' to install the programs and any data files and
documentation.
5. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
4. You can remove the created libraries and object files from the
build directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile readline for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
for the readline developers, and should be used with care.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It
uses those values to create a `Makefile' in the build directory,
and Makefiles in the `doc', `shlib', and `examples'
subdirectories. It also creates a `config.h' file containing
system-dependent definitions. Finally, it creates a shell script
`config.status' that you can run in the future to recreate the
current configuration, a file `config.cache' that saves the
results of its tests to speed up reconfiguring, and a file
`config.log' containing compiler output (useful mainly for
debugging `configure').
If you need to do unusual things to compile readline, please try
to figure out how `configure' could check whether to do them, and
mail diffs or instructions to <bug-readline@gnu.org> so they can
be considered for the next release. If at some point
`config.cache' contains results you don't want to keep, you may
remove or edit it.
The file `configure.in' is used to create `configure' by a
program called `autoconf'. You only need `configure.in' if you
want to change it or regenerate `configure' using a newer version
of `autoconf'. The readline `configure.in' requires autoconf
version 2.50 or newer.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. You can give `configure'
initial values for variables by setting them in the environment. Using
a Bourne-compatible shell, you can do that on the command line like
this:
CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
Or on systems that have the `env' program, you can do it like this:
env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
You can compile readline for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you must use a version of `make' that
supports the `VPATH' variable, such as GNU `make'. `cd' to the
@@ -75,80 +83,59 @@ directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'.
If you have to use a `make' that does not supports the `VPATH'
variable, you have to compile the package for one architecture at a time
in the source code directory. After you have installed the package for
one architecture, use `make distclean' before reconfiguring for another
architecture.
If you have to use a `make' that does not supports the `VPATH'
variable, you have to compile readline for one architecture at a
time in the source code directory. After you have installed
readline for one architecture, use `make distclean' before
reconfiguring for another architecture.
Installation Names
==================
By default, `make install' will install the package's files in
`/usr/local/bin', `/usr/local/man', etc. You can specify an
installation prefix other than `/usr/local' by giving `configure' the
option `--prefix=PATH'.
By default, `make install' will install the readline libraries in
`/usr/local/lib', the include files in
`/usr/local/include/readline', the man pages in `/usr/local/man',
and the info files in `/usr/local/info'. You can specify an
installation prefix other than `/usr/local' by giving `configure'
the option `--prefix=PATH' or by supplying a value for the
DESTDIR variable when running `make install'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
give `configure' the option `--exec-prefix=PATH', the package will use
PATH as the prefix for installing programs and libraries.
Documentation and other data files will still use the regular prefix.
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Optional Features
=================
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files.
If you give `configure' the option `--exec-prefix=PATH', the
readline Makefiles will use PATH as the prefix for installing the
libraries. Documentation and other data files will still use the
regular prefix.
Specifying the System Type
==========================
There may be some features `configure' can not figure out
automatically, but needs to determine by the type of host the package
will run on. Usually `configure' can figure that out, but if it prints
a message saying it can not guess the host type, give it the
`--host=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name with three fields:
CPU-COMPANY-SYSTEM
There may be some features `configure' can not figure out
automatically, but need to determine by the type of host readline
will run on. Usually `configure' can figure that out, but if it
prints a message saying it can not guess the host type, give it
the `--host=TYPE' option. TYPE can either be a short name for
the system type, such as `sun4', or a canonical name with three
fields: CPU-COMPANY-SYSTEM (e.g., i386-unknown-freebsd4.2).
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the host type.
If you are building compiler tools for cross-compiling, you can also
use the `--target=TYPE' option to select the type of system they will
produce code for and the `--build=TYPE' option to select the type of
system on which you are compiling the package.
See the file `config.sub' for the possible values of each field.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share,
If you want to set default values for `configure' scripts to share,
you can create a site shell script called `config.site' that gives
default values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
A warning: the readline `configure' looks for a site script, but not
all `configure' scripts do.
Operation Controls
==================
`configure' recognizes the following options to control how it
`configure' recognizes the following options to control how it
operates.
`--cache-file=FILE'
@@ -174,3 +161,127 @@ operates.
`configure' also accepts some other, not widely useful, options.
Optional Features
=================
The readline `configure' recognizes a single `--with-PACKAGE' option:
`--with-curses'
This tells readline that it can find the termcap library functions
(tgetent, et al.) in the curses library, rather than a separate
termcap library. Readline uses the termcap functions, but does not
link with the termcap or curses library itself, allowing applications
which link with readline the to choose an appropriate library.
This option tells readline to link the example programs with the
curses library rather than libtermcap.
`configure' also recognizes two `--enable-FEATURE' options:
`--enable-shared'
Build the shared libraries by default on supported platforms. The
default is `yes'.
`--enable-static'
Build the static libraries by default. The default is `yes'.
Shared Libraries
================
There is support for building shared versions of the readline and
history libraries. The configure script creates a Makefile in
the `shlib' subdirectory, and typing `make shared' will cause
shared versions of the readline and history libraries to be built
on supported platforms.
If `configure' is given the `--enable-shared' option, it will attempt
to build the shared libraries by default on supported platforms.
Configure calls the script support/shobj-conf to test whether or
not shared library creation is supported and to generate the values
of variables that are substituted into shlib/Makefile. If you
try to build shared libraries on an unsupported platform, `make'
will display a message asking you to update support/shobj-conf for
your platform.
If you need to update support/shobj-conf, you will need to create
a `stanza' for your operating system and compiler. The script uses
the value of host_os and ${CC} as determined by configure. For
instance, FreeBSD 4.2 with any version of gcc is identified as
`freebsd4.2-gcc*'.
In the stanza for your operating system-compiler pair, you will need to
define several variables. They are:
SHOBJ_CC The C compiler used to compile source files into shareable
object files. This is normally set to the value of ${CC}
by configure, and should not need to be changed.
SHOBJ_CFLAGS Flags to pass to the C compiler ($SHOBJ_CC) to create
position-independent code. If you are using gcc, this
should probably be set to `-fpic'.
SHOBJ_LD The link editor to be used to create the shared library from
the object files created by $SHOBJ_CC. If you are using
gcc, a value of `gcc' will probably work.
SHOBJ_LDFLAGS Flags to pass to SHOBJ_LD to enable shared object creation.
If you are using gcc, `-shared' may be all that is necessary.
These should be the flags needed for generic shared object
creation.
SHLIB_XLDFLAGS Additional flags to pass to SHOBJ_LD for shared library
creation. Many systems use the -R option to the link
editor to embed a path within the library for run-time
library searches. A reasonable value for such systems would
be `-R$(libdir)'.
SHLIB_LIBS Any additional libraries that shared libraries should be
linked against when they are created.
SHLIB_LIBPREF The prefix to use when generating the filename of the shared
library. The default is `lib'; Cygwin uses `cyg'.
SHLIB_LIBSUFF The suffix to add to `libreadline' and `libhistory' when
generating the filename of the shared library. Many systems
use `so'; HP-UX uses `sl'.
SHLIB_LIBVERSION The string to append to the filename to indicate the version
of the shared library. It should begin with $(SHLIB_LIBSUFF),
and possibly include version information that allows the
run-time loader to load the version of the shared library
appropriate for a particular program. Systems using shared
libraries similar to SunOS 4.x use major and minor library
version numbers; for those systems a value of
`$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' is appropriate.
Systems based on System V Release 4 don't use minor version
numbers; use `$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' on those systems.
Other Unix versions use different schemes.
SHLIB_DLLVERSION The version number for shared libraries that determines API
compatibility between readline versions and the underlying
system. Used only on Cygwin. Defaults to $SHLIB_MAJOR, but
can be overridden at configuration time by defining DLLVERSION
in the environment.
SHLIB_DOT The character used to separate the name of the shared library
from the suffix and version information. The default is `.';
systems like Cygwin which don't separate version information
from the library name should set this to the empty string.
SHLIB_STATUS Set this to `supported' when you have defined the other
necessary variables. Make uses this to determine whether
or not shared library creation should be attempted. If
shared libraries are not supported, this will be set to
`unsupported'.
You should look at the existing stanzas in support/shobj-conf for ideas.
Once you have updated support/shobj-conf, re-run configure and type
`make shared' or `make'. The shared libraries will be created in the
shlib subdirectory.
If shared libraries are created, `make install' will install them.
You may install only the shared libraries by running `make
install-shared' from the top-level build directory. Running `make
install' in the shlib subdirectory will also work. If you don't want
to install any created shared libraries, run `make install-static'.

View File

@@ -3,15 +3,18 @@
#
doc d
examples d
examples/rlfe d
support d
shlib d
COPYING f
README f
MANIFEST f
INSTALL f
CHANGELOG f
CHANGES f
NEWS f
USAGE f
aclocal.m4 f
acconfig.h f
config.h.in f
configure f
configure.in f
@@ -27,11 +30,19 @@ posixstat.h f
readline.h f
rlconf.h f
rldefs.h f
rlmbutil.h f
rlprivate.h f
rlshell.h f
rlstdc.h f
rltty.h f
rltypedefs.h f
rlwinsize.h f
tcap.h f
tilde.h f
xmalloc.h f
bind.c f
callback.c f
compat.c f
complete.c f
display.c f
emacs_keymap.c f
@@ -41,45 +52,95 @@ isearch.c f
keymaps.c f
kill.c f
macro.c f
mbutil.c f
misc.c f
nls.c f
parens.c f
readline.c f
rltty.c f
savestring.c f
search.c f
shell.c f
signals.c f
terminal.c f
text.c f
tilde.c f
undo.c f
util.c f
vi_keymap.c f
vi_mode.c f
callback.c f
xmalloc.c f
history.c f
histexpand.c f
histfile.c f
histsearch.c f
shlib/Makefile.in f
support/config.guess f
support/config.rpath f
support/config.sub f
support/install.sh f
support/mkdirs f
support/mkdist f
support/mkinstalldirs f
support/shobj-conf f
support/shlib-install f
support/wcwidth.c f
doc/Makefile.in f
doc/texinfo.tex f
doc/rlman.texinfo f
doc/rltech.texinfo f
doc/rluser.texinfo f
doc/hist.texinfo f
doc/hstech.texinfo f
doc/hsuser.texinfo f
doc/version.texi f
doc/fdl.texi f
doc/rlman.texi f
doc/rltech.texi f
doc/rluser.texi f
doc/rluserman.texi f
doc/history.texi f
doc/hstech.texi f
doc/hsuser.texi f
doc/readline.3 f
doc/history.3 f
doc/texi2dvi f
doc/texi2html f
examples/Makefile.in f
examples/excallback.c f
examples/fileman.c f
examples/manexamp.c f
examples/readlinebuf.h f
examples/rl-fgets.c f
examples/rlcat.c f
examples/rltest.c f
examples/rl.c f
examples/rlptytest.c f
examples/rlversion.c f
examples/histexamp.c f
examples/Inputrc f
examples/rlfe/ChangeLog f
examples/rlfe/Makefile.in f
examples/rlfe/README f
examples/rlfe/config.h.in f
examples/rlfe/configure f
examples/rlfe/configure.in f
examples/rlfe/extern.h f
examples/rlfe/os.h f
examples/rlfe/pty.c f
examples/rlfe/rlfe.c f
examples/rlfe/screen.h f
# formatted documentation, from MANIFEST.doc
doc/readline.ps f
doc/history.ps f
doc/rluserman.ps f
doc/readline.dvi f
doc/history.dvi f
doc/rluserman.dvi f
doc/readline.info f
doc/history.info f
doc/rluserman.info f
doc/readline.html f
doc/history.html f
doc/rluserman.html f
doc/readline.0 f
doc/history.0 f
doc/readline_3.ps f
doc/history_3.ps f
doc/history.pdf f
doc/readline.pdf f
doc/rluserman.pdf f

View File

@@ -1,6 +1,6 @@
## -*- text -*- ##
# Master Makefile for the GNU readline library.
# Copyright (C) 1994, 1998 Free Software Foundation, Inc.
# Copyright (C) 1994-2004 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -14,12 +14,20 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
RL_LIBRARY_VERSION = @LIBVERSION@
RL_LIBRARY_NAME = readline
PACKAGE = @PACKAGE_NAME@
VERSION = @PACKAGE_VERSION@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_VERSION = @PACKAGE_VERSION@
srcdir = @srcdir@
VPATH = @srcdir@
VPATH = .:@srcdir@
top_srcdir = @top_srcdir@
BUILD_DIR = @BUILD_DIR@
@@ -28,13 +36,18 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
CC = @CC@
LD = ld # needed when building shared libraries
RANLIB = @RANLIB@
AR = ar
AR = @AR@
ARFLAGS = @ARFLAGS@
RM = rm -f
CP = cp
MV = mv
PURIFY = @PURIFY@
@SET_MAKE@
SHELL = @MAKE_SHELL@
prefix = @prefix@
exec_prefix = @exec_prefix@
@@ -42,12 +55,15 @@ bindir = @bindir@
libdir = @libdir@
mandir = @mandir@
includedir = @includedir@
datadir = @datadir@
localedir = $(datadir)/locale
infodir = @infodir@
man3dir = $(mandir)/man3
SHELL = /bin/sh
# Support an alternate destination root directory for package building
DESTDIR =
# Programs to make tags files.
ETAGS = etags -tw
@@ -56,44 +72,32 @@ CTAGS = ctags -tw
CFLAGS = @CFLAGS@
LOCAL_CFLAGS = @LOCAL_CFLAGS@ -DRL_LIBRARY_VERSION='"$(RL_LIBRARY_VERSION)"'
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@ @LOCAL_LDFLAGS@ @CFLAGS@
DEFS = @DEFS@
DEFS = @DEFS@ @CROSS_COMPILE@
LOCAL_DEFS = @LOCAL_DEFS@
TERMCAP_LIB = @TERMCAP_LIB@
# For libraries which include headers from other libraries.
INCLUDES = -I. -I$(srcdir) -I$(includedir)
INCLUDES = -I. -I$(srcdir)
CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(CPPFLAGS) $(INCLUDES) $(LOCAL_CFLAGS) $(CFLAGS)
XCCFLAGS = $(DEFS) $(LOCAL_DEFS) $(CPPFLAGS) $(INCLUDES)
CCFLAGS = $(XCCFLAGS) $(LOCAL_CFLAGS) $(CFLAGS)
# these two options need tweaking for compiler/OS versions other than gcc
# and SunOS4
PICFLAG= -fpic # -pic for some versions of cc
SHLIB_OPTS= -assert pure-text -ldl # -Bshareable for some versions of gcc
MAJOR= 3
# shared library systems like SVR4's do not use minor versions
MINOR= .0
.SUFFIXES: .so
# could add -Werror here
GCC_LINT_FLAGS = -ansi -Wall -Wshadow -Wpointer-arith -Wcast-qual \
-Wwrite-strings -Wstrict-prototypes \
-Wmissing-prototypes -Wno-implicit -pedantic
GCC_LINT_CFLAGS = $(XCCFLAGS) $(GCC_LINT_FLAGS) @CFLAGS@ @LOCAL_CFLAGS@
.c.o:
${RM} $@
$(CC) -c $(CCFLAGS) $<
.c.so:
-mv $*.o z$*.o
$(CC) -c $(PICFLAG) $(CCFLAGS) $<
mv $*.o $@
-mv z$*.o $*.o
# The name of the main library target.
LIBRARY_NAME = libreadline.a
STATIC_LIBS = libreadline.a libhistory.a
SHARED_READLINE = libreadline.so.$(MAJOR)$(MINOR)
SHARED_HISTORY = libhistory.so.$(MAJOR)$(MINOR)
SHARED_LIBS = $(SHARED_READLINE) $(SHARED_HISTORY)
# The C code source files for this library.
CSOURCES = $(srcdir)/readline.c $(srcdir)/funmap.c $(srcdir)/keymaps.c \
$(srcdir)/vi_mode.c $(srcdir)/parens.c $(srcdir)/rltty.c \
@@ -104,26 +108,22 @@ CSOURCES = $(srcdir)/readline.c $(srcdir)/funmap.c $(srcdir)/keymaps.c \
$(srcdir)/callback.c $(srcdir)/terminal.c $(srcdir)/xmalloc.c \
$(srcdir)/history.c $(srcdir)/histsearch.c $(srcdir)/histexpand.c \
$(srcdir)/histfile.c $(srcdir)/nls.c $(srcdir)/search.c \
$(srcdir)/shell.c $(srcdir)/tilde.c
$(srcdir)/shell.c $(srcdir)/savestring.c $(srcdir)/tilde.c \
$(srcdir)/text.c $(srcdir)/misc.c $(srcdir)/compat.c \
$(srcdir)/mbutil.c
# The header files for this library.
HSOURCES = readline.h rldefs.h chardefs.h keymaps.h history.h histlib.h \
posixstat.h posixdir.h posixjmp.h tilde.h rlconf.h rltty.h \
ansi_stdlib.h tcap.h
ansi_stdlib.h tcap.h rlstdc.h xmalloc.h rlprivate.h rlshell.h \
rltypedefs.h rlmbutil.h
HISTOBJ = history.o histexpand.o histfile.o histsearch.o shell.o
HISTOBJ = history.o histexpand.o histfile.o histsearch.o shell.o mbutil.o
TILDEOBJ = tilde.o
OBJECTS = readline.o vi_mode.o funmap.o keymaps.o parens.o search.o \
rltty.o complete.o bind.o isearch.o display.o signals.o \
util.o kill.o undo.o macro.o input.o callback.o terminal.o \
nls.o xmalloc.o $(HISTOBJ) $(TILDEOBJ)
SHARED_HISTOBJ = history.so histexpand.so histfile.so histsearch.so shell.so
SHARED_TILDEOBJ = tilde.so
SHARED_OBJ = readline.so vi_mode.so funmap.so keymaps.so parens.so search.so \
rltty.so complete.so bind.so isearch.so display.so signals.so \
util.so kill.so undo.so macro.so input.so callback.so terminal.so \
nls.so xmalloc.so $(SHARED_HISTOBJ) $(SHARED_TILDEOBJ)
text.o nls.o misc.o compat.o xmalloc.o $(HISTOBJ) $(TILDEOBJ)
# The texinfo files which document this library.
DOCSOURCE = doc/rlman.texinfo doc/rltech.texinfo doc/rluser.texinfo
@@ -131,40 +131,45 @@ DOCOBJECT = doc/readline.dvi
DOCSUPPORT = doc/Makefile
DOCUMENTATION = $(DOCSOURCE) $(DOCOBJECT) $(DOCSUPPORT)
CREATED_MAKEFILES = Makefile doc/Makefile examples/Makefile
CREATED_MAKEFILES = Makefile doc/Makefile examples/Makefile shlib/Makefile
CREATED_CONFIGURE = config.status config.h config.cache config.log \
stamp-config stamp-h
CREATED_TAGS = TAGS tags
INSTALLED_HEADERS = readline.h chardefs.h keymaps.h history.h tilde.h
INSTALLED_HEADERS = readline.h chardefs.h keymaps.h history.h tilde.h \
rlstdc.h rlconf.h rltypedefs.h
##########################################################################
TARGETS = @STATIC_TARGET@ @SHARED_TARGET@
INSTALL_TARGETS = @STATIC_INSTALL_TARGET@ @SHARED_INSTALL_TARGET@
all: static
all: $(TARGETS)
everything: all examples
static: $(STATIC_LIBS)
shared: $(SHARED_LIBS)
libreadline.a: $(OBJECTS)
$(RM) $@
$(AR) cr $@ $(OBJECTS)
$(AR) $(ARFLAGS) $@ $(OBJECTS)
-test -n "$(RANLIB)" && $(RANLIB) $@
libhistory.a: $(HISTOBJ) xmalloc.o
$(RM) $@
$(AR) cr $@ $(HISTOBJ) xmalloc.o
$(AR) $(ARFLAGS) $@ $(HISTOBJ) xmalloc.o
-test -n "$(RANLIB)" && $(RANLIB) $@
$(SHARED_READLINE): $(SHARED_OBJ)
$(RM) $@
$(LD) ${SHLIB_OPTS} -o $@ $(SHARED_OBJ)
# Since tilde.c is shared between readline and bash, make sure we compile
# it with the right flags when it's built as part of readline
tilde.o: tilde.c
rm -f $@
$(CC) $(CCFLAGS) -DREADLINE_LIBRARY -c $(srcdir)/tilde.c
$(SHARED_HISTORY): $(SHARED_HISTOBJ) xmalloc.so
$(RM) $@
$(LD) ${SHLIB_OPTS} -o $@ $(SHARED_HISTOBJ) xmalloc.so
readline: $(OBJECTS) readline.h rldefs.h chardefs.h ./libreadline.a
$(CC) $(CCFLAGS) -o $@ ./examples/rl.c ./libreadline.a ${TERMCAP_LIB}
readline: $(OBJECTS) readline.h rldefs.h chardefs.h
$(CC) $(CCFLAGS) -o $@ ./examples/rl.c ./libreadline.a -ltermcap
lint: force
$(MAKE) $(MFLAGS) CCFLAGS='$(GCC_LINT_CFLAGS)' static
Makefile makefile: config.status $(srcdir)/Makefile.in
CONFIG_FILES=Makefile CONFIG_HEADERS= $(SHELL) ./config.status
@@ -183,9 +188,13 @@ stamp-h: config.status $(srcdir)/config.h.in
CONFIG_FILES= CONFIG_HEADERS=config.h ./config.status
echo > $@
# CYGNUS LOCAL: Never run autoconf.
#$(srcdir)/configure: $(srcdir)/configure.in Comment-me-out in distribution
# cd $(srcdir) && autoconf Comment-me-out in distribution
#$(srcdir)/configure: $(srcdir)/configure.in ## Comment-me-out in distribution
# cd $(srcdir) && autoconf ## Comment-me-out in distribution
shared: force
-test -d shlib || mkdir shlib
-( cd shlib ; ${MAKE} ${MFLAGS} all )
documentation: force
-test -d doc || mkdir doc
@@ -197,49 +206,54 @@ examples: force
force:
## CYGNUS LOCAL
## Don't mess with people's installed readline's.
## This tries to install this version of readline over whatever
## version is already installed on the system (which could be a
## newer version). There is no real reason for us to install
## readline along with GDB. GDB links statically against readline,
## so it doesn't depend on us installing it on the system.
install-headers: installdirs ${INSTALLED_HEADERS}
for f in ${INSTALLED_HEADERS}; do \
$(INSTALL_DATA) $(srcdir)/$$f $(DESTDIR)$(includedir)/readline ; \
done
install:
#install: installdirs $(STATIC_LIBS)
# for f in ${INSTALLED_HEADERS}; do \
# $(INSTALL_DATA) $(srcdir)/$$f $(includedir)/readline ; \
# done
# -( if test -f $(libdir)/libreadline.a ; then $(MV) $(libdir)/libreadline.a $(libdir)/libreadline.old; fi )
# $(INSTALL_DATA) libreadline.a $(libdir)/libreadline.a
# -test -n "$(RANLIB)" && $(RANLIB) -t $(libdir)/libreadline.a
# -( if test -f $(libdir)/libhistory.a; then $(MV) $(libdir)/libhistory.a $(libdir)/libhistory.old; fi )
# $(INSTALL_DATA) libhistory.a $(libdir)/libhistory.a
# -test -n "$(RANLIB)" && $(RANLIB) -t $(libdir)/libhistory.a
# -( if test -d doc ; then \
# cd doc && \
# ${MAKE} ${MFLAGS} infodir=$(infodir) $@; \
# fi )
installdirs: $(srcdir)/support/mkdirs
-$(SHELL) $(srcdir)/support/mkdirs $(includedir) \
$(includedir)/readline $(libdir) $(infodir) $(man3dir)
uninstall:
-test -n "$(includedir)" && cd $(includedir)/readline && \
uninstall-headers:
-test -n "$(includedir)" && cd $(DESTDIR)$(includedir)/readline && \
${RM} ${INSTALLED_HEADERS}
-test -n "$(libdir)" && cd $(libdir) && \
maybe-uninstall-headers: uninstall-headers
install: $(INSTALL_TARGETS)
install-static: installdirs $(STATIC_LIBS) install-headers install-doc
-$(MV) $(DESTDIR)$(libdir)/libreadline.a $(DESTDIR)$(libdir)/libreadline.old
$(INSTALL_DATA) libreadline.a $(DESTDIR)$(libdir)/libreadline.a
-test -n "$(RANLIB)" && $(RANLIB) $(DESTDIR)$(libdir)/libreadline.a
-$(MV) $(DESTDIR)$(libdir)/libhistory.a $(DESTDIR)$(libdir)/libhistory.old
$(INSTALL_DATA) libhistory.a $(DESTDIR)$(libdir)/libhistory.a
-test -n "$(RANLIB)" && $(RANLIB) $(DESTDIR)$(libdir)/libhistory.a
installdirs: $(srcdir)/support/mkinstalldirs
-$(SHELL) $(srcdir)/support/mkinstalldirs $(DESTDIR)$(includedir) \
$(DESTDIR)$(includedir)/readline $(DESTDIR)$(libdir) \
$(DESTDIR)$(infodir) $(DESTDIR)$(man3dir)
uninstall: uninstall-headers uninstall-doc
-test -n "$(DESTDIR)$(libdir)" && cd $(DESTDIR)$(libdir) && \
${RM} libreadline.a libreadline.old libhistory.a libhistory.old $(SHARED_LIBS)
-( cd shlib; ${MAKE} ${MFLAGS} DESTDIR=${DESTDIR} uninstall )
install-shared: installdirs shared
-$(MV) $(libdir)/$(SHARED_HISTORY) $(libdir)/$(SHARED_HISTORY).old
$(INSTALL_DATA) $(SHARED_HISTORY) $(libdir)/$(SHARED_HISTORY)
-$(MV) $(libdir)/$(SHARED_READLINE) $(libdir)/$(SHARED_READLINE).old
$(INSTALL_DATA) $(SHARED_READLINE) $(libdir)/$(SHARED_READLINE)
install-shared: installdirs install-headers shared install-doc
-( cd shlib ; ${MAKE} ${MFLAGS} DESTDIR=${DESTDIR} install )
uninstall-shared: maybe-uninstall-headers
-( cd shlib; ${MAKE} ${MFLAGS} DESTDIR=${DESTDIR} uninstall )
uninstall-shared:
-test -n "$(libdir)" && cd $(libdir) && ${RM} ${SHARED_LIBS}
install-doc: installdirs
-( if test -d doc ; then \
cd doc && \
${MAKE} ${MFLAGS} infodir=$(infodir) DESTDIR=${DESTDIR} install; \
fi )
uninstall-doc:
-( if test -d doc ; then \
cd doc && \
${MAKE} ${MFLAGS} infodir=$(infodir) DESTDIR=${DESTDIR} uninstall; \
fi )
TAGS: force
$(ETAGS) $(CSOURCES) $(HSOURCES)
@@ -249,15 +263,18 @@ tags: force
clean: force
$(RM) $(OBJECTS) $(STATIC_LIBS)
$(RM) $(SHARED_OBJ) $(SHARED_LIBS)
$(RM) readline readline.exe
-( cd shlib && $(MAKE) $(MFLAGS) $@ )
-( cd doc && $(MAKE) $(MFLAGS) $@ )
-( cd examples && $(MAKE) $(MFLAGS) $@ )
mostlyclean: clean
-( cd shlib && $(MAKE) $(MFLAGS) $@ )
-( cd doc && $(MAKE) $(MFLAGS) $@ )
-( cd examples && $(MAKE) $(MFLAGS) $@ )
distclean maintainer-clean: clean
-( cd shlib && $(MAKE) $(MFLAGS) $@ )
-( cd doc && $(MAKE) $(MFLAGS) $@ )
-( cd examples && $(MAKE) $(MFLAGS) $@ )
$(RM) Makefile
@@ -274,7 +291,7 @@ installcheck:
dist: force
@echo Readline distributions are created using $(srcdir)/support/mkdist.
@echo Here is a sample of the necessary commands:
@echo bash $(srcdir)/support/mkdist -m $(srcdir)/MANIFEST -s $(srcdir) -r $(RL_LIBRARY_NAME)-$(RL_LIBRARY_VERSION)
@echo bash $(srcdir)/support/mkdist -m $(srcdir)/MANIFEST -s $(srcdir) -r $(RL_LIBRARY_NAME) $(RL_LIBRARY_VERSION)
@echo tar cf $(RL_LIBRARY_NAME)-${RL_LIBRARY_VERSION}.tar ${RL_LIBRARY_NAME}-$(RL_LIBRARY_VERSION)
@echo gzip $(RL_LIBRARY_NAME)-$(RL_LIBRARY_VERSION).tar
@@ -285,286 +302,235 @@ dist: force
# Dependencies
bind.o: ansi_stdlib.h posixstat.h
bind.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
bind.o: readline.h keymaps.h chardefs.h tilde.h
bind.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
bind.o: history.h
callback.o: rlconf.h
callback.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
callback.o: readline.h keymaps.h chardefs.h tilde.h
callback.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
compat.o: rlstdc.h
complete.o: ansi_stdlib.h posixdir.h posixstat.h
complete.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
complete.o: readline.h keymaps.h chardefs.h tilde.h
complete.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
display.o: ansi_stdlib.h posixstat.h
display.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
display.o: tcap.h
display.o: readline.h keymaps.h chardefs.h tilde.h
display.o: history.h
funmap.o: readline.h keymaps.h chardefs.h tilde.h
funmap.o: rlconf.h ansi_stdlib.h
display.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
display.o: history.h rlstdc.h
funmap.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
funmap.o: rlconf.h ansi_stdlib.h rlstdc.h
funmap.o: ${BUILD_DIR}/config.h
histexpand.o: ansi_stdlib.h
histexpand.o: history.h histlib.h
histexpand.o: history.h histlib.h rlstdc.h rltypedefs.h
histexpand.o: ${BUILD_DIR}/config.h
histfile.o: ansi_stdlib.h
histfile.o: history.h histlib.h
histfile.o: history.h histlib.h rlstdc.h rltypedefs.h
histfile.o: ${BUILD_DIR}/config.h
history.o: ansi_stdlib.h
history.o: history.h histlib.h
history.o: history.h histlib.h rlstdc.h rltypedefs.h
history.o: ${BUILD_DIR}/config.h
histsearch.o: ansi_stdlib.h
histsearch.o: history.h histlib.h
histsearch.o: history.h histlib.h rlstdc.h rltypedefs.h
histsearch.o: ${BUILD_DIR}/config.h
input.o: ansi_stdlib.h
input.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
input.o: readline.h keymaps.h chardefs.h tilde.h
input.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
isearch.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
isearch.o: readline.h keymaps.h chardefs.h tilde.h
isearch.o: ansi_stdlib.h history.h
isearch.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
isearch.o: ansi_stdlib.h history.h rlstdc.h
keymaps.o: emacs_keymap.c vi_keymap.c
keymaps.o: keymaps.h chardefs.h rlconf.h ansi_stdlib.h
keymaps.o: readline.h keymaps.h chardefs.h tilde.h
keymaps.o: ${BUILD_DIR}/config.h
keymaps.o: keymaps.h rltypedefs.h chardefs.h rlconf.h ansi_stdlib.h
keymaps.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
keymaps.o: ${BUILD_DIR}/config.h rlstdc.h
kill.o: ansi_stdlib.h
kill.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
kill.o: readline.h keymaps.h chardefs.h tilde.h
kill.o: history.h
kill.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
kill.o: history.h rlstdc.h
macro.o: ansi_stdlib.h
macro.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
macro.o: readline.h keymaps.h chardefs.h tilde.h
macro.o: history.h
macro.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
macro.o: history.h rlstdc.h
mbutil.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
mbutil.o: readline.h keymaps.h rltypedefs.h chardefs.h rlstdc.h
misc.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
misc.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
misc.o: history.h rlstdc.h ansi_stdlib.h
nls.o: ansi_stdlib.h
nls.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
nls.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
nls.o: history.h rlstdc.h
parens.o: rlconf.h
parens.o: ${BUILD_DIR}/config.h
parens.o: readline.h keymaps.h chardefs.h tilde.h
readline.o: readline.h keymaps.h chardefs.h tilde.h
parens.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
readline.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
readline.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
readline.o: history.h
readline.o: history.h rlstdc.h
readline.o: posixstat.h ansi_stdlib.h posixjmp.h
rltty.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
rltty.o: rltty.h
rltty.o: readline.h keymaps.h chardefs.h tilde.h
rltty.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
search.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
search.o: readline.h keymaps.h chardefs.h tilde.h
search.o: ansi_stdlib.h history.h
search.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
search.o: ansi_stdlib.h history.h rlstdc.h
shell.o: ${BUILD_DIR}/config.h
shell.o: ansi_stdlib.h
signals.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
signals.o: readline.h keymaps.h chardefs.h tilde.h
signals.o: history.h
signals.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
signals.o: history.h rlstdc.h
terminal.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
terminal.o: tcap.h
terminal.o: readline.h keymaps.h chardefs.h tilde.h
terminal.o: history.h
terminal.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
terminal.o: history.h rlstdc.h
text.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
text.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
text.o: history.h rlstdc.h ansi_stdlib.h
tilde.o: ansi_stdlib.h
tilde.o: ${BUILD_DIR}/config.h
tilde.o: tilde.h
undo.o: ansi_stdlib.h
undo.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
undo.o: readline.h keymaps.h chardefs.h tilde.h
undo.o: history.h
undo.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
undo.o: history.h rlstdc.h
util.o: posixjmp.h ansi_stdlib.h
util.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
util.o: readline.h keymaps.h chardefs.h tilde.h
util.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
vi_mode.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
vi_mode.o: readline.h keymaps.h chardefs.h tilde.h
vi_mode.o: history.h ansi_stdlib.h
vi_mode.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
vi_mode.o: history.h ansi_stdlib.h rlstdc.h
xmalloc.o: ${BUILD_DIR}/config.h
xmalloc.o: ansi_stdlib.h
readline.o: $(srcdir)/readline.c
vi_mode.o: $(srcdir)/vi_mode.c
funmap.o: $(srcdir)/funmap.c
keymaps.o: $(srcdir)/keymaps.c
parens.o: $(srcdir)/parens.c
search.o: $(srcdir)/search.c
rltty.o: $(srcdir)/rltty.c
complete.o: $(srcdir)/complete.c
bind.o: rlshell.h
histfile.o: rlshell.h
nls.o: rlshell.h
readline.o: rlshell.h
shell.o: rlshell.h
terminal.o: rlshell.h
histexpand.o: rlshell.h
bind.o: rlprivate.h
callback.o: rlprivate.h
complete.o: rlprivate.h
display.o: rlprivate.h
input.o: rlprivate.h
isearch.o: rlprivate.h
kill.o: rlprivate.h
macro.o: rlprivate.h
mbutil.o: rlprivate.h
misc.o: rlprivate.h
nls.o: rlprivate.h
parens.o: rlprivate.h
readline.o: rlprivate.h
rltty.o: rlprivate.h
search.o: rlprivate.h
signals.o: rlprivate.h
terminal.o: rlprivate.h
text.o: rlprivate.h
undo.o: rlprivate.h
util.o: rlprivate.h
vi_mode.o: rlprivate.h
bind.o: xmalloc.h
complete.o: xmalloc.h
display.o: xmalloc.h
funmap.o: xmalloc.h
histexpand.o: xmalloc.h
histfile.o: xmalloc.h
history.o: xmalloc.h
input.o: xmalloc.h
isearch.o: xmalloc.h
keymaps.o: xmalloc.h
kill.o: xmalloc.h
macro.o: xmalloc.h
mbutil.o: xmalloc.h
misc.o: xmalloc.h
readline.o: xmalloc.h
savestring.o: xmalloc.h
search.o: xmalloc.h
shell.o: xmalloc.h
terminal.o: xmalloc.h
text.o: xmalloc.h
tilde.o: xmalloc.h
undo.o: xmalloc.h
util.o: xmalloc.h
vi_mode.o: xmalloc.h
xmalloc.o: xmalloc.h
complete.o: rlmbutil.h
display.o: rlmbutil.h
histexpand.o: rlmbutil.h
input.o: rlmbutil.h
isearch.o: rlmbutil.h
mbutil.o: rlmbutil.h
misc.o: rlmbutil.h
readline.o: rlmbutil.h
search.o: rlmbutil.h
text.o: rlmbutil.h
vi_mode.o: rlmbutil.h
bind.o: $(srcdir)/bind.c
isearch.o: $(srcdir)/isearch.c
display.o: $(srcdir)/display.c
signals.o: $(srcdir)/signals.c
util.o: $(srcdir)/util.c
kill.o: $(srcdir)/kill.c
undo.o: $(srcdir)/undo.c
macro.o: $(srcdir)/macro.c
input.o: $(srcdir)/input.c
callback.o: $(srcdir)/callback.c
terminal.o: $(srcdir)/terminal.c
compat.o: $(srcdir)/compat.c
complete.o: $(srcdir)/complete.c
display.o: $(srcdir)/display.c
funmap.o: $(srcdir)/funmap.c
input.o: $(srcdir)/input.c
isearch.o: $(srcdir)/isearch.c
keymaps.o: $(srcdir)/keymaps.c $(srcdir)/emacs_keymap.c $(srcdir)/vi_keymap.c
kill.o: $(srcdir)/kill.c
macro.o: $(srcdir)/macro.c
mbutil.o: $(srcdir)/mbutil.c
misc.o: $(srcdir)/misc.c
nls.o: $(srcdir)/nls.c
parens.o: $(srcdir)/parens.c
readline.o: $(srcdir)/readline.c
rltty.o: $(srcdir)/rltty.c
savestring.o: $(srcdir)/savestring.c
search.o: $(srcdir)/search.c
shell.o: $(srcdir)/shell.c
signals.o: $(srcdir)/signals.c
terminal.o: $(srcdir)/terminal.c
text.o: $(srcdir)/text.c
tilde.o: $(srcdir)/tilde.c
undo.o: $(srcdir)/undo.c
util.o: $(srcdir)/util.c
vi_mode.o: $(srcdir)/vi_mode.c
xmalloc.o: $(srcdir)/xmalloc.c
history.o: $(srcdir)/history.c
histexpand.o: $(srcdir)/histexpand.c
histfile.o: $(srcdir)/histfile.c
history.o: $(srcdir)/history.c
histsearch.o: $(srcdir)/histsearch.c
shell.o: $(srcdir)/shell.c
tilde.o: $(srcdir)/tilde.c
bind.so: ansi_stdlib.h posixstat.h
bind.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
bind.so: readline.h keymaps.h chardefs.h tilde.h
bind.so: history.h
callback.so: rlconf.h
callback.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
callback.so: readline.h keymaps.h chardefs.h tilde.h
complete.so: ansi_stdlib.h posixdir.h posixstat.h
complete.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
complete.so: readline.h keymaps.h chardefs.h tilde.h
display.so: ansi_stdlib.h posixstat.h
display.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
display.so: tcap.h
display.so: readline.h keymaps.h chardefs.h tilde.h
display.so: history.h
funmap.so: readline.h keymaps.h chardefs.h tilde.h
funmap.so: rlconf.h ansi_stdlib.h
funmap.so: ${BUILD_DIR}/config.h
histexpand.so: ansi_stdlib.h
histexpand.so: history.h histlib.h
histexpand.so: ${BUILD_DIR}/config.h
histfile.so: ansi_stdlib.h
histfile.so: history.h histlib.h
histfile.so: ${BUILD_DIR}/config.h
history.so: ansi_stdlib.h
history.so: history.h histlib.h
history.so: ${BUILD_DIR}/config.h
histsearch.so: ansi_stdlib.h
histsearch.so: history.h histlib.h
histsearch.so: ${BUILD_DIR}/config.h
input.so: ansi_stdlib.h
input.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
input.so: readline.h keymaps.h chardefs.h tilde.h
isearch.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
isearch.so: readline.h keymaps.h chardefs.h tilde.h
isearch.so: ansi_stdlib.h history.h
keymaps.so: emacs_keymap.c vi_keymap.c
keymaps.so: keymaps.h chardefs.h rlconf.h ansi_stdlib.h
keymaps.so: readline.h keymaps.h chardefs.h tilde.h
keymaps.so: ${BUILD_DIR}/config.h
kill.so: ansi_stdlib.h
kill.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
kill.so: readline.h keymaps.h chardefs.h tilde.h
kill.so: history.h
macro.so: ansi_stdlib.h
macro.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
macro.so: readline.h keymaps.h chardefs.h tilde.h
macro.so: history.h
nls.so: ansi_stdlib.h
nls.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
parens.so: rlconf.h
parens.so: ${BUILD_DIR}/config.h
parens.so: readline.h keymaps.h chardefs.h tilde.h
readline.so: readline.h keymaps.h chardefs.h tilde.h
readline.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
readline.so: history.h
readline.so: posixstat.h ansi_stdlib.h posixjmp.h
rltty.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
rltty.so: rltty.h
rltty.so: readline.h keymaps.h chardefs.h tilde.h
search.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
search.so: readline.h keymaps.h chardefs.h tilde.h
search.so: ansi_stdlib.h history.h
signals.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
signals.so: readline.h keymaps.h chardefs.h tilde.h
signals.so: history.h
terminal.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
terminal.so: tcap.h
terminal.so: readline.h keymaps.h chardefs.h tilde.h
terminal.so: history.h
tilde.so: ansi_stdlib.h
tilde.so: ${BUILD_DIR}/config.h
tilde.so: tilde.h
undo.so: ansi_stdlib.h
undo.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
undo.so: readline.h keymaps.h chardefs.h tilde.h
undo.so: history.h
util.so: posixjmp.h ansi_stdlib.h
util.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
util.so: readline.h keymaps.h chardefs.h tilde.h
vi_mode.so: rldefs.h ${BUILD_DIR}/config.h rlconf.h
vi_mode.so: readline.h keymaps.h chardefs.h tilde.h
vi_mode.so: history.h ansi_stdlib.h
xmalloc.so: ${BUILD_DIR}/config.h
xmalloc.so: ansi_stdlib.h
readline.o: readline.c
vi_mode.o: vi_mode.c
funmap.o: funmap.c
keymaps.o: keymaps.c
parens.o: parens.c
search.o: search.c
rltty.o: rltty.c
complete.o: complete.c
bind.o: bind.c
isearch.o: isearch.c
display.o: display.c
signals.o: signals.c
util.o: util.c
kill.o: kill.c
undo.o: undo.c
macro.o: macro.c
input.o: input.c
callback.o: callback.c
terminal.o: terminal.c
compat.o: compat.c
complete.o: complete.c
display.o: display.c
funmap.o: funmap.c
input.o: input.c
isearch.o: isearch.c
keymaps.o: keymaps.c emacs_keymap.c vi_keymap.c
kill.o: kill.c
macro.o: macro.c
mbutil.o: mbutil.c
misc.o: misc.c
nls.o: nls.c
parens.o: parens.c
readline.o: readline.c
rltty.o: rltty.c
savestring.o: savestring.c
search.o: search.c
shell.o: shell.c
signals.o: signals.c
terminal.o: terminal.c
text.o: text.c
tilde.o: tilde.c
undo.o: undo.c
util.o: util.c
vi_mode.o: vi_mode.c
xmalloc.o: xmalloc.c
history.o: history.c
histexpand.o: histexpand.c
histfile.o: histfile.c
history.o: history.c
histsearch.o: histsearch.c
shell.o: shell.c
tilde.o: tilde.c
readline.so: $(srcdir)/readline.c
vi_mode.so: $(srcdir)/vi_mode.c
funmap.so: $(srcdir)/funmap.c
keymaps.so: $(srcdir)/keymaps.c
parens.so: $(srcdir)/parens.c
search.so: $(srcdir)/search.c
rltty.so: $(srcdir)/rltty.c
complete.so: $(srcdir)/complete.c
bind.so: $(srcdir)/bind.c
isearch.so: $(srcdir)/isearch.c
display.so: $(srcdir)/display.c
signals.so: $(srcdir)/signals.c
util.so: $(srcdir)/util.c
kill.so: $(srcdir)/kill.c
undo.so: $(srcdir)/undo.c
macro.so: $(srcdir)/macro.c
input.so: $(srcdir)/input.c
callback.so: $(srcdir)/callback.c
terminal.so: $(srcdir)/terminal.c
nls.so: $(srcdir)/nls.c
xmalloc.so: $(srcdir)/xmalloc.c
history.so: $(srcdir)/history.c
histexpand.so: $(srcdir)/histexpand.c
histfile.so: $(srcdir)/histfile.c
histsearch.so: $(srcdir)/histsearch.c
shell.so: $(srcdir)/shell.c
tilde.so: $(srcdir)/tilde.c
readline.so: readline.c
vi_mode.so: vi_mode.c
funmap.so: funmap.c
keymaps.so: keymaps.c
parens.so: parens.c
search.so: search.c
rltty.so: rltty.c
complete.so: complete.c
bind.so: bind.c
isearch.so: isearch.c
display.so: display.c
signals.so: signals.c
util.so: util.c
kill.so: kill.c
undo.so: undo.c
macro.so: macro.c
input.so: input.c
callback.so: callback.c
terminal.so: terminal.c
nls.so: nls.c
xmalloc.so: xmalloc.c
history.so: history.c
histexpand.so: histexpand.c
histfile.so: histfile.c
histsearch.so: histsearch.c
shell.so: shell.c
tilde.so: tilde.c

32
readline/NEWS Normal file
View File

@@ -0,0 +1,32 @@
This is a terse description of the new features added to readline-5.1 since
the release of readline-5.0.
1. New Features in Readline
a. The key sequence sent by the keypad `delete' key is now automatically
bound to delete-char.
b. A negative argument to menu-complete now cycles backward through the
completion list.
c. A new bindable readline variable: bind-tty-special-chars. If non-zero,
readline will bind the terminal special characters to their readline
equivalents when it's called (on by default).
d. New bindable command: vi-rubout. Saves deleted text for possible
reinsertion, as with any vi-mode `text modification' command; `X' is bound
to this in vi command mode.
e. If the rl_completion_query_items is set to a value < 0, readline never
asks the user whether or not to view the possible completions.
f. New application-callable auxiliary function, rl_variable_value, returns
a string corresponding to a readline variable's value.
g. When parsing inputrc files and variable binding commands, the parser
strips trailing whitespace from values assigned to boolean variables
before checking them.
h. A new external application-controllable variable that allows the LINES
and COLUMNS environment variables to set the window size regardless of
what the kernel returns.

View File

@@ -1,7 +1,7 @@
Introduction
============
This is the Gnu Readline library, version 2.2
This is the Gnu Readline library, version 5.1.
The Readline library provides a set of functions for use by applications
that allow users to edit command lines as they are typed in. Both
@@ -16,8 +16,8 @@ may be used without Readline in applications which desire its
capabilities.
The Readline library is free software, distributed under the terms of
the GNU Public License, version 2. For more information, see the file
COPYING.
the [GNU] General Public License, version 2. For more information, see
the file COPYING.
To build the library, try typing `./configure', then `make'. The
configuration process is automated, so no further intervention should
@@ -34,8 +34,11 @@ may work:
Read the file INSTALL in this directory for more information about how
to customize and control the build process.
The file rlconf.h contains defines that enable and disable certain
Readline features.
The file rlconf.h contains C preprocessor defines that enable and disable
certain Readline features.
The special make target `everything' will build the static and shared
libraries (if the target platform supports them) and the examples.
Examples
========
@@ -49,40 +52,111 @@ Shared Libraries
================
There is skeletal support for building shared versions of the
Readline and History libraries.
Readline and History libraries. The configure script creates
a Makefile in the `shlib' subdirectory, and typing `make shared'
will cause shared versions of the Readline and History libraries
to be built on supported platforms.
Typing `make shared' will cause shared versions of the Readline and
History libraries to be built on SunOS 4.1.x. For versions of Unix
other than SunOS, you will have to make some changes to Makefile.in.
The relevant variables are:
If `configure' is given the `--enable-shared' option, it will attempt
to build the shared libraries by default on supported platforms.
PICFLAG Options to give to the compiler to produce position-independent
code. The value `-fpic' works for most versions of gcc.
SHLIB_OPTS Options to give to the linker to produce a shared library.
The value `-assert pure-text -ldl' works on SunOS 4.1.x.
The value `-Bshareable' works for some versions of GNU ld.
Configure calls the script support/shobj-conf to test whether or
not shared library creation is supported and to generate the values
of variables that are substituted into shlib/Makefile. If you
try to build shared libraries on an unsupported platform, `make'
will display a message asking you to update support/shobj-conf for
your platform.
MAJOR The major version number of the shared library. You should
not need to change this.
MINOR The minor version number of the shared library. Some systems,
such as SVR4 and its descendents (e.g., Solaris, Unixware),
do not use minor version numbers. For those systems, this
variable should be left unset.
If you need to update support/shobj-conf, you will need to create
a `stanza' for your operating system and compiler. The script uses
the value of host_os and ${CC} as determined by configure. For
instance, FreeBSD 4.2 with any version of gcc is identified as
`freebsd4.2-gcc*'.
LD The linker. The value of `ld' is correct for SunOS 4.1.x.
You may need to change it to `gcc'; make sure to change
SHLIB_OPTS if you do so.
In the stanza for your operating system-compiler pair, you will need to
define several variables. They are:
Once you have edited Makefile.in, type `make Makefile' to rebuild the
Makefile, then `make shared' to build the shared libraries.
SHOBJ_CC The C compiler used to compile source files into shareable
object files. This is normally set to the value of ${CC}
by configure, and should not need to be changed.
SHOBJ_CFLAGS Flags to pass to the C compiler ($SHOBJ_CC) to create
position-independent code. If you are using gcc, this
should probably be set to `-fpic'.
SHOBJ_LD The link editor to be used to create the shared library from
the object files created by $SHOBJ_CC. If you are using
gcc, a value of `gcc' will probably work.
SHOBJ_LDFLAGS Flags to pass to SHOBJ_LD to enable shared object creation.
If you are using gcc, `-shared' may be all that is necessary.
These should be the flags needed for generic shared object
creation.
SHLIB_XLDFLAGS Additional flags to pass to SHOBJ_LD for shared library
creation. Many systems use the -R option to the link
editor to embed a path within the library for run-time
library searches. A reasonable value for such systems would
be `-R$(libdir)'.
SHLIB_LIBS Any additional libraries that shared libraries should be
linked against when they are created.
SHLIB_LIBPREF The prefix to use when generating the filename of the shared
library. The default is `lib'; Cygwin uses `cyg'.
SHLIB_LIBSUFF The suffix to add to `libreadline' and `libhistory' when
generating the filename of the shared library. Many systems
use `so'; HP-UX uses `sl'.
SHLIB_LIBVERSION The string to append to the filename to indicate the version
of the shared library. It should begin with $(SHLIB_LIBSUFF),
and possibly include version information that allows the
run-time loader to load the version of the shared library
appropriate for a particular program. Systems using shared
libraries similar to SunOS 4.x use major and minor library
version numbers; for those systems a value of
`$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' is appropriate.
Systems based on System V Release 4 don't use minor version
numbers; use `$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' on those systems.
Other Unix versions use different schemes.
SHLIB_DLLVERSION The version number for shared libraries that determines API
compatibility between readline versions and the underlying
system. Used only on Cygwin. Defaults to $SHLIB_MAJOR, but
can be overridden at configuration time by defining DLLVERSION
in the environment.
SHLIB_DOT The character used to separate the name of the shared library
from the suffix and version information. The default is `.';
systems like Cygwin which don't separate version information
from the library name should set this to the empty string.
SHLIB_STATUS Set this to `supported' when you have defined the other
necessary variables. Make uses this to determine whether
or not shared library creation should be attempted.
You should look at the existing stanzas in support/shobj-conf for ideas.
Once you have updated support/shobj-conf, re-run configure and type
`make shared'. The shared libraries will be created in the shlib
subdirectory.
If shared libraries are created, `make install' will install them.
You may install only the shared libraries by running `make
install-shared' from the top-level build directory. Running `make
install' in the shlib subdirectory will also work. If you don't want
to install any created shared libraries, run `make install-static'.
Documentation
=============
The documentation for the Readline and History libraries appears in the
`doc' subdirectory. There are two texinfo files and a Unix-style manual
page describing the programming facilities available in the Readline
library. The texinfo files include both user and programmer's manuals.
The documentation for the Readline and History libraries appears in
the `doc' subdirectory. There are three texinfo files and a
Unix-style manual page describing the facilities available in the
Readline library. The texinfo files include both user and
programmer's manuals. HTML versions of the manuals appear in the
`doc' subdirectory as well.
Reporting Bugs
==============
@@ -93,7 +167,7 @@ Bug reports for Readline should be sent to:
When reporting a bug, please include the following information:
* the version number and release status of Readline (e.g., 2.2-release)
* the version number and release status of Readline (e.g., 4.2-release)
* the machine and OS that it is running on
* a list of the compilation flags or the contents of `config.h', if
appropriate

37
readline/USAGE Normal file
View File

@@ -0,0 +1,37 @@
From rms@gnu.org Thu Jul 22 20:37:55 1999
Flags: 10
Return-Path: rms@gnu.org
Received: from arthur.INS.CWRU.Edu (root@arthur.INS.CWRU.Edu [129.22.8.215]) by odin.INS.CWRU.Edu with ESMTP (8.8.6+cwru/CWRU-2.4-ins)
id UAA25349; Thu, 22 Jul 1999 20:37:54 -0400 (EDT) (from rms@gnu.org for <chet@odin.INS.CWRU.Edu>)
Received: from nike.ins.cwru.edu (root@nike.INS.CWRU.Edu [129.22.8.219]) by arthur.INS.CWRU.Edu with ESMTP (8.8.8+cwru/CWRU-3.6)
id UAA05311; Thu, 22 Jul 1999 20:37:51 -0400 (EDT) (from rms@gnu.org for <chet@po.cwru.edu>)
Received: from pele.santafe.edu (pele.santafe.edu [192.12.12.119]) by nike.ins.cwru.edu with ESMTP (8.8.7/CWRU-2.5-bsdi)
id UAA13350; Thu, 22 Jul 1999 20:37:50 -0400 (EDT) (from rms@gnu.org for <chet@nike.ins.cwru.edu>)
Received: from wijiji.santafe.edu (wijiji [192.12.12.5])
by pele.santafe.edu (8.9.1/8.9.1) with ESMTP id SAA10831
for <chet@nike.ins.cwru.edu>; Thu, 22 Jul 1999 18:37:47 -0600 (MDT)
Received: (from rms@localhost)
by wijiji.santafe.edu (8.9.1b+Sun/8.9.1) id SAA01089;
Thu, 22 Jul 1999 18:37:46 -0600 (MDT)
Date: Thu, 22 Jul 1999 18:37:46 -0600 (MDT)
Message-Id: <199907230037.SAA01089@wijiji.santafe.edu>
X-Authentication-Warning: wijiji.santafe.edu: rms set sender to rms@gnu.org using -f
From: Richard Stallman <rms@gnu.org>
To: chet@nike.ins.cwru.edu
Subject: Use of Readline
Reply-to: rms@gnu.org
I think Allbery's suggestion is a good one. So please add this text
in a suitable place. Please don't put it in the GPL itself; that
should be the same as the GPL everywhere else. Putting it in the
README and/or the documentation would be a good idea.
======================================================================
Our position on the use of Readline through a shared-library linking
mechanism is that there is no legal difference between shared-library
linking and static linking--either kind of linking combines various
modules into a single larger work. The conditions for using Readline
in a larger work are stated in section 3 of the GNU GPL.

View File

@@ -23,32 +23,6 @@
#undef HAVE_GETPW_DECLS
#undef FIONREAD_IN_SYS_IOCTL
#undef HAVE_BSD_SIGNALS
#undef HAVE_LSTAT
#undef HAVE_POSIX_SIGNALS
#undef HAVE_POSIX_SIGSETJMP
#undef HAVE_USG_SIGHOLD
#undef MUST_REINSTALL_SIGHANDLERS
#undef SPEED_T_IN_SYS_TYPES
#undef STRCOLL_BROKEN
#undef STRUCT_DIRENT_HAS_D_FILENO
#undef STRUCT_DIRENT_HAS_D_INO
#undef STRUCT_WINSIZE_IN_SYS_IOCTL
#undef STRUCT_WINSIZE_IN_TERMIOS
/* Leave that blank line there!! Autoheader needs it.
If you're adding to this file, keep in mind:

4489
readline/aclocal.m4 vendored

File diff suppressed because it is too large Load Diff

View File

@@ -18,18 +18,31 @@
You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#if !defined (_STDLIB_H_)
#define _STDLIB_H_ 1
/* String conversion functions. */
extern int atoi ();
extern long int atol ();
extern double atof ();
extern double strtod ();
/* Memory allocation functions. */
extern char *malloc ();
extern char *realloc ();
/* Generic pointer type. */
#ifndef PTR_T
#if defined (__STDC__)
# define PTR_T void *
#else
# define PTR_T char *
#endif
#endif /* PTR_T */
extern PTR_T malloc ();
extern PTR_T realloc ();
extern void free ();
/* Other miscellaneous functions. */

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,13 @@
/* callback.c -- functions to use readline as an X `callback' mechanism. */
/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
The GNU Readline Library is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 1, or
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
The GNU Readline Library is distributed in the hope that it will be
@@ -18,7 +18,7 @@
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#define READLINE_LIBRARY
#if defined (HAVE_CONFIG_H)
@@ -30,24 +30,28 @@
#if defined (READLINE_CALLBACKS)
#include <sys/types.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#else
# include "ansi_stdlib.h"
#endif
#include <stdio.h>
/* System-specific feature definitions and include files. */
#include "rldefs.h"
#include "readline.h"
#include "rlprivate.h"
extern void readline_internal_startup ();
extern char *readline_internal_teardown ();
extern int readline_internal_char ();
extern void _rl_init_line_state ();
extern int _rl_meta_flag;
extern char *rl_prompt;
extern int rl_visible_prompt_length;
/* Private data for callback registration functions. See comments in
rl_callback_read_char for more details. */
_rl_callback_func_t *_rl_callback_func = 0;
_rl_callback_generic_arg *_rl_callback_data = 0;
/* **************************************************************** */
/* */
/* Callback Readline Functions */
/* Callback Readline Functions */
/* */
/* **************************************************************** */
@@ -60,7 +64,7 @@ extern int rl_visible_prompt_length;
text read in at each end of line. The terminal is kept prepped and
signals handled all the time, except during calls to the user's function. */
VFunction *rl_linefunc; /* user callback function */
rl_vcpfunc_t *rl_linefunc; /* user callback function */
static int in_handler; /* terminal_prepped and signals set? */
/* Make sure the terminal is set up, initialize readline, and prompt. */
@@ -73,7 +77,8 @@ _rl_callback_newline ()
{
in_handler = 1;
(*rl_prep_term_function) (_rl_meta_flag);
if (rl_prep_term_function)
(*rl_prep_term_function) (_rl_meta_flag);
#if defined (HANDLE_SIGNALS)
rl_set_signals ();
@@ -86,11 +91,11 @@ _rl_callback_newline ()
/* Install a readline handler, set up the terminal, and issue the prompt. */
void
rl_callback_handler_install (prompt, linefunc)
char *prompt;
VFunction *linefunc;
const char *prompt;
rl_vcpfunc_t *linefunc;
{
rl_prompt = prompt;
rl_visible_prompt_length = rl_prompt ? rl_expand_prompt (rl_prompt) : 0;
rl_set_prompt (prompt);
RL_SETSTATE (RL_STATE_CALLBACK);
rl_linefunc = linefunc;
_rl_callback_newline ();
}
@@ -100,7 +105,8 @@ void
rl_callback_read_char ()
{
char *line;
int eof;
int eof, jcode;
static procenv_t olevel;
if (rl_linefunc == NULL)
{
@@ -108,26 +114,108 @@ rl_callback_read_char ()
abort ();
}
eof = readline_internal_char ();
if (rl_done)
memcpy ((void *)olevel, (void *)readline_top_level, sizeof (procenv_t));
jcode = setjmp (readline_top_level);
if (jcode)
{
line = readline_internal_teardown (eof);
(*rl_redisplay_function) ();
_rl_want_redisplay = 0;
memcpy ((void *)readline_top_level, (void *)olevel, sizeof (procenv_t));
return;
}
(*rl_deprep_term_function) ();
if (RL_ISSTATE (RL_STATE_ISEARCH))
{
eof = _rl_isearch_callback (_rl_iscxt);
if (eof == 0 && (RL_ISSTATE (RL_STATE_ISEARCH) == 0) && RL_ISSTATE (RL_STATE_INPUTPENDING))
rl_callback_read_char ();
return;
}
else if (RL_ISSTATE (RL_STATE_NSEARCH))
{
eof = _rl_nsearch_callback (_rl_nscxt);
return;
}
else if (RL_ISSTATE (RL_STATE_NUMERICARG))
{
eof = _rl_arg_callback (_rl_argcxt);
if (eof == 0 && (RL_ISSTATE (RL_STATE_NUMERICARG) == 0) && RL_ISSTATE (RL_STATE_INPUTPENDING))
rl_callback_read_char ();
/* XXX - this should handle _rl_last_command_was_kill better */
else if (RL_ISSTATE (RL_STATE_NUMERICARG) == 0)
_rl_internal_char_cleanup ();
return;
}
else if (RL_ISSTATE (RL_STATE_MULTIKEY))
{
eof = _rl_dispatch_callback (_rl_kscxt); /* For now */
while ((eof == -1 || eof == -2) && RL_ISSTATE (RL_STATE_MULTIKEY) && _rl_kscxt && (_rl_kscxt->flags & KSEQ_DISPATCHED))
eof = _rl_dispatch_callback (_rl_kscxt);
if (RL_ISSTATE (RL_STATE_MULTIKEY) == 0)
{
_rl_internal_char_cleanup ();
_rl_want_redisplay = 1;
}
}
else if (_rl_callback_func)
{
/* This allows functions that simply need to read an additional character
(like quoted-insert) to register a function to be called when input is
available. _rl_callback_data is simply a pointer to a struct that has
the argument count originally passed to the registering function and
space for any additional parameters. */
eof = (*_rl_callback_func) (_rl_callback_data);
/* If the function `deregisters' itself, make sure the data is cleaned
up. */
if (_rl_callback_func == 0)
{
if (_rl_callback_data)
{
_rl_callback_data_dispose (_rl_callback_data);
_rl_callback_data = 0;
}
_rl_internal_char_cleanup ();
}
}
else
eof = readline_internal_char ();
if (rl_done == 0 && _rl_want_redisplay)
{
(*rl_redisplay_function) ();
_rl_want_redisplay = 0;
}
/* We loop in case some function has pushed input back with rl_execute_next. */
for (;;)
{
if (rl_done)
{
line = readline_internal_teardown (eof);
if (rl_deprep_term_function)
(*rl_deprep_term_function) ();
#if defined (HANDLE_SIGNALS)
rl_clear_signals ();
rl_clear_signals ();
#endif
in_handler = 0;
(*rl_linefunc) (line);
in_handler = 0;
(*rl_linefunc) (line);
/* If the user did not clear out the line, do it for him. */
if (rl_line_buffer[0])
_rl_init_line_state ();
/* If the user did not clear out the line, do it for him. */
if (rl_line_buffer[0])
_rl_init_line_state ();
/* Redisplay the prompt if readline_handler_{install,remove} not called. */
if (in_handler == 0 && rl_linefunc)
_rl_callback_newline ();
/* Redisplay the prompt if readline_handler_{install,remove}
not called. */
if (in_handler == 0 && rl_linefunc)
_rl_callback_newline ();
}
if (rl_pending_input || _rl_pushed_input_available () || RL_ISSTATE (RL_STATE_MACROINPUT))
eof = readline_internal_char ();
else
break;
}
}
@@ -136,14 +224,37 @@ void
rl_callback_handler_remove ()
{
rl_linefunc = NULL;
RL_UNSETSTATE (RL_STATE_CALLBACK);
if (in_handler)
{
in_handler = 0;
(*rl_deprep_term_function) ();
if (rl_deprep_term_function)
(*rl_deprep_term_function) ();
#if defined (HANDLE_SIGNALS)
rl_clear_signals ();
#endif
}
}
_rl_callback_generic_arg *
_rl_callback_data_alloc (count)
int count;
{
_rl_callback_generic_arg *arg;
arg = (_rl_callback_generic_arg *)xmalloc (sizeof (_rl_callback_generic_arg));
arg->count = count;
arg->i1 = arg->i2 = 0;
return arg;
}
void _rl_callback_data_dispose (arg)
_rl_callback_generic_arg *arg;
{
if (arg)
free (arg);
}
#endif

View File

@@ -7,7 +7,7 @@
The GNU Readline Library is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 1, or
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
The GNU Readline Library is distributed in the hope that it will be
@@ -18,7 +18,7 @@
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#ifndef _CHARDEFS_H_
#define _CHARDEFS_H_
@@ -27,10 +27,14 @@
#if defined (HAVE_CONFIG_H)
# if defined (HAVE_STRING_H)
# if ! defined (STDC_HEADERS) && defined (HAVE_MEMORY_H)
# include <memory.h>
# endif
# include <string.h>
# else
# include <strings.h>
# endif /* HAVE_STRING_H */
# if defined (HAVE_STRINGS_H)
# include <strings.h>
# endif /* HAVE_STRINGS_H */
#else
# include <string.h>
#endif /* !HAVE_CONFIG_H */
@@ -40,7 +44,10 @@
#endif
#ifdef CTRL
#undef CTRL
# undef CTRL
#endif
#ifdef UNCTRL
# undef UNCTRL
#endif
/* Some character stuff. */
@@ -51,7 +58,7 @@
#define meta_character_bit 0x080 /* x0000000, must be on. */
#define largest_char 255 /* Largest character value. */
#define CTRL_CHAR(c) ((c) < control_character_threshold && (c) >= 0)
#define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0))
#define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
#define CTRL(c) ((c) & control_character_mask)
@@ -60,33 +67,65 @@
#define UNMETA(c) ((c) & (~meta_character_bit))
#define UNCTRL(c) _rl_to_upper(((c)|control_character_bit))
/* Old versions
#define _rl_lowercase_p(c) (((c) > ('a' - 1) && (c) < ('z' + 1)))
#define _rl_uppercase_p(c) (((c) > ('A' - 1) && (c) < ('Z' + 1)))
#define _rl_digit_p(c) ((c) >= '0' && (c) <= '9')
*/
#if defined STDC_HEADERS || (!defined (isascii) && !defined (HAVE_ISASCII))
# define IN_CTYPE_DOMAIN(c) 1
#else
# define IN_CTYPE_DOMAIN(c) isascii(c)
#endif
#define _rl_lowercase_p(c) (islower(c))
#define _rl_uppercase_p(c) (isupper(c))
#define _rl_digit_p(x) (isdigit (x))
#if !defined (isxdigit) && !defined (HAVE_ISXDIGIT)
# define isxdigit(c) (isdigit((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
#endif
#define _rl_pure_alphabetic(c) (_rl_lowercase_p(c) || _rl_uppercase_p(c))
#define ALPHABETIC(c) (_rl_lowercase_p(c) || _rl_uppercase_p(c) || _rl_digit_p(c))
#if defined (CTYPE_NON_ASCII)
# define NON_NEGATIVE(c) 1
#else
# define NON_NEGATIVE(c) ((unsigned char)(c) == (c))
#endif
/* Old versions
# define _rl_to_upper(c) (_rl_lowercase_p(c) ? ((c) - 32) : (c))
# define _rl_to_lower(c) (_rl_uppercase_p(c) ? ((c) + 32) : (c))
*/
/* Some systems define these; we want our definitions. */
#undef ISPRINT
/* Beware: these only work with single-byte ASCII characters. */
#define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
#define ISDIGIT(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
#define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
#define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
#define _rl_lowercase_p(c) (NON_NEGATIVE(c) && ISLOWER(c))
#define _rl_uppercase_p(c) (NON_NEGATIVE(c) && ISUPPER(c))
#define _rl_digit_p(c) ((c) >= '0' && (c) <= '9')
#define _rl_pure_alphabetic(c) (NON_NEGATIVE(c) && ISALPHA(c))
#define ALPHABETIC(c) (NON_NEGATIVE(c) && ISALNUM(c))
#ifndef _rl_to_upper
# define _rl_to_upper(c) (islower(c) ? toupper(c) : (c))
# define _rl_to_lower(c) (isupper(c) ? tolower(c) : (c))
# define _rl_to_upper(c) (_rl_lowercase_p(c) ? toupper((unsigned char)c) : (c))
# define _rl_to_lower(c) (_rl_uppercase_p(c) ? tolower((unsigned char)c) : (c))
#endif
#ifndef _rl_digit_value
#define _rl_digit_value(x) ((x) - '0')
# define _rl_digit_value(x) ((x) - '0')
#endif
#ifndef _rl_isident
# define _rl_isident(c) (ISALNUM(c) || (c) == '_')
#endif
#ifndef ISOCTAL
# define ISOCTAL(c) ((c) >= '0' && (c) <= '7')
#endif
#define OCTVALUE(c) ((c) - '0')
#define HEXVALUE(c) \
(((c) >= 'a' && (c) <= 'f') \
? (c)-'a'+10 \
: (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
#ifndef NEWLINE
#define NEWLINE '\n'
#endif
@@ -123,18 +162,4 @@
#endif
#define ESC CTRL('[')
#ifndef ISOCTAL
#define ISOCTAL(c) ((c) >= '0' && (c) <= '7')
#endif
#define OCTVALUE(c) ((c) - '0')
#ifndef isxdigit
# define isxdigit(c) (isdigit((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
#endif
#define HEXVALUE(c) \
(((c) >= 'a' && (c) <= 'f') \
? (c)-'a'+10 \
: (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
#endif /* _CHARDEFS_H_ */

113
readline/compat.c Normal file
View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -1,59 +1,66 @@
/* config.h.in. Generated automatically from configure.in by autoheader. */
/* config.h.in. Maintained by hand. */
/* Define if you have the strcoll function and it is properly defined. */
#undef HAVE_STRCOLL
/* Define NO_MULTIBYTE_SUPPORT to not compile in support for multibyte
characters, even if the OS supports them. */
#undef NO_MULTIBYTE_SUPPORT
/* Define if on MINIX. */
#undef _MINIX
/* Define if the system does not provide POSIX.1 features except
with this defined. */
#undef _POSIX_1_SOURCE
/* Define if you need to in order for stat and other things to work. */
#undef _POSIX_SOURCE
/* Define as the return type of signal handlers (int or void). */
#undef RETSIGTYPE
#undef VOID_SIGHANDLER
/* Characteristics of the compiler. */
#undef const
#undef size_t
#undef ssize_t
#undef PROTOTYPES
#undef __CHAR_UNSIGNED__
/* Define if the `S_IS*' macros in <sys/stat.h> do not work properly. */
#undef STAT_MACROS_BROKEN
/* Definitions pulled in from aclocal.m4. */
#undef VOID_SIGHANDLER
/* Define if you have the fcntl function. */
#undef HAVE_FCNTL
#undef TIOCSTAT_IN_SYS_IOCTL
/* Define if you have the getpwent function. */
#undef HAVE_GETPWENT
#undef HAVE_GETPW_DECLS
/* Define if you have the getpwnam function. */
#undef HAVE_GETPWNAM
#undef FIONREAD_IN_SYS_IOCTL
/* Define if you have the getpwuid function. */
#undef HAVE_GETPWUID
#undef HAVE_BSD_SIGNALS
/* Define if you have the isascii function. */
#undef HAVE_ISASCII
/* Define if you have the isxdigit function. */
#undef HAVE_ISXDIGIT
/* Define if you have the kill function. */
#undef HAVE_KILL
/* Define if you have the lstat function. */
#undef HAVE_LSTAT
#undef HAVE_POSIX_SIGNALS
/* Define if you have the mbrlen function. */
#undef HAVE_MBRLEN
#undef HAVE_POSIX_SIGSETJMP
/* Define if you have the mbrtowc function. */
#undef HAVE_MBRTOWC
#undef HAVE_USG_SIGHOLD
/* Define if you have the mbsrtowcs function. */
#undef HAVE_MBSRTOWCS
#undef MUST_REINSTALL_SIGHANDLERS
#undef SPEED_T_IN_SYS_TYPES
#undef STRCOLL_BROKEN
#undef STRUCT_DIRENT_HAS_D_FILENO
#undef STRUCT_DIRENT_HAS_D_INO
#undef STRUCT_WINSIZE_IN_SYS_IOCTL
#undef STRUCT_WINSIZE_IN_TERMIOS
/* Define if you have the lstat function. */
#undef HAVE_LSTAT
/* Define if you have the memmove function. */
#undef HAVE_MEMMOVE
/* Define if you have the putenv function. */
#undef HAVE_PUTENV
@@ -64,24 +71,58 @@
/* Define if you have the setenv function. */
#undef HAVE_SETENV
/* Define if you have the setlocale function. */
/* Define if you have the setlocale function. */
#undef HAVE_SETLOCALE
/* Define if you have the strcasecmp function. */
#undef HAVE_STRCASECMP
/* Define if you have the strcoll function. */
#undef HAVE_STRCOLL
#undef STRCOLL_BROKEN
/* Define if you have the strpbrk function. */
#undef HAVE_STRPBRK
/* Define if you have the tcgetattr function. */
#undef HAVE_TCGETATTR
/* Define if you have the vsnprintf function. */
#undef HAVE_VSNPRINTF
/* Define if you have the wctomb function. */
#undef HAVE_WCTOMB
/* Define if you have the wcwidth function. */
#undef HAVE_WCWIDTH
#undef STDC_HEADERS
/* Define if you have the <dirent.h> header file. */
#undef HAVE_DIRENT_H
/* Define if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define if you have the <langinfo.h> header file. */
#undef HAVE_LANGINFO_H
/* Define if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H
/* Define if you have the <locale.h> header file. */
#undef HAVE_LOCALE_H
/* Define if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define if you have the <ndir.h> header file. */
#undef HAVE_NDIR_H
/* Define if you have the <pwd.h> header file. */
#undef HAVE_PWD_H
/* Define if you have the <stdarg.h> header file. */
#undef HAVE_STDARG_H
@@ -91,6 +132,9 @@
/* Define if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define if you have the <sys/dir.h> header file. */
#undef HAVE_SYS_DIR_H
@@ -126,7 +170,51 @@
/* Define if you have the <varargs.h> header file. */
#undef HAVE_VARARGS_H
/* config.h.bot */
/* Define if you have the <wchar.h> header file. */
#undef HAVE_WCHAR_H
/* Define if you have the <varargs.h> header file. */
#undef HAVE_WCTYPE_H
#undef HAVE_MBSTATE_T
/* Define if you have <langinfo.h> and nl_langinfo(CODESET). */
#undef HAVE_LANGINFO_CODESET
/* Definitions pulled in from aclocal.m4. */
#undef VOID_SIGHANDLER
#undef GWINSZ_IN_SYS_IOCTL
#undef STRUCT_WINSIZE_IN_SYS_IOCTL
#undef STRUCT_WINSIZE_IN_TERMIOS
#undef TIOCSTAT_IN_SYS_IOCTL
#undef FIONREAD_IN_SYS_IOCTL
#undef SPEED_T_IN_SYS_TYPES
#undef HAVE_GETPW_DECLS
#undef STRUCT_DIRENT_HAS_D_INO
#undef STRUCT_DIRENT_HAS_D_FILENO
#undef HAVE_BSD_SIGNALS
#undef HAVE_POSIX_SIGNALS
#undef HAVE_USG_SIGHOLD
#undef MUST_REINSTALL_SIGHANDLERS
#undef HAVE_POSIX_SIGSETJMP
#undef CTYPE_NON_ASCII
/* modify settings or make new ones based on what autoconf tells us. */
/* Ultrix botches type-ahead when switching from canonical to

9910
readline/configure vendored

File diff suppressed because it is too large Load Diff

View File

@@ -4,110 +4,175 @@ dnl
dnl report bugs to chet@po.cwru.edu
dnl
dnl Process this file with autoconf to produce a configure script.
AC_REVISION([for Readline 2.2, version 2.07, from autoconf version] AC_ACVERSION)
LIBVERSION=2.2
AC_INIT(readline.h)
AC_CONFIG_HEADER(config.h)
# Copyright (C) 1987-2005 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
AC_REVISION([for Readline 5.1, version 2.59])
AC_INIT(readline, 5.1-release, bug-readline@gnu.org)
dnl make sure we are using a recent autoconf version
AC_PREREQ(2.10)
AC_PREREQ(2.50)
dnl AC_CONFIG_AUX_DIR(./support)
AC_CONFIG_SRCDIR(readline.h)
AC_CONFIG_AUX_DIR(./support)
AC_CONFIG_HEADERS(config.h)
dnl update the value of RL_READLINE_VERSION in readline.h when this changes
LIBVERSION=5.1
AC_CANONICAL_HOST
dnl configure defaults
opt_curses=no
opt_shared=no
opt_purify=no
dnl arguments to configure
AC_ARG_WITH(curses, --with-curses use the curses library instead of the termcap library,opt_curses=$withval)
AC_ARG_WITH(curses, AC_HELP_STRING([--with-curses], [use the curses library instead of the termcap library]), opt_curses=$withval)
AC_ARG_WITH(purify, AC_HELP_STRING([--with-purify], [configure to postprocess with purify]), opt_purify=$withval)
if test "$opt_curses" = "yes"; then
prefer_curses=yes
fi
# We want these before the checks, so the checks can modify their values.
test -z "$CFLAGS" && CFLAGS=-g auto_cflags=1
if test "$opt_purify" = yes; then
PURIFY="purify"
else
PURIFY=
fi
AC_PROG_CC
AC_MINIX
dnl option parsing for optional features
opt_multibyte=yes
opt_static_libs=yes
opt_shared_libs=yes
AC_ARG_ENABLE(multibyte, AC_HELP_STRING([--enable-multibyte], [enable multibyte characters if OS supports them]), opt_multibyte=$enableval)
AC_ARG_ENABLE(shared, AC_HELP_STRING([--enable-shared], [build shared libraries [[default=YES]]]), opt_shared_libs=$enableval)
AC_ARG_ENABLE(static, AC_HELP_STRING([--enable-static], [build static libraries [[default=YES]]]), opt_static_libs=$enableval)
if test $opt_multibyte = no; then
AC_DEFINE(NO_MULTIBYTE_SUPPORT)
fi
dnl BEGIN changes for CYGNUS cross-building for Cygwin
dnl load up the cross-building cache file -- add more cases and cache
dnl files as necessary
dnl Note that host and target machine are the same, and different than the
dnl build machine.
if test "x$cross_compiling" = "xyes"; then
case "${host}" in
*-cygwin*)
cross_cache=${srcdir}/cross-build/cygwin.cache
if test -r "${cross_cache}"; then
echo "loading cross-build cache file ${cross_cache}"
. ${cross_cache}
fi
LOCAL_CFLAGS="$LOCAL_CFLAGS -I${srcdir}/../libtermcap"
unset cross_cache
;;
*) echo "configure: cross-compiling for a non-cygwin target is not supported" >&2
;;
cross_cache=${srcdir}/cross-build/cygwin.cache
;;
*-mingw*)
cross_cache=${srcdir}/cross-build/mingw.cache
;;
i[[3456]]86-*-beos*)
cross_cache=${srcdir}/cross-build/x86-beos.cache
;;
*) echo "configure: cross-compiling for $host is not supported" >&2
;;
esac
fi
if test "x$cross_compiling" = "xyes"; then
CROSS_COMPILING_FLAG=-DCROSS_COMPILING
else
CROSS_COMPILING_FLAG=
fi
AC_SUBST(CROSS_COMPILING_FLAG)
if test -z "$CC_FOR_BUILD"; then
if test "x$cross_compiling" = "xno"; then
CC_FOR_BUILD='$(CC)'
else
CC_FOR_BUILD=gcc
if test -n "${cross_cache}" && test -r "${cross_cache}"; then
echo "loading cross-build cache file ${cross_cache}"
. ${cross_cache}
fi
unset cross_cache
CROSS_COMPILE='-DCROSS_COMPILING'
AC_SUBST(CROSS_COMPILE)
fi
AC_SUBST(CC_FOR_BUILD)
dnl END changes for CYGNUS cross-building for Cygwin
echo ""
echo "Beginning configuration for readline-$LIBVERSION for ${host_cpu}-${host_vendor}-${host_os}"
echo ""
# We want these before the checks, so the checks can modify their values.
test -z "$CFLAGS" && CFLAGS=-g auto_cflags=1
AC_PROG_MAKE_SET
AC_PROG_CC
dnl AC_AIX
AC_MINIX
# If we're using gcc and the user hasn't specified CFLAGS, add -O to CFLAGS.
test -n "$GCC" && test -n "$auto_cflags" && CFLAGS="$CFLAGS -O"
AC_PROG_GCC_TRADITIONAL
AC_PROG_INSTALL
AC_CHECK_PROG(AR, ar, , ar)
dnl Set default for ARFLAGS, since autoconf does not have a macro for it.
dnl This allows people to set it when running configure or make
test -n "$ARFLAGS" || ARFLAGS="cr"
AC_PROG_RANLIB
AC_RETSIGTYPE
MAKE_SHELL=/bin/sh
AC_SUBST(MAKE_SHELL)
AC_C_CONST
AC_C_PROTOTYPES
AC_C_CHAR_UNSIGNED
AC_TYPE_SIGNAL
AC_TYPE_SIZE_T
AC_CHECK_TYPE(ssize_t, int)
AC_HEADER_STDC
AC_HEADER_STAT
AC_HEADER_DIRENT
AC_CHECK_FUNCS(strcasecmp select setenv putenv tcgetattr setlocale lstat)
AC_CHECK_FUNCS(fcntl kill lstat)
AC_CHECK_FUNCS(memmove putenv select setenv setlocale \
strcasecmp strpbrk tcgetattr vsnprintf)
AC_CHECK_FUNCS(isascii isxdigit)
AC_CHECK_FUNCS(getpwent getpwnam getpwuid)
AC_FUNC_STRCOLL
AC_CHECK_HEADERS(unistd.h stdlib.h varargs.h stdarg.h string.h \
sys/ptem.h sys/pte.h sys/stream.h sys/select.h \
termcap.h termios.h termio.h sys/file.h locale.h)
AC_CHECK_HEADERS(fcntl.h unistd.h stdlib.h varargs.h stdarg.h string.h strings.h \
limits.h locale.h pwd.h memory.h termcap.h termios.h termio.h)
AC_CHECK_HEADERS(sys/pte.h sys/stream.h sys/select.h sys/file.h)
BASH_SIGNAL_CHECK
BASH_REINSTALL_SIGHANDLERS
AC_CHECK_HEADERS(sys/ptem.h,,,
[[
#if HAVE_SYS_STREAM_H
# include <sys/stream.h>
#endif
]])
BASH_SYS_SIGNAL_VINTAGE
BASH_SYS_REINSTALL_SIGHANDLERS
BASH_FUNC_POSIX_SETJMP
BASH_FUNC_LSTAT
BASH_CHECK_GETPW_FUNCS
BASH_FUNC_STRCOLL
BASH_FUNC_CTYPE_NONASCII
BASH_CHECK_GETPW_FUNCS
AC_HEADER_TIOCGWINSZ
BASH_TYPE_SIGHANDLER
BASH_HAVE_TIOCGWINSZ
BASH_HAVE_TIOCSTAT
BASH_HAVE_FIONREAD
BASH_MISC_SPEED_T
BASH_CHECK_SPEED_T
BASH_STRUCT_WINSIZE
BASH_STRUCT_DIRENT_D_INO
BASH_STRUCT_DIRENT_D_FILENO
@@ -118,18 +183,94 @@ aix*) prefer_curses=yes ;;
esac
BASH_CHECK_LIB_TERMCAP
if test "$TERMCAP_LIB" = "./lib/termcap/libtermcap.a"; then
TERMCAP_LIB=-ltermcap #default
if test "$prefer_curses" = yes; then
TERMCAP_LIB=-lcurses
else
TERMCAP_LIB=-ltermcap #default
fi
fi
BASH_CHECK_MULTIBYTE
case "$host_cpu" in
*cray*) LOCAL_CFLAGS=-DCRAY ;;
*s390*) LOCAL_CFLAGS=-fsigned-char ;;
esac
case "$host_os" in
isc*) LOCAL_CFLAGS=-Disc386 ;;
esac
BUILD_DIR=`pwd`
# shared library configuration section
#
# Shared object configuration section. These values are generated by
# ${srcdir}/support/shobj-conf
#
if test -f ${srcdir}/support/shobj-conf; then
AC_MSG_CHECKING(configuration for building shared libraries)
eval `TERMCAP_LIB=$TERMCAP_LIB ${CONFIG_SHELL-/bin/sh} ${srcdir}/support/shobj-conf -C "${CC}" -c ${host_cpu} -o ${host_os} -v ${host_vendor}`
# case "$SHLIB_LIBS" in
# *curses*|*termcap*|*termlib*) ;;
# *) SHLIB_LIBS="$SHLIB_LIBS $TERMCAP_LIB" ;;
# esac
AC_SUBST(SHOBJ_CC)
AC_SUBST(SHOBJ_CFLAGS)
AC_SUBST(SHOBJ_LD)
AC_SUBST(SHOBJ_LDFLAGS)
AC_SUBST(SHOBJ_XLDFLAGS)
AC_SUBST(SHOBJ_LIBS)
AC_SUBST(SHOBJ_STATUS)
AC_SUBST(SHLIB_STATUS)
AC_SUBST(SHLIB_XLDFLAGS)
AC_SUBST(SHLIB_DOT)
AC_SUBST(SHLIB_LIBPREF)
AC_SUBST(SHLIB_LIBSUFF)
AC_SUBST(SHLIB_LIBVERSION)
AC_SUBST(SHLIB_DLLVERSION)
AC_SUBST(SHLIB_LIBS)
AC_MSG_RESULT($SHLIB_STATUS)
# SHLIB_STATUS is either `supported' or `unsupported'. If it's
# `unsupported', turn off any default shared library building
if test "$SHLIB_STATUS" = 'unsupported'; then
opt_shared_libs=no
fi
# shared library versioning
# quoted for m4 so I can use character classes
SHLIB_MAJOR=[`expr "$LIBVERSION" : '\([0-9]\)\..*'`]
SHLIB_MINOR=[`expr "$LIBVERSION" : '[0-9]\.\([0-9]\).*'`]
AC_SUBST(SHLIB_MAJOR)
AC_SUBST(SHLIB_MINOR)
fi
if test "$opt_static_libs" = "yes"; then
STATIC_TARGET=static
STATIC_INSTALL_TARGET=install-static
fi
if test "$opt_shared_libs" = "yes"; then
SHARED_TARGET=shared
SHARED_INSTALL_TARGET=install-shared
fi
AC_SUBST(STATIC_TARGET)
AC_SUBST(SHARED_TARGET)
AC_SUBST(STATIC_INSTALL_TARGET)
AC_SUBST(SHARED_INSTALL_TARGET)
case "$host_os" in
msdosdjgpp*) BUILD_DIR=`pwd.exe` ;; # to prevent //d/path/file
*) BUILD_DIR=`pwd` ;;
esac
case "$BUILD_DIR" in
*\ *) BUILD_DIR=`echo "$BUILD_DIR" | sed 's: :\\\\ :g'` ;;
*) ;;
esac
AC_SUBST(PURIFY)
AC_SUBST(BUILD_DIR)
AC_SUBST(CFLAGS)
@@ -137,6 +278,9 @@ AC_SUBST(LOCAL_CFLAGS)
AC_SUBST(LOCAL_LDFLAGS)
AC_SUBST(LOCAL_DEFS)
AC_SUBST(AR)
AC_SUBST(ARFLAGS)
AC_SUBST(host_cpu)
AC_SUBST(host_os)
@@ -144,7 +288,7 @@ AC_SUBST(LIBVERSION)
AC_SUBST(TERMCAP_LIB)
AC_OUTPUT([Makefile doc/Makefile examples/Makefile],
AC_OUTPUT([Makefile doc/Makefile examples/Makefile shlib/Makefile],
[
# Makefile uses this timestamp file to record whether config.h is up to date.
echo > stamp-h

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,23 @@
# This makefile for Readline library documentation is in -*- text -*- mode.
# Emacs likes it that way.
top_srcdir = @top_srcdir@
# Copyright (C) 1996-2004 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
topdir = @top_srcdir@
srcdir = @srcdir@
VPATH = .:@srcdir@
@@ -8,26 +25,45 @@ prefix = @prefix@
infodir = @infodir@
mandir = @mandir@
man3dir = $(mandir)/man3
manpfx = man
man1ext = .1
man1dir = $(mandir)/$(manpfx)1
man3ext = .3
man3dir = $(mandir)/$(manpfx)3
# set this to a value to have the HTML documentation installed
htmldir =
# Support an alternate destination root directory for package building
DESTDIR =
SHELL = @MAKE_SHELL@
RM = rm -f
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
BUILD_DIR = @BUILD_DIR@
TEXINPUTDIR = $(srcdir)
MAKEINFO = makeinfo
MAKEINFO = LANGUAGE= makeinfo
TEXI2DVI = $(srcdir)/texi2dvi
TEXI2HTML = $(srcdir)/texi2html
QUIETPS = #set this to -q to shut up dvips
DVIPS = dvips -D 300 $(QUIETPS) -o $@ # tricky
PAPERSIZE = letter
PSDPI = 600
DVIPS = dvips -D ${PSDPI} $(QUIETPS) -t ${PAPERSIZE} -o $@ # tricky
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
# These tools might not be available; they're not required
DVIPDF = dvipdfm -o $@ -p ${PAPERSIZE}
PSPDF = gs -sPAPERSIZE=${PAPERSIZE} -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -sOutputFile=$@
RLSRC = $(srcdir)/rlman.texinfo $(srcdir)/rluser.texinfo \
$(srcdir)/rltech.texinfo
HISTSRC = $(srcdir)/hist.texinfo $(srcdir)/hsuser.texinfo \
$(srcdir)/hstech.texinfo
RLSRC = $(srcdir)/rlman.texi $(srcdir)/rluser.texi \
$(srcdir)/rltech.texi $(srcdir)/version.texi \
$(srcdir)/rluserman.texi
HISTSRC = $(srcdir)/history.texi $(srcdir)/hsuser.texi \
$(srcdir)/hstech.texi $(srcdir)/version.texi
# This should be a program that converts troff to an ascii-readable format
NROFF = groff -Tascii
@@ -35,101 +71,182 @@ NROFF = groff -Tascii
# This should be a program that converts troff to postscript
GROFF = groff
DVIOBJ = readline.dvi history.dvi
INFOOBJ = readline.info history.info
PSOBJ = readline.ps history.ps
HTMLOBJ = readline.html history.html
HTMLTOC = readline_toc.html history_toc.html
TEXTOBJ = readline.0
DVIOBJ = readline.dvi history.dvi rluserman.dvi
INFOOBJ = readline.info history.info rluserman.info
PSOBJ = readline.ps history.ps rluserman.ps readline_3.ps history_3.ps
HTMLOBJ = readline.html history.html rluserman.html
TEXTOBJ = readline.0 history.0
PDFOBJ = readline.pdf history.pdf rluserman.pdf
CREATED_DOCS = $(DVIOBJ) $(INFOOBJ) $(PSOBJ) $(HTMLOBJ) $(HTMLTOC) $(TEXTOBJ)
INTERMEDIATE_OBJ = rlman.dvi
.SUFFIXES: .0 .3 .ps .txt .dvi
DIST_DOCS = $(DVIOBJ) $(PSOBJ) $(HTMLOBJ) $(INFOOBJ) $(TEXTOBJ)
.SUFFIXES: .0 .3 .ps .txt .dvi .html .pdf
.3.0:
$(RM) $@
-${NROFF} -man $< > $@
.ps.pdf:
$(RM) $@
-${PSPDF} $<
.dvi.pdf:
$(RM) $@
-${DVIPDF} $<
all: info dvi html ps text
nodvi: info html text
readline.dvi: $(RLSRC)
TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/rlman.texinfo
mv rlman.dvi readline.dvi
readline.info: $(RLSRC)
$(MAKEINFO) --no-split -I $(TEXINPUTDIR) -o $@ $(srcdir)/rlman.texinfo
history.dvi: ${HISTSRC}
TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/hist.texinfo
mv hist.dvi history.dvi
history.info: ${HISTSRC}
$(MAKEINFO) --no-split -I $(TEXINPUTDIR) -o $@ $(srcdir)/hist.texinfo
readline.ps: readline.dvi
$(RM) $@
$(DVIPS) readline.dvi
history.ps: history.dvi
$(RM) $@
$(DVIPS) history.dvi
readline.html: ${RLSRC}
$(TEXI2HTML) -I $(TEXINPUTDIR) $(srcdir)/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) -I $(TEXINPUTDIR) $(srcdir)/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)
text: $(TEXTOBJ)
pdf: $(PDFOBJ)
readline.dvi: $(RLSRC)
TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/rlman.texi
mv rlman.dvi readline.dvi
readline.info: $(RLSRC)
$(MAKEINFO) --no-split -I $(TEXINPUTDIR) -o $@ $(srcdir)/rlman.texi
rluserman.dvi: $(RLSRC)
TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/rluserman.texi
rluserman.info: $(RLSRC)
$(MAKEINFO) --no-split -I $(TEXINPUTDIR) -o $@ $(srcdir)/rluserman.texi
history.dvi: ${HISTSRC}
TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/history.texi
history.info: ${HISTSRC}
$(MAKEINFO) --no-split -I $(TEXINPUTDIR) -o $@ $(srcdir)/history.texi
readline.ps: readline.dvi
$(RM) $@
$(DVIPS) readline.dvi
rluserman.ps: rluserman.dvi
$(RM) $@
$(DVIPS) rluserman.dvi
history.ps: history.dvi
$(RM) $@
$(DVIPS) history.dvi
#
# This leaves readline.html and rlman.html -- rlman.html is for www.gnu.org
#
readline.html: ${RLSRC}
$(TEXI2HTML) -menu -monolithic -I $(TEXINPUTDIR) $(srcdir)/rlman.texi
sed -e 's:rlman.html:readline.html:g' rlman.html > readline.html
$(RM) rlman.html
rluserman.html: ${RLSRC}
$(TEXI2HTML) -menu -monolithic -I $(TEXINPUTDIR) $(srcdir)/rluserman.texi
history.html: ${HISTSRC}
$(TEXI2HTML) -menu -monolithic -I $(TEXINPUTDIR) $(srcdir)/history.texi
readline.0: readline.3
clean:
$(RM) *.aux *.cp *.fn *.ky *.log *.pg *.toc *.tp *.vr *.cps *.pgs \
*.fns *.kys *.tps *.vrs *.o core
readline_3.ps: readline.3
${RM} $@
${GROFF} -man < $(srcdir)/readline.3 > $@
distclean: clean
$(RM) $(CREATED_DOCS)
$(RM) Makefile
history.0: history.3
history_3.ps: history.3
${RM} $@
${GROFF} -man < $(srcdir)/history.3 > $@
readline.pdf: readline.dvi
history.pdf: history.dvi
rluserman.pdf: rluserman.dvi
clean:
$(RM) *.aux *.bak *.cp *.fn *.ky *.log *.pg *.toc *.tp *.vr *.cps \
*.pgs *.bt *.bts *.rw *.rws *.fns *.kys *.tps *.vrs *.o \
core *.core
mostlyclean: clean
maintainer-clean: clean
$(RM) $(CREATED_DOCS)
distclean: clean maybe-clean
$(RM) $(INTERMEDIATE_OBJ)
$(RM) Makefile
installdirs: $(top_srcdir)/support/mkdirs
-$(SHELL) $(top_srcdir)/support/mkdirs $(infodir) $(man3dir)
maybe-clean:
-if test "X$(topdir)" != "X$(BUILD_DIR)"; then \
$(RM) $(DIST_DOCS); \
fi
install: installdirs info
maintainer-clean: clean
$(RM) $(DIST_DOCS)
$(RM) $(INTERMEDIATE_OBJ)
$(RM) $(PDFOBJ)
$(RM) Makefile
installdirs: $(topdir)/support/mkdirs
-$(SHELL) $(topdir)/support/mkdirs $(DESTDIR)$(infodir) $(DESTDIR)$(man3dir)
-if test -n "${htmldir}" ; then \
$(SHELL) $(topdir)/support/mkdirs $(DESTDIR)$(htmldir) ; \
fi
install: installdirs
if test -f readline.info; then \
${INSTALL_DATA} readline.info $(infodir)/readline.info; \
${INSTALL_DATA} readline.info $(DESTDIR)$(infodir)/readline.info; \
else \
${INSTALL_DATA} $(srcdir)/readline.info $(infodir)/readline.info; \
${INSTALL_DATA} $(srcdir)/readline.info $(DESTDIR)$(infodir)/readline.info; \
fi
if test -f rluserman.info; then \
${INSTALL_DATA} rluserman.info $(DESTDIR)$(infodir)/rluserman.info; \
else \
${INSTALL_DATA} $(srcdir)/rluserman.info $(DESTDIR)$(infodir)/rluserman.info; \
fi
if test -f history.info; then \
${INSTALL_DATA} history.info $(infodir)/history.info; \
${INSTALL_DATA} history.info $(DESTDIR)$(infodir)/history.info; \
else \
${INSTALL_DATA} $(srcdir)/history.info $(infodir)/history.info; \
${INSTALL_DATA} $(srcdir)/history.info $(DESTDIR)$(infodir)/history.info; \
fi
if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
install-info --dir-file=$(infodir)/dir $(infodir)/readline.info ; \
install-info --dir-file=$(infodir)/dir $(infodir)/history.info ; \
-if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
install-info --dir-file=$(DESTDIR)$(infodir)/dir \
$(DESTDIR)$(infodir)/readline.info ; \
install-info --dir-file=$(DESTDIR)$(infodir)/dir \
$(DESTDIR)$(infodir)/history.info ; \
install-info --dir-file=$(DESTDIR)$(infodir)/dir \
$(DESTDIR)$(infodir)/rluserman.info ; \
else true; fi
-${INSTALL_DATA} $(srcdir)/readline.3 $(man3dir)/readline.3
-${INSTALL_DATA} $(srcdir)/readline.3 $(DESTDIR)$(man3dir)/readline$(man3ext)
-${INSTALL_DATA} $(srcdir)/history.3 $(DESTDIR)$(man3dir)/history$(man3ext)
-if test -n "${htmldir}" ; then \
if test -f readline.html; then \
${INSTALL_DATA} readline.html $(DESTDIR)$(htmldir)/readline.html; \
else \
${INSTALL_DATA} $(srcdir)/readline.html $(DESTDIR)$(htmldir)/readline.html; \
fi ; \
if test -f history.html; then \
${INSTALL_DATA} history.html $(DESTDIR)$(htmldir)/history.html; \
else \
${INSTALL_DATA} $(srcdir)/history.html $(DESTDIR)$(htmldir)/history.html; \
fi ; \
if test -f rluserman.html; then \
${INSTALL_DATA} rluserman.html $(DESTDIR)$(htmldir)/rluserman.html; \
else \
${INSTALL_DATA} $(srcdir)/rluserman.html $(DESTDIR)$(htmldir)/rluserman.html; \
fi ; \
fi
uninstall:
$(RM) $(infodir)/readline.info
$(RM) $(infodir)/history.info
$(RM) $(man3dir)/readline.3
$(RM) $(DESTDIR)$(infodir)/readline.info
$(RM) $(DESTDIR)$(infodir)/rluserman.info
$(RM) $(DESTDIR)$(infodir)/history.info
$(RM) $(DESTDIR)$(man3dir)/readline$(man3ext)
$(RM) $(DESTDIR)$(man3dir)/history$(man3ext)
-if test -n "${htmldir}" ; then \
$(RM) $(DESTDIR)$(htmldir)/readline.html ; \
$(RM) $(DESTDIR)$(htmldir)/rluserman.html ; \
$(RM) $(DESTDIR)$(htmldir)/history.html ; \
fi

452
readline/doc/fdl.texi Normal file
View File

@@ -0,0 +1,452 @@
@node GNU Free Documentation License
@appendixsec GNU Free Documentation License
@cindex FDL, GNU Free Documentation License
@center Version 1.2, November 2002
@display
Copyright @copyright{} 2000,2001,2002 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@end display
@enumerate 0
@item
PREAMBLE
The purpose of this License is to make a manual, textbook, or other
functional and useful document @dfn{free} in the sense of freedom: to
assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or noncommercially.
Secondarily, this License preserves for the author and publisher a way
to get credit for their work, while not being considered responsible
for modifications made by others.
This License is a kind of ``copyleft'', which means that derivative
works of the document must themselves be free in the same sense. It
complements the GNU General Public License, which is a copyleft
license designed for free software.
We have designed this License in order to use it for manuals for free
software, because free software needs free documentation: a free
program should come with manuals providing the same freedoms that the
software does. But this License is not limited to software manuals;
it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book. We recommend this License
principally for works whose purpose is instruction or reference.
@item
APPLICABILITY AND DEFINITIONS
This License applies to any manual or other work, in any medium, that
contains a notice placed by the copyright holder saying it can be
distributed under the terms of this License. Such a notice grants a
world-wide, royalty-free license, unlimited in duration, to use that
work under the conditions stated herein. The ``Document'', below,
refers to any such manual or work. Any member of the public is a
licensee, and is addressed as ``you''. You accept the license if you
copy, modify or distribute the work in a way requiring permission
under copyright law.
A ``Modified Version'' of the Document means any work containing the
Document or a portion of it, either copied verbatim, or with
modifications and/or translated into another language.
A ``Secondary Section'' is a named appendix or a front-matter section
of the Document that deals exclusively with the relationship of the
publishers or authors of the Document to the Document's overall
subject (or to related matters) and contains nothing that could fall
directly within that overall subject. (Thus, if the Document is in
part a textbook of mathematics, a Secondary Section may not explain
any mathematics.) The relationship could be a matter of historical
connection with the subject or with related matters, or of legal,
commercial, philosophical, ethical or political position regarding
them.
The ``Invariant Sections'' are certain Secondary Sections whose titles
are designated, as being those of Invariant Sections, in the notice
that says that the Document is released under this License. If a
section does not fit the above definition of Secondary then it is not
allowed to be designated as Invariant. The Document may contain zero
Invariant Sections. If the Document does not identify any Invariant
Sections then there are none.
The ``Cover Texts'' are certain short passages of text that are listed,
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
the Document is released under this License. A Front-Cover Text may
be at most 5 words, and a Back-Cover Text may be at most 25 words.
A ``Transparent'' copy of the Document means a machine-readable copy,
represented in a format whose specification is available to the
general public, that is suitable for revising the document
straightforwardly with generic text editors or (for images composed of
pixels) generic paint programs or (for drawings) some widely available
drawing editor, and that is suitable for input to text formatters or
for automatic translation to a variety of formats suitable for input
to text formatters. A copy made in an otherwise Transparent file
format whose markup, or absence of markup, has been arranged to thwart
or discourage subsequent modification by readers is not Transparent.
An image format is not Transparent if used for any substantial amount
of text. A copy that is not ``Transparent'' is called ``Opaque''.
Examples of suitable formats for Transparent copies include plain
@sc{ascii} without markup, Texinfo input format, La@TeX{} input
format, @acronym{SGML} or @acronym{XML} using a publicly available
@acronym{DTD}, and standard-conforming simple @acronym{HTML},
PostScript or @acronym{PDF} designed for human modification. Examples
of transparent image formats include @acronym{PNG}, @acronym{XCF} and
@acronym{JPG}. Opaque formats include proprietary formats that can be
read and edited only by proprietary word processors, @acronym{SGML} or
@acronym{XML} for which the @acronym{DTD} and/or processing tools are
not generally available, and the machine-generated @acronym{HTML},
PostScript or @acronym{PDF} produced by some word processors for
output purposes only.
The ``Title Page'' means, for a printed book, the title page itself,
plus such following pages as are needed to hold, legibly, the material
this License requires to appear in the title page. For works in
formats which do not have any title page as such, ``Title Page'' means
the text near the most prominent appearance of the work's title,
preceding the beginning of the body of the text.
A section ``Entitled XYZ'' means a named subunit of the Document whose
title either is precisely XYZ or contains XYZ in parentheses following
text that translates XYZ in another language. (Here XYZ stands for a
specific section name mentioned below, such as ``Acknowledgements'',
``Dedications'', ``Endorsements'', or ``History''.) To ``Preserve the Title''
of such a section when you modify the Document means that it remains a
section ``Entitled XYZ'' according to this definition.
The Document may include Warranty Disclaimers next to the notice which
states that this License applies to the Document. These Warranty
Disclaimers are considered to be included by reference in this
License, but only as regards disclaiming warranties: any other
implication that these Warranty Disclaimers may have is void and has
no effect on the meaning of this License.
@item
VERBATIM COPYING
You may copy and distribute the Document in any medium, either
commercially or noncommercially, provided that this License, the
copyright notices, and the license notice saying this License applies
to the Document are reproduced in all copies, and that you add no other
conditions whatsoever to those of this License. You may not use
technical measures to obstruct or control the reading or further
copying of the copies you make or distribute. However, you may accept
compensation in exchange for copies. If you distribute a large enough
number of copies you must also follow the conditions in section 3.
You may also lend copies, under the same conditions stated above, and
you may publicly display copies.
@item
COPYING IN QUANTITY
If you publish printed copies (or copies in media that commonly have
printed covers) of the Document, numbering more than 100, and the
Document's license notice requires Cover Texts, you must enclose the
copies in covers that carry, clearly and legibly, all these Cover
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover. Both covers must also clearly and legibly identify
you as the publisher of these copies. The front cover must present
the full title with all words of the title equally prominent and
visible. You may add other material on the covers in addition.
Copying with changes limited to the covers, as long as they preserve
the title of the Document and satisfy these conditions, can be treated
as verbatim copying in other respects.
If the required texts for either cover are too voluminous to fit
legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto adjacent
pages.
If you publish or distribute Opaque copies of the Document numbering
more than 100, you must either include a machine-readable Transparent
copy along with each Opaque copy, or state in or with each Opaque copy
a computer-network location from which the general network-using
public has access to download using public-standard network protocols
a complete Transparent copy of the Document, free of added material.
If you use the latter option, you must take reasonably prudent steps,
when you begin distribution of Opaque copies in quantity, to ensure
that this Transparent copy will remain thus accessible at the stated
location until at least one year after the last time you distribute an
Opaque copy (directly or through your agents or retailers) of that
edition to the public.
It is requested, but not required, that you contact the authors of the
Document well before redistributing any large number of copies, to give
them a chance to provide you with an updated version of the Document.
@item
MODIFICATIONS
You may copy and distribute a Modified Version of the Document under
the conditions of sections 2 and 3 above, provided that you release
the Modified Version under precisely this License, with the Modified
Version filling the role of the Document, thus licensing distribution
and modification of the Modified Version to whoever possesses a copy
of it. In addition, you must do these things in the Modified Version:
@enumerate A
@item
Use in the Title Page (and on the covers, if any) a title distinct
from that of the Document, and from those of previous versions
(which should, if there were any, be listed in the History section
of the Document). You may use the same title as a previous version
if the original publisher of that version gives permission.
@item
List on the Title Page, as authors, one or more persons or entities
responsible for authorship of the modifications in the Modified
Version, together with at least five of the principal authors of the
Document (all of its principal authors, if it has fewer than five),
unless they release you from this requirement.
@item
State on the Title page the name of the publisher of the
Modified Version, as the publisher.
@item
Preserve all the copyright notices of the Document.
@item
Add an appropriate copyright notice for your modifications
adjacent to the other copyright notices.
@item
Include, immediately after the copyright notices, a license notice
giving the public permission to use the Modified Version under the
terms of this License, in the form shown in the Addendum below.
@item
Preserve in that license notice the full lists of Invariant Sections
and required Cover Texts given in the Document's license notice.
@item
Include an unaltered copy of this License.
@item
Preserve the section Entitled ``History'', Preserve its Title, and add
to it an item stating at least the title, year, new authors, and
publisher of the Modified Version as given on the Title Page. If
there is no section Entitled ``History'' in the Document, create one
stating the title, year, authors, and publisher of the Document as
given on its Title Page, then add an item describing the Modified
Version as stated in the previous sentence.
@item
Preserve the network location, if any, given in the Document for
public access to a Transparent copy of the Document, and likewise
the network locations given in the Document for previous versions
it was based on. These may be placed in the ``History'' section.
You may omit a network location for a work that was published at
least four years before the Document itself, or if the original
publisher of the version it refers to gives permission.
@item
For any section Entitled ``Acknowledgements'' or ``Dedications'', Preserve
the Title of the section, and preserve in the section all the
substance and tone of each of the contributor acknowledgements and/or
dedications given therein.
@item
Preserve all the Invariant Sections of the Document,
unaltered in their text and in their titles. Section numbers
or the equivalent are not considered part of the section titles.
@item
Delete any section Entitled ``Endorsements''. Such a section
may not be included in the Modified Version.
@item
Do not retitle any existing section to be Entitled ``Endorsements'' or
to conflict in title with any Invariant Section.
@item
Preserve any Warranty Disclaimers.
@end enumerate
If the Modified Version includes new front-matter sections or
appendices that qualify as Secondary Sections and contain no material
copied from the Document, you may at your option designate some or all
of these sections as invariant. To do this, add their titles to the
list of Invariant Sections in the Modified Version's license notice.
These titles must be distinct from any other section titles.
You may add a section Entitled ``Endorsements'', provided it contains
nothing but endorsements of your Modified Version by various
parties---for example, statements of peer review or that the text has
been approved by an organization as the authoritative definition of a
standard.
You may add a passage of up to five words as a Front-Cover Text, and a
passage of up to 25 words as a Back-Cover Text, to the end of the list
of Cover Texts in the Modified Version. Only one passage of
Front-Cover Text and one of Back-Cover Text may be added by (or
through arrangements made by) any one entity. If the Document already
includes a cover text for the same cover, previously added by you or
by arrangement made by the same entity you are acting on behalf of,
you may not add another; but you may replace the old one, on explicit
permission from the previous publisher that added the old one.
The author(s) and publisher(s) of the Document do not by this License
give permission to use their names for publicity for or to assert or
imply endorsement of any Modified Version.
@item
COMBINING DOCUMENTS
You may combine the Document with other documents released under this
License, under the terms defined in section 4 above for modified
versions, provided that you include in the combination all of the
Invariant Sections of all of the original documents, unmodified, and
list them all as Invariant Sections of your combined work in its
license notice, and that you preserve all their Warranty Disclaimers.
The combined work need only contain one copy of this License, and
multiple identical Invariant Sections may be replaced with a single
copy. If there are multiple Invariant Sections with the same name but
different contents, make the title of each such section unique by
adding at the end of it, in parentheses, the name of the original
author or publisher of that section if known, or else a unique number.
Make the same adjustment to the section titles in the list of
Invariant Sections in the license notice of the combined work.
In the combination, you must combine any sections Entitled ``History''
in the various original documents, forming one section Entitled
``History''; likewise combine any sections Entitled ``Acknowledgements'',
and any sections Entitled ``Dedications''. You must delete all
sections Entitled ``Endorsements.''
@item
COLLECTIONS OF DOCUMENTS
You may make a collection consisting of the Document and other documents
released under this License, and replace the individual copies of this
License in the various documents with a single copy that is included in
the collection, provided that you follow the rules of this License for
verbatim copying of each of the documents in all other respects.
You may extract a single document from such a collection, and distribute
it individually under this License, provided you insert a copy of this
License into the extracted document, and follow this License in all
other respects regarding verbatim copying of that document.
@item
AGGREGATION WITH INDEPENDENT WORKS
A compilation of the Document or its derivatives with other separate
and independent documents or works, in or on a volume of a storage or
distribution medium, is called an ``aggregate'' if the copyright
resulting from the compilation is not used to limit the legal rights
of the compilation's users beyond what the individual works permit.
When the Document is included an aggregate, this License does not
apply to the other works in the aggregate which are not themselves
derivative works of the Document.
If the Cover Text requirement of section 3 is applicable to these
copies of the Document, then if the Document is less than one half of
the entire aggregate, the Document's Cover Texts may be placed on
covers that bracket the Document within the aggregate, or the
electronic equivalent of covers if the Document is in electronic form.
Otherwise they must appear on printed covers that bracket the whole
aggregate.
@item
TRANSLATION
Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section 4.
Replacing Invariant Sections with translations requires special
permission from their copyright holders, but you may include
translations of some or all Invariant Sections in addition to the
original versions of these Invariant Sections. You may include a
translation of this License, and all the license notices in the
Document, and any Warranty Disclaimers, provided that you also include
the original English version of this License and the original versions
of those notices and disclaimers. In case of a disagreement between
the translation and the original version of this License or a notice
or disclaimer, the original version will prevail.
If a section in the Document is Entitled ``Acknowledgements'',
``Dedications'', or ``History'', the requirement (section 4) to Preserve
its Title (section 1) will typically require changing the actual
title.
@item
TERMINATION
You may not copy, modify, sublicense, or distribute the Document except
as expressly provided for under this License. Any other attempt to
copy, modify, sublicense or distribute the Document is void, and will
automatically terminate your rights under this License. However,
parties who have received copies, or rights, from you under this
License will not have their licenses terminated so long as such
parties remain in full compliance.
@item
FUTURE REVISIONS OF THIS LICENSE
The Free Software Foundation may publish new, revised versions
of the GNU Free Documentation License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns. See
@uref{http://www.gnu.org/copyleft/}.
Each version of the License is given a distinguishing version number.
If the Document specifies that a particular numbered version of this
License ``or any later version'' applies to it, you have the option of
following the terms and conditions either of that specified version or
of any later version that has been published (not as a draft) by the
Free Software Foundation. If the Document does not specify a version
number of this License, you may choose any version ever published (not
as a draft) by the Free Software Foundation.
@end enumerate
@page
@appendixsubsec ADDENDUM: How to use this License for your documents
To use this License in a document you have written, include a copy of
the License in the document and put the following copyright and
license notices just after the title page:
@smallexample
@group
Copyright (C) @var{year} @var{your name}.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled ``GNU
Free Documentation License''.
@end group
@end smallexample
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
replace the ``with...Texts.'' line with this:
@smallexample
@group
with the Invariant Sections being @var{list their titles}, with
the Front-Cover Texts being @var{list}, and with the Back-Cover Texts
being @var{list}.
@end group
@end smallexample
If you have Invariant Sections without Cover Texts, or some other
combination of the three, merge those two alternatives to suit the
situation.
If your document contains nontrivial examples of program code, we
recommend releasing these examples in parallel under your choice of
free software license, such as the GNU General Public License,
to permit their use in free software.
@c Local Variables:
@c ispell-local-pdict: "ispell-dict"
@c End:

View File

@@ -6,26 +6,19 @@
@setchapternewpage odd
@ignore
last change: Thu Apr 2 14:38:22 EST 1998
@end ignore
@set EDITION 2.2
@set VERSION 2.2
@set UPDATED 2 April 1998
@set UPDATE-MONTH April 1998
@include manvers.texinfo
@ifinfo
@dircategory Libraries
@direntry
* History: (history). The GNU history library API
@end direntry
@ifinfo
This document describes the GNU History library, a programming tool that
provides a consistent user interface for recalling lines of previously
typed input.
Copyright (C) 1988, 1991, 1993, 1995, 1996, 1998 Free Software Foundation, Inc.
Copyright (C) 1988-2002 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@@ -46,7 +39,7 @@ 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,
except that this permission notice may be stated in a translation approved
by the Foundation.
by the Free Software Foundation.
@end ifinfo
@titlepage
@@ -62,8 +55,8 @@ provides a consistent user interface for recalling lines of previously
typed input.
Published by the Free Software Foundation @*
675 Massachusetts Avenue, @*
Cambridge, MA 02139 USA
59 Temple Place, Suite 330, @*
Boston, MA 02111 USA
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@@ -77,10 +70,10 @@ 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,
except that this permission notice may be stated in a translation approved
by the Foundation.
by the Free Software Foundation.
@vskip 0pt plus 1filll
Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
Copyright @copyright{} 1988-2002 Free Software Foundation, Inc.
@end titlepage
@ifinfo

488
readline/doc/history.0 Normal file
View File

@@ -0,0 +1,488 @@
HISTORY(3) HISTORY(3)
NNAAMMEE
history - GNU History Library
CCOOPPYYRRIIGGHHTT
The GNU History Library is Copyright (C) 1989-2002 by the Free Software
Foundation, Inc.
DDEESSCCRRIIPPTTIIOONN
Many programs read input from the user a line at a time. The GNU His-
tory library is able to keep track of those lines, associate arbitrary
data with each line, and utilize information from previous lines in
composing new ones.
HHIISSTTOORRYY EEXXPPAANNSSIIOONN
The history library supports a history expansion feature that is iden-
tical to the history expansion in bbaasshh.. This section describes what
syntax features are available.
History expansions introduce words from the history list into the input
stream, making it easy to repeat commands, insert the arguments to a
previous command into the current input line, or fix errors in previous
commands quickly.
History expansion is usually performed immediately after a complete
line is read. It takes place in two parts. The first is to determine
which line from the history list to use during substitution. The sec-
ond is to select portions of that line for inclusion into the current
one. The line selected from the history is the _e_v_e_n_t, and the portions
of that line that are acted upon are _w_o_r_d_s. Various _m_o_d_i_f_i_e_r_s are
available to manipulate the selected words. The line is broken into
words in the same fashion as bbaasshh does when reading input, so that sev-
eral words that would otherwise be separated are considered one word
when surrounded by quotes (see the description of hhiissttoorryy__ttookkeenniizzee(())
below). History expansions are introduced by the appearance of the
history expansion character, which is !! by default. Only backslash (\\)
and single quotes can quote the history expansion character.
EEvveenntt DDeessiiggnnaattoorrss
An event designator is a reference to a command line entry in the his-
tory list.
!! Start a history substitution, except when followed by a bbllaannkk,
newline, = or (.
!!_n Refer to command line _n.
!!--_n Refer to the current command line minus _n.
!!!! Refer to the previous command. This is a synonym for `!-1'.
!!_s_t_r_i_n_g
Refer to the most recent command starting with _s_t_r_i_n_g.
!!??_s_t_r_i_n_g[[??]]
Refer to the most recent command containing _s_t_r_i_n_g. The trail-
ing ?? may be omitted if _s_t_r_i_n_g is followed immediately by a new-
line.
^^_s_t_r_i_n_g_1^^_s_t_r_i_n_g_2^^
Quick substitution. Repeat the last command, replacing _s_t_r_i_n_g_1
with _s_t_r_i_n_g_2. Equivalent to ``!!:s/_s_t_r_i_n_g_1/_s_t_r_i_n_g_2/'' (see MMoodd--
iiffiieerrss below).
!!## The entire command line typed so far.
WWoorrdd DDeessiiggnnaattoorrss
Word designators are used to select desired words from the event. A ::
separates the event specification from the word designator. It may be
omitted if the word designator begins with a ^^, $$, **, --, or %%. Words
are numbered from the beginning of the line, with the first word being
denoted by 0 (zero). Words are inserted into the current line sepa-
rated by single spaces.
00 ((zzeerroo))
The zeroth word. For the shell, this is the command word.
_n The _nth word.
^^ The first argument. That is, word 1.
$$ The last argument.
%% The word matched by the most recent `?_s_t_r_i_n_g?' search.
_x--_y A range of words; `-_y' abbreviates `0-_y'.
** All of the words but the zeroth. This is a synonym for `_1_-_$'.
It is not an error to use ** if there is just one word in the
event; the empty string is returned in that case.
xx** Abbreviates _x_-_$.
xx-- Abbreviates _x_-_$ like xx**, but omits the last word.
If a word designator is supplied without an event specification, the
previous command is used as the event.
MMooddiiffiieerrss
After the optional word designator, there may appear a sequence of one
or more of the following modifiers, each preceded by a `:'.
hh Remove a trailing file name component, leaving only the head.
tt Remove all leading file name components, leaving the tail.
rr Remove a trailing suffix of the form _._x_x_x, leaving the basename.
ee Remove all but the trailing suffix.
pp Print the new command but do not execute it.
qq Quote the substituted words, escaping further substitutions.
xx Quote the substituted words as with qq, but break into words at
bbllaannkkss and newlines.
ss//_o_l_d//_n_e_w//
Substitute _n_e_w for the first occurrence of _o_l_d in the event
line. Any delimiter can be used in place of /. The final
delimiter is optional if it is the last character of the event
line. The delimiter may be quoted in _o_l_d and _n_e_w with a single
backslash. If & appears in _n_e_w, it is replaced by _o_l_d. A sin-
gle backslash will quote the &. If _o_l_d is null, it is set to
the last _o_l_d substituted, or, if no previous history substitu-
tions took place, the last _s_t_r_i_n_g in a !!??_s_t_r_i_n_g[[??]] search.
&& Repeat the previous substitution.
gg Cause changes to be applied over the entire event line. This is
used in conjunction with `::ss' (e.g., `::ggss//_o_l_d//_n_e_w//') or `::&&'.
If used with `::ss', any delimiter can be used in place of /, and
the final delimiter is optional if it is the last character of
the event line. An aa may be used as a synonym for gg.
GG Apply the following `ss' modifier once to each word in the event
line.
PPRROOGGRRAAMMMMIINNGG WWIITTHH HHIISSTTOORRYY FFUUNNCCTTIIOONNSS
This section describes how to use the History library in other pro-
grams.
IInnttrroodduuccttiioonn ttoo HHiissttoorryy
The programmer using the History library has available functions for
remembering lines on a history list, associating arbitrary data with a
line, removing lines from the list, searching through the list for a
line containing an arbitrary text string, and referencing any line in
the list directly. In addition, a history _e_x_p_a_n_s_i_o_n function is avail-
able which provides for a consistent user interface across different
programs.
The user using programs written with the History library has the bene-
fit of a consistent user interface with a set of well-known commands
for manipulating the text of previous lines and using that text in new
commands. The basic history manipulation commands are identical to the
history substitution provided by bbaasshh.
If the programmer desires, he can use the Readline library, which
includes some history manipulation by default, and has the added advan-
tage of command line editing.
Before declaring any functions using any functionality the History
library provides in other code, an application writer should include
the file _<_r_e_a_d_l_i_n_e_/_h_i_s_t_o_r_y_._h_> in any file that uses the History
library's features. It supplies extern declarations for all of the
library's public functions and variables, and declares all of the pub-
lic data structures.
HHiissttoorryy SSttoorraaggee
The history list is an array of history entries. A history entry is
declared as follows:
_t_y_p_e_d_e_f _v_o_i_d _* hhiissttddaattaa__tt;;
typedef struct _hist_entry {
char *line;
char *timestamp;
histdata_t data;
} HIST_ENTRY;
The history list itself might therefore be declared as
_H_I_S_T___E_N_T_R_Y _*_* tthhee__hhiissttoorryy__lliisstt;;
The state of the History library is encapsulated into a single struc-
ture:
/*
* A structure used to pass around the current state of the history.
*/
typedef struct _hist_state {
HIST_ENTRY **entries; /* Pointer to the entries themselves. */
int offset; /* The location pointer within this array. */
int length; /* Number of elements within this array. */
int size; /* Number of slots allocated to this array. */
int flags;
} HISTORY_STATE;
If the flags member includes HHSS__SSTTIIFFLLEEDD, the history has been stifled.
HHiissttoorryy FFuunnccttiioonnss
This section describes the calling sequence for the various functions
exported by the GNU History library.
IInniittiiaalliizziinngg HHiissttoorryy aanndd SSttaattee MMaannaaggeemmeenntt
This section describes functions used to initialize and manage the
state of the History library when you want to use the history functions
in your program.
_v_o_i_d uussiinngg__hhiissttoorryy (_v_o_i_d)
Begin a session in which the history functions might be used. This
initializes the interactive variables.
_H_I_S_T_O_R_Y___S_T_A_T_E _* hhiissttoorryy__ggeett__hhiissttoorryy__ssttaattee (_v_o_i_d)
Return a structure describing the current state of the input history.
_v_o_i_d hhiissttoorryy__sseett__hhiissttoorryy__ssttaattee (_H_I_S_T_O_R_Y___S_T_A_T_E _*_s_t_a_t_e)
Set the state of the history list according to _s_t_a_t_e.
HHiissttoorryy LLiisstt MMaannaaggeemmeenntt
These functions manage individual entries on the history list, or set
parameters managing the list itself.
_v_o_i_d aadddd__hhiissttoorryy (_c_o_n_s_t _c_h_a_r _*_s_t_r_i_n_g)
Place _s_t_r_i_n_g at the end of the history list. The associated data field
(if any) is set to NNUULLLL.
_v_o_i_d aadddd__hhiissttoorryy__ttiimmee (_c_o_n_s_t _c_h_a_r _*_s_t_r_i_n_g)
Change the time stamp associated with the most recent history entry to
_s_t_r_i_n_g.
_H_I_S_T___E_N_T_R_Y _* rreemmoovvee__hhiissttoorryy (_i_n_t _w_h_i_c_h)
Remove history entry at offset _w_h_i_c_h from the history. The removed
element is returned so you can free the line, data, and containing
structure.
_h_i_s_t_d_a_t_a___t ffrreeee__hhiissttoorryy__eennttrryy (_H_I_S_T___E_N_T_R_Y _*_h_i_s_t_e_n_t)
Free the history entry _h_i_s_t_e_n_t and any history library private data
associated with it. Returns the application-specific data so the
caller can dispose of it.
_H_I_S_T___E_N_T_R_Y _* rreeppllaaccee__hhiissttoorryy__eennttrryy (_i_n_t _w_h_i_c_h_, _c_o_n_s_t _c_h_a_r _*_l_i_n_e_, _h_i_s_t_-
_d_a_t_a___t _d_a_t_a)
Make the history entry at offset _w_h_i_c_h have _l_i_n_e and _d_a_t_a. This
returns the old entry so the caller can dispose of any application-spe-
cific data. In the case of an invalid _w_h_i_c_h, a NNUULLLL pointer is
returned.
_v_o_i_d cclleeaarr__hhiissttoorryy (_v_o_i_d)
Clear the history list by deleting all the entries.
_v_o_i_d ssttiiffllee__hhiissttoorryy (_i_n_t _m_a_x)
Stifle the history list, remembering only the last _m_a_x entries.
_i_n_t uunnssttiiffllee__hhiissttoorryy (_v_o_i_d)
Stop stifling the history. This returns the previously-set maximum
number of history entries (as set by ssttiiffllee__hhiissttoorryy(())). history was
stifled. The value is positive if the history was stifled, negative if
it wasn't.
_i_n_t hhiissttoorryy__iiss__ssttiifflleedd (_v_o_i_d)
Returns non-zero if the history is stifled, zero if it is not.
IInnffoorrmmaattiioonn AAbboouutt tthhee HHiissttoorryy LLiisstt
These functions return information about the entire history list or
individual list entries.
_H_I_S_T___E_N_T_R_Y _*_* hhiissttoorryy__lliisstt (_v_o_i_d)
Return a NNUULLLL terminated array of _H_I_S_T___E_N_T_R_Y _* which is the current
input history. Element 0 of this list is the beginning of time. If
there is no history, return NNUULLLL.
_i_n_t wwhheerree__hhiissttoorryy (_v_o_i_d)
Returns the offset of the current history element.
_H_I_S_T___E_N_T_R_Y _* ccuurrrreenntt__hhiissttoorryy (_v_o_i_d)
Return the history entry at the current position, as determined by
wwhheerree__hhiissttoorryy(()). If there is no entry there, return a NNUULLLL pointer.
_H_I_S_T___E_N_T_R_Y _* hhiissttoorryy__ggeett (_i_n_t _o_f_f_s_e_t)
Return the history entry at position _o_f_f_s_e_t, starting from hhiiss--
ttoorryy__bbaassee. If there is no entry there, or if _o_f_f_s_e_t is greater than
the history length, return a NNUULLLL pointer.
_t_i_m_e___t hhiissttoorryy__ggeett__ttiimmee (_H_I_S_T___E_N_T_R_Y _*)
Return the time stamp associated with the history entry passed as the
argument.
_i_n_t hhiissttoorryy__ttoottaall__bbyytteess (_v_o_i_d)
Return the number of bytes that the primary history entries are using.
This function returns the sum of the lengths of all the lines in the
history.
MMoovviinngg AArroouunndd tthhee HHiissttoorryy LLiisstt
These functions allow the current index into the history list to be set
or changed.
_i_n_t hhiissttoorryy__sseett__ppooss (_i_n_t _p_o_s)
Set the current history offset to _p_o_s, an absolute index into the list.
Returns 1 on success, 0 if _p_o_s is less than zero or greater than the
number of history entries.
_H_I_S_T___E_N_T_R_Y _* pprreevviioouuss__hhiissttoorryy (_v_o_i_d)
Back up the current history offset to the previous history entry, and
return a pointer to that entry. If there is no previous entry, return
a NNUULLLL pointer.
_H_I_S_T___E_N_T_R_Y _* nneexxtt__hhiissttoorryy (_v_o_i_d)
Move the current history offset forward to the next history entry, and
return the a pointer to that entry. If there is no next entry, return
a NNUULLLL pointer.
SSeeaarrcchhiinngg tthhee HHiissttoorryy LLiisstt
These functions allow searching of the history list for entries con-
taining a specific string. Searching may be performed both forward and
backward from the current history position. The search may be
_a_n_c_h_o_r_e_d, meaning that the string must match at the beginning of the
history entry.
_i_n_t hhiissttoorryy__sseeaarrcchh (_c_o_n_s_t _c_h_a_r _*_s_t_r_i_n_g_, _i_n_t _d_i_r_e_c_t_i_o_n)
Search the history for _s_t_r_i_n_g, starting at the current history offset.
If _d_i_r_e_c_t_i_o_n is less than 0, then the search is through previous
entries, otherwise through subsequent entries. If _s_t_r_i_n_g is found,
then the current history index is set to that history entry, and the
value returned is the offset in the line of the entry where _s_t_r_i_n_g was
found. Otherwise, nothing is changed, and a -1 is returned.
_i_n_t hhiissttoorryy__sseeaarrcchh__pprreeffiixx (_c_o_n_s_t _c_h_a_r _*_s_t_r_i_n_g_, _i_n_t _d_i_r_e_c_t_i_o_n)
Search the history for _s_t_r_i_n_g, starting at the current history offset.
The search is anchored: matching lines must begin with _s_t_r_i_n_g. If
_d_i_r_e_c_t_i_o_n is less than 0, then the search is through previous entries,
otherwise through subsequent entries. If _s_t_r_i_n_g is found, then the
current history index is set to that entry, and the return value is 0.
Otherwise, nothing is changed, and a -1 is returned.
_i_n_t hhiissttoorryy__sseeaarrcchh__ppooss (_c_o_n_s_t _c_h_a_r _*_s_t_r_i_n_g_, _i_n_t _d_i_r_e_c_t_i_o_n_, _i_n_t _p_o_s)
Search for _s_t_r_i_n_g in the history list, starting at _p_o_s, an absolute
index into the list. If _d_i_r_e_c_t_i_o_n is negative, the search proceeds
backward from _p_o_s, otherwise forward. Returns the absolute index of
the history element where _s_t_r_i_n_g was found, or -1 otherwise.
MMaannaaggiinngg tthhee HHiissttoorryy FFiillee
The History library can read the history from and write it to a file.
This section documents the functions for managing a history file.
_i_n_t rreeaadd__hhiissttoorryy (_c_o_n_s_t _c_h_a_r _*_f_i_l_e_n_a_m_e)
Add the contents of _f_i_l_e_n_a_m_e to the history list, a line at a time. If
_f_i_l_e_n_a_m_e is NNUULLLL, then read from _~_/_._h_i_s_t_o_r_y. Returns 0 if successful,
or eerrrrnnoo if not.
_i_n_t rreeaadd__hhiissttoorryy__rraannggee (_c_o_n_s_t _c_h_a_r _*_f_i_l_e_n_a_m_e_, _i_n_t _f_r_o_m_, _i_n_t _t_o)
Read a range of lines from _f_i_l_e_n_a_m_e, adding them to the history list.
Start reading at line _f_r_o_m and end at _t_o. If _f_r_o_m is zero, start at
the beginning. If _t_o is less than _f_r_o_m, then read until the end of the
file. If _f_i_l_e_n_a_m_e is NNUULLLL, then read from _~_/_._h_i_s_t_o_r_y. Returns 0 if
successful, or eerrrrnnoo if not.
_i_n_t wwrriittee__hhiissttoorryy (_c_o_n_s_t _c_h_a_r _*_f_i_l_e_n_a_m_e)
Write the current history to _f_i_l_e_n_a_m_e, overwriting _f_i_l_e_n_a_m_e if neces-
sary. If _f_i_l_e_n_a_m_e is NNUULLLL, then write the history list to _~_/_._h_i_s_t_o_r_y.
Returns 0 on success, or eerrrrnnoo on a read or write error.
_i_n_t aappppeenndd__hhiissttoorryy (_i_n_t _n_e_l_e_m_e_n_t_s_, _c_o_n_s_t _c_h_a_r _*_f_i_l_e_n_a_m_e)
Append the last _n_e_l_e_m_e_n_t_s of the history list to _f_i_l_e_n_a_m_e. If _f_i_l_e_n_a_m_e
is NNUULLLL, then append to _~_/_._h_i_s_t_o_r_y. Returns 0 on success, or eerrrrnnoo on
a read or write error.
_i_n_t hhiissttoorryy__ttrruunnccaattee__ffiillee (_c_o_n_s_t _c_h_a_r _*_f_i_l_e_n_a_m_e_, _i_n_t _n_l_i_n_e_s)
Truncate the history file _f_i_l_e_n_a_m_e, leaving only the last _n_l_i_n_e_s lines.
If _f_i_l_e_n_a_m_e is NNUULLLL, then _~_/_._h_i_s_t_o_r_y is truncated. Returns 0 on suc-
cess, or eerrrrnnoo on failure.
HHiissttoorryy EExxppaannssiioonn
These functions implement history expansion.
_i_n_t hhiissttoorryy__eexxppaanndd (_c_h_a_r _*_s_t_r_i_n_g_, _c_h_a_r _*_*_o_u_t_p_u_t)
Expand _s_t_r_i_n_g, placing the result into _o_u_t_p_u_t, a pointer to a string.
Returns:
0 If no expansions took place (or, if the only change in
the text was the removal of escape characters preceding
the history expansion character);
1 if expansions did take place;
-1 if there was an error in expansion;
2 if the returned line should be displayed, but not exe-
cuted, as with the ::pp modifier.
If an error ocurred in expansion, then _o_u_t_p_u_t contains a descriptive
error message.
_c_h_a_r _* ggeett__hhiissttoorryy__eevveenntt (_c_o_n_s_t _c_h_a_r _*_s_t_r_i_n_g_, _i_n_t _*_c_i_n_d_e_x_, _i_n_t _q_c_h_a_r)
Returns the text of the history event beginning at _s_t_r_i_n_g + _*_c_i_n_d_e_x.
_*_c_i_n_d_e_x is modified to point to after the event specifier. At function
entry, _c_i_n_d_e_x points to the index into _s_t_r_i_n_g where the history event
specification begins. _q_c_h_a_r is a character that is allowed to end the
event specification in addition to the ``normal'' terminating charac-
ters.
_c_h_a_r _*_* hhiissttoorryy__ttookkeenniizzee (_c_o_n_s_t _c_h_a_r _*_s_t_r_i_n_g)
Return an array of tokens parsed out of _s_t_r_i_n_g, much as the shell
might. The tokens are split on the characters in the hhiiss--
ttoorryy__wwoorrdd__ddeelliimmiitteerrss variable, and shell quoting conventions are
obeyed.
_c_h_a_r _* hhiissttoorryy__aarrgg__eexxttrraacctt (_i_n_t _f_i_r_s_t_, _i_n_t _l_a_s_t_, _c_o_n_s_t _c_h_a_r _*_s_t_r_i_n_g)
Extract a string segment consisting of the _f_i_r_s_t through _l_a_s_t arguments
present in _s_t_r_i_n_g. Arguments are split using hhiissttoorryy__ttookkeenniizzee(()).
HHiissttoorryy VVaarriiaabblleess
This section describes the externally-visible variables exported by the
GNU History Library.
_i_n_t hhiissttoorryy__bbaassee
The logical offset of the first entry in the history list.
_i_n_t hhiissttoorryy__lleennggtthh
The number of entries currently stored in the history list.
_i_n_t hhiissttoorryy__mmaaxx__eennttrriieess
The maximum number of history entries. This must be changed using ssttii--
ffllee__hhiissttoorryy(()).
_i_n_t hhiissttoorryy__wwrriittee__ttiimmeessttaammppss
If non-zero, timestamps are written to the history file, so they can be
preserved between sessions. The default value is 0, meaning that
timestamps are not saved.
_c_h_a_r hhiissttoorryy__eexxppaannssiioonn__cchhaarr
The character that introduces a history event. The default is !!. Set-
ting this to 0 inhibits history expansion.
_c_h_a_r hhiissttoorryy__ssuubbsstt__cchhaarr
The character that invokes word substitution if found at the start of a
line. The default is ^^.
_c_h_a_r hhiissttoorryy__ccoommmmeenntt__cchhaarr
During tokenization, if this character is seen as the first character
of a word, then it and all subsequent characters up to a newline are
ignored, suppressing history expansion for the remainder of the line.
This is disabled by default.
_c_h_a_r _* hhiissttoorryy__wwoorrdd__ddeelliimmiitteerrss
The characters that separate tokens for hhiissttoorryy__ttookkeenniizzee(()). The
default value is "" \\tt\\nn(())<<>>;;&&||"".
_c_h_a_r _* hhiissttoorryy__nnoo__eexxppaanndd__cchhaarrss
The list of characters which inhibit history expansion if found immedi-
ately following hhiissttoorryy__eexxppaannssiioonn__cchhaarr. The default is space, tab,
newline, \\rr, and ==.
_c_h_a_r _* hhiissttoorryy__sseeaarrcchh__ddeelliimmiitteerr__cchhaarrss
The list of additional characters which can delimit a history search
string, in addition to space, tab, _: and _? in the case of a substring
search. The default is empty.
_i_n_t hhiissttoorryy__qquuootteess__iinnhhiibbiitt__eexxppaannssiioonn
If non-zero, single-quoted words are not scanned for the history expan-
sion character. The default value is 0.
_r_l___l_i_n_e_b_u_f___f_u_n_c___t _* hhiissttoorryy__iinnhhiibbiitt__eexxppaannssiioonn__ffuunnccttiioonn
This should be set to the address of a function that takes two argu-
ments: a cchhaarr ** (_s_t_r_i_n_g) and an iinntt index into that string (_i). It
should return a non-zero value if the history expansion starting at
_s_t_r_i_n_g_[_i_] should not be performed; zero if the expansion should be
done. It is intended for use by applications like bbaasshh that use the
history expansion character for additional purposes. By default, this
variable is set to NNUULLLL.
FFIILLEESS
_~_/_._h_i_s_t_o_r_y
Default filename for reading and writing saved history
SSEEEE AALLSSOO
_T_h_e _G_n_u _R_e_a_d_l_i_n_e _L_i_b_r_a_r_y, Brian Fox and Chet Ramey
_T_h_e _G_n_u _H_i_s_t_o_r_y _L_i_b_r_a_r_y, Brian Fox and Chet Ramey
_b_a_s_h(1)
_r_e_a_d_l_i_n_e(3)
AAUUTTHHOORRSS
Brian Fox, Free Software Foundation
bfox@gnu.org
Chet Ramey, Case Western Reserve University
chet@ins.CWRU.Edu
BBUUGG RREEPPOORRTTSS
If you find a bug in the hhiissttoorryy library, 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 hhiissttoorryy library that you have.
Once you have determined that a bug actually exists, mail a bug report
to _b_u_g_-_r_e_a_d_l_i_n_e@_g_n_u_._o_r_g. If you have a fix, you are welcome to mail
that as well! Suggestions and `philosophical' bug reports may be
mailed to _b_u_g_-_r_e_a_d_l_i_n_e@_g_n_u_._o_r_g or posted to the Usenet newsgroup
ggnnuu..bbaasshh..bbuugg.
Comments and bug reports concerning this manual page should be directed
to _c_h_e_t_@_i_n_s_._C_W_R_U_._E_d_u.
GNU History 5.0 2003 July 31 HISTORY(3)

663
readline/doc/history.3 Normal file
View File

@@ -0,0 +1,663 @@
.\"
.\" MAN PAGE COMMENTS to
.\"
.\" Chet Ramey
.\" Information Network Services
.\" Case Western Reserve University
.\" chet@ins.CWRU.Edu
.\"
.\" Last Change: Thu Jul 31 08:46:08 EDT 2003
.\"
.TH HISTORY 3 "2003 July 31" "GNU History 5.0"
.\"
.\" 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
..
.ds lp \fR\|(\fP
.ds rp \fR\|)\fP
.\" FnN return-value fun-name N arguments
.de Fn1
\fI\\$1\fP \fB\\$2\fP \\*(lp\fI\\$3\fP\\*(rp
.br
..
.de Fn2
.if t \fI\\$1\fP \fB\\$2\fP \\*(lp\fI\\$3,\|\\$4\fP\\*(rp
.if n \fI\\$1\fP \fB\\$2\fP \\*(lp\fI\\$3, \\$4\fP\\*(rp
.br
..
.de Fn3
.if t \fI\\$1\fP \fB\\$2\fP \\*(lp\fI\\$3,\|\\$4,\|\\$5\fP\|\\*(rp
.if n \fI\\$1\fP \fB\\$2\fP \\*(lp\fI\\$3, \\$4, \\$5\fP\\*(rp
.br
..
.de Vb
\fI\\$1\fP \fB\\$2\fP
.br
..
.SH NAME
history \- GNU History Library
.SH COPYRIGHT
.if t The GNU History Library is Copyright \(co 1989-2002 by the Free Software Foundation, Inc.
.if n The GNU History Library is Copyright (C) 1989-2002 by the Free Software Foundation, Inc.
.SH DESCRIPTION
Many programs read input from the user a line at a time. The GNU
History library is able to keep track of those lines, associate arbitrary
data with each line, and utilize information from previous lines in
composing new ones.
.PP
.SH "HISTORY EXPANSION"
.PP
The history library supports a history expansion feature that
is identical to the history expansion in
.BR bash.
This section describes what syntax features are available.
.PP
History expansions introduce words from the history list into
the input stream, making it easy to repeat commands, insert the
arguments to a previous command into the current input line, or
fix errors in previous commands quickly.
.PP
History expansion is usually performed immediately after a complete line
is read.
It takes place in two parts.
The first is to determine which line from the history list
to use during substitution.
The second is to select portions of that line for inclusion into
the current one.
The line selected from the history is the \fIevent\fP,
and the portions of that line that are acted upon are \fIwords\fP.
Various \fImodifiers\fP are available to manipulate the selected words.
The line is broken into words in the same fashion as \fBbash\fP
does when reading input,
so that several words that would otherwise be separated
are considered one word when surrounded by quotes (see the
description of \fBhistory_tokenize()\fP below).
History expansions are introduced by the appearance of the
history expansion character, which is \^\fB!\fP\^ by default.
Only backslash (\^\fB\e\fP\^) and single quotes can quote
the history expansion character.
.SS Event Designators
.PP
An event designator is a reference to a command line entry in the
history list.
.PP
.PD 0
.TP
.B !
Start a history substitution, except when followed by a
.BR blank ,
newline, = or (.
.TP
.B !\fIn\fR
Refer to command line
.IR n .
.TP
.B !\-\fIn\fR
Refer to the current command line minus
.IR n .
.TP
.B !!
Refer to the previous command. This is a synonym for `!\-1'.
.TP
.B !\fIstring\fR
Refer to the most recent command starting with
.IR string .
.TP
.B !?\fIstring\fR\fB[?]\fR
Refer to the most recent command containing
.IR string .
The trailing \fB?\fP may be omitted if
.I string
is followed immediately by a newline.
.TP
.B \d\s+2^\s-2\u\fIstring1\fP\d\s+2^\s-2\u\fIstring2\fP\d\s+2^\s-2\u
Quick substitution. Repeat the last command, replacing
.I string1
with
.IR string2 .
Equivalent to
``!!:s/\fIstring1\fP/\fIstring2\fP/''
(see \fBModifiers\fP below).
.TP
.B !#
The entire command line typed so far.
.PD
.SS Word Designators
.PP
Word designators are used to select desired words from the event.
A
.B :
separates the event specification from the word designator.
It may be omitted if the word designator begins with a
.BR ^ ,
.BR $ ,
.BR * ,
.BR \- ,
or
.BR % .
Words are numbered from the beginning of the line,
with the first word being denoted by 0 (zero).
Words are inserted into the current line separated by single spaces.
.PP
.PD 0
.TP
.B 0 (zero)
The zeroth word. For the shell, this is the command
word.
.TP
.I n
The \fIn\fRth word.
.TP
.B ^
The first argument. That is, word 1.
.TP
.B $
The last argument.
.TP
.B %
The word matched by the most recent `?\fIstring\fR?' search.
.TP
.I x\fB\-\fPy
A range of words; `\-\fIy\fR' abbreviates `0\-\fIy\fR'.
.TP
.B *
All of the words but the zeroth. This is a synonym
for `\fI1\-$\fP'. It is not an error to use
.B *
if there is just one
word in the event; the empty string is returned in that case.
.TP
.B x*
Abbreviates \fIx\-$\fP.
.TP
.B x\-
Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word.
.PD
.PP
If a word designator is supplied without an event specification, the
previous command is used as the event.
.SS Modifiers
.PP
After the optional word designator, there may appear a sequence of
one or more of the following modifiers, each preceded by a `:'.
.PP
.PD 0
.PP
.TP
.B h
Remove a trailing file name component, leaving only the head.
.TP
.B t
Remove all leading file name components, leaving the tail.
.TP
.B r
Remove a trailing suffix of the form \fI.xxx\fP, leaving the
basename.
.TP
.B e
Remove all but the trailing suffix.
.TP
.B p
Print the new command but do not execute it.
.TP
.B q
Quote the substituted words, escaping further substitutions.
.TP
.B x
Quote the substituted words as with
.BR q ,
but break into words at
.B blanks
and newlines.
.TP
.B s/\fIold\fP/\fInew\fP/
Substitute
.I new
for the first occurrence of
.I old
in the event line. Any delimiter can be used in place of /. The
final delimiter is optional if it is the last character of the
event line. The delimiter may be quoted in
.I old
and
.I new
with a single backslash. If & appears in
.IR new ,
it is replaced by
.IR old .
A single backslash will quote the &. If
.I old
is null, it is set to the last
.I old
substituted, or, if no previous history substitutions took place,
the last
.I string
in a
.B !?\fIstring\fR\fB[?]\fR
search.
.TP
.B &
Repeat the previous substitution.
.TP
.B g
Cause changes to be applied over the entire event line. This is
used in conjunction with `\fB:s\fP' (e.g., `\fB:gs/\fIold\fP/\fInew\fP/\fR')
or `\fB:&\fP'. If used with
`\fB:s\fP', any delimiter can be used
in place of /, and the final delimiter is optional
if it is the last character of the event line.
An \fBa\fP may be used as a synonym for \fBg\fP.
.TP
.B G
Apply the following `\fBs\fP' modifier once to each word in the event line.
.PD
.SH "PROGRAMMING WITH HISTORY FUNCTIONS"
This section describes how to use the History library in other programs.
.SS Introduction to History
.PP
The programmer using the History library has available functions
for remembering lines on a history list, associating arbitrary data
with a line, removing lines from the list, searching through the list
for a line containing an arbitrary text string, and referencing any line
in the list directly. In addition, a history \fIexpansion\fP function
is available which provides for a consistent user interface across
different programs.
.PP
The user using programs written with the History library has the
benefit of a consistent user interface with a set of well-known
commands for manipulating the text of previous lines and using that text
in new commands. The basic history manipulation commands are
identical to
the history substitution provided by \fBbash\fP.
.PP
If the programmer desires, he can use the Readline library, which
includes some history manipulation by default, and has the added
advantage of command line editing.
.PP
Before declaring any functions using any functionality the History
library provides in other code, an application writer should include
the file
.FN <readline/history.h>
in any file that uses the
History library's features. It supplies extern declarations for all
of the library's public functions and variables, and declares all of
the public data structures.
.SS History Storage
.PP
The history list is an array of history entries. A history entry is
declared as follows:
.PP
.Vb "typedef void *" histdata_t;
.PP
.nf
typedef struct _hist_entry {
char *line;
char *timestamp;
histdata_t data;
} HIST_ENTRY;
.fi
.PP
The history list itself might therefore be declared as
.PP
.Vb "HIST_ENTRY **" the_history_list;
.PP
The state of the History library is encapsulated into a single structure:
.PP
.nf
/*
* A structure used to pass around the current state of the history.
*/
typedef struct _hist_state {
HIST_ENTRY **entries; /* Pointer to the entries themselves. */
int offset; /* The location pointer within this array. */
int length; /* Number of elements within this array. */
int size; /* Number of slots allocated to this array. */
int flags;
} HISTORY_STATE;
.fi
.PP
If the flags member includes \fBHS_STIFLED\fP, the history has been
stifled.
.SH "History Functions"
.PP
This section describes the calling sequence for the various functions
exported by the GNU History library.
.SS Initializing History and State Management
This section describes functions used to initialize and manage
the state of the History library when you want to use the history
functions in your program.
.Fn1 void using_history void
Begin a session in which the history functions might be used. This
initializes the interactive variables.
.Fn1 "HISTORY_STATE *" history_get_history_state void
Return a structure describing the current state of the input history.
.Fn1 void history_set_history_state "HISTORY_STATE *state"
Set the state of the history list according to \fIstate\fP.
.SS History List Management
These functions manage individual entries on the history list, or set
parameters managing the list itself.
.Fn1 void add_history "const char *string"
Place \fIstring\fP at the end of the history list. The associated data
field (if any) is set to \fBNULL\fP.
.Fn1 void add_history_time "const char *string"
Change the time stamp associated with the most recent history entry to
\fIstring\fP.
.Fn1 "HIST_ENTRY *" remove_history "int which"
Remove history entry at offset \fIwhich\fP from the history. The
removed element is returned so you can free the line, data,
and containing structure.
.Fn1 "histdata_t" free_history_entry "HIST_ENTRY *histent"
Free the history entry \fIhistent\fP and any history library private
data associated with it. Returns the application-specific data
so the caller can dispose of it.
.Fn3 "HIST_ENTRY *" replace_history_entry "int which" "const char *line" "histdata_t data"
Make the history entry at offset \fIwhich\fP have \fIline\fP and \fIdata\fP.
This returns the old entry so the caller can dispose of any
application-specific data. In the case
of an invalid \fIwhich\fP, a \fBNULL\fP pointer is returned.
.Fn1 void clear_history "void"
Clear the history list by deleting all the entries.
.Fn1 void stifle_history "int max"
Stifle the history list, remembering only the last \fImax\fP entries.
.Fn1 int unstifle_history "void"
Stop stifling the history. This returns the previously-set
maximum number of history entries (as set by \fBstifle_history()\fP).
history was stifled. The value is positive if the history was
stifled, negative if it wasn't.
.Fn1 int history_is_stifled "void"
Returns non-zero if the history is stifled, zero if it is not.
.SS Information About the History List
These functions return information about the entire history list or
individual list entries.
.Fn1 "HIST_ENTRY **" history_list "void"
Return a \fBNULL\fP terminated array of \fIHIST_ENTRY *\fP which is the
current input history. Element 0 of this list is the beginning of time.
If there is no history, return \fBNULL\fP.
.Fn1 int where_history "void"
Returns the offset of the current history element.
.Fn1 "HIST_ENTRY *" current_history "void"
Return the history entry at the current position, as determined by
\fBwhere_history()\fP. If there is no entry there, return a \fBNULL\fP
pointer.
.Fn1 "HIST_ENTRY *" history_get "int offset"
Return the history entry at position \fIoffset\fP, starting from
\fBhistory_base\fP.
If there is no entry there, or if \fIoffset\fP
is greater than the history length, return a \fBNULL\fP pointer.
.Fn1 "time_t" history_get_time "HIST_ENTRY *"
Return the time stamp associated with the history entry passed as the argument.
.Fn1 int history_total_bytes "void"
Return the number of bytes that the primary history entries are using.
This function returns the sum of the lengths of all the lines in the
history.
.SS Moving Around the History List
These functions allow the current index into the history list to be
set or changed.
.Fn1 int history_set_pos "int pos"
Set the current history offset to \fIpos\fP, an absolute index
into the list.
Returns 1 on success, 0 if \fIpos\fP is less than zero or greater
than the number of history entries.
.Fn1 "HIST_ENTRY *" previous_history "void"
Back up the current history offset to the previous history entry, and
return a pointer to that entry. If there is no previous entry, return
a \fBNULL\fP pointer.
.Fn1 "HIST_ENTRY *" next_history "void"
Move the current history offset forward to the next history entry, and
return the a pointer to that entry. If there is no next entry, return
a \fBNULL\fP pointer.
.SS Searching the History List
These functions allow searching of the history list for entries containing
a specific string. Searching may be performed both forward and backward
from the current history position. The search may be \fIanchored\fP,
meaning that the string must match at the beginning of the history entry.
.Fn2 int history_search "const char *string" "int direction"
Search the history for \fIstring\fP, starting at the current history offset.
If \fIdirection\fP is less than 0, then the search is through
previous entries, otherwise through subsequent entries.
If \fIstring\fP is found, then
the current history index is set to that history entry, and the value
returned is the offset in the line of the entry where
\fIstring\fP was found. Otherwise, nothing is changed, and a -1 is
returned.
.Fn2 int history_search_prefix "const char *string" "int direction"
Search the history for \fIstring\fP, starting at the current history
offset. The search is anchored: matching lines must begin with
\fIstring\fP. If \fIdirection\fP is less than 0, then the search is
through previous entries, otherwise through subsequent entries.
If \fIstring\fP is found, then the
current history index is set to that entry, and the return value is 0.
Otherwise, nothing is changed, and a -1 is returned.
.Fn3 int history_search_pos "const char *string" "int direction" "int pos"
Search for \fIstring\fP in the history list, starting at \fIpos\fP, an
absolute index into the list. If \fIdirection\fP is negative, the search
proceeds backward from \fIpos\fP, otherwise forward. Returns the absolute
index of the history element where \fIstring\fP was found, or -1 otherwise.
.SS Managing the History File
The History library can read the history from and write it to a file.
This section documents the functions for managing a history file.
.Fn1 int read_history "const char *filename"
Add the contents of \fIfilename\fP to the history list, a line at a time.
If \fIfilename\fP is \fBNULL\fP, then read from \fI~/.history\fP.
Returns 0 if successful, or \fBerrno\fP if not.
.Fn3 int read_history_range "const char *filename" "int from" "int to"
Read a range of lines from \fIfilename\fP, adding them to the history list.
Start reading at line \fIfrom\fP and end at \fIto\fP.
If \fIfrom\fP is zero, start at the beginning. If \fIto\fP is less than
\fIfrom\fP, then read until the end of the file. If \fIfilename\fP is
\fBNULL\fP, then read from \fI~/.history\fP. Returns 0 if successful,
or \fBerrno\fP if not.
.Fn1 int write_history "const char *filename"
Write the current history to \fIfilename\fP, overwriting \fIfilename\fP
if necessary.
If \fIfilename\fP is \fBNULL\fP, then write the history list to \fI~/.history\fP.
Returns 0 on success, or \fBerrno\fP on a read or write error.
.Fn2 int append_history "int nelements" "const char *filename"
Append the last \fInelements\fP of the history list to \fIfilename\fP.
If \fIfilename\fP is \fBNULL\fP, then append to \fI~/.history\fP.
Returns 0 on success, or \fBerrno\fP on a read or write error.
.Fn2 int history_truncate_file "const char *filename" "int nlines"
Truncate the history file \fIfilename\fP, leaving only the last
\fInlines\fP lines.
If \fIfilename\fP is \fBNULL\fP, then \fI~/.history\fP is truncated.
Returns 0 on success, or \fBerrno\fP on failure.
.SS History Expansion
These functions implement history expansion.
.Fn2 int history_expand "char *string" "char **output"
Expand \fIstring\fP, placing the result into \fIoutput\fP, a pointer
to a string. Returns:
.RS
.PD 0
.TP
0
If no expansions took place (or, if the only change in
the text was the removal of escape characters preceding the history expansion
character);
.TP
1
if expansions did take place;
.TP
-1
if there was an error in expansion;
.TP
2
if the returned line should be displayed, but not executed,
as with the \fB:p\fP modifier.
.PD
.RE
If an error ocurred in expansion, then \fIoutput\fP contains a descriptive
error message.
.Fn3 "char *" get_history_event "const char *string" "int *cindex" "int qchar"
Returns the text of the history event beginning at \fIstring\fP +
\fI*cindex\fP. \fI*cindex\fP is modified to point to after the event
specifier. At function entry, \fIcindex\fP points to the index into
\fIstring\fP where the history event specification begins. \fIqchar\fP
is a character that is allowed to end the event specification in addition
to the ``normal'' terminating characters.
.Fn1 "char **" history_tokenize "const char *string"
Return an array of tokens parsed out of \fIstring\fP, much as the
shell might.
The tokens are split on the characters in the
\fBhistory_word_delimiters\fP variable,
and shell quoting conventions are obeyed.
.Fn3 "char *" history_arg_extract "int first" "int last" "const char *string"
Extract a string segment consisting of the \fIfirst\fP through \fIlast\fP
arguments present in \fIstring\fP. Arguments are split using
\fBhistory_tokenize()\fP.
.SS History Variables
This section describes the externally-visible variables exported by
the GNU History Library.
.Vb int history_base
The logical offset of the first entry in the history list.
.Vb int history_length
The number of entries currently stored in the history list.
.Vb int history_max_entries
The maximum number of history entries. This must be changed using
\fBstifle_history()\fP.
.Vb int history_write_timestamps
If non-zero, timestamps are written to the history file, so they can be
preserved between sessions. The default value is 0, meaning that
timestamps are not saved.
.Vb char history_expansion_char
The character that introduces a history event. The default is \fB!\fP.
Setting this to 0 inhibits history expansion.
.Vb char history_subst_char
The character that invokes word substitution if found at the start of
a line. The default is \fB^\fP.
.Vb char history_comment_char
During tokenization, if this character is seen as the first character
of a word, then it and all subsequent characters up to a newline are
ignored, suppressing history expansion for the remainder of the line.
This is disabled by default.
.Vb "char *" history_word_delimiters
The characters that separate tokens for \fBhistory_tokenize()\fP.
The default value is \fB"\ \et\en()<>;&|"\fP.
.Vb "char *" history_no_expand_chars
The list of characters which inhibit history expansion if found immediately
following \fBhistory_expansion_char\fP. The default is space, tab, newline,
\fB\er\fP, and \fB=\fP.
.Vb "char *" history_search_delimiter_chars
The list of additional characters which can delimit a history search
string, in addition to space, tab, \fI:\fP and \fI?\fP in the case of
a substring search. The default is empty.
.Vb int history_quotes_inhibit_expansion
If non-zero, single-quoted words are not scanned for the history expansion
character. The default value is 0.
.Vb "rl_linebuf_func_t *" history_inhibit_expansion_function
This should be set to the address of a function that takes two arguments:
a \fBchar *\fP (\fIstring\fP)
and an \fBint\fP index into that string (\fIi\fP).
It should return a non-zero value if the history expansion starting at
\fIstring[i]\fP should not be performed; zero if the expansion should
be done.
It is intended for use by applications like \fBbash\fP that use the history
expansion character for additional purposes.
By default, this variable is set to \fBNULL\fP.
.SH FILES
.PD 0
.TP
.FN ~/.history
Default filename for reading and writing saved history
.PD
.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)
.TP
\fIreadline\fP(3)
.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 the
.B history
library, 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 history
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 .

BIN
readline/doc/history.dvi Normal file

Binary file not shown.

2270
readline/doc/history.html Normal file

File diff suppressed because it is too large Load Diff

1352
readline/doc/history.info Normal file

File diff suppressed because it is too large Load Diff

BIN
readline/doc/history.pdf Normal file

Binary file not shown.

4808
readline/doc/history.ps Normal file

File diff suppressed because it is too large Load Diff

104
readline/doc/history.texi Normal file
View File

@@ -0,0 +1,104 @@
\input texinfo @c -*-texinfo-*-
@c %**start of header (This is for running Texinfo on a region.)
@setfilename history.info
@settitle GNU History Library
@c %**end of header (This is for running Texinfo on a region.)
@setchapternewpage odd
@include version.texi
@copying
This document describes the GNU History library
(version @value{VERSION}, @value{UPDATED}),
a programming tool that provides a consistent user interface for
recalling lines of previously typed input.
Copyright @copyright{} 1988-2004 Free Software Foundation, Inc.
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.
@quotation
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with the Front-Cover texts being ``A GNU Manual,''
and with the Back-Cover Texts as in (a) below. A copy of the license is
included in the section entitled ``GNU Free Documentation License.''
(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
this GNU Manual, like GNU software. Copies published by the Free
Software Foundation raise funds for GNU development.''
@end quotation
@end copying
@dircategory Libraries
@direntry
* History: (history). The GNU history library API.
@end direntry
@titlepage
@title GNU History Library
@subtitle Edition @value{EDITION}, for @code{History Library} Version @value{VERSION}.
@subtitle @value{UPDATED-MONTH}
@author Chet Ramey, Case Western Reserve University
@author Brian Fox, Free Software Foundation
@page
@vskip 0pt plus 1filll
@insertcopying
@sp 1
Published by the Free Software Foundation @*
59 Temple Place, Suite 330, @*
Boston, MA 02111-1307 @*
USA @*
@end titlepage
@contents
@ifnottex
@node Top
@top GNU History Library
This document describes the GNU History library, a programming tool that
provides a consistent user interface for recalling lines of previously
typed input.
@menu
* Using History Interactively:: GNU History User's Manual.
* Programming with GNU History:: GNU History Programmer's Manual.
* Copying This Manual:: Copying This Manual.
* Concept Index:: Index of concepts described in this manual.
* Function and Variable Index:: Index of externally visible functions
and variables.
@end menu
@end ifnottex
@syncodeindex fn vr
@include hsuser.texi
@include hstech.texi
@node Copying This Manual
@appendix Copying This Manual
@menu
* GNU Free Documentation License:: License for copying this manual.
@end menu
@include fdl.texi
@node Concept Index
@appendix Concept Index
@printindex cp
@node Function and Variable Index
@appendix Function and Variable Index
@printindex vr
@bye

829
readline/doc/history_3.ps Normal file
View File

@@ -0,0 +1,829 @@
%!PS-Adobe-3.0
%%Creator: groff version 1.18.1
%%CreationDate: Mon Sep 22 09:15:44 2003
%%DocumentNeededResources: font Times-Roman
%%+ font Times-Bold
%%+ font Times-Italic
%%DocumentSuppliedResources: procset grops 1.18 1
%%Pages: 7
%%PageOrder: Ascend
%%Orientation: Portrait
%%EndComments
%%BeginProlog
%%BeginResource: procset grops 1.18 1
/setpacking where{
pop
currentpacking
true setpacking
}if
/grops 120 dict dup begin
/SC 32 def
/A/show load def
/B{0 SC 3 -1 roll widthshow}bind def
/C{0 exch ashow}bind def
/D{0 exch 0 SC 5 2 roll awidthshow}bind def
/E{0 rmoveto show}bind def
/F{0 rmoveto 0 SC 3 -1 roll widthshow}bind def
/G{0 rmoveto 0 exch ashow}bind def
/H{0 rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
/I{0 exch rmoveto show}bind def
/J{0 exch rmoveto 0 SC 3 -1 roll widthshow}bind def
/K{0 exch rmoveto 0 exch ashow}bind def
/L{0 exch rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
/M{rmoveto show}bind def
/N{rmoveto 0 SC 3 -1 roll widthshow}bind def
/O{rmoveto 0 exch ashow}bind def
/P{rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
/Q{moveto show}bind def
/R{moveto 0 SC 3 -1 roll widthshow}bind def
/S{moveto 0 exch ashow}bind def
/T{moveto 0 exch 0 SC 5 2 roll awidthshow}bind def
/SF{
findfont exch
[exch dup 0 exch 0 exch neg 0 0]makefont
dup setfont
[exch/setfont cvx]cvx bind def
}bind def
/MF{
findfont
[5 2 roll
0 3 1 roll
neg 0 0]makefont
dup setfont
[exch/setfont cvx]cvx bind def
}bind def
/level0 0 def
/RES 0 def
/PL 0 def
/LS 0 def
/MANUAL{
statusdict begin/manualfeed true store end
}bind def
/PLG{
gsave newpath clippath pathbbox grestore
exch pop add exch pop
}bind def
/BP{
/level0 save def
1 setlinecap
1 setlinejoin
72 RES div dup scale
LS{
90 rotate
}{
0 PL translate
}ifelse
1 -1 scale
}bind def
/EP{
level0 restore
showpage
}bind def
/DA{
newpath arcn stroke
}bind def
/SN{
transform
.25 sub exch .25 sub exch
round .25 add exch round .25 add exch
itransform
}bind def
/DL{
SN
moveto
SN
lineto stroke
}bind def
/DC{
newpath 0 360 arc closepath
}bind def
/TM matrix def
/DE{
TM currentmatrix pop
translate scale newpath 0 0 .5 0 360 arc closepath
TM setmatrix
}bind def
/RC/rcurveto load def
/RL/rlineto load def
/ST/stroke load def
/MT/moveto load def
/CL/closepath load def
/Fr{
setrgbcolor fill
}bind def
/Fk{
setcmykcolor fill
}bind def
/Fg{
setgray fill
}bind def
/FL/fill load def
/LW/setlinewidth load def
/Cr/setrgbcolor load def
/Ck/setcmykcolor load def
/Cg/setgray load def
/RE{
findfont
dup maxlength 1 index/FontName known not{1 add}if dict begin
{
1 index/FID ne{def}{pop pop}ifelse
}forall
/Encoding exch def
dup/FontName exch def
currentdict end definefont pop
}bind def
/DEFS 0 def
/EBEGIN{
moveto
DEFS begin
}bind def
/EEND/end load def
/CNT 0 def
/level1 0 def
/PBEGIN{
/level1 save def
translate
div 3 1 roll div exch scale
neg exch neg exch translate
0 setgray
0 setlinecap
1 setlinewidth
0 setlinejoin
10 setmiterlimit
[]0 setdash
/setstrokeadjust where{
pop
false setstrokeadjust
}if
/setoverprint where{
pop
false setoverprint
}if
newpath
/CNT countdictstack def
userdict begin
/showpage{}def
}bind def
/PEND{
clear
countdictstack CNT sub{end}repeat
level1 restore
}bind def
end def
/setpacking where{
pop
setpacking
}if
%%EndResource
%%IncludeResource: font Times-Roman
%%IncludeResource: font Times-Bold
%%IncludeResource: font Times-Italic
grops begin/DEFS 1 dict def DEFS begin/u{.001 mul}bind def end/RES 72
def/PL 792 def/LS false def/ENC0[/asciicircum/asciitilde/Scaron/Zcaron
/scaron/zcaron/Ydieresis/trademark/quotesingle/Euro/.notdef/.notdef
/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
/.notdef/.notdef/space/exclam/quotedbl/numbersign/dollar/percent
/ampersand/quoteright/parenleft/parenright/asterisk/plus/comma/hyphen
/period/slash/zero/one/two/three/four/five/six/seven/eight/nine/colon
/semicolon/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N/O
/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright/circumflex
/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y
/z/braceleft/bar/braceright/tilde/.notdef/quotesinglbase/guillemotleft
/guillemotright/bullet/florin/fraction/perthousand/dagger/daggerdbl
/endash/emdash/ff/fi/fl/ffi/ffl/dotlessi/dotlessj/grave/hungarumlaut
/dotaccent/breve/caron/ring/ogonek/quotedblleft/quotedblright/oe/lslash
/quotedblbase/OE/Lslash/.notdef/exclamdown/cent/sterling/currency/yen
/brokenbar/section/dieresis/copyright/ordfeminine/guilsinglleft
/logicalnot/minus/registered/macron/degree/plusminus/twosuperior
/threesuperior/acute/mu/paragraph/periodcentered/cedilla/onesuperior
/ordmasculine/guilsinglright/onequarter/onehalf/threequarters
/questiondown/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE
/Ccedilla/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex
/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis
/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn
/germandbls/agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla
/egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis
/eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/divide/oslash
/ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis]def
/Times-Italic@0 ENC0/Times-Italic RE/Times-Bold@0 ENC0/Times-Bold RE
/Times-Roman@0 ENC0/Times-Roman RE
%%EndProlog
%%Page: 1 1
%%BeginPageSetup
BP
%%EndPageSetup
/F0 10/Times-Roman@0 SF(HIST)72 48 Q(OR)-.18 E 357.18(Y\(3\) HIST)-.65 F
(OR)-.18 E(Y\(3\))-.65 E/F1 10.95/Times-Bold@0 SF -.219(NA)72 84 S(ME)
.219 E F0(history \255 GNU History Library)108 96 Q F1(COPYRIGHT)72
112.8 Q F0(The GNU History Library is Cop)108 124.8 Q
(yright \251 1989-2002 by the Free Softw)-.1 E(are F)-.1 E
(oundation, Inc.)-.15 E F1(DESCRIPTION)72 141.6 Q F0(Man)108 153.6 Q
2.81(yp)-.15 G .31(rograms read input from the user a line at a time.)
-2.81 F .309(The GNU History library is able to k)5.309 F .309
(eep track of)-.1 F .024(those lines, associate arbitrary data with eac\
h line, and utilize information from pre)108 165.6 R .024
(vious lines in composing)-.25 F(ne)108 177.6 Q 2.5(wo)-.25 G(nes.)-2.5
E F1(HIST)72 199.2 Q(OR)-.197 E 2.738(YE)-.383 G(XP)-2.738 E(ANSION)-.81
E F0 .823(The history library supports a history e)108 211.2 R .822
(xpansion feature that is identical to the history e)-.15 F .822
(xpansion in)-.15 F/F2 10/Times-Bold@0 SF(bash.)3.322 E F0
(This section describes what syntax features are a)108 223.2 Q -.25(va)
-.2 G(ilable.).25 E 1.305(History e)108 240 R 1.305
(xpansions introduce w)-.15 F 1.306(ords from the history list into the\
input stream, making it easy to repeat)-.1 F .21
(commands, insert the ar)108 252 R .21(guments to a pre)-.18 F .209
(vious command into the current input line, or \214x errors in pre)-.25
F(vious)-.25 E(commands quickly)108 264 Q(.)-.65 E 1.296(History e)108
280.8 R 1.297(xpansion is usually performed immediately after a complet\
e line is read.)-.15 F 1.297(It tak)6.297 F 1.297(es place in tw)-.1 F
(o)-.1 E 2.855(parts. The)108 292.8 R .354(\214rst is to determine whic\
h line from the history list to use during substitution.)2.855 F .354
(The second is to)5.354 F .116
(select portions of that line for inclusion into the current one.)108
304.8 R .117(The line selected from the history is the)5.116 F/F3 10
/Times-Italic@0 SF -.15(ev)2.617 G(ent).15 E F0(,)A .846
(and the portions of that line that are acted upon are)108 316.8 R F3
(wor)3.346 E(ds)-.37 E F0 5.846(.V)C(arious)-6.956 E F3(modi\214er)3.346
E(s)-.1 E F0 .846(are a)3.346 F -.25(va)-.2 G .845(ilable to manipulate)
.25 F .304(the selected w)108 328.8 R 2.804(ords. The)-.1 F .304
(line is brok)2.804 F .304(en into w)-.1 F .304(ords in the same f)-.1 F
.304(ashion as)-.1 F F2(bash)2.804 E F0 .305
(does when reading input, so)2.804 F .539(that se)108 340.8 R -.15(ve)
-.25 G .539(ral w).15 F .539(ords that w)-.1 F .539
(ould otherwise be separated are considered one w)-.1 F .538
(ord when surrounded by quotes)-.1 F .307(\(see the description of)108
352.8 R F2(history_tok)2.807 E(enize\(\))-.1 E F0(belo)2.807 E 2.807
(w\). History)-.25 F -.15(ex)2.807 G .307
(pansions are introduced by the appearance of).15 F .52(the history e)
108 364.8 R .52(xpansion character)-.15 F 3.02(,w)-.4 G .52(hich is)
-3.02 F F2(!)3.853 E F0 .52(by def)3.853 F 3.02(ault. Only)-.1 F .52
(backslash \()3.02 F F2(\\).833 E F0 3.02(\)a).833 G .52
(nd single quotes can quote the)-3.02 F(history e)108 376.8 Q
(xpansion character)-.15 E(.)-.55 E F2(Ev)87 393.6 Q(ent Designators)-.1
E F0(An e)108 405.6 Q -.15(ve)-.25 G(nt designator is a reference to a \
command line entry in the history list.).15 E F2(!)108 422.4 Q F0
(Start a history substitution, e)32.67 E(xcept when follo)-.15 E
(wed by a)-.25 E F2(blank)2.5 E F0 2.5(,n)C -.25(ew)-2.5 G
(line, = or \(.).25 E F2(!)108 434.4 Q F3(n)A F0(Refer to command line)
27.67 E F3(n)2.5 E F0(.).24 E F2<21ad>108 446.4 Q F3(n)A F0
(Refer to the current command line minus)21.97 E F3(n)2.5 E F0(.).24 E
F2(!!)108 458.4 Q F0(Refer to the pre)29.34 E(vious command.)-.25 E
(This is a synon)5 E(ym for `!\2551'.)-.15 E F2(!)108 470.4 Q F3(string)
A F0(Refer to the most recent command starting with)9.33 E F3(string)2.5
E F0(.).22 E F2(!?)108 482.4 Q F3(string)A F2([?])A F0 1.022
(Refer to the most recent command containing)144 494.4 R F3(string)3.522
E F0 6.022(.T).22 G 1.022(he trailing)-6.022 F F2(?)3.522 E F0 1.022
(may be omitted if)3.522 F F3(string)3.862 E F0(is)3.742 E(follo)144
506.4 Q(wed immediately by a ne)-.25 E(wline.)-.25 E/F4 12/Times-Bold@0
SF(^)108 523.4 Q F3(string1)-5 I F4(^)5 I F3(string2)-5 I F4(^)5 I F0
2.63(Quick substitution.)144 530.4 R 2.629
(Repeat the last command, replacing)7.629 F F3(string1)5.469 E F0(with)
5.129 E F3(string2)5.129 E F0 7.629(.E).02 G(qui)-7.629 E -.25(va)-.25 G
2.629(lent to).25 F -.74(``)144 542.4 S(!!:s/).74 E F3(string1)A F0(/)A
F3(string2)A F0(/')A 2.5('\()-.74 G(see)-2.5 E F2(Modi\214ers)2.5 E F0
(belo)2.5 E(w\).)-.25 E F2(!#)108 554.4 Q F0
(The entire command line typed so f)27.67 E(ar)-.1 E(.)-.55 E F2 -.75
(Wo)87 571.2 S(rd Designators).75 E F0 -.8(Wo)108 583.2 S 1.313
(rd designators are used to select desired w).8 F 1.314(ords from the e)
-.1 F -.15(ve)-.25 G 3.814(nt. A).15 F F2(:)3.814 E F0 1.314
(separates the e)3.814 F -.15(ve)-.25 G 1.314(nt speci\214cation).15 F
.53(from the w)108 595.2 R .529(ord designator)-.1 F 5.529(.I)-.55 G
3.029(tm)-5.529 G .529(ay be omitted if the w)-3.029 F .529
(ord designator be)-.1 F .529(gins with a)-.15 F F2(^)3.029 E F0(,)A F2
($)3.029 E F0(,)A F2(*)3.029 E F0(,)A F2<ad>3.029 E F0 3.029(,o)C(r)
-3.029 E F2(%)3.029 E F0 5.529(.W)C(ords)-6.329 E 1.3
(are numbered from the be)108 607.2 R 1.3
(ginning of the line, with the \214rst w)-.15 F 1.301
(ord being denoted by 0 \(zero\).)-.1 F -.8(Wo)6.301 G 1.301(rds are).8
F(inserted into the current line separated by single spaces.)108 619.2 Q
F2 2.5(0\()108 636 S(zer)-2.5 E(o\))-.18 E F0(The zeroth w)144 648 Q 2.5
(ord. F)-.1 F(or the shell, this is the command w)-.15 E(ord.)-.1 E F3
(n)108.36 660 Q F0(The)30.64 E F3(n)2.5 E F0(th w)A(ord.)-.1 E F2(^)108
672 Q F0(The \214rst ar)32.67 E 2.5(gument. That)-.18 F(is, w)2.5 E
(ord 1.)-.1 E F2($)108 684 Q F0(The last ar)31 E(gument.)-.18 E F2(%)108
696 Q F0(The w)26 E(ord matched by the most recent `?)-.1 E F3(string)A
F0(?' search.)A F3(x)108.77 708 Q F2<ad>A F3(y)A F0 2.5(Ar)20.65 G
(ange of w)-2.5 E(ords; `\255)-.1 E F3(y)A F0 2.5('a)C(bbre)-2.5 E
(viates `0\255)-.25 E F3(y)A F0('.)A(GNU History 5.0)72 768 Q
(2003 July 31)139.005 E(1)203.165 E 0 Cg EP
%%Page: 2 2
%%BeginPageSetup
BP
%%EndPageSetup
/F0 10/Times-Roman@0 SF(HIST)72 48 Q(OR)-.18 E 357.18(Y\(3\) HIST)-.65 F
(OR)-.18 E(Y\(3\))-.65 E/F1 10/Times-Bold@0 SF(*)108 84 Q F0 .316
(All of the w)31 F .316(ords b)-.1 F .316(ut the zeroth.)-.2 F .315
(This is a synon)5.315 F .315(ym for `)-.15 F/F2 10/Times-Italic@0 SF
(1\255$)A F0 2.815('. It)B .315(is not an error to use)2.815 F F1(*)
2.815 E F0 .315(if there is)2.815 F(just one w)144 96 Q(ord in the e)-.1
E -.15(ve)-.25 G(nt; the empty string is returned in that case.).15 E F1
(x*)108 108 Q F0(Abbre)26 E(viates)-.25 E F2(x\255$)2.5 E F0(.)A F1
<78ad>108 120 Q F0(Abbre)25.3 E(viates)-.25 E F2(x\255$)2.5 E F0(lik)2.5
E(e)-.1 E F1(x*)2.5 E F0 2.5(,b)C(ut omits the last w)-2.7 E(ord.)-.1 E
(If a w)108 136.8 Q(ord designator is supplied without an e)-.1 E -.15
(ve)-.25 G(nt speci\214cation, the pre).15 E
(vious command is used as the e)-.25 E -.15(ve)-.25 G(nt.).15 E F1
(Modi\214ers)87 153.6 Q F0 .183(After the optional w)108 165.6 R .183
(ord designator)-.1 F 2.683(,t)-.4 G .184
(here may appear a sequence of one or more of the follo)-2.683 F .184
(wing modi\214ers,)-.25 F(each preceded by a `:'.)108 177.6 Q F1(h)108
194.4 Q F0(Remo)30.44 E .3 -.15(ve a t)-.15 H
(railing \214le name component, lea).15 E(ving only the head.)-.2 E F1
(t)108 206.4 Q F0(Remo)32.67 E .3 -.15(ve a)-.15 H
(ll leading \214le name components, lea).15 E(ving the tail.)-.2 E F1(r)
108 218.4 Q F0(Remo)31.56 E .3 -.15(ve a t)-.15 H(railing suf).15 E
(\214x of the form)-.25 E F2(.xxx)2.5 E F0 2.5(,l)C(ea)-2.5 E
(ving the basename.)-.2 E F1(e)108 230.4 Q F0(Remo)31.56 E .3 -.15(ve a)
-.15 H(ll b).15 E(ut the trailing suf)-.2 E(\214x.)-.25 E F1(p)108 242.4
Q F0(Print the ne)30.44 E 2.5(wc)-.25 G(ommand b)-2.5 E(ut do not e)-.2
E -.15(xe)-.15 G(cute it.).15 E F1(q)108 254.4 Q F0
(Quote the substituted w)30.44 E(ords, escaping further substitutions.)
-.1 E F1(x)108 266.4 Q F0(Quote the substituted w)31 E(ords as with)-.1
E F1(q)2.5 E F0 2.5(,b)C(ut break into w)-2.7 E(ords at)-.1 E F1(blanks)
2.5 E F0(and ne)2.5 E(wlines.)-.25 E F1(s/)108 278.4 Q F2(old)A F1(/)A
F2(ne)A(w)-.15 E F1(/)A F0(Substitute)144 290.4 Q F2(ne)3.082 E(w)-.15 E
F0 .221(for the \214rst occurrence of)3.032 F F2(old)2.951 E F0 .221
(in the e)3.491 F -.15(ve)-.25 G .221(nt line.).15 F(An)5.221 E 2.721
(yd)-.15 G .221(elimiter can be used in place)-2.721 F .616(of /.)144
302.4 R .617
(The \214nal delimiter is optional if it is the last character of the e)
5.616 F -.15(ve)-.25 G .617(nt line.).15 F .617(The delimiter may)5.617
F .666(be quoted in)144 314.4 R F2(old)3.396 E F0(and)3.936 E F2(ne)
3.526 E(w)-.15 E F0 .666(with a single backslash.)3.476 F .666
(If & appears in)5.666 F F2(ne)3.166 E(w)-.15 E F0 3.166(,i).31 G 3.166
(ti)-3.166 G 3.166(sr)-3.166 G .666(eplaced by)-3.166 F F2(old)3.166 E
F0 5.666(.A).77 G .274(single backslash will quote the &.)144 326.4 R
(If)5.274 E F2(old)3.004 E F0 .274(is null, it is set to the last)3.544
F F2(old)3.005 E F0 .275(substituted, or)3.545 F 2.775(,i)-.4 G 2.775
(fn)-2.775 G 2.775(op)-2.775 G(re)-2.775 E(vi-)-.25 E
(ous history substitutions took place, the last)144 338.4 Q F2(string)
2.84 E F0(in a)2.72 E F1(!?)2.5 E F2(string)A F1([?])A F0(search.)5 E F1
(&)108 350.4 Q F0(Repeat the pre)27.67 E(vious substitution.)-.25 E F1
(g)108 362.4 Q F0 .398(Cause changes to be applied o)31 F -.15(ve)-.15 G
2.898(rt).15 G .398(he entire e)-2.898 F -.15(ve)-.25 G .398(nt line.)
.15 F .397(This is used in conjunction with `)5.398 F F1(:s)A F0 2.897
('\()C(e.g.,)-2.897 E(`)144 374.4 Q F1(:gs/)A F2(old)A F1(/)A F2(ne)A(w)
-.15 E F1(/)A F0 1.218('\) or `)B F1(:&)A F0 3.718('. If)B 1.218
(used with `)3.718 F F1(:s)A F0 1.218(', an)B 3.718(yd)-.15 G 1.219
(elimiter can be used in place of /, and the \214nal)-3.718 F .09
(delimiter is optional if it is the last character of the e)144 386.4 R
-.15(ve)-.25 G .089(nt line.).15 F(An)5.089 E F1(a)2.589 E F0 .089
(may be used as a synon)2.589 F .089(ym for)-.15 F F1(g)144 398.4 Q F0
(.)A F1(G)108 410.4 Q F0(Apply the follo)28.22 E(wing `)-.25 E F1(s)A F0
2.5('m)C(odi\214er once to each w)-2.5 E(ord in the e)-.1 E -.15(ve)-.25
G(nt line.).15 E/F3 10.95/Times-Bold@0 SF(PR)72 427.2 Q
(OGRAMMING WITH HIST)-.329 E(OR)-.197 E 2.738(YF)-.383 G(UNCTIONS)-2.738
E F0(This section describes ho)108 439.2 Q 2.5(wt)-.25 G 2.5(ou)-2.5 G
(se the History library in other programs.)-2.5 E F1(Intr)87 456 Q
(oduction to History)-.18 E F0 .796
(The programmer using the History library has a)108 468 R -.25(va)-.2 G
.797(ilable functions for remembering lines on a history list,).25 F
.308(associating arbitrary data with a line, remo)108 480 R .308
(ving lines from the list, searching through the list for a line con-)
-.15 F .303(taining an arbitrary te)108 492 R .303
(xt string, and referencing an)-.15 F 2.803(yl)-.15 G .303
(ine in the list directly)-2.803 F 5.303(.I)-.65 G 2.803(na)-5.303 G
.303(ddition, a history)-2.803 F F2 -.2(ex)2.803 G(pansion).2 E F0
(function is a)108 504 Q -.25(va)-.2 G(ilable which pro).25 E
(vides for a consistent user interf)-.15 E(ace across dif)-.1 E
(ferent programs.)-.25 E .059(The user using programs written with the \
History library has the bene\214t of a consistent user interf)108 520.8
R .058(ace with a)-.1 F .917(set of well-kno)108 532.8 R .917
(wn commands for manipulating the te)-.25 F .917(xt of pre)-.15 F .917
(vious lines and using that te)-.25 F .917(xt in ne)-.15 F 3.418(wc)-.25
G(om-)-3.418 E 4.184(mands. The)108 544.8 R 1.684(basic history manipul\
ation commands are identical to the history substitution pro)4.184 F
1.683(vided by)-.15 F F1(bash)108 556.8 Q F0(.)A .903
(If the programmer desires, he can use the Readline library)108 573.6 R
3.403(,w)-.65 G .904(hich includes some history manipulation by)-3.403 F
(def)108 585.6 Q(ault, and has the added adv)-.1 E
(antage of command line editing.)-.25 E .39(Before declaring an)108
602.4 R 2.89(yf)-.15 G .39(unctions using an)-2.89 F 2.89(yf)-.15 G .39
(unctionality the History library pro)-2.89 F .39
(vides in other code, an appli-)-.15 F .066
(cation writer should include the \214le)108 614.4 R F2(<r)4.232 E
(eadline/history)-.37 E(.h>)-.55 E F0 .067(in an)4.232 F 2.567<798c>-.15
G .067(le that uses the History library')-2.567 F 2.567(sf)-.55 G
(eatures.)-2.567 E .539(It supplies e)108 626.4 R .538
(xtern declarations for all of the library')-.15 F 3.038(sp)-.55 G .538
(ublic functions and v)-3.038 F .538(ariables, and declares all of the)
-.25 F(public data structures.)108 638.4 Q F1(History Storage)87 667.2 Q
F0(The history list is an array of history entries.)108 679.2 Q 2.5(Ah)5
G(istory entry is declared as follo)-2.5 E(ws:)-.25 E F2(typedef void *)
108 696 Q F1(histdata_t;)2.5 E F0(typedef struct _hist_entry {)108 712.8
Q(char *line;)113 724.8 Q(GNU History 5.0)72 768 Q(2003 July 31)139.005
E(2)203.165 E 0 Cg EP
%%Page: 3 3
%%BeginPageSetup
BP
%%EndPageSetup
/F0 10/Times-Roman@0 SF(HIST)72 48 Q(OR)-.18 E 357.18(Y\(3\) HIST)-.65 F
(OR)-.18 E(Y\(3\))-.65 E(char *timestamp;)113 84 Q(histdata_t data;)113
96 Q 2.5(}H)108 108 S(IST_ENTR)-2.5 E -.92(Y;)-.65 G
(The history list itself might therefore be declared as)108 124.8 Q/F1
10/Times-Italic@0 SF(HIST_ENTR)108 141.6 Q 2.5(Y*)-.18 G(*)-2.5 E/F2 10
/Times-Bold@0 SF(the_history_list;)2.5 E F0(The state of the History li\
brary is encapsulated into a single structure:)108 158.4 Q(/*)108 175.2
Q 2.5(*As)110.5 187.2 S
(tructure used to pass around the current state of the history)-2.5 E(.)
-.65 E(*/)110.5 199.2 Q(typedef struct _hist_state {)108 211.2 Q
(HIST_ENTR)113 223.2 Q 2.5(Y*)-.65 G
(*entries; /* Pointer to the entries themselv)-2.5 E(es. */)-.15 E
(int of)113 235.2 Q 25(fset; /*)-.25 F
(The location pointer within this array)2.5 E 2.5(.*)-.65 G(/)-2.5 E
(int length;)113 247.2 Q(/* Number of elements within this array)27.5 E
2.5(.*)-.65 G(/)-2.5 E(int size;)113 259.2 Q
(/* Number of slots allocated to this array)32.5 E 2.5(.*)-.65 G(/)-2.5
E(int \215ags;)113 271.2 Q 2.5(}H)108 283.2 S(IST)-2.5 E(OR)-.18 E(Y_ST)
-.65 E -1.11(AT)-.93 G(E;)1.11 E(If the \215ags member includes)108 300
Q F2(HS_STIFLED)2.5 E F0 2.5(,t)C(he history has been sti\215ed.)-2.5 E
/F3 10.95/Times-Bold@0 SF(History Functions)72 316.8 Q F0
(This section describes the calling sequence for the v)108 328.8 Q
(arious functions e)-.25 E(xported by the GNU History library)-.15 E(.)
-.65 E F2(Initializing History and State Management)87 345.6 Q F0 1.274
(This section describes functions used to initialize and manage the sta\
te of the History library when you)108 357.6 R -.1(wa)108 369.6 S
(nt to use the history functions in your program.).1 E F1(void)108 393.6
Q F2(using_history)2.5 E F0(\()4.166 E F1(void)A F0(\))1.666 E(Be)108
405.6 Q(gin a session in which the history functions might be used.)-.15
E(This initializes the interacti)5 E .3 -.15(ve v)-.25 H(ariables.)-.1 E
F1(HIST)108 429.6 Q(OR)-.18 E(Y_ST)-.18 E -.37(AT)-.5 G 2.5(E*).37 G F2
(history_get_history_state)A F0(\()4.166 E F1(void)A F0(\))1.666 E
(Return a structure describing the current state of the input history)
108 441.6 Q(.)-.65 E F1(void)108 465.6 Q F2(history_set_history_state)
2.5 E F0(\()4.166 E F1(HIST)A(OR)-.18 E(Y_ST)-.18 E -.37(AT)-.5 G 2.5
(E*).37 G(state)-2.5 E F0(\))1.666 E
(Set the state of the history list according to)108 477.6 Q F1(state)2.5
E F0(.)A F2(History List Management)87 506.4 Q F0
(These functions manage indi)108 518.4 Q(vidual entries on the history \
list, or set parameters managing the list itself.)-.25 E F1(void)108
542.4 Q F2(add_history)2.5 E F0(\()4.166 E F1(const c)A(har *string)-.15
E F0(\))1.666 E(Place)108 554.4 Q F1(string)2.5 E F0
(at the end of the history list.)2.5 E
(The associated data \214eld \(if an)5 E(y\) is set to)-.15 E F2(NULL)
2.5 E F0(.)A F1(void)108 578.4 Q F2(add_history_time)2.5 E F0(\()4.166 E
F1(const c)A(har *string)-.15 E F0(\))1.666 E
(Change the time stamp associated with the most recent history entry to)
108 590.4 Q F1(string)2.5 E F0(.)A F1(HIST_ENTR)108 614.4 Q 2.5(Y*)-.18
G F2 -.18(re)C(mo).18 E -.1(ve)-.1 G(_history).1 E F0(\()4.166 E F1
(int whic)A(h)-.15 E F0(\))1.666 E(Remo)108 626.4 Q .353 -.15(ve h)-.15
H .053(istory entry at of).15 F(fset)-.25 E F1(whic)2.553 E(h)-.15 E F0
.053(from the history)2.553 F 5.053(.T)-.65 G .053(he remo)-5.053 F -.15
(ve)-.15 G 2.553(de).15 G .052(lement is returned so you can free the)
-2.553 F(line, data, and containing structure.)108 638.4 Q F1
(histdata_t)108 662.4 Q F2(fr)2.5 E(ee_history_entry)-.18 E F0(\()4.166
E F1(HIST_ENTR)A 2.5(Y*)-.18 G(histent)-2.5 E F0(\))1.666 E .933
(Free the history entry)108 674.4 R F1(histent)3.433 E F0 .933(and an)
3.433 F 3.433(yh)-.15 G .933(istory library pri)-3.433 F -.25(va)-.25 G
.933(te data associated with it.).25 F .934(Returns the applica-)5.933 F
(tion-speci\214c data so the caller can dispose of it.)108 686.4 Q F1
(HIST_ENTR)108 710.4 Q 2.5(Y*)-.18 G F2 -.18(re)C(place_history_entry)
.18 E F0(\()4.166 E F1(int whic)A -.834(h, const)-.15 F -.15(ch)2.5 G
(ar *line).15 E 1.666(,h)-.1 G(istdata_t data)-1.666 E F0(\))3.332 E
(Mak)108 722.4 Q 4.014(et)-.1 G 1.514(he history entry at of)-4.014 F
(fset)-.25 E F1(whic)4.013 E(h)-.15 E F0(ha)4.013 E -.15(ve)-.2 G F1
(line)4.163 E F0(and)4.013 E F1(data)4.013 E F0 6.513(.T)C 1.513
(his returns the old entry so the caller can)-6.513 F(GNU History 5.0)72
768 Q(2003 July 31)139.005 E(3)203.165 E 0 Cg EP
%%Page: 4 4
%%BeginPageSetup
BP
%%EndPageSetup
/F0 10/Times-Roman@0 SF(HIST)72 48 Q(OR)-.18 E 357.18(Y\(3\) HIST)-.65 F
(OR)-.18 E(Y\(3\))-.65 E(dispose of an)108 84 Q 2.5(ya)-.15 G
(pplication-speci\214c data.)-2.5 E(In the case of an in)5 E -.25(va)-.4
G(lid).25 E/F1 10/Times-Italic@0 SF(whic)2.5 E(h)-.15 E F0 2.5(,a)C/F2
10/Times-Bold@0 SF(NULL)A F0(pointer is returned.)2.5 E F1(void)108 108
Q F2(clear_history)2.5 E F0(\()4.166 E F1(void)A F0(\))1.666 E
(Clear the history list by deleting all the entries.)108 120 Q F1(void)
108 144 Q F2(sti\215e_history)2.5 E F0(\()4.166 E F1(int max)A F0(\))
1.666 E(Sti\215e the history list, remembering only the last)108 156 Q
F1(max)2.5 E F0(entries.)2.5 E F1(int)108 180 Q F2(unsti\215e_history)
2.5 E F0(\()4.166 E F1(void)A F0(\))1.666 E .46
(Stop sti\215ing the history)108 192 R 5.46(.T)-.65 G .46
(his returns the pre)-5.46 F .46
(viously-set maximum number of history entries \(as set by)-.25 F F2
(sti-)2.96 E(\215e_history\(\))108 204 Q F0 2.5(\). history)B -.1(wa)2.5
G 2.5(ss).1 G 2.5(ti\215ed. The)-2.5 F -.25(va)2.5 G(lue is positi).25 E
.3 -.15(ve i)-.25 H 2.5(ft).15 G(he history w)-2.5 E(as sti\215ed, ne)
-.1 E -.05(ga)-.15 G(ti).05 E .3 -.15(ve i)-.25 H 2.5(fi).15 G 2.5(tw)
-2.5 G(asn')-2.6 E(t.)-.18 E F1(int)108 228 Q F2(history_is_sti\215ed)
2.5 E F0(\()4.166 E F1(void)A F0(\))1.666 E
(Returns non-zero if the history is sti\215ed, zero if it is not.)108
240 Q F2(Inf)87 268.8 Q(ormation About the History List)-.25 E F0(These\
functions return information about the entire history list or indi)108
280.8 Q(vidual list entries.)-.25 E F1(HIST_ENTR)108 304.8 Q 2.5(Y*)-.18
G(*)-2.5 E F2(history_list)2.5 E F0(\()4.166 E F1(void)A F0(\))1.666 E
.708(Return a)108 316.8 R F2(NULL)3.208 E F0 .708(terminated array of)
3.208 F F1(HIST_ENTR)3.208 E 3.208(Y*)-.18 G F0 .708
(which is the current input history)B 5.707(.E)-.65 G .707
(lement 0 of this)-5.707 F(list is the be)108 328.8 Q(ginning of time.)
-.15 E(If there is no history)5 E 2.5(,r)-.65 G(eturn)-2.5 E F2(NULL)2.5
E F0(.)A F1(int)108 352.8 Q F2(wher)2.5 E(e_history)-.18 E F0(\()4.166 E
F1(void)A F0(\))1.666 E(Returns the of)108 364.8 Q
(fset of the current history element.)-.25 E F1(HIST_ENTR)108 388.8 Q
2.5(Y*)-.18 G F2(curr)A(ent_history)-.18 E F0(\()4.166 E F1(void)A F0
(\))1.666 E 1.373
(Return the history entry at the current position, as determined by)108
400.8 R F2(wher)3.873 E(e_history\(\))-.18 E F0 6.373(.I)C 3.873(ft)
-6.373 G 1.374(here is no entry)-3.873 F(there, return a)108 412.8 Q F2
(NULL)2.5 E F0(pointer)2.5 E(.)-.55 E F1(HIST_ENTR)108 436.8 Q 2.5(Y*)
-.18 G F2(history_get)A F0(\()4.166 E F1(int of)A(fset)-.18 E F0(\))
1.666 E .288(Return the history entry at position)108 448.8 R F1(of)
2.787 E(fset)-.18 E F0 2.787(,s)C .287(tarting from)-2.787 F F2
(history_base)2.787 E F0 5.287(.I)C 2.787(ft)-5.287 G .287
(here is no entry there, or if)-2.787 F F1(of)2.787 E(fset)-.18 E F0
(is greater than the history length, return a)108 460.8 Q F2(NULL)2.5 E
F0(pointer)2.5 E(.)-.55 E F1(time_t)108 484.8 Q F2(history_get_time)2.5
E F0(\()4.166 E F1(HIST_ENTR)A 2.5(Y*)-.18 G F0(\))-.834 E(Return the t\
ime stamp associated with the history entry passed as the ar)108 496.8 Q
(gument.)-.18 E F1(int)108 520.8 Q F2(history_total_bytes)2.5 E F0(\()
4.166 E F1(void)A F0(\))1.666 E .391
(Return the number of bytes that the primary history entries are using.)
108 532.8 R .392(This function returns the sum of the)5.392 F
(lengths of all the lines in the history)108 544.8 Q(.)-.65 E F2(Mo)87
573.6 Q(ving Ar)-.1 E(ound the History List)-.18 E F0
(These functions allo)108 585.6 Q 2.5(wt)-.25 G(he current inde)-2.5 E
2.5(xi)-.15 G(nto the history list to be set or changed.)-2.5 E F1(int)
108 609.6 Q F2(history_set_pos)2.5 E F0(\()4.166 E F1(int pos)A F0(\))
1.666 E .79(Set the current history of)108 621.6 R .79(fset to)-.25 F F1
(pos)3.29 E F0 3.29(,a)C 3.29(na)-3.29 G .79(bsolute inde)-3.29 F 3.29
(xi)-.15 G .79(nto the list.)-3.29 F .79(Returns 1 on success, 0 if)5.79
F F1(pos)3.29 E F0 .79(is less)3.29 F
(than zero or greater than the number of history entries.)108 633.6 Q F1
(HIST_ENTR)108 657.6 Q 2.5(Y*)-.18 G F2(pr)A -.15(ev)-.18 G
(ious_history).15 E F0(\()4.166 E F1(void)A F0(\))1.666 E .207
(Back up the current history of)108 669.6 R .207(fset to the pre)-.25 F
.207(vious history entry)-.25 F 2.708(,a)-.65 G .208
(nd return a pointer to that entry)-2.708 F 5.208(.I)-.65 G 2.708(ft)
-5.208 G .208(here is)-2.708 F(no pre)108 681.6 Q(vious entry)-.25 E 2.5
(,r)-.65 G(eturn a)-2.5 E F2(NULL)2.5 E F0(pointer)2.5 E(.)-.55 E F1
(HIST_ENTR)108 705.6 Q 2.5(Y*)-.18 G F2(next_history)A F0(\()4.166 E F1
(void)A F0(\))1.666 E(Mo)108 717.6 Q 1.047 -.15(ve t)-.15 H .747
(he current history of).15 F .747(fset forw)-.25 F .746(ard to the ne)
-.1 F .746(xt history entry)-.15 F 3.246(,a)-.65 G .746
(nd return the a pointer to that entry)-3.246 F 5.746(.I)-.65 G(f)-5.746
E(there is no ne)108 729.6 Q(xt entry)-.15 E 2.5(,r)-.65 G(eturn a)-2.5
E F2(NULL)2.5 E F0(pointer)2.5 E(.)-.55 E(GNU History 5.0)72 768 Q
(2003 July 31)139.005 E(4)203.165 E 0 Cg EP
%%Page: 5 5
%%BeginPageSetup
BP
%%EndPageSetup
/F0 10/Times-Roman@0 SF(HIST)72 48 Q(OR)-.18 E 357.18(Y\(3\) HIST)-.65 F
(OR)-.18 E(Y\(3\))-.65 E/F1 10/Times-Bold@0 SF(Sear)87 84 Q
(ching the History List)-.18 E F0 .005(These functions allo)108 96 R
2.505(ws)-.25 G .006(earching of the history list for entries containin\
g a speci\214c string.)-2.505 F .006(Searching may be)5.006 F 1.452
(performed both forw)108 108 R 1.452(ard and backw)-.1 F 1.451
(ard from the current history position.)-.1 F 1.451(The search may be)
6.451 F/F2 10/Times-Italic@0 SF(anc)3.951 E(hor)-.15 E(ed)-.37 E F0(,)A
(meaning that the string must match at the be)108 120 Q
(ginning of the history entry)-.15 E(.)-.65 E F2(int)108 144 Q F1
(history_sear)2.5 E(ch)-.18 E F0(\()4.166 E F2(const c)A(har *string)
-.15 E 1.666(,i)-.1 G(nt dir)-1.666 E(ection)-.37 E F0(\))1.666 E .155
(Search the history for)108 156 R F2(string)2.655 E F0 2.656(,s)C .156
(tarting at the current history of)-2.656 F 2.656(fset. If)-.25 F F2
(dir)2.656 E(ection)-.37 E F0 .156(is less than 0, then the search)2.656
F .802(is through pre)108 168 R .802
(vious entries, otherwise through subsequent entries.)-.25 F(If)5.801 E
F2(string)3.301 E F0 .801(is found, then the current his-)3.301 F .064
(tory inde)108 180 R 2.564(xi)-.15 G 2.564(ss)-2.564 G .064
(et to that history entry)-2.564 F 2.564(,a)-.65 G .064(nd the v)-2.564
F .064(alue returned is the of)-.25 F .064
(fset in the line of the entry where)-.25 F F2(string)2.565 E F0 -.1(wa)
108 192 S 2.5(sf).1 G 2.5(ound. Otherwise,)-2.5 F
(nothing is changed, and a -1 is returned.)2.5 E F2(int)108 216 Q F1
(history_sear)2.5 E(ch_pr)-.18 E(e\214x)-.18 E F0(\()4.166 E F2(const c)
A(har *string)-.15 E 1.666(,i)-.1 G(nt dir)-1.666 E(ection)-.37 E F0(\))
1.666 E .684(Search the history for)108 228 R F2(string)3.183 E F0 3.183
(,s)C .683(tarting at the current history of)-3.183 F 3.183(fset. The)
-.25 F .683(search is anchored: matching lines)3.183 F 1.063(must be)108
240 R 1.063(gin with)-.15 F F2(string)3.563 E F0 6.063(.I)C(f)-6.063 E
F2(dir)3.563 E(ection)-.37 E F0 1.064
(is less than 0, then the search is through pre)3.563 F 1.064
(vious entries, otherwise)-.25 F 1.115(through subsequent entries.)108
252 R(If)6.115 E F2(string)3.615 E F0 1.115
(is found, then the current history inde)3.615 F 3.614(xi)-.15 G 3.614
(ss)-3.614 G 1.114(et to that entry)-3.614 F 3.614(,a)-.65 G 1.114
(nd the)-3.614 F(return v)108 264 Q(alue is 0.)-.25 E
(Otherwise, nothing is changed, and a -1 is returned.)5 E F2(int)108 288
Q F1(history_sear)2.5 E(ch_pos)-.18 E F0(\()4.166 E F2(const c)A
(har *string)-.15 E 1.666(,i)-.1 G(nt dir)-1.666 E -.834(ection, int)
-.37 F(pos)2.5 E F0(\))3.332 E .603(Search for)108 300 R F2(string)3.103
E F0 .603(in the history list, starting at)3.103 F F2(pos)3.104 E F0
3.104(,a)C 3.104(na)-3.104 G .604(bsolute inde)-3.104 F 3.104(xi)-.15 G
.604(nto the list.)-3.104 F(If)5.604 E F2(dir)3.104 E(ection)-.37 E F0
.604(is ne)3.104 F -.05(ga)-.15 G(ti).05 E -.15(ve)-.25 G(,).15 E .608
(the search proceeds backw)108 312 R .608(ard from)-.1 F F2(pos)3.108 E
F0 3.108(,o)C .608(therwise forw)-3.108 F 3.108(ard. Returns)-.1 F .608
(the absolute inde)3.108 F 3.108(xo)-.15 G 3.108(ft)-3.108 G .608
(he history ele-)-3.108 F(ment where)108 324 Q F2(string)2.5 E F0 -.1
(wa)2.5 G 2.5(sf).1 G(ound, or -1 otherwise.)-2.5 E F1
(Managing the History File)87 352.8 Q F0 .035(The History library can r\
ead the history from and write it to a \214le.)108 364.8 R .036
(This section documents the functions for)5.035 F
(managing a history \214le.)108 376.8 Q F2(int)108 400.8 Q F1 -.18(re)
2.5 G(ad_history).18 E F0(\()4.166 E F2(const c)A(har *\214lename)-.15 E
F0(\))1.666 E .151(Add the contents of)108 412.8 R F2(\214lename)2.651 E
F0 .151(to the history list, a line at a time.)2.651 F(If)5.15 E F2
(\214lename)2.65 E F0(is)2.65 E F1(NULL)2.65 E F0 2.65(,t)C .15
(hen read from)-2.65 F F2(~/.his-)2.65 E(tory)108 424.8 Q F0 5(.R)C
(eturns 0 if successful, or)-5 E F1(err)2.5 E(no)-.15 E F0(if not.)2.5 E
F2(int)108 448.8 Q F1 -.18(re)2.5 G(ad_history_range).18 E F0(\()4.166 E
F2(const c)A(har *\214lename)-.15 E 1.666(,i)-.1 G(nt fr)-1.666 E -.834
(om, int)-.45 F(to)2.5 E F0(\))3.332 E .052(Read a range of lines from)
108 460.8 R F2(\214lename)2.553 E F0 2.553(,a)C .053
(dding them to the history list.)-2.553 F .053(Start reading at line)
5.053 F F2(fr)2.553 E(om)-.45 E F0 .053(and end at)2.553 F F2(to)2.553 E
F0(.)A(If)108 472.8 Q F2(fr)2.889 E(om)-.45 E F0 .389
(is zero, start at the be)2.889 F 2.889(ginning. If)-.15 F F2(to)2.889 E
F0 .389(is less than)2.889 F F2(fr)2.889 E(om)-.45 E F0 2.889(,t)C .388
(hen read until the end of the \214le.)-2.889 F(If)5.388 E F2
(\214lename)2.888 E F0(is)108 484.8 Q F1(NULL)2.5 E F0 2.5(,t)C
(hen read from)-2.5 E F2(~/.history)2.5 E F0 5(.R)C
(eturns 0 if successful, or)-5 E F1(err)2.5 E(no)-.15 E F0(if not.)2.5 E
F2(int)108 508.8 Q F1(write_history)2.5 E F0(\()4.166 E F2(const c)A
(har *\214lename)-.15 E F0(\))1.666 E .961(Write the current history to)
108 520.8 R F2(\214lename)3.461 E F0 3.461(,o)C -.15(ve)-3.611 G
(rwriting).15 E F2(\214lename)3.461 E F0 .961(if necessary)3.461 F 5.961
(.I)-.65 G(f)-5.961 E F2(\214lename)3.462 E F0(is)3.462 E F1(NULL)3.462
E F0 3.462(,t)C .962(hen write)-3.462 F(the history list to)108 532.8 Q
F2(~/.history)2.5 E F0 5(.R)C(eturns 0 on success, or)-5 E F1(err)2.5 E
(no)-.15 E F0(on a read or write error)2.5 E(.)-.55 E F2(int)108 568.8 Q
F1(append_history)2.5 E F0(\()4.166 E F2(int nelements,)A(const c)1.666
E(har *\214lename)-.15 E F0(\))1.666 E .839(Append the last)108 580.8 R
F2(nelements)3.339 E F0 .839(of the history list to)3.339 F F2
(\214lename)3.339 E F0 5.839(.I)C(f)-5.839 E F2(\214lename)3.339 E F0
(is)3.339 E F1(NULL)3.339 E F0 3.339(,t)C .838(hen append to)-3.339 F F2
(~/.history)3.338 E F0(.)A(Returns 0 on success, or)108 592.8 Q F1(err)
2.5 E(no)-.15 E F0(on a read or write error)2.5 E(.)-.55 E F2(int)108
616.8 Q F1(history_truncate_\214le)2.5 E F0(\()4.166 E F2(const c)A
(har *\214lename)-.15 E 1.666(,i)-.1 G(nt nlines)-1.666 E F0(\))1.666 E
-.35(Tr)108 628.8 S .38(uncate the history \214le).35 F F2(\214lename)
2.88 E F0 2.88(,l)C(ea)-2.88 E .38(ving only the last)-.2 F F2(nlines)
2.881 E F0 2.881(lines. If)2.881 F F2(\214lename)2.881 E F0(is)2.881 E
F1(NULL)2.881 E F0 2.881(,t)C(hen)-2.881 E F2(~/.history)2.881 E F0(is)
2.881 E 2.5(truncated. Returns)108 640.8 R 2.5(0o)2.5 G 2.5(ns)-2.5 G
(uccess, or)-2.5 E F1(err)2.5 E(no)-.15 E F0(on f)2.5 E(ailure.)-.1 E F1
(History Expansion)87 669.6 Q F0(These functions implement history e)108
681.6 Q(xpansion.)-.15 E F2(int)108 705.6 Q F1(history_expand)2.5 E F0
(\()4.166 E F2 -.15(ch)C(ar *string).15 E 1.666(,c)-.1 G(har **output)
-1.816 E F0(\))1.666 E(Expand)108 717.6 Q F2(string)2.5 E F0 2.5(,p)C
(lacing the result into)-2.5 E F2(output)2.5 E F0 2.5(,ap)C
(ointer to a string.)-2.5 E(Returns:)5 E(GNU History 5.0)72 768 Q
(2003 July 31)139.005 E(5)203.165 E 0 Cg EP
%%Page: 6 6
%%BeginPageSetup
BP
%%EndPageSetup
/F0 10/Times-Roman@0 SF(HIST)72 48 Q(OR)-.18 E 357.18(Y\(3\) HIST)-.65 F
(OR)-.18 E(Y\(3\))-.65 E 31(0I)144 84 S 3.066(fn)-31 G 3.066(oe)-3.066 G
.566(xpansions took place \(or)-3.216 F 3.065(,i)-.4 G 3.065(ft)-3.065 G
.565(he only change in the te)-3.065 F .565(xt w)-.15 F .565
(as the remo)-.1 F -.25(va)-.15 G 3.065(lo).25 G 3.065(fe)-3.065 G
(scape)-3.065 E(characters preceding the history e)180 96 Q
(xpansion character\);)-.15 E 31(1i)144 108 S 2.5(fe)-31 G
(xpansions did tak)-2.65 E 2.5(ep)-.1 G(lace;)-2.5 E 25.17(-1 if)144 120
R(there w)2.5 E(as an error in e)-.1 E(xpansion;)-.15 E 31(2i)144 132 S
2.5(ft)-31 G(he returned line should be displayed, b)-2.5 E(ut not e)-.2
E -.15(xe)-.15 G(cuted, as with the).15 E/F1 10/Times-Bold@0 SF(:p)2.5 E
F0(modi\214er)2.5 E(.)-.55 E(If an error ocurred in e)108 144 Q
(xpansion, then)-.15 E/F2 10/Times-Italic@0 SF(output)2.5 E F0
(contains a descripti)2.5 E .3 -.15(ve e)-.25 H(rror message.).15 E F2
-.15(ch)108 168 S(ar *).15 E F1(get_history_e)2.5 E -.1(ve)-.15 G(nt).1
E F0(\()4.166 E F2(const c)A(har *string)-.15 E 1.666(,i)-.1 G
(nt *cinde)-1.666 E -.834(x, int)-.2 F(qc)2.5 E(har)-.15 E F0(\))3.332 E
.262(Returns the te)108 180 R .262(xt of the history e)-.15 F -.15(ve)
-.25 G .262(nt be).15 F .263(ginning at)-.15 F F2(string)2.763 E F0(+)
2.763 E F2(*cinde)2.763 E(x)-.2 E F0(.)A F2(*cinde)5.263 E(x)-.2 E F0
.263(is modi\214ed to point to after the)2.763 F -2.15 -.25(ev e)108 192
T .71(nt speci\214er).25 F 5.71(.A)-.55 G 3.21(tf)-5.71 G .71
(unction entry)-3.21 F(,)-.65 E F2(cinde)3.21 E(x)-.2 E F0 .709
(points to the inde)3.21 F 3.209(xi)-.15 G(nto)-3.209 E F2(string)3.209
E F0 .709(where the history e)3.209 F -.15(ve)-.25 G .709
(nt speci\214ca-).15 F .527(tion be)108 204 R(gins.)-.15 E F2(qc)5.527 E
(har)-.15 E F0 .527(is a character that is allo)3.027 F .527
(wed to end the e)-.25 F -.15(ve)-.25 G .528
(nt speci\214cation in addition to the `).15 F(`normal')-.74 E(')-.74 E
(terminating characters.)108 216 Q F2 -.15(ch)108 240 S(ar **).15 E F1
(history_tok)2.5 E(enize)-.1 E F0(\()4.166 E F2(const c)A(har *string)
-.15 E F0(\))1.666 E .239(Return an array of tok)108 252 R .239
(ens parsed out of)-.1 F F2(string)2.739 E F0 2.739(,m)C .238
(uch as the shell might.)-2.739 F .238(The tok)5.238 F .238
(ens are split on the charac-)-.1 F(ters in the)108 264 Q F1(history_w)
2.5 E(ord_delimiters)-.1 E F0 -.25(va)2.5 G
(riable, and shell quoting con).25 E -.15(ve)-.4 G(ntions are obe).15 E
(yed.)-.15 E F2 -.15(ch)108 288 S(ar *).15 E F1(history_ar)2.5 E
(g_extract)-.1 E F0(\()4.166 E F2(int \214r)A -.834(st, int)-.1 F -.834
(last, const)2.5 F -.15(ch)2.5 G(ar *string).15 E F0(\))3.332 E .025
(Extract a string se)108 300 R .025(gment consisting of the)-.15 F F2
<8c72>2.526 E(st)-.1 E F0(through)2.526 E F2(last)2.526 E F0(ar)2.526 E
.026(guments present in)-.18 F F2(string)2.526 E F0 5.026(.A)C -.18(rg)
-5.026 G .026(uments are split).18 F(using)108 312 Q F1(history_tok)2.5
E(enize\(\))-.1 E F0(.)A F1(History V)87 340.8 Q(ariables)-.92 E F0
(This section describes the e)108 352.8 Q(xternally-visible v)-.15 E
(ariables e)-.25 E(xported by the GNU History Library)-.15 E(.)-.65 E F2
(int)108 376.8 Q F1(history_base)2.5 E F0(The logical of)108 388.8 Q
(fset of the \214rst entry in the history list.)-.25 E F2(int)108 412.8
Q F1(history_length)2.5 E F0
(The number of entries currently stored in the history list.)108 424.8 Q
F2(int)108 448.8 Q F1(history_max_entries)2.5 E F0
(The maximum number of history entries.)108 460.8 Q
(This must be changed using)5 E F1(sti\215e_history\(\))2.5 E F0(.)A F2
(int)108 484.8 Q F1(history_write_timestamps)2.5 E F0 1.468
(If non-zero, timestamps are written to the history \214le, so the)108
496.8 R 3.968(yc)-.15 G 1.468(an be preserv)-3.968 F 1.468
(ed between sessions.)-.15 F(The)6.468 E(def)108 508.8 Q(ault v)-.1 E
(alue is 0, meaning that timestamps are not sa)-.25 E -.15(ve)-.2 G(d.)
.15 E F2 -.15(ch)108 532.8 S(ar).15 E F1(history_expansion_char)2.5 E F0
(The character that introduces a history e)108 544.8 Q -.15(ve)-.25 G
2.5(nt. The).15 F(def)2.5 E(ault is)-.1 E F1(!)2.5 E F0 5(.S)C
(etting this to 0 inhibits history e)-5 E(xpansion.)-.15 E F2 -.15(ch)
108 568.8 S(ar).15 E F1(history_subst_char)2.5 E F0
(The character that in)108 580.8 Q -.2(vo)-.4 G -.1(ke).2 G 2.5(sw).1 G
(ord substitution if found at the start of a line.)-2.6 E(The def)5 E
(ault is)-.1 E F1(^)2.5 E F0(.)A F2 -.15(ch)108 604.8 S(ar).15 E F1
(history_comment_char)2.5 E F0 .116(During tok)108 616.8 R .117
(enization, if this character is seen as the \214rst character of a w)
-.1 F .117(ord, then it and all subsequent char)-.1 F(-)-.2 E .277
(acters up to a ne)108 628.8 R .276
(wline are ignored, suppressing history e)-.25 F .276
(xpansion for the remainder of the line.)-.15 F .276(This is dis-)5.276
F(abled by def)108 640.8 Q(ault.)-.1 E F2 -.15(ch)108 664.8 S(ar *).15 E
F1(history_w)2.5 E(ord_delimiters)-.1 E F0
(The characters that separate tok)108 676.8 Q(ens for)-.1 E F1
(history_tok)2.5 E(enize\(\))-.1 E F0 5(.T)C(he def)-5 E(ault v)-.1 E
(alue is)-.25 E F1 2.5("\\)2.5 G(t\\n\(\)<>;&|")-2.5 E F0(.)A F2 -.15
(ch)108 700.8 S(ar *).15 E F1(history_no_expand_chars)2.5 E F0 2.054
(The list of characters which inhibit history e)108 712.8 R 2.054
(xpansion if found immediately follo)-.15 F(wing)-.25 E F1
(history_expan-)4.555 E(sion_char)108 724.8 Q F0 5(.T)C(he def)-5 E
(ault is space, tab, ne)-.1 E(wline,)-.25 E F1(\\r)2.5 E F0 2.5(,a)C(nd)
-2.5 E F1(=)2.5 E F0(.)A(GNU History 5.0)72 768 Q(2003 July 31)139.005 E
(6)203.165 E 0 Cg EP
%%Page: 7 7
%%BeginPageSetup
BP
%%EndPageSetup
/F0 10/Times-Roman@0 SF(HIST)72 48 Q(OR)-.18 E 357.18(Y\(3\) HIST)-.65 F
(OR)-.18 E(Y\(3\))-.65 E/F1 10/Times-Italic@0 SF -.15(ch)108 84 S(ar *)
.15 E/F2 10/Times-Bold@0 SF(history_sear)2.5 E(ch_delimiter_chars)-.18 E
F0 .401(The list of additional characters which can delimit a history s\
earch string, in addition to space, tab,)108 96 R F1(:)2.901 E F0(and)
2.901 E F1(?)2.901 E F0(in the case of a substring search.)108 108 Q
(The def)5 E(ault is empty)-.1 E(.)-.65 E F1(int)108 132 Q F2
(history_quotes_inhibit_expansion)2.5 E F0 .624
(If non-zero, single-quoted w)108 144 R .625
(ords are not scanned for the history e)-.1 F .625(xpansion character)
-.15 F 5.625(.T)-.55 G .625(he def)-5.625 F .625(ault v)-.1 F .625
(alue is)-.25 F(0.)108 156 Q F1(rl_lineb)108 180 Q(uf_func_t *)-.2 E F2
(history_inhibit_expansion_function)2.5 E F0 .348
(This should be set to the address of a function that tak)108 192 R .348
(es tw)-.1 F 2.848(oa)-.1 G -.18(rg)-2.848 G .347(uments: a).18 F F2
.347(char *)2.847 F F0(\()2.847 E F1(string)A F0 2.847(\)a)C .347(nd an)
-2.847 F F2(int)2.847 E F0(inde)2.847 E(x)-.15 E .227
(into that string \()108 204 R F1(i)A F0 2.727(\). It)B .227
(should return a non-zero v)2.727 F .227(alue if the history e)-.25 F
.227(xpansion starting at)-.15 F F1(string[i])2.728 E F0 .228
(should not)2.728 F .019(be performed; zero if the e)108 216 R .019
(xpansion should be done.)-.15 F .019
(It is intended for use by applications lik)5.019 F(e)-.1 E F2(bash)
2.519 E F0 .018(that use)2.519 F(the history e)108 228 Q
(xpansion character for additional purposes.)-.15 E(By def)5 E
(ault, this v)-.1 E(ariable is set to)-.25 E F2(NULL)2.5 E F0(.)A/F3
10.95/Times-Bold@0 SF(FILES)72 244.8 Q F1(~/.history)109.666 256.8 Q F0
(Def)144 268.8 Q(ault \214lename for reading and writing sa)-.1 E -.15
(ve)-.2 G 2.5(dh).15 G(istory)-2.5 E F3(SEE ALSO)72 285.6 Q F1
(The Gnu Readline Libr)108 297.6 Q(ary)-.15 E F0 2.5(,B)C(rian F)-2.5 E
(ox and Chet Rame)-.15 E(y)-.15 E F1(The Gnu History Libr)108 309.6 Q
(ary)-.15 E F0 2.5(,B)C(rian F)-2.5 E(ox and Chet Rame)-.15 E(y)-.15 E
F1(bash)108 321.6 Q F0(\(1\))A F1 -.37(re)108 333.6 S(adline).37 E F0
(\(3\))A F3 -.548(AU)72 350.4 S(THORS).548 E F0(Brian F)108 362.4 Q
(ox, Free Softw)-.15 E(are F)-.1 E(oundation)-.15 E(bfox@gnu.or)108
374.4 Q(g)-.18 E(Chet Rame)108 391.2 Q 1.3 -.65(y, C)-.15 H(ase W).65 E
(estern Reserv)-.8 E 2.5(eU)-.15 G(ni)-2.5 E -.15(ve)-.25 G(rsity).15 E
(chet@ins.CWR)108 403.2 Q(U.Edu)-.4 E F3 -.11(BU)72 420 S 2.738(GR).11 G
(EPOR)-2.738 E(TS)-.438 E F0 .16(If you \214nd a b)108 432 R .16
(ug in the)-.2 F F2(history)2.66 E F0(library)2.66 E 2.66(,y)-.65 G .16
(ou should report it.)-2.66 F .16(But \214rst, you should mak)5.16 F
2.66(es)-.1 G .16(ure that it really is)-2.66 F 2.5(ab)108 444 S
(ug, and that it appears in the latest v)-2.7 E(ersion of the)-.15 E F2
(history)2.5 E F0(library that you ha)2.5 E -.15(ve)-.2 G(.).15 E .705
(Once you ha)108 460.8 R 1.005 -.15(ve d)-.2 H .705(etermined that a b)
.15 F .704(ug actually e)-.2 F .704(xists, mail a b)-.15 F .704
(ug report to)-.2 F F1 -.2(bu)3.204 G(g\255r).2 E(eadline)-.37 E F0(@)A
F1(gnu.or)A(g)-.37 E F0 5.704(.I)C 3.204(fy)-5.704 G(ou)-3.204 E(ha)108
472.8 Q 1.809 -.15(ve a \214)-.2 H 1.509
(x, you are welcome to mail that as well!).15 F 1.51
(Suggestions and `philosophical' b)6.51 F 1.51(ug reports may be)-.2 F
(mailed to)108 484.8 Q F1 -.2(bu)2.5 G(g-r).2 E(eadline)-.37 E F0(@)A F1
(gnu.or)A(g)-.37 E F0(or posted to the Usenet ne)2.5 E(wsgroup)-.25 E F2
(gnu.bash.b)2.5 E(ug)-.2 E F0(.)A(Comments and b)108 501.6 Q
(ug reports concerning this manual page should be directed to)-.2 E F1
-.15(ch)2.5 G(et@ins.CWR).15 E -.25(U.)-.4 G(Edu).25 E F0(.).25 E
(GNU History 5.0)72 768 Q(2003 July 31)139.005 E(7)203.165 E 0 Cg EP
%%Trailer
end
%%EOF

573
readline/doc/hstech.texi Normal file
View File

@@ -0,0 +1,573 @@
@ignore
This file documents the user interface to the GNU History library.
Copyright (C) 1988-2002 Free Software Foundation, Inc.
Authored by Brian Fox and Chet Ramey.
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 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 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
@node Programming with GNU History
@chapter Programming with GNU History
This chapter describes how to interface programs that you write
with the @sc{gnu} History Library.
It should be considered a technical guide.
For information on the interactive use of @sc{gnu} History, @pxref{Using
History Interactively}.
@menu
* Introduction to History:: What is the GNU History library for?
* History Storage:: How information is stored.
* History Functions:: Functions that you can use.
* History Variables:: Variables that control behaviour.
* History Programming Example:: Example of using the GNU History Library.
@end menu
@node Introduction to History
@section Introduction to History
Many programs read input from the user a line at a time. The @sc{gnu}
History library is able to keep track of those lines, associate arbitrary
data with each line, and utilize information from previous lines in
composing new ones.
The programmer using the History library has available functions
for remembering lines on a history list, associating arbitrary data
with a line, removing lines from the list, searching through the list
for a line containing an arbitrary text string, and referencing any line
in the list directly. In addition, a history @dfn{expansion} function
is available which provides for a consistent user interface across
different programs.
The user using programs written with the History library has the
benefit of a consistent user interface with a set of well-known
commands for manipulating the text of previous lines and using that text
in new commands. The basic history manipulation commands are similar to
the history substitution provided by @code{csh}.
If the programmer desires, he can use the Readline library, which
includes some history manipulation by default, and has the added
advantage of command line editing.
Before declaring any functions using any functionality the History
library provides in other code, an application writer should include
the file @code{<readline/history.h>} in any file that uses the
History library's features. It supplies extern declarations for all
of the library's public functions and variables, and declares all of
the public data structures.
@node History Storage
@section History Storage
The history list is an array of history entries. A history entry is
declared as follows:
@example
typedef void *histdata_t;
typedef struct _hist_entry @{
char *line;
char *timestamp;
histdata_t data;
@} HIST_ENTRY;
@end example
The history list itself might therefore be declared as
@example
HIST_ENTRY **the_history_list;
@end example
The state of the History library is encapsulated into a single structure:
@example
/*
* A structure used to pass around the current state of the history.
*/
typedef struct _hist_state @{
HIST_ENTRY **entries; /* Pointer to the entries themselves. */
int offset; /* The location pointer within this array. */
int length; /* Number of elements within this array. */
int size; /* Number of slots allocated to this array. */
int flags;
@} HISTORY_STATE;
@end example
If the flags member includes @code{HS_STIFLED}, the history has been
stifled.
@node History Functions
@section History Functions
This section describes the calling sequence for the various functions
exported by the @sc{gnu} History library.
@menu
* Initializing History and State Management:: Functions to call when you
want to use history in a
program.
* History List Management:: Functions used to manage the list
of history entries.
* Information About the History List:: Functions returning information about
the history list.
* Moving Around the History List:: Functions used to change the position
in the history list.
* Searching the History List:: Functions to search the history list
for entries containing a string.
* Managing the History File:: Functions that read and write a file
containing the history list.
* History Expansion:: Functions to perform csh-like history
expansion.
@end menu
@node Initializing History and State Management
@subsection Initializing History and State Management
This section describes functions used to initialize and manage
the state of the History library when you want to use the history
functions in your program.
@deftypefun void using_history (void)
Begin a session in which the history functions might be used. This
initializes the interactive variables.
@end deftypefun
@deftypefun {HISTORY_STATE *} history_get_history_state (void)
Return a structure describing the current state of the input history.
@end deftypefun
@deftypefun void history_set_history_state (HISTORY_STATE *state)
Set the state of the history list according to @var{state}.
@end deftypefun
@node History List Management
@subsection History List Management
These functions manage individual entries on the history list, or set
parameters managing the list itself.
@deftypefun void add_history (const char *string)
Place @var{string} at the end of the history list. The associated data
field (if any) is set to @code{NULL}.
@end deftypefun
@deftypefun void add_history_time (const char *string)
Change the time stamp associated with the most recent history entry to
@var{string}.
@end deftypefun
@deftypefun {HIST_ENTRY *} remove_history (int which)
Remove history entry at offset @var{which} from the history. The
removed element is returned so you can free the line, data,
and containing structure.
@end deftypefun
@deftypefun {histdata_t} free_history_entry (HIST_ENTRY *histent)
Free the history entry @var{histent} and any history library private
data associated with it. Returns the application-specific data
so the caller can dispose of it.
@end deftypefun
@deftypefun {HIST_ENTRY *} replace_history_entry (int which, const char *line, histdata_t data)
Make the history entry at offset @var{which} have @var{line} and @var{data}.
This returns the old entry so the caller can dispose of any
application-specific data. In the case
of an invalid @var{which}, a @code{NULL} pointer is returned.
@end deftypefun
@deftypefun void clear_history (void)
Clear the history list by deleting all the entries.
@end deftypefun
@deftypefun void stifle_history (int max)
Stifle the history list, remembering only the last @var{max} entries.
@end deftypefun
@deftypefun int unstifle_history (void)
Stop stifling the history. This returns the previously-set
maximum number of history entries (as set by @code{stifle_history()}).
The value is positive if the history was
stifled, negative if it wasn't.
@end deftypefun
@deftypefun int history_is_stifled (void)
Returns non-zero if the history is stifled, zero if it is not.
@end deftypefun
@node Information About the History List
@subsection Information About the History List
These functions return information about the entire history list or
individual list entries.
@deftypefun {HIST_ENTRY **} history_list (void)
Return a @code{NULL} terminated array of @code{HIST_ENTRY *} which is the
current input history. Element 0 of this list is the beginning of time.
If there is no history, return @code{NULL}.
@end deftypefun
@deftypefun int where_history (void)
Returns the offset of the current history element.
@end deftypefun
@deftypefun {HIST_ENTRY *} current_history (void)
Return the history entry at the current position, as determined by
@code{where_history()}. If there is no entry there, return a @code{NULL}
pointer.
@end deftypefun
@deftypefun {HIST_ENTRY *} history_get (int offset)
Return the history entry at position @var{offset}, starting from
@code{history_base} (@pxref{History Variables}).
If there is no entry there, or if @var{offset}
is greater than the history length, return a @code{NULL} pointer.
@end deftypefun
@deftypefun time_t history_get_time (HIST_ENTRY *entry)
Return the time stamp associated with the history entry @var{entry}.
@end deftypefun
@deftypefun int history_total_bytes (void)
Return the number of bytes that the primary history entries are using.
This function returns the sum of the lengths of all the lines in the
history.
@end deftypefun
@node Moving Around the History List
@subsection Moving Around the History List
These functions allow the current index into the history list to be
set or changed.
@deftypefun int history_set_pos (int pos)
Set the current history offset to @var{pos}, an absolute index
into the list.
Returns 1 on success, 0 if @var{pos} is less than zero or greater
than the number of history entries.
@end deftypefun
@deftypefun {HIST_ENTRY *} previous_history (void)
Back up the current history offset to the previous history entry, and
return a pointer to that entry. If there is no previous entry, return
a @code{NULL} pointer.
@end deftypefun
@deftypefun {HIST_ENTRY *} next_history (void)
Move the current history offset forward to the next history entry, and
return the a pointer to that entry. If there is no next entry, return
a @code{NULL} pointer.
@end deftypefun
@node Searching the History List
@subsection Searching the History List
@cindex History Searching
These functions allow searching of the history list for entries containing
a specific string. Searching may be performed both forward and backward
from the current history position. The search may be @dfn{anchored},
meaning that the string must match at the beginning of the history entry.
@cindex anchored search
@deftypefun int history_search (const char *string, int direction)
Search the history for @var{string}, starting at the current history offset.
If @var{direction} is less than 0, then the search is through
previous entries, otherwise through subsequent entries.
If @var{string} is found, then
the current history index is set to that history entry, and the value
returned is the offset in the line of the entry where
@var{string} was found. Otherwise, nothing is changed, and a -1 is
returned.
@end deftypefun
@deftypefun int history_search_prefix (const char *string, int direction)
Search the history for @var{string}, starting at the current history
offset. The search is anchored: matching lines must begin with
@var{string}. If @var{direction} is less than 0, then the search is
through previous entries, otherwise through subsequent entries.
If @var{string} is found, then the
current history index is set to that entry, and the return value is 0.
Otherwise, nothing is changed, and a -1 is returned.
@end deftypefun
@deftypefun int history_search_pos (const char *string, int direction, int pos)
Search for @var{string} in the history list, starting at @var{pos}, an
absolute index into the list. If @var{direction} is negative, the search
proceeds backward from @var{pos}, otherwise forward. Returns the absolute
index of the history element where @var{string} was found, or -1 otherwise.
@end deftypefun
@node Managing the History File
@subsection Managing the History File
The History library can read the history from and write it to a file.
This section documents the functions for managing a history file.
@deftypefun int read_history (const char *filename)
Add the contents of @var{filename} to the history list, a line at a time.
If @var{filename} is @code{NULL}, then read from @file{~/.history}.
Returns 0 if successful, or @code{errno} if not.
@end deftypefun
@deftypefun int read_history_range (const char *filename, int from, int to)
Read a range of lines from @var{filename}, adding them to the history list.
Start reading at line @var{from} and end at @var{to}.
If @var{from} is zero, start at the beginning. If @var{to} is less than
@var{from}, then read until the end of the file. If @var{filename} is
@code{NULL}, then read from @file{~/.history}. Returns 0 if successful,
or @code{errno} if not.
@end deftypefun
@deftypefun int write_history (const char *filename)
Write the current history to @var{filename}, overwriting @var{filename}
if necessary.
If @var{filename} is @code{NULL}, then write the history list to
@file{~/.history}.
Returns 0 on success, or @code{errno} on a read or write error.
@end deftypefun
@deftypefun int append_history (int nelements, const char *filename)
Append the last @var{nelements} of the history list to @var{filename}.
If @var{filename} is @code{NULL}, then append to @file{~/.history}.
Returns 0 on success, or @code{errno} on a read or write error.
@end deftypefun
@deftypefun int history_truncate_file (const char *filename, int nlines)
Truncate the history file @var{filename}, leaving only the last
@var{nlines} lines.
If @var{filename} is @code{NULL}, then @file{~/.history} is truncated.
Returns 0 on success, or @code{errno} on failure.
@end deftypefun
@node History Expansion
@subsection History Expansion
These functions implement history expansion.
@deftypefun int history_expand (char *string, char **output)
Expand @var{string}, placing the result into @var{output}, a pointer
to a string (@pxref{History Interaction}). Returns:
@table @code
@item 0
If no expansions took place (or, if the only change in
the text was the removal of escape characters preceding the history expansion
character);
@item 1
if expansions did take place;
@item -1
if there was an error in expansion;
@item 2
if the returned line should be displayed, but not executed,
as with the @code{:p} modifier (@pxref{Modifiers}).
@end table
If an error ocurred in expansion, then @var{output} contains a descriptive
error message.
@end deftypefun
@deftypefun {char *} get_history_event (const char *string, int *cindex, int qchar)
Returns the text of the history event beginning at @var{string} +
@var{*cindex}. @var{*cindex} is modified to point to after the event
specifier. At function entry, @var{cindex} points to the index into
@var{string} where the history event specification begins. @var{qchar}
is a character that is allowed to end the event specification in addition
to the ``normal'' terminating characters.
@end deftypefun
@deftypefun {char **} history_tokenize (const char *string)
Return an array of tokens parsed out of @var{string}, much as the
shell might. The tokens are split on the characters in the
@var{history_word_delimiters} variable,
and shell quoting conventions are obeyed.
@end deftypefun
@deftypefun {char *} history_arg_extract (int first, int last, const char *string)
Extract a string segment consisting of the @var{first} through @var{last}
arguments present in @var{string}. Arguments are split using
@code{history_tokenize}.
@end deftypefun
@node History Variables
@section History Variables
This section describes the externally-visible variables exported by
the @sc{gnu} History Library.
@deftypevar int history_base
The logical offset of the first entry in the history list.
@end deftypevar
@deftypevar int history_length
The number of entries currently stored in the history list.
@end deftypevar
@deftypevar int history_max_entries
The maximum number of history entries. This must be changed using
@code{stifle_history()}.
@end deftypevar
@deftypevar int history_write_timestamps
If non-zero, timestamps are written to the history file, so they can be
preserved between sessions. The default value is 0, meaning that
timestamps are not saved.
@end deftypevar
@deftypevar char history_expansion_char
The character that introduces a history event. The default is @samp{!}.
Setting this to 0 inhibits history expansion.
@end deftypevar
@deftypevar char history_subst_char
The character that invokes word substitution if found at the start of
a line. The default is @samp{^}.
@end deftypevar
@deftypevar char history_comment_char
During tokenization, if this character is seen as the first character
of a word, then it and all subsequent characters up to a newline are
ignored, suppressing history expansion for the remainder of the line.
This is disabled by default.
@end deftypevar
@deftypevar {char *} history_word_delimiters
The characters that separate tokens for @code{history_tokenize()}.
The default value is @code{" \t\n()<>;&|"}.
@end deftypevar
@deftypevar {char *} history_search_delimiter_chars
The list of additional characters which can delimit a history search
string, in addition to space, TAB, @samp{:} and @samp{?} in the case of
a substring search. The default is empty.
@end deftypevar
@deftypevar {char *} history_no_expand_chars
The list of characters which inhibit history expansion if found immediately
following @var{history_expansion_char}. The default is space, tab, newline,
carriage return, and @samp{=}.
@end deftypevar
@deftypevar int history_quotes_inhibit_expansion
If non-zero, single-quoted words are not scanned for the history expansion
character. The default value is 0.
@end deftypevar
@deftypevar {rl_linebuf_func_t *} history_inhibit_expansion_function
This should be set to the address of a function that takes two arguments:
a @code{char *} (@var{string})
and an @code{int} index into that string (@var{i}).
It should return a non-zero value if the history expansion starting at
@var{string[i]} should not be performed; zero if the expansion should
be done.
It is intended for use by applications like Bash that use the history
expansion character for additional purposes.
By default, this variable is set to @code{NULL}.
@end deftypevar
@node History Programming Example
@section History Programming Example
The following program demonstrates simple use of the @sc{gnu} History Library.
@smallexample
#include <stdio.h>
#include <readline/history.h>
main (argc, argv)
int argc;
char **argv;
@{
char line[1024], *t;
int len, done = 0;
line[0] = 0;
using_history ();
while (!done)
@{
printf ("history$ ");
fflush (stdout);
t = fgets (line, sizeof (line) - 1, stdin);
if (t && *t)
@{
len = strlen (t);
if (t[len - 1] == '\n')
t[len - 1] = '\0';
@}
if (!t)
strcpy (line, "quit");
if (line[0])
@{
char *expansion;
int result;
result = history_expand (line, &expansion);
if (result)
fprintf (stderr, "%s\n", expansion);
if (result < 0 || result == 2)
@{
free (expansion);
continue;
@}
add_history (expansion);
strncpy (line, expansion, sizeof (line) - 1);
free (expansion);
@}
if (strcmp (line, "quit") == 0)
done = 1;
else if (strcmp (line, "save") == 0)
write_history ("history_file");
else if (strcmp (line, "read") == 0)
read_history ("history_file");
else if (strcmp (line, "list") == 0)
@{
register HIST_ENTRY **the_list;
register int i;
the_list = history_list ();
if (the_list)
for (i = 0; the_list[i]; i++)
printf ("%d: %s\n", i + history_base, the_list[i]->line);
@}
else if (strncmp (line, "delete", 6) == 0)
@{
int which;
if ((sscanf (line + 6, "%d", &which)) == 1)
@{
HIST_ENTRY *entry = remove_history (which);
if (!entry)
fprintf (stderr, "No such entry %d\n", which);
else
@{
free (entry->line);
free (entry);
@}
@}
else
@{
fprintf (stderr, "non-numeric arg given to `delete'\n");
@}
@}
@}
@}
@end smallexample

View File

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

457
readline/doc/hsuser.texi Normal file
View File

@@ -0,0 +1,457 @@
@ignore
This file documents the user interface to the GNU History library.
Copyright (C) 1988-2002 Free Software Foundation, Inc.
Authored by Brian Fox and Chet Ramey.
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 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 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
@node Using History Interactively
@chapter Using History Interactively
@ifclear BashFeatures
@defcodeindex bt
@end ifclear
@ifset BashFeatures
This chapter describes how to use the @sc{gnu} History Library
interactively, from a user's standpoint.
It should be considered a user's guide.
For information on using the @sc{gnu} History Library in other programs,
see the @sc{gnu} Readline Library Manual.
@end ifset
@ifclear BashFeatures
This chapter describes how to use the @sc{gnu} History Library interactively,
from a user's standpoint. It should be considered a user's guide. For
information on using the @sc{gnu} History Library in your own programs,
@pxref{Programming with GNU History}.
@end ifclear
@ifset BashFeatures
@menu
* Bash History Facilities:: How Bash lets you manipulate your command
history.
* Bash History Builtins:: The Bash builtin commands that manipulate
the command history.
* History Interaction:: What it feels like using History as a user.
@end menu
@end ifset
@ifclear BashFeatures
@menu
* History Interaction:: What it feels like using History as a user.
@end menu
@end ifclear
@ifset BashFeatures
@node Bash History Facilities
@section Bash History Facilities
@cindex command history
@cindex history list
When the @option{-o history} option to the @code{set} builtin
is enabled (@pxref{The Set Builtin}),
the shell provides access to the @dfn{command history},
the list of commands previously typed.
The value of the @env{HISTSIZE} shell variable is used as the
number of commands to save in a history list.
The text of the last @env{$HISTSIZE}
commands (default 500) is saved.
The shell stores each command in the history list prior to
parameter and variable expansion
but after history expansion is performed, subject to the
values of the shell variables
@env{HISTIGNORE} and @env{HISTCONTROL}.
When the shell starts up, the history is initialized from the
file named by the @env{HISTFILE} variable (default @file{~/.bash_history}).
The file named by the value of @env{HISTFILE} is truncated, if
necessary, to contain no more than the number of lines specified by
the value of the @env{HISTFILESIZE} variable.
When an interactive shell exits, the last
@env{$HISTSIZE} lines are copied from the history list to the file
named by @env{$HISTFILE}.
If the @code{histappend} shell option is set (@pxref{Bash Builtins}),
the lines are appended to the history file,
otherwise the history file is overwritten.
If @env{HISTFILE}
is unset, or if the history file is unwritable, the history is
not saved. After saving the history, the history file is truncated
to contain no more than @env{$HISTFILESIZE}
lines. If @env{HISTFILESIZE} is not set, no truncation is performed.
If the @env{HISTTIMEFORMAT} is set, the time stamp information
associated with each history entry is written to the history file.
The builtin command @code{fc} may be used to list or edit and re-execute
a portion of the history list.
The @code{history} builtin may be used to display or modify the history
list and manipulate the history file.
When using command-line editing, search commands
are available in each editing mode that provide access to the
history list (@pxref{Commands For History}).
The shell allows control over which commands are saved on the history
list. The @env{HISTCONTROL} and @env{HISTIGNORE}
variables may be set to cause the shell to save only a subset of the
commands entered.
The @code{cmdhist}
shell option, if enabled, causes the shell to attempt to save each
line of a multi-line command in the same history entry, adding
semicolons where necessary to preserve syntactic correctness.
The @code{lithist}
shell option causes the shell to save the command with embedded newlines
instead of semicolons.
The @code{shopt} builtin is used to set these options.
@xref{Bash Builtins}, for a description of @code{shopt}.
@node Bash History Builtins
@section Bash History Builtins
@cindex history builtins
Bash provides two builtin commands which manipulate the
history list and history file.
@table @code
@item fc
@btindex fc
@example
@code{fc [-e @var{ename}] [-nlr] [@var{first}] [@var{last}]}
@code{fc -s [@var{pat}=@var{rep}] [@var{command}]}
@end example
Fix Command. In the first form, a range of commands from @var{first} to
@var{last} is selected from the history list. Both @var{first} and
@var{last} may be specified as a string (to locate the most recent
command beginning with that string) or as a number (an index into the
history list, where a negative number is used as an offset from the
current command number). If @var{last} is not specified it is set to
@var{first}. If @var{first} is not specified it is set to the previous
command for editing and @minus{}16 for listing. If the @option{-l} flag is
given, the commands are listed on standard output. The @option{-n} flag
suppresses the command numbers when listing. The @option{-r} flag
reverses the order of the listing. Otherwise, the editor given by
@var{ename} is invoked on a file containing those commands. If
@var{ename} is not given, the value of the following variable expansion
is used: @code{$@{FCEDIT:-$@{EDITOR:-vi@}@}}. This says to use the
value of the @env{FCEDIT} variable if set, or the value of the
@env{EDITOR} variable if that is set, or @code{vi} if neither is set.
When editing is complete, the edited commands are echoed and executed.
In the second form, @var{command} is re-executed after each instance
of @var{pat} in the selected command is replaced by @var{rep}.
A useful alias to use with the @code{fc} command is @code{r='fc -s'}, so
that typing @samp{r cc} runs the last command beginning with @code{cc}
and typing @samp{r} re-executes the last command (@pxref{Aliases}).
@item history
@btindex history
@example
history [@var{n}]
history -c
history -d @var{offset}
history [-anrw] [@var{filename}]
history -ps @var{arg}
@end example
With no options, display the history list with line numbers.
Lines prefixed with a @samp{*} have been modified.
An argument of @var{n} lists only the last @var{n} lines.
If the shell variable @env{HISTTIMEFORMAT} is set and not null,
it is used as a format string for @var{strftime} to display
the time stamp associated with each displayed history entry.
No intervening blank is printed between the formatted time stamp
and the history line.
Options, if supplied, have the following meanings:
@table @code
@item -c
Clear the history list. This may be combined
with the other options to replace the history list completely.
@item -d @var{offset}
Delete the history entry at position @var{offset}.
@var{offset} should be specified as it appears when the history is
displayed.
@item -a
Append the new
history lines (history lines entered since the beginning of the
current Bash session) to the history file.
@item -n
Append the history lines not already read from the history file
to the current history list. These are lines appended to the history
file since the beginning of the current Bash session.
@item -r
Read the current history file and append its contents to
the history list.
@item -w
Write out the current history to the history file.
@item -p
Perform history substitution on the @var{arg}s and display the result
on the standard output, without storing the results in the history list.
@item -s
The @var{arg}s are added to the end of
the history list as a single entry.
@end table
When any of the @option{-w}, @option{-r}, @option{-a}, or @option{-n} options is
used, if @var{filename}
is given, then it is used as the history file. If not, then
the value of the @env{HISTFILE} variable is used.
@end table
@end ifset
@node History Interaction
@section History Expansion
@cindex history expansion
The History library provides a history expansion feature that is similar
to the history expansion provided by @code{csh}. This section
describes the syntax used to manipulate the history information.
History expansions introduce words from the history list into
the input stream, making it easy to repeat commands, insert the
arguments to a previous command into the current input line, or
fix errors in previous commands quickly.
History expansion takes place in two parts. The first is to determine
which line from the history list should be used during substitution.
The second is to select portions of that line for inclusion into the
current one. The line selected from the history is called the
@dfn{event}, and the portions of that line that are acted upon are
called @dfn{words}. Various @dfn{modifiers} are available to manipulate
the selected words. The line is broken into words in the same fashion
that Bash does, so that several words
surrounded by quotes are considered one word.
History expansions are introduced by the appearance of the
history expansion character, which is @samp{!} by default.
@ifset BashFeatures
Only @samp{\} and @samp{'} may be used to escape the history expansion
character.
@end ifset
@ifset BashFeatures
Several shell options settable with the @code{shopt}
builtin (@pxref{Bash Builtins}) may be used to tailor
the behavior of history expansion. If the
@code{histverify} shell option is enabled, and Readline
is being used, history substitutions are not immediately passed to
the shell parser.
Instead, the expanded line is reloaded into the Readline
editing buffer for further modification.
If Readline is being used, and the @code{histreedit}
shell option is enabled, a failed history expansion will be
reloaded into the Readline editing buffer for correction.
The @option{-p} option to the @code{history} builtin command
may be used to see what a history expansion will do before using it.
The @option{-s} option to the @code{history} builtin may be used to
add commands to the end of the history list without actually executing
them, so that they are available for subsequent recall.
This is most useful in conjunction with Readline.
The shell allows control of the various characters used by the
history expansion mechanism with the @code{histchars} variable.
@end ifset
@menu
* Event Designators:: How to specify which history line to use.
* Word Designators:: Specifying which words are of interest.
* Modifiers:: Modifying the results of substitution.
@end menu
@node Event Designators
@subsection Event Designators
@cindex event designators
An event designator is a reference to a command line entry in the
history list.
@cindex history events
@table @asis
@item @code{!}
@ifset BashFeatures
Start a history substitution, except when followed by a space, tab,
the end of the line, @samp{=} or @samp{(} (when the
@code{extglob} shell option is enabled using the @code{shopt} builtin).
@end ifset
@ifclear BashFeatures
Start a history substitution, except when followed by a space, tab,
the end of the line, or @samp{=}.
@end ifclear
@item @code{!@var{n}}
Refer to command line @var{n}.
@item @code{!-@var{n}}
Refer to the command @var{n} lines back.
@item @code{!!}
Refer to the previous command. This is a synonym for @samp{!-1}.
@item @code{!@var{string}}
Refer to the most recent command starting with @var{string}.
@item @code{!?@var{string}[?]}
Refer to the most recent command containing @var{string}. The trailing
@samp{?} may be omitted if the @var{string} is followed immediately by
a newline.
@item @code{^@var{string1}^@var{string2}^}
Quick Substitution. Repeat the last command, replacing @var{string1}
with @var{string2}. Equivalent to
@code{!!:s/@var{string1}/@var{string2}/}.
@item @code{!#}
The entire command line typed so far.
@end table
@node Word Designators
@subsection Word Designators
Word designators are used to select desired words from the event.
A @samp{:} separates the event specification from the word designator. It
may be omitted if the word designator begins with a @samp{^}, @samp{$},
@samp{*}, @samp{-}, or @samp{%}. Words are numbered from the beginning
of the line, with the first word being denoted by 0 (zero). Words are
inserted into the current line separated by single spaces.
@need 0.75
For example,
@table @code
@item !!
designates the preceding command. When you type this, the preceding
command is repeated in toto.
@item !!:$
designates the last argument of the preceding command. This may be
shortened to @code{!$}.
@item !fi:2
designates the second argument of the most recent command starting with
the letters @code{fi}.
@end table
@need 0.75
Here are the word designators:
@table @code
@item 0 (zero)
The @code{0}th word. For many applications, this is the command word.
@item @var{n}
The @var{n}th word.
@item ^
The first argument; that is, word 1.
@item $
The last argument.
@item %
The word matched by the most recent @samp{?@var{string}?} search.
@item @var{x}-@var{y}
A range of words; @samp{-@var{y}} abbreviates @samp{0-@var{y}}.
@item *
All of the words, except the @code{0}th. This is a synonym for @samp{1-$}.
It is not an error to use @samp{*} if there is just one word in the event;
the empty string is returned in that case.
@item @var{x}*
Abbreviates @samp{@var{x}-$}
@item @var{x}-
Abbreviates @samp{@var{x}-$} like @samp{@var{x}*}, but omits the last word.
@end table
If a word designator is supplied without an event specification, the
previous command is used as the event.
@node Modifiers
@subsection Modifiers
After the optional word designator, you can add a sequence of one or more
of the following modifiers, each preceded by a @samp{:}.
@table @code
@item h
Remove a trailing pathname component, leaving only the head.
@item t
Remove all leading pathname components, leaving the tail.
@item r
Remove a trailing suffix of the form @samp{.@var{suffix}}, leaving
the basename.
@item e
Remove all but the trailing suffix.
@item p
Print the new command but do not execute it.
@ifset BashFeatures
@item q
Quote the substituted words, escaping further substitutions.
@item x
Quote the substituted words as with @samp{q},
but break into words at spaces, tabs, and newlines.
@end ifset
@item s/@var{old}/@var{new}/
Substitute @var{new} for the first occurrence of @var{old} in the
event line. Any delimiter may be used in place of @samp{/}.
The delimiter may be quoted in @var{old} and @var{new}
with a single backslash. If @samp{&} appears in @var{new},
it is replaced by @var{old}. A single backslash will quote
the @samp{&}. The final delimiter is optional if it is the last
character on the input line.
@item &
Repeat the previous substitution.
@item g
@itemx a
Cause changes to be applied over the entire event line. Used in
conjunction with @samp{s}, as in @code{gs/@var{old}/@var{new}/},
or with @samp{&}.
@item G
Apply the following @samp{s} modifier once to each word in the event.
@end table

View File

@@ -1,7 +1,7 @@
@ignore
This file documents the user interface to the GNU History library.
Copyright (C) 1988, 1991, 1996 Free Software Foundation, Inc.
Copyright (C) 1988-2002 Free Software Foundation, Inc.
Authored by Brian Fox and Chet Ramey.
Permission is granted to make and distribute verbatim copies of this manual
@@ -26,16 +26,21 @@ into another language, under the above conditions for modified versions.
@node Using History Interactively
@chapter Using History Interactively
@ifclear BashFeatures
@defcodeindex bt
@end ifclear
@ifset BashFeatures
This chapter describes how to use the GNU History Library interactively,
from a user's standpoint. It should be considered a user's guide. For
information on using the GNU History Library in other programs,
see the GNU Readline Library Manual.
This chapter describes how to use the @sc{gnu} History Library
interactively, from a user's standpoint.
It should be considered a user's guide.
For information on using the @sc{gnu} History Library in other programs,
see the @sc{gnu} Readline Library Manual.
@end ifset
@ifclear BashFeatures
This chapter describes how to use the GNU History Library interactively,
This chapter describes how to use the @sc{gnu} History Library interactively,
from a user's standpoint. It should be considered a user's guide. For
information on using the GNU History Library in your own programs,
information on using the @sc{gnu} History Library in your own programs,
@pxref{Programming with GNU History}.
@end ifclear
@@ -60,42 +65,47 @@ information on using the GNU History Library in your own programs,
@cindex command history
@cindex history list
When the @samp{-o history} option to the @code{set} builtin
When the @option{-o history} option to the @code{set} builtin
is enabled (@pxref{The Set Builtin}),
the shell provides access to the @var{command history},
the list of commands previously typed. The text of the last
@code{HISTSIZE}
commands (default 500) is saved in a history list. The shell
stores each command in the history list prior to parameter and
variable expansion
the shell provides access to the @dfn{command history},
the list of commands previously typed.
The value of the @env{HISTSIZE} shell variable is used as the
number of commands to save in a history list.
The text of the last @env{$HISTSIZE}
commands (default 500) is saved.
The shell stores each command in the history list prior to
parameter and variable expansion
but after history expansion is performed, subject to the
values of the shell variables
@code{HISTIGNORE} and @code{HISTCONTROL}.
@env{HISTIGNORE} and @env{HISTCONTROL}.
When the shell starts up, the history is initialized from the
file named by the @code{HISTFILE} variable (default @file{~/.bash_history}).
@code{HISTFILE} is truncated, if necessary, to contain no more than
the number of lines specified by the value of the @code{HISTFILESIZE}
variable. When an interactive shell exits, the last
@code{HISTSIZE} lines are copied from the history list to @code{HISTFILE}.
file named by the @env{HISTFILE} variable (default @file{~/.bash_history}).
The file named by the value of @env{HISTFILE} is truncated, if
necessary, to contain no more than the number of lines specified by
the value of the @env{HISTFILESIZE} variable.
When an interactive shell exits, the last
@env{$HISTSIZE} lines are copied from the history list to the file
named by @env{$HISTFILE}.
If the @code{histappend} shell option is set (@pxref{Bash Builtins}),
the lines are appended to the history file,
otherwise the history file is overwritten.
If @code{HISTFILE}
If @env{HISTFILE}
is unset, or if the history file is unwritable, the history is
not saved. After saving the history, the history file is truncated
to contain no more than @code{$HISTFILESIZE}
lines. If @code{HISTFILESIZE} is not set, no truncation is performed.
to contain no more than @env{$HISTFILESIZE}
lines. If @env{HISTFILESIZE} is not set, no truncation is performed.
The builtin command @code{fc} may be used to list or edit and re-execute
a portion of the history list.
The @code{history} builtin can be used to display or modify the history
The @code{history} builtin may be used to display or modify the history
list and manipulate the history file.
When using the command-line editing, search commands
When using command-line editing, search commands
are available in each editing mode that provide access to the
history list.
history list (@pxref{Commands For History}).
The shell allows control over which commands are saved on the history
list. The @code{HISTCONTROL} and @code{HISTIGNORE}
list. The @env{HISTCONTROL} and @env{HISTIGNORE}
variables may be set to cause the shell to save only a subset of the
commands entered.
The @code{cmdhist}
@@ -105,19 +115,20 @@ semicolons where necessary to preserve syntactic correctness.
The @code{lithist}
shell option causes the shell to save the command with embedded newlines
instead of semicolons.
The @code{shopt} builtin is used to set these options.
@xref{Bash Builtins}, for a description of @code{shopt}.
@node Bash History Builtins
@section Bash History Builtins
@cindex history builtins
Bash provides two builtin commands that allow you to manipulate the
Bash provides two builtin commands which manipulate the
history list and history file.
@table @code
@item fc
@comment btindex fc
@btindex fc
@example
@code{fc [-e @var{ename}] [-nlr] [@var{first}] [@var{last}]}
@code{fc -s [@var{pat}=@var{rep}] [@var{command}]}
@@ -130,15 +141,15 @@ command beginning with that string) or as a number (an index into the
history list, where a negative number is used as an offset from the
current command number). If @var{last} is not specified it is set to
@var{first}. If @var{first} is not specified it is set to the previous
command for editing and @minus{}16 for listing. If the @samp{-l} flag is
given, the commands are listed on standard output. The @samp{-n} flag
suppresses the command numbers when listing. The @samp{-r} flag
command for editing and @minus{}16 for listing. If the @option{-l} flag is
given, the commands are listed on standard output. The @option{-n} flag
suppresses the command numbers when listing. The @option{-r} flag
reverses the order of the listing. Otherwise, the editor given by
@var{ename} is invoked on a file containing those commands. If
@var{ename} is not given, the value of the following variable expansion
is used: @code{$@{FCEDIT:-$@{EDITOR:-vi@}@}}. This says to use the
value of the @code{FCEDIT} variable if set, or the value of the
@code{EDITOR} variable if that is set, or @code{vi} if neither is set.
value of the @env{FCEDIT} variable if set, or the value of the
@env{EDITOR} variable if that is set, or @code{vi} if neither is set.
When editing is complete, the edited commands are echoed and executed.
In the second form, @var{command} is re-executed after each instance
@@ -149,25 +160,29 @@ that typing @samp{r cc} runs the last command beginning with @code{cc}
and typing @samp{r} re-executes the last command (@pxref{Aliases}).
@item history
@comment btindex history
@btindex history
@example
history [-c] [@var{n}]
history [@var{n}]
history -c
history -d @var{offset}
history [-anrw] [@var{filename}]
history -ps @var{arg}
@end example
Display the history list with line numbers. Lines prefixed with
with a @samp{*} have been modified. An argument of @var{n} says
to list only the last @var{n} lines. Options, if supplied, have
the following meanings:
With no options, display the history list with line numbers.
Lines prefixed with a @samp{*} have been modified.
An argument of @var{n} lists only the last @var{n} lines.
Options, if supplied, have the following meanings:
@table @code
@item -w
Write out the current history to the history file.
@item -c
Clear the history list. This may be combined
with the other options to replace the history list completely.
@item -r
Read the current history file and append its contents to
the history list.
@item -d @var{offset}
Delete the history entry at position @var{offset}.
@var{offset} should be specified as it appears when the history is
displayed.
@item -a
Append the new
@@ -179,23 +194,27 @@ Append the history lines not already read from the history file
to the current history list. These are lines appended to the history
file since the beginning of the current Bash session.
@item -c
Clear the history list. This may be combined
with the other options to replace the history list completely.
@item -r
Read the current history file and append its contents to
the history list.
@item -w
Write out the current history to the history file.
@item -p
Perform history substitution on the @var{arg}s and display the result
on the standard output, without storing the results in the history list.
@item -s
The @var{arg}s are added to the end of
the history list as a single entry.
@item -p
Perform history substitution on the @var{arg}s and display the result
on the standard output, without storing the results in the history list.
@end table
When the @samp{-w}, @samp{-r}, @samp{-a}, or @samp{-n} option is
When any of the @option{-w}, @option{-r}, @option{-a}, or @option{-n} options is
used, if @var{filename}
is given, then it is used as the history file. If not, then
the value of the @code{HISTFILE} variable is used.
the value of the @env{HISTFILE} variable is used.
@end table
@end ifset
@@ -241,9 +260,9 @@ editing buffer for further modification.
If Readline is being used, and the @code{histreedit}
shell option is enabled, a failed history expansion will be
reloaded into the Readline editing buffer for correction.
The @samp{-p} option to the @code{history} builtin command
The @option{-p} option to the @code{history} builtin command
may be used to see what a history expansion will do before using it.
The @samp{-s} option to the @code{history} builtin may be used to
The @option{-s} option to the @code{history} builtin may be used to
add commands to the end of the history list without actually executing
them, so that they are available for subsequent recall.
This is most useful in conjunction with Readline.
@@ -309,6 +328,26 @@ may be omitted if the word designator begins with a @samp{^}, @samp{$},
of the line, with the first word being denoted by 0 (zero). Words are
inserted into the current line separated by single spaces.
@need 0.75
For example,
@table @code
@item !!
designates the preceding command. When you type this, the preceding
command is repeated in toto.
@item !!:$
designates the last argument of the preceding command. This may be
shortened to @code{!$}.
@item !fi:2
designates the second argument of the most recent command starting with
the letters @code{fi}.
@end table
@need 0.75
Here are the word designators:
@table @code
@item 0 (zero)

View File

@@ -0,0 +1,10 @@
@ignore
Copyright (C) 1988-2002 Free Software Foundation, Inc.
@end ignore
@set EDITION 4.3
@set VERSION 4.3
@set UPDATED 2002 March 4
@set UPDATE-MONTH March 2002
@set LASTCHANGE Mon Mar 4 12:00:16 EST 2002

File diff suppressed because it is too large Load Diff

View File

@@ -6,9 +6,9 @@
.\" Case Western Reserve University
.\" chet@ins.CWRU.Edu
.\"
.\" Last Change: Thu Feb 19 10:26:47 EST 1998
.\" Last Change: Tue Sep 13 12:07:26 EDT 2005
.\"
.TH READLINE 3 "1998 Feb 19" GNU
.TH READLINE 3 "2005 Sep 13" "GNU Readline 5.1-beta1"
.\"
.\" File Name macro. This used to be `.PN', for Path Name,
.\" but Sun doesn't seem to like that very much.
@@ -22,20 +22,20 @@ readline \- get a line from a user with editing
.LP
.nf
.ft B
#include <readline.h>
#include <history.h>
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
.ft
.fi
.LP
.nf
.ft B
char *readline (prompt)
char *prompt;
.ft
\fIchar *\fP
.br
\fBreadline\fP (\fIconst char *prompt\fP);
.fi
.SH COPYRIGHT
.if n Readline is Copyright (C) 1989, 1991, 1993, 1995, 1996 by the Free Software Foundation, Inc.
.if t Readline is Copyright \(co 1989, 1991, 1993, 1995, 1996 by the Free Software Foundation, Inc.
.if n Readline is Copyright (C) 1989\-2004 by the Free Software Foundation, Inc.
.if t Readline is Copyright \(co 1989\-2004 by the Free Software Foundation, Inc.
.SH DESCRIPTION
.LP
.B readline
@@ -44,9 +44,10 @@ and return it, using
.B prompt
as a prompt. If
.B prompt
is null, no prompt is issued. The line returned is allocated with
.IR malloc (3),
so the caller must free it when finished. The line returned
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
@@ -56,6 +57,11 @@ 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
@@ -129,6 +135,7 @@ or
.RS
C\-Meta\-u: universal\-argument
.RE
.sp
into the
.I inputrc
would make M\-C\-u execute the readline command
@@ -136,17 +143,19 @@ would make M\-C\-u execute the readline command
.PP
The following symbolic character names are recognized while
processing key bindings:
.IR RUBOUT ,
.IR DEL ,
.IR ESC ,
.IR ESCAPE ,
.IR LFD ,
.IR NEWLINE ,
.IR RET ,
.IR RETURN ,
.IR SPC ,
.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
@@ -159,6 +168,7 @@ 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.
.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:
@@ -168,7 +178,7 @@ Control\-u: universal\-argument
.br
Meta\-Rubout: backward\-kill\-word
.br
Control\-o: ">&output"
Control\-o: "> output"
.RE
.LP
In the above example,
@@ -182,7 +192,8 @@ and
.I C\-o
is bound to run the macro
expressed on the right hand side (that is, to insert the text
.I >&output
.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,
@@ -192,7 +203,8 @@ differs from
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.
used, as in the following example, but the symbolic character names
are not recognized.
.sp
.RS
"\eC\-u": universal\-argument
@@ -212,8 +224,11 @@ is bound to the function
and
.I "ESC [ 1 1 ~"
is bound to insert the text
.BR "Function Key 1" .
The full set of GNU Emacs style escape sequences is
.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
@@ -230,10 +245,10 @@ an escape character
backslash
.TP
.B \e"
literal "
literal ", a double quote
.TP
.B \e'
literal '
literal ', a single quote
.RE
.PD
.PP
@@ -267,12 +282,12 @@ horizontal tab
vertical tab
.TP
.B \e\fInnn\fP
the character whose ASCII code is the octal value \fInnn\fP
the eight-bit character whose value is the octal value \fInnn\fP
(one to three digits)
.TP
.B \ex\fInnn\fP
the character whose ASCII code is the hexadecimal value \fInnn\fP
(one to three digits)
.B \ex\fIHH\fP
the eight-bit character whose value is the hexadecimal value \fIHH\fP
(one or two hex digits)
.RE
.PD
.PP
@@ -311,7 +326,12 @@ file with a statement of the form
Except where noted, readline variables can take the values
.B On
or
.BR Off .
.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
@@ -322,6 +342,11 @@ 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
@@ -344,12 +369,12 @@ 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.
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 prepending an
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)
@@ -359,7 +384,7 @@ 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.
to emacs or vi.
.B editing\-mode
can be set to either
.B emacs
@@ -375,11 +400,29 @@ arrow keys.
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 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,
@@ -387,29 +430,39 @@ 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
.IR emacs .
The value of
.B editing\-mode
also affects the default keymap.
.TP
.B mark\-directories (On)
If set to \fBOn\fP, complete<d directory names have a slash
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 meta\-flag (Off)
If set to \fBOn\fP, readline will enable eight-bit input (that is,
it will not strip the high bit from the characters it reads),
regardless of what the terminal claims it can support.
.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, unless the leading `.' is
supplied by the user in the filename to be completed.
.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.
@@ -421,9 +474,19 @@ set to
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 visible\-stats (Off)
If set to \fBOn\fP, a character denoting a file's type as reported
by \fBstat\fP(2) is appended to the filename when listing possible
by \fIstat\fP(2) is appended to the filename when listing possible
completions.
.PD
.SS Conditional Constructs
@@ -471,7 +534,7 @@ key sequence that quotes the current or previous word in Bash:
.sp 1
.RS
.nf
\fB$if\fP bash
\fB$if\fP Bash
# Quote the current or previous word
"\eC-xq": "\eeb\e"\eef\e""
\fB$endif\fP
@@ -509,20 +572,27 @@ 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.
The Escape character is used to terminate an incremental search.
Control-J will also terminate the search.
Control-G will abort an incremental search and restore the original
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.
To find other matching entries in the history list, type Control-S or
Control-R as appropriate.
.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 \fInewline\fP will terminate the search and accept
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
@@ -532,6 +602,11 @@ typed by the user or be part of the contents of the current line.
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
@@ -553,7 +628,7 @@ 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 this, or the previous, word. Words are
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)
@@ -569,9 +644,11 @@ Refresh the current line.
.PD 0
.TP
.B accept\-line (Newline, Return)
Accept the line regardless of where the cursor is. If this line is
non-empty, add it to the history list. If the line is a modified
history line, then restore the history line to its original state.
Accept the line regardless of where the cursor is.
If this line is
non-empty, it may be added to the history list for future recall with
\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
@@ -617,12 +694,14 @@ 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 (the current
cursor position). With an argument
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\-_\^)
@@ -631,15 +710,17 @@ the previous history entry). With an argument,
behave exactly like \fByank\-nth\-arg\fP.
Successive calls to \fByank\-last\-arg\fP move back through the history
list, inserting the last argument of each line in turn.
The history expansion facilities are used to extract the last argument,
as if the "!$" history expansion had been specified.
.PD
.SS Commands for Changing Text
.PP
.PD 0
.TP
.B delete\-char (C\-d)
Delete the character under the cursor. If point is at the
Delete the character at point. If point is at the
beginning of the line, there are no characters in the line, and
the last character typed was not bound to \fBBdelete\-char\fP, then return
the last character typed was not bound to \fBdelete\-char\fP, then return
.SM
.BR EOF .
.TP
@@ -647,6 +728,11 @@ the last character typed was not bound to \fBBdelete\-char\fP, then return
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.
@@ -658,13 +744,17 @@ Insert a tab character.
Insert the character typed.
.TP
.B transpose\-chars (C\-t)
Drag the character before point forward over the character at point.
Point moves forward as well. If point is at the end of the line, then
transpose the two characters before point. Negative arguments don't work.
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 behind the cursor past the word in front of the cursor
moving the cursor over that word as well.
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,
@@ -677,13 +767,24 @@ lowercase the previous word, but do not move point.
.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 the current cursor position to the end of the line.
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.
@@ -694,22 +795,25 @@ 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 the
cursor is.
Kill all characters on the current line, no matter where point is.
.TP
.B kill\-word (M\-d)
Kill from the cursor to the end of the current word, or if between
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 the cursor. Word boundaries are the same as
those used by \fBbackward\-word\fP.
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 the cursor, using white space as a word boundary.
The word boundaries are different from
.BR backward\-kill\-word .
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.
@@ -730,7 +834,7 @@ 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 the cursor.
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
@@ -791,13 +895,20 @@ 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 and the
original text is restored.
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 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
@@ -847,11 +958,11 @@ 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\-~)
.B tilde\-expand (M\-&)
Perform tilde expansion on the current word.
.TP
.B set\-mark (C\-@, M-<space>)
Set the mark to the current point. If a
.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)
@@ -867,11 +978,20 @@ A character is read and point is moved to the previous occurrence of that
character. A negative count searches for subsequent occurrences.
.TP
.B insert\-comment (M\-#)
The value of the readline
Without a numeric argument, the value of the readline
.B comment\-begin
variable is inserted at the beginning of the current line, and the line
is accepted as if a newline had been typed. This makes the current line
a shell comment.
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
@@ -887,14 +1007,14 @@ of an \fIinputrc\fP file.
.TP
.B dump\-macros
Print all of the readline key sequences bound to macros and the
strings they ouput. If a numeric argument is supplied,
strings they output. If a numeric argument is supplied,
the output is formatted in such a way that it can be made part
of an \fIinputrc\fP file.
.TP
.B emacs\-editing\-mode (C\-e)
When in
.B vi
editing mode, this causes a switch to
command mode, this causes a switch to
.B emacs
editing mode.
.TP
@@ -908,25 +1028,23 @@ editing mode.
.SH DEFAULT KEY BINDINGS
.LP
The following is a list of the default emacs and vi bindings.
Characters with the 8th bit set are written as M\-<character>, and
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
.I self\-insert
.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
.IR self\-insert .
.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
.I metafied
characters are bound to the same function in the emacs mode
meta keymap.
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
@@ -1012,7 +1130,7 @@ Emacs Meta bindings
"M-Y" yank-pop
"M-\e" delete-horizontal-space
"M-~" tilde-expand
"M-C-?" backward-delete-word
"M-C-?" backward-kill-word
"M-_" yank-last-arg
.PP
Emacs Control-X bindings
@@ -1072,6 +1190,7 @@ VI Command Mode functions
"C-V" quoted-insert
"C-W" unix-word-rubout
"C-Y" yank
"C-_" vi-undo
"\^ " forward-char
"#" insert-comment
"$" end-of-line
@@ -1126,7 +1245,7 @@ VI Command Mode functions
"r" vi-change-char
"s" vi-subst
"t" vi-char-search
"u" undo
"u" vi-undo
"w" vi-next-word
"x" vi-delete
"y" vi-yank-to
@@ -1149,9 +1268,9 @@ VI Command Mode functions
Individual \fBreadline\fP initialization file
.PD
.SH AUTHORS
Brian Fox, Free Software Foundation (primary author)
Brian Fox, Free Software Foundation
.br
bfox@ai.MIT.Edu
bfox@gnu.org
.PP
Chet Ramey, Case Western Reserve University
.br

BIN
readline/doc/readline.dvi Normal file

Binary file not shown.

6713
readline/doc/readline.html Normal file

File diff suppressed because it is too large Load Diff

4397
readline/doc/readline.info Normal file

File diff suppressed because it is too large Load Diff

BIN
readline/doc/readline.pdf Normal file

Binary file not shown.

9188
readline/doc/readline.ps Normal file

File diff suppressed because it is too large Load Diff

1356
readline/doc/readline_3.ps Normal file

File diff suppressed because it is too large Load Diff

101
readline/doc/rlman.texi Normal file
View File

@@ -0,0 +1,101 @@
\input texinfo @c -*-texinfo-*-
@comment %**start of header (This is for running Texinfo on a region.)
@setfilename readline.info
@settitle GNU Readline Library
@comment %**end of header (This is for running Texinfo on a region.)
@synindex vr fn
@setchapternewpage odd
@include version.texi
@copying
This manual describes the GNU Readline Library
(version @value{VERSION}, @value{UPDATED}), a library which aids in the
consistency of user interface across discrete programs which provide
a command line interface.
Copyright @copyright{} 1988-2004 Free Software Foundation, Inc.
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.
@quotation
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with the Front-Cover texts being ``A GNU Manual,''
and with the Back-Cover Texts as in (a) below. A copy of the license is
included in the section entitled ``GNU Free Documentation License.''
(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
this GNU Manual, like GNU software. Copies published by the Free
Software Foundation raise funds for GNU development.''
@end quotation
@end copying
@dircategory Libraries
@direntry
* Readline: (readline). The GNU readline library API.
@end direntry
@titlepage
@title GNU Readline Library
@subtitle Edition @value{EDITION}, for @code{Readline Library} Version @value{VERSION}.
@subtitle @value{UPDATED-MONTH}
@author Chet Ramey, Case Western Reserve University
@author Brian Fox, Free Software Foundation
@page
@vskip 0pt plus 1filll
@insertcopying
@sp 1
Published by the Free Software Foundation @*
59 Temple Place, Suite 330, @*
Boston, MA 02111-1307 @*
USA @*
@end titlepage
@contents
@ifnottex
@node Top
@top GNU Readline Library
This document describes the GNU Readline Library, a utility which aids
in the consistency of user interface across discrete programs which
provide a command line interface.
@menu
* Command Line Editing:: GNU Readline User's Manual.
* Programming with GNU Readline:: GNU Readline Programmer's Manual.
* Copying This Manual:: Copying this manual.
* Concept Index:: Index of concepts described in this manual.
* Function and Variable Index:: Index of externally visible functions
and variables.
@end menu
@end ifnottex
@include rluser.texi
@include rltech.texi
@node Copying This Manual
@appendix Copying This Manual
@menu
* GNU Free Documentation License:: License for copying this manual.
@end menu
@include fdl.texi
@node Concept Index
@unnumbered Concept Index
@printindex cp
@node Function and Variable Index
@unnumbered Function and Variable Index
@printindex fn
@bye

View File

@@ -6,26 +6,19 @@
@synindex vr fn
@setchapternewpage odd
@ignore
last change: Thu Apr 2 14:39:03 EST 1998
@end ignore
@set EDITION 2.2
@set VERSION 2.2
@set UPDATED 2 April 1998
@set UPDATE-MONTH April 1998
@include manvers.texinfo
@ifinfo
@dircategory Libraries
@direntry
* Readline: (readline). The GNU readline library API
@end direntry
@ifinfo
This document describes the GNU Readline Library, a utility which aids
in the consistency of user interface across discrete programs that need
to provide a command line interface.
Copyright (C) 1988, 1991, 1993, 1996, 1998 Free Software Foundation, Inc.
Copyright (C) 1988-2002 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@@ -46,7 +39,7 @@ 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,
except that this permission notice may be stated in a translation approved
by the Foundation.
by the Free Software Foundation.
@end ifinfo
@titlepage
@@ -62,8 +55,8 @@ in the consistency of user interface across discrete programs that need
to provide a command line interface.
Published by the Free Software Foundation @*
675 Massachusetts Avenue, @*
Cambridge, MA 02139 USA
59 Temple Place, Suite 330, @*
Boston, MA 02111 USA
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@@ -77,10 +70,10 @@ 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,
except that this permission notice may be stated in a translation approved
by the Foundation.
by the Free Software Foundation.
@vskip 0pt plus 1filll
Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
Copyright @copyright{} 1988-2002 Free Software Foundation, Inc.
@end titlepage
@ifinfo

2285
readline/doc/rltech.texi Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1846
readline/doc/rluser.texi Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

BIN
readline/doc/rluserman.dvi Normal file

Binary file not shown.

2796
readline/doc/rluserman.html Normal file

File diff suppressed because it is too large Load Diff

1746
readline/doc/rluserman.info Normal file

File diff suppressed because it is too large Load Diff

BIN
readline/doc/rluserman.pdf Normal file

Binary file not shown.

4948
readline/doc/rluserman.ps Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,88 @@
\input texinfo @c -*-texinfo-*-
@comment %**start of header (This is for running Texinfo on a region.)
@setfilename rluserman.info
@settitle GNU Readline Library
@comment %**end of header (This is for running Texinfo on a region.)
@setchapternewpage odd
@include version.texi
@copying
This manual describes the end user interface of the GNU Readline Library
(version @value{VERSION}, @value{UPDATED}), a library which aids in the
consistency of user interface across discrete programs which provide
a command line interface.
Copyright @copyright{} 1988-2005 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
@quotation
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with the Front-Cover texts being ``A GNU Manual,''
and with the Back-Cover Texts as in (a) below. A copy of the license is
included in the section entitled ``GNU Free Documentation License.''
(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
this GNU Manual, like GNU software. Copies published by the Free
Software Foundation raise funds for GNU development.''
@end quotation
@end copying
@dircategory Libraries
@direntry
* RLuserman: (rluserman). The GNU readline library User's Manual.
@end direntry
@titlepage
@title GNU Readline Library User Interface
@subtitle Edition @value{EDITION}, for @code{Readline Library} Version @value{VERSION}.
@subtitle @value{UPDATED-MONTH}
@author Chet Ramey, Case Western Reserve University
@author Brian Fox, Free Software Foundation
@page
@vskip 0pt plus 1filll
@insertcopying
@sp 1
Published by the Free Software Foundation @*
59 Temple Place, Suite 330, @*
Boston, MA 02111-1307 @*
USA @*
@end titlepage
@contents
@ifnottex
@node Top
@top GNU Readline Library
This document describes the end user interface of the GNU Readline Library,
a utility which aids in the consistency of user interface across discrete
programs which provide a command line interface.
@menu
* Command Line Editing:: GNU Readline User's Manual.
* Copying This Manual:: Copying This Manual.
@end menu
@end ifnottex
@include rluser.texi
@node Copying This Manual
@appendix Copying This Manual
@menu
* GNU Free Documentation License:: License for copying this manual.
@end menu
@include fdl.texi
@bye

View File

@@ -0,0 +1,94 @@
\input texinfo @c -*-texinfo-*-
@comment %**start of header (This is for running Texinfo on a region.)
@setfilename rluserman.info
@settitle GNU Readline Library
@comment %**end of header (This is for running Texinfo on a region.)
@setchapternewpage odd
@include manvers.texinfo
@ifinfo
@dircategory Libraries
@direntry
* RLuserman: (rluserman). The GNU readline library User's Manual.
@end direntry
This document describes the end user interface of the GNU Readline Library,
a utility which aids in the consistency of user interface across discrete
programs that need to provide a command line interface.
Copyright (C) 1988-2002 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
pare preserved on all copies.
@ignore
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).
@end ignore
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, 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,
except that this permission notice may be stated in a translation approved
by the Free Software Foundation.
@end ifinfo
@titlepage
@title GNU Readline Library User Interface
@subtitle Edition @value{EDITION}, for @code{Readline Library} Version @value{VERSION}.
@subtitle @value{UPDATE-MONTH}
@author Brian Fox, Free Software Foundation
@author Chet Ramey, Case Western Reserve University
@page
This document describes the end user interface of the GNU Readline Library,
a utility which aids in the consistency of user interface across discrete
programs that need to provide a command line interface.
Published by the Free Software Foundation @*
59 Temple Place, Suite 330, @*
Boston, MA 02111 USA
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 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,
except that this permission notice may be stated in a translation approved
by the Free Software Foundation.
@vskip 0pt plus 1filll
Copyright @copyright{} 1988-2002 Free Software Foundation, Inc.
@end titlepage
@ifinfo
@node Top
@top GNU Readline Library
This document describes the end user interface of the GNU Readline Library,
a utility which aids in the consistency of user interface across discrete
programs that need to provide a command line interface.
@menu
* Command Line Editing:: GNU Readline User's Manual.
@end menu
@end ifinfo
@include rluser.texinfo
@contents
@bye

View File

@@ -1,10 +1,10 @@
#! /bin/sh
# texi2dvi --- smartly produce DVI files from texinfo sources
# Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
# texi2dvi --- produce DVI (or PDF) files from Texinfo (or LaTeX) sources.
# $Id$
#
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001,
# 2002, 2003 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
@@ -19,257 +19,642 @@
# along with this program; if not, you can either send email to this
# program's maintainer or write to: The Free Software Foundation,
# Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
# Commentary:
# Author: Noah Friedman <friedman@prep.ai.mit.edu>
# Please send bug reports, etc. to bug-texinfo@prep.ai.mit.edu
#
# Original author: Noah Friedman <friedman@gnu.org>.
#
# Please send bug reports, etc. to bug-texinfo@gnu.org.
# If possible, please send a copy of the output of the script called with
# the `--debug' option when making a bug report.
# In the interest of general portability, some common bourne shell
# constructs were avoided because they weren't guaranteed to be available
# in some earlier implementations. I've tried to make this program as
# portable as possible. Welcome to unix, where the lowest common
# denominator is rapidly diminishing.
#
# Among the more interesting lossages I noticed with some bourne shells
# are:
# * No shell functions.
# * No `unset' builtin.
# * `shift' cannot take a numeric argument, and signals an error if
# there are no arguments to shift.
# Code:
# Name by which this script was invoked.
progname=`echo "$0" | sed -e 's/[^\/]*\///g'`
# This string is expanded by rcs automatically when this file is checked out.
rcs_revision='$Revision$'
version=`set - $rcs_revision; echo $2`
rcs_version=`set - $rcs_revision; echo $2`
program=`echo $0 | sed -e 's!.*/!!'`
version="texi2dvi (GNU Texinfo 4.5) $rcs_version
# To prevent hairy quoting and escaping later.
bq='`'
eq="'"
Copyright (C) 2003 Free Software Foundation, Inc.
There is NO warranty. You may redistribute this software
under the terms of the GNU General Public License.
For more information about these matters, see the files named COPYING."
usage="Usage: $progname {options} [file1] {file2 {...}}
(version $version)
usage="Usage: $program [OPTION]... FILE...
Options are:
-D, --debug Turn on shell debugging ($bq${bq}set -x$eq$eq).
-h, --help You're looking at it.
-v, --version Print version number.
Run each Texinfo or LaTeX FILE through TeX in turn until all
cross-references are resolved, building all indices. The directory
containing each FILE is searched for included files. The suffix of FILE
is used to determine its language (LaTeX or Texinfo).
Arguments in brackets are required. Those in braces are optional.
"
Makeinfo is used to perform Texinfo macro expansion before running TeX
when needed.
# Initialize variables.
Operation modes:
-b, --batch no interaction
-c, --clean remove all auxiliary files
-D, --debug turn on shell debugging (set -x)
-h, --help display this help and exit successfully
-o, --output=OFILE leave output in OFILE (implies --clean);
Only one input FILE may be specified in this case
-q, --quiet no output unless errors (implies --batch)
-s, --silent same as --quiet
-v, --version display version information and exit successfully
-V, --verbose report on what is done
TeX tuning:
-@ use @input instead of \input; for preloaded Texinfo
-e, -E, --expand force macro expansion using makeinfo
-I DIR search DIR for Texinfo files
-l, --language=LANG specify the LANG of FILE (LaTeX or Texinfo)
-p, --pdf use pdftex or pdflatex for processing
-t, --texinfo=CMD insert CMD after @setfilename in copy of input file
multiple values accumulate
The values of the BIBTEX, LATEX (or PDFLATEX), MAKEINDEX, MAKEINFO,
TEX (or PDFTEX), and TEXINDEX environment variables are used to run
those commands, if they are set.
Email bug reports to <bug-texinfo@gnu.org>,
general questions and discussion to <help-texinfo@gnu.org>.
Texinfo home page: http://www.gnu.org/software/texinfo/"
# Initialize variables for option overriding and otherwise.
# Don't use `unset' since old bourne shells don't have this command.
# Instead, assign them an empty value.
# Some of these, like TEX and TEXINDEX, may be inherited from the environment
backup_extension=.bak
batch=false # eval for batch mode
clean=
debug=
orig_pwd="`pwd`"
verbose=
texindex="${TEXINDEX-texindex}"
tex="${TEX-tex}"
escape='\'
expand= # t for expansion via makeinfo
miincludes= # makeinfo include path
oformat=dvi
oname= # --output
quiet= # by default let the tools' message be displayed
set_language=
textra=
tmpdir=${TMPDIR:-/tmp}/t2d$$ # avoid collisions on 8.3 filesystems.
txincludes= # TEXINPUTS extensions, with trailing colon
txiprereq=19990129 # minimum texinfo.tex version to have macro expansion
verbose=false # echo for verbose mode
# Save this so we can construct a new TEXINPUTS path for each file to be
# processed.
orig_pwd=`pwd`
# Systems which define $COMSPEC or $ComSpec use semicolons to separate
# directories in TEXINPUTS.
if test -n "$COMSPEC$ComSpec"; then
path_sep=";"
else
path_sep=":"
fi
# Pacify verbose cds.
CDPATH=${ZSH_VERSION+.}$path_sep
# In case someone crazy insists on using grep -E.
: ${EGREP=egrep}
# Save this so we can construct a new TEXINPUTS path for each file.
TEXINPUTS_orig="$TEXINPUTS"
export TEXINPUTS
# Unfortunately makeindex does not read TEXINPUTS.
INDEXSTYLE_orig="$INDEXSTYLE"
export TEXINPUTS INDEXSTYLE
# Push a token among the arguments that will be used to notice when we
# ended options/arguments parsing.
# Use "set dummy ...; shift" rather than 'set - ..." because on
# Solaris set - turns off set -x (but keeps set -e).
# Use ${1+"$@"} rather than "$@" because Digital Unix and Ultrix 4.3
# still expand "$@" to a single argument (the empty string) rather
# than nothing at all.
arg_sep="$$--$$"
set dummy ${1+"$@"} "$arg_sep"; shift
#
# Parse command line arguments.
# Make sure that all wildcarded options are long enough to be unambiguous.
# It's a good idea to document the full long option name in each case.
# Long options which take arguments will need a `*' appended to the
# canonical name to match the value appended after the `=' character.
while : ; do
case $# in 0) break ;; esac
case "$1" in
-D | --debug | --d* )
debug=t
shift
;;
-h | --help | --h* )
echo "$usage" 1>&2
exit 0
;;
-v | --version | --v* )
echo "texi2dvi version $version" 1>&2
exit 0
;;
-- ) # Stop option processing
shift
break
;;
-* )
case "$1" in
--*=* ) arg=`echo "$1" | sed -e 's/=.*//'` ;;
* ) arg="$1" ;;
esac
exec 1>&2
echo "$progname: unknown or ambiguous option $bq$arg$eq"
echo "$progname: Use $bq--help$eq for a list of options."
exit 1
;;
* )
break
;;
esac
done
while test x"$1" != x"$arg_sep"; do
# See if there are any command line args left (which will be interpreted as
# filename arguments)
# Handle --option=value by splitting apart and putting back on argv.
case "$1" in
--*=*)
opt=`echo "$1" | sed -e 's/=.*//'`
val=`echo "$1" | sed -e 's/[^=]*=//'`
shift
set dummy "$opt" "$val" ${1+"$@"}; shift
;;
esac
# This recognizes --quark as --quiet. So what.
case "$1" in
-@ ) escape=@;;
# Silently and without documentation accept -b and --b[atch] as synonyms.
-b | --b*) batch=eval;;
-q | -s | --q* | --s*) quiet=t; batch=eval;;
-c | --c*) clean=t;;
-D | --d*) debug=t;;
-e | -E | --e*) expand=t;;
-h | --h*) echo "$usage"; exit 0;;
-I | --I*)
shift
miincludes="$miincludes -I $1"
txincludes="$txincludes$1$path_sep"
;;
-l | --l*) shift; set_language=$1;;
-o | --o*)
shift
clean=t
case "$1" in
/* | ?:/*) oname=$1;;
*) oname="$orig_pwd/$1";;
esac;;
-p | --p*) oformat=pdf;;
-t | --t*) shift; textra="$textra\\
$1";;
-v | --vers*) echo "$version"; exit 0;;
-V | --verb*) verbose=echo;;
--) # What remains are not options.
shift
while test x"$1" != x"$arg_sep"; do
set dummy ${1+"$@"} "$1"; shift
shift
done
break;;
-*)
echo "$0: Unknown or ambiguous option \`$1'." >&2
echo "$0: Try \`--help' for more information." >&2
exit 1;;
*) set dummy ${1+"$@"} "$1"; shift;;
esac
shift
done
# Pop the token
shift
# Interpret remaining command line args as filenames.
case $# in
0 )
exec 1>&2
echo "$progname: at least one file name is required as an argument."
echo "$progname: Use $bq--help$eq for a description of command syntax."
0)
echo "$0: Missing file arguments." >&2
echo "$0: Try \`--help' for more information." >&2
exit 2
;;
1) ;;
*)
if test -n "$oname"; then
echo "$0: Can't use option \`--output' with more than one argument." >&2
exit 2
;;
fi
;;
esac
case "$debug" in t ) set -x ;; esac
# Prepare the temporary directory. Remove it at exit, unless debugging.
if test -z "$debug"; then
trap "cd / && rm -rf $tmpdir" 0 1 2 15
fi
# Texify files
for command_line_filename in ${1+"$@"} ; do
# Roughly equivalent to `dirname ...`, but more portable
directory="`echo ${command_line_filename} | sed 's/\/[^\/]*$//'`"
filename_texi="`basename ${command_line_filename}`"
# Strip off the last extension part (probably .texinfo or .texi)
filename_noext="`echo ${filename_texi} | sed 's/\.[^.]*$//'`"
# Create the temporary directory with strict rights
(umask 077 && mkdir $tmpdir) || exit 1
# If directory and file are the same, then it's probably because there's
# no pathname component. Set dirname to `.', the current directory.
if test "z${directory}" = "z${command_line_filename}" ; then
directory="."
fi
# Prepare the tools we might need. This may be extra work in some
# cases, but improves the readibility of the script.
utildir=$tmpdir/utils
mkdir $utildir || exit 1
# Source file might @include additional texinfo sources. Put `.' and
# directory where source file(s) reside in TEXINPUTS before anything
# else. `.' goes first to ensure that any old .aux, .cps, etc. files in
# ${directory} don't get used in preference to fresher files in `.'.
TEXINPUTS=".:${directory}:${TEXINPUTS_orig}"
# A sed script that preprocesses Texinfo sources in order to keep the
# iftex sections only. We want to remove non TeX sections, and
# comment (with `@c texi2dvi') TeX sections so that makeinfo does not
# try to parse them. Nevertheless, while commenting TeX sections,
# don't comment @macro/@end macro so that makeinfo does propagate
# them. Unfortunately makeinfo --iftex --no-ifhtml --no-ifinfo
# doesn't work well enough (yet) to use that, so work around with sed.
comment_iftex_sed=$utildir/comment.sed
cat <<EOF >$comment_iftex_sed
/^@tex/,/^@end tex/{
s/^/@c texi2dvi/
}
/^@iftex/,/^@end iftex/{
s/^/@c texi2dvi/
/^@c texi2dvi@macro/,/^@c texi2dvi@end macro/{
s/^@c texi2dvi//
}
}
/^@html/,/^@end html/{
s/^/@c (texi2dvi)/
}
/^@ifhtml/,/^@end ifhtml/{
s/^/@c (texi2dvi)/
}
/^@ifnottex/,/^@end ifnottex/{
s/^/@c (texi2dvi)/
}
/^@ifinfo/,/^@end ifinfo/{
/^@node/p
/^@menu/,/^@end menu/p
t
s/^/@c (texi2dvi)/
}
s/^@ifnotinfo/@c texi2dvi@ifnotinfo/
s/^@end ifnotinfo/@c texi2dvi@end ifnotinfo/
EOF
# Uncommenting is simple: Remove any leading `@c texi2dvi'.
uncomment_iftex_sed=$utildir/uncomment.sed
cat <<EOF >$uncomment_iftex_sed
s/^@c texi2dvi//
EOF
# "Unset" variables that might have values from previous iterations and
# which won't be completely reset later.
definite_index_files=""
# A shell script that computes the list of xref files.
# Takes the filename (without extension) of which we look for xref
# files as argument. The index files must be reported last.
get_xref_files=$utildir/get_xref.sh
cat <<\EOF >$get_xref_files
#! /bin/sh
# See if file exists here. If it doesn't we're in trouble since, even
# though the user may be able to reenter a valid filename at the tex
# prompt (assuming they're attending the terminal), this script won't be
# able to find the right index files and so forth.
if test ! -r "${command_line_filename}" ; then
echo "${progname}: ${command_line_filename}: No such file or permission denied." 1>&2
continue;
fi
# Get list of xref files (indexes, tables and lists).
# Find all files having root filename with a two-letter extension,
# saves the ones that are really Texinfo-related files. .?o? catches
# many files: .toc, .log, LaTeX tables and lists, FiXme's .lox, maybe more.
for this_file in "$1".?o? "$1".aux "$1".?? "$1".idx; do
# If file is empty, skip it.
test -s "$this_file" || continue
# If the file is not suitable to be an index or xref file, don't
# process it. The file can't be if its first character is not a
# backslash or single quote.
first_character=`sed -n '1s/^\(.\).*$/\1/p;q' $this_file`
if test "x$first_character" = "x\\" \
|| test "x$first_character" = "x'"; then
xref_files="$xref_files ./$this_file"
fi
done
echo "$xref_files"
EOF
chmod 500 $get_xref_files
# Find all files having root filename with a two-letter extension,
# determine whether they're really index files, and save them. Foo.aux
# is actually the cross-references file, but we need to keep track of
# that too.
possible_index_files="`eval echo ${filename_noext}.?? ${filename_noext}.aux`"
for this_file in ${possible_index_files} ; do
# If file is empty, forget it.
if test ! -s "${this_file}" ; then
continue;
fi
# File descriptor usage:
# 0 standard input
# 1 standard output (--verbose messages)
# 2 standard error
# 3 some systems may open it to /dev/tty
# 4 used on the Kubota Titan
# 5 tools output (turned off by --quiet)
# Examine first character of file. If it's not a backslash or
# single quote, then it's definitely not an index or xref file.
first_character="`sed -n '1s/^\(.\).*$/\1/p;q' ${this_file}`"
if test "${first_character}" = "\\" -o "${first_character}" = "'" ; then
definite_index_files="${definite_index_files} ${this_file}"
fi
done
orig_index_files="${definite_index_files}"
orig_index_files_sans_aux="`echo ${definite_index_files} \
| sed 's/'${filename_noext}'\.aux//;
s/^[ ]*//;s/[ ]*$//;'`"
# Tools' output. If quiet, discard, else redirect to the message flow.
if test "$quiet" = t; then
exec 5>/dev/null
else
exec 5>&1
fi
# Now save copies of original index files so we have some means of
# comparison later.
for index_file_to_save in ${orig_index_files} ; do
cp "${index_file_to_save}" "${index_file_to_save}${backup_extension}"
done
# Enable tracing
test "$debug" = t && set -x
# Run texindex on current index files. If they already exist, and
# after running TeX a first time the index files don't change, then
# there's no reason to run TeX again. But we won't know that if the
# index files are out of date or nonexistent.
if test "${orig_index_files_sans_aux}" ; then
${texindex} ${orig_index_files_sans_aux}
fi
#
# TeXify files.
if ${tex} ${command_line_filename} ; then # TeX run first time
definite_index_files=""
# Get list of new index files
possible_index_files="`eval echo ${filename_noext}.?? ${filename_noext}.aux`"
for this_file in ${possible_index_files} ; do
# If file is empty, forget it.
if test ! -s ${this_file} ; then
continue;
fi
for command_line_filename in ${1+"$@"}; do
$verbose "Processing $command_line_filename ..."
# Examine first character of file. If it's not a backslash or
# single quote, then it's definitely not an index or xref file.
first_character="`sed -n '1s/^\(.\).*$/\1/p;q' ${this_file}`"
if test "${first_character}" = "\\" -o "${first_character}" = "'" ; then
definite_index_files="${definite_index_files} ${this_file}"
fi
done
new_index_files="${definite_index_files}"
new_index_files_sans_aux="`echo ${definite_index_files} \
| sed 's/'${filename_noext}'\.aux//;
s/^[ ]*//;s/[ ]*$//;'`"
# If the COMMAND_LINE_FILENAME is not absolute (e.g., --debug.tex),
# prepend `./' in order to avoid that the tools take it as an option.
echo "$command_line_filename" | $EGREP '^(/|[A-z]:/)' >/dev/null \
|| command_line_filename="./$command_line_filename"
# If old and new list don't at least have the same file list, then one
# file or another has definitely changed.
if test "${orig_index_files}" != "${new_index_files}" ; then
index_files_changed_p=t
# See if the file exists. If it doesn't we're in trouble since, even
# though the user may be able to reenter a valid filename at the tex
# prompt (assuming they're attending the terminal), this script won't
# be able to find the right xref files and so forth.
if test ! -r "$command_line_filename"; then
echo "$0: Could not read $command_line_filename, skipping." >&2
continue
fi
# Get the name of the current directory. We want the full path
# because in clean mode we are in tmp, in which case a relative
# path has no meaning.
filename_dir=`echo $command_line_filename | sed 's!/[^/]*$!!;s!^$!.!'`
filename_dir=`cd "$filename_dir" >/dev/null && pwd`
# Strip directory part but leave extension.
filename_ext=`basename "$command_line_filename"`
# Strip extension.
filename_noext=`echo "$filename_ext" | sed 's/\.[^.]*$//'`
ext=`echo "$filename_ext" | sed 's/^.*\.//'`
# _src. Use same basename since we want to generate aux files with
# the same basename as the manual. If --expand, then output the
# macro-expanded file to here, else copy the original file.
tmpdir_src=$tmpdir/src
filename_src=$tmpdir_src/$filename_noext.$ext
# _xtr. The file with the user's extra commands.
tmpdir_xtr=$tmpdir/xtr
filename_xtr=$tmpdir_xtr/$filename_noext.$ext
# _bak. Copies of the previous xref files (another round is run if
# they differ from the new one).
tmpdir_bak=$tmpdir/bak
# Make all those directories and give up if we can't succeed.
mkdir $tmpdir_src $tmpdir_xtr $tmpdir_bak || exit 1
# Source file might include additional sources.
# We want `.:$orig_pwd' before anything else. (We'll add `.:' later
# after all other directories have been turned into absolute paths.)
# `.' goes first to ensure that any old .aux, .cps,
# etc. files in ${directory} don't get used in preference to fresher
# files in `.'. Include orig_pwd in case we are in clean mode, where
# we've cd'd to a temp directory.
common="$orig_pwd$path_sep$filename_dir$path_sep$txincludes"
TEXINPUTS="$common$TEXINPUTS_orig"
INDEXSTYLE="$common$INDEXSTYLE_orig"
# Convert relative paths to absolute paths, so we can run in another
# directory (e.g., in --clean mode, or during the macro-support
# detection.)
#
# Empty path components are meaningful to tex. We rewrite them
# as `EMPTY' so they don't get lost when we split on $path_sep.
TEXINPUTS=`echo $TEXINPUTS |sed 's/^:/EMPTY:/;s/:$/:EMPTY/;s/::/:EMPTY:/g'`
INDEXSTYLE=`echo $INDEXSTYLE |sed 's/^:/EMPTY:/;s/:$/:EMPTY/;s/::/:EMPTY:/g'`
save_IFS=$IFS
IFS=$path_sep
set x $TEXINPUTS; shift
TEXINPUTS=.
for dir
do
case $dir in
EMPTY)
TEXINPUTS=$TEXINPUTS$path_sep
;;
[\\/]* | ?:[\\/]*) # Absolute paths don't need to be expansed.
TEXINPUTS=$TEXINPUTS$path_sep$dir
;;
*)
abs=`cd "$dir" && pwd` && TEXINPUTS=$TEXINPUTS$path_sep$abs
;;
esac
done
set x $INDEXSTYLE; shift
INDEXSTYLE=.
for dir
do
case $dir in
EMPTY)
INDEXSTYLE=$INDEXSTYLE$path_sep
;;
[\\/]* | ?:[\\/]*) # Absolute paths don't need to be expansed.
INDEXSTYLE=$INDEXSTYLE$path_sep$dir
;;
*)
abs=`cd "$dir" && pwd` && INDEXSTYLE=$INDEXSTYLE$path_sep$abs
;;
esac
done
IFS=$save_IFS
# If the user explicitly specified the language, use that.
# Otherwise, if the first line is \input texinfo, assume it's texinfo.
# Otherwise, guess from the file extension.
if test -n "$set_language"; then
language=$set_language
elif sed 1q "$command_line_filename" | grep 'input texinfo' >/dev/null; then
language=texinfo
else
language=
fi
# Get the type of the file (latex or texinfo) from the given language
# we just guessed, or from the file extension if not set yet.
case ${language:-$filename_ext} in
[lL]a[tT]e[xX] | *.ltx | *.tex)
# Assume a LaTeX file. LaTeX needs bibtex and uses latex for
# compilation. No makeinfo.
bibtex=${BIBTEX:-bibtex}
makeinfo= # no point in running makeinfo on latex source.
texindex=${MAKEINDEX:-makeindex}
if test $oformat = dvi; then
tex=${LATEX:-latex}
else
# File list is the same. We must compare each file until we find a
# difference.
index_files_changed_p=""
for this_file in ${new_index_files} ; do
# cmp -s will return nonzero exit status if files differ.
cmp -s "${this_file}" "${this_file}${backup_extension}"
if test $? -ne 0 ; then
# We only need to keep comparing until we find *one* that
# differs, because we'll have to run texindex & tex no
# matter what.
index_files_changed_p=t
break
fi
done
tex=${PDFLATEX:-pdflatex}
fi
;;
# If index files have changed since TeX has been run, or if the aux
# file wasn't present originally, run texindex and TeX again.
if test "${index_files_changed_p}" ; then
retval=0
if test "${new_index_files_sans_aux}" ; then
${texindex} ${new_index_files_sans_aux}
retval=$?
fi
if test ${retval} -eq 0 ; then
${tex} "${command_line_filename}"
fi
*)
# Assume a Texinfo file. Texinfo files need makeinfo, texindex and tex.
bibtex=
texindex=${TEXINDEX:-texindex}
if test $oformat = dvi; then
tex=${TEX:-tex}
else
tex=${PDFTEX:-pdftex}
fi
fi
# Unless required by the user, makeinfo expansion is wanted only
# if texinfo.tex is too old.
if test "$expand" = t; then
makeinfo=${MAKEINFO:-makeinfo}
else
# Check if texinfo.tex performs macro expansion by looking for
# its version. The version is a date of the form YEAR-MO-DA.
# We don't need to use [0-9] to match the digits since anyway
# the comparison with $txiprereq, a number, will fail with non
# digits.
txiversion_tex=txiversion.tex
echo '\input texinfo.tex @bye' >$tmpdir/$txiversion_tex
# Run in the tmpdir to avoid leaving files.
eval `cd $tmpdir >/dev/null &&
$tex $txiversion_tex 2>/dev/null |
sed -n 's/^.*\[\(.*\)version \(....\)-\(..\)-\(..\).*$/txiformat=\1 txiversion="\2\3\4"/p'`
$verbose "texinfo.tex preloaded as \`$txiformat', version is \`$txiversion' ..."
if test "$txiprereq" -le "$txiversion" >/dev/null 2>&1; then
makeinfo=
else
makeinfo=${MAKEINFO:-makeinfo}
fi
# As long as we had to run TeX, offer the user this convenience
if test "$txiformat" = Texinfo; then
escape=@
fi
fi
;;
esac
# Generate list of files to delete, then call rm once with the entire
# list. This is significantly faster than multiple executions of rm.
file_list=""
for file in ${orig_index_files} ; do
file_list="${file_list} ${file}${backup_extension}"
done
if test "${file_list}" ; then
rm -f ${file_list}
fi
# Expand macro commands in the original source file using Makeinfo.
# Always use `end' footnote style, since the `separate' style
# generates different output (arguably this is a bug in -E).
# Discard main info output, the user asked to run TeX, not makeinfo.
if test -n "$makeinfo"; then
$verbose "Macro-expanding $command_line_filename to $filename_src ..."
sed -f $comment_iftex_sed "$command_line_filename" \
| $makeinfo --footnote-style=end -I "$filename_dir" $miincludes \
-o /dev/null --macro-expand=- \
| sed -f $uncomment_iftex_sed >"$filename_src"
filename_input=$filename_src
fi
# If makeinfo failed (or was not even run), use the original file as input.
if test $? -ne 0 \
|| test ! -r "$filename_src"; then
$verbose "Reverting to $command_line_filename ..."
filename_input=$filename_dir/$filename_ext
fi
# Used most commonly for @finalout, @smallbook, etc.
if test -n "$textra"; then
$verbose "Inserting extra commands: $textra"
sed '/^@setfilename/a\
'"$textra" "$filename_input" >$filename_xtr
filename_input=$filename_xtr
fi
# If clean mode was specified, then move to the temporary directory.
if test "$clean" = t; then
$verbose "cd $tmpdir_src"
cd "$tmpdir_src" || exit 1
fi
while :; do # will break out of loop below
orig_xref_files=`$get_xref_files "$filename_noext"`
# Save copies of originals for later comparison.
if test -n "$orig_xref_files"; then
$verbose "Backing up xref files: `echo $orig_xref_files | sed 's|\./||g'`"
cp $orig_xref_files $tmpdir_bak
fi
# Run bibtex on current file.
# - If its input (AUX) exists.
# - If AUX contains both `\bibdata' and `\bibstyle'.
# - If some citations are missing (LOG contains `Citation').
# or the LOG complains of a missing .bbl
#
# We run bibtex first, because I can see reasons for the indexes
# to change after bibtex is run, but I see no reason for the
# converse.
#
# Don't try to be too smart. Running bibtex only if the bbl file
# exists and is older than the LaTeX file is wrong, since the
# document might include files that have changed. Because there
# can be several AUX (if there are \include's), but a single LOG,
# looking for missing citations in LOG is easier, though we take
# the risk to match false messages.
if test -n "$bibtex" \
&& test -r "$filename_noext.aux" \
&& test -r "$filename_noext.log" \
&& (grep '^\\bibdata[{]' "$filename_noext.aux" \
&& grep '^\\bibstyle[{]' "$filename_noext.aux" \
&& (grep 'Warning:.*Citation.*undefined' "$filename_noext.log" \
|| grep 'No file .*\.bbl\.' "$filename_noext.log")) \
>/dev/null 2>&1; \
then
$verbose "Running $bibtex $filename_noext ..."
if $bibtex "$filename_noext" >&5; then :; else
echo "$0: $bibtex exited with bad status, quitting." >&2
exit 1
fi
fi
# What we'll run texindex on -- exclude non-index files.
# Since we know index files are last, it is correct to remove everything
# before .aux and .?o?. But don't really do <anything>o<anything>
# -- don't match whitespace as <anything>.
# Otherwise, if orig_xref_files contains something like
# foo.xo foo.whatever
# the space after the o will get matched.
index_files=`echo "$orig_xref_files" \
| sed "s!.*\.aux!!g;
s!./$filename_noext\.[^ ]o[^ ]!!g;
s/^[ ]*//;s/[ ]*$//"`
# Run texindex (or makeindex) on current index files. If they
# already exist, and after running TeX a first time the index
# files don't change, then there's no reason to run TeX again.
# But we won't know that if the index files are out of date or
# nonexistent.
if test -n "$texindex" && test -n "$index_files"; then
$verbose "Running $texindex $index_files ..."
if $texindex $index_files 2>&5 1>&2; then :; else
echo "$0: $texindex exited with bad status, quitting." >&2
exit 1
fi
fi
# Finally, run TeX.
# Prevent $ESCAPE from being interpreted by the shell if it happens
# to be `/'.
$batch tex_args="\\${escape}nonstopmode\ \\${escape}input"
cmd="$tex $tex_args $filename_input"
$verbose "Running $cmd ..."
if $cmd >&5; then :; else
echo "$0: $tex exited with bad status, quitting." >&2
echo "$0: see $filename_noext.log for errors." >&2
test "$clean" = t \
&& cp "$filename_noext.log" "$orig_pwd"
exit 1
fi
# Decide if looping again is needed.
finished=t
# LaTeX (and the package changebar) report in the LOG file if it
# should be rerun. This is needed for files included from
# subdirs, since texi2dvi does not try to compare xref files in
# subdirs. Performing xref files test is still good since LaTeX
# does not report changes in xref files.
if grep "Rerun to get" "$filename_noext.log" >/dev/null 2>&1; then
finished=
fi
# Check if xref files changed.
new_xref_files=`$get_xref_files "$filename_noext"`
$verbose "Original xref files = `echo $orig_xref_files | sed 's|\./||g'`"
$verbose "New xref files = `echo $new_xref_files | sed 's|\./||g'`"
# If old and new lists don't at least have the same file list,
# then one file or another has definitely changed.
test "x$orig_xref_files" != "x$new_xref_files" && finished=
# File list is the same. We must compare each file until we find
# a difference.
if test -n "$finished"; then
for this_file in $new_xref_files; do
$verbose "Comparing xref file `echo $this_file | sed 's|\./||g'` ..."
# cmp -s returns nonzero exit status if files differ.
if cmp -s "$this_file" "$tmpdir_bak/$this_file"; then :; else
# We only need to keep comparing until we find one that
# differs, because we'll have to run texindex & tex again no
# matter how many more there might be.
finished=
$verbose "xref file `echo $this_file | sed 's|\./||g'` differed ..."
test "$debug" = t && diff -c "$tmpdir_bak/$this_file" "$this_file"
break
fi
done
fi
# If finished, exit the loop, else rerun the loop.
test -n "$finished" && break
done
# If we were in clean mode, compilation was in a tmp directory.
# Copy the DVI (or PDF) file into the directory where the compilation
# has been done. (The temp dir is about to get removed anyway.)
# We also return to the original directory so that
# - the next file is processed in correct conditions
# - the temporary file can be removed
if test -n "$clean"; then
if test -n "$oname"; then
dest=$oname
else
dest=$orig_pwd
fi
$verbose "Copying $oformat file from `pwd` to $dest"
cp -p "./$filename_noext.$oformat" "$dest"
cd / # in case $orig_pwd is on a different drive (for DOS)
cd $orig_pwd || exit 1
fi
# Remove temporary files.
if test "x$debug" = "x"; then
$verbose "Removing $tmpdir_src $tmpdir_xtr $tmpdir_bak ..."
cd /
rm -rf $tmpdir_src $tmpdir_xtr $tmpdir_bak
fi
done
# texi2dvi ends here
$verbose "$0 done."
exit 0 # exit successfully, not however we ended the loop.

File diff suppressed because it is too large Load Diff

6688
readline/doc/texinfo.tex Normal file

File diff suppressed because it is too large Load Diff

10
readline/doc/version.texi Normal file
View File

@@ -0,0 +1,10 @@
@ignore
Copyright (C) 1988-2005 Free Software Foundation, Inc.
@end ignore
@set EDITION 5.1-beta1
@set VERSION 5.1-beta1
@set UPDATED 11 November 2005
@set UPDATED-MONTH November 2005
@set LASTCHANGE Fri Nov 11 19:50:51 EST 2005

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,22 @@
# on which program is running, or what terminal is active.
#
# Copyright (C) 1989-2002 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
# In all programs, all terminals, make sure this is bound.
"\C-x\C-r": re-read-init-file

View File

@@ -1,6 +1,24 @@
# This is the Makefile for the examples subdirectory of readline. -*- text -*-
#
SHELL = /bin/sh
# This is the Makefile for the readline examples subdirectory.
#
# Copyright (C) 1994 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
RL_LIBRARY_VERSION = @LIBVERSION@
SHELL = @MAKE_SHELL@
RM = rm -f
srcdir = @srcdir@
@@ -8,39 +26,61 @@ VPATH = .:@srcdir@
top_srcdir = @top_srcdir@
BUILD_DIR = .
# Support an alternate destination root directory for package building
DESTDIR =
DEFS = @DEFS@
CC = @CC@
CFLAGS = @CFLAGS@
LOCAL_CFLAGS = @LOCAL_CFLAGS@
LOCAL_CFLAGS = @LOCAL_CFLAGS@ -DREADLINE_LIBRARY -DRL_LIBRARY_VERSION='"$(RL_LIBRARY_VERSION)"'
CPPFLAGS = @CPPFLAGS@
INCLUDES = -I $(srcdir) -I $(top_srcdir) -I..
INCLUDES = -I$(srcdir) -I$(top_srcdir) -I..
CCFLAGS = $(DEFS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(INCLUDES) $(CFLAGS)
LDFLAGS = -g -L..
LDFLAGS = -g -L.. @LDFLAGS@
PURIFY = @PURIFY@
READLINE_LIB = ../libreadline.a
HISTORY_LIB = ../libhistory.a
TERMCAP_LIB = @TERMCAP_LIB@
.c.o:
${RM} $@
$(CC) $(CCFLAGS) -c $<
EXECUTABLES = fileman rltest rl
OBJECTS = fileman.o rltest.o rl.o
EXECUTABLES = fileman rltest rl rlcat rlversion histexamp
OBJECTS = fileman.o rltest.o rl.o rlcat.o rlversion.o histexamp.o
all: $(EXECUTABLES)
everything: all
rl: rl.o
$(CC) $(LDFLAGS) -o $@ rl.o -lreadline $(TERMCAP_LIB)
rl: rl.o $(READLINE_LIB)
$(PURIFY) $(CC) $(LDFLAGS) -o $@ rl.o $(READLINE_LIB) $(TERMCAP_LIB)
fileman: fileman.o
$(CC) $(LDFLAGS) -o $@ fileman.o -lreadline $(TERMCAP_LIB)
rlcat: rlcat.o $(READLINE_LIB)
$(PURIFY) $(CC) $(LDFLAGS) -o $@ rlcat.o $(READLINE_LIB) $(TERMCAP_LIB)
rltest: rltest.o
$(CC) $(LDFLAGS) -o $@ rltest.o -lreadline $(TERMCAP_LIB)
fileman: fileman.o $(READLINE_LIB)
$(PURIFY) $(CC) $(LDFLAGS) -o $@ fileman.o $(READLINE_LIB) $(TERMCAP_LIB)
rltest: rltest.o $(READLINE_LIB)
$(PURIFY) $(CC) $(LDFLAGS) -o $@ rltest.o $(READLINE_LIB) $(TERMCAP_LIB)
rlptytest: rlptytest.o $(READLINE_LIB)
$(PURIFY) $(CC) $(LDFLAGS) -o $@ rlptytest.o $(READLINE_LIB) $(TERMCAP_LIB)
rlversion: rlversion.o $(READLINE_LIB)
$(CC) $(LDFLAGS) -o $@ rlversion.o $(READLINE_LIB) $(TERMCAP_LIB)
histexamp: histexamp.o $(HISTORY_LIB)
$(PURIFY) $(CC) $(LDFLAGS) -o $@ histexamp.o -lhistory $(TERMCAP_LIB)
clean mostlyclean:
$(RM) $(OBJECTS)
$(RM) $(EXECUTABLES)
$(RM) $(EXECUTABLES) *.exe
distclean maintainer-clean: clean
$(RM) Makefile
@@ -48,3 +88,15 @@ distclean maintainer-clean: clean
fileman.o: fileman.c
rltest.o: rltest.c
rl.o: rl.c
rlversion.o: rlversion.c
histexamp.o: histexamp.c
rlcat.o: rlcat.c
rlptytest.o: rlptytest.c
fileman.o: $(top_srcdir)/readline.h
rltest.o: $(top_srcdir)/readline.h
rl.o: $(top_srcdir)/readline.h
rlversion.o: $(top_srcdir)/readline.h
histexamp.o: $(top_srcdir)/history.h
rlcat.o: $(top_srcdir)/readline.h $(top_srcdir)/history.h
rlptytest.o: $(top_srcdir)/readline.h $(top_srcdir)/history.h

View File

@@ -0,0 +1,188 @@
/*
From: Jeff Solomon <jsolomon@stanford.edu>
Date: Fri, 9 Apr 1999 10:13:27 -0700 (PDT)
To: chet@po.cwru.edu
Subject: new readline example
Message-ID: <14094.12094.527305.199695@mrclean.Stanford.EDU>
Chet,
I've been using readline 4.0. Specifically, I've been using the perl
version Term::ReadLine::Gnu. It works great.
Anyway, I've been playing around the alternate interface and I wanted
to contribute a little C program, callback.c, to you that you could
use as an example of the alternate interface in the /examples
directory of the readline distribution.
My example shows how, using the alternate interface, you can
interactively change the prompt (which is very nice imo). Also, I
point out that you must roll your own terminal setting when using the
alternate interface because readline depreps (using your parlance) the
terminal while in the user callback. I try to demostrate what I mean
with an example. I've included the program below.
To compile, I just put the program in the examples directory and made
the appropriate changes to the EXECUTABLES and OBJECTS line and added
an additional target 'callback'.
I compiled on my Sun Solaris2.6 box using Sun's cc.
Let me know what you think.
Jeff
*/
#if defined (HAVE_CONFIG_H)
#include <config.h>
#endif
#include <stdio.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <termios.h> /* xxx - should make this more general */
#ifdef READLINE_LIBRARY
# include "readline.h"
#else
# include <readline/readline.h>
#endif
/* This little examples demonstrates the alternate interface to using readline.
* In the alternate interface, the user maintains control over program flow and
* only calls readline when STDIN is readable. Using the alternate interface,
* you can do anything else while still using readline (like talking to a
* network or another program) without blocking.
*
* Specifically, this program highlights two importants features of the
* alternate interface. The first is the ability to interactively change the
* prompt, which can't be done using the regular interface since rl_prompt is
* read-only.
*
* The second feature really highlights a subtle point when using the alternate
* interface. That is, readline will not alter the terminal when inside your
* callback handler. So let's so, your callback executes a user command that
* takes a non-trivial amount of time to complete (seconds). While your
* executing the command, the user continues to type keystrokes and expects them
* to be re-echoed on the new prompt when it returns. Unfortunately, the default
* terminal configuration doesn't do this. After the prompt returns, the user
* must hit one additional keystroke and then will see all of his previous
* keystrokes. To illustrate this, compile and run this program. Type "sleep" at
* the prompt and then type "bar" before the prompt returns (you have 3
* seconds). Notice how "bar" is re-echoed on the prompt after the prompt
* returns? This is what you expect to happen. Now comment out the 4 lines below
* the line that says COMMENT LINE BELOW. Recompile and rerun the program and do
* the same thing. When the prompt returns, you should not see "bar". Now type
* "f", see how "barf" magically appears? This behavior is un-expected and not
* desired.
*/
void process_line(char *line);
int change_prompt(void);
char *get_prompt(void);
int prompt = 1;
char prompt_buf[40], line_buf[256];
tcflag_t old_lflag;
cc_t old_vtime;
struct termios term;
int
main()
{
fd_set fds;
/* Adjust the terminal slightly before the handler is installed. Disable
* canonical mode processing and set the input character time flag to be
* non-blocking.
*/
if( tcgetattr(STDIN_FILENO, &term) < 0 ) {
perror("tcgetattr");
exit(1);
}
old_lflag = term.c_lflag;
old_vtime = term.c_cc[VTIME];
term.c_lflag &= ~ICANON;
term.c_cc[VTIME] = 1;
/* COMMENT LINE BELOW - see above */
if( tcsetattr(STDIN_FILENO, TCSANOW, &term) < 0 ) {
perror("tcsetattr");
exit(1);
}
rl_add_defun("change-prompt", change_prompt, CTRL('t'));
rl_callback_handler_install(get_prompt(), process_line);
while(1) {
FD_ZERO(&fds);
FD_SET(fileno(stdin), &fds);
if( select(FD_SETSIZE, &fds, NULL, NULL, NULL) < 0) {
perror("select");
exit(1);
}
if( FD_ISSET(fileno(stdin), &fds) ) {
rl_callback_read_char();
}
}
}
void
process_line(char *line)
{
if( line == NULL ) {
fprintf(stderr, "\n", line);
/* reset the old terminal setting before exiting */
term.c_lflag = old_lflag;
term.c_cc[VTIME] = old_vtime;
if( tcsetattr(STDIN_FILENO, TCSANOW, &term) < 0 ) {
perror("tcsetattr");
exit(1);
}
exit(0);
}
if( strcmp(line, "sleep") == 0 ) {
sleep(3);
} else {
fprintf(stderr, "|%s|\n", line);
}
free (line);
}
int
change_prompt(void)
{
/* toggle the prompt variable */
prompt = !prompt;
/* save away the current contents of the line */
strcpy(line_buf, rl_line_buffer);
/* install a new handler which will change the prompt and erase the current line */
rl_callback_handler_install(get_prompt(), process_line);
/* insert the old text on the new line */
rl_insert_text(line_buf);
/* redraw the current line - this is an undocumented function. It invokes the
* redraw-current-line command.
*/
rl_refresh_line(0, 0);
}
char *
get_prompt(void)
{
/* The prompts can even be different lengths! */
sprintf(prompt_buf, "%s",
prompt ? "Hit ctrl-t to toggle prompt> " : "Pretty cool huh?> ");
return prompt_buf;
}

View File

@@ -1,22 +1,42 @@
/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
The GNU Readline Library is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
The GNU Readline Library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
/* fileman.c -- A tiny application which demonstrates how to use the
GNU Readline library. This application interactively allows users
to manipulate files and their modes. */
/*
* Remove the next line if you're compiling this against an installed
* libreadline.a
*/
#define READLINE_LIBRARY
#ifdef HAVE_CONFIG_H
#include <config.h>
# include <config.h>
#endif
#include <sys/types.h>
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
# include <sys/file.h>
#endif
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
@@ -26,6 +46,10 @@
# include <strings.h>
#endif /* !HAVE_STRING_H */
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef READLINE_LIBRARY
# include "readline.h"
# include "history.h"
@@ -34,19 +58,25 @@
# include <readline/history.h>
#endif
extern char *getwd ();
extern char *xmalloc ();
/* The names of functions that actually do the manipulation. */
int com_list (), com_view (), com_rename (), com_stat (), com_pwd ();
int com_delete (), com_help (), com_cd (), com_quit ();
int com_list PARAMS((char *));
int com_view PARAMS((char *));
int com_rename PARAMS((char *));
int com_stat PARAMS((char *));
int com_pwd PARAMS((char *));
int com_delete PARAMS((char *));
int com_help PARAMS((char *));
int com_cd PARAMS((char *));
int com_quit PARAMS((char *));
/* A structure which contains information on the commands this program
can understand. */
typedef struct {
char *name; /* User printable name of the function. */
Function *func; /* Function to call to do the job. */
rl_icpfunc_t *func; /* Function to call to do the job. */
char *doc; /* Documentation for this function. */
} COMMAND;
@@ -62,7 +92,7 @@ COMMAND commands[] = {
{ "rename", com_rename, "Rename FILE to NEWNAME" },
{ "stat", com_stat, "Print out statistics on FILE" },
{ "view", com_view, "View the contents of FILE" },
{ (char *)NULL, (Function *)NULL, (char *)NULL }
{ (char *)NULL, (rl_icpfunc_t *)NULL, (char *)NULL }
};
/* Forward declarations. */
@@ -202,8 +232,8 @@ stripwhite (string)
/* */
/* **************************************************************** */
char *command_generator ();
char **fileman_completion ();
char *command_generator PARAMS((const char *, int));
char **fileman_completion PARAMS((const char *, int, int));
/* Tell the GNU Readline library how to complete. We want to try to complete
on command names if this is the first word in the line, or on filenames
@@ -214,7 +244,7 @@ initialize_readline ()
rl_readline_name = "FileMan";
/* Tell the completer that we want a crack first. */
rl_attempted_completion_function = (CPPFunction *)fileman_completion;
rl_attempted_completion_function = fileman_completion;
}
/* Attempt to complete on the contents of TEXT. START and END bound the
@@ -224,7 +254,7 @@ initialize_readline ()
or NULL if there aren't any. */
char **
fileman_completion (text, start, end)
char *text;
const char *text;
int start, end;
{
char **matches;
@@ -235,7 +265,7 @@ fileman_completion (text, start, end)
to complete. Otherwise it is the name of a file in the current
directory. */
if (start == 0)
matches = completion_matches (text, command_generator);
matches = rl_completion_matches (text, command_generator);
return (matches);
}
@@ -245,7 +275,7 @@ fileman_completion (text, start, end)
start at the top of the list. */
char *
command_generator (text, state)
char *text;
const char *text;
int state;
{
static int list_index, len;
@@ -300,7 +330,12 @@ com_view (arg)
if (!valid_argument ("view", arg))
return 1;
#if defined (__MSDOS__)
/* more.com doesn't grok slashes in pathnames */
sprintf (syscom, "less %s", arg);
#else
sprintf (syscom, "more %s", arg);
#endif
return (system (syscom));
}
@@ -406,7 +441,7 @@ com_pwd (ignore)
{
char dir[1024], *s;
s = getwd (dir);
s = getcwd (dir, sizeof(dir) - 1);
if (s == 0)
{
printf ("Error getting pwd: %s\n", dir);

View File

@@ -1,9 +1,42 @@
main ()
/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
The GNU Readline Library is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
The GNU Readline Library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include <stdio.h>
#ifdef READLINE_LIBRARY
# include "history.h"
#else
# include <readline/history.h>
#endif
#include <string.h>
main (argc, argv)
int argc;
char **argv;
{
char line[1024], *t;
int len, done = 0;
int len, done;
line[0] = 0;
done = 0;
using_history ();
while (!done)
@@ -12,71 +45,80 @@ main ()
fflush (stdout);
t = fgets (line, sizeof (line) - 1, stdin);
if (t && *t)
{
len = strlen (t);
if (t[len - 1] == '\n')
t[len - 1] = '\0';
}
{
len = strlen (t);
if (t[len - 1] == '\n')
t[len - 1] = '\0';
}
if (!t)
strcpy (line, "quit");
strcpy (line, "quit");
if (line[0])
{
char *expansion;
int result;
{
char *expansion;
int result;
using_history ();
using_history ();
result = history_expand (line, &expansion);
if (result)
fprintf (stderr, "%s\n", expansion);
result = history_expand (line, &expansion);
if (result)
fprintf (stderr, "%s\n", expansion);
if (result < 0 || result == 2)
{
free (expansion);
continue;
}
if (result < 0 || result == 2)
{
free (expansion);
continue;
}
add_history (expansion);
strncpy (line, expansion, sizeof (line) - 1);
free (expansion);
}
add_history (expansion);
strncpy (line, expansion, sizeof (line) - 1);
free (expansion);
}
if (strcmp (line, "quit") == 0)
done = 1;
done = 1;
else if (strcmp (line, "save") == 0)
write_history ("history_file");
write_history ("history_file");
else if (strcmp (line, "read") == 0)
read_history ("history_file");
read_history ("history_file");
else if (strcmp (line, "list") == 0)
{
register HIST_ENTRY **the_list;
register int i;
{
register HIST_ENTRY **the_list;
register int i;
time_t tt;
char timestr[128];
the_list = history_list ();
if (the_list)
for (i = 0; the_list[i]; i++)
printf ("%d: %s\n", i + history_base, the_list[i]->line);
}
the_list = history_list ();
if (the_list)
for (i = 0; the_list[i]; i++)
{
tt = history_get_time (the_list[i]);
if (tt)
strftime (timestr, sizeof (timestr), "%a %R", localtime(&tt));
else
strcpy (timestr, "??");
printf ("%d: %s: %s\n", i + history_base, timestr, the_list[i]->line);
}
}
else if (strncmp (line, "delete", 6) == 0)
{
int which;
if ((sscanf (line + 6, "%d", &which)) == 1)
{
HIST_ENTRY *entry = remove_history (which);
if (!entry)
fprintf (stderr, "No such entry %d\n", which);
else
{
free (entry->line);
free (entry);
}
}
else
{
fprintf (stderr, "non-numeric arg given to `delete'\n");
}
}
{
int which;
if ((sscanf (line + 6, "%d", &which)) == 1)
{
HIST_ENTRY *entry = remove_history (which);
if (!entry)
fprintf (stderr, "No such entry %d\n", which);
else
{
free (entry->line);
free (entry);
}
}
else
{
fprintf (stderr, "non-numeric arg given to `delete'\n");
}
}
}
}

View File

@@ -1,12 +1,31 @@
/* manexamp.c -- The examples which appear in the documentation are here. */
/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
The GNU Readline Library is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
The GNU Readline Library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include <stdio.h>
#include <readline/readline.h>
/* **************************************************************** */
/* */
* How to Emulate gets () */
/* How to Emulate gets () */
/* */
/* **************************************************************** */
@@ -82,13 +101,12 @@ invert_case_line (count, key)
for (; start != end; start += direction)
{
if (uppercase_p (rl_line_buffer[start]))
rl_line_buffer[start] = to_lower (rl_line_buffer[start]);
else if (lowercase_p (rl_line_buffer[start]))
rl_line_buffer[start] = to_upper (rl_line_buffer[start]);
if (_rl_uppercase_p (rl_line_buffer[start]))
rl_line_buffer[start] = _rl_to_lower (rl_line_buffer[start]);
else if (_rl_lowercase_p (rl_line_buffer[start]))
rl_line_buffer[start] = _rl_to_upper (rl_line_buffer[start]);
}
/* Move point to on top of the last character changed. */
rl_point = end - direction;
}

View File

@@ -0,0 +1,139 @@
/*******************************************************************************
* $Revision$
* $Date$
* $Author$
*
* Contents: A streambuf which uses the GNU readline library for line I/O
* (c) 2001 by Dimitris Vyzovitis [vyzo@media.mit.edu]
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
******************************************************************************/
#ifndef _READLINEBUF_H_
#define _READLINEBUF_H_
#include <iostream>
#include <cstring>
#include <cassert>
#include <cstdlib>
#include <cstdio>
#include <readline/readline.h>
#include <readline/history.h>
#if (defined __GNUC__) && (__GNUC__ < 3)
#include <streambuf.h>
#else
#include <streambuf>
using std::streamsize;
using std::streambuf;
#endif
class readlinebuf : public streambuf {
public:
#if (defined __GNUC__) && (__GNUC__ < 3)
typedef char char_type;
typedef int int_type;
typedef streampos pos_type;
typedef streamoff off_type;
#endif
static const int_type eof = EOF; // this is -1
static const int_type not_eof = 0;
private:
const char* prompt_;
bool history_;
char* line_;
int low_;
int high_;
protected:
virtual int_type showmanyc() const { return high_ - low_; }
virtual streamsize xsgetn( char_type* buf, streamsize n ) {
int rd = n > (high_ - low_)? (high_ - low_) : n;
memcpy( buf, line_, rd );
low_ += rd;
if ( rd < n ) {
low_ = high_ = 0;
free( line_ ); // free( NULL ) is a noop
line_ = readline( prompt_ );
if ( line_ ) {
high_ = strlen( line_ );
if ( history_ && high_ ) add_history( line_ );
rd += xsgetn( buf + rd, n - rd );
}
}
return rd;
}
virtual int_type underflow() {
if ( high_ == low_ ) {
low_ = high_ = 0;
free( line_ ); // free( NULL ) is a noop
line_ = readline( prompt_ );
if ( line_ ) {
high_ = strlen( line_ );
if ( history_ && high_ ) add_history( line_ );
}
}
if ( low_ < high_ ) return line_[low_];
else return eof;
}
virtual int_type uflow() {
int_type c = underflow();
if ( c != eof ) ++low_;
return c;
}
virtual int_type pbackfail( int_type c = eof ) {
if ( low_ > 0 ) --low_;
else if ( c != eof ) {
if ( high_ > 0 ) {
char* nl = (char*)realloc( line_, high_ + 1 );
if ( nl ) {
line_ = (char*)memcpy( nl + 1, line_, high_ );
high_ += 1;
line_[0] = char( c );
} else return eof;
} else {
assert( !line_ );
line_ = (char*)malloc( sizeof( char ) );
*line_ = char( c );
high_ = 1;
}
} else return eof;
return not_eof;
}
public:
readlinebuf( const char* prompt = NULL, bool history = true )
: prompt_( prompt ), history_( history ),
line_( NULL ), low_( 0 ), high_( 0 ) {
setbuf( 0, 0 );
}
};
#endif

View File

@@ -0,0 +1,374 @@
/*
Date: Tue, 16 Mar 2004 19:38:40 -0800
From: Harold Levy <Harold.Levy@synopsys.com>
Subject: fgets(stdin) --> readline() redirector
To: chet@po.cwru.edu
Hi Chet,
Here is something you may find useful enough to include in the readline
distribution. It is a shared library that redirects calls to fgets(stdin)
to readline() via LD_PRELOAD, and it supports a custom prompt and list of
command names. Many people have asked me for this file, so I thought I'd
pass it your way in hope of just including it with readline to begin with.
Best Regards,
-Harold
*/
/******************************************************************************
*******************************************************************************
FILE NAME: fgets.c TARGET: libfgets.so
AUTHOR: Harold Levy VERSION: 1.0
hlevy@synopsys.com
ABSTRACT: Customize fgets() behavior via LD_PRELOAD in the following ways:
-- If fgets(stdin) is called, redirect to GNU readline() to obtain
command-line editing, file-name completion, history, etc.
-- A list of commands for command-name completion can be configured by
setting the environment-variable FGETS_COMMAND_FILE to a file containing
the list of commands to be used.
-- Command-line editing with readline() works best when the prompt string
is known; you can set this with the FGETS_PROMPT environment variable.
-- There special strings that libfgets will interpret as internal commands:
_fgets_reset_ reset the command list
_fgets_dump_ dump status
_fgets_debug_ toggle debug messages
HOW TO BUILD: Here are examples of how to build libfgets.so on various
platforms; you will have to add -I and -L flags to configure access to
the readline header and library files.
(32-bit builds with gcc)
AIX: gcc -fPIC fgets.c -shared -o libfgets.so -lc -ldl -lreadline -ltermcap
HP-UX: gcc -fPIC fgets.c -shared -o libfgets.so -lc -ldld -lreadline
Linux: gcc -fPIC fgets.c -shared -o libfgets.so -lc -ldl -lreadline
SunOS: gcc -fPIC fgets.c -shared -o libfgets.so -lc -ldl -lgen -lreadline
(64-bit builds without gcc)
SunOS: SUNWspro/bin/cc -D_LARGEFILE64_SOURCE=1 -xtarget=ultra -xarch=v9 \
-KPIC fgets.c -Bdynamic -lc -ldl -lgen -ltermcap -lreadline
HOW TO USE: Different operating systems have different levels of support
for the LD_PRELOAD concept. The generic method for 32-bit platforms is to
put libtermcap.so, libfgets.so, and libreadline.so (with absolute paths)
in the LD_PRELOAD environment variable, and to put their parent directories
in the LD_LIBRARY_PATH environment variable. Unfortunately there is no
generic method for 64-bit platforms; e.g. for 64-bit SunOS, you would have
to build both 32-bit and 64-bit libfgets and libreadline libraries, and
use the LD_FLAGS_32 and LD_FLAGS_64 environment variables with preload and
library_path configurations (a mix of 32-bit and 64-bit calls are made under
64-bit SunOS).
EXAMPLE WRAPPER: Here is an example shell script wrapper around the
program "foo" that uses fgets() for command-line input:
#!/bin/csh
#### replace this with the libtermcap.so directory:
set dir1 = "/usr/lib"
#### replace this with the libfgets.so directory:
set dir2 = "/usr/fgets"
#### replace this with the libreadline.so directory:
set dir3 = "/usr/local/lib"
set lib1 = "${dir1}/libtermcap.so"
set lib2 = "${dir2}/libfgets.so"
set lib3 = "${dir3}/libreadline.so"
if ( "${?LD_PRELOAD}" ) then
setenv LD_PRELOAD "${lib1}:${lib2}:${lib3}:${LD_PRELOAD}"
else
setenv LD_PRELOAD "${lib1}:${lib2}:${lib3}"
endif
if ( "${?LD_LIBRARY_PATH}" ) then
setenv LD_LIBRARY_PATH "${dir1}:${dir2}:${dir3}:${LD_LIBRARY_PATH}"
else
setenv LD_LIBRARY_PATH "${dir1}:${dir2}:${dir3}"
endif
setenv FGETS_COMMAND_FILE "${dir2}/foo.commands"
setenv FGETS_PROMPT "foo> "
exec "foo" $*
Copyright (C)<29>2003-2004 Harold Levy.
This code links to the GNU readline library, and as such is bound by the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 2 or (at your option) any later version.
The GNU General Public License is often shipped with GNU software, and is
generally kept in a file called COPYING or LICENSE. If you do not have a
copy of the license, write to the Free Software Foundation, 59 Temple Place,
Suite 330, Boston, MA 02111 USA.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
*******************************************************************************
******************************************************************************/
#include <dlfcn.h>
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <unistd.h>
#include <readline/readline.h>
#include <readline/history.h>
/* for dynamically connecting to the native fgets() */
#if defined(RTLD_NEXT)
#define REAL_LIBC RTLD_NEXT
#else
#define REAL_LIBC ((void *) -1L)
#endif
typedef char * ( * fgets_t ) ( char * s, int n, FILE * stream ) ;
/* private data */
/* -- writeable data is stored in the shared library's data segment
-- every process that uses the shared library gets a private memory copy of
its entire data segment
-- static data in the shared library is not copied to the application
-- only read-only (i.e. 'const') data is stored in the shared library's
text segment
*/
static char ** my_fgets_names = NULL ;
static int my_fgets_number_of_names = 0 ;
static int my_fgets_debug_flag = 0 ;
/* invoked with _fgets_reset_ */
static void
my_fgets_reset (
void
) {
if ( my_fgets_names && (my_fgets_number_of_names > 0) ) {
int i ;
if ( my_fgets_debug_flag ) {
printf ( "libfgets: removing command list\n" ) ;
}
for ( i = 0 ; i < my_fgets_number_of_names ; i ++ ) {
if ( my_fgets_names[i] ) free ( my_fgets_names[i] ) ;
}
free ( my_fgets_names ) ;
}
my_fgets_names = NULL ;
my_fgets_number_of_names = 0 ;
}
/* invoked with _fgets_dump_ */
static void
my_fgets_dump (
void
) {
char * s ;
printf ( "\n" ) ;
s = getenv ( "FGETS_PROMPT" ) ;
printf ( "FGETS_PROMPT = %s\n", s ? s : "" ) ;
s = getenv ( "FGETS_COMMAND_FILE" ) ;
printf ( "FGETS_COMMAND_FILE = %s\n", s ? s : "" ) ;
printf ( "debug flag = %d\n", my_fgets_debug_flag ) ;
printf ( "#commands = %d\n", my_fgets_number_of_names ) ;
if ( my_fgets_debug_flag ) {
if ( my_fgets_names && (my_fgets_number_of_names > 0) ) {
int i ;
for ( i = 0 ; i < my_fgets_number_of_names ; i ++ ) {
printf ( "%s\n", my_fgets_names[i] ) ;
}
}
}
printf ( "\n" ) ;
}
/* invoked with _fgets_debug_ */
static void
my_fgets_debug_toggle (
void
) {
my_fgets_debug_flag = my_fgets_debug_flag ? 0 : 1 ;
if ( my_fgets_debug_flag ) {
printf ( "libfgets: debug flag = %d\n", my_fgets_debug_flag ) ;
}
}
/* read the command list if needed, return the i-th name */
static char *
my_fgets_lookup (
int index
) {
if ( (! my_fgets_names) || (! my_fgets_number_of_names) ) {
char * fname ;
FILE * fp ;
fgets_t _fgets ;
int i ;
char buf1[256], buf2[256] ;
fname = getenv ( "FGETS_COMMAND_FILE" ) ;
if ( ! fname ) {
if ( my_fgets_debug_flag ) {
printf ( "libfgets: empty or unset FGETS_COMMAND_FILE\n" ) ;
}
return NULL ;
}
fp = fopen ( fname, "r" ) ;
if ( ! fp ) {
if ( my_fgets_debug_flag ) {
printf ( "libfgets: cannot open '%s' for reading\n", fname ) ;
}
return NULL ;
}
_fgets = (fgets_t) dlsym ( REAL_LIBC, "fgets" ) ;
if ( ! _fgets ) {
fprintf ( stderr,
"libfgets: failed to dynamically link to native fgets()\n"
) ;
return NULL ;
}
for ( i = 0 ; _fgets(buf1,255,fp) ; i ++ ) ;
if ( ! i ) { fclose(fp) ; return NULL ; }
my_fgets_names = (char**) calloc ( i, sizeof(char*) ) ;
rewind ( fp ) ;
i = 0 ;
while ( _fgets(buf1,255,fp) ) {
buf1[255] = 0 ;
if ( 1 == sscanf(buf1,"%s",buf2) ) {
my_fgets_names[i] = strdup(buf2) ;
i ++ ;
}
}
fclose ( fp ) ;
my_fgets_number_of_names = i ;
if ( my_fgets_debug_flag ) {
printf ( "libfgets: successfully read %d commands\n", i ) ;
}
}
if ( index < my_fgets_number_of_names ) {
return my_fgets_names[index] ;
} else {
return NULL ;
}
}
/* generate a list of partial name matches for readline() */
static char *
my_fgets_generator (
const char * text,
int state
)
{
static int list_index, len ;
char * name ;
if ( ! state ) {
list_index = 0 ;
len = strlen ( text ) ;
}
while ( ( name = my_fgets_lookup(list_index) ) ) {
list_index ++ ;
if ( ! strncmp ( name, text, len ) ) {
return ( strdup ( name ) ) ;
}
}
return ( NULL ) ;
}
/* partial name completion callback for readline() */
static char **
my_fgets_completion (
const char * text,
int start,
int end
)
{
char ** matches ;
matches = NULL ;
if ( ! start ) {
matches = rl_completion_matches ( text, my_fgets_generator ) ;
}
return ( matches ) ;
}
/* fgets() intercept */
char *
fgets (
char * s,
int n,
FILE * stream
)
{
if ( ! s ) return NULL ;
if ( stream == stdin ) {
char * prompt ;
char * my_fgets_line ;
rl_already_prompted = 1 ;
rl_attempted_completion_function = my_fgets_completion ;
rl_catch_signals = 1 ;
rl_catch_sigwinch = 1 ;
rl_set_signals () ;
prompt = getenv ( "FGETS_PROMPT" ) ;
for (
my_fgets_line = 0 ; ! my_fgets_line ; my_fgets_line=readline(prompt)
) ;
if ( ! strncmp(my_fgets_line, "_fgets_reset_", 13) ) {
my_fgets_reset () ;
free ( my_fgets_line ) ;
strcpy ( s, "\n" ) ;
return ( s ) ;
}
if ( ! strncmp(my_fgets_line, "_fgets_dump_", 12) ) {
my_fgets_dump () ;
free ( my_fgets_line ) ;
strcpy ( s, "\n" ) ;
return ( s ) ;
}
if ( ! strncmp(my_fgets_line, "_fgets_debug_", 13) ) {
my_fgets_debug_toggle () ;
free ( my_fgets_line ) ;
strcpy ( s, "\n" ) ;
return ( s ) ;
}
(void) strncpy ( s, my_fgets_line, n-1 ) ;
(void) strcat ( s, "\n" ) ;
if ( *my_fgets_line ) add_history ( my_fgets_line ) ;
free ( my_fgets_line ) ;
return ( s ) ;
} else {
static fgets_t _fgets ;
_fgets = (fgets_t) dlsym ( REAL_LIBC, "fgets" ) ;
if ( ! _fgets ) {
fprintf ( stderr,
"libfgets: failed to dynamically link to native fgets()\n"
) ;
strcpy ( s, "\n" ) ;
return ( s ) ;
}
return (
_fgets ( s, n, stream )
) ;
}
}

View File

@@ -2,14 +2,28 @@
* rl - command-line interface to read a line from the standard input
* (or another fd) using readline.
*
* usage: rl [-p prompt] [-u unit] [-d default]
* usage: rl [-p prompt] [-u unit] [-d default] [-n nchars]
*/
/*
* Remove the next line if you're compiling this against an installed
* libreadline.a
*/
#define READLINE_LIBRARY
/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
The GNU Readline Library is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
The GNU Readline Library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#if defined (HAVE_CONFIG_H)
# include <config.h>
@@ -17,9 +31,22 @@
#include <stdio.h>
#include <sys/types.h>
#include "posixstat.h"
#include "readline.h"
#include "history.h"
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#else
extern void exit();
#endif
#if defined (READLINE_LIBRARY)
# include "posixstat.h"
# include "readline.h"
# include "history.h"
#else
# include <sys/stat.h>
# include <readline/readline.h>
# include <readline/history.h>
#endif
extern int optind;
extern char *optarg;
@@ -38,23 +65,26 @@ set_deftext ()
{
rl_insert_text (deftext);
deftext = (char *)NULL;
rl_startup_hook = (Function *)NULL;
rl_startup_hook = (rl_hook_func_t *)NULL;
}
return 0;
}
static void
usage()
{
fprintf (stderr, "%s: usage: %s [-p prompt] [-u unit] [-d default]\n",
fprintf (stderr, "%s: usage: %s [-p prompt] [-u unit] [-d default] [-n nchars]\n",
progname, progname);
}
int
main (argc, argv)
int argc;
char **argv;
{
char *temp, *prompt;
struct stat sb;
int done, opt, fd;
int opt, fd, nch;
FILE *ifp;
progname = strrchr(argv[0], '/');
@@ -65,10 +95,10 @@ main (argc, argv)
/* defaults */
prompt = "readline$ ";
fd = 0;
fd = nch = 0;
deftext = (char *)0;
while ((opt = getopt(argc, argv, "p:u:d:")) != EOF)
while ((opt = getopt(argc, argv, "p:u:d:n:")) != EOF)
{
switch (opt)
{
@@ -86,6 +116,14 @@ main (argc, argv)
case 'd':
deftext = optarg;
break;
case 'n':
nch = atoi(optarg);
if (nch < 0)
{
fprintf (stderr, "%s: bad value for -n: `%s'\n", progname, optarg);
exit (2);
}
break;
default:
usage ();
exit (2);
@@ -106,12 +144,15 @@ main (argc, argv)
if (deftext && *deftext)
rl_startup_hook = set_deftext;
if (nch > 0)
rl_num_chars_to_read = nch;
temp = readline (prompt);
/* Test for EOF. */
if (temp == 0)
exit (1);
puts (temp);
printf ("%s\n", temp);
exit (0);
}

180
readline/examples/rlcat.c Normal file
View File

@@ -0,0 +1,180 @@
/*
* rlcat - cat(1) using readline
*
* usage: rlcat
*/
/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
The GNU Readline Library is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
The GNU Readline Library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#if defined (HAVE_CONFIG_H)
# include <config.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/types.h>
#include "posixstat.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#else
extern void exit();
#endif
#ifndef errno
extern int errno;
#endif
#if defined (READLINE_LIBRARY)
# include "readline.h"
# include "history.h"
#else
# include <readline/readline.h>
# include <readline/history.h>
#endif
extern int optind;
extern char *optarg;
static int stdcat();
static char *progname;
static int vflag;
static void
usage()
{
fprintf (stderr, "%s: usage: %s [-vEVN] [filename]\n", progname, progname);
}
int
main (argc, argv)
int argc;
char **argv;
{
char *temp;
int opt, Vflag, Nflag;
progname = strrchr(argv[0], '/');
if (progname == 0)
progname = argv[0];
else
progname++;
vflag = Vflag = Nflag = 0;
while ((opt = getopt(argc, argv, "vEVN")) != EOF)
{
switch (opt)
{
case 'v':
vflag = 1;
break;
case 'V':
Vflag = 1;
break;
case 'E':
Vflag = 0;
break;
case 'N':
Nflag = 1;
break;
default:
usage ();
exit (2);
}
}
argc -= optind;
argv += optind;
if (isatty(0) == 0 || argc || Nflag)
return stdcat(argc, argv);
rl_variable_bind ("editing-mode", Vflag ? "vi" : "emacs");
while (temp = readline (""))
{
if (*temp)
add_history (temp);
printf ("%s\n", temp);
}
return (ferror (stdout));
}
static int
fcopy(fp)
FILE *fp;
{
int c;
char *x;
while ((c = getc(fp)) != EOF)
{
if (vflag && isascii ((unsigned char)c) && isprint((unsigned char)c) == 0)
{
x = rl_untranslate_keyseq (c);
if (fputs (x, stdout) != 0)
return 1;
}
else if (putchar (c) == EOF)
return 1;
}
return (ferror (stdout));
}
int
stdcat (argc, argv)
int argc;
char **argv;
{
int i, fd, r;
char *s;
FILE *fp;
if (argc == 0)
return (fcopy(stdin));
for (i = 0, r = 1; i < argc; i++)
{
if (*argv[i] == '-' && argv[i][1] == 0)
fp = stdin;
else
{
fp = fopen (argv[i], "r");
if (fp == 0)
{
fprintf (stderr, "%s: %s: cannot open: %s\n", progname, argv[i], strerror(errno));
continue;
}
}
r = fcopy (fp);
if (fp != stdin)
fclose(fp);
}
return r;
}

1042
readline/examples/rlfe.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,37 @@
2004-11-04 Per Bothner <per@bothner.com>
* pty.c: Import from screen-4.0.2.
* configure.in, Makefile.in, config.h.in: Set up autoconf handling,
copying a bunk of stuff over from screen.
* rlfe.c: Use OpenPTY from pty.c instead of get_master_pty.
2004-11-03 Per Bothner <per@bothner.com>
* rlfe.c: Get input emphasis (boldening) more robust.
* rlfe.c: Various cleanups on comments and names.
2003-11-07 Wolfgang Taeuber <wolfgang_taeuber@agilent.com>
* Specify a history file and the size of the history file with command
* line options; use EDITOR/VISUAL to set vi/emacs preference.
1999-09-03 Chet Ramey <chet@nike.ins.cwru.edu>
* fep.c: Memmove is not universally available. This patch assumes
that an autoconf test has been performed, and that memcpy is
available without checking.
* fep.c: VDISCARD is not universally available, even when termios is.
* fep.c: If a system doesn't have TIOCSCTTY, the first `open'
performed after setsid allocates a controlling terminal. The
original code would leave the child process running on the slave pty
without a controlling tty if TIOCSCTTY was not available.
* fep.c: Most versions of SVR4, including solaris, don't allow
terminal ioctl calls on the master side of the pty.
1999-08-28 Per Bothner <per@bothner.com>
* fep.c: Initial release.

View File

@@ -0,0 +1,176 @@
#
# Makefile template for rlfe
#
# See machine dependant config.h for more configuration options.
#
srcdir = @srcdir@
VPATH = @srcdir@
DESTDIR =
# Where to install screen.
prefix = @prefix@
exec_prefix = @exec_prefix@
# don't forget to change mandir and infodir in doc/Makefile.
bindir = $(exec_prefix)/bin
VERSION = @VERSION@
SCREEN = screen-$(VERSION)
CC = @CC@
CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@
#LDFLAGS = -L$(READLINE_DIR)
LDFLAGS = @LDFLAGS@
LIBS = -lreadline -lhistory -lncurses
CPP=@CPP@
CPP_DEPEND=$(CC) -MM
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
AWK = @AWK@
OPTIONS=
#OPTIONS= -DDEBUG
SHELL=/bin/sh
CFILES= rlfe.c pty.c
HFILES= extern.h os.h screen.h
EXTRA_DIST=configure.in configure Makefile.in config.h.in ChangeLog README
OFILES= rlfe.o pty.o
all: rlfe
rlfe: $(OFILES)
$(CC) $(LDFLAGS) -o $@ $(OFILES) $(LIBS)
rlfe-$(VERSION).tar.gz:
tar czf $@ $(CFILES) $(HFILES) $(EXTRA_DIST)
.c.o:
$(CC) -c -I. -I$(srcdir) $(M_CFLAGS) $(DEFS) $(OPTIONS) $(CFLAGS) $<
install_bin: .version screen
-if [ -f $(DESTDIR)$(bindir)/$(SCREEN) ] && [ ! -f $(DESTDIR)$(bindir)/$(SCREEN).old ]; \
then mv $(DESTDIR)$(bindir)/$(SCREEN) $(DESTDIR)$(bindir)/$(SCREEN).old; fi
$(INSTALL_PROGRAM) screen $(DESTDIR)$(bindir)/$(SCREEN)
-chown root $(DESTDIR)$(bindir)/$(SCREEN) && chmod 4755 $(DESTDIR)$(bindir)/$(SCREEN)
# This doesn't work if $(bindir)/screen is a symlink
-if [ -f $(DESTDIR)$(bindir)/screen ] && [ ! -f $(DESTDIR)$(bindir)/screen.old ]; then mv $(DESTDIR)$(bindir)/screen $(DESTDIR)$(bindir)/screen.old; fi
rm -f $(DESTDIR)$(bindir)/screen
(cd $(DESTDIR)$(bindir) && ln -sf $(SCREEN) screen)
cp $(srcdir)/utf8encodings/?? $(DESTDIR)$(SCREENENCODINGS)
uninstall: .version
rm -f $(DESTDIR)$(bindir)/$(SCREEN)
rm -f $(DESTDIR)$(bindir)/screen
-mv $(DESTDIR)$(bindir)/screen.old $(DESTDIR)$(bindir)/screen
rm -f $(DESTDIR)$(ETCSCREENRC)
cd doc; $(MAKE) uninstall
shadow:
mkdir shadow;
cd shadow; ln -s ../*.[ch] ../*.in ../*.sh ../configure ../doc ../terminfo ../etc .
rm -f shadow/term.h shadow/tty.c shadow/comm.h shadow/osdef.h
echo "install all Makefiles and config:" > shadow/Makefile
echo " rm -f config.cache" >> shadow/Makefile
echo " sh ./configure" >> shadow/Makefile
term.h: term.c term.sh
AWK=$(AWK) srcdir=$(srcdir) sh $(srcdir)/term.sh
kmapdef.c: term.h
tty.c: tty.sh
sh $(srcdir)/tty.sh tty.c
mostlyclean:
rm -f $(OFILES) rlfe *.o
clean celan: mostlyclean
rm -f tty.c term.h comm.h osdef.h kmapdef.c core
# Delete all files from the current directory that are created by
# configuring or building the program.
# building of term.h/comm.h requires awk. Keep it in the distribution
# we keep config.h, as this file knows where 'make dist' finds the ETCSCREENRC.
#distclean: mostlyclean
# rm -f $(SCREEN).tar $(SCREEN).tar.gz
# rm -f config.status Makefile
# rm -f osdef.h doc/Makefile
maintainer-clean:
@echo "This command is not even intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
# Delete everything from the current directory that can be
# reconstructed with this Makefile.
realclean: .version mostlyclean
rm -f $(SCREEN).tar $(SCREEN).tar.gz
rm -f config.status Makefile doc/Makefile
rm -f tty.c term.h comm.h osdef.h kmapdef.c
rm -f config.h
echo "install all Makefiles and config:" > Makefile
echo " sh ./configure" >> Makefile
tags TAGS: $(CFILES)
-ctags *.sh $(CFILES) *.h
-ctags -e *.sh $(CFILES) *.h
dist: .version $(SCREEN).tar.gz
# Perform self-tests (if any).
check:
config:
rm -f config.cache
sh ./configure
###############################################################################
.version:
@rev=`sed < $(srcdir)/patchlevel.h -n -e '/#define REV/s/#define REV *//p'`; \
vers=`sed < $(srcdir)/patchlevel.h -n -e '/#define VERS/s/#define VERS *//p'`; \
pat=`sed < $(srcdir)/patchlevel.h -n -e '/#define PATCHLEVEL/s/#define PATCHLEVEL *//p'`; \
if [ "$${rev}.$${vers}.$${pat}" != "$(VERSION)" ]; then \
echo "This distribution is screen-$${rev}.$${vers}.$${pat}, but"; \
echo "the Makefile is from $(VERSION). Please update!"; exit 1; fi
###############################################################################
mdepend: $(CFILES) term.h
@rm -f DEPEND ; \
for i in ${CFILES} ; do \
echo "$$i" ; \
echo `echo "$$i" | sed -e 's/.c$$/.o/'`": $$i" `\
cc -E $$i |\
grep '^# .*"\./.*\.h"' |\
(sort -t'"' -u -k 2,2 2>/dev/null || sort -t'"' -u +1 -2) |\
sed -e 's/.*"\.\/\(.*\)".*/\1/'\
` >> DEPEND ; \
done
depend: depend.in
./config.status || ./configure
depend.in: $(CFILES) term.h
cp Makefile.in Makefile.in~
sed -e '/\#\#\# Dependencies/q' < Makefile.in > tmp_make
for i in $(CFILES); do echo $$i; $(CPP_DEPEND) $$i >> tmp_make; done
mv tmp_make Makefile.in
###############################################################################
### Dependencies:
pty.o: pty.c config.h

View File

@@ -0,0 +1,78 @@
rlfe (ReadLine Front-End) is a "universal wrapper" around readline.
You specify an interactive program to run (typically a shell), and
readline is used to edit input lines.
There are other such front-ends; what distinguishes this one is that
it monitors the state of the inferior pty, and if the inferior program
switches its terminal to raw mode, then rlfe passes your characters
through directly. This basically means you can run your entire
session (including bash and terminal-mode emacs) under rlfe.
FEATURES
* Can use all readline commands (and history) in commands that
read input lines in "canonical mode" - even 'cat'!
* Automatically switches between "readline-editing mode" and "raw mode"
depending on the terminal mode. If the inferior program invokes
readline itself, it will do its own line editing. (The inferior
readline will not know about rlfe, and it will have its own history.)
You can even run programs like 'emavs -nw' and 'vi' under rlfe.
The goal is you could leave rlfe always on without even knowing
about it. (We're not quite there, but it works tolerably well.)
* The input line (after any prompt) is changed to bold-face.
INSTALL
The usual: ./configure && make && make install
Note so far rlfe has only been tested on GNU Linux (Fedora Core 2)
and Mac OS X (10.3).
This assumes readline header files and libraries are in the default
places. If not, you can create a link named readline pointing to the
readline sources. To link with libreadline.a and libhistory.a
you can copy or link them, or add LDFLAGS='-/path/to/readline' to
the make command-line.
USAGE
Just run it. That by default runs bash. You can run some other
command by giving it as command-line arguments.
There are a few tweaks: -h allows you to name the history file,
and -s allows you to specify its size. It default to "emacs" mode,
but if the the environment variable EDITOR is set to "vi" that
mode is chosen.
ISSUES
* The mode switching depends on the terminal mode set by the inferior
program. Thus ssh/telnet/screen-type programs will typically be in
raw mode, so rlfe won't be much use, even if remote programs run in
canonical mode. The work-around is to run rlfe on the remote end.
* Echo supression and prompt recognition are somewhat fragile.
(A protocol so that the o/s tty code can reliably communicate its
state to rlfe could solve this problem, and the previous one.)
* See the intro to rlfe.c for more notes.
* Assumes a VT100-compatible terminal, though that could be generalized
if anybody cares.
* Requires ncurses.
* It would be useful to integrate rlfe's logic in a terminal emulator.
That would make it easier to reposition the edit position with a mouse,
integrate cut-and-paste with the system clipboard, and more robustly
handle escape sequence and multi-byte characters more robustly.
AUTHOR
Per Bothner <per@bothner.com>
LICENSE
GPL.

View File

@@ -0,0 +1,375 @@
/* Copyright 2004 Per Bothner <per@bothner.com>
* Based on config.h from screen-4.0.2.
* Copyright (c) 1993-2000
* Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
* Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
* Copyright (c) 1987 Oliver Laumann
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (see the file COPYING); if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
****************************************************************
* $Id$ FAU
*/
/**********************************************************************
*
* User Configuration Section
*/
/*
* define PTYMODE if you do not like the default of 0622, which allows
* public write to your pty.
* define PTYGROUP to some numerical group-id if you do not want the
* tty to be in "your" group.
* Note, screen is unable to change mode or group of the pty if it
* is not installed with sufficient privilege. (e.g. set-uid-root)
* define PTYROFS if the /dev/pty devices are mounted on a read-only
* filesystem so screen should not even attempt to set mode or group
* even if running as root (e.g. on TiVo).
*/
#undef PTYMODE
#undef PTYGROUP
#undef PTYROFS
/*
* If screen is NOT installed set-uid root, screen can provide tty
* security by exclusively locking the ptys. While this keeps other
* users from opening your ptys, it also keeps your own subprocesses
* from being able to open /dev/tty. Define LOCKPTY to add this
* exclusive locking.
*/
#undef LOCKPTY
/**********************************************************************
*
* End of User Configuration Section
*
* Rest of this file is modified by 'configure'
* Change at your own risk!
*
*/
/*
* Some defines to identify special unix variants
*/
#ifndef SVR4
#undef SVR4
#endif
#ifndef _POSIX_SOURCE
#undef _POSIX_SOURCE
#endif
/*
* Define POSIX if your system supports IEEE Std 1003.1-1988 (POSIX).
*/
#undef POSIX
/*
* Define TERMIO if you have struct termio instead of struct sgttyb.
* This is usually the case for SVID systems, where BSD uses sgttyb.
* POSIX systems should define this anyway, even though they use
* struct termios.
*/
#undef TERMIO
/*
* Define CYTERMIO if you have cyrillic termio modes.
*/
#undef CYTERMIO
/*
* Define TERMINFO if your machine emulates the termcap routines
* with the terminfo database.
* Thus the .screenrc file is parsed for
* the command 'terminfo' and not 'termcap'.
*/
#undef TERMINFO
/*
* If your library does not define ospeed, define this.
*/
#undef NEED_OSPEED
/*
* Define SYSV if your machine is SYSV complient (Sys V, HPUX, A/UX)
*/
#ifndef SYSV
#undef SYSV
#endif
/*
* Define SIGVOID if your signal handlers return void. On older
* systems, signal returns int, but on newer ones, it returns void.
*/
#undef SIGVOID
/*
* Define USESIGSET if you have sigset for BSD 4.1 reliable signals.
*/
#undef USESIGSET
/*
* Define SYSVSIGS if signal handlers must be reinstalled after
* they have been called.
*/
#undef SYSVSIGS
/*
* Define BSDWAIT if your system defines a 'union wait' in <sys/wait.h>
*
* Only allow BSDWAIT i.e. wait3 on nonposix systems, since
* posix implies wait(3) and waitpid(3). vdlinden@fwi.uva.nl
*
*/
#ifndef POSIX
#undef BSDWAIT
#endif
/*
* On RISCOS we prefer wait2() over wait3(). rouilj@sni-usa.com
*/
#ifdef BSDWAIT
#undef USE_WAIT2
#endif
/*
* Define if you have the utempter utmp helper program
*/
#undef HAVE_UTEMPTER
/*
* If ttyslot() breaks getlogin() by returning indexes to utmp entries
* of type DEAD_PROCESS, then our getlogin() replacement should be
* selected by defining BUGGYGETLOGIN.
*/
#undef BUGGYGETLOGIN
/*
* If your system has the calls setreuid() and setregid(),
* define HAVE_SETREUID. Otherwise screen will use a forked process to
* safely create output files without retaining any special privileges.
*/
#undef HAVE_SETREUID
/*
* If your system supports BSD4.4's seteuid() and setegid(), define
* HAVE_SETEUID.
*/
#undef HAVE_SETEUID
/*
* If you want the "time" command to display the current load average
* define LOADAV. Maybe you must install screen with the needed
* privileges to read /dev/kmem.
* Note that NLIST_ stuff is only checked, when getloadavg() is not available.
*/
#undef LOADAV
#undef LOADAV_NUM
#undef LOADAV_TYPE
#undef LOADAV_SCALE
#undef LOADAV_GETLOADAVG
#undef LOADAV_UNIX
#undef LOADAV_AVENRUN
#undef LOADAV_USE_NLIST64
#undef NLIST_DECLARED
#undef NLIST_STRUCT
#undef NLIST_NAME_UNION
/*
* If your system has the new format /etc/ttys (like 4.3 BSD) and the
* getttyent(3) library functions, define GETTTYENT.
*/
#undef GETTTYENT
/*
* Define USEBCOPY if the bcopy/memcpy from your system's C library
* supports the overlapping of source and destination blocks. When
* undefined, screen uses its own (probably slower) version of bcopy().
*
* SYSV machines may have a working memcpy() -- Oh, this is
* quite unlikely. Tell me if you see one.
* "But then, memmove() should work, if at all available" he thought...
* Boing, never say "works everywhere" unless you checked SCO UNIX.
* Their memove fails the test in the configure script. Sigh. (Juergen)
*/
#undef USEBCOPY
#undef USEMEMCPY
#undef USEMEMMOVE
/*
* If your system has vsprintf() and requires the use of the macros in
* "varargs.h" to use functions with variable arguments,
* define USEVARARGS.
*/
#undef USEVARARGS
/*
* If your system has strerror() define this.
*/
#undef HAVE_STRERROR
/*
* If the select return value doesn't treat a descriptor that is
* usable for reading and writing as two hits, define SELECT_BROKEN.
*/
#undef SELECT_BROKEN
/*
* Define this if your system supports named pipes.
*/
#undef NAMEDPIPE
/*
* Define this if your system exits select() immediatly if a pipe is
* opened read-only and no writer has opened it.
*/
#undef BROKEN_PIPE
/*
* Define this if the unix-domain socket implementation doesn't
* create a socket in the filesystem.
*/
#undef SOCK_NOT_IN_FS
/*
* If your system has setenv() and unsetenv() define USESETENV
*/
#undef USESETENV
/*
* If your system does not come with a setenv()/putenv()/getenv()
* functions, you may bring in our own code by defining NEEDPUTENV.
*/
#undef NEEDPUTENV
/*
* If the passwords are stored in a shadow file and you want the
* builtin lock to work properly, define SHADOWPW.
*/
#undef SHADOWPW
/*
* If you are on a SYS V machine that restricts filename length to 14
* characters, you may need to enforce that by setting NAME_MAX to 14
*/
#undef NAME_MAX /* KEEP_UNDEF_HERE override system value */
#undef NAME_MAX
/*
* define HAVE_RENAME if your system has a rename() function
*/
#undef HAVE_RENAME
/*
* define HAVE__EXIT if your system has the _exit() call.
*/
#undef HAVE__EXIT
/*
* define HAVE_LSTAT if your system has symlinks and the lstat() call.
*/
#undef HAVE_LSTAT
/*
* define HAVE_UTIMES if your system has the utimes() call.
*/
#undef HAVE_UTIMES
/*
* define HAVE_FCHOWN if your system has the fchown() call.
*/
#undef HAVE_FCHOWN
/*
* define HAVE_FCHMOD if your system has the fchmod() call.
*/
#undef HAVE_FCHMOD
/*
* define HAVE_VSNPRINTF if your system has vsnprintf() (GNU lib).
*/
#undef HAVE_VSNPRINTF
/*
* define HAVE_GETCWD if your system has the getcwd() call.
*/
#undef HAVE_GETCWD
/*
* define HAVE_SETLOCALE if your system has the setlocale() call.
*/
#undef HAVE_SETLOCALE
/*
* define HAVE_STRFTIME if your system has the strftime() call.
*/
#undef HAVE_STRFTIME
/*
* define HAVE_NL_LANGINFO if your system has the nl_langinfo() call
* and <langinfo.h> defines CODESET.
*/
#undef HAVE_NL_LANGINFO
/*
* Newer versions of Solaris include fdwalk, which can greatly improve
* the startup time of screen; otherwise screen spends a lot of time
* closing file descriptors.
*/
#undef HAVE_FDWALK
/*
* define HAVE_DEV_PTC if you have a /dev/ptc character special
* device.
*/
#undef HAVE_DEV_PTC
/*
* define HAVE_SVR4_PTYS if you have a /dev/ptmx character special
* device and support the ptsname(), grantpt(), unlockpt() functions.
*/
#undef HAVE_SVR4_PTYS
/*
* define HAVE_GETPT if you have the getpt() function.
*/
#undef HAVE_GETPT
/*
* define HAVE_OPENPTY if your system has the openpty() call.
*/
#undef HAVE_OPENPTY
/*
* define PTYRANGE0 and or PTYRANGE1 if you want to adapt screen
* to unusual environments. E.g. For SunOs the defaults are "qpr" and
* "0123456789abcdef". For SunOs 4.1.2
* #define PTYRANGE0 "pqrstuvwxyzPQRST"
* is recommended by Dan Jacobson.
*/
#undef PTYRANGE0
#undef PTYRANGE1
#define USEVARARGS

5400
readline/examples/rlfe/configure vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,438 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(rlfe.c)
AC_CONFIG_HEADER(config.h)
VERSION=0.4
AC_SUBST(VERSION)
dnl
dnl Define some useful macros
dnl
AC_DEFUN(AC_PROGRAM_SOURCE,
[AC_REQUIRE([AC_PROG_CPP])AC_PROVIDE([$0])cat > conftest.c <<EOF
#include "confdefs.h"
[$1]
_CUT_HERE_
[$2]
EOF
eval "$ac_cpp conftest.c 2>&5 | sed -e '1,/_CUT_HERE_/d' -e 's/ //g' > conftest.out"
. ./conftest.out
rm -f conftest*
])dnl
dnl
define(AC_NOTE,
[echo "$1" 1>&AC_FD_MSG
])dnl
old_CFLAGS="$CFLAGS"
AC_PROG_CC
AC_PROG_CPP
AC_PROG_GCC_TRADITIONAL
AC_ISC_POSIX
AC_TRY_RUN(main(){exit(0);},,[
if test $CC != cc ; then
AC_NOTE(Your $CC failed - restarting with CC=cc)
AC_NOTE()
CC=cc
export CC
exec $0 $configure_args
fi
])
AC_TRY_RUN(main(){exit(0);},,
exec 5>&2
eval $ac_link
AC_NOTE(CC=$CC; CFLAGS=$CFLAGS; LIBS=$LIBS;)
AC_NOTE($ac_compile)
AC_MSG_ERROR(Can't run the compiler - sorry))
AC_TRY_RUN([
main()
{
int __something_strange_();
__something_strange_(0);
}
],AC_MSG_ERROR(Your compiler does not set the exit status - sorry))
AC_PROG_AWK
if test -f etc/toolcheck; then
AC_CHECKING(for buggy tools)
sh etc/toolcheck 1>&AC_FD_MSG
fi
dnl
dnl **** special unix variants ****
dnl
AC_CHECKING(for System V)
AC_TRY_COMPILE(
[#include <sys/types.h>
#include <signal.h>
#include <fcntl.h>], [int x = SIGCHLD | FNDELAY;], , AC_DEFINE(SYSV))
AC_CHECKING(for Solaris 2.x)
AC_EGREP_CPP(yes,
[#if defined(SVR4) && defined(sun)
yes
#endif
], LIBS="$LIBS -lsocket -lnsl -lkstat")
dnl
dnl **** select() ****
dnl
AC_CHECKING(select)
AC_TRY_LINK(,[select(0, 0, 0, 0, 0);],,
LIBS="$LIBS -lnet -lnsl"
AC_CHECKING(select with $LIBS)
AC_TRY_LINK(,[select(0, 0, 0, 0, 0);],,
AC_MSG_ERROR(!!! no select - no screen))
)
dnl
dnl **** check the select implementation ****
dnl
AC_CHECKING(select return value)
AC_TRY_RUN([
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
char *nam = "/tmp/conftest$$";
#ifdef NAMEDPIPE
#ifndef O_NONBLOCK
#define O_NONBLOCK O_NDELAY
#endif
#ifndef S_IFIFO
#define S_IFIFO 0010000
#endif
main()
{
#ifdef FD_SET
fd_set f;
#else
int f;
#endif
#ifdef __FreeBSD__
/* From Andrew A. Chernov (ache@astral.msk.su):
* opening RDWR fifo fails in BSD 4.4, but select return values are
* right.
*/
exit(0);
#endif
(void)alarm(5);
#ifdef POSIX
if (mkfifo(nam, 0777))
#else
if (mknod(nam, S_IFIFO|0777, 0))
#endif
exit(1);
close(0);
if (open(nam, O_RDWR | O_NONBLOCK))
exit(1);
if (write(0, "TEST", 4) == -1)
exit(1);
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
main()
{
int s1, s2, l;
struct sockaddr_un a;
#ifdef FD_SET
fd_set f;
#else
int f;
#endif
(void)alarm(5);
if ((s1 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
exit(1);
a.sun_family = AF_UNIX;
strcpy(a.sun_path, nam);
(void) unlink(nam);
if (bind(s1, (struct sockaddr *) &a, strlen(nam)+2) == -1)
exit(1);
if (listen(s1, 2))
exit(1);
if (fork() == 0)
{
if ((s2 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
kill(getppid(), 3);
(void)connect(s2, (struct sockaddr *)&a, strlen(nam) + 2);
if (write(s2, "HELLO", 5) == -1)
kill(getppid(), 3);
exit(0);
}
l = sizeof(a);
close(0);
if (accept(s1, (struct sockaddr *)&a, &l))
exit(1);
#endif
#ifdef FD_SET
FD_SET(0, &f);
#else
f = 1;
#endif
if (select(1, &f, 0, 0, 0) == -1)
exit(1);
if (select(1, &f, &f, 0, 0) != 2)
exit(1);
exit(0);
}
],AC_NOTE(- select is ok),
AC_NOTE(- select can't count) AC_DEFINE(SELECT_BROKEN))
dnl
dnl **** termcap or terminfo ****
dnl
AC_CHECKING(for tgetent)
AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
olibs="$LIBS"
LIBS="-lcurses $olibs"
AC_CHECKING(libcurses)
AC_TRY_LINK(,[
#ifdef __hpux
__sorry_hpux_libcurses_is_totally_broken_in_10_10();
#else
tgetent((char *)0, (char *)0);
#endif
],,
LIBS="-ltermcap $olibs"
AC_CHECKING(libtermcap)
AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
LIBS="-ltermlib $olibs"
AC_CHECKING(libtermlib)
AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
LIBS="-lncurses $olibs"
AC_CHECKING(libncurses)
AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
AC_MSG_ERROR(!!! no tgetent - no screen))))))
AC_TRY_RUN([
main()
{
exit(strcmp(tgoto("%p1%d", 0, 1), "1") ? 0 : 1);
}], AC_NOTE(- you use the termcap database),
AC_NOTE(- you use the terminfo database) AC_DEFINE(TERMINFO))
AC_CHECKING(ospeed)
AC_TRY_LINK(extern short ospeed;,ospeed=5;,,AC_DEFINE(NEED_OSPEED))
dnl
dnl **** PTY specific things ****
dnl
AC_CHECKING(for /dev/ptc)
if test -r /dev/ptc; then
AC_DEFINE(HAVE_DEV_PTC)
fi
AC_CHECKING(for SVR4 ptys)
sysvr4ptys=
if test -c /dev/ptmx ; then
AC_TRY_LINK([],[ptsname(0);grantpt(0);unlockpt(0);],[AC_DEFINE(HAVE_SVR4_PTYS)
sysvr4ptys=1])
fi
AC_CHECK_FUNCS(getpt)
dnl check for openpty()
if test -z "$sysvr4ptys"; then
AC_CHECK_FUNCS(openpty,,
[AC_CHECK_LIB(util,openpty, [AC_DEFINE(HAVE_OPENPTY)] [LIBS="$LIBS -lutil"])])
fi
AC_CHECKING(for ptyranges)
if test -d /dev/ptym ; then
pdir='/dev/ptym'
else
pdir='/dev'
fi
dnl SCO uses ptyp%d
AC_EGREP_CPP(yes,
[#ifdef M_UNIX
yes;
#endif
], ptys=`echo /dev/ptyp??`, ptys=`echo $pdir/pty??`)
dnl if test -c /dev/ptyp19; then
dnl ptys=`echo /dev/ptyp??`
dnl else
dnl ptys=`echo $pdir/pty??`
dnl fi
if test "$ptys" != "$pdir/pty??" ; then
p0=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\).$/\1/g' | sort -u | tr -d '\012'`
p1=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\)$/\1/g' | sort -u | tr -d '\012'`
AC_DEFINE_UNQUOTED(PTYRANGE0,"$p0")
AC_DEFINE_UNQUOTED(PTYRANGE1,"$p1")
fi
dnl **** pty mode/group handling ****
dnl
dnl support provided by Luke Mewburn <lm@rmit.edu.au>, 931222
AC_ARG_WITH(pty-mode, [ --with-pty-mode=mode default mode for ptys], [ ptymode="${withval}" ])
AC_ARG_WITH(pty-group, [ --with-pty-group=group default group for ptys], [ ptygrp="${withval}" ])
test -n "$ptymode" || ptymode=0620
if test -n "$ptygrp" ; then
AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
else
AC_CHECKING(default tty permissions/group)
rm -f conftest_grp
AC_TRY_RUN([
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
main()
{
struct stat sb;
char *x,*ttyname();
int om, m;
FILE *fp;
if (!(x = ttyname(0))) exit(1);
if (stat(x, &sb)) exit(1);
om = sb.st_mode;
if (om & 002) exit(0);
m = system("mesg y");
if (m == -1 || m == 127) exit(1);
if (stat(x, &sb)) exit(1);
m = sb.st_mode;
if (chmod(x, om)) exit(1);
if (m & 002) exit(0);
if (sb.st_gid == getgid()) exit(1);
if (!(fp=fopen("conftest_grp", "w")))
exit(1);
fprintf(fp, "%d\n", sb.st_gid);
fclose(fp);
exit(0);
}
],[
if test -f conftest_grp; then
ptygrp=`cat conftest_grp`
AC_NOTE([- pty mode: $ptymode, group: $ptygrp])
AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
else
AC_NOTE(- ptys are world accessable)
fi
],[
WRITEPATH=''
XTERMPATH=''
AC_PATH_PROG(WRITEPATH, write)
AC_PATH_PROG(XTERMPATH, xterm)
found=
if test -n "$WRITEPATH$XTERMPATH"; then
findfollow=
lsfollow=
found=`find $WRITEPATH $XTERMPATH -follow -print 2>/dev/null`
if test -n "$found"; then
findfollow=-follow
lsfollow=L
fi
if test -n "$XTERMPATH"; then
ptygrpn=`ls -l$lsfollow $XTERMPATH | sed -n -e 1p | $AWK '{print $4}'`
if test tty != "$ptygrpn"; then
XTERMPATH=
fi
fi
fi
if test -n "$WRITEPATH$XTERMPATH"; then
found=`find $WRITEPATH $XTERMPATH $findfollow -perm -2000 -print`
if test -n "$found"; then
ptygrp=`ls -ln$lsfollow $found | sed -n -e 1p | $AWK '{print $4}'`
AC_NOTE([- pty mode: $ptymode, group: $ptygrp])
AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
else
AC_NOTE(- ptys are world accessable)
fi
else
AC_NOTE(- can't determine - assume ptys are world accessable)
fi
]
)
rm -f conftest_grp
fi
dnl
dnl **** signal handling ****
dnl
if test -n "$posix" ; then
dnl POSIX has reliable signals with void return type.
AC_NOTE(assuming posix signal definition)
AC_DEFINE(SIGVOID)
else
AC_CHECKING(return type of signal handlers)
AC_TRY_COMPILE(
[#include <sys/types.h>
#include <signal.h>
#ifdef signal
#undef signal
#endif
extern void (*signal ()) ();], [int i;], AC_DEFINE(SIGVOID))
AC_CHECKING(sigset)
AC_TRY_LINK([
#include <sys/types.h>
#include <signal.h>
],[
#ifdef SIGVOID
sigset(0, (void (*)())0);
#else
sigset(0, (int (*)())0);
#endif
], AC_DEFINE(USESIGSET))
AC_CHECKING(signal implementation)
AC_TRY_RUN([
#include <sys/types.h>
#include <signal.h>
#ifndef SIGCLD
#define SIGCLD SIGCHLD
#endif
#ifdef USESIGSET
#define signal sigset
#endif
int got;
#ifdef SIGVOID
void
#endif
hand()
{
got++;
}
main()
{
/* on hpux we use sigvec to get bsd signals */
#ifdef __hpux
(void)signal(SIGCLD, hand);
kill(getpid(), SIGCLD);
kill(getpid(), SIGCLD);
if (got < 2)
exit(1);
#endif
exit(0);
}
],,AC_DEFINE(SYSVSIGS))
fi
AC_OUTPUT(Makefile)

View File

@@ -0,0 +1,33 @@
/* Copyright (c) 1993-2002
* Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
* Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
* Copyright (c) 1987 Oliver Laumann
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (see the file COPYING); if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
****************************************************************
* $Id$ FAU
*/
#if !defined(__GNUC__) || __GNUC__ < 2
#undef __attribute__
#define __attribute__(x)
#endif
/* pty.c */
extern int OpenPTY __P((char **));
extern void InitPTY __P((int));

530
readline/examples/rlfe/os.h Normal file
View File

@@ -0,0 +1,530 @@
/* Copyright (c) 1993-2002
* Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
* Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
* Copyright (c) 1987 Oliver Laumann
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (see the file COPYING); if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
****************************************************************
* $Id$ FAU
*/
#include <stdio.h>
#include <errno.h>
#include <sys/param.h>
/* In strict ANSI mode, HP-UX machines define __hpux but not hpux */
#if defined(__hpux) && !defined(hpux)
# define hpux
#endif
#if defined(__bsdi__) || defined(__386BSD__) || defined(_CX_UX) || defined(hpux) || defined(_IBMR2) || defined(linux)
# include <signal.h>
#endif /* __bsdi__ || __386BSD__ || _CX_UX || hpux || _IBMR2 || linux */
#ifdef ISC
# ifdef ENAMETOOLONG
# undef ENAMETOOLONG
# endif
# ifdef ENOTEMPTY
# undef ENOTEMPTY
# endif
# include <sys/bsdtypes.h>
# include <net/errno.h>
#endif
#ifdef sun
# define getpgrp __getpgrp
# define exit __exit
#endif
#ifdef POSIX
# include <unistd.h>
# if defined(__STDC__)
# include <stdlib.h>
# endif /* __STDC__ */
#endif /* POSIX */
#ifdef sun
# undef getpgrp
# undef exit
#endif /* sun */
#ifndef linux /* all done in <errno.h> */
extern int errno;
#endif /* linux */
#ifndef HAVE_STRERROR
/* No macros, please */
#undef strerror
#endif
#if !defined(SYSV) && !defined(linux)
# ifdef NEWSOS
# define strlen ___strlen___
# include <strings.h>
# undef strlen
# else /* NEWSOS */
# include <strings.h>
# endif /* NEWSOS */
#else /* SYSV */
# if defined(SVR4) || defined(NEWSOS)
# define strlen ___strlen___
# include <string.h>
# undef strlen
# if !defined(NEWSOS) && !defined(__hpux)
extern size_t strlen(const char *);
# endif
# else /* SVR4 */
# include <string.h>
# endif /* SVR4 */
#endif /* SYSV */
#ifdef USEVARARGS
# if defined(__STDC__)
# include <stdarg.h>
# define VA_LIST(var) va_list var;
# define VA_DOTS ...
# define VA_DECL
# define VA_START(ap, fmt) va_start(ap, fmt)
# define VA_ARGS(ap) ap
# define VA_END(ap) va_end(ap)
# else
# include <varargs.h>
# define VA_LIST(var) va_list var;
# define VA_DOTS va_alist
# define VA_DECL va_dcl
# define VA_START(ap, fmt) va_start(ap)
# define VA_ARGS(ap) ap
# define VA_END(ap) va_end(ap)
# endif
#else
# define VA_LIST(var)
# define VA_DOTS p1, p2, p3, p4, p5, p6
# define VA_DECL unsigned long VA_DOTS;
# define VA_START(ap, fmt)
# define VA_ARGS(ap) VA_DOTS
# define VA_END(ap)
# undef vsnprintf
# define vsnprintf xsnprintf
#endif
#if !defined(sun) && !defined(B43) && !defined(ISC) && !defined(pyr) && !defined(_CX_UX)
# include <time.h>
#endif
#include <sys/time.h>
#ifdef M_UNIX /* SCO */
# include <sys/stream.h>
# include <sys/ptem.h>
# define ftruncate(fd, s) chsize(fd, s)
#endif
#ifdef SYSV
# define index strchr
# define rindex strrchr
# define bzero(poi,len) memset(poi,0,len)
# define bcmp memcmp
# define killpg(pgrp,sig) kill( -(pgrp), sig)
#endif
#ifndef HAVE_GETCWD
# define getcwd(b,l) getwd(b)
#endif
#ifndef USEBCOPY
# ifdef USEMEMMOVE
# define bcopy(s,d,len) memmove(d,s,len)
# else
# ifdef USEMEMCPY
# define bcopy(s,d,len) memcpy(d,s,len)
# else
# define NEED_OWN_BCOPY
# define bcopy xbcopy
# endif
# endif
#endif
#ifdef hpux
# define setreuid(ruid, euid) setresuid(ruid, euid, -1)
# define setregid(rgid, egid) setresgid(rgid, egid, -1)
#endif
#if defined(HAVE_SETEUID) || defined(HAVE_SETREUID)
# define USE_SETEUID
#endif
#if !defined(HAVE__EXIT) && !defined(_exit)
#define _exit(x) exit(x)
#endif
#ifndef HAVE_UTIMES
# define utimes utime
#endif
#ifdef BUILTIN_TELNET
# include <netinet/in.h>
# include <arpa/inet.h>
#endif
#if defined(USE_LOCALE) && (!defined(HAVE_SETLOCALE) || !defined(HAVE_STRFTIME))
# undef USE_LOCALE
#endif
/*****************************************************************
* terminal handling
*/
#ifdef POSIX
# include <termios.h>
# ifdef hpux
# include <bsdtty.h>
# endif /* hpux */
# ifdef NCCS
# define MAXCC NCCS
# else
# define MAXCC 256
# endif
#else /* POSIX */
# ifdef TERMIO
# include <termio.h>
# ifdef NCC
# define MAXCC NCC
# else
# define MAXCC 256
# endif
# ifdef CYTERMIO
# include <cytermio.h>
# endif
# else /* TERMIO */
# include <sgtty.h>
# endif /* TERMIO */
#endif /* POSIX */
#ifndef VDISABLE
# ifdef _POSIX_VDISABLE
# define VDISABLE _POSIX_VDISABLE
# else
# define VDISABLE 0377
# endif /* _POSIX_VDISABLE */
#endif /* !VDISABLE */
/* on sgi, regardless of the stream head's read mode (RNORM/RMSGN/RMSGD)
* TIOCPKT mode causes data loss if our buffer is too small (IOSIZE)
* to hold the whole packet at first read().
* (Marc Boucher)
*
* matthew green:
* TIOCPKT is broken on dgux 5.4.1 generic AViiON mc88100
*
* Joe Traister: On AIX4, programs like irc won't work if screen
* uses TIOCPKT (select fails to return on pty read).
*/
#if defined(sgi) || defined(DGUX) || defined(_IBMR2)
# undef TIOCPKT
#endif
/* linux ncurses is broken, we have to use our own tputs */
#if defined(linux) && defined(TERMINFO)
# define tputs xtputs
#endif
/* Alexandre Oliva: SVR4 style ptys don't work with osf */
#ifdef __osf__
# undef HAVE_SVR4_PTYS
#endif
/*****************************************************************
* utmp handling
*/
#ifdef GETUTENT
typedef char *slot_t;
#else
typedef int slot_t;
#endif
#if defined(UTMPOK) || defined(BUGGYGETLOGIN)
# if defined(SVR4) && !defined(DGUX) && !defined(__hpux) && !defined(linux)
# include <utmpx.h>
# define UTMPFILE UTMPX_FILE
# define utmp utmpx
# define getutent getutxent
# define getutid getutxid
# define getutline getutxline
# define pututline pututxline
# define setutent setutxent
# define endutent endutxent
# define ut_time ut_xtime
# else /* SVR4 */
# include <utmp.h>
# endif /* SVR4 */
# ifdef apollo
/*
* We don't have GETUTENT, so we dig into utmp ourselves.
* But we save the permanent filedescriptor and
* open utmp just when we need to.
* This code supports an unsorted utmp. jw.
*/
# define UTNOKEEP
# endif /* apollo */
# ifndef UTMPFILE
# ifdef UTMP_FILE
# define UTMPFILE UTMP_FILE
# else
# ifdef _PATH_UTMP
# define UTMPFILE _PATH_UTMP
# else
# define UTMPFILE "/etc/utmp"
# endif /* _PATH_UTMP */
# endif
# endif
#endif /* UTMPOK || BUGGYGETLOGIN */
#if !defined(UTMPOK) && defined(USRLIMIT)
# undef USRLIMIT
#endif
#ifdef LOGOUTOK
# ifndef LOGINDEFAULT
# define LOGINDEFAULT 0
# endif
#else
# ifdef LOGINDEFAULT
# undef LOGINDEFAULT
# endif
# define LOGINDEFAULT 1
#endif
/*****************************************************************
* file stuff
*/
#ifndef F_OK
#define F_OK 0
#endif
#ifndef X_OK
#define X_OK 1
#endif
#ifndef W_OK
#define W_OK 2
#endif
#ifndef R_OK
#define R_OK 4
#endif
#ifndef S_IFIFO
#define S_IFIFO 0010000
#endif
#ifndef S_IREAD
#define S_IREAD 0000400
#endif
#ifndef S_IWRITE
#define S_IWRITE 0000200
#endif
#ifndef S_IEXEC
#define S_IEXEC 0000100
#endif
#if defined(S_IFIFO) && defined(S_IFMT) && !defined(S_ISFIFO)
#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
#endif
#if defined(S_IFSOCK) && defined(S_IFMT) && !defined(S_ISSOCK)
#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
#endif
#if defined(S_IFCHR) && defined(S_IFMT) && !defined(S_ISCHR)
#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
#endif
#if defined(S_IFDIR) && defined(S_IFMT) && !defined(S_ISDIR)
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
#endif
#if defined(S_IFLNK) && defined(S_IFMT) && !defined(S_ISLNK)
#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
#endif
/*
* SunOS 4.1.3: `man 2V open' has only one line that mentions O_NOBLOCK:
*
* O_NONBLOCK Same as O_NDELAY above.
*
* on the very same SunOS 4.1.3, I traced the open system call and found
* that an open("/dev/ttyy08", O_RDWR|O_NONBLOCK|O_NOCTTY) was blocked,
* whereas open("/dev/ttyy08", O_RDWR|O_NDELAY |O_NOCTTY) went through.
*
* For this simple reason I now favour O_NDELAY. jw. 4.5.95
*/
#if defined(sun) && !defined(SVR4)
# undef O_NONBLOCK
#endif
#if !defined(O_NONBLOCK) && defined(O_NDELAY)
# define O_NONBLOCK O_NDELAY
#endif
#if !defined(FNBLOCK) && defined(FNONBLOCK)
# define FNBLOCK FNONBLOCK
#endif
#if !defined(FNBLOCK) && defined(FNDELAY)
# define FNBLOCK FNDELAY
#endif
#if !defined(FNBLOCK) && defined(O_NONBLOCK)
# define FNBLOCK O_NONBLOCK
#endif
#ifndef POSIX
#undef mkfifo
#define mkfifo(n,m) mknod(n,S_IFIFO|(m),0)
#endif
#if !defined(HAVE_LSTAT) && !defined(lstat)
# define lstat stat
#endif
/*****************************************************************
* signal handling
*/
#ifdef SIGVOID
# define SIGRETURN
# define sigret_t void
#else
# define SIGRETURN return 0;
# define sigret_t int
#endif
/* Geeeee, reverse it? */
#if defined(SVR4) || (defined(SYSV) && defined(ISC)) || defined(_AIX) || defined(linux) || defined(ultrix) || defined(__386BSD__) || defined(__bsdi__) || defined(POSIX) || defined(NeXT)
# define SIGHASARG
#endif
#ifdef SIGHASARG
# define SIGPROTOARG (int)
# define SIGDEFARG (sigsig) int sigsig;
# define SIGARG 0
#else
# define SIGPROTOARG (void)
# define SIGDEFARG ()
# define SIGARG
#endif
#ifndef SIGCHLD
#define SIGCHLD SIGCLD
#endif
#if defined(POSIX) || defined(hpux)
# define signal xsignal
#else
# ifdef USESIGSET
# define signal sigset
# endif /* USESIGSET */
#endif
/* used in screen.c and attacher.c */
#ifndef NSIG /* kbeal needs these w/o SYSV */
# define NSIG 32
#endif /* !NSIG */
/*****************************************************************
* Wait stuff
*/
#if (!defined(sysV68) && !defined(M_XENIX)) || defined(NeXT) || defined(M_UNIX)
# include <sys/wait.h>
#endif
#ifndef WTERMSIG
# ifndef BSDWAIT /* if wait is NOT a union: */
# define WTERMSIG(status) (status & 0177)
# else
# define WTERMSIG(status) status.w_T.w_Termsig
# endif
#endif
#ifndef WSTOPSIG
# ifndef BSDWAIT /* if wait is NOT a union: */
# define WSTOPSIG(status) ((status >> 8) & 0377)
# else
# define WSTOPSIG(status) status.w_S.w_Stopsig
# endif
#endif
/* NET-2 uses WCOREDUMP */
#if defined(WCOREDUMP) && !defined(WIFCORESIG)
# define WIFCORESIG(status) WCOREDUMP(status)
#endif
#ifndef WIFCORESIG
# ifndef BSDWAIT /* if wait is NOT a union: */
# define WIFCORESIG(status) (status & 0200)
# else
# define WIFCORESIG(status) status.w_T.w_Coredump
# endif
#endif
#ifndef WEXITSTATUS
# ifndef BSDWAIT /* if wait is NOT a union: */
# define WEXITSTATUS(status) ((status >> 8) & 0377)
# else
# define WEXITSTATUS(status) status.w_T.w_Retcode
# endif
#endif
/*****************************************************************
* select stuff
*/
#if defined(M_XENIX) || defined(M_UNIX) || defined(_SEQUENT_)
#include <sys/select.h> /* for timeval + FD... */
#endif
/*
* SunOS 3.5 - Tom Schmidt - Micron Semiconductor, Inc - 27-Jul-93
* tschmidt@vax.micron.com
*/
#ifndef FD_SET
# ifndef SUNOS3
typedef struct fd_set { int fds_bits[1]; } fd_set;
# endif
# define FD_ZERO(fd) ((fd)->fds_bits[0] = 0)
# define FD_SET(b, fd) ((fd)->fds_bits[0] |= 1 << (b))
# define FD_ISSET(b, fd) ((fd)->fds_bits[0] & 1 << (b))
# define FD_SETSIZE 32
#endif
/*****************************************************************
* user defineable stuff
*/
#ifndef TERMCAP_BUFSIZE
# define TERMCAP_BUFSIZE 2048
#endif
#ifndef MAXPATHLEN
# define MAXPATHLEN 1024
#endif
/*
* you may try to vary this value. Use low values if your (VMS) system
* tends to choke when pasting. Use high values if you want to test
* how many characters your pty's can buffer.
*/
#define IOSIZE 4096

View File

@@ -0,0 +1,387 @@
/* Copyright (c) 1993-2002
* Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
* Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
* Copyright (c) 1987 Oliver Laumann
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (see the file COPYING); if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
****************************************************************
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include "config.h"
#include "screen.h"
#ifndef sun
# include <sys/ioctl.h>
#endif
/* for solaris 2.1, Unixware (SVR4.2) and possibly others */
#ifdef HAVE_SVR4_PTYS
# include <sys/stropts.h>
#endif
#if defined(sun) && defined(LOCKPTY) && !defined(TIOCEXCL)
# include <sys/ttold.h>
#endif
#ifdef ISC
# include <sys/tty.h>
# include <sys/sioctl.h>
# include <sys/pty.h>
#endif
#ifdef sgi
# include <sys/sysmacros.h>
#endif /* sgi */
#include "extern.h"
/*
* if no PTYRANGE[01] is in the config file, we pick a default
*/
#ifndef PTYRANGE0
# define PTYRANGE0 "qpr"
#endif
#ifndef PTYRANGE1
# define PTYRANGE1 "0123456789abcdef"
#endif
/* SVR4 pseudo ttys don't seem to work with SCO-5 */
#ifdef M_UNIX
# undef HAVE_SVR4_PTYS
#endif
extern int eff_uid;
/* used for opening a new pty-pair: */
static char PtyName[32], TtyName[32];
#if !(defined(sequent) || defined(_SEQUENT_) || defined(HAVE_SVR4_PTYS))
# ifdef hpux
static char PtyProto[] = "/dev/ptym/ptyXY";
static char TtyProto[] = "/dev/pty/ttyXY";
# else
# ifdef M_UNIX
static char PtyProto[] = "/dev/ptypXY";
static char TtyProto[] = "/dev/ttypXY";
# else
static char PtyProto[] = "/dev/ptyXY";
static char TtyProto[] = "/dev/ttyXY";
# endif
# endif /* hpux */
#endif
static void initmaster __P((int));
#if defined(sun)
/* sun's utmp_update program opens the salve side, thus corrupting
*/
int pty_preopen = 1;
#else
int pty_preopen = 0;
#endif
/*
* Open all ptys with O_NOCTTY, just to be on the safe side
* (RISCos mips breaks otherwise)
*/
#ifndef O_NOCTTY
# define O_NOCTTY 0
#endif
/***************************************************************/
static void
initmaster(f)
int f;
{
#ifdef POSIX
tcflush(f, TCIOFLUSH);
#else
# ifdef TIOCFLUSH
(void) ioctl(f, TIOCFLUSH, (char *) 0);
# endif
#endif
#ifdef LOCKPTY
(void) ioctl(f, TIOCEXCL, (char *) 0);
#endif
}
void
InitPTY(f)
int f;
{
if (f < 0)
return;
#if defined(I_PUSH) && defined(HAVE_SVR4_PTYS) && !defined(sgi) && !defined(linux) && !defined(__osf__) && !defined(M_UNIX)
if (ioctl(f, I_PUSH, "ptem"))
Panic(errno, "InitPTY: cannot I_PUSH ptem");
if (ioctl(f, I_PUSH, "ldterm"))
Panic(errno, "InitPTY: cannot I_PUSH ldterm");
# ifdef sun
if (ioctl(f, I_PUSH, "ttcompat"))
Panic(errno, "InitPTY: cannot I_PUSH ttcompat");
# endif
#endif
}
/***************************************************************/
#if defined(OSX) && !defined(PTY_DONE)
#define PTY_DONE
int
OpenPTY(ttyn)
char **ttyn;
{
register int f;
if ((f = open_controlling_pty(TtyName)) < 0)
return -1;
initmaster(f);
*ttyn = TtyName;
return f;
}
#endif
/***************************************************************/
#if (defined(sequent) || defined(_SEQUENT_)) && !defined(PTY_DONE)
#define PTY_DONE
int
OpenPTY(ttyn)
char **ttyn;
{
char *m, *s;
register int f;
if ((f = getpseudotty(&s, &m)) < 0)
return -1;
#ifdef _SEQUENT_
fvhangup(s);
#endif
strncpy(PtyName, m, sizeof(PtyName));
strncpy(TtyName, s, sizeof(TtyName));
initmaster(f);
*ttyn = TtyName;
return f;
}
#endif
/***************************************************************/
#if defined(__sgi) && !defined(PTY_DONE)
#define PTY_DONE
int
OpenPTY(ttyn)
char **ttyn;
{
int f;
char *name, *_getpty();
sigret_t (*sigcld)__P(SIGPROTOARG);
/*
* SIGCHLD set to SIG_DFL for _getpty() because it may fork() and
* exec() /usr/adm/mkpts
*/
sigcld = signal(SIGCHLD, SIG_DFL);
name = _getpty(&f, O_RDWR | O_NONBLOCK, 0600, 0);
signal(SIGCHLD, sigcld);
if (name == 0)
return -1;
initmaster(f);
*ttyn = name;
return f;
}
#endif
/***************************************************************/
#if defined(MIPS) && defined(HAVE_DEV_PTC) && !defined(PTY_DONE)
#define PTY_DONE
int
OpenPTY(ttyn)
char **ttyn;
{
register int f;
struct stat buf;
strcpy(PtyName, "/dev/ptc");
if ((f = open(PtyName, O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0)
return -1;
if (fstat(f, &buf) < 0)
{
close(f);
return -1;
}
sprintf(TtyName, "/dev/ttyq%d", minor(buf.st_rdev));
initmaster(f);
*ttyn = TtyName;
return f;
}
#endif
/***************************************************************/
#if defined(HAVE_SVR4_PTYS) && !defined(PTY_DONE)
#define PTY_DONE
int
OpenPTY(ttyn)
char **ttyn;
{
register int f;
char *m, *ptsname();
int unlockpt __P((int)), grantpt __P((int));
#if defined(HAVE_GETPT) && defined(linux)
int getpt __P((void));
#endif
sigret_t (*sigcld)__P(SIGPROTOARG);
strcpy(PtyName, "/dev/ptmx");
#if defined(HAVE_GETPT) && defined(linux)
if ((f = getpt()) == -1)
#else
if ((f = open(PtyName, O_RDWR | O_NOCTTY)) == -1)
#endif
return -1;
/*
* SIGCHLD set to SIG_DFL for grantpt() because it fork()s and
* exec()s pt_chmod
*/
sigcld = signal(SIGCHLD, SIG_DFL);
if ((m = ptsname(f)) == NULL || grantpt(f) || unlockpt(f))
{
signal(SIGCHLD, sigcld);
close(f);
return -1;
}
signal(SIGCHLD, sigcld);
strncpy(TtyName, m, sizeof(TtyName));
initmaster(f);
*ttyn = TtyName;
return f;
}
#endif
/***************************************************************/
#if defined(_AIX) && defined(HAVE_DEV_PTC) && !defined(PTY_DONE)
#define PTY_DONE
int
OpenPTY(ttyn)
char **ttyn;
{
register int f;
/* a dumb looking loop replaced by mycrofts code: */
strcpy (PtyName, "/dev/ptc");
if ((f = open (PtyName, O_RDWR | O_NOCTTY)) < 0)
return -1;
strncpy(TtyName, ttyname(f), sizeof(TtyName));
if (eff_uid && access(TtyName, R_OK | W_OK))
{
close(f);
return -1;
}
initmaster(f);
# ifdef _IBMR2
pty_preopen = 1;
# endif
*ttyn = TtyName;
return f;
}
#endif
/***************************************************************/
#if defined(HAVE_OPENPTY) && !defined(PTY_DONE)
#define PTY_DONE
int
OpenPTY(ttyn)
char **ttyn;
{
int f, s;
if (openpty(&f, &s, TtyName, NULL, NULL) != 0)
return -1;
close(s);
initmaster(f);
pty_preopen = 1;
*ttyn = TtyName;
return f;
}
#endif
/***************************************************************/
#ifndef PTY_DONE
int
OpenPTY(ttyn)
char **ttyn;
{
register char *p, *q, *l, *d;
register int f;
debug("OpenPTY: Using BSD style ptys.\n");
strcpy(PtyName, PtyProto);
strcpy(TtyName, TtyProto);
for (p = PtyName; *p != 'X'; p++)
;
for (q = TtyName; *q != 'X'; q++)
;
for (l = PTYRANGE0; (*p = *l) != '\0'; l++)
{
for (d = PTYRANGE1; (p[1] = *d) != '\0'; d++)
{
debug1("OpenPTY tries '%s'\n", PtyName);
if ((f = open(PtyName, O_RDWR | O_NOCTTY)) == -1)
continue;
q[0] = *l;
q[1] = *d;
if (eff_uid && access(TtyName, R_OK | W_OK))
{
close(f);
continue;
}
#if defined(sun) && defined(TIOCGPGRP) && !defined(SUNOS3)
/* Hack to ensure that the slave side of the pty is
* unused. May not work in anything other than SunOS4.1
*/
{
int pgrp;
/* tcgetpgrp does not work (uses TIOCGETPGRP)! */
if (ioctl(f, TIOCGPGRP, (char *)&pgrp) != -1 || errno != EIO)
{
close(f);
continue;
}
}
#endif
initmaster(f);
*ttyn = TtyName;
return f;
}
}
return -1;
}
#endif

View File

@@ -0,0 +1,780 @@
/* A front-end using readline to "cook" input lines.
*
* Copyright (C) 2004, 1999 Per Bothner
*
* This front-end program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* Some code from Johnson & Troan: "Linux Application Development"
* (Addison-Wesley, 1998) was used directly or for inspiration.
*
* 2003-11-07 Wolfgang Taeuber <wolfgang_taeuber@agilent.com>
* Specify a history file and the size of the history file with command
* line options; use EDITOR/VISUAL to set vi/emacs preference.
*/
/* PROBLEMS/TODO:
*
* Only tested under GNU/Linux and Mac OS 10.x; needs to be ported.
*
* Switching between line-editing-mode vs raw-char-mode depending on
* what tcgetattr returns is inherently not robust, plus it doesn't
* work when ssh/telnetting in. A better solution is possible if the
* tty system can send in-line escape sequences indicating the current
* mode, echo'd input, etc. That would also allow a user preference
* to set different colors for prompt, input, stdout, and stderr.
*
* When running mc -c under the Linux console, mc does not recognize
* mouse clicks, which mc does when not running under rlfe.
*
* Pasting selected text containing tabs is like hitting the tab character,
* which invokes readline completion. We don't want this. I don't know
* if this is fixable without integrating rlfe into a terminal emulator.
*
* Echo suppression is a kludge, but can only be avoided with better kernel
* support: We need a tty mode to disable "real" echoing, while still
* letting the inferior think its tty driver to doing echoing.
* Stevens's book claims SCR$ and BSD4.3+ have TIOCREMOTE.
*
* The latest readline may have some hooks we can use to avoid having
* to back up the prompt. (See HAVE_ALREADY_PROMPTED.)
*
* Desirable readline feature: When in cooked no-echo mode (e.g. password),
* echo characters are they are types with '*', but remove them when done.
*
* Asynchronous output while we're editing an input line should be
* inserted in the output view *before* the input line, so that the
* lines being edited (with the prompt) float at the end of the input.
*
* A "page mode" option to emulate more/less behavior: At each page of
* output, pause for a user command. This required parsing the output
* to keep track of line lengths. It also requires remembering the
* output, if we want an option to scroll back, which suggests that
* this should be integrated with a terminal emulator like xterm.
*/
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <netdb.h>
#include <stdlib.h>
#include <errno.h>
#include <grp.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <termios.h>
#include "config.h"
#ifdef READLINE_LIBRARY
# include "readline.h"
# include "history.h"
#else
# include <readline/readline.h>
# include <readline/history.h>
#endif
#ifndef COMMAND
#define COMMAND "/bin/bash"
#endif
#ifndef COMMAND_ARGS
#define COMMAND_ARGS COMMAND
#endif
#ifndef ALT_COMMAND
#define ALT_COMMAND "/bin/sh"
#endif
#ifndef ALT_COMMAND_ARGS
#define ALT_COMMAND_ARGS ALT_COMMAND
#endif
#ifndef HAVE_MEMMOVE
# if __GNUC__ > 1
# define memmove(d, s, n) __builtin_memcpy(d, s, n)
# else
# define memmove(d, s, n) memcpy(d, s, n)
# endif
#else
# define memmove(d, s, n) memcpy(d, s, n)
#endif
#define APPLICATION_NAME "rlfe"
static int in_from_inferior_fd;
static int out_to_inferior_fd;
static void set_edit_mode ();
static void usage_exit ();
static char *hist_file = 0;
static int hist_size = 0;
/* Unfortunately, we cannot safely display echo from the inferior process.
The reason is that the echo bit in the pty is "owned" by the inferior,
and if we try to turn it off, we could confuse the inferior.
Thus, when echoing, we get echo twice: First readline echoes while
we're actually editing. Then we send the line to the inferior, and the
terminal driver send back an extra echo.
The work-around is to remember the input lines, and when we see that
line come back, we supress the output.
A better solution (supposedly available on SVR4) would be a smarter
terminal driver, with more flags ... */
#define ECHO_SUPPRESS_MAX 1024
char echo_suppress_buffer[ECHO_SUPPRESS_MAX];
int echo_suppress_start = 0;
int echo_suppress_limit = 0;
/*#define DEBUG*/
#ifdef DEBUG
FILE *logfile = NULL;
#define DPRINT0(FMT) (fprintf(logfile, FMT), fflush(logfile))
#define DPRINT1(FMT, V1) (fprintf(logfile, FMT, V1), fflush(logfile))
#define DPRINT2(FMT, V1, V2) (fprintf(logfile, FMT, V1, V2), fflush(logfile))
#else
#define DPRINT0(FMT) ((void) 0) /* Do nothing */
#define DPRINT1(FMT, V1) ((void) 0) /* Do nothing */
#define DPRINT2(FMT, V1, V2) ((void) 0) /* Do nothing */
#endif
struct termios orig_term;
/* Pid of child process. */
static pid_t child = -1;
static void
sig_child (int signo)
{
int status;
wait (&status);
if (hist_file != 0)
{
write_history (hist_file);
if (hist_size)
history_truncate_file (hist_file, hist_size);
}
DPRINT0 ("(Child process died.)\n");
tcsetattr(STDIN_FILENO, TCSANOW, &orig_term);
exit (0);
}
volatile int propagate_sigwinch = 0;
/* sigwinch_handler
* propagate window size changes from input file descriptor to
* master side of pty.
*/
void sigwinch_handler(int signal) {
propagate_sigwinch = 1;
}
/* get_slave_pty() returns an integer file descriptor.
* If it returns < 0, an error has occurred.
* Otherwise, it has returned the slave file descriptor.
*/
int get_slave_pty(char *name) {
struct group *gptr;
gid_t gid;
int slave = -1;
/* chown/chmod the corresponding pty, if possible.
* This will only work if the process has root permissions.
* Alternatively, write and exec a small setuid program that
* does just this.
*/
if ((gptr = getgrnam("tty")) != 0) {
gid = gptr->gr_gid;
} else {
/* if the tty group does not exist, don't change the
* group on the slave pty, only the owner
*/
gid = -1;
}
/* Note that we do not check for errors here. If this is code
* where these actions are critical, check for errors!
*/
chown(name, getuid(), gid);
/* This code only makes the slave read/writeable for the user.
* If this is for an interactive shell that will want to
* receive "write" and "wall" messages, OR S_IWGRP into the
* second argument below.
*/
chmod(name, S_IRUSR|S_IWUSR);
/* open the corresponding slave pty */
slave = open(name, O_RDWR);
return (slave);
}
/* Certain special characters, such as ctrl/C, we want to pass directly
to the inferior, rather than letting readline handle them. */
static char special_chars[20];
static int special_chars_count;
static void
add_special_char(int ch)
{
if (ch != 0)
special_chars[special_chars_count++] = ch;
}
static int eof_char;
static int
is_special_char(int ch)
{
int i;
#if 0
if (ch == eof_char && rl_point == rl_end)
return 1;
#endif
for (i = special_chars_count; --i >= 0; )
if (special_chars[i] == ch)
return 1;
return 0;
}
static char buf[1024];
/* buf[0 .. buf_count-1] is the what has been emitted on the current line.
It is used as the readline prompt. */
static int buf_count = 0;
int do_emphasize_input = 1;
int current_emphasize_input;
char *start_input_mode = "\033[1m";
char *end_input_mode = "\033[0m";
int num_keys = 0;
static void maybe_emphasize_input (int on)
{
if (on == current_emphasize_input
|| (on && ! do_emphasize_input))
return;
fprintf (rl_outstream, on ? start_input_mode : end_input_mode);
fflush (rl_outstream);
current_emphasize_input = on;
}
static void
null_prep_terminal (int meta)
{
}
static void
null_deprep_terminal ()
{
maybe_emphasize_input (0);
}
static int
pre_input_change_mode (void)
{
return 0;
}
char pending_special_char;
static void
line_handler (char *line)
{
if (line == NULL)
{
char buf[1];
DPRINT0("saw eof!\n");
buf[0] = '\004'; /* ctrl/d */
write (out_to_inferior_fd, buf, 1);
}
else
{
static char enter[] = "\r";
/* Send line to inferior: */
int length = strlen (line);
if (length > ECHO_SUPPRESS_MAX-2)
{
echo_suppress_start = 0;
echo_suppress_limit = 0;
}
else
{
if (echo_suppress_limit + length > ECHO_SUPPRESS_MAX - 2)
{
if (echo_suppress_limit - echo_suppress_start + length
<= ECHO_SUPPRESS_MAX - 2)
{
memmove (echo_suppress_buffer,
echo_suppress_buffer + echo_suppress_start,
echo_suppress_limit - echo_suppress_start);
echo_suppress_limit -= echo_suppress_start;
echo_suppress_start = 0;
}
else
{
echo_suppress_limit = 0;
}
echo_suppress_start = 0;
}
memcpy (echo_suppress_buffer + echo_suppress_limit,
line, length);
echo_suppress_limit += length;
echo_suppress_buffer[echo_suppress_limit++] = '\r';
echo_suppress_buffer[echo_suppress_limit++] = '\n';
}
write (out_to_inferior_fd, line, length);
if (pending_special_char == 0)
{
write (out_to_inferior_fd, enter, sizeof(enter)-1);
if (*line)
add_history (line);
}
free (line);
}
rl_callback_handler_remove ();
buf_count = 0;
num_keys = 0;
if (pending_special_char != 0)
{
write (out_to_inferior_fd, &pending_special_char, 1);
pending_special_char = 0;
}
}
/* Value of rl_getc_function.
Use this because readline should read from stdin, not rl_instream,
points to the pty (so readline has monitor its terminal modes). */
int
my_rl_getc (FILE *dummy)
{
int ch = rl_getc (stdin);
if (is_special_char (ch))
{
pending_special_char = ch;
return '\r';
}
return ch;
}
int
main(int argc, char** argv)
{
char *path;
int i;
int master;
char *name;
int in_from_tty_fd;
struct sigaction act;
struct winsize ws;
struct termios t;
int maxfd;
fd_set in_set;
static char empty_string[1] = "";
char *prompt = empty_string;
int ioctl_err = 0;
int arg_base = 1;
#ifdef DEBUG
logfile = fopen("/tmp/rlfe.log", "w");
#endif
while (arg_base<argc)
{
if (argv[arg_base][0] != '-')
break;
if (arg_base+1 >= argc )
usage_exit();
switch(argv[arg_base][1])
{
case 'h':
arg_base++;
hist_file = argv[arg_base];
break;
case 's':
arg_base++;
hist_size = atoi(argv[arg_base]);
if (hist_size<0)
usage_exit();
break;
default:
usage_exit();
}
arg_base++;
}
if (hist_file)
read_history (hist_file);
set_edit_mode ();
rl_readline_name = APPLICATION_NAME;
if ((master = OpenPTY (&name)) < 0)
{
perror("ptypair: could not open master pty");
exit(1);
}
DPRINT1("pty name: '%s'\n", name);
/* set up SIGWINCH handler */
act.sa_handler = sigwinch_handler;
sigemptyset(&(act.sa_mask));
act.sa_flags = 0;
if (sigaction(SIGWINCH, &act, NULL) < 0)
{
perror("ptypair: could not handle SIGWINCH ");
exit(1);
}
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) < 0)
{
perror("ptypair: could not get window size");
exit(1);
}
if ((child = fork()) < 0)
{
perror("cannot fork");
exit(1);
}
if (child == 0)
{
int slave; /* file descriptor for slave pty */
/* We are in the child process */
close(master);
#ifdef TIOCSCTTY
if ((slave = get_slave_pty(name)) < 0)
{
perror("ptypair: could not open slave pty");
exit(1);
}
#endif
/* We need to make this process a session group leader, because
* it is on a new PTY, and things like job control simply will
* not work correctly unless there is a session group leader
* and process group leader (which a session group leader
* automatically is). This also disassociates us from our old
* controlling tty.
*/
if (setsid() < 0)
{
perror("could not set session leader");
}
/* Tie us to our new controlling tty. */
#ifdef TIOCSCTTY
if (ioctl(slave, TIOCSCTTY, NULL))
{
perror("could not set new controlling tty");
}
#else
if ((slave = get_slave_pty(name)) < 0)
{
perror("ptypair: could not open slave pty");
exit(1);
}
#endif
/* make slave pty be standard in, out, and error */
dup2(slave, STDIN_FILENO);
dup2(slave, STDOUT_FILENO);
dup2(slave, STDERR_FILENO);
/* at this point the slave pty should be standard input */
if (slave > 2)
{
close(slave);
}
/* Try to restore window size; failure isn't critical */
if (ioctl(STDOUT_FILENO, TIOCSWINSZ, &ws) < 0)
{
perror("could not restore window size");
}
/* now start the shell */
{
static char* command_args[] = { COMMAND_ARGS, NULL };
static char* alt_command_args[] = { ALT_COMMAND_ARGS, NULL };
if (argc <= 1)
{
execvp (COMMAND, command_args);
execvp (ALT_COMMAND, alt_command_args);
}
else
execvp (argv[arg_base], &argv[arg_base]);
}
/* should never be reached */
exit(1);
}
/* parent */
signal (SIGCHLD, sig_child);
/* Note that we only set termios settings for standard input;
* the master side of a pty is NOT a tty.
*/
tcgetattr(STDIN_FILENO, &orig_term);
t = orig_term;
eof_char = t.c_cc[VEOF];
/* add_special_char(t.c_cc[VEOF]);*/
add_special_char(t.c_cc[VINTR]);
add_special_char(t.c_cc[VQUIT]);
add_special_char(t.c_cc[VSUSP]);
#if defined (VDISCARD)
add_special_char(t.c_cc[VDISCARD]);
#endif
t.c_lflag &= ~(ICANON | ISIG | ECHO | ECHOCTL | ECHOE | \
ECHOK | ECHOKE | ECHONL | ECHOPRT );
t.c_iflag &= ~ICRNL;
t.c_iflag |= IGNBRK;
t.c_cc[VMIN] = 1;
t.c_cc[VTIME] = 0;
tcsetattr(STDIN_FILENO, TCSANOW, &t);
in_from_inferior_fd = master;
out_to_inferior_fd = master;
rl_instream = fdopen (master, "r");
rl_getc_function = my_rl_getc;
rl_prep_term_function = null_prep_terminal;
rl_deprep_term_function = null_deprep_terminal;
rl_pre_input_hook = pre_input_change_mode;
rl_callback_handler_install (prompt, line_handler);
in_from_tty_fd = STDIN_FILENO;
FD_ZERO (&in_set);
maxfd = in_from_inferior_fd > in_from_tty_fd ? in_from_inferior_fd
: in_from_tty_fd;
for (;;)
{
int num;
FD_SET (in_from_inferior_fd, &in_set);
FD_SET (in_from_tty_fd, &in_set);
num = select(maxfd+1, &in_set, NULL, NULL, NULL);
if (propagate_sigwinch)
{
struct winsize ws;
if (ioctl (STDIN_FILENO, TIOCGWINSZ, &ws) >= 0)
{
ioctl (master, TIOCSWINSZ, &ws);
}
propagate_sigwinch = 0;
continue;
}
if (num <= 0)
{
perror ("select");
exit (-1);
}
if (FD_ISSET (in_from_tty_fd, &in_set))
{
extern int readline_echoing_p;
struct termios term_master;
int do_canon = 1;
int do_icrnl = 1;
int ioctl_ret;
DPRINT1("[tty avail num_keys:%d]\n", num_keys);
/* If we can't get tty modes for the master side of the pty, we
can't handle non-canonical-mode programs. Always assume the
master is in canonical echo mode if we can't tell. */
ioctl_ret = tcgetattr(master, &term_master);
if (ioctl_ret >= 0)
{
do_canon = (term_master.c_lflag & ICANON) != 0;
do_icrnl = (term_master.c_lflag & ICRNL) != 0;
readline_echoing_p = (term_master.c_lflag & ECHO) != 0;
DPRINT1 ("echo,canon,crnl:%03d\n",
100 * readline_echoing_p
+ 10 * do_canon
+ 1 * do_icrnl);
}
else
{
if (ioctl_err == 0)
DPRINT1("tcgetattr on master fd failed: errno = %d\n", errno);
ioctl_err = 1;
}
if (do_canon == 0 && num_keys == 0)
{
char ch[10];
int count = read (STDIN_FILENO, ch, sizeof(ch));
DPRINT1("[read %d chars from stdin: ", count);
DPRINT2(" \"%.*s\"]\n", count, ch);
if (do_icrnl)
{
int i = count;
while (--i >= 0)
{
if (ch[i] == '\r')
ch[i] = '\n';
}
}
maybe_emphasize_input (1);
write (out_to_inferior_fd, ch, count);
}
else
{
if (num_keys == 0)
{
int i;
/* Re-install callback handler for new prompt. */
if (prompt != empty_string)
free (prompt);
if (prompt == NULL)
{
DPRINT0("New empty prompt\n");
prompt = empty_string;
}
else
{
if (do_emphasize_input && buf_count > 0)
{
prompt = malloc (buf_count + strlen (end_input_mode)
+ strlen (start_input_mode) + 5);
sprintf (prompt, "\001%s\002%.*s\001%s\002",
end_input_mode,
buf_count, buf,
start_input_mode);
}
else
{
prompt = malloc (buf_count + 1);
memcpy (prompt, buf, buf_count);
prompt[buf_count] = '\0';
}
DPRINT1("New prompt '%s'\n", prompt);
#if 0 /* ifdef HAVE_RL_ALREADY_PROMPTED */
/* Doesn't quite work when do_emphasize_input is 1. */
rl_already_prompted = buf_count > 0;
#else
if (buf_count > 0)
write (1, "\r", 1);
#endif
}
rl_callback_handler_install (prompt, line_handler);
}
num_keys++;
maybe_emphasize_input (1);
rl_callback_read_char ();
}
}
else /* output from inferior. */
{
int i;
int count;
int old_count;
if (buf_count > (sizeof(buf) >> 2))
buf_count = 0;
count = read (in_from_inferior_fd, buf+buf_count,
sizeof(buf) - buf_count);
DPRINT2("read %d from inferior, buf_count=%d", count, buf_count);
DPRINT2(": \"%.*s\"", count, buf+buf_count);
maybe_emphasize_input (0);
if (count <= 0)
{
DPRINT0 ("(Connection closed by foreign host.)\n");
tcsetattr(STDIN_FILENO, TCSANOW, &orig_term);
exit (0);
}
old_count = buf_count;
/* Look for any pending echo that we need to suppress. */
while (echo_suppress_start < echo_suppress_limit
&& count > 0
&& buf[buf_count] == echo_suppress_buffer[echo_suppress_start])
{
count--;
buf_count++;
echo_suppress_start++;
}
DPRINT1("suppressed %d characters of echo.\n", buf_count-old_count);
/* Write to the terminal anything that was not suppressed. */
if (count > 0)
write (1, buf + buf_count, count);
/* Finally, look for a prompt candidate.
* When we get around to going input (from the keyboard),
* we will consider the prompt to be anything since the last
* line terminator. So we need to save that text in the
* initial part of buf. However, anything before the
* most recent end-of-line is not interesting. */
buf_count += count;
#if 1
for (i = buf_count; --i >= old_count; )
#else
for (i = buf_count - 1; i-- >= buf_count - count; )
#endif
{
if (buf[i] == '\n' || buf[i] == '\r')
{
i++;
memmove (buf, buf+i, buf_count - i);
buf_count -= i;
break;
}
}
DPRINT2("-> i: %d, buf_count: %d\n", i, buf_count);
}
}
}
static void set_edit_mode ()
{
int vi = 0;
char *shellopts;
shellopts = getenv ("SHELLOPTS");
while (shellopts != 0)
{
if (strncmp ("vi", shellopts, 2) == 0)
{
vi = 1;
break;
}
shellopts = index (shellopts + 1, ':');
}
if (!vi)
{
if (getenv ("EDITOR") != 0)
vi |= strcmp (getenv ("EDITOR"), "vi") == 0;
}
if (vi)
rl_variable_bind ("editing-mode", "vi");
else
rl_variable_bind ("editing-mode", "emacs");
}
static void usage_exit ()
{
fprintf (stderr, "Usage: rlfe [-h histfile] [-s size] cmd [arg1] [arg2] ...\n\n");
exit (1);
}

View File

@@ -0,0 +1,2 @@
/* Dummy header to avoid modifying pty.c */
#include "os.h"

View File

@@ -0,0 +1,337 @@
/*
*
* Another test harness for the readline callback interface.
*
* Author: Bob Rossi <bob@brasko.net>
*/
#if defined (HAVE_CONFIG_H)
#include <config.h>
#endif
#include <stdio.h>
#include <sys/types.h>
#include <errno.h>
#include <curses.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#if 0 /* LINUX */
#include <pty.h>
#else
#include <util.h>
#endif
#ifdef READLINE_LIBRARY
# include "readline.h"
#else
# include <readline/readline.h>
#endif
/**
* Master/Slave PTY used to keep readline off of stdin/stdout.
*/
static int masterfd = -1;
static int slavefd;
void
sigint (s)
int s;
{
tty_reset (STDIN_FILENO);
close (masterfd);
close (slavefd);
printf ("\n");
exit (0);
}
static int
user_input()
{
int size;
const int MAX = 1024;
char *buf = (char *)malloc(MAX+1);
size = read (STDIN_FILENO, buf, MAX);
if (size == -1)
return -1;
size = write (masterfd, buf, size);
if (size == -1)
return -1;
return 0;
}
static int
readline_input()
{
const int MAX = 1024;
char *buf = (char *)malloc(MAX+1);
int size;
size = read (masterfd, buf, MAX);
if (size == -1)
{
free( buf );
buf = NULL;
return -1;
}
buf[size] = 0;
/* Display output from readline */
if ( size > 0 )
fprintf(stderr, "%s", buf);
free( buf );
buf = NULL;
return 0;
}
static void
rlctx_send_user_command(char *line)
{
/* This happens when rl_callback_read_char gets EOF */
if ( line == NULL )
return;
if (strcmp (line, "exit") == 0) {
tty_reset (STDIN_FILENO);
close (masterfd);
close (slavefd);
printf ("\n");
exit (0);
}
/* Don't add the enter command */
if ( line && *line != '\0' )
add_history(line);
}
static void
custom_deprep_term_function ()
{
}
static int
init_readline (int inputfd, int outputfd)
{
FILE *inputFILE, *outputFILE;
inputFILE = fdopen (inputfd, "r");
if (!inputFILE)
return -1;
outputFILE = fdopen (outputfd, "w");
if (!outputFILE)
return -1;
rl_instream = inputFILE;
rl_outstream = outputFILE;
/* Tell readline what the prompt is if it needs to put it back */
rl_callback_handler_install("(rltest): ", rlctx_send_user_command);
/* Set the terminal type to dumb so the output of readline can be
* understood by tgdb */
if ( rl_reset_terminal("dumb") == -1 )
return -1;
/* For some reason, readline can not deprep the terminal.
* However, it doesn't matter because no other application is working on
* the terminal besides readline */
rl_deprep_term_function = custom_deprep_term_function;
using_history();
read_history(".history");
return 0;
}
static int
main_loop(void)
{
fd_set rset;
int max;
max = (masterfd > STDIN_FILENO) ? masterfd : STDIN_FILENO;
max = (max > slavefd) ? max : slavefd;
for (;;)
{
/* Reset the fd_set, and watch for input from GDB or stdin */
FD_ZERO(&rset);
FD_SET(STDIN_FILENO, &rset);
FD_SET(slavefd, &rset);
FD_SET(masterfd, &rset);
/* Wait for input */
if (select(max + 1, &rset, NULL, NULL, NULL) == -1)
{
if (errno == EINTR)
continue;
else
return -1;
}
/* Input received through the pty: Handle it
* Wrote to masterfd, slave fd has that input, alert readline to read it.
*/
if (FD_ISSET(slavefd, &rset))
rl_callback_read_char();
/* Input received through the pty.
* Readline read from slavefd, and it wrote to the masterfd.
*/
if (FD_ISSET(masterfd, &rset))
if ( readline_input() == -1 )
return -1;
/* Input received: Handle it, write to masterfd (input to readline) */
if (FD_ISSET(STDIN_FILENO, &rset))
if ( user_input() == -1 )
return -1;
}
return 0;
}
/* The terminal attributes before calling tty_cbreak */
static struct termios save_termios;
static struct winsize size;
static enum { RESET, TCBREAK } ttystate = RESET;
/* tty_cbreak: Sets terminal to cbreak mode. Also known as noncanonical mode.
* 1. Signal handling is still turned on, so the user can still type those.
* 2. echo is off
* 3. Read in one char at a time.
*
* fd - The file descriptor of the terminal
*
* Returns: 0 on sucess, -1 on error
*/
int tty_cbreak(int fd){
struct termios buf;
int ttysavefd = -1;
if(tcgetattr(fd, &save_termios) < 0)
return -1;
buf = save_termios;
buf.c_lflag &= ~(ECHO | ICANON);
buf.c_iflag &= ~(ICRNL | INLCR);
buf.c_cc[VMIN] = 1;
buf.c_cc[VTIME] = 0;
#if defined (VLNEXT) && defined (_POSIX_VDISABLE)
buf.c_cc[VLNEXT] = _POSIX_VDISABLE;
#endif
#if defined (VDSUSP) && defined (_POSIX_VDISABLE)
buf.c_cc[VDSUSP] = _POSIX_VDISABLE;
#endif
/* enable flow control; only stty start char can restart output */
#if 0
buf.c_iflag |= (IXON|IXOFF);
#ifdef IXANY
buf.c_iflag &= ~IXANY;
#endif
#endif
/* disable flow control; let ^S and ^Q through to pty */
buf.c_iflag &= ~(IXON|IXOFF);
#ifdef IXANY
buf.c_iflag &= ~IXANY;
#endif
if(tcsetattr(fd, TCSAFLUSH, &buf) < 0)
return -1;
ttystate = TCBREAK;
ttysavefd = fd;
/* set size */
if(ioctl(fd, TIOCGWINSZ, (char *)&size) < 0)
return -1;
#ifdef DEBUG
err_msg("%d rows and %d cols\n", size.ws_row, size.ws_col);
#endif
return (0);
}
int
tty_off_xon_xoff (int fd)
{
struct termios buf;
int ttysavefd = -1;
if(tcgetattr(fd, &buf) < 0)
return -1;
buf.c_iflag &= ~(IXON|IXOFF);
if(tcsetattr(fd, TCSAFLUSH, &buf) < 0)
return -1;
return 0;
}
/* tty_reset: Sets the terminal attributes back to their previous state.
* PRE: tty_cbreak must have already been called.
*
* fd - The file descrioptor of the terminal to reset.
*
* Returns: 0 on success, -1 on error
*/
int tty_reset(int fd)
{
if(ttystate != TCBREAK)
return (0);
if(tcsetattr(fd, TCSAFLUSH, &save_termios) < 0)
return (-1);
ttystate = RESET;
return 0;
}
int
main()
{
int val;
val = openpty (&masterfd, &slavefd, NULL, NULL, NULL);
if (val == -1)
return -1;
val = tty_off_xon_xoff (masterfd);
if (val == -1)
return -1;
val = init_readline (slavefd, slavefd);
if (val == -1)
return -1;
val = tty_cbreak (STDIN_FILENO);
if (val == -1)
return -1;
signal (SIGINT, sigint);
val = main_loop ();
tty_reset (STDIN_FILENO);
if (val == -1)
return -1;
return 0;
}

View File

@@ -4,11 +4,25 @@
/* */
/* **************************************************************** */
/*
* Remove the next line if you're compiling this against an installed
* libreadline.a
*/
#define READLINE_LIBRARY
/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
The GNU Readline Library is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
The GNU Readline Library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#if defined (HAVE_CONFIG_H)
#include <config.h>
@@ -16,8 +30,20 @@
#include <stdio.h>
#include <sys/types.h>
#include "readline.h"
#include "history.h"
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#else
extern void exit();
#endif
#ifdef READLINE_LIBRARY
# include "readline.h"
# include "history.h"
#else
# include <readline/readline.h>
# include <readline/history.h>
#endif
extern HIST_ENTRY **history_list ();

View File

@@ -0,0 +1,49 @@
/*
* rlversion -- print out readline's version number
*/
/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
The GNU Readline Library is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
The GNU Readline Library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#if defined (HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdio.h>
#include <sys/types.h>
#include "posixstat.h"
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#else
extern void exit();
#endif
#ifdef READLINE_LIBRARY
# include "readline.h"
#else
# include <readline/readline.h>
#endif
main()
{
printf ("%s\n", rl_library_version ? rl_library_version : "unknown");
exit (0);
}

View File

@@ -7,7 +7,7 @@
The GNU Readline Library is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 1, or
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
The GNU Readline Library is distributed in the hope that it will be
@@ -18,15 +18,13 @@
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#define READLINE_LIBRARY
#if defined (HAVE_CONFIG_H)
# include <config.h>
#endif
extern char *xmalloc (), *xrealloc ();
#if !defined (BUFSIZ)
#include <stdio.h>
#endif /* BUFSIZ */
@@ -40,7 +38,15 @@ extern char *xmalloc (), *xrealloc ();
#include "rlconf.h"
#include "readline.h"
extern int _rl_qsort_string_compare ();
#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;
@@ -54,7 +60,8 @@ static FUNMAP default_funmap[] = {
{ "abort", rl_abort },
{ "accept-line", rl_newline },
{ "arrow-key-prefix", rl_arrow_keys },
{ "backward-char", rl_backward },
{ "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 },
@@ -71,6 +78,7 @@ static FUNMAP default_funmap[] = {
{ "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 },
@@ -83,7 +91,9 @@ static FUNMAP default_funmap[] = {
{ "end-of-history", rl_end_of_history },
{ "end-of-line", rl_end_of_line },
{ "exchange-point-and-mark", rl_exchange_point_and_mark },
{ "forward-char", rl_forward },
{ "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 },
@@ -100,7 +110,8 @@ static FUNMAP default_funmap[] = {
{ "non-incremental-reverse-search-history", rl_noninc_reverse_search },
{ "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
{ "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
#ifdef __CYGWIN32__
{ "overwrite-mode", rl_overwrite_mode },
#ifdef __CYGWIN__
{ "paste-from-clipboard", rl_paste_from_clipboard },
#endif
{ "possible-completions", rl_possible_completions },
@@ -120,6 +131,7 @@ static FUNMAP default_funmap[] = {
{ "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 },
@@ -134,7 +146,6 @@ static FUNMAP default_funmap[] = {
{ "vi-arg-digit", rl_vi_arg_digit },
{ "vi-back-to-indent", rl_vi_back_to_indent },
{ "vi-bWord", rl_vi_bWord },
{ "vi-bracktype", rl_vi_bracktype },
{ "vi-bword", rl_vi_bword },
{ "vi-change-case", rl_vi_change_case },
{ "vi-change-char", rl_vi_change_char },
@@ -165,6 +176,7 @@ static FUNMAP default_funmap[] = {
{ "vi-put", rl_vi_put },
{ "vi-redo", rl_vi_redo },
{ "vi-replace", rl_vi_replace },
{ "vi-rubout", rl_vi_rubout },
{ "vi-search", rl_vi_search },
{ "vi-search-again", rl_vi_search_again },
{ "vi-set-mark", rl_vi_set_mark },
@@ -174,13 +186,13 @@ static FUNMAP default_funmap[] = {
{ "vi-yank-to", rl_vi_yank_to },
#endif /* VI_MODE */
{(char *)NULL, (Function *)NULL }
{(char *)NULL, (rl_command_func_t *)NULL }
};
int
rl_add_funmap_entry (name, function)
char *name;
Function *function;
const char *name;
rl_command_func_t *function;
{
if (funmap_entry + 2 >= funmap_size)
{
@@ -217,36 +229,27 @@ rl_initialize_funmap ()
/* Produce a NULL terminated array of known function names. The array
is sorted. The array itself is allocated, but not the strings inside.
You should free () the array when you done, but not the pointrs. */
char **
const char **
rl_funmap_names ()
{
char **result;
const char **result;
int result_size, result_index;
/* Make sure that the function map has been initialized. */
rl_initialize_funmap ();
for (result_index = result_size = 0, result = (char **)NULL; funmap[result_index]; result_index++)
for (result_index = result_size = 0, result = (const char **)NULL; funmap[result_index]; result_index++)
{
if (result_index + 2 > result_size)
{
result_size += 20;
result = (char **)xrealloc (result, result_size * sizeof (char *));
result = (const char **)xrealloc (result, result_size * sizeof (char *));
}
result[result_index] = funmap[result_index]->name;
result[result_index + 1] = (char *)NULL;
}
qsort (result, result_index, sizeof (char *), _rl_qsort_string_compare);
qsort (result, result_index, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
return (result);
}
/* Things that mean `Control'. */
char *possible_control_prefixes[] = {
"Control-", "C-", "CTRL-", (char *)NULL
};
char *possible_meta_prefixes[] = {
"Meta", "M-", (char *)NULL
};

View File

@@ -1,13 +1,13 @@
/* histexpand.c -- history expansion. */
/* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
/* Copyright (C) 1989-2004 Free Software Foundation, Inc.
This file contains the GNU History Library (the Library), a set of
routines for managing the text of previously typed lines.
The Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
the Free Software Foundation; either version 2, or (at your option)
any later version.
The Library is distributed in the hope that it will be useful, but
@@ -18,7 +18,7 @@
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#define READLINE_LIBRARY
@@ -41,18 +41,23 @@
# include <unistd.h>
#endif
#if defined (HAVE_STRING_H)
# include <string.h>
#else
# include <strings.h>
#endif /* !HAVE_STRING_H */
#include "rlmbutil.h"
#include "history.h"
#include "histlib.h"
#include "rlshell.h"
#include "xmalloc.h"
#define HISTORY_WORD_DELIMITERS " \t\n;&()|<>"
#define HISTORY_QUOTE_CHARACTERS "\"'`"
#define slashify_in_quotes "\\`\"$"
typedef int _hist_search_func_t PARAMS((const char *, int));
extern int rl_byte_oriented; /* declared in mbutil.c */
static char error_pointer;
static char *subst_lhs;
@@ -60,15 +65,12 @@ static char *subst_rhs;
static int subst_lhs_len;
static int subst_rhs_len;
static char *get_history_word_specifier ();
static char *history_find_word ();
static char *get_history_word_specifier PARAMS((char *, char *, int *));
static char *history_find_word PARAMS((char *, int));
static int history_tokenize_word PARAMS((const char *, int));
static char *history_substring PARAMS((const char *, int, int));
extern int history_offset;
extern char *single_quote ();
static char *quote_breaks ();
extern char *xmalloc (), *xrealloc ();
static char *quote_breaks PARAMS((char *));
/* Variables exported by this file. */
/* The character that represents the start of a history expansion
@@ -93,9 +95,12 @@ char *history_no_expand_chars = " \t\n\r=";
The default is 0. */
int history_quotes_inhibit_expansion = 0;
/* Used to split words by history_tokenize_internal. */
char *history_word_delimiters = HISTORY_WORD_DELIMITERS;
/* If set, this points to a function that is called to verify that a
particular history expansion should be performed. */
Function *history_inhibit_expansion_function;
rl_linebuf_func_t *history_inhibit_expansion_function;
/* **************************************************************** */
/* */
@@ -124,7 +129,7 @@ static char *search_match;
line = get_history_event ("!echo:p", &index, 0); */
char *
get_history_event (string, caller_index, delimiting_quote)
char *string;
const char *string;
int *caller_index;
int delimiting_quote;
{
@@ -132,7 +137,7 @@ get_history_event (string, caller_index, delimiting_quote)
register char c;
HIST_ENTRY *entry;
int which, sign, local_index, substring_okay;
Function *search_func;
_hist_search_func_t *search_func;
char *temp;
/* The event can be specified in a number of ways.
@@ -201,15 +206,35 @@ get_history_event (string, caller_index, delimiting_quote)
/* Only a closing `?' or a newline delimit a substring search string. */
for (local_index = i; c = string[i]; i++)
if ((!substring_okay && (whitespace (c) || c == ':' ||
(history_search_delimiter_chars && member (c, history_search_delimiter_chars)) ||
string[i] == delimiting_quote)) ||
string[i] == '\n' ||
(substring_okay && string[i] == '?'))
break;
{
#if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
{
int v;
mbstate_t ps;
memset (&ps, 0, sizeof (mbstate_t));
/* These produce warnings because we're passing a const string to a
function that takes a non-const string. */
_rl_adjust_point ((char *)string, i, &ps);
if ((v = _rl_get_char_len ((char *)string + i, &ps)) > 1)
{
i += v - 1;
continue;
}
}
#endif /* HANDLE_MULTIBYTE */
if ((!substring_okay && (whitespace (c) || c == ':' ||
(history_search_delimiter_chars && member (c, history_search_delimiter_chars)) ||
string[i] == delimiting_quote)) ||
string[i] == '\n' ||
(substring_okay && string[i] == '?'))
break;
}
which = i - local_index;
temp = xmalloc (1 + which);
temp = (char *)xmalloc (1 + which);
if (which)
strncpy (temp, string + local_index, which);
temp[which] = '\0';
@@ -311,7 +336,7 @@ quote_breaks (s)
len += 2;
}
r = ret = xmalloc (len);
r = ret = (char *)xmalloc (len);
*r++ = '\'';
for (p = s; p && *p; )
{
@@ -342,7 +367,8 @@ hist_error(s, start, current, errtype)
char *s;
int start, current, errtype;
{
char *temp, *emsg;
char *temp;
const char *emsg;
int ll, elen;
ll = current - start;
@@ -365,13 +391,17 @@ hist_error(s, start, current, errtype)
emsg = "unrecognized history modifier";
elen = 29;
break;
case NO_PREV_SUBST:
emsg = "no previous substitution";
elen = 24;
break;
default:
emsg = "unknown expansion error";
elen = 23;
break;
}
temp = xmalloc (ll + elen + 3);
temp = (char *)xmalloc (ll + elen + 3);
strncpy (temp, s + start, ll);
temp[ll] = ':';
temp[ll + 1] = ' ';
@@ -397,17 +427,37 @@ get_subst_pattern (str, iptr, delimiter, is_rhs, lenptr)
int *iptr, delimiter, is_rhs, *lenptr;
{
register int si, i, j, k;
char *s = (char *) NULL;
char *s;
#if defined (HANDLE_MULTIBYTE)
mbstate_t ps;
#endif
s = (char *)NULL;
i = *iptr;
#if defined (HANDLE_MULTIBYTE)
memset (&ps, 0, sizeof (mbstate_t));
_rl_adjust_point (str, i, &ps);
#endif
for (si = i; str[si] && str[si] != delimiter; si++)
if (str[si] == '\\' && str[si + 1] == delimiter)
si++;
#if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
{
int v;
if ((v = _rl_get_char_len (str + si, &ps)) > 1)
si += v - 1;
else if (str[si] == '\\' && str[si + 1] == delimiter)
si++;
}
else
#endif /* HANDLE_MULTIBYTE */
if (str[si] == '\\' && str[si + 1] == delimiter)
si++;
if (si > i || is_rhs)
{
s = xmalloc (si - i + 1);
s = (char *)xmalloc (si - i + 1);
for (j = 0, k = i; k < si; j++, k++)
{
/* Remove a backslash quoting the search string delimiter. */
@@ -434,13 +484,13 @@ postproc_subst_rhs ()
char *new;
int i, j, new_size;
new = xmalloc (new_size = subst_rhs_len + subst_lhs_len);
new = (char *)xmalloc (new_size = subst_rhs_len + subst_lhs_len);
for (i = j = 0; i < subst_rhs_len; i++)
{
if (subst_rhs[i] == '&')
{
if (j + subst_lhs_len >= new_size)
new = xrealloc (new, (new_size = new_size * 2 + subst_lhs_len));
new = (char *)xrealloc (new, (new_size = new_size * 2 + subst_lhs_len));
strcpy (new + j, subst_lhs);
j += subst_lhs_len;
}
@@ -450,7 +500,7 @@ postproc_subst_rhs ()
if (subst_rhs[i] == '\\' && subst_rhs[i + 1] == '&')
i++;
if (j >= new_size)
new = xrealloc (new, new_size *= 2);
new = (char *)xrealloc (new, new_size *= 2);
new[j++] = subst_rhs[i];
}
}
@@ -473,11 +523,16 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
char *current_line; /* for !# */
{
int i, n, starting_index;
int substitute_globally, want_quotes, print_only;
int substitute_globally, subst_bywords, want_quotes, print_only;
char *event, *temp, *result, *tstr, *t, c, *word_spec;
int result_len;
#if defined (HANDLE_MULTIBYTE)
mbstate_t ps;
result = xmalloc (result_len = 128);
memset (&ps, 0, sizeof (mbstate_t));
#endif
result = (char *)xmalloc (result_len = 128);
i = start;
@@ -506,8 +561,21 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
quote, then this expansion takes place inside of the
quoted string. If we have to search for some text ("!foo"),
allow the delimiter to end the search string. */
if (i && (string[i - 1] == '\'' || string[i - 1] == '"'))
quoted_search_delimiter = string[i - 1];
#if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
{
int c, l;
l = _rl_find_prev_mbchar (string, i, MB_FIND_ANY);
c = string[l];
/* XXX - original patch had i - 1 ??? If i == 0 it would fail. */
if (i && (c == '\'' || c == '"'))
quoted_search_delimiter = c;
}
else
#endif /* HANDLE_MULTIBYTE */
if (i && (string[i - 1] == '\'' || string[i - 1] == '"'))
quoted_search_delimiter = string[i - 1];
event = get_history_event (string, &i, quoted_search_delimiter);
}
@@ -537,19 +605,25 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
FREE (word_spec);
/* Perhaps there are other modifiers involved. Do what they say. */
want_quotes = substitute_globally = print_only = 0;
want_quotes = substitute_globally = subst_bywords = print_only = 0;
starting_index = i;
while (string[i] == ':')
{
c = string[i + 1];
if (c == 'g')
if (c == 'g' || c == 'a')
{
substitute_globally = 1;
i++;
c = string[i + 1];
}
else if (c == 'G')
{
subst_bywords = 1;
i++;
c = string[i + 1];
}
switch (c)
{
@@ -620,13 +694,26 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
case '&':
case 's':
{
char *new_event, *t;
int delimiter, failed, si, l_temp;
char *new_event;
int delimiter, failed, si, l_temp, ws, we;
if (c == 's')
{
if (i + 2 < (int)strlen (string))
delimiter = string[i + 2];
{
#if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
{
_rl_adjust_point (string, i + 2, &ps);
if (_rl_get_char_len (string + i + 2, &ps) > 1)
delimiter = 0;
else
delimiter = string[i + 2];
}
else
#endif /* HANDLE_MULTIBYTE */
delimiter = string[i + 2];
}
else
break; /* no search delimiter */
@@ -654,15 +741,6 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
}
}
/* If there is no lhs, the substitution can't succeed. */
if (subst_lhs_len == 0)
{
*ret_string = hist_error (string, starting_index, i, SUBST_FAILED);
free (result);
free (temp);
return -1;
}
FREE (subst_rhs);
subst_rhs = get_subst_pattern (string, &i, delimiter, 1, &subst_rhs_len);
@@ -674,6 +752,15 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
else
i += 2;
/* If there is no lhs, the substitution can't succeed. */
if (subst_lhs_len == 0)
{
*ret_string = hist_error (string, starting_index, i, NO_PREV_SUBST);
free (result);
free (temp);
return -1;
}
l_temp = strlen (temp);
/* Ignore impossible cases. */
if (subst_lhs_len > l_temp)
@@ -685,33 +772,67 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
}
/* Find the first occurrence of THIS in TEMP. */
si = 0;
/* Substitute SUBST_RHS for SUBST_LHS in TEMP. There are three
cases to consider:
1. substitute_globally == subst_bywords == 0
2. substitute_globally == 1 && subst_bywords == 0
3. substitute_globally == 0 && subst_bywords == 1
In the first case, we substitute for the first occurrence only.
In the second case, we substitute for every occurrence.
In the third case, we tokenize into words and substitute the
first occurrence of each word. */
si = we = 0;
for (failed = 1; (si + subst_lhs_len) <= l_temp; si++)
if (STREQN (temp+si, subst_lhs, subst_lhs_len))
{
int len = subst_rhs_len - subst_lhs_len + l_temp;
new_event = xmalloc (1 + len);
strncpy (new_event, temp, si);
strncpy (new_event + si, subst_rhs, subst_rhs_len);
strncpy (new_event + si + subst_rhs_len,
temp + si + subst_lhs_len,
l_temp - (si + subst_lhs_len));
new_event[len] = '\0';
free (temp);
temp = new_event;
{
/* First skip whitespace and find word boundaries if
we're past the end of the word boundary we found
the last time. */
if (subst_bywords && si > we)
{
for (; temp[si] && whitespace (temp[si]); si++)
;
ws = si;
we = history_tokenize_word (temp, si);
}
failed = 0;
if (STREQN (temp+si, subst_lhs, subst_lhs_len))
{
int len = subst_rhs_len - subst_lhs_len + l_temp;
new_event = (char *)xmalloc (1 + len);
strncpy (new_event, temp, si);
strncpy (new_event + si, subst_rhs, subst_rhs_len);
strncpy (new_event + si + subst_rhs_len,
temp + si + subst_lhs_len,
l_temp - (si + subst_lhs_len));
new_event[len] = '\0';
free (temp);
temp = new_event;
if (substitute_globally)
{
si += subst_rhs_len;
l_temp = strlen (temp);
substitute_globally++;
continue;
}
else
break;
}
failed = 0;
if (substitute_globally)
{
/* Reported to fix a bug that causes it to skip every
other match when matching a single character. Was
si += subst_rhs_len previously. */
si += subst_rhs_len - 1;
l_temp = strlen (temp);
substitute_globally++;
continue;
}
else if (subst_bywords)
{
si = we;
l_temp = strlen (temp);
continue;
}
else
break;
}
}
if (substitute_globally > 1)
{
@@ -739,7 +860,7 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
char *x;
if (want_quotes == 'q')
x = single_quote (temp);
x = sh_single_quote (temp);
else if (want_quotes == 'x')
x = quote_breaks (temp);
else
@@ -751,7 +872,7 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
n = strlen (temp);
if (n >= result_len)
result = xrealloc (result, n + 2);
result = (char *)xrealloc (result, n + 2);
strcpy (result, temp);
free (temp);
@@ -782,7 +903,7 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
{ \
while (j >= result_len) \
result_len += 128; \
result = xrealloc (result, result_len); \
result = (char *)xrealloc (result, result_len); \
} \
strcpy (result + j - sl, s); \
} \
@@ -792,7 +913,7 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
do \
{ \
if (j >= result_len - 1) \
result = xrealloc (result, result_len += 64); \
result = (char *)xrealloc (result, result_len += 64); \
result[j++] = c; \
result[j] = '\0'; \
} \
@@ -804,16 +925,24 @@ history_expand (hstring, output)
char **output;
{
register int j;
int i, r, l, passc, cc, modified, eindex, only_printing;
int i, r, l, passc, cc, modified, eindex, only_printing, dquote;
char *string;
/* The output string, and its length. */
int result_len;
char *result;
#if defined (HANDLE_MULTIBYTE)
char mb[MB_LEN_MAX];
mbstate_t ps;
#endif
/* Used when adding the string. */
char *temp;
if (output == 0)
return 0;
/* Setting the history expansion character to 0 inhibits all
history expansion. */
if (history_expansion_char == 0)
@@ -823,7 +952,7 @@ history_expand (hstring, output)
}
/* Prepare the buffer for printing error messages. */
result = xmalloc (result_len = 256);
result = (char *)xmalloc (result_len = 256);
result[0] = '\0';
only_printing = modified = 0;
@@ -840,7 +969,7 @@ history_expand (hstring, output)
that is the substitution that we do. */
if (hstring[0] == history_subst_char)
{
string = xmalloc (l + 5);
string = (char *)xmalloc (l + 5);
string[0] = string[1] = history_expansion_char;
string[2] = ':';
@@ -850,20 +979,37 @@ history_expand (hstring, output)
}
else
{
#if defined (HANDLE_MULTIBYTE)
memset (&ps, 0, sizeof (mbstate_t));
#endif
string = hstring;
/* If not quick substitution, still maybe have to do expansion. */
/* `!' followed by one of the characters in history_no_expand_chars
is NOT an expansion. */
for (i = 0; string[i]; i++)
for (i = dquote = 0; string[i]; i++)
{
#if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
{
int v;
v = _rl_get_char_len (string + i, &ps);
if (v > 1)
{
i += v - 1;
continue;
}
}
#endif /* HANDLE_MULTIBYTE */
cc = string[i + 1];
/* The history_comment_char, if set, appearing that the beginning
/* The history_comment_char, if set, appearing at the beginning
of a word signifies that the rest of the line should not have
history expansion performed on it.
Skip the rest of the line and break out of the loop. */
if (history_comment_char && string[i] == history_comment_char &&
(i == 0 || member (string[i - 1], HISTORY_WORD_DELIMITERS)))
(i == 0 || member (string[i - 1], history_word_delimiters)))
{
while (string[i])
i++;
@@ -884,9 +1030,19 @@ history_expand (hstring, output)
else
break;
}
/* XXX - at some point, might want to extend this to handle
double quotes as well. */
else if (history_quotes_inhibit_expansion && string[i] == '\'')
/* Shell-like quoting: allow backslashes to quote double quotes
inside a double-quoted string. */
else if (dquote && string[i] == '\\' && cc == '"')
i++;
/* More shell-like quoting: if we're paying attention to single
quotes and letting them quote the history expansion character,
then we need to pay attention to double quotes, because single
quotes are not special inside double-quoted strings. */
else if (history_quotes_inhibit_expansion && string[i] == '"')
{
dquote = 1 - dquote;
}
else if (dquote == 0 && history_quotes_inhibit_expansion && string[i] == '\'')
{
/* If this is bash, single quotes inhibit history expansion. */
i++;
@@ -899,6 +1055,7 @@ history_expand (hstring, output)
if (cc == '\'' || cc == history_expansion_char)
i++;
}
}
if (string[i] != history_expansion_char)
@@ -910,7 +1067,7 @@ history_expand (hstring, output)
}
/* Extract and perform the substitution. */
for (passc = i = j = 0; i < l; i++)
for (passc = dquote = i = j = 0; i < l; i++)
{
int tchar = string[i];
@@ -921,6 +1078,30 @@ history_expand (hstring, output)
continue;
}
#if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
{
int k, c;
c = tchar;
memset (mb, 0, sizeof (mb));
for (k = 0; k < MB_LEN_MAX; k++)
{
mb[k] = (char)c;
memset (&ps, 0, sizeof (mbstate_t));
if (_rl_get_char_len (mb, &ps) == -2)
c = string[++i];
else
break;
}
if (strlen (mb) > 1)
{
ADD_STRING (mb);
break;
}
}
#endif /* HANDLE_MULTIBYTE */
if (tchar == history_expansion_char)
tchar = -3;
else if (tchar == history_comment_char)
@@ -937,11 +1118,16 @@ history_expand (hstring, output)
ADD_CHAR (tchar);
break;
case '"':
dquote = 1 - dquote;
ADD_CHAR (tchar);
break;
case '\'':
{
/* If history_quotes_inhibit_expansion is set, single quotes
inhibit history expansion. */
if (history_quotes_inhibit_expansion)
if (dquote == 0 && history_quotes_inhibit_expansion)
{
int quote, slen;
@@ -949,7 +1135,7 @@ history_expand (hstring, output)
hist_string_extract_single_quoted (string, &i);
slen = i - quote + 2;
temp = xmalloc (slen);
temp = (char *)xmalloc (slen);
strncpy (temp, string + quote, slen);
temp[slen - 1] = '\0';
ADD_STRING (temp);
@@ -961,9 +1147,9 @@ history_expand (hstring, output)
}
case -2: /* history_comment_char */
if (i == 0 || member (string[i - 1], HISTORY_WORD_DELIMITERS))
if (i == 0 || member (string[i - 1], history_word_delimiters))
{
temp = xmalloc (l - i + 1);
temp = (char *)xmalloc (l - i + 1);
strcpy (temp, string + i);
ADD_STRING (temp);
free (temp);
@@ -995,7 +1181,7 @@ history_expand (hstring, output)
{
if (result)
{
temp = xmalloc (1 + strlen (result));
temp = (char *)xmalloc (1 + strlen (result));
strcpy (temp, result);
ADD_STRING (temp);
free (temp);
@@ -1036,7 +1222,9 @@ history_expand (hstring, output)
if (only_printing)
{
#if 0
add_history (result);
#endif
return (2);
}
@@ -1099,7 +1287,10 @@ get_history_word_specifier (spec, from, caller_index)
if (spec[i] == '-')
first = 0;
else if (spec[i] == '^')
first = 1;
{
first = 1;
i++;
}
else if (_rl_digit_p (spec[i]) && expecting_word_spec)
{
for (first = 0; _rl_digit_p (spec[i]); i++)
@@ -1129,7 +1320,14 @@ get_history_word_specifier (spec, from, caller_index)
i++;
last = '$';
}
else if (!spec[i] || spec[i] == ':') /* could be modifier separator */
#if 0
else if (!spec[i] || spec[i] == ':')
/* check against `:' because there could be a modifier separator */
#else
else
/* csh seems to allow anything to terminate the word spec here,
leaving it as an abbreviation. */
#endif
last = -1; /* x- abbreviates x-$ omitting word `$' */
}
@@ -1149,7 +1347,7 @@ get_history_word_specifier (spec, from, caller_index)
char *
history_arg_extract (first, last, string)
int first, last;
char *string;
const char *string;
{
register int i, len;
char *result;
@@ -1185,7 +1383,7 @@ history_arg_extract (first, last, string)
{
for (size = 0, i = first; i < last; i++)
size += strlen (list[i]) + 1;
result = xmalloc (size + 1);
result = (char *)xmalloc (size + 1);
result[0] = '\0';
for (i = first, offset = 0; i < last; i++)
@@ -1207,7 +1405,103 @@ history_arg_extract (first, last, string)
return (result);
}
#define slashify_in_quotes "\\`\"$"
static int
history_tokenize_word (string, ind)
const char *string;
int ind;
{
register int i;
int delimiter;
i = ind;
delimiter = 0;
if (member (string[i], "()\n"))
{
i++;
return i;
}
if (member (string[i], "<>;&|$"))
{
int peek = string[i + 1];
if (peek == string[i] && peek != '$')
{
if (peek == '<' && string[i + 2] == '-')
i++;
i += 2;
return i;
}
else
{
if ((peek == '&' && (string[i] == '>' || string[i] == '<')) ||
(peek == '>' && string[i] == '&') ||
(peek == '(' && (string[i] == '>' || string[i] == '<')) || /* ) */
(peek == '(' && string[i] == '$')) /* ) */
{
i += 2;
return i;
}
}
if (string[i] != '$')
{
i++;
return i;
}
}
/* Get word from string + i; */
if (member (string[i], HISTORY_QUOTE_CHARACTERS))
delimiter = string[i++];
for (; string[i]; i++)
{
if (string[i] == '\\' && string[i + 1] == '\n')
{
i++;
continue;
}
if (string[i] == '\\' && delimiter != '\'' &&
(delimiter != '"' || member (string[i], slashify_in_quotes)))
{
i++;
continue;
}
if (delimiter && string[i] == delimiter)
{
delimiter = 0;
continue;
}
if (!delimiter && (member (string[i], history_word_delimiters)))
break;
if (!delimiter && member (string[i], HISTORY_QUOTE_CHARACTERS))
delimiter = string[i];
}
return i;
}
static char *
history_substring (string, start, end)
const char *string;
int start, end;
{
register int len;
register char *result;
len = end - start;
result = (char *)xmalloc (len + 1);
strncpy (result, string + start, len);
result[len] = '\0';
return result;
}
/* Parse STRING into tokens and return an array of strings. If WIND is
not -1 and INDP is not null, we also want the word surrounding index
@@ -1215,19 +1509,21 @@ history_arg_extract (first, last, string)
*INDP. */
static char **
history_tokenize_internal (string, wind, indp)
char *string;
const char *string;
int wind, *indp;
{
char **result;
register int i, start, result_index, size;
int len, delimiter;
/* If we're searching for a string that's not part of a word (e.g., " "),
make sure we set *INDP to a reasonable value. */
if (indp && wind != -1)
*indp = -1;
/* Get a token, and stuff it into RESULT. The tokens are split
exactly where the shell would split them. */
for (i = result_index = size = 0, result = (char **)NULL; string[i]; )
{
delimiter = 0;
/* Skip leading whitespace. */
for (; string[i] && whitespace (string[i]); i++)
;
@@ -1235,88 +1531,30 @@ history_tokenize_internal (string, wind, indp)
return (result);
start = i;
if (member (string[i], "()\n"))
i = history_tokenize_word (string, start);
/* If we have a non-whitespace delimiter character (which would not be
skipped by the loop above), use it and any adjacent delimiters to
make a separate field. Any adjacent white space will be skipped the
next time through the loop. */
if (i == start && history_word_delimiters)
{
i++;
goto got_token;
while (string[i] && member (string[i], history_word_delimiters))
i++;
}
if (member (string[i], "<>;&|$"))
{
int peek = string[i + 1];
if (peek == string[i] && peek != '$')
{
if (peek == '<' && string[i + 2] == '-')
i++;
i += 2;
goto got_token;
}
else
{
if ((peek == '&' && (string[i] == '>' || string[i] == '<')) ||
((peek == '>') && (string[i] == '&')) ||
((peek == '(') && (string[i] == '$')))
{
i += 2;
goto got_token;
}
}
if (string[i] != '$')
{
i++;
goto got_token;
}
}
/* Get word from string + i; */
if (member (string[i], HISTORY_QUOTE_CHARACTERS))
delimiter = string[i++];
for (; string[i]; i++)
{
if (string[i] == '\\' && string[i + 1] == '\n')
{
i++;
continue;
}
if (string[i] == '\\' && delimiter != '\'' &&
(delimiter != '"' || member (string[i], slashify_in_quotes)))
{
i++;
continue;
}
if (delimiter && string[i] == delimiter)
{
delimiter = 0;
continue;
}
if (!delimiter && (member (string[i], HISTORY_WORD_DELIMITERS)))
break;
if (!delimiter && member (string[i], HISTORY_QUOTE_CHARACTERS))
delimiter = string[i];
}
got_token:
/* If we are looking for the word in which the character at a
particular index falls, remember it. */
if (indp && wind != -1 && wind >= start && wind < i)
*indp = result_index;
len = i - start;
if (result_index + 2 >= size)
result = (char **)xrealloc (result, ((size += 10) * sizeof (char *)));
result[result_index] = xmalloc (1 + len);
strncpy (result[result_index], string + start, len);
result[result_index][len] = '\0';
result[++result_index] = (char *)NULL;
result[result_index++] = history_substring (string, start, i);
result[result_index] = (char *)NULL;
}
return (result);
@@ -1326,7 +1564,7 @@ history_tokenize_internal (string, wind, indp)
parsed out of STRING. */
char **
history_tokenize (string)
char *string;
const char *string;
{
return (history_tokenize_internal (string, -1, (int *)NULL));
}
@@ -1343,7 +1581,7 @@ history_find_word (line, ind)
int i, wind;
words = history_tokenize_internal (line, ind, &wind);
if (wind == -1)
if (wind == -1 || words == 0)
return ((char *)NULL);
s = words[wind];
for (i = 0; i < wind; i++)

View File

@@ -1,13 +1,13 @@
/* histfile.c - functions to manipulate the history file. */
/* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
/* Copyright (C) 1989-2003 Free Software Foundation, Inc.
This file contains the GNU History Library (the Library), a set of
routines for managing the text of previously typed lines.
The Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
the Free Software Foundation; either version 2, or (at your option)
any later version.
The Library is distributed in the hope that it will be useful, but
@@ -18,13 +18,18 @@
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
/* 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
@@ -32,10 +37,10 @@
#include <stdio.h>
#include <sys/types.h>
#ifndef _MINIX
#if ! defined (_MINIX) && defined (HAVE_SYS_FILE_H)
# include <sys/file.h>
#endif
#include <sys/stat.h>
#include "posixstat.h"
#include <fcntl.h>
#if defined (HAVE_STDLIB_H)
@@ -48,21 +53,39 @@
# include <unistd.h>
#endif
#if defined (HAVE_STRING_H)
# include <string.h>
#else
# include <strings.h>
#endif /* !HAVE_STRING_H */
#if defined (__EMX__) || defined (__CYGWIN__)
# undef HAVE_MMAP
#endif
#if defined (__EMX__)
#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__ */
/* If we're not compiling for __EMX__, we don't want this at all. Ever. */
#else /* !__EMX__ && !__CYGWIN__ */
# undef O_BINARY
# define O_BINARY 0
#endif /* !__EMX__ */
#endif /* !__EMX__ && !__CYGWIN__ */
#include <errno.h>
#if !defined (errno)
@@ -72,19 +95,25 @@ extern int errno;
#include "history.h"
#include "histlib.h"
/* Functions imported from shell.c */
extern char *get_env_value ();
#include "rlshell.h"
#include "xmalloc.h"
extern char *xmalloc (), *xrealloc ();
/* 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)
/* 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)
char *filename;
const char *filename;
{
char *return_val, *home;
char *return_val;
const char *home;
int home_len;
return_val = filename ? savestring (filename) : (char *)NULL;
@@ -92,7 +121,7 @@ history_filename (filename)
if (return_val)
return (return_val);
home = get_env_value ("HOME");
home = sh_get_env_value ("HOME");
if (home == 0)
{
@@ -102,10 +131,14 @@ history_filename (filename)
else
home_len = strlen (home);
return_val = xmalloc (2 + home_len + 8); /* strlen(".history") == 8 */
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);
}
@@ -115,7 +148,7 @@ history_filename (filename)
successful, or errno if not. */
int
read_history (filename)
char *filename;
const char *filename;
{
return (read_history_range (filename, 0, -1));
}
@@ -127,16 +160,23 @@ read_history (filename)
~/.history. Returns 0 if successful, or errno if not. */
int
read_history_range (filename, from, to)
char *filename;
const char *filename;
int from, to;
{
register int line_start, line_end;
char *input, *buffer;
int file, current_line;
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 = (char *)NULL;
buffer = last_ts = (char *)NULL;
input = history_filename (filename);
file = open (input, O_RDONLY|O_BINARY, 0666);
@@ -148,55 +188,93 @@ read_history_range (filename, from, to)
/* check for overflow on very large files */
if (file_size != finfo.st_size || file_size + 1 < file_size)
{
#if defined (EFBIG)
errno = EFBIG;
#endif
errno = overflow_errno;
goto error_and_exit;
}
buffer = xmalloc (file_size + 1);
if (read (file, buffer, file_size) != file_size)
#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 (errno);
return (chars_read);
}
close (file);
/* Set TO to larger than end of file if negative. */
if (to < 0)
to = file_size;
to = chars_read;
/* Start at beginning of file, work to end. */
line_start = line_end = current_line = 0;
bufend = buffer + chars_read;
current_line = 0;
/* Skip lines until we are at FROM. */
while (line_start < file_size && current_line < from)
{
for (line_end = line_start; line_end < file_size; line_end++)
if (buffer[line_end] == '\n')
{
current_line++;
line_start = line_end + 1;
if (current_line == from)
break;
}
}
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 < file_size; line_end++)
if (buffer[line_end] == '\n')
for (line_end = line_start; line_end < bufend; line_end++)
if (*line_end == '\n')
{
buffer[line_end] = '\0';
*line_end = '\0';
if (buffer[line_start])
add_history (buffer + line_start);
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++;
@@ -207,30 +285,52 @@ read_history_range (filename, from, to)
}
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. */
If FNAME is NULL, then use ~/.history. Returns 0 on success, errno
on failure. */
int
history_truncate_file (fname, lines)
char *fname;
register int lines;
const char *fname;
int lines;
{
register int i;
int file, chars_read;
char *buffer, *filename;
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 = open (filename, O_RDONLY|O_BINARY, 0666);
rv = 0;
/* Don't try to truncate non-regular files. */
if (file == -1 || fstat (file, &finfo) == -1)
goto truncate_exit;
{
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;
@@ -239,24 +339,40 @@ history_truncate_file (fname, lines)
{
close (file);
#if defined (EFBIG)
errno = EFBIG;
rv = errno = EFBIG;
#elif defined (EOVERFLOW)
rv = errno = EOVERFLOW;
#else
rv = errno = EINVAL;
#endif
goto truncate_exit;
}
buffer = xmalloc (file_size + 1);
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)
goto truncate_exit;
{
rv = (chars_read < 0) ? errno : 0;
goto truncate_exit;
}
/* Count backwards from the end of buffer until we have passed
LINES lines. */
for (i = chars_read - 1; lines && i; i--)
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 (buffer[i] == '\n')
if (*bp == '\n' && HIST_TIMESTAMP_START(bp1) == 0)
lines--;
bp1 = bp;
}
/* If this is the first line, then the file contains exactly the
@@ -264,18 +380,27 @@ history_truncate_file (fname, lines)
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 ( ; i; i--)
if (buffer[i] == '\n')
{
i++;
break;
}
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 (i && ((file = open (filename, O_WRONLY|O_TRUNC|O_BINARY, 0600)) != -1))
if (bp > buffer && ((file = open (filename, O_WRONLY|O_TRUNC|O_BINARY, 0600)) != -1))
{
write (file, buffer + i, file_size - i);
write (file, bp, chars_read - (bp - buffer));
#if defined (__BEOS__)
/* BeOS ignores O_TRUNC. */
ftruncate (file, chars_read - (bp - buffer));
#endif
close (file);
}
@@ -284,7 +409,7 @@ history_truncate_file (fname, lines)
FREE (buffer);
free (filename);
return 0;
return rv;
}
/* Workhorse function for writing history. Writes NELEMENT entries
@@ -292,15 +417,21 @@ history_truncate_file (fname, lines)
wish to replace FILENAME with the entries. */
static int
history_do_write (filename, nelements, overwrite)
char *filename;
const char *filename;
int nelements, overwrite;
{
register int i;
char *output;
int file, mode;
int file, mode, rv;
#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);
rv = 0;
if ((file = open (output, mode, 0600)) == -1)
{
@@ -308,6 +439,10 @@ history_do_write (filename, nelements, overwrite)
return (errno);
}
#ifdef HISTORY_USE_MMAP
cursize = overwrite ? 0 : lseek (file, 0, SEEK_END);
#endif
if (nelements > history_length)
nelements = history_length;
@@ -322,27 +457,68 @@ history_do_write (filename, nelements, overwrite)
the_history = history_list ();
/* Calculate the total number of bytes to write. */
for (buffer_size = 0, i = history_length - nelements; i < history_length; i++)
buffer_size += 1 + strlen (the_history[i]->line);
#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. */
buffer = xmalloc (buffer_size);
#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;
FREE (output);
close (file);
return rv;
}
#else
buffer = (char *)malloc (buffer_size);
if (buffer == 0)
{
rv = errno;
FREE (output);
close (file);
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';
}
write (file, buffer, buffer_size);
#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;
free (buffer);
#endif
}
close (file);
FREE (output);
return (0);
return (rv);
}
/* Append NELEMENT entries to FILENAME. The entries appended are from
@@ -350,7 +526,7 @@ history_do_write (filename, nelements, overwrite)
int
append_history (nelements, filename)
int nelements;
char *filename;
const char *filename;
{
return (history_do_write (filename, nelements, HISTORY_APPEND));
}
@@ -360,7 +536,7 @@ append_history (nelements, filename)
are as in read_history ().*/
int
write_history (filename)
char *filename;
const char *filename;
{
return (history_do_write (filename, history_length, HISTORY_OVERWRITE));
}

View File

@@ -6,7 +6,7 @@
The Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
the Free Software Foundation; either version 2, or (at your option)
any later version.
The Library is distributed in the hope that it will be useful, but
@@ -17,27 +17,24 @@
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#if !defined (_HISTLIB_H_)
#define _HISTLIB_H_
/* Function pointers can be declared as (Function *)foo. */
#if !defined (_FUNCTION_DEF)
# define _FUNCTION_DEF
typedef int Function ();
typedef void VFunction ();
typedef char *CPFunction ();
typedef char **CPPFunction ();
#endif /* _FUNCTION_DEF */
#if defined (HAVE_STRING_H)
# include <string.h>
#else
# include <strings.h>
#endif /* !HAVE_STRING_H */
#if !defined (STREQ)
#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))
#define STREQN(a, b, n) (((n) == 0) ? (1) \
: ((a)[0] == (b)[0]) && (strncmp ((a), (b), (n)) == 0))
#endif
#ifndef savestring
# ifndef strcpy
extern char *strcpy ();
# endif
#define savestring(x) strcpy (xmalloc (1 + strlen (x)), (x))
#endif
@@ -69,6 +66,7 @@ extern char *strchr ();
#define BAD_WORD_SPEC 1
#define SUBST_FAILED 2
#define BAD_MODIFIER 3
#define NO_PREV_SUBST 4
/* Possible definitions for history starting point specification. */
#define ANCHORED_SEARCH 1
@@ -78,4 +76,7 @@ extern char *strchr ();
#define HISTORY_APPEND 0
#define HISTORY_OVERWRITE 1
/* Some variable definitions shared across history source files. */
extern int history_offset;
#endif /* !_HISTLIB_H_ */

View File

@@ -1,13 +1,13 @@
/* History.c -- standalone history library */
/* history.c -- standalone history library */
/* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
/* Copyright (C) 1989-2005 Free Software Foundation, Inc.
This file contains the GNU History Library (the Library), a set of
routines for managing the text of previously typed lines.
The Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
the Free Software Foundation; either version 2, or (at your option)
any later version.
The Library is distributed in the hope that it will be useful, but
@@ -18,7 +18,7 @@
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
/* The goal is to make the implementation transparent, so that you
don't have to know what data types are used, just what functions
@@ -44,20 +44,16 @@
# include <unistd.h>
#endif
#if defined (HAVE_STRING_H)
# include <string.h>
#else
# include <strings.h>
#endif /* !HAVE_STRING_H */
#include "history.h"
#include "histlib.h"
extern char *xmalloc (), *xrealloc ();
#include "xmalloc.h"
/* The number of slots to increase the_history by. */
#define DEFAULT_HISTORY_GROW_SIZE 50
static char *hist_inittime PARAMS((void));
/* **************************************************************** */
/* */
/* History Functions */
@@ -71,9 +67,13 @@ static HIST_ENTRY **the_history = (HIST_ENTRY **)NULL;
history that we save. */
static int history_stifled;
/* The current number of slots allocated to the input_history. */
static int history_size;
/* If HISTORY_STIFLED is non-zero, then this is the maximum number of
entries to remember. */
int max_input_history;
int history_max_entries;
int max_input_history; /* backwards compatibility */
/* The current location of the interactive history pointer. Just makes
life easier for outside callers. */
@@ -82,9 +82,6 @@ int history_offset;
/* The number of strings currently stored in the history list. */
int history_length;
/* The current number of slots allocated to the input_history. */
static int history_size;
/* The logical `base' of the history array. It defaults to 1. */
int history_base = 1;
@@ -128,16 +125,15 @@ using_history ()
}
/* Return the number of bytes that the primary history entries are using.
This just adds up the lengths of the_history->lines. */
This just adds up the lengths of the_history->lines and the associated
timestamps. */
int
history_total_bytes ()
{
register int i, result;
result = 0;
for (i = 0; the_history && the_history[i]; i++)
result += strlen (the_history[i]->line);
for (i = result = 0; the_history && the_history[i]; i++)
result += HISTENT_BYTES (the_history[i]);
return (result);
}
@@ -208,34 +204,65 @@ history_get (offset)
int local_index;
local_index = offset - history_base;
return (local_index >= history_length || local_index < 0 || !the_history)
return (local_index >= history_length || local_index < 0 || the_history == 0)
? (HIST_ENTRY *)NULL
: the_history[local_index];
}
time_t
history_get_time (hist)
HIST_ENTRY *hist;
{
char *ts;
time_t t;
if (hist == 0 || hist->timestamp == 0)
return 0;
ts = hist->timestamp;
if (ts[0] != history_comment_char)
return 0;
t = (time_t) atol (ts + 1); /* XXX - should use strtol() here */
return t;
}
static char *
hist_inittime ()
{
time_t t;
char ts[64], *ret;
t = (time_t) time ((time_t *)0);
#if defined (HAVE_VSNPRINTF) /* assume snprintf if vsnprintf exists */
snprintf (ts, sizeof (ts) - 1, "X%lu", (unsigned long) t);
#else
sprintf (ts, "X%lu", (unsigned long) t);
#endif
ret = savestring (ts);
ret[0] = history_comment_char;
return ret;
}
/* Place STRING at the end of the history list. The data field
is set to NULL. */
void
add_history (string)
char *string;
const char *string;
{
HIST_ENTRY *temp;
if (history_stifled && (history_length == max_input_history))
if (history_stifled && (history_length == history_max_entries))
{
register int i;
/* If the history is stifled, and history_length is zero,
and it equals max_input_history, we don't save items. */
and it equals history_max_entries, we don't save items. */
if (history_length == 0)
return;
/* If there is something in the slot, then remove it. */
if (the_history[0])
{
free (the_history[0]->line);
free (the_history[0]);
}
(void) free_history_entry (the_history[0]);
/* Copy the rest of the entries, moving down one slot. */
for (i = 0; i < history_length; i++)
@@ -267,29 +294,61 @@ add_history (string)
temp->line = savestring (string);
temp->data = (char *)NULL;
temp->timestamp = hist_inittime ();
the_history[history_length] = (HIST_ENTRY *)NULL;
the_history[history_length - 1] = temp;
}
/* Change the time stamp of the most recent history entry to STRING. */
void
add_history_time (string)
const char *string;
{
HIST_ENTRY *hs;
hs = the_history[history_length - 1];
FREE (hs->timestamp);
hs->timestamp = savestring (string);
}
/* Free HIST and return the data so the calling application can free it
if necessary and desired. */
histdata_t
free_history_entry (hist)
HIST_ENTRY *hist;
{
histdata_t x;
if (hist == 0)
return ((histdata_t) 0);
FREE (hist->line);
FREE (hist->timestamp);
x = hist->data;
free (hist);
return (x);
}
/* Make the history entry at WHICH have LINE and DATA. This returns
the old entry so you can dispose of the data. In the case of an
invalid WHICH, a NULL pointer is returned. */
HIST_ENTRY *
replace_history_entry (which, line, data)
int which;
char *line;
char *data;
const char *line;
histdata_t data;
{
HIST_ENTRY *temp = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY));
HIST_ENTRY *old_value;
HIST_ENTRY *temp, *old_value;
if (which >= history_length)
if (which < 0 || which >= history_length)
return ((HIST_ENTRY *)NULL);
temp = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY));
old_value = the_history[which];
temp->line = savestring (line);
temp->data = data;
temp->timestamp = savestring (old_value->timestamp);
the_history[which] = temp;
return (old_value);
@@ -303,19 +362,17 @@ remove_history (which)
int which;
{
HIST_ENTRY *return_value;
register int i;
if (which >= history_length || !history_length)
return_value = (HIST_ENTRY *)NULL;
else
{
register int i;
return_value = the_history[which];
if (which < 0 || which >= history_length || history_length == 0 || the_history == 0)
return ((HIST_ENTRY *)NULL);
for (i = which; i < history_length; i++)
the_history[i] = the_history[i + 1];
return_value = the_history[which];
history_length--;
}
for (i = which; i < history_length; i++)
the_history[i] = the_history[i + 1];
history_length--;
return (return_value);
}
@@ -325,19 +382,16 @@ void
stifle_history (max)
int max;
{
register int i, j;
if (max < 0)
max = 0;
if (history_length > max)
{
register int i, j;
/* This loses because we cannot free the data. */
for (i = 0, j = history_length - max; i < j; i++)
{
free (the_history[i]->line);
free (the_history[i]);
}
free_history_entry (the_history[i]);
history_base = i;
for (j = 0, i = history_length - max; j < max; i++, j++)
@@ -347,22 +401,22 @@ stifle_history (max)
}
history_stifled = 1;
max_input_history = max;
max_input_history = history_max_entries = max;
}
/* Stop stifling the history. This returns the previous amount the
history was stifled by. The value is positive if the history was
stifled, negative if it wasn't. */
/* Stop stifling the history. This returns the previous maximum
number of history entries. The value is positive if the history
was stifled, negative if it wasn't. */
int
unstifle_history ()
{
if (history_stifled)
{
history_stifled = 0;
return (-max_input_history);
return (history_max_entries);
}
return (max_input_history);
else
return (-history_max_entries);
}
int
@@ -379,8 +433,7 @@ clear_history ()
/* This loses because we cannot free the data. */
for (i = 0; i < history_length; i++)
{
free (the_history[i]->line);
free (the_history[i]);
free_history_entry (the_history[i]);
the_history[i] = (HIST_ENTRY *)NULL;
}

View File

@@ -1,12 +1,12 @@
/* History.h -- the names of functions that you can call in history. */
/* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
/* history.h -- the names of functions that you can call in history. */
/* Copyright (C) 1989-2003 Free Software Foundation, Inc.
This file contains the GNU History Library (the Library), a set of
routines for managing the text of previously typed lines.
The Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
the Free Software Foundation; either version 2, or (at your option)
any later version.
The Library is distributed in the hope that it will be useful, but
@@ -17,25 +17,41 @@
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#ifndef _HISTORY_H_
#define _HISTORY_H_
#if !defined (_FUNCTION_DEF)
# define _FUNCTION_DEF
typedef int Function ();
typedef void VFunction ();
typedef char *CPFunction ();
typedef char **CPPFunction ();
#ifdef __cplusplus
extern "C" {
#endif
#include <time.h> /* XXX - for history timestamp code */
#if defined READLINE_LIBRARY
# include "rlstdc.h"
# include "rltypedefs.h"
#else
# include <readline/rlstdc.h>
# include <readline/rltypedefs.h>
#endif
#ifdef __STDC__
typedef void *histdata_t;
#else
typedef char *histdata_t;
#endif
/* The structure used to store a history entry. */
typedef struct _hist_entry {
char *line;
char *data;
char *timestamp; /* char * rather than time_t for read/write */
histdata_t data;
} HIST_ENTRY;
/* Size of the history-library-managed space in history entry HS. */
#define HISTENT_BYTES(hs) (strlen ((hs)->line) + strlen ((hs)->timestamp))
/* A structure used to pass the current state of the history stuff around. */
typedef struct _hist_state {
HIST_ENTRY **entries; /* Pointer to the entries themselves. */
@@ -52,81 +68,93 @@ typedef struct _hist_state {
/* Begin a session in which the history functions might be used. This
just initializes the interactive variables. */
extern void using_history ();
extern void using_history PARAMS((void));
/* Return the current HISTORY_STATE of the history. */
extern HISTORY_STATE *history_get_history_state ();
extern HISTORY_STATE *history_get_history_state PARAMS((void));
/* Set the state of the current history array to STATE. */
extern void history_set_history_state ();
extern void history_set_history_state PARAMS((HISTORY_STATE *));
/* Manage the history list. */
/* Place STRING at the end of the history list.
The associated data field (if any) is set to NULL. */
extern void add_history ();
extern void add_history PARAMS((const char *));
/* Change the timestamp associated with the most recent history entry to
STRING. */
extern void add_history_time PARAMS((const char *));
/* A reasonably useless function, only here for completeness. WHICH
is the magic number that tells us which element to delete. The
elements are numbered from 0. */
extern HIST_ENTRY *remove_history ();
extern HIST_ENTRY *remove_history PARAMS((int));
/* Free the history entry H and return any application-specific data
associated with it. */
extern histdata_t free_history_entry PARAMS((HIST_ENTRY *));
/* Make the history entry at WHICH have LINE and DATA. This returns
the old entry so you can dispose of the data. In the case of an
invalid WHICH, a NULL pointer is returned. */
extern HIST_ENTRY *replace_history_entry ();
extern HIST_ENTRY *replace_history_entry PARAMS((int, const char *, histdata_t));
/* Clear the history list and start over. */
extern void clear_history ();
extern void clear_history PARAMS((void));
/* Stifle the history list, remembering only MAX number of entries. */
extern void stifle_history ();
extern void stifle_history PARAMS((int));
/* Stop stifling the history. This returns the previous amount the
history was stifled by. The value is positive if the history was
stifled, negative if it wasn't. */
extern int unstifle_history ();
extern int unstifle_history PARAMS((void));
/* Return 1 if the history is stifled, 0 if it is not. */
extern int history_is_stifled ();
extern int history_is_stifled PARAMS((void));
/* Information about the history list. */
/* Return a NULL terminated array of HIST_ENTRY which is the current input
history. Element 0 of this list is the beginning of time. If there
is no history, return NULL. */
extern HIST_ENTRY **history_list ();
extern HIST_ENTRY **history_list PARAMS((void));
/* Returns the number which says what history element we are now
looking at. */
extern int where_history ();
extern int where_history PARAMS((void));
/* Return the history entry at the current position, as determined by
history_offset. If there is no entry there, return a NULL pointer. */
HIST_ENTRY *current_history ();
extern HIST_ENTRY *current_history PARAMS((void));
/* Return the history entry which is logically at OFFSET in the history
array. OFFSET is relative to history_base. */
extern HIST_ENTRY *history_get ();
extern HIST_ENTRY *history_get PARAMS((int));
/* Return the timestamp associated with the HIST_ENTRY * passed as an
argument */
extern time_t history_get_time PARAMS((HIST_ENTRY *));
/* Return the number of bytes that the primary history entries are using.
This just adds up the lengths of the_history->lines. */
extern int history_total_bytes ();
extern int history_total_bytes PARAMS((void));
/* Moving around the history list. */
/* Set the position in the history list to POS. */
int history_set_pos ();
extern int history_set_pos PARAMS((int));
/* Back up history_offset to the previous history entry, and return
a pointer to that entry. If there is no previous entry, return
a NULL pointer. */
extern HIST_ENTRY *previous_history ();
extern HIST_ENTRY *previous_history PARAMS((void));
/* Move history_offset forward to the next item in the input_history,
and return the a pointer to that entry. If there is no next entry,
return a NULL pointer. */
extern HIST_ENTRY *next_history ();
extern HIST_ENTRY *next_history PARAMS((void));
/* Searching the history list. */
@@ -136,44 +164,45 @@ extern HIST_ENTRY *next_history ();
current_history () is the history entry, and the value of this function
is the offset in the line of that history entry that the string was
found in. Otherwise, nothing is changed, and a -1 is returned. */
extern int history_search ();
extern int history_search PARAMS((const char *, int));
/* Search the history for STRING, starting at history_offset.
The search is anchored: matching lines must begin with string. */
extern int history_search_prefix ();
The search is anchored: matching lines must begin with string.
DIRECTION is as in history_search(). */
extern int history_search_prefix PARAMS((const char *, int));
/* Search for STRING in the history list, starting at POS, an
absolute index into the list. DIR, if negative, says to search
backwards from POS, else forwards.
Returns the absolute index of the history element where STRING
was found, or -1 otherwise. */
extern int history_search_pos ();
extern int history_search_pos PARAMS((const char *, int, int));
/* Managing the history file. */
/* Add the contents of FILENAME to the history list, a line at a time.
If FILENAME is NULL, then read from ~/.history. Returns 0 if
successful, or errno if not. */
extern int read_history ();
extern int read_history PARAMS((const char *));
/* Read a range of lines from FILENAME, adding them to the history list.
Start reading at the FROM'th line and end at the TO'th. If FROM
is zero, start at the beginning. If TO is less than FROM, read
until the end of the file. If FILENAME is NULL, then read from
~/.history. Returns 0 if successful, or errno if not. */
extern int read_history_range ();
extern int read_history_range PARAMS((const char *, int, int));
/* Write the current history to FILENAME. If FILENAME is NULL,
then write the history list to ~/.history. Values returned
are as in read_history (). */
extern int write_history ();
extern int write_history PARAMS((const char *));
/* Append NELEMENT entries to FILENAME. The entries appended are from
the end of the list minus NELEMENTs up to the end of the list. */
int append_history ();
extern int append_history PARAMS((int, const char *));
/* Truncate the history file, leaving only the last NLINES lines. */
extern int history_truncate_file ();
extern int history_truncate_file PARAMS((const char *, int));
/* History expansion. */
@@ -189,35 +218,49 @@ extern int history_truncate_file ();
If an error ocurred in expansion, then OUTPUT contains a descriptive
error message. */
extern int history_expand ();
extern int history_expand PARAMS((char *, char **));
/* Extract a string segment consisting of the FIRST through LAST
arguments present in STRING. Arguments are broken up as in
the shell. */
extern char *history_arg_extract ();
extern char *history_arg_extract PARAMS((int, int, const char *));
/* Return the text of the history event beginning at the current
offset into STRING. */
extern char *get_history_event ();
offset into STRING. Pass STRING with *INDEX equal to the
history_expansion_char that begins this specification.
DELIMITING_QUOTE is a character that is allowed to end the string
specification for what to search for in addition to the normal
characters `:', ` ', `\t', `\n', and sometimes `?'. */
extern char *get_history_event PARAMS((const char *, int *, int));
/* Return an array of tokens, much as the shell might. The tokens are
parsed out of STRING. */
extern char **history_tokenize ();
extern char **history_tokenize PARAMS((const char *));
/* Exported history variables. */
extern int history_base;
extern int history_length;
extern int max_input_history;
extern int history_max_entries;
extern char history_expansion_char;
extern char history_subst_char;
extern char *history_word_delimiters;
extern char history_comment_char;
extern char *history_no_expand_chars;
extern char *history_search_delimiter_chars;
extern int history_quotes_inhibit_expansion;
extern int history_write_timestamps;
/* Backwards compatibility */
extern int max_input_history;
/* If set, this function is called to decide whether or not a particular
history expansion should be treated as a special case for the calling
application and not expanded. */
extern Function *history_inhibit_expansion_function;
extern rl_linebuf_func_t *history_inhibit_expansion_function;
#ifdef __cplusplus
}
#endif
#endif /* !_HISTORY_H_ */

View File

@@ -7,7 +7,7 @@
The Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
the Free Software Foundation; either version 2, or (at your option)
any later version.
The Library is distributed in the hope that it will be useful, but
@@ -18,7 +18,7 @@
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#define READLINE_LIBRARY
@@ -32,28 +32,23 @@
#else
# include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */
#if defined (HAVE_UNISTD_H)
# ifdef _MINIX
# include <sys/types.h>
# endif
# include <unistd.h>
#endif
#if defined (HAVE_STRING_H)
# include <string.h>
#else
# include <strings.h>
#endif /* !HAVE_STRING_H */
#include "history.h"
#include "histlib.h"
/* Variables imported from other history library files. */
extern int history_offset;
/* The list of alternate characters that can delimit a history search
string. */
char *history_search_delimiter_chars = (char *)NULL;
static int history_search_internal PARAMS((const char *, int, int));
/* Search the history for STRING, starting at history_offset.
If DIRECTION < 0, then the search is through previous entries, else
through subsequent. If ANCHORED is non-zero, the string must
@@ -66,7 +61,7 @@ char *history_search_delimiter_chars = (char *)NULL;
static int
history_search_internal (string, direction, anchored)
char *string;
const char *string;
int direction, anchored;
{
register int i, reverse;
@@ -82,11 +77,11 @@ history_search_internal (string, direction, anchored)
if (string == 0 || *string == '\0')
return (-1);
if (!history_length || ((i == history_length) && !reverse))
if (!history_length || ((i >= history_length) && !reverse))
return (-1);
if (reverse && (i == history_length))
i--;
if (reverse && (i >= history_length))
i = history_length - 1;
#define NEXT_LINE() do { if (reverse) i--; else i++; } while (0)
@@ -162,7 +157,7 @@ history_search_internal (string, direction, anchored)
/* Do a non-anchored search for STRING through the history in DIRECTION. */
int
history_search (string, direction)
char *string;
const char *string;
int direction;
{
return (history_search_internal (string, direction, NON_ANCHORED_SEARCH));
@@ -171,7 +166,7 @@ history_search (string, direction)
/* Do an anchored search for string through the history in DIRECTION. */
int
history_search_prefix (string, direction)
char *string;
const char *string;
int direction;
{
return (history_search_internal (string, direction, ANCHORED_SEARCH));
@@ -182,7 +177,7 @@ history_search_prefix (string, direction)
which point to begin searching. */
int
history_search_pos (string, dir, pos)
char *string;
const char *string;
int dir, pos;
{
int ret, old;

View File

@@ -1,6 +1,6 @@
/* input.c -- character input functions for readline. */
/* Copyright (C) 1994 Free Software Foundation, Inc.
/* Copyright (C) 1994-2005 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
@@ -18,9 +18,13 @@
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#define READLINE_LIBRARY
#if defined (__TANDEM)
# include <floss.h>
#endif
#if defined (HAVE_CONFIG_H)
# include <config.h>
#endif
@@ -63,48 +67,31 @@ extern int 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
/* Functions imported from other files in the library. */
extern char *xmalloc (), *xrealloc ();
/* Variables and functions from macro.c. */
extern void _rl_add_macro_char ();
extern void _rl_with_macro_input ();
extern int _rl_next_macro_key ();
extern int _rl_defining_kbd_macro;
#if defined (VI_MODE)
extern void _rl_vi_set_last ();
extern int _rl_vi_textmod_command ();
#endif /* VI_MODE */
extern FILE *rl_instream, *rl_outstream;
extern Function *rl_last_func;
extern int rl_key_sequence_length;
extern int rl_pending_input;
extern int rl_editing_mode;
extern Keymap _rl_keymap;
extern int _rl_convert_meta_chars_to_ascii;
#if defined (__GO32__)
# include <pc.h>
#endif /* __GO32__ */
/* Non-null means it is a pointer to a function to run while waiting for
character input. */
Function *rl_event_hook = (Function *)NULL;
rl_hook_func_t *rl_event_hook = (rl_hook_func_t *)NULL;
Function *rl_getc_function = rl_getc;
rl_getc_func_t *rl_getc_function = rl_getc;
static int _keyboard_input_timeout = 100000; /* 0.1 seconds; it's in usec */
static int ibuffer_space PARAMS((void));
static int rl_get_char PARAMS((int *));
static int rl_gather_tyi PARAMS((void));
/* **************************************************************** */
/* */
@@ -124,38 +111,13 @@ _rl_any_typein ()
return any_typein;
}
/* Add KEY to the buffer of characters to be read. */
int
rl_stuff_char (key)
int key;
{
if (key == EOF)
{
key = NEWLINE;
rl_pending_input = EOF;
}
ibuffer[push_index++] = key;
if (push_index >= ibuffer_len)
push_index = 0;
return push_index;
}
/* Make C be the next command to be executed. */
int
rl_execute_next (c)
int c;
{
rl_pending_input = c;
return 0;
}
/* Return the amount of space available in the
buffer for stuffing characters. */
/* 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);
return (pop_index - push_index - 1);
else
return (ibuffer_len - (push_index - pop_index));
}
@@ -181,8 +143,8 @@ rl_get_char (key)
/* Stuff KEY into the *front* of the input buffer.
Returns non-zero if successful, zero if there is
no space left in the buffer. */
static int
rl_unget_char (key)
int
_rl_unget_char (key)
int key;
{
if (ibuffer_space ())
@@ -196,25 +158,21 @@ rl_unget_char (key)
return (0);
}
/* If a character is available to be read, then read it
and stuff it into IBUFFER. Otherwise, just return. */
static void
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 ()
{
#if defined (__GO32__)
char input;
if (isatty (0) && kbhit () && ibuffer_space ())
{
int i;
i = (*rl_getc_function) (rl_instream);
rl_stuff_char (i);
}
#else /* !__GO32__ */
int tty;
register int tem, result;
int chars_avail;
int chars_avail, k;
char input;
#if defined(HAVE_SELECT)
fd_set readfds, exceptfds;
@@ -229,14 +187,18 @@ rl_gather_tyi ()
FD_SET (tty, &readfds);
FD_SET (tty, &exceptfds);
timeout.tv_sec = 0;
timeout.tv_usec = 100000; /* 0.1 seconds */
if (select (tty + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout) <= 0)
return; /* Nothing to read. */
timeout.tv_usec = _keyboard_input_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)
@@ -249,14 +211,19 @@ rl_gather_tyi ()
fcntl (tty, F_SETFL, tem);
if (chars_avail == -1 && errno == EAGAIN)
return;
return 0;
if (chars_avail == 0) /* EOF */
{
rl_stuff_char (EOF);
return (0);
}
}
#endif /* O_NDELAY */
/* If there's nothing available, don't waste time trying to read
something. */
if (chars_avail <= 0)
return;
return 0;
tem = ibuffer_space ();
@@ -273,18 +240,40 @@ rl_gather_tyi ()
if (result != -1)
{
while (chars_avail--)
rl_stuff_char ((*rl_getc_function) (rl_instream));
{
k = (*rl_getc_function) (rl_instream);
rl_stuff_char (k);
if (k == NEWLINE || k == RETURN)
break;
}
}
else
{
if (chars_avail)
rl_stuff_char (input);
}
#endif /* !__GO32__ */
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. */
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 ()
{
@@ -292,7 +281,7 @@ _rl_input_available ()
fd_set readfds, exceptfds;
struct timeval timeout;
#endif
#if defined(FIONREAD)
#if !defined (HAVE_SELECT) && defined(FIONREAD)
int chars_avail;
#endif
int tty;
@@ -305,18 +294,32 @@ _rl_input_available ()
FD_SET (tty, &readfds);
FD_SET (tty, &exceptfds);
timeout.tv_sec = 0;
timeout.tv_usec = 100000; /* 0.1 seconds */
timeout.tv_usec = _keyboard_input_timeout;
return (select (tty + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout) > 0);
#endif
#else
#if defined (FIONREAD)
if (ioctl (tty, FIONREAD, &chars_avail) == 0)
return (chars_avail);
#endif
#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;
@@ -325,7 +328,7 @@ _rl_insert_typein (c)
char *string;
i = key = 0;
string = xmalloc (ibuffer_len + 1);
string = (char *)xmalloc (ibuffer_len + 1);
string[i++] = (char) c;
while ((t = rl_get_char (&key)) &&
@@ -334,13 +337,54 @@ _rl_insert_typein (c)
string[i++] = key;
if (t)
rl_unget_char (key);
_rl_unget_char (key);
string[i] = '\0';
rl_insert_text (string);
free (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 (push_index >= ibuffer_len)
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 */
@@ -358,7 +402,7 @@ rl_read_key ()
if (rl_pending_input)
{
c = rl_pending_input;
rl_pending_input = 0;
rl_clear_pending_input ();
}
else
{
@@ -372,7 +416,13 @@ rl_read_key ()
while (rl_event_hook && rl_get_char (&c) == 0)
{
(*rl_event_hook) ();
rl_gather_tyi ();
if (rl_done) /* XXX - experimental */
return ('\n');
if (rl_gather_tyi () < 0) /* XXX - EIO */
{
rl_done = 1;
return ('\n');
}
}
}
else
@@ -389,16 +439,15 @@ int
rl_getc (stream)
FILE *stream;
{
int result, flags;
int result;
unsigned char c;
#if defined (__GO32__)
if (isatty (0))
return (getkey () & 0x7F);
#endif /* __GO32__ */
while (1)
{
#if defined (__MINGW32__)
if (isatty (fileno (stream)))
return (getch ());
#endif
result = read (fileno (stream), &c, sizeof (unsigned char));
if (result == sizeof (unsigned char))
@@ -409,41 +458,113 @@ rl_getc (stream)
if (result == 0)
return (EOF);
#if defined (__BEOS__)
if (errno == EINTR)
continue;
#endif
#if defined (EWOULDBLOCK)
if (errno == 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 ((flags = fcntl (fileno (stream), F_GETFL, 0)) < 0)
if (sh_unset_nodelay_mode (fileno (stream)) < 0)
return (EOF);
if (flags & O_NDELAY)
{
flags &= ~O_NDELAY;
fcntl (fileno (stream), F_SETFL, flags);
continue;
}
continue;
}
#endif /* EWOULDBLOCK */
#if defined (_POSIX_VERSION) && defined (EAGAIN) && defined (O_NONBLOCK)
if (errno == EAGAIN)
{
if ((flags = fcntl (fileno (stream), F_GETFL, 0)) < 0)
return (EOF);
if (flags & O_NONBLOCK)
{
flags &= ~O_NONBLOCK;
fcntl (fileno (stream), F_SETFL, flags);
continue;
}
}
#endif /* _POSIX_VERSION && EAGAIN && O_NONBLOCK */
#undef X_EWOULDBLOCK
#undef X_EAGAIN
#if !defined (__GO32__)
/* If the error that we received was SIGINT, then try again,
this is simply an interrupted system call to read ().
Otherwise, some error ocurred, also signifying EOF. */
if (errno != EINTR)
return (EOF);
#endif /* !__GO32__ */
}
}
#if defined (HANDLE_MULTIBYTE)
/* read multibyte char */
int
_rl_read_mbchar (mbchar, size)
char *mbchar;
int size;
{
int mb_len = 0;
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));
while (mb_len < size)
{
RL_SETSTATE(RL_STATE_MOREINPUT);
mbchar[mb_len++] = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
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 MBLEN. 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, mblen)
int first;
char *mb;
int mblen;
{
int i, c;
mbstate_t ps;
c = first;
memset (mb, 0, mblen);
for (i = 0; i < mblen; 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 */

View File

@@ -4,7 +4,7 @@
/* */
/* **************************************************************** */
/* Copyright (C) 1987,1989 Free Software Foundation, Inc.
/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file contains the Readline Library (the Library), a set of
routines for providing Emacs style line input to programs that ask
@@ -12,7 +12,7 @@
The Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
the Free Software Foundation; either version 2, or (at your option)
any later version.
The Library is distributed in the hope that it will be useful, but
@@ -23,7 +23,7 @@
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#define READLINE_LIBRARY
#if defined (HAVE_CONFIG_H)
@@ -45,32 +45,89 @@
#endif
#include "rldefs.h"
#include "rlmbutil.h"
#include "readline.h"
#include "history.h"
#include "rlprivate.h"
#include "xmalloc.h"
/* Variables exported to other files in the readline library. */
char *_rl_isearch_terminators = (char *)NULL;
_rl_search_cxt *_rl_iscxt = 0;
/* Variables imported from other files in the readline library. */
extern Keymap _rl_keymap;
extern HIST_ENTRY *saved_line_for_history;
extern int rl_line_buffer_len;
extern int rl_point, rl_end;
extern char *rl_line_buffer;
extern HIST_ENTRY *_rl_saved_line_for_history;
extern void _rl_save_prompt ();
extern void _rl_restore_prompt ();
static int rl_search_history PARAMS((int, int));
extern int rl_execute_next ();
extern void rl_extend_line_buffer ();
extern int _rl_input_available ();
extern char *xmalloc (), *xrealloc ();
static int rl_search_history ();
static _rl_search_cxt *_rl_isearch_init PARAMS((int));
static void _rl_isearch_fini PARAMS((_rl_search_cxt *));
static int _rl_isearch_cleanup PARAMS((_rl_search_cxt *, int));
/* Last line found by the current incremental search, so we don't `find'
identical lines many times in a row. */
static char *prev_line_found;
/* Last search string and its length. */
static char *last_isearch_string;
static int last_isearch_string_len;
static char *default_isearch_terminators = "\033\012";
_rl_search_cxt *
_rl_scxt_alloc (type, flags)
int type, flags;
{
_rl_search_cxt *cxt;
cxt = (_rl_search_cxt *)xmalloc (sizeof (_rl_search_cxt));
cxt->type = type;
cxt->sflags = flags;
cxt->search_string = 0;
cxt->search_string_size = cxt->search_string_index = 0;
cxt->lines = 0;
cxt->allocated_line = 0;
cxt->hlen = cxt->hindex = 0;
cxt->save_point = rl_point;
cxt->save_mark = rl_mark;
cxt->save_line = where_history ();
cxt->last_found_line = cxt->save_line;
cxt->prev_line_found = 0;
cxt->save_undo_list = 0;
cxt->history_pos = 0;
cxt->direction = 0;
cxt->lastc = 0;
cxt->sline = 0;
cxt->sline_len = cxt->sline_index = 0;
cxt->search_terminators = 0;
return cxt;
}
void
_rl_scxt_dispose (cxt, flags)
_rl_search_cxt *cxt;
int flags;
{
FREE (cxt->search_string);
FREE (cxt->allocated_line);
FREE (cxt->lines);
free (cxt);
}
/* Search backwards through the history looking for a string which is typed
interactively. Start with the current line. */
int
@@ -91,7 +148,7 @@ rl_forward_search_history (sign, key)
/* Display the current state of the search in the echo-area.
SEARCH_STRING contains the string that is being searched for,
DIRECTION is zero for forward, or 1 for reverse,
DIRECTION is zero for forward, or non-zero for reverse,
WHERE is the history list number of the current line. If it is
-1, then this line is the starting one. */
static void
@@ -104,7 +161,7 @@ rl_display_search (search_string, reverse_p, where)
searchlen = (search_string && *search_string) ? strlen (search_string) : 0;
message = xmalloc (searchlen + 33);
message = (char *)xmalloc (searchlen + 33);
msglen = 0;
#if defined (NOTDEF)
@@ -134,11 +191,423 @@ rl_display_search (search_string, reverse_p, where)
strcpy (message + msglen, "': ");
rl_message ("%s", message, 0);
rl_message ("%s", message);
free (message);
(*rl_redisplay_function) ();
}
static _rl_search_cxt *
_rl_isearch_init (direction)
int direction;
{
_rl_search_cxt *cxt;
register int i;
HIST_ENTRY **hlist;
cxt = _rl_scxt_alloc (RL_SEARCH_ISEARCH, 0);
if (direction < 0)
cxt->sflags |= SF_REVERSE;
cxt->search_terminators = _rl_isearch_terminators ? _rl_isearch_terminators
: default_isearch_terminators;
/* Create an arrary of pointers to the lines that we want to search. */
hlist = history_list ();
rl_maybe_replace_line ();
i = 0;
if (hlist)
for (i = 0; hlist[i]; i++);
/* Allocate space for this many lines, +1 for the current input line,
and remember those lines. */
cxt->lines = (char **)xmalloc ((1 + (cxt->hlen = i)) * sizeof (char *));
for (i = 0; i < cxt->hlen; i++)
cxt->lines[i] = hlist[i]->line;
if (_rl_saved_line_for_history)
cxt->lines[i] = _rl_saved_line_for_history->line;
else
{
/* Keep track of this so we can free it. */
cxt->allocated_line = (char *)xmalloc (1 + strlen (rl_line_buffer));
strcpy (cxt->allocated_line, &rl_line_buffer[0]);
cxt->lines[i] = cxt->allocated_line;
}
cxt->hlen++;
/* The line where we start the search. */
cxt->history_pos = cxt->save_line;
rl_save_prompt ();
/* Initialize search parameters. */
cxt->search_string = (char *)xmalloc (cxt->search_string_size = 128);
cxt->search_string[cxt->search_string_index = 0] = '\0';
/* Normalize DIRECTION into 1 or -1. */
cxt->direction = (direction >= 0) ? 1 : -1;
cxt->sline = rl_line_buffer;
cxt->sline_len = strlen (cxt->sline);
cxt->sline_index = rl_point;
_rl_iscxt = cxt; /* save globally */
return cxt;
}
static void
_rl_isearch_fini (cxt)
_rl_search_cxt *cxt;
{
/* First put back the original state. */
strcpy (rl_line_buffer, cxt->lines[cxt->save_line]);
rl_restore_prompt ();
/* Save the search string for possible later use. */
FREE (last_isearch_string);
last_isearch_string = cxt->search_string;
last_isearch_string_len = cxt->search_string_index;
cxt->search_string = 0;
if (cxt->last_found_line < cxt->save_line)
rl_get_previous_history (cxt->save_line - cxt->last_found_line, 0);
else
rl_get_next_history (cxt->last_found_line - cxt->save_line, 0);
/* If the string was not found, put point at the end of the last matching
line. If last_found_line == orig_line, we didn't find any matching
history lines at all, so put point back in its original position. */
if (cxt->sline_index < 0)
{
if (cxt->last_found_line == cxt->save_line)
cxt->sline_index = cxt->save_point;
else
cxt->sline_index = strlen (rl_line_buffer);
rl_mark = cxt->save_mark;
}
rl_point = cxt->sline_index;
/* Don't worry about where to put the mark here; rl_get_previous_history
and rl_get_next_history take care of it. */
rl_clear_message ();
}
int
_rl_search_getchar (cxt)
_rl_search_cxt *cxt;
{
int c;
/* Read a key and decide how to proceed. */
RL_SETSTATE(RL_STATE_MOREINPUT);
c = cxt->lastc = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
#if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
c = cxt->lastc = _rl_read_mbstring (cxt->lastc, cxt->mb, MB_LEN_MAX);
#endif
return c;
}
/* Process just-read character C according to isearch context CXT. Return
-1 if the caller should just free the context and return, 0 if we should
break out of the loop, and 1 if we should continue to read characters. */
int
_rl_isearch_dispatch (cxt, c)
_rl_search_cxt *cxt;
int c;
{
int n, wstart, wlen, limit, cval;
rl_command_func_t *f;
f = (rl_command_func_t *)NULL;
/* Translate the keys we do something with to opcodes. */
if (c >= 0 && _rl_keymap[c].type == ISFUNC)
{
f = _rl_keymap[c].function;
if (f == rl_reverse_search_history)
cxt->lastc = (cxt->sflags & SF_REVERSE) ? -1 : -2;
else if (f == rl_forward_search_history)
cxt->lastc = (cxt->sflags & SF_REVERSE) ? -2 : -1;
else if (f == rl_rubout)
cxt->lastc = -3;
else if (c == CTRL ('G'))
cxt->lastc = -4;
else if (c == CTRL ('W')) /* XXX */
cxt->lastc = -5;
else if (c == CTRL ('Y')) /* XXX */
cxt->lastc = -6;
}
/* The characters in isearch_terminators (set from the user-settable
variable isearch-terminators) are used to terminate the search but
not subsequently execute the character as a command. The default
value is "\033\012" (ESC and C-J). */
if (strchr (cxt->search_terminators, cxt->lastc))
{
/* ESC still terminates the search, but if there is pending
input or if input arrives within 0.1 seconds (on systems
with select(2)) it is used as a prefix character
with rl_execute_next. WATCH OUT FOR THIS! This is intended
to allow the arrow keys to be used like ^F and ^B are used
to terminate the search and execute the movement command.
XXX - since _rl_input_available depends on the application-
settable keyboard timeout value, this could alternatively
use _rl_input_queued(100000) */
if (cxt->lastc == ESC && _rl_input_available ())
rl_execute_next (ESC);
return (0);
}
#define ENDSRCH_CHAR(c) \
((CTRL_CHAR (c) || META_CHAR (c) || (c) == RUBOUT) && ((c) != CTRL ('G')))
#if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
{
if (cxt->lastc >= 0 && (cxt->mb[0] && cxt->mb[1] == '\0') && ENDSRCH_CHAR (cxt->lastc))
{
/* This sets rl_pending_input to c; it will be picked up the next
time rl_read_key is called. */
rl_execute_next (cxt->lastc);
return (0);
}
}
else
#endif
if (cxt->lastc >= 0 && ENDSRCH_CHAR (cxt->lastc))
{
/* This sets rl_pending_input to LASTC; it will be picked up the next
time rl_read_key is called. */
rl_execute_next (cxt->lastc);
return (0);
}
/* Now dispatch on the character. `Opcodes' affect the search string or
state. Other characters are added to the string. */
switch (cxt->lastc)
{
/* search again */
case -1:
if (cxt->search_string_index == 0)
{
if (last_isearch_string)
{
cxt->search_string_size = 64 + last_isearch_string_len;
cxt->search_string = (char *)xrealloc (cxt->search_string, cxt->search_string_size);
strcpy (cxt->search_string, last_isearch_string);
cxt->search_string_index = last_isearch_string_len;
rl_display_search (cxt->search_string, (cxt->sflags & SF_REVERSE), -1);
break;
}
return (1);
}
else if (cxt->sflags & SF_REVERSE)
cxt->sline_index--;
else if (cxt->sline_index != cxt->sline_len)
cxt->sline_index++;
else
rl_ding ();
break;
/* switch directions */
case -2:
cxt->direction = -cxt->direction;
if (cxt->direction < 0)
cxt->sflags |= SF_REVERSE;
else
cxt->sflags &= ~SF_REVERSE;
break;
/* delete character from search string. */
case -3: /* C-H, DEL */
/* This is tricky. To do this right, we need to keep a
stack of search positions for the current search, with
sentinels marking the beginning and end. But this will
do until we have a real isearch-undo. */
if (cxt->search_string_index == 0)
rl_ding ();
else
cxt->search_string[--cxt->search_string_index] = '\0';
break;
case -4: /* C-G, abort */
rl_replace_line (cxt->lines[cxt->save_line], 0);
rl_point = cxt->save_point;
rl_mark = cxt->save_mark;
rl_restore_prompt();
rl_clear_message ();
return -1;
case -5: /* C-W */
/* skip over portion of line we already matched and yank word */
wstart = rl_point + cxt->search_string_index;
if (wstart >= rl_end)
{
rl_ding ();
break;
}
/* if not in a word, move to one. */
cval = _rl_char_value (rl_line_buffer, wstart);
if (_rl_walphabetic (cval) == 0)
{
rl_ding ();
break;
}
n = MB_NEXTCHAR (rl_line_buffer, wstart, 1, MB_FIND_NONZERO);;
while (n < rl_end)
{
cval = _rl_char_value (rl_line_buffer, n);
if (_rl_walphabetic (cval) == 0)
break;
n = MB_NEXTCHAR (rl_line_buffer, n, 1, MB_FIND_NONZERO);;
}
wlen = n - wstart + 1;
if (cxt->search_string_index + wlen + 1 >= cxt->search_string_size)
{
cxt->search_string_size += wlen + 1;
cxt->search_string = (char *)xrealloc (cxt->search_string, cxt->search_string_size);
}
for (; wstart < n; wstart++)
cxt->search_string[cxt->search_string_index++] = rl_line_buffer[wstart];
cxt->search_string[cxt->search_string_index] = '\0';
break;
case -6: /* C-Y */
/* skip over portion of line we already matched and yank rest */
wstart = rl_point + cxt->search_string_index;
if (wstart >= rl_end)
{
rl_ding ();
break;
}
n = rl_end - wstart + 1;
if (cxt->search_string_index + n + 1 >= cxt->search_string_size)
{
cxt->search_string_size += n + 1;
cxt->search_string = (char *)xrealloc (cxt->search_string, cxt->search_string_size);
}
for (n = wstart; n < rl_end; n++)
cxt->search_string[cxt->search_string_index++] = rl_line_buffer[n];
cxt->search_string[cxt->search_string_index] = '\0';
break;
/* Add character to search string and continue search. */
default:
if (cxt->search_string_index + 2 >= cxt->search_string_size)
{
cxt->search_string_size += 128;
cxt->search_string = (char *)xrealloc (cxt->search_string, cxt->search_string_size);
}
#if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
{
int j, l;
for (j = 0, l = strlen (cxt->mb); j < l; )
cxt->search_string[cxt->search_string_index++] = cxt->mb[j++];
}
else
#endif
cxt->search_string[cxt->search_string_index++] = c;
cxt->search_string[cxt->search_string_index] = '\0';
break;
}
for (cxt->sflags &= ~(SF_FOUND|SF_FAILED);; )
{
limit = cxt->sline_len - cxt->search_string_index + 1;
/* Search the current line. */
while ((cxt->sflags & SF_REVERSE) ? (cxt->sline_index >= 0) : (cxt->sline_index < limit))
{
if (STREQN (cxt->search_string, cxt->sline + cxt->sline_index, cxt->search_string_index))
{
cxt->sflags |= SF_FOUND;
break;
}
else
cxt->sline_index += cxt->direction;
}
if (cxt->sflags & SF_FOUND)
break;
/* Move to the next line, but skip new copies of the line
we just found and lines shorter than the string we're
searching for. */
do
{
/* Move to the next line. */
cxt->history_pos += cxt->direction;
/* At limit for direction? */
if ((cxt->sflags & SF_REVERSE) ? (cxt->history_pos < 0) : (cxt->history_pos == cxt->hlen))
{
cxt->sflags |= SF_FAILED;
break;
}
/* We will need these later. */
cxt->sline = cxt->lines[cxt->history_pos];
cxt->sline_len = strlen (cxt->sline);
}
while ((cxt->prev_line_found && STREQ (cxt->prev_line_found, cxt->lines[cxt->history_pos])) ||
(cxt->search_string_index > cxt->sline_len));
if (cxt->sflags & SF_FAILED)
break;
/* Now set up the line for searching... */
cxt->sline_index = (cxt->sflags & SF_REVERSE) ? cxt->sline_len - cxt->search_string_index : 0;
}
if (cxt->sflags & SF_FAILED)
{
/* We cannot find the search string. Ding the bell. */
rl_ding ();
cxt->history_pos = cxt->last_found_line;
return 1;
}
/* We have found the search string. Just display it. But don't
actually move there in the history list until the user accepts
the location. */
if (cxt->sflags & SF_FOUND)
{
cxt->prev_line_found = cxt->lines[cxt->history_pos];
rl_replace_line (cxt->lines[cxt->history_pos], 0);
rl_point = cxt->sline_index;
cxt->last_found_line = cxt->history_pos;
rl_display_search (cxt->search_string, (cxt->sflags & SF_REVERSE), (cxt->history_pos == cxt->save_line) ? -1 : cxt->history_pos);
}
return 1;
}
static int
_rl_isearch_cleanup (cxt, r)
_rl_search_cxt *cxt;
int r;
{
if (r >= 0)
_rl_isearch_fini (cxt);
_rl_scxt_dispose (cxt, 0);
_rl_iscxt = 0;
RL_UNSETSTATE(RL_STATE_ISEARCH);
return (r != 0);
}
/* Search through the history looking for an interactively typed string.
This is analogous to i-search. We start the search in the current line.
DIRECTION is which direction to search; >= 0 means forward, < 0 means
@@ -147,287 +616,51 @@ static int
rl_search_history (direction, invoking_key)
int direction, invoking_key;
{
/* The string that the user types in to search for. */
char *search_string;
_rl_search_cxt *cxt; /* local for now, but saved globally */
int c, r;
/* The current length of SEARCH_STRING. */
int search_string_index;
RL_SETSTATE(RL_STATE_ISEARCH);
cxt = _rl_isearch_init (direction);
/* The amount of space that SEARCH_STRING has allocated to it. */
int search_string_size;
rl_display_search (cxt->search_string, (cxt->sflags & SF_REVERSE), -1);
/* The list of lines to search through. */
char **lines, *allocated_line;
/* If we are using the callback interface, all we do is set up here and
return. The key is that we leave RL_STATE_ISEARCH set. */
if (RL_ISSTATE (RL_STATE_CALLBACK))
return (0);
/* The length of LINES. */
int hlen;
/* Where we get LINES from. */
HIST_ENTRY **hlist;
register int i;
int orig_point, orig_line, last_found_line;
int c, found, failed, sline_len;
/* The line currently being searched. */
char *sline;
/* Offset in that line. */
int line_index;
/* Non-zero if we are doing a reverse search. */
int reverse;
orig_point = rl_point;
last_found_line = orig_line = where_history ();
reverse = direction < 0;
hlist = history_list ();
allocated_line = (char *)NULL;
/* Create an arrary of pointers to the lines that we want to search. */
maybe_replace_line ();
i = 0;
if (hlist)
for (i = 0; hlist[i]; i++);
/* Allocate space for this many lines, +1 for the current input line,
and remember those lines. */
lines = (char **)xmalloc ((1 + (hlen = i)) * sizeof (char *));
for (i = 0; i < hlen; i++)
lines[i] = hlist[i]->line;
if (saved_line_for_history)
lines[i] = saved_line_for_history->line;
else
{
/* Keep track of this so we can free it. */
allocated_line = xmalloc (1 + strlen (rl_line_buffer));
strcpy (allocated_line, &rl_line_buffer[0]);
lines[i] = allocated_line;
}
hlen++;
/* The line where we start the search. */
i = orig_line;
_rl_save_prompt ();
/* Initialize search parameters. */
search_string = xmalloc (search_string_size = 128);
*search_string = '\0';
search_string_index = 0;
prev_line_found = (char *)0; /* XXX */
/* Normalize DIRECTION into 1 or -1. */
direction = (direction >= 0) ? 1 : -1;
rl_display_search (search_string, reverse, -1);
sline = rl_line_buffer;
sline_len = strlen (sline);
line_index = rl_point;
found = failed = 0;
r = -1;
for (;;)
{
Function *f = (Function *)NULL;
/* Read a key and decide how to proceed. */
c = rl_read_key ();
if (_rl_keymap[c].type == ISFUNC)
{
f = _rl_keymap[c].function;
if (f == rl_reverse_search_history)
c = reverse ? -1 : -2;
else if (f == rl_forward_search_history)
c = !reverse ? -1 : -2;
}
/* Let NEWLINE (^J) terminate the search for people who don't like
using ESC. ^M can still be used to terminate the search and
immediately execute the command. */
if (c == ESC || c == NEWLINE)
{
/* ESC still terminates the search, but if there is pending
input or if input arrives within 0.1 seconds (on systems
with select(2)) it is used as a prefix character
with rl_execute_next. WATCH OUT FOR THIS! This is intended
to allow the arrow keys to be used like ^F and ^B are used
to terminate the search and execute the movement command. */
if (c == ESC && _rl_input_available ()) /* XXX */
rl_execute_next (ESC);
break;
}
if (c >= 0 && (CTRL_CHAR (c) || META_CHAR (c) || c == RUBOUT) && c != CTRL ('G'))
{
rl_execute_next (c);
break;
}
switch (c)
{
case -1:
if (search_string_index == 0)
continue;
else if (reverse)
--line_index;
else if (line_index != sline_len)
++line_index;
else
ding ();
break;
/* switch directions */
case -2:
direction = -direction;
reverse = direction < 0;
break;
case CTRL ('G'):
strcpy (rl_line_buffer, lines[orig_line]);
rl_point = orig_point;
rl_end = strlen (rl_line_buffer);
_rl_restore_prompt();
rl_clear_message ();
if (allocated_line)
free (allocated_line);
free (lines);
return 0;
#if 0
/* delete character from search string. */
case -3:
if (search_string_index == 0)
ding ();
else
{
search_string[--search_string_index] = '\0';
/* This is tricky. To do this right, we need to keep a
stack of search positions for the current search, with
sentinels marking the beginning and end. */
}
break;
#endif
default:
/* Add character to search string and continue search. */
if (search_string_index + 2 >= search_string_size)
{
search_string_size += 128;
search_string = xrealloc (search_string, search_string_size);
}
search_string[search_string_index++] = c;
search_string[search_string_index] = '\0';
break;
}
for (found = failed = 0;;)
{
int limit = sline_len - search_string_index + 1;
/* Search the current line. */
while (reverse ? (line_index >= 0) : (line_index < limit))
{
if (STREQN (search_string, sline + line_index, search_string_index))
{
found++;
break;
}
else
line_index += direction;
}
if (found)
break;
/* Move to the next line, but skip new copies of the line
we just found and lines shorter than the string we're
searching for. */
do
{
/* Move to the next line. */
i += direction;
/* At limit for direction? */
if (reverse ? (i < 0) : (i == hlen))
{
failed++;
break;
}
/* We will need these later. */
sline = lines[i];
sline_len = strlen (sline);
}
while ((prev_line_found && STREQ (prev_line_found, lines[i])) ||
(search_string_index > sline_len));
if (failed)
break;
/* Now set up the line for searching... */
line_index = reverse ? sline_len - search_string_index : 0;
}
if (failed)
{
/* We cannot find the search string. Ding the bell. */
ding ();
i = last_found_line;
continue; /* XXX - was break */
}
/* We have found the search string. Just display it. But don't
actually move there in the history list until the user accepts
the location. */
if (found)
{
int line_len;
prev_line_found = lines[i];
line_len = strlen (lines[i]);
if (line_len >= rl_line_buffer_len)
rl_extend_line_buffer (line_len);
strcpy (rl_line_buffer, lines[i]);
rl_point = line_index;
rl_end = line_len;
last_found_line = i;
rl_display_search (search_string, reverse, (i == orig_line) ? -1 : i);
}
c = _rl_search_getchar (cxt);
/* We might want to handle EOF here (c == 0) */
r = _rl_isearch_dispatch (cxt, cxt->lastc);
if (r <= 0)
break;
}
/* The searching is over. The user may have found the string that she
was looking for, or else she may have exited a failing search. If
LINE_INDEX is -1, then that shows that the string searched for was
not found. We use this to determine where to place rl_point. */
/* First put back the original state. */
strcpy (rl_line_buffer, lines[orig_line]);
_rl_restore_prompt ();
/* Free the search string. */
free (search_string);
if (last_found_line < orig_line)
rl_get_previous_history (orig_line - last_found_line);
else
rl_get_next_history (last_found_line - orig_line);
/* If the string was not found, put point at the end of the line. */
if (line_index < 0)
line_index = strlen (rl_line_buffer);
rl_point = line_index;
rl_clear_message ();
if (allocated_line)
free (allocated_line);
free (lines);
return 0;
return (_rl_isearch_cleanup (cxt, r));
}
#if defined (READLINE_CALLBACKS)
/* Called from the callback functions when we are ready to read a key. The
callback functions know to call this because RL_ISSTATE(RL_STATE_ISEARCH).
If _rl_isearch_dispatch finishes searching, this function is responsible
for turning off RL_STATE_ISEARCH, which it does using _rl_isearch_cleanup. */
int
_rl_isearch_callback (cxt)
_rl_search_cxt *cxt;
{
int c, r;
c = _rl_search_getchar (cxt);
/* We might want to handle EOF here */
r = _rl_isearch_dispatch (cxt, cxt->lastc);
return (r <= 0) ? _rl_isearch_cleanup (cxt, r) : 0;
}
#endif

View File

@@ -7,7 +7,7 @@
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 1, or (at your option) any
Free Software Foundation; either version 2, or (at your option) any
later version.
Readline is distributed in the hope that it will be useful, but
@@ -17,7 +17,7 @@
You should have received a copy of the GNU General Public License
along with Readline; see the file COPYING. If not, write to the Free
Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#define READLINE_LIBRARY
#if defined (HAVE_CONFIG_H)
@@ -30,18 +30,18 @@
# include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */
#include <stdio.h> /* for FILE * definition for readline.h */
#include "readline.h"
#include "rlconf.h"
#include "keymaps.h"
#include "emacs_keymap.c"
#if defined (VI_MODE)
#include "vi_keymap.c"
#endif
extern int rl_do_lowercase_version ();
extern int rl_rubout (), rl_insert ();
extern char *xmalloc (), *xrealloc ();
#include "xmalloc.h"
/* **************************************************************** */
/* */
@@ -61,14 +61,16 @@ rl_make_bare_keymap ()
for (i = 0; i < KEYMAP_SIZE; i++)
{
keymap[i].type = ISFUNC;
keymap[i].function = (Function *)NULL;
keymap[i].function = (rl_command_func_t *)NULL;
}
#if 0
for (i = 'A'; i < ('Z' + 1); i++)
{
keymap[i].type = ISFUNC;
keymap[i].function = rl_do_lowercase_version;
}
#endif
return (keymap);
}
@@ -79,8 +81,9 @@ rl_copy_keymap (map)
Keymap map;
{
register int i;
Keymap temp = rl_make_bare_keymap ();
Keymap temp;
temp = rl_make_bare_keymap ();
for (i = 0; i < KEYMAP_SIZE; i++)
{
temp[i].type = map[i].type;
@@ -109,12 +112,8 @@ rl_make_keymap ()
newmap[CTRL('H')].function = rl_rubout;
#if KEYMAP_SIZE > 128
/* Printing characters in some 8-bit character sets. */
for (i = 128; i < 160; i++)
newmap[i].function = rl_insert;
/* ISO Latin-1 printing characters should self-insert. */
for (i = 160; i < 256; i++)
/* Printing characters in ISO Latin-1 and some 8-bit character sets. */
for (i = 128; i < 256; i++)
newmap[i].function = rl_insert;
#endif /* KEYMAP_SIZE > 128 */
@@ -124,7 +123,7 @@ rl_make_keymap ()
/* Free the storage associated with MAP. */
void
rl_discard_keymap (map)
Keymap (map);
Keymap map;
{
int i;

View File

@@ -7,7 +7,7 @@
The GNU Readline Library is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 1, or
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
The GNU Readline Library is distributed in the hope that it will be
@@ -18,23 +18,23 @@
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#ifndef _KEYMAPS_H_
#define _KEYMAPS_H_
#if defined (READLINE_LIBRARY)
# include "chardefs.h"
#else
# include <readline/chardefs.h>
#ifdef __cplusplus
extern "C" {
#endif
#if !defined (_FUNCTION_DEF)
# define _FUNCTION_DEF
typedef int Function ();
typedef void VFunction ();
typedef char *CPFunction ();
typedef char **CPPFunction ();
#if defined (READLINE_LIBRARY)
# include "rlstdc.h"
# include "chardefs.h"
# include "rltypedefs.h"
#else
# include <readline/rlstdc.h>
# include <readline/chardefs.h>
# include <readline/rltypedefs.h>
#endif
/* A keymap contains one entry for each key in the ASCII set.
@@ -44,16 +44,17 @@ typedef char **CPPFunction ();
TYPE says which kind of thing FUNCTION is. */
typedef struct _keymap_entry {
char type;
Function *function;
rl_command_func_t *function;
} KEYMAP_ENTRY;
/* This must be large enough to hold bindings for all of the characters
in a desired character set (e.g, 128 for ASCII, 256 for ISO Latin-x,
and so on). */
#define KEYMAP_SIZE 256
and so on) plus one for subsequence matching. */
#define KEYMAP_SIZE 257
#define ANYOTHERKEY KEYMAP_SIZE-1
/* I wanted to make the above structure contain a union of:
union { Function *function; struct _keymap_entry *keymap; } value;
union { rl_command_func_t *function; struct _keymap_entry *keymap; } value;
but this made it impossible for me to create a static array.
Maybe I need C lessons. */
@@ -70,26 +71,33 @@ extern KEYMAP_ENTRY_ARRAY vi_insertion_keymap, vi_movement_keymap;
/* Return a new, empty keymap.
Free it with free() when you are done. */
extern Keymap rl_make_bare_keymap ();
extern Keymap rl_make_bare_keymap PARAMS((void));
/* Return a new keymap which is a copy of MAP. */
extern Keymap rl_copy_keymap ();
extern Keymap rl_copy_keymap PARAMS((Keymap));
/* Return a new keymap with the printing characters bound to rl_insert,
the lowercase Meta characters bound to run their equivalents, and
the Meta digits bound to produce numeric arguments. */
extern Keymap rl_make_keymap ();
extern Keymap rl_make_keymap PARAMS((void));
extern void rl_discard_keymap ();
/* Free the storage associated with a keymap. */
extern void rl_discard_keymap PARAMS((Keymap));
/* These functions actually appear in bind.c */
/* Return the keymap corresponding to a given name. Names look like
`emacs' or `emacs-meta' or `vi-insert'. */
extern Keymap rl_get_keymap_by_name ();
`emacs' or `emacs-meta' or `vi-insert'. */
extern Keymap rl_get_keymap_by_name PARAMS((const char *));
/* Return the current keymap. */
extern Keymap rl_get_keymap ();
extern Keymap rl_get_keymap PARAMS((void));
/* Set the current keymap to MAP. */
extern void rl_set_keymap ();
extern void rl_set_keymap PARAMS((Keymap));
#ifdef __cplusplus
}
#endif
#endif /* _KEYMAPS_H_ */

Some files were not shown because too many files have changed in this diff Show More