summaryrefslogtreecommitdiffstats
path: root/gnu
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1994-05-13 15:48:04 +0000
committerache <ache@FreeBSD.org>1994-05-13 15:48:04 +0000
commitb772d1e49f137fdb0f34072572aa6ccdf24f61a2 (patch)
treeb88d5c25249bf0f2b44192dc7b0e94c38d6f30ac /gnu
parent073116681cf05d0a7198d2ffc0a174a005275d5c (diff)
downloadFreeBSD-src-b772d1e49f137fdb0f34072572aa6ccdf24f61a2.zip
FreeBSD-src-b772d1e49f137fdb0f34072572aa6ccdf24f61a2.tar.gz
Upgrade to readline 2.0 from bash1.14.1
Diffstat (limited to 'gnu')
-rw-r--r--gnu/lib/libreadline/Makefile7
-rw-r--r--gnu/lib/libreadline/README6
-rw-r--r--gnu/lib/libreadline/README.FreeBSD4
-rw-r--r--gnu/lib/libreadline/STANDALONE32
-rw-r--r--gnu/lib/libreadline/ansi_stdlib.h41
-rw-r--r--gnu/lib/libreadline/bind.c153
-rw-r--r--gnu/lib/libreadline/complete.c323
-rw-r--r--gnu/lib/libreadline/display.c299
-rw-r--r--gnu/lib/libreadline/doc/hsuser.texinfo76
-rw-r--r--gnu/lib/libreadline/doc/rluser.texinfo523
-rw-r--r--gnu/lib/libreadline/doc/texindex.c902
-rw-r--r--gnu/lib/libreadline/emacs_keymap.c8
-rw-r--r--gnu/lib/libreadline/funmap.c12
-rw-r--r--gnu/lib/libreadline/history.c1516
-rw-r--r--gnu/lib/libreadline/isearch.c321
-rw-r--r--gnu/lib/libreadline/keymaps.c6
-rw-r--r--gnu/lib/libreadline/memalloc.h56
-rw-r--r--gnu/lib/libreadline/parens.c7
-rw-r--r--gnu/lib/libreadline/readline.c644
-rw-r--r--gnu/lib/libreadline/readline/chardefs.h18
-rw-r--r--gnu/lib/libreadline/readline/history.h14
-rw-r--r--gnu/lib/libreadline/readline/keymaps.h14
-rw-r--r--gnu/lib/libreadline/readline/readline.h97
-rw-r--r--gnu/lib/libreadline/readline/tilde.h38
-rw-r--r--gnu/lib/libreadline/rlconf.h57
-rw-r--r--gnu/lib/libreadline/rldefs.h44
-rw-r--r--gnu/lib/libreadline/rltty.c44
-rw-r--r--gnu/lib/libreadline/search.c109
-rw-r--r--gnu/lib/libreadline/signals.c19
-rw-r--r--gnu/lib/libreadline/tcsh_hack.readme8
-rw-r--r--gnu/lib/libreadline/tilde.c48
-rw-r--r--gnu/lib/libreadline/vi_keymap.c10
-rw-r--r--gnu/lib/libreadline/vi_mode.c144
33 files changed, 3544 insertions, 2056 deletions
diff --git a/gnu/lib/libreadline/Makefile b/gnu/lib/libreadline/Makefile
index 6271df5..7193879 100644
--- a/gnu/lib/libreadline/Makefile
+++ b/gnu/lib/libreadline/Makefile
@@ -1,17 +1,18 @@
-# $Id: Makefile,v 1.6 1994/05/11 15:49:41 ache Exp $
+# $Id: Makefile,v 1.7 1994/05/11 16:30:27 ache Exp $
SHLIB_MAJOR=1
SHLIB_MINOR=0
CFLAGS+= -I${.CURDIR} -I${.CURDIR}/readline -DVOID_SIGHANDLER \
-DHAVE_UNISTD_H -DHAVE_STRING_H -DHAVE_STDLIB_H -DHAVE_VARARGS_H \
- -DVISIBLE_STATS -DVI_MODE -DPAREN_MATCHING \
+ -DFreeBSD \
-Dstricmp=strcasecmp -Dstrnicmp=strncasecmp
LIB= readline
SRCS+= readline.c funmap.c keymaps.c vi_mode.c parens.c \
rltty.c complete.c bind.c isearch.c display.c signals.c \
history.c search.c tilde.c xmalloc.c
+HEADERS= history.h readline.h keymaps.h chardefs.h tilde.h
NOMAN= noman
beforeinstall:
@@ -22,6 +23,6 @@ beforeinstall:
fi
cd ${.CURDIR}/readline; \
install -c -o ${BINOWN} -g ${BINGRP} -m 444 \
- history.h readline.h keymaps.h chardefs.h ${DESTDIR}/usr/include/readline
+ ${HEADERS} ${DESTDIR}/usr/include/readline
.include <bsd.lib.mk>
diff --git a/gnu/lib/libreadline/README b/gnu/lib/libreadline/README
new file mode 100644
index 0000000..131471c
--- /dev/null
+++ b/gnu/lib/libreadline/README
@@ -0,0 +1,6 @@
+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.
diff --git a/gnu/lib/libreadline/README.FreeBSD b/gnu/lib/libreadline/README.FreeBSD
index bd6f23e..9e1829c 100644
--- a/gnu/lib/libreadline/README.FreeBSD
+++ b/gnu/lib/libreadline/README.FreeBSD
@@ -11,11 +11,9 @@ Workaround for this implemented via TIOCGWINSZ/TIOCSWINSZ
with same winsize structure: it does nothing expect polling
process from background. Look tcsh_hack.readme for details.
-Here is megred version with readline comes from gdb4.11
-and with readline 2.0 comes from bash1.13.1.CWRU
-
If you want 8-bit clean version, put
set convert-meta off
+ set output-meta on
in your ~/.inputrc file
ache@astral.msk.su
diff --git a/gnu/lib/libreadline/STANDALONE b/gnu/lib/libreadline/STANDALONE
new file mode 100644
index 0000000..17d5fb7
--- /dev/null
+++ b/gnu/lib/libreadline/STANDALONE
@@ -0,0 +1,32 @@
+This is a description of C preprocessor defines that readline accepts.
+Most are passed in from the parent `make'; e.g. from the bash source
+directory.
+
+NO_SYS_FILE <sys/file.h> is not present
+HAVE_UNISTD_H <unistd.h> exists
+HAVE_STDLIB_H <stdlib.h> exists
+HAVE_GETPW_DECLS declarations for the getpw functions are in <pwd.h>
+HAVE_VARARGS_H <varargs.h> exists and is usable
+HAVE_STRING_H <string.h> exists
+HAVE_ALLOCA_H <alloca.h> exists and is needed for alloca()
+HAVE_ALLOCA alloca(3) or a define for it exists
+PRAGMA_ALLOCA use of alloca() requires a #pragma, as in AIX 3.x
+VOID_SIGHANDLER signal handlers are void functions
+HAVE_DIRENT_H <dirent.h> exists and is usable
+HAVE_SYS_PTEM_H <sys/ptem.h> exists
+HAVE_SYS_PTE_H <sys/pte.h> exists
+HAVE_SYS_STREAM_H <sys/stream.h> exists
+
+System-specific options:
+
+OSF1 A machine running OSF/1
+BSD386 BSDI's BSD/386 version 1.0 or 1.1
+NetBSD NetBSD
+FreeBSD FreeBSD version 1.1
+_386BSD Old FreeBSD or NetBSD or ancient Jolitz 386bsd
+AIX AIX 3.x
+USG Running a variant of System V
+USGr3 Running System V.3
+XENIX_22 Xenix 2.2
+Linux Linux
+CRAY running a recent version of Cray UNICOS
diff --git a/gnu/lib/libreadline/ansi_stdlib.h b/gnu/lib/libreadline/ansi_stdlib.h
new file mode 100644
index 0000000..52339da
--- /dev/null
+++ b/gnu/lib/libreadline/ansi_stdlib.h
@@ -0,0 +1,41 @@
+/* ansi_stdlib.h -- An ANSI Standard stdlib.h. */
+/* A minimal stdlib.h containing extern declarations for those functions
+ that bash uses. */
+
+/* Copyright (C) 1993 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#if !defined (_STDLIB_H_)
+#define _STDLIB_H_ 1
+
+/* String conversion functions. */
+extern int atoi ();
+extern long int atol ();
+
+/* Memory allocation functions. */
+extern char *malloc ();
+extern char *realloc ();
+extern void free ();
+
+/* Other miscellaneous functions. */
+extern void abort ();
+extern void exit ();
+extern char *getenv ();
+extern void qsort ();
+
+#endif /* _STDLIB_H */
diff --git a/gnu/lib/libreadline/bind.c b/gnu/lib/libreadline/bind.c
index ee54398..16dbdba 100644
--- a/gnu/lib/libreadline/bind.c
+++ b/gnu/lib/libreadline/bind.c
@@ -57,19 +57,22 @@ extern int errno;
extern char *strchr (), *strrchr ();
#endif /* !strchr && !__STDC__ */
-extern char *tilde_expand ();
-
extern int _rl_horizontal_scroll_mode;
extern int _rl_mark_modified_lines;
-extern int _rl_prefer_visible_bell;
+extern int _rl_bell_preference;
extern int _rl_meta_flag;
extern int rl_blink_matching_paren;
extern int _rl_convert_meta_chars_to_ascii;
+extern int _rl_output_meta_chars;
+extern int _rl_complete_show_all;
#if defined (VISIBLE_STATS)
extern int rl_visible_stats;
#endif /* VISIBLE_STATS */
extern int rl_complete_with_tilde_expansion;
extern int rl_completion_query_items;
+#if defined (VI_MODE)
+extern char *rl_vi_comment_begin;
+#endif
extern int rl_explicit_arg;
extern int rl_editing_mode;
@@ -80,6 +83,9 @@ extern char *possible_control_prefixes[], *possible_meta_prefixes[];
extern char **rl_funmap_names ();
+/* Forward declarations */
+void rl_set_keymap_from_edit_mode ();
+
static int glean_key_from_name ();
#if defined (STATIC_MALLOC)
@@ -105,6 +111,7 @@ rl_add_defun (name, function, key)
if (key != -1)
rl_bind_key (key, function);
rl_add_funmap_entry (name, function);
+ return 0;
}
/* Bind KEY to FUNCTION. Returns non-zero if KEY is out of range. */
@@ -120,12 +127,9 @@ rl_bind_key (key, function)
{
if (_rl_keymap[ESC].type == ISKMAP)
{
-#if defined (CRAY)
- Keymap escmap = (Keymap)((int)_rl_keymap[ESC].function);
-#else
- Keymap escmap = (Keymap)_rl_keymap[ESC].function;
-#endif
+ Keymap escmap;
+ escmap = FUNCTION_TO_KEYMAP (_rl_keymap, ESC);
key = UNMETA (key);
escmap[key].type = ISFUNC;
escmap[key].function = function;
@@ -183,7 +187,7 @@ rl_set_key (keyseq, function, map)
Function *function;
Keymap map;
{
- rl_generic_bind (ISFUNC, keyseq, function, map);
+ return (rl_generic_bind (ISFUNC, keyseq, function, map));
}
/* Bind the key sequence represented by the string KEYSEQ to
@@ -249,7 +253,7 @@ rl_generic_bind (type, keyseq, data, map)
{
ic = UNMETA (ic);
if (map[ESC].type == ISKMAP)
- map = (Keymap) map[ESC].function;
+ map = FUNCTION_TO_KEYMAP (map, ESC);
}
if ((i + 1) < keys_len)
@@ -260,16 +264,16 @@ rl_generic_bind (type, keyseq, data, map)
free ((char *)map[ic].function);
map[ic].type = ISKMAP;
- map[ic].function = (Function *)rl_make_bare_keymap ();
+ map[ic].function = KEYMAP_TO_FUNCTION (rl_make_bare_keymap());
}
- map = (Keymap)map[ic].function;
+ map = FUNCTION_TO_KEYMAP (map, ic);
}
else
{
if (map[ic].type == ISMACR)
free ((char *)map[ic].function);
- map[ic].function = (Function *)data;
+ map[ic].function = KEYMAP_TO_FUNCTION (data);
map[ic].type = type;
}
}
@@ -388,7 +392,7 @@ rl_function_of_keyseq (keyseq, map, type)
}
else
{
- map = (Keymap)map[ESC].function;
+ map = FUNCTION_TO_KEYMAP (map, ESC);
ic = UNMETA (ic);
}
}
@@ -405,7 +409,7 @@ rl_function_of_keyseq (keyseq, map, type)
return (map[ic].function);
}
else
- map = (Keymap)map[ic].function;
+ map = FUNCTION_TO_KEYMAP (map, ic);
}
else
{
@@ -415,6 +419,7 @@ rl_function_of_keyseq (keyseq, map, type)
return (map[ic].function);
}
}
+ return ((Function *) NULL);
}
/* The last key bindings file read. */
@@ -424,15 +429,19 @@ static char *last_readline_init_file = (char *)NULL;
rl_re_read_init_file (count, ignore)
int count, ignore;
{
- return (rl_read_init_file ((char *)NULL));
+ int r;
+ r = rl_read_init_file ((char *)NULL);
+ rl_set_keymap_from_edit_mode ();
+ return r;
}
-/* The final, last-ditch effort file name for an init file. */
-#define DEFAULT_INPUTRC "~/.inputrc"
-
/* Do key bindings from a file. If FILENAME is NULL it defaults
- to `~/.inputrc'. If the file existed and could be opened and
- read, 0 is returned, otherwise errno is returned. */
+ to the first non-null filename from this list:
+ 1. the filename used for the previous call
+ 2. the value of the shell variable `INPUTRC'
+ 3. ~/.inputrc
+ If the file existed and could be opened and read, 0 is returned,
+ otherwise errno is returned. */
int
rl_read_init_file (filename)
char *filename;
@@ -445,9 +454,10 @@ rl_read_init_file (filename)
/* Default the filename. */
if (!filename)
{
- if (last_readline_init_file)
- filename = last_readline_init_file;
- else
+ filename = last_readline_init_file;
+ if (!filename)
+ filename = getenv ("INPUTRC");
+ if (!filename)
filename = DEFAULT_INPUTRC;
}
@@ -462,10 +472,13 @@ rl_read_init_file (filename)
else
free (openname);
- if (last_readline_init_file)
- free (last_readline_init_file);
+ if (filename != last_readline_init_file)
+ {
+ if (last_readline_init_file)
+ free (last_readline_init_file);
- last_readline_init_file = savestring (filename);
+ last_readline_init_file = savestring (filename);
+ }
/* Read the file into BUFFER. */
buffer = (char *)xmalloc ((int)finfo.st_size + 1);
@@ -487,6 +500,10 @@ rl_read_init_file (filename)
/* Mark end of line. */
line[i] = '\0';
+ /* Skip leading whitespace. */
+ while (*line && whitespace (*line))
+ line++;
+
/* If the line is not a comment, then parse it. */
if (*line && *line != '#')
rl_parse_and_bind (line);
@@ -552,7 +569,7 @@ parser_if (args)
/* Terminals like "aaa-60" are equivalent to "aaa". */
tname = savestring (rl_terminal_name);
- tem = strrchr (tname, '-');
+ tem = strchr (tname, '-');
if (tem)
*tem = '\0';
@@ -682,9 +699,6 @@ handle_parser_directive (statement)
return (1);
}
-/* Ugly but working hack for binding prefix meta. */
-#define PREFIX_META_HACK
-
static int substring_member_of_array ();
/* Read the binding command from STRING and perform it.
@@ -928,10 +942,11 @@ static struct {
} boolean_varlist [] = {
{ "horizontal-scroll-mode", &_rl_horizontal_scroll_mode },
{ "mark-modified-lines", &_rl_mark_modified_lines },
- { "prefer-visible-bell", &_rl_prefer_visible_bell },
{ "meta-flag", &_rl_meta_flag },
{ "blink-matching-paren", &rl_blink_matching_paren },
{ "convert-meta", &_rl_convert_meta_chars_to_ascii },
+ { "show-all-if-ambiguous", &_rl_complete_show_all },
+ { "output-meta", &_rl_output_meta_chars },
#if defined (VISIBLE_STATS)
{ "visible-stats", &rl_visible_stats },
#endif /* VISIBLE_STATS */
@@ -970,10 +985,6 @@ rl_variable_bind (name, value)
#if defined (VI_MODE)
_rl_keymap = vi_insertion_keymap;
rl_editing_mode = vi_mode;
-#else
-#if defined (NOTDEF)
- ding ();
-#endif /* NOTDEF */
#endif /* VI_MODE */
}
else if (strnicmp (value, "emacs", 5) == 0)
@@ -987,8 +998,6 @@ rl_variable_bind (name, value)
else if (stricmp (name, "comment-begin") == 0)
{
#if defined (VI_MODE)
- extern char *rl_vi_comment_begin;
-
if (*value)
{
if (rl_vi_comment_begin)
@@ -1009,6 +1018,37 @@ rl_variable_bind (name, value)
}
rl_completion_query_items = nval;
}
+ else if (stricmp (name, "keymap") == 0)
+ {
+ Keymap kmap;
+ kmap = rl_get_keymap_by_name (value);
+ if (kmap)
+ rl_set_keymap (kmap);
+ }
+ else if (stricmp (name, "bell-style") == 0)
+ {
+ if (!*value)
+ _rl_bell_preference = AUDIBLE_BELL;
+ else
+ {
+ if (stricmp (value, "none") == 0 || stricmp (value, "off") == 0)
+ _rl_bell_preference = NO_BELL;
+ else if (stricmp (value, "audible") == 0 || stricmp (value, "on") == 0)
+ _rl_bell_preference = AUDIBLE_BELL;
+ else if (stricmp (value, "visible") == 0)
+ _rl_bell_preference = VISIBLE_BELL;
+ }
+ }
+ else if (stricmp (name, "prefer-visible-bell") == 0)
+ {
+ /* Backwards compatibility. */
+ if (*value && (stricmp (value, "on") == 0 ||
+ (*value == '1' && !value[1])))
+ _rl_bell_preference = VISIBLE_BELL;
+ else
+ _rl_bell_preference = AUDIBLE_BELL;
+ }
+
return 0;
}
@@ -1135,8 +1175,8 @@ rl_list_funmap_names (ignore)
/* Return a NULL terminated array of strings which represent the key
sequences that are used to invoke FUNCTION in MAP. */
-static char **
-invoking_keyseqs_in_map (function, map)
+char **
+rl_invoking_keyseqs_in_map (function, map)
Function *function;
Keymap map;
{
@@ -1194,11 +1234,7 @@ invoking_keyseqs_in_map (function, map)
their target. Add the key sequences found to RESULT. */
if (map[key].function)
seqs =
-#if defined (CRAY)
- invoking_keyseqs_in_map (function, (Keymap)((int)map[key].function));
-#else
- invoking_keyseqs_in_map (function, (Keymap)map[key].function);
-#endif
+ rl_invoking_keyseqs_in_map (function, FUNCTION_TO_KEYMAP (map, key));
if (seqs)
{
@@ -1252,18 +1288,16 @@ char **
rl_invoking_keyseqs (function)
Function *function;
{
- return (invoking_keyseqs_in_map (function, _rl_keymap));
+ return (rl_invoking_keyseqs_in_map (function, _rl_keymap));
}
/* Print all of the current functions and their bindings to
rl_outstream. If an explicit argument is given, then print
the output in such a way that it can be read back in. */
int
-rl_dump_functions (count)
- int count;
+rl_dump_functions (count, key)
+ int count, key;
{
- void rl_function_dumper ();
-
rl_function_dumper (rl_explicit_arg);
rl_on_new_line ();
return (0);
@@ -1290,7 +1324,7 @@ rl_function_dumper (print_readably)
char **invokers;
function = rl_named_function (name);
- invokers = invoking_keyseqs_in_map (function, _rl_keymap);
+ invokers = rl_invoking_keyseqs_in_map (function, _rl_keymap);
if (print_readably)
{
@@ -1339,7 +1373,22 @@ rl_function_dumper (print_readably)
}
}
-
+/* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. */
+void
+_rl_bind_if_unbound (keyseq, default_func)
+ char *keyseq;
+ Function *default_func;
+{
+ Function *func;
+
+ if (keyseq)
+ {
+ func = rl_function_of_keyseq (keyseq, _rl_keymap, (int *)NULL);
+ if (!func || func == rl_do_lowercase_version)
+ rl_set_key (keyseq, default_func, _rl_keymap);
+ }
+}
+
/* **************************************************************** */
/* */
/* String Utility Functions */
diff --git a/gnu/lib/libreadline/complete.c b/gnu/lib/libreadline/complete.c
index f3d9711..524ca4e 100644
--- a/gnu/lib/libreadline/complete.c
+++ b/gnu/lib/libreadline/complete.c
@@ -43,17 +43,19 @@
extern int errno;
#endif /* !errno */
-/* These next are for filename completion. Perhaps this belongs
- in a different place. */
#include <pwd.h>
-#if defined (USG) && !defined (isc386) && !defined (sgi)
-extern struct passwd *getpwuid (), *getpwent ();
-#endif
-#if defined (isc386) && !defined (__STDC__) && defined (_POSIX_SOURCE)
+#if defined (USG) && !defined (HAVE_GETPW_DECLS)
extern struct passwd *getpwent ();
-#endif
+#endif /* USG && !HAVE_GETPW_DECLS */
-/* #define HACK_TERMCAP_MOTION */
+/* ISC systems don't define getpwent() if _POSIX_SOURCE is defined. */
+#if defined (isc386) && defined (_POSIX_SOURCE)
+# if defined (__STDC__)
+extern struct passwd *getpwent (void);
+# else
+extern struct passwd *getpwent ();
+# endif /* !__STDC__ */
+#endif /* isc386 && _POSIX_SOURCE */
#include "posixstat.h"
@@ -95,11 +97,14 @@ extern char *xmalloc (), *xrealloc ();
/* If non-zero, then this is the address of a function to call when
completing on a directory name. The function is called with
the address of a string (the current directory name) as an arg. */
-Function *rl_symbolic_link_hook = (Function *)NULL;
+Function *rl_directory_completion_hook = (Function *)NULL;
/* Non-zero means readline completion functions perform tilde expansion. */
int rl_complete_with_tilde_expansion = 0;
+/* If non-zero, non-unique completions always show the list of matches. */
+int _rl_complete_show_all = 0;
+
#if defined (VISIBLE_STATS)
# if !defined (X_OK)
# define X_OK 1
@@ -133,6 +138,10 @@ Function *rl_completion_entry_function = (Function *)NULL;
array of strings returned. */
CPPFunction *rl_attempted_completion_function = (CPPFunction *)NULL;
+/* Non-zero means to suppress normal filename completion after the
+ user-specified completion function has been called. */
+int rl_attempted_completion_over = 0;
+
/* Local variable states what happened during the last completion attempt. */
static int completion_changed_buffer = 0;
@@ -144,22 +153,24 @@ rl_complete (ignore, invoking_key)
int ignore, invoking_key;
{
if (rl_last_func == rl_complete && !completion_changed_buffer)
- rl_complete_internal ('?');
+ return (rl_complete_internal ('?'));
+ else if (_rl_complete_show_all)
+ return (rl_complete_internal ('!'));
else
- rl_complete_internal (TAB);
+ return (rl_complete_internal (TAB));
}
/* List the possible completions. See description of rl_complete (). */
rl_possible_completions (ignore, invoking_key)
int ignore, invoking_key;
{
- rl_complete_internal ('?');
+ return (rl_complete_internal ('?'));
}
rl_insert_completions (ignore, invoking_key)
int ignore, invoking_key;
{
- rl_complete_internal ('*');
+ return (rl_complete_internal ('*'));
}
/* The user must press "y" or "n". Non-zero return means "y" pressed. */
@@ -170,9 +181,9 @@ get_y_or_n ()
for (;;)
{
c = rl_read_key ();
- if (c == 'y' || c == 'Y')
+ if (c == 'y' || c == 'Y' || c == ' ')
return (1);
- if (c == 'n' || c == 'N')
+ if (c == 'n' || c == 'N' || c == RUBOUT)
return (0);
if (c == ABORT_CHAR)
rl_abort ();
@@ -263,11 +274,90 @@ _delete_quotes (text)
}
#endif /* SHELL */
+/* Return the portion of PATHNAME that should be output when listing
+ possible completions. If we are hacking filename completion, we
+ are only interested in the basename, the portion following the
+ final slash. Otherwise, we return what we were passed. */
+static char *
+printable_part (pathname)
+ char *pathname;
+{
+ char *temp = (char *)NULL;
+
+ if (rl_filename_completion_desired)
+ temp = strrchr (pathname, '/');
+
+ if (!temp)
+ return (pathname);
+ else
+ return (++temp);
+}
+
+/* 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 1 if we printed an extension character, 0 if not. */
+static int
+print_filename (to_print, full_pathname)
+ char *to_print, *full_pathname;
+{
+#if !defined (VISIBLE_STATS)
+ fputs (to_print, rl_outstream);
+ return 0;
+#else
+ char *s, c, *new_full_pathname;
+ int extension_char = 0, slen, tlen;
+
+ fputs (to_print, rl_outstream);
+ if (rl_filename_completion_desired && rl_visible_stats)
+ {
+ /* If to_print != full_pathname, to_print is the basename of the
+ path passed. In this case, we try to expand the directory
+ name before checking for the stat character. */
+ if (to_print != full_pathname)
+ {
+ /* Terminate the directory name. */
+ c = to_print[-1];
+ to_print[-1] = '\0';
+
+ s = tilde_expand (full_pathname);
+ if (rl_directory_completion_hook)
+ (*rl_directory_completion_hook) (&s);
+
+ slen = strlen (s);
+ tlen = strlen (to_print);
+ new_full_pathname = xmalloc (slen + tlen + 2);
+ strcpy (new_full_pathname, s);
+ new_full_pathname[slen] = '/';
+ strcpy (new_full_pathname + slen + 1, to_print);
+
+ extension_char = stat_char (new_full_pathname);
+
+ free (new_full_pathname);
+ to_print[-1] = c;
+ }
+ else
+ {
+ s = tilde_expand (full_pathname);
+ extension_char = stat_char (s);
+ }
+
+ free (s);
+ if (extension_char)
+ putc (extension_char, rl_outstream);
+ return (extension_char != 0);
+ }
+ else
+ return 0;
+#endif /* VISIBLE_STATS */
+}
+
/* Complete the word at or before point.
WHAT_TO_DO says what to do with the completion.
`?' means list the possible completions.
TAB means do standard completion.
- `*' means insert all of the possible completions. */
+ `*' means insert all of the possible completions.
+ `!' means to do standard completion, and list all possible completions if
+ there is more than one. */
rl_complete_internal (what_to_do)
int what_to_do;
{
@@ -276,10 +366,10 @@ rl_complete_internal (what_to_do)
int start, scan, end, delimiter = 0, pass_next;
char *text, *saved_line_buffer;
char *replacement;
+ char quote_char = '\0';
#if defined (SHELL)
int found_quote = 0;
#endif
- char quote_char = '\0';
if (rl_line_buffer)
saved_line_buffer = savestring (rl_line_buffer);
@@ -352,12 +442,13 @@ rl_complete_internal (what_to_do)
substring on which to complete. */
while (--rl_point)
{
+ scan = rl_line_buffer[rl_point];
#if defined (SHELL)
/* Don't let word break characters in quoted substrings break
words for the completer. */
if (found_quote)
{
- if (strchr (rl_completer_quote_characters, rl_line_buffer[rl_point]))
+ if (strchr (rl_completer_quote_characters, scan))
{
quoted = !quoted;
continue;
@@ -366,23 +457,23 @@ rl_complete_internal (what_to_do)
continue;
}
#endif /* SHELL */
- if (strchr (rl_completer_word_break_characters, rl_line_buffer[rl_point]))
+ if (strchr (rl_completer_word_break_characters, scan))
break;
}
}
/* If we are at a word break, then advance past it. */
- if (strchr (rl_completer_word_break_characters, rl_line_buffer[rl_point]))
+ scan = rl_line_buffer[rl_point];
+ if (strchr (rl_completer_word_break_characters, scan))
{
/* If the character that caused the word break was a quoting
character, then remember it as the delimiter. */
- if (strchr ("\"'", rl_line_buffer[rl_point]) && (end - rl_point) > 1)
- delimiter = rl_line_buffer[rl_point];
+ if (strchr ("\"'", scan) && (end - rl_point) > 1)
+ delimiter = scan;
/* If the character isn't needed to determine something special
about what kind of completion to perform, then advance past it. */
- if (!rl_special_prefixes ||
- !strchr (rl_special_prefixes, rl_line_buffer[rl_point]))
+ if (!rl_special_prefixes || strchr (rl_special_prefixes, scan) == 0)
rl_point++;
}
}
@@ -399,11 +490,9 @@ rl_complete_internal (what_to_do)
{
matches = (*rl_attempted_completion_function) (text, start, end);
- if (matches)
+ if (matches || rl_attempted_completion_over)
{
- /* XXX - This is questionable code. - XXX */
- if (matches == (char **)-1)
- matches = (char **)NULL;
+ rl_attempted_completion_over = 0;
our_func = (Function *)NULL;
goto after_usual_completion;
}
@@ -441,6 +530,7 @@ rl_complete_internal (what_to_do)
char *lowest_common;
int j, newlen = 0;
char dead_slot;
+ char **temp_array;
/* Sort the items. */
/* It is safe to sort this array, because the lowest common
@@ -464,25 +554,19 @@ rl_complete_internal (what_to_do)
/* We have marked all the dead slots with (char *)&dead_slot.
Copy all the non-dead entries into a new array. */
- {
- char **temp_array =
- (char **)xmalloc ((3 + newlen) * sizeof (char *));
-
- for (i = 1, j = 1; matches[i]; i++)
- {
- if (matches[i] != (char *)&dead_slot)
- temp_array[j++] = matches[i];
- }
-
- temp_array[j] = (char *)NULL;
-
- if (matches[0] != (char *)&dead_slot)
- free (matches[0]);
+ temp_array = (char **)xmalloc ((3 + newlen) * sizeof (char *));
+ for (i = j = 1; matches[i]; i++)
+ {
+ if (matches[i] != (char *)&dead_slot)
+ temp_array[j++] = matches[i];
+ }
+ temp_array[j] = (char *)NULL;
- free (matches);
+ if (matches[0] != (char *)&dead_slot)
+ free (matches[0]);
+ free (matches);
- matches = temp_array;
- }
+ matches = temp_array;
/* Place the lowest common denominator back in [0]. */
matches[0] = lowest_common;
@@ -500,6 +584,7 @@ rl_complete_internal (what_to_do)
switch (what_to_do)
{
case TAB:
+ case '!':
/* If we are matching filenames, then here is our chance to
do clever processing by re-examining the list. Call the
ignore function with the array as a parameter. It can
@@ -529,7 +614,11 @@ rl_complete_internal (what_to_do)
This also checks whether the common prefix of several
matches needs to be quoted. If the common prefix should
not be checked, add !matches[1] to the if clause. */
- if (rl_strpbrk (matches[0], rl_completer_word_break_characters))
+ if (rl_strpbrk (matches[0], rl_completer_word_break_characters)
+#if defined (SHELL)
+ || rl_strpbrk (matches[0], "$`")
+#endif
+ )
do_replace = matches[1] ? MULT_MATCH : SINGLE_MATCH;
if (do_replace != NO_MATCH)
@@ -558,7 +647,7 @@ rl_complete_internal (what_to_do)
free (mtext);
rlen = strlen (rtext);
- replacement = (char *)alloca (rlen + 1);
+ replacement = xmalloc (rlen + 1);
strcpy (replacement, rtext);
if (do_replace == MULT_MATCH)
replacement[rlen - 1] = '\0';
@@ -567,7 +656,7 @@ rl_complete_internal (what_to_do)
/* Found an embedded word break character in a potential
match, so we need to prepend a quote character if we
are replacing the completion string. */
- replacement = (char *)alloca (strlen (matches[0]) + 2);
+ replacement = xmalloc (strlen (matches[0]) + 2);
quote_char = *rl_completer_quote_characters;
*replacement = quote_char;
strcpy (replacement + 1, matches[0]);
@@ -577,9 +666,13 @@ rl_complete_internal (what_to_do)
if (replacement)
{
+ rl_begin_undo_group ();
rl_delete_text (start, rl_point);
rl_point = start;
rl_insert_text (replacement);
+ rl_end_undo_group ();
+ if (replacement != matches[0])
+ free (replacement);
}
/* If there are more matches, ring the bell to indicate.
@@ -589,7 +682,9 @@ rl_complete_internal (what_to_do)
of the line, then add a space. */
if (matches[1])
{
- if (rl_editing_mode != vi_mode)
+ if (what_to_do == '!')
+ goto display_matches; /* XXX */
+ else if (rl_editing_mode != vi_mode)
ding (); /* There are other matches remaining. */
}
else
@@ -608,8 +703,7 @@ rl_complete_internal (what_to_do)
struct stat finfo;
char *filename = tilde_expand (matches[0]);
- if ((stat (filename, &finfo) == 0) &&
- S_ISDIR (finfo.st_mode))
+ if ((stat (filename, &finfo) == 0) && S_ISDIR (finfo.st_mode))
{
if (rl_line_buffer[rl_point] != '/')
rl_insert_text ("/");
@@ -633,9 +727,9 @@ rl_complete_internal (what_to_do)
{
int i = 1;
+ rl_begin_undo_group ();
rl_delete_text (start, rl_point);
rl_point = start;
- rl_begin_undo_group ();
if (matches[1])
{
while (matches[i])
@@ -655,34 +749,17 @@ rl_complete_internal (what_to_do)
case '?':
{
- int len, count, limit, max = 0;
+ int len, count, limit, max;
int j, k, l;
/* Handle simple case first. What if there is only one answer? */
if (!matches[1])
{
- char *temp = (char *)NULL;
-
- if (rl_filename_completion_desired)
- temp = strrchr (matches[0], '/');
-
- if (!temp)
- temp = matches[0];
- else
- temp++;
+ char *temp;
+ temp = printable_part (matches[0]);
crlf ();
- fprintf (rl_outstream, "%s", temp);
-#if defined (VISIBLE_STATS)
- if (rl_filename_completion_desired && rl_visible_stats)
- {
- int extension_char;
-
- extension_char = stat_char (matches[0]);
- if (extension_char)
- putc (extension_char, rl_outstream);
- }
-#endif /* VISIBLE_STATS */
+ print_filename (temp, matches[0]);
crlf ();
goto restart;
}
@@ -690,23 +767,13 @@ rl_complete_internal (what_to_do)
/* There is more than one answer. Find out how many there are,
and find out what the maximum printed length of a single entry
is. */
- for (i = 1; matches[i]; i++)
+ display_matches:
+ for (max = 0, i = 1; matches[i]; i++)
{
char *temp;
int name_length;
- /* If we are hacking filenames, then only count the characters
- after the last slash in the pathname. */
- if (rl_filename_completion_desired)
- temp = strrchr (matches[i], '/');
- else
- temp = (char *)NULL;
-
- if (!temp)
- temp = matches[i];
- else
- temp++;
-
+ temp = printable_part (matches[i]);
name_length = strlen (temp);
if (name_length > max)
@@ -764,40 +831,15 @@ rl_complete_internal (what_to_do)
for (j = 0, l = i; j < limit; j++)
{
if (l > len || !matches[l])
- {
- break;
- }
+ break;
else
{
- char *temp = (char *)NULL;
+ char *temp;
int printed_length;
- if (rl_filename_completion_desired)
- temp = strrchr (matches[l], '/');
-
- if (!temp)
- temp = matches[l];
- else
- temp++;
-
+ temp = printable_part (matches[l]);
printed_length = strlen (temp);
- fprintf (rl_outstream, "%s", temp);
-
-#if defined (VISIBLE_STATS)
- if (rl_filename_completion_desired &&
- rl_visible_stats)
- {
- int extension_char;
-
- extension_char = stat_char (matches[l]);
-
- if (extension_char)
- {
- putc (extension_char, rl_outstream);
- printed_length++;
- }
- }
-#endif /* VISIBLE_STATS */
+ printed_length += print_filename (temp, matches[l]);
if (j + 1 < limit)
{
@@ -835,6 +877,7 @@ rl_complete_internal (what_to_do)
free (saved_line_buffer);
}
+ return 0;
}
#if defined (VISIBLE_STATS)
@@ -848,11 +891,18 @@ stat_char (filename)
char *filename;
{
struct stat finfo;
- int character = 0;
+ int character, r;
- if (stat (filename, &finfo) == -1)
- return (character);
+#if defined (S_ISLNK)
+ r = lstat (filename, &finfo);
+#else
+ r = stat (filename, &finfo);
+#endif
+
+ if (r == -1)
+ return (0);
+ character = 0;
if (S_ISDIR (finfo.st_mode))
character = '/';
#if defined (S_ISLNK)
@@ -888,9 +938,9 @@ username_completion_function (text, state)
int state;
char *text;
{
-#if defined (_GO32_)
+#if defined (__GO32__)
return (char *)NULL;
-#else /* !_GO32_ */
+#else /* !__GO32__ */
static char *username = (char *)NULL;
static struct passwd *entry;
static int namelen, first_char, first_char_loc;
@@ -914,7 +964,8 @@ username_completion_function (text, state)
while (entry = getpwent ())
{
- if (strncmp (username, entry->pw_name, namelen) == 0)
+ if ((username[0] == entry->pw_name[0]) &&
+ (strncmp (username, entry->pw_name, namelen) == 0))
break;
}
@@ -936,7 +987,7 @@ username_completion_function (text, state)
return (value);
}
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
}
/* **************************************************************** */
@@ -1091,13 +1142,20 @@ filename_completion_function (text, state)
users_dirname = savestring (dirname);
{
char *temp_dirname;
+ int replace_dirname;
temp_dirname = tilde_expand (dirname);
free (dirname);
dirname = temp_dirname;
- if (rl_symbolic_link_hook)
- (*rl_symbolic_link_hook) (&dirname);
+ replace_dirname = 0;
+ if (rl_directory_completion_hook)
+ replace_dirname = (*rl_directory_completion_hook) (&dirname);
+ if (replace_dirname)
+ {
+ free (users_dirname);
+ users_dirname = savestring (dirname);
+ }
}
directory = opendir (dirname);
filename_len = strlen (filename);
@@ -1125,14 +1183,12 @@ filename_completion_function (text, state)
}
else
{
- /* Otherwise, if these match upto the length of filename, then
+ /* Otherwise, if these match up to the length of filename, then
it is a match. */
if (((int)D_NAMLEN (entry)) >= filename_len &&
(entry->d_name[0] == filename[0]) &&
(strncmp (filename, entry->d_name, filename_len) == 0))
- {
- break;
- }
+ break;
}
}
@@ -1166,7 +1222,8 @@ filename_completion_function (text, state)
{
char *temp;
- if (dirname && (strcmp (dirname, ".") != 0))
+ /* dirname && (strcmp (dirname, ".") != 0) */
+ if (dirname && (dirname[0] != '.' || dirname[1]))
{
if (rl_complete_with_tilde_expansion && *users_dirname == '~')
{
@@ -1191,9 +1248,8 @@ filename_completion_function (text, state)
strcat (temp, entry->d_name);
}
else
- {
- temp = (savestring (entry->d_name));
- }
+ temp = (savestring (entry->d_name));
+
return (temp);
}
}
@@ -1239,10 +1295,11 @@ rl_tilde_expand (ignore, key)
int len;
len = end - start + 1;
- temp = (char *)alloca (len + 1);
+ temp = xmalloc (len + 1);
strncpy (temp, rl_line_buffer + start, len);
temp[len] = '\0';
homedir = tilde_expand (temp);
+ free (temp);
insert:
rl_begin_undo_group ();
diff --git a/gnu/lib/libreadline/display.c b/gnu/lib/libreadline/display.c
index 6827621..38b1787 100644
--- a/gnu/lib/libreadline/display.c
+++ b/gnu/lib/libreadline/display.c
@@ -53,12 +53,13 @@ extern int readline_echoing_p;
extern char *term_clreol, *term_im, *term_ic, *term_ei, *term_DC;
/* Termcap variables. */
extern char *term_up, *term_dc, *term_cr, *term_IC;
-extern int screenheight, screenwidth, terminal_can_insert;
+extern int screenheight, screenwidth, screenchars;
+extern int terminal_can_insert;
extern void _rl_output_some_chars ();
-extern void _rl_output_character_function ();
+extern int _rl_output_character_function ();
-extern int _rl_convert_meta_chars_to_ascii;
+extern int _rl_output_meta_chars;
extern int _rl_horizontal_scroll_mode;
extern int _rl_mark_modified_lines;
extern int _rl_prefer_visible_bell;
@@ -139,15 +140,138 @@ static int forced_display = 0;
/* Default and initial buffer size. Can grow. */
static int line_size = 1024;
+static char *last_prompt_string = (char *)NULL;
+static char *local_prompt, *local_prompt_prefix;
+static int visible_length, prefix_length;
+
+/* The number of invisible characters in the line currently being
+ displayed on the screen. */
+static int visible_wrap_offset = 0;
+
+/* The length (buffer offset) of the first line of the last (possibly
+ multi-line) buffer displayed on the screen. */
+static int visible_first_line_len = 0;
+
+/* 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. */
+
+/* Current implementation:
+ \001 (^A) start non-visible characters
+ \002 (^B) end non-visible characters
+ all characters except \001 and \002 (following a \001) are copied to
+ the returned string; all characters except those between \001 and
+ \002 are assumed to be `visible'. */
+
+static char *
+expand_prompt (pmt, lp)
+ char *pmt;
+ int *lp;
+{
+ char *r, *ret, *p;
+ int l, rl, ignoring;
+
+ /* Short-circuit if we can. */
+ if (strchr (pmt, RL_PROMPT_START_IGNORE) == 0)
+ {
+ r = savestring (pmt);
+ if (lp)
+ *lp = strlen (r);
+ return r;
+ }
+
+ l = strlen (pmt);
+ r = ret = xmalloc (l + 1);
+
+ for (rl = ignoring = 0, p = pmt; p && *p; p++)
+ {
+ /* This code strips the invisible character string markers
+ RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE */
+ if (*p == RL_PROMPT_START_IGNORE)
+ {
+ ignoring++;
+ continue;
+ }
+ else if (ignoring && *p == RL_PROMPT_END_IGNORE)
+ {
+ ignoring = 0;
+ continue;
+ }
+ else
+ {
+ *r++ = *p;
+ if (!ignoring)
+ rl++;
+ }
+ }
+
+ *r = '\0';
+ if (lp)
+ *lp = rl;
+ return ret;
+}
+
+/*
+ * Expand the prompt string into the various display components, if
+ * necessary.
+ *
+ * local_prompt = expanded last line of string in rl_display_prompt
+ * (portion after the final newline)
+ * local_prompt_prefix = portion before last newline of rl_display_prompt,
+ * expanded via expand_prompt
+ * visible_length = number of visible characters in local_prompt
+ * prefix_length = number of visible characters in local_prompt_prefix
+ *
+ * This function is called once per call to readline(). It may also be
+ * called arbitrarily to expand the primary prompt.
+ *
+ * The return value is the number of visible characters on the last line
+ * of the (possibly multi-line) prompt.
+ */
+int
+rl_expand_prompt (prompt)
+ char *prompt;
+{
+ char *p, *t;
+ int c;
+
+ /* Clear out any saved values. */
+ if (local_prompt)
+ free (local_prompt);
+ if (local_prompt_prefix)
+ free (local_prompt_prefix);
+ local_prompt = local_prompt_prefix = (char *)0;
+
+ p = strrchr (prompt, '\n');
+ if (!p)
+ {
+ /* The prompt is only one line. */
+ local_prompt = expand_prompt (prompt, &visible_length);
+ local_prompt_prefix = (char *)0;
+ return (visible_length);
+ }
+ else
+ {
+ /* The prompt spans multiple lines. */
+ t = ++p;
+ local_prompt = expand_prompt (p, &visible_length);
+ 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, &prefix_length);
+ *t = c;
+ return (prefix_length);
+ }
+}
+
/* Basic redisplay algorithm. */
void
rl_redisplay ()
{
register int in, out, c, linenum;
register char *line = invisible_line;
+ int c_pos = 0, inv_botlin = 0, wrap_offset, wrap_column;
char *prompt_this_line;
- int c_pos = 0;
- int inv_botlin = 0; /* Number of lines in newly drawn buffer. */
if (!readline_echoing_p)
return;
@@ -186,20 +310,41 @@ rl_redisplay ()
if (visible_line[0] != invisible_line[0])
rl_display_fixed = 0;
- prompt_this_line = strrchr (rl_display_prompt, '\n');
- if (!prompt_this_line)
- prompt_this_line = rl_display_prompt;
- else
+ /* If the prompt to be displayed is the `primary' readline prompt (the
+ one passed to readline()), use the values we have already expanded.
+ If not, use what's already in rl_display_prompt. WRAP_OFFSET is the
+ number of non-visible characters in the prompt string. */
+ if (rl_display_prompt == rl_prompt)
{
- prompt_this_line++;
- if (forced_display)
- _rl_output_some_chars
- (rl_display_prompt, prompt_this_line - rl_display_prompt);
+ int local_len = strlen (local_prompt);
+ if (local_prompt_prefix && forced_display)
+ _rl_output_some_chars (local_prompt_prefix, strlen (local_prompt_prefix));
+
+ if (local_prompt)
+ strncpy (line + out, local_prompt, local_len);
+ out += local_len;
+ line[out] = '\0';
+ wrap_offset = local_len - visible_length;
}
+ else
+ {
+ int pmtlen;
+ prompt_this_line = strrchr (rl_display_prompt, '\n');
+ if (!prompt_this_line)
+ prompt_this_line = rl_display_prompt;
+ else
+ {
+ prompt_this_line++;
+ if (forced_display)
+ _rl_output_some_chars (rl_display_prompt, prompt_this_line - rl_display_prompt);
+ }
- strncpy (line + out, prompt_this_line, strlen (prompt_this_line));
- out += strlen (prompt_this_line);
- line[out] = '\0';
+ pmtlen = strlen (prompt_this_line);
+ strncpy (line + out, prompt_this_line, pmtlen);
+ out += pmtlen;
+ line[out] = '\0';
+ wrap_offset = 0;
+ }
for (in = 0; in < rl_end; in++)
{
@@ -218,7 +363,7 @@ rl_redisplay ()
if (META_CHAR (c))
{
- if (_rl_convert_meta_chars_to_ascii)
+ if (_rl_output_meta_chars == 0)
{
sprintf (line + out, "\\%o", c);
out += 4;
@@ -226,7 +371,6 @@ rl_redisplay ()
else
line[out++] = c;
}
-#define DISPLAY_TABS
#if defined (DISPLAY_TABS)
else if (c == '\t')
{
@@ -252,6 +396,8 @@ rl_redisplay ()
if (c_pos < 0)
c_pos = out;
+ /* C_POS == position in buffer where cursor should be placed. */
+
/* PWP: now is when things get a bit hairy. The visible and invisible
line buffers are really multiple lines, which would wrap every
(screenwidth - 1) characters. Go through each in turn, finding
@@ -263,7 +409,8 @@ rl_redisplay ()
if (!_rl_horizontal_scroll_mode && term_up && *term_up)
{
- int total_screen_chars = (screenwidth * screenheight);
+ int total_screen_chars = screenchars;
+ int nleft, cursor_linenum, pos;
if (!rl_display_fixed || forced_display)
{
@@ -275,15 +422,48 @@ rl_redisplay ()
if (out >= total_screen_chars)
out = total_screen_chars - 1;
- /* Number of screen lines to display. */
- inv_botlin = out / screenwidth;
+ /* Number of screen lines to display. The first line wraps at
+ (screenwidth + wrap_offset) chars, the rest of the lines have
+ screenwidth chars. */
+ nleft = out - screenwidth - wrap_offset;
+ if (nleft > 0)
+ inv_botlin = 1 + nleft / screenwidth;
+ else
+ inv_botlin = 0;
+
+ /* The first line is at character position 0 in the buffer. The
+ second and subsequent lines start at N * screenwidth, offset by
+ OFFSET. OFFSET is wrap_offset for the invisible line and
+ visible_wrap_offset for the line currently displayed. */
+
+#define L_OFFSET(n, offset) ((n) > 0 ? ((n) * screenwidth) + (offset) : 0)
+#define VIS_CHARS(line) &visible_line[L_OFFSET((line), visible_wrap_offset)]
+#define VIS_LINE(line) ((line) > _rl_vis_botlin) ? "" : VIS_CHARS(line)
+#define INV_LINE(line) &invisible_line[L_OFFSET((line), wrap_offset)]
/* For each line in the buffer, do the updating display. */
for (linenum = 0; linenum <= inv_botlin; linenum++)
- update_line (linenum > _rl_vis_botlin ? ""
- : &visible_line[linenum * screenwidth],
- &invisible_line[linenum * screenwidth],
- linenum);
+ {
+ update_line (VIS_LINE(linenum), INV_LINE(linenum), linenum);
+
+ /* If this is the line with the prompt, we might need to
+ compensate for invisible characters in the new line. Do
+ this only if there is not more than one new line (which
+ implies that we completely overwrite the old visible line)
+ and the new line is shorter than the old. */
+ if (linenum == 0 &&
+ inv_botlin == 0 &&
+ (wrap_offset > visible_wrap_offset) &&
+ (_rl_last_c_pos < visible_first_line_len))
+ {
+ nleft = screenwidth + wrap_offset - _rl_last_c_pos;
+ clear_to_eol (nleft);
+ }
+
+ /* Since the new first line is now visible, save its length. */
+ if (linenum == 0)
+ visible_first_line_len = _rl_last_c_pos;
+ }
/* We may have deleted some lines. If so, clear the left over
blank ones at the bottom out. */
@@ -292,7 +472,7 @@ rl_redisplay ()
char *tt;
for (; linenum <= _rl_vis_botlin; linenum++)
{
- tt = &visible_line[linenum * screenwidth];
+ tt = VIS_CHARS (linenum);
_rl_move_vert (linenum);
_rl_move_cursor_relative (0, tt);
clear_to_eol
@@ -302,9 +482,19 @@ rl_redisplay ()
_rl_vis_botlin = inv_botlin;
/* Move the cursor where it should be. */
- _rl_move_vert (c_pos / screenwidth);
- _rl_move_cursor_relative (c_pos % screenwidth,
- &invisible_line[(c_pos / screenwidth) * screenwidth]);
+ /* Which line? */
+ nleft = c_pos - screenwidth - wrap_offset;
+ if (nleft > 0)
+ cursor_linenum = 1 + nleft / screenwidth;
+ else
+ cursor_linenum = 0;
+ _rl_move_vert (cursor_linenum);
+
+ /* Where on that line? And where does that line start
+ in the buffer? */
+ pos = L_OFFSET(cursor_linenum, wrap_offset);
+ nleft = c_pos - pos;
+ _rl_move_cursor_relative (nleft, &invisible_line[pos]);
}
}
else /* Do horizontal scrolling. */
@@ -350,6 +540,7 @@ rl_redisplay ()
visible_line = invisible_line;
invisible_line = temp;
rl_display_fixed = 0;
+ visible_wrap_offset = wrap_offset;
}
}
@@ -357,12 +548,12 @@ rl_redisplay ()
line on the screen; vis:
/old first difference
- /beginning of line | /old last same /old EOL
- v v v v
+ /beginning of line | /old last same /old EOL
+ v v v v
old: eddie> Oh, my little gruntle-buggy is to me, as lurgid as
new: eddie> Oh, my little buggy says to me, as lurgid as
- ^ ^ ^ ^
- \beginning of line | \new last same \new end of line
+ ^ ^ ^ ^
+ \beginning of line | \new last same \new end of line
\new first difference
All are character pointers for the sake of speed. Special cases for
@@ -494,6 +685,7 @@ rl_on_new_line ()
_rl_last_c_pos = _rl_last_v_pos = 0;
_rl_vis_botlin = last_lmargin = 0;
+ return 0;
}
/* Actually update the display, period. */
@@ -508,6 +700,7 @@ rl_forced_update_display ()
rl_on_new_line ();
forced_display++;
rl_redisplay ();
+ return 0;
}
/* Move the cursor from _rl_last_c_pos to NEW, which are buffer indices.
@@ -553,7 +746,7 @@ _rl_move_cursor_relative (new, data)
#else
for (i = _rl_last_c_pos; i < new; i++)
putc (data[i], rl_outstream);
-#endif /* HACK_TERMCAP_MOTION */
+#endif /* HACK_TERMCAP_MOTION */
}
else
backspace (_rl_last_c_pos - new);
@@ -570,14 +763,14 @@ _rl_move_vert (to)
if (_rl_last_v_pos == to || to > screenheight)
return;
-#if defined (_GO32_)
+#if defined (__GO32__)
{
int row, col;
ScreenGetCursor (&row, &col);
ScreenSetCursor ((row + to - _rl_last_v_pos), col);
}
-#else /* !_GO32_ */
+#else /* !__GO32__ */
if ((delta = to - _rl_last_v_pos) > 0)
{
@@ -592,18 +785,20 @@ _rl_move_vert (to)
for (i = 0; i < -delta; i++)
tputs (term_up, 1, _rl_output_character_function);
}
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
_rl_last_v_pos = to; /* Now TO is here */
}
/* Physically print C on rl_outstream. This is for functions which know
- how to optimize the display. */
+ how to optimize the display. Return the number of characters output. */
rl_show_char (c)
int c;
{
- if (META_CHAR (c) && _rl_convert_meta_chars_to_ascii)
+ int n = 1;
+ if (META_CHAR (c) && (_rl_output_meta_chars == 0))
{
fprintf (rl_outstream, "M-");
+ n += 2;
c = UNMETA (c);
}
@@ -613,11 +808,14 @@ rl_show_char (c)
if (c < 32)
#endif /* !DISPLAY_TABS */
{
+ fprintf (rl_outstream, "C-");
+ n += 2;
c += 64;
}
putc (c, rl_outstream);
fflush (rl_outstream);
+ return n;
}
int
@@ -625,7 +823,7 @@ rl_character_len (c, pos)
register int c, pos;
{
if (META_CHAR (c))
- return (_rl_convert_meta_chars_to_ascii ? 4 : 1);
+ return ((_rl_output_meta_chars == 0) ? 4 : 1);
if (c == '\t')
{
@@ -636,10 +834,7 @@ rl_character_len (c, pos)
#endif /* !DISPLAY_TABS */
}
- if (isprint (c))
- return (1);
- else
- return (2);
+ return ((isprint (c)) ? 1 : 2);
}
/* How to print things in the "echo-area". The prompt is treated as a
@@ -659,6 +854,7 @@ rl_message (va_alist)
rl_display_prompt = msg_buf;
rl_redisplay ();
+ return 0;
}
#else /* !HAVE_VARARGS_H */
rl_message (format, arg1, arg2)
@@ -667,6 +863,7 @@ rl_message (format, arg1, arg2)
sprintf (msg_buf, format, arg1, arg2);
rl_display_prompt = msg_buf;
rl_redisplay ();
+ return 0;
}
#endif /* !HAVE_VARARGS_H */
@@ -675,6 +872,7 @@ rl_clear_message ()
{
rl_display_prompt = rl_prompt;
rl_redisplay ();
+ return 0;
}
rl_reset_line_state ()
@@ -683,6 +881,7 @@ rl_reset_line_state ()
rl_display_prompt = rl_prompt ? rl_prompt : "";
forced_display = 1;
+ return 0;
}
/* Quick redisplay hack when erasing characters at the end of the line. */
@@ -707,13 +906,13 @@ static void
clear_to_eol (count)
int count;
{
-#if !defined (_GO32_)
+#if !defined (__GO32__)
if (term_clreol)
{
tputs (term_clreol, 1, _rl_output_character_function);
}
else
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
{
register int i;
@@ -733,7 +932,7 @@ insert_some_chars (string, count)
char *string;
int count;
{
-#if defined (_GO32_)
+#if defined (__GO32__)
int row, col, width;
char *row_start;
@@ -779,7 +978,7 @@ insert_some_chars (string, count)
if (term_ei && *term_ei)
tputs (term_ei, 1, _rl_output_character_function);
}
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
}
/* Delete COUNT characters from the display line. */
@@ -787,7 +986,7 @@ static void
delete_chars (count)
int count;
{
-#if defined (_GO32_)
+#if defined (__GO32__)
int row, col, width;
char *row_start;
@@ -814,5 +1013,5 @@ delete_chars (count)
while (count--)
tputs (term_dc, 1, _rl_output_character_function);
}
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
}
diff --git a/gnu/lib/libreadline/doc/hsuser.texinfo b/gnu/lib/libreadline/doc/hsuser.texinfo
index a460165..44f7fa0 100644
--- a/gnu/lib/libreadline/doc/hsuser.texinfo
+++ b/gnu/lib/libreadline/doc/hsuser.texinfo
@@ -2,7 +2,7 @@
This file documents the user interface to the GNU History library.
Copyright (C) 1988, 1991 Free Software Foundation, Inc.
-Authored by Brian Fox.
+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
@@ -48,8 +48,8 @@ information on using the GNU History Library in your own programs,
@cindex expansion
The History library provides a history expansion feature that is similar
-to the history expansion in Csh. The following text describes the sytax
-that you use to manipulate the history information.
+to the history expansion in @code{csh}. The following text describes
+the syntax used to manipulate the history information.
History expansion takes place in two parts. The first is to determine
which line from the previous history should be used during substitution.
@@ -57,13 +57,13 @@ The second is to select portions of that line for inclusion into the
current one. The line selected from the previous history is called the
@dfn{event}, and the portions of that line that are acted upon are
called @dfn{words}. The line is broken into words in the same fashion
-that the Bash shell does, so that several English (or Unix) words
+that Bash does, so that several English (or Unix) words
surrounded by quotes are considered as one word.
@menu
* Event Designators:: How to specify which history line to use.
* Word Designators:: Specifying which words are of interest.
-* Modifiers:: Modifying the results of susbstitution.
+* Modifiers:: Modifying the results of substitution.
@end menu
@node Event Designators
@@ -76,8 +76,8 @@ history list.
@table @asis
@item @code{!}
-Start a history subsititution, except when followed by a space, tab, or
-the end of the line... @key{=} or @key{(}.
+Start a history substitution, except when followed by a space, tab,
+the end of the line, @key{=} or @key{(}.
@item @code{!!}
Refer to the previous command. This is a synonym for @code{!-1}.
@@ -94,6 +94,14 @@ Refer to the most recent command starting with @var{string}.
@item @code{!?string}[@code{?}]
Refer to the most recent command containing @var{string}.
+@item @code{!#}
+The entire command line typed so far.
+
+@item @code{^string1^string2^}
+Quick Substitution. Repeat the last command, replacing @var{string1}
+with @var{string2}. Equivalent to
+@code{!!:s/string1/string2/}.
+
@end table
@node Word Designators
@@ -107,13 +115,13 @@ with the first word being denoted by a 0 (zero).
@table @code
@item 0 (zero)
-The zero'th word. For many applications, this is the command word.
+The @code{0}th word. For many applications, this is the command word.
@item n
-The @var{n}'th word.
+The @var{n}th word.
@item ^
-The first argument. that is, word 1.
+The first argument; that is, word 1.
@item $
The last argument.
@@ -122,12 +130,18 @@ The last argument.
The word matched by the most recent @code{?string?} search.
@item x-y
-A range of words; @code{-@var{y}} Abbreviates @code{0-@var{y}}.
+A range of words; @code{-@var{y}} abbreviates @code{0-@var{y}}.
@item *
-All of the words, excepting the zero'th. This is a synonym for @code{1-$}.
-It is not an error to use @key{*} if there is just one word in the event.
-The empty string is returned in that case.
+All of the words, except the @code{0}th. This is a synonym for @code{1-$}.
+It is not an error to use @key{*} if there is just one word in the event;
+the empty string is returned in that case.
+
+@item x*
+Abbreviates @code{x-$}
+
+@item x-
+Abbreviates @code{x-$} like @code{x*}, but omits the last word.
@end table
@@ -139,11 +153,6 @@ of the following modifiers, each preceded by a @key{:}.
@table @code
-@item #
-The entire command line typed so far. This means the current command,
-not the previous command, so it really isn't a word designator, and doesn't
-belong in this section.
-
@item h
Remove a trailing pathname component, leaving only the head.
@@ -151,11 +160,38 @@ Remove a trailing pathname component, leaving only the head.
Remove a trailing suffix of the form @samp{.}@var{suffix}, leaving the basename.
@item e
-Remove all but the suffix.
+Remove all but the trailing suffix.
@item t
Remove all leading pathname components, leaving the tail.
@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 @code{q},
+but break into words at spaces, tabs, and newlines.
+@end ifset
+
+@item s/old/new/
+Substitute @var{new} for the first occurrence of @var{old} in the
+event line. Any delimiter may be used in place of @key{/}.
+The delimiter may be quoted in @var{old} and @var{new}
+with a single backslash. If @key{&} appears in @var{new},
+it is replaced by @var{old}. A single backslash will quote
+the @key{&}. 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 @code{s}, as in @code{gs/old/new/}, or with
+@code{&}.
+
@end table
diff --git a/gnu/lib/libreadline/doc/rluser.texinfo b/gnu/lib/libreadline/doc/rluser.texinfo
index 553c88e..36a65b8 100644
--- a/gnu/lib/libreadline/doc/rluser.texinfo
+++ b/gnu/lib/libreadline/doc/rluser.texinfo
@@ -5,14 +5,14 @@
@ignore
This file documents the end user interface to the GNU command line
-editing feautres. It is to be an appendix to manuals for programs which
+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 Free Software Foundation, Inc.
-Authored by Brian Fox.
+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
@@ -39,18 +39,23 @@ into another language, under the above conditions for modified versions.
@node Command Line Editing
@chapter Command Line Editing
-This text describes GNU's command line editing interface.
+This chapter describes the basic features of the GNU
+command line editing interface.
@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 line the vi editor.
@end menu
@node Introduction and Notation
@section Introduction to Line Editing
-The following paragraphs describe the notation we use to represent
+The following paragraphs describe the notation used to represent
keystrokes.
The text @key{C-k} is read as `Control-K' and describes the character
@@ -97,19 +102,19 @@ regardless of the location of the cursor within the line.
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 @key{DEL} to
-back up, and delete the mistyped character.
+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 miss typing a character that you wanted to type, and
not notice your error until you have typed several other characters. In
that case, you can type @key{C-b} to move the cursor to the left, and then
-correct your mistake. Aftwerwards, you can move the cursor to the right
+correct your mistake. Afterwards, you can move the cursor to the right
with @key{C-f}.
When you add text in the middle of a line, you will notice that characters
-to the right of the cursor get `pushed over' to make room for the text
+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 get `pulled back' to fill in the
+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 basic bare
essentials for editing the text of an input line follows.
@@ -123,7 +128,7 @@ Delete the character to the left of the cursor.
@item @key{C-d}
Delete the character underneath the cursor.
@item @w{Printing characters}
-Insert itself into the line at the cursor.
+Insert the character into the line at the cursor.
@item @key{C-_}
Undo the last thing that you did. You can undo all the way back to an
empty line.
@@ -160,11 +165,19 @@ operate on characters while meta keystrokes operate on words.
@subsection Readline Killing Commands
@dfn{Killing} text means to delete the text from the line, but to save
-it away for later use, usually by @dfn{yanking} it back into the line.
+it away for later use, usually by @dfn{yanking} (re-inserting)
+it back into the line.
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.
+
Here is the list of commands for killing text.
@table @key
@@ -186,7 +199,7 @@ Kill from the cursor to the previous whitespace. This is different than
@end table
And, here is how to @dfn{yank} the text back into the line. Yanking
-is
+means to copy the most-recently-killed text from the kill buffer.
@table @key
@item C-y
@@ -197,13 +210,6 @@ Rotate the kill-ring, and yank the new top. You can only do this if
the prior command is @key{C-y} or @key{M-y}.
@end table
-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 in one clean sweep. 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.
-
@node Readline Arguments
@subsection Readline Arguments
@@ -226,81 +232,155 @@ the @key{C-d} command an argument of 10, you could type @key{M-1 0 C-d}.
@section Readline Init File
Although the Readline library comes with a set of Emacs-like
-keybindings, it is possible that you would like to use a different set
+keybindings installed by default,
+it is possible that you would like to use a different set
of keybindings. You can customize programs that use Readline by putting
commands in an @dfn{init} file in your home directory. The name of this
-file is @file{~/.inputrc}.
+file is taken from the value of the shell variable @code{INPUTRC}. If
+that variable is unset, the default is @file{~/.inputrc}.
When a program which uses the Readline library starts up, the
-@file{~/.inputrc} file is read, and the keybindings are set.
+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 Syntax:: Syntax for the commands in @file{~/.inputrc}.
-* Readline Vi Mode:: Switching to @code{vi} mode in Readline.
+* Readline Init Syntax:: Syntax for the commands in the inputrc file.
+* Conditional Init Constructs:: Conditional key bindings in the inputrc file.
@end menu
@node Readline Init Syntax
@subsection Readline Init Syntax
-There are only four constructs allowed in the @file{~/.inputrc}
-file:
+There are only a few basic constructs allowed in the
+Readline init file. Blank lines are ignored.
+Lines beginning with a @key{#} are comments.
+Lines beginning with a @key{$} indicate conditional
+constructs (@pxref{Conditional Init Constructs}). Other lines
+denote variable settings and key bindings.
@table @asis
@item Variable Settings
-You can change the state of a few variables in Readline. You do this by
+You can change the state of a few variables in Readline by
using the @code{set} command within the init file. Here is how you
-would specify that you wish to use Vi line editing commands:
+would specify that you wish to use @code{vi} line editing commands:
@example
set editing-mode vi
@end example
-Right now, there are only a few variables which can be set; so few in
-fact, that we just iterate them here:
+Right now, there are only a few variables which can be set;
+so few, in fact, that we just list them here:
@table @code
@item editing-mode
@vindex editing-mode
The @code{editing-mode} variable controls which editing mode you are
-using. By default, GNU Readline starts up in Emacs editing mode, where
-the keystrokes are most similar to Emacs. This variable can either be
-set to @code{emacs} or @code{vi}.
+using. By default, Readline starts up in Emacs editing mode, where
+the keystrokes are most similar to Emacs. This variable can be
+set to either @code{emacs} or @code{vi}.
@item horizontal-scroll-mode
@vindex horizontal-scroll-mode
-This variable can either be set to @code{On} or @code{Off}. Setting it
+This variable can be set to either @code{On} or @code{Off}. Setting it
to @code{On} means that the text of the lines that you edit will scroll
-horizontally on a single screen line when they are larger than the width
+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 @code{Off}.
@item mark-modified-lines
@vindex mark-modified-lines
-This variable when set to @code{On}, says to display an asterisk
-(@samp{*}) at the starts of history lines which have been modified.
-This variable is off by default.
-
-@item prefer-visible-bell
-@vindex prefer-visible-bell
-If this variable is set to @code{On} it means to use a visible bell if
-one is available, rather than simply ringing the terminal bell. By
-default, the value is @code{Off}.
+This variable, when set to @code{On}, says to display an asterisk
+(@samp{*}) at the start of history lines which have been modified.
+This variable is @code{off} by default.
+
+@item bell-style
+@vindex bell-style
+Controls what happens when Readline wants to ring the terminal bell.
+If set to @code{none}, Readline never rings the bell. If set to
+@code{visible}, Readline uses a visible bell if one is available.
+If set to @code{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{vi-comment} command is executed. The default value
+is @code{"#"}.
+
+@item meta-flag
+@vindex meta-flag
+If set to @code{on}, Readline will enable eight-bit input (it
+will not strip the eighth bit from the characters it reads),
+regardless of what the terminal claims it can support. The
+default value is @code{off}.
+
+@item convert-meta
+@vindex convert-meta
+If set to @code{on}, Readline will convert characters with the
+eigth bit set to an ASCII key sequence by stripping the eigth
+bit and prepending an @key{ESC} character, converting them to a
+meta-prefixed key sequence. The default value is @code{on}.
+
+@item output-meta
+@vindex output-meta
+If set to @code{on}, Readline will display characters with the
+eighth bit set directly rather than as a meta-prefixed escape
+sequence. The default is @code{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. The default limit is
+@code{100}.
+
+@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 show-all-if-ambiguous
+@vindex show-all-if-ambiguous
+This alters the default behavior of the completion functions. If
+set to @code{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 @code{off}.
+
+@item expand-tilde
+@vindex expand-tilde
+If set to @code{on}, tilde expansion is performed when Readline
+attempts word completion. The default is @code{off}.
+
@end table
@item Key Bindings
-The syntax for controlling keybindings in the @file{~/.inputrc} file is
-simple. First you have to know the @i{name} of the command that you
+The syntax for controlling key bindings in the init file is
+simple. First you have to know the name of the command that you
want to change. The following pages contain tables of the command name,
the default keybinding, and a short description of what the command
does.
Once you know the name of the command, simply place the name of the key
you wish to bind the command to, a colon, and then the name of the
-command on a line in the @file{~/.inputrc} file. The name of the key
+command on a line in the init file. The name of the key
can be expressed in different ways, depending on which is most
comfortable for you.
@@ -319,10 +399,11 @@ expressed on the right hand side (that is, to insert the text
@samp{>&output} into the line).
@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. Simply place the key sequence
-in double quotes. GNU Emacs style key escapes can be used, as in the
-following example:
+@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 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
@@ -334,9 +415,97 @@ In the above example, @samp{C-u} is bound to the function
@code{universal-argument} (just as it was in the first example),
@samp{C-x C-r} is bound to the function @code{re-read-init-file}, and
@samp{ESC [ 1 1 ~} is bound to insert the text @samp{Function Key 1}.
+The following 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{"}
+@item @kbd{\'}
+@key{'}
@end table
+
+When entering the text of a macro, single or double quotes should
+be used to indicate a macro definition. Unquoted text
+is assumed to be a function name. Backslash
+will quote any character in the macro text, including @key{"}
+and @key{'}.
+For example, the following binding will make @kbd{C-x \}
+insert a single @key{\} into the line:
+@example
+"\C-x\\": "\\"
+@end example
+
@end table
+@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 three parser directives used.
+
+@ftable @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 the full name of the terminal and the
+portion of the terminal name before the first @samp{-}. This
+allows @var{sun} to match both @var{sun} and @var{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 it.
+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 you saw 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.
+@end ftable
+
+@node Bindable Readline Commands
+@section Bindable Readline Commands
@menu
* Commands For Moving:: Moving about the line.
@@ -345,11 +514,12 @@ In the above example, @samp{C-u} is bound to the function
* 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.
-* Miscellaneous Commands:: Other miscillaneous commands.
+* Keyboard Macros:: Saving and re-executing typed characters
+* Miscellaneous Commands:: Other miscellaneous commands.
@end menu
@node Commands For Moving
-@subsubsection Commands For Moving
+@subsection Commands For Moving
@ftable @code
@item beginning-of-line (C-a)
Move to the start of the current line.
@@ -364,24 +534,38 @@ Move forward a character.
Move back a character.
@item forward-word (M-f)
-Move forward to the end of the next word.
+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 this, or the previous, word.
+Move back to the start of this, or the previous, word. Words are
+composed of letters and digits.
@item clear-screen (C-l)
-Clear the screen leaving the current line at the top of the screen.
+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
-@subsubsection Commands For Manipulating The History
+@subsection Commands For Manipulating The History
@ftable @code
@item accept-line (Newline, 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 @code{HISTCONTROL} variable. If this line was a 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, add it to the history list. If this line was a history
line, then restore the history line to its original state.
+@end ifclear
@item previous-history (C-p)
Move `up' through the history list.
@@ -393,7 +577,7 @@ Move `down' through the history list.
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 you are entering!
+Move to the end of the input history, i.e., the line you are entering.
@item reverse-search-history (C-r)
Search backward starting at the current line and moving `up' through
@@ -401,17 +585,44 @@ 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 neccessary.
+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 current 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 current 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). 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.
@end ftable
@node Commands For Text
-@subsubsection Commands For Changing Text
+@subsection Commands For Changing Text
@ftable @code
@item delete-char (C-d)
Delete the character under the cursor. If the cursor is at the
-beginning of the line, and there are no characters in the line, and
+beginning of the line, there are no characters in the line, and
the last character typed was not C-d, then return EOF.
@item backward-delete-char (Rubout)
@@ -420,7 +631,7 @@ the characters instead of deleting them.
@item quoted-insert (C-q, C-v)
Add the next character that you type to the line verbatim. This is
-how to insert things like C-q for example.
+how to insert key sequences like @key{C-q}, for example.
@item tab-insert (M-TAB)
Insert a tab character.
@@ -429,9 +640,12 @@ Insert a tab character.
Insert yourself.
@item transpose-chars (C-t)
-Drag the character before point forward over the character at point.
-Point moves forward as well. If point is at the end of the line, then
-transpose the two characters before point. Negative args don't work.
+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 argumentss don't work.
@item transpose-words (M-t)
Drag the word behind the cursor past the word in front of the cursor
@@ -439,47 +653,56 @@ moving the cursor over that word as well.
@item upcase-word (M-u)
Uppercase the current (or following) word. With a negative argument,
-do the previous word, but do not move point.
+do the previous word, but do not move the cursor.
@item downcase-word (M-l)
Lowercase the current (or following) word. With a negative argument,
-do the previous word, but do not move point.
+do the previous word, but do not move the cursor.
@item capitalize-word (M-c)
-Uppercase the current (or following) word. With a negative argument,
-do the previous word, but do not move point.
+Capitalize the current (or following) word. With a negative argument,
+do the previous word, but do not move the cursor.
@end ftable
@node Commands For Killing
-@subsubsection Killing And Yanking
+@subsection Killing And Yanking
@ftable @code
@item kill-line (C-k)
Kill the text from the current cursor position to the end of the line.
-@item backward-kill-line ()
-Kill backward to the beginning of the line. This is normally unbound.
+@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.
+Save the killed text on the kill-ring.
+
+@item kill-whole-line ()
+Kill all characters on the current line, no matter where the
+cursor is. By default, this is unbound.
@item kill-word (M-d)
Kill from the cursor to the end of the current word, or if between
-words, to the end of the next word.
+words, to the end of the next word. Word boundaries are the same
+as @code{forward-word}.
@item backward-kill-word (M-DEL)
-Kill the word behind the cursor.
-
-@item unix-line-discard (C-u)
-Do what C-u used to do in Unix line input. We save the killed text on
-the kill-ring, though.
+Kill the word behind the cursor. Word boundaries are the same
+as @code{backward-word}.
@item unix-word-rubout (C-w)
-Do what C-w used to do in Unix line input. The killed text is saved
-on the kill-ring. This is different than backward-kill-word because
-the word boundaries differ.
+Kill the word behind the cursor, 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 yank (C-y)
-Yank the top of the kill ring into the buffer at point.
+Yank the top of the kill ring into the buffer at the current
+cursor position.
@item yank-pop (M-y)
Rotate the kill-ring, and yank the new top. You can only do this if
@@ -487,7 +710,7 @@ the prior command is yank or yank-pop.
@end ftable
@node Numeric Arguments
-@subsubsection Specifying Numeric Arguments
+@subsection Specifying Numeric Arguments
@ftable @code
@item digit-argument (M-0, M-1, ... M--)
@@ -495,64 +718,148 @@ Add this digit to the argument already accumulating, or start a new
argument. M-- starts a negative argument.
@item universal-argument ()
-Do what C-u does in emacs. By default, this is not bound.
+Each time this is executed, the argument count is multiplied by four.
+The argument count is initially one, so executing this function the
+first time makes the argument count four. By default, this is not
+bound to a key.
@end ftable
-
@node Commands For Completion
-@subsubsection Letting Readline Type For You
+@subsection Letting Readline Type For You
@ftable @code
@item complete (TAB)
-Attempt to do completion on the text before point. This is
+Attempt to do completion on the text before the cursor. This is
implementation defined. Generally, if you are typing a filename
argument, you can do filename completion; if you are typing a command,
you can do command completion, if you are typing in a symbol to GDB, you
can do symbol name completion, if you are typing in a variable to Bash,
-you can do variable name completion...
+you can do variable name completion, and so on.
+@ifset BashFeatures
+See the Bash manual page for a complete list of available completion
+functions.
+@end ifset
@item possible-completions (M-?)
-List the possible completions of the text before point.
+List the possible completions of the text before the cursor.
+
+@item insert-completions ()
+Insert all completions of the text before point that would have
+been generated by @code{possible-completions}. By default, this
+is not bound to a key.
+
+@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
-@subsubsection Some Miscellaneous Commands
+@subsection Some Miscellaneous Commands
@ftable @code
@item re-read-init-file (C-x C-r)
-Read in the contents of your @file{~/.inputrc} file, and incorporate
-any bindings found there.
+Read in the contents of your init file, and incorporate
+any bindings or variable assignments found there.
@item abort (C-g)
-Ding! Stops things.
+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, ...)
-Run the command that is bound to your uppercase brother.
+Run the command that is bound to the corresoponding uppercase
+character.
@item prefix-meta (ESC)
Make the next character that you type be metafied. This is for people
without a meta key. Typing @samp{ESC f} is equivalent to typing
@samp{M-f}.
-@item undo (C-_)
+@item undo (C-_, 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 typing the `undo'
+Undo all changes made to this line. This is like typing the @code{undo}
command enough times to get back to the beginning.
-@end ftable
-@node Readline Vi Mode
-@subsection Readline Vi Mode
+@item tilde-expand (M-~)
+Perform tilde expansion on the current word.
+
+@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.
-While the Readline library does not have a full set of Vi editing
-functions, it does contain enough to allow simple editing of the line.
+@ifset BashFeatures
+@item display-shell-version (C-x C-v)
+Display version information about the current instance of Bash.
-In order to switch interactively between Emacs and Vi editing modes, use
-the command M-C-j (toggle-editing-mode).
+@item shell-expand-line (M-C-e)
+Expand the line the way the shell does when it reads it. This
+performs alias and history expansion as well as all of the shell
+word expansions.
+
+@item history-expand-line (M-^)
+Perform history expansion on the current line.
+
+@item insert-last-argument (M-., M-_)
+Insert the last argument to the previous command (the last word on
+the previous line). 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 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 emacs-editing-mode (C-e)
+When in @code{vi} editing mode, this causes a switch back to
+emacs editing mode, as if the command @code{set -o emacs} had
+been executed.
+
+@end ifset
+
+@end ftable
-When you enter a line in Vi mode, you are already placed in `insertion'
-mode, as if you had typed an `i'. Pressing @key{ESC} switches you into
-`edit' mode, where you can edit the text of the line with the standard
-Vi movement keys, move to previous history lines with `k', and following
-lines with `j', and so forth.
+@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 Posix 1003.2 standard.
+
+@ifset BashFeatures
+In order to switch interactively between @code{Emacs} and @code{Vi}
+editing modes, use the @code{set -o emacs} and @code{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 M-C-j (toggle-editing-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 following lines with @samp{j}, and
+so forth.
diff --git a/gnu/lib/libreadline/doc/texindex.c b/gnu/lib/libreadline/doc/texindex.c
index cb979da..9233bab 100644
--- a/gnu/lib/libreadline/doc/texindex.c
+++ b/gnu/lib/libreadline/doc/texindex.c
@@ -1,9 +1,12 @@
-/* Prepare Tex index dribble output into an actual index.
- Copyright (C) 1987 Free Software Foundation, Inc.
+/* Prepare TeX index dribble output into an actual index.
+
+ Version 1.45
+
+ Copyright (C) 1987, 1991, 1992 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 1, or (at your option)
+ 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,
@@ -13,137 +16,124 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
-extern int errno;
+#include "getopt.h"
+#include "bashansi.h"
-#ifdef VMS
-#ifndef VAX11C
-#define noshare
+#if !defined (errno)
+extern int errno;
#endif
-#include <perror.h>
-#include <file.h>
+#if defined (HAVE_UNISTD_H)
+# include <unistd.h>
+#else /* !HAVE_UNISTD_H */
+extern long lseek ();
+#endif /* !HAVE_UNISTD_H */
-#define EXIT_SUCCESS ((1 << 28) | 1)
-#define EXIT_FATAL ((1 << 28) | 4)
-#define unlink delete
-#define tell(fd) lseek(fd, 0L, 1)
-
-#else /* Not VMS */
+extern char *mktemp ();
-#ifdef USG
-#include <sys/types.h>
-#include <sys/fcntl.h>
+#if !defined (HAVE_STRERROR)
+extern int sys_nerr;
+extern char *sys_errlist[];
#endif
-#include <sys/file.h>
-#define EXIT_SUCCESS 0
-#define EXIT_FATAL 1
+#include <sys/types.h>
-#endif /* Not VMS */
+#if defined (_AIX) || !defined (_POSIX_VERSION)
+# include <sys/file.h>
+#endif
+#include <fcntl.h>
-#ifndef L_XTND
-#define L_XTND 2
-#endif
+#define TI_NO_ERROR 0
+#define TI_FATAL_ERROR 1
-#ifdef VMS
-extern noshare int sys_nerr;
-extern noshare char *sys_errlist[];
-#else
-extern int sys_nerr;
-extern char *sys_errlist[];
-#endif
+#if !defined (SEEK_SET)
+# define SEEK_SET 0
+# define SEEK_CUR 1
+# define SEEK_END 2
+#endif /* !SEEK_SET */
/* When sorting in core, this structure describes one line
- and the position and length of its first keyfield. */
-
+ and the position and length of its first keyfield. */
struct lineinfo
- {
- char *text; /* The actual text of the line */
- union
- { /* The start of the key (for textual comparison) */
- char *text;
- long number; /* or the numeric value (for numeric comparison) */
- } key;
- long keylen; /* Length of key field */
- };
-
-/* This structure describes a field to use as a sort key */
-
+{
+ char *text; /* The actual text of the line. */
+ union {
+ char *text; /* The start of the key (for textual comparison). */
+ long number; /* The numeric value (for numeric comparison). */
+ } key;
+ long keylen; /* Length of KEY field. */
+};
+
+/* This structure describes a field to use as a sort key. */
struct keyfield
- {
- int startwords; /* # words to skip */
- int startchars; /* and # additional chars to skip, to start of field */
- int endwords; /* similar, from beg (or end) of line, to find end of field */
- int endchars;
- char ignore_blanks; /* Ignore spaces and tabs within the field */
- char fold_case; /* Convert upper case to lower before comparing */
- char reverse; /* Compare in reverse order */
- char numeric; /* Parse text as an integer and compare the integers */
- char positional; /* Sort according to position within the file */
- char braced; /* Count balanced-braced groupings as fields */
- };
-
-/* Vector of keyfields to use */
-
+{
+ int startwords; /* Number of words to skip. */
+ int startchars; /* Number of additional chars to skip. */
+ int endwords; /* Number of words to ignore at end. */
+ int endchars; /* Ditto for characters of last word. */
+ char ignore_blanks; /* Non-zero means ignore spaces and tabs. */
+ char fold_case; /* Non-zero means case doesn't matter. */
+ char reverse; /* Non-zero means compare in reverse order. */
+ char numeric; /* Non-zeros means field is ASCII numeric. */
+ char positional; /* Sort according to file position. */
+ char braced; /* Count balanced-braced groupings as fields. */
+};
+
+/* Vector of keyfields to use. */
struct keyfield keyfields[3];
/* Number of keyfields stored in that vector. */
-
int num_keyfields = 3;
-/* Vector of input file names, terminated with a zero (null pointer) */
-
+/* Vector of input file names, terminated with a null pointer. */
char **infiles;
-/* Vector of corresponding output file names, or zero meaning default it */
-
+/* Vector of corresponding output file names, or NULL, meaning default it
+ (add an `s' to the end). */
char **outfiles;
-/* Length of `infiles' */
-
+/* Length of `infiles'. */
int num_infiles;
-/* Pointer to the array of pointers to lines being sorted */
-
+/* Pointer to the array of pointers to lines being sorted. */
char **linearray;
/* The allocated length of `linearray'. */
-
long nlines;
/* Directory to use for temporary files. On Unix, it ends with a slash. */
-
char *tempdir;
/* Start of filename to use for temporary files. */
-
char *tempbase;
/* Number of last temporary file. */
-
int tempcount;
/* Number of last temporary file already deleted.
- Temporary files are deleted by `flush_tempfiles' in order of creation. */
-
+ Temporary files are deleted by `flush_tempfiles' in order of creation. */
int last_deleted_tempcount;
/* During in-core sort, this points to the base of the data block
- which contains all the lines of data. */
-
+ which contains all the lines of data. */
char *text_base;
-/* Additional command switches */
+/* Additional command switches .*/
-int keep_tempfiles; /* Nonzero means do not delete tempfiles -- for debugging */
+/* Nonzero means do not delete tempfiles -- for debugging. */
+int keep_tempfiles;
-/* Forward declarations of functions in this file */
+/* The name this program was run with. */
+char *program_name;
+
+/* Forward declarations of functions in this file. */
void decode_command ();
void sort_in_core ();
@@ -155,20 +145,23 @@ long find_value ();
char *find_braced_pos ();
char *find_braced_end ();
void writelines ();
+int compare_field ();
int compare_full ();
long readline ();
int merge_files ();
int merge_direct ();
+void pfatal_with_name ();
+void fatal ();
+void error ();
+void *xmalloc (), *xrealloc ();
char *concat ();
char *maketempname ();
void flush_tempfiles ();
char *tempcopy ();
-
-extern char *mktemp ();
#define MAX_IN_CORE_SORT 500000
-int
+void
main (argc, argv)
int argc;
char **argv;
@@ -177,21 +170,24 @@ main (argc, argv)
tempcount = 0;
last_deleted_tempcount = 0;
+ program_name = argv[0];
/* Describe the kind of sorting to do. */
- /* The first keyfield uses the first braced field and folds case */
+ /* The first keyfield uses the first braced field and folds case. */
keyfields[0].braced = 1;
keyfields[0].fold_case = 1;
keyfields[0].endwords = -1;
keyfields[0].endchars = -1;
- /* The second keyfield uses the second braced field, numerically */
+
+ /* The second keyfield uses the second braced field, numerically. */
keyfields[1].braced = 1;
keyfields[1].numeric = 1;
keyfields[1].startwords = 1;
keyfields[1].endwords = -1;
keyfields[1].endchars = -1;
+
/* The third keyfield (which is ignored while discarding duplicates)
- compares the whole line */
+ compares the whole line. */
keyfields[2].endwords = -1;
keyfields[2].endchars = -1;
@@ -206,12 +202,13 @@ main (argc, argv)
int desc;
long ptr;
char *outfile;
- char *p;
- desc = open (infiles[i], 0, 0);
- if (desc < 0) pfatal_with_name (infiles[i]);
- lseek (desc, 0, L_XTND);
- ptr = tell (desc);
+ desc = open (infiles[i], O_RDONLY, 0);
+ if (desc < 0)
+ pfatal_with_name (infiles[i]);
+ lseek (desc, 0L, SEEK_END);
+ ptr = lseek (desc, 0L, SEEK_CUR);
+
close (desc);
outfile = outfiles[i];
@@ -221,107 +218,84 @@ main (argc, argv)
}
if (ptr < MAX_IN_CORE_SORT)
- /* Sort a small amount of data */
- sort_in_core (infiles[i], ptr, outfile);
+ /* Sort a small amount of data. */
+ sort_in_core (infiles[i], ptr, outfile);
else
- sort_offline (infiles[i], ptr, outfile);
+ sort_offline (infiles[i], ptr, outfile);
}
flush_tempfiles (tempcount);
- exit (EXIT_SUCCESS);
+ exit (TI_NO_ERROR);
}
-/* This page decodes the command line arguments to set the parameter variables
- and set up the vector of keyfields and the vector of input files */
+void
+usage ()
+{
+ fprintf (stderr, "\
+Usage: %s [-k] infile [-o outfile] ...\n", program_name);
+ exit (1);
+}
+
+/* Decode the command line arguments to set the parameter variables
+ and set up the vector of keyfields and the vector of input files. */
void
decode_command (argc, argv)
int argc;
char **argv;
{
- int i;
+ int optc;
char **ip;
char **op;
- /* Store default values into parameter variables */
+ /* Store default values into parameter variables. */
-#ifdef VMS
- tempdir = "sys$scratch:";
-#else
- tempdir = "/tmp/";
-#endif
+ tempdir = getenv ("TMPDIR");
+ if (tempdir == NULL)
+ tempdir = "/tmp/";
+ else
+ tempdir = concat (tempdir, "/", "");
keep_tempfiles = 0;
- /* Allocate argc input files, which must be enough. */
+ /* Allocate ARGC input files, which must be enough. */
infiles = (char **) xmalloc (argc * sizeof (char *));
outfiles = (char **) xmalloc (argc * sizeof (char *));
ip = infiles;
op = outfiles;
- /* First find all switches that control the default kind-of-sort */
-
- for (i = 1; i < argc; i++)
+ while ((optc = getopt (argc, argv, "-ko:")) != EOF)
{
- int tem = classify_arg (argv[i]);
- char c;
- char *p;
-
- if (tem <= 0)
+ switch (optc)
{
- *ip++ = argv[i];
- *op++ = 0;
- continue;
- }
- if (tem > 1)
- {
- if (i + 1 == argc)
- fatal ("switch %s given with no argument following it", argv[i]);
- else if (!strcmp (argv[i], "-T"))
- tempdir = argv[i + 1];
- else if (!strcmp (argv[i], "-o"))
- *(op - 1) = argv[i + 1];
- i += tem - 1;
- continue;
- }
+ case 1: /* Non-option filename. */
+ *ip++ = optarg;
+ *op++ = NULL;
+ break;
- p = &argv[i][1];
- while (c = *p++)
- switch (c)
- {
- case 'k':
- keep_tempfiles = 1;
- break;
+ case 'k':
+ keep_tempfiles = 1;
+ break;
- default:
- fatal ("invalid command switch %c", c);
- }
- switchdone: ;
- }
+ case 'o':
+ if (op > outfiles)
+ *(op - 1) = optarg;
+ break;
- /* Record number of keyfields, terminate list of filenames */
+ default:
+ usage ();
+ }
+ }
+ /* Record number of keyfields and terminate list of filenames. */
num_infiles = ip - infiles;
*ip = 0;
-}
-
-/* Return 0 for an argument that is not a switch;
- for a switch, return 1 plus the number of following arguments that the switch swallows.
-*/
-
-int
-classify_arg (arg)
- char *arg;
-{
- if (!strcmp (arg, "-T") || !strcmp (arg, "-o"))
- return 2;
- if (arg[0] == '-')
- return 1;
- return 0;
+ if (num_infiles == 0)
+ usage ();
}
-/* Create a name for a temporary file */
+/* Return a name for a temporary file. */
char *
maketempname (count)
@@ -332,18 +306,20 @@ maketempname (count)
return concat (tempdir, tempbase, tempsuffix);
}
-/* Delete all temporary files up to the specified count */
+/* Delete all temporary files up to TO_COUNT. */
void
flush_tempfiles (to_count)
int to_count;
{
- if (keep_tempfiles) return;
+ if (keep_tempfiles)
+ return;
while (last_deleted_tempcount < to_count)
unlink (maketempname (++last_deleted_tempcount));
}
-/* Copy an input file into a temporary file, and return the temporary file name */
+/* Copy the input file open on IDESC into a temporary file
+ and return the temporary file name. */
#define BUFSIZE 1024
@@ -357,13 +333,15 @@ tempcopy (idesc)
odesc = open (outfile, O_WRONLY | O_CREAT, 0666);
- if (odesc < 0) pfatal_with_name (outfile);
+ if (odesc < 0)
+ pfatal_with_name (outfile);
while (1)
{
int nread = read (idesc, buffer, BUFSIZE);
write (odesc, buffer, nread);
- if (!nread) break;
+ if (!nread)
+ break;
}
close (odesc);
@@ -371,8 +349,7 @@ tempcopy (idesc)
return outfile;
}
-/* Compare two lines, provided as pointers to pointers to text,
- according to the specified set of keyfields */
+/* Compare LINE1 and LINE2 according to the specified set of keyfields. */
int
compare_full (line1, line2)
@@ -381,7 +358,8 @@ compare_full (line1, line2)
int i;
/* Compare using the first keyfield;
- if that does not distinguish the lines, try the second keyfield; and so on. */
+ if that does not distinguish the lines, try the second keyfield;
+ and so on. */
for (i = 0; i < num_keyfields; i++)
{
@@ -389,22 +367,22 @@ compare_full (line1, line2)
char *start1 = find_field (&keyfields[i], *line1, &length1);
char *start2 = find_field (&keyfields[i], *line2, &length2);
int tem = compare_field (&keyfields[i], start1, length1, *line1 - text_base,
- start2, length2, *line2 - text_base);
+ start2, length2, *line2 - text_base);
if (tem)
{
if (keyfields[i].reverse)
- return - tem;
- return tem;
+ return -tem;
+ return tem;
}
}
- return 0; /* Lines match exactly */
+ return 0; /* Lines match exactly. */
}
-/* Compare two lines described by structures
- in which the first keyfield is identified in advance.
- For positional sorting, assumes that the order of the lines in core
- reflects their nominal order. */
+/* Compare LINE1 and LINE2, described by structures
+ in which the first keyfield is identified in advance.
+ For positional sorting, assumes that the order of the lines in core
+ reflects their nominal order. */
int
compare_prepared (line1, line2)
@@ -414,7 +392,7 @@ compare_prepared (line1, line2)
int tem;
char *text1, *text2;
- /* Compare using the first keyfield, which has been found for us already */
+ /* Compare using the first keyfield, which has been found for us already. */
if (keyfields->positional)
{
if (line1->text - text_base > line2->text - text_base)
@@ -425,11 +403,12 @@ compare_prepared (line1, line2)
else if (keyfields->numeric)
tem = line1->key.number - line2->key.number;
else
- tem = compare_field (keyfields, line1->key.text, line1->keylen, 0, line2->key.text, line2->keylen, 0);
+ tem = compare_field (keyfields, line1->key.text, line1->keylen, 0,
+ line2->key.text, line2->keylen, 0);
if (tem)
{
if (keyfields->reverse)
- return - tem;
+ return -tem;
return tem;
}
@@ -437,7 +416,8 @@ compare_prepared (line1, line2)
text2 = line2->text;
/* Compare using the second keyfield;
- if that does not distinguish the lines, try the third keyfield; and so on. */
+ if that does not distinguish the lines, try the third keyfield;
+ and so on. */
for (i = 1; i < num_keyfields; i++)
{
@@ -445,22 +425,22 @@ compare_prepared (line1, line2)
char *start1 = find_field (&keyfields[i], text1, &length1);
char *start2 = find_field (&keyfields[i], text2, &length2);
int tem = compare_field (&keyfields[i], start1, length1, text1 - text_base,
- start2, length2, text2 - text_base);
+ start2, length2, text2 - text_base);
if (tem)
{
if (keyfields[i].reverse)
- return - tem;
- return tem;
+ return -tem;
+ return tem;
}
}
- return 0; /* Lines match exactly */
+ return 0; /* Lines match exactly. */
}
/* Like compare_full but more general.
- You can pass any strings, and you can say how many keyfields to use.
- `pos1' and `pos2' should indicate the nominal positional ordering of
- the two lines in the input. */
+ You can pass any strings, and you can say how many keyfields to use.
+ POS1 and POS2 should indicate the nominal positional ordering of
+ the two lines in the input. */
int
compare_general (str1, str2, pos1, pos2, use_keyfields)
@@ -471,28 +451,30 @@ compare_general (str1, str2, pos1, pos2, use_keyfields)
int i;
/* Compare using the first keyfield;
- if that does not distinguish the lines, try the second keyfield; and so on. */
+ if that does not distinguish the lines, try the second keyfield;
+ and so on. */
for (i = 0; i < use_keyfields; i++)
{
long length1, length2;
char *start1 = find_field (&keyfields[i], str1, &length1);
char *start2 = find_field (&keyfields[i], str2, &length2);
- int tem = compare_field (&keyfields[i], start1, length1, pos1, start2, length2, pos2);
+ int tem = compare_field (&keyfields[i], start1, length1, pos1,
+ start2, length2, pos2);
if (tem)
{
if (keyfields[i].reverse)
- return - tem;
- return tem;
+ return -tem;
+ return tem;
}
}
- return 0; /* Lines match exactly */
+ return 0; /* Lines match exactly. */
}
-/* Find the start and length of a field in `str' according to `keyfield'.
- A pointer to the starting character is returned, and the length
- is stored into the int that `lengthptr' points to. */
+/* Find the start and length of a field in STR according to KEYFIELD.
+ A pointer to the starting character is returned, and the length
+ is stored into the int that LENGTHPTR points to. */
char *
find_field (keyfield, str, lengthptr)
@@ -504,11 +486,13 @@ find_field (keyfield, str, lengthptr)
char *end;
char *(*fun) ();
- if (keyfield->braced) fun = find_braced_pos;
- else fun = find_pos;
+ if (keyfield->braced)
+ fun = find_braced_pos;
+ else
+ fun = find_pos;
- start = ( *fun )(str, keyfield->startwords, keyfield->startchars,
- keyfield->ignore_blanks);
+ start = (*fun) (str, keyfield->startwords, keyfield->startchars,
+ keyfield->ignore_blanks);
if (keyfield->endwords < 0)
{
if (keyfield->braced)
@@ -516,22 +500,24 @@ find_field (keyfield, str, lengthptr)
else
{
end = start;
- while (*end && *end != '\n') end++;
+ while (*end && *end != '\n')
+ end++;
}
}
else
{
- end = ( *fun )(str, keyfield->endwords, keyfield->endchars, 0);
- if (end - str < start - str) end = start;
+ end = (*fun) (str, keyfield->endwords, keyfield->endchars, 0);
+ if (end - str < start - str)
+ end = start;
}
*lengthptr = end - start;
return start;
}
-/* Find a pointer to a specified place within `str',
- skipping (from the beginning) `words' words and then `chars' chars.
- If `ignore_blanks' is nonzero, we skip all blanks
- after finding the specified word. */
+/* Return a pointer to a specified place within STR,
+ skipping (from the beginning) WORDS words and then CHARS chars.
+ If IGNORE_BLANKS is nonzero, we skip all blanks
+ after finding the specified word. */
char *
find_pos (str, words, chars, ignore_blanks)
@@ -546,23 +532,28 @@ find_pos (str, words, chars, ignore_blanks)
{
char c;
/* Find next bunch of nonblanks and skip them. */
- while ((c = *p) == ' ' || c == '\t') p++;
- while ((c = *p) && c != '\n' && !(c == ' ' || c == '\t')) p++;
- if (!*p || *p == '\n') return p;
+ while ((c = *p) == ' ' || c == '\t')
+ p++;
+ while ((c = *p) && c != '\n' && !(c == ' ' || c == '\t'))
+ p++;
+ if (!*p || *p == '\n')
+ return p;
}
- while (*p == ' ' || *p == '\t') p++;
+ while (*p == ' ' || *p == '\t')
+ p++;
for (i = 0; i < chars; i++)
{
- if (!*p || *p == '\n') break;
+ if (!*p || *p == '\n')
+ break;
p++;
}
return p;
}
/* Like find_pos but assumes that each field is surrounded by braces
- and that braces within fields are balanced. */
+ and that braces within fields are balanced. */
char *
find_braced_pos (str, words, chars, ignore_blanks)
@@ -578,39 +569,43 @@ find_braced_pos (str, words, chars, ignore_blanks)
for (i = 0; i < words; i++)
{
bracelevel = 1;
- while ((c = *p++) != '{' && c != '\n' && c);
+ while ((c = *p++) != '{' && c != '\n' && c)
+ /* Do nothing. */ ;
if (c != '{')
return p - 1;
while (bracelevel)
{
c = *p++;
- if (c == '{') bracelevel++;
- if (c == '}') bracelevel--;
-#if 0
- if (c == '\\' || c == '@') c = *p++; /* \ quotes braces and \ */
-#endif
- if (c == 0 || c == '\n') return p-1;
+ if (c == '{')
+ bracelevel++;
+ if (c == '}')
+ bracelevel--;
+ if (c == 0 || c == '\n')
+ return p - 1;
}
}
- while ((c = *p++) != '{' && c != '\n' && c);
+ while ((c = *p++) != '{' && c != '\n' && c)
+ /* Do nothing. */ ;
if (c != '{')
- return p-1;
+ return p - 1;
if (ignore_blanks)
- while ((c = *p) == ' ' || c == '\t') p++;
-
+ while ((c = *p) == ' ' || c == '\t')
+ p++;
+
for (i = 0; i < chars; i++)
{
- if (!*p || *p == '\n') break;
+ if (!*p || *p == '\n')
+ break;
p++;
}
return p;
}
-/* Find the end of the balanced-brace field which starts at `str'.
- The position returned is just before the closing brace. */
+/* Find the end of the balanced-brace field which starts at STR.
+ The position returned is just before the closing brace. */
char *
find_braced_end (str)
@@ -624,12 +619,12 @@ find_braced_end (str)
while (bracelevel)
{
c = *p++;
- if (c == '{') bracelevel++;
- if (c == '}') bracelevel--;
-#if 0
- if (c == '\\' || c == '@') c = *p++;
-#endif
- if (c == 0 || c == '\n') return p-1;
+ if (c == '{')
+ bracelevel++;
+ if (c == '}')
+ bracelevel--;
+ if (c == 0 || c == '\n')
+ return p - 1;
}
return p - 1;
}
@@ -639,12 +634,13 @@ find_value (start, length)
char *start;
long length;
{
- while (length != 0L) {
- if (isdigit(*start))
- return atol(start);
- length--;
- start++;
- }
+ while (length != 0L)
+ {
+ if (isdigit (*start))
+ return atol (start);
+ length--;
+ start++;
+ }
return 0l;
}
@@ -653,6 +649,7 @@ find_value (start, length)
and ignore case in the first sorting. */
int char_order[256];
+void
init_char_order ()
{
int i;
@@ -662,14 +659,16 @@ init_char_order ()
for (i = '0'; i <= '9'; i++)
char_order[i] += 512;
- for (i = 'a'; i <= 'z'; i++) {
- char_order[i] = 512 + i;
- char_order[i + 'A' - 'a'] = 512 + i;
- }
+ for (i = 'a'; i <= 'z'; i++)
+ {
+ char_order[i] = 512 + i;
+ char_order[i + 'A' - 'a'] = 512 + i;
+ }
}
/* Compare two fields (each specified as a start pointer and a character count)
- according to `keyfield'. The sign of the value reports the relation between the fields */
+ according to KEYFIELD.
+ The sign of the value reports the relation between the fields. */
int
compare_field (keyfield, start1, length1, pos1, start2, length2, pos2)
@@ -690,9 +689,11 @@ compare_field (keyfield, start1, length1, pos1, start2, length2, pos2)
}
if (keyfield->numeric)
{
- long value = find_value (start1, length1) - find_value (start2, length2);
- if (value > 0) return 1;
- if (value < 0) return -1;
+ long value = find_value (start1, length1) - find_value (start2, length2);
+ if (value > 0)
+ return 1;
+ if (value < 0)
+ return -1;
return 0;
}
else
@@ -702,20 +703,23 @@ compare_field (keyfield, start1, length1, pos1, start2, length2, pos2)
char *e1 = start1 + length1;
char *e2 = start2 + length2;
- int fold_case = keyfield->fold_case;
-
while (1)
{
int c1, c2;
- if (p1 == e1) c1 = 0;
- else c1 = *p1++;
- if (p2 == e2) c2 = 0;
- else c2 = *p2++;
+ if (p1 == e1)
+ c1 = 0;
+ else
+ c1 = *p1++;
+ if (p2 == e2)
+ c2 = 0;
+ else
+ c2 = *p2++;
if (char_order[c1] != char_order[c2])
return char_order[c1] - char_order[c2];
- if (!c1) break;
+ if (!c1)
+ break;
}
/* Strings are equal except possibly for case. */
@@ -725,15 +729,20 @@ compare_field (keyfield, start1, length1, pos1, start2, length2, pos2)
{
int c1, c2;
- if (p1 == e1) c1 = 0;
- else c1 = *p1++;
- if (p2 == e2) c2 = 0;
- else c2 = *p2++;
+ if (p1 == e1)
+ c1 = 0;
+ else
+ c1 = *p1++;
+ if (p2 == e2)
+ c2 = 0;
+ else
+ c2 = *p2++;
if (c1 != c2)
/* Reverse sign here so upper case comes out last. */
return c2 - c1;
- if (!c1) break;
+ if (!c1)
+ break;
}
return 0;
@@ -741,16 +750,16 @@ compare_field (keyfield, start1, length1, pos1, start2, length2, pos2)
}
/* A `struct linebuffer' is a structure which holds a line of text.
- `readline' reads a line from a stream into a linebuffer
- and works regardless of the length of the line. */
+ `readline' reads a line from a stream into a linebuffer
+ and works regardless of the length of the line. */
struct linebuffer
- {
- long size;
- char *buffer;
- };
+{
+ long size;
+ char *buffer;
+};
-/* Initialize a linebuffer for use */
+/* Initialize LINEBUFFER for use. */
void
initbuffer (linebuffer)
@@ -760,8 +769,8 @@ initbuffer (linebuffer)
linebuffer->buffer = (char *) xmalloc (200);
}
-/* Read a line of text from `stream' into `linebuffer'.
- Return the length of the line. */
+/* Read a line of text from STREAM into LINEBUFFER.
+ Return the length of the line. */
long
readline (linebuffer, stream)
@@ -798,10 +807,12 @@ readline (linebuffer, stream)
void
sort_offline (infile, nfiles, total, outfile)
char *infile;
+ int nfiles;
long total;
char *outfile;
{
- int ntemps = 2 * (total + MAX_IN_CORE_SORT - 1) / MAX_IN_CORE_SORT; /* More than enough */
+ /* More than enough. */
+ int ntemps = 2 * (total + MAX_IN_CORE_SORT - 1) / MAX_IN_CORE_SORT;
char **tempfiles = (char **) xmalloc (ntemps * sizeof (char *));
FILE *istream = fopen (infile, "r");
int i;
@@ -822,7 +833,7 @@ sort_offline (infile, nfiles, total, outfile)
}
/* Split up the input into `ntemps' temporary files, or maybe fewer,
- and put the new files' names into `tempfiles' */
+ and put the new files' names into `tempfiles' */
for (i = 0; i < ntemps; i++)
{
@@ -830,11 +841,12 @@ sort_offline (infile, nfiles, total, outfile)
FILE *ostream = fopen (outname, "w");
long tempsize = 0;
- if (!ostream) pfatal_with_name (outname);
+ if (!ostream)
+ pfatal_with_name (outname);
tempfiles[i] = outname;
- /* Copy lines into this temp file as long as it does not make file "too big"
- or until there are no more lines. */
+ /* Copy lines into this temp file as long as it does not make file
+ "too big" or until there are no more lines. */
while (tempsize + linelength + 1 <= MAX_IN_CORE_SORT)
{
@@ -845,7 +857,8 @@ sort_offline (infile, nfiles, total, outfile)
/* Read another line of input data. */
linelength = readline (&lb, istream);
- if (!linelength && feof (istream)) break;
+ if (!linelength && feof (istream))
+ break;
if (lb.buffer[0] != '\\' && lb.buffer[0] != '@')
{
@@ -855,39 +868,41 @@ sort_offline (infile, nfiles, total, outfile)
}
}
fclose (ostream);
- if (feof (istream)) break;
+ if (feof (istream))
+ break;
}
free (lb.buffer);
- fail:
+fail:
/* Record number of temp files we actually needed. */
ntemps = i;
/* Sort each tempfile into another tempfile.
- Delete the first set of tempfiles and put the names of the second into `tempfiles' */
+ Delete the first set of tempfiles and put the names of the second
+ into `tempfiles'. */
for (i = 0; i < ntemps; i++)
{
char *newtemp = maketempname (++tempcount);
sort_in_core (&tempfiles[i], MAX_IN_CORE_SORT, newtemp);
if (!keep_tempfiles)
- unlink (tempfiles[i]);
+ unlink (tempfiles[i]);
tempfiles[i] = newtemp;
}
if (failure)
return;
- /* Merge the tempfiles together and indexify */
+ /* Merge the tempfiles together and indexify. */
merge_files (tempfiles, ntemps, outfile);
}
-/* Sort `infile', whose size is `total',
- assuming that is small enough to be done in-core,
- then indexify it and send the output to `outfile' (or to stdout). */
+/* Sort INFILE, whose size is TOTAL,
+ assuming that is small enough to be done in-core,
+ then indexify it and send the output to OUTFILE (or to stdout). */
void
sort_in_core (infile, total, outfile)
@@ -903,15 +918,16 @@ sort_in_core (infile, total, outfile)
FILE *ostream = stdout;
struct lineinfo *lineinfo;
- /* Read the contents of the file into the moby array `data' */
+ /* Read the contents of the file into the moby array `data'. */
- int desc = open (infile, 0, 0);
+ int desc = open (infile, O_RDONLY, 0);
if (desc < 0)
fatal ("failure reopening %s", infile);
- for (file_size = 0; ; )
+ for (file_size = 0;;)
{
- if ((i = read (desc, data + file_size, total - file_size)) <= 0)
+ i = read (desc, data + file_size, total - file_size);
+ if (i <= 0)
break;
file_size += i;
}
@@ -928,14 +944,16 @@ sort_in_core (infile, total, outfile)
init_char_order ();
- /* Sort routines want to know this address */
+ /* Sort routines want to know this address. */
text_base = data;
- /* Create the array of pointers to lines, with a default size frequently enough. */
+ /* Create the array of pointers to lines, with a default size
+ frequently enough. */
nlines = total / 50;
- if (!nlines) nlines = 2;
+ if (!nlines)
+ nlines = 2;
linearray = (char **) xmalloc (nlines * sizeof (char *));
/* `nextline' points to the next free slot in this array.
@@ -952,11 +970,11 @@ sort_in_core (infile, total, outfile)
return;
}
- /* Sort the lines */
+ /* Sort the lines. */
/* If we have enough space, find the first keyfield of each line in advance.
- Make a `struct lineinfo' for each line, which records the keyfield
- as well as the line, and sort them. */
+ Make a `struct lineinfo' for each line, which records the keyfield
+ as well as the line, and sort them. */
lineinfo = (struct lineinfo *) malloc ((nextline - linearray) * sizeof (struct lineinfo));
@@ -983,7 +1001,7 @@ sort_in_core (infile, total, outfile)
else
qsort (linearray, nextline - linearray, sizeof (char *), compare_full);
- /* Open the output file */
+ /* Open the output file. */
if (outfile)
{
@@ -993,7 +1011,8 @@ sort_in_core (infile, total, outfile)
}
writelines (linearray, nextline - linearray, ostream);
- if (outfile) fclose (ostream);
+ if (outfile)
+ fclose (ostream);
free (linearray);
free (data);
@@ -1025,8 +1044,10 @@ parsefile (filename, nextline, data, size)
return 0;
*line = p;
- while (*p && *p != '\n') p++;
- if (p != end) p++;
+ while (*p && *p != '\n')
+ p++;
+ if (p != end)
+ p++;
line++;
if (line == linearray + nlines)
@@ -1041,42 +1062,42 @@ parsefile (filename, nextline, data, size)
}
/* Indexification is a filter applied to the sorted lines
- as they are being written to the output file.
- Multiple entries for the same name, with different page numbers,
- get combined into a single entry with multiple page numbers.
- The first braced field, which is used for sorting, is discarded.
- However, its first character is examined, folded to lower case,
- and if it is different from that in the previous line fed to us
- a \initial line is written with one argument, the new initial.
-
- If an entry has four braced fields, then the second and third
- constitute primary and secondary names.
- In this case, each change of primary name
- generates a \primary line which contains only the primary name,
- and in between these are \secondary lines which contain
- just a secondary name and page numbers.
-*/
+ as they are being written to the output file.
+ Multiple entries for the same name, with different page numbers,
+ get combined into a single entry with multiple page numbers.
+ The first braced field, which is used for sorting, is discarded.
+ However, its first character is examined, folded to lower case,
+ and if it is different from that in the previous line fed to us
+ a \initial line is written with one argument, the new initial.
+
+ If an entry has four braced fields, then the second and third
+ constitute primary and secondary names.
+ In this case, each change of primary name
+ generates a \primary line which contains only the primary name,
+ and in between these are \secondary lines which contain
+ just a secondary name and page numbers. */
/* The last primary name we wrote a \primary entry for.
- If only one level of indexing is being done, this is the last name seen */
+ If only one level of indexing is being done, this is the last name seen. */
char *lastprimary;
-int lastprimarylength; /* Length of storage allocated for lastprimary */
+/* Length of storage allocated for lastprimary. */
+int lastprimarylength;
/* Similar, for the secondary name. */
char *lastsecondary;
int lastsecondarylength;
/* Zero if we are not in the middle of writing an entry.
- One if we have written the beginning of an entry but have not
- yet written any page numbers into it.
- Greater than one if we have written the beginning of an entry
- plus at least one page number. */
+ One if we have written the beginning of an entry but have not
+ yet written any page numbers into it.
+ Greater than one if we have written the beginning of an entry
+ plus at least one page number. */
int pending;
/* The initial (for sorting purposes) of the last primary entry written.
- When this changes, a \initial {c} line is written */
+ When this changes, a \initial {c} line is written */
-char * lastinitial;
+char *lastinitial;
int lastinitiallength;
@@ -1085,7 +1106,17 @@ int lastinitiallength;
char lastinitial1[2];
-/* Initialize static storage for writing an index */
+/* Initialize static storage for writing an index. */
+
+static void
+xbzero(s, n)
+ char *s;
+ int n;
+{
+ register char *p;
+ for (p = s; n--; )
+ *p++ = '\0';
+}
void
init_index ()
@@ -1097,35 +1128,35 @@ init_index ()
lastinitiallength = 0;
lastprimarylength = 100;
lastprimary = (char *) xmalloc (lastprimarylength + 1);
- bzero (lastprimary, lastprimarylength + 1);
+ xbzero (lastprimary, lastprimarylength + 1);
lastsecondarylength = 100;
lastsecondary = (char *) xmalloc (lastsecondarylength + 1);
- bzero (lastsecondary, lastsecondarylength + 1);
+ xbzero (lastsecondary, lastsecondarylength + 1);
}
/* Indexify. Merge entries for the same name,
- insert headers for each initial character, etc. */
+ insert headers for each initial character, etc. */
+void
indexify (line, ostream)
char *line;
FILE *ostream;
{
char *primary, *secondary, *pagenumber;
- int primarylength, secondarylength, pagelength;
- int len = strlen (line);
+ int primarylength, secondarylength = 0, pagelength;
int nosecondary;
int initiallength;
char *initial;
char initial1[2];
register char *p;
- /* First, analyze the parts of the entry fed to us this time */
+ /* First, analyze the parts of the entry fed to us this time. */
p = find_braced_pos (line, 0, 0, 0);
if (*p == '{')
{
initial = p;
- /* Get length of inner pair of braces starting at p,
+ /* Get length of inner pair of braces starting at `p',
including that inner pair of braces. */
initiallength = find_braced_end (p + 1) + 1 - p;
}
@@ -1153,17 +1184,18 @@ indexify (line, ostream)
if (!nosecondary)
secondarylength = find_braced_end (secondary) - secondary;
- /* If the primary is different from before, make a new primary entry */
+ /* If the primary is different from before, make a new primary entry. */
if (strncmp (primary, lastprimary, primarylength))
{
- /* Close off current secondary entry first, if one is open */
+ /* Close off current secondary entry first, if one is open. */
if (pending)
{
fputs ("}\n", ostream);
pending = 0;
}
- /* If this primary has a different initial, include an entry for the initial */
+ /* If this primary has a different initial, include an entry for
+ the initial. */
if (initiallength != lastinitiallength ||
strncmp (initial, lastinitial, initiallength))
{
@@ -1196,26 +1228,26 @@ indexify (line, ostream)
else
fputs ("}\n", ostream);
- /* Record name of most recent primary */
+ /* Record name of most recent primary. */
if (lastprimarylength < primarylength)
{
- lastprimarylength = primarylength + 100;
+ lastprimarylength = primarylength + 100;
lastprimary = (char *) xrealloc (lastprimary,
1 + lastprimarylength);
}
strncpy (lastprimary, primary, primarylength);
lastprimary[primarylength] = 0;
- /* There is no current secondary within this primary, now */
+ /* There is no current secondary within this primary, now. */
lastsecondary[0] = 0;
}
- /* Should not have an entry with no subtopic following one with a subtopic */
+ /* Should not have an entry with no subtopic following one with a subtopic. */
if (nosecondary && *lastsecondary)
error ("entry %s follows an entry with a secondary name", line);
- /* Start a new secondary entry if necessary */
+ /* Start a new secondary entry if necessary. */
if (!nosecondary && strncmp (secondary, lastsecondary, secondarylength))
{
if (pending)
@@ -1230,24 +1262,24 @@ indexify (line, ostream)
fputs ("}{", ostream);
pending = 1;
- /* Record name of most recent secondary */
+ /* Record name of most recent secondary. */
if (lastsecondarylength < secondarylength)
{
- lastsecondarylength = secondarylength + 100;
+ lastsecondarylength = secondarylength + 100;
lastsecondary = (char *) xrealloc (lastsecondary,
- 1 + lastsecondarylength);
+ 1 + lastsecondarylength);
}
strncpy (lastsecondary, secondary, secondarylength);
lastsecondary[secondarylength] = 0;
}
- /* Here to add one more page number to the current entry */
+ /* Here to add one more page number to the current entry. */
if (pending++ != 1)
- fputs (", ", ostream); /* Punctuate first, if this is not the first */
+ fputs (", ", ostream); /* Punctuate first, if this is not the first. */
fwrite (pagenumber, pagelength, 1, ostream);
}
-/* Close out any unfinished output entry */
+/* Close out any unfinished output entry. */
void
finish_index (ostream)
@@ -1260,7 +1292,7 @@ finish_index (ostream)
}
/* Copy the lines in the sorted order.
- Each line is copied out of the input file it was found in. */
+ Each line is copied out of the input file it was found in. */
void
writelines (linearray, nlines, ostream)
@@ -1273,19 +1305,22 @@ writelines (linearray, nlines, ostream)
init_index ();
- /* Output the text of the lines, and free the buffer space */
+ /* Output the text of the lines, and free the buffer space. */
for (next_line = linearray; next_line != stop_line; next_line++)
{
/* If -u was specified, output the line only if distinct from previous one. */
if (next_line == linearray
- /* Compare previous line with this one, using only the explicitly specd keyfields */
+ /* Compare previous line with this one, using only the
+ explicitly specd keyfields. */
|| compare_general (*(next_line - 1), *next_line, 0L, 0L, num_keyfields - 1))
{
char *p = *next_line;
char c;
- while ((c = *p++) && c != '\n');
- *(p-1) = 0;
+
+ while ((c = *p++) && c != '\n')
+ /* Do nothing. */ ;
+ *(p - 1) = 0;
indexify (*next_line, ostream);
}
}
@@ -1294,10 +1329,11 @@ writelines (linearray, nlines, ostream)
}
/* Assume (and optionally verify) that each input file is sorted;
- merge them and output the result.
- Returns nonzero if any input file fails to be sorted.
+ merge them and output the result.
+ Returns nonzero if any input file fails to be sorted.
- This is the high-level interface that can handle an unlimited number of files. */
+ This is the high-level interface that can handle an unlimited
+ number of files. */
#define MAX_DIRECT_MERGE 10
@@ -1342,15 +1378,15 @@ merge_files (infiles, nfiles, outfile)
free (tempfiles);
return value;
-}
+}
/* Assume (and optionally verify) that each input file is sorted;
- merge them and output the result.
- Returns nonzero if any input file fails to be sorted.
+ merge them and output the result.
+ Returns nonzero if any input file fails to be sorted.
- This version of merging will not work if the number of
- input files gets too high. Higher level functions
- use it only with a bounded number of input files. */
+ This version of merging will not work if the number of
+ input files gets too high. Higher level functions
+ use it only with a bounded number of input files. */
int
merge_direct (infiles, nfiles, outfile)
@@ -1358,7 +1394,6 @@ merge_direct (infiles, nfiles, outfile)
int nfiles;
char *outfile;
{
- char **ip = infiles;
struct linebuffer *lb1, *lb2;
struct linebuffer **thisline, **prevline;
FILE **streams;
@@ -1373,14 +1408,15 @@ merge_direct (infiles, nfiles, outfile)
{
ostream = fopen (outfile, "w");
}
- if (!ostream) pfatal_with_name (outfile);
+ if (!ostream)
+ pfatal_with_name (outfile);
init_index ();
if (nfiles == 0)
{
if (outfile)
- fclose (ostream);
+ fclose (ostream);
return 0;
}
@@ -1392,22 +1428,26 @@ merge_direct (infiles, nfiles, outfile)
while `prevline' holds the last file line used,
which is remembered so that we can verify that the file is properly sorted. */
- /* lb1 and lb2 contain one buffer each per file */
+ /* lb1 and lb2 contain one buffer each per file. */
lb1 = (struct linebuffer *) xmalloc (nfiles * sizeof (struct linebuffer));
lb2 = (struct linebuffer *) xmalloc (nfiles * sizeof (struct linebuffer));
/* thisline[i] points to the linebuffer holding the next available line in file i,
or is zero if there are no lines left in that file. */
- thisline = (struct linebuffer **) xmalloc (nfiles * sizeof (struct linebuffer *));
- /* prevline[i] points to the linebuffer holding the last used line from file i.
- This is just for verifying that file i is properly sorted. */
- prevline = (struct linebuffer **) xmalloc (nfiles * sizeof (struct linebuffer *));
+ thisline = (struct linebuffer **)
+ xmalloc (nfiles * sizeof (struct linebuffer *));
+ /* prevline[i] points to the linebuffer holding the last used line
+ from file i. This is just for verifying that file i is properly
+ sorted. */
+ prevline = (struct linebuffer **)
+ xmalloc (nfiles * sizeof (struct linebuffer *));
/* streams[i] holds the input stream for file i. */
streams = (FILE **) xmalloc (nfiles * sizeof (FILE *));
- /* file_lossage[i] is nonzero if we already know file i is not properly sorted. */
+ /* file_lossage[i] is nonzero if we already know file i is not
+ properly sorted. */
file_lossage = (int *) xmalloc (nfiles * sizeof (int));
- /* Allocate and initialize all that storage */
+ /* Allocate and initialize all that storage. */
for (i = 0; i < nfiles; i++)
{
@@ -1423,7 +1463,7 @@ merge_direct (infiles, nfiles, outfile)
readline (thisline[i], streams[i]);
}
- /* Keep count of number of files not at eof */
+ /* Keep count of number of files not at eof. */
nleft = nfiles;
while (nleft)
@@ -1440,21 +1480,24 @@ merge_direct (infiles, nfiles, outfile)
if (thisline[i] &&
(!best ||
0 < compare_general (best->buffer, thisline[i]->buffer,
- (long) bestfile, (long) i, num_keyfields)))
+ (long) bestfile, (long) i, num_keyfields)))
{
best = thisline[i];
bestfile = i;
}
}
- /* Output that line, unless it matches the previous one and we don't want duplicates */
+ /* Output that line, unless it matches the previous one and we
+ don't want duplicates. */
if (!(prev_out &&
- !compare_general (prev_out->buffer, best->buffer, 0L, 1L, num_keyfields - 1)))
+ !compare_general (prev_out->buffer,
+ best->buffer, 0L, 1L, num_keyfields - 1)))
indexify (best->buffer, ostream);
prev_out = best;
- /* Now make the line the previous of its file, and fetch a new line from that file */
+ /* Now make the line the previous of its file, and fetch a new
+ line from that file. */
exch = prevline[bestfile];
prevline[bestfile] = thisline[bestfile];
@@ -1462,22 +1505,24 @@ merge_direct (infiles, nfiles, outfile)
while (1)
{
- /* If the file has no more, mark it empty */
+ /* If the file has no more, mark it empty. */
if (feof (streams[bestfile]))
{
thisline[bestfile] = 0;
- nleft--; /* Update the number of files still not empty */
+ /* Update the number of files still not empty. */
+ nleft--;
break;
}
readline (thisline[bestfile], streams[bestfile]);
- if (thisline[bestfile]->buffer[0] || !feof (streams[bestfile])) break;
+ if (thisline[bestfile]->buffer[0] || !feof (streams[bestfile]))
+ break;
}
}
finish_index (ostream);
- /* Free all storage and close all input streams */
+ /* Free all storage and close all input streams. */
for (i = 0; i < nfiles; i++)
{
@@ -1500,48 +1545,64 @@ merge_direct (infiles, nfiles, outfile)
/* Print error message and exit. */
+void
fatal (s1, s2)
char *s1, *s2;
{
error (s1, s2);
- exit (EXIT_FATAL);
+ exit (TI_FATAL_ERROR);
}
-/* Print error message. `s1' is printf control string, `s2' is arg for it. */
+/* Print error message. S1 is printf control string, S2 is arg for it. */
+void
error (s1, s2)
char *s1, *s2;
{
- printf ("texindex: ");
+ printf ("%s: ", program_name);
printf (s1, s2);
printf ("\n");
}
+#if !defined (HAVE_STRERROR)
+static char *
+strerror (n)
+ int n;
+{
+ static char ebuf[40];
+
+ if (n < sys_nerr)
+ return sys_errlist[n];
+ else
+ {
+ sprintf (ebuf, "Unknown error %d", n);
+ return ebuf;
+ }
+}
+#endif
+
+void
perror_with_name (name)
char *name;
{
char *s;
- if (errno < sys_nerr)
- s = concat ("", sys_errlist[errno], " for %s");
- else
- s = "cannot open %s";
+ s = concat ("", strerror (errno), " for %s");
error (s, name);
}
+void
pfatal_with_name (name)
char *name;
{
char *s;
- if (errno < sys_nerr)
- s = concat ("", sys_errlist[errno], " for %s");
- else
- s = "cannot open %s";
+ s = concat ("", strerror (errno), " for %s");
fatal (s, name);
}
-/* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
+/* Return a newly-allocated string whose contents concatenate those of
+ S1, S2, S3. */
char *
concat (s1, s2, s3)
@@ -1558,49 +1619,48 @@ concat (s1, s2, s3)
return result;
}
-/* Like malloc but get fatal error if memory is exhausted. */
-
-int
-xmalloc (size)
- int size;
+/* Just like malloc, but kills the program in case of fatal error. */
+void *
+xmalloc (nbytes)
+ int nbytes;
{
- int result = malloc (size);
- if (!result)
- fatal ("virtual memory exhausted", 0);
- return result;
-}
+ void *temp = (void *) malloc (nbytes);
+ if (nbytes && temp == (void *)NULL)
+ memory_error ("xmalloc", nbytes);
-int
-xrealloc (ptr, size)
- char *ptr;
- int size;
+ return (temp);
+}
+
+/* Like realloc (), but barfs if there isn't enough memory. */
+void *
+xrealloc (pointer, nbytes)
+ void *pointer;
+ int nbytes;
{
- int result = realloc (ptr, size);
- if (!result)
- fatal ("virtual memory exhausted");
- return result;
+ void *temp;
+
+ if (!pointer)
+ temp = (void *)xmalloc (nbytes);
+ else
+ temp = (void *)realloc (pointer, nbytes);
+
+ if (nbytes && !temp)
+ memory_error ("xrealloc", nbytes);
+
+ return (temp);
}
-bzero (b, length)
- register char *b;
- register int length;
+memory_error (callers_name, bytes_wanted)
+ char *callers_name;
+ int bytes_wanted;
{
-#ifdef VMS
- short zero = 0;
- long max_str = 65535;
- long len;
+ char printable_string[80];
- while (length > max_str)
- {
- (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b);
- length -= max_str;
- b += max_str;
- }
- len = length;
- (void) LIB$MOVC5 (&zero, &zero, &zero, &len, b);
-#else
- while (length-- > 0)
- *b++ = 0;
-#endif /* not VMS */
+ sprintf (printable_string,
+ "Virtual memory exhausted in %s ()! Needed %d bytes.",
+ callers_name, bytes_wanted);
+
+ error (printable_string, "");
+ abort ();
}
diff --git a/gnu/lib/libreadline/emacs_keymap.c b/gnu/lib/libreadline/emacs_keymap.c
index ebaaead..b31ac1f 100644
--- a/gnu/lib/libreadline/emacs_keymap.c
+++ b/gnu/lib/libreadline/emacs_keymap.c
@@ -322,7 +322,7 @@ KEYMAP_ENTRY_ARRAY emacs_standard_keymap = {
{ ISFUNC, rl_insert }, /* Latin small letter y with acute */
{ ISFUNC, rl_insert }, /* Latin small letter thorn (Icelandic) */
{ ISFUNC, rl_insert } /* Latin small letter y with diaeresis */
-#endif /* MEYMAP_SIZE > 128 */
+#endif /* KEYMAP_SIZE > 128 */
};
KEYMAP_ENTRY_ARRAY emacs_meta_keymap = {
@@ -336,7 +336,7 @@ KEYMAP_ENTRY_ARRAY emacs_meta_keymap = {
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-e */
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-f */
{ ISFUNC, rl_abort }, /* Meta-Control-g */
- { ISFUNC, (Function *)0x0 }, /* Meta-Control-h */
+ { ISFUNC, rl_backward_kill_word }, /* Meta-Control-h */
{ ISFUNC, rl_tab_insert }, /* Meta-Control-i */
{ ISFUNC, rl_vi_editing_mode }, /* Meta-Control-j */
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-k */
@@ -356,7 +356,7 @@ KEYMAP_ENTRY_ARRAY emacs_meta_keymap = {
{ ISFUNC, rl_yank_nth_arg }, /* Meta-Control-y */
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-z */
- { ISFUNC, (Function *)0x0 }, /* Meta-Control-[ */
+ { ISFUNC, rl_complete }, /* Meta-Control-[ */
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-\ */
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-] */
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-^ */
@@ -469,7 +469,7 @@ KEYMAP_ENTRY_ARRAY emacs_meta_keymap = {
{ ISFUNC, (Function *)0x0 }, /* Meta-{ */
{ ISFUNC, (Function *)0x0 }, /* Meta-| */
{ ISFUNC, (Function *)0x0 }, /* Meta-} */
- { ISFUNC, (Function *)0x0 }, /* Meta-~ */
+ { ISFUNC, rl_tilde_expand }, /* Meta-~ */
{ ISFUNC, rl_backward_kill_word }, /* Meta-rubout */
#if KEYMAP_SIZE > 128
diff --git a/gnu/lib/libreadline/funmap.c b/gnu/lib/libreadline/funmap.c
index 0ae1889..bbc64e0 100644
--- a/gnu/lib/libreadline/funmap.c
+++ b/gnu/lib/libreadline/funmap.c
@@ -36,6 +36,7 @@ extern char *xmalloc (), *xrealloc ();
# include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */
+#include "rlconf.h"
#include "readline.h"
FUNMAP **funmap = (FUNMAP **)NULL;
@@ -68,18 +69,24 @@ static FUNMAP default_funmap[] = {
{ "do-lowercase-version", rl_do_lowercase_version },
{ "downcase-word", rl_downcase_word },
{ "dump-functions", rl_dump_functions },
+ { "emacs-editing-mode", rl_emacs_editing_mode },
{ "end-kbd-macro", rl_end_kbd_macro },
{ "end-of-history", rl_end_of_history },
{ "end-of-line", rl_end_of_line },
{ "forward-char", rl_forward },
{ "forward-search-history", rl_forward_search_history },
{ "forward-word", rl_forward_word },
+ { "history-search-backward", rl_history_search_backward },
+ { "history-search-forward", rl_history_search_forward },
{ "insert-completions", rl_insert_completions },
+ { "kill-whole-line", rl_kill_full_line },
{ "kill-line", rl_kill_line },
{ "kill-word", rl_kill_word },
{ "next-history", rl_get_next_history },
{ "non-incremental-forward-search-history", rl_noninc_forward_search },
{ "non-incremental-reverse-search-history", rl_noninc_reverse_search },
+ { "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
+ { "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
{ "possible-completions", rl_possible_completions },
{ "previous-history", rl_get_previous_history },
{ "quoted-insert", rl_quoted_insert },
@@ -90,6 +97,7 @@ static FUNMAP default_funmap[] = {
{ "self-insert", rl_insert },
{ "start-kbd-macro", rl_start_kbd_macro },
{ "tab-insert", rl_tab_insert },
+ { "tilde-expand", rl_tilde_expand },
{ "transpose-chars", rl_transpose_chars },
{ "transpose-words", rl_transpose_words },
{ "undo", rl_undo_command },
@@ -102,7 +110,6 @@ static FUNMAP default_funmap[] = {
{ "yank-pop", rl_yank_pop },
#if defined (VI_MODE)
-
{ "vi-append-eol", rl_vi_append_eol },
{ "vi-append-mode", rl_vi_append_mode },
{ "vi-arg-digit", rl_vi_arg_digit },
@@ -135,10 +142,12 @@ static FUNMAP default_funmap[] = {
{ "vi-overstrike-delete", rl_vi_overstrike_delete },
{ "vi-prev-word", rl_vi_prev_word },
{ "vi-put", rl_vi_put },
+ { "vi-redo", rl_vi_redo },
{ "vi-replace", rl_vi_replace },
{ "vi-search", rl_vi_search },
{ "vi-search-again", rl_vi_search_again },
{ "vi-subst", rl_vi_subst },
+ { "vi-tilde-expand", rl_vi_tilde_expand },
{ "vi-yank-arg", rl_vi_yank_arg },
{ "vi-yank-to", rl_vi_yank_to },
@@ -163,6 +172,7 @@ rl_add_funmap_entry (name, function)
funmap[funmap_entry]->function = function;
funmap[++funmap_entry] = (FUNMAP *)NULL;
+ return funmap_entry;
}
static int funmap_initialized = 0;
diff --git a/gnu/lib/libreadline/history.c b/gnu/lib/libreadline/history.c
index 45c6c78..03d52ed 100644
--- a/gnu/lib/libreadline/history.c
+++ b/gnu/lib/libreadline/history.c
@@ -24,12 +24,6 @@
don't have to know what data types are used, just what functions
you can call. I think I have done that. */
-#if defined (STATIC_MALLOC)
-static char *xmalloc (), *xrealloc ();
-#else
-extern char *xmalloc (), *xrealloc ();
-#endif /* STATIC_MALLOC */
-
#include <stdio.h>
#include <sys/types.h>
#include <sys/file.h>
@@ -55,21 +49,19 @@ extern char *xmalloc (), *xrealloc ();
extern int errno;
#endif /* !errno */
-#if defined (__GNUC__)
-# undef alloca
-# define alloca __builtin_alloca
+#include "memalloc.h"
+#include "history.h"
+
+#if defined (STATIC_MALLOC)
+static char *xmalloc (), *xrealloc ();
#else
-# if defined (sparc) || defined (HAVE_ALLOCA_H)
-# include <alloca.h>
-# else
-extern char *alloca ();
-# endif /* sparc || HAVE_ALLOCA_H */
-#endif /* !__GNU_C__ */
+extern char *xmalloc (), *xrealloc ();
+#endif /* STATIC_MALLOC */
-#include "history.h"
+#define STREQ(a, b) (((a)[0] == (b)[0]) && (strcmp ((a), (b)) == 0))
+#define STREQN(a, b, n) (((a)[0] == (b)[0]) && (strncmp ((a), (b), (n)) == 0))
#ifndef savestring
-extern char *xmalloc ();
# ifndef strcpy
extern char *strcpy ();
# endif
@@ -84,6 +76,10 @@ extern char *strcpy ();
#define digit(c) ((c) >= '0' && (c) <= '9')
#endif
+#ifndef digit_value
+#define digit_value(c) ((c) - '0')
+#endif
+
#ifndef member
# ifndef strchr
extern char *strchr ();
@@ -91,10 +87,25 @@ extern char *strchr ();
#define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
#endif
+/* Possible history errors passed to hist_error. */
+#define EVENT_NOT_FOUND 0
+#define BAD_WORD_SPEC 1
+#define SUBST_FAILED 2
+#define BAD_MODIFIER 3
+
static char error_pointer;
+static char *subst_lhs;
+static char *subst_rhs;
+static int subst_lhs_len = 0;
+static int subst_rhs_len = 0;
+
static char *get_history_word_specifier ();
+#if defined (SHELL)
+extern char *single_quote ();
+#endif
+
/* **************************************************************** */
/* */
/* History Functions */
@@ -209,7 +220,7 @@ add_history (string)
/* If the history is stifled, and history_length is zero,
and it equals max_input_history, we don't save items. */
- if (!history_length)
+ if (history_length == 0)
return;
/* If there is something in the slot, then remove it. */
@@ -219,6 +230,7 @@ add_history (string)
free (the_history[0]);
}
+ /* Copy the rest of the entries, moving down one slot. */
for (i = 0; i < history_length; i++)
the_history[i] = the_history[i + 1];
@@ -229,9 +241,8 @@ add_history (string)
{
if (!history_size)
{
- the_history = (HIST_ENTRY **)
- xmalloc ((history_size = DEFAULT_HISTORY_GROW_SIZE)
- * sizeof (HIST_ENTRY *));
+ history_size = DEFAULT_HISTORY_GROW_SIZE;
+ the_history = (HIST_ENTRY **)xmalloc (history_size * sizeof (HIST_ENTRY *));
history_length = 1;
}
@@ -239,10 +250,9 @@ add_history (string)
{
if (history_length == (history_size - 1))
{
+ history_size += DEFAULT_HISTORY_GROW_SIZE;
the_history = (HIST_ENTRY **)
- xrealloc (the_history,
- ((history_size += DEFAULT_HISTORY_GROW_SIZE)
- * sizeof (HIST_ENTRY *)));
+ xrealloc (the_history, history_size * sizeof (HIST_ENTRY *));
}
history_length++;
}
@@ -306,11 +316,13 @@ history_search_internal (string, direction, anchored)
char *string;
int direction, anchored;
{
- register int i = history_offset;
- register int reverse = (direction < 0);
+ register int i, reverse;
register char *line;
- register int index;
- int string_len = strlen (string);
+ register int line_index;
+ int string_len;
+
+ i = history_offset;
+ reverse = (direction < 0);
/* Take care of trivial cases first. */
@@ -320,69 +332,71 @@ history_search_internal (string, direction, anchored)
if (reverse && (i == history_length))
i--;
+#define NEXT_LINE() do { if (reverse) i--; else i++; } while (0)
+
+ 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))
+ if ((reverse && i < 0) || (!reverse && i == history_length))
return (-1);
line = the_history[i]->line;
- index = strlen (line);
+ line_index = strlen (line);
/* If STRING is longer than line, no match. */
- if (string_len > index)
- goto next_line;
+ if (string_len > line_index)
+ {
+ NEXT_LINE ();
+ continue;
+ }
/* Handle anchored searches first. */
if (anchored == ANCHORED_SEARCH)
{
- if (strncmp (string, line, string_len) == 0)
+ if (STREQN (string, line, string_len))
{
history_offset = i;
return (0);
}
- goto next_line;
+ NEXT_LINE ();
+ continue;
}
/* Do substring search. */
if (reverse)
{
- index -= string_len;
+ line_index -= string_len;
- while (index >= 0)
+ while (line_index >= 0)
{
- if (strncmp (string, line + index, string_len) == 0)
+ if (STREQN (string, line + line_index, string_len))
{
history_offset = i;
- return (index);
+ return (line_index);
}
- index--;
+ line_index--;
}
}
else
{
- register int limit = index - string_len + 1;
- index = 0;
+ register int limit = line_index - string_len + 1;
+ line_index = 0;
- while (index < limit)
+ while (line_index < limit)
{
- if (strncmp (string, line + index, string_len) == 0)
+ if (STREQN (string, line + line_index, string_len))
{
history_offset = i;
- return (index);
+ return (line_index);
}
- index++;
+ line_index++;
}
}
- next_line:
- if (reverse)
- i--;
- else
- i++;
+ NEXT_LINE ();
}
}
@@ -488,15 +502,20 @@ history_filename (filename)
if (!return_val)
{
char *home;
+ int home_len;
home = getenv ("HOME");
if (!home)
home = ".";
- return_val = (char *)xmalloc (2 + strlen (home) + strlen (".history"));
+ home_len = strlen (home);
+ /* strlen(".history") == 8 */
+ return_val = xmalloc (2 + home_len + 8);
- sprintf (return_val, "%s/.history", home);
+ strcpy (return_val, home);
+ return_val[home_len] = '/';
+ strcpy (return_val + home_len + 1, ".history");
}
return (return_val);
@@ -530,15 +549,14 @@ read_history_range (filename, from, to)
input = history_filename (filename);
file = open (input, O_RDONLY, 0666);
- if ((file < 0) ||
- (stat (input, &finfo) == -1))
+ if ((file < 0) || (fstat (file, &finfo) == -1))
goto error_and_exit;
- buffer = (char *)xmalloc ((int)finfo.st_size + 1);
+ buffer = xmalloc ((int)finfo.st_size + 1);
if (read (file, buffer, finfo.st_size) != finfo.st_size)
- error_and_exit:
{
+ error_and_exit:
if (file >= 0)
close (file);
@@ -612,15 +630,12 @@ history_truncate_file (fname, lines)
struct stat finfo;
filename = history_filename (fname);
- if (stat (filename, &finfo) == -1)
- goto truncate_exit;
-
file = open (filename, O_RDONLY, 0666);
- if (file == -1)
+ if (file == -1 || fstat (file, &finfo) == -1)
goto truncate_exit;
- buffer = (char *)xmalloc ((int)finfo.st_size + 1);
+ buffer = xmalloc ((int)finfo.st_size + 1);
chars_read = read (file, buffer, finfo.st_size);
close (file);
@@ -635,26 +650,25 @@ history_truncate_file (fname, lines)
lines--;
}
- /* If there are fewer lines in the file than we want to truncate to,
- then we are all done. */
- if (!i)
- goto truncate_exit;
-
- /* Otherwise, write from the start of this line until the end of the
- buffer. */
- for (--i; i; i--)
+ /* If this is the first line, then the file contains exactly the
+ number of lines we want to truncate to, so we don't need to do
+ anything. It's the first line if we don't find a newline between
+ the current value of i and 0. Otherwise, write from the start of
+ this line until the end of the buffer. */
+ for ( ; i; i--)
if (buffer[i] == '\n')
{
i++;
break;
}
- file = open (filename, O_WRONLY | O_TRUNC | O_CREAT, 0666);
- if (file == -1)
- goto truncate_exit;
-
- write (file, buffer + i, finfo.st_size - i);
- close (file);
+ /* Write only if there are more lines in the file than we want to
+ truncate to. */
+ if (i && ((file = open (filename, O_WRONLY, 0666)) != -1))
+ {
+ write (file, buffer + i, finfo.st_size - i);
+ close (file);
+ }
truncate_exit:
if (buffer)
@@ -679,10 +693,7 @@ history_do_write (filename, nelements, overwrite)
char *output = history_filename (filename);
int file, mode;
- if (overwrite)
- mode = O_WRONLY | O_CREAT | O_TRUNC;
- else
- mode = O_WRONLY | O_APPEND;
+ mode = overwrite ? O_WRONLY | O_CREAT | O_TRUNC : O_WRONLY | O_APPEND;
if ((file = open (output, mode, 0666)) == -1)
{
@@ -707,7 +718,7 @@ history_do_write (filename, nelements, overwrite)
buffer_size += 1 + strlen (the_history[i]->line);
/* Allocate the buffer, and fill it. */
- buffer = (char *)xmalloc (buffer_size);
+ buffer = xmalloc (buffer_size);
for (i = history_length - nelements; i < history_length; i++)
{
@@ -869,8 +880,11 @@ get_history_event (string, caller_index, delimiting_quote)
int delimiting_quote;
{
register int i = *caller_index;
- int which, sign = 1;
+ register char c;
HIST_ENTRY *entry;
+ int which, sign = 1;
+ int local_index, search_mode, substring_okay = 0;
+ char *temp;
/* The event can be specified in a number of ways.
@@ -889,13 +903,16 @@ get_history_event (string, caller_index, delimiting_quote)
/* Move on to the specification. */
i++;
+#define RETURN_ENTRY(e, w) \
+ return ((e = history_get (w)) ? e->line : (char *)NULL)
+
/* Handle !! case. */
if (string[i] == history_expansion_char)
{
i++;
which = history_base + (history_length - 1);
*caller_index = i;
- goto get_which;
+ RETURN_ENTRY (entry, which);
}
/* Hack case of numeric line specification. */
@@ -907,98 +924,84 @@ get_history_event (string, caller_index, delimiting_quote)
if (digit (string[i]))
{
- int start = i;
-
- /* Get the extent of the digits. */
- for (; digit (string[i]); i++);
-
- /* Get the digit value. */
- sscanf (string + start, "%d", &which);
+ /* Get the extent of the digits and compute the value. */
+ for (which = 0; digit (string[i]); i++)
+ which = (which * 10) + digit_value (string[i]);
*caller_index = i;
if (sign < 0)
which = (history_length + history_base) - which;
- get_which:
- if (entry = history_get (which))
- return (entry->line);
-
- return ((char *)NULL);
+ RETURN_ENTRY (entry, which);
}
/* This must be something to search for. If the spec begins with
a '?', then the string may be anywhere on the line. Otherwise,
the string must be found at the start of a line. */
- {
- int local_index;
- char *temp;
- int substring_okay = 0;
-
- if (string[i] == '?')
- {
- substring_okay++;
- i++;
- }
+ if (string[i] == '?')
+ {
+ substring_okay++;
+ i++;
+ }
- for (local_index = i; string[i]; i++)
- if (whitespace (string[i]) ||
- string[i] == '\n' ||
- string[i] == ':' ||
- (substring_okay && string[i] == '?') ||
+ /* Only a closing `?' or a newline delimit a substring search string. */
+ for (local_index = i; c = string[i]; i++)
+ if ((!substring_okay && (whitespace (c) || c == ':' ||
#if defined (SHELL)
- member (string[i], ";&()|<>") ||
+ member (c, ";&()|<>") ||
#endif /* SHELL */
- string[i] == delimiting_quote)
- break;
+ string[i] == delimiting_quote)) ||
+ string[i] == '\n' ||
+ (substring_okay && string[i] == '?'))
+ break;
- temp = (char *)alloca (1 + (i - local_index));
- strncpy (temp, &string[local_index], (i - local_index));
- temp[i - local_index] = '\0';
+ temp = xmalloc (1 + (i - local_index));
+ strncpy (temp, &string[local_index], (i - local_index));
+ temp[i - local_index] = '\0';
- if (string[i] == '?')
- i++;
+ if (substring_okay && string[i] == '?')
+ i++;
- *caller_index = i;
+ *caller_index = i;
- search_again:
+#define FAIL_SEARCH() \
+ do { history_offset = history_length; free (temp) ; return (char *)NULL; } while (0)
- local_index = history_search_internal
- (temp, -1, substring_okay ? NON_ANCHORED_SEARCH : ANCHORED_SEARCH);
+ search_mode = substring_okay ? NON_ANCHORED_SEARCH : ANCHORED_SEARCH;
+ while (1)
+ {
+ local_index = history_search_internal (temp, -1, search_mode);
- if (local_index < 0)
- search_lost:
- {
- history_offset = history_length;
- return ((char *)NULL);
- }
+ if (local_index < 0)
+ FAIL_SEARCH ();
- if (local_index == 0 || substring_okay)
- {
- entry = current_history ();
- history_offset = history_length;
+ if (local_index == 0 || substring_okay)
+ {
+ entry = current_history ();
+ history_offset = history_length;
- /* If this was a substring search, then remember the string that
- we matched for word substitution. */
- if (substring_okay)
- {
- if (search_string)
- free (search_string);
- search_string = savestring (temp);
- }
-
- return (entry->line);
- }
+ /* If this was a substring search, then remember the
+ string that we matched for word substitution. */
+ if (substring_okay)
+ {
+ if (search_string)
+ free (search_string);
+ search_string = temp;
+ }
+ else
+ free (temp);
+ return (entry->line);
+ }
- if (history_offset)
- history_offset--;
- else
- goto search_lost;
-
- goto search_again;
- }
+ if (history_offset)
+ history_offset--;
+ else
+ FAIL_SEARCH ();
+ }
+#undef FAIL_SEARCH
+#undef RETURN_ENTRY
}
-
#if defined (SHELL)
/* Function for extracting single-quoted strings. Used for inhibiting
history expansion within single quotes. */
@@ -1019,43 +1022,535 @@ rl_string_extract_single_quoted (string, sindex)
*sindex = i;
}
+
+static char *
+quote_breaks (s)
+ char *s;
+{
+ register char *p, *r;
+ char *ret;
+ int len = 3;
+
+ for (p = s; p && *p; p++, len++)
+ {
+ if (*p == '\'')
+ len += 3;
+ else if (whitespace (*p) || *p == '\n')
+ len += 2;
+ }
+
+ r = ret = xmalloc (len);
+ *r++ = '\'';
+ for (p = s; p && *p; )
+ {
+ if (*p == '\'')
+ {
+ *r++ = '\'';
+ *r++ = '\\';
+ *r++ = '\'';
+ *r++ = '\'';
+ p++;
+ }
+ else if (whitespace (*p) || *p == '\n')
+ {
+ *r++ = '\'';
+ *r++ = *p++;
+ *r++ = '\'';
+ }
+ else
+ *r++ = *p++;
+ }
+ *r++ = '\'';
+ *r = '\0';
+ return ret;
+}
#endif /* SHELL */
+static char *
+hist_error (ret, s, start, current, errtype)
+ char *ret, *s;
+ int start, current, errtype;
+{
+ char *temp, *emsg;
+ int ll;
+
+ ll = 1 + (current - start);
+ temp = xmalloc (1 + ll);
+ strncpy (temp, s + start, ll);
+ temp[ll] = 0;
+
+ switch (errtype)
+ {
+ case EVENT_NOT_FOUND:
+ emsg = "event not found";
+ break;
+ case BAD_WORD_SPEC:
+ emsg = "bad word specifier";
+ break;
+ case SUBST_FAILED:
+ emsg = "substitution failed";
+ break;
+ case BAD_MODIFIER:
+ emsg = "unrecognized history modifier";
+ break;
+ default:
+ emsg = "unknown expansion error";
+ break;
+ }
+
+ sprintf (ret, "%s: %s", temp, emsg);
+ free (temp);
+ return ret;
+}
+
+/* Get a history substitution string from STR starting at *IPTR
+ and return it. The length is returned in LENPTR.
+
+ A backslash can quote the delimiter. If the string is the
+ empty string, the previous pattern is used. If there is
+ no previous pattern for the lhs, the last history search
+ string is used.
+
+ If IS_RHS is 1, we ignore empty strings and set the pattern
+ to "" anyway. subst_lhs is not changed if the lhs is empty;
+ subst_rhs is allowed to be set to the empty string. */
+
+static char *
+get_subst_pattern (str, iptr, delimiter, is_rhs, lenptr)
+ char *str;
+ int *iptr, delimiter, is_rhs, *lenptr;
+{
+ register int si, i, j, k;
+ char *s = (char *) NULL;
+
+ i = *iptr;
+
+ for (si = i; str[si] && str[si] != delimiter; si++)
+ if (str[si] == '\\' && str[si + 1] == delimiter)
+ si++;
+
+ if (si > i || is_rhs)
+ {
+ s = xmalloc (si - i + 1);
+ for (j = 0, k = i; k < si; j++, k++)
+ {
+ /* Remove a backslash quoting the search string delimiter. */
+ if (str[k] == '\\' && str[k + 1] == delimiter)
+ k++;
+ s[j] = str[k];
+ }
+ s[j] = '\0';
+ if (lenptr)
+ *lenptr = j;
+ }
+
+ i = si;
+ if (str[i])
+ i++;
+ *iptr = i;
+
+ return s;
+}
+
+static void
+postproc_subst_rhs ()
+{
+ char *new;
+ int i, j, new_size;
+
+ new = xmalloc (new_size = subst_rhs_len + subst_lhs_len);
+ for (i = j = 0; i < subst_rhs_len; i++)
+ {
+ if (subst_rhs[i] == '&')
+ {
+ if (j + subst_lhs_len >= new_size)
+ new = xrealloc (new, (new_size = new_size * 2 + subst_lhs_len));
+ strcpy (new + j, subst_lhs);
+ j += subst_lhs_len;
+ }
+ else
+ {
+ /* a single backslash protects the `&' from lhs interpolation */
+ if (subst_rhs[i] == '\\' && subst_rhs[i + 1] == '&')
+ i++;
+ if (j >= new_size)
+ new = xrealloc (new, new_size *= 2);
+ new[j++] = subst_rhs[i];
+ }
+ }
+ new[j] = '\0';
+ free (subst_rhs);
+ subst_rhs = new;
+ subst_rhs_len = j;
+}
+
+/* Expand the bulk of a history specifier starting at STRING[START].
+ Returns 0 if everything is OK, -1 if an error occurred, and 1
+ if the `p' modifier was supplied and the caller should just print
+ the returned string. Returns the new index into string in
+ *END_INDEX_PTR, and the expanded specifier in *RET_STRING. */
+static int
+history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
+ char *string;
+ int start, *end_index_ptr;
+ char **ret_string;
+ char *current_line; /* for !# */
+{
+ int i, n, starting_index;
+ int substitute_globally, want_quotes, print_only;
+ char *event, *temp, *result, *tstr, *t, c, *word_spec;
+ int result_len;
+
+ result = xmalloc (result_len = 128);
+
+ i = start;
+
+ /* If it is followed by something that starts a word specifier,
+ then !! is implied as the event specifier. */
+
+ if (member (string[i + 1], ":$*%^"))
+ {
+ char fake_s[3];
+ int fake_i = 0;
+ i++;
+ fake_s[0] = fake_s[1] = history_expansion_char;
+ fake_s[2] = '\0';
+ event = get_history_event (fake_s, &fake_i, 0);
+ }
+ else if (string[i + 1] == '#')
+ {
+ i += 2;
+ event = current_line;
+ }
+ else
+ {
+ int quoted_search_delimiter = 0;
+
+ /* If the character before this `!' is a double or single
+ quote, then this expansion takes place inside of the
+ quoted string. If we have to search for some text ("!foo"),
+ allow the delimiter to end the search string. */
+ if (i && (string[i - 1] == '\'' || string[i - 1] == '"'))
+ quoted_search_delimiter = string[i - 1];
+ event = get_history_event (string, &i, quoted_search_delimiter);
+ }
+
+ if (!event)
+ {
+ hist_error (result, string, start, i, EVENT_NOT_FOUND);
+ *ret_string = result;
+ return (-1);
+ }
+
+ /* If a word specifier is found, then do what that requires. */
+ starting_index = i;
+ word_spec = get_history_word_specifier (string, event, &i);
+
+ /* There is no such thing as a `malformed word specifier'. However,
+ it is possible for a specifier that has no match. In that case,
+ we complain. */
+ if (word_spec == (char *)&error_pointer)
+ {
+ hist_error (result, string, starting_index, i, BAD_WORD_SPEC);
+ *ret_string = result;
+ return (-1);
+ }
+
+ /* If no word specifier, than the thing of interest was the event. */
+ if (!word_spec)
+ temp = savestring (event);
+ else
+ {
+ temp = savestring (word_spec);
+ free (word_spec);
+ }
+
+ /* Perhaps there are other modifiers involved. Do what they say. */
+ want_quotes = substitute_globally = print_only = 0;
+ starting_index = i;
+
+ while (string[i] == ':')
+ {
+ c = string[i + 1];
+
+ if (c == 'g')
+ {
+ substitute_globally = 1;
+ i++;
+ c = string[i + 1];
+ }
+
+ switch (c)
+ {
+ default:
+ hist_error (result, string, i+1, i+2, BAD_MODIFIER);
+ *ret_string = result;
+ free (temp);
+ return -1;
+
+#if defined (SHELL)
+ case 'q':
+ want_quotes = 'q';
+ break;
+
+ case 'x':
+ want_quotes = 'x';
+ break;
+#endif /* SHELL */
+
+ /* :p means make this the last executed line. So we
+ return an error state after adding this line to the
+ history. */
+ case 'p':
+ print_only++;
+ break;
+
+ /* :t discards all but the last part of the pathname. */
+ case 't':
+ tstr = strrchr (temp, '/');
+ if (tstr)
+ {
+ tstr++;
+ t = savestring (tstr);
+ free (temp);
+ temp = t;
+ }
+ break;
+
+ /* :h discards the last part of a pathname. */
+ case 'h':
+ tstr = strrchr (temp, '/');
+ if (tstr)
+ *tstr = '\0';
+ break;
+
+ /* :r discards the suffix. */
+ case 'r':
+ tstr = strrchr (temp, '.');
+ if (tstr)
+ *tstr = '\0';
+ break;
+
+ /* :e discards everything but the suffix. */
+ case 'e':
+ tstr = strrchr (temp, '.');
+ if (tstr)
+ {
+ t = savestring (tstr);
+ free (temp);
+ temp = t;
+ }
+ break;
+
+ /* :s/this/that substitutes `that' for the first
+ occurrence of `this'. :gs/this/that substitutes `that'
+ for each occurrence of `this'. :& repeats the last
+ substitution. :g& repeats the last substitution
+ globally. */
+
+ case '&':
+ case 's':
+ {
+ char *new_event, *t;
+ int delimiter, failed, si, l_temp;
+
+ if (c == 's')
+ {
+ if (i + 2 < (int)strlen (string))
+ delimiter = string[i + 2];
+ else
+ break; /* no search delimiter */
+
+ i += 3;
+
+ t = get_subst_pattern (string, &i, delimiter, 0, &subst_lhs_len);
+ /* An empty substitution lhs with no previous substitution
+ uses the last search string as the lhs. */
+ if (t)
+ {
+ if (subst_lhs)
+ free (subst_lhs);
+ subst_lhs = t;
+ }
+ else if (!subst_lhs)
+ {
+ if (search_string && *search_string)
+ {
+ subst_lhs = savestring (search_string);
+ subst_lhs_len = strlen (subst_lhs);
+ }
+ else
+ {
+ subst_lhs = (char *) NULL;
+ subst_lhs_len = 0;
+ }
+ }
+
+ /* If there is no lhs, the substitution can't succeed. */
+ if (subst_lhs_len == 0)
+ {
+ hist_error (result, string, starting_index, i, SUBST_FAILED);
+ *ret_string = result;
+ free (temp);
+ return -1;
+ }
+
+ if (subst_rhs)
+ free (subst_rhs);
+ subst_rhs = get_subst_pattern (string, &i, delimiter, 1, &subst_rhs_len);
+
+ /* If `&' appears in the rhs, it's supposed to be replaced
+ with the lhs. */
+ if (member ('&', subst_rhs))
+ postproc_subst_rhs ();
+ }
+ else
+ i += 2;
+
+ l_temp = strlen (temp);
+ /* Ignore impossible cases. */
+ if (subst_lhs_len > l_temp)
+ {
+ hist_error (result, string, starting_index, i, SUBST_FAILED);
+ *ret_string = result;
+ free (temp);
+ return (-1);
+ }
+
+ /* Find the first occurrence of THIS in TEMP. */
+ si = 0;
+ for (failed = 1; (si + subst_lhs_len) <= l_temp; si++)
+ if (STREQN (temp+si, subst_lhs, subst_lhs_len))
+ {
+ int len = subst_rhs_len - subst_lhs_len + l_temp;
+ new_event = xmalloc (1 + len);
+ strncpy (new_event, temp, si);
+ strncpy (new_event + si, subst_rhs, subst_rhs_len);
+ strncpy (new_event + si + subst_rhs_len,
+ temp + si + subst_lhs_len,
+ l_temp - (si + subst_lhs_len));
+ new_event[len] = '\0';
+ free (temp);
+ temp = new_event;
+
+ failed = 0;
+
+ if (substitute_globally)
+ {
+ si += subst_rhs_len;
+ l_temp = strlen (temp);
+ substitute_globally++;
+ continue;
+ }
+ else
+ break;
+ }
+
+ if (substitute_globally > 1)
+ {
+ substitute_globally = 0;
+ continue; /* don't want to increment i */
+ }
+
+ if (failed == 0)
+ continue; /* don't want to increment i */
+
+ hist_error (result, string, starting_index, i, SUBST_FAILED);
+ *ret_string = result;
+ free (temp);
+ return (-1);
+ }
+ }
+ i += 2;
+ }
+ /* Done with modfiers. */
+ /* Believe it or not, we have to back the pointer up by one. */
+ --i;
+
+#if defined (SHELL)
+ if (want_quotes)
+ {
+ char *x;
+
+ if (want_quotes == 'q')
+ x = single_quote (temp);
+ else if (want_quotes == 'x')
+ x = quote_breaks (temp);
+ else
+ x = savestring (temp);
+
+ free (temp);
+ temp = x;
+ }
+#endif /* SHELL */
+
+ n = strlen (temp);
+ if (n > result_len)
+ result = xrealloc (result, n + 1);
+ strcpy (result, temp);
+ free (temp);
+
+ *end_index_ptr = i;
+ *ret_string = result;
+ return (print_only);
+}
+
/* Expand the string STRING, placing the result into OUTPUT, a pointer
to a string. Returns:
+ -1) If there was an error in expansion.
0) If no expansions took place (or, if the only change in
the text was the de-slashifying of the history expansion
character)
1) If expansions did take place
- -1) If there was an error in expansion.
+ 2) If the `p' modifier was given and the caller should print the result
If an error ocurred in expansion, then OUTPUT contains a descriptive
error message. */
+
+#define ADD_STRING(s) \
+ do \
+ { \
+ int sl = strlen (s); \
+ j += sl; \
+ while (j >= result_len) \
+ result = xrealloc (result, result_len += 128); \
+ strcpy (result + j - sl, s); \
+ } \
+ while (0)
+
+#define ADD_CHAR(c) \
+ do \
+ { \
+ if (j >= result_len) \
+ result = xrealloc (result, result_len += 64); \
+ result[j++] = c; \
+ result[j] = '\0'; \
+ } \
+ while (0)
+
int
-history_expand (string, output)
- char *string;
+history_expand (hstring, output)
+ char *hstring;
char **output;
{
- register int j, l = strlen (string);
- int i, word_spec_error = 0;
- int cc, modified = 0;
- char *word_spec, *event;
- int starting_index, only_printing = 0, substitute_globally = 0;
+ register int j;
+ int i, r, l, passc, cc, modified, eindex, only_printing;
+ char *string;
/* The output string, and its length. */
- int len = 0;
- char *result = (char *)NULL;
+ int result_len;
+ char *result;
- /* Used in add_string; */
- char *temp, tt[2], tbl[3];
+ /* Used when adding the string. */
+ char *temp;
/* Prepare the buffer for printing error messages. */
- result = (char *)xmalloc (len = 256);
+ result = xmalloc (result_len = 256);
+ result[0] = '\0';
- result[0] = tt[1] = tbl[2] = '\0';
- tbl[0] = '\\';
- tbl[1] = history_expansion_char;
+ only_printing = modified = 0;
+ l = strlen (hstring);
/* Grovel the string. Only backslash can quote the history escape
character. We also handle arg specifiers. */
@@ -1066,377 +1561,177 @@ history_expand (string, output)
/* The quick substitution character is a history expansion all right. That
is to say, "^this^that^" is equivalent to "!!:s^this^that^", and in fact,
that is the substitution that we do. */
- if (string[0] == history_subst_char)
+ if (hstring[0] == history_subst_char)
{
- char *format_string = (char *)alloca (10 + strlen (string));
+ string = xmalloc (l + 5);
- sprintf (format_string, "%c%c:s%s",
- history_expansion_char, history_expansion_char,
- string);
- string = format_string;
+ string[0] = string[1] = history_expansion_char;
+ string[2] = ':';
+ string[3] = 's';
+ strcpy (string + 4, hstring);
l += 4;
- goto grovel;
}
-
- /* If not quick substitution, still maybe have to do expansion. */
-
- /* `!' followed by one of the characters in history_no_expand_chars
- is NOT an expansion. */
- for (i = 0; string[i]; i++)
+ else
{
- if (string[i] == history_expansion_char)
+ string = hstring;
+ /* If not quick substitution, still maybe have to do expansion. */
+
+ /* `!' followed by one of the characters in history_no_expand_chars
+ is NOT an expansion. */
+ for (i = 0; string[i]; i++)
{
- if (!string[i + 1] || member (string[i + 1], history_no_expand_chars))
- continue;
+ cc = string[i + 1];
+ if (string[i] == history_expansion_char)
+ {
+ if (!cc || member (cc, history_no_expand_chars))
+ continue;
#if defined (SHELL)
- /* The shell uses ! as a pattern negation character in globbing [...]
- expressions, so let those pass without expansion. */
- else if (i > 0 && (string[i - 1] == '[') && member (']', string + i))
- continue;
+ /* The shell uses ! as a pattern negation character
+ in globbing [...] expressions, so let those pass
+ without expansion. */
+ else if (i > 0 && (string[i - 1] == '[') &&
+ member (']', string + i + 1))
+ continue;
#endif /* SHELL */
- else
- goto grovel;
- }
+ else
+ break;
+ }
#if defined (SHELL)
- else if (string[i] == '\'')
- {
- /* If this is bash, single quotes inhibit history expansion. */
- i++;
- rl_string_extract_single_quoted (string, &i);
+ else if (string[i] == '\'')
+ {
+ /* If this is bash, single quotes inhibit history expansion. */
+ i++;
+ rl_string_extract_single_quoted (string, &i);
+ }
+ else if (string[i] == '\\')
+ {
+ /* If this is bash, allow backslashes to quote single
+ quotes and
+ the history expansion character. */
+ if (cc == '\'' || cc == history_expansion_char)
+ i++;
+ }
+#endif /* SHELL */
}
- else if (string[i] == '\\')
+
+ if (string[i] != history_expansion_char)
{
- /* If this is bash, allow backslashes to quote single quotes and
- the history expansion character. */
- if (string[i + 1] == '\'' || (string[i + 1] == history_expansion_char))
- i++;
+ free (result);
+ *output = savestring (string);
+ return (0);
}
-#endif /* SHELL */
}
-
- free (result);
- *output = savestring (string);
- return (0);
-
- grovel:
-
- for (i = j = 0; i < l; i++)
+ /* Extract and perform the substitution. */
+ for (passc = i = j = 0; i < l; i++)
{
- int passc = 0;
int tchar = string[i];
+ if (passc)
+ {
+ passc = 0;
+ ADD_CHAR (tchar);
+ continue;
+ }
+
if (tchar == history_expansion_char)
tchar = -3;
- if (passc)
- {
- passc = 0;
- goto add_char;
- }
-
switch (tchar)
{
+ default:
+ ADD_CHAR (string[i]);
+ break;
+
case '\\':
- if (string[i + 1] == history_expansion_char)
- {
- i++;
- temp = tbl;
- goto do_add;
- }
- else
- {
- passc++;
- goto add_char;
- }
+ passc++;
+ ADD_CHAR (tchar);
+ break;
#if defined (SHELL)
case '\'':
{
/* If this is bash, single quotes inhibit history expansion. */
- int quote = i, slen;
+ int quote, slen;
- ++i;
+ quote = i++;
rl_string_extract_single_quoted (string, &i);
slen = i - quote + 2;
- temp = (char *)alloca (slen);
+ temp = xmalloc (slen);
strncpy (temp, string + quote, slen);
temp[slen - 1] = '\0';
- goto do_add;
+ ADD_STRING (temp);
+ free (temp);
+ break;
}
#endif /* SHELL */
- /* case history_expansion_char: */
- case -3:
- starting_index = i + 1;
+ case -3: /* history_expansion_char */
cc = string[i + 1];
/* If the history_expansion_char is followed by one of the
characters in history_no_expand_chars, then it is not a
candidate for expansion of any kind. */
if (member (cc, history_no_expand_chars))
- goto add_char;
+ {
+ ADD_CHAR (string[i]);
+ break;
+ }
+#ifdef NO_BANG_HASH_MODIFIERS
/* There is something that is listed as a `word specifier' in csh
documentation which means `the expanded text to this point'.
- That is not a word specifier, it is an event specifier. */
-
+ That is not a word specifier, it is an event specifier. If we
+ don't want to allow modifiers with `!#', just stick the current
+ output line in again. */
if (cc == '#')
- goto hack_pound_sign;
-
- /* If it is followed by something that starts a word specifier,
- then !! is implied as the event specifier. */
-
- if (member (cc, ":$*%^"))
{
- char fake_s[3];
- int fake_i = 0;
+ if (result)
+ {
+ temp = xmalloc (1 + strlen (result));
+ strcpy (temp, result);
+ ADD_STRING (temp);
+ free (temp);
+ }
i++;
- fake_s[0] = fake_s[1] = history_expansion_char;
- fake_s[2] = '\0';
- event = get_history_event (fake_s, &fake_i, 0);
- }
- else
- {
- int quoted_search_delimiter = 0;
-
- /* If the character before this `!' is a double or single
- quote, then this expansion takes place inside of the
- quoted string. If we have to search for some text ("!foo"),
- allow the delimiter to end the search string. */
- if (i && (string[i - 1] == '\'' || string[i - 1] == '"'))
- quoted_search_delimiter = string[i - 1];
-
- event = get_history_event (string, &i, quoted_search_delimiter);
+ break;
}
-
- if (!event)
- event_not_found:
- {
- int ll = 1 + (i - starting_index);
-
- temp = (char *)alloca (1 + ll);
- strncpy (temp, string + starting_index, ll);
- temp[ll - 1] = 0;
- sprintf (result, "%s: %s.", temp,
- word_spec_error ? "Bad word specifier" : "Event not found");
- *output = result;
- return (-1);
- }
-
- /* If a word specifier is found, then do what that requires. */
- starting_index = i;
-
- word_spec = get_history_word_specifier (string, event, &i);
+#endif
- /* There is no such thing as a `malformed word specifier'. However,
- it is possible for a specifier that has no match. In that case,
- we complain. */
- if (word_spec == (char *)&error_pointer)
+ r = history_expand_internal (string, i, &eindex, &temp, result);
+ if (r < 0)
{
- word_spec_error++;
- goto event_not_found;
+ *output = temp;
+ free (result);
+ if (string != hstring)
+ free (string);
+ return -1;
}
-
- /* If no word specifier, than the thing of interest was the event. */
- if (!word_spec)
- temp = event;
else
{
- temp = (char *)alloca (1 + strlen (word_spec));
- strcpy (temp, word_spec);
- free (word_spec);
- }
-
- /* Perhaps there are other modifiers involved. Do what they say. */
-
- hack_specials:
-
- if (string[i] == ':')
- {
- char *tstr;
-
- switch (string[i + 1])
+ if (temp)
{
- /* :p means make this the last executed line. So we
- return an error state after adding this line to the
- history. */
- case 'p':
- only_printing++;
- goto next_special;
-
- /* :t discards all but the last part of the pathname. */
- case 't':
- tstr = strrchr (temp, '/');
- if (tstr)
- temp = ++tstr;
- goto next_special;
-
- /* :h discards the last part of a pathname. */
- case 'h':
- tstr = strrchr (temp, '/');
- if (tstr)
- *tstr = '\0';
- goto next_special;
-
- /* :r discards the suffix. */
- case 'r':
- tstr = strrchr (temp, '.');
- if (tstr)
- *tstr = '\0';
- goto next_special;
-
- /* :e discards everything but the suffix. */
- case 'e':
- tstr = strrchr (temp, '.');
- if (tstr)
- temp = tstr;
- goto next_special;
-
- /* :s/this/that substitutes `this' for `that'. */
- /* :gs/this/that substitutes `this' for `that' globally. */
- case 'g':
-#ifdef NOTYET
- /* :g/this/that is equivalent to :gs/this/that */
- substitute_globally = 1;
- if (string[i + 2] == 's')
- i++;
-#else
- if (string[i + 2] == 's')
- {
- i++;
- substitute_globally = 1;
- goto substitute;
- }
-#endif
- else
-
- case 's':
- substitute:
- {
- char *this, *that, *new_event;
- int delimiter = 0;
- int si, l_this, l_that, l_temp = strlen (temp);
-
- if (i + 2 < (int)strlen (string))
- delimiter = string[i + 2];
-
- if (!delimiter)
- break;
-
- i += 3;
-
- /* Get THIS. */
- for (si = i; string[si] && string[si] != delimiter; si++);
- l_this = (si - i);
- this = (char *)alloca (1 + l_this);
- strncpy (this, string + i, l_this);
- this[l_this] = '\0';
-
- i = si;
- if (string[si])
- i++;
-
- /* Get THAT. */
- for (si = i; string[si] && string[si] != delimiter; si++);
- l_that = (si - i);
- that = (char *)alloca (1 + l_that);
- strncpy (that, string + i, l_that);
- that[l_that] = '\0';
-
- i = si;
- if (string[si]) i++;
-
- /* Ignore impossible cases. */
- if (l_this > l_temp)
- goto cant_substitute;
-
- /* Find the first occurrence of THIS in TEMP. */
- si = 0;
- for (; (si + l_this) <= l_temp; si++)
- if (strncmp (temp + si, this, l_this) == 0)
- {
- new_event =
- (char *)alloca (1 + (l_that - l_this) + l_temp);
- strncpy (new_event, temp, si);
- strncpy (new_event + si, that, l_that);
- strncpy (new_event + si + l_that,
- temp + si + l_this,
- l_temp - (si + l_this));
- new_event[(l_that - l_this) + l_temp] = '\0';
- temp = new_event;
-
- if (substitute_globally)
- {
- si += l_that;
- l_temp = strlen (temp);
- substitute_globally++;
- continue;
- }
-
- goto hack_specials;
- }
-
- cant_substitute:
-
- if (substitute_globally > 1)
- {
- substitute_globally = 0;
- goto hack_specials;
- }
-
- goto event_not_found;
- }
-
- /* :# is the line so far. Note that we have to
- alloca () it since RESULT could be realloc ()'ed
- below in add_string. */
- case '#':
- hack_pound_sign:
- if (result)
- {
- temp = (char *)alloca (1 + strlen (result));
- strcpy (temp, result);
- }
- else
- temp = "";
-
- next_special:
- i += 2;
- goto hack_specials;
+ modified++;
+ if (*temp)
+ ADD_STRING (temp);
+ free (temp);
}
-
+ only_printing = r == 1;
+ i = eindex;
}
- /* Believe it or not, we have to back the pointer up by one. */
- --i;
- goto add_string;
-
- /* A regular character. Just add it to the output string. */
- default:
- add_char:
- tt[0] = string[i];
- temp = tt;
- goto do_add;
-
- add_string:
- modified++;
-
- do_add:
- j += strlen (temp);
- while (j > (len - 1))
- result = (char *)xrealloc (result, (len += 256));
-
- strcpy (result + (j - strlen (temp)), temp);
+ break;
}
}
*output = result;
+ if (string != hstring)
+ free (string);
if (only_printing)
{
add_history (result);
- return (-1);
+ return (2);
}
return (modified != 0);
@@ -1455,15 +1750,19 @@ get_history_word_specifier (spec, from, caller_index)
register int i = *caller_index;
int first, last;
int expecting_word_spec = 0;
- char *history_arg_extract ();
+ char *result;
/* The range of words to return doesn't exist yet. */
first = last = 0;
+ result = (char *)NULL;
/* If we found a colon, then this *must* be a word specification. If
it isn't, then it is an error. */
if (spec[i] == ':')
- i++, expecting_word_spec++;
+ {
+ i++;
+ expecting_word_spec++;
+ }
/* Handle special cases first. */
@@ -1471,24 +1770,15 @@ get_history_word_specifier (spec, from, caller_index)
if (spec[i] == '%')
{
*caller_index = i + 1;
- if (search_string)
- return (savestring (search_string));
- else
- return (savestring (""));
+ return (search_string ? savestring (search_string) : savestring (""));
}
/* `*' matches all of the arguments, but not the command. */
if (spec[i] == '*')
{
- char *star_result;
-
*caller_index = i + 1;
- star_result = history_arg_extract (1, '$', from);
-
- if (!star_result)
- star_result = savestring ("");
-
- return (star_result);
+ result = history_arg_extract (1, '$', from);
+ return (result ? result : savestring (""));
}
/* `$' is last arg. */
@@ -1499,68 +1789,55 @@ get_history_word_specifier (spec, from, caller_index)
}
/* Try to get FIRST and LAST figured out. */
- if (spec[i] == '-' || spec[i] == '^')
- {
- first = 1;
- goto get_last;
- }
- if (digit (spec[i]) && expecting_word_spec)
+ if (spec[i] == '-' || spec[i] == '^')
+ first = 1;
+ else if (digit (spec[i]) && expecting_word_spec)
{
- sscanf (spec + i, "%d", &first);
- for (; digit (spec[i]); i++);
+ for (first = 0; digit (spec[i]); i++)
+ first = (first * 10) + digit_value (spec[i]);
}
else
- return ((char *)NULL);
+ return ((char *)NULL); /* no valid `first' for word specifier */
- get_last:
- if (spec[i] == '^')
+ if (spec[i] == '^' || spec[i] == '*')
{
+ last = (spec[i] == '^') ? 1 : '$'; /* x* abbreviates x-$ */
i++;
- last = 1;
- goto get_args;
}
-
- if (spec[i] != '-')
+ else if (spec[i] != '-')
+ last = first;
+ else
{
- last = first;
- goto get_args;
- }
-
- i++;
+ i++;
- if (digit (spec[i]))
- {
- sscanf (spec + i, "%d", &last);
- for (; digit (spec[i]); i++);
+ if (digit (spec[i]))
+ {
+ for (last = 0; digit (spec[i]); i++)
+ last = (last * 10) + digit_value (spec[i]);
+ }
+ else if (spec[i] == '$')
+ {
+ i++;
+ last = '$';
+ }
+ else if (!spec[i] || spec[i] == ':') /* could be modifier separator */
+ last = -1; /* x- abbreviates x-$ omitting word `$' */
}
- else
- if (spec[i] == '$')
- {
- i++;
- last = '$';
- }
- get_args:
- {
- char *result = (char *)NULL;
-
- *caller_index = i;
+ *caller_index = i;
- if (last >= first)
- result = history_arg_extract (first, last, from);
+ if (last >= first || last == '$' || last < 0)
+ result = history_arg_extract (first, last, from);
- if (result)
- return (result);
- else
- return ((char *)&error_pointer);
- }
+ return (result ? result : (char *)&error_pointer);
}
/* Extract the args specified, starting at FIRST, and ending at LAST.
The args are taken from STRING. If either FIRST or LAST is < 0,
then make that arg count from the right (subtract from the number of
- tokens, so that FIRST = -1 means the next to last token on the line). */
+ tokens, so that FIRST = -1 means the next to last token on the line).
+ If LAST is `$' the last arg from STRING is used. */
char *
history_arg_extract (first, last, string)
int first, last;
@@ -1569,13 +1846,16 @@ history_arg_extract (first, last, string)
register int i, len;
char *result = (char *)NULL;
int size = 0, offset = 0;
+ char **list;
- char **history_tokenize (), **list;
-
- if (!(list = history_tokenize (string)))
+ /* XXX - think about making history_tokenize return a struct array,
+ each struct in array being a string and a length to avoid the
+ calls to strlen below. */
+ if ((list = history_tokenize (string)) == NULL)
return ((char *)NULL);
- for (len = 0; list[len]; len++);
+ for (len = 0; list[len]; len++)
+ ;
if (last < 0)
last = len + last - 1;
@@ -1595,27 +1875,24 @@ history_arg_extract (first, last, string)
result = ((char *)NULL);
else
{
+ for (size = 0, i = first; i < last; i++)
+ size += strlen (list[i]) + 1;
+ result = xmalloc (size + 1);
+
for (i = first; i < last; i++)
{
- int l = strlen (list[i]);
-
- if (!result)
- result = (char *)xmalloc ((size = (2 + l)));
- else
- result = (char *)xrealloc (result, (size += (2 + l)));
strcpy (result + offset, list[i]);
- offset += l;
+ offset += strlen (list[i]);
if (i + 1 < last)
{
- strcpy (result + offset, " ");
- offset++;
+ result[offset++] = ' ';
+ result[offset] = 0;
}
}
}
for (i = 0; i < len; i++)
free (list[i]);
-
free (list);
return (result);
@@ -1637,113 +1914,94 @@ history_tokenize (string)
/* Get a token, and stuff it into RESULT. The tokens are split
exactly where the shell would split them. */
- get_token:
-
- /* Skip leading whitespace. */
- for (; string[i] && whitespace(string[i]); i++);
-
- start = i;
-
- if (!string[i] || string[i] == history_comment_char)
- return (result);
-
- if (member (string[i], "()\n"))
+ while (string[i])
{
- i++;
- goto got_token;
- }
+ int delimiter = 0;
- if (member (string[i], "<>;&|$"))
- {
- int peek = string[i + 1];
+ /* Skip leading whitespace. */
+ for (; string[i] && whitespace (string[i]); i++)
+ ;
+ if (!string[i] || string[i] == history_comment_char)
+ return (result);
- if (peek == string[i] && peek != '$')
+ start = i;
+
+ if (member (string[i], "()\n"))
{
- if (peek == '<' && string[i + 2] == '-')
- i++;
- i += 2;
+ i++;
goto got_token;
}
- else
+
+ if (member (string[i], "<>;&|$"))
{
- if ((peek == '&' &&
- (string[i] == '>' || string[i] == '<')) ||
- ((peek == '>') && (string[i] == '&')) ||
- ((peek == '(') && (string[i] == '$')))
+ int peek = string[i + 1];
+
+ if (peek == string[i] && peek != '$')
{
+ if (peek == '<' && string[i + 2] == '-')
+ i++;
i += 2;
goto got_token;
}
+ else
+ {
+ if ((peek == '&' && (string[i] == '>' || string[i] == '<')) ||
+ ((peek == '>') && (string[i] == '&')) ||
+ ((peek == '(') && (string[i] == '$')))
+ {
+ i += 2;
+ goto got_token;
+ }
+ }
+ if (string[i] != '$')
+ {
+ i++;
+ goto got_token;
+ }
}
- if (string[i] != '$')
- {
- i++;
- goto got_token;
- }
- }
- /* Get word from string + i; */
- {
- int delimiter = 0;
+ /* Get word from string + i; */
- if (member (string[i], "\"'`"))
- delimiter = string[i++];
+ if (member (string[i], "\"'`"))
+ delimiter = string[i++];
- for (;string[i]; i++)
- {
- if (string[i] == '\\')
- {
- if (string[i + 1] == '\n')
- {
- i++;
- continue;
- }
- else
- {
- if (delimiter != '\'')
- if ((delimiter != '"') ||
- (member (string[i], slashify_in_quotes)))
- {
- i++;
- continue;
- }
- }
- }
+ for (; string[i]; i++)
+ {
+ if (string[i] == '\\' && string[i + 1] == '\n')
+ {
+ i++;
+ continue;
+ }
- if (delimiter && string[i] == delimiter)
- {
- delimiter = 0;
- continue;
- }
+ if (string[i] == '\\' && delimiter != '\'' &&
+ (delimiter != '"' || member (string[i], slashify_in_quotes)))
+ {
+ i++;
+ continue;
+ }
- if (!delimiter && (member (string[i], " \t\n;&()|<>")))
- goto got_token;
+ if (delimiter && string[i] == delimiter)
+ {
+ delimiter = 0;
+ continue;
+ }
- if (!delimiter && member (string[i], "\"'`"))
- {
+ if (!delimiter && (member (string[i], " \t\n;&()|<>")))
+ break;
+
+ if (!delimiter && member (string[i], "\"'`"))
delimiter = string[i];
- continue;
- }
- }
+ }
got_token:
- len = i - start;
- if (result_index + 2 >= size)
- {
- if (!size)
- result = (char **)xmalloc ((size = 10) * (sizeof (char *)));
- else
- 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_index++;
- result[result_index] = (char *)NULL;
- }
- if (string[i])
- goto get_token;
+ len = i - start;
+ if (result_index + 2 >= size)
+ result = (char **)xrealloc (result, ((size += 10) * sizeof (char *)));
+ result[result_index] = xmalloc (1 + len);
+ strncpy (result[result_index], string + start, len);
+ result[result_index][len] = '\0';
+ result[++result_index] = (char *)NULL;
+ }
return (result);
}
diff --git a/gnu/lib/libreadline/isearch.c b/gnu/lib/libreadline/isearch.c
index 3222311..fdeb7cb 100644
--- a/gnu/lib/libreadline/isearch.c
+++ b/gnu/lib/libreadline/isearch.c
@@ -27,27 +27,27 @@
#include <stdio.h>
-#if defined (__GNUC__)
-# define alloca __builtin_alloca
-#else
-# if defined (sparc) || defined (HAVE_ALLOCA_H)
-# include <alloca.h>
-# endif
-#endif
-
+#include "memalloc.h"
#include "readline.h"
#include "history.h"
+#define STREQ(a, b) (((a)[0] == (b)[0]) && (strcmp ((a), (b)) == 0))
+#define STREQN(a, b, n) (((a)[0] == (b)[0]) && (strncmp ((a), (b), (n)) == 0))
+
+/* Variables imported from other files in the readline library. */
extern Keymap _rl_keymap;
extern HIST_ENTRY *saved_line_for_history;
extern int rl_line_buffer_len;
extern int rl_point, rl_end;
-extern char *rl_prompt, *rl_line_buffer;
+extern char *rl_line_buffer;
-/* Remove these declarations when we have a complete libgnu.a. */
extern char *xmalloc (), *xrealloc ();
-static void rl_search_history ();
+static int rl_search_history ();
+
+/* 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;
/* Search backwards through the history looking for a string which is typed
interactively. Start with the current line. */
@@ -55,7 +55,7 @@ rl_reverse_search_history (sign, key)
int sign;
int key;
{
- rl_search_history (-sign, key);
+ return (rl_search_history (-sign, key));
}
/* Search forwards through the history looking for a string which is typed
@@ -64,7 +64,7 @@ rl_forward_search_history (sign, key)
int sign;
int key;
{
- rl_search_history (sign, key);
+ return (rl_search_history (sign, key));
}
/* Display the current state of the search in the echo-area.
@@ -77,11 +77,9 @@ rl_display_search (search_string, reverse_p, where)
char *search_string;
int reverse_p, where;
{
- char *message = (char *)NULL;
-
- message =
- (char *)xmalloc (1 + (search_string ? strlen (search_string) : 0) + 30);
+ char *message;
+ message = xmalloc (1 + (search_string ? strlen (search_string) : 0) + 30);
*message = '\0';
#if defined (NOTDEF)
@@ -109,7 +107,7 @@ rl_display_search (search_string, reverse_p, where)
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 void
+static int
rl_search_history (direction, invoking_key)
int direction;
int invoking_key;
@@ -124,7 +122,7 @@ rl_search_history (direction, invoking_key)
int search_string_size;
/* The list of lines to search through. */
- char **lines;
+ char **lines, *allocated_line = (char *)NULL;
/* The length of LINES. */
int hlen;
@@ -136,13 +134,13 @@ rl_search_history (direction, invoking_key)
int orig_point = rl_point;
int orig_line = where_history ();
int last_found_line = orig_line;
- int c, done = 0;
+ int c, done = 0, found, failed, sline_len;
/* The line currently being searched. */
char *sline;
/* Offset in that line. */
- int index;
+ int line_index;
/* Non-zero if we are doing a reverse search. */
int reverse = (direction < 0);
@@ -154,21 +152,18 @@ rl_search_history (direction, invoking_key)
/* Allocate space for this many lines, +1 for the current input line,
and remember those lines. */
- lines = (char **)alloca ((1 + (hlen = i)) * sizeof (char *));
+ lines = (char **)xmalloc ((1 + (hlen = i)) * sizeof (char *));
for (i = 0; i < hlen; i++)
lines[i] = hlist[i]->line;
if (saved_line_for_history)
lines[i] = saved_line_for_history->line;
else
- /* So I have to type it in this way instead. */
{
- char *alloced_line;
-
- /* Keep that MIPS alloca () happy. */
- alloced_line = (char *)alloca (1 + strlen (rl_line_buffer));
- lines[i] = alloced_line;
- strcpy (lines[i], &rl_line_buffer[0]);
+ /* Keep track of this so we can free it. */
+ allocated_line = xmalloc (1 + strlen (rl_line_buffer));
+ strcpy (allocated_line, &rl_line_buffer[0]);
+ lines[i] = allocated_line;
}
hlen++;
@@ -177,39 +172,37 @@ rl_search_history (direction, invoking_key)
i = orig_line;
/* Initialize search parameters. */
- search_string = (char *)xmalloc (search_string_size = 128);
+ search_string = xmalloc (search_string_size = 128);
*search_string = '\0';
search_string_index = 0;
/* Normalize DIRECTION into 1 or -1. */
- if (direction >= 0)
- direction = 1;
- else
- direction = -1;
+ direction = (direction >= 0) ? 1 : -1;
rl_display_search (search_string, reverse, -1);
sline = rl_line_buffer;
- index = rl_point;
+ sline_len = strlen (sline);
+ line_index = rl_point;
+ found = failed = 0;
while (!done)
{
+ Function *f = (Function *)NULL;
+
+ /* Read a key and decide how to proceed. */
c = rl_read_key ();
/* Hack C to Do What I Mean. */
- {
- Function *f = (Function *)NULL;
-
- if (_rl_keymap[c].type == ISFUNC)
- {
- f = _rl_keymap[c].function;
+ if (_rl_keymap[c].type == ISFUNC)
+ {
+ f = _rl_keymap[c].function;
- if (f == rl_reverse_search_history)
- c = reverse ? -1 : -2;
- else if (f == rl_forward_search_history)
- c = !reverse ? -1 : -2;
- }
- }
+ if (f == rl_reverse_search_history)
+ c = reverse ? -1 : -2;
+ else if (f == rl_forward_search_history)
+ c = !reverse ? -1 : -2;
+ }
switch (c)
{
@@ -217,22 +210,36 @@ rl_search_history (direction, invoking_key)
done = 1;
continue;
- /* case invoking_key: */
case -1:
- goto search_again;
+ if (!search_string_index)
+ continue;
+ else
+ {
+ if (reverse)
+ --line_index;
+ else
+ {
+ if (line_index != sline_len)
+ ++line_index;
+ else
+ ding ();
+ }
+ }
+ break;
/* switch directions */
case -2:
direction = -direction;
reverse = (direction < 0);
-
- goto do_search;
+ break;
case CTRL ('G'):
strcpy (rl_line_buffer, lines[orig_line]);
rl_point = orig_point;
rl_end = strlen (rl_line_buffer);
rl_clear_message ();
+ free (allocated_line);
+ free (lines);
return;
default:
@@ -244,134 +251,122 @@ rl_search_history (direction, invoking_key)
}
else
{
+ /* Add character to search string and continue search. */
if (search_string_index + 2 >= search_string_size)
- search_string = (char *)xrealloc
- (search_string, (search_string_size += 128));
+ {
+ search_string_size += 128;
+ search_string = xrealloc (search_string, search_string_size);
+ }
search_string[search_string_index++] = c;
search_string[search_string_index] = '\0';
- goto do_search;
+ break;
+ }
+ }
- search_again:
+ found = failed = 0;
+ while (1)
+ {
+ int limit = sline_len - search_string_index + 1;
- if (!search_string_index)
- continue;
+ /* 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 += reverse ? -1 : 1;
+ }
+ if (found)
+ break;
+
+ /* Move to the next line, but skip new copies of the line
+ we just found and lines shorter than the string we're
+ searching for. */
+ do
+ {
+ /* Move to the next line. */
+ i += direction;
+
+ /* At limit for direction? */
+ if ((reverse && i < 0) || (!reverse && i == hlen))
{
- if (reverse)
- --index;
- else
- if (index != strlen (sline))
- ++index;
- else
- ding ();
+ failed++;
+ break;
}
- do_search:
- while (1)
- {
- if (reverse)
- {
- while (index >= 0)
- if (strncmp
- (search_string, sline + index, search_string_index)
- == 0)
- goto string_found;
- else
- index--;
- }
- else
- {
- register int limit =
- (strlen (sline) - search_string_index) + 1;
-
- while (index < limit)
- {
- if (strncmp (search_string,
- sline + index,
- search_string_index) == 0)
- goto string_found;
- index++;
- }
- }
-
- next_line:
- i += direction;
-
- /* At limit for direction? */
- if ((reverse && i < 0) ||
- (!reverse && i == hlen))
- goto search_failed;
-
- sline = lines[i];
- if (reverse)
- index = strlen (sline);
- else
- index = 0;
+ /* 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 the search string is longer than the current
- line, no match. */
- if (search_string_index > (int)strlen (sline))
- goto next_line;
+ if (failed)
+ break;
- /* Start actually searching. */
- if (reverse)
- index -= search_string_index;
- }
+ /* Now set up the line for searching... */
+ if (reverse)
+ line_index = sline_len - search_string_index;
+ else
+ line_index = 0;
+ }
- search_failed:
- /* We cannot find the search string. Ding the bell. */
- ding ();
- i = last_found_line;
- break;
+ if (failed)
+ {
+ /* We cannot find the search string. Ding the bell. */
+ ding ();
+ i = last_found_line;
+ break;
+ }
- string_found:
- /* 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. */
- {
- int line_len;
-
- line_len = strlen (lines[i]);
-
- if (line_len >= rl_line_buffer_len)
- rl_extend_line_buffer (line_len);
-
- strcpy (rl_line_buffer, lines[i]);
- rl_point = index;
- rl_end = line_len;
- last_found_line = i;
- rl_display_search
- (search_string, reverse, (i == orig_line) ? -1 : i);
- }
- }
+ /* We have found the search string. Just display it. But don't
+ actually move there in the history list until the user accepts
+ the location. */
+ if (found)
+ {
+ int line_len;
+
+ prev_line_found = lines[i];
+ line_len = strlen (lines[i]);
+
+ if (line_len >= rl_line_buffer_len)
+ rl_extend_line_buffer (line_len);
+
+ strcpy (rl_line_buffer, lines[i]);
+ rl_point = line_index;
+ rl_end = line_len;
+ last_found_line = i;
+ rl_display_search (search_string, reverse, (i == orig_line) ? -1 : i);
}
}
/* 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
- INDEX is -1, then that shows that the string searched for was not
- found. We use this to determine where to place rl_point. */
- {
- int now = last_found_line;
-
- /* First put back the original state. */
- strcpy (rl_line_buffer, lines[orig_line]);
-
- /* Free the search string. */
- free (search_string);
-
- if (now < orig_line)
- rl_get_previous_history (orig_line - now);
- else
- rl_get_next_history (now - orig_line);
-
- /* If the index of the "matched" string is less than zero, then the
- final search string was never matched, so put point somewhere
- reasonable. */
- if (index < 0)
- index = strlen (rl_line_buffer);
-
- rl_point = index;
- rl_clear_message ();
- }
+ LINE_INDEX is -1, then that shows that the string searched for was
+ not found. We use this to determine where to place rl_point. */
+
+ /* First put back the original state. */
+ strcpy (rl_line_buffer, lines[orig_line]);
+
+ /* Free the search string. */
+ free (search_string);
+
+ if (last_found_line < orig_line)
+ rl_get_previous_history (orig_line - last_found_line);
+ else
+ rl_get_next_history (last_found_line - orig_line);
+
+ /* If the string was not found, put point at the end of the line. */
+ if (line_index < 0)
+ line_index = strlen (rl_line_buffer);
+ rl_point = line_index;
+ rl_clear_message ();
+
+ free (allocated_line);
+ free (lines);
+
+ return 0;
}
diff --git a/gnu/lib/libreadline/keymaps.c b/gnu/lib/libreadline/keymaps.c
index 01ee3f2..8bb196d 100644
--- a/gnu/lib/libreadline/keymaps.c
+++ b/gnu/lib/libreadline/keymaps.c
@@ -25,6 +25,7 @@
# include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */
+#include "rlconf.h"
#include "keymaps.h"
#include "emacs_keymap.c"
@@ -32,6 +33,9 @@
#include "vi_keymap.c"
#endif
+extern int rl_do_lowercase_version ();
+extern int rl_rubout (), rl_insert ();
+
#if defined (STATIC_MALLOC)
static char *xmalloc (), *xrealloc ();
#else
@@ -90,7 +94,6 @@ rl_copy_keymap (map)
Keymap
rl_make_keymap ()
{
- extern int rl_insert (), rl_rubout ();
register int i;
Keymap newmap;
@@ -118,6 +121,7 @@ rl_make_keymap ()
}
/* Free the storage associated with MAP. */
+void
rl_discard_keymap (map)
Keymap (map);
{
diff --git a/gnu/lib/libreadline/memalloc.h b/gnu/lib/libreadline/memalloc.h
new file mode 100644
index 0000000..750d53d
--- /dev/null
+++ b/gnu/lib/libreadline/memalloc.h
@@ -0,0 +1,56 @@
+/* memalloc.h -- consolidate code for including alloca.h or malloc.h and
+ defining alloca. */
+
+/* Copyright (C) 1993 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#if !defined (__MEMALLOC_H__)
+# define __MEMALLOC_H__
+
+#if defined (sparc) && defined (sun) && !defined (HAVE_ALLOCA_H)
+# define HAVE_ALLOCA_H
+#endif
+
+#if defined (__GNUC__) && !defined (HAVE_ALLOCA)
+# define HAVE_ALLOCA
+#endif
+
+#if defined (HAVE_ALLOCA_H) && !defined (HAVE_ALLOCA)
+# define HAVE_ALLOCA
+#endif /* HAVE_ALLOCA_H && !HAVE_ALLOCA */
+
+#if !defined (BUILDING_MAKEFILE)
+
+#if defined (__GNUC__)
+# undef alloca
+# define alloca __builtin_alloca
+#else /* !__GNUC__ */
+# if defined (HAVE_ALLOCA_H)
+# if defined (IBMESA)
+# include <malloc.h>
+# else /* !IBMESA */
+# include <alloca.h>
+# endif /* !IBMESA */
+# else
+extern char *alloca ();
+# endif /* !HAVE_ALLOCA_H */
+#endif /* !__GNUC__ */
+
+#endif /* !BUILDING_MAKEFILE */
+
+#endif /* __MEMALLOC_H__ */
diff --git a/gnu/lib/libreadline/parens.c b/gnu/lib/libreadline/parens.c
index 260bc4d..023a736 100644
--- a/gnu/lib/libreadline/parens.c
+++ b/gnu/lib/libreadline/parens.c
@@ -27,6 +27,8 @@
#endif
#include "readline.h"
+extern int rl_explicit_arg;
+
/* Non-zero means try to blink the matching open parenthesis when the
close parenthesis is inserted. */
#if defined (FD_SET)
@@ -40,8 +42,6 @@ static int find_matching_open ();
rl_insert_close (count, invoking_key)
int count, invoking_key;
{
- extern int rl_explicit_arg;
-
if (rl_explicit_arg || !rl_blink_matching_paren)
rl_insert (count, invoking_key);
else
@@ -58,7 +58,7 @@ rl_insert_close (count, invoking_key)
/* Emacs might message or ring the bell here, but I don't. */
if (match_point < 0)
- return;
+ return -1;
FD_ZERO (&readfds);
FD_SET (fileno (rl_instream), &readfds);
@@ -74,6 +74,7 @@ rl_insert_close (count, invoking_key)
rl_insert (count, invoking_key);
#endif /* !FD_SET */
}
+ return 0;
}
static int
diff --git a/gnu/lib/libreadline/readline.c b/gnu/lib/libreadline/readline.c
index a23e344..1f52a5c 100644
--- a/gnu/lib/libreadline/readline.c
+++ b/gnu/lib/libreadline/readline.c
@@ -30,10 +30,10 @@
#include <signal.h>
/* This is needed to include support for TIOCGWINSZ and window resizing. */
-#if defined (OSF1) || defined (BSD386) || defined (_386BSD) || \
- defined (FreeBSD) || defined (NetBSD) || defined (AIX)
+#if defined (OSF1) || defined (BSD386) || defined (NetBSD) || \
+ defined (FreeBSD) || defined (_386BSD) || defined (AIX)
# include <sys/ioctl.h>
-#endif /* OSF1 */
+#endif /* OSF1 || BSD386 */
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
@@ -53,8 +53,6 @@ extern int errno;
#include <setjmp.h>
-/* #define HACK_TERMCAP_MOTION */
-
#include "posixstat.h"
/* System-specific feature definitions and include files. */
@@ -72,12 +70,10 @@ extern int errno;
/* Functions imported from other files in the library. */
extern char *tgetstr ();
extern void rl_prep_terminal (), rl_deprep_terminal ();
-extern void rl_vi_set_last ();
-extern Function *rl_function_of_keyseq ();
-extern char *tilde_expand ();
+
+extern void _rl_bind_if_unbound ();
/* External redisplay functions and variables from display.c */
-extern void rl_redisplay ();
extern void _rl_move_vert ();
extern void _rl_erase_at_end_of_line ();
@@ -86,29 +82,40 @@ extern void _rl_move_cursor_relative ();
extern int _rl_vis_botlin;
extern int _rl_last_c_pos;
extern int rl_display_fixed;
+extern char *rl_display_prompt;
/* Variables imported from complete.c. */
extern char *rl_completer_word_break_characters;
extern char *rl_basic_word_break_characters;
-extern Function *rl_symbolic_link_hook;
extern int rl_completion_query_items;
extern int rl_complete_with_tilde_expansion;
+#if defined (VI_MODE)
+extern void _rl_vi_set_last ();
+extern void _rl_vi_reset_last ();
+extern void _rl_vi_done_inserting ();
+#endif /* VI_MODE */
+
/* Forward declarations used in this file. */
-void rl_dispatch ();
-void free_history_entry ();
-void _rl_output_character_function ();
+void _rl_free_history_entry ();
+
+int _rl_dispatch ();
void _rl_set_screen_size ();
-void free_undo_list (), rl_add_undo ();
+int _rl_output_character_function ();
-#if !defined (_GO32_)
+static char *readline_internal ();
+static void readline_initialize_everything ();
+static int init_terminal_io ();
+static void start_using_history ();
+
+#if !defined (__GO32__)
static void readline_default_bindings ();
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
-#if defined (_GO32_)
+#if defined (__GO32__)
# include <sys/pc.h>
# undef HANDLE_SIGNALS
-#endif /* _GO32_ */
+#endif /* __GO32__ */
#if defined (STATIC_MALLOC)
static char *xmalloc (), *xrealloc ();
@@ -180,6 +187,7 @@ int readline_echoing_p = 1;
/* Current prompt. */
char *rl_prompt;
+int rl_visible_prompt_length = 0;
/* The number of characters read in order to type this complete command. */
int rl_key_sequence_length = 0;
@@ -207,10 +215,10 @@ int _rl_horizontal_scroll_mode = 0;
/* Non-zero means to display an asterisk at the starts of history lines
which have been modified. */
int _rl_mark_modified_lines = 0;
-
-/* Non-zero means to use a visible bell if one is available rather than
- simply ringing the terminal bell. */
-int _rl_prefer_visible_bell = 0;
+
+/* The style of `bell' notification preferred. This can be set to NO_BELL,
+ AUDIBLE_BELL, or VISIBLE_BELL. */
+int _rl_bell_preference = AUDIBLE_BELL;
/* Line buffer and maintenence. */
char *rl_line_buffer = (char *)NULL;
@@ -236,6 +244,10 @@ static int defining_kbd_macro = 0;
emacs_meta_keymap or vi_escape_keymap. */
int _rl_convert_meta_chars_to_ascii = 1;
+/* Non-zero means to output characters with the meta bit set directly
+ rather than as a meta-prefixed escape sequence. */
+int _rl_output_meta_chars = 0;
+
/* Non-zero tells rl_delete_text and rl_insert_text to not add to
the undo list. */
static int doing_an_undo = 0;
@@ -255,7 +267,6 @@ char *
readline (prompt)
char *prompt;
{
- char *readline_internal ();
char *value;
rl_prompt = prompt;
@@ -267,6 +278,8 @@ readline (prompt)
return ((char *)NULL);
}
+ rl_visible_prompt_length = rl_expand_prompt (rl_prompt);
+
rl_initialize ();
rl_prep_terminal (_rl_meta_flag);
@@ -287,7 +300,7 @@ readline (prompt)
/* Read a line of input from the global rl_instream, doing output on
the global rl_outstream.
If rl_prompt is non-null, then that is our prompt. */
-char *
+static char *
readline_internal ()
{
int lastc, c, eof_found;
@@ -351,7 +364,7 @@ readline_internal ()
}
lastc = c;
- rl_dispatch (c, _rl_keymap);
+ _rl_dispatch (c, _rl_keymap);
/* If there was no change in last_command_was_kill, then no kill
has taken place. Note that if input is pending we are reading
@@ -384,7 +397,7 @@ readline_internal ()
rl_revert_line ();
entry = replace_history_entry (where_history (), the_line,
(HIST_ENTRY *)NULL);
- free_history_entry (entry);
+ _rl_free_history_entry (entry);
strcpy (the_line, temp);
free (temp);
@@ -429,6 +442,7 @@ rl_stuff_char (key)
ibuffer[push_index++] = key;
if (push_index >= ibuffer_len)
push_index = 0;
+ return push_index;
}
/* Return the amount of space available in the
@@ -483,7 +497,7 @@ rl_unget_char (key)
void
rl_gather_tyi ()
{
-#if defined (_GO32_)
+#if defined (__GO32__)
char input;
if (isatty (0))
@@ -495,7 +509,7 @@ rl_gather_tyi ()
}
else if (kbhit () && ibuffer_space ())
rl_stuff_char (getkey ());
-#else /* !_GO32_ */
+#else /* !__GO32__ */
int tty = fileno (in_stream);
register int tem, result = -1;
@@ -549,7 +563,7 @@ rl_gather_tyi ()
if (chars_avail)
rl_stuff_char (input);
}
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
}
static int next_macro_key ();
@@ -597,14 +611,12 @@ static void add_macro_char (), with_macro_input ();
/* 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. */
-void
-rl_dispatch (key, map)
+int
+_rl_dispatch (key, map)
register int key;
Keymap map;
{
-#if defined (VI_MODE)
- extern int _rl_vi_last_command, _rl_vi_last_repeat, _rl_vi_last_arg_sign;
-#endif
+ int r = 0;
if (defining_kbd_macro)
add_macro_char (key);
@@ -613,18 +625,14 @@ rl_dispatch (key, map)
{
if (map[ESC].type == ISKMAP)
{
-#if defined (CRAY)
- map = (Keymap)((int)map[ESC].function);
-#else
- map = (Keymap)map[ESC].function;
-#endif
+ map = FUNCTION_TO_KEYMAP (map, ESC);
key = UNMETA (key);
rl_key_sequence_length += 2;
- rl_dispatch (key, map);
+ return (_rl_dispatch (key, map));
}
else
ding ();
- return;
+ return 0;
}
switch (map[key].type)
@@ -637,12 +645,9 @@ rl_dispatch (key, map)
{
/* Special case rl_do_lowercase_version (). */
if (func == rl_do_lowercase_version)
- {
- rl_dispatch (to_lower (key), map);
- return;
- }
+ return (_rl_dispatch (to_lower (key), map));
- (*map[key].function)(rl_numeric_arg * rl_arg_sign, key);
+ r = (*map[key].function)(rl_numeric_arg * rl_arg_sign, key);
/* If we have input pending, then the last command was a prefix
command. Don't change the state of rl_last_func. Otherwise,
@@ -653,7 +658,7 @@ rl_dispatch (key, map)
else
{
rl_abort ();
- return;
+ return -1;
}
}
break;
@@ -665,21 +670,12 @@ rl_dispatch (key, map)
rl_key_sequence_length++;
newkey = rl_read_key ();
-#if defined (CRAY)
- /* If you cast map[key].function to type (Keymap) on a Cray,
- the compiler takes the value of may[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. */
- rl_dispatch (newkey, (Keymap)((int)map[key].function));
-#else
- rl_dispatch (newkey, (Keymap)map[key].function);
-#endif /* !CRAY */
+ r = _rl_dispatch (newkey, FUNCTION_TO_KEYMAP (map, key));
}
else
{
rl_abort ();
- return;
+ return -1;
}
break;
@@ -690,19 +686,16 @@ rl_dispatch (key, map)
macro = savestring ((char *)map[key].function);
with_macro_input (macro);
- return;
+ return 0;
}
break;
}
#if defined (VI_MODE)
if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap &&
rl_vi_textmod_command (key))
- {
- _rl_vi_last_command = key;
- _rl_vi_last_repeat = rl_numeric_arg;
- _rl_vi_last_arg_sign = rl_arg_sign;
- }
+ _rl_vi_set_last (key, rl_numeric_arg, rl_arg_sign);
#endif
+ return (r);
}
@@ -734,7 +727,7 @@ static int current_macro_index = 0;
struct saved_macro {
struct saved_macro *next;
char *string;
- int index;
+ int sindex;
};
/* The list of saved macros. */
@@ -782,7 +775,7 @@ push_executing_macro ()
saver = (struct saved_macro *)xmalloc (sizeof (struct saved_macro));
saver->next = macro_list;
- saver->index = executing_macro_index;
+ saver->sindex = executing_macro_index;
saver->string = executing_macro;
macro_list = saver;
@@ -803,7 +796,7 @@ pop_executing_macro ()
{
struct saved_macro *disposer = macro_list;
executing_macro = macro_list->string;
- executing_macro_index = macro_list->index;
+ executing_macro_index = macro_list->sindex;
macro_list = macro_list->next;
free (disposer);
}
@@ -837,7 +830,10 @@ rl_start_kbd_macro (ignore1, ignore2)
int ignore1, ignore2;
{
if (defining_kbd_macro)
- rl_abort ();
+ {
+ rl_abort ();
+ return -1;
+ }
if (rl_explicit_arg)
{
@@ -848,6 +844,7 @@ rl_start_kbd_macro (ignore1, ignore2)
current_macro_index = 0;
defining_kbd_macro = 1;
+ return 0;
}
/* Stop defining a keyboard macro.
@@ -857,14 +854,17 @@ rl_end_kbd_macro (count, ignore)
int count, ignore;
{
if (!defining_kbd_macro)
- rl_abort ();
+ {
+ rl_abort ();
+ return -1;
+ }
current_macro_index -= (rl_key_sequence_length - 1);
current_macro[current_macro_index] = '\0';
defining_kbd_macro = 0;
- rl_call_last_kbd_macro (--count, 0);
+ return (rl_call_last_kbd_macro (--count, 0));
}
/* Execute the most recently defined keyboard macro.
@@ -884,6 +884,7 @@ rl_call_last_kbd_macro (count, ignore)
while (count--)
with_macro_input (savestring (current_macro));
+ return 0;
}
void
@@ -905,7 +906,6 @@ _rl_kill_kbd_macro ()
defining_kbd_macro = 0;
}
-
/* **************************************************************** */
/* */
@@ -943,9 +943,12 @@ rl_initialize ()
/* Parsing of key-bindings begins in an enabled state. */
_rl_parsing_conditionalized_out = 0;
+
+ return 0;
}
/* Initialize the entire state of the world. */
+static void
readline_initialize_everything ()
{
/* Find out if we are running in Emacs. */
@@ -971,10 +974,10 @@ readline_initialize_everything ()
/* Initialize the terminal interface. */
init_terminal_io ((char *)NULL);
-#if !defined (_GO32_)
+#if !defined (__GO32__)
/* Bind tty characters to readline functions. */
readline_default_bindings ();
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
/* Initialize the function names. */
rl_initialize_funmap ();
@@ -982,12 +985,14 @@ readline_initialize_everything ()
/* Read in the init file. */
rl_read_init_file ((char *)NULL);
+ /* Override the effect of any `set keymap' assignments in the
+ inputrc file. */
+ rl_set_keymap_from_edit_mode ();
+
/* 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;
- }
+ if (rl_completer_word_break_characters == (char *)NULL)
+ rl_completer_word_break_characters = rl_basic_word_break_characters;
}
/* If this system allows us to look at the values of the regular
@@ -1007,42 +1012,11 @@ readline_default_bindings ()
/* **************************************************************** */
/* Handle C-u style numeric args, as well as M--, and M-digits. */
-
-/* Add the current digit to the argument in progress. */
-rl_digit_argument (ignore, key)
- int ignore, key;
-{
- rl_pending_input = key;
- rl_digit_loop ();
-}
-
-/* What to do when you abort reading an argument. */
-rl_discard_argument ()
-{
- ding ();
- rl_clear_message ();
- rl_init_argument ();
-}
-
-/* Create a default argument. */
-rl_init_argument ()
-{
- rl_numeric_arg = rl_arg_sign = 1;
- rl_explicit_arg = 0;
-}
-
-/* C-u, universal argument. Multiply the current argument by 4.
- Read a key. If the key has nothing to do with arguments, then
- dispatch on it. If the key is the abort character then abort. */
-rl_universal_argument ()
-{
- rl_numeric_arg *= 4;
- rl_digit_loop ();
-}
-
+static int
rl_digit_loop ()
{
int key, c;
+
while (1)
{
rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg);
@@ -1073,11 +1047,45 @@ rl_digit_loop ()
else
{
rl_clear_message ();
- rl_dispatch (key, _rl_keymap);
- return;
+ return (_rl_dispatch (key, _rl_keymap));
}
}
}
+ return 0;
+}
+
+/* Add the current digit to the argument in progress. */
+rl_digit_argument (ignore, key)
+ int ignore, key;
+{
+ rl_pending_input = key;
+ return (rl_digit_loop ());
+}
+
+/* What to do when you abort reading an argument. */
+rl_discard_argument ()
+{
+ ding ();
+ rl_clear_message ();
+ rl_init_argument ();
+ return 0;
+}
+
+/* Create a default argument. */
+rl_init_argument ()
+{
+ rl_numeric_arg = rl_arg_sign = 1;
+ rl_explicit_arg = 0;
+ return 0;
+}
+
+/* C-u, universal argument. Multiply the current argument by 4.
+ Read a key. If the key has nothing to do with arguments, then
+ dispatch on it. If the key is the abort character then abort. */
+rl_universal_argument ()
+{
+ rl_numeric_arg *= 4;
+ return (rl_digit_loop ());
}
/* **************************************************************** */
@@ -1089,6 +1097,8 @@ rl_digit_loop ()
static char *term_buffer = (char *)NULL;
static char *term_string_buffer = (char *)NULL;
+static int tcap_initialized = 0;
+
/* Non-zero means this terminal can't really do anything. */
int dumb_term = 0;
/* On Solaris2, sys/types.h #includes sys/reg.h, which #defines PC.
@@ -1102,8 +1112,9 @@ char *BC, *UP;
/* Some strings to control terminal actions. These are output by tputs (). */
char *term_goto, *term_clreol, *term_cr, *term_clrpag, *term_backspace;
+char *term_pc;
-int screenwidth, screenheight;
+int screenwidth, screenheight, screenchars;
/* Non-zero if we determine that the terminal can do character insertion. */
int terminal_can_insert = 0;
@@ -1136,12 +1147,16 @@ char *term_mo;
/* The key sequences output by the arrow keys, if this terminal has any. */
char *term_ku, *term_kd, *term_kr, *term_kl;
+/* How to initialize and reset the arrow keys, if this terminal has any. */
+char *term_ks, *term_ke;
+
/* Re-initialize the terminal considering that the TERM/TERMCAP variable
has changed. */
rl_reset_terminal (terminal_name)
char *terminal_name;
{
init_terminal_io (terminal_name);
+ return 0;
}
/* Set readline's idea of the screen size. TTY is a file descriptor open
@@ -1191,7 +1206,7 @@ _rl_set_screen_size (tty, ignore_env)
}
/* If all else fails, default to 80x24 terminal. */
- if (screenwidth <= 0)
+ if (screenwidth <= 1)
screenwidth = 80;
if (screenheight <= 0)
@@ -1204,19 +1219,73 @@ _rl_set_screen_size (tty, ignore_env)
#endif
screenwidth--;
+
+ screenchars = screenwidth * screenheight;
}
+struct _tc_string {
+ char *tc_var;
+ char **tc_value;
+};
+
+/* This should be kept sorted, just in case we decide to change the
+ search algorithm to something smarter. */
+static struct _tc_string tc_strings[] =
+{
+ "DC", &term_DC,
+ "IC", &term_IC,
+ "ce", &term_clreol,
+ "cl", &term_clrpag,
+ "cr", &term_cr,
+ "dc", &term_dc,
+ "ei", &term_ei,
+ "ic", &term_ic,
+ "im", &term_im,
+ "kd", &term_kd,
+ "kl", &term_kl,
+ "kr", &term_kr,
+ "ku", &term_ku,
+ "ks", &term_ks,
+ "ke", &term_ke,
+ "le", &term_backspace,
+ "mm", &term_mm,
+ "mo", &term_mo,
+#if defined (HACK_TERMCAP_MOTION)
+ "nd", &term_forward_char,
+#endif
+ "pc", &term_pc,
+ "up", &term_up,
+ "vb", &visible_bell,
+};
+
+#define NUM_TC_STRINGS (sizeof (tc_strings) / sizeof (struct _tc_string))
+
+/* Read the desired terminal capability strings into BP. The capabilities
+ are described in the TC_STRINGS table. */
+static void
+get_term_capabilities (bp)
+ char **bp;
+{
+ register int i;
+
+ for (i = 0; i < NUM_TC_STRINGS; i++)
+ *(tc_strings[i].tc_value) = tgetstr (tc_strings[i].tc_var, bp);
+ tcap_initialized = 1;
+}
+
+static int
init_terminal_io (terminal_name)
char *terminal_name;
{
-#if defined (_GO32_)
+#if defined (__GO32__)
screenwidth = ScreenCols ();
screenheight = ScreenRows ();
+ screenchars = screenwidth * screenheight;
term_cr = "\r";
term_im = term_ei = term_ic = term_IC = (char *)NULL;
term_up = term_dc = term_DC = visible_bell = (char *)NULL;
- /* Does the _GO32_ have a meta key? I don't know. */
+ /* Does the __GO32__ have a meta key? I don't know. */
term_has_meta = 0;
term_mm = term_mo = (char *)NULL;
@@ -1228,7 +1297,7 @@ init_terminal_io (terminal_name)
#endif /* HACK_TERMCAP_MOTION */
terminal_can_insert = 0;
return;
-#else /* !_GO32_ */
+#else /* !__GO32__ */
char *term, *buffer;
int tty;
@@ -1253,6 +1322,7 @@ init_terminal_io (terminal_name)
dumb_term = 1;
screenwidth = 79;
screenheight = 24;
+ screenchars = 79 * 24;
term_cr = "\r";
term_im = term_ei = term_ic = term_IC = (char *)NULL;
term_up = term_dc = term_DC = visible_bell = (char *)NULL;
@@ -1264,22 +1334,17 @@ init_terminal_io (terminal_name)
return 0;
}
- BC = tgetstr ("pc", &buffer);
- PC = buffer ? *buffer : 0;
-
- term_backspace = tgetstr ("le", &buffer);
+ get_term_capabilities (&buffer);
- term_cr = tgetstr ("cr", &buffer);
- term_clreol = tgetstr ("ce", &buffer);
- term_clrpag = tgetstr ("cl", &buffer);
+ /* Set up the variables that the termcap library expects the application
+ to provide. */
+ PC = term_pc ? *term_pc : 0;
+ BC = term_backspace;
+ UP = term_up;
if (!term_cr)
term_cr = "\r";
-#if defined (HACK_TERMCAP_MOTION)
- term_forward_char = tgetstr ("nd", &buffer);
-#endif /* HACK_TERMCAP_MOTION */
-
if (rl_instream)
tty = fileno (rl_instream);
else
@@ -1289,31 +1354,16 @@ init_terminal_io (terminal_name)
_rl_set_screen_size (tty, 0);
- term_im = tgetstr ("im", &buffer);
- term_ei = tgetstr ("ei", &buffer);
- term_IC = tgetstr ("IC", &buffer);
- term_ic = tgetstr ("ic", &buffer);
-
/* "An application program can assume that the terminal can do
character insertion if *any one of* the capabilities `IC',
`im', `ic' or `ip' is provided." But we can't do anything if
only `ip' is provided, so... */
terminal_can_insert = (term_IC || term_im || term_ic);
- term_up = tgetstr ("up", &buffer);
- term_dc = tgetstr ("dc", &buffer);
- term_DC = tgetstr ("DC", &buffer);
-
- visible_bell = tgetstr ("vb", &buffer);
-
- /* Check to see if this terminal has a meta key. */
+ /* Check to see if this terminal has a meta key and clear the capability
+ variables if there is none. */
term_has_meta = (tgetflag ("km") || tgetflag ("MT"));
- if (term_has_meta)
- {
- term_mm = tgetstr ("mm", &buffer);
- term_mo = tgetstr ("mo", &buffer);
- }
- else
+ if (!term_has_meta)
{
term_mm = (char *)NULL;
term_mo = (char *)NULL;
@@ -1321,60 +1371,37 @@ init_terminal_io (terminal_name)
/* Attempt to find and bind the arrow keys. Do not override already
bound keys in an overzealous attempt, however. */
- term_ku = tgetstr ("ku", &buffer);
- term_kd = tgetstr ("kd", &buffer);
- term_kr = tgetstr ("kr", &buffer);
- term_kl = tgetstr ("kl", &buffer);
+ _rl_bind_if_unbound (term_ku, rl_get_previous_history);
+ _rl_bind_if_unbound (term_kd, rl_get_next_history);
+ _rl_bind_if_unbound (term_kr, rl_forward);
+ _rl_bind_if_unbound (term_kl, rl_backward);
- if (term_ku)
- {
- Function *func;
-
- func = rl_function_of_keyseq (term_ku, _rl_keymap, (int *)NULL);
-
- if (!func || func == rl_do_lowercase_version)
- rl_set_key (term_ku, rl_get_previous_history, _rl_keymap);
- }
-
- if (term_kd)
- {
- Function *func;
-
- func = rl_function_of_keyseq (term_kd, _rl_keymap, (int *)NULL);
-
- if (!func || func == rl_do_lowercase_version)
- rl_set_key (term_kd, rl_get_next_history, _rl_keymap);
- }
-
- if (term_kr)
- {
- Function *func;
-
- func = rl_function_of_keyseq (term_kr, _rl_keymap, (int *)NULL);
+#endif /* !__GO32__ */
+ return 0;
+}
- if (!func || func == rl_do_lowercase_version)
- rl_set_key (term_kr, rl_forward, _rl_keymap);
- }
+char *
+rl_get_termcap (cap)
+ char *cap;
+{
+ register int i;
- if (term_kl)
+ if (tcap_initialized == 0)
+ return ((char *)NULL);
+ for (i = 0; i < NUM_TC_STRINGS; i++)
{
- Function *func;
-
- func = rl_function_of_keyseq (term_kl, _rl_keymap, (int *)NULL);
-
- if (!func || func == rl_do_lowercase_version)
- rl_set_key (term_kl, rl_backward, _rl_keymap);
+ if (tc_strings[i].tc_var[0] == cap[0] && strcmp (tc_strings[i].tc_var, cap) == 0)
+ return *(tc_strings[i].tc_value);
}
-#endif /* !_GO32_ */
- return 0;
+ return ((char *)NULL);
}
/* A function for the use of tputs () */
-void
+int
_rl_output_character_function (c)
int c;
{
- putc (c, out_stream);
+ return putc (c, out_stream);
}
/* Write COUNT characters from STRING to the output stream. */
@@ -1392,14 +1419,15 @@ backspace (count)
{
register int i;
-#if !defined (_GO32_)
+#if !defined (__GO32__)
if (term_backspace)
for (i = 0; i < count; i++)
tputs (term_backspace, 1, _rl_output_character_function);
else
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
for (i = 0; i < count; i++)
putc ('\b', out_stream);
+ return 0;
}
/* Move to the start of the next line. */
@@ -1409,6 +1437,7 @@ crlf ()
tputs (term_cr, 1, _rl_output_character_function);
#endif /* NEW_TTY_DRIVER */
putc ('\n', out_stream);
+ return 0;
}
@@ -1451,15 +1480,29 @@ ding ()
{
if (readline_echoing_p)
{
-#if !defined (_GO32_)
- if (_rl_prefer_visible_bell && visible_bell)
- tputs (visible_bell, 1, _rl_output_character_function);
- else
-#endif /* !_GO32_ */
- {
+#if !defined (__GO32__)
+ switch (_rl_bell_preference)
+ {
+ case NO_BELL:
+ default:
+ break;
+ case VISIBLE_BELL:
+ if (visible_bell)
+ {
+ tputs (visible_bell, 1, _rl_output_character_function);
+ break;
+ }
+ /* FALLTHROUGH */
+ case AUDIBLE_BELL:
fprintf (stderr, "\007");
fflush (stderr);
- }
+ break;
+ }
+#else /* __GO32__ */
+ fprintf (stderr, "\007");
+ fflush (stderr);
+#endif /* __GO32__ */
+ return (0);
}
return (-1);
}
@@ -1544,7 +1587,7 @@ rl_insert_text (string)
if (!doing_an_undo)
{
/* If possible and desirable, concatenate the undos. */
- if ((strlen (string) == 1) &&
+ if ((l == 1) &&
rl_undo_list &&
(rl_undo_list->what == UNDO_INSERT) &&
(rl_undo_list->end == rl_point) &&
@@ -1556,6 +1599,7 @@ rl_insert_text (string)
rl_point += l;
rl_end += l;
the_line[rl_end] = '\0';
+ return l;
}
/* Delete the string between FROM and TO. FROM is
@@ -1564,6 +1608,7 @@ rl_delete_text (from, to)
int from, to;
{
register char *text;
+ register int diff, i;
/* Fix it if the caller is confused. */
if (from > to)
@@ -1573,7 +1618,11 @@ rl_delete_text (from, to)
to = t;
}
text = rl_copy_text (from, to);
- strncpy (the_line + from, the_line + to, rl_end - to);
+
+ /* Some versions of strncpy() can't handle overlapping arguments. */
+ diff = to - from;
+ for (i = from; i < rl_end - diff; i++)
+ the_line[i] = the_line[i + diff];
/* Remember how to undo this delete. */
if (!doing_an_undo)
@@ -1581,8 +1630,9 @@ rl_delete_text (from, to)
else
free (text);
- rl_end -= (to - from);
+ rl_end -= diff;
the_line[rl_end] = '\0';
+ return (diff);
}
@@ -1626,22 +1676,23 @@ rl_forward (count)
{
if (count < 0)
rl_backward (-count);
- else
- while (count)
- {
+ else if (count > 0)
+ {
+ int end = rl_point + count;
#if defined (VI_MODE)
- if (rl_point >= (rl_end - (rl_editing_mode == vi_mode)))
+ int lend = rl_end - (rl_editing_mode == vi_mode);
#else
- if (rl_point == rl_end)
-#endif /* VI_MODE */
- {
- ding ();
- return 0;
- }
- else
- rl_point++;
- --count;
- }
+ int lend = rl_end;
+#endif
+
+ if (end > lend)
+ {
+ rl_point = lend;
+ ding ();
+ }
+ else
+ rl_point = end;
+ }
return 0;
}
@@ -1651,18 +1702,16 @@ rl_backward (count)
{
if (count < 0)
rl_forward (-count);
- else
- while (count)
- {
- if (!rl_point)
- {
- ding ();
- return 0;
- }
- else
- --rl_point;
- --count;
- }
+ else if (count > 0)
+ {
+ if (rl_point < count)
+ {
+ rl_point = 0;
+ ding ();
+ }
+ else
+ rl_point -= count;
+ }
return 0;
}
@@ -1705,14 +1754,17 @@ rl_forward_word (count)
while (++rl_point < rl_end)
{
c = the_line[rl_point];
- if (alphabetic (c)) break;
+ if (alphabetic (c))
+ break;
}
}
- if (rl_point == rl_end) return;
+ if (rl_point == rl_end)
+ return 0;
while (++rl_point < rl_end)
{
c = the_line[rl_point];
- if (!alphabetic (c)) break;
+ if (!alphabetic (c))
+ break;
}
--count;
}
@@ -1745,7 +1797,8 @@ rl_backward_word (count)
while (--rl_point)
{
c = the_line[rl_point - 1];
- if (alphabetic (c)) break;
+ if (alphabetic (c))
+ break;
}
}
@@ -1754,7 +1807,8 @@ rl_backward_word (count)
c = the_line[rl_point - 1];
if (!alphabetic (c))
break;
- else --rl_point;
+ else
+ --rl_point;
}
--count;
}
@@ -1764,12 +1818,24 @@ rl_backward_word (count)
/* Clear the current line. Numeric argument to C-l does this. */
rl_refresh_line ()
{
- int curr_line = _rl_last_c_pos / screenwidth;
+ int curr_line, nleft;
+
+ /* Find out whether or not there might be invisible characters in the
+ editing buffer. */
+ if (rl_display_prompt == rl_prompt)
+ nleft = _rl_last_c_pos - screenwidth - rl_visible_prompt_length;
+ else
+ nleft = _rl_last_c_pos - screenwidth;
+
+ if (nleft > 0)
+ curr_line = 1 + nleft / screenwidth;
+ else
+ curr_line = 0;
_rl_move_vert (curr_line);
_rl_move_cursor_relative (0, the_line); /* XXX is this right */
-#if defined (_GO32_)
+#if defined (__GO32__)
{
int row, col, width, row_start;
@@ -1778,10 +1844,10 @@ rl_refresh_line ()
row_start = ScreenPrimary + (row * width);
memset (row_start + col, 0, (width - col) * 2);
}
-#else /* !_GO32_ */
+#else /* !__GO32__ */
if (term_clreol)
tputs (term_clreol, 1, _rl_output_character_function);
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
rl_forced_update_display ();
rl_display_fixed = 1;
@@ -1800,11 +1866,11 @@ rl_clear_screen ()
return 0;
}
-#if !defined (_GO32_)
+#if !defined (__GO32__)
if (term_clrpag)
tputs (term_clrpag, 1, _rl_output_character_function);
else
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
crlf ();
rl_forced_update_display ();
@@ -1865,32 +1931,34 @@ rl_insert (count, c)
readline because of extra large arguments. */
if (count > 1 && count < 1024)
{
- string = (char *)alloca (1 + count);
+ string = xmalloc (1 + count);
for (i = 0; i < count; i++)
string[i] = c;
string[i] = '\0';
rl_insert_text (string);
+ free (string);
+
return 0;
}
if (count > 1024)
{
int decreaser;
-
- string = (char *)alloca (1024 + 1);
+ char str[1024+1];
for (i = 0; i < 1024; i++)
- string[i] = c;
+ str[i] = c;
while (count)
{
decreaser = (count > 1024 ? 1024 : count);
- string[decreaser] = '\0';
- rl_insert_text (string);
+ str[decreaser] = '\0';
+ rl_insert_text (str);
count -= decreaser;
}
+
return 0;
}
@@ -1903,7 +1971,7 @@ rl_insert (count, c)
int key = 0, t;
i = 0;
- string = (char *)alloca (ibuffer_len + 1);
+ string = xmalloc (ibuffer_len + 1);
string[i++] = c;
while ((t = rl_get_char (&key)) &&
@@ -1916,15 +1984,16 @@ rl_insert (count, c)
string[i] = '\0';
rl_insert_text (string);
+ free (string);
}
else
{
/* Inserting a single character. */
- string = (char *)alloca (2);
+ char str[2];
- string[1] = '\0';
- string[0] = c;
- rl_insert_text (string);
+ str[1] = '\0';
+ str[0] = c;
+ rl_insert_text (str);
}
return 0;
}
@@ -1956,15 +2025,8 @@ rl_newline (count, key)
rl_done = 1;
#if defined (VI_MODE)
- {
- extern int _rl_vi_doing_insert;
- if (_rl_vi_doing_insert)
- {
- rl_end_undo_group ();
- _rl_vi_doing_insert = 0;
- }
- }
- rl_vi_set_last ();
+ _rl_vi_done_inserting ();
+ _rl_vi_reset_last ();
#endif /* VI_MODE */
@@ -1993,7 +2055,7 @@ rl_clean_up_for_exit ()
/* What to do for some uppercase characters, like meta characters,
and some characters appearing in emacs_ctlx_keymap. This function
- is just a stub, you bind keys to it and the code in rl_dispatch ()
+ is just a stub, you bind keys to it and the code in _rl_dispatch ()
is special cased. */
rl_do_lowercase_version (ignore1, ignore2)
int ignore1, ignore2;
@@ -2116,7 +2178,7 @@ rl_unix_word_rubout ()
while (rl_point && !whitespace (the_line[rl_point - 1]))
rl_point--;
- rl_kill_text (rl_point, orig_point);
+ rl_kill_text (orig_point, rl_point);
}
return 0;
}
@@ -2431,11 +2493,7 @@ undo_thing:
if (waiting_for_begin)
waiting_for_begin--;
else
-#if 0
- abort ();
-#else
ding ();
-#endif
break;
}
@@ -2535,19 +2593,19 @@ rl_undo_command (count)
HIST_ENTRY *saved_line_for_history = (HIST_ENTRY *)NULL;
/* Set the history pointer back to the last entry in the history. */
+static void
start_using_history ()
{
using_history ();
if (saved_line_for_history)
- free_history_entry (saved_line_for_history);
+ _rl_free_history_entry (saved_line_for_history);
saved_line_for_history = (HIST_ENTRY *)NULL;
- return 0;
}
/* Free the contents (and containing structure) of a HIST_ENTRY. */
void
-free_history_entry (entry)
+_rl_free_history_entry (entry)
HIST_ENTRY *entry;
{
if (!entry)
@@ -2586,7 +2644,7 @@ maybe_unsave_line ()
strcpy (the_line, saved_line_for_history->line);
rl_undo_list = (UNDO_LIST *)saved_line_for_history->data;
- free_history_entry (saved_line_for_history);
+ _rl_free_history_entry (saved_line_for_history);
saved_line_for_history = (HIST_ENTRY *)NULL;
rl_end = rl_point = strlen (the_line);
}
@@ -2927,8 +2985,8 @@ rl_kill_word (count)
}
/* Rubout the word before point, placing it on the kill ring. */
-rl_backward_kill_word (count)
- int count;
+rl_backward_kill_word (count, ignore)
+ int count, ignore;
{
int orig_point = rl_point;
@@ -2941,6 +2999,7 @@ rl_backward_kill_word (count)
if (rl_point != orig_point)
rl_kill_text (orig_point, rl_point);
}
+ return 0;
}
/* Kill from here to the end of the line. If DIRECTION is negative, kill
@@ -2984,8 +3043,20 @@ rl_backward_kill_line (direction)
return 0;
}
+/* Kill the whole line, no matter where point is. */
+rl_kill_full_line (count, ignore)
+ int count, ignore;
+{
+ rl_begin_undo_group ();
+ rl_point = 0;
+ rl_kill_text (rl_point, rl_end);
+ rl_end_undo_group ();
+ return 0;
+}
+
/* Yank back the last killed text. This ignores arguments. */
-rl_yank ()
+rl_yank (count, ignore)
+ int count, ignore;
{
if (!rl_kill_ring)
{
@@ -3002,7 +3073,8 @@ rl_yank ()
before point is identical to the current kill item, then
delete that text from the line, rotate the index down, and
yank back some other text. */
-rl_yank_pop ()
+rl_yank_pop (count, key)
+ int count, key;
{
int l;
@@ -3023,7 +3095,7 @@ rl_yank_pop ()
rl_kill_index--;
if (rl_kill_index < 0)
rl_kill_index = rl_kill_ring_length - 1;
- rl_yank ();
+ rl_yank (1, 0);
return 0;
}
else
@@ -3035,7 +3107,7 @@ rl_yank_pop ()
/* Yank the COUNTth argument from the previous history line. */
rl_yank_nth_arg (count, ignore)
- int count;
+ int count, ignore;
{
register HIST_ENTRY *entry = previous_history ();
char *arg;
@@ -3061,14 +3133,12 @@ rl_yank_nth_arg (count, ignore)
/* Vi mode always inserts a space before yanking the argument, and it
inserts it right *after* rl_point. */
if (rl_editing_mode == vi_mode)
- rl_point++;
+ {
+ rl_vi_append_mode ();
+ rl_insert_text (" ");
+ }
#endif /* VI_MODE */
-#if 0
- if (rl_point && the_line[rl_point - 1] != ' ')
- rl_insert_text (" ");
-#endif
-
rl_insert_text (arg);
free (arg);
@@ -3077,7 +3147,8 @@ rl_yank_nth_arg (count, ignore)
}
/* How to toggle back and forth between editing modes. */
-rl_vi_editing_mode ()
+rl_vi_editing_mode (count, key)
+ int count, key;
{
#if defined (VI_MODE)
rl_editing_mode = vi_mode;
@@ -3086,7 +3157,8 @@ rl_vi_editing_mode ()
#endif /* VI_MODE */
}
-rl_emacs_editing_mode ()
+rl_emacs_editing_mode (count, key)
+ int count, key;
{
rl_editing_mode = emacs_mode;
_rl_keymap = emacs_standard_keymap;
@@ -3107,10 +3179,10 @@ rl_getc (stream)
int result;
unsigned char c;
-#if defined (_GO32_)
+#if defined (__GO32__)
if (isatty (0))
return (getkey ());
-#endif /* _GO32_ */
+#endif /* __GO32__ */
while (1)
{
@@ -3157,13 +3229,13 @@ rl_getc (stream)
}
#endif /* _POSIX_VERSION && EAGAIN && O_NONBLOCK */
-#if !defined (_GO32_)
+#if !defined (__GO32__)
/* If the error that we received was SIGINT, then try again,
this is simply an interrupted system call to read ().
Otherwise, some error ocurred, also signifying EOF. */
if (errno != EINTR)
return (EOF);
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
}
}
diff --git a/gnu/lib/libreadline/readline/chardefs.h b/gnu/lib/libreadline/readline/chardefs.h
index 2dde30a..aa63da6 100644
--- a/gnu/lib/libreadline/readline/chardefs.h
+++ b/gnu/lib/libreadline/readline/chardefs.h
@@ -32,19 +32,23 @@ extern char *xmalloc ();
#define UNMETA(c) ((c) & (~meta_character_bit))
#define UNCTRL(c) to_upper(((c)|control_character_bit))
-#define lowercase_p(c) (((c) > ('a' - 1) && (c) < ('z' + 1)))
-#define uppercase_p(c) (((c) > ('A' - 1) && (c) < ('Z' + 1)))
+#define lowercase_p(c) islower(c)
+#define uppercase_p(c) isupper(c)
-#define pure_alphabetic(c) (lowercase_p(c) || uppercase_p(c))
+#define pure_alphabetic(c) isalpha(c)
#ifndef to_upper
-#define to_upper(c) (lowercase_p(c) ? ((c) - 32) : (c))
-#define to_lower(c) (uppercase_p(c) ? ((c) + 32) : (c))
+#define to_upper(c) toupper(c)
+#define to_lower(c) tolower(c)
#endif
#define CTRL_P(c) ((c) < control_character_threshold)
#define META_P(c) ((c) > meta_character_threshold)
+#ifndef digit_value
+#define digit_value(x) ((x) - '0')
+#endif
+
#ifndef NEWLINE
#define NEWLINE '\n'
#endif
@@ -54,7 +58,7 @@ extern char *xmalloc ();
#endif
#ifndef RUBOUT
-#define RUBOUT 0x07f
+#define RUBOUT 0x7f
#endif
#ifndef TAB
@@ -74,7 +78,7 @@ extern char *xmalloc ();
#ifdef SPACE
#undef SPACE
#endif
-#define SPACE 0x020
+#define SPACE 0x20
#ifdef ESC
#undef ESC
diff --git a/gnu/lib/libreadline/readline/history.h b/gnu/lib/libreadline/readline/history.h
index 72bdff9..2ef5424 100644
--- a/gnu/lib/libreadline/readline/history.h
+++ b/gnu/lib/libreadline/readline/history.h
@@ -125,6 +125,10 @@ extern int history_search ();
error message. */
extern int history_expand ();
+/* Return an array of tokens, much as the shell might. The tokens are
+ parsed out of STRING. */
+extern char **history_tokenize ();
+
/* Extract a string segment consisting of the FIRST through LAST
arguments present in STRING. Arguments are broken up as in
the shell. */
@@ -133,3 +137,13 @@ extern char *history_arg_extract ();
/* 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 ();
+
+/* Exported history variables. */
+extern int history_stifled;
+extern int history_length;
+extern int max_input_history;
+extern char history_expansion_char;
+extern char history_subst_char;
+extern char history_comment_char;
+extern char *history_no_expand_chars;
+extern int history_base;
diff --git a/gnu/lib/libreadline/readline/keymaps.h b/gnu/lib/libreadline/readline/keymaps.h
index 2419f1a..f7e9f6f 100644
--- a/gnu/lib/libreadline/readline/keymaps.h
+++ b/gnu/lib/libreadline/readline/keymaps.h
@@ -66,24 +66,26 @@ extern KEYMAP_ENTRY_ARRAY vi_insertion_keymap, vi_movement_keymap;
/* Return a new, empty keymap.
Free it with free() when you are done. */
-Keymap rl_make_bare_keymap ();
+extern Keymap rl_make_bare_keymap ();
/* Return a new keymap which is a copy of MAP. */
-Keymap rl_copy_keymap ();
+extern Keymap rl_copy_keymap ();
/* Return a new keymap with the printing characters bound to rl_insert,
the lowercase Meta characters bound to run their equivalents, and
the Meta digits bound to produce numeric arguments. */
-Keymap rl_make_keymap ();
+extern Keymap rl_make_keymap ();
+
+extern void rl_discard_keymap ();
/* Return the keymap corresponding to a given name. Names look like
`emacs' or `emacs-meta' or `vi-insert'. */
-Keymap rl_get_keymap_by_name ();
+extern Keymap rl_get_keymap_by_name ();
/* Return the current keymap. */
-Keymap rl_get_keymap ();
+extern Keymap rl_get_keymap ();
/* Set the current keymap to MAP. */
-void rl_set_keymap ();
+extern void rl_set_keymap ();
#endif /* _KEYMAPS_H_ */
diff --git a/gnu/lib/libreadline/readline/readline.h b/gnu/lib/libreadline/readline/readline.h
index 1e47124..bbc8a0f 100644
--- a/gnu/lib/libreadline/readline/readline.h
+++ b/gnu/lib/libreadline/readline/readline.h
@@ -24,6 +24,7 @@
#define _READLINE_H_
#include <readline/keymaps.h>
+#include <readline/tilde.h>
/* The functions for manipulating the text of the line within readline.
Most of these functions are bound to keys by default. */
@@ -38,13 +39,29 @@ extern int
rl_forward_word (), rl_tab_insert (), rl_yank_pop (), rl_yank_nth_arg (),
rl_backward_kill_word (), rl_backward_kill_line (), rl_transpose_words (),
rl_complete (), rl_possible_completions (), rl_insert_completions (),
- rl_do_lowercase_version (),
+ rl_do_lowercase_version (), rl_kill_full_line (),
rl_digit_argument (), rl_universal_argument (), rl_abort (),
rl_undo_command (), rl_revert_line (), rl_beginning_of_history (),
rl_end_of_history (), rl_forward_search_history (), rl_insert (),
rl_upcase_word (), rl_downcase_word (), rl_capitalize_word (),
rl_restart_output (), rl_re_read_init_file (), rl_dump_functions (),
- rl_delete_horizontal_space ();
+ rl_delete_horizontal_space (), rl_history_search_forward (),
+ rl_history_search_backward ();
+
+/* `Public' utility functions. */
+extern int rl_insert_text (), rl_delete_text (), rl_kill_text ();
+extern int rl_complete_internal ();
+extern int rl_expand_prompt ();
+extern int rl_initialize ();
+extern int rl_set_signals (), rl_clear_signals ();
+extern int rl_init_argument (), rl_digit_argument ();
+extern int rl_read_key (), rl_getc (), rl_stuff_char ();
+extern int maybe_save_line (), maybe_unsave_line (), maybe_replace_line ();
+extern int rl_modifying ();
+
+extern int rl_begin_undo_group (), rl_end_undo_group ();
+extern void rl_add_undo (), free_undo_list ();
+extern int rl_do_undo ();
extern int rl_insert_close ();
@@ -57,6 +74,7 @@ extern int
rl_noninc_forward_search_again (), rl_noninc_reverse_search_again ();
/* Things for vi mode. */
+extern int rl_vi_check (), rl_vi_textmod_command ();
extern int
rl_vi_redo (), rl_vi_tilde_expand (),
rl_vi_movement_mode (), rl_vi_insertion_mode (), rl_vi_arg_digit (),
@@ -73,8 +91,8 @@ extern int
rl_vi_complete (), rl_vi_fetch_history ();
/* Keyboard macro commands. */
-extern int
-rl_start_kbd_macro (), rl_end_kbd_macro (), rl_call_last_kbd_macro ();
+extern int rl_start_kbd_macro (), rl_end_kbd_macro ();
+extern int rl_call_last_kbd_macro ();
extern int rl_arrow_keys(), rl_refresh_line ();
@@ -137,10 +155,10 @@ extern char *rl_basic_word_break_characters;
rl_basic_word_break_characters. */
extern char *rl_completer_word_break_characters;
-/* List of characters which are used to quote a substring of the command
- line, upon which completion is to be performed for the entire substring.
- Within quoted substrings, rl_completer_word_break_characters are treated
- as normal characters, unless they also appear in this list. */
+/* List of characters which can be used to quote a substring of the line.
+ Completion occurs on the entire substring, and within the substring
+ rl_completer_word_break_characters are treated as any other character,
+ unless they also appear within this list. */
extern char *rl_completer_quote_characters;
/* List of characters that are word break characters, but should be left
@@ -177,7 +195,10 @@ extern Function *rl_startup_hook;
/* If non-zero, then this is the address of a function to call when
completing on a directory name. The function is called with
the address of a string (the current directory name) as an arg. */
-extern Function *rl_symbolic_link_hook;
+extern Function *rl_directory_completion_hook;
+
+/* Backwards compatibility with previous versions of readline. */
+#define rl_symbolic_link_hook rl_directory_completion_hook
/* The address of a function to call periodically while Readline is
awaiting character input, or NULL, for no event handling. */
@@ -187,28 +208,9 @@ extern Function *rl_event_hook;
with an asterisk. */
extern int rl_show_star;
-
-/* **************************************************************** */
-/* */
-/* Tilde Variables That Can be Externally Set */
-/* */
-/* **************************************************************** */
-
-/* If non-null, this contains the address of a function to call if the
- standard meaning for expanding a tilde fails. The function is called
- with the text (sans tilde, as in "foo"), and returns a malloc()'ed string
- which is the expansion, or a NULL pointer if there is no expansion. */
-extern Function *tilde_expansion_failure_hook;
-
-/* When non-null, this is a NULL terminated array of strings which
- are duplicates for a tilde prefix. Bash uses this to expand
- `=~' and `:~'. */
-extern char **tilde_additional_prefixes;
-
-/* When non-null, this is a NULL terminated array of strings which match
- the end of a username, instead of just "/". Bash sets this to
- `/' and `:'. */
-extern char **tilde_additional_suffixes;
+/* Non-zero means to suppress normal filename completion after the
+ user-specified completion function has been called. */
+extern int rl_attempted_completion_over;
/* **************************************************************** */
/* */
@@ -219,14 +221,47 @@ extern char **tilde_additional_suffixes;
/* Read a line of input. Prompt with PROMPT. A NULL PROMPT means none. */
extern char *readline ();
+/* These functions are from complete.c. */
/* Return an array of strings which are the result of repeatadly calling
FUNC with TEXT. */
extern char **completion_matches ();
+extern char *username_completion_function ();
+extern char *filename_completion_function ();
+/* These functions are from bind.c. */
/* rl_add_defun (char *name, Function *function, int key)
Add NAME to the list of named functions. Make FUNCTION
be the function that gets called.
If KEY is not -1, then bind it. */
extern int rl_add_defun ();
+extern int rl_bind_key (), rl_bind_key_in_map ();
+extern int rl_unbind_key (), rl_unbind_key_in_map ();
+extern int rl_set_key ();
+extern int rl_macro_bind (), rl_generic_bind (), rl_variable_bind ();
+extern int rl_translate_keyseq ();
+extern Function *rl_named_function (), *rl_function_of_keyseq ();
+extern int rl_parse_and_bind ();
+extern Keymap rl_get_keymap (), rl_get_keymap_by_name ();
+extern void rl_set_keymap ();
+extern char **rl_invoking_keyseqs (), **rl_invoking_keyseqs_in_map ();
+extern void rl_function_dumper ();
+extern int rl_read_init_file ();
+
+/* Functions in funmap.c */
+extern void rl_list_funmap_names ();
+extern void rl_initialize_funmap ();
+
+/* Functions in display.c */
+extern void rl_redisplay ();
+extern int rl_message (), rl_clear_message ();
+extern int rl_reset_line_state ();
+extern int rl_character_len ();
+extern int rl_show_char ();
+extern int crlf (), rl_on_new_line ();
+extern int rl_forced_update_display ();
+
+/* Definitions available for use by readline clients. */
+#define RL_PROMPT_START_IGNORE '\001'
+#define RL_PROMPT_END_IGNORE '\002'
#endif /* _READLINE_H_ */
diff --git a/gnu/lib/libreadline/readline/tilde.h b/gnu/lib/libreadline/readline/tilde.h
new file mode 100644
index 0000000..726d081
--- /dev/null
+++ b/gnu/lib/libreadline/readline/tilde.h
@@ -0,0 +1,38 @@
+/* tilde.h: Externally available variables and function in libtilde.a. */
+
+#if !defined (__TILDE_H__)
+# define __TILDE_H__
+
+/* Function pointers can be declared as (Function *)foo. */
+#if !defined (__FUNCTION_DEF)
+# define __FUNCTION_DEF
+typedef int Function ();
+typedef void VFunction ();
+typedef char *CPFunction ();
+typedef char **CPPFunction ();
+#endif /* _FUNCTION_DEF */
+
+/* If non-null, this contains the address of a function to call if the
+ standard meaning for expanding a tilde fails. The function is called
+ with the text (sans tilde, as in "foo"), and returns a malloc()'ed string
+ which is the expansion, or a NULL pointer if there is no expansion. */
+extern CPFunction *tilde_expansion_failure_hook;
+
+/* When non-null, this is a NULL terminated array of strings which
+ are duplicates for a tilde prefix. Bash uses this to expand
+ `=~' and `:~'. */
+extern char **tilde_additional_prefixes;
+
+/* When non-null, this is a NULL terminated array of strings which match
+ the end of a username, instead of just "/". Bash sets this to
+ `:' and `=~'. */
+extern char **tilde_additional_suffixes;
+
+/* Return a new string which is the result of tilde expanding STRING. */
+extern char *tilde_expand ();
+
+/* Do the work of tilde expansion on FILENAME. FILENAME starts with a
+ tilde. If there is no expansion, call tilde_expansion_failure_hook. */
+extern char *tilde_expand_word ();
+
+#endif /* __TILDE_H__ */
diff --git a/gnu/lib/libreadline/rlconf.h b/gnu/lib/libreadline/rlconf.h
new file mode 100644
index 0000000..a9b100f
--- /dev/null
+++ b/gnu/lib/libreadline/rlconf.h
@@ -0,0 +1,57 @@
+/* rlconf.h -- readline configuration definitions */
+
+/* Copyright (C) 1994 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 1, 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,
+ 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#if !defined (_RLCONF_H_)
+#define _RLCONF_H_
+
+/* Define this if you want the vi-mode editing available. */
+#define VI_MODE
+
+/* Define this to get an indication of file type when listing completions. */
+#define VISIBLE_STATS
+
+/* If defined, readline shows opening parens and braces when closing
+ paren or brace entered. */
+#define PAREN_MATCHING
+
+/* This definition is needed by readline.c, rltty.c, and signals.c. */
+/* If on, then readline handles signals in a way that doesn't screw. */
+#define HANDLE_SIGNALS
+
+/* Ugly but working hack for binding prefix meta. */
+#define PREFIX_META_HACK
+
+/* The final, last-ditch effort file name for an init file. */
+#define DEFAULT_INPUTRC "~/.inputrc"
+
+/* If defined, expand tabs to spaces. */
+#define DISPLAY_TABS
+
+/* If defined, use the terminal escape sequence to move the cursor forward
+ over a character when updating the line rather than rewriting it. */
+/* #define HACK_TERMCAP_MOTION */
+
+/* The string inserted by the vi-mode `insert comment' command. */
+#define VI_COMMENT_BEGIN_DEFAULT "#"
+
+#endif /* _RLCONF_H_ */
diff --git a/gnu/lib/libreadline/rldefs.h b/gnu/lib/libreadline/rldefs.h
index 4d5eb8d..8f8a176 100644
--- a/gnu/lib/libreadline/rldefs.h
+++ b/gnu/lib/libreadline/rldefs.h
@@ -26,13 +26,8 @@
#if !defined (_RLDEFS_H)
#define _RLDEFS_H
-#if defined (__GNUC__)
-# undef alloca
-# define alloca __builtin_alloca
-#else
-# if defined (sparc) || defined (HAVE_ALLOCA_H)
-# include <alloca.h>
-# endif
+#if !defined (PRAGMA_ALLOCA)
+# include "memalloc.h"
#endif
#define NEW_TTY_DRIVER
@@ -75,11 +70,11 @@
/* System V.3 machines have the old 4.1 BSD `reliable' signal interface. */
#if !defined (HAVE_BSD_SIGNALS) && !defined (HAVE_POSIX_SIGNALS)
-# if defined (USGr3)
+# if defined (USGr3) && !defined (XENIX_22)
# if !defined (HAVE_USG_SIGHOLD)
# define HAVE_USG_SIGHOLD
# endif /* !HAVE_USG_SIGHOLD */
-# endif /* USGr3 */
+# endif /* USGr3 && !XENIX_22 */
#endif /* !HAVE_BSD_SIGNALS && !HAVE_POSIX_SIGNALS */
/* Other (BSD) machines use sgtty. */
@@ -125,7 +120,9 @@
#endif /* !HAVE_DIRENT_H */
#if defined (USG) && defined (TIOCGWINSZ) && !defined (Linux)
-# include <sys/stream.h>
+# if defined (HAVE_SYS_STREAM_H)
+# include <sys/stream.h>
+# endif /* HAVE_SYS_STREAM_H */
# if defined (HAVE_SYS_PTEM_H)
# include <sys/ptem.h>
# endif /* HAVE_SYS_PTEM_H */
@@ -137,7 +134,7 @@
/* 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)
+# define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
#endif
/* Decide which flavor of the header file describing the C library
@@ -163,14 +160,31 @@ extern char *strchr (), *strrchr ();
# include <varargs.h>
#endif /* HAVE_VARARGS_H */
-/* This definition is needed by readline.c, rltty.c, and signals.c. */
-/* If on, then readline handles signals in a way that doesn't screw. */
-#define HANDLE_SIGNALS
-
#if !defined (emacs_mode)
# define no_mode -1
# define vi_mode 0
# define emacs_mode 1
#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) (Function *)((int)(data))
+#else
+# define FUNCTION_TO_KEYMAP(map, key) (Keymap)(map[key].function)
+# define KEYMAP_TO_FUNCTION(data) (Function *)(data)
+#endif
+
+/* Possible values for _rl_bell_preference. */
+#define NO_BELL 0
+#define AUDIBLE_BELL 1
+#define VISIBLE_BELL 2
+
+/* CONFIGURATION SECTION */
+#include "rlconf.h"
+
#endif /* !_RLDEFS_H */
diff --git a/gnu/lib/libreadline/rltty.c b/gnu/lib/libreadline/rltty.c
index a73682b..81f8ce5 100644
--- a/gnu/lib/libreadline/rltty.c
+++ b/gnu/lib/libreadline/rltty.c
@@ -40,10 +40,10 @@ extern int errno;
extern int readline_echoing_p;
extern int _rl_eof_char;
-#if defined (_GO32_)
+#if defined (__GO32__)
# include <sys/pc.h>
# undef HANDLE_SIGNALS
-#endif /* _GO32_ */
+#endif /* __GO32__ */
/* **************************************************************** */
/* */
@@ -107,10 +107,10 @@ release_sigint ()
sigint_blocked = 0;
}
-
+
/* **************************************************************** */
/* */
-/* Controlling the Meta Key */
+/* Controlling the Meta Key and Keypad */
/* */
/* **************************************************************** */
@@ -118,11 +118,13 @@ extern int term_has_meta;
extern char *term_mm;
extern char *term_mo;
-static void
+extern char *term_ks;
+extern char *term_ke;
+static int
outchar (c)
int c;
{
- putc (c, rl_outstream);
+ return putc (c, rl_outstream);
}
/* Turn on/off the meta key depending on ON. */
@@ -138,7 +140,17 @@ control_meta_key (on)
tputs (term_mo, 1, outchar);
}
}
-
+
+static void
+control_keypad (on)
+ int on;
+{
+ if (on && term_ks)
+ tputs (term_ks, 1, outchar);
+ else if (!on && term_ke)
+ tputs (term_ke, 1, outchar);
+}
+
/* **************************************************************** */
/* */
/* Saving and Restoring the TTY */
@@ -250,7 +262,7 @@ prepare_terminal_settings (meta_flag, otio, tiop)
int meta_flag;
TIOTYPE otio, *tiop;
{
-#if !defined (_GO32_)
+#if !defined (__GO32__)
readline_echoing_p = (otio.sgttyb.sg_flags & ECHO);
/* Copy the original settings to the structure we're going to use for
@@ -316,7 +328,7 @@ prepare_terminal_settings (meta_flag, otio, tiop)
tiop->ltchars.t_dsuspc = -1; /* C-y */
tiop->ltchars.t_lnextc = -1; /* C-v */
#endif /* TIOCGLTC */
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
}
#else /* !defined (NEW_TTY_DRIVER) */
@@ -455,7 +467,7 @@ void
rl_prep_terminal (meta_flag)
int meta_flag;
{
-#if !defined (_GO32_)
+#if !defined (__GO32__)
int tty = fileno (rl_instream);
TIOTYPE tio;
@@ -482,17 +494,18 @@ rl_prep_terminal (meta_flag)
}
control_meta_key (1);
+ control_keypad (1);
terminal_prepped = 1;
release_sigint ();
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
}
/* Restore the terminal's normal settings and modes. */
void
rl_deprep_terminal ()
{
-#if !defined (_GO32_)
+#if !defined (__GO32__)
int tty = fileno (rl_instream);
if (!terminal_prepped)
@@ -508,10 +521,11 @@ rl_deprep_terminal ()
}
control_meta_key (0);
+ control_keypad (0);
terminal_prepped = 0;
release_sigint ();
-#endif /* !_GO32_ */
+#endif /* !__GO32__ */
}
/* **************************************************************** */
@@ -548,6 +562,8 @@ rl_restart_output (count, key)
# endif /* TCXONC */
# endif /* !TERMIOS_TTY_DRIVER */
#endif /* !TIOCSTART */
+
+ return 0;
}
rl_stop_output (count, key)
@@ -573,6 +589,8 @@ rl_stop_output (count, key)
# endif /* TCXONC */
# endif /* !TERMIOS_TTY_DRIVER */
#endif /* !TIOCSTOP */
+
+ return 0;
}
/* **************************************************************** */
diff --git a/gnu/lib/libreadline/search.c b/gnu/lib/libreadline/search.c
index 3bf6c1e..8b8ab18 100644
--- a/gnu/lib/libreadline/search.c
+++ b/gnu/lib/libreadline/search.c
@@ -23,17 +23,15 @@
#include <stdio.h>
-#if defined (__GNUC__)
-# define alloca __builtin_alloca
-#else
-# if defined (sparc) || defined (HAVE_ALLOCA_H)
-# include <alloca.h>
-# endif
-#endif
-
+#include "memalloc.h"
#include "readline.h"
#include "history.h"
+#define STREQ(a, b) (((a)[0] == (b)[0]) && (strcmp ((a), (b)) == 0))
+#define STREQN(a, b, n) (((a)[0] == (b)[0]) && (strncmp ((a), (b), (n)) == 0))
+
+#define abs(x) (((x) > 0) ? (x) : -(x))
+
extern char *xmalloc (), *xrealloc ();
/* Variables imported from readline.c */
@@ -42,9 +40,14 @@ extern Keymap _rl_keymap;
extern char *rl_prompt;
extern char *rl_line_buffer;
extern HIST_ENTRY *saved_line_for_history;
+extern Function *rl_last_func;
+
+/* Functions imported from the rest of the library. */
+extern int _rl_free_history_entry ();
static char *noninc_search_string = (char *) NULL;
static int noninc_history_pos = 0;
+static char *prev_line_found = (char *) NULL;
/* Search the history list for STRING starting at absolute history position
POS. If STRING begins with `^', the search must match STRING at the
@@ -123,7 +126,7 @@ noninc_dosearch (string, dir)
rl_clear_message ();
if (saved_line_for_history)
- free_history_entry (saved_line_for_history);
+ _rl_free_history_entry (saved_line_for_history);
saved_line_for_history = (HIST_ENTRY *)NULL;
}
@@ -147,14 +150,16 @@ noninc_search (dir, pchar)
rl_line_buffer[0] = 0;
rl_end = rl_point = 0;
+ /* XXX - this needs fixing to work with the prompt expansion stuff - XXX */
pmtlen = (rl_prompt && *rl_prompt) ? strlen (rl_prompt) : 0;
- p = (char *)alloca (2 + pmtlen);
+ p = xmalloc (2 + pmtlen);
if (pmtlen)
strcpy (p, rl_prompt);
p[pmtlen] = pchar ? pchar : ':';
p[pmtlen + 1] = '\0';
rl_message (p, 0, 0);
+ free (p);
/* Read the search string. */
while (c = rl_read_key ())
@@ -170,11 +175,15 @@ noninc_search (dir, pchar)
rl_point = saved_point;
return;
}
- /* FALLTHROUGH */
+ rl_rubout (1);
+ break;
case CTRL('W'):
+ rl_unix_word_rubout ();
+ break;
+
case CTRL('U'):
- rl_dispatch (c, _rl_keymap);
+ rl_unix_line_discard ();
break;
case RETURN:
@@ -273,3 +282,79 @@ rl_noninc_reverse_search_again (count, key)
noninc_dosearch (noninc_search_string, -1);
return 0;
}
+
+static int
+rl_history_search_internal (count, direction)
+ int count, direction;
+{
+ HIST_ENTRY *temp, *old_temp;
+ int line_len;
+
+ maybe_save_line ();
+
+ temp = old_temp = (HIST_ENTRY *)NULL;
+ while (count)
+ {
+ temp = (direction < 0) ? previous_history () : next_history ();
+ if (!temp)
+ break;
+ if (STREQN (rl_line_buffer, temp->line, rl_point))
+ {
+ /* Don't find multiple instances of the same line. */
+ if (prev_line_found && STREQ (prev_line_found, temp->line))
+ continue;
+ if (direction < 0)
+ old_temp = temp;
+ prev_line_found = temp->line;
+ count--;
+ }
+ }
+
+ if (!temp)
+ {
+ if (direction < 0 && old_temp)
+ temp = old_temp;
+ else
+ {
+ maybe_unsave_line ();
+ ding ();
+ return 1;
+ }
+ }
+
+ line_len = strlen (temp->line);
+ if (line_len >= rl_line_buffer_len)
+ rl_extend_line_buffer (line_len);
+ strcpy (rl_line_buffer, temp->line);
+ rl_undo_list = (UNDO_LIST *)temp->data;
+ rl_end = line_len;
+ return 0;
+}
+
+/* Search forward in the history for the string of characters
+ from the start of the line to rl_point. This is a non-incremental
+ search. */
+int
+rl_history_search_forward (count, ignore)
+ int count, ignore;
+{
+ if (count == 0)
+ return (0);
+ if (rl_last_func != rl_history_search_forward)
+ prev_line_found = (char *)NULL;
+ return (rl_history_search_internal (abs (count), (count > 0) ? 1 : -1));
+}
+
+/* Search backward through the history for the string of characters
+ from the start of the line to rl_point. This is a non-incremental
+ search. */
+int
+rl_history_search_backward (count, ignore)
+ int count, ignore;
+{
+ if (count == 0)
+ return (0);
+ if (rl_last_func != rl_history_search_backward)
+ prev_line_found = (char *)NULL;
+ return (rl_history_search_internal (abs (count), (count > 0) ? -1 : 1));
+}
diff --git a/gnu/lib/libreadline/signals.c b/gnu/lib/libreadline/signals.c
index 8c0624d..8cfbb47 100644
--- a/gnu/lib/libreadline/signals.c
+++ b/gnu/lib/libreadline/signals.c
@@ -62,10 +62,11 @@ static void cr ();
extern int readline_echoing_p;
extern int rl_pending_input;
+extern char *term_cr;
extern int _rl_meta_flag;
-extern void _rl_output_character_function ();
+extern int _rl_output_character_function ();
extern void free_undo_list ();
@@ -79,9 +80,9 @@ extern void free_undo_list ();
to say SigHandler *foo = signal (SIGKILL, SIG_IGN); */
typedef sighandler SigHandler ();
-#if defined (_GO32_)
+#if defined (__GO32__)
# undef HANDLE_SIGNALS
-#endif /* _GO32_ */
+#endif /* __GO32__ */
#if defined (STATIC_MALLOC)
static char *xmalloc (), *xrealloc ();
@@ -125,11 +126,14 @@ rl_handle_sigwinch (sig)
/* Interrupt handling. */
static SigHandler
*old_int = (SigHandler *)NULL,
+ *old_alrm = (SigHandler *)NULL;
+#if !defined (SHELL)
+static SigHandler
*old_tstp = (SigHandler *)NULL,
*old_ttou = (SigHandler *)NULL,
*old_ttin = (SigHandler *)NULL,
- *old_cont = (SigHandler *)NULL,
- *old_alrm = (SigHandler *)NULL;
+ *old_cont = (SigHandler *)NULL;
+#endif /* !SHELL */
/* Handle an interrupt character. */
static sighandler
@@ -261,6 +265,7 @@ rl_set_signals ()
old_sigwinch =
(SigHandler *) rl_set_sighandler (SIGWINCH, rl_handle_sigwinch);
#endif /* SIGWINCH */
+ return 0;
}
rl_clear_signals ()
@@ -284,14 +289,14 @@ rl_clear_signals ()
#if defined (SIGWINCH)
signal (SIGWINCH, old_sigwinch);
#endif
+
+ return 0;
}
/* Move to the start of the current line. */
static void
cr ()
{
- extern char *term_cr;
-
if (term_cr)
tputs (term_cr, 1, _rl_output_character_function);
}
diff --git a/gnu/lib/libreadline/tcsh_hack.readme b/gnu/lib/libreadline/tcsh_hack.readme
index ed05869..6fd5da1 100644
--- a/gnu/lib/libreadline/tcsh_hack.readme
+++ b/gnu/lib/libreadline/tcsh_hack.readme
@@ -1,5 +1,5 @@
-*** rltty.c.orig Tue May 10 02:18:03 1994
---- rltty.c Tue May 10 03:12:55 1994
+*** rltty.c.orig Thu May 12 19:02:50 1994
+--- rltty.c Thu May 12 19:03:06 1994
***************
*** 21,26 ****
--- 21,27 ----
@@ -11,8 +11,8 @@
#include <errno.h>
#include <stdio.h>
***************
-*** 347,352 ****
---- 348,359 ----
+*** 359,364 ****
+--- 360,371 ----
int tty;
TIOTYPE *tiop;
{
diff --git a/gnu/lib/libreadline/tilde.c b/gnu/lib/libreadline/tilde.c
index c0cb023..89168a0 100644
--- a/gnu/lib/libreadline/tilde.c
+++ b/gnu/lib/libreadline/tilde.c
@@ -19,18 +19,7 @@
along with Readline; see the file COPYING. If not, write to the Free
Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
-#if defined (__GNUC__)
-# undef alloca
-# define alloca __builtin_alloca
-#else /* !__GNUC__ */
-# if defined (_AIX)
- #pragma alloca
-# else /* !_AIX */
-# if defined (HAVE_ALLOCA_H)
-# include <alloca.h>
-# endif /* HAVE_ALLOCA_H */
-# endif /* !AIX */
-#endif /* !__GNUC__ */
+#include "memalloc.h"
#if defined (HAVE_STRING_H)
# include <string.h>
@@ -44,15 +33,12 @@
# include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */
-#include <tilde.h>
+#include "tilde.h"
#include <pwd.h>
-#if defined (USG) && !defined (isc386) && !defined (sgi)
-extern struct passwd *getpwuid (), *getpwent ();
-#endif
-#if defined (isc386) && !defined (__STDC__) && defined (_POSIX_SOURCE)
-extern struct passwd *getpwent ();
-#endif
+#if defined (USG) && !defined (HAVE_GETPW_DECLS)
+extern struct passwd *getpwuid (), *getpwnam ();
+#endif /* USG && !defined (HAVE_GETPW_DECLS) */
#if !defined (savestring)
extern char *xmalloc ();
@@ -254,21 +240,23 @@ tilde_expand_word (filename)
temp_home = entry->pw_dir;
}
- temp_name = (char *)alloca (1 + strlen (&dirname[1])
- + (temp_home ? strlen (temp_home) : 0));
+ temp_name = xmalloc (1 + strlen (&dirname[1])
+ + (temp_home ? strlen (temp_home) : 0));
temp_name[0] = '\0';
if (temp_home)
strcpy (temp_name, temp_home);
- strcat (temp_name, &dirname[1]);
+ strcat (temp_name, dirname + 1);
free (dirname);
- dirname = savestring (temp_name);
+ dirname = temp_name;
}
else
{
+ char u_name[257];
struct passwd *user_entry;
- char *username = (char *)alloca (257);
+ char *username;
int i, c;
+ username = u_name;
for (i = 1; c = dirname[i]; i++)
{
if (c == '/')
@@ -291,25 +279,25 @@ tilde_expand_word (filename)
if (expansion)
{
- temp_name = (char *)alloca (1 + strlen (expansion)
+ temp_name = xmalloc (1 + strlen (expansion)
+ strlen (&dirname[i]));
strcpy (temp_name, expansion);
strcat (temp_name, &dirname[i]);
free (expansion);
- goto return_name;
+ free (dirname);
+ dirname = temp_name;
}
}
/* We shouldn't report errors. */
}
else
{
- temp_name = (char *)alloca (1 + strlen (user_entry->pw_dir)
- + strlen (&dirname[i]));
+ temp_name = xmalloc (1 + strlen (user_entry->pw_dir)
+ + strlen (&dirname[i]));
strcpy (temp_name, user_entry->pw_dir);
strcat (temp_name, &dirname[i]);
- return_name:
free (dirname);
- dirname = savestring (temp_name);
+ dirname = temp_name;
}
endpwent ();
}
diff --git a/gnu/lib/libreadline/vi_keymap.c b/gnu/lib/libreadline/vi_keymap.c
index 24fbc3e..bd42a74 100644
--- a/gnu/lib/libreadline/vi_keymap.c
+++ b/gnu/lib/libreadline/vi_keymap.c
@@ -26,7 +26,9 @@
#include "readline.h"
+#if 0
extern KEYMAP_ENTRY_ARRAY vi_escape_keymap;
+#endif
/* The keymap arrays for handling vi mode. */
KEYMAP_ENTRY_ARRAY vi_movement_keymap = {
@@ -59,7 +61,7 @@ KEYMAP_ENTRY_ARRAY vi_movement_keymap = {
{ ISFUNC, rl_yank }, /* Control-y */
{ ISFUNC, (Function *)0x0 }, /* Control-z */
- { ISFUNC, rl_abort }, /* Control-[ */
+ { ISFUNC, rl_abort }, /* Control-[ */ /* vi_escape_keymap */
{ ISFUNC, (Function *)0x0 }, /* Control-\ */
{ ISFUNC, (Function *)0x0 }, /* Control-] */
{ ISFUNC, (Function *)0x0 }, /* Control-^ */
@@ -84,7 +86,7 @@ KEYMAP_ENTRY_ARRAY vi_movement_keymap = {
{ ISFUNC, rl_vi_search }, /* / */
/* Regular digits. */
- { ISFUNC, rl_vi_arg_digit }, /* 0 */
+ { ISFUNC, rl_beg_of_line }, /* 0 */
{ ISFUNC, rl_vi_arg_digit }, /* 1 */
{ ISFUNC, rl_vi_arg_digit }, /* 2 */
{ ISFUNC, rl_vi_arg_digit }, /* 3 */
@@ -592,8 +594,9 @@ KEYMAP_ENTRY_ARRAY vi_insertion_keymap = {
#endif /* KEYMAP_SIZE > 128 */
};
+/* Unused for the time being. */
+#if 0
KEYMAP_ENTRY_ARRAY vi_escape_keymap = {
-
/* The regular control keys come first. */
{ ISFUNC, (Function *)0x0 }, /* Control-@ */
{ ISFUNC, (Function *)0x0 }, /* Control-a */
@@ -871,3 +874,4 @@ KEYMAP_ENTRY_ARRAY vi_escape_keymap = {
{ ISFUNC, (Function *)0x0 }
#endif /* KEYMAP_SIZE > 128 */
};
+#endif
diff --git a/gnu/lib/libreadline/vi_mode.c b/gnu/lib/libreadline/vi_mode.c
index 971c377..86382b1 100644
--- a/gnu/lib/libreadline/vi_mode.c
+++ b/gnu/lib/libreadline/vi_mode.c
@@ -20,12 +20,14 @@
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */
-
+
/* **************************************************************** */
/* */
/* VI Emulation Mode */
/* */
/* **************************************************************** */
+#include "rlconf.h"
+
#if defined (VI_MODE)
#include <sys/types.h>
@@ -36,12 +38,6 @@
# include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */
-#if defined (STATIC_MALLOC)
-static char *xmalloc (), *xrealloc ();
-#else
-extern char *xmalloc (), *xrealloc ();
-#endif /* STATIC_MALLOC */
-
#include <stdio.h>
/* Some standard library routines. */
@@ -77,6 +73,12 @@ extern char *xmalloc (), *xrealloc ();
#define VI_COMMENT_BEGIN_DEFAULT "#"
#endif
+#if defined (STATIC_MALLOC)
+static char *xmalloc (), *xrealloc ();
+#else
+extern char *xmalloc (), *xrealloc ();
+#endif /* STATIC_MALLOC */
+
/* Variables imported from readline.c */
extern int rl_point, rl_end, rl_mark, rl_done;
extern FILE *rl_instream;
@@ -86,11 +88,13 @@ extern char *rl_prompt;
extern char *rl_line_buffer;
extern int rl_arg_sign;
+extern void _rl_dispatch ();
+
extern void rl_extend_line_buffer ();
-extern int rl_vi_check (), rl_digit_loop1 ();
+extern int rl_vi_check ();
/* Non-zero means enter insertion mode. */
-int _rl_vi_doing_insert = 0;
+static int _rl_vi_doing_insert = 0;
/* String inserted into the line by rl_vi_comment (). */
char *rl_vi_comment_begin = (char *)NULL;
@@ -106,9 +110,14 @@ static Keymap vi_replace_map = (Keymap)NULL;
/* The number of characters inserted in the last replace operation. */
static int vi_replace_count = 0;
-int _rl_vi_last_command = 'i'; /* default `.' puts you in insert mode */
-int _rl_vi_last_repeat = 1;
-int _rl_vi_last_arg_sign = 1;
+/* If non-zero, we have text inserted after a c[motion] command that put
+ us implicitly into insert mode. Some people want this text to be
+ attached to the command so that it is `redoable' with `.'. */
+static int vi_continued_command = 0;
+
+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 = 0;
static int _rl_vi_last_search_char = 0;
static int _rl_vi_last_replacement = 0;
@@ -118,8 +127,10 @@ static int vi_redoing = 0;
/* Text modification commands. These are the `redoable' commands. */
static char *vi_textmod = "_*\\AaIiCcDdPpYyRrSsXx~";
+static int rl_digit_loop1 ();
+
void
-rl_vi_set_last ()
+_rl_vi_reset_last ()
{
_rl_vi_last_command = 'i';
_rl_vi_last_repeat = 1;
@@ -127,6 +138,15 @@ rl_vi_set_last ()
_rl_vi_last_motion = 0;
}
+void
+_rl_vi_set_last (key, repeat, sign)
+ int key, repeat, sign;
+{
+ _rl_vi_last_command = key;
+ _rl_vi_last_repeat = repeat;
+ _rl_vi_last_arg_sign = sign;
+}
+
/* Is the command C a VI mode text modification command? */
int
rl_vi_textmod_command (c)
@@ -148,7 +168,7 @@ rl_vi_redo (count, c)
}
vi_redoing = 1;
- rl_dispatch (_rl_vi_last_command, _rl_keymap);
+ _rl_dispatch (_rl_vi_last_command, _rl_keymap);
vi_redoing = 0;
return (0);
@@ -158,9 +178,6 @@ rl_vi_redo (count, c)
rl_vi_yank_arg (count)
int count;
{
- /* vi mode is defined to insert a space before the last argument. */
- rl_insert (1, ' ');
-
/* Readline thinks that the first word on a line is the 0th, while vi
thinks the first word on a line is the 1st. Compensate. */
if (rl_explicit_arg)
@@ -168,7 +185,6 @@ rl_vi_yank_arg (count)
else
rl_yank_nth_arg ('$', 0);
- rl_vi_insertion_mode ();
return (0);
}
@@ -256,7 +272,10 @@ rl_vi_complete (ignore, key)
rl_complete (0, key);
if (key == '*' || key == '\\')
- rl_vi_insertion_mode ();
+ {
+ _rl_vi_set_last (key, 1, rl_arg_sign);
+ rl_vi_insertion_mode ();
+ }
return (0);
}
@@ -265,6 +284,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 ();
return (0);
}
@@ -292,7 +312,7 @@ rl_vi_prev_word (count, key)
/* Next word in vi mode. */
rl_vi_next_word (count, key)
- int count;
+ int count, key;
{
if (count < 0)
return (rl_vi_prev_word (-count, key));
@@ -493,7 +513,7 @@ rl_vi_insert_beg ()
rl_vi_append_mode ()
{
if (rl_point < rl_end)
- rl_point += 1;
+ rl_point++;
rl_vi_insertion_mode ();
return (0);
}
@@ -522,25 +542,33 @@ rl_vi_insertion_mode ()
return (0);
}
+void
+_rl_vi_done_inserting ()
+{
+ if (_rl_vi_doing_insert)
+ {
+ rl_end_undo_group ();
+ /* Now, the text between rl_undo_list->next->start and
+ rl_undo_list->next->end is what was inserted while in insert
+ mode. */
+ _rl_vi_doing_insert = 0;
+ vi_continued_command = 1;
+ }
+ else
+ vi_continued_command = 0;
+}
+
rl_vi_movement_mode ()
{
if (rl_point > 0)
rl_backward (1);
- rl_vi_set_last ();
+#if 0
+ _rl_vi_reset_last ();
+#endif
_rl_keymap = vi_movement_keymap;
- vi_done_inserting ();
- return (0);
-}
-
-vi_done_inserting ()
-{
- if (_rl_vi_doing_insert)
- {
- rl_end_undo_group ();
- _rl_vi_doing_insert = 0;
- }
+ _rl_vi_done_inserting ();
return (0);
}
@@ -639,9 +667,7 @@ rl_vi_domove (key, nextkey)
c = rl_read_key (); /* real command */
*nextkey = c;
}
- else if ((key == 'd' && c == 'd') ||
- (key == 'y' && c == 'y') ||
- (key == 'c' && c == 'c'))
+ else if (key == c && (key == 'd' || key == 'y' || key == 'c'))
{
rl_mark = rl_end;
rl_beg_of_line ();
@@ -660,7 +686,7 @@ rl_vi_domove (key, nextkey)
rl_line_buffer[rl_end++] = ' ';
rl_line_buffer[rl_end] = '\0';
- rl_dispatch (c, _rl_keymap);
+ _rl_dispatch (c, _rl_keymap);
/* Remove the blank that we added. */
rl_end = old_end;
@@ -675,23 +701,30 @@ rl_vi_domove (key, nextkey)
/* rl_vi_f[wW]ord () leaves the cursor on the first character of the next
word. If we are not at the end of the line, and we are on a
non-whitespace character, move back one (presumably to whitespace). */
- if ((c == 'w' || c == 'W') && (rl_point < rl_end) &&
+ if ((to_upper (c) == 'W') && rl_point < rl_end && rl_point > rl_mark &&
!whitespace (rl_line_buffer[rl_point]))
rl_point--;
/* If cw or cW, back up to the end of a word, so the behaviour of ce
or cE is the actual result. Brute-force, no subtlety. */
- if (key == 'c' && (to_upper (c) == 'W'))
+ if (key == 'c' && rl_point >= rl_mark && (to_upper (c) == 'W'))
{
- while (rl_point && whitespace (rl_line_buffer[rl_point]))
+ /* Don't move farther back than where we started. */
+ while (rl_point > rl_mark && whitespace (rl_line_buffer[rl_point]))
rl_point--;
- /* Move past the end of the word so that the kill doesn't remove the
- last letter of the previous word. Only do this if we are not at
- the end of the line. */
- if ((rl_point >= 0) && (rl_point < (rl_end - 1)) &&
- !whitespace (rl_line_buffer[rl_point]))
- rl_point++;
+ /* Posix.2 says that if cw or cW moves the cursor towards the end of
+ the line, the character under the cursor should be deleted. */
+ if (rl_point == rl_mark)
+ rl_point++;
+ else
+ {
+ /* Move past the end of the word so that the kill doesn't
+ remove the last letter of the previous word. Only do this
+ if we are not at the end of the line. */
+ if (rl_point >= 0 && rl_point < (rl_end - 1) && !whitespace (rl_line_buffer[rl_point]))
+ rl_point++;
+ }
}
if (rl_mark < rl_point)
@@ -702,6 +735,7 @@ rl_vi_domove (key, nextkey)
/* A simplified loop for vi. Don't dispatch key at end.
Don't recognize minus sign? */
+static int
rl_digit_loop1 ()
{
int key, c;
@@ -790,9 +824,11 @@ rl_vi_change_to (count, key)
if ((to_upper (c) == 'W') && rl_point < start_pos)
rl_point = start_pos;
+ rl_kill_text (rl_point, rl_mark);
+
rl_begin_undo_group ();
_rl_vi_doing_insert = 1;
- rl_kill_text (rl_point, rl_mark);
+ _rl_vi_set_last (key, count, rl_arg_sign);
rl_vi_insertion_mode ();
return (0);
@@ -930,7 +966,7 @@ rl_vi_char_search (count, key)
if (pos == 0)
{
ding ();
- return;
+ return -1;
}
pos--;
@@ -1096,7 +1132,6 @@ rl_vi_subst (count, key)
int count, key;
{
rl_begin_undo_group ();
- _rl_vi_doing_insert = 1;
if (uppercase_p (key))
{
@@ -1108,7 +1143,12 @@ rl_vi_subst (count, key)
rl_end_undo_group ();
+ _rl_vi_set_last (key, count, rl_arg_sign);
+
+ rl_begin_undo_group ();
+ _rl_vi_doing_insert = 1;
rl_vi_insertion_mode ();
+
return (0);
}
@@ -1202,6 +1242,7 @@ rl_vi_replace (count, key)
return (0);
}
+#if 0
/* Try to complete the word we are standing on or the word that ends with
the previous character. A space matches everything. Word delimiters are
space and ;. */
@@ -1211,9 +1252,9 @@ rl_vi_possible_completions()
if (rl_line_buffer[rl_point] != ' ' && rl_line_buffer[rl_point] != ';')
{
- while (rl_line_buffer[rl_point] != ' ' &&
+ while (rl_point < rl_end && rl_line_buffer[rl_point] != ' ' &&
rl_line_buffer[rl_point] != ';')
- ;
+ rl_point++;
}
else if (rl_line_buffer[rl_point - 1] == ';')
{
@@ -1226,6 +1267,7 @@ rl_vi_possible_completions()
return (0);
}
+#endif
#if defined (STATIC_MALLOC)
OpenPOWER on IntegriCloud