diff options
author | Daniel Jacobowitz <drow@false.org> | 2006-05-05 18:26:14 +0000 |
---|---|---|
committer | Daniel Jacobowitz <drow@false.org> | 2006-05-05 18:26:14 +0000 |
commit | 5bdf8622148be4764cc0757fd5b3e41f4d73b2b2 (patch) | |
tree | ec69331983824d95160ec9a14f71d6bccd23ed42 /readline | |
parent | 2006-05-05 H.J. Lu <hongjiu.lu@intel.com> (diff) | |
download | binutils-gdb-5bdf8622148be4764cc0757fd5b3e41f4d73b2b2.tar.gz binutils-gdb-5bdf8622148be4764cc0757fd5b3e41f4d73b2b2.tar.bz2 binutils-gdb-5bdf8622148be4764cc0757fd5b3e41f4d73b2b2.zip |
Readline 5.1 import for HEAD.
Diffstat (limited to 'readline')
84 files changed, 8824 insertions, 8530 deletions
diff --git a/readline/CHANGELOG b/readline/CHANGELOG index 350defafe1b..b6499c3b716 100644 --- a/readline/CHANGELOG +++ b/readline/CHANGELOG @@ -697,3 +697,224 @@ 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] diff --git a/readline/CHANGES b/readline/CHANGES index bc9fe94e992..1ba0c1256df 100644 --- a/readline/CHANGES +++ b/readline/CHANGES @@ -1,3 +1,312 @@ +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. diff --git a/readline/ChangeLog.gdb b/readline/ChangeLog.gdb index e95619318ea..c35742655eb 100644 --- a/readline/ChangeLog.gdb +++ b/readline/ChangeLog.gdb @@ -1,3 +1,7 @@ +2006-04-24 Daniel Jacobowitz <dan@codesourcery.com> + + Imported readline 5.1, and upstream patches 001-004. + 2006-03-21 Denis Pilat <denis.pilat@st.com> * histfile.c (read_history_range): Remove '\r' character from diff --git a/readline/INSTALL b/readline/INSTALL index adb27a9f222..1a73c779000 100644 --- a/readline/INSTALL +++ b/readline/INSTALL @@ -1,7 +1,7 @@ Basic Installation ================== -These are installation instructions for Readline-4.3. +These are installation instructions for Readline-5.1. The simplest way to compile readline is: @@ -238,6 +238,9 @@ SHLIB_XLDFLAGS Additional flags to pass to SHOBJ_LD for shared library 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'. @@ -254,6 +257,17 @@ SHLIB_LIBVERSION The string to append to the filename to indicate the 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 diff --git a/readline/MANIFEST b/readline/MANIFEST index 1507eda6f94..b288fb6f80a 100644 --- a/readline/MANIFEST +++ b/readline/MANIFEST @@ -3,6 +3,7 @@ # doc d examples d +examples/rlfe d support d shlib d COPYING f @@ -11,6 +12,7 @@ MANIFEST f INSTALL f CHANGELOG f CHANGES f +NEWS f USAGE f aclocal.m4 f config.h.in f @@ -74,23 +76,26 @@ 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/manvers.texinfo f -doc/rlman.texinfo f -doc/rltech.texinfo f -doc/rluser.texinfo f -doc/rluserman.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 @@ -100,13 +105,25 @@ 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/rlfe.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 @@ -124,3 +141,6 @@ 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 diff --git a/readline/Makefile.in b/readline/Makefile.in index f039ec627f4..2dbd4bb9589 100644 --- a/readline/Makefile.in +++ b/readline/Makefile.in @@ -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 @@ -18,6 +18,14 @@ 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@ top_srcdir = @top_srcdir@ @@ -35,6 +43,8 @@ RM = rm -f CP = cp MV = mv +PURIFY = @PURIFY@ + @SET_MAKE@ SHELL = @MAKE_SHELL@ @@ -45,6 +55,8 @@ bindir = @bindir@ libdir = @libdir@ mandir = @mandir@ includedir = @includedir@ +datadir = @datadir@ +localedir = $(datadir)/locale infodir = @infodir@ @@ -61,7 +73,7 @@ CFLAGS = @CFLAGS@ LOCAL_CFLAGS = @LOCAL_CFLAGS@ -DRL_LIBRARY_VERSION='"$(RL_LIBRARY_VERSION)"' CPPFLAGS = @CPPFLAGS@ -DEFS = @DEFS@ +DEFS = @DEFS@ @CROSS_COMPILE@ LOCAL_DEFS = @LOCAL_DEFS@ TERMCAP_LIB = @TERMCAP_LIB@ @@ -211,7 +223,7 @@ uninstall-headers: maybe-uninstall-headers: uninstall-headers -## CYGNUS LOCAL +## GDB 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 @@ -223,38 +235,42 @@ install: #install: $(INSTALL_TARGETS) -install-static: installdirs $(STATIC_LIBS) install-headers +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 - -( if test -d doc ; then \ - cd doc && \ - ${MAKE} ${MFLAGS} infodir=$(infodir) DESTDIR=${DESTDIR} install; \ - fi ) -installdirs: $(srcdir)/support/mkdirs - -$(SHELL) $(srcdir)/support/mkdirs $(DESTDIR)$(includedir) \ +installdirs: $(srcdir)/support/mkinstalldirs + -$(SHELL) $(srcdir)/support/mkinstalldirs $(DESTDIR)$(includedir) \ $(DESTDIR)$(includedir)/readline $(DESTDIR)$(libdir) \ $(DESTDIR)$(infodir) $(DESTDIR)$(man3dir) -uninstall: uninstall-headers +uninstall: uninstall-headers uninstall-doc -test -n "$(DESTDIR)$(libdir)" && cd $(DESTDIR)$(libdir) && \ ${RM} libreadline.a libreadline.old libhistory.a libhistory.old $(SHARED_LIBS) - -( if test -d doc ; then \ - cd doc && \ - ${MAKE} ${MFLAGS} infodir=$(infodir) DESTDIR=${DESTDIR} $@; \ - fi ) -( cd shlib; ${MAKE} ${MFLAGS} DESTDIR=${DESTDIR} uninstall ) -install-shared: installdirs install-headers shared +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 ) +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) diff --git a/readline/README b/readline/README index 7aa939452fb..8dd09cc5373 100644 --- a/readline/README +++ b/readline/README @@ -1,7 +1,7 @@ Introduction ============ -This is the Gnu Readline library, version 4.3. +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 @@ -102,6 +102,9 @@ SHLIB_XLDFLAGS Additional flags to pass to SHOBJ_LD for shared library 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'. @@ -118,6 +121,17 @@ SHLIB_LIBVERSION The string to append to the filename to indicate the 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. diff --git a/readline/acconfig.h b/readline/acconfig.h deleted file mode 100644 index 577cf9c7d49..00000000000 --- a/readline/acconfig.h +++ /dev/null @@ -1,56 +0,0 @@ -/* acconfig.h - This file is in the public domain. - - Descriptive text for the C preprocessor macros that - the distributed Autoconf macros can define. - No software package will use all of them; autoheader copies the ones - your configure.in uses into your configuration header file templates. - - The entries are in sort -df order: alphabetical, case insensitive, - ignoring punctuation (such as underscores). Although this order - can split up related entries, it makes it easier to check whether - a given entry is in the file. - - Leave the following blank line there!! Autoheader needs it. */ - - -/* Definitions pulled in from aclocal.m4. */ -#undef VOID_SIGHANDLER - -#undef GWINSZ_IN_SYS_IOCTL - -#undef TIOCSTAT_IN_SYS_IOCTL - -#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: - The entries are in sort -df order: alphabetical, case insensitive, - ignoring punctuation (such as underscores). */ diff --git a/readline/aclocal.m4 b/readline/aclocal.m4 index 35613c2702f..485ca491c1d 100644 --- a/readline/aclocal.m4 +++ b/readline/aclocal.m4 @@ -685,65 +685,26 @@ fi ]) AC_DEFUN(BASH_FUNC_GETCWD, -[AC_MSG_CHECKING([if getcwd() calls popen()]) -AC_CACHE_VAL(bash_cv_getcwd_calls_popen, +[AC_MSG_CHECKING([if getcwd() will dynamically allocate memory]) +AC_CACHE_VAL(bash_cv_getcwd_malloc, [AC_TRY_RUN([ #include <stdio.h> #ifdef HAVE_UNISTD_H #include <unistd.h> #endif -#ifndef __STDC__ -#ifndef const -#define const -#endif -#endif - -int popen_called; - -FILE * -popen(command, type) - const char *command; - const char *type; -{ - popen_called = 1; - return (FILE *)NULL; -} - -FILE *_popen(command, type) - const char *command; - const char *type; -{ - return (popen (command, type)); -} - -int -pclose(stream) -FILE *stream; -{ - return 0; -} - -int -_pclose(stream) -FILE *stream; -{ - return 0; -} - main() { - char lbuf[32]; - popen_called = 0; - getcwd(lbuf, 32); - exit (popen_called); + char *xpwd; + xpwd = getcwd(0, 0); + exit (xpwd == 0); } -], bash_cv_getcwd_calls_popen=no, bash_cv_getcwd_calls_popen=yes, - [AC_MSG_WARN(cannot check whether getcwd calls popen if cross compiling -- defaulting to no) - bash_cv_getcwd_calls_popen=no] +], bash_cv_getcwd_malloc=yes, bash_cv_getcwd_malloc=no, + [AC_MSG_WARN(cannot check whether getcwd allocates memory when cross-compiling -- defaulting to no) + bash_cv_getcwd_malloc=no] )]) -AC_MSG_RESULT($bash_cv_getcwd_calls_popen) -if test $bash_cv_getcwd_calls_popen = yes; then +AC_MSG_RESULT($bash_cv_getcwd_malloc) +if test $bash_cv_getcwd_malloc = no; then AC_DEFINE(GETCWD_BROKEN) AC_LIBOBJ(getcwd) fi @@ -981,11 +942,12 @@ AC_MSG_CHECKING(which library has the termcap functions) _bash_needmsg= fi AC_CACHE_VAL(bash_cv_termcap_lib, -[AC_CHECK_LIB(termcap, tgetent, bash_cv_termcap_lib=libtermcap, +[AC_CHECK_FUNC(tgetent, bash_cv_termcap_lib=libc, + [AC_CHECK_LIB(termcap, tgetent, bash_cv_termcap_lib=libtermcap, [AC_CHECK_LIB(tinfo, tgetent, bash_cv_termcap_lib=libtinfo, [AC_CHECK_LIB(curses, tgetent, bash_cv_termcap_lib=libcurses, [AC_CHECK_LIB(ncurses, tgetent, bash_cv_termcap_lib=libncurses, - bash_cv_termcap_lib=gnutermcap)])])])]) + bash_cv_termcap_lib=gnutermcap)])])])])]) if test "X$_bash_needmsg" = "Xyes"; then AC_MSG_CHECKING(which library has the termcap functions) fi @@ -1003,6 +965,9 @@ TERMCAP_DEP= elif test $bash_cv_termcap_lib = libncurses; then TERMCAP_LIB=-lncurses TERMCAP_DEP= +elif test $bash_cv_termcap_lib = libc; then +TERMCAP_LIB= +TERMCAP_DEP= else TERMCAP_LIB=-lcurses TERMCAP_DEP= @@ -1061,7 +1026,7 @@ fi AC_DEFUN(BASH_STRUCT_DIRENT_D_INO, [AC_REQUIRE([AC_HEADER_DIRENT]) -AC_MSG_CHECKING(if struct dirent has a d_ino member) +AC_MSG_CHECKING(for struct dirent.d_ino) AC_CACHE_VAL(bash_cv_dirent_has_dino, [AC_TRY_COMPILE([ #include <stdio.h> @@ -1088,13 +1053,13 @@ struct dirent d; int z; z = d.d_ino; ], bash_cv_dirent_has_dino=yes, bash_cv_dirent_has_dino=no)]) AC_MSG_RESULT($bash_cv_dirent_has_dino) if test $bash_cv_dirent_has_dino = yes; then -AC_DEFINE(STRUCT_DIRENT_HAS_D_INO) +AC_DEFINE(HAVE_STRUCT_DIRENT_D_INO) fi ]) AC_DEFUN(BASH_STRUCT_DIRENT_D_FILENO, [AC_REQUIRE([AC_HEADER_DIRENT]) -AC_MSG_CHECKING(if struct dirent has a d_fileno member) +AC_MSG_CHECKING(for struct dirent.d_fileno) AC_CACHE_VAL(bash_cv_dirent_has_d_fileno, [AC_TRY_COMPILE([ #include <stdio.h> @@ -1121,7 +1086,40 @@ struct dirent d; int z; z = d.d_fileno; ], bash_cv_dirent_has_d_fileno=yes, bash_cv_dirent_has_d_fileno=no)]) AC_MSG_RESULT($bash_cv_dirent_has_d_fileno) if test $bash_cv_dirent_has_d_fileno = yes; then -AC_DEFINE(STRUCT_DIRENT_HAS_D_FILENO) +AC_DEFINE(HAVE_STRUCT_DIRENT_D_FILENO) +fi +]) + +AC_DEFUN(BASH_STRUCT_DIRENT_D_NAMLEN, +[AC_REQUIRE([AC_HEADER_DIRENT]) +AC_MSG_CHECKING(for struct dirent.d_namlen) +AC_CACHE_VAL(bash_cv_dirent_has_d_namlen, +[AC_TRY_COMPILE([ +#include <stdio.h> +#include <sys/types.h> +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif /* HAVE_UNISTD_H */ +#if defined(HAVE_DIRENT_H) +# include <dirent.h> +#else +# define dirent direct +# ifdef HAVE_SYS_NDIR_H +# include <sys/ndir.h> +# endif /* SYSNDIR */ +# ifdef HAVE_SYS_DIR_H +# include <sys/dir.h> +# endif /* SYSDIR */ +# ifdef HAVE_NDIR_H +# include <ndir.h> +# endif +#endif /* HAVE_DIRENT_H */ +],[ +struct dirent d; int z; z = d.d_namlen; +], bash_cv_dirent_has_d_namlen=yes, bash_cv_dirent_has_d_namlen=no)]) +AC_MSG_RESULT($bash_cv_dirent_has_d_namlen) +if test $bash_cv_dirent_has_d_namlen = yes; then +AC_DEFINE(HAVE_STRUCT_DIRENT_D_NAMLEN) fi ]) @@ -1141,6 +1139,22 @@ if test $bash_cv_struct_timeval = yes; then fi ]) +AC_DEFUN(BASH_STRUCT_TIMEZONE, +[AC_MSG_CHECKING(for struct timezone in sys/time.h and time.h) +AC_CACHE_VAL(bash_cv_struct_timezone, +[ +AC_EGREP_HEADER(struct timezone, sys/time.h, + bash_cv_struct_timezone=yes, + AC_EGREP_HEADER(struct timezone, time.h, + bash_cv_struct_timezone=yes, + bash_cv_struct_timezone=no)) +]) +AC_MSG_RESULT($bash_cv_struct_timezone) +if test $bash_cv_struct_timezone = yes; then + AC_DEFINE(HAVE_STRUCT_TIMEZONE) +fi +]) + AC_DEFUN(BASH_STRUCT_WINSIZE, [AC_MSG_CHECKING(for struct winsize in sys/ioctl.h and termios.h) AC_CACHE_VAL(bash_cv_struct_winsize_header, @@ -1526,9 +1540,16 @@ fi AC_DEFUN(BASH_CHECK_DEV_FD, [AC_MSG_CHECKING(whether /dev/fd is available) AC_CACHE_VAL(bash_cv_dev_fd, -[if test -d /dev/fd && test -r /dev/fd/0; then - bash_cv_dev_fd=standard - elif test -d /proc/self/fd && test -r /proc/self/fd/0; then +[if test -d /dev/fd && test -r /dev/fd/0 < /dev/null; then +# check for systems like FreeBSD 5 that only provide /dev/fd/[012] + exec 3<&0 + if test -r /dev/fd/3; then + bash_cv_dev_fd=standard + else + bash_cv_dev_fd=absent + fi + exec 3<&- + elif test -d /proc/self/fd && test -r /proc/self/fd/0 < /dev/null; then bash_cv_dev_fd=whacky else bash_cv_dev_fd=absent @@ -1547,9 +1568,9 @@ fi AC_DEFUN(BASH_CHECK_DEV_STDIN, [AC_MSG_CHECKING(whether /dev/stdin stdout stderr are available) AC_CACHE_VAL(bash_cv_dev_stdin, -[if test -d /dev/fd && test -r /dev/stdin; then +[if test -d /dev/fd && test -r /dev/stdin < /dev/null; then bash_cv_dev_stdin=present - elif test -d /proc/self/fd && test -r /dev/stdin; then + elif test -d /proc/self/fd && test -r /dev/stdin < /dev/null; then bash_cv_dev_stdin=present else bash_cv_dev_stdin=absent @@ -1652,9 +1673,13 @@ AC_CHECK_HEADERS(wctype.h) AC_CHECK_HEADERS(wchar.h) AC_CHECK_HEADERS(langinfo.h) -AC_CHECK_FUNC(mbrtowc, AC_DEFINE(HAVE_MBRTOWC)) AC_CHECK_FUNC(mbsrtowcs, AC_DEFINE(HAVE_MBSRTOWCS)) +AC_CHECK_FUNC(mbrtowc, AC_DEFINE(HAVE_MBRTOWC)) +AC_CHECK_FUNC(mbrlen, AC_DEFINE(HAVE_MBRLEN)) +AC_CHECK_FUNC(wctomb, AC_DEFINE(HAVE_WCTOMB)) AC_CHECK_FUNC(wcwidth, AC_DEFINE(HAVE_WCWIDTH)) +AC_CHECK_FUNC(wcsdup, AC_DEFINE(HAVE_WCSDUP)) + if test "$ac_cv_func_wcwidth" = no && test "$ac_cv_header_wchar_h" = yes; then WCWIDTH_OBJ=wcwidth.o else @@ -1663,14 +1688,12 @@ fi AC_SUBST(WCWIDTH_OBJ) AC_CACHE_CHECK([for mbstate_t], bash_cv_have_mbstate_t, -[AC_TRY_LINK( -[#include <wchar.h>], -[int -main () -{ +[AC_TRY_COMPILE([ +#include <wchar.h>], [ mbstate_t ps; - return 0; -}], bash_cv_have_mbstate_t=yes, bash_cv_have_mbstate_t=no)]) + mbstate_t *psp; + psp = (mbstate_t *)0; +], bash_cv_have_mbstate_t=yes, bash_cv_have_mbstate_t=no)]) if test $bash_cv_have_mbstate_t = yes; then AC_DEFINE(HAVE_MBSTATE_T) fi @@ -1719,23 +1742,30 @@ LIBS="$LIBS -lreadline ${TERMCAP_LIB}" CFLAGS="$CFLAGS -I${ac_cv_rl_includedir}" LDFLAGS="$LDFLAGS -L${ac_cv_rl_libdir}" -AC_TRY_RUN([ +AC_CACHE_VAL(ac_cv_rl_version, +[AC_TRY_RUN([ #include <stdio.h> #include <readline/readline.h> +extern int rl_gnu_readline_p; + main() { FILE *fp; fp = fopen("conftest.rlv", "w"); - if (fp == 0) exit(1); - fprintf(fp, "%s\n", rl_library_version ? rl_library_version : "0.0"); + if (fp == 0) + exit(1); + if (rl_gnu_readline_p != 1) + fprintf(fp, "0.0\n"); + else + fprintf(fp, "%s\n", rl_library_version ? rl_library_version : "0.0"); fclose(fp); exit(0); } ], ac_cv_rl_version=`cat conftest.rlv`, ac_cv_rl_version='0.0', -ac_cv_rl_version='4.2') +ac_cv_rl_version='4.2')]) CFLAGS="$_save_CFLAGS" LDFLAGS="$_save_LDFLAGS" @@ -1797,3 +1827,2140 @@ AC_MSG_RESULT($ac_cv_rl_version) fi ]) + +AC_DEFUN(BASH_FUNC_CTYPE_NONASCII, +[ +AC_MSG_CHECKING(whether the ctype macros accept non-ascii characters) +AC_CACHE_VAL(bash_cv_func_ctype_nonascii, +[AC_TRY_RUN([ +#ifdef HAVE_LOCALE_H +#include <locale.h> +#endif +#include <stdio.h> +#include <ctype.h> + +main(c, v) +int c; +char *v[]; +{ + char *deflocale; + unsigned char x; + int r1, r2; + +#ifdef HAVE_SETLOCALE + /* We take a shot here. If that locale is not known, try the + system default. We try this one because '\342' (226) is + known to be a printable character in that locale. */ + deflocale = setlocale(LC_ALL, "en_US.ISO8859-1"); + if (deflocale == 0) + deflocale = setlocale(LC_ALL, ""); +#endif + + x = '\342'; + r1 = isprint(x); + x -= 128; + r2 = isprint(x); + exit (r1 == 0 || r2 == 0); +} +], bash_cv_func_ctype_nonascii=yes, bash_cv_func_ctype_nonascii=no, + [AC_MSG_WARN(cannot check ctype macros if cross compiling -- defaulting to no) + bash_cv_func_ctype_nonascii=no] +)]) +AC_MSG_RESULT($bash_cv_func_ctype_nonascii) +if test $bash_cv_func_ctype_nonascii = yes; then +AC_DEFINE(CTYPE_NON_ASCII) +fi +]) + +AC_DEFUN(BASH_CHECK_WCONTINUED, +[ +AC_MSG_CHECKING(whether WCONTINUED flag to waitpid is unavailable or available but broken) +AC_CACHE_VAL(bash_cv_wcontinued_broken, +[AC_TRY_RUN([ +#include <sys/types.h> +#include <sys/wait.h> +#include <unistd.h> +#include <errno.h> + +#ifndef errno +extern int errno; +#endif +main() +{ + int x; + + x = waitpid(-1, (int *)0, WNOHANG|WCONTINUED); + if (x == -1 && errno == EINVAL) + exit (1); + else + exit (0); +} +], bash_cv_wcontinued_broken=no,bash_cv_wcontinued_broken=yes, + [AC_MSG_WARN(cannot check WCONTINUED if cross compiling -- defaulting to no) + bash_cv_wcontinued_broken=no] +)]) +AC_MSG_RESULT($bash_cv_wcontinued_broken) +if test $bash_cv_wcontinued_broken = yes; then +AC_DEFINE(WCONTINUED_BROKEN) +fi +]) + +dnl +dnl tests added for bashdb +dnl + + +AC_DEFUN([AM_PATH_LISPDIR], + [AC_ARG_WITH(lispdir, AC_HELP_STRING([--with-lispdir], [override the default lisp directory]), + [ lispdir="$withval" + AC_MSG_CHECKING([where .elc files should go]) + AC_MSG_RESULT([$lispdir])], + [ + # If set to t, that means we are running in a shell under Emacs. + # If you have an Emacs named "t", then use the full path. + test x"$EMACS" = xt && EMACS= + AC_CHECK_PROGS(EMACS, emacs xemacs, no) + if test $EMACS != "no"; then + if test x${lispdir+set} != xset; then + AC_CACHE_CHECK([where .elc files should go], [am_cv_lispdir], [dnl + am_cv_lispdir=`$EMACS -batch -q -eval '(while load-path (princ (concat (car load-path) "\n")) (setq load-path (cdr load-path)))' | sed -n -e 's,/$,,' -e '/.*\/lib\/\(x\?emacs\/site-lisp\)$/{s,,${libdir}/\1,;p;q;}' -e '/.*\/share\/\(x\?emacs\/site-lisp\)$/{s,,${datadir}/\1,;p;q;}'` + if test -z "$am_cv_lispdir"; then + am_cv_lispdir='${datadir}/emacs/site-lisp' + fi + ]) + lispdir="$am_cv_lispdir" + fi + fi + ]) + AC_SUBST(lispdir) +]) + +dnl +dnl tests added for gettext +dnl +# codeset.m4 serial AM1 (gettext-0.10.40) +dnl Copyright (C) 2000-2002 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl From Bruno Haible. + +AC_DEFUN([AM_LANGINFO_CODESET], +[ + AC_CACHE_CHECK([for nl_langinfo and CODESET], am_cv_langinfo_codeset, + [AC_TRY_LINK([#include <langinfo.h>], + [char* cs = nl_langinfo(CODESET);], + am_cv_langinfo_codeset=yes, + am_cv_langinfo_codeset=no) + ]) + if test $am_cv_langinfo_codeset = yes; then + AC_DEFINE(HAVE_LANGINFO_CODESET, 1, + [Define if you have <langinfo.h> and nl_langinfo(CODESET).]) + fi +]) +# gettext.m4 serial 20 (gettext-0.12) +dnl Copyright (C) 1995-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +dnl Authors: +dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000. +dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003. + +dnl Macro to add for using GNU gettext. + +dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]). +dnl INTLSYMBOL can be one of 'external', 'no-libtool', 'use-libtool'. The +dnl default (if it is not specified or empty) is 'no-libtool'. +dnl INTLSYMBOL should be 'external' for packages with no intl directory, +dnl and 'no-libtool' or 'use-libtool' for packages with an intl directory. +dnl If INTLSYMBOL is 'use-libtool', then a libtool library +dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static, +dnl depending on --{enable,disable}-{shared,static} and on the presence of +dnl AM-DISABLE-SHARED). If INTLSYMBOL is 'no-libtool', a static library +dnl $(top_builddir)/intl/libintl.a will be created. +dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext +dnl implementations (in libc or libintl) without the ngettext() function +dnl will be ignored. If NEEDSYMBOL is specified and is +dnl 'need-formatstring-macros', then GNU gettext implementations that don't +dnl support the ISO C 99 <inttypes.h> formatstring macros will be ignored. +dnl INTLDIR is used to find the intl libraries. If empty, +dnl the value `$(top_builddir)/intl/' is used. +dnl +dnl The result of the configuration is one of three cases: +dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled +dnl and used. +dnl Catalog format: GNU --> install in $(datadir) +dnl Catalog extension: .mo after installation, .gmo in source tree +dnl 2) GNU gettext has been found in the system's C library. +dnl Catalog format: GNU --> install in $(datadir) +dnl Catalog extension: .mo after installation, .gmo in source tree +dnl 3) No internationalization, always use English msgid. +dnl Catalog format: none +dnl Catalog extension: none +dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur. +dnl The use of .gmo is historical (it was needed to avoid overwriting the +dnl GNU format catalogs when building on a platform with an X/Open gettext), +dnl but we keep it in order not to force irrelevant filename changes on the +dnl maintainers. +dnl +AC_DEFUN([AM_GNU_GETTEXT], +[ + dnl Argument checking. + ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], , + [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT +])])])])]) + ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], , + [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT +])])])]) + define(gt_included_intl, ifelse([$1], [external], [no], [yes])) + define(gt_libtool_suffix_prefix, ifelse([$1], [use-libtool], [l], [])) + + AC_REQUIRE([AM_PO_SUBDIRS])dnl + ifelse(gt_included_intl, yes, [ + AC_REQUIRE([AM_INTL_SUBDIR])dnl + ]) + + dnl Prerequisites of AC_LIB_LINKFLAGS_BODY. + AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) + AC_REQUIRE([AC_LIB_RPATH]) + + dnl Sometimes libintl requires libiconv, so first search for libiconv. + dnl Ideally we would do this search only after the + dnl if test "$USE_NLS" = "yes"; then + dnl if test "$gt_cv_func_gnugettext_libc" != "yes"; then + dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT + dnl the configure script would need to contain the same shell code + dnl again, outside any 'if'. There are two solutions: + dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'. + dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE. + dnl Since AC_PROVIDE_IFELSE is only in autoconf >= 2.52 and not + dnl documented, we avoid it. + ifelse(gt_included_intl, yes, , [ + AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY]) + ]) + + dnl Set USE_NLS. + AM_NLS + + ifelse(gt_included_intl, yes, [ + BUILD_INCLUDED_LIBINTL=no + USE_INCLUDED_LIBINTL=no + ]) + LIBINTL= + LTLIBINTL= + POSUB= + + dnl If we use NLS figure out what method + if test "$USE_NLS" = "yes"; then + gt_use_preinstalled_gnugettext=no + ifelse(gt_included_intl, yes, [ + AC_MSG_CHECKING([whether included gettext is requested]) + AC_ARG_WITH(included-gettext, + [ --with-included-gettext use the GNU gettext library included here], + nls_cv_force_use_gnu_gettext=$withval, + nls_cv_force_use_gnu_gettext=no) + AC_MSG_RESULT($nls_cv_force_use_gnu_gettext) + + nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext" + if test "$nls_cv_force_use_gnu_gettext" != "yes"; then + ]) + dnl User does not insist on using GNU NLS library. Figure out what + dnl to use. If GNU gettext is available we use this. Else we have + dnl to fall back to GNU NLS library. + + dnl Add a version number to the cache macros. + define([gt_api_version], ifelse([$2], [need-formatstring-macros], 3, ifelse([$2], [need-ngettext], 2, 1))) + define([gt_cv_func_gnugettext_libc], [gt_cv_func_gnugettext]gt_api_version[_libc]) + define([gt_cv_func_gnugettext_libintl], [gt_cv_func_gnugettext]gt_api_version[_libintl]) + + AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc, + [AC_TRY_LINK([#include <libintl.h> +]ifelse([$2], [need-formatstring-macros], +[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION +#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) +#endif +changequote(,)dnl +typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; +changequote([,])dnl +], [])[extern int _nl_msg_cat_cntr; +extern int *_nl_domain_bindings;], + [bindtextdomain ("", ""); +return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_domain_bindings], + gt_cv_func_gnugettext_libc=yes, + gt_cv_func_gnugettext_libc=no)]) + + if test "$gt_cv_func_gnugettext_libc" != "yes"; then + dnl Sometimes libintl requires libiconv, so first search for libiconv. + ifelse(gt_included_intl, yes, , [ + AM_ICONV_LINK + ]) + dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL + dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv]) + dnl because that would add "-liconv" to LIBINTL and LTLIBINTL + dnl even if libiconv doesn't exist. + AC_LIB_LINKFLAGS_BODY([intl]) + AC_CACHE_CHECK([for GNU gettext in libintl], + gt_cv_func_gnugettext_libintl, + [gt_save_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $INCINTL" + gt_save_LIBS="$LIBS" + LIBS="$LIBS $LIBINTL" + dnl Now see whether libintl exists and does not depend on libiconv. + AC_TRY_LINK([#include <libintl.h> +]ifelse([$2], [need-formatstring-macros], +[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION +#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) +#endif +changequote(,)dnl +typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; +changequote([,])dnl +], [])[extern int _nl_msg_cat_cntr; +extern +#ifdef __cplusplus +"C" +#endif +const char *_nl_expand_alias ();], + [bindtextdomain ("", ""); +return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias (0)], + gt_cv_func_gnugettext_libintl=yes, + gt_cv_func_gnugettext_libintl=no) + dnl Now see whether libintl exists and depends on libiconv. + if test "$gt_cv_func_gnugettext_libintl" != yes && test -n "$LIBICONV"; then + LIBS="$LIBS $LIBICONV" + AC_TRY_LINK([#include <libintl.h> +]ifelse([$2], [need-formatstring-macros], +[#ifndef __GNU_GETTEXT_SUPPORTED_REVISION +#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) +#endif +changequote(,)dnl +typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; +changequote([,])dnl +], [])[extern int _nl_msg_cat_cntr; +extern +#ifdef __cplusplus +"C" +#endif +const char *_nl_expand_alias ();], + [bindtextdomain ("", ""); +return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext ("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias (0)], + [LIBINTL="$LIBINTL $LIBICONV" + LTLIBINTL="$LTLIBINTL $LTLIBICONV" + gt_cv_func_gnugettext_libintl=yes + ]) + fi + CPPFLAGS="$gt_save_CPPFLAGS" + LIBS="$gt_save_LIBS"]) + fi + + dnl If an already present or preinstalled GNU gettext() is found, + dnl use it. But if this macro is used in GNU gettext, and GNU + dnl gettext is already preinstalled in libintl, we update this + dnl libintl. (Cf. the install rule in intl/Makefile.in.) + if test "$gt_cv_func_gnugettext_libc" = "yes" \ + || { test "$gt_cv_func_gnugettext_libintl" = "yes" \ + && test "$PACKAGE" != gettext-runtime \ + && test "$PACKAGE" != gettext-tools; }; then + gt_use_preinstalled_gnugettext=yes + else + dnl Reset the values set by searching for libintl. + LIBINTL= + LTLIBINTL= + INCINTL= + fi + + ifelse(gt_included_intl, yes, [ + if test "$gt_use_preinstalled_gnugettext" != "yes"; then + dnl GNU gettext is not found in the C library. + dnl Fall back on included GNU gettext library. + nls_cv_use_gnu_gettext=yes + fi + fi + + if test "$nls_cv_use_gnu_gettext" = "yes"; then + dnl Mark actions used to generate GNU NLS library. + BUILD_INCLUDED_LIBINTL=yes + USE_INCLUDED_LIBINTL=yes + LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV" + LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV" + LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'` + fi + + if test "$gt_use_preinstalled_gnugettext" = "yes" \ + || test "$nls_cv_use_gnu_gettext" = "yes"; then + dnl Mark actions to use GNU gettext tools. + CATOBJEXT=.gmo + fi + ]) + + if test "$gt_use_preinstalled_gnugettext" = "yes" \ + || test "$nls_cv_use_gnu_gettext" = "yes"; then + AC_DEFINE(ENABLE_NLS, 1, + [Define to 1 if translation of program messages to the user's native language + is requested.]) + else + USE_NLS=no + fi + fi + + AC_MSG_CHECKING([whether to use NLS]) + AC_MSG_RESULT([$USE_NLS]) + if test "$USE_NLS" = "yes"; then + AC_MSG_CHECKING([where the gettext function comes from]) + if test "$gt_use_preinstalled_gnugettext" = "yes"; then + if test "$gt_cv_func_gnugettext_libintl" = "yes"; then + gt_source="external libintl" + else + gt_source="libc" + fi + else + gt_source="included intl directory" + fi + AC_MSG_RESULT([$gt_source]) + fi + + if test "$USE_NLS" = "yes"; then + + if test "$gt_use_preinstalled_gnugettext" = "yes"; then + if test "$gt_cv_func_gnugettext_libintl" = "yes"; then + AC_MSG_CHECKING([how to link with libintl]) + AC_MSG_RESULT([$LIBINTL]) + AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL]) + fi + + dnl For backward compatibility. Some packages may be using this. + AC_DEFINE(HAVE_GETTEXT, 1, + [Define if the GNU gettext() function is already present or preinstalled.]) + AC_DEFINE(HAVE_DCGETTEXT, 1, + [Define if the GNU dcgettext() function is already present or preinstalled.]) + fi + + dnl We need to process the po/ directory. + POSUB=po + fi + + ifelse(gt_included_intl, yes, [ + dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL + dnl to 'yes' because some of the testsuite requires it. + if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then + BUILD_INCLUDED_LIBINTL=yes + fi + + dnl Make all variables we use known to autoconf. + AC_SUBST(BUILD_INCLUDED_LIBINTL) + AC_SUBST(USE_INCLUDED_LIBINTL) + AC_SUBST(CATOBJEXT) + + dnl For backward compatibility. Some configure.ins may be using this. + nls_cv_header_intl= + nls_cv_header_libgt= + + dnl For backward compatibility. Some Makefiles may be using this. + DATADIRNAME=share + AC_SUBST(DATADIRNAME) + + dnl For backward compatibility. Some Makefiles may be using this. + INSTOBJEXT=.mo + AC_SUBST(INSTOBJEXT) + + dnl For backward compatibility. Some Makefiles may be using this. + GENCAT=gencat + AC_SUBST(GENCAT) + + dnl For backward compatibility. Some Makefiles may be using this. + if test "$USE_INCLUDED_LIBINTL" = yes; then + INTLOBJS="\$(GETTOBJS)" + fi + AC_SUBST(INTLOBJS) + + dnl Enable libtool support if the surrounding package wishes it. + INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix + AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX) + ]) + + dnl For backward compatibility. Some Makefiles may be using this. + INTLLIBS="$LIBINTL" + AC_SUBST(INTLLIBS) + + dnl Make all documented variables known to autoconf. + AC_SUBST(LIBINTL) + AC_SUBST(LTLIBINTL) + AC_SUBST(POSUB) +]) + + +dnl Checks for all prerequisites of the intl subdirectory, +dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS, +dnl USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL. +AC_DEFUN([AM_INTL_SUBDIR], +[ + AC_REQUIRE([AC_PROG_INSTALL])dnl + AC_REQUIRE([AM_MKINSTALLDIRS])dnl + AC_REQUIRE([AC_PROG_CC])dnl + AC_REQUIRE([AC_CANONICAL_HOST])dnl + AC_REQUIRE([AC_PROG_RANLIB])dnl + AC_REQUIRE([AC_ISC_POSIX])dnl + AC_REQUIRE([AC_HEADER_STDC])dnl + AC_REQUIRE([AC_C_CONST])dnl + AC_REQUIRE([AC_C_INLINE])dnl + AC_REQUIRE([AC_TYPE_OFF_T])dnl + AC_REQUIRE([AC_TYPE_SIZE_T])dnl + AC_REQUIRE([AC_FUNC_ALLOCA])dnl + AC_REQUIRE([AC_FUNC_MMAP])dnl + AC_REQUIRE([jm_GLIBC21])dnl + AC_REQUIRE([gt_INTDIV0])dnl + AC_REQUIRE([jm_AC_TYPE_UINTMAX_T])dnl + AC_REQUIRE([gt_HEADER_INTTYPES_H])dnl + AC_REQUIRE([gt_INTTYPES_PRI])dnl + + AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \ +stdlib.h string.h unistd.h sys/param.h]) + AC_CHECK_FUNCS([feof_unlocked fgets_unlocked getc_unlocked getcwd getegid \ +geteuid getgid getuid mempcpy munmap putenv setenv setlocale stpcpy \ +strcasecmp strdup strtoul tsearch __argz_count __argz_stringify __argz_next \ +__fsetlocking]) + + AM_ICONV + AM_LANGINFO_CODESET + if test $ac_cv_header_locale_h = yes; then + AM_LC_MESSAGES + fi + + dnl intl/plural.c is generated from intl/plural.y. It requires bison, + dnl because plural.y uses bison specific features. It requires at least + dnl bison-1.26 because earlier versions generate a plural.c that doesn't + dnl compile. + dnl bison is only needed for the maintainer (who touches plural.y). But in + dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put + dnl the rule in general Makefile. Now, some people carelessly touch the + dnl files or have a broken "make" program, hence the plural.c rule will + dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not + dnl present or too old. + AC_CHECK_PROGS([INTLBISON], [bison]) + if test -z "$INTLBISON"; then + ac_verc_fail=yes + else + dnl Found it, now check the version. + AC_MSG_CHECKING([version of bison]) +changequote(<<,>>)dnl + ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'` + case $ac_prog_version in + '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; + 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*) +changequote([,])dnl + ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; + *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;; + esac + AC_MSG_RESULT([$ac_prog_version]) + fi + if test $ac_verc_fail = yes; then + INTLBISON=: + fi +]) + + +dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version]) +AC_DEFUN([AM_GNU_GETTEXT_VERSION], []) +# glibc21.m4 serial 2 (fileutils-4.1.3, gettext-0.10.40) +dnl Copyright (C) 2000-2002 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +# Test for the GNU C Library, version 2.1 or newer. +# From Bruno Haible. + +AC_DEFUN([jm_GLIBC21], + [ + AC_CACHE_CHECK(whether we are using the GNU C Library 2.1 or newer, + ac_cv_gnu_library_2_1, + [AC_EGREP_CPP([Lucky GNU user], + [ +#include <features.h> +#ifdef __GNU_LIBRARY__ + #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2) + Lucky GNU user + #endif +#endif + ], + ac_cv_gnu_library_2_1=yes, + ac_cv_gnu_library_2_1=no) + ] + ) + AC_SUBST(GLIBC21) + GLIBC21="$ac_cv_gnu_library_2_1" + ] +) +# iconv.m4 serial AM4 (gettext-0.11.3) +dnl Copyright (C) 2000-2002 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl From Bruno Haible. + +AC_DEFUN([AM_ICONV_LINKFLAGS_BODY], +[ + dnl Prerequisites of AC_LIB_LINKFLAGS_BODY. + AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) + AC_REQUIRE([AC_LIB_RPATH]) + + dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV + dnl accordingly. + AC_LIB_LINKFLAGS_BODY([iconv]) +]) + +AC_DEFUN([AM_ICONV_LINK], +[ + dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and + dnl those with the standalone portable GNU libiconv installed). + + dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV + dnl accordingly. + AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY]) + + dnl Add $INCICONV to CPPFLAGS before performing the following checks, + dnl because if the user has installed libiconv and not disabled its use + dnl via --without-libiconv-prefix, he wants to use it. The first + dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed. + am_save_CPPFLAGS="$CPPFLAGS" + AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV]) + + AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [ + am_cv_func_iconv="no, consider installing GNU libiconv" + am_cv_lib_iconv=no + AC_TRY_LINK([#include <stdlib.h> +#include <iconv.h>], + [iconv_t cd = iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd);], + am_cv_func_iconv=yes) + if test "$am_cv_func_iconv" != yes; then + am_save_LIBS="$LIBS" + LIBS="$LIBS $LIBICONV" + AC_TRY_LINK([#include <stdlib.h> +#include <iconv.h>], + [iconv_t cd = iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd);], + am_cv_lib_iconv=yes + am_cv_func_iconv=yes) + LIBS="$am_save_LIBS" + fi + ]) + if test "$am_cv_func_iconv" = yes; then + AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.]) + fi + if test "$am_cv_lib_iconv" = yes; then + AC_MSG_CHECKING([how to link with libiconv]) + AC_MSG_RESULT([$LIBICONV]) + else + dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV + dnl either. + CPPFLAGS="$am_save_CPPFLAGS" + LIBICONV= + LTLIBICONV= + fi + AC_SUBST(LIBICONV) + AC_SUBST(LTLIBICONV) +]) + +AC_DEFUN([AM_ICONV], +[ + AM_ICONV_LINK + if test "$am_cv_func_iconv" = yes; then + AC_MSG_CHECKING([for iconv declaration]) + AC_CACHE_VAL(am_cv_proto_iconv, [ + AC_TRY_COMPILE([ +#include <stdlib.h> +#include <iconv.h> +extern +#ifdef __cplusplus +"C" +#endif +#if defined(__STDC__) || defined(__cplusplus) +size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); +#else +size_t iconv(); +#endif +], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const") + am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"]) + am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'` + AC_MSG_RESULT([$]{ac_t:- + }[$]am_cv_proto_iconv) + AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1, + [Define as const if the declaration of iconv() needs const.]) + fi +]) +# intdiv0.m4 serial 1 (gettext-0.11.3) +dnl Copyright (C) 2002 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl From Bruno Haible. + +AC_DEFUN([gt_INTDIV0], +[ + AC_REQUIRE([AC_PROG_CC])dnl + AC_REQUIRE([AC_CANONICAL_HOST])dnl + + AC_CACHE_CHECK([whether integer division by zero raises SIGFPE], + gt_cv_int_divbyzero_sigfpe, + [ + AC_TRY_RUN([ +#include <stdlib.h> +#include <signal.h> + +static void +#ifdef __cplusplus +sigfpe_handler (int sig) +#else +sigfpe_handler (sig) int sig; +#endif +{ + /* Exit with code 0 if SIGFPE, with code 1 if any other signal. */ + exit (sig != SIGFPE); +} + +int x = 1; +int y = 0; +int z; +int nan; + +int main () +{ + signal (SIGFPE, sigfpe_handler); +/* IRIX and AIX (when "xlc -qcheck" is used) yield signal SIGTRAP. */ +#if (defined (__sgi) || defined (_AIX)) && defined (SIGTRAP) + signal (SIGTRAP, sigfpe_handler); +#endif +/* Linux/SPARC yields signal SIGILL. */ +#if defined (__sparc__) && defined (__linux__) + signal (SIGILL, sigfpe_handler); +#endif + + z = x / y; + nan = y / y; + exit (1); +} +], gt_cv_int_divbyzero_sigfpe=yes, gt_cv_int_divbyzero_sigfpe=no, + [ + # Guess based on the CPU. + case "$host_cpu" in + alpha* | i[34567]86 | m68k | s390*) + gt_cv_int_divbyzero_sigfpe="guessing yes";; + *) + gt_cv_int_divbyzero_sigfpe="guessing no";; + esac + ]) + ]) + case "$gt_cv_int_divbyzero_sigfpe" in + *yes) value=1;; + *) value=0;; + esac + AC_DEFINE_UNQUOTED(INTDIV0_RAISES_SIGFPE, $value, + [Define if integer division by zero raises signal SIGFPE.]) +]) +# inttypes.m4 serial 1 (gettext-0.11.4) +dnl Copyright (C) 1997-2002 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl From Paul Eggert. + +# Define HAVE_INTTYPES_H if <inttypes.h> exists and doesn't clash with +# <sys/types.h>. + +AC_DEFUN([gt_HEADER_INTTYPES_H], +[ + AC_CACHE_CHECK([for inttypes.h], gt_cv_header_inttypes_h, + [ + AC_TRY_COMPILE( + [#include <sys/types.h> +#include <inttypes.h>], + [], gt_cv_header_inttypes_h=yes, gt_cv_header_inttypes_h=no) + ]) + if test $gt_cv_header_inttypes_h = yes; then + AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H, 1, + [Define if <inttypes.h> exists and doesn't clash with <sys/types.h>.]) + fi +]) +# inttypes_h.m4 serial 5 (gettext-0.12) +dnl Copyright (C) 1997-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl From Paul Eggert. + +# Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists, +# doesn't clash with <sys/types.h>, and declares uintmax_t. + +AC_DEFUN([jm_AC_HEADER_INTTYPES_H], +[ + AC_CACHE_CHECK([for inttypes.h], jm_ac_cv_header_inttypes_h, + [AC_TRY_COMPILE( + [#include <sys/types.h> +#include <inttypes.h>], + [uintmax_t i = (uintmax_t) -1;], + jm_ac_cv_header_inttypes_h=yes, + jm_ac_cv_header_inttypes_h=no)]) + if test $jm_ac_cv_header_inttypes_h = yes; then + AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H_WITH_UINTMAX, 1, + [Define if <inttypes.h> exists, doesn't clash with <sys/types.h>, + and declares uintmax_t. ]) + fi +]) +# inttypes-pri.m4 serial 1 (gettext-0.11.4) +dnl Copyright (C) 1997-2002 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl From Bruno Haible. + +# Define PRI_MACROS_BROKEN if <inttypes.h> exists and defines the PRI* +# macros to non-string values. This is the case on AIX 4.3.3. + +AC_DEFUN([gt_INTTYPES_PRI], +[ + AC_REQUIRE([gt_HEADER_INTTYPES_H]) + if test $gt_cv_header_inttypes_h = yes; then + AC_CACHE_CHECK([whether the inttypes.h PRIxNN macros are broken], + gt_cv_inttypes_pri_broken, + [ + AC_TRY_COMPILE([#include <inttypes.h> +#ifdef PRId32 +char *p = PRId32; +#endif +], [], gt_cv_inttypes_pri_broken=no, gt_cv_inttypes_pri_broken=yes) + ]) + fi + if test "$gt_cv_inttypes_pri_broken" = yes; then + AC_DEFINE_UNQUOTED(PRI_MACROS_BROKEN, 1, + [Define if <inttypes.h> exists and defines unusable PRI* macros.]) + fi +]) +# isc-posix.m4 serial 2 (gettext-0.11.2) +dnl Copyright (C) 1995-2002 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +# This file is not needed with autoconf-2.53 and newer. Remove it in 2005. + +# This test replaces the one in autoconf. +# Currently this macro should have the same name as the autoconf macro +# because gettext's gettext.m4 (distributed in the automake package) +# still uses it. Otherwise, the use in gettext.m4 makes autoheader +# give these diagnostics: +# configure.in:556: AC_TRY_COMPILE was called before AC_ISC_POSIX +# configure.in:556: AC_TRY_RUN was called before AC_ISC_POSIX + +undefine([AC_ISC_POSIX]) + +AC_DEFUN([AC_ISC_POSIX], + [ + dnl This test replaces the obsolescent AC_ISC_POSIX kludge. + AC_CHECK_LIB(cposix, strerror, [LIBS="$LIBS -lcposix"]) + ] +) +# lcmessage.m4 serial 3 (gettext-0.11.3) +dnl Copyright (C) 1995-2002 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +dnl Authors: +dnl Ulrich Drepper <drepper@cygnus.com>, 1995. + +# Check whether LC_MESSAGES is available in <locale.h>. + +AC_DEFUN([AM_LC_MESSAGES], +[ + AC_CACHE_CHECK([for LC_MESSAGES], am_cv_val_LC_MESSAGES, + [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES], + am_cv_val_LC_MESSAGES=yes, am_cv_val_LC_MESSAGES=no)]) + if test $am_cv_val_LC_MESSAGES = yes; then + AC_DEFINE(HAVE_LC_MESSAGES, 1, + [Define if your <locale.h> file defines LC_MESSAGES.]) + fi +]) +# lib-ld.m4 serial 2 (gettext-0.12) +dnl Copyright (C) 1996-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl Subroutines of libtool.m4, +dnl with replacements s/AC_/AC_LIB/ and s/lt_cv/acl_cv/ to avoid collision +dnl with libtool.m4. + +dnl From libtool-1.4. Sets the variable with_gnu_ld to yes or no. +AC_DEFUN([AC_LIB_PROG_LD_GNU], +[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], acl_cv_prog_gnu_ld, +[# I'd rather use --version here, but apparently some GNU ld's only accept -v. +if $LD -v 2>&1 </dev/null | egrep '(GNU|with BFD)' 1>&5; then + acl_cv_prog_gnu_ld=yes +else + acl_cv_prog_gnu_ld=no +fi]) +with_gnu_ld=$acl_cv_prog_gnu_ld +]) + +dnl From libtool-1.4. Sets the variable LD. +AC_DEFUN([AC_LIB_PROG_LD], +[AC_ARG_WITH(gnu-ld, +[ --with-gnu-ld assume the C compiler uses GNU ld [default=no]], +test "$withval" = no || with_gnu_ld=yes, with_gnu_ld=no) +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl +# Prepare PATH_SEPARATOR. +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi +ac_prog=ld +if test "$GCC" = yes; then + # Check if gcc -print-prog-name=ld gives a path. + AC_MSG_CHECKING([for ld used by GCC]) + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [[\\/]* | [A-Za-z]:[\\/]*)] + [re_direlt='/[^/][^/]*/\.\./'] + # Canonicalize the path of ld + ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'` + while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do + ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` + done + test -z "$LD" && LD="$ac_prog" + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test "$with_gnu_ld" = yes; then + AC_MSG_CHECKING([for GNU ld]) +else + AC_MSG_CHECKING([for non-GNU ld]) +fi +AC_CACHE_VAL(acl_cv_path_LD, +[if test -z "$LD"; then + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}" + for ac_dir in $PATH; do + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + acl_cv_path_LD="$ac_dir/$ac_prog" + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some GNU ld's only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + if "$acl_cv_path_LD" -v 2>&1 < /dev/null | egrep '(GNU|with BFD)' > /dev/null; then + test "$with_gnu_ld" != no && break + else + test "$with_gnu_ld" != yes && break + fi + fi + done + IFS="$ac_save_ifs" +else + acl_cv_path_LD="$LD" # Let the user override the test with a path. +fi]) +LD="$acl_cv_path_LD" +if test -n "$LD"; then + AC_MSG_RESULT($LD) +else + AC_MSG_RESULT(no) +fi +test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH]) +AC_LIB_PROG_LD_GNU +]) +# lib-link.m4 serial 4 (gettext-0.12) +dnl Copyright (C) 2001-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl From Bruno Haible. + +dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and +dnl the libraries corresponding to explicit and implicit dependencies. +dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and +dnl augments the CPPFLAGS variable. +AC_DEFUN([AC_LIB_LINKFLAGS], +[ + AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) + AC_REQUIRE([AC_LIB_RPATH]) + define([Name],[translit([$1],[./-], [___])]) + define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [ + AC_LIB_LINKFLAGS_BODY([$1], [$2]) + ac_cv_lib[]Name[]_libs="$LIB[]NAME" + ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME" + ac_cv_lib[]Name[]_cppflags="$INC[]NAME" + ]) + LIB[]NAME="$ac_cv_lib[]Name[]_libs" + LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs" + INC[]NAME="$ac_cv_lib[]Name[]_cppflags" + AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) + AC_SUBST([LIB]NAME) + AC_SUBST([LTLIB]NAME) + dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the + dnl results of this search when this library appears as a dependency. + HAVE_LIB[]NAME=yes + undefine([Name]) + undefine([NAME]) +]) + +dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode) +dnl searches for libname and the libraries corresponding to explicit and +dnl implicit dependencies, together with the specified include files and +dnl the ability to compile and link the specified testcode. If found, it +dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and +dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and +dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs +dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty. +AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], +[ + AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) + AC_REQUIRE([AC_LIB_RPATH]) + define([Name],[translit([$1],[./-], [___])]) + define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + + dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME + dnl accordingly. + AC_LIB_LINKFLAGS_BODY([$1], [$2]) + + dnl Add $INC[]NAME to CPPFLAGS before performing the following checks, + dnl because if the user has installed lib[]Name and not disabled its use + dnl via --without-lib[]Name-prefix, he wants to use it. + ac_save_CPPFLAGS="$CPPFLAGS" + AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) + + AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [ + ac_save_LIBS="$LIBS" + LIBS="$LIBS $LIB[]NAME" + AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no]) + LIBS="$ac_save_LIBS" + ]) + if test "$ac_cv_lib[]Name" = yes; then + HAVE_LIB[]NAME=yes + AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.]) + AC_MSG_CHECKING([how to link with lib[]$1]) + AC_MSG_RESULT([$LIB[]NAME]) + else + HAVE_LIB[]NAME=no + dnl If $LIB[]NAME didn't lead to a usable library, we don't need + dnl $INC[]NAME either. + CPPFLAGS="$ac_save_CPPFLAGS" + LIB[]NAME= + LTLIB[]NAME= + fi + AC_SUBST([HAVE_LIB]NAME) + AC_SUBST([LIB]NAME) + AC_SUBST([LTLIB]NAME) + undefine([Name]) + undefine([NAME]) +]) + +dnl Determine the platform dependent parameters needed to use rpath: +dnl libext, shlibext, hardcode_libdir_flag_spec, hardcode_libdir_separator, +dnl hardcode_direct, hardcode_minus_L. +AC_DEFUN([AC_LIB_RPATH], +[ + AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS + AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld + AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host + AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir + AC_CACHE_CHECK([for shared library run path origin], acl_cv_rpath, [ + CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \ + ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh + . ./conftest.sh + rm -f ./conftest.sh + acl_cv_rpath=done + ]) + wl="$acl_cv_wl" + libext="$acl_cv_libext" + shlibext="$acl_cv_shlibext" + hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" + hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" + hardcode_direct="$acl_cv_hardcode_direct" + hardcode_minus_L="$acl_cv_hardcode_minus_L" + dnl Determine whether the user wants rpath handling at all. + AC_ARG_ENABLE(rpath, + [ --disable-rpath do not hardcode runtime library paths], + :, enable_rpath=yes) +]) + +dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and +dnl the libraries corresponding to explicit and implicit dependencies. +dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables. +AC_DEFUN([AC_LIB_LINKFLAGS_BODY], +[ + define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + dnl By default, look in $includedir and $libdir. + use_additional=yes + AC_LIB_WITH_FINAL_PREFIX([ + eval additional_includedir=\"$includedir\" + eval additional_libdir=\"$libdir\" + ]) + AC_LIB_ARG_WITH([lib$1-prefix], +[ --with-lib$1-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib + --without-lib$1-prefix don't search for lib$1 in includedir and libdir], +[ + if test "X$withval" = "Xno"; then + use_additional=no + else + if test "X$withval" = "X"; then + AC_LIB_WITH_FINAL_PREFIX([ + eval additional_includedir=\"$includedir\" + eval additional_libdir=\"$libdir\" + ]) + else + additional_includedir="$withval/include" + additional_libdir="$withval/lib" + fi + fi +]) + dnl Search the library and its dependencies in $additional_libdir and + dnl $LDFLAGS. Using breadth-first-seach. + LIB[]NAME= + LTLIB[]NAME= + INC[]NAME= + rpathdirs= + ltrpathdirs= + names_already_handled= + names_next_round='$1 $2' + while test -n "$names_next_round"; do + names_this_round="$names_next_round" + names_next_round= + for name in $names_this_round; do + already_handled= + for n in $names_already_handled; do + if test "$n" = "$name"; then + already_handled=yes + break + fi + done + if test -z "$already_handled"; then + names_already_handled="$names_already_handled $name" + dnl See if it was already located by an earlier AC_LIB_LINKFLAGS + dnl or AC_LIB_HAVE_LINKFLAGS call. + uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'` + eval value=\"\$HAVE_LIB$uppername\" + if test -n "$value"; then + if test "$value" = yes; then + eval value=\"\$LIB$uppername\" + test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value" + eval value=\"\$LTLIB$uppername\" + test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value" + else + dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined + dnl that this library doesn't exist. So just drop it. + : + fi + else + dnl Search the library lib$name in $additional_libdir and $LDFLAGS + dnl and the already constructed $LIBNAME/$LTLIBNAME. + found_dir= + found_la= + found_so= + found_a= + if test $use_additional = yes; then + if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then + found_dir="$additional_libdir" + found_so="$additional_libdir/lib$name.$shlibext" + if test -f "$additional_libdir/lib$name.la"; then + found_la="$additional_libdir/lib$name.la" + fi + else + if test -f "$additional_libdir/lib$name.$libext"; then + found_dir="$additional_libdir" + found_a="$additional_libdir/lib$name.$libext" + if test -f "$additional_libdir/lib$name.la"; then + found_la="$additional_libdir/lib$name.la" + fi + fi + fi + fi + if test "X$found_dir" = "X"; then + for x in $LDFLAGS $LTLIB[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + case "$x" in + -L*) + dir=`echo "X$x" | sed -e 's/^X-L//'` + if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then + found_dir="$dir" + found_so="$dir/lib$name.$shlibext" + if test -f "$dir/lib$name.la"; then + found_la="$dir/lib$name.la" + fi + else + if test -f "$dir/lib$name.$libext"; then + found_dir="$dir" + found_a="$dir/lib$name.$libext" + if test -f "$dir/lib$name.la"; then + found_la="$dir/lib$name.la" + fi + fi + fi + ;; + esac + if test "X$found_dir" != "X"; then + break + fi + done + fi + if test "X$found_dir" != "X"; then + dnl Found the library. + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name" + if test "X$found_so" != "X"; then + dnl Linking with a shared library. We attempt to hardcode its + dnl directory into the executable's runpath, unless it's the + dnl standard /usr/lib. + if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; then + dnl No hardcoding is needed. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" + else + dnl Use an explicit option to hardcode DIR into the resulting + dnl binary. + dnl Potentially add DIR to ltrpathdirs. + dnl The ltrpathdirs will be appended to $LTLIBNAME at the end. + haveit= + for x in $ltrpathdirs; do + if test "X$x" = "X$found_dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + ltrpathdirs="$ltrpathdirs $found_dir" + fi + dnl The hardcoding into $LIBNAME is system dependent. + if test "$hardcode_direct" = yes; then + dnl Using DIR/libNAME.so during linking hardcodes DIR into the + dnl resulting binary. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" + else + if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then + dnl Use an explicit option to hardcode DIR into the resulting + dnl binary. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" + dnl Potentially add DIR to rpathdirs. + dnl The rpathdirs will be appended to $LIBNAME at the end. + haveit= + for x in $rpathdirs; do + if test "X$x" = "X$found_dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + rpathdirs="$rpathdirs $found_dir" + fi + else + dnl Rely on "-L$found_dir". + dnl But don't add it if it's already contained in the LDFLAGS + dnl or the already constructed $LIBNAME + haveit= + for x in $LDFLAGS $LIB[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-L$found_dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir" + fi + if test "$hardcode_minus_L" != no; then + dnl FIXME: Not sure whether we should use + dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" + dnl here. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" + else + dnl We cannot use $hardcode_runpath_var and LD_RUN_PATH + dnl here, because this doesn't fit in flags passed to the + dnl compiler. So give up. No hardcoding. This affects only + dnl very old systems. + dnl FIXME: Not sure whether we should use + dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" + dnl here. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" + fi + fi + fi + fi + else + if test "X$found_a" != "X"; then + dnl Linking with a static library. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a" + else + dnl We shouldn't come here, but anyway it's good to have a + dnl fallback. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name" + fi + fi + dnl Assume the include files are nearby. + additional_includedir= + case "$found_dir" in + */lib | */lib/) + basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'` + additional_includedir="$basedir/include" + ;; + esac + if test "X$additional_includedir" != "X"; then + dnl Potentially add $additional_includedir to $INCNAME. + dnl But don't add it + dnl 1. if it's the standard /usr/include, + dnl 2. if it's /usr/local/include and we are using GCC on Linux, + dnl 3. if it's already present in $CPPFLAGS or the already + dnl constructed $INCNAME, + dnl 4. if it doesn't exist as a directory. + if test "X$additional_includedir" != "X/usr/include"; then + haveit= + if test "X$additional_includedir" = "X/usr/local/include"; then + if test -n "$GCC"; then + case $host_os in + linux*) haveit=yes;; + esac + fi + fi + if test -z "$haveit"; then + for x in $CPPFLAGS $INC[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-I$additional_includedir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test -d "$additional_includedir"; then + dnl Really add $additional_includedir to $INCNAME. + INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir" + fi + fi + fi + fi + fi + dnl Look for dependencies. + if test -n "$found_la"; then + dnl Read the .la file. It defines the variables + dnl dlname, library_names, old_library, dependency_libs, current, + dnl age, revision, installed, dlopen, dlpreopen, libdir. + save_libdir="$libdir" + case "$found_la" in + */* | *\\*) . "$found_la" ;; + *) . "./$found_la" ;; + esac + libdir="$save_libdir" + dnl We use only dependency_libs. + for dep in $dependency_libs; do + case "$dep" in + -L*) + additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'` + dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME. + dnl But don't add it + dnl 1. if it's the standard /usr/lib, + dnl 2. if it's /usr/local/lib and we are using GCC on Linux, + dnl 3. if it's already present in $LDFLAGS or the already + dnl constructed $LIBNAME, + dnl 4. if it doesn't exist as a directory. + if test "X$additional_libdir" != "X/usr/lib"; then + haveit= + if test "X$additional_libdir" = "X/usr/local/lib"; then + if test -n "$GCC"; then + case $host_os in + linux*) haveit=yes;; + esac + fi + fi + if test -z "$haveit"; then + haveit= + for x in $LDFLAGS $LIB[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-L$additional_libdir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test -d "$additional_libdir"; then + dnl Really add $additional_libdir to $LIBNAME. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir" + fi + fi + haveit= + for x in $LDFLAGS $LTLIB[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-L$additional_libdir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test -d "$additional_libdir"; then + dnl Really add $additional_libdir to $LTLIBNAME. + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir" + fi + fi + fi + fi + ;; + -R*) + dir=`echo "X$dep" | sed -e 's/^X-R//'` + if test "$enable_rpath" != no; then + dnl Potentially add DIR to rpathdirs. + dnl The rpathdirs will be appended to $LIBNAME at the end. + haveit= + for x in $rpathdirs; do + if test "X$x" = "X$dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + rpathdirs="$rpathdirs $dir" + fi + dnl Potentially add DIR to ltrpathdirs. + dnl The ltrpathdirs will be appended to $LTLIBNAME at the end. + haveit= + for x in $ltrpathdirs; do + if test "X$x" = "X$dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + ltrpathdirs="$ltrpathdirs $dir" + fi + fi + ;; + -l*) + dnl Handle this in the next round. + names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'` + ;; + *.la) + dnl Handle this in the next round. Throw away the .la's + dnl directory; it is already contained in a preceding -L + dnl option. + names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'` + ;; + *) + dnl Most likely an immediate library name. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep" + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep" + ;; + esac + done + fi + else + dnl Didn't find the library; assume it is in the system directories + dnl known to the linker and runtime loader. (All the system + dnl directories known to the linker should also be known to the + dnl runtime loader, otherwise the system is severely misconfigured.) + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name" + fi + fi + fi + done + done + if test "X$rpathdirs" != "X"; then + if test -n "$hardcode_libdir_separator"; then + dnl Weird platform: only the last -rpath option counts, the user must + dnl pass all path elements in one option. We can arrange that for a + dnl single library, but not when more than one $LIBNAMEs are used. + alldirs= + for found_dir in $rpathdirs; do + alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir" + done + dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl. + acl_save_libdir="$libdir" + libdir="$alldirs" + eval flag=\"$hardcode_libdir_flag_spec\" + libdir="$acl_save_libdir" + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" + else + dnl The -rpath options are cumulative. + for found_dir in $rpathdirs; do + acl_save_libdir="$libdir" + libdir="$found_dir" + eval flag=\"$hardcode_libdir_flag_spec\" + libdir="$acl_save_libdir" + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" + done + fi + fi + if test "X$ltrpathdirs" != "X"; then + dnl When using libtool, the option that works for both libraries and + dnl executables is -R. The -R options are cumulative. + for found_dir in $ltrpathdirs; do + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir" + done + fi +]) + +dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR, +dnl unless already present in VAR. +dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes +dnl contains two or three consecutive elements that belong together. +AC_DEFUN([AC_LIB_APPENDTOVAR], +[ + for element in [$2]; do + haveit= + for x in $[$1]; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X$element"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + [$1]="${[$1]}${[$1]:+ }$element" + fi + done +]) +# lib-prefix.m4 serial 2 (gettext-0.12) +dnl Copyright (C) 2001-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl From Bruno Haible. + +dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and +dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't +dnl require excessive bracketing. +ifdef([AC_HELP_STRING], +[AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])], +[AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])]) + +dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed +dnl to access previously installed libraries. The basic assumption is that +dnl a user will want packages to use other packages he previously installed +dnl with the same --prefix option. +dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate +dnl libraries, but is otherwise very convenient. +AC_DEFUN([AC_LIB_PREFIX], +[ + AC_BEFORE([$0], [AC_LIB_LINKFLAGS]) + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) + dnl By default, look in $includedir and $libdir. + use_additional=yes + AC_LIB_WITH_FINAL_PREFIX([ + eval additional_includedir=\"$includedir\" + eval additional_libdir=\"$libdir\" + ]) + AC_LIB_ARG_WITH([lib-prefix], +[ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib + --without-lib-prefix don't search for libraries in includedir and libdir], +[ + if test "X$withval" = "Xno"; then + use_additional=no + else + if test "X$withval" = "X"; then + AC_LIB_WITH_FINAL_PREFIX([ + eval additional_includedir=\"$includedir\" + eval additional_libdir=\"$libdir\" + ]) + else + additional_includedir="$withval/include" + additional_libdir="$withval/lib" + fi + fi +]) + if test $use_additional = yes; then + dnl Potentially add $additional_includedir to $CPPFLAGS. + dnl But don't add it + dnl 1. if it's the standard /usr/include, + dnl 2. if it's already present in $CPPFLAGS, + dnl 3. if it's /usr/local/include and we are using GCC on Linux, + dnl 4. if it doesn't exist as a directory. + if test "X$additional_includedir" != "X/usr/include"; then + haveit= + for x in $CPPFLAGS; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-I$additional_includedir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test "X$additional_includedir" = "X/usr/local/include"; then + if test -n "$GCC"; then + case $host_os in + linux*) haveit=yes;; + esac + fi + fi + if test -z "$haveit"; then + if test -d "$additional_includedir"; then + dnl Really add $additional_includedir to $CPPFLAGS. + CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir" + fi + fi + fi + fi + dnl Potentially add $additional_libdir to $LDFLAGS. + dnl But don't add it + dnl 1. if it's the standard /usr/lib, + dnl 2. if it's already present in $LDFLAGS, + dnl 3. if it's /usr/local/lib and we are using GCC on Linux, + dnl 4. if it doesn't exist as a directory. + if test "X$additional_libdir" != "X/usr/lib"; then + haveit= + for x in $LDFLAGS; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-L$additional_libdir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test "X$additional_libdir" = "X/usr/local/lib"; then + if test -n "$GCC"; then + case $host_os in + linux*) haveit=yes;; + esac + fi + fi + if test -z "$haveit"; then + if test -d "$additional_libdir"; then + dnl Really add $additional_libdir to $LDFLAGS. + LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir" + fi + fi + fi + fi + fi +]) + +dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix, +dnl acl_final_exec_prefix, containing the values to which $prefix and +dnl $exec_prefix will expand at the end of the configure script. +AC_DEFUN([AC_LIB_PREPARE_PREFIX], +[ + dnl Unfortunately, prefix and exec_prefix get only finally determined + dnl at the end of configure. + if test "X$prefix" = "XNONE"; then + acl_final_prefix="$ac_default_prefix" + else + acl_final_prefix="$prefix" + fi + if test "X$exec_prefix" = "XNONE"; then + acl_final_exec_prefix='${prefix}' + else + acl_final_exec_prefix="$exec_prefix" + fi + acl_save_prefix="$prefix" + prefix="$acl_final_prefix" + eval acl_final_exec_prefix=\"$acl_final_exec_prefix\" + prefix="$acl_save_prefix" +]) + +dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the +dnl variables prefix and exec_prefix bound to the values they will have +dnl at the end of the configure script. +AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX], +[ + acl_save_prefix="$prefix" + prefix="$acl_final_prefix" + acl_save_exec_prefix="$exec_prefix" + exec_prefix="$acl_final_exec_prefix" + $1 + exec_prefix="$acl_save_exec_prefix" + prefix="$acl_save_prefix" +]) +# nls.m4 serial 1 (gettext-0.12) +dnl Copyright (C) 1995-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +dnl Authors: +dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000. +dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003. + +AC_DEFUN([AM_NLS], +[ + AC_MSG_CHECKING([whether NLS is requested]) + dnl Default is enabled NLS + AC_ARG_ENABLE(nls, + [ --disable-nls do not use Native Language Support], + USE_NLS=$enableval, USE_NLS=yes) + AC_MSG_RESULT($USE_NLS) + AC_SUBST(USE_NLS) +]) + +AC_DEFUN([AM_MKINSTALLDIRS], +[ + dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly + dnl find the mkinstalldirs script in another subdir but $(top_srcdir). + dnl Try to locate it. + MKINSTALLDIRS= + if test -n "$ac_aux_dir"; then + case "$ac_aux_dir" in + /*) MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs" ;; + *) MKINSTALLDIRS="\$(top_builddir)/$ac_aux_dir/mkinstalldirs" ;; + esac + fi + if test -z "$MKINSTALLDIRS"; then + MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs" + fi + AC_SUBST(MKINSTALLDIRS) +]) +# po.m4 serial 1 (gettext-0.12) +dnl Copyright (C) 1995-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +dnl Authors: +dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000. +dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003. + +dnl Checks for all prerequisites of the po subdirectory. +AC_DEFUN([AM_PO_SUBDIRS], +[ + AC_REQUIRE([AC_PROG_MAKE_SET])dnl + AC_REQUIRE([AC_PROG_INSTALL])dnl + AC_REQUIRE([AM_MKINSTALLDIRS])dnl + AC_REQUIRE([AM_NLS])dnl + + dnl Perform the following tests also if --disable-nls has been given, + dnl because they are needed for "make dist" to work. + + dnl Search for GNU msgfmt in the PATH. + dnl The first test excludes Solaris msgfmt and early GNU msgfmt versions. + dnl The second test excludes FreeBSD msgfmt. + AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt, + [$ac_dir/$ac_word --statistics /dev/null >/dev/null 2>&1 && + (if $ac_dir/$ac_word --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)], + :) + AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT) + + dnl Search for GNU xgettext 0.12 or newer in the PATH. + dnl The first test excludes Solaris xgettext and early GNU xgettext versions. + dnl The second test excludes FreeBSD xgettext. + AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext, + [$ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >/dev/null 2>&1 && + (if $ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)], + :) + dnl Remove leftover from FreeBSD xgettext call. + rm -f messages.po + + dnl Search for GNU msgmerge 0.11 or newer in the PATH. + AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge, + [$ac_dir/$ac_word --update -q /dev/null /dev/null >/dev/null 2>&1], :) + + dnl This could go away some day; the PATH_PROG_WITH_TEST already does it. + dnl Test whether we really found GNU msgfmt. + if test "$GMSGFMT" != ":"; then + dnl If it is no GNU msgfmt we define it as : so that the + dnl Makefiles still can work. + if $GMSGFMT --statistics /dev/null >/dev/null 2>&1 && + (if $GMSGFMT --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then + : ; + else + GMSGFMT=`echo "$GMSGFMT" | sed -e 's,^.*/,,'` + AC_MSG_RESULT( + [found $GMSGFMT program is not GNU msgfmt; ignore it]) + GMSGFMT=":" + fi + fi + + dnl This could go away some day; the PATH_PROG_WITH_TEST already does it. + dnl Test whether we really found GNU xgettext. + if test "$XGETTEXT" != ":"; then + dnl If it is no GNU xgettext we define it as : so that the + dnl Makefiles still can work. + if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >/dev/null 2>&1 && + (if $XGETTEXT --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then + : ; + else + AC_MSG_RESULT( + [found xgettext program is not GNU xgettext; ignore it]) + XGETTEXT=":" + fi + dnl Remove leftover from FreeBSD xgettext call. + rm -f messages.po + fi + + AC_OUTPUT_COMMANDS([ + for ac_file in $CONFIG_FILES; do + # Support "outfile[:infile[:infile...]]" + case "$ac_file" in + *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; + esac + # PO directories have a Makefile.in generated from Makefile.in.in. + case "$ac_file" in */Makefile.in) + # Adjust a relative srcdir. + ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'` + ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`" + ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'` + # In autoconf-2.13 it is called $ac_given_srcdir. + # In autoconf-2.50 it is called $srcdir. + test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir" + case "$ac_given_srcdir" in + .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;; + /*) top_srcdir="$ac_given_srcdir" ;; + *) top_srcdir="$ac_dots$ac_given_srcdir" ;; + esac + if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then + rm -f "$ac_dir/POTFILES" + test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES" + cat "$ac_given_srcdir/$ac_dir/POTFILES.in" | sed -e "/^#/d" -e "/^[ ]*\$/d" -e "s,.*, $top_srcdir/& \\\\," | sed -e "\$s/\(.*\) \\\\/\1/" > "$ac_dir/POTFILES" + POMAKEFILEDEPS="POTFILES.in" + # ALL_LINGUAS, POFILES, GMOFILES, UPDATEPOFILES, DUMMYPOFILES depend + # on $ac_dir but don't depend on user-specified configuration + # parameters. + if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then + # The LINGUAS file contains the set of available languages. + if test -n "$OBSOLETE_ALL_LINGUAS"; then + test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete" + fi + ALL_LINGUAS_=`sed -e "/^#/d" "$ac_given_srcdir/$ac_dir/LINGUAS"` + # Hide the ALL_LINGUAS assigment from automake. + eval 'ALL_LINGUAS''=$ALL_LINGUAS_' + POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS" + else + # The set of available languages was given in configure.in. + eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS' + fi + case "$ac_given_srcdir" in + .) srcdirpre= ;; + *) srcdirpre='$(srcdir)/' ;; + esac + POFILES= + GMOFILES= + UPDATEPOFILES= + DUMMYPOFILES= + for lang in $ALL_LINGUAS; do + POFILES="$POFILES $srcdirpre$lang.po" + GMOFILES="$GMOFILES $srcdirpre$lang.gmo" + UPDATEPOFILES="$UPDATEPOFILES $lang.po-update" + DUMMYPOFILES="$DUMMYPOFILES $lang.nop" + done + # CATALOGS depends on both $ac_dir and the user's LINGUAS + # environment variable. + INST_LINGUAS= + if test -n "$ALL_LINGUAS"; then + for presentlang in $ALL_LINGUAS; do + useit=no + if test "%UNSET%" != "$LINGUAS"; then + desiredlanguages="$LINGUAS" + else + desiredlanguages="$ALL_LINGUAS" + fi + for desiredlang in $desiredlanguages; do + # Use the presentlang catalog if desiredlang is + # a. equal to presentlang, or + # b. a variant of presentlang (because in this case, + # presentlang can be used as a fallback for messages + # which are not translated in the desiredlang catalog). + case "$desiredlang" in + "$presentlang"*) useit=yes;; + esac + done + if test $useit = yes; then + INST_LINGUAS="$INST_LINGUAS $presentlang" + fi + done + fi + CATALOGS= + if test -n "$INST_LINGUAS"; then + for lang in $INST_LINGUAS; do + CATALOGS="$CATALOGS $lang.gmo" + done + fi + test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile" + sed -e "/^POTFILES =/r $ac_dir/POTFILES" -e "/^# Makevars/r $ac_given_srcdir/$ac_dir/Makevars" -e "s|@POFILES@|$POFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@POMAKEFILEDEPS@|$POMAKEFILEDEPS|g" "$ac_dir/Makefile.in" > "$ac_dir/Makefile" + for f in "$ac_given_srcdir/$ac_dir"/Rules-*; do + if test -f "$f"; then + case "$f" in + *.orig | *.bak | *~) ;; + *) cat "$f" >> "$ac_dir/Makefile" ;; + esac + fi + done + fi + ;; + esac + done], + [# Capture the value of obsolete ALL_LINGUAS because we need it to compute + # POFILES, GMOFILES, UPDATEPOFILES, DUMMYPOFILES, CATALOGS. But hide it + # from automake. + eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"' + # Capture the value of LINGUAS because we need it to compute CATALOGS. + LINGUAS="${LINGUAS-%UNSET%}" + ]) +]) +# progtest.m4 serial 3 (gettext-0.12) +dnl Copyright (C) 1996-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. +dnl +dnl This file can can be used in projects which are not available under +dnl the GNU General Public License or the GNU Library General Public +dnl License but which still want to provide support for the GNU gettext +dnl functionality. +dnl Please note that the actual code of the GNU gettext library is covered +dnl by the GNU Library General Public License, and the rest of the GNU +dnl gettext package package is covered by the GNU General Public License. +dnl They are *not* in the public domain. + +dnl Authors: +dnl Ulrich Drepper <drepper@cygnus.com>, 1996. + +# Search path for a program which passes the given test. + +dnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR, +dnl TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]]) +AC_DEFUN([AM_PATH_PROG_WITH_TEST], +[ +# Prepare PATH_SEPARATOR. +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi + +# Find out how to test for executable files. Don't use a zero-byte file, +# as systems may use methods other than mode bits to determine executability. +cat >conf$$.file <<_ASEOF +#! /bin/sh +exit 0 +_ASEOF +chmod +x conf$$.file +if test -x conf$$.file >/dev/null 2>&1; then + ac_executable_p="test -x" +else + ac_executable_p="test -f" +fi +rm -f conf$$.file + +# Extract the first word of "$2", so it can be a program name with args. +set dummy $2; ac_word=[$]2 +AC_MSG_CHECKING([for $ac_word]) +AC_CACHE_VAL(ac_cv_path_$1, +[case "[$]$1" in + [[\\/]]* | ?:[[\\/]]*) + ac_cv_path_$1="[$]$1" # Let the user override the test with a path. + ;; + *) + ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in ifelse([$5], , $PATH, [$5]); do + IFS="$ac_save_IFS" + test -z "$ac_dir" && ac_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then + if [$3]; then + ac_cv_path_$1="$ac_dir/$ac_word$ac_exec_ext" + break 2 + fi + fi + done + done + IFS="$ac_save_IFS" +dnl If no 4th arg is given, leave the cache variable unset, +dnl so AC_PATH_PROGS will keep looking. +ifelse([$4], , , [ test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4" +])dnl + ;; +esac])dnl +$1="$ac_cv_path_$1" +if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then + AC_MSG_RESULT([$]$1) +else + AC_MSG_RESULT(no) +fi +AC_SUBST($1)dnl +]) +# stdint_h.m4 serial 3 (gettext-0.12) +dnl Copyright (C) 1997-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl From Paul Eggert. + +# Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists, +# doesn't clash with <sys/types.h>, and declares uintmax_t. + +AC_DEFUN([jm_AC_HEADER_STDINT_H], +[ + AC_CACHE_CHECK([for stdint.h], jm_ac_cv_header_stdint_h, + [AC_TRY_COMPILE( + [#include <sys/types.h> +#include <stdint.h>], + [uintmax_t i = (uintmax_t) -1;], + jm_ac_cv_header_stdint_h=yes, + jm_ac_cv_header_stdint_h=no)]) + if test $jm_ac_cv_header_stdint_h = yes; then + AC_DEFINE_UNQUOTED(HAVE_STDINT_H_WITH_UINTMAX, 1, + [Define if <stdint.h> exists, doesn't clash with <sys/types.h>, + and declares uintmax_t. ]) + fi +]) +# uintmax_t.m4 serial 7 (gettext-0.12) +dnl Copyright (C) 1997-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl From Paul Eggert. + +AC_PREREQ(2.13) + +# Define uintmax_t to 'unsigned long' or 'unsigned long long' +# if it is not already defined in <stdint.h> or <inttypes.h>. + +AC_DEFUN([jm_AC_TYPE_UINTMAX_T], +[ + AC_REQUIRE([jm_AC_HEADER_INTTYPES_H]) + AC_REQUIRE([jm_AC_HEADER_STDINT_H]) + if test $jm_ac_cv_header_inttypes_h = no && test $jm_ac_cv_header_stdint_h = no; then + AC_REQUIRE([jm_AC_TYPE_UNSIGNED_LONG_LONG]) + test $ac_cv_type_unsigned_long_long = yes \ + && ac_type='unsigned long long' \ + || ac_type='unsigned long' + AC_DEFINE_UNQUOTED(uintmax_t, $ac_type, + [Define to unsigned long or unsigned long long + if <stdint.h> and <inttypes.h> don't define.]) + else + AC_DEFINE(HAVE_UINTMAX_T, 1, + [Define if you have the 'uintmax_t' type in <stdint.h> or <inttypes.h>.]) + fi +]) +# ulonglong.m4 serial 2 (fileutils-4.0.32, gettext-0.10.40) +dnl Copyright (C) 1999-2002 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl From Paul Eggert. + +AC_DEFUN([jm_AC_TYPE_UNSIGNED_LONG_LONG], +[ + AC_CACHE_CHECK([for unsigned long long], ac_cv_type_unsigned_long_long, + [AC_TRY_LINK([unsigned long long ull = 1; int i = 63;], + [unsigned long long ullmax = (unsigned long long) -1; + return ull << i | ull >> i | ullmax / ull | ullmax % ull;], + ac_cv_type_unsigned_long_long=yes, + ac_cv_type_unsigned_long_long=no)]) + if test $ac_cv_type_unsigned_long_long = yes; then + AC_DEFINE(HAVE_UNSIGNED_LONG_LONG, 1, + [Define if you have the unsigned long long type.]) + fi +]) diff --git a/readline/bind.c b/readline/bind.c index 71038881482..7559d32f6b3 100644 --- a/readline/bind.c +++ b/readline/bind.c @@ -1,6 +1,6 @@ /* bind.c -- key binding and startup file support for the readline library. */ -/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1987-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -19,8 +19,13 @@ 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 (__TANDEM) +# include <floss.h> +#endif + #if defined (HAVE_CONFIG_H) # include <config.h> #endif @@ -72,6 +77,9 @@ static char *_rl_read_file PARAMS((char *, size_t *)); static void _rl_init_file_error PARAMS((const char *)); static int _rl_read_init_file PARAMS((const char *, int)); static int glean_key_from_name PARAMS((char *)); +static int find_boolean_var PARAMS((const char *)); + +static char *_rl_get_string_variable_value PARAMS((const char *)); static int substring_member_of_array PARAMS((char *, const char **)); static int currently_reading_init_file; @@ -148,6 +156,34 @@ rl_bind_key_in_map (key, function, map) return (result); } +/* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. Right + now, this is always used to attempt to bind the arrow keys, hence the + check for rl_vi_movement_mode. */ +int +rl_bind_key_if_unbound_in_map (key, default_func, kmap) + int key; + rl_command_func_t *default_func; + Keymap kmap; +{ + char keyseq[2]; + + keyseq[0] = (unsigned char)key; + keyseq[1] = '\0'; + return (rl_bind_keyseq_if_unbound_in_map (keyseq, default_func, kmap)); +} + +int +rl_bind_key_if_unbound (key, default_func) + int key; + rl_command_func_t *default_func; +{ + char keyseq[2]; + + keyseq[0] = (unsigned char)key; + keyseq[1] = '\0'; + return (rl_bind_keyseq_if_unbound_in_map (keyseq, default_func, _rl_keymap)); +} + /* Make KEY do nothing in the currently selected keymap. Returns non-zero in case of error. */ int @@ -200,9 +236,30 @@ rl_unbind_command_in_map (command, map) } /* Bind the key sequence represented by the string KEYSEQ to + FUNCTION, starting in the current keymap. This makes new + keymaps as necessary. */ +int +rl_bind_keyseq (keyseq, function) + const char *keyseq; + rl_command_func_t *function; +{ + return (rl_generic_bind (ISFUNC, keyseq, (char *)function, _rl_keymap)); +} + +/* Bind the key sequence represented by the string KEYSEQ to FUNCTION. This makes new keymaps as necessary. The initial place to do bindings is in MAP. */ int +rl_bind_keyseq_in_map (keyseq, function, map) + const char *keyseq; + rl_command_func_t *function; + Keymap map; +{ + return (rl_generic_bind (ISFUNC, keyseq, (char *)function, map)); +} + +/* Backwards compatibility; equivalent to rl_bind_keyseq_in_map() */ +int rl_set_key (keyseq, function, map) const char *keyseq; rl_command_func_t *function; @@ -211,6 +268,40 @@ rl_set_key (keyseq, function, map) return (rl_generic_bind (ISFUNC, keyseq, (char *)function, map)); } +/* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. Right + now, this is always used to attempt to bind the arrow keys, hence the + check for rl_vi_movement_mode. */ +int +rl_bind_keyseq_if_unbound_in_map (keyseq, default_func, kmap) + const char *keyseq; + rl_command_func_t *default_func; + Keymap kmap; +{ + rl_command_func_t *func; + + if (keyseq) + { + func = rl_function_of_keyseq (keyseq, kmap, (int *)NULL); +#if defined (VI_MODE) + if (!func || func == rl_do_lowercase_version || func == rl_vi_movement_mode) +#else + if (!func || func == rl_do_lowercase_version) +#endif + return (rl_bind_keyseq_in_map (keyseq, default_func, kmap)); + else + return 1; + } + return 0; +} + +int +rl_bind_keyseq_if_unbound (keyseq, default_func) + const char *keyseq; + rl_command_func_t *default_func; +{ + return (rl_bind_keyseq_if_unbound_in_map (keyseq, default_func, _rl_keymap)); +} + /* Bind the key sequence represented by the string KEYSEQ to the string of characters MACRO. This makes new keymaps as necessary. The initial place to do bindings is in MAP. */ @@ -253,7 +344,7 @@ rl_generic_bind (type, keyseq, data, map) k.function = 0; /* If no keys to bind to, exit right away. */ - if (!keyseq || !*keyseq) + if (keyseq == 0 || *keyseq == 0) { if (type == ISMACR) free (data); @@ -281,7 +372,7 @@ rl_generic_bind (type, keyseq, data, map) if (ic < 0 || ic >= KEYMAP_SIZE) return -1; - if (_rl_convert_meta_chars_to_ascii && META_CHAR (ic)) + if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii) { ic = UNMETA (ic); if (map[ESC].type == ISKMAP) @@ -372,7 +463,14 @@ rl_translate_keyseq (seq, array, len) else if (c == 'M') { i++; - array[l++] = ESC; /* ESC is meta-prefix */ + /* XXX - should obey convert-meta setting? */ + if (_rl_convert_meta_chars_to_ascii && _rl_keymap[ESC].type == ISKMAP) + array[l++] = ESC; /* ESC is meta-prefix */ + else + { + i++; + array[l++] = META (seq[i]); + } } else if (c == 'C') { @@ -912,9 +1010,15 @@ parser_else (args) return 0; } +#if 0 /* Check the previous (n - 1) levels of the stack to make sure that we haven't previously turned off parsing. */ for (i = 0; i < if_stack_depth - 1; i++) +#else + /* Check the previous (n) levels of the stack to make sure that + we haven't previously turned off parsing. */ + for (i = 0; i < if_stack_depth; i++) +#endif if (if_stack[i] == 1) return 0; @@ -1091,9 +1195,9 @@ rl_parse_and_bind (string) /* If this is a command to set a variable, then do that. */ if (_rl_stricmp (string, "set") == 0) { - char *var = string + i; - char *value; + char *var, *value, *e; + var = string + i; /* Make VAR point to start of variable name. */ while (*var && whitespace (*var)) var++; @@ -1104,6 +1208,20 @@ rl_parse_and_bind (string) *value++ = '\0'; while (*value && whitespace (*value)) value++; + /* Strip trailing whitespace from values to boolean variables. Temp + fix until I get a real quoted-string parser here. */ + i = find_boolean_var (var); + if (i >= 0) + { + /* remove trailing whitespace */ + e = value + strlen (value) - 1; + while (e >= value && whitespace (*e)) + e--; + e++; /* skip back to whitespace or EOS */ + if (*e && e >= value) + *e = '\0'; + } + rl_variable_bind (var, value); return 0; } @@ -1124,8 +1242,9 @@ rl_parse_and_bind (string) the quoted string delimiter, like the shell. */ if (*funname == '\'' || *funname == '"') { - int delimiter = string[i++], passc; + int delimiter, passc; + delimiter = string[i++]; for (passc = 0; c = string[i]; i++) { if (passc) @@ -1161,7 +1280,7 @@ rl_parse_and_bind (string) } /* If this is a new-style key-binding, then do the binding with - rl_set_key (). Otherwise, let the older code deal with it. */ + rl_bind_keyseq (). Otherwise, let the older code deal with it. */ if (*string == '"') { char *seq; @@ -1200,7 +1319,7 @@ rl_parse_and_bind (string) rl_macro_bind (seq, &funname[1], _rl_keymap); } else - rl_set_key (seq, rl_named_function (funname), _rl_keymap); + rl_bind_keyseq (seq, rl_named_function (funname)); free (seq); return 0; @@ -1261,6 +1380,7 @@ static struct { int *value; int flags; } boolean_varlist [] = { + { "bind-tty-special-chars", &_rl_bind_stty_chars, 0 }, { "blink-matching-paren", &rl_blink_matching_paren, V_SPECIAL }, { "byte-oriented", &rl_byte_oriented, 0 }, { "completion-ignore-case", &_rl_completion_case_fold, 0 }, @@ -1281,6 +1401,7 @@ static struct { { "prefer-visible-bell", &_rl_prefer_visible_bell, V_SPECIAL }, { "print-completions-horizontally", &_rl_print_completions_horizontally, 0 }, { "show-all-if-ambiguous", &_rl_complete_show_all, 0 }, + { "show-all-if-unmodified", &_rl_complete_show_unmodified, 0 }, #if defined (VISIBLE_STATS) { "visible-stats", &rl_visible_stats, 0 }, #endif /* VISIBLE_STATS */ @@ -1373,13 +1494,34 @@ find_string_var (name) values result in 0 (false). */ static int bool_to_int (value) - char *value; + const char *value; { return (value == 0 || *value == '\0' || (_rl_stricmp (value, "on") == 0) || (value[0] == '1' && value[1] == '\0')); } +char * +rl_variable_value (name) + const char *name; +{ + register int i; + int v; + char *ret; + + /* Check for simple variables first. */ + i = find_boolean_var (name); + if (i >= 0) + return (*boolean_varlist[i].value ? "on" : "off"); + + i = find_string_var (name); + if (i >= 0) + return (_rl_get_string_variable_value (string_varlist[i].name)); + + /* Unknown variable names return NULL. */ + return 0; +} + int rl_variable_bind (name, value) const char *name, *value; @@ -1650,7 +1792,7 @@ rl_get_keymap_name_from_edit_mode () /* Each of the following functions produces information about the state of keybindings and functions known to Readline. The info is always printed to rl_outstream, and in such a way that it can - be read back in (i.e., passed to rl_parse_and_bind (). */ + be read back in (i.e., passed to rl_parse_and_bind ()). */ /* Print the names of functions known to Readline. */ void @@ -2022,12 +2164,68 @@ rl_dump_macros (count, key) return (0); } +static char * +_rl_get_string_variable_value (name) + const char *name; +{ + static char numbuf[32]; + char *ret; + int n; + + if (_rl_stricmp (name, "bell-style") == 0) + { + switch (_rl_bell_preference) + { + case NO_BELL: + return "none"; + case VISIBLE_BELL: + return "visible"; + case AUDIBLE_BELL: + default: + return "audible"; + } + } + else if (_rl_stricmp (name, "comment-begin") == 0) + return (_rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT); + else if (_rl_stricmp (name, "completion-query-items") == 0) + { + sprintf (numbuf, "%d", rl_completion_query_items); + return (numbuf); + } + else if (_rl_stricmp (name, "editing-mode") == 0) + return (rl_get_keymap_name_from_edit_mode ()); + else if (_rl_stricmp (name, "isearch-terminators") == 0) + { + if (_rl_isearch_terminators == 0) + return 0; + ret = _rl_untranslate_macro_value (_rl_isearch_terminators); + if (ret) + { + strncpy (numbuf, ret, sizeof (numbuf) - 1); + free (ret); + numbuf[sizeof(numbuf) - 1] = '\0'; + } + else + numbuf[0] = '\0'; + return numbuf; + } + else if (_rl_stricmp (name, "keymap") == 0) + { + ret = rl_get_keymap_name (_rl_keymap); + if (ret == 0) + ret = rl_get_keymap_name_from_edit_mode (); + return (ret ? ret : "none"); + } + else + return (0); +} + void rl_variable_dumper (print_readably) int print_readably; { int i; - const char *kname; + char *v; for (i = 0; boolean_varlist[i].name; i++) { @@ -2039,63 +2237,16 @@ rl_variable_dumper (print_readably) *boolean_varlist[i].value ? "on" : "off"); } - /* bell-style */ - switch (_rl_bell_preference) - { - case NO_BELL: - kname = "none"; break; - case VISIBLE_BELL: - kname = "visible"; break; - case AUDIBLE_BELL: - default: - kname = "audible"; break; - } - if (print_readably) - fprintf (rl_outstream, "set bell-style %s\n", kname); - else - fprintf (rl_outstream, "bell-style is set to `%s'\n", kname); - - /* comment-begin */ - if (print_readably) - fprintf (rl_outstream, "set comment-begin %s\n", _rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT); - else - fprintf (rl_outstream, "comment-begin is set to `%s'\n", _rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT); - - /* completion-query-items */ - if (print_readably) - fprintf (rl_outstream, "set completion-query-items %d\n", rl_completion_query_items); - else - fprintf (rl_outstream, "completion-query-items is set to `%d'\n", rl_completion_query_items); - - /* editing-mode */ - if (print_readably) - fprintf (rl_outstream, "set editing-mode %s\n", (rl_editing_mode == emacs_mode) ? "emacs" : "vi"); - else - fprintf (rl_outstream, "editing-mode is set to `%s'\n", (rl_editing_mode == emacs_mode) ? "emacs" : "vi"); - - /* isearch-terminators */ - if (_rl_isearch_terminators) + for (i = 0; string_varlist[i].name; i++) { - char *disp; - - disp = _rl_untranslate_macro_value (_rl_isearch_terminators); - + v = _rl_get_string_variable_value (string_varlist[i].name); + if (v == 0) /* _rl_isearch_terminators can be NULL */ + continue; if (print_readably) - fprintf (rl_outstream, "set isearch-terminators \"%s\"\n", disp); + fprintf (rl_outstream, "set %s %s\n", string_varlist[i].name, v); else - fprintf (rl_outstream, "isearch-terminators is set to \"%s\"\n", disp); - - free (disp); + fprintf (rl_outstream, "%s is set to `%s'\n", string_varlist[i].name, v); } - - /* keymap */ - kname = rl_get_keymap_name (_rl_keymap); - if (kname == 0) - kname = rl_get_keymap_name_from_edit_mode (); - if (print_readably) - fprintf (rl_outstream, "set keymap %s\n", kname ? kname : "none"); - else - fprintf (rl_outstream, "keymap is set to `%s'\n", kname ? kname : "none"); } /* Print all of the current variables and their values to @@ -2112,28 +2263,6 @@ rl_dump_variables (count, key) return (0); } -/* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. Right - now, this is always used to attempt to bind the arrow keys, hence the - check for rl_vi_movement_mode. */ -void -_rl_bind_if_unbound (keyseq, default_func) - const char *keyseq; - rl_command_func_t *default_func; -{ - rl_command_func_t *func; - - if (keyseq) - { - func = rl_function_of_keyseq (keyseq, _rl_keymap, (int *)NULL); -#if defined (VI_MODE) - if (!func || func == rl_do_lowercase_version || func == rl_vi_movement_mode) -#else - if (!func || func == rl_do_lowercase_version) -#endif - rl_set_key (keyseq, default_func, _rl_keymap); - } -} - /* Return non-zero if any members of ARRAY are a substring in STRING. */ static int substring_member_of_array (string, array) diff --git a/readline/callback.c b/readline/callback.c index a8f4323c929..9120969ca23 100644 --- a/readline/callback.c +++ b/readline/callback.c @@ -1,6 +1,6 @@ /* callback.c -- functions to use readline as an X `callback' mechanism. */ -/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1987-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -44,9 +44,14 @@ #include "readline.h" #include "rlprivate.h" +/* Private data for callback registration functions. See comments in + rl_callback_read_char for more details. */ +_rl_callback_func_t *_rl_callback_func = 0; +_rl_callback_generic_arg *_rl_callback_data = 0; + /* **************************************************************** */ /* */ -/* Callback Readline Functions */ +/* Callback Readline Functions */ /* */ /* **************************************************************** */ @@ -72,7 +77,8 @@ _rl_callback_newline () { in_handler = 1; - (*rl_prep_term_function) (_rl_meta_flag); + if (rl_prep_term_function) + (*rl_prep_term_function) (_rl_meta_flag); #if defined (HANDLE_SIGNALS) rl_set_signals (); @@ -89,6 +95,7 @@ rl_callback_handler_install (prompt, linefunc) rl_vcpfunc_t *linefunc; { rl_set_prompt (prompt); + RL_SETSTATE (RL_STATE_CALLBACK); rl_linefunc = linefunc; _rl_callback_newline (); } @@ -98,7 +105,8 @@ void rl_callback_read_char () { char *line; - int eof; + int eof, jcode; + static procenv_t olevel; if (rl_linefunc == NULL) { @@ -106,7 +114,79 @@ rl_callback_read_char () abort (); } - eof = readline_internal_char (); + memcpy ((void *)olevel, (void *)readline_top_level, sizeof (procenv_t)); + jcode = setjmp (readline_top_level); + if (jcode) + { + (*rl_redisplay_function) (); + _rl_want_redisplay = 0; + memcpy ((void *)readline_top_level, (void *)olevel, sizeof (procenv_t)); + return; + } + + if (RL_ISSTATE (RL_STATE_ISEARCH)) + { + eof = _rl_isearch_callback (_rl_iscxt); + if (eof == 0 && (RL_ISSTATE (RL_STATE_ISEARCH) == 0) && RL_ISSTATE (RL_STATE_INPUTPENDING)) + rl_callback_read_char (); + + return; + } + else if (RL_ISSTATE (RL_STATE_NSEARCH)) + { + eof = _rl_nsearch_callback (_rl_nscxt); + return; + } + else if (RL_ISSTATE (RL_STATE_NUMERICARG)) + { + eof = _rl_arg_callback (_rl_argcxt); + if (eof == 0 && (RL_ISSTATE (RL_STATE_NUMERICARG) == 0) && RL_ISSTATE (RL_STATE_INPUTPENDING)) + rl_callback_read_char (); + /* XXX - this should handle _rl_last_command_was_kill better */ + else if (RL_ISSTATE (RL_STATE_NUMERICARG) == 0) + _rl_internal_char_cleanup (); + + return; + } + else if (RL_ISSTATE (RL_STATE_MULTIKEY)) + { + eof = _rl_dispatch_callback (_rl_kscxt); /* For now */ + while ((eof == -1 || eof == -2) && RL_ISSTATE (RL_STATE_MULTIKEY) && _rl_kscxt && (_rl_kscxt->flags & KSEQ_DISPATCHED)) + eof = _rl_dispatch_callback (_rl_kscxt); + if (RL_ISSTATE (RL_STATE_MULTIKEY) == 0) + { + _rl_internal_char_cleanup (); + _rl_want_redisplay = 1; + } + } + else if (_rl_callback_func) + { + /* This allows functions that simply need to read an additional character + (like quoted-insert) to register a function to be called when input is + available. _rl_callback_data is simply a pointer to a struct that has + the argument count originally passed to the registering function and + space for any additional parameters. */ + eof = (*_rl_callback_func) (_rl_callback_data); + /* If the function `deregisters' itself, make sure the data is cleaned + up. */ + if (_rl_callback_func == 0) + { + if (_rl_callback_data) + { + _rl_callback_data_dispose (_rl_callback_data); + _rl_callback_data = 0; + } + _rl_internal_char_cleanup (); + } + } + else + eof = readline_internal_char (); + + if (rl_done == 0 && _rl_want_redisplay) + { + (*rl_redisplay_function) (); + _rl_want_redisplay = 0; + } /* We loop in case some function has pushed input back with rl_execute_next. */ for (;;) @@ -115,7 +195,8 @@ rl_callback_read_char () { line = readline_internal_teardown (eof); - (*rl_deprep_term_function) (); + if (rl_deprep_term_function) + (*rl_deprep_term_function) (); #if defined (HANDLE_SIGNALS) rl_clear_signals (); #endif @@ -131,10 +212,10 @@ rl_callback_read_char () if (in_handler == 0 && rl_linefunc) _rl_callback_newline (); } - if (rl_pending_input) + if (rl_pending_input || _rl_pushed_input_available () || RL_ISSTATE (RL_STATE_MACROINPUT)) eof = readline_internal_char (); else - break; + break; } } @@ -143,14 +224,37 @@ void rl_callback_handler_remove () { rl_linefunc = NULL; + RL_UNSETSTATE (RL_STATE_CALLBACK); if (in_handler) { in_handler = 0; - (*rl_deprep_term_function) (); + if (rl_deprep_term_function) + (*rl_deprep_term_function) (); #if defined (HANDLE_SIGNALS) rl_clear_signals (); #endif } } +_rl_callback_generic_arg * +_rl_callback_data_alloc (count) + int count; +{ + _rl_callback_generic_arg *arg; + + arg = (_rl_callback_generic_arg *)xmalloc (sizeof (_rl_callback_generic_arg)); + arg->count = count; + + arg->i1 = arg->i2 = 0; + + return arg; +} + +void _rl_callback_data_dispose (arg) + _rl_callback_generic_arg *arg; +{ + if (arg) + free (arg); +} + #endif diff --git a/readline/chardefs.h b/readline/chardefs.h index a537be220b0..def3a111bd3 100644 --- a/readline/chardefs.h +++ b/readline/chardefs.h @@ -77,11 +77,17 @@ # define isxdigit(c) (isdigit((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) #endif -#define NON_NEGATIVE(c) ((unsigned char)(c) == (c)) +#if defined (CTYPE_NON_ASCII) +# define NON_NEGATIVE(c) 1 +#else +# define NON_NEGATIVE(c) ((unsigned char)(c) == (c)) +#endif /* 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)) diff --git a/readline/complete.c b/readline/complete.c index a4ff24e8720..d93c15ae55d 100644 --- a/readline/complete.c +++ b/readline/complete.c @@ -1,6 +1,6 @@ /* complete.c -- filename completion for readline. */ -/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1987-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -28,7 +28,7 @@ #include <sys/types.h> #include <fcntl.h> #if defined (HAVE_SYS_FILE_H) -#include <sys/file.h> +# include <sys/file.h> #endif #if defined (HAVE_UNISTD_H) @@ -48,7 +48,7 @@ extern int errno; #endif /* !errno */ -#ifdef HAVE_PWD_H +#if defined (HAVE_PWD_H) #include <pwd.h> #endif @@ -81,10 +81,9 @@ typedef int QSFUNC (); /* Most systems don't declare getpwent in <pwd.h> if _POSIX_SOURCE is defined. */ -#if defined(HAVE_GETPWENT) && \ - (!defined (HAVE_GETPW_DECLS) || defined (_POSIX_SOURCE)) +#if defined (HAVE_GETPWENT) && (!defined (HAVE_GETPW_DECLS) || defined (_POSIX_SOURCE)) extern struct passwd *getpwent PARAMS((void)); -#endif /* defiend (HAVE_GETPWENT) && (!HAVE_GETPW_DECLS || _POSIX_SOURCE) */ +#endif /* HAVE_GETPWENT && (!HAVE_GETPW_DECLS || _POSIX_SOURCE) */ /* If non-zero, then this is the address of a function to call when completing a word would normally display the list of possible matches. @@ -102,12 +101,16 @@ rl_compdisp_func_t *rl_completion_display_matches_hook = (rl_compdisp_func_t *)N static int stat_char PARAMS((char *)); #endif +static int path_isdir PARAMS((const char *)); + static char *rl_quote_filename PARAMS((char *, int, char *)); static void set_completion_defaults PARAMS((int)); static int get_y_or_n PARAMS((int)); static int _rl_internal_pager PARAMS((int)); static char *printable_part PARAMS((char *)); +static int fnwidth PARAMS((const char *)); +static int fnprint PARAMS((const char *)); static int print_filename PARAMS((char *, char *)); static char **gen_completion_matches PARAMS((char *, int, int, rl_compentry_func_t *, int, int)); @@ -133,6 +136,10 @@ static char *make_quoted_replacement PARAMS((char *, int, char *)); /* If non-zero, non-unique completions always show the list of matches. */ int _rl_complete_show_all = 0; +/* If non-zero, non-unique completions show the list of matches, unless it + is not possible to do partial completion and modify the line. */ +int _rl_complete_show_unmodified = 0; + /* If non-zero, completed directory names have a slash appended. */ int _rl_complete_mark_directories = 1; @@ -201,7 +208,8 @@ int rl_completion_type = 0; /* Up to this many items will be displayed in response to a possible-completions call. After that, we ask the user if - she is sure she wants to see them all. */ + she is sure she wants to see them all. A negative value means + don't ask. */ int rl_completion_query_items = 100; int _rl_page_completions = 1; @@ -217,7 +225,12 @@ const char *rl_basic_quote_characters = "\"'"; /* The list of characters that signal a break between words for rl_complete_internal. The default list is the contents of rl_basic_word_break_characters. */ -const char *rl_completer_word_break_characters = (const char *)NULL; +/*const*/ char *rl_completer_word_break_characters = (/*const*/ char *)NULL; + +/* Hook function to allow an application to set the completion word + break characters before readline breaks up the line. Allows + position-dependent word break characters. */ +rl_cpvfunc_t *rl_completion_word_break_hook = (rl_cpvfunc_t *)NULL; /* List of characters which can be used to quote a substring of the line. Completion occurs on the entire substring, and within the substring @@ -285,6 +298,19 @@ int rl_completion_suppress_append = 0; default is a space. */ int rl_completion_append_character = ' '; +/* If non-zero, the completion functions don't append any closing quote. + This is set to 0 by rl_complete_internal and may be changed by an + application-specific completion function. */ +int rl_completion_suppress_quote = 0; + +/* Set to any quote character readline thinks it finds before any application + completion function is called. */ +int rl_completion_quote_character; + +/* Set to a non-zero value if readline found quoting anywhere in the word to + be completed; set before any application completion function is called. */ +int rl_completion_found_quote; + /* If non-zero, a slash will be appended to completed filenames that are symbolic links to directory names, subject to the value of the mark-directories variable (which is user-settable). This exists so @@ -323,6 +349,8 @@ rl_complete (ignore, invoking_key) return (rl_complete_internal ('?')); else if (_rl_complete_show_all) return (rl_complete_internal ('!')); + else if (_rl_complete_show_unmodified) + return (rl_complete_internal ('@')); else return (rl_complete_internal (TAB)); } @@ -355,6 +383,8 @@ rl_completion_mode (cfunc) return '?'; else if (_rl_complete_show_all) return '!'; + else if (_rl_complete_show_unmodified) + return '@'; else return TAB; } @@ -375,7 +405,7 @@ set_completion_defaults (what_to_do) rl_filename_completion_desired = 0; rl_filename_quoting_desired = 1; rl_completion_type = what_to_do; - rl_completion_suppress_append = 0; + rl_completion_suppress_append = rl_completion_suppress_quote = 0; /* The completion entry function may optionally change this. */ rl_completion_mark_symlink_dirs = _rl_complete_mark_symlink_dirs; @@ -426,6 +456,15 @@ _rl_internal_pager (lines) return 0; } +static int +path_isdir (filename) + const char *filename; +{ + struct stat finfo; + + return (stat (filename, &finfo) == 0 && S_ISDIR (finfo.st_mode)); +} + #if defined (VISIBLE_STATS) /* Return the character which best describes FILENAME. `@' for symbolic links @@ -523,53 +562,149 @@ printable_part (pathname) return ++temp; } +/* Compute width of STRING when displayed on screen by print_filename */ +static int +fnwidth (string) + const char *string; +{ + int width, pos; +#if defined (HANDLE_MULTIBYTE) + mbstate_t ps; + int left, w; + size_t clen; + wchar_t wc; + + left = strlen (string) + 1; + memset (&ps, 0, sizeof (mbstate_t)); +#endif + + width = pos = 0; + while (string[pos]) + { + if (CTRL_CHAR (*string) || *string == RUBOUT) + { + width += 2; + pos++; + } + else + { +#if defined (HANDLE_MULTIBYTE) + clen = mbrtowc (&wc, string + pos, left - pos, &ps); + if (MB_INVALIDCH (clen)) + { + width++; + pos++; + memset (&ps, 0, sizeof (mbstate_t)); + } + else if (MB_NULLWCH (clen)) + break; + else + { + pos += clen; + w = wcwidth (wc); + width += (w >= 0) ? w : 1; + } +#else + width++; + pos++; +#endif + } + } + + return width; +} + +static int +fnprint (to_print) + const char *to_print; +{ + int printed_len; + const char *s; +#if defined (HANDLE_MULTIBYTE) + mbstate_t ps; + const char *end; + size_t tlen; + int width, w; + wchar_t wc; + + end = to_print + strlen (to_print) + 1; + memset (&ps, 0, sizeof (mbstate_t)); +#endif + + printed_len = 0; + s = to_print; + while (*s) + { + if (CTRL_CHAR (*s)) + { + putc ('^', rl_outstream); + putc (UNCTRL (*s), rl_outstream); + printed_len += 2; + s++; +#if defined (HANDLE_MULTIBYTE) + memset (&ps, 0, sizeof (mbstate_t)); +#endif + } + else if (*s == RUBOUT) + { + putc ('^', rl_outstream); + putc ('?', rl_outstream); + printed_len += 2; + s++; +#if defined (HANDLE_MULTIBYTE) + memset (&ps, 0, sizeof (mbstate_t)); +#endif + } + else + { +#if defined (HANDLE_MULTIBYTE) + tlen = mbrtowc (&wc, s, end - s, &ps); + if (MB_INVALIDCH (tlen)) + { + tlen = 1; + width = 1; + memset (&ps, 0, sizeof (mbstate_t)); + } + else if (MB_NULLWCH (tlen)) + break; + else + { + w = wcwidth (wc); + width = (w >= 0) ? w : 1; + } + fwrite (s, 1, tlen, rl_outstream); + s += tlen; + printed_len += width; +#else + putc (*s, rl_outstream); + s++; + printed_len++; +#endif + } + } + + return printed_len; +} + /* Output TO_PRINT to rl_outstream. If VISIBLE_STATS is defined and we are using it, check for and output a single character for `special' filenames. Return the number of characters we output. */ -#define PUTX(c) \ - do { \ - if (CTRL_CHAR (c)) \ - { \ - putc ('^', rl_outstream); \ - putc (UNCTRL (c), rl_outstream); \ - printed_len += 2; \ - } \ - else if (c == RUBOUT) \ - { \ - putc ('^', rl_outstream); \ - putc ('?', rl_outstream); \ - printed_len += 2; \ - } \ - else \ - { \ - putc (c, rl_outstream); \ - printed_len++; \ - } \ - } while (0) - static int print_filename (to_print, full_pathname) char *to_print, *full_pathname; { - int printed_len = 0; -#if !defined (VISIBLE_STATS) - char *s; + int printed_len, extension_char, slen, tlen; + char *s, c, *new_full_pathname, *dn; - for (s = to_print; *s; s++) - { - PUTX (*s); - } -#else - char *s, c, *new_full_pathname; - int extension_char, slen, tlen; + extension_char = 0; + printed_len = fnprint (to_print); - for (s = to_print; *s; s++) - { - PUTX (*s); - } - - if (rl_filename_completion_desired && rl_visible_stats) +#if defined (VISIBLE_STATS) + if (rl_filename_completion_desired && (rl_visible_stats || _rl_complete_mark_directories)) +#else + if (rl_filename_completion_desired && _rl_complete_mark_directories) +#endif { /* If to_print != full_pathname, to_print is the basename of the path passed. In this case, we try to expand the directory @@ -585,7 +720,17 @@ print_filename (to_print, full_pathname) files in the root directory. If we pass a null string to the bash directory completion hook, for example, it will expand it to the current directory. We just want the `/'. */ - s = tilde_expand (full_pathname && *full_pathname ? full_pathname : "/"); + if (full_pathname == 0 || *full_pathname == 0) + dn = "/"; + else if (full_pathname[0] != '/') + dn = full_pathname; + else if (full_pathname[1] == 0) + dn = "//"; /* restore trailing slash to `//' */ + else if (full_pathname[1] == '/' && full_pathname[2] == 0) + dn = "/"; /* don't turn /// into // */ + else + dn = full_pathname; + s = tilde_expand (dn); if (rl_directory_completion_hook) (*rl_directory_completion_hook) (&s); @@ -593,10 +738,20 @@ print_filename (to_print, full_pathname) tlen = strlen (to_print); new_full_pathname = (char *)xmalloc (slen + tlen + 2); strcpy (new_full_pathname, s); + if (s[slen - 1] == '/') + slen--; + else + new_full_pathname[slen] = '/'; new_full_pathname[slen] = '/'; strcpy (new_full_pathname + slen + 1, to_print); - extension_char = stat_char (new_full_pathname); +#if defined (VISIBLE_STATS) + if (rl_visible_stats) + extension_char = stat_char (new_full_pathname); + else +#endif + if (path_isdir (new_full_pathname)) + extension_char = '/'; free (new_full_pathname); to_print[-1] = c; @@ -604,7 +759,13 @@ print_filename (to_print, full_pathname) else { s = tilde_expand (full_pathname); - extension_char = stat_char (s); +#if defined (VISIBLE_STATS) + if (rl_visible_stats) + extension_char = stat_char (s); + else +#endif + if (path_isdir (s)) + extension_char = '/'; } free (s); @@ -614,7 +775,7 @@ print_filename (to_print, full_pathname) printed_len++; } } -#endif /* VISIBLE_STATS */ + return printed_len; } @@ -654,19 +815,25 @@ _rl_find_completion_word (fp, dp) int *fp, *dp; { int scan, end, found_quote, delimiter, pass_next, isbrk; - char quote_char; + char quote_char, *brkchars; end = rl_point; found_quote = delimiter = 0; quote_char = '\0'; + brkchars = 0; + if (rl_completion_word_break_hook) + brkchars = (*rl_completion_word_break_hook) (); + if (brkchars == 0) + brkchars = rl_completer_word_break_characters; + if (rl_completer_quote_characters) { /* We have a list of characters which can be used in pairs to quote substrings for the completer. Try to find the start of an unclosed quoted substring. */ /* FOUND_QUOTE is set so we know what kind of quotes we found. */ - for (scan = pass_next = 0; scan < end; scan++) + for (scan = pass_next = 0; scan < end; scan = MB_NEXTCHAR (rl_line_buffer, scan, 1, MB_FIND_ANY)) { if (pass_next) { @@ -716,15 +883,11 @@ _rl_find_completion_word (fp, dp) /* We didn't find an unclosed quoted substring upon which to do completion, so use the word break characters to find the substring on which to complete. */ -#if defined (HANDLE_MULTIBYTE) - while (rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_ANY)) -#else - while (--rl_point) -#endif + while (rl_point = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_ANY)) { scan = rl_line_buffer[rl_point]; - if (strchr (rl_completer_word_break_characters, scan) == 0) + if (strchr (brkchars, scan) == 0) continue; /* Call the application-specific function to tell us whether @@ -752,9 +915,9 @@ _rl_find_completion_word (fp, dp) if (rl_char_is_quoted_p) isbrk = (found_quote == 0 || (*rl_char_is_quoted_p) (rl_line_buffer, rl_point) == 0) && - strchr (rl_completer_word_break_characters, scan) != 0; + strchr (brkchars, scan) != 0; else - isbrk = strchr (rl_completer_word_break_characters, scan) != 0; + isbrk = strchr (brkchars, scan) != 0; if (isbrk) { @@ -789,6 +952,9 @@ gen_completion_matches (text, start, end, our_func, found_quote, quote_char) { char **matches, *temp; + rl_completion_found_quote = found_quote; + rl_completion_quote_character = quote_char; + /* If the user wants to TRY to complete, but then wants to give up and use the default completion function, they set the variable rl_attempted_completion_function. */ @@ -892,6 +1058,7 @@ compute_lcd_of_matches (match_list, matches, text) { register int i, c1, c2, si; int low; /* Count of max-matched characters. */ + char *dtext; /* dequoted TEXT, if needed */ #if defined (HANDLE_MULTIBYTE) int v; mbstate_t ps1, ps2; @@ -983,6 +1150,26 @@ compute_lcd_of_matches (match_list, matches, text) the user typed in the face of multiple matches differing in case. */ if (_rl_completion_case_fold) { + /* We're making an assumption here: + IF we're completing filenames AND + the application has defined a filename dequoting function AND + we found a quote character AND + the application has requested filename quoting + THEN + we assume that TEXT was dequoted before checking against + the file system and needs to be dequoted here before we + check against the list of matches + FI */ + dtext = (char *)NULL; + if (rl_filename_completion_desired && + rl_filename_dequoting_function && + rl_completion_found_quote && + rl_filename_quoting_desired) + { + dtext = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character); + text = dtext; + } + /* sort the list to get consistent answers. */ qsort (match_list+1, matches, sizeof(char *), (QSFUNC *)_rl_qsort_string_compare); @@ -1002,6 +1189,8 @@ compute_lcd_of_matches (match_list, matches, text) else /* otherwise, just use the text the user typed. */ strncpy (match_list[0], text, low); + + FREE (dtext); } else strncpy (match_list[0], match_list[1], low); @@ -1206,7 +1395,7 @@ display_matches (matches) for (max = 0, i = 1; matches[i]; i++) { temp = printable_part (matches[i]); - len = strlen (temp); + len = fnwidth (temp); if (len > max) max = len; @@ -1223,7 +1412,7 @@ display_matches (matches) /* If there are many items, then ask the user if she really wants to see them all. */ - if (len >= rl_completion_query_items) + if (rl_completion_query_items > 0 && len >= rl_completion_query_items) { rl_crlf (); fprintf (rl_outstream, "Display all %d possibilities? (y or n)", len); @@ -1341,7 +1530,8 @@ append_to_match (text, delimiter, quote_char, nontrivial_match) struct stat finfo; temp_string_index = 0; - if (quote_char && rl_point && rl_line_buffer[rl_point - 1] != quote_char) + if (quote_char && rl_point && rl_completion_suppress_quote == 0 && + rl_line_buffer[rl_point - 1] != quote_char) temp_string[temp_string_index++] = quote_char; if (delimiter) @@ -1359,7 +1549,7 @@ append_to_match (text, delimiter, quote_char, nontrivial_match) : stat (filename, &finfo); if (s == 0 && S_ISDIR (finfo.st_mode)) { - if (_rl_complete_mark_directories) + if (_rl_complete_mark_directories /* && rl_completion_suppress_append == 0 */) { /* This is clumsy. Avoid putting in a double slash if point is at the end of the line and the previous character is a @@ -1452,7 +1642,9 @@ _rl_free_match_list (matches) TAB means do standard completion. `*' means insert all of the possible completions. `!' means to do standard completion, and list all possible completions if - there is more than one. */ + there is more than one. + `@' means to do standard completion, and list all possible completions if + there is more than one and partial completion is not possible. */ int rl_complete_internal (what_to_do) int what_to_do; @@ -1471,7 +1663,6 @@ rl_complete_internal (what_to_do) our_func = rl_completion_entry_function ? rl_completion_entry_function : rl_filename_completion_function; - /* We now look backwards for the start of a filename/variable word. */ end = rl_point; found_quote = delimiter = 0; @@ -1519,6 +1710,7 @@ rl_complete_internal (what_to_do) { case TAB: case '!': + case '@': /* Insert the first match with proper quoting. */ if (*matches[0]) insert_match (matches[0], start, matches[1] ? MULT_MATCH : SINGLE_MATCH, "e_char); @@ -1538,6 +1730,12 @@ rl_complete_internal (what_to_do) display_matches (matches); break; } + else if (what_to_do == '@') + { + if (nontrivial_lcd == 0) + display_matches (matches); + break; + } else if (rl_editing_mode != vi_mode) rl_ding (); /* There are other matches remaining. */ } @@ -1665,7 +1863,7 @@ rl_username_completion_function (text, state) setpwent (); } -#ifdef HAVE_GETPWENT +#if defined (HAVE_GETPWENT) while (entry = getpwent ()) { /* Null usernames should result in all users as possible completions. */ @@ -1676,7 +1874,7 @@ rl_username_completion_function (text, state) if (entry == 0) { -#ifdef HAVE_GETPWENT +#if defined (HAVE_GETPWENT) endpwent (); #endif return ((char *)NULL); @@ -1990,9 +2188,11 @@ rl_menu_complete (count, ignore) return (0); } - match_list_index = (match_list_index + count) % match_list_size; + match_list_index += count; if (match_list_index < 0) match_list_index += match_list_size; + else + match_list_index %= match_list_size; if (match_list_index == 0 && match_list_size > 1) { diff --git a/readline/config.h.bot b/readline/config.h.bot deleted file mode 100644 index d7a6dc45ce4..00000000000 --- a/readline/config.h.bot +++ /dev/null @@ -1,22 +0,0 @@ -/* config.h.bot */ -/* modify settings or make new ones based on what autoconf tells us. */ - -/* Ultrix botches type-ahead when switching from canonical to - non-canonical mode, at least through version 4.3 */ -#if !defined (HAVE_TERMIOS_H) || !defined (HAVE_TCGETATTR) || defined (ultrix) -# define TERMIOS_MISSING -#endif - -#if defined (STRCOLL_BROKEN) -# undef HAVE_STRCOLL -#endif - -#if defined (__STDC__) && defined (HAVE_STDARG_H) -# define PREFER_STDARG -# define USE_VARARGS -#else -# if defined (HAVE_VARARGS_H) -# define PREFER_VARARGS -# define USE_VARARGS -# endif -#endif diff --git a/readline/config.h.in b/readline/config.h.in index 8d1f0bcafa4..b4aae982a7b 100644 --- a/readline/config.h.in +++ b/readline/config.h.in @@ -1,11 +1,17 @@ /* config.h.in. Maintained by hand. */ +/* 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 as the return type of signal handlers (int or void). */ #undef RETSIGTYPE +#undef VOID_SIGHANDLER + /* Characteristics of the compiler. */ #undef const @@ -20,11 +26,18 @@ /* Define if the `S_IS*' macros in <sys/stat.h> do not work properly. */ #undef STAT_MACROS_BROKEN -#undef VOID_SIGHANDLER - /* Define if you have the fcntl function. */ -#undef HAVE_FCNTL - +#undef HAVE_FCNTL + +/* Define if you have the getpwent function. */ +#undef HAVE_GETPWENT + +/* Define if you have the getpwnam function. */ +#undef HAVE_GETPWNAM + +/* Define if you have the getpwuid function. */ +#undef HAVE_GETPWUID + /* Define if you have the isascii function. */ #undef HAVE_ISASCII @@ -37,6 +50,9 @@ /* Define if you have the lstat function. */ #undef HAVE_LSTAT +/* Define if you have the mbrlen function. */ +#undef HAVE_MBRLEN + /* Define if you have the mbrtowc function. */ #undef HAVE_MBRTOWC @@ -49,15 +65,6 @@ /* Define if you have the putenv function. */ #undef HAVE_PUTENV -/* Define if you have the getpwent function. */ -#undef HAVE_GETPWENT - -/* Define if you have the getpwnam function. */ -#undef HAVE_GETPWNAM - -/* Define if you have the getpwnam function. */ -#undef HAVE_GETPWUID - /* Define if you have the select function. */ #undef HAVE_SELECT @@ -84,12 +91,20 @@ /* 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 @@ -198,6 +213,8 @@ #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 diff --git a/readline/configure b/readline/configure index 720d789bae0..17b6f52f4f7 100755 --- a/readline/configure +++ b/readline/configure @@ -1,7 +1,7 @@ #! /bin/sh -# From configure.in for Readline 4.3, version 2.45, from autoconf version AC_ACVERSION. +# From configure.in for Readline 5.1, version 2.59. # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.59 for readline 4.3. +# Generated by GNU Autoconf 2.59 for readline 5.1-release. # # Report bugs to <bug-readline@gnu.org>. # @@ -270,8 +270,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='readline' PACKAGE_TARNAME='readline' -PACKAGE_VERSION='4.3' -PACKAGE_STRING='readline 4.3' +PACKAGE_VERSION='5.1-release' +PACKAGE_STRING='readline 5.1-release' PACKAGE_BUGREPORT='bug-readline@gnu.org' ac_unique_file="readline.h" @@ -312,7 +312,7 @@ ac_includes_default="\ # include <unistd.h> #endif" -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os SET_MAKE CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP EGREP CROSS_COMPILING_FLAG CC_FOR_BUILD INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA AR RANLIB ac_ct_RANLIB MAKE_SHELL WCWIDTH_OBJ SHOBJ_CC SHOBJ_CFLAGS SHOBJ_LD SHOBJ_LDFLAGS SHOBJ_XLDFLAGS SHOBJ_LIBS SHOBJ_STATUS SHLIB_STATUS SHLIB_XLDFLAGS SHLIB_LIBSUFF SHLIB_LIBVERSION SHLIB_LIBS SHLIB_MAJOR SHLIB_MINOR STATIC_TARGET SHARED_TARGET STATIC_INSTALL_TARGET SHARED_INSTALL_TARGET BUILD_DIR LOCAL_CFLAGS LOCAL_LDFLAGS LOCAL_DEFS ARFLAGS LIBVERSION TERMCAP_LIB LIBOBJS LTLIBOBJS' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os CROSS_COMPILE SET_MAKE CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP EGREP CC_FOR_BUILD INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA AR RANLIB ac_ct_RANLIB MAKE_SHELL WCWIDTH_OBJ SHOBJ_CC SHOBJ_CFLAGS SHOBJ_LD SHOBJ_LDFLAGS SHOBJ_XLDFLAGS SHOBJ_LIBS SHOBJ_STATUS SHLIB_STATUS SHLIB_XLDFLAGS SHLIB_DOT SHLIB_LIBPREF SHLIB_LIBSUFF SHLIB_LIBVERSION SHLIB_DLLVERSION SHLIB_LIBS SHLIB_MAJOR SHLIB_MINOR STATIC_TARGET SHARED_TARGET STATIC_INSTALL_TARGET SHARED_INSTALL_TARGET PURIFY BUILD_DIR LOCAL_CFLAGS LOCAL_LDFLAGS LOCAL_DEFS ARFLAGS LIBVERSION TERMCAP_LIB LIBOBJS LTLIBOBJS' ac_subst_files='' # Initialize some variables set by options. @@ -781,7 +781,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures readline 4.3 to adapt to many kinds of systems. +\`configure' configures readline 5.1-release to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -842,17 +842,14 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of readline 4.3:";; + short | recursive ) echo "Configuration of readline 5.1-release:";; esac cat <<\_ACEOF Optional Features: --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] -<<<<<<< configure - --enable-shared build shared libraries [default=NO] -======= ->>>>>>> 1.6 + --enable-multibyte enable multibyte characters if OS supports them --enable-static build static libraries [default=YES] Optional Packages: @@ -860,6 +857,7 @@ Optional Packages: --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-curses use the curses library instead of the termcap library + --with-purify configure to postprocess with purify Some influential environment variables: CC C compiler command @@ -962,14 +960,14 @@ esac else echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi - cd $ac_popdir + cd "$ac_popdir" done fi test -n "$ac_init_help" && exit 0 if $ac_init_version; then cat <<\_ACEOF -readline configure 4.3 +readline configure 5.1-release generated by GNU Autoconf 2.59 Copyright (C) 2003 Free Software Foundation, Inc. @@ -983,7 +981,7 @@ cat >&5 <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by readline $as_me 4.3, which was +It was created by readline $as_me 5.1-release, which was generated by GNU Autoconf 2.59. Invocation command line was $ $0 $@ @@ -1323,13 +1321,8 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - ac_config_headers="$ac_config_headers config.h" - - -LIBVERSION=4.3 - ac_aux_dir= -for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do +for ac_dir in `cd $srcdir;pwd`/.. $srcdir/`cd $srcdir;pwd`/..; do if test -f $ac_dir/install-sh; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install-sh -c" @@ -1345,14 +1338,19 @@ for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do fi done if test -z "$ac_aux_dir"; then - { { echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&5 -echo "$as_me: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&2;} + { { echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in \`cd $srcdir;pwd\`/.. $srcdir/\`cd $srcdir;pwd\`/.." >&5 +echo "$as_me: error: cannot find install-sh or install.sh in \`cd $srcdir;pwd\`/.. $srcdir/\`cd $srcdir;pwd\`/.." >&2;} { (exit 1); exit 1; }; } fi ac_config_guess="$SHELL $ac_aux_dir/config.guess" ac_config_sub="$SHELL $ac_aux_dir/config.sub" ac_configure="$SHELL $ac_aux_dir/configure" # This should be Cygnus configure. + ac_config_headers="$ac_config_headers config.h" + + +LIBVERSION=5.1 + # Make sure we can run config.sub. $ac_config_sub sun4 >/dev/null 2>&1 || { { echo "$as_me:$LINENO: error: cannot run $ac_config_sub" >&5 @@ -1409,6 +1407,7 @@ host_os=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` opt_curses=no +opt_purify=no # Check whether --with-curses or --without-curses was given. @@ -1417,19 +1416,69 @@ if test "${with_curses+set}" = set; then opt_curses=$withval fi; +# Check whether --with-purify or --without-purify was given. +if test "${with_purify+set}" = set; then + withval="$with_purify" + opt_purify=$withval +fi; + if test "$opt_curses" = "yes"; then prefer_curses=yes fi +if test "$opt_purify" = yes; then + PURIFY="purify" +else + PURIFY= +fi + +opt_multibyte=yes opt_static_libs=yes opt_shared_libs=no +# Check whether --enable-multibyte or --disable-multibyte was given. +if test "${enable_multibyte+set}" = set; then + enableval="$enable_multibyte" + opt_multibyte=$enableval +fi; # Check whether --enable-static or --disable-static was given. if test "${enable_static+set}" = set; then enableval="$enable_static" opt_static_libs=$enableval fi; +if test $opt_multibyte = no; then +cat >>confdefs.h <<\_ACEOF +#define NO_MULTIBYTE_SUPPORT 1 +_ACEOF + +fi + + + +if test "x$cross_compiling" = "xyes"; then + case "${host}" in + *-cygwin*) + 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 + 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' + +fi + echo "" echo "Beginning configuration for readline-$LIBVERSION for ${host_cpu}-${host_vendor}-${host_os}" echo "" @@ -2034,8 +2083,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2093,8 +2141,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2210,8 +2257,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2265,8 +2311,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2311,8 +2356,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2356,8 +2400,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2680,8 +2723,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2851,8 +2893,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2915,8 +2956,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3071,13 +3111,6 @@ if test "x$cross_compiling" = "xyes"; then fi fi -if test "x$cross_compiling" = "xyes"; then - CROSS_COMPILING_FLAG=-DCROSS_COMPILING -else - CROSS_COMPILING_FLAG= -fi - - if test -z "$CC_FOR_BUILD"; then if test "x$cross_compiling" = "xno"; then CC_FOR_BUILD='$(CC)' @@ -3416,8 +3449,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3500,8 +3532,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3571,8 +3602,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3634,8 +3664,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3700,8 +3729,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3735,6 +3763,172 @@ _ACEOF fi +echo "$as_me:$LINENO: checking for ANSI C header files" >&5 +echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6 +if test "${ac_cv_header_stdc+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <float.h> + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_header_stdc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_header_stdc=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <string.h> + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then + : +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <stdlib.h> + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then + : +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then + : +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <ctype.h> +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + exit(2); + exit (0); +} +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + : +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +ac_cv_header_stdc=no +fi +rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi +fi +fi +echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5 +echo "${ECHO_T}$ac_cv_header_stdc" >&6 +if test $ac_cv_header_stdc = yes; then + +cat >>confdefs.h <<\_ACEOF +#define STDC_HEADERS 1 +_ACEOF + +fi + + echo "$as_me:$LINENO: checking whether stat file-mode macros are broken" >&5 echo $ECHO_N "checking whether stat file-mode macros are broken... $ECHO_C" >&6 if test "${ac_cv_header_stat_broken+set}" = set; then @@ -3833,8 +4027,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3906,8 +4099,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3961,8 +4153,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -4033,8 +4224,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -4088,8 +4278,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -4127,23 +4316,322 @@ fi +for ac_func in fcntl kill lstat +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func. + For example, HP-UX 11i <limits.h> declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer <limits.h> to <assert.h> if __STDC__ is defined, since + <limits.h> exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include <limits.h> +#else +# include <assert.h> +#endif + +#undef $ac_func + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + + + + + + + + + +for ac_func in memmove putenv select setenv setlocale \ + strcasecmp strpbrk tcgetattr vsnprintf +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func. + For example, HP-UX 11i <limits.h> declares gettimeofday. */ +#define $ac_func innocuous_$ac_func +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer <limits.h> to <assert.h> if __STDC__ is defined, since + <limits.h> exists even on freestanding compilers. */ +#ifdef __STDC__ +# include <limits.h> +#else +# include <assert.h> +#endif +#undef $ac_func +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + + +for ac_func in isascii isxdigit +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func. + For example, HP-UX 11i <limits.h> declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer <limits.h> to <assert.h> if __STDC__ is defined, since + <limits.h> exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include <limits.h> +#else +# include <assert.h> +#endif +#undef $ac_func +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 +eval "$as_ac_var=no" +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF +fi +done -for ac_func in fcntl kill lstat memmove putenv select setenv setlocale \ - strcasecmp strpbrk tcgetattr vsnprintf isascii isxdigit \ - getpwnam getpwent getpwuid +for ac_func in getpwent getpwnam getpwuid do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 @@ -4211,8 +4699,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -4318,14 +4805,160 @@ fi +for ac_header in 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 +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 +else + # Is the header compilable? +echo "$as_me:$LINENO: checking $ac_header usability" >&5 +echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 +ac_header_compiler=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6 +# Is the header present? +echo "$as_me:$LINENO: checking $ac_header presence" >&5 +echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <$ac_header> +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_c_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi +rm -f conftest.err conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6 + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in + yes:no: ) + { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} + ac_header_preproc=yes + ;; + no:yes:* ) + { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 +echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 +echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 +echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 +echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} + ( + cat <<\_ASBOX +## ----------------------------------- ## +## Report this to bug-readline@gnu.org ## +## ----------------------------------- ## +_ASBOX + ) | + sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + eval "$as_ac_Header=\$ac_header_preproc" +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 + +fi +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done -for ac_header in unistd.h stdlib.h varargs.h stdarg.h string.h strings.h \ - limits.h sys/ptem.h sys/pte.h sys/stream.h sys/select.h \ - termcap.h termios.h termio.h sys/file.h locale.h memory.h \ - pwd.h + + + +for ac_header in sys/pte.h sys/stream.h sys/select.h sys/file.h do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` if eval "test \"\${$as_ac_Header+set}\" = set"; then @@ -4358,8 +4991,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -4476,6 +5108,71 @@ done +for ac_header in sys/ptem.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +#if HAVE_SYS_STREAM_H +# include <sys/stream.h> +#endif + + +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_Header=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_Header=no" +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + + echo "$as_me:$LINENO: checking for type of signal functions" >&5 echo $ECHO_N "checking for type of signal functions... $ECHO_C" >&6 if test "${bash_cv_signal_vintage+set}" = set; then @@ -4512,8 +5209,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -4558,8 +5254,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -4607,8 +5302,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -4880,8 +5574,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -5001,6 +5694,89 @@ _ACEOF fi +echo "$as_me:$LINENO: checking whether the ctype macros accept non-ascii characters" >&5 +echo $ECHO_N "checking whether the ctype macros accept non-ascii characters... $ECHO_C" >&6 +if test "${bash_cv_func_ctype_nonascii+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test "$cross_compiling" = yes; then + { echo "$as_me:$LINENO: WARNING: cannot check ctype macros if cross compiling -- defaulting to no" >&5 +echo "$as_me: WARNING: cannot check ctype macros if cross compiling -- defaulting to no" >&2;} + bash_cv_func_ctype_nonascii=no + +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +#ifdef HAVE_LOCALE_H +#include <locale.h> +#endif +#include <stdio.h> +#include <ctype.h> + +main(c, v) +int c; +char *v[]; +{ + char *deflocale; + unsigned char x; + int r1, r2; + +#ifdef HAVE_SETLOCALE + /* We take a shot here. If that locale is not known, try the + system default. We try this one because '\342' (226) is + known to be a printable character in that locale. */ + deflocale = setlocale(LC_ALL, "en_US.ISO8859-1"); + if (deflocale == 0) + deflocale = setlocale(LC_ALL, ""); +#endif + + x = '\342'; + r1 = isprint(x); + x -= 128; + r2 = isprint(x); + exit (r1 == 0 || r2 == 0); +} + +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + bash_cv_func_ctype_nonascii=yes +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +bash_cv_func_ctype_nonascii=no +fi +rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi +fi + +echo "$as_me:$LINENO: result: $bash_cv_func_ctype_nonascii" >&5 +echo "${ECHO_T}$bash_cv_func_ctype_nonascii" >&6 +if test $bash_cv_func_ctype_nonascii = yes; then +cat >>confdefs.h <<\_ACEOF +#define CTYPE_NON_ASCII 1 +_ACEOF + +fi + + echo "$as_me:$LINENO: checking whether getpw functions are declared in pwd.h" >&5 echo $ECHO_N "checking whether getpw functions are declared in pwd.h... $ECHO_C" >&6 if test "${bash_cv_getpw_declared+set}" = set; then @@ -5148,8 +5924,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -5209,8 +5984,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -5271,8 +6045,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -5332,8 +6105,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -5394,8 +6166,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -5437,8 +6208,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -5483,8 +6253,8 @@ echo "${ECHO_T}not found" >&6 fi -echo "$as_me:$LINENO: checking if struct dirent has a d_ino member" >&5 -echo $ECHO_N "checking if struct dirent has a d_ino member... $ECHO_C" >&6 +echo "$as_me:$LINENO: checking for struct dirent.d_ino" >&5 +echo $ECHO_N "checking for struct dirent.d_ino... $ECHO_C" >&6 if test "${bash_cv_dirent_has_dino+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else @@ -5534,8 +6304,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -5561,14 +6330,14 @@ echo "$as_me:$LINENO: result: $bash_cv_dirent_has_dino" >&5 echo "${ECHO_T}$bash_cv_dirent_has_dino" >&6 if test $bash_cv_dirent_has_dino = yes; then cat >>confdefs.h <<\_ACEOF -#define STRUCT_DIRENT_HAS_D_INO 1 +#define HAVE_STRUCT_DIRENT_D_INO 1 _ACEOF fi -echo "$as_me:$LINENO: checking if struct dirent has a d_fileno member" >&5 -echo $ECHO_N "checking if struct dirent has a d_fileno member... $ECHO_C" >&6 +echo "$as_me:$LINENO: checking for struct dirent.d_fileno" >&5 +echo $ECHO_N "checking for struct dirent.d_fileno... $ECHO_C" >&6 if test "${bash_cv_dirent_has_d_fileno+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else @@ -5618,8 +6387,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -5645,7 +6413,7 @@ echo "$as_me:$LINENO: result: $bash_cv_dirent_has_d_fileno" >&5 echo "${ECHO_T}$bash_cv_dirent_has_d_fileno" >&6 if test $bash_cv_dirent_has_d_fileno = yes; then cat >>confdefs.h <<\_ACEOF -#define STRUCT_DIRENT_HAS_D_FILENO 1 +#define HAVE_STRUCT_DIRENT_D_FILENO 1 _ACEOF fi @@ -5665,6 +6433,98 @@ fi if test "${bash_cv_termcap_lib+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else + echo "$as_me:$LINENO: checking for tgetent" >&5 +echo $ECHO_N "checking for tgetent... $ECHO_C" >&6 +if test "${ac_cv_func_tgetent+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define tgetent to an innocuous variant, in case <limits.h> declares tgetent. + For example, HP-UX 11i <limits.h> declares gettimeofday. */ +#define tgetent innocuous_tgetent + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char tgetent (); below. + Prefer <limits.h> to <assert.h> if __STDC__ is defined, since + <limits.h> exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include <limits.h> +#else +# include <assert.h> +#endif + +#undef tgetent + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char tgetent (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_tgetent) || defined (__stub___tgetent) +choke me +#else +char (*f) () = tgetent; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != tgetent; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_func_tgetent=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_func_tgetent=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_func_tgetent" >&5 +echo "${ECHO_T}$ac_cv_func_tgetent" >&6 +if test $ac_cv_func_tgetent = yes; then + bash_cv_termcap_lib=libc +else echo "$as_me:$LINENO: checking for tgetent in -ltermcap" >&5 echo $ECHO_N "checking for tgetent in -ltermcap... $ECHO_C" >&6 if test "${ac_cv_lib_termcap_tgetent+set}" = set; then @@ -5703,8 +6563,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -5770,8 +6629,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -5837,8 +6695,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -5904,8 +6761,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -5944,6 +6800,8 @@ fi fi +fi + if test "X$_bash_needmsg" = "Xyes"; then echo "$as_me:$LINENO: checking which library has the termcap functions" >&5 echo $ECHO_N "checking which library has the termcap functions... $ECHO_C" >&6 @@ -5963,6 +6821,9 @@ TERMCAP_DEP= elif test $bash_cv_termcap_lib = libncurses; then TERMCAP_LIB=-lncurses TERMCAP_DEP= +elif test $bash_cv_termcap_lib = libc; then +TERMCAP_LIB= +TERMCAP_DEP= else TERMCAP_LIB=-lcurses TERMCAP_DEP= @@ -6011,8 +6872,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -6161,8 +7021,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -6311,8 +7170,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -6428,6 +7286,102 @@ fi done +echo "$as_me:$LINENO: checking for mbsrtowcs" >&5 +echo $ECHO_N "checking for mbsrtowcs... $ECHO_C" >&6 +if test "${ac_cv_func_mbsrtowcs+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define mbsrtowcs to an innocuous variant, in case <limits.h> declares mbsrtowcs. + For example, HP-UX 11i <limits.h> declares gettimeofday. */ +#define mbsrtowcs innocuous_mbsrtowcs + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char mbsrtowcs (); below. + Prefer <limits.h> to <assert.h> if __STDC__ is defined, since + <limits.h> exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include <limits.h> +#else +# include <assert.h> +#endif + +#undef mbsrtowcs + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char mbsrtowcs (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_mbsrtowcs) || defined (__stub___mbsrtowcs) +choke me +#else +char (*f) () = mbsrtowcs; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != mbsrtowcs; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_func_mbsrtowcs=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_func_mbsrtowcs=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_func_mbsrtowcs" >&5 +echo "${ECHO_T}$ac_cv_func_mbsrtowcs" >&6 +if test $ac_cv_func_mbsrtowcs = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_MBSRTOWCS 1 +_ACEOF + +fi + echo "$as_me:$LINENO: checking for mbrtowc" >&5 echo $ECHO_N "checking for mbrtowc... $ECHO_C" >&6 if test "${ac_cv_func_mbrtowc+set}" = set; then @@ -6493,8 +7447,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -6525,9 +7478,9 @@ _ACEOF fi -echo "$as_me:$LINENO: checking for mbsrtowcs" >&5 -echo $ECHO_N "checking for mbsrtowcs... $ECHO_C" >&6 -if test "${ac_cv_func_mbsrtowcs+set}" = set; then +echo "$as_me:$LINENO: checking for mbrlen" >&5 +echo $ECHO_N "checking for mbrlen... $ECHO_C" >&6 +if test "${ac_cv_func_mbrlen+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else cat >conftest.$ac_ext <<_ACEOF @@ -6536,12 +7489,12 @@ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ -/* Define mbsrtowcs to an innocuous variant, in case <limits.h> declares mbsrtowcs. +/* Define mbrlen to an innocuous variant, in case <limits.h> declares mbrlen. For example, HP-UX 11i <limits.h> declares gettimeofday. */ -#define mbsrtowcs innocuous_mbsrtowcs +#define mbrlen innocuous_mbrlen /* System header to define __stub macros and hopefully few prototypes, - which can conflict with char mbsrtowcs (); below. + which can conflict with char mbrlen (); below. Prefer <limits.h> to <assert.h> if __STDC__ is defined, since <limits.h> exists even on freestanding compilers. */ @@ -6551,7 +7504,7 @@ cat >>conftest.$ac_ext <<_ACEOF # include <assert.h> #endif -#undef mbsrtowcs +#undef mbrlen /* Override any gcc2 internal prototype to avoid an error. */ #ifdef __cplusplus @@ -6560,14 +7513,14 @@ extern "C" #endif /* We use char because int might match the return type of a gcc2 builtin and then its argument prototype would still apply. */ -char mbsrtowcs (); +char mbrlen (); /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ -#if defined (__stub_mbsrtowcs) || defined (__stub___mbsrtowcs) +#if defined (__stub_mbrlen) || defined (__stub___mbrlen) choke me #else -char (*f) () = mbsrtowcs; +char (*f) () = mbrlen; #endif #ifdef __cplusplus } @@ -6576,7 +7529,7 @@ char (*f) () = mbsrtowcs; int main () { -return f != mbsrtowcs; +return f != mbrlen; ; return 0; } @@ -6590,8 +7543,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -6603,21 +7555,117 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); }; }; then - ac_cv_func_mbsrtowcs=yes + ac_cv_func_mbrlen=yes else echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 -ac_cv_func_mbsrtowcs=no +ac_cv_func_mbrlen=no fi rm -f conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi -echo "$as_me:$LINENO: result: $ac_cv_func_mbsrtowcs" >&5 -echo "${ECHO_T}$ac_cv_func_mbsrtowcs" >&6 -if test $ac_cv_func_mbsrtowcs = yes; then +echo "$as_me:$LINENO: result: $ac_cv_func_mbrlen" >&5 +echo "${ECHO_T}$ac_cv_func_mbrlen" >&6 +if test $ac_cv_func_mbrlen = yes; then cat >>confdefs.h <<\_ACEOF -#define HAVE_MBSRTOWCS 1 +#define HAVE_MBRLEN 1 +_ACEOF + +fi + +echo "$as_me:$LINENO: checking for wctomb" >&5 +echo $ECHO_N "checking for wctomb... $ECHO_C" >&6 +if test "${ac_cv_func_wctomb+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define wctomb to an innocuous variant, in case <limits.h> declares wctomb. + For example, HP-UX 11i <limits.h> declares gettimeofday. */ +#define wctomb innocuous_wctomb + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char wctomb (); below. + Prefer <limits.h> to <assert.h> if __STDC__ is defined, since + <limits.h> exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include <limits.h> +#else +# include <assert.h> +#endif + +#undef wctomb + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char wctomb (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_wctomb) || defined (__stub___wctomb) +choke me +#else +char (*f) () = wctomb; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != wctomb; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_func_wctomb=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_func_wctomb=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_func_wctomb" >&5 +echo "${ECHO_T}$ac_cv_func_wctomb" >&6 +if test $ac_cv_func_wctomb = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_WCTOMB 1 _ACEOF fi @@ -6687,8 +7735,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -6719,6 +7766,103 @@ _ACEOF fi +echo "$as_me:$LINENO: checking for wcsdup" >&5 +echo $ECHO_N "checking for wcsdup... $ECHO_C" >&6 +if test "${ac_cv_func_wcsdup+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define wcsdup to an innocuous variant, in case <limits.h> declares wcsdup. + For example, HP-UX 11i <limits.h> declares gettimeofday. */ +#define wcsdup innocuous_wcsdup + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char wcsdup (); below. + Prefer <limits.h> to <assert.h> if __STDC__ is defined, since + <limits.h> exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include <limits.h> +#else +# include <assert.h> +#endif + +#undef wcsdup + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char wcsdup (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_wcsdup) || defined (__stub___wcsdup) +choke me +#else +char (*f) () = wcsdup; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != wcsdup; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_func_wcsdup=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_func_wcsdup=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_func_wcsdup" >&5 +echo "${ECHO_T}$ac_cv_func_wcsdup" >&6 +if test $ac_cv_func_wcsdup = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_WCSDUP 1 +_ACEOF + +fi + + if test "$ac_cv_func_wcwidth" = no && test "$ac_cv_header_wchar_h" = yes; then WCWIDTH_OBJ=wcwidth.o else @@ -6737,37 +7881,36 @@ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ + #include <wchar.h> int main () { -int -main () -{ + mbstate_t ps; - return 0; -} + mbstate_t *psp; + psp = (mbstate_t *)0; + ; return 0; } _ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>conftest.er1 +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 ac_status=$? grep -v '^ *+' conftest.er1 >conftest.err rm -f conftest.er1 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); }; } && - { ac_try='test -s conftest$ac_exeext' + { ac_try='test -s conftest.$ac_objext' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -6780,8 +7923,7 @@ sed 's/^/| /' conftest.$ac_ext >&5 bash_cv_have_mbstate_t=no fi -rm -f conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext fi echo "$as_me:$LINENO: result: $bash_cv_have_mbstate_t" >&5 echo "${ECHO_T}$bash_cv_have_mbstate_t" >&6 @@ -6821,8 +7963,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -6872,7 +8013,16 @@ esac if test -f ${srcdir}/support/shobj-conf; then echo "$as_me:$LINENO: checking configuration for building shared libraries" >&5 echo $ECHO_N "checking configuration for building shared libraries... $ECHO_C" >&6 - eval `${CONFIG_SHELL-/bin/sh} ${srcdir}/support/shobj-conf -C "${CC}" -c ${host_cpu} -o ${host_os} -v ${host_vendor}` + 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 + + + + @@ -6921,6 +8071,12 @@ 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 + + @@ -7302,7 +8458,7 @@ _ASBOX } >&5 cat >&5 <<_CSEOF -This file was extended by readline $as_me 4.3, which was +This file was extended by readline $as_me 5.1-release, which was generated by GNU Autoconf 2.59. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -7365,7 +8521,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -readline config.status 4.3 +readline config.status 5.1-release configured by $0, generated by GNU Autoconf 2.59, with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" @@ -7567,6 +8723,7 @@ s,@host@,$host,;t t s,@host_cpu@,$host_cpu,;t t s,@host_vendor@,$host_vendor,;t t s,@host_os@,$host_os,;t t +s,@CROSS_COMPILE@,$CROSS_COMPILE,;t t s,@SET_MAKE@,$SET_MAKE,;t t s,@CC@,$CC,;t t s,@CFLAGS@,$CFLAGS,;t t @@ -7577,7 +8734,6 @@ s,@EXEEXT@,$EXEEXT,;t t s,@OBJEXT@,$OBJEXT,;t t s,@CPP@,$CPP,;t t s,@EGREP@,$EGREP,;t t -s,@CROSS_COMPILING_FLAG@,$CROSS_COMPILING_FLAG,;t t s,@CC_FOR_BUILD@,$CC_FOR_BUILD,;t t s,@INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t @@ -7596,8 +8752,11 @@ s,@SHOBJ_LIBS@,$SHOBJ_LIBS,;t t s,@SHOBJ_STATUS@,$SHOBJ_STATUS,;t t s,@SHLIB_STATUS@,$SHLIB_STATUS,;t t s,@SHLIB_XLDFLAGS@,$SHLIB_XLDFLAGS,;t t +s,@SHLIB_DOT@,$SHLIB_DOT,;t t +s,@SHLIB_LIBPREF@,$SHLIB_LIBPREF,;t t s,@SHLIB_LIBSUFF@,$SHLIB_LIBSUFF,;t t s,@SHLIB_LIBVERSION@,$SHLIB_LIBVERSION,;t t +s,@SHLIB_DLLVERSION@,$SHLIB_DLLVERSION,;t t s,@SHLIB_LIBS@,$SHLIB_LIBS,;t t s,@SHLIB_MAJOR@,$SHLIB_MAJOR,;t t s,@SHLIB_MINOR@,$SHLIB_MINOR,;t t @@ -7605,6 +8764,7 @@ s,@STATIC_TARGET@,$STATIC_TARGET,;t t s,@SHARED_TARGET@,$SHARED_TARGET,;t t s,@STATIC_INSTALL_TARGET@,$STATIC_INSTALL_TARGET,;t t s,@SHARED_INSTALL_TARGET@,$SHARED_INSTALL_TARGET,;t t +s,@PURIFY@,$PURIFY,;t t s,@BUILD_DIR@,$BUILD_DIR,;t t s,@LOCAL_CFLAGS@,$LOCAL_CFLAGS,;t t s,@LOCAL_LDFLAGS@,$LOCAL_LDFLAGS,;t t @@ -7780,11 +8940,6 @@ esac *) ac_INSTALL=$ac_top_builddir$INSTALL ;; esac - if test x"$ac_file" != x-; then - { echo "$as_me:$LINENO: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - rm -f "$ac_file" - fi # Let's still pretend it is `configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ @@ -7823,6 +8978,12 @@ echo "$as_me: error: cannot find input file: $f" >&2;} fi;; esac done` || { (exit 1); exit 1; } + + if test x"$ac_file" != x-; then + { echo "$as_me:$LINENO: creating $ac_file" >&5 +echo "$as_me: creating $ac_file" >&6;} + rm -f "$ac_file" + fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF sed "$ac_vpsub diff --git a/readline/configure.in b/readline/configure.in index c436cca914a..6c7b8187f6e 100644 --- a/readline/configure.in +++ b/readline/configure.in @@ -4,38 +4,102 @@ 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 4.3, version 2.45, from autoconf version] AC_ACVERSION) -AC_INIT(readline, 4.3, bug-readline@gnu.org) +# 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.50) AC_CONFIG_SRCDIR(readline.h) +dnl GDB LOCAL dnl AC_CONFIG_AUX_DIR(./support) +AC_CONFIG_AUX_DIR(`cd $srcdir;pwd`/..) AC_CONFIG_HEADERS(config.h) dnl update the value of RL_READLINE_VERSION in readline.h when this changes -LIBVERSION=4.3 +LIBVERSION=5.1 AC_CANONICAL_HOST dnl configure defaults opt_curses=no +opt_purify=no dnl arguments to configure 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 +if test "$opt_purify" = yes; then + PURIFY="purify" +else + PURIFY= +fi + dnl option parsing for optional features +opt_multibyte=yes opt_static_libs=yes opt_shared_libs=no +AC_ARG_ENABLE(multibyte, AC_HELP_STRING([--enable-multibyte], [enable multibyte characters if OS supports them]), opt_multibyte=$enableval) +dnl 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 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 + ;; + *-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 + 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 + echo "" echo "Beginning configuration for readline-$LIBVERSION for ${host_cpu}-${host_vendor}-${host_os}" echo "" @@ -49,7 +113,8 @@ dnl AC_AIX AC_MINIX dnl BEGIN changes for CYGNUS cross-building for Cygwin - +dnl NOTE: Some of these changes may no longer be necessary. + dnl load up the cross-building cache file -- add more cases and cache dnl files as necessary if test "x$cross_compiling" = "xyes"; then @@ -73,14 +138,7 @@ if test "x$cross_compiling" = "xyes"; then unset cross_cache fi 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)' @@ -115,19 +173,29 @@ 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(fcntl kill lstat memmove putenv select setenv setlocale \ - strcasecmp strpbrk tcgetattr vsnprintf isascii isxdigit \ - getpwnam getpwent getpwuid) +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 strings.h \ - limits.h sys/ptem.h sys/pte.h sys/stream.h sys/select.h \ - termcap.h termios.h termio.h sys/file.h locale.h memory.h \ - pwd.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) + +AC_CHECK_HEADERS(sys/ptem.h,,, +[[ +#if HAVE_SYS_STREAM_H +# include <sys/stream.h> +#endif +]]) BASH_SYS_SIGNAL_VINTAGE BASH_SYS_REINSTALL_SIGHANDLERS @@ -135,6 +203,7 @@ BASH_SYS_REINSTALL_SIGHANDLERS BASH_FUNC_POSIX_SETJMP BASH_FUNC_LSTAT BASH_FUNC_STRCOLL +BASH_FUNC_CTYPE_NONASCII BASH_CHECK_GETPW_FUNCS @@ -179,7 +248,13 @@ esac # if test -f ${srcdir}/support/shobj-conf; then AC_MSG_CHECKING(configuration for building shared libraries) - eval `${CONFIG_SHELL-/bin/sh} ${srcdir}/support/shobj-conf -C "${CC}" -c ${host_cpu} -o ${host_os} -v ${host_vendor}` + 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) @@ -189,8 +264,11 @@ if test -f ${srcdir}/support/shobj-conf; then 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) @@ -227,6 +305,12 @@ 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) diff --git a/readline/display.c b/readline/display.c index b9bb2d3e8ac..08580987712 100644 --- a/readline/display.c +++ b/readline/display.c @@ -1,6 +1,6 @@ /* display.c -- readline redisplay facility. */ -/* 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. @@ -122,16 +122,24 @@ rl_voidfunc_t *rl_redisplay_function = rl_redisplay; int rl_display_fixed = 0; int _rl_suppress_redisplay = 0; +int _rl_want_redisplay = 0; /* The stuff that gets printed out before the actual text of the line. This is usually pointing to rl_prompt. */ char *rl_display_prompt = (char *)NULL; /* Pseudo-global variables declared here. */ + /* The visible cursor position. If you print some text, adjust this. */ +/* NOTE: _rl_last_c_pos is used as a buffer index when not in a locale + supporting multibyte characters, and an absolute cursor position when + in such a locale. This is an artifact of the donated multibyte support. + Care must be taken when modifying its value. */ int _rl_last_c_pos = 0; int _rl_last_v_pos = 0; +static int cpos_adjusted; + /* Number of lines currently on screen minus 1. */ int _rl_vis_botlin = 0; @@ -182,12 +190,27 @@ static int prompt_invis_chars_first_line; static int prompt_last_screen_line; +static int prompt_physical_chars; + +/* Variables to save and restore prompt and display information. */ + +/* These are getting numerous enough that it's time to create a struct. */ + +static char *saved_local_prompt; +static char *saved_local_prefix; +static int saved_last_invisible; +static int saved_visible_length; +static int saved_prefix_length; +static int saved_invis_chars_first_line; +static int saved_physical_chars; + /* Expand the prompt string S and return the number of visible characters in *LP, if LP is not null. This is currently more-or-less a placeholder for expansion. LIP, if non-null is a place to store the index of the last invisible character in the returned string. NIFLP, if non-zero, is a place to store the number of invisible characters in - the first prompt line. */ + the first prompt line. The previous are used as byte counts -- indexes + into a character buffer. */ /* Current implementation: \001 (^A) start non-visible characters @@ -197,19 +220,25 @@ static int prompt_last_screen_line; \002 are assumed to be `visible'. */ static char * -expand_prompt (pmt, lp, lip, niflp) +expand_prompt (pmt, lp, lip, niflp, vlp) char *pmt; - int *lp, *lip, *niflp; + int *lp, *lip, *niflp, *vlp; { char *r, *ret, *p; - int l, rl, last, ignoring, ninvis, invfl; + int l, rl, last, ignoring, ninvis, invfl, invflset, ind, pind, physchars; /* Short-circuit if we can. */ - if (strchr (pmt, RL_PROMPT_START_IGNORE) == 0) + if ((MB_CUR_MAX <= 1 || rl_byte_oriented) && strchr (pmt, RL_PROMPT_START_IGNORE) == 0) { r = savestring (pmt); if (lp) *lp = strlen (r); + if (lip) + *lip = 0; + if (niflp) + *niflp = 0; + if (vlp) + *vlp = lp ? *lp : strlen (r); return r; } @@ -217,8 +246,9 @@ expand_prompt (pmt, lp, lip, niflp) r = ret = (char *)xmalloc (l + 1); invfl = 0; /* invisible chars in first line of prompt */ + invflset = 0; /* we only want to set invfl once */ - for (rl = ignoring = last = ninvis = 0, p = pmt; p && *p; p++) + for (rl = ignoring = last = ninvis = physchars = 0, p = pmt; p && *p; p++) { /* This code strips the invisible character string markers RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE */ @@ -230,18 +260,47 @@ expand_prompt (pmt, lp, lip, niflp) else if (ignoring && *p == RL_PROMPT_END_IGNORE) { ignoring = 0; - last = r - ret - 1; + if (p[-1] != RL_PROMPT_START_IGNORE) + last = r - ret - 1; continue; } else { - *r++ = *p; - if (!ignoring) - rl++; +#if defined (HANDLE_MULTIBYTE) + if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + { + pind = p - pmt; + ind = _rl_find_next_mbchar (pmt, pind, 1, MB_FIND_NONZERO); + l = ind - pind; + while (l--) + *r++ = *p++; + if (!ignoring) + { + rl += ind - pind; + physchars += _rl_col_width (pmt, pind, ind); + } + else + ninvis += ind - pind; + p--; /* compensate for later increment */ + } else - ninvis++; - if (rl == _rl_screenwidth) - invfl = ninvis; +#endif + { + *r++ = *p; + if (!ignoring) + { + rl++; /* visible length byte counter */ + physchars++; + } + else + ninvis++; /* invisible chars byte counter */ + } + + if (invflset == 0 && rl >= _rl_screenwidth) + { + invfl = ninvis; + invflset = 1; + } } } @@ -255,6 +314,8 @@ expand_prompt (pmt, lp, lip, niflp) *lip = last; if (niflp) *niflp = invfl; + if (vlp) + *vlp = physchars; return ret; } @@ -266,7 +327,7 @@ _rl_strip_prompt (pmt) { char *ret; - ret = expand_prompt (pmt, (int *)NULL, (int *)NULL, (int *)NULL); + ret = expand_prompt (pmt, (int *)NULL, (int *)NULL, (int *)NULL, (int *)NULL); return ret; } @@ -299,7 +360,8 @@ rl_expand_prompt (prompt) FREE (local_prompt_prefix); local_prompt = local_prompt_prefix = (char *)0; - prompt_last_invisible = prompt_visible_length = 0; + prompt_last_invisible = prompt_invis_chars_first_line = 0; + prompt_visible_length = prompt_physical_chars = 0; if (prompt == 0 || *prompt == 0) return (0); @@ -310,7 +372,8 @@ rl_expand_prompt (prompt) /* The prompt is only one logical line, though it might wrap. */ local_prompt = expand_prompt (prompt, &prompt_visible_length, &prompt_last_invisible, - &prompt_invis_chars_first_line); + &prompt_invis_chars_first_line, + &prompt_physical_chars); local_prompt_prefix = (char *)0; return (prompt_visible_length); } @@ -320,13 +383,15 @@ rl_expand_prompt (prompt) t = ++p; local_prompt = expand_prompt (p, &prompt_visible_length, &prompt_last_invisible, - &prompt_invis_chars_first_line); + (int *)NULL, + &prompt_physical_chars); c = *t; *t = '\0'; /* The portion of the prompt string up to and including the final newline is now null-terminated. */ local_prompt_prefix = expand_prompt (prompt, &prompt_prefix_length, (int *)NULL, - &prompt_invis_chars_first_line); + &prompt_invis_chars_first_line, + (int *)NULL); *t = c; return (prompt_prefix_length); } @@ -384,8 +449,8 @@ rl_redisplay () { register int in, out, c, linenum, cursor_linenum; register char *line; - int c_pos, inv_botlin, lb_botlin, lb_linenum; - int newlines, lpos, temp; + int c_pos, inv_botlin, lb_botlin, lb_linenum, o_cpos; + int newlines, lpos, temp, modmark, n0, num; char *prompt_this_line; #if defined (HANDLE_MULTIBYTE) wchar_t wc; @@ -401,7 +466,7 @@ rl_redisplay () if (!rl_display_prompt) rl_display_prompt = ""; - if (invisible_line == 0) + if (invisible_line == 0 || vis_lbreaks == 0) { init_line_structures (0); rl_on_new_line (); @@ -415,10 +480,12 @@ rl_redisplay () /* Mark the line as modified or not. We only do this for history lines. */ + modmark = 0; if (_rl_mark_modified_lines && current_history () && rl_undo_list) { line[out++] = '*'; line[out] = '\0'; + modmark = 1; } /* If someone thought that the redisplay was handled, but the currently @@ -472,7 +539,7 @@ rl_redisplay () } } - pmtlen = strlen (prompt_this_line); + prompt_physical_chars = pmtlen = strlen (prompt_this_line); temp = pmtlen + out + 2; if (temp >= line_size) { @@ -531,9 +598,15 @@ rl_redisplay () /* inv_lbreaks[i] is where line i starts in the buffer. */ inv_lbreaks[newlines = 0] = 0; +#if 0 lpos = out - wrap_offset; +#else + lpos = prompt_physical_chars + modmark; +#endif + #if defined (HANDLE_MULTIBYTE) memset (_rl_wrapped_line, 0, vis_lbsize); + num = 0; #endif /* prompt_invis_chars_first_line is the number of invisible characters in @@ -550,17 +623,34 @@ rl_redisplay () prompt_invis_chars_first_line variable could be made into an array saying how many invisible characters there are per line, but that's probably too much work for the benefit gained. How many people have - prompts that exceed two physical lines? */ - temp = ((newlines + 1) * _rl_screenwidth) + -#if 0 - ((newlines == 0) ? prompt_invis_chars_first_line : 0) + + prompts that exceed two physical lines? + Additional logic fix from Edward Catmur <ed@catmur.co.uk> */ +#if defined (HANDLE_MULTIBYTE) + n0 = num; + temp = local_prompt ? strlen (local_prompt) : 0; + while (num < temp) + { + if (_rl_col_width (local_prompt, n0, num) > _rl_screenwidth) + { + num = _rl_find_prev_mbchar (local_prompt, num, MB_FIND_ANY); + break; + } + num++; + } + temp = num + #else - ((newlines == 0 && local_prompt_prefix == 0) ? prompt_invis_chars_first_line : 0) + -#endif - ((newlines == 1) ? wrap_offset : 0); - + temp = ((newlines + 1) * _rl_screenwidth) + +#endif /* !HANDLE_MULTIBYTE */ + ((local_prompt_prefix == 0) ? ((newlines == 0) ? prompt_invis_chars_first_line + : ((newlines == 1) ? wrap_offset : 0)) + : ((newlines == 0) ? wrap_offset :0)); + inv_lbreaks[++newlines] = temp; +#if defined (HANDLE_MULTIBYTE) + lpos -= _rl_col_width (local_prompt, n0, num); +#else lpos -= _rl_screenwidth; +#endif } prompt_last_screen_line = newlines; @@ -590,7 +680,7 @@ rl_redisplay () #if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) { - if (wc_bytes == (size_t)-1 || wc_bytes == (size_t)-2) + if (MB_INVALIDCH (wc_bytes)) { /* Byte sequence is invalid or shortened. Assume that the first byte represents a character. */ @@ -599,12 +689,12 @@ rl_redisplay () wc_width = 1; memset (&ps, 0, sizeof (mbstate_t)); } - else if (wc_bytes == (size_t)0) + else if (MB_NULLWCH (wc_bytes)) break; /* Found '\0' */ else { temp = wcwidth (wc); - wc_width = (temp < 0) ? 1 : temp; + wc_width = (temp >= 0) ? temp : 1; } } #endif @@ -769,7 +859,7 @@ rl_redisplay () if (_rl_horizontal_scroll_mode == 0 && _rl_term_up && *_rl_term_up) { - int nleft, pos, changed_screen_line; + int nleft, pos, changed_screen_line, tx; if (!rl_display_fixed || forced_display) { @@ -800,9 +890,26 @@ rl_redisplay () /* For each line in the buffer, do the updating display. */ for (linenum = 0; linenum <= inv_botlin; linenum++) { + o_cpos = _rl_last_c_pos; + cpos_adjusted = 0; update_line (VIS_LINE(linenum), INV_LINE(linenum), linenum, VIS_LLEN(linenum), INV_LLEN(linenum), inv_botlin); + /* update_line potentially changes _rl_last_c_pos, but doesn't + take invisible characters into account, since _rl_last_c_pos + is an absolute cursor position in a multibyte locale. See + if compensating here is the right thing, or if we have to + change update_line itself. There is one case in which + update_line adjusts _rl_last_c_pos itself (so it can pass + _rl_move_cursor_relative accurate values); it communicates + this back by setting cpos_adjusted */ + if (linenum == 0 && (MB_CUR_MAX > 1 && rl_byte_oriented == 0) && + cpos_adjusted == 0 && + _rl_last_c_pos != o_cpos && + _rl_last_c_pos > wrap_offset && + o_cpos < prompt_last_invisible) + _rl_last_c_pos -= wrap_offset; + /* If this is the line with the prompt, we might need to compensate for invisible characters in the new line. Do this only if there is not more than one new line (which @@ -814,7 +921,10 @@ rl_redisplay () (wrap_offset > visible_wrap_offset) && (_rl_last_c_pos < visible_first_line_len)) { - nleft = _rl_screenwidth + wrap_offset - _rl_last_c_pos; + if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + nleft = _rl_screenwidth - _rl_last_c_pos; + else + nleft = _rl_screenwidth + wrap_offset - _rl_last_c_pos; if (nleft) _rl_clear_to_eol (nleft); } @@ -850,7 +960,7 @@ rl_redisplay () the physical cursor position on the screen stays the same, but the buffer position needs to be adjusted to account for invisible characters. */ - if (cursor_linenum == 0 && wrap_offset) + if ((MB_CUR_MAX == 1 || rl_byte_oriented) && cursor_linenum == 0 && wrap_offset) _rl_last_c_pos += wrap_offset; } @@ -871,7 +981,7 @@ rl_redisplay () #endif _rl_output_some_chars (local_prompt, nleft); if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - _rl_last_c_pos = _rl_col_width(local_prompt, 0, nleft); + _rl_last_c_pos = _rl_col_width (local_prompt, 0, nleft) - wrap_offset; else _rl_last_c_pos = nleft; } @@ -883,18 +993,31 @@ rl_redisplay () start of the line and the cursor position. */ nleft = c_pos - pos; + /* NLEFT is now a number of characters in a buffer. When in a + multibyte locale, however, _rl_last_c_pos is an absolute cursor + position that doesn't take invisible characters in the prompt + into account. We use a fudge factor to compensate. */ + /* Since _rl_backspace() doesn't know about invisible characters in the prompt, and there's no good way to tell it, we compensate for those characters here and call _rl_backspace() directly. */ if (wrap_offset && cursor_linenum == 0 && nleft < _rl_last_c_pos) { - _rl_backspace (_rl_last_c_pos - nleft); if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - _rl_last_c_pos = _rl_col_width (&visible_line[pos], 0, nleft); + tx = _rl_col_width (&visible_line[pos], 0, nleft) - visible_wrap_offset; else - _rl_last_c_pos = nleft; + tx = nleft; + if (_rl_last_c_pos > tx) + { + _rl_backspace (_rl_last_c_pos - tx); /* XXX */ + _rl_last_c_pos = tx; + } } + /* We need to note that in a multibyte locale we are dealing with + _rl_last_c_pos as an absolute cursor position, but moving to a + point specified by a buffer position (NLEFT) that doesn't take + invisible characters into account. */ if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) _rl_move_cursor_relative (nleft, &invisible_line[pos]); else if (nleft != _rl_last_c_pos) @@ -1053,7 +1176,10 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) the exact cursor position and cut-and-paste with certain terminal emulators. In this calculation, TEMP is the physical screen position of the cursor. */ - temp = _rl_last_c_pos - W_OFFSET(_rl_last_v_pos, visible_wrap_offset); + if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + temp = _rl_last_c_pos; + else + temp = _rl_last_c_pos - W_OFFSET(_rl_last_v_pos, visible_wrap_offset); if (temp == _rl_screenwidth && _rl_term_autowrap && !_rl_horizontal_scroll_mode && _rl_last_v_pos == current_line - 1) { @@ -1073,12 +1199,12 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) memset (&ps, 0, sizeof (mbstate_t)); ret = mbrtowc (&wc, new, MB_CUR_MAX, &ps); - if (ret == (size_t)-1 || ret == (size_t)-2) + if (MB_INVALIDCH (ret)) { tempwidth = 1; ret = 1; } - else if (ret == 0) + else if (MB_NULLWCH (ret)) tempwidth = 0; else tempwidth = wcwidth (wc); @@ -1095,7 +1221,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) ret = mbrtowc (&wc, old, MB_CUR_MAX, &ps); if (ret != 0 && bytes != 0) { - if (ret == (size_t)-1 || ret == (size_t)-2) + if (MB_INVALIDCH (ret)) memmove (old+bytes, old+1, strlen (old+1)); else memmove (old+bytes, old+ret, strlen (old+ret)); @@ -1118,7 +1244,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) putc (new[0], rl_outstream); else putc (' ', rl_outstream); - _rl_last_c_pos = 1; /* XXX */ + _rl_last_c_pos = 1; _rl_last_v_pos++; if (old[0] && new[0]) old[0] = new[0]; @@ -1130,18 +1256,37 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) #if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) { - memset (&ps_new, 0, sizeof(mbstate_t)); - memset (&ps_old, 0, sizeof(mbstate_t)); - - new_offset = old_offset = 0; - for (ofd = old, nfd = new; - (ofd - old < omax) && *ofd && - _rl_compare_chars(old, old_offset, &ps_old, new, new_offset, &ps_new); ) + /* See if the old line is a subset of the new line, so that the + only change is adding characters. */ + temp = (omax < nmax) ? omax : nmax; + if (memcmp (old, new, temp) == 0) { - old_offset = _rl_find_next_mbchar (old, old_offset, 1, MB_FIND_ANY); - new_offset = _rl_find_next_mbchar (new, new_offset, 1, MB_FIND_ANY); - ofd = old + old_offset; - nfd = new + new_offset; + ofd = old + temp; + nfd = new + temp; + } + else + { + memset (&ps_new, 0, sizeof(mbstate_t)); + memset (&ps_old, 0, sizeof(mbstate_t)); + + if (omax == nmax && STREQN (new, old, omax)) + { + ofd = old + omax; + nfd = new + nmax; + } + else + { + new_offset = old_offset = 0; + for (ofd = old, nfd = new; + (ofd - old < omax) && *ofd && + _rl_compare_chars(old, old_offset, &ps_old, new, new_offset, &ps_new); ) + { + old_offset = _rl_find_next_mbchar (old, old_offset, 1, MB_FIND_ANY); + new_offset = _rl_find_next_mbchar (new, new_offset, 1, MB_FIND_ANY); + ofd = old + old_offset; + nfd = new + new_offset; + } + } } } else @@ -1173,8 +1318,11 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) memset (&ps_old, 0, sizeof (mbstate_t)); memset (&ps_new, 0, sizeof (mbstate_t)); +#if 0 + /* On advice from jir@yamato.ibm.com */ _rl_adjust_point (old, ols - old, &ps_old); _rl_adjust_point (new, nls - new, &ps_new); +#endif if (_rl_compare_chars (old, ols - old, &ps_old, new, nls - new, &ps_new) == 0) break; @@ -1237,7 +1385,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) if (_rl_last_v_pos != current_line) { _rl_move_vert (current_line); - if (current_line == 0 && visible_wrap_offset) + if ((MB_CUR_MAX == 1 || rl_byte_oriented) && current_line == 0 && visible_wrap_offset) _rl_last_c_pos += visible_wrap_offset; } @@ -1266,7 +1414,12 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) #endif _rl_output_some_chars (local_prompt, lendiff); if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - _rl_last_c_pos = _rl_col_width (local_prompt, 0, lendiff); + { + /* We take wrap_offset into account here so we can pass correct + information to _rl_move_cursor_relative. */ + _rl_last_c_pos = _rl_col_width (local_prompt, 0, lendiff) - wrap_offset; + cpos_adjusted = 1; + } else _rl_last_c_pos = lendiff; } @@ -1328,7 +1481,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) insert_some_chars (nfd, lendiff, col_lendiff); _rl_last_c_pos += col_lendiff; } - else if (*ols == 0) + else if ((MB_CUR_MAX == 1 || rl_byte_oriented != 0) && *ols == 0 && lendiff > 0) { /* At the end of a line the characters do not have to be "inserted". They can just be placed on the screen. */ @@ -1351,7 +1504,11 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) if ((temp - lendiff) > 0) { _rl_output_some_chars (nfd + lendiff, temp - lendiff); -#if 0 +#if 1 + /* XXX -- this bears closer inspection. Fixes a redisplay bug + reported against bash-3.0-alpha by Andreas Schwab involving + multibyte characters and prompt strings with invisible + characters, but was previously disabled. */ _rl_last_c_pos += _rl_col_width (nfd+lendiff, 0, temp-col_lendiff); #else _rl_last_c_pos += _rl_col_width (nfd+lendiff, 0, temp-lendiff); @@ -1363,6 +1520,10 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) /* cannot insert chars, write to EOL */ _rl_output_some_chars (nfd, temp); _rl_last_c_pos += col_temp; + /* If we're in a multibyte locale and were before the last invisible + char in the current line (which implies we just output some invisible + characters) we need to adjust _rl_last_c_pos, since it represents + a physical character position. */ } } else /* Delete characters from line. */ @@ -1394,7 +1555,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) if (temp > 0) { _rl_output_some_chars (nfd, temp); - _rl_last_c_pos += col_temp; + _rl_last_c_pos += col_temp; /* XXX */ } lendiff = (oe - old) - (ne - new); if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) @@ -1430,12 +1591,13 @@ rl_on_new_line () /* Tell the update routines that we have moved onto a new line with the prompt already displayed. Code originally from the version of readline - distributed with CLISP. */ + distributed with CLISP. rl_expand_prompt must have already been called + (explicitly or implicitly). This still doesn't work exactly right. */ int rl_on_new_line_with_prompt () { int prompt_size, i, l, real_screenwidth, newlines; - char *prompt_last_line; + char *prompt_last_line, *lprompt; /* Initialize visible_line and invisible_line to ensure that they can hold the already-displayed prompt. */ @@ -1444,8 +1606,9 @@ rl_on_new_line_with_prompt () /* Make sure the line structures hold the already-displayed prompt for redisplay. */ - strcpy (visible_line, rl_prompt); - strcpy (invisible_line, rl_prompt); + lprompt = local_prompt ? local_prompt : rl_prompt; + strcpy (visible_line, lprompt); + strcpy (invisible_line, lprompt); /* If the prompt contains newlines, take the last tail. */ prompt_last_line = strrchr (rl_prompt, '\n'); @@ -1454,7 +1617,7 @@ rl_on_new_line_with_prompt () l = strlen (prompt_last_line); if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - _rl_last_c_pos = _rl_col_width (prompt_last_line, 0, l); + _rl_last_c_pos = _rl_col_width (prompt_last_line, 0, l); /* XXX */ else _rl_last_c_pos = l; @@ -1480,6 +1643,8 @@ rl_on_new_line_with_prompt () vis_lbreaks[newlines] = l; visible_wrap_offset = 0; + rl_display_prompt = rl_prompt; /* XXX - make sure it's set */ + return 0; } @@ -1501,6 +1666,8 @@ rl_forced_update_display () } /* Move the cursor from _rl_last_c_pos to NEW, which are buffer indices. + (Well, when we don't have multibyte characters, _rl_last_c_pos is a + buffer index.) DATA is the contents of the screen line of interest; i.e., where the movement is being done. */ void @@ -1509,28 +1676,40 @@ _rl_move_cursor_relative (new, data) const char *data; { register int i; + int woff; /* number of invisible chars on current line */ + int cpos, dpos; /* current and desired cursor positions */ - /* If we don't have to do anything, then return. */ + woff = W_OFFSET (_rl_last_v_pos, wrap_offset); + cpos = _rl_last_c_pos; #if defined (HANDLE_MULTIBYTE) /* If we have multibyte characters, NEW is indexed by the buffer point in a multibyte string, but _rl_last_c_pos is the display position. In this case, NEW's display position is not obvious and must be - calculated. */ - if (MB_CUR_MAX == 1 || rl_byte_oriented) + calculated. We need to account for invisible characters in this line, + as long as we are past them and they are counted by _rl_col_width. */ + if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) { - if (_rl_last_c_pos == new) - return; + dpos = _rl_col_width (data, 0, new); + if (dpos > woff) + dpos -= woff; } - else if (_rl_last_c_pos == _rl_col_width (data, 0, new)) - return; -#else - if (_rl_last_c_pos == new) return; + else #endif + dpos = new; + + /* If we don't have to do anything, then return. */ + if (cpos == dpos) + return; /* It may be faster to output a CR, and then move forwards instead of moving backwards. */ /* i == current physical cursor position. */ - i = _rl_last_c_pos - W_OFFSET(_rl_last_v_pos, visible_wrap_offset); +#if defined (HANDLE_MULTIBYTE) + if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + i = _rl_last_c_pos; + else +#endif + i = _rl_last_c_pos - woff; if (new == 0 || CR_FASTER (new, _rl_last_c_pos) || (_rl_term_autowrap && i == _rl_screenwidth)) { @@ -1539,10 +1718,10 @@ _rl_move_cursor_relative (new, data) #else tputs (_rl_term_cr, 1, _rl_output_character_function); #endif /* !__MSDOS__ */ - _rl_last_c_pos = 0; + cpos = _rl_last_c_pos = 0; } - if (_rl_last_c_pos < new) + if (cpos < dpos) { /* Move the cursor forward. We do it by printing the command to move the cursor forward if there is one, else print that @@ -1556,31 +1735,11 @@ _rl_move_cursor_relative (new, data) #if defined (HACK_TERMCAP_MOTION) if (_rl_term_forward_char) { - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - int width; - width = _rl_col_width (data, _rl_last_c_pos, new); - for (i = 0; i < width; i++) - tputs (_rl_term_forward_char, 1, _rl_output_character_function); - } - else - { - for (i = _rl_last_c_pos; i < new; i++) - tputs (_rl_term_forward_char, 1, _rl_output_character_function); - } - } - else if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - tputs (_rl_term_cr, 1, _rl_output_character_function); - for (i = 0; i < new; i++) - putc (data[i], rl_outstream); + for (i = cpos; i < dpos; i++) + tputs (_rl_term_forward_char, 1, _rl_output_character_function); } else - for (i = _rl_last_c_pos; i < new; i++) - putc (data[i], rl_outstream); - -#else /* !HACK_TERMCAP_MOTION */ - +#endif /* HACK_TERMCAP_MOTION */ if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) { tputs (_rl_term_cr, 1, _rl_output_character_function); @@ -1588,32 +1747,20 @@ _rl_move_cursor_relative (new, data) putc (data[i], rl_outstream); } else - for (i = _rl_last_c_pos; i < new; i++) + for (i = cpos; i < new; i++) putc (data[i], rl_outstream); - -#endif /* !HACK_TERMCAP_MOTION */ - } + #if defined (HANDLE_MULTIBYTE) /* NEW points to the buffer point, but _rl_last_c_pos is the display point. The byte length of the string is probably bigger than the column width of the string, which means that if NEW == _rl_last_c_pos, then NEW's display point is less than _rl_last_c_pos. */ - else if (_rl_last_c_pos >= new) -#else - else if (_rl_last_c_pos > new) #endif - { - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - _rl_backspace (_rl_last_c_pos - _rl_col_width (data, 0, new)); - else - _rl_backspace (_rl_last_c_pos - new); - } + else if (cpos > dpos) + _rl_backspace (cpos - dpos); - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - _rl_last_c_pos = _rl_col_width (data, 0, new); - else - _rl_last_c_pos = new; + _rl_last_c_pos = dpos; } /* PWP: move the cursor up or down. */ @@ -1711,9 +1858,9 @@ rl_character_len (c, pos) return ((ISPRINT (uc)) ? 1 : 2); } - /* How to print things in the "echo-area". The prompt is treated as a mini-modeline. */ +static int msg_saved_prompt = 0; #if defined (USE_VARARGS) int @@ -1744,8 +1891,19 @@ rl_message (va_alist) #endif va_end (args); + if (saved_local_prompt == 0) + { + rl_save_prompt (); + msg_saved_prompt = 1; + } rl_display_prompt = msg_buf; + local_prompt = expand_prompt (msg_buf, &prompt_visible_length, + &prompt_last_invisible, + &prompt_invis_chars_first_line, + &prompt_physical_chars); + local_prompt_prefix = (char *)NULL; (*rl_redisplay_function) (); + return 0; } #else /* !USE_VARARGS */ @@ -1755,8 +1913,20 @@ rl_message (format, arg1, arg2) { sprintf (msg_buf, format, arg1, arg2); msg_buf[sizeof(msg_buf) - 1] = '\0'; /* overflow? */ + rl_display_prompt = msg_buf; + if (saved_local_prompt == 0) + { + rl_save_prompt (); + msg_saved_prompt = 1; + } + local_prompt = expand_prompt (msg_buf, &prompt_visible_length, + &prompt_last_invisible, + &prompt_invis_chars_first_line, + &prompt_physical_chars); + local_prompt_prefix = (char *)NULL; (*rl_redisplay_function) (); + return 0; } #endif /* !USE_VARARGS */ @@ -1766,6 +1936,11 @@ int rl_clear_message () { rl_display_prompt = rl_prompt; + if (msg_saved_prompt) + { + rl_restore_prompt (); + msg_saved_prompt = 0; + } (*rl_redisplay_function) (); return 0; } @@ -1780,21 +1955,20 @@ rl_reset_line_state () return 0; } -static char *saved_local_prompt; -static char *saved_local_prefix; -static int saved_last_invisible; -static int saved_visible_length; - void rl_save_prompt () { saved_local_prompt = local_prompt; saved_local_prefix = local_prompt_prefix; + saved_prefix_length = prompt_prefix_length; saved_last_invisible = prompt_last_invisible; saved_visible_length = prompt_visible_length; + saved_invis_chars_first_line = prompt_invis_chars_first_line; + saved_physical_chars = prompt_physical_chars; local_prompt = local_prompt_prefix = (char *)0; - prompt_last_invisible = prompt_visible_length = 0; + prompt_last_invisible = prompt_visible_length = prompt_prefix_length = 0; + prompt_invis_chars_first_line = prompt_physical_chars = 0; } void @@ -1805,8 +1979,16 @@ rl_restore_prompt () local_prompt = saved_local_prompt; local_prompt_prefix = saved_local_prefix; + prompt_prefix_length = saved_prefix_length; prompt_last_invisible = saved_last_invisible; prompt_visible_length = saved_visible_length; + prompt_invis_chars_first_line = saved_invis_chars_first_line; + prompt_physical_chars = saved_physical_chars; + + /* can test saved_local_prompt to see if prompt info has been saved. */ + saved_local_prompt = saved_local_prefix = (char *)0; + saved_last_invisible = saved_visible_length = saved_prefix_length = 0; + saved_invis_chars_first_line = saved_physical_chars = 0; } char * @@ -1814,11 +1996,15 @@ _rl_make_prompt_for_search (pchar) int pchar; { int len; - char *pmt; + char *pmt, *p; rl_save_prompt (); - if (saved_local_prompt == 0) + /* We've saved the prompt, and can do anything with the various prompt + strings we need before they're restored. We want the unexpanded + portion of the prompt string after any final newline. */ + p = rl_prompt ? strrchr (rl_prompt, '\n') : 0; + if (p == 0) { len = (rl_prompt && *rl_prompt) ? strlen (rl_prompt) : 0; pmt = (char *)xmalloc (len + 2); @@ -1829,16 +2015,17 @@ _rl_make_prompt_for_search (pchar) } else { - len = *saved_local_prompt ? strlen (saved_local_prompt) : 0; + p++; + len = strlen (p); pmt = (char *)xmalloc (len + 2); if (len) - strcpy (pmt, saved_local_prompt); + strcpy (pmt, p); pmt[len] = pchar; pmt[len+1] = '\0'; - local_prompt = savestring (pmt); - prompt_last_invisible = saved_last_invisible; - prompt_visible_length = saved_visible_length + 1; - } + } + + /* will be overwritten by expand_prompt, called from rl_message */ + prompt_physical_chars = saved_physical_chars + 1; return pmt; } @@ -1907,9 +2094,9 @@ insert_some_chars (string, count, col) char *string; int count, col; { -#if defined(__MSDOS__) || defined(__MINGW32__) +#if defined (__MSDOS__) || defined (__MINGW32__) _rl_output_some_chars (string, count); -#else /* !__MSDOS__ && !__MINGW32__ */ +#else /* DEBUGGING */ if (MB_CUR_MAX == 1 || rl_byte_oriented) if (count != col) @@ -1948,7 +2135,7 @@ insert_some_chars (string, count, col) if (_rl_term_ei && *_rl_term_ei) tputs (_rl_term_ei, 1, _rl_output_character_function); } -#endif /* !__MSDOS__ */ +#endif /* __MSDOS__ || __MINGW32__ */ } /* Delete COUNT characters from the display line. */ @@ -1959,7 +2146,7 @@ delete_chars (count) if (count > _rl_screenwidth) /* XXX */ return; -#if !defined(__MSDOS__) && !defined(__MINGW32__) +#if !defined (__MSDOS__) && !defined (__MINGW32__) if (_rl_term_DC && *_rl_term_DC) { char *buffer; @@ -2028,32 +2215,22 @@ static void redraw_prompt (t) char *t; { - char *oldp, *oldl, *oldlprefix; - int oldlen, oldlast, oldplen, oldninvis; + char *oldp; - /* Geez, I should make this a struct. */ oldp = rl_display_prompt; - oldl = local_prompt; - oldlprefix = local_prompt_prefix; - oldlen = prompt_visible_length; - oldplen = prompt_prefix_length; - oldlast = prompt_last_invisible; - oldninvis = prompt_invis_chars_first_line; + rl_save_prompt (); rl_display_prompt = t; local_prompt = expand_prompt (t, &prompt_visible_length, &prompt_last_invisible, - &prompt_invis_chars_first_line); + &prompt_invis_chars_first_line, + &prompt_physical_chars); local_prompt_prefix = (char *)NULL; + rl_forced_update_display (); rl_display_prompt = oldp; - local_prompt = oldl; - local_prompt_prefix = oldlprefix; - prompt_visible_length = oldlen; - prompt_prefix_length = oldplen; - prompt_last_invisible = oldlast; - prompt_invis_chars_first_line = oldninvis; + rl_restore_prompt(); } /* Redisplay the current line after a SIGWINCH is received. */ @@ -2163,7 +2340,7 @@ _rl_col_width (str, start, end) while (point < start) { tmp = mbrlen (str + point, max, &ps); - if ((size_t)tmp == (size_t)-1 || (size_t)tmp == (size_t)-2) + if (MB_INVALIDCH ((size_t)tmp)) { /* In this case, the bytes are invalid or too short to compose a multibyte character, so we assume that the first byte represents @@ -2175,8 +2352,8 @@ _rl_col_width (str, start, end) effect of mbstate is undefined. */ memset (&ps, 0, sizeof (mbstate_t)); } - else if (tmp == 0) - break; /* Found '\0' */ + else if (MB_NULLWCH (tmp)) + break; /* Found '\0' */ else { point += tmp; @@ -2192,7 +2369,7 @@ _rl_col_width (str, start, end) while (point < end) { tmp = mbrtowc (&wc, str + point, max, &ps); - if ((size_t)tmp == (size_t)-1 || (size_t)tmp == (size_t)-2) + if (MB_INVALIDCH ((size_t)tmp)) { /* In this case, the bytes are invalid or too short to compose a multibyte character, so we assume that the first byte represents @@ -2207,8 +2384,8 @@ _rl_col_width (str, start, end) effect of mbstate is undefined. */ memset (&ps, 0, sizeof (mbstate_t)); } - else if (tmp == 0) - break; /* Found '\0' */ + else if (MB_NULLWCH (tmp)) + break; /* Found '\0' */ else { point += tmp; diff --git a/readline/doc/ChangeLog.gdb b/readline/doc/ChangeLog.gdb index 1253d9c4aed..14d32f67c09 100644 --- a/readline/doc/ChangeLog.gdb +++ b/readline/doc/ChangeLog.gdb @@ -1,3 +1,7 @@ +2006-04-24 Daniel Jacobowitz <dan@codesourcery.com> + + Imported readline 5.1, and upstream patches 001-004. + 2003-09-14 Andrew Cagney <cagney@redhat.com> * history.0: Delete generated file. diff --git a/readline/doc/Makefile.in b/readline/doc/Makefile.in index 8a85ae17c8b..692a4e87db1 100644 --- a/readline/doc/Makefile.in +++ b/readline/doc/Makefile.in @@ -1,7 +1,7 @@ # This makefile for Readline library documentation is in -*- text -*- mode. # Emacs likes it that way. -# Copyright (C) 1996 Free Software Foundation, Inc. +# 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 @@ -52,14 +52,18 @@ TEXI2DVI = $(srcdir)/texi2dvi TEXI2HTML = $(srcdir)/texi2html QUIETPS = #set this to -q to shut up dvips PAPERSIZE = letter -PSDPI = 300 # I don't have any 600-dpi printers +PSDPI = 600 DVIPS = dvips -D ${PSDPI} $(QUIETPS) -t ${PAPERSIZE} -o $@ # tricky -RLSRC = $(srcdir)/rlman.texinfo $(srcdir)/rluser.texinfo \ - $(srcdir)/rltech.texinfo $(srcdir)/manvers.texinfo \ - $(srcdir)/rluserman.texinfo -HISTSRC = $(srcdir)/hist.texinfo $(srcdir)/hsuser.texinfo \ - $(srcdir)/hstech.texinfo $(srcdir)/manvers.texinfo +# 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.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 @@ -72,39 +76,54 @@ 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 -INTERMEDIATE_OBJ = rlman.dvi hist.dvi rluserman.dvi +INTERMEDIATE_OBJ = rlman.dvi DIST_DOCS = $(DVIOBJ) $(PSOBJ) $(HTMLOBJ) $(INFOOBJ) $(TEXTOBJ) -.SUFFIXES: .0 .3 .ps .txt .dvi +.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 +info: $(INFOOBJ) +dvi: $(DVIOBJ) +ps: $(PSOBJ) +html: $(HTMLOBJ) +text: $(TEXTOBJ) +pdf: $(PDFOBJ) + readline.dvi: $(RLSRC) - TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/rlman.texinfo + TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/rlman.texi mv rlman.dvi readline.dvi readline.info: $(RLSRC) - $(MAKEINFO) --no-split -I $(TEXINPUTDIR) -o $@ $(srcdir)/rlman.texinfo + $(MAKEINFO) --no-split -I $(TEXINPUTDIR) -o $@ $(srcdir)/rlman.texi rluserman.dvi: $(RLSRC) - TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/rluserman.texinfo + TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/rluserman.texi rluserman.info: $(RLSRC) - $(MAKEINFO) --no-split -I $(TEXINPUTDIR) -o $@ $(srcdir)/rluserman.texinfo + $(MAKEINFO) --no-split -I $(TEXINPUTDIR) -o $@ $(srcdir)/rluserman.texi history.dvi: ${HISTSRC} - TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/hist.texinfo - mv hist.dvi history.dvi + TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/history.texi history.info: ${HISTSRC} - $(MAKEINFO) --no-split -I $(TEXINPUTDIR) -o $@ $(srcdir)/hist.texinfo + $(MAKEINFO) --no-split -I $(TEXINPUTDIR) -o $@ $(srcdir)/history.texi readline.ps: readline.dvi $(RM) $@ @@ -122,22 +141,15 @@ history.ps: 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.texinfo + $(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.texinfo + $(TEXI2HTML) -menu -monolithic -I $(TEXINPUTDIR) $(srcdir)/rluserman.texi history.html: ${HISTSRC} - $(TEXI2HTML) -menu -monolithic -I $(TEXINPUTDIR) $(srcdir)/hist.texinfo - sed -e 's:hist.html:history.html:g' hist.html > history.html - $(RM) hist.html - -info: $(INFOOBJ) -dvi: $(DVIOBJ) -ps: $(PSOBJ) -html: $(HTMLOBJ) -text: $(TEXTOBJ) + $(TEXI2HTML) -menu -monolithic -I $(TEXINPUTDIR) $(srcdir)/history.texi readline.0: readline.3 @@ -151,9 +163,14 @@ 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 *.cp *.fn *.ky *.log *.pg *.toc *.tp *.vr *.cps *.pgs \ - *.fns *.kys *.tps *.vrs *.bt *.bts *.o core *.core + $(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 @@ -169,6 +186,7 @@ maybe-clean: maintainer-clean: clean $(RM) $(DIST_DOCS) $(RM) $(INTERMEDIATE_OBJ) + $(RM) $(PDFOBJ) $(RM) Makefile installdirs: $(topdir)/support/mkdirs diff --git a/readline/doc/hist.texinfo b/readline/doc/hist.texinfo deleted file mode 100644 index 63ceb16e607..00000000000 --- a/readline/doc/hist.texinfo +++ /dev/null @@ -1,110 +0,0 @@ -\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 manvers.texinfo - -@ifinfo -@dircategory Libraries -@direntry -* History: (history). The GNU history library API -@end direntry - -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-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 History Library -@subtitle Edition @value{EDITION}, for @code{History 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 GNU History library, a programming tool that -provides a consistent user interface for recalling lines of previously -typed input. - -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 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. -* Concept Index:: Index of concepts described in this manual. -* Function and Variable Index:: Index of externally visible functions - and variables. -@end menu -@end ifinfo - -@syncodeindex fn vr - -@include hsuser.texinfo -@include hstech.texinfo - -@node Concept Index -@appendix Concept Index -@printindex cp - -@node Function and Variable Index -@appendix Function and Variable Index -@printindex vr - -@contents -@bye diff --git a/readline/doc/history.3 b/readline/doc/history.3 index ed0cb9f84e0..3ade839ff7d 100644 --- a/readline/doc/history.3 +++ b/readline/doc/history.3 @@ -6,9 +6,9 @@ .\" Case Western Reserve University .\" chet@ins.CWRU.Edu .\" -.\" Last Change: Thu Jan 31 16:08:07 EST 2002 +.\" Last Change: Thu Jul 31 08:46:08 EDT 2003 .\" -.TH HISTORY 3 "2002 January 31" "GNU History 4.3" +.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. @@ -249,6 +249,10 @@ 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. @@ -292,6 +296,7 @@ declared as follows: .nf typedef struct _hist_entry { char *line; + char *timestamp; histdata_t data; } HIST_ENTRY; .fi @@ -345,14 +350,24 @@ parameters managing the list itself. 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 you can dispose of the data. In the case +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" @@ -394,6 +409,9 @@ Return the history entry at position \fIoffset\fP, starting from 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 @@ -551,6 +569,11 @@ The number of entries currently stored in the history list. 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. diff --git a/readline/doc/history.pdf b/readline/doc/history.pdf Binary files differdeleted file mode 100644 index 2ed10c44da0..00000000000 --- a/readline/doc/history.pdf +++ /dev/null diff --git a/readline/doc/hstech.texinfo b/readline/doc/hstech.texinfo deleted file mode 100644 index 949444668fc..00000000000 --- a/readline/doc/hstech.texinfo +++ /dev/null @@ -1,550 +0,0 @@ -@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; - 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 {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 {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 (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 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 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_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 {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 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 diff --git a/readline/doc/hsuser.texinfo b/readline/doc/hsuser.texinfo deleted file mode 100644 index 418bfa8eff6..00000000000 --- a/readline/doc/hsuser.texinfo +++ /dev/null @@ -1,437 +0,0 @@ -@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. - -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. -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{!} -Start a history substitution, except when followed by a space, tab, -the end of the line, @samp{=} or @samp{(}. - -@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 -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{&}. - -@end table diff --git a/readline/doc/inc-hist.texinfo b/readline/doc/inc-hist.texinfo index 37ed15f4dd1..b5ed3cb4830 100644 --- a/readline/doc/inc-hist.texinfo +++ b/readline/doc/inc-hist.texinfo @@ -1,7 +1,7 @@ @ignore This file documents the user interface to the GNU History library. -Copyright (C) 1988-1999 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 @@ -38,11 +38,10 @@ 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. -@c For -@c information on using the GNU History Library in your own programs, -@c @pxref{Programming with GNU History}. +For information on using the @sc{gnu} History Library in other programs, +see the @sc{gnu} Readline Library Manual. @end ifclear @ifset BashFeatures @@ -66,36 +65,39 @@ from a user's standpoint. It should be considered a user's guide. @cindex command history @cindex history list -When the @samp{-o history} option to the @code{set} builtin +When the @option{-o history} option to the @code{set} builtin is enabled (@pxref{The Set Builtin}), -the shell provides access to the @var{command history}, +the shell provides access to the @dfn{command history}, the list of commands previously typed. -The value of the @code{HISTSIZE} shell variable is used as the +The value of the @env{HISTSIZE} shell variable is used as the number of commands to save in a history list. -The text of the last @code{$HISTSIZE} +The text of the last @env{$HISTSIZE} commands (default 500) is saved. The shell stores each command in the history list prior to parameter and variable expansion but after history expansion is performed, subject to the values of the shell variables -@code{HISTIGNORE} and @code{HISTCONTROL}. +@env{HISTIGNORE} and @env{HISTCONTROL}. When the shell starts up, the history is initialized from the -file named by the @code{HISTFILE} variable (default @file{~/.bash_history}). -The file named by the value of @code{HISTFILE} is truncated, if +file named by the @env{HISTFILE} variable (default @file{~/.bash_history}). +The file named by the value of @env{HISTFILE} is truncated, if necessary, to contain no more than the number of lines specified by -the value of the @code{HISTFILESIZE} variable. +the value of the @env{HISTFILESIZE} variable. When an interactive shell exits, the last -@code{$HISTSIZE} lines are copied from the history list to the file -named by @code{$HISTFILE}. +@env{$HISTSIZE} lines are copied from the history list to the file +named by @env{$HISTFILE}. If the @code{histappend} shell option is set (@pxref{Bash Builtins}), the lines are appended to the history file, otherwise the history file is overwritten. -If @code{HISTFILE} +If @env{HISTFILE} is unset, or if the history file is unwritable, the history is not saved. After saving the history, the history file is truncated -to contain no more than @code{$HISTFILESIZE} -lines. If @code{HISTFILESIZE} is not set, no truncation is performed. +to contain no more than @env{$HISTFILESIZE} +lines. If @env{HISTFILESIZE} is not set, no truncation is performed. + +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. @@ -106,7 +108,7 @@ are available in each editing mode that provide access to the history list (@pxref{Commands For History}). The shell allows control over which commands are saved on the history -list. The @code{HISTCONTROL} and @code{HISTIGNORE} +list. The @env{HISTCONTROL} and @env{HISTIGNORE} variables may be set to cause the shell to save only a subset of the commands entered. The @code{cmdhist} @@ -142,15 +144,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 @@ -171,8 +173,14 @@ history -ps @var{arg} @end example With no options, display the history list with line numbers. -Lines prefixed with with a @samp{*} have been modified. +Lines prefixed with a @samp{*} have been modified. An argument of @var{n} lists only the last @var{n} lines. +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 @@ -212,10 +220,10 @@ the history list as a single entry. @end table -When any of the @samp{-w}, @samp{-r}, @samp{-a}, or @samp{-n} options is +When any of the @option{-w}, @option{-r}, @option{-a}, or @option{-n} options is used, if @var{filename} is given, then it is used as the history file. If not, then -the value of the @code{HISTFILE} variable is used. +the value of the @env{HISTFILE} variable is used. @end table @end ifset @@ -261,9 +269,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. @@ -289,8 +297,15 @@ history list. @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{(}. +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}. @@ -431,8 +446,12 @@ character on the input line. 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 diff --git a/readline/doc/manvers.texinfo b/readline/doc/manvers.texinfo deleted file mode 100644 index 1206cf0f235..00000000000 --- a/readline/doc/manvers.texinfo +++ /dev/null @@ -1,10 +0,0 @@ -@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 diff --git a/readline/doc/readline.3 b/readline/doc/readline.3 index afd6ba29362..90cd9971e8e 100644 --- a/readline/doc/readline.3 +++ b/readline/doc/readline.3 @@ -6,9 +6,9 @@ .\" Case Western Reserve University .\" chet@ins.CWRU.Edu .\" -.\" Last Change: Tue Jan 22 09:18:25 EST 2002 +.\" Last Change: Tue Sep 13 12:07:26 EDT 2005 .\" -.TH READLINE 3 "2002 January 22" "GNU Readline 4.3" +.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. @@ -34,8 +34,8 @@ readline \- get a line from a user with editing \fBreadline\fP (\fIconst char *prompt\fP); .fi .SH COPYRIGHT -.if n Readline is Copyright (C) 1989\-2002 by the Free Software Foundation, Inc. -.if t Readline is Copyright \(co 1989\-2002 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 @@ -328,6 +328,10 @@ Except where noted, readline variables can take the values or .B Off (without regard to case). +Unrecognized variable names are ignored. +When a variable value is read, empty or null values, "on" (case-insensitive), +and "1" are equivalent to \fBOn\fP. All other values are equivalent to +\fBOff\fP. The variables and their default values are: .PP .PD 0 @@ -338,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 @@ -360,7 +369,7 @@ 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 @@ -391,9 +400,9 @@ arrow keys. If set to \fBon\fP, tilde expansion is performed when readline attempts word completion. .TP -.B history-preserve-point +.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 retrived with \fBprevious-history\fP +same location on each history line retrieved with \fBprevious-history\fP or \fBnext-history\fP. .TP .B horizontal\-scroll\-mode (Off) @@ -465,6 +474,16 @@ 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 \fIstat\fP(2) is appended to the filename when listing possible @@ -681,6 +700,8 @@ With an argument 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\-_\^) @@ -689,6 +710,8 @@ 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 @@ -787,6 +810,11 @@ Word boundaries are the same as those used by \fBbackward\-word\fP. Kill the word behind point, using white space as a word boundary. The killed text is saved on the kill-ring. .TP +.B unix\-filename\-rubout +Kill the word behind point, using white space and the slash character +as the word boundaries. +The killed text is saved on the kill-ring. +.TP .B delete\-horizontal\-space (M\-\e) Delete all spaces and tabs around point. .TP @@ -868,7 +896,7 @@ with a single match from the list of possible completions. Repeated execution of \fBmenu\-complete\fP steps through the list of possible completions, inserting each match in turn. At the end of the list of completions, the bell is rung -(subject to the setting of \Bbell\-style\fP) +(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 @@ -979,7 +1007,7 @@ 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 diff --git a/readline/doc/readline.pdf b/readline/doc/readline.pdf Binary files differdeleted file mode 100644 index 7fc2dfeddaa..00000000000 --- a/readline/doc/readline.pdf +++ /dev/null diff --git a/readline/doc/rlman.texinfo b/readline/doc/rlman.texinfo deleted file mode 100644 index 1ffebad08a7..00000000000 --- a/readline/doc/rlman.texinfo +++ /dev/null @@ -1,108 +0,0 @@ -\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 manvers.texinfo - -@ifinfo -@dircategory Libraries -@direntry -* Readline: (readline). The GNU readline library API -@end direntry - -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-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 -@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 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 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. -* Programming with GNU Readline:: GNU Readline Programmer's Manual. -* Concept Index:: Index of concepts described in this manual. -* Function and Variable Index:: Index of externally visible functions - and variables. -@end menu -@end ifinfo - -@include rluser.texinfo -@include rltech.texinfo - -@node Concept Index -@unnumbered Concept Index -@printindex cp - -@node Function and Variable Index -@unnumbered Function and Variable Index -@printindex fn - -@contents -@bye diff --git a/readline/doc/rltech.texinfo b/readline/doc/rltech.texinfo deleted file mode 100644 index 037e824e28a..00000000000 --- a/readline/doc/rltech.texinfo +++ /dev/null @@ -1,2165 +0,0 @@ -@comment %**start of header (This is for running Texinfo on a region.) -@setfilename rltech.info -@comment %**end of header (This is for running Texinfo on a region.) -@setchapternewpage odd - -@ifinfo -This document describes the GNU Readline Library, a utility for aiding -in the consitency 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 Foundation. -@end ifinfo - -@node Programming with GNU Readline -@chapter Programming with GNU Readline - -This chapter describes the interface between the @sc{gnu} Readline Library and -other programs. If you are a programmer, and you wish to include the -features found in @sc{gnu} Readline -such as completion, line editing, and interactive history manipulation -in your own programs, this section is for you. - -@menu -* Basic Behavior:: Using the default behavior of Readline. -* Custom Functions:: Adding your own functions to Readline. -* Readline Variables:: Variables accessible to custom - functions. -* Readline Convenience Functions:: Functions which Readline supplies to - aid in writing your own custom - functions. -* Readline Signal Handling:: How Readline behaves when it receives signals. -* Custom Completers:: Supplanting or supplementing Readline's - completion functions. -@end menu - -@node Basic Behavior -@section Basic Behavior - -Many programs provide a command line interface, such as @code{mail}, -@code{ftp}, and @code{sh}. For such programs, the default behaviour of -Readline is sufficient. This section describes how to use Readline in -the simplest way possible, perhaps to replace calls in your code to -@code{gets()} or @code{fgets()}. - -@findex readline -@cindex readline, function - -The function @code{readline()} prints a prompt @var{prompt} -and then reads and returns a single line of text from the user. -If @var{prompt} is @code{NULL} or the empty string, no prompt is displayed. -The line @code{readline} returns is allocated with @code{malloc()}; -the caller should @code{free()} the line when it has finished with it. -The declaration for @code{readline} in ANSI C is - -@example -@code{char *readline (const char *@var{prompt});} -@end example - -@noindent -So, one might say -@example -@code{char *line = readline ("Enter a line: ");} -@end example -@noindent -in order to read a line of text from the user. -The line returned has the final newline removed, so only the -text remains. - -If @code{readline} encounters an @code{EOF} while reading the line, and the -line is empty at that point, then @code{(char *)NULL} is returned. -Otherwise, the line is ended just as if a newline had been typed. - -If you want the user to be able to get at the line later, (with -@key{C-p} for example), you must call @code{add_history()} to save the -line away in a @dfn{history} list of such lines. - -@example -@code{add_history (line)}; -@end example - -@noindent -For full details on the GNU History Library, see the associated manual. - -It is preferable to avoid saving empty lines on the history list, since -users rarely have a burning need to reuse a blank line. Here is -a function which usefully replaces the standard @code{gets()} library -function, and has the advantage of no static buffer to overflow: - -@example -/* A static variable for holding the line. */ -static char *line_read = (char *)NULL; - -/* Read a string, and return a pointer to it. - Returns NULL on EOF. */ -char * -rl_gets () -@{ - /* If the buffer has already been allocated, - return the memory to the free pool. */ - if (line_read) - @{ - free (line_read); - line_read = (char *)NULL; - @} - - /* Get a line from the user. */ - line_read = readline (""); - - /* If the line has any text in it, - save it on the history. */ - if (line_read && *line_read) - add_history (line_read); - - return (line_read); -@} -@end example - -This function gives the user the default behaviour of @key{TAB} -completion: completion on file names. If you do not want Readline to -complete on filenames, you can change the binding of the @key{TAB} key -with @code{rl_bind_key()}. - -@example -@code{int rl_bind_key (int @var{key}, rl_command_func_t *@var{function});} -@end example - -@code{rl_bind_key()} takes two arguments: @var{key} is the character that -you want to bind, and @var{function} is the address of the function to -call when @var{key} is pressed. Binding @key{TAB} to @code{rl_insert()} -makes @key{TAB} insert itself. -@code{rl_bind_key()} returns non-zero if @var{key} is not a valid -ASCII character code (between 0 and 255). - -Thus, to disable the default @key{TAB} behavior, the following suffices: -@example -@code{rl_bind_key ('\t', rl_insert);} -@end example - -This code should be executed once at the start of your program; you -might write a function called @code{initialize_readline()} which -performs this and other desired initializations, such as installing -custom completers (@pxref{Custom Completers}). - -@node Custom Functions -@section Custom Functions - -Readline provides many functions for manipulating the text of -the line, but it isn't possible to anticipate the needs of all -programs. This section describes the various functions and variables -defined within the Readline library which allow a user program to add -customized functionality to Readline. - -Before declaring any functions that customize Readline's behavior, or -using any functionality Readline provides in other code, an -application writer should include the file @code{<readline/readline.h>} -in any file that uses Readline's features. Since some of the definitions -in @code{readline.h} use the @code{stdio} library, the file -@code{<stdio.h>} should be included before @code{readline.h}. - -@code{readline.h} defines a C preprocessor variable that should -be treated as an integer, @code{RL_READLINE_VERSION}, which may -be used to conditionally compile application code depending on -the installed Readline version. The value is a hexadecimal -encoding of the major and minor version numbers of the library, -of the form 0x@var{MMmm}. @var{MM} is the two-digit major -version number; @var{mm} is the two-digit minor version number. -For Readline 4.2, for example, the value of -@code{RL_READLINE_VERSION} would be @code{0x0402}. - -@menu -* Readline Typedefs:: C declarations to make code readable. -* Function Writing:: Variables and calling conventions. -@end menu - -@node Readline Typedefs -@subsection Readline Typedefs - -For readabilty, we declare a number of new object types, all pointers -to functions. - -The reason for declaring these new types is to make it easier to write -code describing pointers to C functions with appropriately prototyped -arguments and return values. - -For instance, say we want to declare a variable @var{func} as a pointer -to a function which takes two @code{int} arguments and returns an -@code{int} (this is the type of all of the Readline bindable functions). -Instead of the classic C declaration - -@code{int (*func)();} - -@noindent -or the ANSI-C style declaration - -@code{int (*func)(int, int);} - -@noindent -we may write - -@code{rl_command_func_t *func;} - -The full list of function pointer types available is - -@table @code -@item typedef int rl_command_func_t (int, int); - -@item typedef char *rl_compentry_func_t (const char *, int); - -@item typedef char **rl_completion_func_t (const char *, int, int); - -@item typedef char *rl_quote_func_t (char *, int, char *); - -@item typedef char *rl_dequote_func_t (char *, int); - -@item typedef int rl_compignore_func_t (char **); - -@item typedef void rl_compdisp_func_t (char **, int, int); - -@item typedef int rl_hook_func_t (void); - -@item typedef int rl_getc_func_t (FILE *); - -@item typedef int rl_linebuf_func_t (char *, int); - -@item typedef int rl_intfunc_t (int); -@item #define rl_ivoidfunc_t rl_hook_func_t -@item typedef int rl_icpfunc_t (char *); -@item typedef int rl_icppfunc_t (char **); - -@item typedef void rl_voidfunc_t (void); -@item typedef void rl_vintfunc_t (int); -@item typedef void rl_vcpfunc_t (char *); -@item typedef void rl_vcppfunc_t (char **); - -@end table - -@node Function Writing -@subsection Writing a New Function - -In order to write new functions for Readline, you need to know the -calling conventions for keyboard-invoked functions, and the names of the -variables that describe the current state of the line read so far. - -The calling sequence for a command @code{foo} looks like - -@example -@code{int foo (int count, int key)} -@end example - -@noindent -where @var{count} is the numeric argument (or 1 if defaulted) and -@var{key} is the key that invoked this function. - -It is completely up to the function as to what should be done with the -numeric argument. Some functions use it as a repeat count, some -as a flag, and others to choose alternate behavior (refreshing the current -line as opposed to refreshing the screen, for example). Some choose to -ignore it. In general, if a -function uses the numeric argument as a repeat count, it should be able -to do something useful with both negative and positive arguments. -At the very least, it should be aware that it can be passed a -negative argument. - -A command function should return 0 if its action completes successfully, -and a non-zero value if some error occurs. - -@node Readline Variables -@section Readline Variables - -These variables are available to function writers. - -@deftypevar {char *} rl_line_buffer -This is the line gathered so far. You are welcome to modify the -contents of the line, but see @ref{Allowing Undoing}. The -function @code{rl_extend_line_buffer} is available to increase -the memory allocated to @code{rl_line_buffer}. -@end deftypevar - -@deftypevar int rl_point -The offset of the current cursor position in @code{rl_line_buffer} -(the @emph{point}). -@end deftypevar - -@deftypevar int rl_end -The number of characters present in @code{rl_line_buffer}. When -@code{rl_point} is at the end of the line, @code{rl_point} and -@code{rl_end} are equal. -@end deftypevar - -@deftypevar int rl_mark -The @var{mark} (saved position) in the current line. If set, the mark -and point define a @emph{region}. -@end deftypevar - -@deftypevar int rl_done -Setting this to a non-zero value causes Readline to return the current -line immediately. -@end deftypevar - -@deftypevar int rl_num_chars_to_read -Setting this to a positive value before calling @code{readline()} causes -Readline to return after accepting that many characters, rather -than reading up to a character bound to @code{accept-line}. -@end deftypevar - -@deftypevar int rl_pending_input -Setting this to a value makes it the next keystroke read. This is a -way to stuff a single character into the input stream. -@end deftypevar - -@deftypevar int rl_dispatching -Set to a non-zero value if a function is being called from a key binding; -zero otherwise. Application functions can test this to discover whether -they were called directly or by Readline's dispatching mechanism. -@end deftypevar - -@deftypevar int rl_erase_empty_line -Setting this to a non-zero value causes Readline to completely erase -the current line, including any prompt, any time a newline is typed as -the only character on an otherwise-empty line. The cursor is moved to -the beginning of the newly-blank line. -@end deftypevar - -@deftypevar {char *} rl_prompt -The prompt Readline uses. This is set from the argument to -@code{readline()}, and should not be assigned to directly. -The @code{rl_set_prompt()} function (@pxref{Redisplay}) may -be used to modify the prompt string after calling @code{readline()}. -@end deftypevar - -@deftypevar int rl_already_prompted -If an application wishes to display the prompt itself, rather than have -Readline do it the first time @code{readline()} is called, it should set -this variable to a non-zero value after displaying the prompt. -The prompt must also be passed as the argument to @code{readline()} so -the redisplay functions can update the display properly. -The calling application is responsible for managing the value; Readline -never sets it. -@end deftypevar - -@deftypevar {const char *} rl_library_version -The version number of this revision of the library. -@end deftypevar - -@deftypevar int rl_readline_version -An integer encoding the current version of the library. The encoding is -of the form 0x@var{MMmm}, where @var{MM} is the two-digit major version -number, and @var{mm} is the two-digit minor version number. -For example, for Readline-4.2, @code{rl_readline_version} would have the -value 0x0402. -@end deftypevar - -@deftypevar {int} rl_gnu_readline_p -Always set to 1, denoting that this is @sc{gnu} readline rather than some -emulation. -@end deftypevar - -@deftypevar {const char *} rl_terminal_name -The terminal type, used for initialization. If not set by the application, -Readline sets this to the value of the @env{TERM} environment variable -the first time it is called. -@end deftypevar - -@deftypevar {const char *} rl_readline_name -This variable is set to a unique name by each application using Readline. -The value allows conditional parsing of the inputrc file -(@pxref{Conditional Init Constructs}). -@end deftypevar - -@deftypevar {FILE *} rl_instream -The stdio stream from which Readline reads input. -If @code{NULL}, Readline defaults to @var{stdin}. -@end deftypevar - -@deftypevar {FILE *} rl_outstream -The stdio stream to which Readline performs output. -If @code{NULL}, Readline defaults to @var{stdout}. -@end deftypevar - -@deftypevar {rl_command_func_t *} rl_last_func -The address of the last command function Readline executed. May be used to -test whether or not a function is being executed twice in succession, for -example. -@end deftypevar - -@deftypevar {rl_hook_func_t *} rl_startup_hook -If non-zero, this is the address of a function to call just -before @code{readline} prints the first prompt. -@end deftypevar - -@deftypevar {rl_hook_func_t *} rl_pre_input_hook -If non-zero, this is the address of a function to call after -the first prompt has been printed and just before @code{readline} -starts reading input characters. -@end deftypevar - -@deftypevar {rl_hook_func_t *} rl_event_hook -If non-zero, this is the address of a function to call periodically -when Readline is waiting for terminal input. -By default, this will be called at most ten times a second if there -is no keyboard input. -@end deftypevar - -@deftypevar {rl_getc_func_t *} rl_getc_function -If non-zero, Readline will call indirectly through this pointer -to get a character from the input stream. By default, it is set to -@code{rl_getc}, the default Readline character input function -(@pxref{Character Input}). -@end deftypevar - -@deftypevar {rl_voidfunc_t *} rl_redisplay_function -If non-zero, Readline will call indirectly through this pointer -to update the display with the current contents of the editing buffer. -By default, it is set to @code{rl_redisplay}, the default Readline -redisplay function (@pxref{Redisplay}). -@end deftypevar - -@deftypevar {rl_vintfunc_t *} rl_prep_term_function -If non-zero, Readline will call indirectly through this pointer -to initialize the terminal. The function takes a single argument, an -@code{int} flag that says whether or not to use eight-bit characters. -By default, this is set to @code{rl_prep_terminal} -(@pxref{Terminal Management}). -@end deftypevar - -@deftypevar {rl_voidfunc_t *} rl_deprep_term_function -If non-zero, Readline will call indirectly through this pointer -to reset the terminal. This function should undo the effects of -@code{rl_prep_term_function}. -By default, this is set to @code{rl_deprep_terminal} -(@pxref{Terminal Management}). -@end deftypevar - -@deftypevar {Keymap} rl_executing_keymap -This variable is set to the keymap (@pxref{Keymaps}) in which the -currently executing readline function was found. -@end deftypevar - -@deftypevar {Keymap} rl_binding_keymap -This variable is set to the keymap (@pxref{Keymaps}) in which the -last key binding occurred. -@end deftypevar - -@deftypevar {char *} rl_executing_macro -This variable is set to the text of any currently-executing macro. -@end deftypevar - -@deftypevar {int} rl_readline_state -A variable with bit values that encapsulate the current Readline state. -A bit is set with the @code{RL_SETSTATE} macro, and unset with the -@code{RL_UNSETSTATE} macro. Use the @code{RL_ISSTATE} macro to test -whether a particular state bit is set. Current state bits include: - -@table @code -@item RL_STATE_NONE -Readline has not yet been called, nor has it begun to intialize. -@item RL_STATE_INITIALIZING -Readline is initializing its internal data structures. -@item RL_STATE_INITIALIZED -Readline has completed its initialization. -@item RL_STATE_TERMPREPPED -Readline has modified the terminal modes to do its own input and redisplay. -@item RL_STATE_READCMD -Readline is reading a command from the keyboard. -@item RL_STATE_METANEXT -Readline is reading more input after reading the meta-prefix character. -@item RL_STATE_DISPATCHING -Readline is dispatching to a command. -@item RL_STATE_MOREINPUT -Readline is reading more input while executing an editing command. -@item RL_STATE_ISEARCH -Readline is performing an incremental history search. -@item RL_STATE_NSEARCH -Readline is performing a non-incremental history search. -@item RL_STATE_SEARCH -Readline is searching backward or forward through the history for a string. -@item RL_STATE_NUMERICARG -Readline is reading a numeric argument. -@item RL_STATE_MACROINPUT -Readline is currently getting its input from a previously-defined keyboard -macro. -@item RL_STATE_MACRODEF -Readline is currently reading characters defining a keyboard macro. -@item RL_STATE_OVERWRITE -Readline is in overwrite mode. -@item RL_STATE_COMPLETING -Readline is performing word completion. -@item RL_STATE_SIGHANDLER -Readline is currently executing the readline signal handler. -@item RL_STATE_UNDOING -Readline is performing an undo. -@item RL_STATE_DONE -Readline has read a key sequence bound to @code{accept-line} -and is about to return the line to the caller. -@end table - -@end deftypevar - -@deftypevar {int} rl_explicit_arg -Set to a non-zero value if an explicit numeric argument was specified by -the user. Only valid in a bindable command function. -@end deftypevar - -@deftypevar {int} rl_numeric_arg -Set to the value of any numeric argument explicitly specified by the user -before executing the current Readline function. Only valid in a bindable -command function. -@end deftypevar - -@deftypevar {int} rl_editing_mode -Set to a value denoting Readline's current editing mode. A value of -@var{1} means Readline is currently in emacs mode; @var{0} -means that vi mode is active. -@end deftypevar - - -@node Readline Convenience Functions -@section Readline Convenience Functions - -@menu -* Function Naming:: How to give a function you write a name. -* Keymaps:: Making keymaps. -* Binding Keys:: Changing Keymaps. -* Associating Function Names and Bindings:: Translate function names to - key sequences. -* Allowing Undoing:: How to make your functions undoable. -* Redisplay:: Functions to control line display. -* Modifying Text:: Functions to modify @code{rl_line_buffer}. -* Character Input:: Functions to read keyboard input. -* Terminal Management:: Functions to manage terminal settings. -* Utility Functions:: Generally useful functions and hooks. -* Miscellaneous Functions:: Functions that don't fall into any category. -* Alternate Interface:: Using Readline in a `callback' fashion. -* A Readline Example:: An example Readline function. -@end menu - -@node Function Naming -@subsection Naming a Function - -The user can dynamically change the bindings of keys while using -Readline. This is done by representing the function with a descriptive -name. The user is able to type the descriptive name when referring to -the function. Thus, in an init file, one might find - -@example -Meta-Rubout: backward-kill-word -@end example - -This binds the keystroke @key{Meta-Rubout} to the function -@emph{descriptively} named @code{backward-kill-word}. You, as the -programmer, should bind the functions you write to descriptive names as -well. Readline provides a function for doing that: - -@deftypefun int rl_add_defun (const char *name, rl_command_func_t *function, int key) -Add @var{name} to the list of named functions. Make @var{function} be -the function that gets called. If @var{key} is not -1, then bind it to -@var{function} using @code{rl_bind_key()}. -@end deftypefun - -Using this function alone is sufficient for most applications. It is -the recommended way to add a few functions to the default functions that -Readline has built in. If you need to do something other -than adding a function to Readline, you may need to use the -underlying functions described below. - -@node Keymaps -@subsection Selecting a Keymap - -Key bindings take place on a @dfn{keymap}. The keymap is the -association between the keys that the user types and the functions that -get run. You can make your own keymaps, copy existing keymaps, and tell -Readline which keymap to use. - -@deftypefun Keymap rl_make_bare_keymap (void) -Returns a new, empty keymap. The space for the keymap is allocated with -@code{malloc()}; the caller should free it by calling -@code{rl_discard_keymap()} when done. -@end deftypefun - -@deftypefun Keymap rl_copy_keymap (Keymap map) -Return a new keymap which is a copy of @var{map}. -@end deftypefun - -@deftypefun Keymap rl_make_keymap (void) -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. -@end deftypefun - -@deftypefun void rl_discard_keymap (Keymap keymap) -Free the storage associated with @var{keymap}. -@end deftypefun - -Readline has several internal keymaps. These functions allow you to -change which keymap is active. - -@deftypefun Keymap rl_get_keymap (void) -Returns the currently active keymap. -@end deftypefun - -@deftypefun void rl_set_keymap (Keymap keymap) -Makes @var{keymap} the currently active keymap. -@end deftypefun - -@deftypefun Keymap rl_get_keymap_by_name (const char *name) -Return the keymap matching @var{name}. @var{name} is one which would -be supplied in a @code{set keymap} inputrc line (@pxref{Readline Init File}). -@end deftypefun - -@deftypefun {char *} rl_get_keymap_name (Keymap keymap) -Return the name matching @var{keymap}. @var{name} is one which would -be supplied in a @code{set keymap} inputrc line (@pxref{Readline Init File}). -@end deftypefun - -@node Binding Keys -@subsection Binding Keys - -Key sequences are associate with functions through the keymap. -Readline has several internal keymaps: @code{emacs_standard_keymap}, -@code{emacs_meta_keymap}, @code{emacs_ctlx_keymap}, -@code{vi_movement_keymap}, and @code{vi_insertion_keymap}. -@code{emacs_standard_keymap} is the default, and the examples in -this manual assume that. - -Since @code{readline()} installs a set of default key bindings the first -time it is called, there is always the danger that a custom binding -installed before the first call to @code{readline()} will be overridden. -An alternate mechanism is to install custom key bindings in an -initialization function assigned to the @code{rl_startup_hook} variable -(@pxref{Readline Variables}). - -These functions manage key bindings. - -@deftypefun int rl_bind_key (int key, rl_command_func_t *function) -Binds @var{key} to @var{function} in the currently active keymap. -Returns non-zero in the case of an invalid @var{key}. -@end deftypefun - -@deftypefun int rl_bind_key_in_map (int key, rl_command_func_t *function, Keymap map) -Bind @var{key} to @var{function} in @var{map}. Returns non-zero in the case -of an invalid @var{key}. -@end deftypefun - -@deftypefun int rl_unbind_key (int key) -Bind @var{key} to the null function in the currently active keymap. -Returns non-zero in case of error. -@end deftypefun - -@deftypefun int rl_unbind_key_in_map (int key, Keymap map) -Bind @var{key} to the null function in @var{map}. -Returns non-zero in case of error. -@end deftypefun - -@deftypefun int rl_unbind_function_in_map (rl_command_func_t *function, Keymap map) -Unbind all keys that execute @var{function} in @var{map}. -@end deftypefun - -@deftypefun int rl_unbind_command_in_map (const char *command, Keymap map) -Unbind all keys that are bound to @var{command} in @var{map}. -@end deftypefun - -@deftypefun int rl_set_key (const char *keyseq, rl_command_func_t *function, Keymap map) -Bind the key sequence represented by the string @var{keyseq} to the function -@var{function}. This makes new keymaps as -necessary. The initial keymap in which to do bindings is @var{map}. -@end deftypefun - -@deftypefun int rl_generic_bind (int type, const char *keyseq, char *data, Keymap map) -Bind the key sequence represented by the string @var{keyseq} to the arbitrary -pointer @var{data}. @var{type} says what kind of data is pointed to by -@var{data}; this can be a function (@code{ISFUNC}), a macro -(@code{ISMACR}), or a keymap (@code{ISKMAP}). This makes new keymaps as -necessary. The initial keymap in which to do bindings is @var{map}. -@end deftypefun - -@deftypefun int rl_parse_and_bind (char *line) -Parse @var{line} as if it had been read from the @code{inputrc} file and -perform any key bindings and variable assignments found -(@pxref{Readline Init File}). -@end deftypefun - -@deftypefun int rl_read_init_file (const char *filename) -Read keybindings and variable assignments from @var{filename} -(@pxref{Readline Init File}). -@end deftypefun - -@node Associating Function Names and Bindings -@subsection Associating Function Names and Bindings - -These functions allow you to find out what keys invoke named functions -and the functions invoked by a particular key sequence. You may also -associate a new function name with an arbitrary function. - -@deftypefun {rl_command_func_t *} rl_named_function (const char *name) -Return the function with name @var{name}. -@end deftypefun - -@deftypefun {rl_command_func_t *} rl_function_of_keyseq (const char *keyseq, Keymap map, int *type) -Return the function invoked by @var{keyseq} in keymap @var{map}. -If @var{map} is @code{NULL}, the current keymap is used. If @var{type} is -not @code{NULL}, the type of the object is returned in the @code{int} variable -it points to (one of @code{ISFUNC}, @code{ISKMAP}, or @code{ISMACR}). -@end deftypefun - -@deftypefun {char **} rl_invoking_keyseqs (rl_command_func_t *function) -Return an array of strings representing the key sequences used to -invoke @var{function} in the current keymap. -@end deftypefun - -@deftypefun {char **} rl_invoking_keyseqs_in_map (rl_command_func_t *function, Keymap map) -Return an array of strings representing the key sequences used to -invoke @var{function} in the keymap @var{map}. -@end deftypefun - -@deftypefun void rl_function_dumper (int readable) -Print the readline function names and the key sequences currently -bound to them to @code{rl_outstream}. If @var{readable} is non-zero, -the list is formatted in such a way that it can be made part of an -@code{inputrc} file and re-read. -@end deftypefun - -@deftypefun void rl_list_funmap_names (void) -Print the names of all bindable Readline functions to @code{rl_outstream}. -@end deftypefun - -@deftypefun {const char **} rl_funmap_names (void) -Return a NULL terminated array of known function names. The array is -sorted. The array itself is allocated, but not the strings inside. You -should @code{free()} the array when you are done, but not the pointers. -@end deftypefun - -@deftypefun int rl_add_funmap_entry (const char *name, rl_command_func_t *function) -Add @var{name} to the list of bindable Readline command names, and make -@var{function} the function to be called when @var{name} is invoked. -@end deftypefun - -@node Allowing Undoing -@subsection Allowing Undoing - -Supporting the undo command is a painless thing, and makes your -functions much more useful. It is certainly easy to try -something if you know you can undo it. - -If your function simply inserts text once, or deletes text once, and -uses @code{rl_insert_text()} or @code{rl_delete_text()} to do it, then -undoing is already done for you automatically. - -If you do multiple insertions or multiple deletions, or any combination -of these operations, you should group them together into one operation. -This is done with @code{rl_begin_undo_group()} and -@code{rl_end_undo_group()}. - -The types of events that can be undone are: - -@smallexample -enum undo_code @{ UNDO_DELETE, UNDO_INSERT, UNDO_BEGIN, UNDO_END @}; -@end smallexample - -Notice that @code{UNDO_DELETE} means to insert some text, and -@code{UNDO_INSERT} means to delete some text. That is, the undo code -tells what to undo, not how to undo it. @code{UNDO_BEGIN} and -@code{UNDO_END} are tags added by @code{rl_begin_undo_group()} and -@code{rl_end_undo_group()}. - -@deftypefun int rl_begin_undo_group (void) -Begins saving undo information in a group construct. The undo -information usually comes from calls to @code{rl_insert_text()} and -@code{rl_delete_text()}, but could be the result of calls to -@code{rl_add_undo()}. -@end deftypefun - -@deftypefun int rl_end_undo_group (void) -Closes the current undo group started with @code{rl_begin_undo_group -()}. There should be one call to @code{rl_end_undo_group()} -for each call to @code{rl_begin_undo_group()}. -@end deftypefun - -@deftypefun void rl_add_undo (enum undo_code what, int start, int end, char *text) -Remember how to undo an event (according to @var{what}). The affected -text runs from @var{start} to @var{end}, and encompasses @var{text}. -@end deftypefun - -@deftypefun void rl_free_undo_list (void) -Free the existing undo list. -@end deftypefun - -@deftypefun int rl_do_undo (void) -Undo the first thing on the undo list. Returns @code{0} if there was -nothing to undo, non-zero if something was undone. -@end deftypefun - -Finally, if you neither insert nor delete text, but directly modify the -existing text (e.g., change its case), call @code{rl_modifying()} -once, just before you modify the text. You must supply the indices of -the text range that you are going to modify. - -@deftypefun int rl_modifying (int start, int end) -Tell Readline to save the text between @var{start} and @var{end} as a -single undo unit. It is assumed that you will subsequently modify -that text. -@end deftypefun - -@node Redisplay -@subsection Redisplay - -@deftypefun void rl_redisplay (void) -Change what's displayed on the screen to reflect the current contents -of @code{rl_line_buffer}. -@end deftypefun - -@deftypefun int rl_forced_update_display (void) -Force the line to be updated and redisplayed, whether or not -Readline thinks the screen display is correct. -@end deftypefun - -@deftypefun int rl_on_new_line (void) -Tell the update functions that we have moved onto a new (empty) line, -usually after ouputting a newline. -@end deftypefun - -@deftypefun int rl_on_new_line_with_prompt (void) -Tell the update functions that we have moved onto a new line, with -@var{rl_prompt} already displayed. -This could be used by applications that want to output the prompt string -themselves, but still need Readline to know the prompt string length for -redisplay. -It should be used after setting @var{rl_already_prompted}. -@end deftypefun - -@deftypefun int rl_reset_line_state (void) -Reset the display state to a clean state and redisplay the current line -starting on a new line. -@end deftypefun - -@deftypefun int rl_crlf (void) -Move the cursor to the start of the next screen line. -@end deftypefun - -@deftypefun int rl_show_char (int c) -Display character @var{c} on @code{rl_outstream}. -If Readline has not been set to display meta characters directly, this -will convert meta characters to a meta-prefixed key sequence. -This is intended for use by applications which wish to do their own -redisplay. -@end deftypefun - -@deftypefun int rl_message (const char *, @dots{}) -The arguments are a format string as would be supplied to @code{printf}, -possibly containing conversion specifications such as @samp{%d}, and -any additional arguments necessary to satisfy the conversion specifications. -The resulting string is displayed in the @dfn{echo area}. The echo area -is also used to display numeric arguments and search strings. -@end deftypefun - -@deftypefun int rl_clear_message (void) -Clear the message in the echo area. -@end deftypefun - -@deftypefun void rl_save_prompt (void) -Save the local Readline prompt display state in preparation for -displaying a new message in the message area with @code{rl_message()}. -@end deftypefun - -@deftypefun void rl_restore_prompt (void) -Restore the local Readline prompt display state saved by the most -recent call to @code{rl_save_prompt}. -@end deftypefun - -@deftypefun int rl_expand_prompt (char *prompt) -Expand any special character sequences in @var{prompt} and set up the -local Readline prompt redisplay variables. -This function is called by @code{readline()}. It may also be called to -expand the primary prompt if the @code{rl_on_new_line_with_prompt()} -function or @code{rl_already_prompted} variable is used. -It returns the number of visible characters on the last line of the -(possibly multi-line) prompt. -@end deftypefun - -@deftypefun int rl_set_prompt (const char *prompt) -Make Readline use @var{prompt} for subsequent redisplay. This calls -@code{rl_expand_prompt()} to expand the prompt and sets @code{rl_prompt} -to the result. -@end deftypefun - -@node Modifying Text -@subsection Modifying Text - -@deftypefun int rl_insert_text (const char *text) -Insert @var{text} into the line at the current cursor position. -Returns the number of characters inserted. -@end deftypefun - -@deftypefun int rl_delete_text (int start, int end) -Delete the text between @var{start} and @var{end} in the current line. -Returns the number of characters deleted. -@end deftypefun - -@deftypefun {char *} rl_copy_text (int start, int end) -Return a copy of the text between @var{start} and @var{end} in -the current line. -@end deftypefun - -@deftypefun int rl_kill_text (int start, int end) -Copy the text between @var{start} and @var{end} in the current line -to the kill ring, appending or prepending to the last kill if the -last command was a kill command. The text is deleted. -If @var{start} is less than @var{end}, -the text is appended, otherwise prepended. If the last command was -not a kill, a new kill ring slot is used. -@end deftypefun - -@deftypefun int rl_push_macro_input (char *macro) -Cause @var{macro} to be inserted into the line, as if it had been invoked -by a key bound to a macro. Not especially useful; use -@code{rl_insert_text()} instead. -@end deftypefun - -@node Character Input -@subsection Character Input - -@deftypefun int rl_read_key (void) -Return the next character available from Readline's current input stream. -This handles input inserted into -the input stream via @var{rl_pending_input} (@pxref{Readline Variables}) -and @code{rl_stuff_char()}, macros, and characters read from the keyboard. -While waiting for input, this function will call any function assigned to -the @code{rl_event_hook} variable. -@end deftypefun - -@deftypefun int rl_getc (FILE *stream) -Return the next character available from @var{stream}, which is assumed to -be the keyboard. -@end deftypefun - -@deftypefun int rl_stuff_char (int c) -Insert @var{c} into the Readline input stream. It will be "read" -before Readline attempts to read characters from the terminal with -@code{rl_read_key()}. Up to 512 characters may be pushed back. -@code{rl_stuff_char} returns 1 if the character was successfully inserted; -0 otherwise. -@end deftypefun - -@deftypefun int rl_execute_next (int c) -Make @var{c} be the next command to be executed when @code{rl_read_key()} -is called. This sets @var{rl_pending_input}. -@end deftypefun - -@deftypefun int rl_clear_pending_input (void) -Unset @var{rl_pending_input}, effectively negating the effect of any -previous call to @code{rl_execute_next()}. This works only if the -pending input has not already been read with @code{rl_read_key()}. -@end deftypefun - -@deftypefun int rl_set_keyboard_input_timeout (int u) -While waiting for keyboard input in @code{rl_read_key()}, Readline will -wait for @var{u} microseconds for input before calling any function -assigned to @code{rl_event_hook}. The default waiting period is -one-tenth of a second. Returns the old timeout value. -@end deftypefun - -@node Terminal Management -@subsection Terminal Management - -@deftypefun void rl_prep_terminal (int meta_flag) -Modify the terminal settings for Readline's use, so @code{readline()} -can read a single character at a time from the keyboard. -The @var{meta_flag} argument should be non-zero if Readline should -read eight-bit input. -@end deftypefun - -@deftypefun void rl_deprep_terminal (void) -Undo the effects of @code{rl_prep_terminal()}, leaving the terminal in -the state in which it was before the most recent call to -@code{rl_prep_terminal()}. -@end deftypefun - -@deftypefun void rl_tty_set_default_bindings (Keymap kmap) -Read the operating system's terminal editing characters (as would be displayed -by @code{stty}) to their Readline equivalents. The bindings are performed -in @var{kmap}. -@end deftypefun - -@deftypefun int rl_reset_terminal (const char *terminal_name) -Reinitialize Readline's idea of the terminal settings using -@var{terminal_name} as the terminal type (e.g., @code{vt100}). -If @var{terminal_name} is @code{NULL}, the value of the @code{TERM} -environment variable is used. -@end deftypefun - -@node Utility Functions -@subsection Utility Functions - -@deftypefun void rl_replace_line (const char *text, int clear_undo) -Replace the contents of @code{rl_line_buffer} with @var{text}. -The point and mark are preserved, if possible. -If @var{clear_undo} is non-zero, the undo list associated with the -current line is cleared. -@end deftypefun - -@deftypefun int rl_extend_line_buffer (int len) -Ensure that @code{rl_line_buffer} has enough space to hold @var{len} -characters, possibly reallocating it if necessary. -@end deftypefun - -@deftypefun int rl_initialize (void) -Initialize or re-initialize Readline's internal state. -It's not strictly necessary to call this; @code{readline()} calls it before -reading any input. -@end deftypefun - -@deftypefun int rl_ding (void) -Ring the terminal bell, obeying the setting of @code{bell-style}. -@end deftypefun - -@deftypefun int rl_alphabetic (int c) -Return 1 if @var{c} is an alphabetic character. -@end deftypefun - -@deftypefun void rl_display_match_list (char **matches, int len, int max) -A convenience function for displaying a list of strings in -columnar format on Readline's output stream. @code{matches} is the list -of strings, in argv format, such as a list of completion matches. -@code{len} is the number of strings in @code{matches}, and @code{max} -is the length of the longest string in @code{matches}. This function uses -the setting of @code{print-completions-horizontally} to select how the -matches are displayed (@pxref{Readline Init File Syntax}). -@end deftypefun - -The following are implemented as macros, defined in @code{chardefs.h}. -Applications should refrain from using them. - -@deftypefun int _rl_uppercase_p (int c) -Return 1 if @var{c} is an uppercase alphabetic character. -@end deftypefun - -@deftypefun int _rl_lowercase_p (int c) -Return 1 if @var{c} is a lowercase alphabetic character. -@end deftypefun - -@deftypefun int _rl_digit_p (int c) -Return 1 if @var{c} is a numeric character. -@end deftypefun - -@deftypefun int _rl_to_upper (int c) -If @var{c} is a lowercase alphabetic character, return the corresponding -uppercase character. -@end deftypefun - -@deftypefun int _rl_to_lower (int c) -If @var{c} is an uppercase alphabetic character, return the corresponding -lowercase character. -@end deftypefun - -@deftypefun int _rl_digit_value (int c) -If @var{c} is a number, return the value it represents. -@end deftypefun - -@node Miscellaneous Functions -@subsection Miscellaneous Functions - -@deftypefun int rl_macro_bind (const char *keyseq, const char *macro, Keymap map) -Bind the key sequence @var{keyseq} to invoke the macro @var{macro}. -The binding is performed in @var{map}. When @var{keyseq} is invoked, the -@var{macro} will be inserted into the line. This function is deprecated; -use @code{rl_generic_bind()} instead. -@end deftypefun - -@deftypefun void rl_macro_dumper (int readable) -Print the key sequences bound to macros and their values, using -the current keymap, to @code{rl_outstream}. -If @var{readable} is non-zero, the list is formatted in such a way -that it can be made part of an @code{inputrc} file and re-read. -@end deftypefun - -@deftypefun int rl_variable_bind (const char *variable, const char *value) -Make the Readline variable @var{variable} have @var{value}. -This behaves as if the readline command -@samp{set @var{variable} @var{value}} had been executed in an @code{inputrc} -file (@pxref{Readline Init File Syntax}). -@end deftypefun - -@deftypefun void rl_variable_dumper (int readable) -Print the readline variable names and their current values -to @code{rl_outstream}. -If @var{readable} is non-zero, the list is formatted in such a way -that it can be made part of an @code{inputrc} file and re-read. -@end deftypefun - -@deftypefun int rl_set_paren_blink_timeout (int u) -Set the time interval (in microseconds) that Readline waits when showing -a balancing character when @code{blink-matching-paren} has been enabled. -@end deftypefun - -@deftypefun {char *} rl_get_termcap (const char *cap) -Retrieve the string value of the termcap capability @var{cap}. -Readline fetches the termcap entry for the current terminal name and -uses those capabilities to move around the screen line and perform other -terminal-specific operations, like erasing a line. Readline does not -use all of a terminal's capabilities, and this function will return -values for only those capabilities Readline uses. -@end deftypefun - -@node Alternate Interface -@subsection Alternate Interface - -An alternate interface is available to plain @code{readline()}. Some -applications need to interleave keyboard I/O with file, device, or -window system I/O, typically by using a main loop to @code{select()} -on various file descriptors. To accomodate this need, readline can -also be invoked as a `callback' function from an event loop. There -are functions available to make this easy. - -@deftypefun void rl_callback_handler_install (const char *prompt, rl_vcpfunc_t *lhandler) -Set up the terminal for readline I/O and display the initial -expanded value of @var{prompt}. Save the value of @var{lhandler} to -use as a function to call when a complete line of input has been entered. -The function takes the text of the line as an argument. -@end deftypefun - -@deftypefun void rl_callback_read_char (void) -Whenever an application determines that keyboard input is available, it -should call @code{rl_callback_read_char()}, which will read the next -character from the current input source. -If that character completes the line, @code{rl_callback_read_char} will -invoke the @var{lhandler} function saved by @code{rl_callback_handler_install} -to process the line. -Before calling the @var{lhandler} function, the terminal settings are -reset to the values they had before calling -@code{rl_callback_handler_install}. -If the @var{lhandler} function returns, -the terminal settings are modified for Readline's use again. -@code{EOF} is indicated by calling @var{lhandler} with a -@code{NULL} line. -@end deftypefun - -@deftypefun void rl_callback_handler_remove (void) -Restore the terminal to its initial state and remove the line handler. -This may be called from within a callback as well as independently. -If the @var{lhandler} installed by @code{rl_callback_handler_install} -does not exit the program, either this function or the function referred -to by the value of @code{rl_deprep_term_function} should be called before -the program exits to reset the terminal settings. -@end deftypefun - -@node A Readline Example -@subsection A Readline Example - -Here is a function which changes lowercase characters to their uppercase -equivalents, and uppercase characters to lowercase. If -this function was bound to @samp{M-c}, then typing @samp{M-c} would -change the case of the character under point. Typing @samp{M-1 0 M-c} -would change the case of the following 10 characters, leaving the cursor on -the last character changed. - -@example -/* Invert the case of the COUNT following characters. */ -int -invert_case_line (count, key) - int count, key; -@{ - register int start, end, i; - - start = rl_point; - - if (rl_point >= rl_end) - return (0); - - if (count < 0) - @{ - direction = -1; - count = -count; - @} - else - direction = 1; - - /* Find the end of the range to modify. */ - end = start + (count * direction); - - /* Force it to be within range. */ - if (end > rl_end) - end = rl_end; - else if (end < 0) - end = 0; - - if (start == end) - return (0); - - if (start > end) - @{ - int temp = start; - start = end; - end = temp; - @} - - /* Tell readline that we are modifying the line, - so it will save the undo information. */ - rl_modifying (start, end); - - for (i = start; i != end; i++) - @{ - if (_rl_uppercase_p (rl_line_buffer[i])) - rl_line_buffer[i] = _rl_to_lower (rl_line_buffer[i]); - else if (_rl_lowercase_p (rl_line_buffer[i])) - rl_line_buffer[i] = _rl_to_upper (rl_line_buffer[i]); - @} - /* Move point to on top of the last character changed. */ - rl_point = (direction == 1) ? end - 1 : start; - return (0); -@} -@end example - -@node Readline Signal Handling -@section Readline Signal Handling - -Signals are asynchronous events sent to a process by the Unix kernel, -sometimes on behalf of another process. They are intended to indicate -exceptional events, like a user pressing the interrupt key on his terminal, -or a network connection being broken. There is a class of signals that can -be sent to the process currently reading input from the keyboard. Since -Readline changes the terminal attributes when it is called, it needs to -perform special processing when such a signal is received in order to -restore the terminal to a sane state, or provide application writers with -functions to do so manually. - -Readline contains an internal signal handler that is installed for a -number of signals (@code{SIGINT}, @code{SIGQUIT}, @code{SIGTERM}, -@code{SIGALRM}, @code{SIGTSTP}, @code{SIGTTIN}, and @code{SIGTTOU}). -When one of these signals is received, the signal handler -will reset the terminal attributes to those that were in effect before -@code{readline()} was called, reset the signal handling to what it was -before @code{readline()} was called, and resend the signal to the calling -application. -If and when the calling application's signal handler returns, Readline -will reinitialize the terminal and continue to accept input. -When a @code{SIGINT} is received, the Readline signal handler performs -some additional work, which will cause any partially-entered line to be -aborted (see the description of @code{rl_free_line_state()} below). - -There is an additional Readline signal handler, for @code{SIGWINCH}, which -the kernel sends to a process whenever the terminal's size changes (for -example, if a user resizes an @code{xterm}). The Readline @code{SIGWINCH} -handler updates Readline's internal screen size information, and then calls -any @code{SIGWINCH} signal handler the calling application has installed. -Readline calls the application's @code{SIGWINCH} signal handler without -resetting the terminal to its original state. If the application's signal -handler does more than update its idea of the terminal size and return (for -example, a @code{longjmp} back to a main processing loop), it @emph{must} -call @code{rl_cleanup_after_signal()} (described below), to restore the -terminal state. - -Readline provides two variables that allow application writers to -control whether or not it will catch certain signals and act on them -when they are received. It is important that applications change the -values of these variables only when calling @code{readline()}, not in -a signal handler, so Readline's internal signal state is not corrupted. - -@deftypevar int rl_catch_signals -If this variable is non-zero, Readline will install signal handlers for -@code{SIGINT}, @code{SIGQUIT}, @code{SIGTERM}, @code{SIGALRM}, -@code{SIGTSTP}, @code{SIGTTIN}, and @code{SIGTTOU}. - -The default value of @code{rl_catch_signals} is 1. -@end deftypevar - -@deftypevar int rl_catch_sigwinch -If this variable is non-zero, Readline will install a signal handler for -@code{SIGWINCH}. - -The default value of @code{rl_catch_sigwinch} is 1. -@end deftypevar - -If an application does not wish to have Readline catch any signals, or -to handle signals other than those Readline catches (@code{SIGHUP}, -for example), -Readline provides convenience functions to do the necessary terminal -and internal state cleanup upon receipt of a signal. - -@deftypefun void rl_cleanup_after_signal (void) -This function will reset the state of the terminal to what it was before -@code{readline()} was called, and remove the Readline signal handlers for -all signals, depending on the values of @code{rl_catch_signals} and -@code{rl_catch_sigwinch}. -@end deftypefun - -@deftypefun void rl_free_line_state (void) -This will free any partial state associated with the current input line -(undo information, any partial history entry, any partially-entered -keyboard macro, and any partially-entered numeric argument). This -should be called before @code{rl_cleanup_after_signal()}. The -Readline signal handler for @code{SIGINT} calls this to abort the -current input line. -@end deftypefun - -@deftypefun void rl_reset_after_signal (void) -This will reinitialize the terminal and reinstall any Readline signal -handlers, depending on the values of @code{rl_catch_signals} and -@code{rl_catch_sigwinch}. -@end deftypefun - -If an application does not wish Readline to catch @code{SIGWINCH}, it may -call @code{rl_resize_terminal()} or @code{rl_set_screen_size()} to force -Readline to update its idea of the terminal size when a @code{SIGWINCH} -is received. - -@deftypefun void rl_resize_terminal (void) -Update Readline's internal screen size by reading values from the kernel. -@end deftypefun - -@deftypefun void rl_set_screen_size (int rows, int cols) -Set Readline's idea of the terminal size to @var{rows} rows and -@var{cols} columns. -@end deftypefun - -If an application does not want to install a @code{SIGWINCH} handler, but -is still interested in the screen dimensions, Readline's idea of the screen -size may be queried. - -@deftypefun void rl_get_screen_size (int *rows, int *cols) -Return Readline's idea of the terminal's size in the -variables pointed to by the arguments. -@end deftypefun - -The following functions install and remove Readline's signal handlers. - -@deftypefun int rl_set_signals (void) -Install Readline's signal handler for @code{SIGINT}, @code{SIGQUIT}, -@code{SIGTERM}, @code{SIGALRM}, @code{SIGTSTP}, @code{SIGTTIN}, -@code{SIGTTOU}, and @code{SIGWINCH}, depending on the values of -@code{rl_catch_signals} and @code{rl_catch_sigwinch}. -@end deftypefun - -@deftypefun int rl_clear_signals (void) -Remove all of the Readline signal handlers installed by -@code{rl_set_signals()}. -@end deftypefun - -@node Custom Completers -@section Custom Completers - -Typically, a program that reads commands from the user has a way of -disambiguating commands and data. If your program is one of these, then -it can provide completion for commands, data, or both. -The following sections describe how your program and Readline -cooperate to provide this service. - -@menu -* How Completing Works:: The logic used to do completion. -* Completion Functions:: Functions provided by Readline. -* Completion Variables:: Variables which control completion. -* A Short Completion Example:: An example of writing completer subroutines. -@end menu - -@node How Completing Works -@subsection How Completing Works - -In order to complete some text, the full list of possible completions -must be available. That is, it is not possible to accurately -expand a partial word without knowing all of the possible words -which make sense in that context. The Readline library provides -the user interface to completion, and two of the most common -completion functions: filename and username. For completing other types -of text, you must write your own completion function. This section -describes exactly what such functions must do, and provides an example. - -There are three major functions used to perform completion: - -@enumerate -@item -The user-interface function @code{rl_complete()}. This function is -called with the same arguments as other bindable Readline functions: -@var{count} and @var{invoking_key}. -It isolates the word to be completed and calls -@code{rl_completion_matches()} to generate a list of possible completions. -It then either lists the possible completions, inserts the possible -completions, or actually performs the -completion, depending on which behavior is desired. - -@item -The internal function @code{rl_completion_matches()} uses an -application-supplied @dfn{generator} function to generate the list of -possible matches, and then returns the array of these matches. -The caller should place the address of its generator function in -@code{rl_completion_entry_function}. - -@item -The generator function is called repeatedly from -@code{rl_completion_matches()}, returning a string each time. The -arguments to the generator function are @var{text} and @var{state}. -@var{text} is the partial word to be completed. @var{state} is zero the -first time the function is called, allowing the generator to perform -any necessary initialization, and a positive non-zero integer for -each subsequent call. The generator function returns -@code{(char *)NULL} to inform @code{rl_completion_matches()} that there are -no more possibilities left. Usually the generator function computes the -list of possible completions when @var{state} is zero, and returns them -one at a time on subsequent calls. Each string the generator function -returns as a match must be allocated with @code{malloc()}; Readline -frees the strings when it has finished with them. - -@end enumerate - -@deftypefun int rl_complete (int ignore, int invoking_key) -Complete the word at or before point. You have supplied the function -that does the initial simple matching selection algorithm (see -@code{rl_completion_matches()}). The default is to do filename completion. -@end deftypefun - -@deftypevar {rl_compentry_func_t *} rl_completion_entry_function -This is a pointer to the generator function for -@code{rl_completion_matches()}. -If the value of @code{rl_completion_entry_function} is -@code{NULL} then the default filename generator -function, @code{rl_filename_completion_function()}, is used. -@end deftypevar - -@node Completion Functions -@subsection Completion Functions - -Here is the complete list of callable completion functions present in -Readline. - -@deftypefun int rl_complete_internal (int what_to_do) -Complete the word at or before point. @var{what_to_do} says what to do -with the completion. A value of @samp{?} means list the possible -completions. @samp{TAB} means do standard completion. @samp{*} means -insert all of the possible completions. @samp{!} means to display -all of the possible completions, if there is more than one, as well as -performing partial completion. -@end deftypefun - -@deftypefun int rl_complete (int ignore, int invoking_key) -Complete the word at or before point. You have supplied the function -that does the initial simple matching selection algorithm (see -@code{rl_completion_matches()} and @code{rl_completion_entry_function}). -The default is to do filename -completion. This calls @code{rl_complete_internal()} with an -argument depending on @var{invoking_key}. -@end deftypefun - -@deftypefun int rl_possible_completions (int count, int invoking_key) -List the possible completions. See description of @code{rl_complete -()}. This calls @code{rl_complete_internal()} with an argument of -@samp{?}. -@end deftypefun - -@deftypefun int rl_insert_completions (int count, int invoking_key) -Insert the list of possible completions into the line, deleting the -partially-completed word. See description of @code{rl_complete()}. -This calls @code{rl_complete_internal()} with an argument of @samp{*}. -@end deftypefun - -@deftypefun int rl_completion_mode (rl_command_func_t *cfunc) -Returns the apppriate value to pass to @code{rl_complete_internal()} -depending on whether @var{cfunc} was called twice in succession and -the value of the @code{show-all-if-ambiguous} variable. -Application-specific completion functions may use this function to present -the same interface as @code{rl_complete()}. -@end deftypefun - -@deftypefun {char **} rl_completion_matches (const char *text, rl_compentry_func_t *entry_func) -Returns an array of strings which is a list of completions for -@var{text}. If there are no completions, returns @code{NULL}. -The first entry in the returned array is the substitution for @var{text}. -The remaining entries are the possible completions. The array is -terminated with a @code{NULL} pointer. - -@var{entry_func} is a function of two args, and returns a -@code{char *}. The first argument is @var{text}. The second is a -state argument; it is zero on the first call, and non-zero on subsequent -calls. @var{entry_func} returns a @code{NULL} pointer to the caller -when there are no more matches. -@end deftypefun - -@deftypefun {char *} rl_filename_completion_function (const char *text, int state) -A generator function for filename completion in the general case. -@var{text} is a partial filename. -The Bash source is a useful reference for writing custom -completion functions (the Bash completion functions call this and other -Readline functions). -@end deftypefun - -@deftypefun {char *} rl_username_completion_function (const char *text, int state) -A completion generator for usernames. @var{text} contains a partial -username preceded by a random character (usually @samp{~}). As with all -completion generators, @var{state} is zero on the first call and non-zero -for subsequent calls. -@end deftypefun - -@node Completion Variables -@subsection Completion Variables - -@deftypevar {rl_compentry_func_t *} rl_completion_entry_function -A pointer to the generator function for @code{rl_completion_matches()}. -@code{NULL} means to use @code{rl_filename_completion_function()}, the default -filename completer. -@end deftypevar - -@deftypevar {rl_completion_func_t *} rl_attempted_completion_function -A pointer to an alternative function to create matches. -The function is called with @var{text}, @var{start}, and @var{end}. -@var{start} and @var{end} are indices in @code{rl_line_buffer} defining -the boundaries of @var{text}, which is a character string. -If this function exists and returns @code{NULL}, or if this variable is -set to @code{NULL}, then @code{rl_complete()} will call the value of -@code{rl_completion_entry_function} to generate matches, otherwise the -array of strings returned will be used. -If this function sets the @code{rl_attempted_completion_over} -variable to a non-zero value, Readline will not perform its default -completion even if this function returns no matches. -@end deftypevar - -@deftypevar {rl_quote_func_t *} rl_filename_quoting_function -A pointer to a function that will quote a filename in an -application-specific fashion. This is called if filename completion is being -attempted and one of the characters in @code{rl_filename_quote_characters} -appears in a completed filename. The function is called with -@var{text}, @var{match_type}, and @var{quote_pointer}. The @var{text} -is the filename to be quoted. The @var{match_type} is either -@code{SINGLE_MATCH}, if there is only one completion match, or -@code{MULT_MATCH}. Some functions use this to decide whether or not to -insert a closing quote character. The @var{quote_pointer} is a pointer -to any opening quote character the user typed. Some functions choose -to reset this character. -@end deftypevar - -@deftypevar {rl_dequote_func_t *} rl_filename_dequoting_function -A pointer to a function that will remove application-specific quoting -characters from a filename before completion is attempted, so those -characters do not interfere with matching the text against names in -the filesystem. It is called with @var{text}, the text of the word -to be dequoted, and @var{quote_char}, which is the quoting character -that delimits the filename (usually @samp{'} or @samp{"}). If -@var{quote_char} is zero, the filename was not in an embedded string. -@end deftypevar - -@deftypevar {rl_linebuf_func_t *} rl_char_is_quoted_p -A pointer to a function to call that determines whether or not a specific -character in the line buffer is quoted, according to whatever quoting -mechanism the program calling Readline uses. The function is called with -two arguments: @var{text}, the text of the line, and @var{index}, the -index of the character in the line. It is used to decide whether a -character found in @code{rl_completer_word_break_characters} should be -used to break words for the completer. -@end deftypevar - -@deftypevar {rl_compignore_func_t *} rl_ignore_some_completions_function -This function, if defined, is called by the completer when real filename -completion is done, after all the matching names have been generated. -It is passed a @code{NULL} terminated array of matches. -The first element (@code{matches[0]}) is the -maximal substring common to all matches. This function can -re-arrange the list of matches as required, but each element deleted -from the array must be freed. -@end deftypevar - -@deftypevar {rl_icppfunc_t *} rl_directory_completion_hook -This function, if defined, is allowed to modify the directory portion -of filenames Readline completes. It is called with the address of a -string (the current directory name) as an argument, and may modify that string. -If the string is replaced with a new string, the old value should be freed. -Any modified directory name should have a trailing slash. -The modified value will be displayed as part of the completion, replacing -the directory portion of the pathname the user typed. -It returns an integer that should be non-zero if the function modifies -its directory argument. -It could be used to expand symbolic links or shell variables in pathnames. -@end deftypevar - -@deftypevar {rl_compdisp_func_t *} rl_completion_display_matches_hook -If non-zero, then this is the address of a function to call when -completing a word would normally display the list of possible matches. -This function is called in lieu of Readline displaying the list. -It takes three arguments: -(@code{char **}@var{matches}, @code{int} @var{num_matches}, @code{int} @var{max_length}) -where @var{matches} is the array of matching strings, -@var{num_matches} is the number of strings in that array, and -@var{max_length} is the length of the longest string in that array. -Readline provides a convenience function, @code{rl_display_match_list}, -that takes care of doing the display to Readline's output stream. That -function may be called from this hook. -@end deftypevar - -@deftypevar {const char *} rl_basic_word_break_characters -The basic list of characters that signal a break between words for the -completer routine. The default value of this variable is the characters -which break words for completion in Bash: -@code{" \t\n\"\\'`@@$><=;|&@{("}. -@end deftypevar - -@deftypevar {const char *} rl_basic_quote_characters -A list of quote characters which can cause a word break. -@end deftypevar - -@deftypevar {const char *} rl_completer_word_break_characters -The list of characters that signal a break between words for -@code{rl_complete_internal()}. The default list is the value of -@code{rl_basic_word_break_characters}. -@end deftypevar - -@deftypevar {const char *} rl_completer_quote_characters -A list of characters which can be used to quote a substring of the line. -Completion occurs on the entire substring, and within the substring -@code{rl_completer_word_break_characters} are treated as any other character, -unless they also appear within this list. -@end deftypevar - -@deftypevar {const char *} rl_filename_quote_characters -A list of characters that cause a filename to be quoted by the completer -when they appear in a completed filename. The default is the null string. -@end deftypevar - -@deftypevar {const char *} rl_special_prefixes -The list of characters that are word break characters, but should be -left in @var{text} when it is passed to the completion function. -Programs can use this to help determine what kind of completing to do. -For instance, Bash sets this variable to "$@@" so that it can complete -shell variables and hostnames. -@end deftypevar - -@deftypevar int rl_completion_query_items -Up to this many items will be displayed in response to a -possible-completions call. After that, we ask the user if she is sure -she wants to see them all. The default value is 100. -@end deftypevar - -@deftypevar {int} rl_completion_append_character -When a single completion alternative matches at the end of the command -line, this character is appended to the inserted completion text. The -default is a space character (@samp{ }). Setting this to the null -character (@samp{\0}) prevents anything being appended automatically. -This can be changed in custom completion functions to -provide the ``most sensible word separator character'' according to -an application-specific command line syntax specification. -@end deftypevar - -@deftypevar int rl_completion_suppress_append -If non-zero, @var{rl_completion_append_character} is not appended to -matches at the end of the command line, as described above. It is -set to 0 before any application-specific completion function is called. -@end deftypevar - -@deftypevar int rl_completion_mark_symlink_dirs -If non-zero, a slash will be appended to completed filenames that are -symbolic links to directory names, subject to the value of the -user-settable @var{mark-directories} variable. -This variable exists so that application completion functions can -override the user's global preference (set via the -@var{mark-symlinked-directories} Readline variable) if appropriate. -This variable is set to the user's preference before any -application completion function is called, so unless that function -modifies the value, the user's preferences are honored. -@end deftypevar - -@deftypevar int rl_ignore_completion_duplicates -If non-zero, then duplicates in the matches are removed. -The default is 1. -@end deftypevar - -@deftypevar int rl_filename_completion_desired -Non-zero means that the results of the matches are to be treated as -filenames. This is @emph{always} zero on entry, and can only be changed -within a completion entry generator function. If it is set to a non-zero -value, directory names have a slash appended and Readline attempts to -quote completed filenames if they contain any characters in -@code{rl_filename_quote_characters} and @code{rl_filename_quoting_desired} -is set to a non-zero value. -@end deftypevar - -@deftypevar int rl_filename_quoting_desired -Non-zero means that the results of the matches are to be quoted using -double quotes (or an application-specific quoting mechanism) if the -completed filename contains any characters in -@code{rl_filename_quote_chars}. This is @emph{always} non-zero -on entry, and can only be changed within a completion entry generator -function. The quoting is effected via a call to the function pointed to -by @code{rl_filename_quoting_function}. -@end deftypevar - -@deftypevar int rl_attempted_completion_over -If an application-specific completion function assigned to -@code{rl_attempted_completion_function} sets this variable to a non-zero -value, Readline will not perform its default filename completion even -if the application's completion function returns no matches. -It should be set only by an application's completion function. -@end deftypevar - -@deftypevar int rl_completion_type -Set to a character describing the type of completion Readline is currently -attempting; see the description of @code{rl_complete_internal()} -(@pxref{Completion Functions}) for the list of characters. -@end deftypevar - -@deftypevar int rl_inhibit_completion -If this variable is non-zero, completion is inhibited. The completion -character will be inserted as any other bound to @code{self-insert}. -@end deftypevar - -@node A Short Completion Example -@subsection A Short Completion Example - -Here is a small application demonstrating the use of the GNU Readline -library. It is called @code{fileman}, and the source code resides in -@file{examples/fileman.c}. This sample application provides -completion of command names, line editing features, and access to the -history list. - -@page -@smallexample -/* 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. */ - -#include <stdio.h> -#include <sys/types.h> -#include <sys/file.h> -#include <sys/stat.h> -#include <sys/errno.h> - -#include <readline/readline.h> -#include <readline/history.h> - -extern char *xmalloc (); - -/* The names of functions that actually do the manipulation. */ -int com_list __P((char *)); -int com_view __P((char *)); -int com_rename __P((char *)); -int com_stat __P((char *)); -int com_pwd __P((char *)); -int com_delete __P((char *)); -int com_help __P((char *)); -int com_cd __P((char *)); -int com_quit __P((char *)); - -/* A structure which contains information on the commands this program - can understand. */ - -typedef struct @{ - char *name; /* User printable name of the function. */ - rl_icpfunc_t *func; /* Function to call to do the job. */ - char *doc; /* Documentation for this function. */ -@} COMMAND; - -COMMAND commands[] = @{ - @{ "cd", com_cd, "Change to directory DIR" @}, - @{ "delete", com_delete, "Delete FILE" @}, - @{ "help", com_help, "Display this text" @}, - @{ "?", com_help, "Synonym for `help'" @}, - @{ "list", com_list, "List files in DIR" @}, - @{ "ls", com_list, "Synonym for `list'" @}, - @{ "pwd", com_pwd, "Print the current working directory" @}, - @{ "quit", com_quit, "Quit using Fileman" @}, - @{ "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, (rl_icpfunc_t *)NULL, (char *)NULL @} -@}; - -/* Forward declarations. */ -char *stripwhite (); -COMMAND *find_command (); - -/* The name of this program, as taken from argv[0]. */ -char *progname; - -/* When non-zero, this means the user is done using this program. */ -int done; - -char * -dupstr (s) - int s; -@{ - char *r; - - r = xmalloc (strlen (s) + 1); - strcpy (r, s); - return (r); -@} - -main (argc, argv) - int argc; - char **argv; -@{ - char *line, *s; - - progname = argv[0]; - - initialize_readline (); /* Bind our completer. */ - - /* Loop reading and executing lines until the user quits. */ - for ( ; done == 0; ) - @{ - line = readline ("FileMan: "); - - if (!line) - break; - - /* Remove leading and trailing whitespace from the line. - Then, if there is anything left, add it to the history list - and execute it. */ - s = stripwhite (line); - - if (*s) - @{ - add_history (s); - execute_line (s); - @} - - free (line); - @} - exit (0); -@} - -/* Execute a command line. */ -int -execute_line (line) - char *line; -@{ - register int i; - COMMAND *command; - char *word; - - /* Isolate the command word. */ - i = 0; - while (line[i] && whitespace (line[i])) - i++; - word = line + i; - - while (line[i] && !whitespace (line[i])) - i++; - - if (line[i]) - line[i++] = '\0'; - - command = find_command (word); - - if (!command) - @{ - fprintf (stderr, "%s: No such command for FileMan.\n", word); - return (-1); - @} - - /* Get argument to command, if any. */ - while (whitespace (line[i])) - i++; - - word = line + i; - - /* Call the function. */ - return ((*(command->func)) (word)); -@} - -/* Look up NAME as the name of a command, and return a pointer to that - command. Return a NULL pointer if NAME isn't a command name. */ -COMMAND * -find_command (name) - char *name; -@{ - register int i; - - for (i = 0; commands[i].name; i++) - if (strcmp (name, commands[i].name) == 0) - return (&commands[i]); - - return ((COMMAND *)NULL); -@} - -/* Strip whitespace from the start and end of STRING. Return a pointer - into STRING. */ -char * -stripwhite (string) - char *string; -@{ - register char *s, *t; - - for (s = string; whitespace (*s); s++) - ; - - if (*s == 0) - return (s); - - t = s + strlen (s) - 1; - while (t > s && whitespace (*t)) - t--; - *++t = '\0'; - - return s; -@} - -/* **************************************************************** */ -/* */ -/* Interface to Readline Completion */ -/* */ -/* **************************************************************** */ - -char *command_generator __P((const char *, int)); -char **fileman_completion __P((const char *, int, int)); - -/* Tell the GNU Readline library how to complete. We want to try to - complete on command names if this is the first word in the line, or - on filenames if not. */ -initialize_readline () -@{ - /* Allow conditional parsing of the ~/.inputrc file. */ - rl_readline_name = "FileMan"; - - /* Tell the completer that we want a crack first. */ - rl_attempted_completion_function = fileman_completion; -@} - -/* Attempt to complete on the contents of TEXT. START and END - bound the region of rl_line_buffer that contains the word to - complete. TEXT is the word to complete. We can use the entire - contents of rl_line_buffer in case we want to do some simple - parsing. Returnthe array of matches, or NULL if there aren't any. */ -char ** -fileman_completion (text, start, end) - const char *text; - int start, end; -@{ - char **matches; - - matches = (char **)NULL; - - /* If this word is at the start of the line, then it is a command - to complete. Otherwise it is the name of a file in the current - directory. */ - if (start == 0) - matches = rl_completion_matches (text, command_generator); - - return (matches); -@} - -/* Generator function for command completion. STATE lets us - know whether to start from scratch; without any state - (i.e. STATE == 0), then we start at the top of the list. */ -char * -command_generator (text, state) - const char *text; - int state; -@{ - static int list_index, len; - char *name; - - /* If this is a new word to complete, initialize now. This - includes saving the length of TEXT for efficiency, and - initializing the index variable to 0. */ - if (!state) - @{ - list_index = 0; - len = strlen (text); - @} - - /* Return the next name which partially matches from the - command list. */ - while (name = commands[list_index].name) - @{ - list_index++; - - if (strncmp (name, text, len) == 0) - return (dupstr(name)); - @} - - /* If no names matched, then return NULL. */ - return ((char *)NULL); -@} - -/* **************************************************************** */ -/* */ -/* FileMan Commands */ -/* */ -/* **************************************************************** */ - -/* String to pass to system (). This is for the LIST, VIEW and RENAME - commands. */ -static char syscom[1024]; - -/* List the file(s) named in arg. */ -com_list (arg) - char *arg; -@{ - if (!arg) - arg = ""; - - sprintf (syscom, "ls -FClg %s", arg); - return (system (syscom)); -@} - -com_view (arg) - char *arg; -@{ - if (!valid_argument ("view", arg)) - return 1; - - sprintf (syscom, "more %s", arg); - return (system (syscom)); -@} - -com_rename (arg) - char *arg; -@{ - too_dangerous ("rename"); - return (1); -@} - -com_stat (arg) - char *arg; -@{ - struct stat finfo; - - if (!valid_argument ("stat", arg)) - return (1); - - if (stat (arg, &finfo) == -1) - @{ - perror (arg); - return (1); - @} - - printf ("Statistics for `%s':\n", arg); - - printf ("%s has %d link%s, and is %d byte%s in length.\n", arg, - finfo.st_nlink, - (finfo.st_nlink == 1) ? "" : "s", - finfo.st_size, - (finfo.st_size == 1) ? "" : "s"); - printf ("Inode Last Change at: %s", ctime (&finfo.st_ctime)); - printf (" Last access at: %s", ctime (&finfo.st_atime)); - printf (" Last modified at: %s", ctime (&finfo.st_mtime)); - return (0); -@} - -com_delete (arg) - char *arg; -@{ - too_dangerous ("delete"); - return (1); -@} - -/* Print out help for ARG, or for all of the commands if ARG is - not present. */ -com_help (arg) - char *arg; -@{ - register int i; - int printed = 0; - - for (i = 0; commands[i].name; i++) - @{ - if (!*arg || (strcmp (arg, commands[i].name) == 0)) - @{ - printf ("%s\t\t%s.\n", commands[i].name, commands[i].doc); - printed++; - @} - @} - - if (!printed) - @{ - printf ("No commands match `%s'. Possibilties are:\n", arg); - - for (i = 0; commands[i].name; i++) - @{ - /* Print in six columns. */ - if (printed == 6) - @{ - printed = 0; - printf ("\n"); - @} - - printf ("%s\t", commands[i].name); - printed++; - @} - - if (printed) - printf ("\n"); - @} - return (0); -@} - -/* Change to the directory ARG. */ -com_cd (arg) - char *arg; -@{ - if (chdir (arg) == -1) - @{ - perror (arg); - return 1; - @} - - com_pwd (""); - return (0); -@} - -/* Print out the current working directory. */ -com_pwd (ignore) - char *ignore; -@{ - char dir[1024], *s; - - s = getcwd (dir, sizeof(dir) - 1); - if (s == 0) - @{ - printf ("Error getting pwd: %s\n", dir); - return 1; - @} - - printf ("Current directory is %s\n", dir); - return 0; -@} - -/* The user wishes to quit using this program. Just set DONE - non-zero. */ -com_quit (arg) - char *arg; -@{ - done = 1; - return (0); -@} - -/* Function which tells you that you can't do this. */ -too_dangerous (caller) - char *caller; -@{ - fprintf (stderr, - "%s: Too dangerous for me to distribute.\n" - caller); - fprintf (stderr, "Write it yourself.\n"); -@} - -/* Return non-zero if ARG is a valid argument for CALLER, - else print an error message and return zero. */ -int -valid_argument (caller, arg) - char *caller, *arg; -@{ - if (!arg || !*arg) - @{ - fprintf (stderr, "%s: Argument required.\n", caller); - return (0); - @} - - return (1); -@} -@end smallexample diff --git a/readline/doc/rluser.texinfo b/readline/doc/rluser.texinfo deleted file mode 100644 index 94f851e67f2..00000000000 --- a/readline/doc/rluser.texinfo +++ /dev/null @@ -1,1796 +0,0 @@ -@comment %**start of header (This is for running Texinfo on a region.) -@setfilename rluser.info -@comment %**end of header (This is for running Texinfo on a region.) -@setchapternewpage odd - -@ignore -This file documents the end user interface to the GNU command line -editing features. It is to be an appendix to manuals for programs which -use these features. There is a document entitled "readline.texinfo" -which contains both end-user and programmer documentation for the -GNU Readline Library. - -Copyright (C) 1988-2002 Free Software Foundation, Inc. - -Authored by Brian Fox and Chet Ramey. - -Permission is granted to process this file through Tex and print the -results, provided the printed document carries copying permission notice -identical to this one except for the removal of this paragraph (this -paragraph not being relevant to the printed manual). - -Permission is granted to make and distribute verbatim copies of this manual -provided the copyright notice and this permission notice are preserved on -all copies. - -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided also that the -GNU Copyright statement is available to the distributee, and provided that -the entire resulting derived work is distributed under the terms of a -permission notice identical to this one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions. -@end ignore - -@comment If you are including this manual as an appendix, then set the -@comment variable readline-appendix. - -@ifclear BashFeatures -@defcodeindex bt -@end ifclear - -@node Command Line Editing -@chapter Command Line Editing - -This chapter describes the basic features of the @sc{gnu} -command line editing interface. -@ifset BashFeatures -Command line editing is provided by the Readline library, which is -used by several different programs, including Bash. -@end ifset - -@menu -* Introduction and Notation:: Notation used in this text. -* Readline Interaction:: The minimum set of commands for editing a line. -* Readline Init File:: Customizing Readline from a user's view. -* Bindable Readline Commands:: A description of most of the Readline commands - available for binding -* Readline vi Mode:: A short description of how to make Readline - behave like the vi editor. -@ifset BashFeatures -* Programmable Completion:: How to specify the possible completions for - a specific command. -* Programmable Completion Builtins:: Builtin commands to specify how to - complete arguments for a particular command. -@end ifset -@end menu - -@node Introduction and Notation -@section Introduction to Line Editing - -The following paragraphs describe the notation used to represent -keystrokes. - -The text @kbd{C-k} is read as `Control-K' and describes the character -produced when the @key{k} key is pressed while the Control key -is depressed. - -The text @kbd{M-k} is read as `Meta-K' and describes the character -produced when the Meta key (if you have one) is depressed, and the @key{k} -key is pressed. -The Meta key is labeled @key{ALT} on many keyboards. -On keyboards with two keys labeled @key{ALT} (usually to either side of -the space bar), the @key{ALT} on the left side is generally set to -work as a Meta key. -The @key{ALT} key on the right may also be configured to work as a -Meta key or may be configured as some other modifier, such as a -Compose key for typing accented characters. - -If you do not have a Meta or @key{ALT} key, or another key working as -a Meta key, the identical keystroke can be generated by typing @key{ESC} -@emph{first}, and then typing @key{k}. -Either process is known as @dfn{metafying} the @key{k} key. - -The text @kbd{M-C-k} is read as `Meta-Control-k' and describes the -character produced by @dfn{metafying} @kbd{C-k}. - -In addition, several keys have their own names. Specifically, -@key{DEL}, @key{ESC}, @key{LFD}, @key{SPC}, @key{RET}, and @key{TAB} all -stand for themselves when seen in this text, or in an init file -(@pxref{Readline Init File}). -If your keyboard lacks a @key{LFD} key, typing @key{C-j} will -produce the desired character. -The @key{RET} key may be labeled @key{Return} or @key{Enter} on -some keyboards. - -@node Readline Interaction -@section Readline Interaction -@cindex interaction, readline - -Often during an interactive session you type in a long line of text, -only to notice that the first word on the line is misspelled. The -Readline library gives you a set of commands for manipulating the text -as you type it in, allowing you to just fix your typo, and not forcing -you to retype the majority of the line. Using these editing commands, -you move the cursor to the place that needs correction, and delete or -insert the text of the corrections. Then, when you are satisfied with -the line, you simply press @key{RET}. You do not have to be at the -end of the line to press @key{RET}; the entire line is accepted -regardless of the location of the cursor within the line. - -@menu -* Readline Bare Essentials:: The least you need to know about Readline. -* Readline Movement Commands:: Moving about the input line. -* Readline Killing Commands:: How to delete text, and how to get it back! -* Readline Arguments:: Giving numeric arguments to commands. -* Searching:: Searching through previous lines. -@end menu - -@node Readline Bare Essentials -@subsection Readline Bare Essentials -@cindex notation, readline -@cindex command editing -@cindex editing command lines - -In order to enter characters into the line, simply type them. The typed -character appears where the cursor was, and then the cursor moves one -space to the right. If you mistype a character, you can use your -erase character to back up and delete the mistyped character. - -Sometimes you may mistype a character, and -not notice the error until you have typed several other characters. In -that case, you can type @kbd{C-b} to move the cursor to the left, and then -correct your mistake. Afterwards, you can move the cursor to the right -with @kbd{C-f}. - -When you add text in the middle of a line, you will notice that characters -to the right of the cursor are `pushed over' to make room for the text -that you have inserted. Likewise, when you delete text behind the cursor, -characters to the right of the cursor are `pulled back' to fill in the -blank space created by the removal of the text. A list of the bare -essentials for editing the text of an input line follows. - -@table @asis -@item @kbd{C-b} -Move back one character. -@item @kbd{C-f} -Move forward one character. -@item @key{DEL} or @key{Backspace} -Delete the character to the left of the cursor. -@item @kbd{C-d} -Delete the character underneath the cursor. -@item @w{Printing characters} -Insert the character into the line at the cursor. -@item @kbd{C-_} or @kbd{C-x C-u} -Undo the last editing command. You can undo all the way back to an -empty line. -@end table - -@noindent -(Depending on your configuration, the @key{Backspace} key be set to -delete the character to the left of the cursor and the @key{DEL} key set -to delete the character underneath the cursor, like @kbd{C-d}, rather -than the character to the left of the cursor.) - -@node Readline Movement Commands -@subsection Readline Movement Commands - - -The above table describes the most basic keystrokes that you need -in order to do editing of the input line. For your convenience, many -other commands have been added in addition to @kbd{C-b}, @kbd{C-f}, -@kbd{C-d}, and @key{DEL}. Here are some commands for moving more rapidly -about the line. - -@table @kbd -@item C-a -Move to the start of the line. -@item C-e -Move to the end of the line. -@item M-f -Move forward a word, where a word is composed of letters and digits. -@item M-b -Move backward a word. -@item C-l -Clear the screen, reprinting the current line at the top. -@end table - -Notice how @kbd{C-f} moves forward a character, while @kbd{M-f} moves -forward a word. It is a loose convention that control keystrokes -operate on characters while meta keystrokes operate on words. - -@node Readline Killing Commands -@subsection Readline Killing Commands - -@cindex killing text -@cindex yanking text - -@dfn{Killing} text means to delete the text from the line, but to save -it away for later use, usually by @dfn{yanking} (re-inserting) -it back into the line. -(`Cut' and `paste' are more recent jargon for `kill' and `yank'.) - -If the description for a command says that it `kills' text, then you can -be sure that you can get the text back in a different (or the same) -place later. - -When you use a kill command, the text is saved in a @dfn{kill-ring}. -Any number of consecutive kills save all of the killed text together, so -that when you yank it back, you get it all. The kill -ring is not line specific; the text that you killed on a previously -typed line is available to be yanked back later, when you are typing -another line. -@cindex kill ring - -Here is the list of commands for killing text. - -@table @kbd -@item C-k -Kill the text from the current cursor position to the end of the line. - -@item M-d -Kill from the cursor to the end of the current word, or, if between -words, to the end of the next word. -Word boundaries are the same as those used by @kbd{M-f}. - -@item M-@key{DEL} -Kill from the cursor the start of the current word, or, if between -words, to the start of the previous word. -Word boundaries are the same as those used by @kbd{M-b}. - -@item C-w -Kill from the cursor to the previous whitespace. This is different than -@kbd{M-@key{DEL}} because the word boundaries differ. - -@end table - -Here is how to @dfn{yank} the text back into the line. Yanking -means to copy the most-recently-killed text from the kill buffer. - -@table @kbd -@item C-y -Yank the most recently killed text back into the buffer at the cursor. - -@item M-y -Rotate the kill-ring, and yank the new top. You can only do this if -the prior command is @kbd{C-y} or @kbd{M-y}. -@end table - -@node Readline Arguments -@subsection Readline Arguments - -You can pass numeric arguments to Readline commands. Sometimes the -argument acts as a repeat count, other times it is the @i{sign} of the -argument that is significant. If you pass a negative argument to a -command which normally acts in a forward direction, that command will -act in a backward direction. For example, to kill text back to the -start of the line, you might type @samp{M-- C-k}. - -The general way to pass numeric arguments to a command is to type meta -digits before the command. If the first `digit' typed is a minus -sign (@samp{-}), then the sign of the argument will be negative. Once -you have typed one meta digit to get the argument started, you can type -the remainder of the digits, and then the command. For example, to give -the @kbd{C-d} command an argument of 10, you could type @samp{M-1 0 C-d}, -which will delete the next ten characters on the input line. - -@node Searching -@subsection Searching for Commands in the History - -Readline provides commands for searching through the command history -@ifset BashFeatures -(@pxref{Bash History Facilities}) -@end ifset -for lines containing a specified string. -There are two search modes: @dfn{incremental} and @dfn{non-incremental}. - -Incremental searches begin before the user has finished typing the -search string. -As each character of the search string is typed, Readline displays -the next entry from the history matching the string typed so far. -An incremental search requires only as many characters as needed to -find the desired history entry. -To search backward in the history for a particular string, type -@kbd{C-r}. Typing @kbd{C-s} searches forward through the history. -The characters present in the value of the @code{isearch-terminators} variable -are used to terminate an incremental search. -If that variable has not been assigned a value, the @key{ESC} and -@kbd{C-J} characters will terminate an incremental search. -@kbd{C-g} will abort an incremental search and restore the original line. -When the search is terminated, the history entry containing the -search string becomes the current line. - -To find other matching entries in the history list, type @kbd{C-r} or -@kbd{C-s} as appropriate. -This will search backward or forward in the history for the next -entry matching the search string typed so far. -Any other key sequence bound to a Readline command will terminate -the search and execute that command. -For instance, a @key{RET} will terminate the search and accept -the line, thereby executing the command from the history list. -A movement command will terminate the search, make the last line found -the current line, and begin editing. - -Readline remembers the last incremental search string. If two -@kbd{C-r}s are typed without any intervening characters defining a new -search string, any remembered search string is used. - -Non-incremental searches read the entire search string before starting -to search for matching history lines. The search string may be -typed by the user or be part of the contents of the current line. - -@node Readline Init File -@section Readline Init File -@cindex initialization file, readline - -Although the Readline library comes with a set of Emacs-like -keybindings installed by default, it is possible to use a different set -of keybindings. -Any user can customize programs that use Readline by putting -commands in an @dfn{inputrc} file, conventionally in his home directory. -The name of this -@ifset BashFeatures -file is taken from the value of the shell variable @env{INPUTRC}. If -@end ifset -@ifclear BashFeatures -file is taken from the value of the environment variable @env{INPUTRC}. If -@end ifclear -that variable is unset, the default is @file{~/.inputrc}. - -When a program which uses the Readline library starts up, the -init file is read, and the key bindings are set. - -In addition, the @code{C-x C-r} command re-reads this init file, thus -incorporating any changes that you might have made to it. - -@menu -* Readline Init File Syntax:: Syntax for the commands in the inputrc file. - -* Conditional Init Constructs:: Conditional key bindings in the inputrc file. - -* Sample Init File:: An example inputrc file. -@end menu - -@node Readline Init File Syntax -@subsection Readline Init File Syntax - -There are only a few basic constructs allowed in the -Readline init file. Blank lines are ignored. -Lines beginning with a @samp{#} are comments. -Lines beginning with a @samp{$} indicate conditional -constructs (@pxref{Conditional Init Constructs}). Other lines -denote variable settings and key bindings. - -@table @asis -@item Variable Settings -You can modify the run-time behavior of Readline by -altering the values of variables in Readline -using the @code{set} command within the init file. -The syntax is simple: - -@example -set @var{variable} @var{value} -@end example - -@noindent -Here, for example, is how to -change from the default Emacs-like key binding to use -@code{vi} line editing commands: - -@example -set editing-mode vi -@end example - -Variable names and values, where appropriate, are recognized without regard -to case. - -@ifset BashFeatures -The @w{@code{bind -V}} command lists the current Readline variable names -and values. @xref{Bash Builtins}. -@end ifset - -A great deal of run-time behavior is changeable with the following -variables. - -@cindex variables, readline -@table @code - -@item bell-style -@vindex bell-style -Controls what happens when Readline wants to ring the terminal bell. -If set to @samp{none}, Readline never rings the bell. If set to -@samp{visible}, Readline uses a visible bell if one is available. -If set to @samp{audible} (the default), Readline attempts to ring -the terminal's bell. - -@item comment-begin -@vindex comment-begin -The string to insert at the beginning of the line when the -@code{insert-comment} command is executed. The default value -is @code{"#"}. - -@item completion-ignore-case -If set to @samp{on}, Readline performs filename matching and completion -in a case-insensitive fashion. -The default value is @samp{off}. - -@item completion-query-items -@vindex completion-query-items -The number of possible completions that determines when the user is -asked whether he wants to see the list of possibilities. If the -number of possible completions is greater than this value, -Readline will ask the user whether or not he wishes to view -them; otherwise, they are simply listed. -This variable must be set to an integer value greater than or equal to 0. -The default limit is @code{100}. - -@item convert-meta -@vindex convert-meta -If set to @samp{on}, Readline will convert characters with the -eighth bit set to an @sc{ascii} key sequence by stripping the eighth -bit and prefixing an @key{ESC} character, converting them to a -meta-prefixed key sequence. The default value is @samp{on}. - -@item disable-completion -@vindex disable-completion -If set to @samp{On}, Readline will inhibit word completion. -Completion characters will be inserted into the line as if they had -been mapped to @code{self-insert}. The default is @samp{off}. - -@item editing-mode -@vindex editing-mode -The @code{editing-mode} variable controls which default set of -key bindings is used. By default, Readline starts up in Emacs editing -mode, where the keystrokes are most similar to Emacs. This variable can be -set to either @samp{emacs} or @samp{vi}. - -@item enable-keypad -@vindex enable-keypad -When set to @samp{on}, Readline will try to enable the application -keypad when it is called. Some systems need this to enable the -arrow keys. The default is @samp{off}. - -@item expand-tilde -@vindex expand-tilde -If set to @samp{on}, tilde expansion is performed when Readline -attempts word completion. The default is @samp{off}. - -@vindex history-preserve-point -If set to @samp{on}, the history code attempts to place point at the -same location on each history line retrived with @code{previous-history} -or @code{next-history}. - -@item horizontal-scroll-mode -@vindex horizontal-scroll-mode -This variable can be set to either @samp{on} or @samp{off}. Setting it -to @samp{on} means that the text of the lines being edited will scroll -horizontally on a single screen line when they are longer than the width -of the screen, instead of wrapping onto a new screen line. By default, -this variable is set to @samp{off}. - -@item input-meta -@vindex input-meta -@vindex meta-flag -If set to @samp{on}, Readline will enable eight-bit input (it -will not clear the eighth bit in the characters it reads), -regardless of what the terminal claims it can support. The -default value is @samp{off}. The name @code{meta-flag} is a -synonym for this variable. - -@item isearch-terminators -@vindex isearch-terminators -The string of characters that should terminate an incremental search without -subsequently executing the character as a command (@pxref{Searching}). -If this variable has not been given a value, the characters @key{ESC} and -@kbd{C-J} will terminate an incremental search. - -@item keymap -@vindex keymap -Sets Readline's idea of the current keymap for key binding commands. -Acceptable @code{keymap} names are -@code{emacs}, -@code{emacs-standard}, -@code{emacs-meta}, -@code{emacs-ctlx}, -@code{vi}, -@code{vi-move}, -@code{vi-command}, and -@code{vi-insert}. -@code{vi} is equivalent to @code{vi-command}; @code{emacs} is -equivalent to @code{emacs-standard}. The default value is @code{emacs}. -The value of the @code{editing-mode} variable also affects the -default keymap. - -@item mark-directories -If set to @samp{on}, completed directory names have a slash -appended. The default is @samp{on}. - -@item mark-modified-lines -@vindex mark-modified-lines -This variable, when set to @samp{on}, causes Readline to display an -asterisk (@samp{*}) at the start of history lines which have been modified. -This variable is @samp{off} by default. - -@item mark-symlinked-directories -@vindex mark-symlinked-directories -If set to @samp{on}, completed names which are symbolic links -to directories have a slash appended (subject to the value of -@code{mark-directories}). -The default is @samp{off}. - -@item match-hidden-files -@vindex match-hidden-files -This variable, when set to @samp{on}, causes Readline to match files whose -names begin with a @samp{.} (hidden files) when performing filename -completion, unless the leading @samp{.} is -supplied by the user in the filename to be completed. -This variable is @samp{on} by default. - -@item output-meta -@vindex output-meta -If set to @samp{on}, Readline will display characters with the -eighth bit set directly rather than as a meta-prefixed escape -sequence. The default is @samp{off}. - -@item page-completions -@vindex page-completions -If set to @samp{on}, Readline uses an internal @code{more}-like pager -to display a screenful of possible completions at a time. -This variable is @samp{on} by default. - -@item print-completions-horizontally -If set to @samp{on}, Readline will display completions with matches -sorted horizontally in alphabetical order, rather than down the screen. -The default is @samp{off}. - -@item show-all-if-ambiguous -@vindex show-all-if-ambiguous -This alters the default behavior of the completion functions. If -set to @samp{on}, -words which have more than one possible completion cause the -matches to be listed immediately instead of ringing the bell. -The default value is @samp{off}. - -@item visible-stats -@vindex visible-stats -If set to @samp{on}, a character denoting a file's type -is appended to the filename when listing possible -completions. The default is @samp{off}. - -@end table - -@item Key Bindings -The syntax for controlling key bindings in the init file is -simple. First you need to find the name of the command that you -want to change. The following sections contain tables of the command -name, the default keybinding, if any, and a short description of what -the command does. - -Once you know the name of the command, simply place on a line -in the init file the name of the key -you wish to bind the command to, a colon, and then the name of the -command. The name of the key -can be expressed in different ways, depending on what you find most -comfortable. - -In addition to command names, readline allows keys to be bound -to a string that is inserted when the key is pressed (a @var{macro}). - -@ifset BashFeatures -The @w{@code{bind -p}} command displays Readline function names and -bindings in a format that can put directly into an initialization file. -@xref{Bash Builtins}. -@end ifset - -@table @asis -@item @w{@var{keyname}: @var{function-name} or @var{macro}} -@var{keyname} is the name of a key spelled out in English. For example: -@example -Control-u: universal-argument -Meta-Rubout: backward-kill-word -Control-o: "> output" -@end example - -In the above example, @kbd{C-u} is bound to the function -@code{universal-argument}, -@kbd{M-DEL} is bound to the function @code{backward-kill-word}, and -@kbd{C-o} is bound to run the macro -expressed on the right hand side (that is, to insert the text -@samp{> output} into the line). - -A number of symbolic character names are recognized while -processing this key binding syntax: -@var{DEL}, -@var{ESC}, -@var{ESCAPE}, -@var{LFD}, -@var{NEWLINE}, -@var{RET}, -@var{RETURN}, -@var{RUBOUT}, -@var{SPACE}, -@var{SPC}, -and -@var{TAB}. - -@item @w{"@var{keyseq}": @var{function-name} or @var{macro}} -@var{keyseq} differs from @var{keyname} above in that strings -denoting an entire key sequence can be specified, by placing -the key sequence in double quotes. Some @sc{gnu} Emacs style key -escapes can be used, as in the following example, but the -special character names are not recognized. - -@example -"\C-u": universal-argument -"\C-x\C-r": re-read-init-file -"\e[11~": "Function Key 1" -@end example - -In the above example, @kbd{C-u} is again bound to the function -@code{universal-argument} (just as it was in the first example), -@samp{@kbd{C-x} @kbd{C-r}} is bound to the function @code{re-read-init-file}, -and @samp{@key{ESC} @key{[} @key{1} @key{1} @key{~}} is bound to insert -the text @samp{Function Key 1}. - -@end table - -The following @sc{gnu} Emacs style escape sequences are available when -specifying key sequences: - -@table @code -@item @kbd{\C-} -control prefix -@item @kbd{\M-} -meta prefix -@item @kbd{\e} -an escape character -@item @kbd{\\} -backslash -@item @kbd{\"} -@key{"}, a double quotation mark -@item @kbd{\'} -@key{'}, a single quote or apostrophe -@end table - -In addition to the @sc{gnu} Emacs style escape sequences, a second -set of backslash escapes is available: - -@table @code -@item \a -alert (bell) -@item \b -backspace -@item \d -delete -@item \f -form feed -@item \n -newline -@item \r -carriage return -@item \t -horizontal tab -@item \v -vertical tab -@item \@var{nnn} -the eight-bit character whose value is the octal value @var{nnn} -(one to three digits) -@item \x@var{HH} -the eight-bit character whose value is the hexadecimal value @var{HH} -(one or two hex digits) -@end table - -When entering the text of a macro, single or double quotes must -be used to indicate a macro definition. -Unquoted text is assumed to be a function name. -In the macro body, the backslash escapes described above are expanded. -Backslash will quote any other character in the macro text, -including @samp{"} and @samp{'}. -For example, the following binding will make @samp{@kbd{C-x} \} -insert a single @samp{\} into the line: -@example -"\C-x\\": "\\" -@end example - -@end table - -@node Conditional Init Constructs -@subsection Conditional Init Constructs - -Readline implements a facility similar in spirit to the conditional -compilation features of the C preprocessor which allows key -bindings and variable settings to be performed as the result -of tests. There are four parser directives used. - -@table @code -@item $if -The @code{$if} construct allows bindings to be made based on the -editing mode, the terminal being used, or the application using -Readline. The text of the test extends to the end of the line; -no characters are required to isolate it. - -@table @code -@item mode -The @code{mode=} form of the @code{$if} directive is used to test -whether Readline is in @code{emacs} or @code{vi} mode. -This may be used in conjunction -with the @samp{set keymap} command, for instance, to set bindings in -the @code{emacs-standard} and @code{emacs-ctlx} keymaps only if -Readline is starting out in @code{emacs} mode. - -@item term -The @code{term=} form may be used to include terminal-specific -key bindings, perhaps to bind the key sequences output by the -terminal's function keys. The word on the right side of the -@samp{=} is tested against both the full name of the terminal and -the portion of the terminal name before the first @samp{-}. This -allows @code{sun} to match both @code{sun} and @code{sun-cmd}, -for instance. - -@item application -The @var{application} construct is used to include -application-specific settings. Each program using the Readline -library sets the @var{application name}, and you can test for -a particular value. -This could be used to bind key sequences to functions useful for -a specific program. For instance, the following command adds a -key sequence that quotes the current or previous word in Bash: -@example -$if Bash -# Quote the current or previous word -"\C-xq": "\eb\"\ef\"" -$endif -@end example -@end table - -@item $endif -This command, as seen in the previous example, terminates an -@code{$if} command. - -@item $else -Commands in this branch of the @code{$if} directive are executed if -the test fails. - -@item $include -This directive takes a single filename as an argument and reads commands -and bindings from that file. -For example, the following directive reads from @file{/etc/inputrc}: -@example -$include /etc/inputrc -@end example -@end table - -@node Sample Init File -@subsection Sample Init File - -Here is an example of an @var{inputrc} file. This illustrates key -binding, variable assignment, and conditional syntax. - -@example -@page -# This file controls the behaviour of line input editing for -# programs that use the GNU Readline library. Existing -# programs include FTP, Bash, and GDB. -# -# You can re-read the inputrc file with C-x C-r. -# Lines beginning with '#' are comments. -# -# First, include any systemwide bindings and variable -# assignments from /etc/Inputrc -$include /etc/Inputrc - -# -# Set various bindings for emacs mode. - -set editing-mode emacs - -$if mode=emacs - -Meta-Control-h: backward-kill-word Text after the function name is ignored - -# -# Arrow keys in keypad mode -# -#"\M-OD": backward-char -#"\M-OC": forward-char -#"\M-OA": previous-history -#"\M-OB": next-history -# -# Arrow keys in ANSI mode -# -"\M-[D": backward-char -"\M-[C": forward-char -"\M-[A": previous-history -"\M-[B": next-history -# -# Arrow keys in 8 bit keypad mode -# -#"\M-\C-OD": backward-char -#"\M-\C-OC": forward-char -#"\M-\C-OA": previous-history -#"\M-\C-OB": next-history -# -# Arrow keys in 8 bit ANSI mode -# -#"\M-\C-[D": backward-char -#"\M-\C-[C": forward-char -#"\M-\C-[A": previous-history -#"\M-\C-[B": next-history - -C-q: quoted-insert - -$endif - -# An old-style binding. This happens to be the default. -TAB: complete - -# Macros that are convenient for shell interaction -$if Bash -# edit the path -"\C-xp": "PATH=$@{PATH@}\e\C-e\C-a\ef\C-f" -# prepare to type a quoted word -- -# insert open and close double quotes -# and move to just after the open quote -"\C-x\"": "\"\"\C-b" -# insert a backslash (testing backslash escapes -# in sequences and macros) -"\C-x\\": "\\" -# Quote the current or previous word -"\C-xq": "\eb\"\ef\"" -# Add a binding to refresh the line, which is unbound -"\C-xr": redraw-current-line -# Edit variable on current line. -"\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y=" -$endif - -# use a visible bell if one is available -set bell-style visible - -# don't strip characters to 7 bits when reading -set input-meta on - -# allow iso-latin1 characters to be inserted rather -# than converted to prefix-meta sequences -set convert-meta off - -# display characters with the eighth bit set directly -# rather than as meta-prefixed characters -set output-meta on - -# if there are more than 150 possible completions for -# a word, ask the user if he wants to see all of them -set completion-query-items 150 - -# For FTP -$if Ftp -"\C-xg": "get \M-?" -"\C-xt": "put \M-?" -"\M-.": yank-last-arg -$endif -@end example - -@node Bindable Readline Commands -@section Bindable Readline Commands - -@menu -* Commands For Moving:: Moving about the line. -* Commands For History:: Getting at previous lines. -* Commands For Text:: Commands for changing text. -* Commands For Killing:: Commands for killing and yanking. -* Numeric Arguments:: Specifying numeric arguments, repeat counts. -* Commands For Completion:: Getting Readline to do the typing for you. -* Keyboard Macros:: Saving and re-executing typed characters -* Miscellaneous Commands:: Other miscellaneous commands. -@end menu - -This section describes Readline commands that may be bound to key -sequences. -@ifset BashFeatures -You can list your key bindings by executing -@w{@code{bind -P}} or, for a more terse format, suitable for an -@var{inputrc} file, @w{@code{bind -p}}. (@xref{Bash Builtins}.) -@end ifset -Command names without an accompanying key sequence are unbound by default. - -In the following descriptions, @dfn{point} refers to the current cursor -position, and @dfn{mark} refers to a cursor position saved by the -@code{set-mark} command. -The text between the point and mark is referred to as the @dfn{region}. - -@node Commands For Moving -@subsection Commands For Moving -@ftable @code -@item beginning-of-line (C-a) -Move to the start of the current line. - -@item end-of-line (C-e) -Move to the end of the line. - -@item forward-char (C-f) -Move forward a character. - -@item backward-char (C-b) -Move back a character. - -@item forward-word (M-f) -Move forward to the end of the next word. Words are composed of -letters and digits. - -@item backward-word (M-b) -Move back to the start of the current or previous word. Words are -composed of letters and digits. - -@item clear-screen (C-l) -Clear the screen and redraw the current line, -leaving the current line at the top of the screen. - -@item redraw-current-line () -Refresh the current line. By default, this is unbound. - -@end ftable - -@node Commands For History -@subsection Commands For Manipulating The History - -@ftable @code -@item accept-line (Newline or Return) -@ifset BashFeatures -Accept the line regardless of where the cursor is. -If this line is -non-empty, add it to the history list according to the setting of -the @env{HISTCONTROL} and @env{HISTIGNORE} variables. -If this line is a modified history line, then restore the history line -to its original state. -@end ifset -@ifclear BashFeatures -Accept the line regardless of where the cursor is. -If this line is -non-empty, it may be added to the history list for future recall with -@code{add_history()}. -If this line is a modified history line, the history line is restored -to its original state. -@end ifclear - -@item previous-history (C-p) -Move `back' through the history list, fetching the previous command. - -@item next-history (C-n) -Move `forward' through the history list, fetching the next command. - -@item beginning-of-history (M-<) -Move to the first line in the history. - -@item end-of-history (M->) -Move to the end of the input history, i.e., the line currently -being entered. - -@item reverse-search-history (C-r) -Search backward starting at the current line and moving `up' through -the history as necessary. This is an incremental search. - -@item forward-search-history (C-s) -Search forward starting at the current line and moving `down' through -the the history as necessary. This is an incremental search. - -@item non-incremental-reverse-search-history (M-p) -Search backward starting at the current line and moving `up' -through the history as necessary using a non-incremental search -for a string supplied by the user. - -@item non-incremental-forward-search-history (M-n) -Search forward starting at the current line and moving `down' -through the the history as necessary using a non-incremental search -for a string supplied by the user. - -@item history-search-forward () -Search forward through the history for the string of characters -between the start of the current line and the point. -This is a non-incremental search. -By default, this command is unbound. - -@item history-search-backward () -Search backward through the history for the string of characters -between the start of the current line and the point. This -is a non-incremental search. By default, this command is unbound. - -@item yank-nth-arg (M-C-y) -Insert the first argument to the previous command (usually -the second word on the previous line) at point. -With an argument @var{n}, -insert the @var{n}th word from the previous command (the words -in the previous command begin with word 0). A negative argument -inserts the @var{n}th word from the end of the previous command. - -@item yank-last-arg (M-. or M-_) -Insert last argument to the previous command (the last word of the -previous history entry). With an -argument, behave exactly like @code{yank-nth-arg}. -Successive calls to @code{yank-last-arg} move back through the history -list, inserting the last argument of each line in turn. - -@end ftable - -@node Commands For Text -@subsection Commands For Changing Text - -@ftable @code -@item delete-char (C-d) -Delete the character at point. If point is at the -beginning of the line, there are no characters in the line, and -the last character typed was not bound to @code{delete-char}, then -return @sc{eof}. - -@item backward-delete-char (Rubout) -Delete the character behind the cursor. A numeric argument means -to kill the characters instead of deleting them. - -@item forward-backward-delete-char () -Delete the character under the cursor, unless the cursor is at the -end of the line, in which case the character behind the cursor is -deleted. By default, this is not bound to a key. - -@item quoted-insert (C-q or C-v) -Add the next character typed to the line verbatim. This is -how to insert key sequences like @kbd{C-q}, for example. - -@ifclear BashFeatures -@item tab-insert (M-@key{TAB}) -Insert a tab character. -@end ifclear - -@item self-insert (a, b, A, 1, !, @dots{}) -Insert yourself. - -@item transpose-chars (C-t) -Drag the character before the cursor forward over -the character at the cursor, moving the -cursor forward as well. If the insertion point -is at the end of the line, then this -transposes the last two characters of the line. -Negative arguments have no effect. - -@item transpose-words (M-t) -Drag the word before point past the word after point, -moving point past that word as well. -If the insertion point is at the end of the line, this transposes -the last two words on the line. - -@item upcase-word (M-u) -Uppercase the current (or following) word. With a negative argument, -uppercase the previous word, but do not move the cursor. - -@item downcase-word (M-l) -Lowercase the current (or following) word. With a negative argument, -lowercase the previous word, but do not move the cursor. - -@item capitalize-word (M-c) -Capitalize the current (or following) word. With a negative argument, -capitalize the previous word, but do not move the cursor. - -@item overwrite-mode () -Toggle overwrite mode. With an explicit positive numeric argument, -switches to overwrite mode. With an explicit non-positive numeric -argument, switches to insert mode. This command affects only -@code{emacs} mode; @code{vi} mode does overwrite differently. -Each call to @code{readline()} starts in insert mode. - -In overwrite mode, characters bound to @code{self-insert} replace -the text at point rather than pushing the text to the right. -Characters bound to @code{backward-delete-char} replace the character -before point with a space. - -By default, this command is unbound. - -@end ftable - -@node Commands For Killing -@subsection Killing And Yanking - -@ftable @code - -@item kill-line (C-k) -Kill the text from point to the end of the line. - -@item backward-kill-line (C-x Rubout) -Kill backward to the beginning of the line. - -@item unix-line-discard (C-u) -Kill backward from the cursor to the beginning of the current line. - -@item kill-whole-line () -Kill all characters on the current line, no matter where point is. -By default, this is unbound. - -@item kill-word (M-d) -Kill from point to the end of the current word, or if between -words, to the end of the next word. -Word boundaries are the same as @code{forward-word}. - -@item backward-kill-word (M-@key{DEL}) -Kill the word behind point. -Word boundaries are the same as @code{backward-word}. - -@item unix-word-rubout (C-w) -Kill the word behind point, using white space as a word boundary. -The killed text is saved on the kill-ring. - -@item delete-horizontal-space () -Delete all spaces and tabs around point. By default, this is unbound. - -@item kill-region () -Kill the text in the current region. -By default, this command is unbound. - -@item copy-region-as-kill () -Copy the text in the region to the kill buffer, so it can be yanked -right away. By default, this command is unbound. - -@item copy-backward-word () -Copy the word before point to the kill buffer. -The word boundaries are the same as @code{backward-word}. -By default, this command is unbound. - -@item copy-forward-word () -Copy the word following point to the kill buffer. -The word boundaries are the same as @code{forward-word}. -By default, this command is unbound. - -@item yank (C-y) -Yank the top of the kill ring into the buffer at point. - -@item yank-pop (M-y) -Rotate the kill-ring, and yank the new top. You can only do this if -the prior command is @code{yank} or @code{yank-pop}. -@end ftable - -@node Numeric Arguments -@subsection Specifying Numeric Arguments -@ftable @code - -@item digit-argument (@kbd{M-0}, @kbd{M-1}, @dots{} @kbd{M--}) -Add this digit to the argument already accumulating, or start a new -argument. @kbd{M--} starts a negative argument. - -@item universal-argument () -This is another way to specify an argument. -If this command is followed by one or more digits, optionally with a -leading minus sign, those digits define the argument. -If the command is followed by digits, executing @code{universal-argument} -again ends the numeric argument, but is otherwise ignored. -As a special case, if this command is immediately followed by a -character that is neither a digit or minus sign, the argument count -for the next command is multiplied by four. -The argument count is initially one, so executing this function the -first time makes the argument count four, a second time makes the -argument count sixteen, and so on. -By default, this is not bound to a key. -@end ftable - -@node Commands For Completion -@subsection Letting Readline Type For You - -@ftable @code -@item complete (@key{TAB}) -Attempt to perform completion on the text before point. -The actual completion performed is application-specific. -@ifset BashFeatures -Bash attempts completion treating the text as a variable (if the -text begins with @samp{$}), username (if the text begins with -@samp{~}), hostname (if the text begins with @samp{@@}), or -command (including aliases and functions) in turn. If none -of these produces a match, filename completion is attempted. -@end ifset -@ifclear BashFeatures -The default is filename completion. -@end ifclear - -@item possible-completions (M-?) -List the possible completions of the text before point. - -@item insert-completions (M-*) -Insert all completions of the text before point that would have -been generated by @code{possible-completions}. - -@item menu-complete () -Similar to @code{complete}, but replaces the word to be completed -with a single match from the list of possible completions. -Repeated execution of @code{menu-complete} steps through the list -of possible completions, inserting each match in turn. -At the end of the list of completions, the bell is rung -(subject to the setting of @code{bell-style}) -and the original text is restored. -An argument of @var{n} moves @var{n} positions forward in the list -of matches; a negative argument may be used to move backward -through the list. -This command is intended to be bound to @key{TAB}, but is unbound -by default. - -@item delete-char-or-list () -Deletes the character under the cursor if not at the beginning or -end of the line (like @code{delete-char}). -If at the end of the line, behaves identically to -@code{possible-completions}. -This command is unbound by default. - -@ifset BashFeatures -@item complete-filename (M-/) -Attempt filename completion on the text before point. - -@item possible-filename-completions (C-x /) -List the possible completions of the text before point, -treating it as a filename. - -@item complete-username (M-~) -Attempt completion on the text before point, treating -it as a username. - -@item possible-username-completions (C-x ~) -List the possible completions of the text before point, -treating it as a username. - -@item complete-variable (M-$) -Attempt completion on the text before point, treating -it as a shell variable. - -@item possible-variable-completions (C-x $) -List the possible completions of the text before point, -treating it as a shell variable. - -@item complete-hostname (M-@@) -Attempt completion on the text before point, treating -it as a hostname. - -@item possible-hostname-completions (C-x @@) -List the possible completions of the text before point, -treating it as a hostname. - -@item complete-command (M-!) -Attempt completion on the text before point, treating -it as a command name. Command completion attempts to -match the text against aliases, reserved words, shell -functions, shell builtins, and finally executable filenames, -in that order. - -@item possible-command-completions (C-x !) -List the possible completions of the text before point, -treating it as a command name. - -@item dynamic-complete-history (M-@key{TAB}) -Attempt completion on the text before point, comparing -the text against lines from the history list for possible -completion matches. - -@item complete-into-braces (M-@{) -Perform filename completion and insert the list of possible completions -enclosed within braces so the list is available to the shell -(@pxref{Brace Expansion}). - -@end ifset -@end ftable - -@node Keyboard Macros -@subsection Keyboard Macros -@ftable @code - -@item start-kbd-macro (C-x () -Begin saving the characters typed into the current keyboard macro. - -@item end-kbd-macro (C-x )) -Stop saving the characters typed into the current keyboard macro -and save the definition. - -@item call-last-kbd-macro (C-x e) -Re-execute the last keyboard macro defined, by making the characters -in the macro appear as if typed at the keyboard. - -@end ftable - -@node Miscellaneous Commands -@subsection Some Miscellaneous Commands -@ftable @code - -@item re-read-init-file (C-x C-r) -Read in the contents of the @var{inputrc} file, and incorporate -any bindings or variable assignments found there. - -@item abort (C-g) -Abort the current editing command and -ring the terminal's bell (subject to the setting of -@code{bell-style}). - -@item do-uppercase-version (M-a, M-b, M-@var{x}, @dots{}) -If the metafied character @var{x} is lowercase, run the command -that is bound to the corresponding uppercase character. - -@item prefix-meta (@key{ESC}) -Metafy the next character typed. This is for keyboards -without a meta key. Typing @samp{@key{ESC} f} is equivalent to typing -@kbd{M-f}. - -@item undo (C-_ or C-x C-u) -Incremental undo, separately remembered for each line. - -@item revert-line (M-r) -Undo all changes made to this line. This is like executing the @code{undo} -command enough times to get back to the beginning. - -@ifset BashFeatures -@item tilde-expand (M-&) -@end ifset -@ifclear BashFeatures -@item tilde-expand (M-~) -@end ifclear -Perform tilde expansion on the current word. - -@item set-mark (C-@@) -Set the mark to the point. If a -numeric argument is supplied, the mark is set to that position. - -@item exchange-point-and-mark (C-x C-x) -Swap the point with the mark. The current cursor position is set to -the saved position, and the old cursor position is saved as the mark. - -@item character-search (C-]) -A character is read and point is moved to the next occurrence of that -character. A negative count searches for previous occurrences. - -@item character-search-backward (M-C-]) -A character is read and point is moved to the previous occurrence -of that character. A negative count searches for subsequent -occurrences. - -@item insert-comment (M-#) -Without a numeric argument, the value of the @code{comment-begin} -variable is inserted at the beginning of the current line. -If a numeric argument is supplied, this command acts as a toggle: if -the characters at the beginning of the line do not match the value -of @code{comment-begin}, the value is inserted, otherwise -the characters in @code{comment-begin} are deleted from the beginning of -the line. -In either case, the line is accepted as if a newline had been typed. -@ifset BashFeatures -The default value of @code{comment-begin} causes this command -to make the current line a shell comment. -If a numeric argument causes the comment character to be removed, the line -will be executed by the shell. -@end ifset - -@item dump-functions () -Print all of the functions and their key bindings to the -Readline output stream. If a numeric argument is supplied, -the output is formatted in such a way that it can be made part -of an @var{inputrc} file. This command is unbound by default. - -@item dump-variables () -Print all of the settable variables and their values to the -Readline output stream. If a numeric argument is supplied, -the output is formatted in such a way that it can be made part -of an @var{inputrc} file. This command is unbound by default. - -@item dump-macros () -Print all of the Readline key sequences bound to macros and the -strings they output. If a numeric argument is supplied, -the output is formatted in such a way that it can be made part -of an @var{inputrc} file. This command is unbound by default. - -@ifset BashFeatures -@item glob-complete-word (M-g) -The word before point is treated as a pattern for pathname expansion, -with an asterisk implicitly appended. This pattern is used to -generate a list of matching file names for possible completions. - -@item glob-expand-word (C-x *) -The word before point is treated as a pattern for pathname expansion, -and the list of matching file names is inserted, replacing the word. -If a numeric argument is supplied, a @samp{*} is appended before -pathname expansion. - -@item glob-list-expansions (C-x g) -The list of expansions that would have been generated by -@code{glob-expand-word} is displayed, and the line is redrawn. -If a numeric argument is supplied, a @samp{*} is appended before -pathname expansion. - -@item display-shell-version (C-x C-v) -Display version information about the current instance of Bash. - -@item shell-expand-line (M-C-e) -Expand the line as the shell does. -This performs alias and history expansion as well as all of the shell -word expansions (@pxref{Shell Expansions}). - -@item history-expand-line (M-^) -Perform history expansion on the current line. - -@item magic-space () -Perform history expansion on the current line and insert a space -(@pxref{History Interaction}). - -@item alias-expand-line () -Perform alias expansion on the current line (@pxref{Aliases}). - -@item history-and-alias-expand-line () -Perform history and alias expansion on the current line. - -@item insert-last-argument (M-. or M-_) -A synonym for @code{yank-last-arg}. - -@item operate-and-get-next (C-o) -Accept the current line for execution and fetch the next line -relative to the current line from the history for editing. Any -argument is ignored. - -@item edit-and-execute-command (C-xC-e) -Invoke an editor on the current command line, and execute the result as shell -commands. -Bash attempts to invoke -@code{$FCEDIT}, @code{$EDITOR}, and @code{emacs} -as the editor, in that order. - -@end ifset - -@ifclear BashFeatures -@item emacs-editing-mode (C-e) -When in @code{vi} command mode, this causes a switch to @code{emacs} -editing mode. - -@item vi-editing-mode (M-C-j) -When in @code{emacs} editing mode, this causes a switch to @code{vi} -editing mode. - -@end ifclear - -@end ftable - -@node Readline vi Mode -@section Readline vi Mode - -While the Readline library does not have a full set of @code{vi} -editing functions, it does contain enough to allow simple editing -of the line. The Readline @code{vi} mode behaves as specified in -the @sc{posix} 1003.2 standard. - -@ifset BashFeatures -In order to switch interactively between @code{emacs} and @code{vi} -editing modes, use the @samp{set -o emacs} and @samp{set -o vi} -commands (@pxref{The Set Builtin}). -@end ifset -@ifclear BashFeatures -In order to switch interactively between @code{emacs} and @code{vi} -editing modes, use the command @kbd{M-C-j} (bound to emacs-editing-mode -when in @code{vi} mode and to vi-editing-mode in @code{emacs} mode). -@end ifclear -The Readline default is @code{emacs} mode. - -When you enter a line in @code{vi} mode, you are already placed in -`insertion' mode, as if you had typed an @samp{i}. Pressing @key{ESC} -switches you into `command' mode, where you can edit the text of the -line with the standard @code{vi} movement keys, move to previous -history lines with @samp{k} and subsequent lines with @samp{j}, and -so forth. - -@ifset BashFeatures -@node Programmable Completion -@section Programmable Completion -@cindex programmable completion - -When word completion is attempted for an argument to a command for -which a completion specification (a @var{compspec}) has been defined -using the @code{complete} builtin (@pxref{Programmable Completion Builtins}), -the programmable completion facilities are invoked. - -First, the command name is identified. -If a compspec has been defined for that command, the -compspec is used to generate the list of possible completions for the word. -If the command word is a full pathname, a compspec for the full -pathname is searched for first. -If no compspec is found for the full pathname, an attempt is made to -find a compspec for the portion following the final slash. - -Once a compspec has been found, it is used to generate the list of -matching words. -If a compspec is not found, the default Bash completion -described above (@pxref{Commands For Completion}) is performed. - -First, the actions specified by the compspec are used. -Only matches which are prefixed by the word being completed are -returned. -When the @option{-f} or @option{-d} option is used for filename or -directory name completion, the shell variable @env{FIGNORE} is -used to filter the matches. -@xref{Bash Variables}, for a description of @env{FIGNORE}. - -Any completions specified by a filename expansion pattern to the -@option{-G} option are generated next. -The words generated by the pattern need not match the word being completed. -The @env{GLOBIGNORE} shell variable is not used to filter the matches, -but the @env{FIGNORE} shell variable is used. - -Next, the string specified as the argument to the @option{-W} option -is considered. -The string is first split using the characters in the @env{IFS} -special variable as delimiters. -Shell quoting is honored. -Each word is then expanded using -brace expansion, tilde expansion, parameter and variable expansion, -command substitution, arithmetic expansion, and pathname expansion, -as described above (@pxref{Shell Expansions}). -The results are split using the rules described above -(@pxref{Word Splitting}). -The results of the expansion are prefix-matched against the word being -completed, and the matching words become the possible completions. - -After these matches have been generated, any shell function or command -specified with the @option{-F} and @option{-C} options is invoked. -When the command or function is invoked, the @env{COMP_LINE} and -@env{COMP_POINT} variables are assigned values as described above -(@pxref{Bash Variables}). -If a shell function is being invoked, the @env{COMP_WORDS} and -@env{COMP_CWORD} variables are also set. -When the function or command is invoked, the first argument is the -name of the command whose arguments are being completed, the -second argument is the word being completed, and the third argument -is the word preceding the word being completed on the current command line. -No filtering of the generated completions against the word being completed -is performed; the function or command has complete freedom in generating -the matches. - -Any function specified with @option{-F} is invoked first. -The function may use any of the shell facilities, including the -@code{compgen} builtin described below -(@pxref{Programmable Completion Builtins}), to generate the matches. -It must put the possible completions in the @env{COMPREPLY} array -variable. - -Next, any command specified with the @option{-C} option is invoked -in an environment equivalent to command substitution. -It should print a list of completions, one per line, to -the standard output. -Backslash may be used to escape a newline, if necessary. - -After all of the possible completions are generated, any filter -specified with the @option{-X} option is applied to the list. -The filter is a pattern as used for pathname expansion; a @samp{&} -in the pattern is replaced with the text of the word being completed. -A literal @samp{&} may be escaped with a backslash; the backslash -is removed before attempting a match. -Any completion that matches the pattern will be removed from the list. -A leading @samp{!} negates the pattern; in this case any completion -not matching the pattern will be removed. - -Finally, any prefix and suffix specified with the @option{-P} and @option{-S} -options are added to each member of the completion list, and the result is -returned to the Readline completion code as the list of possible -completions. - -If the previously-applied actions do not generate any matches, and the -@option{-o dirnames} option was supplied to @code{complete} when the -compspec was defined, directory name completion is attempted. - -By default, if a compspec is found, whatever it generates is returned to -the completion code as the full set of possible completions. -The default Bash completions are not attempted, and the Readline default -of filename completion is disabled. -If the @option{-o default} option was supplied to @code{complete} when the -compspec was defined, Readline's default completion will be performed -if the compspec generates no matches. - -When a compspec indicates that directory name completion is desired, -the programmable completion functions force Readline to append a slash -to completed names which are symbolic links to directories, subject to -the value of the @var{mark-directories} Readline variable, regardless -of the setting of the @var{mark-symlinked-directories} Readline variable. - -@node Programmable Completion Builtins -@section Programmable Completion Builtins -@cindex completion builtins - -Two builtin commands are available to manipulate the programmable completion -facilities. - -@table @code -@item compgen -@btindex compgen -@example -@code{compgen [@var{option}] [@var{word}]} -@end example - -Generate possible completion matches for @var{word} according to -the @var{option}s, which may be any option accepted by the -@code{complete} -builtin with the exception of @option{-p} and @option{-r}, and write -the matches to the standard output. -When using the @option{-F} or @option{-C} options, the various shell variables -set by the programmable completion facilities, while available, will not -have useful values. - -The matches will be generated in the same way as if the programmable -completion code had generated them directly from a completion specification -with the same flags. -If @var{word} is specified, only those completions matching @var{word} -will be displayed. - -The return value is true unless an invalid option is supplied, or no -matches were generated. - -@item complete -@btindex complete -@example -@code{complete [-abcdefgjksuv] [-o @var{comp-option}] [-A @var{action}] [-G @var{globpat}] [-W @var{wordlist}] -[-P @var{prefix}] [-S @var{suffix}] [-X @var{filterpat}] [-F @var{function}] -[-C @var{command}] @var{name} [@var{name} @dots{}]} -@code{complete -pr [@var{name} @dots{}]} -@end example - -Specify how arguments to each @var{name} should be completed. -If the @option{-p} option is supplied, or if no options are supplied, existing -completion specifications are printed in a way that allows them to be -reused as input. -The @option{-r} option removes a completion specification for -each @var{name}, or, if no @var{name}s are supplied, all -completion specifications. - -The process of applying these completion specifications when word completion -is attempted is described above (@pxref{Programmable Completion}). - -Other options, if specified, have the following meanings. -The arguments to the @option{-G}, @option{-W}, and @option{-X} options -(and, if necessary, the @option{-P} and @option{-S} options) -should be quoted to protect them from expansion before the -@code{complete} builtin is invoked. - - -@table @code -@item -o @var{comp-option} -The @var{comp-option} controls several aspects of the compspec's behavior -beyond the simple generation of completions. -@var{comp-option} may be one of: - -@table @code - -@item default -Use Readline's default filename completion if the compspec generates -no matches. - -@item dirnames -Perform directory name completion if the compspec generates no matches. - -@item filenames -Tell Readline that the compspec generates filenames, so it can perform any -filename\-specific processing (like adding a slash to directory names or -suppressing trailing spaces). This option is intended to be used with -shell functions specified with @option{-F}. - -@item nospace -Tell Readline not to append a space (the default) to words completed at -the end of the line. -@end table - -@item -A @var{action} -The @var{action} may be one of the following to generate a list of possible -completions: - -@table @code -@item alias -Alias names. May also be specified as @option{-a}. - -@item arrayvar -Array variable names. - -@item binding -Readline key binding names (@pxref{Bindable Readline Commands}). - -@item builtin -Names of shell builtin commands. May also be specified as @option{-b}. - -@item command -Command names. May also be specified as @option{-c}. - -@item directory -Directory names. May also be specified as @option{-d}. - -@item disabled -Names of disabled shell builtins. - -@item enabled -Names of enabled shell builtins. - -@item export -Names of exported shell variables. May also be specified as @option{-e}. - -@item file -File names. May also be specified as @option{-f}. - -@item function -Names of shell functions. - -@item group -Group names. May also be specified as @option{-g}. - -@item helptopic -Help topics as accepted by the @code{help} builtin (@pxref{Bash Builtins}). - -@item hostname -Hostnames, as taken from the file specified by the -@env{HOSTFILE} shell variable (@pxref{Bash Variables}). - -@item job -Job names, if job control is active. May also be specified as @option{-j}. - -@item keyword -Shell reserved words. May also be specified as @option{-k}. - -@item running -Names of running jobs, if job control is active. - -@item service -Service names. May also be specified as @option{-s}. - -@item setopt -Valid arguments for the @option{-o} option to the @code{set} builtin -(@pxref{The Set Builtin}). - -@item shopt -Shell option names as accepted by the @code{shopt} builtin -(@pxref{Bash Builtins}). - -@item signal -Signal names. - -@item stopped -Names of stopped jobs, if job control is active. - -@item user -User names. May also be specified as @option{-u}. - -@item variable -Names of all shell variables. May also be specified as @option{-v}. -@end table - -@item -G @var{globpat} -The filename expansion pattern @var{globpat} is expanded to generate -the possible completions. - -@item -W @var{wordlist} -The @var{wordlist} is split using the characters in the -@env{IFS} special variable as delimiters, and each resultant word -is expanded. -The possible completions are the members of the resultant list which -match the word being completed. - -@item -C @var{command} -@var{command} is executed in a subshell environment, and its output is -used as the possible completions. - -@item -F @var{function} -The shell function @var{function} is executed in the current shell -environment. -When it finishes, the possible completions are retrieved from the value -of the @env{COMPREPLY} array variable. - -@item -X @var{filterpat} -@var{filterpat} is a pattern as used for filename expansion. -It is applied to the list of possible completions generated by the -preceding options and arguments, and each completion matching -@var{filterpat} is removed from the list. -A leading @samp{!} in @var{filterpat} negates the pattern; in this -case, any completion not matching @var{filterpat} is removed. - -@item -P @var{prefix} -@var{prefix} is added at the beginning of each possible completion -after all other options have been applied. - -@item -S @var{suffix} -@var{suffix} is appended to each possible completion -after all other options have been applied. -@end table - -The return value is true unless an invalid option is supplied, an option -other than @option{-p} or @option{-r} is supplied without a @var{name} -argument, an attempt is made to remove a completion specification for -a @var{name} for which no specification exists, or -an error occurs adding a completion specification. - -@end table -@end ifset diff --git a/readline/doc/rluserman.pdf b/readline/doc/rluserman.pdf Binary files differdeleted file mode 100644 index 4a2184bf461..00000000000 --- a/readline/doc/rluserman.pdf +++ /dev/null diff --git a/readline/doc/rluserman.texinfo b/readline/doc/rluserman.texinfo deleted file mode 100644 index 89abe31aeb5..00000000000 --- a/readline/doc/rluserman.texinfo +++ /dev/null @@ -1,94 +0,0 @@ -\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 diff --git a/readline/doc/texi2dvi b/readline/doc/texi2dvi index c186848d9b9..c0bcc0ae21e 100755 --- a/readline/doc/texi2dvi +++ b/readline/doc/texi2dvi @@ -2,7 +2,8 @@ # texi2dvi --- produce DVI (or PDF) files from Texinfo (or LaTeX) sources. # $Id$ # -# Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 99 Free Software Foundation, Inc. +# 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 @@ -29,9 +30,9 @@ rcs_revision='$Revision$' rcs_version=`set - $rcs_revision; echo $2` program=`echo $0 | sed -e 's!.*/!!'` -version="texi2dvi (GNU Texinfo 4.0) $rcs_version +version="texi2dvi (GNU Texinfo 4.5) $rcs_version -Copyright (C) 1999 Free Software Foundation, Inc. +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." @@ -46,46 +47,52 @@ is used to determine its language (LaTeX or Texinfo). Makeinfo is used to perform Texinfo macro expansion before running TeX when needed. -Options: - -@ Use @input instead of \input; for preloaded Texinfo. - -b, --batch No interaction. - -c, --clean Remove all auxiliary files. - -D, --debug Turn on shell debugging (set -x). - -e, --expand Force macro expansion using makeinfo. - -I DIR Search DIR for Texinfo files. - -h, --help Display this help and exit successfully. - -l, --language=LANG Specify the LANG of FILE: LaTeX or Texinfo. - -p, --pdf Use pdftex or pdflatex for processing. - -q, --quiet No output unless errors (implies --batch). - -s, --silent Same as --quiet. - -t, --texinfo=CMD Insert CMD after @setfilename in copy of input file. - Multiple values accumulate. - -v, --version Display version information and exit successfully. - -V, --verbose Report on what is done. +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>." +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. -escape='\' batch=false # eval for batch mode clean= debug= +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= -miincludes= # makeinfo include path textra= tmpdir=${TMPDIR:-/tmp}/t2d$$ # avoid collisions on 8.3 filesystems. -txincludes= # TEXINPUTS extensions +txincludes= # TEXINPUTS extensions, with trailing colon txiprereq=19990129 # minimum texinfo.tex version to have macro expansion -quiet= # by default let the tools' message be displayed verbose=false # echo for verbose mode orig_pwd=`pwd` @@ -98,6 +105,12 @@ 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" # Unfortunately makeindex does not read TEXINPUTS. @@ -136,14 +149,21 @@ while test x"$1" != x"$arg_sep"; do -q | -s | --q* | --s*) quiet=t; batch=eval;; -c | --c*) clean=t;; -D | --d*) debug=t;; - -e | --e*) expand=t;; + -e | -E | --e*) expand=t;; -h | --h*) echo "$usage"; exit 0;; -I | --I*) shift miincludes="$miincludes -I $1" - txincludes="$txincludes$path_sep$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";; @@ -168,11 +188,20 @@ done shift # Interpret remaining command line args as filenames. -if test $# = 0; then +case $# in + 0) echo "$0: Missing file arguments." >&2 echo "$0: Try \`--help' for more information." >&2 exit 2 -fi + ;; + 1) ;; + *) + if test -n "$oname"; then + echo "$0: Can't use option \`--output' with more than one argument." >&2 + exit 2 + fi + ;; +esac # Prepare the temporary directory. Remove it at exit, unless debugging. if test -z "$debug"; then @@ -205,14 +234,23 @@ cat <<EOF >$comment_iftex_sed s/^@c texi2dvi// } } -/^@html/,/^@end html/d -/^@ifhtml/,/^@end ifhtml/d -/^@ifnottex/,/^@end ifnottex/d +/^@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 - d + 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 @@ -230,7 +268,7 @@ cat <<\EOF >$get_xref_files # 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 -# LaTeX tables and lists. +# 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 @@ -273,7 +311,7 @@ for command_line_filename in ${1+"$@"}; do # 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 \ + echo "$command_line_filename" | $EGREP '^(/|[A-z]:/)' >/dev/null \ || command_line_filename="./$command_line_filename" # See if the file exists. If it doesn't we're in trouble since, even @@ -314,22 +352,67 @@ for command_line_filename in ${1+"$@"}; do # 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. Put `.' and - # directory where source file(s) reside in TEXINPUTS before anything - # else. `.' goes first to ensure that any old .aux, .cps, + # 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=".$path_sep$orig_pwd$path_sep$filename_dir$path_sep$txincludes$path_sep" + 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" | fgrep 'input texinfo' >/dev/null; then + elif sed 1q "$command_line_filename" | grep 'input texinfo' >/dev/null; then language=texinfo else language= @@ -373,9 +456,9 @@ for command_line_filename in ${1+"$@"}; do 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'` + 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= @@ -467,10 +550,14 @@ for command_line_filename in ${1+"$@"}; do # 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?. + # 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!./$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 @@ -489,8 +576,8 @@ for command_line_filename in ${1+"$@"}; do # Prevent $ESCAPE from being interpreted by the shell if it happens # to be `/'. $batch tex_args="\\${escape}nonstopmode\ \\${escape}input" - $verbose "Running $cmd ..." 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 @@ -508,7 +595,7 @@ for command_line_filename in ${1+"$@"}; do # 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 fgrep "Rerun to get" "$filename_noext.log" >/dev/null 2>&1; then + if grep "Rerun to get" "$filename_noext.log" >/dev/null 2>&1; then finished= fi @@ -550,8 +637,13 @@ for command_line_filename in ${1+"$@"}; do # - the next file is processed in correct conditions # - the temporary file can be removed if test -n "$clean"; then - $verbose "Copying $oformat file from `pwd` to $orig_pwd" - cp -p "./$filename_noext.$oformat" "$orig_pwd" + 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 diff --git a/readline/emacs_keymap.c b/readline/emacs_keymap.c index ca9d1343b65..c7399534fdb 100644 --- a/readline/emacs_keymap.c +++ b/readline/emacs_keymap.c @@ -278,7 +278,13 @@ KEYMAP_ENTRY_ARRAY emacs_standard_keymap = { { ISFUNC, rl_insert }, /* Latin capital letter Y with acute */ { ISFUNC, rl_insert }, /* Latin capital letter thorn (Icelandic) */ { ISFUNC, rl_insert }, /* Latin small letter sharp s (German) */ +#ifndef __MINGW32__ { ISFUNC, rl_insert }, /* Latin small letter a with grave */ +#else + /* Temporary - this is a bug in readline 5.1 that should be fixed in + readline 5.2. */ + { ISFUNC, 0 }, /* Must leave this unbound for the arrow keys to work. */ +#endif { ISFUNC, rl_insert }, /* Latin small letter a with acute */ { ISFUNC, rl_insert }, /* Latin small letter a with circumflex */ { ISFUNC, rl_insert }, /* Latin small letter a with tilde */ diff --git a/readline/examples/ChangeLog.gdb b/readline/examples/ChangeLog.gdb index 5ff9ba18ddc..48966545f7c 100644 --- a/readline/examples/ChangeLog.gdb +++ b/readline/examples/ChangeLog.gdb @@ -1,3 +1,7 @@ +2006-04-24 Daniel Jacobowitz <dan@codesourcery.com> + + Imported readline 5.1, and upstream patches 001-004. + 2002-02-24 Elena Zannoni <ezannoni@redhat.com> * ChangeLog.gdb: Rename from ChangeLog.Cygnus. diff --git a/readline/examples/Makefile.in b/readline/examples/Makefile.in index 72c9904ff0f..e27bbc0cf6a 100644 --- a/readline/examples/Makefile.in +++ b/readline/examples/Makefile.in @@ -40,6 +40,8 @@ INCLUDES = -I$(srcdir) -I$(top_srcdir) -I.. CCFLAGS = $(DEFS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(INCLUDES) $(CFLAGS) LDFLAGS = -g -L.. @LDFLAGS@ +PURIFY = @PURIFY@ + READLINE_LIB = ../libreadline.a HISTORY_LIB = ../libhistory.a @@ -50,33 +52,35 @@ TERMCAP_LIB = @TERMCAP_LIB@ $(CC) $(CCFLAGS) -c $< EXECUTABLES = fileman rltest rl rlcat rlversion histexamp -OBJECTS = fileman.o rltest.o rl.o rlversion.o histexamp.o +OBJECTS = fileman.o rltest.o rl.o rlcat.o rlversion.o histexamp.o all: $(EXECUTABLES) -everything: all rlfe +everything: all rl: rl.o $(READLINE_LIB) - $(CC) $(LDFLAGS) -o $@ rl.o -lreadline $(TERMCAP_LIB) + $(PURIFY) $(CC) $(LDFLAGS) -o $@ rl.o $(READLINE_LIB) $(TERMCAP_LIB) rlcat: rlcat.o $(READLINE_LIB) - $(CC) $(LDFLAGS) -o $@ rlcat.o -lreadline $(TERMCAP_LIB) + $(PURIFY) $(CC) $(LDFLAGS) -o $@ rlcat.o $(READLINE_LIB) $(TERMCAP_LIB) fileman: fileman.o $(READLINE_LIB) - $(CC) $(LDFLAGS) -o $@ fileman.o -lreadline $(TERMCAP_LIB) + $(PURIFY) $(CC) $(LDFLAGS) -o $@ fileman.o $(READLINE_LIB) $(TERMCAP_LIB) rltest: rltest.o $(READLINE_LIB) - $(CC) $(LDFLAGS) -o $@ rltest.o -lreadline $(TERMCAP_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 -lreadline $(TERMCAP_LIB) + $(CC) $(LDFLAGS) -o $@ rlversion.o $(READLINE_LIB) $(TERMCAP_LIB) histexamp: histexamp.o $(HISTORY_LIB) - $(CC) $(LDFLAGS) -o $@ histexamp.o -lhistory $(TERMCAP_LIB) + $(PURIFY) $(CC) $(LDFLAGS) -o $@ histexamp.o -lhistory $(TERMCAP_LIB) clean mostlyclean: $(RM) $(OBJECTS) $(RM) $(EXECUTABLES) *.exe - $(RM) rlfe.o rlfe distclean maintainer-clean: clean $(RM) Makefile @@ -86,19 +90,13 @@ 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 - -# Stuff for Per Bothner's `rlfe' program - -rlfe: rlfe.o $(READLINE_LIB) $(HISTORY_LIB) - $(CC) $(LDFLAGS) -o $@ rlfe.o -lreadline -lhistory ${TERMCAP_LIB} - -rlfe.o: rlfe.c - -rlfe.o: $(top_srcdir)/readline.h -rlfe.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 diff --git a/readline/examples/histexamp.c b/readline/examples/histexamp.c index 45651dfb137..4f059c17cc3 100644 --- a/readline/examples/histexamp.c +++ b/readline/examples/histexamp.c @@ -26,14 +26,17 @@ # 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) @@ -42,71 +45,80 @@ main (argc, argv) 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; - - 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); - } + { + 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++) + { + 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"); + } + } } } diff --git a/readline/examples/rl.c b/readline/examples/rl.c index d2604895e52..c608c15f3d6 100644 --- a/readline/examples/rl.c +++ b/readline/examples/rl.c @@ -31,12 +31,19 @@ #include <stdio.h> #include <sys/types.h> -#include "posixstat.h" + +#ifdef HAVE_STDLIB_H +# include <stdlib.h> +#else +extern void exit(); +#endif #if defined (READLINE_LIBRARY) +# include "posixstat.h" # include "readline.h" # include "history.h" #else +# include <sys/stat.h> # include <readline/readline.h> # include <readline/history.h> #endif diff --git a/readline/examples/rlcat.c b/readline/examples/rlcat.c index 176b9f44b68..33aea4a3007 100644 --- a/readline/examples/rlcat.c +++ b/readline/examples/rlcat.c @@ -40,6 +40,12 @@ #include <string.h> #include <errno.h> +#ifdef HAVE_STDLIB_H +# include <stdlib.h> +#else +extern void exit(); +#endif + #ifndef errno extern int errno; #endif diff --git a/readline/examples/rlfe.c b/readline/examples/rlfe.c deleted file mode 100644 index d634d7ce878..00000000000 --- a/readline/examples/rlfe.c +++ /dev/null @@ -1,1042 +0,0 @@ -/* A front-end using readline to "cook" input lines for Kawa. - * - * Copyright (C) 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. - */ - -/* PROBLEMS/TODO: - * - * Only tested under Linux; needs to be ported. - * - * When running mc -c under the Linux console, mc does not recognize - * mouse clicks, which mc does when not running under fep. - * - * 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 fep 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. - * - * Desirable readline feature: When in cooked no-echo mode (e.g. password), - * echo characters are they are types with '*', but remove them when done. - * - * A synchronous 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. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#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 <limits.h> -#include <dirent.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/sh" -#endif -#ifndef COMMAND_ARGS -#define COMMAND_ARGS COMMAND -#endif - -#ifndef HAVE_MEMMOVE -#ifndef 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 -#endif - -#define APPLICATION_NAME "Rlfe" - -#ifndef errno -extern int errno; -#endif - -extern int optind; -extern char *optarg; - -static char *progname; -static char *progversion; - -static int in_from_inferior_fd; -static int out_to_inferior_fd; - -/* 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 */ - -static FILE *logfile = NULL; - -#ifdef DEBUG -FILE *debugfile = NULL; -#define DPRINT0(FMT) (fprintf(debugfile, FMT), fflush(debugfile)) -#define DPRINT1(FMT, V1) (fprintf(debugfile, FMT, V1), fflush(debugfile)) -#define DPRINT2(FMT, V1, V2) (fprintf(debugfile, FMT, V1, V2), fflush(debugfile)) -#else -#define DPRINT0(FMT) /* Do nothing */ -#define DPRINT1(FMT, V1) /* Do nothing */ -#define DPRINT2(FMT, V1, V2) /* Do nothing */ -#endif - -struct termios orig_term; - -static int rlfe_directory_completion_hook __P((char **)); -static int rlfe_directory_rewrite_hook __P((char **)); -static char *rlfe_filename_completion_function __P((const char *, int)); - -/* Pid of child process. */ -static pid_t child = -1; - -static void -sig_child (int signo) -{ - int status; - wait (&status); - 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_master_pty() takes a double-indirect character pointer in which - * to put a slave name, and returns an integer file descriptor. - * If it returns < 0, an error has occurred. - * Otherwise, it has returned the master pty file descriptor, and fills - * in *name with the name of the corresponding slave pty. - * Once the slave pty has been opened, you are responsible to free *name. - */ - -int get_master_pty(char **name) { - int i, j; - /* default to returning error */ - int master = -1; - - /* create a dummy name to fill in */ - *name = strdup("/dev/ptyXX"); - - /* search for an unused pty */ - for (i=0; i<16 && master <= 0; i++) { - for (j=0; j<16 && master <= 0; j++) { - (*name)[5] = 'p'; - (*name)[8] = "pqrstuvwxyzPQRST"[i]; - (*name)[9] = "0123456789abcdef"[j]; - /* open the master pty */ - if ((master = open(*name, O_RDWR)) < 0) { - if (errno == ENOENT) { - /* we are out of pty devices */ - free (*name); - return (master); - } - } - else { - /* By substituting a letter, we change the master pty - * name into the slave pty name. - */ - (*name)[5] = 't'; - if (access(*name, R_OK|W_OK) != 0) - { - close(master); - master = -1; - } - } - } - } - if ((master < 0) && (i == 16) && (j == 16)) { - /* must have tried every pty unsuccessfully */ - free (*name); - return (master); - } - - (*name)[5] = 't'; - - return (master); -} - -/* 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 num_keys = 0; - -static void -null_prep_terminal (int meta) -{ -} - -static void -null_deprep_terminal () -{ -} - -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; -} - -static void -usage() -{ - fprintf (stderr, "%s: usage: %s [-l filename] [-a] [-n appname] [-hv] [command [arguments...]]\n", - progname, progname); -} - -int -main(int argc, char** argv) -{ - char *path; - int i, append; - int master; - char *name, *logfname, *appname; - 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; - - if ((progname = strrchr (argv[0], '/')) == 0) - progname = argv[0]; - else - progname++; - progversion = RL_LIBRARY_VERSION; - - append = 0; - appname = APPLICATION_NAME; - logfname = (char *)NULL; - - while ((i = getopt (argc, argv, "ahl:n:v")) != EOF) - { - switch (i) - { - case 'l': - logfname = optarg; - break; - case 'n': - appname = optarg; - break; - case 'a': - append = 1; - break; - case 'h': - usage (); - exit (0); - case 'v': - fprintf (stderr, "%s version %s\n", progname, progversion); - exit (0); - default: - usage (); - exit (2); - } - } - - argc -= optind; - argv += optind; - - if (logfname) - { - logfile = fopen (logfname, append ? "a" : "w"); - if (logfile == 0) - fprintf (stderr, "%s: warning: could not open log file %s: %s\n", - progname, logfname, strerror (errno)); - } - - rl_readline_name = appname; - -#ifdef DEBUG - debugfile = fopen("LOG", "w"); -#endif - - if ((master = get_master_pty(&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); - } - free(name); -#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); - } - free(name); -#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 }; - if (argc < 1) - execvp(COMMAND, command_args); - else - execvp(argv[0], &argv[0]); - } - - /* should never be reached */ - exit(1); - } - - /* parent */ - signal (SIGCHLD, sig_child); - free(name); - - /* 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 - -#if 0 - t.c_lflag |= (ICANON | ISIG | ECHO | ECHOCTL | ECHOE | \ - ECHOK | ECHOKE | ECHONL | ECHOPRT ); -#else - t.c_lflag &= ~(ICANON | ISIG | ECHO | ECHOCTL | ECHOE | \ - ECHOK | ECHOKE | ECHONL | ECHOPRT ); -#endif - 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_callback_handler_install (prompt, line_handler); - -#if 1 - rl_directory_completion_hook = rlfe_directory_completion_hook; - rl_completion_entry_function = rlfe_filename_completion_function; -#else - rl_directory_rewrite_hook = rlfe_directory_rewrite_hook; -#endif - - 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 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) - { - DPRINT2 ("echo:%d, canon:%d\n", - (term_master.c_lflag & ECHO) != 0, - (term_master.c_lflag & ICANON) != 0); - do_canon = (term_master.c_lflag & ICANON) != 0; - readline_echoing_p = (term_master.c_lflag & ECHO) != 0; - } - 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)); - 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); - prompt = malloc (buf_count + 1); - if (prompt == NULL) - prompt = empty_string; - else - { - memcpy (prompt, buf, buf_count); - prompt[buf_count] = '\0'; - DPRINT1("New prompt '%s'\n", prompt); -#if 0 /* ifdef HAVE_RL_ALREADY_PROMPTED -- doesn't work */ - 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++; - rl_callback_read_char (); - } - } - else /* input 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); - if (count <= 0) - { - DPRINT0 ("(Connection closed by foreign host.)\n"); - tcsetattr(STDIN_FILENO, TCSANOW, &orig_term); - exit (0); - } - old_count = buf_count; - - /* Do some minimal carriage return translation and backspace - processing before logging the input line. */ - if (logfile) - { -#ifndef __GNUC__ - char *b; -#else - char b[count + 1]; -#endif - int i, j; - -#ifndef __GNUC__ - b = malloc (count + 1); - if (b) { -#endif - for (i = 0; i < count; i++) - b[i] = buf[buf_count + i]; - b[i] = '\0'; - for (i = j = 0; i <= count; i++) - { - if (b[i] == '\r') - { - if (b[i+1] != '\n') - b[j++] = '\n'; - } - else if (b[i] == '\b') - { - if (i) - j--; - } - else - b[j++] = b[i]; - } - fprintf (logfile, "%s", b); - -#ifndef __GNUC__ - free (b); - } -#endif - } - - /* 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++; - } - - /* 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); - } - } -} - -/* - * - * FILENAME COMPLETION FOR RLFE - * - */ - -#ifndef PATH_MAX -# define PATH_MAX 1024 -#endif - -#define DIRSEP '/' -#define ISDIRSEP(x) ((x) == '/') -#define PATHSEP(x) (ISDIRSEP(x) || (x) == 0) - -#define DOT_OR_DOTDOT(x) \ - ((x)[0] == '.' && (PATHSEP((x)[1]) || \ - ((x)[1] == '.' && PATHSEP((x)[2])))) - -#define FREE(x) if (x) free(x) - -#define STRDUP(s, x) do { \ - s = strdup (x);\ - if (s == 0) \ - return ((char *)NULL); \ - } while (0) - -static int -get_inferior_cwd (path, psize) - char *path; - size_t psize; -{ - int n; - static char procfsbuf[PATH_MAX] = { '\0' }; - - if (procfsbuf[0] == '\0') - sprintf (procfsbuf, "/proc/%d/cwd", (int)child); - n = readlink (procfsbuf, path, psize); - if (n < 0) - return n; - if (n > psize) - return -1; - path[n] = '\0'; - return n; -} - -static int -rlfe_directory_rewrite_hook (dirnamep) - char **dirnamep; -{ - char *ldirname, cwd[PATH_MAX], *retdir, *ld; - int n, ldlen; - - ldirname = *dirnamep; - - if (*ldirname == '/') - return 0; - - n = get_inferior_cwd (cwd, sizeof(cwd) - 1); - if (n < 0) - return 0; - if (n == 0) /* current directory */ - { - cwd[0] = '.'; - cwd[1] = '\0'; - n = 1; - } - - /* Minimally canonicalize ldirname by removing leading `./' */ - for (ld = ldirname; *ld; ) - { - if (ISDIRSEP (ld[0])) - ld++; - else if (ld[0] == '.' && PATHSEP(ld[1])) - ld++; - else - break; - } - ldlen = (ld && *ld) ? strlen (ld) : 0; - - retdir = (char *)malloc (n + ldlen + 3); - if (retdir == 0) - return 0; - if (ldlen) - sprintf (retdir, "%s/%s", cwd, ld); - else - strcpy (retdir, cwd); - free (ldirname); - - *dirnamep = retdir; - - DPRINT1("rl_directory_rewrite_hook returns %s\n", retdir); - return 1; -} - -/* Translate *DIRNAMEP to be relative to the inferior's CWD. Leave a trailing - slash on the result. */ -static int -rlfe_directory_completion_hook (dirnamep) - char **dirnamep; -{ - char *ldirname, *retdir; - int n, ldlen; - - ldirname = *dirnamep; - - if (*ldirname == '/') - return 0; - - n = rlfe_directory_rewrite_hook (dirnamep); - if (n == 0) - return 0; - - ldirname = *dirnamep; - ldlen = (ldirname && *ldirname) ? strlen (ldirname) : 0; - - if (ldlen == 0 || ldirname[ldlen - 1] != '/') - { - retdir = (char *)malloc (ldlen + 3); - if (retdir == 0) - return 0; - if (ldlen) - strcpy (retdir, ldirname); - else - retdir[ldlen++] = '.'; - retdir[ldlen] = '/'; - retdir[ldlen+1] = '\0'; - free (ldirname); - - *dirnamep = retdir; - } - - DPRINT1("rl_directory_completion_hook returns %s\n", retdir); - return 1; -} - -static char * -rlfe_filename_completion_function (text, state) - const char *text; - int state; -{ - static DIR *directory; - static char *filename = (char *)NULL; - static char *dirname = (char *)NULL, *ud = (char *)NULL; - static int flen, udlen; - char *temp; - struct dirent *dentry; - - if (state == 0) - { - if (directory) - { - closedir (directory); - directory = 0; - } - FREE (dirname); - FREE (filename); - FREE (ud); - - if (text && *text) - STRDUP (filename, text); - else - { - filename = malloc(1); - if (filename == 0) - return ((char *)NULL); - filename[0] = '\0'; - } - dirname = (text && *text) ? strdup (text) : strdup ("."); - if (dirname == 0) - return ((char *)NULL); - - temp = strrchr (dirname, '/'); - if (temp) - { - strcpy (filename, ++temp); - *temp = '\0'; - } - else - { - dirname[0] = '.'; - dirname[1] = '\0'; - } - - STRDUP (ud, dirname); - udlen = strlen (ud); - - rlfe_directory_completion_hook (&dirname); - - directory = opendir (dirname); - flen = strlen (filename); - - rl_filename_completion_desired = 1; - } - - dentry = 0; - while (directory && (dentry = readdir (directory))) - { - if (flen == 0) - { - if (DOT_OR_DOTDOT(dentry->d_name) == 0) - break; - } - else - { - if ((dentry->d_name[0] == filename[0]) && - (strlen (dentry->d_name) >= flen) && - (strncmp (filename, dentry->d_name, flen) == 0)) - break; - } - } - - if (dentry == 0) - { - if (directory) - { - closedir (directory); - directory = 0; - } - FREE (dirname); - FREE (filename); - FREE (ud); - dirname = filename = ud = 0; - return ((char *)NULL); - } - - if (ud == 0 || (ud[0] == '.' && ud[1] == '\0')) - temp = strdup (dentry->d_name); - else - { - temp = malloc (1 + udlen + strlen (dentry->d_name)); - strcpy (temp, ud); - strcpy (temp + udlen, dentry->d_name); - } - return (temp); -} diff --git a/readline/examples/rltest.c b/readline/examples/rltest.c index 99f083b2b9c..cb67bab80c5 100644 --- a/readline/examples/rltest.c +++ b/readline/examples/rltest.c @@ -31,6 +31,12 @@ #include <stdio.h> #include <sys/types.h> +#ifdef HAVE_STDLIB_H +# include <stdlib.h> +#else +extern void exit(); +#endif + #ifdef READLINE_LIBRARY # include "readline.h" # include "history.h" diff --git a/readline/examples/rlversion.c b/readline/examples/rlversion.c index 53949d1e3b7..6c8687488e9 100644 --- a/readline/examples/rlversion.c +++ b/readline/examples/rlversion.c @@ -30,6 +30,12 @@ #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 diff --git a/readline/funmap.c b/readline/funmap.c index fe9a1da43d7..9c760cc3475 100644 --- a/readline/funmap.c +++ b/readline/funmap.c @@ -131,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 }, @@ -175,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 }, diff --git a/readline/histexpand.c b/readline/histexpand.c index 6c81196161d..68470146902 100644 --- a/readline/histexpand.c +++ b/readline/histexpand.c @@ -1,6 +1,6 @@ /* 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. @@ -52,6 +52,8 @@ #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 */ @@ -65,6 +67,8 @@ static int subst_rhs_len; 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)); static char *quote_breaks PARAMS((char *)); @@ -202,23 +206,24 @@ get_history_event (string, caller_index, delimiting_quote) /* Only a closing `?' or a newline delimit a substring search string. */ for (local_index = i; c = string[i]; i++) + { #if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - int v; - mbstate_t ps; + if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + { + int v; + mbstate_t ps; + + memset (&ps, 0, sizeof (mbstate_t)); + /* These produce warnings because we're passing a const string to a + function that takes a non-const string. */ + _rl_adjust_point ((char *)string, i, &ps); + if ((v = _rl_get_char_len ((char *)string + i, &ps)) > 1) + { + i += v - 1; + continue; + } + } - memset (&ps, 0, sizeof (mbstate_t)); - /* These produce warnings because we're passing a const string to a - function that takes a non-const string. */ - _rl_adjust_point (string, i, &ps); - if ((v = _rl_get_char_len (string + i, &ps)) > 1) - { - i += v - 1; - continue; - } - } - else #endif /* HANDLE_MULTIBYTE */ if ((!substring_okay && (whitespace (c) || c == ':' || (history_search_delimiter_chars && member (c, history_search_delimiter_chars)) || @@ -226,6 +231,7 @@ get_history_event (string, caller_index, delimiting_quote) string[i] == '\n' || (substring_okay && string[i] == '?')) break; + } which = i - local_index; temp = (char *)xmalloc (1 + which); @@ -517,7 +523,7 @@ 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) @@ -599,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) { @@ -683,7 +695,7 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line) case 's': { char *new_event; - int delimiter, failed, si, l_temp; + int delimiter, failed, si, l_temp, ws, we; if (c == 's') { @@ -760,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 = (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; - - failed = 0; - - if (substitute_globally) - { - si += subst_rhs_len; - l_temp = strlen (temp); - substitute_globally++; - continue; - } - else - break; - } + { + /* 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); + } + + 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; + + 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) { @@ -879,7 +925,7 @@ 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. */ @@ -942,7 +988,7 @@ history_expand (hstring, output) /* `!' 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) @@ -984,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++; @@ -999,6 +1055,7 @@ history_expand (hstring, output) if (cc == '\'' || cc == history_expansion_char) i++; } + } if (string[i] != history_expansion_char) @@ -1010,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]; @@ -1061,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; @@ -1160,7 +1222,9 @@ history_expand (hstring, output) if (only_printing) { +#if 0 add_history (result); +#endif return (2); } @@ -1223,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++) @@ -1338,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 @@ -1351,7 +1514,6 @@ history_tokenize_internal (string, 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. */ @@ -1362,8 +1524,6 @@ history_tokenize_internal (string, wind, indp) 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++) ; @@ -1371,88 +1531,30 @@ history_tokenize_internal (string, wind, indp) return (result); start = i; - - if (member (string[i], "()\n")) - { - i++; - goto got_token; - } - if (member (string[i], "<>;&|$")) - { - int peek = string[i + 1]; + i = history_tokenize_word (string, start); - 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 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) { - 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]; + i++; + while (string[i] && member (string[i], history_word_delimiters)) + 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] = (char *)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); diff --git a/readline/histfile.c b/readline/histfile.c index c19630dc8f3..d1e54cc4c62 100644 --- a/readline/histfile.c +++ b/readline/histfile.c @@ -1,6 +1,6 @@ /* 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. @@ -23,8 +23,13 @@ /* 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,7 +37,7 @@ #include <stdio.h> #include <sys/types.h> -#ifndef _MINIX +#if ! defined (_MINIX) && defined (HAVE_SYS_FILE_H) # include <sys/file.h> #endif #include "posixstat.h" @@ -52,7 +57,7 @@ # undef HAVE_MMAP #endif -#ifdef HAVE_MMAP +#ifdef HISTORY_USE_MMAP # include <sys/mman.h> # ifdef MAP_FILE @@ -67,7 +72,7 @@ # define MAP_FAILED ((void *)-1) # endif -#endif /* HAVE_MMAP */ +#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 @@ -93,6 +98,13 @@ extern int errno; #include "rlshell.h" #include "xmalloc.h" +/* If non-zero, we write timestamps to the history file in history_do_write() */ +int history_write_timestamps = 0; + +/* Does S look like the beginning of a history timestamp entry? Placeholder + for more extensive tests. */ +#define HIST_TIMESTAMP_START(s) (*(s) == history_comment_char) + /* 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 (). */ @@ -151,13 +163,20 @@ read_history_range (filename, from, to) const char *filename; int from, to; { - register char *line_start, *line_end; - char *input, *buffer, *bufend; + 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); @@ -169,37 +188,42 @@ 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; -#elif defined (EOVERFLOW) - errno = EOVERFLOW; -#endif + errno = overflow_errno; goto error_and_exit; } -#ifdef HAVE_MMAP +#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) - goto error_and_exit; + { + errno = overflow_errno; + goto error_and_exit; + } chars_read = file_size; #else buffer = (char *)malloc (file_size + 1); if (buffer == 0) - goto error_and_exit; + { + errno = overflow_errno; + goto error_and_exit; + } chars_read = read (file, buffer, file_size); #endif if (chars_read < 0) { error_and_exit: - chars_read = errno; + if (errno != 0) + chars_read = errno; + else + chars_read = EIO; if (file >= 0) close (file); FREE (input); -#ifndef HAVE_MMAP +#ifndef HISTORY_USE_MMAP FREE (buffer); #endif @@ -220,8 +244,12 @@ read_history_range (filename, from, to) for (line_start = line_end = buffer; line_end < bufend && current_line < from; line_end++) if (*line_end == '\n') { - current_line++; - line_start = line_end + 1; + 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. */ @@ -234,7 +262,22 @@ read_history_range (filename, from, to) *line_end = '\0'; if (*line_start) - add_history (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++; @@ -245,7 +288,7 @@ read_history_range (filename, from, to) } FREE (input); -#ifndef HAVE_MMAP +#ifndef HISTORY_USE_MMAP FREE (buffer); #else munmap (buffer, file_size); @@ -262,7 +305,7 @@ history_truncate_file (fname, lines) const char *fname; int lines; { - char *buffer, *filename, *bp; + char *buffer, *filename, *bp, *bp1; /* bp1 == bp+1 */ int file, chars_read, rv; struct stat finfo; size_t file_size; @@ -325,11 +368,14 @@ history_truncate_file (fname, lines) } /* Count backwards from the end of buffer until we have passed - LINES lines. */ - for (bp = buffer + chars_read - 1; lines && bp > buffer; bp--) + LINES lines. bp1 is set funny initially. But since bp[1] can't + be a comment character (since it's off the end) and *bp can't be + both a newline and the history comment character, it should be OK. */ + for (bp1 = bp = buffer + chars_read - 1; lines && bp > buffer; bp--) { - if (*bp == '\n') + if (*bp == '\n' && HIST_TIMESTAMP_START(bp1) == 0) lines--; + bp1 = bp; } /* If this is the first line, then the file contains exactly the @@ -338,11 +384,14 @@ history_truncate_file (fname, lines) the current value of i and 0. Otherwise, write from the start of this line until the end of the buffer. */ for ( ; bp > buffer; bp--) - if (*bp == '\n') - { - bp++; - break; - } + { + 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. */ @@ -377,9 +426,9 @@ history_do_write (filename, nelements, overwrite) register int i; char *output; int file, mode, rv; +#ifdef HISTORY_USE_MMAP size_t cursize; -#ifdef HAVE_MMAP 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; @@ -393,7 +442,7 @@ history_do_write (filename, nelements, overwrite) return (errno); } -#ifdef HAVE_MMAP +#ifdef HISTORY_USE_MMAP cursize = overwrite ? 0 : lseek (file, 0, SEEK_END); #endif @@ -411,10 +460,18 @@ 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. */ -#ifdef HAVE_MMAP +#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); @@ -439,12 +496,18 @@ mmap_error: for (j = 0, i = history_length - nelements; i < history_length; i++) { + if (history_write_timestamps && the_history[i]->timestamp && the_history[i]->timestamp[0]) + { + strcpy (buffer + j, the_history[i]->timestamp); + j += strlen (the_history[i]->timestamp); + buffer[j++] = '\n'; + } strcpy (buffer + j, the_history[i]->line); j += strlen (the_history[i]->line); buffer[j++] = '\n'; } -#ifdef HAVE_MMAP +#ifdef HISTORY_USE_MMAP if (msync (buffer, buffer_size, 0) != 0 || munmap (buffer, buffer_size) != 0) rv = errno; #else diff --git a/readline/history.c b/readline/history.c index 4242f33efe1..a538f91c0d7 100644 --- a/readline/history.c +++ b/readline/history.c @@ -1,6 +1,6 @@ -/* 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. @@ -52,6 +52,8 @@ /* The number of slots to increase the_history by. */ #define DEFAULT_HISTORY_GROW_SIZE 50 +static char *hist_inittime PARAMS((void)); + /* **************************************************************** */ /* */ /* History Functions */ @@ -123,14 +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; for (i = result = 0; the_history && the_history[i]; i++) - result += strlen (the_history[i]->line); + result += HISTENT_BYTES (the_history[i]); return (result); } @@ -201,11 +204,45 @@ 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 @@ -225,10 +262,7 @@ add_history (string) /* 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++) @@ -260,10 +294,41 @@ 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. */ @@ -275,7 +340,7 @@ replace_history_entry (which, line, data) { HIST_ENTRY *temp, *old_value; - if (which >= history_length) + if (which < 0 || which >= history_length) return ((HIST_ENTRY *)NULL); temp = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY)); @@ -283,6 +348,7 @@ replace_history_entry (which, line, data) temp->line = savestring (line); temp->data = data; + temp->timestamp = savestring (old_value->timestamp); the_history[which] = temp; return (old_value); @@ -298,17 +364,15 @@ remove_history (which) HIST_ENTRY *return_value; register int i; - if (which >= history_length || !history_length) - return_value = (HIST_ENTRY *)NULL; - else - { - return_value = the_history[which]; + if (which < 0 || which >= history_length || history_length == 0 || the_history == 0) + return ((HIST_ENTRY *)NULL); - for (i = which; i < history_length; i++) - the_history[i] = the_history[i + 1]; + return_value = the_history[which]; - history_length--; - } + for (i = which; i < history_length; i++) + the_history[i] = the_history[i + 1]; + + history_length--; return (return_value); } @@ -327,10 +391,7 @@ stifle_history (max) { /* 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++) @@ -372,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; } diff --git a/readline/history.h b/readline/history.h index 58b5de4655f..14ca2a996c7 100644 --- a/readline/history.h +++ b/readline/history.h @@ -1,5 +1,5 @@ -/* 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. @@ -26,6 +26,8 @@ extern "C" { #endif +#include <time.h> /* XXX - for history timestamp code */ + #if defined READLINE_LIBRARY # include "rlstdc.h" # include "rltypedefs.h" @@ -43,9 +45,13 @@ typedef char *histdata_t; /* The structure used to store a history entry. */ typedef struct _hist_entry { char *line; + 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. */ @@ -76,11 +82,19 @@ extern void history_set_history_state PARAMS((HISTORY_STATE *)); The associated data field (if any) is set to NULL. */ 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 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. */ @@ -119,6 +133,10 @@ extern HIST_ENTRY *current_history PARAMS((void)); array. OFFSET is relative to history_base. */ 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 PARAMS((void)); @@ -231,6 +249,8 @@ 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; diff --git a/readline/histsearch.c b/readline/histsearch.c index d94fd6cd9c6..1cc5875a4b4 100644 --- a/readline/histsearch.c +++ b/readline/histsearch.c @@ -77,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) diff --git a/readline/input.c b/readline/input.c index 9120dfa8a8d..9f8905384d2 100644 --- a/readline/input.c +++ b/readline/input.c @@ -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. @@ -21,6 +21,10 @@ 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 @@ -154,6 +158,12 @@ _rl_unget_char (key) return (0); } +int +_rl_pushed_input_available () +{ + return (push_index != pop_index); +} + /* If a character is available to be read, then read it and stuff it into IBUFFER. Otherwise, just return. Returns number of characters read (0 if none available) and -1 on error (EIO). */ @@ -162,7 +172,7 @@ rl_gather_tyi () { int tty; register int tem, result; - int chars_avail; + int chars_avail, k; char input; #if defined(HAVE_SELECT) fd_set readfds, exceptfds; @@ -202,9 +212,24 @@ rl_gather_tyi () fcntl (tty, F_SETFL, tem); if (chars_avail == -1 && errno == EAGAIN) return 0; + if (chars_avail == 0) /* EOF */ + { + rl_stuff_char (EOF); + return (0); + } } #endif /* O_NDELAY */ +#if defined (__MINGW32__) + /* We use getch to read console input, so use the same + mechanism to check for more. Otherwise, we don't know. */ + if (isatty (fileno (rl_instream))) + chars_avail = _kbhit (); + else + chars_avail = 0; + result = 0; +#endif + /* If there's nothing available, don't waste time trying to read something. */ if (chars_avail <= 0) @@ -225,7 +250,12 @@ 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 { @@ -285,6 +315,13 @@ _rl_input_available () #endif +#if defined (__MINGW32__) + /* We use getch to read console input, so use the same + mechanism to check for more. Otherwise, we don't know. */ + if (isatty (fileno (rl_instream))) + return _kbhit (); +#endif + return 0; } @@ -424,12 +461,9 @@ rl_getc (stream) while (1) { -#ifdef __MINGW32__ - /* On Windows, use a special routine to read a single character - from the console. (Otherwise, no characters are available - until the user hits the return key.) */ +#if defined (__MINGW32__) if (isatty (fileno (stream))) - return getch (); + return (getch ()); #endif result = read (fileno (stream), &c, sizeof (unsigned char)); @@ -506,6 +540,12 @@ _rl_read_mbchar (mbchar, size) ps = ps_back; continue; } + else if (mbchar_bytes_length == 0) + { + mbchar[0] = '\0'; /* null wide character */ + mb_len = 1; + break; + } else if (mbchar_bytes_length > (size_t)(0)) break; } diff --git a/readline/isearch.c b/readline/isearch.c index c1ea5b30852..d7d8520ed85 100644 --- a/readline/isearch.c +++ b/readline/isearch.c @@ -4,7 +4,7 @@ /* */ /* **************************************************************** */ -/* Copyright (C) 1987-2002 Free Software Foundation, Inc. +/* Copyright (C) 1987-2005 Free Software Foundation, Inc. This file contains the Readline Library (the Library), a set of routines for providing Emacs style line input to programs that ask @@ -56,12 +56,17 @@ /* Variables exported to other files in the readline library. */ char *_rl_isearch_terminators = (char *)NULL; +_rl_search_cxt *_rl_iscxt = 0; + /* Variables imported from other files in the readline library. */ extern HIST_ENTRY *_rl_saved_line_for_history; -/* Forward declarations */ static int rl_search_history PARAMS((int, int)); +static _rl_search_cxt *_rl_isearch_init PARAMS((int)); +static void _rl_isearch_fini PARAMS((_rl_search_cxt *)); +static int _rl_isearch_cleanup PARAMS((_rl_search_cxt *, int)); + /* Last line found by the current incremental search, so we don't `find' identical lines many times in a row. */ static char *prev_line_found; @@ -72,6 +77,57 @@ static int last_isearch_string_len; static char *default_isearch_terminators = "\033\012"; +_rl_search_cxt * +_rl_scxt_alloc (type, flags) + int type, flags; +{ + _rl_search_cxt *cxt; + + cxt = (_rl_search_cxt *)xmalloc (sizeof (_rl_search_cxt)); + + cxt->type = type; + cxt->sflags = flags; + + cxt->search_string = 0; + cxt->search_string_size = cxt->search_string_index = 0; + + cxt->lines = 0; + cxt->allocated_line = 0; + cxt->hlen = cxt->hindex = 0; + + cxt->save_point = rl_point; + cxt->save_mark = rl_mark; + cxt->save_line = where_history (); + cxt->last_found_line = cxt->save_line; + cxt->prev_line_found = 0; + + cxt->save_undo_list = 0; + + cxt->history_pos = 0; + cxt->direction = 0; + + cxt->lastc = 0; + + cxt->sline = 0; + cxt->sline_len = cxt->sline_index = 0; + + cxt->search_terminators = 0; + + return cxt; +} + +void +_rl_scxt_dispose (cxt, flags) + _rl_search_cxt *cxt; + int flags; +{ + FREE (cxt->search_string); + FREE (cxt->allocated_line); + FREE (cxt->lines); + + free (cxt); +} + /* Search backwards through the history looking for a string which is typed interactively. Start with the current line. */ int @@ -92,7 +148,7 @@ rl_forward_search_history (sign, key) /* Display the current state of the search in the echo-area. SEARCH_STRING contains the string that is being searched for, - DIRECTION is zero for forward, or 1 for reverse, + DIRECTION is zero for forward, or non-zero for reverse, WHERE is the history list number of the current line. If it is -1, then this line is the starting one. */ static void @@ -140,66 +196,23 @@ rl_display_search (search_string, reverse_p, where) (*rl_redisplay_function) (); } -/* 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 - backwards. */ -static int -rl_search_history (direction, invoking_key) - int direction, invoking_key; +static _rl_search_cxt * +_rl_isearch_init (direction) + int direction; { - /* The string that the user types in to search for. */ - char *search_string; - - /* The current length of SEARCH_STRING. */ - int search_string_index; - - /* The amount of space that SEARCH_STRING has allocated to it. */ - int search_string_size; - - /* The list of lines to search through. */ - char **lines, *allocated_line; - - /* The length of LINES. */ - int hlen; - - /* Where we get LINES from. */ - HIST_ENTRY **hlist; - + _rl_search_cxt *cxt; register int i; - int orig_point, orig_mark, orig_line, last_found_line; - int c, found, failed, sline_len; - int n, wstart, wlen; -#if defined (HANDLE_MULTIBYTE) - char mb[MB_LEN_MAX]; -#endif - - /* The line currently being searched. */ - char *sline; - - /* Offset in that line. */ - int line_index; - - /* Non-zero if we are doing a reverse search. */ - int reverse; + HIST_ENTRY **hlist; - /* The list of characters which terminate the search, but are not - subsequently executed. If the variable isearch-terminators has - been set, we use that value, otherwise we use ESC and C-J. */ - char *isearch_terminators; + cxt = _rl_scxt_alloc (RL_SEARCH_ISEARCH, 0); + if (direction < 0) + cxt->sflags |= SF_REVERSE; - RL_SETSTATE(RL_STATE_ISEARCH); - orig_point = rl_point; - orig_mark = rl_mark; - last_found_line = orig_line = where_history (); - reverse = direction < 0; - hlist = history_list (); - allocated_line = (char *)NULL; - - isearch_terminators = _rl_isearch_terminators ? _rl_isearch_terminators + 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) @@ -207,354 +220,447 @@ rl_search_history (direction, invoking_key) /* 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; + 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) - lines[i] = _rl_saved_line_for_history->line; + cxt->lines[i] = _rl_saved_line_for_history->line; else { /* Keep track of this so we can free it. */ - allocated_line = (char *)xmalloc (1 + strlen (rl_line_buffer)); - strcpy (allocated_line, &rl_line_buffer[0]); - lines[i] = allocated_line; + cxt->allocated_line = (char *)xmalloc (1 + strlen (rl_line_buffer)); + strcpy (cxt->allocated_line, &rl_line_buffer[0]); + cxt->lines[i] = cxt->allocated_line; } - hlen++; + cxt->hlen++; /* The line where we start the search. */ - i = orig_line; + cxt->history_pos = cxt->save_line; rl_save_prompt (); /* Initialize search parameters. */ - search_string = (char *)xmalloc (search_string_size = 128); - *search_string = '\0'; - search_string_index = 0; - prev_line_found = (char *)0; /* XXX */ + 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. */ - direction = (direction >= 0) ? 1 : -1; + cxt->direction = (direction >= 0) ? 1 : -1; - rl_display_search (search_string, reverse, -1); + cxt->sline = rl_line_buffer; + cxt->sline_len = strlen (cxt->sline); + cxt->sline_index = rl_point; - sline = rl_line_buffer; - sline_len = strlen (sline); - line_index = rl_point; + _rl_iscxt = cxt; /* save globally */ - found = failed = 0; - for (;;) + 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) { - rl_command_func_t *f = (rl_command_func_t *)NULL; + 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; + } - /* Read a key and decide how to proceed. */ - RL_SETSTATE(RL_STATE_MOREINPUT); - c = rl_read_key (); - RL_UNSETSTATE(RL_STATE_MOREINPUT); + 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 = _rl_read_mbstring (c, mb, MB_LEN_MAX); + if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + c = cxt->lastc = _rl_read_mbstring (cxt->lastc, cxt->mb, MB_LEN_MAX); #endif - /* Translate the keys we do something with to opcodes. */ - if (c >= 0 && _rl_keymap[c].type == ISFUNC) - { - f = _rl_keymap[c].function; - - if (f == rl_reverse_search_history) - c = reverse ? -1 : -2; - else if (f == rl_forward_search_history) - c = !reverse ? -1 : -2; - else if (f == rl_rubout) - c = -3; - else if (c == CTRL ('G')) - c = -4; - else if (c == CTRL ('W')) /* XXX */ - c = -5; - else if (c == CTRL ('Y')) /* XXX */ - c = -6; - } + return c; +} - /* The characters in isearch_terminators (set from the user-settable - variable isearch-terminators) are used to terminate the search but - not subsequently execute the character as a command. The default - value is "\033\012" (ESC and C-J). */ - if (strchr (isearch_terminators, c)) - { - /* ESC still terminates the search, but if there is pending - input or if input arrives within 0.1 seconds (on systems - with select(2)) it is used as a prefix character - with rl_execute_next. WATCH OUT FOR THIS! This is intended - to allow the arrow keys to be used like ^F and ^B are used - to terminate the search and execute the movement command. - XXX - since _rl_input_available depends on the application- - settable keyboard timeout value, this could alternatively - use _rl_input_queued(100000) */ - if (c == ESC && _rl_input_available ()) - rl_execute_next (ESC); - break; - } +/* 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 (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 (c >= 0 && strlen (mb) == 1 && ENDSRCH_CHAR (c)) + if (last_isearch_string) { - /* This sets rl_pending_input to c; it will be picked up the next - time rl_read_key is called. */ - rl_execute_next (c); + 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 -#endif - if (c >= 0 && ENDSRCH_CHAR (c)) + 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) { - /* This sets rl_pending_input to c; it will be picked up the next - time rl_read_key is called. */ - rl_execute_next (c); + rl_ding (); break; } - switch (c) + /* if not in a word, move to one. */ + cval = _rl_char_value (rl_line_buffer, wstart); + if (_rl_walphabetic (cval) == 0) { - case -1: - if (search_string_index == 0) - { - if (last_isearch_string) - { - search_string_size = 64 + last_isearch_string_len; - search_string = (char *)xrealloc (search_string, search_string_size); - strcpy (search_string, last_isearch_string); - search_string_index = last_isearch_string_len; - rl_display_search (search_string, reverse, -1); - break; - } - continue; - } - else if (reverse) - --line_index; - else if (line_index != sline_len) - ++line_index; - else - rl_ding (); + rl_ding (); break; - - /* switch directions */ - case -2: - direction = -direction; - reverse = direction < 0; + } + 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; + } - /* delete character from search string. */ - case -3: /* C-H, DEL */ - /* This is tricky. To do this right, we need to keep a - stack of search positions for the current search, with - sentinels marking the beginning and end. But this will - do until we have a real isearch-undo. */ - if (search_string_index == 0) - rl_ding (); - else - search_string[--search_string_index] = '\0'; - - break; + for (cxt->sflags &= ~(SF_FOUND|SF_FAILED);; ) + { + limit = cxt->sline_len - cxt->search_string_index + 1; - case -4: /* C-G */ - rl_replace_line (lines[orig_line], 0); - rl_point = orig_point; - rl_mark = orig_mark; - rl_restore_prompt(); - rl_clear_message (); - if (allocated_line) - free (allocated_line); - free (lines); - RL_UNSETSTATE(RL_STATE_ISEARCH); - return 0; - - case -5: /* C-W */ - /* skip over portion of line we already matched */ - wstart = rl_point + search_string_index; - if (wstart >= rl_end) + /* 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)) { - rl_ding (); + cxt->sflags |= SF_FOUND; break; } + else + cxt->sline_index += cxt->direction; + } + if (cxt->sflags & SF_FOUND) + break; - /* if not in a word, move to one. */ - if (rl_alphabetic(rl_line_buffer[wstart]) == 0) - { - rl_ding (); - break; - } - n = wstart; - while (n < rl_end && rl_alphabetic(rl_line_buffer[n])) - n++; - wlen = n - wstart + 1; - if (search_string_index + wlen + 1 >= search_string_size) - { - search_string_size += wlen + 1; - search_string = (char *)xrealloc (search_string, search_string_size); - } - for (; wstart < n; wstart++) - search_string[search_string_index++] = rl_line_buffer[wstart]; - search_string[search_string_index] = '\0'; - break; + /* 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; - case -6: /* C-Y */ - /* skip over portion of line we already matched */ - wstart = rl_point + search_string_index; - if (wstart >= rl_end) + /* At limit for direction? */ + if ((cxt->sflags & SF_REVERSE) ? (cxt->history_pos < 0) : (cxt->history_pos == cxt->hlen)) { - rl_ding (); + cxt->sflags |= SF_FAILED; break; } - n = rl_end - wstart + 1; - if (search_string_index + n + 1 >= search_string_size) - { - search_string_size += n + 1; - search_string = (char *)xrealloc (search_string, search_string_size); - } - for (n = wstart; n < rl_end; n++) - search_string[search_string_index++] = rl_line_buffer[n]; - search_string[search_string_index] = '\0'; - break; - default: - /* Add character to search string and continue search. */ - if (search_string_index + 2 >= search_string_size) - { - search_string_size += 128; - search_string = (char *)xrealloc (search_string, search_string_size); - } -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - { - int j, l; - for (j = 0, l = strlen (mb); j < l; ) - search_string[search_string_index++] = mb[j++]; - } - else -#endif - search_string[search_string_index++] = c; - search_string[search_string_index] = '\0'; - break; + /* 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)); - for (found = failed = 0;;) - { - int limit = sline_len - search_string_index + 1; + if (cxt->sflags & SF_FAILED) + break; - /* 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; + /* Now set up the line for searching... */ + cxt->sline_index = (cxt->sflags & SF_REVERSE) ? cxt->sline_len - cxt->search_string_index : 0; + } - /* 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 (cxt->sflags & SF_FAILED) + { + /* We cannot find the search string. Ding the bell. */ + rl_ding (); + cxt->history_pos = cxt->last_found_line; + return 1; + } - if (failed) - 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 (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); + } - /* Now set up the line for searching... */ - line_index = reverse ? sline_len - search_string_index : 0; - } + return 1; +} - if (failed) - { - /* We cannot find the search string. Ding the bell. */ - rl_ding (); - i = last_found_line; - continue; /* XXX - was break */ - } +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; - /* We have found the search string. Just display it. But don't - actually move there in the history list until the user accepts - the location. */ - if (found) - { - prev_line_found = lines[i]; - rl_replace_line (lines[i], 0); - rl_point = line_index; - last_found_line = i; - rl_display_search (search_string, reverse, (i == orig_line) ? -1 : i); - } - } + RL_UNSETSTATE(RL_STATE_ISEARCH); - /* 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. */ + return (r != 0); +} - /* First put back the original state. */ - strcpy (rl_line_buffer, lines[orig_line]); +/* 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 + backwards. */ +static int +rl_search_history (direction, invoking_key) + int direction, invoking_key; +{ + _rl_search_cxt *cxt; /* local for now, but saved globally */ + int c, r; - rl_restore_prompt (); + RL_SETSTATE(RL_STATE_ISEARCH); + cxt = _rl_isearch_init (direction); - /* Save the search string for possible later use. */ - FREE (last_isearch_string); - last_isearch_string = search_string; - last_isearch_string_len = search_string_index; + rl_display_search (cxt->search_string, (cxt->sflags & SF_REVERSE), -1); - if (last_found_line < orig_line) - rl_get_previous_history (orig_line - last_found_line, 0); - else - rl_get_next_history (last_found_line - orig_line, 0); + /* If 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); - /* If the string was not found, put point at the end of the last matching - line. If last_found_line == orig_line, we didn't find any matching - history lines at all, so put point back in its original position. */ - if (line_index < 0) + r = -1; + for (;;) { - if (last_found_line == orig_line) - line_index = orig_point; - else - line_index = strlen (rl_line_buffer); - rl_mark = orig_mark; + 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; } - rl_point = line_index; - /* Don't worry about where to put the mark here; rl_get_previous_history - and rl_get_next_history take care of it. */ - - rl_clear_message (); + /* 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. */ + return (_rl_isearch_cleanup (cxt, r)); +} - FREE (allocated_line); - free (lines); +#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; - RL_UNSETSTATE(RL_STATE_ISEARCH); + c = _rl_search_getchar (cxt); + /* We might want to handle EOF here */ + r = _rl_isearch_dispatch (cxt, cxt->lastc); - return 0; + return (r <= 0) ? _rl_isearch_cleanup (cxt, r) : 0; } +#endif diff --git a/readline/keymaps.c b/readline/keymaps.c index 12506d3aab2..70d0cc08d3f 100644 --- a/readline/keymaps.c +++ b/readline/keymaps.c @@ -64,11 +64,13 @@ rl_make_bare_keymap () 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 */ diff --git a/readline/kill.c b/readline/kill.c index a616b920d90..1d3254c3275 100644 --- a/readline/kill.c +++ b/readline/kill.c @@ -339,6 +339,47 @@ rl_unix_word_rubout (count, key) if (rl_editing_mode == emacs_mode) rl_mark = rl_point; } + + return 0; +} + +/* This deletes one filename component in a Unix pathname. That is, it + deletes backward to directory separator (`/') or whitespace. */ +int +rl_unix_filename_rubout (count, key) + int count, key; +{ + int orig_point, c; + + if (rl_point == 0) + rl_ding (); + else + { + orig_point = rl_point; + if (count <= 0) + count = 1; + + while (count--) + { + c = rl_line_buffer[rl_point - 1]; + while (rl_point && (whitespace (c) || c == '/')) + { + rl_point--; + c = rl_line_buffer[rl_point - 1]; + } + + while (rl_point && (whitespace (c) == 0) && c != '/') + { + rl_point--; + c = rl_line_buffer[rl_point - 1]; + } + } + + rl_kill_text (orig_point, rl_point); + if (rl_editing_mode == emacs_mode) + rl_mark = rl_point; + } + return 0; } diff --git a/readline/macro.c b/readline/macro.c index b73c3af9aa4..2975bf1f74f 100644 --- a/readline/macro.c +++ b/readline/macro.c @@ -100,6 +100,8 @@ _rl_with_macro_input (string) int _rl_next_macro_key () { + int c; + if (rl_executing_macro == 0) return (0); @@ -109,7 +111,14 @@ _rl_next_macro_key () return (_rl_next_macro_key ()); } +#if defined (READLINE_CALLBACKS) + c = rl_executing_macro[executing_macro_index++]; + if (RL_ISSTATE (RL_STATE_CALLBACK) && RL_ISSTATE (RL_STATE_READCMD) && rl_executing_macro[executing_macro_index] == 0) + _rl_pop_executing_macro (); + return c; +#else return (rl_executing_macro[executing_macro_index++]); +#endif } /* Save the currently executing macro on a stack of saved macros. */ diff --git a/readline/mbutil.c b/readline/mbutil.c index 8794d02ddca..17dde53ed7b 100644 --- a/readline/mbutil.c +++ b/readline/mbutil.c @@ -1,6 +1,6 @@ /* mbutil.c -- readline multibyte character utility functions */ -/* Copyright (C) 2001 Free Software Foundation, Inc. +/* Copyright (C) 2001-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -77,27 +77,29 @@ _rl_find_next_mbchar_internal (string, seed, count, find_non_zero) char *string; int seed, count, find_non_zero; { - size_t tmp = 0; + size_t tmp; mbstate_t ps; - int point = 0; + int point; wchar_t wc; + tmp = 0; + memset(&ps, 0, sizeof (mbstate_t)); if (seed < 0) seed = 0; if (count <= 0) return seed; - point = seed + _rl_adjust_point(string, seed, &ps); + point = seed + _rl_adjust_point (string, seed, &ps); /* if this is true, means that seed was not pointed character started byte. So correct the point and consume count */ if (seed < point) - count --; + count--; while (count > 0) { tmp = mbrtowc (&wc, string+point, strlen(string + point), &ps); - if ((size_t)(tmp) == (size_t)-1 || (size_t)(tmp) == (size_t)-2) + if (MB_INVALIDCH ((size_t)tmp)) { /* invalid bytes. asume a byte represents a character */ point++; @@ -105,9 +107,8 @@ _rl_find_next_mbchar_internal (string, seed, count, find_non_zero) /* reset states. */ memset(&ps, 0, sizeof(mbstate_t)); } - else if (tmp == (size_t)0) - /* found '\0' char */ - break; + else if (MB_NULLWCH (tmp)) + break; /* found wide '\0' */ else { /* valid bytes */ @@ -127,15 +128,16 @@ _rl_find_next_mbchar_internal (string, seed, count, find_non_zero) if (find_non_zero) { tmp = mbrtowc (&wc, string + point, strlen (string + point), &ps); - while (wcwidth (wc) == 0) + while (tmp > 0 && wcwidth (wc) == 0) { point += tmp; tmp = mbrtowc (&wc, string + point, strlen (string + point), &ps); - if (tmp == (size_t)(0) || tmp == (size_t)(-1) || tmp == (size_t)(-2)) + if (MB_NULLWCH (tmp) || MB_INVALIDCH (tmp)) break; } } - return point; + + return point; } static int @@ -160,7 +162,7 @@ _rl_find_prev_mbchar_internal (string, seed, find_non_zero) while (point < seed) { tmp = mbrtowc (&wc, string + point, length - point, &ps); - if ((size_t)(tmp) == (size_t)-1 || (size_t)(tmp) == (size_t)-2) + if (MB_INVALIDCH ((size_t)tmp)) { /* in this case, bytes are invalid or shorted to compose multibyte char, so assume that the first byte represents @@ -169,8 +171,12 @@ _rl_find_prev_mbchar_internal (string, seed, find_non_zero) /* clear the state of the byte sequence, because in this case effect of mbstate is undefined */ memset(&ps, 0, sizeof (mbstate_t)); + + /* Since we're assuming that this byte represents a single + non-zero-width character, don't forget about it. */ + prev = point; } - else if (tmp == 0) + else if (MB_NULLWCH (tmp)) break; /* Found '\0' char. Can this happen? */ else { @@ -273,7 +279,7 @@ _rl_adjust_point(string, point, ps) while (pos < point) { tmp = mbrlen (string + pos, length - pos, ps); - if((size_t)(tmp) == (size_t)-1 || (size_t)(tmp) == (size_t)-2) + if (MB_INVALIDCH ((size_t)tmp)) { /* in this case, bytes are invalid or shorted to compose multibyte char, so assume that the first byte represents @@ -284,7 +290,7 @@ _rl_adjust_point(string, point, ps) if (ps) memset (ps, 0, sizeof (mbstate_t)); } - else if (tmp == 0) + else if (MB_NULLWCH (tmp)) pos++; else pos += tmp; @@ -310,6 +316,28 @@ _rl_is_mbchar_matched (string, seed, end, mbchar, length) return 0; return 1; } + +wchar_t +_rl_char_value (buf, ind) + char *buf; + int ind; +{ + size_t tmp; + wchar_t wc; + mbstate_t ps; + int l; + + if (MB_LEN_MAX == 1 || rl_byte_oriented) + return ((wchar_t) buf[ind]); + l = strlen (buf); + if (ind >= l - 1) + return ((wchar_t) buf[ind]); + memset (&ps, 0, sizeof (mbstate_t)); + tmp = mbrtowc (&wc, buf + ind, l - ind, &ps); + if (MB_INVALIDCH (tmp) || MB_NULLWCH (tmp)) + return ((wchar_t) buf[ind]); + return wc; +} #endif /* HANDLE_MULTIBYTE */ /* Find next `count' characters started byte point of the specified seed. diff --git a/readline/misc.c b/readline/misc.c index f3775d30ecb..d4558321dec 100644 --- a/readline/misc.c +++ b/readline/misc.c @@ -1,6 +1,6 @@ /* misc.c -- miscellaneous bindable readline functions. */ -/* Copyright (C) 1987-2002 Free Software Foundation, Inc. +/* Copyright (C) 1987-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -63,6 +63,8 @@ void _rl_free_history_entry PARAMS((HIST_ENTRY *)); to preserve the value of rl_point from line to line. */ int _rl_history_preserve_point = 0; +_rl_arg_cxt _rl_argcxt; + /* Saved target point for when _rl_history_preserve_point is set. Special value of -1 means that point is at the end of the line. */ int _rl_history_saved_point = -1; @@ -73,77 +75,74 @@ int _rl_history_saved_point = -1; /* */ /* **************************************************************** */ -/* Handle C-u style numeric args, as well as M--, and M-digits. */ -static int -rl_digit_loop () +int +_rl_arg_overflow () { - int key, c, sawminus, sawdigits; + if (rl_numeric_arg > 1000000) + { + _rl_argcxt = 0; + rl_explicit_arg = rl_numeric_arg = 0; + rl_ding (); + rl_restore_prompt (); + rl_clear_message (); + RL_UNSETSTATE(RL_STATE_NUMERICARG); + return 1; + } + return 0; +} +void +_rl_arg_init () +{ rl_save_prompt (); - + _rl_argcxt = 0; RL_SETSTATE(RL_STATE_NUMERICARG); - sawminus = sawdigits = 0; - while (1) - { - if (rl_numeric_arg > 1000000) - { - sawdigits = rl_explicit_arg = rl_numeric_arg = 0; - rl_ding (); - rl_restore_prompt (); - rl_clear_message (); - RL_UNSETSTATE(RL_STATE_NUMERICARG); - return 1; - } - rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg); - RL_SETSTATE(RL_STATE_MOREINPUT); - key = c = rl_read_key (); - RL_UNSETSTATE(RL_STATE_MOREINPUT); +} - if (c < 0) - { - _rl_abort_internal (); - return -1; - } +int +_rl_arg_getchar () +{ + int c; - /* If we see a key bound to `universal-argument' after seeing digits, - it ends the argument but is otherwise ignored. */ - if (_rl_keymap[c].type == ISFUNC && - _rl_keymap[c].function == rl_universal_argument) - { - if (sawdigits == 0) - { - rl_numeric_arg *= 4; - continue; - } - else - { - RL_SETSTATE(RL_STATE_MOREINPUT); - key = rl_read_key (); - RL_UNSETSTATE(RL_STATE_MOREINPUT); - rl_restore_prompt (); - rl_clear_message (); - RL_UNSETSTATE(RL_STATE_NUMERICARG); - return (_rl_dispatch (key, _rl_keymap)); - } - } + rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg); + RL_SETSTATE(RL_STATE_MOREINPUT); + c = rl_read_key (); + RL_UNSETSTATE(RL_STATE_MOREINPUT); - c = UNMETA (c); + return c; +} - if (_rl_digit_p (c)) - { - rl_numeric_arg = rl_explicit_arg ? (rl_numeric_arg * 10) + c - '0' : c - '0'; - sawdigits = rl_explicit_arg = 1; - } - else if (c == '-' && rl_explicit_arg == 0) +/* Process C as part of the current numeric argument. Return -1 if the + argument should be aborted, 0 if we should not read any more chars, and + 1 if we should continue to read chars. */ +int +_rl_arg_dispatch (cxt, c) + _rl_arg_cxt cxt; + int c; +{ + int key, r; + + key = c; + + /* If we see a key bound to `universal-argument' after seeing digits, + it ends the argument but is otherwise ignored. */ + if (_rl_keymap[c].type == ISFUNC && _rl_keymap[c].function == rl_universal_argument) + { + if ((cxt & NUM_SAWDIGITS) == 0) { - rl_numeric_arg = sawminus = 1; - rl_arg_sign = -1; + rl_numeric_arg *= 4; + return 1; } + else if (RL_ISSTATE (RL_STATE_CALLBACK)) + { + _rl_argcxt |= NUM_READONE; + return 0; /* XXX */ + } else { - /* Make M-- command equivalent to M--1 command. */ - if (sawminus && rl_numeric_arg == 1 && rl_explicit_arg == 0) - rl_explicit_arg = 1; + RL_SETSTATE(RL_STATE_MOREINPUT); + key = rl_read_key (); + RL_UNSETSTATE(RL_STATE_MOREINPUT); rl_restore_prompt (); rl_clear_message (); RL_UNSETSTATE(RL_STATE_NUMERICARG); @@ -151,35 +150,96 @@ rl_digit_loop () } } - /*NOTREACHED*/ -} + c = UNMETA (c); -/* Add the current digit to the argument in progress. */ -int -rl_digit_argument (ignore, key) - int ignore, key; -{ - rl_execute_next (key); - return (rl_digit_loop ()); + if (_rl_digit_p (c)) + { + r = _rl_digit_value (c); + rl_numeric_arg = rl_explicit_arg ? (rl_numeric_arg * 10) + r : r; + rl_explicit_arg = 1; + _rl_argcxt |= NUM_SAWDIGITS; + } + else if (c == '-' && rl_explicit_arg == 0) + { + rl_numeric_arg = 1; + _rl_argcxt |= NUM_SAWMINUS; + rl_arg_sign = -1; + } + else + { + /* Make M-- command equivalent to M--1 command. */ + if ((_rl_argcxt & NUM_SAWMINUS) && rl_numeric_arg == 1 && rl_explicit_arg == 0) + rl_explicit_arg = 1; + rl_restore_prompt (); + rl_clear_message (); + RL_UNSETSTATE(RL_STATE_NUMERICARG); + + r = _rl_dispatch (key, _rl_keymap); + if (RL_ISSTATE (RL_STATE_CALLBACK)) + { + /* At worst, this will cause an extra redisplay. Otherwise, + we have to wait until the next character comes in. */ + if (rl_done == 0) + (*rl_redisplay_function) (); + r = 0; + } + return r; + } + + return 1; } -/* What to do when you abort reading an argument. */ -int -rl_discard_argument () +/* Handle C-u style numeric args, as well as M--, and M-digits. */ +static int +rl_digit_loop () { - rl_ding (); - rl_clear_message (); - _rl_init_argument (); - return 0; + int c, r; + + while (1) + { + if (_rl_arg_overflow ()) + return 1; + + c = _rl_arg_getchar (); + + if (c < 0) + { + _rl_abort_internal (); + return -1; + } + + r = _rl_arg_dispatch (_rl_argcxt, c); + if (r <= 0 || (RL_ISSTATE (RL_STATE_NUMERICARG) == 0)) + break; + } } /* Create a default argument. */ -int -_rl_init_argument () +void +_rl_reset_argument () { rl_numeric_arg = rl_arg_sign = 1; rl_explicit_arg = 0; - return 0; + _rl_argcxt = 0; +} + +/* Start a numeric argument with initial value KEY */ +int +rl_digit_argument (ignore, key) + int ignore, key; +{ + _rl_arg_init (); + if (RL_ISSTATE (RL_STATE_CALLBACK)) + { + _rl_arg_dispatch (_rl_argcxt, key); + rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg); + return 0; + } + else + { + rl_execute_next (key); + return (rl_digit_loop ()); + } } /* C-u, universal argument. Multiply the current argument by 4. @@ -189,8 +249,43 @@ int rl_universal_argument (count, key) int count, key; { + _rl_arg_init (); rl_numeric_arg *= 4; - return (rl_digit_loop ()); + + return (RL_ISSTATE (RL_STATE_CALLBACK) ? 0 : rl_digit_loop ()); +} + +int +_rl_arg_callback (cxt) + _rl_arg_cxt cxt; +{ + int c, r; + + c = _rl_arg_getchar (); + + if (_rl_argcxt & NUM_READONE) + { + _rl_argcxt &= ~NUM_READONE; + rl_restore_prompt (); + rl_clear_message (); + RL_UNSETSTATE(RL_STATE_NUMERICARG); + rl_execute_next (c); + return 0; + } + + r = _rl_arg_dispatch (cxt, c); + return (r != 1); +} + +/* What to do when you abort reading an argument. */ +int +rl_discard_argument () +{ + rl_ding (); + rl_clear_message (); + _rl_reset_argument (); + + return 0; } /* **************************************************************** */ @@ -225,8 +320,10 @@ _rl_free_history_entry (entry) { if (entry == 0) return; - if (entry->line) - free (entry->line); + + FREE (entry->line); + FREE (entry->timestamp); + free (entry); } @@ -242,6 +339,7 @@ rl_maybe_replace_line () { temp = replace_history_entry (where_history (), rl_line_buffer, (histdata_t)rl_undo_list); free (temp->line); + FREE (temp->timestamp); free (temp); } return 0; @@ -253,6 +351,8 @@ rl_maybe_unsave_line () { if (_rl_saved_line_for_history) { + /* Can't call with `1' because rl_undo_list might point to an undo + list from a history entry, as in rl_replace_from_history() below. */ rl_replace_line (_rl_saved_line_for_history->line, 0); rl_undo_list = (UNDO_LIST *)_rl_saved_line_for_history->data; _rl_free_history_entry (_rl_saved_line_for_history); @@ -272,8 +372,10 @@ rl_maybe_save_line () { _rl_saved_line_for_history = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY)); _rl_saved_line_for_history->line = savestring (rl_line_buffer); + _rl_saved_line_for_history->timestamp = (char *)NULL; _rl_saved_line_for_history->data = (char *)rl_undo_list; } + return 0; } @@ -298,7 +400,7 @@ _rl_history_set_point () rl_point = rl_end; #if defined (VI_MODE) - if (rl_editing_mode == vi_mode) + if (rl_editing_mode == vi_mode && _rl_keymap != vi_insertion_keymap) rl_point = 0; #endif /* VI_MODE */ @@ -311,6 +413,8 @@ rl_replace_from_history (entry, flags) HIST_ENTRY *entry; int flags; /* currently unused */ { + /* Can't call with `1' because rl_undo_list might point to an undo list + from a history entry, just like we're setting up here. */ rl_replace_line (entry->line, 0); rl_undo_list = (UNDO_LIST *)entry->data; rl_point = rl_end; @@ -435,6 +539,7 @@ rl_get_previous_history (count, key) rl_replace_from_history (temp, 0); _rl_history_set_point (); } + return 0; } diff --git a/readline/nls.c b/readline/nls.c index 706c8195c10..bcee87561aa 100644 --- a/readline/nls.c +++ b/readline/nls.c @@ -75,6 +75,23 @@ static char *normalize_codeset PARAMS((char *)); static char *find_codeset PARAMS((char *, size_t *)); #endif /* !HAVE_SETLOCALE */ +static char *_rl_get_locale_var PARAMS((const char *)); + +static char * +_rl_get_locale_var (v) + const char *v; +{ + char *lspec; + + lspec = sh_get_env_value ("LC_ALL"); + if (lspec == 0 || *lspec == 0) + lspec = sh_get_env_value (v); + if (lspec == 0 || *lspec == 0) + lspec = sh_get_env_value ("LANG"); + + return lspec; +} + /* Check for LC_ALL, LC_CTYPE, and LANG and use the first with a value to decide the defaults for 8-bit character input and output. Returns 1 if we set eight-bit mode. */ @@ -84,10 +101,21 @@ _rl_init_eightbit () /* If we have setlocale(3), just check the current LC_CTYPE category value, and go into eight-bit mode if it's not C or POSIX. */ #if defined (HAVE_SETLOCALE) - char *t; + char *lspec, *t; /* Set the LC_CTYPE locale category from environment variables. */ - t = setlocale (LC_CTYPE, ""); + lspec = _rl_get_locale_var ("LC_CTYPE"); + /* Since _rl_get_locale_var queries the right environment variables, + we query the current locale settings with setlocale(), and, if + that doesn't return anything, we set lspec to the empty string to + force the subsequent call to setlocale() to define the `native' + environment. */ + if (lspec == 0 || *lspec == 0) + lspec = setlocale (LC_CTYPE, (char *)NULL); + if (lspec == 0) + lspec = ""; + t = setlocale (LC_CTYPE, lspec); + if (t && *t && (t[0] != 'C' || t[1]) && (STREQ (t, "POSIX") == 0)) { _rl_meta_flag = 1; @@ -105,9 +133,8 @@ _rl_init_eightbit () /* We don't have setlocale. Finesse it. Check the environment for the appropriate variables and set eight-bit mode if they have the right values. */ - lspec = sh_get_env_value ("LC_ALL"); - if (lspec == 0) lspec = sh_get_env_value ("LC_CTYPE"); - if (lspec == 0) lspec = sh_get_env_value ("LANG"); + lspec = _rl_get_locale_var ("LC_CTYPE"); + if (lspec == 0 || (t = normalize_codeset (lspec)) == 0) return (0); for (i = 0; t && legal_lang_values[i]; i++) diff --git a/readline/parens.c b/readline/parens.c index 54ef1f3695f..737f7675e93 100644 --- a/readline/parens.c +++ b/readline/parens.c @@ -21,6 +21,10 @@ 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #define READLINE_LIBRARY +#if defined (__TANDEM) +# include <floss.h> +#endif + #include "rlconf.h" #if defined (HAVE_CONFIG_H) diff --git a/readline/posixdir.h b/readline/posixdir.h index 505e27954f1..91f6d96111d 100644 --- a/readline/posixdir.h +++ b/readline/posixdir.h @@ -25,7 +25,11 @@ #if defined (HAVE_DIRENT_H) # include <dirent.h> -# define D_NAMLEN(d) (strlen ((d)->d_name)) +# if defined (HAVE_STRUCT_DIRENT_D_NAMLEN) +# define D_NAMLEN(d) ((d)->d_namlen) +# else +# define D_NAMLEN(d) (strlen ((d)->d_name)) +# endif /* !HAVE_STRUCT_DIRENT_D_NAMLEN */ #else # if defined (HAVE_SYS_NDIR_H) # include <sys/ndir.h> @@ -42,11 +46,11 @@ # define D_NAMLEN(d) ((d)->d_namlen) #endif /* !HAVE_DIRENT_H */ -#if defined (STRUCT_DIRENT_HAS_D_INO) && !defined (STRUCT_DIRENT_HAS_D_FILENO) +#if defined (HAVE_STRUCT_DIRENT_D_INO) && !defined (HAVE_STRUCT_DIRENT_D_FILENO) # define d_fileno d_ino #endif -#if defined (_POSIX_SOURCE) && (!defined (STRUCT_DIRENT_HAS_D_INO) || defined (BROKEN_DIRENT_D_INO)) +#if defined (_POSIX_SOURCE) && (!defined (HAVE_STRUCT_DIRENT_D_INO) || defined (BROKEN_DIRENT_D_INO)) /* Posix does not require that the d_ino field be present, and some systems do not provide it. */ # define REAL_DIR_ENTRY(dp) 1 diff --git a/readline/readline.c b/readline/readline.c index 07fb58fd210..5eaaf47435e 100644 --- a/readline/readline.c +++ b/readline/readline.c @@ -1,7 +1,7 @@ /* readline.c -- a general facility for reading lines of input with emacs style editing and completion. */ -/* Copyright (C) 1987-2002 Free Software Foundation, Inc. +/* Copyright (C) 1987-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -68,11 +68,11 @@ #include "xmalloc.h" #ifndef RL_LIBRARY_VERSION -# define RL_LIBRARY_VERSION "4.3" +# define RL_LIBRARY_VERSION "5.1" #endif #ifndef RL_READLINE_VERSION -# define RL_READLINE_VERSION 0x0403 +# define RL_READLINE_VERSION 0x0501 #endif extern void _rl_free_history_entry PARAMS((HIST_ENTRY *)); @@ -85,6 +85,10 @@ static void bind_arrow_keys_internal PARAMS((Keymap)); static void bind_arrow_keys PARAMS((void)); static void readline_default_bindings PARAMS((void)); +static void reset_default_bindings PARAMS((void)); + +static int _rl_subseq_result PARAMS((int, Keymap, int, int)); +static int _rl_subseq_getchar PARAMS((int)); /* **************************************************************** */ /* */ @@ -103,6 +107,7 @@ int rl_gnu_readline_p = 1; By default, it is the standard emacs keymap. */ Keymap _rl_keymap = emacs_standard_keymap; + /* The current style of editing. */ int rl_editing_mode = emacs_mode; @@ -218,6 +223,9 @@ char *_rl_comment_begin; /* Keymap holding the function currently being executed. */ Keymap rl_executing_keymap; +/* Keymap we're currently using to dispatch. */ +Keymap _rl_dispatching_keymap; + /* Non-zero means to erase entire line, including prompt, on empty input lines. */ int rl_erase_empty_line = 0; @@ -229,6 +237,9 @@ int rl_num_chars_to_read; char *rl_line_buffer = (char *)NULL; int rl_line_buffer_len = 0; +/* Key sequence `contexts' */ +_rl_keyseq_cxt *_rl_kscxt = 0; + /* Forward declarations used by the display, termcap, and history code. */ /* **************************************************************** */ @@ -250,6 +261,10 @@ int _rl_convert_meta_chars_to_ascii = 1; rather than as a meta-prefixed escape sequence. */ int _rl_output_meta_chars = 0; +/* Non-zero means to look at the termios special characters and bind + them to equivalent readline functions at startup. */ +int _rl_bind_stty_chars = 1; + /* **************************************************************** */ /* */ /* Top Level Functions */ @@ -267,6 +282,7 @@ rl_set_prompt (prompt) { FREE (rl_prompt); rl_prompt = prompt ? savestring (prompt) : (char *)NULL; + rl_display_prompt = rl_prompt ? rl_prompt : ""; rl_visible_prompt_length = rl_expand_prompt (rl_prompt); return 0; @@ -290,14 +306,16 @@ readline (prompt) rl_set_prompt (prompt); rl_initialize (); - (*rl_prep_term_function) (_rl_meta_flag); + if (rl_prep_term_function) + (*rl_prep_term_function) (_rl_meta_flag); #if defined (HANDLE_SIGNALS) rl_set_signals (); #endif value = readline_internal (); - (*rl_deprep_term_function) (); + if (rl_deprep_term_function) + (*rl_deprep_term_function) (); #if defined (HANDLE_SIGNALS) rl_clear_signals (); @@ -347,7 +365,7 @@ readline_internal_setup () #if defined (VI_MODE) if (rl_editing_mode == vi_mode) - rl_vi_insertion_mode (1, 0); + rl_vi_insertion_mode (1, 'i'); #endif /* VI_MODE */ if (rl_pre_input_hook) @@ -387,6 +405,36 @@ readline_internal_teardown (eof) return (eof ? (char *)NULL : savestring (the_line)); } +void +_rl_internal_char_cleanup () +{ +#if defined (VI_MODE) + /* In vi mode, when you exit insert mode, the cursor moves back + over the previous character. We explicitly check for that here. */ + if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap) + rl_vi_check (); +#endif /* VI_MODE */ + + if (rl_num_chars_to_read && rl_end >= rl_num_chars_to_read) + { + (*rl_redisplay_function) (); + _rl_want_redisplay = 0; + rl_newline (1, '\n'); + } + + if (rl_done == 0) + { + (*rl_redisplay_function) (); + _rl_want_redisplay = 0; + } + + /* If the application writer has told us to erase the entire line if + the only character typed was something bound to rl_newline, do so. */ + if (rl_erase_empty_line && rl_done && rl_last_func == rl_newline && + rl_point == 0 && rl_end == 0) + _rl_erase_entire_line (); +} + STATIC_CALLBACK int #if defined (READLINE_CALLBACKS) readline_internal_char () @@ -409,12 +457,21 @@ readline_internal_charloop () code = setjmp (readline_top_level); if (code) - (*rl_redisplay_function) (); + { + (*rl_redisplay_function) (); + _rl_want_redisplay = 0; + /* If we get here, we're not being called from something dispatched + from _rl_callback_read_char(), which sets up its own value of + readline_top_level (saving and restoring the old, of course), so + we can just return here. */ + if (RL_ISSTATE (RL_STATE_CALLBACK)) + return (0); + } if (rl_pending_input == 0) { /* Then initialize the argument and number of keys read. */ - _rl_init_argument (); + _rl_reset_argument (); rl_key_sequence_length = 0; } @@ -448,27 +505,7 @@ readline_internal_charloop () if (rl_pending_input == 0 && lk == _rl_last_command_was_kill) _rl_last_command_was_kill = 0; -#if defined (VI_MODE) - /* In vi mode, when you exit insert mode, the cursor moves back - over the previous character. We explicitly check for that here. */ - if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap) - rl_vi_check (); -#endif /* VI_MODE */ - - if (rl_num_chars_to_read && rl_end >= rl_num_chars_to_read) - { - (*rl_redisplay_function) (); - rl_newline (1, '\n'); - } - - if (rl_done == 0) - (*rl_redisplay_function) (); - - /* If the application writer has told us to erase the entire line if - the only character typed was something bound to rl_newline, do so. */ - if (rl_erase_empty_line && rl_done && rl_last_func == rl_newline && - rl_point == 0 && rl_end == 0) - _rl_erase_entire_line (); + _rl_internal_char_cleanup (); #if defined (READLINE_CALLBACKS) return 0; @@ -518,6 +555,107 @@ _rl_set_the_line () the_line = rl_line_buffer; } +#if defined (READLINE_CALLBACKS) +_rl_keyseq_cxt * +_rl_keyseq_cxt_alloc () +{ + _rl_keyseq_cxt *cxt; + + cxt = (_rl_keyseq_cxt *)xmalloc (sizeof (_rl_keyseq_cxt)); + + cxt->flags = cxt->subseq_arg = cxt->subseq_retval = 0; + + cxt->okey = 0; + cxt->ocxt = _rl_kscxt; + cxt->childval = 42; /* sentinel value */ + + return cxt; +} + +void +_rl_keyseq_cxt_dispose (cxt) + _rl_keyseq_cxt *cxt; +{ + free (cxt); +} + +void +_rl_keyseq_chain_dispose () +{ + _rl_keyseq_cxt *cxt; + + while (_rl_kscxt) + { + cxt = _rl_kscxt; + _rl_kscxt = _rl_kscxt->ocxt; + _rl_keyseq_cxt_dispose (cxt); + } +} +#endif + +static int +_rl_subseq_getchar (key) + int key; +{ + int k; + + if (key == ESC) + RL_SETSTATE(RL_STATE_METANEXT); + RL_SETSTATE(RL_STATE_MOREINPUT); + k = rl_read_key (); + RL_UNSETSTATE(RL_STATE_MOREINPUT); + if (key == ESC) + RL_UNSETSTATE(RL_STATE_METANEXT); + + return k; +} + +#if defined (READLINE_CALLBACKS) +int +_rl_dispatch_callback (cxt) + _rl_keyseq_cxt *cxt; +{ + int nkey, r; + + /* For now */ +#if 1 + /* The first time this context is used, we want to read input and dispatch + on it. When traversing the chain of contexts back `up', we want to use + the value from the next context down. We're simulating recursion using + a chain of contexts. */ + if ((cxt->flags & KSEQ_DISPATCHED) == 0) + { + nkey = _rl_subseq_getchar (cxt->okey); + r = _rl_dispatch_subseq (nkey, cxt->dmap, cxt->subseq_arg); + cxt->flags |= KSEQ_DISPATCHED; + } + else + r = cxt->childval; +#else + r = _rl_dispatch_subseq (nkey, cxt->dmap, cxt->subseq_arg); +#endif + + /* For now */ + r = _rl_subseq_result (r, cxt->oldmap, cxt->okey, (cxt->flags & KSEQ_SUBSEQ)); + + if (r == 0) /* success! */ + { + _rl_keyseq_chain_dispose (); + RL_UNSETSTATE (RL_STATE_MULTIKEY); + return r; + } + + if (r != -3) /* magic value that says we added to the chain */ + _rl_kscxt = cxt->ocxt; + if (_rl_kscxt) + _rl_kscxt->childval = r; + if (r != -3) + _rl_keyseq_cxt_dispose (cxt); + + return r; +} +#endif /* READLINE_CALLBACKS */ + /* Do the command associated with KEY in MAP. If the associated command is really a keymap, then read another key, and dispatch into that map. */ @@ -526,6 +664,7 @@ _rl_dispatch (key, map) register int key; Keymap map; { + _rl_dispatching_keymap = map; return _rl_dispatch_subseq (key, map, 0); } @@ -538,6 +677,9 @@ _rl_dispatch_subseq (key, map, got_subseq) int r, newkey; char *macro; rl_command_func_t *func; +#if defined (READLINE_CALLBACKS) + _rl_keyseq_cxt *cxt; +#endif if (META_CHAR (key) && _rl_convert_meta_chars_to_ascii) { @@ -571,13 +713,9 @@ _rl_dispatch_subseq (key, map, got_subseq) rl_executing_keymap = map; -#if 0 - _rl_suppress_redisplay = (map[key].function == rl_insert) && _rl_input_available (); -#endif - rl_dispatching = 1; RL_SETSTATE(RL_STATE_DISPATCHING); - r = (*map[key].function)(rl_numeric_arg * rl_arg_sign, key); + (*map[key].function)(rl_numeric_arg * rl_arg_sign, key); RL_UNSETSTATE(RL_STATE_DISPATCHING); rl_dispatching = 0; @@ -606,6 +744,10 @@ _rl_dispatch_subseq (key, map, got_subseq) } else { +#if defined (READLINE_CALLBACKS) + RL_UNSETSTATE (RL_STATE_MULTIKEY); + _rl_keyseq_chain_dispose (); +#endif _rl_abort_internal (); return -1; } @@ -627,44 +769,43 @@ _rl_dispatch_subseq (key, map, got_subseq) #endif rl_key_sequence_length++; + _rl_dispatching_keymap = FUNCTION_TO_KEYMAP (map, key); - if (key == ESC) - RL_SETSTATE(RL_STATE_METANEXT); - RL_SETSTATE(RL_STATE_MOREINPUT); - newkey = rl_read_key (); - RL_UNSETSTATE(RL_STATE_MOREINPUT); - if (key == ESC) - RL_UNSETSTATE(RL_STATE_METANEXT); + /* Allocate new context here. Use linked contexts (linked through + cxt->ocxt) to simulate recursion */ +#if defined (READLINE_CALLBACKS) + if (RL_ISSTATE (RL_STATE_CALLBACK)) + { + /* Return 0 only the first time, to indicate success to + _rl_callback_read_char. The rest of the time, we're called + from _rl_dispatch_callback, so we return 3 to indicate + special handling is necessary. */ + r = RL_ISSTATE (RL_STATE_MULTIKEY) ? -3 : 0; + cxt = _rl_keyseq_cxt_alloc (); + + if (got_subseq) + cxt->flags |= KSEQ_SUBSEQ; + cxt->okey = key; + cxt->oldmap = map; + cxt->dmap = _rl_dispatching_keymap; + cxt->subseq_arg = got_subseq || cxt->dmap[ANYOTHERKEY].function; + + RL_SETSTATE (RL_STATE_MULTIKEY); + _rl_kscxt = cxt; + + return r; /* don't indicate immediate success */ + } +#endif + newkey = _rl_subseq_getchar (key); if (newkey < 0) { _rl_abort_internal (); return -1; } - r = _rl_dispatch_subseq (newkey, FUNCTION_TO_KEYMAP (map, key), got_subseq || map[ANYOTHERKEY].function); - - if (r == -2) - /* We didn't match anything, and the keymap we're indexed into - shadowed a function previously bound to that prefix. Call - the function. The recursive call to _rl_dispatch_subseq has - already taken care of pushing any necessary input back onto - the input queue with _rl_unget_char. */ - r = _rl_dispatch (ANYOTHERKEY, FUNCTION_TO_KEYMAP (map, key)); - else if (r && map[ANYOTHERKEY].function) - { - /* We didn't match (r is probably -1), so return something to - tell the caller that it should try ANYOTHERKEY for an - overridden function. */ - _rl_unget_char (key); - return -2; - } - else if (r && got_subseq) - { - /* OK, back up the chain. */ - _rl_unget_char (key); - return -1; - } + r = _rl_dispatch_subseq (newkey, _rl_dispatching_keymap, got_subseq || map[ANYOTHERKEY].function); + return _rl_subseq_result (r, map, key, got_subseq); } else { @@ -688,9 +829,69 @@ _rl_dispatch_subseq (key, map, got_subseq) _rl_vi_textmod_command (key)) _rl_vi_set_last (key, rl_numeric_arg, rl_arg_sign); #endif + return (r); } +static int +_rl_subseq_result (r, map, key, got_subseq) + int r; + Keymap map; + int key, got_subseq; +{ + Keymap m; + int type, nt; + rl_command_func_t *func, *nf; + + if (r == -2) + /* We didn't match anything, and the keymap we're indexed into + shadowed a function previously bound to that prefix. Call + the function. The recursive call to _rl_dispatch_subseq has + already taken care of pushing any necessary input back onto + the input queue with _rl_unget_char. */ + { + m = _rl_dispatching_keymap; + type = m[ANYOTHERKEY].type; + func = m[ANYOTHERKEY].function; + if (type == ISFUNC && func == rl_do_lowercase_version) + r = _rl_dispatch (_rl_to_lower (key), map); + else if (type == ISFUNC && func == rl_insert) + { + /* If the function that was shadowed was self-insert, we + somehow need a keymap with map[key].func == self-insert. + Let's use this one. */ + nt = m[key].type; + nf = m[key].function; + + m[key].type = type; + m[key].function = func; + r = _rl_dispatch (key, m); + m[key].type = nt; + m[key].function = nf; + } + else + r = _rl_dispatch (ANYOTHERKEY, m); + } + else if (r && map[ANYOTHERKEY].function) + { + /* We didn't match (r is probably -1), so return something to + tell the caller that it should try ANYOTHERKEY for an + overridden function. */ + _rl_unget_char (key); + _rl_dispatching_keymap = map; + return -2; + } + else if (r && got_subseq) + { + /* OK, back up the chain. */ + _rl_unget_char (key); + _rl_dispatching_keymap = map; + return -1; + } + + return r; +} + /* **************************************************************** */ /* */ /* Initializations */ @@ -839,7 +1040,7 @@ readline_initialize_everything () /* If the completion parser's default word break characters haven't been set yet, then do so now. */ if (rl_completer_word_break_characters == (char *)NULL) - rl_completer_word_break_characters = rl_basic_word_break_characters; + rl_completer_word_break_characters = (char *)rl_basic_word_break_characters; } /* If this system allows us to look at the values of the regular @@ -848,7 +1049,20 @@ readline_initialize_everything () static void readline_default_bindings () { - rl_tty_set_default_bindings (_rl_keymap); + if (_rl_bind_stty_chars) + rl_tty_set_default_bindings (_rl_keymap); +} + +/* Reset the default bindings for the terminal special characters we're + interested in back to rl_insert and read the new ones. */ +static void +reset_default_bindings () +{ + if (_rl_bind_stty_chars) + { + rl_tty_unset_default_bindings (_rl_keymap); + rl_tty_set_default_bindings (_rl_keymap); + } } /* Bind some common arrow key sequences in MAP. */ @@ -862,42 +1076,33 @@ bind_arrow_keys_internal (map) _rl_keymap = map; #if defined (__MSDOS__) - _rl_bind_if_unbound ("\033[0A", rl_get_previous_history); - _rl_bind_if_unbound ("\033[0B", rl_backward_char); - _rl_bind_if_unbound ("\033[0C", rl_forward_char); - _rl_bind_if_unbound ("\033[0D", rl_get_next_history); + rl_bind_keyseq_if_unbound ("\033[0A", rl_get_previous_history); + rl_bind_keyseq_if_unbound ("\033[0B", rl_backward_char); + rl_bind_keyseq_if_unbound ("\033[0C", rl_forward_char); + rl_bind_keyseq_if_unbound ("\033[0D", rl_get_next_history); #endif -#ifdef __MINGW32__ - /* Under Windows, when an extend key (like an arrow key) is - pressed, getch() will return 340 (octal) followed by a code for - the extended key. We use macros to transform those into the - normal ANSI terminal sequences for these keys. */ - - /* Up arrow. */ - rl_macro_bind ("\340H", "\033[A", map); - /* Left arrow. */ - rl_macro_bind ("\340K", "\033[D", map); - /* Right arrow. */ - rl_macro_bind ("\340M", "\033[C", map); - /* Down arrow. */ - rl_macro_bind ("\340P", "\033[B", map); + rl_bind_keyseq_if_unbound ("\033[A", rl_get_previous_history); + rl_bind_keyseq_if_unbound ("\033[B", rl_get_next_history); + rl_bind_keyseq_if_unbound ("\033[C", rl_forward_char); + rl_bind_keyseq_if_unbound ("\033[D", rl_backward_char); + rl_bind_keyseq_if_unbound ("\033[H", rl_beg_of_line); + rl_bind_keyseq_if_unbound ("\033[F", rl_end_of_line); + + rl_bind_keyseq_if_unbound ("\033OA", rl_get_previous_history); + rl_bind_keyseq_if_unbound ("\033OB", rl_get_next_history); + rl_bind_keyseq_if_unbound ("\033OC", rl_forward_char); + rl_bind_keyseq_if_unbound ("\033OD", rl_backward_char); + rl_bind_keyseq_if_unbound ("\033OH", rl_beg_of_line); + rl_bind_keyseq_if_unbound ("\033OF", rl_end_of_line); + +#if defined (__MINGW32__) + rl_bind_keyseq_if_unbound ("\340H", rl_get_previous_history); + rl_bind_keyseq_if_unbound ("\340P", rl_get_next_history); + rl_bind_keyseq_if_unbound ("\340M", rl_forward_char); + rl_bind_keyseq_if_unbound ("\340K", rl_backward_char); #endif - _rl_bind_if_unbound ("\033[A", rl_get_previous_history); - _rl_bind_if_unbound ("\033[B", rl_get_next_history); - _rl_bind_if_unbound ("\033[C", rl_forward_char); - _rl_bind_if_unbound ("\033[D", rl_backward_char); - _rl_bind_if_unbound ("\033[H", rl_beg_of_line); - _rl_bind_if_unbound ("\033[F", rl_end_of_line); - - _rl_bind_if_unbound ("\033OA", rl_get_previous_history); - _rl_bind_if_unbound ("\033OB", rl_get_next_history); - _rl_bind_if_unbound ("\033OC", rl_forward_char); - _rl_bind_if_unbound ("\033OD", rl_backward_char); - _rl_bind_if_unbound ("\033OH", rl_beg_of_line); - _rl_bind_if_unbound ("\033OF", rl_end_of_line); - _rl_keymap = xkeymap; } @@ -950,9 +1155,7 @@ rl_save_state (sp) sp->macro = rl_executing_macro; sp->catchsigs = rl_catch_signals; -#if defined (SIGWINCH) sp->catchsigwinch = rl_catch_sigwinch; -#endif return (0); } @@ -986,9 +1189,7 @@ rl_restore_state (sp) rl_executing_macro = sp->macro; rl_catch_signals = sp->catchsigs; -#if defined (SIGWINCH) rl_catch_sigwinch = sp->catchsigwinch; -#endif return (0); } diff --git a/readline/readline.h b/readline/readline.h index f11b3d0357c..fade6d41d2f 100644 --- a/readline/readline.h +++ b/readline/readline.h @@ -1,6 +1,6 @@ /* Readline.h -- the names of functions callable from within readline. */ -/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1987-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -40,9 +40,9 @@ extern "C" { #endif /* Hex-encoded Readline version number. */ -#define RL_READLINE_VERSION 0x0403 /* Readline 4.3 */ -#define RL_VERSION_MAJOR 4 -#define RL_VERSION_MINOR 3 +#define RL_READLINE_VERSION 0x0501 /* Readline 5.1 */ +#define RL_VERSION_MAJOR 5 +#define RL_VERSION_MINOR 1 /* Readline data structures. */ @@ -160,6 +160,7 @@ extern int rl_kill_line PARAMS((int, int)); extern int rl_backward_kill_line PARAMS((int, int)); extern int rl_kill_full_line PARAMS((int, int)); extern int rl_unix_word_rubout PARAMS((int, int)); +extern int rl_unix_filename_rubout PARAMS((int, int)); extern int rl_unix_line_discard PARAMS((int, int)); extern int rl_copy_region_to_kill PARAMS((int, int)); extern int rl_kill_region PARAMS((int, int)); @@ -240,6 +241,7 @@ extern int rl_vi_column PARAMS((int, int)); extern int rl_vi_delete_to PARAMS((int, int)); extern int rl_vi_change_to PARAMS((int, int)); extern int rl_vi_yank_to PARAMS((int, int)); +extern int rl_vi_rubout PARAMS((int, int)); extern int rl_vi_delete PARAMS((int, int)); extern int rl_vi_back_to_indent PARAMS((int, int)); extern int rl_vi_first_print PARAMS((int, int)); @@ -258,6 +260,8 @@ extern int rl_vi_check PARAMS((void)); extern int rl_vi_domove PARAMS((int, int *)); extern int rl_vi_bracktype PARAMS((int)); +extern void rl_vi_start_inserting PARAMS((int, int, int)); + /* VI-mode pseudo-bindable commands, used as utility functions. */ extern int rl_vi_fWord PARAMS((int, int)); extern int rl_vi_bWord PARAMS((int, int)); @@ -290,12 +294,22 @@ extern int rl_bind_key PARAMS((int, rl_command_func_t *)); extern int rl_bind_key_in_map PARAMS((int, rl_command_func_t *, Keymap)); extern int rl_unbind_key PARAMS((int)); extern int rl_unbind_key_in_map PARAMS((int, Keymap)); +extern int rl_bind_key_if_unbound PARAMS((int, rl_command_func_t *)); +extern int rl_bind_key_if_unbound_in_map PARAMS((int, rl_command_func_t *, Keymap)); extern int rl_unbind_function_in_map PARAMS((rl_command_func_t *, Keymap)); extern int rl_unbind_command_in_map PARAMS((const char *, Keymap)); -extern int rl_set_key PARAMS((const char *, rl_command_func_t *, Keymap)); +extern int rl_bind_keyseq PARAMS((const char *, rl_command_func_t *)); +extern int rl_bind_keyseq_in_map PARAMS((const char *, rl_command_func_t *, Keymap)); +extern int rl_bind_keyseq_if_unbound PARAMS((const char *, rl_command_func_t *)); +extern int rl_bind_keyseq_if_unbound_in_map PARAMS((const char *, rl_command_func_t *, Keymap)); extern int rl_generic_bind PARAMS((int, const char *, char *, Keymap)); + +extern char *rl_variable_value PARAMS((const char *)); extern int rl_variable_bind PARAMS((const char *, const char *)); +/* Backwards compatibility, use rl_bind_keyseq_in_map instead. */ +extern int rl_set_key PARAMS((const char *, rl_command_func_t *, Keymap)); + /* Backwards compatibility, use rl_generic_bind instead. */ extern int rl_macro_bind PARAMS((const char *, const char *, Keymap)); @@ -358,7 +372,7 @@ extern int rl_clear_message PARAMS((void)); extern int rl_reset_line_state PARAMS((void)); extern int rl_crlf PARAMS((void)); -#if (defined (__STDC__) || defined (__cplusplus)) && defined (USE_VARARGS) && defined (PREFER_STDARG) +#if defined (USE_VARARGS) && defined (PREFER_STDARG) extern int rl_message (const char *, ...) __attribute__((__format__ (printf, 1, 2))); #else extern int rl_message (); @@ -384,11 +398,13 @@ extern char *rl_copy_text PARAMS((int, int)); extern void rl_prep_terminal PARAMS((int)); extern void rl_deprep_terminal PARAMS((void)); extern void rl_tty_set_default_bindings PARAMS((Keymap)); +extern void rl_tty_unset_default_bindings PARAMS((Keymap)); extern int rl_reset_terminal PARAMS((const char *)); extern void rl_resize_terminal PARAMS((void)); extern void rl_set_screen_size PARAMS((int, int)); extern void rl_get_screen_size PARAMS((int *, int *)); +extern void rl_reset_screen_size PARAMS((void)); extern char *rl_get_termcap PARAMS((const char *)); @@ -516,6 +532,11 @@ extern const char *rl_terminal_name; extern FILE *rl_instream; extern FILE *rl_outstream; +/* If non-zero, Readline gives values of LINES and COLUMNS from the environment + greater precedence than values fetched from the kernel when computing the + screen dimensions. */ +extern int rl_prefer_env_winsize; + /* If non-zero, then this is the address of a function to call just before readline_internal () prints the first prompt. */ extern rl_hook_func_t *rl_startup_hook; @@ -603,7 +624,12 @@ extern const char *rl_basic_word_break_characters; /* The list of characters that signal a break between words for rl_complete_internal. The default list is the contents of rl_basic_word_break_characters. */ -extern const char *rl_completer_word_break_characters; +extern /*const*/ char *rl_completer_word_break_characters; + +/* Hook function to allow an application to set the completion word + break characters before readline breaks up the line. Allows + position-dependent word break characters. */ +extern rl_cpvfunc_t *rl_completion_word_break_hook; /* List of characters which can be used to quote a substring of the line. Completion occurs on the entire substring, and within the substring @@ -687,6 +713,11 @@ extern int rl_attempted_completion_over; functions. */ extern int rl_completion_type; +/* Up to this many items will be displayed in response to a + possible-completions call. After that, we ask the user if she + is sure she wants to see them all. The default value is 100. */ +extern int rl_completion_query_items; + /* Character appended to completed words when at the end of the line. The default is a space. Nothing is added if this is '\0'. */ extern int rl_completion_append_character; @@ -695,10 +726,18 @@ extern int rl_completion_append_character; rl_completion_append_character will not be appended. */ extern int rl_completion_suppress_append; -/* Up to this many items will be displayed in response to a - possible-completions call. After that, we ask the user if she - is sure she wants to see them all. The default value is 100. */ -extern int rl_completion_query_items; +/* Set to any quote character readline thinks it finds before any application + completion function is called. */ +extern int rl_completion_quote_character; + +/* Set to a non-zero value if readline found quoting anywhere in the word to + be completed; set before any application completion function is called. */ +extern int rl_completion_found_quote; + +/* If non-zero, the completion functions don't append any closing quote. + This is set to 0 by rl_complete_internal and may be changed by an + application-specific completion function. */ +extern int rl_completion_suppress_quote; /* If non-zero, a slash will be appended to completed filenames that are symbolic links to directory names, subject to the value of the @@ -729,28 +768,33 @@ extern int rl_inhibit_completion; #define MULT_MATCH 2 /* Possible state values for rl_readline_state */ -#define RL_STATE_NONE 0x00000 /* no state; before first call */ - -#define RL_STATE_INITIALIZING 0x00001 /* initializing */ -#define RL_STATE_INITIALIZED 0x00002 /* initialization done */ -#define RL_STATE_TERMPREPPED 0x00004 /* terminal is prepped */ -#define RL_STATE_READCMD 0x00008 /* reading a command key */ -#define RL_STATE_METANEXT 0x00010 /* reading input after ESC */ -#define RL_STATE_DISPATCHING 0x00020 /* dispatching to a command */ -#define RL_STATE_MOREINPUT 0x00040 /* reading more input in a command function */ -#define RL_STATE_ISEARCH 0x00080 /* doing incremental search */ -#define RL_STATE_NSEARCH 0x00100 /* doing non-inc search */ -#define RL_STATE_SEARCH 0x00200 /* doing a history search */ -#define RL_STATE_NUMERICARG 0x00400 /* reading numeric argument */ -#define RL_STATE_MACROINPUT 0x00800 /* getting input from a macro */ -#define RL_STATE_MACRODEF 0x01000 /* defining keyboard macro */ -#define RL_STATE_OVERWRITE 0x02000 /* overwrite mode */ -#define RL_STATE_COMPLETING 0x04000 /* doing completion */ -#define RL_STATE_SIGHANDLER 0x08000 /* in readline sighandler */ -#define RL_STATE_UNDOING 0x10000 /* doing an undo */ -#define RL_STATE_INPUTPENDING 0x20000 /* rl_execute_next called */ - -#define RL_STATE_DONE 0x80000 /* done; accepted line */ +#define RL_STATE_NONE 0x000000 /* no state; before first call */ + +#define RL_STATE_INITIALIZING 0x000001 /* initializing */ +#define RL_STATE_INITIALIZED 0x000002 /* initialization done */ +#define RL_STATE_TERMPREPPED 0x000004 /* terminal is prepped */ +#define RL_STATE_READCMD 0x000008 /* reading a command key */ +#define RL_STATE_METANEXT 0x000010 /* reading input after ESC */ +#define RL_STATE_DISPATCHING 0x000020 /* dispatching to a command */ +#define RL_STATE_MOREINPUT 0x000040 /* reading more input in a command function */ +#define RL_STATE_ISEARCH 0x000080 /* doing incremental search */ +#define RL_STATE_NSEARCH 0x000100 /* doing non-inc search */ +#define RL_STATE_SEARCH 0x000200 /* doing a history search */ +#define RL_STATE_NUMERICARG 0x000400 /* reading numeric argument */ +#define RL_STATE_MACROINPUT 0x000800 /* getting input from a macro */ +#define RL_STATE_MACRODEF 0x001000 /* defining keyboard macro */ +#define RL_STATE_OVERWRITE 0x002000 /* overwrite mode */ +#define RL_STATE_COMPLETING 0x004000 /* doing completion */ +#define RL_STATE_SIGHANDLER 0x008000 /* in readline sighandler */ +#define RL_STATE_UNDOING 0x010000 /* doing an undo */ +#define RL_STATE_INPUTPENDING 0x020000 /* rl_execute_next called */ +#define RL_STATE_TTYCSAVED 0x040000 /* tty special chars saved */ +#define RL_STATE_CALLBACK 0x080000 /* using the callback interface */ +#define RL_STATE_VIMOTION 0x100000 /* reading vi motion arg */ +#define RL_STATE_MULTIKEY 0x200000 /* reading multiple-key command */ +#define RL_STATE_VICMDONCE 0x400000 /* entered vi command mode at least once */ + +#define RL_STATE_DONE 0x800000 /* done; accepted line */ #define RL_SETSTATE(x) (rl_readline_state |= (x)) #define RL_UNSETSTATE(x) (rl_readline_state &= ~(x)) @@ -785,6 +829,12 @@ struct readline_state { int catchsigs; int catchsigwinch; + /* search state */ + + /* completion state */ + + /* options state */ + /* reserved for future expansion, so the struct size doesn't change */ char reserved[64]; }; diff --git a/readline/rldefs.h b/readline/rldefs.h index b80db8cffed..0f6c87446dd 100644 --- a/readline/rldefs.h +++ b/readline/rldefs.h @@ -2,7 +2,7 @@ for readline. This should be included after any files that define system-specific constants like _POSIX_VERSION or USG. */ -/* Copyright (C) 1987,1989 Free Software Foundation, Inc. +/* Copyright (C) 1987-2005 Free Software Foundation, Inc. This file contains the Readline Library (the Library), a set of routines for providing Emacs style line input to programs that ask @@ -32,15 +32,17 @@ #include "rlstdc.h" -#if defined (__MINGW32__) -# define NO_TTY_DRIVER -#elif defined (_POSIX_VERSION) && !defined (TERMIOS_MISSING) +#if defined (_POSIX_VERSION) && !defined (TERMIOS_MISSING) # define TERMIOS_TTY_DRIVER #else # if defined (HAVE_TERMIO_H) # define TERMIO_TTY_DRIVER # else -# define NEW_TTY_DRIVER +# if !defined (__MINGW32__) +# define NEW_TTY_DRIVER +# else +# define NO_TTY_DRIVER +# endif # endif #endif @@ -79,7 +81,7 @@ extern int _rl_stricmp PARAMS((char *, char *)); extern int _rl_strnicmp PARAMS((char *, char *, int)); #endif -#if defined (HAVE_STRPBRK) +#if defined (HAVE_STRPBRK) && !defined (HAVE_MULTIBYTE) # define _rl_strpbrk(a,b) strpbrk((a),(b)) #else extern char *_rl_strpbrk PARAMS((const char *, const char *)); diff --git a/readline/rlmbutil.h b/readline/rlmbutil.h index dab954fad90..cf6ef9e4dbe 100644 --- a/readline/rlmbutil.h +++ b/readline/rlmbutil.h @@ -45,12 +45,28 @@ #if defined (HAVE_WCTYPE_H) && defined (HAVE_WCHAR_H) # include <wchar.h> # include <wctype.h> -# if defined (HAVE_MBSTATE_T) && defined (HAVE_MBSRTOWCS) +# if defined (HAVE_MBSTATE_T) && defined (HAVE_MBSRTOWCS) && defined (HAVE_MBRTOWC) && defined (HAVE_MBRLEN) && defined (HAVE_WCWIDTH) /* system is supposed to support XPG5 */ # define HANDLE_MULTIBYTE 1 # endif #endif +/* If we don't want multibyte chars even on a system that supports them, let + the configuring user turn multibyte support off. */ +#if defined (NO_MULTIBYTE_SUPPORT) +# undef HANDLE_MULTIBYTE +#endif + +/* Some systems, like BeOS, have multibyte encodings but lack mbstate_t. */ +#if HANDLE_MULTIBYTE && !defined (HAVE_MBSTATE_T) +# define wcsrtombs(dest, src, len, ps) (wcsrtombs) (dest, src, len, 0) +# define mbsrtowcs(dest, src, len, ps) (mbsrtowcs) (dest, src, len, 0) +# define wcrtomb(s, wc, ps) (wcrtomb) (s, wc, 0) +# define mbrtowc(pwc, s, n, ps) (mbrtowc) (pwc, s, n, 0) +# define mbrlen(s, n, ps) (mbrlen) (s, n, 0) +# define mbstate_t int +#endif + /* Make sure MB_LEN_MAX is at least 16 on systems that claim to be able to handle multibyte chars (some systems define MB_LEN_MAX as 1) */ #ifdef HANDLE_MULTIBYTE @@ -91,6 +107,24 @@ extern int _rl_read_mbstring PARAMS((int, char *, int)); extern int _rl_is_mbchar_matched PARAMS((char *, int, int, char *, int)); +extern wchar_t _rl_char_value PARAMS((char *, int)); +extern int _rl_walphabetic PARAMS((wchar_t)); + +#define _rl_to_wupper(wc) (iswlower (wc) ? towupper (wc) : (wc)) +#define _rl_to_wlower(wc) (iswupper (wc) ? towlower (wc) : (wc)) + +#define MB_NEXTCHAR(b,s,c,f) \ + ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) \ + ? _rl_find_next_mbchar ((b), (s), (c), (f)) \ + : ((s) + (c))) +#define MB_PREVCHAR(b,s,f) \ + ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) \ + ? _rl_find_prev_mbchar ((b), (s), (f)) \ + : ((s) - 1)) + +#define MB_INVALIDCH(x) ((x) == (size_t)-1 || (x) == (size_t)-2) +#define MB_NULLWCH(x) ((x) == 0) + #else /* !HANDLE_MULTIBYTE */ #undef MB_LEN_MAX @@ -102,6 +136,19 @@ extern int _rl_is_mbchar_matched PARAMS((char *, int, int, char *, int)); #define _rl_find_prev_mbchar(b, i, f) (((i) == 0) ? (i) : ((i) - 1)) #define _rl_find_next_mbchar(b, i1, i2, f) ((i1) + (i2)) +#define _rl_char_value(buf,ind) ((buf)[(ind)]) + +#define _rl_walphabetic(c) (rl_alphabetic (c)) + +#define _rl_to_wupper(c) (_rl_to_upper (c)) +#define _rl_to_wlower(c) (_rl_to_lower (c)) + +#define MB_NEXTCHAR(b,s,c,f) ((s) + (c)) +#define MB_PREVCHAR(b,s,f) ((s) - 1) + +#define MB_INVALIDCH(x) (0) +#define MB_NULLWCH(x) (0) + #endif /* !HANDLE_MULTIBYTE */ extern int rl_byte_oriented; diff --git a/readline/rlprivate.h b/readline/rlprivate.h index ccb914469e7..1c216ead14f 100644 --- a/readline/rlprivate.h +++ b/readline/rlprivate.h @@ -1,7 +1,7 @@ /* rlprivate.h -- functions and variables global to the readline library, but not intended for use by applications. */ -/* Copyright (C) 1999 Free Software Foundation, Inc. +/* Copyright (C) 1999-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -30,6 +30,95 @@ /************************************************************************* * * + * Global structs undocumented in texinfo manual and not in readline.h * + * * + *************************************************************************/ +/* search types */ +#define RL_SEARCH_ISEARCH 0x01 /* incremental search */ +#define RL_SEARCH_NSEARCH 0x02 /* non-incremental search */ +#define RL_SEARCH_CSEARCH 0x04 /* intra-line char search */ + +/* search flags */ +#define SF_REVERSE 0x01 +#define SF_FOUND 0x02 +#define SF_FAILED 0x04 + +typedef struct __rl_search_context +{ + int type; + int sflags; + + char *search_string; + int search_string_index; + int search_string_size; + + char **lines; + char *allocated_line; + int hlen; + int hindex; + + int save_point; + int save_mark; + int save_line; + int last_found_line; + char *prev_line_found; + + UNDO_LIST *save_undo_list; + + int history_pos; + int direction; + + int lastc; +#if defined (HANDLE_MULTIBYTE) + char mb[MB_LEN_MAX]; +#endif + + char *sline; + int sline_len; + int sline_index; + + char *search_terminators; +} _rl_search_cxt; + +/* Callback data for reading numeric arguments */ +#define NUM_SAWMINUS 0x01 +#define NUM_SAWDIGITS 0x02 +#define NUM_READONE 0x04 + +typedef int _rl_arg_cxt; + +/* A context for reading key sequences longer than a single character when + using the callback interface. */ +#define KSEQ_DISPATCHED 0x01 +#define KSEQ_SUBSEQ 0x02 +#define KSEQ_RECURSIVE 0x04 + +typedef struct __rl_keyseq_context +{ + int flags; + int subseq_arg; + int subseq_retval; /* XXX */ + Keymap dmap; + + Keymap oldmap; + int okey; + struct __rl_keyseq_context *ocxt; + int childval; +} _rl_keyseq_cxt; + + /* fill in more as needed */ +/* `Generic' callback data and functions */ +typedef struct __rl_callback_generic_arg +{ + int count; + int i1, i2; + /* add here as needed */ +} _rl_callback_generic_arg; + +typedef int _rl_callback_func_t PARAMS((_rl_callback_generic_arg *)); + +/************************************************************************* + * * * Global functions undocumented in texinfo manual and not in readline.h * * * *************************************************************************/ @@ -54,6 +143,8 @@ extern int readline_echoing_p; extern int rl_key_sequence_length; extern int rl_byte_oriented; +extern _rl_keyseq_cxt *_rl_kscxt; + /* display.c */ extern int rl_display_fixed; @@ -100,10 +191,19 @@ extern void readline_internal_setup PARAMS((void)); extern char *readline_internal_teardown PARAMS((int)); extern int readline_internal_char PARAMS((void)); +extern _rl_keyseq_cxt *_rl_keyseq_cxt_alloc PARAMS((void)); +extern void _rl_keyseq_cxt_dispose PARAMS((_rl_keyseq_cxt *)); +extern void _rl_keyseq_chain_dispose PARAMS((void)); + +extern int _rl_dispatch_callback PARAMS((_rl_keyseq_cxt *)); + +/* callback.c */ +extern _rl_callback_generic_arg *_rl_callback_data_alloc PARAMS((int)); +extern void _rl_callback_data_dispose PARAMS((_rl_callback_generic_arg *)); + #endif /* READLINE_CALLBACKS */ /* bind.c */ -extern void _rl_bind_if_unbound PARAMS((const char *, rl_command_func_t *)); /* complete.c */ extern char _rl_find_completion_word PARAMS((int *, int *)); @@ -131,6 +231,16 @@ extern int _rl_input_available PARAMS((void)); extern int _rl_input_queued PARAMS((int)); extern void _rl_insert_typein PARAMS((int)); extern int _rl_unget_char PARAMS((int)); +extern int _rl_pushed_input_available PARAMS((void)); + +/* isearch.c */ +extern _rl_search_cxt *_rl_scxt_alloc PARAMS((int, int)); +extern void _rl_scxt_dispose PARAMS((_rl_search_cxt *, int)); + +extern int _rl_isearch_dispatch PARAMS((_rl_search_cxt *, int)); +extern int _rl_isearch_callback PARAMS((_rl_search_cxt *)); + +extern int _rl_search_getchar PARAMS((_rl_search_cxt *)); /* macro.c */ extern void _rl_with_macro_input PARAMS((char *)); @@ -141,7 +251,12 @@ extern void _rl_add_macro_char PARAMS((int)); extern void _rl_kill_kbd_macro PARAMS((void)); /* misc.c */ -extern int _rl_init_argument PARAMS((void)); +extern int _rl_arg_overflow PARAMS((void)); +extern void _rl_arg_init PARAMS((void)); +extern int _rl_arg_getchar PARAMS((void)); +extern int _rl_arg_callback PARAMS((_rl_arg_cxt)); +extern void _rl_reset_argument PARAMS((void)); + extern void _rl_start_using_history PARAMS((void)); extern int _rl_free_saved_history_line PARAMS((void)); extern void _rl_set_insert_mode PARAMS((int, int)); @@ -157,11 +272,15 @@ extern void _rl_init_line_state PARAMS((void)); extern void _rl_set_the_line PARAMS((void)); extern int _rl_dispatch PARAMS((int, Keymap)); extern int _rl_dispatch_subseq PARAMS((int, Keymap, int)); +extern void _rl_internal_char_cleanup PARAMS((void)); /* rltty.c */ extern int _rl_disable_tty_signals PARAMS((void)); extern int _rl_restore_tty_signals PARAMS((void)); +/* search.c */ +extern int _rl_nsearch_callback PARAMS((_rl_search_cxt *)); + /* terminal.c */ extern void _rl_get_screen_size PARAMS((int, int)); extern int _rl_init_terminal_io PARAMS((const char *)); @@ -217,8 +336,13 @@ extern void _rl_vi_done_inserting PARAMS((void)); extern const char *_rl_possible_control_prefixes[]; extern const char *_rl_possible_meta_prefixes[]; +/* callback.c */ +extern _rl_callback_func_t *_rl_callback_func; +extern _rl_callback_generic_arg *_rl_callback_data; + /* complete.c */ extern int _rl_complete_show_all; +extern int _rl_complete_show_unmodified; extern int _rl_complete_mark_directories; extern int _rl_complete_mark_symlink_dirs; extern int _rl_print_completions_horizontally; @@ -230,11 +354,14 @@ extern int _rl_page_completions; extern int _rl_vis_botlin; extern int _rl_last_c_pos; extern int _rl_suppress_redisplay; +extern int _rl_want_redisplay; extern char *rl_display_prompt; /* isearch.c */ extern char *_rl_isearch_terminators; +extern _rl_search_cxt *_rl_iscxt; + /* macro.c */ extern char *_rl_executing_macro; @@ -242,6 +369,8 @@ extern char *_rl_executing_macro; extern int _rl_history_preserve_point; extern int _rl_history_saved_point; +extern _rl_arg_cxt _rl_argcxt; + /* readline.c */ extern int _rl_horizontal_scroll_mode; extern int _rl_mark_modified_lines; @@ -249,6 +378,7 @@ extern int _rl_bell_preference; extern int _rl_meta_flag; extern int _rl_convert_meta_chars_to_ascii; extern int _rl_output_meta_chars; +extern int _rl_bind_stty_chars; extern char *_rl_comment_begin; extern unsigned char _rl_parsing_conditionalized_out; extern Keymap _rl_keymap; @@ -258,6 +388,9 @@ extern int _rl_last_command_was_kill; extern int _rl_eof_char; extern procenv_t readline_top_level; +/* search.c */ +extern _rl_search_cxt *_rl_nscxt; + /* terminal.c */ extern int _rl_enable_keypad; extern int _rl_enable_meta; @@ -281,4 +414,7 @@ extern int _rl_term_autowrap; extern int _rl_doing_an_undo; extern int _rl_undo_group_level; +/* vi_mode.c */ +extern int _rl_vi_last_command; + #endif /* _RL_PRIVATE_H_ */ diff --git a/readline/rlstdc.h b/readline/rlstdc.h index d6a22b3742c..847fa9c26f4 100644 --- a/readline/rlstdc.h +++ b/readline/rlstdc.h @@ -37,7 +37,7 @@ #endif #ifndef __attribute__ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) # define __attribute__(x) # endif #endif diff --git a/readline/rltty.c b/readline/rltty.c index 2ccb9d1a566..9a0326ed209 100644 --- a/readline/rltty.c +++ b/readline/rltty.c @@ -1,7 +1,7 @@ /* rltty.c -- functions to prepare and restore the terminal for readline's use. */ -/* Copyright (C) 1992 Free Software Foundation, Inc. +/* Copyright (C) 1992-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -188,6 +188,8 @@ static int set_tty_settings PARAMS((int, TIOTYPE *)); static void prepare_terminal_settings PARAMS((int, TIOTYPE, TIOTYPE *)); +static void set_special_char PARAMS((Keymap, TIOTYPE *, int, rl_command_func_t)); + static void save_tty_chars (tiop) TIOTYPE *tiop; @@ -229,12 +231,11 @@ get_tty_settings (tty, tiop) int tty; TIOTYPE *tiop; { -#if defined (TIOCGWINSZ) set_winsize (tty); -#endif tiop->flags = tiop->lflag = 0; + errno = 0; if (ioctl (tty, TIOCGETP, &(tiop->sgttyb)) < 0) return -1; tiop->flags |= SGTTY_SET; @@ -404,6 +405,9 @@ static int set_tty_settings PARAMS((int, TIOTYPE *)); static void prepare_terminal_settings PARAMS((int, TIOTYPE, TIOTYPE *)); +static void set_special_char PARAMS((Keymap, TIOTYPE *, int, rl_command_func_t)); +static void _rl_bind_tty_special_chars PARAMS((Keymap, TIOTYPE)); + #if defined (FLUSHO) # define OUTPUT_BEING_FLUSHED(tp) (tp->c_lflag & FLUSHO) #else @@ -515,10 +519,9 @@ get_tty_settings (tty, tiop) int tty; TIOTYPE *tiop; { -#if defined (TIOCGWINSZ) set_winsize (tty); -#endif + errno = 0; if (_get_tty_settings (tty, tiop) < 0) return -1; @@ -632,10 +635,9 @@ prepare_terminal_settings (meta_flag, oldtio, tiop) #endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */ } -#endif /* NEW_TTY_DRIVER */ +#endif /* !NEW_TTY_DRIVER */ -/* Put the terminal in CBREAK mode so that we can detect key - presses. */ +/* Put the terminal in CBREAK mode so that we can detect key presses. */ #if defined (NO_TTY_DRIVER) void rl_prep_terminal (meta_flag) @@ -650,7 +652,6 @@ rl_deprep_terminal () } #else /* ! NO_TTY_DRIVER */ -/* Put the terminal in CBREAK mode so that we can detect key presses. */ void rl_prep_terminal (meta_flag) int meta_flag; @@ -668,13 +669,43 @@ rl_prep_terminal (meta_flag) if (get_tty_settings (tty, &tio) < 0) { +#if defined (ENOTSUP) + /* MacOS X, at least, lies about the value of errno if tcgetattr fails. */ + if (errno == ENOTTY || errno == ENOTSUP) +#else + if (errno == ENOTTY) +#endif + readline_echoing_p = 1; /* XXX */ release_sigint (); return; } otio = tio; + if (_rl_bind_stty_chars) + { +#if defined (VI_MODE) + /* If editing in vi mode, make sure we restore the bindings in the + insertion keymap no matter what keymap we ended up in. */ + if (rl_editing_mode == vi_mode) + rl_tty_unset_default_bindings (vi_insertion_keymap); + else +#endif + rl_tty_unset_default_bindings (_rl_keymap); + } save_tty_chars (&otio); + RL_SETSTATE(RL_STATE_TTYCSAVED); + if (_rl_bind_stty_chars) + { +#if defined (VI_MODE) + /* If editing in vi mode, make sure we set the bindings in the + insertion keymap no matter what keymap we ended up in. */ + if (rl_editing_mode == vi_mode) + _rl_bind_tty_special_chars (vi_insertion_keymap, tio); + else +#endif + _rl_bind_tty_special_chars (_rl_keymap, tio); + } prepare_terminal_settings (meta_flag, otio, &tio); @@ -809,71 +840,105 @@ rl_stop_output (count, key) /* */ /* **************************************************************** */ -/* Set the system's default editing characters to their readline equivalents - in KMAP. Should be static, now that we have rl_tty_set_default_bindings. */ -void -rltty_set_default_bindings (kmap) - Keymap kmap; -{ #if !defined (NO_TTY_DRIVER) - TIOTYPE ttybuff; - int tty = fileno (rl_instream); +#define SET_SPECIAL(sc, func) set_special_char(kmap, &ttybuff, sc, func) +#endif -#if defined (NEW_TTY_DRIVER) +#if defined (NO_TTY_DRIVER) -#define SET_SPECIAL(sc, func) \ - do \ - { \ - int ic; \ - ic = sc; \ - if (ic != -1 && kmap[(unsigned char)ic].type == ISFUNC) \ - kmap[(unsigned char)ic].function = func; \ - } \ - while (0) +#define SET_SPECIAL(sc, func) +#define RESET_SPECIAL(c) - if (get_tty_settings (tty, &ttybuff) == 0) +#elif defined (NEW_TTY_DRIVER) +static void +set_special_char (kmap, tiop, sc, func) + Keymap kmap; + TIOTYPE *tiop; + int sc; + rl_command_func_t *func; +{ + if (sc != -1 && kmap[(unsigned char)sc].type == ISFUNC) + kmap[(unsigned char)sc].function = func; +} + +#define RESET_SPECIAL(c) \ + if (c != -1 && kmap[(unsigned char)c].type == ISFUNC) + kmap[(unsigned char)c].function = rl_insert; + +static void +_rl_bind_tty_special_chars (kmap, ttybuff) + Keymap kmap; + TIOTYPE ttybuff; +{ + if (ttybuff.flags & SGTTY_SET) { - if (ttybuff.flags & SGTTY_SET) - { - SET_SPECIAL (ttybuff.sgttyb.sg_erase, rl_rubout); - SET_SPECIAL (ttybuff.sgttyb.sg_kill, rl_unix_line_discard); - } + SET_SPECIAL (ttybuff.sgttyb.sg_erase, rl_rubout); + SET_SPECIAL (ttybuff.sgttyb.sg_kill, rl_unix_line_discard); + } # if defined (TIOCGLTC) - if (ttybuff.flags & LTCHARS_SET) - { - SET_SPECIAL (ttybuff.ltchars.t_werasc, rl_unix_word_rubout); - SET_SPECIAL (ttybuff.ltchars.t_lnextc, rl_quoted_insert); - } -# endif /* TIOCGLTC */ + if (ttybuff.flags & LTCHARS_SET) + { + SET_SPECIAL (ttybuff.ltchars.t_werasc, rl_unix_word_rubout); + SET_SPECIAL (ttybuff.ltchars.t_lnextc, rl_quoted_insert); } +# endif /* TIOCGLTC */ +} #else /* !NEW_TTY_DRIVER */ +static void +set_special_char (kmap, tiop, sc, func) + Keymap kmap; + TIOTYPE *tiop; + int sc; + rl_command_func_t *func; +{ + unsigned char uc; -#define SET_SPECIAL(sc, func) \ - do \ - { \ - unsigned char uc; \ - uc = ttybuff.c_cc[sc]; \ - if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) \ - kmap[uc].function = func; \ - } \ - while (0) + uc = tiop->c_cc[sc]; + if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) + kmap[uc].function = func; +} - if (get_tty_settings (tty, &ttybuff) == 0) - { - SET_SPECIAL (VERASE, rl_rubout); - SET_SPECIAL (VKILL, rl_unix_line_discard); +/* used later */ +#define RESET_SPECIAL(uc) \ + if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) \ + kmap[uc].function = rl_insert; + +static void +_rl_bind_tty_special_chars (kmap, ttybuff) + Keymap kmap; + TIOTYPE ttybuff; +{ + SET_SPECIAL (VERASE, rl_rubout); + SET_SPECIAL (VKILL, rl_unix_line_discard); # if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER) - SET_SPECIAL (VLNEXT, rl_quoted_insert); + SET_SPECIAL (VLNEXT, rl_quoted_insert); # endif /* VLNEXT && TERMIOS_TTY_DRIVER */ # if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER) - SET_SPECIAL (VWERASE, rl_unix_word_rubout); + SET_SPECIAL (VWERASE, rl_unix_word_rubout); # endif /* VWERASE && TERMIOS_TTY_DRIVER */ - } +} + #endif /* !NEW_TTY_DRIVER */ + +/* Set the system's default editing characters to their readline equivalents + in KMAP. Should be static, now that we have rl_tty_set_default_bindings. */ +void +rltty_set_default_bindings (kmap) + Keymap kmap; +{ +#if !defined (NO_TTY_DRIVER) + TIOTYPE ttybuff; + int tty; + static int called = 0; + + tty = fileno (rl_instream); + + if (get_tty_settings (tty, &ttybuff) == 0) + _rl_bind_tty_special_chars (kmap, ttybuff); #endif } @@ -886,6 +951,30 @@ rl_tty_set_default_bindings (kmap) rltty_set_default_bindings (kmap); } +/* Rebind all of the tty special chars that readline worries about back + to self-insert. Call this before saving the current terminal special + chars with save_tty_chars(). This only works on POSIX termios or termio + systems. */ +void +rl_tty_unset_default_bindings (kmap) + Keymap kmap; +{ + /* Don't bother before we've saved the tty special chars at least once. */ + if (RL_ISSTATE(RL_STATE_TTYCSAVED) == 0) + return; + + RESET_SPECIAL (_rl_tty_chars.t_erase); + RESET_SPECIAL (_rl_tty_chars.t_kill); + +# if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER) + RESET_SPECIAL (_rl_tty_chars.t_lnext); +# endif /* VLNEXT && TERMIOS_TTY_DRIVER */ + +# if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER) + RESET_SPECIAL (_rl_tty_chars.t_werase); +# endif /* VWERASE && TERMIOS_TTY_DRIVER */ +} + #if defined (HANDLE_SIGNALS) #if defined (NEW_TTY_DRIVER) || defined (NO_TTY_DRIVER) diff --git a/readline/rltty.h b/readline/rltty.h index 029a3fbc0e1..142e96b6a64 100644 --- a/readline/rltty.h +++ b/readline/rltty.h @@ -61,22 +61,22 @@ #endif /* !NEW_TTY_DRIVER && !_POSIX_VDISABLE */ typedef struct _rl_tty_chars { - char t_eof; - char t_eol; - char t_eol2; - char t_erase; - char t_werase; - char t_kill; - char t_reprint; - char t_intr; - char t_quit; - char t_susp; - char t_dsusp; - char t_start; - char t_stop; - char t_lnext; - char t_flush; - char t_status; + unsigned char t_eof; + unsigned char t_eol; + unsigned char t_eol2; + unsigned char t_erase; + unsigned char t_werase; + unsigned char t_kill; + unsigned char t_reprint; + unsigned char t_intr; + unsigned char t_quit; + unsigned char t_susp; + unsigned char t_dsusp; + unsigned char t_start; + unsigned char t_stop; + unsigned char t_lnext; + unsigned char t_flush; + unsigned char t_status; } _RL_TTY_CHARS; #endif /* _RLTTY_H_ */ diff --git a/readline/rltypedefs.h b/readline/rltypedefs.h index f3280e9fce0..862bdb8e4d9 100644 --- a/readline/rltypedefs.h +++ b/readline/rltypedefs.h @@ -1,6 +1,6 @@ /* rltypedefs.h -- Type declarations for readline functions. */ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2000-2004 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. @@ -79,6 +79,12 @@ typedef void rl_voidfunc_t PARAMS((void)); typedef void rl_vintfunc_t PARAMS((int)); typedef void rl_vcpfunc_t PARAMS((char *)); typedef void rl_vcppfunc_t PARAMS((char **)); + +typedef char *rl_cpvfunc_t PARAMS((void)); +typedef char *rl_cpifunc_t PARAMS((int)); +typedef char *rl_cpcpfunc_t PARAMS((char *)); +typedef char *rl_cpcppfunc_t PARAMS((char **)); + #endif /* _RL_FUNCTION_TYPEDEF */ #ifdef __cplusplus diff --git a/readline/savestring.c b/readline/savestring.c index c7ebeb1e552..820428d8881 100644 --- a/readline/savestring.c +++ b/readline/savestring.c @@ -1,6 +1,6 @@ /* savestring.c */ -/* Copyright (C) 1998 Free Software Foundation, Inc. +/* Copyright (C) 1998,2003 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. @@ -19,6 +19,7 @@ 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 #include <config.h> #ifdef HAVE_STRING_H diff --git a/readline/search.c b/readline/search.c index 7e0d60b5eb4..8013916c20e 100644 --- a/readline/search.c +++ b/readline/search.c @@ -1,6 +1,6 @@ /* search.c - code for non-incremental searching in emacs and vi modes. */ -/* Copyright (C) 1992 Free Software Foundation, Inc. +/* Copyright (C) 1992-2005 Free Software Foundation, Inc. This file is part of the Readline Library (the Library), a set of routines for providing Emacs style line input to programs that ask @@ -53,6 +53,8 @@ #endif #define abs(x) (((x) >= 0) ? (x) : -(x)) +_rl_search_cxt *_rl_nscxt = 0; + extern HIST_ENTRY *_rl_saved_line_for_history; /* Functions imported from the rest of the library. */ @@ -68,13 +70,19 @@ static int rl_history_search_pos; static char *history_search_string; static int history_string_size; +static UNDO_LIST *noninc_saved_undo_list; static void make_history_line_current PARAMS((HIST_ENTRY *)); static int noninc_search_from_pos PARAMS((char *, int, int)); -static void noninc_dosearch PARAMS((char *, int)); -static void noninc_search PARAMS((int, int)); +static int noninc_dosearch PARAMS((char *, int)); +static int noninc_search PARAMS((int, int)); static int rl_history_search_internal PARAMS((int, int)); static void rl_history_search_reinit PARAMS((void)); +static _rl_search_cxt *_rl_nsearch_init PARAMS((int, int)); +static int _rl_nsearch_cleanup PARAMS((_rl_search_cxt *, int)); +static void _rl_nsearch_abort PARAMS((_rl_search_cxt *)); +static int _rl_nsearch_dispatch PARAMS((_rl_search_cxt *, int)); + /* Make the data from the history entry ENTRY be the contents of the current line. This doesn't do anything with rl_point; the caller must set it. */ @@ -82,8 +90,16 @@ static void make_history_line_current (entry) HIST_ENTRY *entry; { - rl_replace_line (entry->line, 0); - rl_undo_list = (UNDO_LIST *)entry->data; + _rl_replace_text (entry->line, 0, rl_end); + _rl_fix_point (1); +#if defined (VI_MODE) + if (rl_editing_mode == vi_mode) + /* POSIX.2 says that the `U' command doesn't affect the copy of any + command lines to the edit line. We're going to implement that by + making the undo list start after the matching line is copied to the + current editing buffer. */ + rl_free_undo_list (); +#endif if (_rl_saved_line_for_history) _rl_free_history_entry (_rl_saved_line_for_history); @@ -125,8 +141,8 @@ noninc_search_from_pos (string, pos, dir) /* Search for a line in the history containing STRING. If DIR is < 0, the search is backwards through previous entries, else through subsequent - entries. */ -static void + entries. Returns 1 if the search was successful, 0 otherwise. */ +static int noninc_dosearch (string, dir) char *string; int dir; @@ -137,7 +153,7 @@ noninc_dosearch (string, dir) if (string == 0 || *string == '\0' || noninc_history_pos < 0) { rl_ding (); - return; + return 0; } pos = noninc_search_from_pos (string, noninc_history_pos + dir, dir); @@ -148,7 +164,7 @@ noninc_dosearch (string, dir) rl_clear_message (); rl_point = 0; rl_ding (); - return; + return 0; } noninc_history_pos = pos; @@ -159,7 +175,7 @@ noninc_dosearch (string, dir) #if defined (VI_MODE) if (rl_editing_mode != vi_mode) #endif - history_set_pos (oldpos); + history_set_pos (oldpos); make_history_line_current (entry); @@ -167,27 +183,29 @@ noninc_dosearch (string, dir) rl_mark = rl_end; rl_clear_message (); + return 1; } -/* Search non-interactively through the history list. DIR < 0 means to - search backwards through the history of previous commands; otherwise - the search is for commands subsequent to the current position in the - history list. PCHAR is the character to use for prompting when reading - the search string; if not specified (0), it defaults to `:'. */ -static void -noninc_search (dir, pchar) - int dir; - int pchar; +static _rl_search_cxt * +_rl_nsearch_init (dir, pchar) + int dir, pchar; { - int saved_point, saved_mark, c; + _rl_search_cxt *cxt; char *p; -#if defined (HANDLE_MULTIBYTE) - char mb[MB_LEN_MAX]; -#endif + + cxt = _rl_scxt_alloc (RL_SEARCH_NSEARCH, 0); + if (dir < 0) + cxt->sflags |= SF_REVERSE; /* not strictly needed */ + + cxt->direction = dir; + cxt->history_pos = cxt->save_line; rl_maybe_save_line (); - saved_point = rl_point; - saved_mark = rl_mark; + + /* Clear the undo list, since reading the search string should create its + own undo list, and the whole list will end up being freed when we + finish reading the search string. */ + rl_undo_list = 0; /* Use the line buffer to read the search string. */ rl_line_buffer[0] = 0; @@ -197,99 +215,169 @@ noninc_search (dir, pchar) rl_message (p, 0, 0); free (p); -#define SEARCH_RETURN rl_restore_prompt (); RL_UNSETSTATE(RL_STATE_NSEARCH); return - RL_SETSTATE(RL_STATE_NSEARCH); - /* Read the search string. */ - while (1) + + _rl_nscxt = cxt; + + return cxt; +} + +static int +_rl_nsearch_cleanup (cxt, r) + _rl_search_cxt *cxt; + int r; +{ + _rl_scxt_dispose (cxt, 0); + _rl_nscxt = 0; + + RL_UNSETSTATE(RL_STATE_NSEARCH); + + return (r != 1); +} + +static void +_rl_nsearch_abort (cxt) + _rl_search_cxt *cxt; +{ + rl_maybe_unsave_line (); + rl_clear_message (); + rl_point = cxt->save_point; + rl_mark = cxt->save_mark; + rl_restore_prompt (); + + RL_UNSETSTATE (RL_STATE_NSEARCH); +} + +/* Process just-read character C according to search context CXT. Return -1 + if the caller should abort the search, 0 if we should break out of the + loop, and 1 if we should continue to read characters. */ +static int +_rl_nsearch_dispatch (cxt, c) + _rl_search_cxt *cxt; + int c; +{ + switch (c) { - RL_SETSTATE(RL_STATE_MOREINPUT); - c = rl_read_key (); - RL_UNSETSTATE(RL_STATE_MOREINPUT); + case CTRL('W'): + rl_unix_word_rubout (1, c); + break; -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - c = _rl_read_mbstring (c, mb, MB_LEN_MAX); -#endif + case CTRL('U'): + rl_unix_line_discard (1, c); + break; - if (c == 0) - break; + case RETURN: + case NEWLINE: + return 0; - switch (c) + case CTRL('H'): + case RUBOUT: + if (rl_point == 0) { - case CTRL('H'): - case RUBOUT: - if (rl_point == 0) - { - rl_maybe_unsave_line (); - rl_clear_message (); - rl_point = saved_point; - rl_mark = saved_mark; - SEARCH_RETURN; - } - _rl_rubout_char (1, c); - break; - - case CTRL('W'): - rl_unix_word_rubout (1, c); - break; - - case CTRL('U'): - rl_unix_line_discard (1, c); - break; - - case RETURN: - case NEWLINE: - goto dosearch; - /* NOTREACHED */ - break; - - case CTRL('C'): - case CTRL('G'): - rl_maybe_unsave_line (); - rl_clear_message (); - rl_point = saved_point; - rl_mark = saved_mark; - rl_ding (); - SEARCH_RETURN; + _rl_nsearch_abort (cxt); + return -1; + } + _rl_rubout_char (1, c); + break; + + case CTRL('C'): + case CTRL('G'): + rl_ding (); + _rl_nsearch_abort (cxt); + return -1; - default: + default: #if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - rl_insert_text (mb); - else + if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + rl_insert_text (cxt->mb); + else #endif - _rl_insert_char (1, c); - break; - } - (*rl_redisplay_function) (); + _rl_insert_char (1, c); + break; } - dosearch: - rl_mark = saved_mark; + (*rl_redisplay_function) (); + return 1; +} + +/* Perform one search according to CXT, using NONINC_SEARCH_STRING. Return + -1 if the search should be aborted, any other value means to clean up + using _rl_nsearch_cleanup (). Returns 1 if the search was successful, + 0 otherwise. */ +static int +_rl_nsearch_dosearch (cxt) + _rl_search_cxt *cxt; +{ + rl_mark = cxt->save_mark; /* If rl_point == 0, we want to re-use the previous search string and start from the saved history position. If there's no previous search string, punt. */ if (rl_point == 0) { - if (!noninc_search_string) + if (noninc_search_string == 0) { rl_ding (); - SEARCH_RETURN; + rl_restore_prompt (); + RL_UNSETSTATE (RL_STATE_NSEARCH); + return -1; } } else { /* We want to start the search from the current history position. */ - noninc_history_pos = where_history (); + noninc_history_pos = cxt->save_line; FREE (noninc_search_string); noninc_search_string = savestring (rl_line_buffer); + + /* If we don't want the subsequent undo list generated by the search + matching a history line to include the contents of the search string, + we need to clear rl_line_buffer here. For now, we just clear the + undo list generated by reading the search string. (If the search + fails, the old undo list will be restored by rl_maybe_unsave_line.) */ + rl_free_undo_list (); } rl_restore_prompt (); - noninc_dosearch (noninc_search_string, dir); - RL_UNSETSTATE(RL_STATE_NSEARCH); + return (noninc_dosearch (noninc_search_string, cxt->direction)); +} + +/* Search non-interactively through the history list. DIR < 0 means to + search backwards through the history of previous commands; otherwise + the search is for commands subsequent to the current position in the + history list. PCHAR is the character to use for prompting when reading + the search string; if not specified (0), it defaults to `:'. */ +static int +noninc_search (dir, pchar) + int dir; + int pchar; +{ + _rl_search_cxt *cxt; + int c, r; + + cxt = _rl_nsearch_init (dir, pchar); + + if (RL_ISSTATE (RL_STATE_CALLBACK)) + return (0); + + /* Read the search string. */ + r = 0; + while (1) + { + c = _rl_search_getchar (cxt); + + if (c == 0) + break; + + r = _rl_nsearch_dispatch (cxt, c); + if (r < 0) + return 1; + else if (r == 0) + break; + } + + r = _rl_nsearch_dosearch (cxt); + return ((r >= 0) ? _rl_nsearch_cleanup (cxt, r) : (r != 1)); } /* Search forward through the history list for a string. If the vi-mode @@ -298,8 +386,7 @@ int rl_noninc_forward_search (count, key) int count, key; { - noninc_search (1, (key == '?') ? '?' : 0); - return 0; + return noninc_search (1, (key == '?') ? '?' : 0); } /* Reverse search the history list for a string. If the vi-mode code @@ -308,8 +395,7 @@ int rl_noninc_reverse_search (count, key) int count, key; { - noninc_search (-1, (key == '/') ? '/' : 0); - return 0; + return noninc_search (-1, (key == '/') ? '/' : 0); } /* Search forward through the history list for the last string searched @@ -318,13 +404,15 @@ int rl_noninc_forward_search_again (count, key) int count, key; { + int r; + if (!noninc_search_string) { rl_ding (); return (-1); } - noninc_dosearch (noninc_search_string, 1); - return 0; + r = noninc_dosearch (noninc_search_string, 1); + return (r != 1); } /* Reverse search in the history list for the last string searched @@ -333,15 +421,34 @@ int rl_noninc_reverse_search_again (count, key) int count, key; { + int r; + if (!noninc_search_string) { rl_ding (); return (-1); } - noninc_dosearch (noninc_search_string, -1); - return 0; + r = noninc_dosearch (noninc_search_string, -1); + return (r != 1); } +#if defined (READLINE_CALLBACKS) +int +_rl_nsearch_callback (cxt) + _rl_search_cxt *cxt; +{ + int c, r; + + c = _rl_search_getchar (cxt); + r = _rl_nsearch_dispatch (cxt, c); + if (r != 0) + return 1; + + r = _rl_nsearch_dosearch (cxt); + return ((r >= 0) ? _rl_nsearch_cleanup (cxt, r) : (r != 1)); +} +#endif + static int rl_history_search_internal (count, dir) int count, dir; diff --git a/readline/shell.c b/readline/shell.c index 35b1c1d6ea9..346f8113d43 100644 --- a/readline/shell.c +++ b/readline/shell.c @@ -27,7 +27,6 @@ #endif #include <sys/types.h> -#include <stdio.h> #if defined (HAVE_UNISTD_H) # include <unistd.h> @@ -49,8 +48,10 @@ # include <limits.h> #endif +#if defined (HAVE_FCNTL_H) #include <fcntl.h> -#ifdef HAVE_PWD_H +#endif +#if defined (HAVE_PWD_H) #include <pwd.h> #endif @@ -60,9 +61,9 @@ #include "rlshell.h" #include "xmalloc.h" -#if !defined (HAVE_GETPW_DECLS) +#if defined (HAVE_GETPWUID) && !defined (HAVE_GETPW_DECLS) extern struct passwd *getpwuid PARAMS((uid_t)); -#endif /* !HAVE_GETPW_DECLS */ +#endif /* HAVE_GETPWUID && !HAVE_GETPW_DECLS */ #ifndef NULL # define NULL 0 @@ -125,23 +126,27 @@ sh_set_lines_and_columns (lines, cols) { char *b; -#if defined (HAVE_PUTENV) - b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("LINES=") + 1); - sprintf (b, "LINES=%d", lines); - putenv (b); - b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("COLUMNS=") + 1); - sprintf (b, "COLUMNS=%d", cols); - putenv (b); -#else /* !HAVE_PUTENV */ -# if defined (HAVE_SETENV) +#if defined (HAVE_SETENV) b = (char *)xmalloc (INT_STRLEN_BOUND (int) + 1); sprintf (b, "%d", lines); setenv ("LINES", b, 1); + free (b); + b = (char *)xmalloc (INT_STRLEN_BOUND (int) + 1); sprintf (b, "%d", cols); setenv ("COLUMNS", b, 1); -# endif /* HAVE_SETENV */ -#endif /* !HAVE_PUTENV */ + free (b); +#else /* !HAVE_SETENV */ +# if defined (HAVE_PUTENV) + b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("LINES=") + 1); + sprintf (b, "LINES=%d", lines); + putenv (b); + + b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("COLUMNS=") + 1); + sprintf (b, "COLUMNS=%d", cols); + putenv (b); +# endif /* HAVE_PUTENV */ +#endif /* !HAVE_SETENV */ } char * @@ -158,7 +163,7 @@ sh_get_home_dir () struct passwd *entry; home_dir = (char *)NULL; -#ifdef HAVE_GETPWUID +#if defined (HAVE_GETPWUID) entry = getpwuid (getuid ()); if (entry) home_dir = entry->pw_dir; @@ -176,7 +181,7 @@ int sh_unset_nodelay_mode (fd) int fd; { -#ifdef HAVE_FNCTL +#if defined (HAVE_FCNTL) int flags, bflags; if ((flags = fcntl (fd, F_GETFL, 0)) < 0) diff --git a/readline/shlib/Makefile.in b/readline/shlib/Makefile.in index 22748c47c03..40039c38bcd 100644 --- a/readline/shlib/Makefile.in +++ b/readline/shlib/Makefile.in @@ -1,7 +1,7 @@ ## -*- text -*- ## # Makefile for the GNU readline library shared library support. # -# Copyright (C) 1998 Free Software Foundation, Inc. +# Copyright (C) 1998-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 @@ -17,6 +17,14 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. +PACKAGE = @PACKAGE_NAME@ +VERSION = @PACKAGE_VERSION@ + +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_VERSION = @PACKAGE_VERSION@ + RL_LIBRARY_VERSION = @LIBVERSION@ RL_LIBRARY_NAME = readline @@ -45,7 +53,10 @@ host_os = @host_os@ prefix = @prefix@ exec_prefix = @exec_prefix@ includedir = @includedir@ +bindir = @bindir@ libdir = @libdir@ +datadir = @datadir@ +localedir = $(datadir)/locale # Support an alternate destination root directory for package building DESTDIR = @@ -55,7 +66,7 @@ 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@ # @@ -72,14 +83,20 @@ SHOBJ_LDFLAGS = @SHOBJ_LDFLAGS@ SHOBJ_XLDFLAGS = @SHOBJ_XLDFLAGS@ SHOBJ_LIBS = @SHOBJ_LIBS@ -SHLIB_XLDFLAGS = @SHLIB_XLDFLAGS@ +SHLIB_XLDFLAGS = @LDFLAGS@ @SHLIB_XLDFLAGS@ SHLIB_LIBS = @SHLIB_LIBS@ + +SHLIB_DOT = @SHLIB_DOT@ +SHLIB_LIBPREF = @SHLIB_LIBPREF@ SHLIB_LIBSUFF = @SHLIB_LIBSUFF@ SHLIB_LIBVERSION = @SHLIB_LIBVERSION@ +SHLIB_DLLVERSION = @SHLIB_DLLVERSION@ SHLIB_STATUS = @SHLIB_STATUS@ +TERMCAP_LIB = @TERMCAP_LIB@ + # shared library versioning SHLIB_MAJOR= @SHLIB_MAJOR@ # shared library systems like SVR4's do not use minor versions @@ -99,8 +116,8 @@ CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(CPPFLAGS) $(INCLUDES) $(LOCAL_CFLAGS) $(CFLAGS # The name of the main library target. -SHARED_READLINE = libreadline.$(SHLIB_LIBVERSION) -SHARED_HISTORY = libhistory.$(SHLIB_LIBVERSION) +SHARED_READLINE = $(SHLIB_LIBPREF)readline$(SHLIB_DOT)$(SHLIB_LIBVERSION) +SHARED_HISTORY = $(SHLIB_LIBPREF)history$(SHLIB_DOT)$(SHLIB_LIBVERSION) SHARED_LIBS = $(SHARED_READLINE) $(SHARED_HISTORY) WCWIDTH_OBJ = @WCWIDTH_OBJ@ @@ -117,7 +134,7 @@ CSOURCES = $(topdir)/readline.c $(topdir)/funmap.c $(topdir)/keymaps.c \ $(topdir)/histfile.c $(topdir)/nls.c $(topdir)/search.c \ $(topdir)/shell.c $(topdir)/savestring.c $(topdir)/tilde.c \ $(topdir)/text.c $(topdir)/misc.c $(topdir)/compat.c \ - $(topdir)/mbutil.c $(WCWIDTH_SRC) + $(topdir)/mbutil.c $(topdir)/support/wcwidth.c # The header files for this library. HSOURCES = readline.h rldefs.h chardefs.h keymaps.h history.h histlib.h \ @@ -170,13 +187,13 @@ installdirs: $(topdir)/support/mkdirs -$(SHELL) $(topdir)/support/mkdirs $(DESTDIR)$(libdir) install: installdirs $(SHLIB_STATUS) - $(SHELL) $(topdir)/support/shlib-install -O $(host_os) -d $(DESTDIR)$(libdir) -i "$(INSTALL_DATA)" $(SHARED_HISTORY) - $(SHELL) $(topdir)/support/shlib-install -O $(host_os) -d $(DESTDIR)$(libdir) -i "$(INSTALL_DATA)" $(SHARED_READLINE) + $(SHELL) $(topdir)/support/shlib-install -O $(host_os) -d $(DESTDIR)$(libdir) -b $(DESTDIR)$(bindir) -i "$(INSTALL_DATA)" $(SHARED_HISTORY) + $(SHELL) $(topdir)/support/shlib-install -O $(host_os) -d $(DESTDIR)$(libdir) -b $(DESTDIR)$(bindir) -i "$(INSTALL_DATA)" $(SHARED_READLINE) @echo install: you may need to run ldconfig uninstall: - $(SHELL) $(topdir)/support/shlib-install -O $(host_os) -d $(DESTDIR)$(libdir) -U $(SHARED_HISTORY) - $(SHELL) $(topdir)/support/shlib-install -O $(host_os) -d $(DESTDIR)$(libdir) -U $(SHARED_READLINE) + $(SHELL) $(topdir)/support/shlib-install -O $(host_os) -d $(DESTDIR)$(libdir) -b $(DESTDIR)$(bindir) -U $(SHARED_HISTORY) + $(SHELL) $(topdir)/support/shlib-install -O $(host_os) -d $(DESTDIR)$(libdir) -b $(DESTDIR)$(bindir) -U $(SHARED_READLINE) @echo uninstall: you may need to run ldconfig clean mostlyclean: force @@ -396,7 +413,7 @@ search.so: $(topdir)/search.c shell.so: $(topdir)/shell.c signals.so: $(topdir)/signals.c terminal.so: $(topdir)/terminal.c -text.so: $(topdir)/terminal.c +text.so: $(topdir)/text.c tilde.so: $(topdir)/tilde.c undo.so: $(topdir)/undo.c util.so: $(topdir)/util.c @@ -430,7 +447,7 @@ search.so: search.c signals.so: signals.c shell.so: shell.c terminal.so: terminal.c -text.so: terminal.c +text.so: text.c tilde.so: tilde.c undo.so: undo.c util.so: util.c diff --git a/readline/signals.c b/readline/signals.c index fa3e26af544..f344ed83497 100644 --- a/readline/signals.c +++ b/readline/signals.c @@ -1,6 +1,6 @@ /* signals.c -- signal handling support for readline. */ -/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1987-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -73,6 +73,10 @@ typedef struct { SigHandler *sa_handler; int sa_mask, sa_flags; } sighandler_cxt # define sigemptyset(m) #endif /* !HAVE_POSIX_SIGNALS */ +#ifndef SA_RESTART +# define SA_RESTART 0 +#endif + static SigHandler *rl_set_sighandler PARAMS((int, SigHandler *, sighandler_cxt *)); static void rl_maybe_set_sighandler PARAMS((int, SigHandler *, sighandler_cxt *)); @@ -85,12 +89,12 @@ int rl_catch_signals = 1; /* If non-zero, readline will install a signal handler for SIGWINCH. */ #ifdef SIGWINCH int rl_catch_sigwinch = 1; +#else +int rl_catch_sigwinch = 0; /* for the readline state struct in readline.c */ #endif static int signals_set_flag; -#ifdef SIGWINCH static int sigwinch_set_flag; -#endif /* **************************************************************** */ /* */ @@ -127,11 +131,11 @@ rl_signal_handler (sig) #if !defined (HAVE_BSD_SIGNALS) && !defined (HAVE_POSIX_SIGNALS) /* Since the signal will not be blocked while we are in the signal handler, ignore it until rl_clear_signals resets the catcher. */ - if (sig == SIGINT -#ifdef SIGALRM - || sig == SIGALRM -#endif - ) +# if defined (SIGALRM) + if (sig == SIGINT || sig == SIGALRM) +# else + if (sig == SIGINT) +# endif rl_set_sighandler (sig, SIG_IGN, &dummy_cxt); #endif /* !HAVE_BSD_SIGNALS && !HAVE_POSIX_SIGNALS */ @@ -141,16 +145,16 @@ rl_signal_handler (sig) rl_free_line_state (); /* FALLTHROUGH */ + case SIGTERM: #if defined (SIGTSTP) case SIGTSTP: case SIGTTOU: case SIGTTIN: #endif /* SIGTSTP */ -#ifdef SIGALRM +#if defined (SIGALRM) case SIGALRM: #endif - case SIGTERM: -#ifdef SIGQUIT +#if defined (SIGQUIT) case SIGQUIT: #endif rl_cleanup_after_signal (); @@ -168,13 +172,10 @@ rl_signal_handler (sig) signal (sig, SIG_ACK); #endif - /* If we have the POSIX kill function, use it; otherwise, fall - back to the ISO C raise function. (Windows is an example of - a platform that has raise, but not kill.) */ -#ifdef HAVE_KILL +#if defined (HAVE_KILL) kill (getpid (), sig); #else - raise (sig); + raise (sig); /* assume we have raise */ #endif /* Let the signal that we just sent through. */ @@ -250,7 +251,7 @@ rl_set_sighandler (sig, handler, ohandler) struct sigaction act; act.sa_handler = handler; - act.sa_flags = 0; /* XXX - should we set SA_RESTART for SIGWINCH? */ + act.sa_flags = (sig == SIGWINCH) ? SA_RESTART : 0; sigemptyset (&act.sa_mask); sigemptyset (&ohandler->sa_mask); sigaction (sig, &act, &old_handler); @@ -292,11 +293,11 @@ rl_set_signals () { rl_maybe_set_sighandler (SIGINT, rl_signal_handler, &old_int); rl_maybe_set_sighandler (SIGTERM, rl_signal_handler, &old_term); -#ifdef SIGQUIT +#if defined (SIGQUIT) rl_maybe_set_sighandler (SIGQUIT, rl_signal_handler, &old_quit); #endif -#ifdef SIGALRM +#if defined (SIGALRM) oh = rl_set_sighandler (SIGALRM, rl_signal_handler, &old_alrm); if (oh == (SigHandler *)SIG_IGN) rl_sigaction (SIGALRM, &old_alrm, &dummy); @@ -347,10 +348,10 @@ rl_clear_signals () rl_sigaction (SIGINT, &old_int, &dummy); rl_sigaction (SIGTERM, &old_term, &dummy); -#ifdef SIGQUIT +#if defined (SIGQUIT) rl_sigaction (SIGQUIT, &old_quit, &dummy); #endif -#ifdef SIGALRM +#if defined (SIGALRM) rl_sigaction (SIGALRM, &old_alrm, &dummy); #endif @@ -387,7 +388,8 @@ void rl_cleanup_after_signal () { _rl_clean_up_for_exit (); - (*rl_deprep_term_function) (); + if (rl_deprep_term_function) + (*rl_deprep_term_function) (); rl_clear_signals (); rl_clear_pending_input (); } @@ -396,7 +398,8 @@ rl_cleanup_after_signal () void rl_reset_after_signal () { - (*rl_prep_term_function) (_rl_meta_flag); + if (rl_prep_term_function) + (*rl_prep_term_function) (_rl_meta_flag); rl_set_signals (); } @@ -417,7 +420,7 @@ rl_free_line_state () _rl_kill_kbd_macro (); rl_clear_message (); - _rl_init_argument (); + _rl_reset_argument (); } #endif /* HANDLE_SIGNALS */ diff --git a/readline/support/shlib-install b/readline/support/shlib-install index 654cfa9dd53..2cd252a3658 100755 --- a/readline/support/shlib-install +++ b/readline/support/shlib-install @@ -3,7 +3,7 @@ # shlib-install - install a shared library and do any necessary host-specific # post-installation configuration (like ldconfig) # -# usage: shlib-install [-D] -O host_os -d installation-dir -i install-prog [-U] library +# usage: shlib-install [-D] -O host_os -d installation-dir [-b bin-dir] -i install-prog [-U] library # # Chet Ramey # chet@po.cwru.edu @@ -15,7 +15,7 @@ INSTALLDIR=/usr/local/lib LDCONFIG=ldconfig PROGNAME=`basename $0` -USAGE="$PROGNAME [-D] -O host_os -d installation-dir -i install-prog [-U] library" +USAGE="$PROGNAME [-D] -O host_os -d installation-dir [-b bin-dir] -i install-prog [-U] library" # process options @@ -23,6 +23,7 @@ while [ $# -gt 0 ]; do case "$1" in -O) shift; host_os="$1"; shift ;; -d) shift; INSTALLDIR="$1"; shift ;; + -b) shift; BINDIR="$1" ; shift ;; -i) shift; INSTALLPROG="$1" ; shift ;; -D) echo=echo ; shift ;; -U) uninstall=true ; shift ;; @@ -64,11 +65,30 @@ fi # post-install/uninstall # HP-UX and Darwin/MacOS X require that a shared library have execute permission +# Cygwin installs both a dll (which must go in $BINDIR) and an implicit +# link library (in $libdir) case "$host_os" in hpux*|darwin*|macosx*) if [ -z "$uninstall" ]; then chmod 555 ${INSTALLDIR}/${LIBNAME} fi ;; +cygwin*) + IMPLIBNAME=`echo ${LIBNAME} \ + | sed -e 's,^cyg,lib,' -e 's,[0-9]*.dll$,.dll.a,'` + if [ -z "$uninstall" ]; then + ${echo} $RM ${BINDIR}/${LIBNAME}.${OLDSUFF} + if [ -f "$BINDIR/$LIBNAME" ]; then + ${echo} $MV $BINDIR/$LIBNAME $BINDIR/$LIBNAME.$OLDSUFF + fi + ${echo} $MV ${INSTALLDIR}/${LIBNAME} ${BINDIR}/${LIBNAME} + ${echo} chmod a+x ${BINDIR}/${LIBNAME} + ${echo} eval ${INSTALLPROG} ${LIBNAME}.a \ + ${INSTALLDIR}/${IMPLIBNAME} + else + ${echo} ${RM} ${BINDIR}/${LIBNAME} + ${echo} ${RM} ${INSTALLDIR}/${IMPLIBNAME} + fi ;; + *) ;; esac @@ -88,24 +108,38 @@ case "$LIBNAME" in LINK1=`echo $LIBNAME | sed 's:\(.*\)\.[0-9]\.[0-9]:\1:'` # libname.dylib esac -INSTALL_LINK1='cd $INSTALLDIR ; ln -s $LIBNAME $LINK1' -INSTALL_LINK2='cd $INSTALLDIR ; ln -s $LIBNAME $LINK2' +INSTALL_LINK1='${echo} cd $INSTALLDIR && ${echo} ${LN} $LIBNAME $LINK1' +INSTALL_LINK2='${echo} cd $INSTALLDIR && ${echo} ${LN} $LIBNAME $LINK2' # # Create symlinks to the installed library. This section is incomplete. # case "$host_os" in -*linux*|bsdi4*|*gnu*|darwin*|macosx*) +*linux*) + # libname.so.M -> libname.so.M.N + ${echo} ${RM} ${INSTALLDIR}/$LINK2 + if [ -z "$uninstall" ]; then + eval $INSTALL_LINK2 + fi + + # libname.so -> libname.so.M + ${echo} ${RM} ${INSTALLDIR}/$LINK1 + if [ -z "$uninstall" ]; then + ${echo} cd $INSTALLDIR && ${echo} ${LN} $LINK2 $LINK1 + fi + ;; + +bsdi4*|*gnu*|darwin*|macosx*|k*bsd*-gnu) # libname.so.M -> libname.so.M.N ${echo} ${RM} ${INSTALLDIR}/$LINK2 if [ -z "$uninstall" ]; then - ${echo} ln -s $LIBNAME ${INSTALLDIR}/$LINK2 + eval $INSTALL_LINK2 fi # libname.so -> libname.so.M.N ${echo} ${RM} ${INSTALLDIR}/$LINK1 if [ -z "$uninstall" ]; then - ${echo} ln -s $LIBNAME ${INSTALLDIR}/$LINK1 + eval $INSTALL_LINK1 fi ;; @@ -113,7 +147,7 @@ solaris2*|aix4.[2-9]*|osf*|irix[56]*|sysv[45]*|dgux*) # libname.so -> libname.so.M ${echo} ${RM} ${INSTALLDIR}/$LINK1 if [ -z "$uninstall" ]; then - ${echo} ln -s $LIBNAME ${INSTALLDIR}/$LINK1 + eval $INSTALL_LINK1 fi ;; @@ -124,19 +158,19 @@ freebsd[3-9]*|freebsdelf[3-9]*|freebsdaout[3-9]*) # libname.so -> libname.so.M ${echo} ${RM} ${INSTALLDIR}/$LINK1 if [ -z "$uninstall" ]; then - ${echo} ln -s $LIBNAME ${INSTALLDIR}/$LINK1 + eval $INSTALL_LINK1 fi else # libname.so.M -> libname.so.M.N ${echo} ${RM} ${INSTALLDIR}/$LINK2 if [ -z "$uninstall" ]; then - ${echo} ln -s $LIBNAME ${INSTALLDIR}/$LINK2 + eval $INSTALL_LINK2 fi # libname.so -> libname.so.M.N ${echo} ${RM} ${INSTALLDIR}/$LINK1 if [ -z "$uninstall" ]; then - ${echo} ln -s $LIBNAME ${INSTALLDIR}/$LINK1 + eval $INSTALL_LINK1 fi fi ;; @@ -145,11 +179,16 @@ hpux1*) # libname.sl -> libname.M ${echo} ${RM} ${INSTALLDIR}/$LINK1.sl if [ -z "$uninstall" ]; then -# ${echo} ln -s $LIBNAME ${INSTALLDIR}/${LINK1}.sl - ${echo} ln -s $LIBNAME ${INSTALLDIR}/${LINK1} + eval $INSTALL_LINK1 fi ;; +cygwin*) + # Links to .dlls don't work. Hence shobj-conf used DLLVERSION.dll + # instead of so.SHLIB_MAJOR.SHLIB_MINOR. The postinstall above + # took care of everything else. + ;; + *) ;; esac diff --git a/readline/support/shobj-conf b/readline/support/shobj-conf index 6bd7fb120ca..0e306bc1a72 100755 --- a/readline/support/shobj-conf +++ b/readline/support/shobj-conf @@ -41,9 +41,13 @@ SHOBJ_LIBS= SHLIB_XLDFLAGS= SHLIB_LIBS= + +SHLIB_DOT='.' +SHLIB_LIBPREF='lib' SHLIB_LIBSUFF='so' SHLIB_LIBVERSION='$(SHLIB_LIBSUFF)' +SHLIB_DLLVERSION='$(SHLIB_MAJOR)' PROGNAME=`basename $0` USAGE="$PROGNAME [-C compiler] -c host_cpu -o host_os -v host_vendor" @@ -78,10 +82,14 @@ sunos4*) sunos5*-*gcc*|solaris2*-*gcc*) SHOBJ_CFLAGS=-fpic SHOBJ_LD='${CC}' - # This line works for the Solaris linker in /usr/ccs/bin/ld - SHOBJ_LDFLAGS='-shared -Wl,-i -Wl,-h,$@' - # This line works for the GNU ld -# SHOBJ_LDFLAGS='-shared -Wl,-h,$@' + ld_used=`gcc -print-prog-name=ld` + if ${ld_used} -V 2>&1 | grep GNU >/dev/null 2>&1; then + # This line works for the GNU ld + SHOBJ_LDFLAGS='-shared -Wl,-h,$@' + else + # This line works for the Solaris linker in /usr/ccs/bin/ld + SHOBJ_LDFLAGS='-shared -Wl,-i -Wl,-h,$@' + fi # SHLIB_XLDFLAGS='-R $(libdir)' SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' @@ -97,7 +105,7 @@ sunos5*|solaris2*) ;; # All versions of Linux or the semi-mythical GNU Hurd. -linux*|gnu*) +linux*-*|gnu*-*|k*bsd*-gnu-*) SHOBJ_CFLAGS=-fPIC SHOBJ_LD='${CC}' SHOBJ_LDFLAGS='-shared -Wl,-soname,$@' @@ -116,7 +124,7 @@ freebsd2* | netbsd*) ;; # FreeBSD-3.x ELF -freebsd[3-9]*|freebsdelf[3-9]*|freebsdaout[3-9]*) +freebsd[3-9]*|freebsdelf[3-9]*|freebsdaout[3-9]*|dragonfly*) SHOBJ_CFLAGS=-fpic SHOBJ_LD='${CC}' @@ -138,17 +146,23 @@ darwin*|macosx*) SHOBJ_STATUS=unsupported SHLIB_STATUS=supported - SHOBJ_CFLAGS='-dynamic -fno-common' + SHOBJ_CFLAGS='-fno-common' - SHOBJ_LD=/usr/bin/libtool + SHOBJ_LD='${CC}' SHLIB_LIBVERSION='$(SHLIB_MAJOR)$(SHLIB_MINOR).$(SHLIB_LIBSUFF)' SHLIB_LIBSUFF='dylib' - SHOBJ_LDFLAGS='-dynamic' - SHLIB_XLDFLAGS='-arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v' + case "${host_os}" in + darwin[78]*) SHOBJ_LDFLAGS='' + SHLIB_XLDFLAGS='-dynamiclib -arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v' + ;; + *) SHOBJ_LDFLAGS='-dynamic' + SHLIB_XLDFLAGS='-arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v' + ;; + esac - SHLIB_LIBS='-lSystem' + SHLIB_LIBS='-lncurses' # see if -lcurses works on MacOS X 10.1 ;; openbsd*) @@ -296,6 +310,8 @@ hpux10*-*gcc*) # must use gcc; the bundled cc cannot compile PIC code SHOBJ_CFLAGS='-fpic' SHOBJ_LD='${CC}' + # if you have problems linking here, moving the `-Wl,+h,$@' from + # SHLIB_XLDFLAGS to SHOBJ_LDFLAGS has been reported to work SHOBJ_LDFLAGS='-shared -Wl,-b -Wl,+s' SHLIB_XLDFLAGS='-Wl,+h,$@ -Wl,+b,$(libdir)' @@ -400,7 +416,39 @@ sysv5uw7*) SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' ;; - + +sysv5UnixWare*-*gcc*) + SHOBJ_CFLAGS=-fpic + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-shared' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +sysv5UnixWare*) + SHOBJ_CFLAGS='-K PIC' + SHOBJ_LD=ld + SHOBJ_LDFLAGS='-G -dy -z text -h $@' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +sysv5OpenUNIX*-*gcc*) + SHOBJ_CFLAGS=-fpic + SHOBJ_LD='${CC}' + SHOBJ_LDFLAGS='-shared' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + +sysv5OpenUNIX*) + SHOBJ_CFLAGS='-K PIC' + SHOBJ_LD=ld + SHOBJ_LDFLAGS='-G -dy -z text -h $@' + + SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' + ;; + dgux*-*gcc*) SHOBJ_CFLAGS=-fpic SHOBJ_LD='${CC}' @@ -422,6 +470,24 @@ msdos*) SHLIB_STATUS=unsupported ;; +cygwin*) + SHOBJ_LD='$(CC)' + SHOBJ_LDFLAGS='-shared -Wl,--enable-auto-import -Wl,--enable-auto-image-base -Wl,--export-all -Wl,--out-implib=$(@).a' + SHLIB_LIBPREF='cyg' + SHLIB_LIBSUFF='dll' + SHLIB_LIBVERSION='$(SHLIB_DLLVERSION).$(SHLIB_LIBSUFF)' + SHLIB_LIBS='$(TERMCAP_LIB)' + + SHLIB_DOT= + # For official cygwin releases, DLLVERSION will be defined in the + # environment of configure, and will be incremented any time the API + # changes in a non-backwards compatible manner. Otherwise, it is just + # SHLIB_MAJOR. + if [ -n "$DLLVERSION" ] ; then + SHLIB_DLLVERSION="$DLLVERSION" + fi + ;; + # # Rely on correct gcc configuration for everything else # @@ -449,8 +515,14 @@ echo SHOBJ_LIBS=\'"$SHOBJ_LIBS"\' echo SHLIB_XLDFLAGS=\'"$SHLIB_XLDFLAGS"\' echo SHLIB_LIBS=\'"$SHLIB_LIBS"\' + +echo SHLIB_DOT=\'"$SHLIB_DOT"\' + +echo SHLIB_LIBPREF=\'"$SHLIB_LIBPREF"\' echo SHLIB_LIBSUFF=\'"$SHLIB_LIBSUFF"\' + echo SHLIB_LIBVERSION=\'"$SHLIB_LIBVERSION"\' +echo SHLIB_DLLVERSION=\'"$SHLIB_DLLVERSION"\' echo SHOBJ_STATUS=\'"$SHOBJ_STATUS"\' echo SHLIB_STATUS=\'"$SHLIB_STATUS"\' diff --git a/readline/terminal.c b/readline/terminal.c index ce45d28d024..21732a791bb 100644 --- a/readline/terminal.c +++ b/readline/terminal.c @@ -1,6 +1,6 @@ /* terminal.c -- controlling the terminal with termcap. */ -/* Copyright (C) 1996 Free Software Foundation, Inc. +/* Copyright (C) 1996-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -78,6 +78,8 @@ #define CUSTOM_REDISPLAY_FUNC() (rl_redisplay_function != rl_redisplay) #define CUSTOM_INPUT_FUNC() (rl_getc_function != rl_getc) +int rl_prefer_env_winsize; + /* **************************************************************** */ /* */ /* Terminal and Termcap */ @@ -87,9 +89,6 @@ #ifndef __MSDOS__ static char *term_buffer = (char *)NULL; static char *term_string_buffer = (char *)NULL; - -/* Non-zero means this terminal can't really do anything. */ -static int dumb_term; #endif /* !__MSDOS__ */ static int tcap_initialized; @@ -134,7 +133,7 @@ char *_rl_term_up; static char *_rl_visible_bell; /* Non-zero means the terminal can auto-wrap lines. */ -int _rl_term_autowrap; +int _rl_term_autowrap = -1; /* Non-zero means that this terminal has a meta key. */ static int term_has_meta; @@ -159,6 +158,9 @@ static char *_rl_term_kh; static char *_rl_term_kH; static char *_rl_term_at7; /* @7 */ +/* Delete key */ +static char *_rl_term_kD; + /* Insert key */ static char *_rl_term_kI; @@ -205,12 +207,14 @@ _rl_get_screen_size (tty, ignore_env) #if defined (TIOCGWINSZ) struct winsize window_size; #endif /* TIOCGWINSZ */ + int wr, wc; + wr = wc = -1; #if defined (TIOCGWINSZ) if (ioctl (tty, TIOCGWINSZ, &window_size) == 0) { - _rl_screenwidth = (int) window_size.ws_col; - _rl_screenheight = (int) window_size.ws_row; + wc = (int) window_size.ws_col; + wr = (int) window_size.ws_row; } #endif /* TIOCGWINSZ */ @@ -232,13 +236,25 @@ _rl_get_screen_size (tty, ignore_env) _emx_get_screensize (&_rl_screenwidth, &_rl_screenheight); #endif + if (ignore_env || rl_prefer_env_winsize == 0) + { + _rl_screenwidth = wc; + _rl_screenheight = wr; + } + else + _rl_screenwidth = _rl_screenheight = -1; + /* Environment variable COLUMNS overrides setting of "co" if IGNORE_ENV - is unset. */ + is unset. If we prefer the environment, check it first before + assigning the value returned by the kernel. */ if (_rl_screenwidth <= 0) { if (ignore_env == 0 && (ss = sh_get_env_value ("COLUMNS"))) _rl_screenwidth = atoi (ss); + if (_rl_screenwidth <= 0) + _rl_screenwidth = wc; + #if defined (__DJGPP__) if (_rl_screenwidth <= 0) _rl_screenwidth = ScreenCols (); @@ -255,6 +271,9 @@ _rl_get_screen_size (tty, ignore_env) if (ignore_env == 0 && (ss = sh_get_env_value ("LINES"))) _rl_screenheight = atoi (ss); + if (_rl_screenheight <= 0) + _rl_screenheight = wr; + #if defined (__DJGPP__) if (_rl_screenheight <= 0) _rl_screenheight = ScreenRows (); @@ -286,16 +305,20 @@ void _rl_set_screen_size (rows, cols) int rows, cols; { - if (rows == 0 || cols == 0) - return; + if (_rl_term_autowrap == -1) + _rl_init_terminal_io (rl_terminal_name); - _rl_screenheight = rows; - _rl_screenwidth = cols; - - if (_rl_term_autowrap == 0) - _rl_screenwidth--; + if (rows > 0) + _rl_screenheight = rows; + if (cols > 0) + { + _rl_screenwidth = cols; + if (_rl_term_autowrap == 0) + _rl_screenwidth--; + } - _rl_screenchars = _rl_screenwidth * _rl_screenheight; + if (rows > 0 || cols > 0) + _rl_screenchars = _rl_screenwidth * _rl_screenheight; } void @@ -314,6 +337,12 @@ rl_get_screen_size (rows, cols) if (cols) *cols = _rl_screenwidth; } + +void +rl_reset_screen_size () +{ + _rl_get_screen_size (fileno (rl_instream), 0); +} void rl_resize_terminal () @@ -347,6 +376,7 @@ static struct _tc_string tc_strings[] = { "ei", &_rl_term_ei }, { "ic", &_rl_term_ic }, { "im", &_rl_term_im }, + { "kD", &_rl_term_kD }, /* delete */ { "kH", &_rl_term_kH }, /* home down ?? */ { "kI", &_rl_term_kI }, /* insert */ { "kd", &_rl_term_kd }, @@ -381,11 +411,7 @@ get_term_capabilities (bp) register int i; for (i = 0; i < NUM_TC_STRINGS; i++) -# ifdef __LCC__ *(tc_strings[i].tc_value) = tgetstr ((char *)tc_strings[i].tc_var, bp); -# else - *(tc_strings[i].tc_value) = tgetstr (tc_strings[i].tc_var, bp); -# endif #endif tcap_initialized = 1; } @@ -401,7 +427,6 @@ _rl_init_terminal_io (terminal_name) term = terminal_name ? terminal_name : sh_get_env_value ("TERM"); _rl_term_clrpag = _rl_term_cr = _rl_term_clreol = (char *)NULL; tty = rl_instream ? fileno (rl_instream) : 0; - _rl_screenwidth = _rl_screenheight = 0; if (term == 0) term = "dumb"; @@ -451,12 +476,17 @@ _rl_init_terminal_io (terminal_name) _rl_term_autowrap = 0; /* used by _rl_get_screen_size */ + /* Allow calling application to set default height and width, using + rl_set_screen_size */ + if (_rl_screenwidth <= 0 || _rl_screenheight <= 0) + { #if defined (__EMX__) - _emx_get_screensize (&_rl_screenwidth, &_rl_screenheight); - _rl_screenwidth--; + _emx_get_screensize (&_rl_screenwidth, &_rl_screenheight); + _rl_screenwidth--; #else /* !__EMX__ */ - _rl_get_screen_size (tty, 0); + _rl_get_screen_size (tty, 0); #endif /* !__EMX__ */ + } /* Defaults. */ if (_rl_screenwidth <= 0 || _rl_screenheight <= 0) @@ -471,7 +501,7 @@ _rl_init_terminal_io (terminal_name) _rl_term_im = _rl_term_ei = _rl_term_ic = _rl_term_IC = (char *)NULL; _rl_term_up = _rl_term_dc = _rl_term_DC = _rl_visible_bell = (char *)NULL; _rl_term_ku = _rl_term_kd = _rl_term_kl = _rl_term_kr = (char *)NULL; - _rl_term_kh = _rl_term_kH = _rl_term_kI = (char *)NULL; + _rl_term_kh = _rl_term_kH = _rl_term_kI = _rl_term_kD = (char *)NULL; _rl_term_ks = _rl_term_ke = _rl_term_at7 = (char *)NULL; _rl_term_mm = _rl_term_mo = (char *)NULL; _rl_term_ve = _rl_term_vs = (char *)NULL; @@ -503,7 +533,10 @@ _rl_init_terminal_io (terminal_name) _rl_term_autowrap = tgetflag ("am") && tgetflag ("xn"); - _rl_get_screen_size (tty, 0); + /* Allow calling application to set default height and width, using + rl_set_screen_size */ + if (_rl_screenwidth <= 0 || _rl_screenheight <= 0) + _rl_get_screen_size (tty, 0); /* "An application program can assume that the terminal can do character insertion if *any one of* the capabilities `IC', @@ -542,13 +575,15 @@ bind_termcap_arrow_keys (map) xkeymap = _rl_keymap; _rl_keymap = map; - _rl_bind_if_unbound (_rl_term_ku, rl_get_previous_history); - _rl_bind_if_unbound (_rl_term_kd, rl_get_next_history); - _rl_bind_if_unbound (_rl_term_kr, rl_forward); - _rl_bind_if_unbound (_rl_term_kl, rl_backward); + rl_bind_keyseq_if_unbound (_rl_term_ku, rl_get_previous_history); + rl_bind_keyseq_if_unbound (_rl_term_kd, rl_get_next_history); + rl_bind_keyseq_if_unbound (_rl_term_kr, rl_forward_char); + rl_bind_keyseq_if_unbound (_rl_term_kl, rl_backward_char); + + rl_bind_keyseq_if_unbound (_rl_term_kh, rl_beg_of_line); /* Home */ + rl_bind_keyseq_if_unbound (_rl_term_at7, rl_end_of_line); /* End */ - _rl_bind_if_unbound (_rl_term_kh, rl_beg_of_line); /* Home */ - _rl_bind_if_unbound (_rl_term_at7, rl_end_of_line); /* End */ + rl_bind_keyseq_if_unbound (_rl_term_kD, rl_delete); _rl_keymap = xkeymap; } @@ -575,6 +610,7 @@ int rl_reset_terminal (terminal_name) const char *terminal_name; { + _rl_screenwidth = _rl_screenheight = 0; _rl_init_terminal_io (terminal_name); return 0; } @@ -656,8 +692,8 @@ rl_ding () tputs (_rl_visible_bell, 1, _rl_output_character_function); break; } -#endif /* FALLTHROUGH */ +#endif case AUDIBLE_BELL: fprintf (stderr, "\007"); fflush (stderr); diff --git a/readline/text.c b/readline/text.c index 2a7b724f481..bb87604aa6d 100644 --- a/readline/text.c +++ b/readline/text.c @@ -1,6 +1,6 @@ /* text.c -- text handling commands for readline. */ -/* Copyright (C) 1987-2002 Free Software Foundation, Inc. +/* Copyright (C) 1987-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -62,6 +62,11 @@ static int rl_change_case PARAMS((int, int)); static int _rl_char_search PARAMS((int, int, int)); +#if defined (READLINE_CALLBACKS) +static int _rl_insert_next_callback PARAMS((_rl_callback_generic_arg *)); +static int _rl_char_search_callback PARAMS((_rl_callback_generic_arg *)); +#endif + /* **************************************************************** */ /* */ /* Insert and Delete */ @@ -170,6 +175,9 @@ _rl_fix_point (fix_mark_too) } #undef _RL_FIX_POINT +/* Replace the contents of the line buffer between START and END with + TEXT. The operation is undoable. To replace the entire line in an + undoable mode, use _rl_replace_text(text, 0, rl_end); */ int _rl_replace_text (text, start, end) const char *text; @@ -417,8 +425,7 @@ rl_end_of_line (count, key) return 0; } -/* XXX - these might need changes for multibyte characters */ -/* Move forward a word. We do what Emacs does. */ +/* Move forward a word. We do what Emacs does. Handles multibyte chars. */ int rl_forward_word (count, key) int count, key; @@ -435,68 +442,80 @@ rl_forward_word (count, key) /* If we are not in a word, move forward until we are in one. Then, move forward until we hit a non-alphabetic character. */ - c = rl_line_buffer[rl_point]; - if (rl_alphabetic (c) == 0) + c = _rl_char_value (rl_line_buffer, rl_point); + + if (_rl_walphabetic (c) == 0) { - while (++rl_point < rl_end) + rl_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO); + while (rl_point < rl_end) { - c = rl_line_buffer[rl_point]; - if (rl_alphabetic (c)) + c = _rl_char_value (rl_line_buffer, rl_point); + if (_rl_walphabetic (c)) break; + rl_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO); } } if (rl_point == rl_end) return 0; - while (++rl_point < rl_end) + rl_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO); + while (rl_point < rl_end) { - c = rl_line_buffer[rl_point]; - if (rl_alphabetic (c) == 0) + c = _rl_char_value (rl_line_buffer, rl_point); + if (_rl_walphabetic (c) == 0) break; + rl_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO); } + --count; } return 0; } -/* Move backward a word. We do what Emacs does. */ +/* Move backward a word. We do what Emacs does. Handles multibyte chars. */ int rl_backward_word (count, key) int count, key; { - int c; + int c, p; if (count < 0) return (rl_forward_word (-count, key)); while (count) { - if (!rl_point) + if (rl_point == 0) return 0; /* Like rl_forward_word (), except that we look at the characters just before point. */ - c = rl_line_buffer[rl_point - 1]; - if (rl_alphabetic (c) == 0) + p = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO); + c = _rl_char_value (rl_line_buffer, p); + + if (_rl_walphabetic (c) == 0) { - while (--rl_point) + rl_point = p; + while (rl_point > 0) { - c = rl_line_buffer[rl_point - 1]; - if (rl_alphabetic (c)) + p = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO); + c = _rl_char_value (rl_line_buffer, p); + if (_rl_walphabetic (c)) break; + rl_point = p; } } while (rl_point) { - c = rl_line_buffer[rl_point - 1]; - if (rl_alphabetic (c) == 0) + p = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO); + c = _rl_char_value (rl_line_buffer, p); + if (_rl_walphabetic (c) == 0) break; else - --rl_point; + rl_point = p; } --count; @@ -753,10 +772,8 @@ _rl_insert_char (count, c) return 0; } -#if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX == 1 || rl_byte_oriented) { -#endif /* We are inserting a single character. If there is pending input, then make a string of all of the pending characters that are bound to rl_insert, and insert @@ -772,8 +789,8 @@ _rl_insert_char (count, c) str[0] = c; rl_insert_text (str); } -#if defined (HANDLE_MULTIBYTE) } +#if defined (HANDLE_MULTIBYTE) else { rl_insert_text (incoming); @@ -801,13 +818,10 @@ _rl_overwrite_char (count, c) k = _rl_read_mbstring (c, mbkey, MB_LEN_MAX); #endif + rl_begin_undo_group (); + for (i = 0; i < count; i++) { - rl_begin_undo_group (); - - if (rl_point < rl_end) - rl_delete (1, c); - #if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) rl_insert_text (mbkey); @@ -815,9 +829,12 @@ _rl_overwrite_char (count, c) #endif _rl_insert_char (1, c); - rl_end_undo_group (); + if (rl_point < rl_end) + rl_delete (1, c); } + rl_end_undo_group (); + return 0; } @@ -830,27 +847,63 @@ rl_insert (count, c) } /* Insert the next typed character verbatim. */ -int -rl_quoted_insert (count, key) - int count, key; +static int +_rl_insert_next (count) + int count; { int c; -#if defined (HANDLE_SIGNALS) - _rl_disable_tty_signals (); -#endif - RL_SETSTATE(RL_STATE_MOREINPUT); c = rl_read_key (); RL_UNSETSTATE(RL_STATE_MOREINPUT); #if defined (HANDLE_SIGNALS) - _rl_restore_tty_signals (); + if (RL_ISSTATE (RL_STATE_CALLBACK) == 0) + _rl_restore_tty_signals (); #endif return (_rl_insert_char (count, c)); } +#if defined (READLINE_CALLBACKS) +static int +_rl_insert_next_callback (data) + _rl_callback_generic_arg *data; +{ + int count; + + count = data->count; + + /* Deregister function, let rl_callback_read_char deallocate data */ + _rl_callback_func = 0; + _rl_want_redisplay = 1; + + return _rl_insert_next (count); +} +#endif + +int +rl_quoted_insert (count, key) + int count, key; +{ + /* Let's see...should the callback interface futz with signal handling? */ +#if defined (HANDLE_SIGNALS) + if (RL_ISSTATE (RL_STATE_CALLBACK) == 0) + _rl_disable_tty_signals (); +#endif + +#if defined (READLINE_CALLBACKS) + if (RL_ISSTATE (RL_STATE_CALLBACK)) + { + _rl_callback_data = _rl_callback_data_alloc (count); + _rl_callback_func = _rl_insert_next_callback; + return (0); + } +#endif + + return _rl_insert_next (count); +} + /* Insert a tab character. */ int rl_tab_insert (count, key) @@ -877,7 +930,8 @@ rl_newline (count, key) if (rl_editing_mode == vi_mode) { _rl_vi_done_inserting (); - _rl_vi_reset_last (); + if (_rl_vi_textmod_command (_rl_vi_last_command) == 0) /* XXX */ + _rl_vi_reset_last (); } #endif /* VI_MODE */ @@ -935,9 +989,12 @@ _rl_overwrite_rubout (count, key) rl_delete_text (opoint, rl_point); /* Emacs puts point at the beginning of the sequence of spaces. */ - opoint = rl_point; - _rl_insert_char (l, ' '); - rl_point = opoint; + if (rl_point < rl_end) + { + opoint = rl_point; + _rl_insert_char (l, ' '); + rl_point = opoint; + } rl_end_undo_group (); @@ -981,43 +1038,17 @@ _rl_rubout_char (count, key) return -1; } + orig_point = rl_point; if (count > 1 || rl_explicit_arg) { - orig_point = rl_point; -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - rl_backward_char (count, key); - else -#endif - rl_backward_byte (count, key); + rl_backward_char (count, key); rl_kill_text (orig_point, rl_point); } - else + else if (MB_CUR_MAX == 1 || rl_byte_oriented) { -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX == 1 || rl_byte_oriented) - { -#endif - c = rl_line_buffer[--rl_point]; - rl_delete_text (rl_point, rl_point + 1); -#if defined (HANDLE_MULTIBYTE) - } - else - { - int orig_point; - - orig_point = rl_point; - rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO); - c = rl_line_buffer[rl_point]; - rl_delete_text (rl_point, orig_point); - } -#endif /* HANDLE_MULTIBYTE */ - - /* I don't think that the hack for end of line is needed for - multibyte chars. */ -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX == 1 || rl_byte_oriented) -#endif + c = rl_line_buffer[--rl_point]; + rl_delete_text (rl_point, orig_point); + /* The erase-at-end-of-line hack is of questionable merit now. */ if (rl_point == rl_end && ISPRINT (c) && _rl_last_c_pos) { int l; @@ -1025,6 +1056,11 @@ _rl_rubout_char (count, key) _rl_erase_at_end_of_line (l); } } + else + { + rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO); + rl_delete_text (rl_point, orig_point); + } return 0; } @@ -1035,8 +1071,6 @@ int rl_delete (count, key) int count, key; { - int r; - if (count < 0) return (_rl_rubout_char (-count, key)); @@ -1049,27 +1083,22 @@ rl_delete (count, key) if (count > 1 || rl_explicit_arg) { int orig_point = rl_point; -#if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) rl_forward_char (count, key); else -#endif rl_forward_byte (count, key); - r = rl_kill_text (orig_point, rl_point); + rl_kill_text (orig_point, rl_point); rl_point = orig_point; - return r; } else { int new_point; - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - new_point = _rl_find_next_mbchar (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO); - else - new_point = rl_point + 1; - - return (rl_delete_text (rl_point, new_point)); + + new_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO); + rl_delete_text (rl_point, new_point); } + return 0; } /* Delete the character under the cursor, unless the insertion @@ -1106,6 +1135,10 @@ rl_delete_horizontal_space (count, ignore) rl_delete_text (start, rl_point); rl_point = start; } + + if (rl_point < 0) + rl_point = 0; + return 0; } @@ -1199,42 +1232,80 @@ static int rl_change_case (count, op) int count, op; { - register int start, end; - int inword, c; + int start, next, end; + int inword, c, nc, nop; +#if defined (HANDLE_MULTIBYTE) + wchar_t wc, nwc; + char mb[MB_LEN_MAX+1]; + int mblen, p; + mbstate_t ps; +#endif start = rl_point; rl_forward_word (count, 0); end = rl_point; + if (op != UpCase && op != DownCase && op != CapCase) + { + rl_ding (); + return -1; + } + if (count < 0) SWAP (start, end); +#if defined (HANDLE_MULTIBYTE) + memset (&ps, 0, sizeof (mbstate_t)); +#endif + /* We are going to modify some text, so let's prepare to undo it. */ rl_modifying (start, end); - for (inword = 0; start < end; start++) + inword = 0; + while (start < end) { - c = rl_line_buffer[start]; - switch (op) - { - case UpCase: - rl_line_buffer[start] = _rl_to_upper (c); - break; + c = _rl_char_value (rl_line_buffer, start); + /* This assumes that the upper and lower case versions are the same width. */ + next = MB_NEXTCHAR (rl_line_buffer, start, 1, MB_FIND_NONZERO); - case DownCase: - rl_line_buffer[start] = _rl_to_lower (c); - break; - - case CapCase: - rl_line_buffer[start] = (inword == 0) ? _rl_to_upper (c) : _rl_to_lower (c); - inword = rl_alphabetic (rl_line_buffer[start]); - break; + if (_rl_walphabetic (c) == 0) + { + inword = 0; + start = next; + continue; + } - default: - rl_ding (); - return -1; + if (op == CapCase) + { + nop = inword ? DownCase : UpCase; + inword = 1; } + else + nop = op; + if (MB_CUR_MAX == 1 || rl_byte_oriented || isascii (c)) + { + nc = (nop == UpCase) ? _rl_to_upper (c) : _rl_to_lower (c); + rl_line_buffer[start] = nc; + } +#if defined (HANDLE_MULTIBYTE) + else + { + mbrtowc (&wc, rl_line_buffer + start, end - start, &ps); + nwc = (nop == UpCase) ? _rl_to_wupper (wc) : _rl_to_wlower (wc); + if (nwc != wc) /* just skip unchanged characters */ + { + mblen = wcrtomb (mb, nwc, &ps); + if (mblen > 0) + mb[mblen] = '\0'; + /* Assume the same width */ + strncpy (rl_line_buffer + start, mb, mblen); + } + } +#endif + + start = next; } + rl_point = end; return 0; } @@ -1314,11 +1385,11 @@ rl_transpose_chars (count, key) { #if defined (HANDLE_MULTIBYTE) char *dummy; - int i, prev_point; + int i; #else char dummy[2]; #endif - int char_length; + int char_length, prev_point; if (count == 0) return 0; @@ -1333,20 +1404,12 @@ rl_transpose_chars (count, key) if (rl_point == rl_end) { - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO); - else - --rl_point; + rl_point = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO); count = 1; } -#if defined (HANDLE_MULTIBYTE) prev_point = rl_point; - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO); - else -#endif - rl_point--; + rl_point = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO); #if defined (HANDLE_MULTIBYTE) char_length = prev_point - rl_point; @@ -1480,10 +1543,33 @@ _rl_char_search (count, fdir, bdir) } #endif /* !HANDLE_MULTIBYTE */ +#if defined (READLINE_CALLBACKS) +static int +_rl_char_search_callback (data) + _rl_callback_generic_arg *data; +{ + _rl_callback_func = 0; + _rl_want_redisplay = 1; + + return (_rl_char_search (data->count, data->i1, data->i2)); +} +#endif + int rl_char_search (count, key) int count, key; { +#if defined (READLINE_CALLBACKS) + if (RL_ISSTATE (RL_STATE_CALLBACK)) + { + _rl_callback_data = _rl_callback_data_alloc (count); + _rl_callback_data->i1 = FFIND; + _rl_callback_data->i2 = BFIND; + _rl_callback_func = _rl_char_search_callback; + return (0); + } +#endif + return (_rl_char_search (count, FFIND, BFIND)); } @@ -1491,6 +1577,17 @@ int rl_backward_char_search (count, key) int count, key; { +#if defined (READLINE_CALLBACKS) + if (RL_ISSTATE (RL_STATE_CALLBACK)) + { + _rl_callback_data = _rl_callback_data_alloc (count); + _rl_callback_data->i1 = BFIND; + _rl_callback_data->i2 = FFIND; + _rl_callback_func = _rl_char_search_callback; + return (0); + } +#endif + return (_rl_char_search (count, BFIND, FFIND)); } diff --git a/readline/tilde.c b/readline/tilde.c index 60fc7fc6cdd..32f3d3cf380 100644 --- a/readline/tilde.c +++ b/readline/tilde.c @@ -43,9 +43,9 @@ #endif /* HAVE_STDLIB_H */ #include <sys/types.h> -#ifdef HAVE_PWD_H +#if defined (HAVE_PWD_H) #include <pwd.h> -#endif /* HAVE_PWD_H */ +#endif #include "tilde.h" @@ -55,10 +55,14 @@ static void *xmalloc (), *xrealloc (); # include "xmalloc.h" #endif /* TEST || STATIC_MALLOC */ -#if defined (HAVE_GETPWNAM) && !defined (HAVE_GETPW_DECLS) +#if !defined (HAVE_GETPW_DECLS) +# if defined (HAVE_GETPWUID) extern struct passwd *getpwuid PARAMS((uid_t)); +# endif +# if defined (HAVE_GETPWNAM) extern struct passwd *getpwnam PARAMS((const char *)); -#endif /* defined (HAVE_GETPWNAM) && !HAVE_GETPW_DECLS */ +# endif +#endif /* !HAVE_GETPW_DECLS */ #if !defined (savestring) #define savestring(x) strcpy ((char *)xmalloc (1 + strlen (x)), (x)) @@ -279,6 +283,39 @@ isolate_tilde_prefix (fname, lenp) return ret; } +#if 0 +/* Public function to scan a string (FNAME) beginning with a tilde and find + the portion of the string that should be passed to the tilde expansion + function. Right now, it just calls tilde_find_suffix and allocates new + memory, but it can be expanded to do different things later. */ +char * +tilde_find_word (fname, flags, lenp) + const char *fname; + int flags, *lenp; +{ + int x; + char *r; + + x = tilde_find_suffix (fname); + if (x == 0) + { + r = savestring (fname); + if (lenp) + *lenp = 0; + } + else + { + r = (char *)xmalloc (1 + x); + strncpy (r, fname, x); + r[x] = '\0'; + if (lenp) + *lenp = x; + } + + return r; +} +#endif + /* Return a string that is PREFIX concatenated with SUFFIX starting at SUFFIND. */ static char * @@ -349,8 +386,11 @@ tilde_expand_word (filename) /* No preexpansion hook, or the preexpansion hook failed. Look in the password database. */ dirname = (char *)NULL; -#ifdef HAVE_GETPWNAM +#if defined (HAVE_GETPWNAM) user_entry = getpwnam (username); +#else + user_entry = 0; +#endif if (user_entry == 0) { /* If the calling program has a special syntax for expanding tildes, @@ -370,12 +410,12 @@ tilde_expand_word (filename) if (dirname == 0) dirname = savestring (filename); } +#if defined (HAVE_GETPWENT) else { free (username); dirname = glue_prefix_and_suffix (user_entry->pw_dir, filename, user_len); } - endpwent (); #endif return (dirname); diff --git a/readline/tilde.h b/readline/tilde.h index f8182c999d9..c58ce20e7a2 100644 --- a/readline/tilde.h +++ b/readline/tilde.h @@ -71,6 +71,9 @@ extern char *tilde_expand PARAMS((const char *)); tilde. If there is no expansion, call tilde_expansion_failure_hook. */ extern char *tilde_expand_word PARAMS((const char *)); +/* Find the portion of the string beginning with ~ that should be expanded. */ +extern char *tilde_find_word PARAMS((const char *, int, int *)); + #ifdef __cplusplus } #endif diff --git a/readline/undo.c b/readline/undo.c index 25c287b5a2d..fedfa121fc0 100644 --- a/readline/undo.c +++ b/readline/undo.c @@ -237,7 +237,12 @@ rl_revert_line (count, key) { while (rl_undo_list) rl_do_undo (); +#if defined (VI_MODE) + if (rl_editing_mode == vi_mode) + rl_point = rl_mark = 0; /* rl_end should be set correctly */ +#endif } + return 0; } diff --git a/readline/util.c b/readline/util.c index c7bd360e43c..e44ef64349d 100644 --- a/readline/util.c +++ b/readline/util.c @@ -1,6 +1,6 @@ /* util.c -- readline utility functions */ -/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1987-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -44,6 +44,7 @@ /* System-specific feature definitions and include files. */ #include "rldefs.h" +#include "rlmbutil.h" #if defined (TIOCSTAT_IN_SYS_IOCTL) # include <sys/ioctl.h> @@ -78,13 +79,29 @@ rl_alphabetic (c) strchr (pathname_alphabetic_chars, c) != NULL); } +#if defined (HANDLE_MULTIBYTE) +int +_rl_walphabetic (wc) + wchar_t wc; +{ + int c; + + if (iswalnum (wc)) + return (1); + + c = wc & 0177; + return (_rl_allow_pathname_alphabetic_chars && + strchr (pathname_alphabetic_chars, c) != NULL); +} +#endif + /* How to abort things. */ int _rl_abort_internal () { rl_ding (); rl_clear_message (); - _rl_init_argument (); + _rl_reset_argument (); rl_clear_pending_input (); RL_UNSETSTATE (RL_STATE_MACRODEF); @@ -250,7 +267,7 @@ _rl_strpbrk (string1, string2) { v = _rl_get_char_len (string1, &ps); if (v > 1) - string += v - 1; /* -1 to account for auto-increment in loop */ + string1 += v - 1; /* -1 to account for auto-increment in loop */ } #endif } diff --git a/readline/vi_keymap.c b/readline/vi_keymap.c index 53a67c674ce..4b48c75cc5d 100644 --- a/readline/vi_keymap.c +++ b/readline/vi_keymap.c @@ -130,7 +130,7 @@ KEYMAP_ENTRY_ARRAY vi_movement_keymap = { { ISFUNC, rl_revert_line }, /* U */ { ISFUNC, (rl_command_func_t *)0x0 }, /* V */ { ISFUNC, rl_vi_next_word }, /* W */ - { ISFUNC, rl_rubout }, /* X */ + { ISFUNC, rl_vi_rubout }, /* X */ { ISFUNC, rl_vi_yank_to }, /* Y */ { ISFUNC, (rl_command_func_t *)0x0 }, /* Z */ diff --git a/readline/vi_mode.c b/readline/vi_mode.c index 89303644c59..ac5fd7446dc 100644 --- a/readline/vi_mode.c +++ b/readline/vi_mode.c @@ -1,7 +1,7 @@ /* vi_mode.c -- A vi emulation mode for Bash. Derived from code written by Jeff Sparkes (jsparkes@bnr.ca). */ -/* Copyright (C) 1987, 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. @@ -63,6 +63,8 @@ #define member(c, s) ((c) ? (char *)strchr ((s), (c)) != (char *)NULL : 0) #endif +int _rl_vi_last_command = 'i'; /* default `.' puts you in insert mode */ + /* Non-zero means enter insertion mode. */ static int _rl_vi_doing_insert; @@ -83,12 +85,12 @@ static int vi_continued_command; static char *vi_insert_buffer; static int vi_insert_buffer_size; -static int _rl_vi_last_command = 'i'; /* default `.' puts you in insert mode */ static int _rl_vi_last_repeat = 1; static int _rl_vi_last_arg_sign = 1; static int _rl_vi_last_motion; #if defined (HANDLE_MULTIBYTE) static char _rl_vi_last_search_mbchar[MB_LEN_MAX]; +static int _rl_vi_last_search_mblen; #else static int _rl_vi_last_search_char; #endif @@ -106,8 +108,22 @@ static int vi_mark_chars['z' - 'a' + 1]; static void _rl_vi_stuff_insert PARAMS((int)); static void _rl_vi_save_insert PARAMS((UNDO_LIST *)); + +static int _rl_vi_arg_dispatch PARAMS((int)); static int rl_digit_loop1 PARAMS((void)); +static int _rl_vi_set_mark PARAMS((void)); +static int _rl_vi_goto_mark PARAMS((void)); + +static int _rl_vi_callback_getchar PARAMS((char *, int)); + +#if defined (READLINE_CALLBACKS) +static int _rl_vi_callback_set_mark PARAMS((_rl_callback_generic_arg *)); +static int _rl_vi_callback_goto_mark PARAMS((_rl_callback_generic_arg *)); +static int _rl_vi_callback_change_char PARAMS((_rl_callback_generic_arg *)); +static int _rl_vi_callback_char_search PARAMS((_rl_callback_generic_arg *)); +#endif + void _rl_vi_initialize_line () { @@ -115,6 +131,8 @@ _rl_vi_initialize_line () for (i = 0; i < sizeof (vi_mark_chars) / sizeof (int); i++) vi_mark_chars[i] = -1; + + RL_UNSETSTATE(RL_STATE_VICMDONCE); } void @@ -135,6 +153,16 @@ _rl_vi_set_last (key, repeat, sign) _rl_vi_last_arg_sign = sign; } +/* A convenience function that calls _rl_vi_set_last to save the last command + information and enters insertion mode. */ +void +rl_vi_start_inserting (key, repeat, sign) + int key, repeat, sign; +{ + _rl_vi_set_last (key, repeat, sign); + rl_vi_insertion_mode (1, key); +} + /* Is the command C a VI mode text modification command? */ int _rl_vi_textmod_command (c) @@ -261,10 +289,12 @@ rl_vi_search (count, key) switch (key) { case '?': + _rl_free_saved_history_line (); rl_noninc_forward_search (count, key); break; case '/': + _rl_free_saved_history_line (); rl_noninc_reverse_search (count, key); break; @@ -297,10 +327,8 @@ rl_vi_complete (ignore, key) rl_complete (0, key); if (key == '*' || key == '\\') - { - _rl_vi_set_last (key, 1, rl_arg_sign); - rl_vi_insertion_mode (1, key); - } + rl_vi_start_inserting (key, 1, rl_arg_sign); + return (0); } @@ -310,8 +338,7 @@ rl_vi_tilde_expand (ignore, key) int ignore, key; { rl_tilde_expand (0, key); - _rl_vi_set_last (key, 1, rl_arg_sign); /* XXX */ - rl_vi_insertion_mode (1, key); + rl_vi_start_inserting (key, 1, rl_arg_sign); return (0); } @@ -429,7 +456,8 @@ rl_vi_eWord (count, ignore) /* Move to the next non-whitespace character (to the start of the next word). */ - while (++rl_point < rl_end && whitespace (rl_line_buffer[rl_point])); + while (rl_point < rl_end && whitespace (rl_line_buffer[rl_point])) + rl_point++; if (rl_point && rl_point < rl_end) { @@ -640,7 +668,7 @@ _rl_vi_done_inserting () } else { - if (_rl_vi_last_key_before_insert == 'i' && rl_undo_list) + if ((_rl_vi_last_key_before_insert == 'i' || _rl_vi_last_key_before_insert == 'a') && rl_undo_list) _rl_vi_save_insert (rl_undo_list); /* XXX - Other keys probably need to be checked. */ else if (_rl_vi_last_key_before_insert == 'C') @@ -660,6 +688,13 @@ rl_vi_movement_mode (count, key) _rl_keymap = vi_movement_keymap; _rl_vi_done_inserting (); + + /* This is how POSIX.2 says `U' should behave -- everything up until the + first time you go into command mode should not be undone. */ + if (RL_ISSTATE (RL_STATE_VICMDONCE) == 0) + rl_free_undo_list (); + + RL_SETSTATE (RL_STATE_VICMDONCE); return (0); } @@ -681,7 +716,7 @@ _rl_vi_change_mbchar_case (count) { wchar_t wc; char mb[MB_LEN_MAX+1]; - int mblen; + int mblen, p; mbstate_t ps; memset (&ps, 0, sizeof (mbstate_t)); @@ -704,11 +739,14 @@ _rl_vi_change_mbchar_case (count) /* Vi is kind of strange here. */ if (wc) { - mblen = wctomb (mb, wc); + p = rl_point; + mblen = wcrtomb (mb, wc, &ps); if (mblen >= 0) mb[mblen] = '\0'; rl_begin_undo_group (); - rl_delete (1, 0); + rl_vi_delete (1, 0); + if (rl_point < p) /* Did we retreat at EOL? */ + rl_point++; /* XXX - should we advance more than 1 for mbchar? */ rl_insert_text (mb); rl_end_undo_group (); rl_vi_check (); @@ -725,12 +763,13 @@ int rl_vi_change_case (count, ignore) int count, ignore; { - char c = 0; + int c, p; /* Don't try this on an empty line. */ if (rl_point >= rl_end) return (0); + c = 0; #if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) return (_rl_vi_change_mbchar_case (count)); @@ -752,8 +791,11 @@ rl_vi_change_case (count, ignore) /* Vi is kind of strange here. */ if (c) { + p = rl_point; rl_begin_undo_group (); - rl_delete (1, c); + rl_vi_delete (1, c); + if (rl_point < p) /* Did we retreat at EOL? */ + rl_point++; _rl_insert_char (1, c); rl_end_undo_group (); rl_vi_check (); @@ -771,7 +813,9 @@ rl_vi_put (count, key) if (!_rl_uppercase_p (key) && (rl_point + 1 <= rl_end)) rl_point = _rl_find_next_mbchar (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO); - rl_yank (1, key); + while (count--) + rl_yank (1, key); + rl_backward_char (1, key); return (0); } @@ -819,7 +863,10 @@ rl_vi_domove (key, nextkey) { save = rl_numeric_arg; rl_numeric_arg = _rl_digit_value (c); + rl_explicit_arg = 1; + RL_SETSTATE (RL_STATE_NUMERICARG|RL_STATE_VIMOTION); rl_digit_loop1 (); + RL_UNSETSTATE (RL_STATE_VIMOTION); rl_numeric_arg *= save; RL_SETSTATE(RL_STATE_MOREINPUT); c = rl_read_key (); /* real command */ @@ -892,52 +939,59 @@ rl_vi_domove (key, nextkey) return (0); } +/* Process C as part of the current numeric argument. Return -1 if the + argument should be aborted, 0 if we should not read any more chars, and + 1 if we should continue to read chars. */ +static int +_rl_vi_arg_dispatch (c) + int c; +{ + int key; + + key = c; + if (c >= 0 && _rl_keymap[c].type == ISFUNC && _rl_keymap[c].function == rl_universal_argument) + { + rl_numeric_arg *= 4; + return 1; + } + + c = UNMETA (c); + + if (_rl_digit_p (c)) + { + if (rl_explicit_arg) + rl_numeric_arg = (rl_numeric_arg * 10) + _rl_digit_value (c); + else + rl_numeric_arg = _rl_digit_value (c); + rl_explicit_arg = 1; + return 1; + } + else + { + rl_clear_message (); + rl_stuff_char (key); + return 0; + } +} + /* A simplified loop for vi. Don't dispatch key at end. Don't recognize minus sign? Should this do rl_save_prompt/rl_restore_prompt? */ static int rl_digit_loop1 () { - int key, c; + int c, r; - RL_SETSTATE(RL_STATE_NUMERICARG); while (1) { - if (rl_numeric_arg > 1000000) - { - rl_explicit_arg = rl_numeric_arg = 0; - rl_ding (); - rl_clear_message (); - RL_UNSETSTATE(RL_STATE_NUMERICARG); - return 1; - } - rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg); - RL_SETSTATE(RL_STATE_MOREINPUT); - key = c = rl_read_key (); - RL_UNSETSTATE(RL_STATE_MOREINPUT); + if (_rl_arg_overflow ()) + return 1; - if (c >= 0 && _rl_keymap[c].type == ISFUNC && - _rl_keymap[c].function == rl_universal_argument) - { - rl_numeric_arg *= 4; - continue; - } + c = _rl_arg_getchar (); - c = UNMETA (c); - if (_rl_digit_p (c)) - { - if (rl_explicit_arg) - rl_numeric_arg = (rl_numeric_arg * 10) + _rl_digit_value (c); - else - rl_numeric_arg = _rl_digit_value (c); - rl_explicit_arg = 1; - } - else - { - rl_clear_message (); - rl_stuff_char (key); - break; - } + r = _rl_vi_arg_dispatch (c); + if (r <= 0) + break; } RL_UNSETSTATE(RL_STATE_NUMERICARG); @@ -1017,8 +1071,7 @@ rl_vi_change_to (count, key) /* `C' does not save the text inserted for undoing or redoing. */ if (_rl_uppercase_p (key) == 0) _rl_vi_doing_insert = 1; - _rl_vi_set_last (key, count, rl_arg_sign); - rl_vi_insertion_mode (1, key); + rl_vi_start_inserting (key, rl_numeric_arg, rl_arg_sign); } return (0); @@ -1028,8 +1081,9 @@ int rl_vi_yank_to (count, key) int count, key; { - int c, save = rl_point; + int c, save; + save = rl_point; if (_rl_uppercase_p (key)) rl_stuff_char ('$'); @@ -1054,11 +1108,45 @@ rl_vi_yank_to (count, key) } int +rl_vi_rubout (count, key) + int count, key; +{ + int p, opoint; + + if (count < 0) + return (rl_vi_delete (-count, key)); + + if (rl_point == 0) + { + rl_ding (); + return -1; + } + + opoint = rl_point; + if (count > 1 && MB_CUR_MAX > 1 && rl_byte_oriented == 0) + rl_backward_char (count, key); + else if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO); + else + rl_point -= count; + + if (rl_point < 0) + rl_point = 0; + + rl_kill_text (rl_point, opoint); + + return (0); +} + +int rl_vi_delete (count, key) int count, key; { int end; + if (count < 0) + return (rl_vi_rubout (-count, key)); + if (rl_end == 0) { rl_ding (); @@ -1077,6 +1165,7 @@ rl_vi_delete (count, key) if (rl_point > 0 && rl_point == rl_end) rl_backward_char (1, key); + return (0); } @@ -1097,64 +1186,102 @@ rl_vi_first_print (count, key) return (rl_vi_back_to_indent (1, key)); } +static int _rl_cs_dir, _rl_cs_orig_dir; + +#if defined (READLINE_CALLBACKS) +static int +_rl_vi_callback_char_search (data) + _rl_callback_generic_arg *data; +{ +#if defined (HANDLE_MULTIBYTE) + _rl_vi_last_search_mblen = _rl_read_mbchar (_rl_vi_last_search_mbchar, MB_LEN_MAX); +#else + RL_SETSTATE(RL_STATE_MOREINPUT); + _rl_vi_last_search_char = rl_read_key (); + RL_UNSETSTATE(RL_STATE_MOREINPUT); +#endif + + _rl_callback_func = 0; + _rl_want_redisplay = 1; + +#if defined (HANDLE_MULTIBYTE) + return (_rl_char_search_internal (data->count, _rl_cs_dir, _rl_vi_last_search_mbchar, _rl_vi_last_search_mblen)); +#else + return (_rl_char_search_internal (data->count, _rl_cs_dir, _rl_vi_last_search_char)); +#endif +} +#endif + int rl_vi_char_search (count, key) int count, key; { #if defined (HANDLE_MULTIBYTE) static char *target; - static int mb_len; + static int tlen; #else static char target; #endif - static int orig_dir, dir; if (key == ';' || key == ',') - dir = key == ';' ? orig_dir : -orig_dir; + _rl_cs_dir = (key == ';') ? _rl_cs_orig_dir : -_rl_cs_orig_dir; else { - if (vi_redoing) -#if defined (HANDLE_MULTIBYTE) - target = _rl_vi_last_search_mbchar; -#else - target = _rl_vi_last_search_char; -#endif - else - { -#if defined (HANDLE_MULTIBYTE) - mb_len = _rl_read_mbchar (_rl_vi_last_search_mbchar, MB_LEN_MAX); - target = _rl_vi_last_search_mbchar; -#else - RL_SETSTATE(RL_STATE_MOREINPUT); - _rl_vi_last_search_char = target = rl_read_key (); - RL_UNSETSTATE(RL_STATE_MOREINPUT); -#endif - } - switch (key) { case 't': - orig_dir = dir = FTO; + _rl_cs_orig_dir = _rl_cs_dir = FTO; break; case 'T': - orig_dir = dir = BTO; + _rl_cs_orig_dir = _rl_cs_dir = BTO; break; case 'f': - orig_dir = dir = FFIND; + _rl_cs_orig_dir = _rl_cs_dir = FFIND; break; case 'F': - orig_dir = dir = BFIND; + _rl_cs_orig_dir = _rl_cs_dir = BFIND; break; } + + if (vi_redoing) + { + /* set target and tlen below */ + } +#if defined (READLINE_CALLBACKS) + else if (RL_ISSTATE (RL_STATE_CALLBACK)) + { + _rl_callback_data = _rl_callback_data_alloc (count); + _rl_callback_data->i1 = _rl_cs_dir; + _rl_callback_func = _rl_vi_callback_char_search; + return (0); + } +#endif + else + { +#if defined (HANDLE_MULTIBYTE) + _rl_vi_last_search_mblen = _rl_read_mbchar (_rl_vi_last_search_mbchar, MB_LEN_MAX); +#else + RL_SETSTATE(RL_STATE_MOREINPUT); + _rl_vi_last_search_char = rl_read_key (); + RL_UNSETSTATE(RL_STATE_MOREINPUT); +#endif + } } #if defined (HANDLE_MULTIBYTE) - return (_rl_char_search_internal (count, dir, target, mb_len)); + target = _rl_vi_last_search_mbchar; + tlen = _rl_vi_last_search_mblen; +#else + target = _rl_vi_last_search_char; +#endif + +#if defined (HANDLE_MULTIBYTE) + return (_rl_char_search_internal (count, _rl_cs_dir, target, tlen)); #else - return (_rl_char_search_internal (count, dir, target)); + return (_rl_char_search_internal (count, _rl_cs_dir, target)); #endif } @@ -1265,60 +1392,109 @@ rl_vi_bracktype (c) } } -/* XXX - think about reading an entire mbchar with _rl_read_mbchar and - inserting it in one bunch instead of the loop below (like in - rl_vi_char_search or _rl_vi_change_mbchar_case. Set c to mbchar[0] - for test against 033 or ^C. Make sure that _rl_read_mbchar does - this right. */ -int -rl_vi_change_char (count, key) - int count, key; +static int +_rl_vi_change_char (count, c, mb) + int count, c; + char *mb; { - int c; - - if (vi_redoing) - c = _rl_vi_last_replacement; - else - { - RL_SETSTATE(RL_STATE_MOREINPUT); - _rl_vi_last_replacement = c = rl_read_key (); - RL_UNSETSTATE(RL_STATE_MOREINPUT); - } + int p; if (c == '\033' || c == CTRL ('C')) return -1; + rl_begin_undo_group (); while (count-- && rl_point < rl_end) { - rl_begin_undo_group (); - - rl_delete (1, c); + p = rl_point; + rl_vi_delete (1, c); + if (rl_point < p) /* Did we retreat at EOL? */ + rl_point++; #if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - while (_rl_insert_char (1, c)) - { - RL_SETSTATE (RL_STATE_MOREINPUT); - c = rl_read_key (); - RL_UNSETSTATE (RL_STATE_MOREINPUT); - } + rl_insert_text (mb); else #endif _rl_insert_char (1, c); - if (count == 0) - rl_backward_char (1, c); - - rl_end_undo_group (); } + + /* The cursor shall be left on the last character changed. */ + rl_backward_char (1, c); + + rl_end_undo_group (); + return (0); } +static int +_rl_vi_callback_getchar (mb, mblen) + char *mb; + int mblen; +{ + int c; + + RL_SETSTATE(RL_STATE_MOREINPUT); + c = rl_read_key (); + RL_UNSETSTATE(RL_STATE_MOREINPUT); + +#if defined (HANDLE_MULTIBYTE) + if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + c = _rl_read_mbstring (c, mb, mblen); +#endif + + return c; +} + +#if defined (READLINE_CALLBACKS) +static int +_rl_vi_callback_change_char (data) + _rl_callback_generic_arg *data; +{ + int c; + char mb[MB_LEN_MAX]; + + _rl_vi_last_replacement = c = _rl_vi_callback_getchar (mb, MB_LEN_MAX); + + _rl_callback_func = 0; + _rl_want_redisplay = 1; + + return (_rl_vi_change_char (data->count, c, mb)); +} +#endif + +int +rl_vi_change_char (count, key) + int count, key; +{ + int c; + char mb[MB_LEN_MAX]; + + if (vi_redoing) + { + c = _rl_vi_last_replacement; + mb[0] = c; + mb[1] = '\0'; + } +#if defined (READLINE_CALLBACKS) + else if (RL_ISSTATE (RL_STATE_CALLBACK)) + { + _rl_callback_data = _rl_callback_data_alloc (count); + _rl_callback_func = _rl_vi_callback_change_char; + return (0); + } +#endif + else + _rl_vi_last_replacement = c = _rl_vi_callback_getchar (mb, MB_LEN_MAX); + + return (_rl_vi_change_char (count, c, mb)); +} + int rl_vi_subst (count, key) int count, key; { /* If we are redoing, rl_vi_change_to will stuff the last motion char */ if (vi_redoing == 0) - rl_stuff_char ((key == 'S') ? 'c' : ' '); /* `S' == `cc', `s' == `c ' */ + rl_stuff_char ((key == 'S') ? 'c' : 'l'); /* `S' == `cc', `s' == `cl' */ return (rl_vi_change_to (count, 'c')); } @@ -1434,9 +1610,8 @@ rl_vi_possible_completions() #endif /* Functions to save and restore marks. */ -int -rl_vi_set_mark (count, key) - int count, key; +static int +_rl_vi_set_mark () { int ch; @@ -1454,10 +1629,37 @@ rl_vi_set_mark (count, key) return 0; } +#if defined (READLINE_CALLBACKS) +static int +_rl_vi_callback_set_mark (data) + _rl_callback_generic_arg *data; +{ + _rl_callback_func = 0; + _rl_want_redisplay = 1; + + return (_rl_vi_set_mark ()); +} +#endif + int -rl_vi_goto_mark (count, key) +rl_vi_set_mark (count, key) int count, key; { +#if defined (READLINE_CALLBACKS) + if (RL_ISSTATE (RL_STATE_CALLBACK)) + { + _rl_callback_data = 0; + _rl_callback_func = _rl_vi_callback_set_mark; + return (0); + } +#endif + + return (_rl_vi_set_mark ()); +} + +static int +_rl_vi_goto_mark () +{ int ch; RL_SETSTATE(RL_STATE_MOREINPUT); @@ -1485,4 +1687,31 @@ rl_vi_goto_mark (count, key) return 0; } +#if defined (READLINE_CALLBACKS) +static int +_rl_vi_callback_goto_mark (data) + _rl_callback_generic_arg *data; +{ + _rl_callback_func = 0; + _rl_want_redisplay = 1; + + return (_rl_vi_goto_mark ()); +} +#endif + +int +rl_vi_goto_mark (count, key) + int count, key; +{ +#if defined (READLINE_CALLBACKS) + if (RL_ISSTATE (RL_STATE_CALLBACK)) + { + _rl_callback_data = 0; + _rl_callback_func = _rl_vi_callback_goto_mark; + return (0); + } +#endif + + return (_rl_vi_goto_mark ()); +} #endif /* VI_MODE */ |