Update of /cvsroot/mingw/msys/packages/bash/2.05b/lib/readline In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10360/2.05b/lib/readline Added Files: COPYING ChangeLog Makefile.in README STANDALONE ansi_stdlib.h bind.c callback.c chardefs.h compat.c complete.c display.c emacs_keymap.c funmap.c histexpand.c histfile.c histlib.h history.c history.h histsearch.c input.c isearch.c keymaps.c keymaps.h kill.c macro.c mbutil.c misc.c nls.c parens.c posixdir.h posixjmp.h posixstat.h readline.c readline.h rlconf.h rldefs.h rlmbutil.h rlprivate.h rlshell.h rlstdc.h rltty.c rltty.h rltypedefs.h rlwinsize.h savestring.c search.c shell.c signals.c tcap.h terminal.c text.c tilde.c tilde.h undo.c util.c vi_keymap.c vi_mode.c xmalloc.c xmalloc.h Log Message: Pristine source --- NEW FILE: STANDALONE --- This is not to be built as a standalone library to be installed in some public place; get the full readline distribution instead. --- NEW FILE: rldefs.h --- /* rldefs.h -- an attempt to isolate some of the system-specific defines 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. This file contains the Readline Library (the Library), a set of routines for providing Emacs style line input to programs that ask for it. The Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. The Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. The GNU General Public License is often shipped with GNU software, and is generally kept in a file called COPYING or LICENSE. If you do not have a copy of the license, write to the Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #if !defined (_RLDEFS_H_) #define _RLDEFS_H_ #if defined (HAVE_CONFIG_H) # include "config.h" #endif #include "rlstdc.h" #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 # endif #endif /* Posix macro to check file in statbuf for directory-ness. This requires that <sys/stat.h> be included before this test. */ #if defined (S_IFDIR) && !defined (S_ISDIR) # define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) #endif /* Decide which flavor of the header file describing the C library string functions to include and include it. */ #if defined (HAVE_STRING_H) # include <string.h> #else /* !HAVE_STRING_H */ # include <strings.h> #endif /* !HAVE_STRING_H */ #if !defined (strchr) && !defined (__STDC__) extern char *strchr (), *strrchr (); #endif /* !strchr && !__STDC__ */ #if defined (PREFER_STDARG) # include <stdarg.h> #else # if defined (PREFER_VARARGS) # include <varargs.h> # endif #endif #if defined (HAVE_STRCASECMP) #define _rl_stricmp strcasecmp #define _rl_strnicmp strncasecmp #else extern int _rl_stricmp PARAMS((char *, char *)); extern int _rl_strnicmp PARAMS((char *, char *, int)); #endif #if defined (HAVE_STRPBRK) # define _rl_strpbrk(a,b) strpbrk((a),(b)) #else extern char *_rl_strpbrk PARAMS((const char *, const char *)); #endif #if !defined (emacs_mode) # define no_mode -1 # define vi_mode 0 # define emacs_mode 1 #endif #if !defined (RL_IM_INSERT) # define RL_IM_INSERT 1 # define RL_IM_OVERWRITE 0 # # define RL_IM_DEFAULT RL_IM_INSERT #endif /* If you cast map[key].function to type (Keymap) on a Cray, the compiler takes the value of map[key].function and divides it by 4 to convert between pointer types (pointers to functions and pointers to structs are different sizes). This is not what is wanted. */ #if defined (CRAY) # define FUNCTION_TO_KEYMAP(map, key) (Keymap)((int)map[key].function) # define KEYMAP_TO_FUNCTION(data) (rl_command_func_t *)((int)(data)) #else # define FUNCTION_TO_KEYMAP(map, key) (Keymap)(map[key].function) # define KEYMAP_TO_FUNCTION(data) (rl_command_func_t *)(data) #endif #ifndef savestring #define savestring(x) strcpy ((char *)xmalloc (1 + strlen (x)), (x)) #endif /* Possible values for _rl_bell_preference. */ #define NO_BELL 0 #define AUDIBLE_BELL 1 #define VISIBLE_BELL 2 /* Definitions used when searching the line for characters. */ /* NOTE: it is necessary that opposite directions are inverses */ #define FTO 1 /* forward to */ #define BTO -1 /* backward to */ #define FFIND 2 /* forward find */ #define BFIND -2 /* backward find */ /* Possible values for the found_quote flags word used by the completion functions. It says what kind of (shell-like) quoting we found anywhere in the line. */ #define RL_QF_SINGLE_QUOTE 0x01 #define RL_QF_DOUBLE_QUOTE 0x02 #define RL_QF_BACKSLASH 0x04 #define RL_QF_OTHER_QUOTE 0x08 /* Default readline line buffer length. */ #define DEFAULT_BUFFER_SIZE 256 #if !defined (STREQ) #define STREQ(a, b) (((a)[0] == (b)[0]) && (strcmp ((a), (b)) == 0)) #define STREQN(a, b, n) (((n) == 0) ? (1) \ : ((a)[0] == (b)[0]) && (strncmp ((a), (b), (n)) == 0)) #endif #if !defined (FREE) # define FREE(x) if (x) free (x) #endif #if !defined (SWAP) # define SWAP(s, e) do { int t; t = s; s = e; e = t; } while (0) #endif /* CONFIGURATION SECTION */ #include "rlconf.h" #endif /* !_RLDEFS_H_ */ --- NEW FILE: Makefile.in --- ## -*- text -*- ############################################################# # # # Makefile for the Bash versions of the GNU Readline and History Libraries. # # # ############################################################################# # Copyright (C) 1994 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. srcdir = @srcdir@ VPATH = .:@srcdir@ topdir = @top_srcdir@ BUILD_DIR = @BUILD_DIR@ INSTALL = @INSTALL@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_DATA = @INSTALL_DATA@ CC = @CC@ RANLIB = @RANLIB@ AR = @AR@ ARFLAGS = @ARFLAGS@ RM = rm -f CP = cp MV = mv SHELL = @MAKE_SHELL@ # Programs to make tags files. ETAGS = etags -tw CTAGS = ctags -tw CFLAGS = @CFLAGS@ LOCAL_CFLAGS = @LOCAL_CFLAGS@ CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ DEFS = @DEFS@ LOCAL_DEFS = @LOCAL_DEFS@ INCLUDES = -I. -I$(BUILD_DIR) -I$(topdir) -I$(topdir)/lib CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(APP_CFLAGS) $(CPPFLAGS) ${INCLUDES} $(LOCAL_CFLAGS) $(CFLAGS) .c.o: ${RM} $@ $(CC) -c $(CCFLAGS) $< # The name of the main library target. LIBRARY_NAME = libreadline.a # The C code source files for this library. CSOURCES = $(srcdir)/readline.c $(srcdir)/funmap.c $(srcdir)/keymaps.c \ $(srcdir)/vi_mode.c $(srcdir)/parens.c $(srcdir)/rltty.c \ $(srcdir)/complete.c $(srcdir)/bind.c $(srcdir)/isearch.c \ $(srcdir)/display.c $(srcdir)/signals.c $(srcdir)/emacs_keymap.c \ $(srcdir)/vi_keymap.c $(srcdir)/util.c $(srcdir)/kill.c \ $(srcdir)/undo.c $(srcdir)/macro.c $(srcdir)/input.c \ $(srcdir)/callback.c $(srcdir)/terminal.c $(srcdir)/xmalloc.c \ $(srcdir)/history.c $(srcdir)/histsearch.c $(srcdir)/histexpand.c \ $(srcdir)/histfile.c $(srcdir)/nls.c $(srcdir)/search.c \ $(srcdir)/shell.c $(srcdir)/tilde.c $(srcdir)/savestring.c \ $(srcdir)/text.c $(srcdir)/misc.c $(srcdir)/compat.c \ $(srcdir)/mbutil.c # The header files for this library. HSOURCES = readline.h rldefs.h chardefs.h keymaps.h history.h histlib.h \ posixstat.h posixdir.h posixjmp.h tilde.h rlconf.h rltty.h \ ansi_stdlib.h rlstdc.h tcap.h xmalloc.h rlprivate.h rlshell.h \ rltypedefs.h rlmbutil.h HISTOBJ = history.o histexpand.o histfile.o histsearch.o shell.o savestring.o \ mbutil.o TILDEOBJ = tilde.o OBJECTS = readline.o vi_mode.o funmap.o keymaps.o parens.o search.o \ rltty.o complete.o bind.o isearch.o display.o signals.o \ util.o kill.o undo.o macro.o input.o callback.o terminal.o \ text.o nls.o misc.o $(HISTOBJ) $(TILDEOBJ) xmalloc.o compat.o # The texinfo files which document this library. DOCSOURCE = doc/rlman.texinfo doc/rltech.texinfo doc/rluser.texinfo DOCOBJECT = doc/readline.dvi DOCSUPPORT = doc/Makefile DOCUMENTATION = $(DOCSOURCE) $(DOCOBJECT) $(DOCSUPPORT) SUPPORT = Makefile ChangeLog $(DOCSUPPORT) examples/[-a-z.]* SOURCES = $(CSOURCES) $(HSOURCES) $(DOCSOURCE) THINGS_TO_TAR = $(SOURCES) $(SUPPORT) INSTALLED_HEADERS = readline.h chardefs.h keymaps.h history.h tilde.h \ rlstdc.h rlconf.h rltypedefs.h ########################################################################## all: libreadline.a libhistory.a libreadline.a: $(OBJECTS) $(RM) $@ $(AR) $(ARFLAGS) $@ $(OBJECTS) -test -n "$(RANLIB)" && $(RANLIB) $@ libhistory.a: $(HISTOBJ) xmalloc.o $(RM) $@ $(AR) $(ARFLAGS) $@ $(HISTOBJ) xmalloc.o -test -n "$(RANLIB)" && $(RANLIB) $@ documentation: force test -d doc || mkdir doc -( cd doc && $(MAKE) $(MFLAGS) ) # Since tilde.c is shared between readline and bash, make sure we compile # it with the right flags when it's built as part of readline tilde.o: tilde.c rm -f $@ $(CC) $(CCFLAGS) -DREADLINE_LIBRARY -c $(srcdir)/tilde.c force: install: @echo "This version of the readline library should not be installed." uninstall: @echo "This version of the readline library should not be installed." TAGS: force $(ETAGS) $(CSOURCES) $(HSOURCES) tags: force $(CTAGS) $(CSOURCES) $(HSOURCES) clean: force $(RM) $(OBJECTS) *.a -( cd doc && $(MAKE) $(MFLAGS) $@ ) mostlyclean: clean -( cd doc && $(MAKE) $(MFLAGS) $@ ) distclean maintainer-clean: clean -( cd doc && $(MAKE) $(MFLAGS) $@ ) $(RM) Makefile $(RM) TAGS tags # Dependencies bind.o: ansi_stdlib.h posixstat.h bind.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h bind.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h bind.o: history.h rlstdc.h callback.o: rlconf.h ansi_stdlib.h callback.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h callback.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h compat.o: rlstdc.h complete.o: ansi_stdlib.h posixdir.h posixstat.h complete.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h complete.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h display.o: ansi_stdlib.h posixstat.h display.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h display.o: tcap.h display.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h display.o: history.h rlstdc.h funmap.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h funmap.o: rlconf.h ansi_stdlib.h rlstdc.h funmap.o: ${BUILD_DIR}/config.h histexpand.o: ansi_stdlib.h histexpand.o: history.h histlib.h rlstdc.h histexpand.o: ${BUILD_DIR}/config.h histfile.o: ansi_stdlib.h histfile.o: history.h histlib.h rlstdc.h histfile.o: ${BUILD_DIR}/config.h history.o: ansi_stdlib.h history.o: history.h histlib.h rlstdc.h history.o: ${BUILD_DIR}/config.h histsearch.o: ansi_stdlib.h histsearch.o: history.h histlib.h rlstdc.h histsearch.o: ${BUILD_DIR}/config.h input.o: ansi_stdlib.h input.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h input.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h isearch.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h isearch.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h isearch.o: ansi_stdlib.h history.h rlstdc.h keymaps.o: emacs_keymap.c vi_keymap.c keymaps.o: keymaps.h rltypedefs.h chardefs.h rlconf.h ansi_stdlib.h keymaps.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h keymaps.o: ${BUILD_DIR}/config.h rlstdc.h kill.o: ansi_stdlib.h kill.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h kill.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h kill.o: history.h rlstdc.h macro.o: ansi_stdlib.h macro.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h macro.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h macro.o: history.h rlstdc.h mbutil.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h rlmbutil.h mbutil.o: readline.h keymaps.h rltypedefs.h chardefs.h rlstdc.h misc.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h misc.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h misc.o: history.h rlstdc.h ansi_stdlib.h nls.o: ansi_stdlib.h nls.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h nls.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h nls.o: history.h rlstdc.h parens.o: rlconf.h parens.o: ${BUILD_DIR}/config.h parens.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h readline.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h readline.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h readline.o: history.h rlstdc.h readline.o: posixstat.h ansi_stdlib.h posixjmp.h rltty.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h rltty.o: rltty.h rltty.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h search.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h search.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h search.o: ansi_stdlib.h history.h rlstdc.h shell.o: ${BUILD_DIR}/config.h ansi_stdlib.h signals.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h signals.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h signals.o: history.h rlstdc.h terminal.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h terminal.o: tcap.h terminal.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h terminal.o: history.h rlstdc.h text.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h text.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h text.o: history.h rlstdc.h ansi_stdlib.h rltty.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h tilde.o: ansi_stdlib.h tilde.o: ${BUILD_DIR}/config.h tilde.o: tilde.h undo.o: ansi_stdlib.h undo.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h undo.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h undo.o: history.h rlstdc.h xmalloc.h util.o: posixjmp.h ansi_stdlib.h util.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h util.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h vi_mode.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h vi_mode.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h vi_mode.o: history.h ansi_stdlib.h rlstdc.h xmalloc.o: ${BUILD_DIR}/config.h ansi_stdlib.h bind.o: rlshell.h histfile.o: rlshell.h nls.o: rlshell.h readline.o: rlshell.h shell.o: rlshell.h terminal.o: rlshell.h histexpand.o: rlshell.h bind.o: rlprivate.h callback.o: rlprivate.h complete.o: rlprivate.h display.o: rlprivate.h input.o: rlprivate.h isearch.o: rlprivate.h kill.o: rlprivate.h macro.o: rlprivate.h mbutil.o: rlprivate.h misc.o: rlprivate.h nls.o: rlprivate.h parens.o: rlprivate.h readline.o: rlprivate.h rltty.o: rlprivate.h search.o: rlprivate.h signals.o: rlprivate.h terminal.o: rlprivate.h text.o: rlprivate.h undo.o: rlprivate.h util.o: rlprivate.h vi_mode.o: rlprivate.h bind.o: xmalloc.h complete.o: xmalloc.h display.o: xmalloc.h funmap.o: xmalloc.h histexpand.o: xmalloc.h histfile.o: xmalloc.h history.o: xmalloc.h input.o: xmalloc.h isearch.o: xmalloc.h keymaps.o: xmalloc.h kill.o: xmalloc.h macro.o: xmalloc.h mbutil.o: xmalloc.h misc.o: xmalloc.h readline.o: xmalloc.h savestring.o: xmalloc.h search.o: xmalloc.h shell.o: xmalloc.h terminal.o: xmalloc.h text.o: xmalloc.h tilde.o: xmalloc.h undo.o: xmalloc.h util.o: xmalloc.h vi_mode.o: xmalloc.h xmalloc.o: xmalloc.h complete.o: rlmbutil.h display.o: rlmbutil.h histexpand.o: rlmbutil.h input.o: rlmbutil.h isearch.o: rlmbutil.h mbutil.o: rlmbutil.h misc.o: rlmbutil.h readline.o: rlmbutil.h search.o: rlmbutil.h text.o: rlmbutil.h vi_mode.o: rlmbutil.h # Rules for deficient makes, like SunOS and Solaris bind.o: bind.c callback.o: callback.c compat.o: compat.c complete.o: complete.c display.o: display.c funmap.o: funmap.c input.o: input.c isearch.o: isearch.c keymaps.o: keymaps.c emacs_keymap.c vi_keymap.c kill.o: kill.c macro.o: macro.c mbutil.o: mbutil.c misc.o: misc.c nls.o: nls.c parens.o: parens.c readline.o: readline.c rltty.o: rltty.c savestring.o: savestring.c search.o: search.c shell.o: shell.c signals.o: signals.c terminal.o: terminal.c text.o: terminal.c tilde.o: tilde.c undo.o: undo.c util.o: util.c vi_mode.o: vi_mode.c xmalloc.o: xmalloc.c histexpand.o: histexpand.c histfile.o: histfile.c history.o: history.c histsearch.o: histsearch.c --- NEW FILE: rltty.c --- /* rltty.c -- functions to prepare and restore the terminal for readline's use. */ /* Copyright (C) 1992 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. The GNU Readline Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. The GNU Readline Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. The GNU General Public License is often shipped with GNU software, and is generally kept in a file called COPYING or LICENSE. If you do not have a copy of the license, write to the Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #define READLINE_LIBRARY #if defined (HAVE_CONFIG_H) # include <config.h> #endif #include <sys/types.h> #include <signal.h> #include <errno.h> #include <stdio.h> #if defined (HAVE_UNISTD_H) # include <unistd.h> #endif /* HAVE_UNISTD_H */ #include "rldefs.h" #if defined (GWINSZ_IN_SYS_IOCTL) # include <sys/ioctl.h> #endif /* GWINSZ_IN_SYS_IOCTL */ #include "rltty.h" #include "readline.h" #include "rlprivate.h" #if !defined (errno) extern int errno; #endif /* !errno */ rl_vintfunc_t *rl_prep_term_function = rl_prep_terminal; rl_voidfunc_t *rl_deprep_term_function = rl_deprep_terminal; static void block_sigint PARAMS((void)); static void release_sigint PARAMS((void)); static void set_winsize PARAMS((int)); /* **************************************************************** */ /* */ /* Signal Management */ /* */ /* **************************************************************** */ #if defined (HAVE_POSIX_SIGNALS) static sigset_t sigint_set, sigint_oset; #else /* !HAVE_POSIX_SIGNALS */ # if defined (HAVE_BSD_SIGNALS) static int sigint_oldmask; # endif /* HAVE_BSD_SIGNALS */ #endif /* !HAVE_POSIX_SIGNALS */ static int sigint_blocked; /* Cause SIGINT to not be delivered until the corresponding call to release_sigint(). */ static void block_sigint () { if (sigint_blocked) return; #if defined (HAVE_POSIX_SIGNALS) sigemptyset (&sigint_set); sigemptyset (&sigint_oset); sigaddset (&sigint_set, SIGINT); sigprocmask (SIG_BLOCK, &sigint_set, &sigint_oset); #else /* !HAVE_POSIX_SIGNALS */ # if defined (HAVE_BSD_SIGNALS) sigint_oldmask = sigblock (sigmask (SIGINT)); # else /* !HAVE_BSD_SIGNALS */ # if defined (HAVE_USG_SIGHOLD) sighold (SIGINT); # endif /* HAVE_USG_SIGHOLD */ # endif /* !HAVE_BSD_SIGNALS */ #endif /* !HAVE_POSIX_SIGNALS */ sigint_blocked = 1; } /* Allow SIGINT to be delivered. */ static void release_sigint () { if (sigint_blocked == 0) return; #if defined (HAVE_POSIX_SIGNALS) sigprocmask (SIG_SETMASK, &sigint_oset, (sigset_t *)NULL); #else # if defined (HAVE_BSD_SIGNALS) sigsetmask (sigint_oldmask); # else /* !HAVE_BSD_SIGNALS */ # if defined (HAVE_USG_SIGHOLD) sigrelse (SIGINT); # endif /* HAVE_USG_SIGHOLD */ # endif /* !HAVE_BSD_SIGNALS */ #endif /* !HAVE_POSIX_SIGNALS */ sigint_blocked = 0; } /* **************************************************************** */ /* */ /* Saving and Restoring the TTY */ /* */ /* **************************************************************** */ /* Non-zero means that the terminal is in a prepped state. */ static int terminal_prepped; static _RL_TTY_CHARS _rl_tty_chars, _rl_last_tty_chars; /* If non-zero, means that this process has called tcflow(fd, TCOOFF) and output is suspended. */ #if defined (__ksr1__) static int ksrflow; #endif /* Dummy call to force a backgrounded readline to stop before it tries to get the tty settings. */ static void set_winsize (tty) int tty; { #if defined (TIOCGWINSZ) struct winsize w; if (ioctl (tty, TIOCGWINSZ, &w) == 0) (void) ioctl (tty, TIOCSWINSZ, &w); #endif /* TIOCGWINSZ */ } #if defined (NEW_TTY_DRIVER) /* Values for the `flags' field of a struct bsdtty. This tells which elements of the struct bsdtty have been fetched from the system and are valid. */ #define SGTTY_SET 0x01 #define LFLAG_SET 0x02 #define TCHARS_SET 0x04 #define LTCHARS_SET 0x08 struct bsdtty { struct sgttyb sgttyb; /* Basic BSD tty driver information. */ int lflag; /* Local mode flags, like LPASS8. */ #if defined (TIOCGETC) struct tchars tchars; /* Terminal special characters, including ^S and ^Q. */ #endif #if defined (TIOCGLTC) struct ltchars ltchars; /* 4.2 BSD editing characters */ #endif int flags; /* Bitmap saying which parts of the struct are valid. */ }; #define TIOTYPE struct bsdtty static TIOTYPE otio; static void save_tty_chars PARAMS((TIOTYPE *)); static int _get_tty_settings PARAMS((int, TIOTYPE *)); static int get_tty_settings PARAMS((int, TIOTYPE *)); static int _set_tty_settings PARAMS((int, TIOTYPE *)); static int set_tty_settings PARAMS((int, TIOTYPE *)); static void prepare_terminal_settings PARAMS((int, TIOTYPE, TIOTYPE *)); static void save_tty_chars (tiop) TIOTYPE *tiop; { _rl_last_tty_chars = _rl_tty_chars; if (tiop->flags & SGTTY_SET) { _rl_tty_chars.t_erase = tiop->sgttyb.sg_erase; _rl_tty_chars.t_kill = tiop->sgttyb.sg_kill; } if (tiop->flags & TCHARS_SET) { _rl_tty_chars.t_intr = tiop->tchars.t_intrc; _rl_tty_chars.t_quit = tiop->tchars.t_quitc; _rl_tty_chars.t_start = tiop->tchars.t_startc; _rl_tty_chars.t_stop = tiop->tchars.t_stopc; _rl_tty_chars.t_eof = tiop->tchars.t_eofc; _rl_tty_chars.t_eol = '\n'; _rl_tty_chars.t_eol2 = tiop->tchars.t_brkc; } if (tiop->flags & LTCHARS_SET) { _rl_tty_chars.t_susp = tiop->ltchars.t_suspc; _rl_tty_chars.t_dsusp = tiop->ltchars.t_dsuspc; _rl_tty_chars.t_reprint = tiop->ltchars.t_rprntc; _rl_tty_chars.t_flush = tiop->ltchars.t_flushc; _rl_tty_chars.t_werase = tiop->ltchars.t_werasc; _rl_tty_chars.t_lnext = tiop->ltchars.t_lnextc; } _rl_tty_chars.t_status = -1; } static int get_tty_settings (tty, tiop) int tty; TIOTYPE *tiop; { set_winsize (tty); tiop->flags = tiop->lflag = 0; if (ioctl (tty, TIOCGETP, &(tiop->sgttyb)) < 0) return -1; tiop->flags |= SGTTY_SET; #if defined (TIOCLGET) if (ioctl (tty, TIOCLGET, &(tiop->lflag)) == 0) tiop->flags |= LFLAG_SET; #endif #if defined (TIOCGETC) if (ioctl (tty, TIOCGETC, &(tiop->tchars)) == 0) tiop->flags |= TCHARS_SET; #endif #if defined (TIOCGLTC) if (ioctl (tty, TIOCGLTC, &(tiop->ltchars)) == 0) tiop->flags |= LTCHARS_SET; #endif return 0; } static int set_tty_settings (tty, tiop) int tty; TIOTYPE *tiop; { if (tiop->flags & SGTTY_SET) { ioctl (tty, TIOCSETN, &(tiop->sgttyb)); tiop->flags &= ~SGTTY_SET; } readline_echoing_p = 1; #if defined (TIOCLSET) if (tiop->flags & LFLAG_SET) { ioctl (tty, TIOCLSET, &(tiop->lflag)); tiop->flags &= ~LFLAG_SET; } #endif #if defined (TIOCSETC) if (tiop->flags & TCHARS_SET) { ioctl (tty, TIOCSETC, &(tiop->tchars)); tiop->flags &= ~TCHARS_SET; } #endif #if defined (TIOCSLTC) if (tiop->flags & LTCHARS_SET) { ioctl (tty, TIOCSLTC, &(tiop->ltchars)); tiop->flags &= ~LTCHARS_SET; } #endif return 0; } static void prepare_terminal_settings (meta_flag, oldtio, tiop) int meta_flag; TIOTYPE oldtio, *tiop; { readline_echoing_p = (oldtio.sgttyb.sg_flags & ECHO); /* Copy the original settings to the structure we're going to use for our settings. */ tiop->sgttyb = oldtio.sgttyb; tiop->lflag = oldtio.lflag; #if defined (TIOCGETC) tiop->tchars = oldtio.tchars; #endif #if defined (TIOCGLTC) tiop->ltchars = oldtio.ltchars; #endif tiop->flags = oldtio.flags; /* First, the basic settings to put us into character-at-a-time, no-echo input mode. */ tiop->sgttyb.sg_flags &= ~(ECHO | CRMOD); tiop->sgttyb.sg_flags |= CBREAK; /* If this terminal doesn't care how the 8th bit is used, then we can use it for the meta-key. If only one of even or odd parity is specified, then the terminal is using parity, and we cannot. */ #if !defined (ANYP) # define ANYP (EVENP | ODDP) #endif if (((oldtio.sgttyb.sg_flags & ANYP) == ANYP) || ((oldtio.sgttyb.sg_flags & ANYP) == 0)) { tiop->sgttyb.sg_flags |= ANYP; /* Hack on local mode flags if we can. */ #if defined (TIOCLGET) # if defined (LPASS8) tiop->lflag |= LPASS8; # endif /* LPASS8 */ #endif /* TIOCLGET */ } #if defined (TIOCGETC) # if defined (USE_XON_XOFF) /* Get rid of terminal output start and stop characters. */ tiop->tchars.t_stopc = -1; /* C-s */ tiop->tchars.t_startc = -1; /* C-q */ /* If there is an XON character, bind it to restart the output. */ if (oldtio.tchars.t_startc != -1) rl_bind_key (oldtio.tchars.t_startc, rl_restart_output); # endif /* USE_XON_XOFF */ /* If there is an EOF char, bind _rl_eof_char to it. */ if (oldtio.tchars.t_eofc != -1) _rl_eof_char = oldtio.tchars.t_eofc; # if defined (NO_KILL_INTR) /* Get rid of terminal-generated SIGQUIT and SIGINT. */ tiop->tchars.t_quitc = -1; /* C-\ */ tiop->tchars.t_intrc = -1; /* C-c */ # endif /* NO_KILL_INTR */ #endif /* TIOCGETC */ #if defined (TIOCGLTC) /* Make the interrupt keys go away. Just enough to make people happy. */ tiop->ltchars.t_dsuspc = -1; /* C-y */ tiop->ltchars.t_lnextc = -1; /* C-v */ #endif /* TIOCGLTC */ } #else /* !defined (NEW_TTY_DRIVER) */ #if !defined (VMIN) # define VMIN VEOF #endif #if !defined (VTIME) # define VTIME VEOL #endif #if defined (TERMIOS_TTY_DRIVER) # define TIOTYPE struct termios # define DRAIN_OUTPUT(fd) tcdrain (fd) # define GETATTR(tty, tiop) (tcgetattr (tty, tiop)) # ifdef M_UNIX # define SETATTR(tty, tiop) (tcsetattr (tty, TCSANOW, tiop)) # else # define SETATTR(tty, tiop) (tcsetattr (tty, TCSADRAIN, tiop)) # endif /* !M_UNIX */ #else # define TIOTYPE struct termio # define DRAIN_OUTPUT(fd) # define GETATTR(tty, tiop) (ioctl (tty, TCGETA, tiop)) # define SETATTR(tty, tiop) (ioctl (tty, TCSETAW, tiop)) #endif /* !TERMIOS_TTY_DRIVER */ static TIOTYPE otio; static void save_tty_chars PARAMS((TIOTYPE *)); static int _get_tty_settings PARAMS((int, TIOTYPE *)); static int get_tty_settings PARAMS((int, TIOTYPE *)); static int _set_tty_settings PARAMS((int, TIOTYPE *)); static int set_tty_settings PARAMS((int, TIOTYPE *)); static void prepare_terminal_settings PARAMS((int, TIOTYPE, TIOTYPE *)); #if defined (FLUSHO) # define OUTPUT_BEING_FLUSHED(tp) (tp->c_lflag & FLUSHO) #else # define OUTPUT_BEING_FLUSHED(tp) 0 #endif static void save_tty_chars (tiop) TIOTYPE *tiop; { _rl_last_tty_chars = _rl_tty_chars; _rl_tty_chars.t_eof = tiop->c_cc[VEOF]; _rl_tty_chars.t_eol = tiop->c_cc[VEOL]; #ifdef VEOL2 _rl_tty_chars.t_eol2 = tiop->c_cc[VEOL2]; #endif _rl_tty_chars.t_erase = tiop->c_cc[VERASE]; #ifdef VWERASE _rl_tty_chars.t_werase = tiop->c_cc[VWERASE]; #endif _rl_tty_chars.t_kill = tiop->c_cc[VKILL]; #ifdef VREPRINT _rl_tty_chars.t_reprint = tiop->c_cc[VREPRINT]; #endif _rl_tty_chars.t_intr = tiop->c_cc[VINTR]; _rl_tty_chars.t_quit = tiop->c_cc[VQUIT]; #ifdef VSUSP _rl_tty_chars.t_susp = tiop->c_cc[VSUSP]; #endif #ifdef VDSUSP _rl_tty_chars.t_dsusp = tiop->c_cc[VDSUSP]; #endif #ifdef VSTART _rl_tty_chars.t_start = tiop->c_cc[VSTART]; #endif #ifdef VSTOP _rl_tty_chars.t_stop = tiop->c_cc[VSTOP]; #endif #ifdef VLNEXT _rl_tty_chars.t_lnext = tiop->c_cc[VLNEXT]; #endif #ifdef VDISCARD _rl_tty_chars.t_flush = tiop->c_cc[VDISCARD]; #endif #ifdef VSTATUS _rl_tty_chars.t_status = tiop->c_cc[VSTATUS]; #endif } #if defined (_AIX) || defined (_AIX41) /* Currently this is only used on AIX */ static void rltty_warning (msg) char *msg; { fprintf (stderr, "readline: warning: %s\n", msg); } #endif #if defined (_AIX) void setopost(tp) TIOTYPE *tp; { if ((tp->c_oflag & OPOST) == 0) { rltty_warning ("turning on OPOST for terminal\r"); tp->c_oflag |= OPOST|ONLCR; } } #endif static int _get_tty_settings (tty, tiop) int tty; TIOTYPE *tiop; { int ioctl_ret; while (1) { ioctl_ret = GETATTR (tty, tiop); if (ioctl_ret < 0) { if (errno != EINTR) return -1; else continue; } if (OUTPUT_BEING_FLUSHED (tiop)) { #if defined (FLUSHO) && defined (_AIX41) rltty_warning ("turning off output flushing"); tiop->c_lflag &= ~FLUSHO; break; #else continue; #endif } break; } return 0; } static int get_tty_settings (tty, tiop) int tty; TIOTYPE *tiop; { set_winsize (tty); if (_get_tty_settings (tty, tiop) < 0) return -1; #if defined (_AIX) setopost(tiop); #endif return 0; } static int _set_tty_settings (tty, tiop) int tty; TIOTYPE *tiop; { while (SETATTR (tty, tiop) < 0) { if (errno != EINTR) return -1; errno = 0; } return 0; } static int set_tty_settings (tty, tiop) int tty; TIOTYPE *tiop; { if (_set_tty_settings (tty, tiop) < 0) return -1; #if 0 #if defined (TERMIOS_TTY_DRIVER) # if defined (__ksr1__) if (ksrflow) { ksrflow = 0; tcflow (tty, TCOON); } # else /* !ksr1 */ tcflow (tty, TCOON); /* Simulate a ^Q. */ # endif /* !ksr1 */ #else ioctl (tty, TCXONC, 1); /* Simulate a ^Q. */ #endif /* !TERMIOS_TTY_DRIVER */ #endif /* 0 */ return 0; } static void prepare_terminal_settings (meta_flag, oldtio, tiop) int meta_flag; TIOTYPE oldtio, *tiop; { readline_echoing_p = (oldtio.c_lflag & ECHO); tiop->c_lflag &= ~(ICANON | ECHO); if ((unsigned char) oldtio.c_cc[VEOF] != (unsigned char) _POSIX_VDISABLE) _rl_eof_char = oldtio.c_cc[VEOF]; #if defined (USE_XON_XOFF) #if defined (IXANY) tiop->c_iflag &= ~(IXON | IXOFF | IXANY); #else /* `strict' Posix systems do not define IXANY. */ tiop->c_iflag &= ~(IXON | IXOFF); #endif /* IXANY */ #endif /* USE_XON_XOFF */ /* Only turn this off if we are using all 8 bits. */ if (((tiop->c_cflag & CSIZE) == CS8) || meta_flag) tiop->c_iflag &= ~(ISTRIP | INPCK); /* Make sure we differentiate between CR and NL on input. */ tiop->c_iflag &= ~(ICRNL | INLCR); #if !defined (HANDLE_SIGNALS) tiop->c_lflag &= ~ISIG; #else tiop->c_lflag |= ISIG; #endif tiop->c_cc[VMIN] = 1; tiop->c_cc[VTIME] = 0; #if defined (FLUSHO) if (OUTPUT_BEING_FLUSHED (tiop)) { tiop->c_lflag &= ~FLUSHO; oldtio.c_lflag &= ~FLUSHO; } #endif /* Turn off characters that we need on Posix systems with job control, just to be sure. This includes ^Y and ^V. This should not really be necessary. */ #if defined (TERMIOS_TTY_DRIVER) && defined (_POSIX_VDISABLE) #if defined (VLNEXT) tiop->c_cc[VLNEXT] = _POSIX_VDISABLE; #endif #if defined (VDSUSP) tiop->c_cc[VDSUSP] = _POSIX_VDISABLE; #endif #endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */ } #endif /* NEW_TTY_DRIVER */ /* Put the terminal in CBREAK mode so that we can detect key presses. */ void rl_prep_terminal (meta_flag) int meta_flag; { int tty; TIOTYPE tio; if (terminal_prepped) return; /* Try to keep this function from being INTerrupted. */ block_sigint (); tty = fileno (rl_instream); if (get_tty_settings (tty, &tio) < 0) { release_sigint (); return; } otio = tio; save_tty_chars (&otio); prepare_terminal_settings (meta_flag, otio, &tio); if (set_tty_settings (tty, &tio) < 0) { release_sigint (); return; } if (_rl_enable_keypad) _rl_control_keypad (1); fflush (rl_outstream); terminal_prepped = 1; RL_SETSTATE(RL_STATE_TERMPREPPED); release_sigint (); } /* Restore the terminal's normal settings and modes. */ void rl_deprep_terminal () { int tty; if (!terminal_prepped) return; /* Try to keep this function from being interrupted. */ block_sigint (); tty = fileno (rl_instream); if (_rl_enable_keypad) _rl_control_keypad (0); fflush (rl_outstream); if (set_tty_settings (tty, &otio) < 0) { release_sigint (); return; } terminal_prepped = 0; RL_UNSETSTATE(RL_STATE_TERMPREPPED); release_sigint (); } /* **************************************************************** */ /* */ /* Bogus Flow Control */ /* */ /* **************************************************************** */ int rl_restart_output (count, key) int count, key; { int fildes = fileno (rl_outstream); #if defined (TIOCSTART) #if defined (apollo) ioctl (&fildes, TIOCSTART, 0); #else ioctl (fildes, TIOCSTART, 0); #endif /* apollo */ #else /* !TIOCSTART */ # if defined (TERMIOS_TTY_DRIVER) # if defined (__ksr1__) if (ksrflow) { ksrflow = 0; tcflow (fildes, TCOON); } # else /* !ksr1 */ tcflow (fildes, TCOON); /* Simulate a ^Q. */ # endif /* !ksr1 */ # else /* !TERMIOS_TTY_DRIVER */ # if defined (TCXONC) ioctl (fildes, TCXONC, TCOON); # endif /* TCXONC */ # endif /* !TERMIOS_TTY_DRIVER */ #endif /* !TIOCSTART */ return 0; } int rl_stop_output (count, key) int count, key; { int fildes = fileno (rl_instream); #if defined (TIOCSTOP) # if defined (apollo) ioctl (&fildes, TIOCSTOP, 0); # else ioctl (fildes, TIOCSTOP, 0); # endif /* apollo */ #else /* !TIOCSTOP */ # if defined (TERMIOS_TTY_DRIVER) # if defined (__ksr1__) ksrflow = 1; # endif /* ksr1 */ tcflow (fildes, TCOOFF); # else # if defined (TCXONC) ioctl (fildes, TCXONC, TCOON); # endif /* TCXONC */ # endif /* !TERMIOS_TTY_DRIVER */ #endif /* !TIOCSTOP */ return 0; } /* **************************************************************** */ /* */ /* Default Key Bindings */ /* */ /* **************************************************************** */ /* Set the system's default editing characters to their readline equivalents in KMAP. Should be static, now that we have rl_tty_set_default_bindings. */ void rltty_set_default_bindings (kmap) Keymap kmap; { TIOTYPE ttybuff; int tty = fileno (rl_instream); #if defined (NEW_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) if (get_tty_settings (tty, &ttybuff) == 0) { if (ttybuff.flags & SGTTY_SET) { SET_SPECIAL (ttybuff.sgttyb.sg_erase, rl_rubout); SET_SPECIAL (ttybuff.sgttyb.sg_kill, rl_unix_line_discard); } # if defined (TIOCGLTC) if (ttybuff.flags & LTCHARS_SET) { SET_SPECIAL (ttybuff.ltchars.t_werasc, rl_unix_word_rubout); SET_SPECIAL (ttybuff.ltchars.t_lnextc, rl_quoted_insert); } # endif /* TIOCGLTC */ } #else /* !NEW_TTY_DRIVER */ #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) if (get_tty_settings (tty, &ttybuff) == 0) { SET_SPECIAL (VERASE, rl_rubout); SET_SPECIAL (VKILL, rl_unix_line_discard); # if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER) SET_SPECIAL (VLNEXT, rl_quoted_insert); # endif /* VLNEXT && TERMIOS_TTY_DRIVER */ # if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER) SET_SPECIAL (VWERASE, rl_unix_word_rubout); # endif /* VWERASE && TERMIOS_TTY_DRIVER */ } #endif /* !NEW_TTY_DRIVER */ } /* New public way to set the system default editing chars to their readline equivalents. */ void rl_tty_set_default_bindings (kmap) Keymap kmap; { rltty_set_default_bindings (kmap); } #if defined (HANDLE_SIGNALS) #if defined (NEW_TTY_DRIVER) int _rl_disable_tty_signals () { return 0; } int _rl_restore_tty_signals () { return 0; } #else static TIOTYPE sigstty, nosigstty; static int tty_sigs_disabled = 0; int _rl_disable_tty_signals () { if (tty_sigs_disabled) return 0; if (_get_tty_settings (fileno (rl_instream), &sigstty) < 0) return -1; nosigstty = sigstty; nosigstty.c_lflag &= ~ISIG; nosigstty.c_iflag &= ~IXON; if (_set_tty_settings (fileno (rl_instream), &nosigstty) < 0) return (_set_tty_settings (fileno (rl_instream), &sigstty)); tty_sigs_disabled = 1; return 0; } int _rl_restore_tty_signals () { int r; if (tty_sigs_disabled == 0) return 0; r = _set_tty_settings (fileno (rl_instream), &sigstty); if (r == 0) tty_sigs_disabled = 0; return r; } #endif /* !NEW_TTY_DRIVER */ #endif /* HANDLE_SIGNALS */ --- NEW FILE: README --- This is the distribution of the Gnu Readline library. See the file STANDALONE for a description of the #defines that can be passed via the makefile to build readline on different systems. The file rlconf.h contains defines that enable and disable certain readline features. --- NEW FILE: shell.c --- /* shell.c -- readline utility functions that are normally provided by bash when readline is linked as part of the shell. */ /* Copyright (C) 1997 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. The GNU Readline Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. The GNU Readline Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. The GNU General Public License is often shipped with GNU software, and is generally kept in a file called COPYING or LICENSE. If you do not have a copy of the license, write to the Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #define READLINE_LIBRARY #if defined (HAVE_CONFIG_H) # include <config.h> #endif #include <sys/types.h> #if defined (HAVE_UNISTD_H) # include <unistd.h> #endif /* HAVE_UNISTD_H */ #if defined (HAVE_STDLIB_H) # include <stdlib.h> #else # include "ansi_stdlib.h" #endif /* HAVE_STDLIB_H */ #if defined (HAVE_STRING_H) # include <string.h> #else # include <strings.h> #endif /* !HAVE_STRING_H */ #if defined (HAVE_LIMITS_H) # include <limits.h> #endif #include <fcntl.h> #include <pwd.h> #include <stdio.h> #include "rlstdc.h" #include "rlshell.h" #include "xmalloc.h" #if !defined (HAVE_GETPW_DECLS) extern struct passwd *getpwuid PARAMS((uid_t)); #endif /* !HAVE_GETPW_DECLS */ #ifndef NULL # define NULL 0 #endif #ifndef CHAR_BIT # define CHAR_BIT 8 #endif /* Nonzero if the integer type T is signed. */ #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) /* Bound on length of the string representing an integer value of type T. Subtract one for the sign bit if T is signed; 302 / 1000 is log10 (2) rounded up; add one for integer division truncation; add one more for a minus sign if t is signed. */ #define INT_STRLEN_BOUND(t) \ ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 1000 \ + 1 + TYPE_SIGNED (t)) /* All of these functions are resolved from bash if we are linking readline as part of bash. */ /* Does shell-like quoting using single quotes. */ char * sh_single_quote (string) char *string; { register int c; char *result, *r, *s; result = (char *)xmalloc (3 + (4 * strlen (string))); r = result; *r++ = '\''; for (s = string; s && (c = *s); s++) { *r++ = c; if (c == '\'') { *r++ = '\\'; /* insert escaped single quote */ *r++ = '\''; *r++ = '\''; /* start new quoted string */ } } *r++ = '\''; *r = '\0'; return (result); } /* Set the environment variables LINES and COLUMNS to lines and cols, respectively. */ void sh_set_lines_and_columns (lines, cols) int lines, cols; { char *b; #if defined (HAVE_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) b = (char *)xmalloc (INT_STRLEN_BOUND (int) + 1); sprintf (b, "%d", lines); setenv ("LINES", b, 1); b = (char *)xmalloc (INT_STRLEN_BOUND (int) + 1); sprintf (b, "%d", cols); setenv ("COLUMNS", b, 1); # endif /* HAVE_SETENV */ #endif /* !HAVE_PUTENV */ } char * sh_get_env_value (varname) const char *varname; { return ((char *)getenv (varname)); } char * sh_get_home_dir () { char *home_dir; struct passwd *entry; home_dir = (char *)NULL; entry = getpwuid (getuid ()); if (entry) home_dir = entry->pw_dir; return (home_dir); } #if !defined (O_NDELAY) # if defined (FNDELAY) # define O_NDELAY FNDELAY # endif #endif int sh_unset_nodelay_mode (fd) int fd; { int flags, bflags; if ((flags = fcntl (fd, F_GETFL, 0)) < 0) return -1; bflags = 0; #ifdef O_NONBLOCK bflags |= O_NONBLOCK; #endif #ifdef O_NDELAY bflags |= O_NDELAY; #endif if (flags & bflags) { flags &= ~bflags; return (fcntl (fd, F_SETFL, flags)); } return 0; } --- NEW FILE: util.c --- /* util.c -- readline utility functions */ /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. The GNU Readline Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. The GNU Readline Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. The GNU General Public License is often shipped with GNU software, and is generally kept in a file called COPYING or LICENSE. If you do not have a copy of the license, write to the Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #define READLINE_LIBRARY #if defined (HAVE_CONFIG_H) # include <config.h> #endif #include <sys/types.h> #include <fcntl.h> #include "posixjmp.h" #if defined (HAVE_UNISTD_H) # include <unistd.h> /* for _POSIX_VERSION */ #endif /* HAVE_UNISTD_H */ #if defined (HAVE_STDLIB_H) # include <stdlib.h> #else # include "ansi_stdlib.h" #endif /* HAVE_STDLIB_H */ #include <stdio.h> #include <ctype.h> /* System-specific feature definitions and include files. */ #include "rldefs.h" #if defined (TIOCSTAT_IN_SYS_IOCTL) # include <sys/ioctl.h> #endif /* TIOCSTAT_IN_SYS_IOCTL */ /* Some standard library routines. */ #include "readline.h" #include "rlprivate.h" #include "xmalloc.h" /* **************************************************************** */ /* */ /* Utility Functions */ /* */ /* **************************************************************** */ /* Return 0 if C is not a member of the class of characters that belong in words, or 1 if it is. */ int _rl_allow_pathname_alphabetic_chars = 0; static const char *pathname_alphabetic_chars = "/-_=~.#$"; int rl_alphabetic (c) int c; { if (ALPHABETIC (c)) return (1); return (_rl_allow_pathname_alphabetic_chars && strchr (pathname_alphabetic_chars, c) != NULL); } /* How to abort things. */ int _rl_abort_internal () { rl_ding (); rl_clear_message (); _rl_init_argument (); rl_clear_pending_input (); RL_UNSETSTATE (RL_STATE_MACRODEF); while (rl_executing_macro) _rl_pop_executing_macro (); rl_last_func = (rl_command_func_t *)NULL; longjmp (readline_top_level, 1); return (0); } int rl_abort (count, key) int count, key; { return (_rl_abort_internal ()); } int rl_tty_status (count, key) int count, key; { #if defined (TIOCSTAT) ioctl (1, TIOCSTAT, (char *)0); rl_refresh_line (count, key); #else rl_ding (); #endif return 0; } /* Return a copy of the string between FROM and TO. FROM is inclusive, TO is not. */ char * rl_copy_text (from, to) int from, to; { register int length; char *copy; /* Fix it if the caller is confused. */ if (from > to) SWAP (from, to); length = to - from; copy = (char *)xmalloc (1 + length); strncpy (copy, rl_line_buffer + from, length); copy[length] = '\0'; return (copy); } /* Increase the size of RL_LINE_BUFFER until it has enough space to hold LEN characters. */ void rl_extend_line_buffer (len) int len; { while (len >= rl_line_buffer_len) { rl_line_buffer_len += DEFAULT_BUFFER_SIZE; rl_line_buffer = (char *)xrealloc (rl_line_buffer, rl_line_buffer_len); } _rl_set_the_line (); } /* A function for simple tilde expansion. */ int rl_tilde_expand (ignore, key) int ignore, key; { register int start, end; char *homedir, *temp; int len; end = rl_point; start = end - 1; if (rl_point == rl_end && rl_line_buffer[rl_point] == '~') { homedir = tilde_expand ("~"); _rl_replace_text (homedir, start, end); return (0); } else if (rl_line_buffer[start] != '~') { for (; !whitespace (rl_line_buffer[start]) && start >= 0; start--) ; start++; } end = start; do end++; while (whitespace (rl_line_buffer[end]) == 0 && end < rl_end); if (whitespace (rl_line_buffer[end]) || end >= rl_end) end--; /* If the first character of the current word is a tilde, perform tilde expansion and insert the result. If not a tilde, do nothing. */ if (rl_line_buffer[start] == '~') { len = end - start + 1; temp = (char *)xmalloc (len + 1); strncpy (temp, rl_line_buffer + start, len); temp[len] = '\0'; homedir = tilde_expand (temp); free (temp); _rl_replace_text (homedir, start, end); } return (0); } /* **************************************************************** */ /* */ /* String Utility Functions */ /* */ /* **************************************************************** */ /* Determine if s2 occurs in s1. If so, return a pointer to the match in s1. The compare is case insensitive. */ char * _rl_strindex (s1, s2) register const char *s1, *s2; { register int i, l, len; for (i = 0, l = strlen (s2), len = strlen (s1); (len - i) >= l; i++) if (_rl_strnicmp (s1 + i, s2, l) == 0) return ((char *) (s1 + i)); return ((char *)NULL); } #ifndef HAVE_STRPBRK /* Find the first occurrence in STRING1 of any character from STRING2. Return a pointer to the character in STRING1. */ char * _rl_strpbrk (string1, string2) const char *string1, *string2; { register const char *scan; #if defined (HANDLE_MULTIBYTE) mbstate_t ps; register int i, v; memset (&ps, 0, sizeof (mbstate_t)); #endif for (; *string1; string1++) { for (scan = string2; *scan; scan++) { if (*string1 == *scan) return ((char *)string1); } #if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) { v = _rl_get_char_len (string1, &ps); if (v > 1) string += v - 1; /* -1 to account for auto-increment in loop */ } #endif } return ((char *)NULL); } #endif #if !defined (HAVE_STRCASECMP) /* Compare at most COUNT characters from string1 to string2. Case doesn't matter. */ int _rl_strnicmp (string1, string2, count) char *string1, *string2; int count; { register char ch1, ch2; while (count) { ch1 = *string1++; ch2 = *string2++; if (_rl_to_upper(ch1) == _rl_to_upper(ch2)) count--; else break; } return (count); } /* strcmp (), but caseless. */ int _rl_stricmp (string1, string2) char *string1, *string2; { register char ch1, ch2; while (*string1 && *string2) { ch1 = *string1++; ch2 = *string2++; if (_rl_to_upper(ch1) != _rl_to_upper(ch2)) return (1); } return (*string1 - *string2); } #endif /* !HAVE_STRCASECMP */ /* Stupid comparison routine for qsort () ing strings. */ int _rl_qsort_string_compare (s1, s2) char **s1, **s2; { #if defined (HAVE_STRCOLL) return (strcoll (*s1, *s2)); #else int result; result = **s1 - **s2; if (result == 0) result = strcmp (*s1, *s2); return result; #endif } /* Function equivalents for the macros defined in chardefs.h. */ #define FUNCTION_FOR_MACRO(f) int (f) (c) int c; { return f (c); } FUNCTION_FOR_MACRO (_rl_digit_p) FUNCTION_FOR_MACRO (_rl_digit_value) FUNCTION_FOR_MACRO (_rl_lowercase_p) FUNCTION_FOR_MACRO (_rl_pure_alphabetic) FUNCTION_FOR_MACRO (_rl_to_lower) FUNCTION_FOR_MACRO (_rl_to_upper) FUNCTION_FOR_MACRO (_rl_uppercase_p) /* Backwards compatibility, now that savestring has been removed from all `public' readline header files. */ #undef _rl_savestring char * _rl_savestring (s) const char *s; { return (strcpy ((char *)xmalloc (1 + (int)strlen (s)), (s))); } --- NEW FILE: histsearch.c --- /* histsearch.c -- searching the history list. */ /* Copyright (C) 1989, 1992 Free Software Foundation, Inc. This file contains the GNU History Library (the Library), a set of routines for managing the text of previously typed lines. The Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. The Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. The GNU General Public License is often shipped with GNU software, and is generally kept in a file called COPYING or LICENSE. If you do not have a copy of the license, write to the Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #define READLINE_LIBRARY #if defined (HAVE_CONFIG_H) # include <config.h> #endif #include <stdio.h> #if defined (HAVE_STDLIB_H) # include <stdlib.h> #else # include "ansi_stdlib.h" #endif /* HAVE_STDLIB_H */ #if defined (HAVE_UNISTD_H) # ifdef _MINIX # include <sys/types.h> # endif # include <unistd.h> #endif #include "history.h" #include "histlib.h" /* The list of alternate characters that can delimit a history search string. */ char *history_search_delimiter_chars = (char *)NULL; static int history_search_internal PARAMS((const char *, int, int)); /* Search the history for STRING, starting at history_offset. If DIRECTION < 0, then the search is through previous entries, else through subsequent. If ANCHORED is non-zero, the string must appear at the beginning of a history line, otherwise, the string may appear anywhere in the line. If the string is found, then current_history () is the history entry, and the value of this function is the offset in the line of that history entry that the string was found in. Otherwise, nothing is changed, and a -1 is returned. */ static int history_search_internal (string, direction, anchored) const char *string; int direction, anchored; { register int i, reverse; register char *line; register int line_index; int string_len; HIST_ENTRY **the_history; /* local */ i = history_offset; reverse = (direction < 0); /* Take care of trivial cases first. */ if (string == 0 || *string == '\0') return (-1); if (!history_length || ((i == history_length) && !reverse)) return (-1); if (reverse && (i == history_length)) i--; #define NEXT_LINE() do { if (reverse) i--; else i++; } while (0) the_history = history_list (); string_len = strlen (string); while (1) { /* Search each line in the history list for STRING. */ /* At limit for direction? */ if ((reverse && i < 0) || (!reverse && i == history_length)) return (-1); line = the_history[i]->line; line_index = strlen (line); /* If STRING is longer than line, no match. */ if (string_len > line_index) { NEXT_LINE (); continue; } /* Handle anchored searches first. */ if (anchored == ANCHORED_SEARCH) { if (STREQN (string, line, string_len)) { history_offset = i; return (0); } NEXT_LINE (); continue; } /* Do substring search. */ if (reverse) { line_index -= string_len; while (line_index >= 0) { if (STREQN (string, line + line_index, string_len)) { history_offset = i; return (line_index); } line_index--; } } else { register int limit; limit = line_index - string_len + 1; line_index = 0; while (line_index < limit) { if (STREQN (string, line + line_index, string_len)) { history_offset = i; return (line_index); } line_index++; } } NEXT_LINE (); } } /* Do a non-anchored search for STRING through the history in DIRECTION. */ int history_search (string, direction) const char *string; int direction; { return (history_search_internal (string, direction, NON_ANCHORED_SEARCH)); } /* Do an anchored search for string through the history in DIRECTION. */ int history_search_prefix (string, direction) const char *string; int direction; { return (history_search_internal (string, direction, ANCHORED_SEARCH)); } /* Search for STRING in the history list. DIR is < 0 for searching backwards. POS is an absolute index into the history list at which point to begin searching. */ int history_search_pos (string, dir, pos) const char *string; int dir, pos; { int ret, old; old = where_history (); history_set_pos (pos); if (history_search (string, dir) == -1) { history_set_pos (old); return (-1); } ret = where_history (); history_set_pos (old); return ret; } --- NEW FILE: COPYING --- GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contain... [truncated message content] |