1999-04-16 03:34:55 +02:00
|
|
|
/* histsearch.c -- searching the history list. */
|
|
|
|
|
|
|
|
/* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
This file contains the GNU History Library (the Library), a set of
|
|
|
|
routines for managing the text of previously typed lines.
|
|
|
|
|
|
|
|
The Library is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
readline:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
Locally modified files: Makefile.in, configure.in, configure
(regenerated), config.h.in (regenerated), readline.h, rltty.c,
shell.c signals.c.
Locally added files: acconfig.h, config/*, config.h.bot,
cross-build/*, doc/inc-hit.texinfo.
New files: USAGE, rlprivate.h, rlshell.h, xmalloc.h.
examples:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
New files: excallback.c, rlfe.c.
doc:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
Regenerated inc-hist.texinfo as copy of hsuser.texinfo, for
inclusion in the gdb manual.
New file: rluserman.texinfo
2000-07-09 19:20:00 +02:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
1999-04-16 03:34:55 +02:00
|
|
|
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,
|
readline:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
Locally modified files: Makefile.in, configure.in, configure
(regenerated), config.h.in (regenerated), readline.h, rltty.c,
shell.c signals.c.
Locally added files: acconfig.h, config/*, config.h.bot,
cross-build/*, doc/inc-hit.texinfo.
New files: USAGE, rlprivate.h, rlshell.h, xmalloc.h.
examples:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
New files: excallback.c, rlfe.c.
doc:
2000-07-09 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
* Import of readline 4.1.
Regenerated inc-hist.texinfo as copy of hsuser.texinfo, for
inclusion in the gdb manual.
New file: rluserman.texinfo
2000-07-09 19:20:00 +02:00
|
|
|
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
1999-04-16 03:34:55 +02:00
|
|
|
|
|
|
|
#define READLINE_LIBRARY
|
|
|
|
|
|
|
|
#if defined (HAVE_CONFIG_H)
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#if defined (HAVE_STDLIB_H)
|
|
|
|
# include <stdlib.h>
|
|
|
|
#else
|
|
|
|
# include "ansi_stdlib.h"
|
|
|
|
#endif /* HAVE_STDLIB_H */
|
Import of readline 4.3.
Non-readline modified files:
src/gdb/ChangeLog src/gdb/defs.h src/gdb/cli/cli-cmds.c
src/gdb/cli/cli-setshow.c src/gdb/tui/ChangeLog
src/gdb/tui/tuiWin.c
In readline directory:
* compat.c, mbutil.c, misc.c, rlmbutil.h, rltypedefs.h,
text.c, doc/history.0, doc/history.3, support/wcwidth.c,
examples/readlinebuf.h, examples/rlcat.c: New files.
* CHANGELOG, CHANGES, INSTALL, MANIFEST, Makefile.in, README,
aclocal.m4, ansi_stdlib.h, bind.c, callback.c, chardefs.h,
complete.c, config.h.in, configure, configure.in, display.c,
emacs_keymap.c, funmap.c, histexpand.c, histfile.c, histlib.h,
history.c, history.h, histsearch.c, input.c, isearch.c,
keymaps.c, keymaps.h, kill.c, macro.c, nls.c, parens.c,
posixdir.h, readline.c, readline.h, rlconf.h, rldefs.h,
rlprivate.h, rlshell.h, rlstdc.h, rltty.c, savestring.c,
search.c, shell.c, signals.c, terminal.c, tilde.c, tilde.h,
undo.c, util.c, vi_keymap.c, vi_mode.c, xmalloc.c, xmalloc.h,
doc/Makefile.in, doc/hist.texinfo, doc/hstech.texinfo,
doc/hsuser.texinfo, doc/manvers.texinfo, doc/readline.3,
doc/rlman.texinfo, doc/rltech.texinfo, doc/rluser.texinfo
doc/rluserman.texinfo, doc/texi2dvi, doc/texi2html,
shlib/Makefile.in, support/install.sh, support/mkdirs,
support/mkdist, support/shlib-install, support/shobj-conf,
examples/Inputrc, examples/Makefile.in, examples/fileman.c,
examples/histexamp.c, examples/manexamp.c, examples/rl.c,
examples/rlfe.c, examples/rltest.c, examples/rlversion.c:
Modified files.
2002-12-08 23:31:39 +01:00
|
|
|
|
1999-04-16 03:34:55 +02:00
|
|
|
#if defined (HAVE_UNISTD_H)
|
|
|
|
# ifdef _MINIX
|
|
|
|
# include <sys/types.h>
|
|
|
|
# endif
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "history.h"
|
|
|
|
#include "histlib.h"
|
|
|
|
|
|
|
|
/* The list of alternate characters that can delimit a history search
|
|
|
|
string. */
|
|
|
|
char *history_search_delimiter_chars = (char *)NULL;
|
|
|
|
|
Import of readline 4.3.
Non-readline modified files:
src/gdb/ChangeLog src/gdb/defs.h src/gdb/cli/cli-cmds.c
src/gdb/cli/cli-setshow.c src/gdb/tui/ChangeLog
src/gdb/tui/tuiWin.c
In readline directory:
* compat.c, mbutil.c, misc.c, rlmbutil.h, rltypedefs.h,
text.c, doc/history.0, doc/history.3, support/wcwidth.c,
examples/readlinebuf.h, examples/rlcat.c: New files.
* CHANGELOG, CHANGES, INSTALL, MANIFEST, Makefile.in, README,
aclocal.m4, ansi_stdlib.h, bind.c, callback.c, chardefs.h,
complete.c, config.h.in, configure, configure.in, display.c,
emacs_keymap.c, funmap.c, histexpand.c, histfile.c, histlib.h,
history.c, history.h, histsearch.c, input.c, isearch.c,
keymaps.c, keymaps.h, kill.c, macro.c, nls.c, parens.c,
posixdir.h, readline.c, readline.h, rlconf.h, rldefs.h,
rlprivate.h, rlshell.h, rlstdc.h, rltty.c, savestring.c,
search.c, shell.c, signals.c, terminal.c, tilde.c, tilde.h,
undo.c, util.c, vi_keymap.c, vi_mode.c, xmalloc.c, xmalloc.h,
doc/Makefile.in, doc/hist.texinfo, doc/hstech.texinfo,
doc/hsuser.texinfo, doc/manvers.texinfo, doc/readline.3,
doc/rlman.texinfo, doc/rltech.texinfo, doc/rluser.texinfo
doc/rluserman.texinfo, doc/texi2dvi, doc/texi2html,
shlib/Makefile.in, support/install.sh, support/mkdirs,
support/mkdist, support/shlib-install, support/shobj-conf,
examples/Inputrc, examples/Makefile.in, examples/fileman.c,
examples/histexamp.c, examples/manexamp.c, examples/rl.c,
examples/rlfe.c, examples/rltest.c, examples/rlversion.c:
Modified files.
2002-12-08 23:31:39 +01:00
|
|
|
static int history_search_internal PARAMS((const char *, int, int));
|
|
|
|
|
1999-04-16 03:34:55 +02:00
|
|
|
/* Search the history for STRING, starting at history_offset.
|
|
|
|
If DIRECTION < 0, then the search is through previous entries, else
|
|
|
|
through subsequent. If ANCHORED is non-zero, the string must
|
|
|
|
appear at the beginning of a history line, otherwise, the string
|
|
|
|
may appear anywhere in the line. If the string is found, then
|
|
|
|
current_history () is the history entry, and the value of this
|
|
|
|
function is the offset in the line of that history entry that the
|
|
|
|
string was found in. Otherwise, nothing is changed, and a -1 is
|
|
|
|
returned. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
history_search_internal (string, direction, anchored)
|
Import of readline 4.3.
Non-readline modified files:
src/gdb/ChangeLog src/gdb/defs.h src/gdb/cli/cli-cmds.c
src/gdb/cli/cli-setshow.c src/gdb/tui/ChangeLog
src/gdb/tui/tuiWin.c
In readline directory:
* compat.c, mbutil.c, misc.c, rlmbutil.h, rltypedefs.h,
text.c, doc/history.0, doc/history.3, support/wcwidth.c,
examples/readlinebuf.h, examples/rlcat.c: New files.
* CHANGELOG, CHANGES, INSTALL, MANIFEST, Makefile.in, README,
aclocal.m4, ansi_stdlib.h, bind.c, callback.c, chardefs.h,
complete.c, config.h.in, configure, configure.in, display.c,
emacs_keymap.c, funmap.c, histexpand.c, histfile.c, histlib.h,
history.c, history.h, histsearch.c, input.c, isearch.c,
keymaps.c, keymaps.h, kill.c, macro.c, nls.c, parens.c,
posixdir.h, readline.c, readline.h, rlconf.h, rldefs.h,
rlprivate.h, rlshell.h, rlstdc.h, rltty.c, savestring.c,
search.c, shell.c, signals.c, terminal.c, tilde.c, tilde.h,
undo.c, util.c, vi_keymap.c, vi_mode.c, xmalloc.c, xmalloc.h,
doc/Makefile.in, doc/hist.texinfo, doc/hstech.texinfo,
doc/hsuser.texinfo, doc/manvers.texinfo, doc/readline.3,
doc/rlman.texinfo, doc/rltech.texinfo, doc/rluser.texinfo
doc/rluserman.texinfo, doc/texi2dvi, doc/texi2html,
shlib/Makefile.in, support/install.sh, support/mkdirs,
support/mkdist, support/shlib-install, support/shobj-conf,
examples/Inputrc, examples/Makefile.in, examples/fileman.c,
examples/histexamp.c, examples/manexamp.c, examples/rl.c,
examples/rlfe.c, examples/rltest.c, examples/rlversion.c:
Modified files.
2002-12-08 23:31:39 +01:00
|
|
|
const char *string;
|
1999-04-16 03:34:55 +02:00
|
|
|
int direction, anchored;
|
|
|
|
{
|
|
|
|
register int i, reverse;
|
|
|
|
register char *line;
|
|
|
|
register int line_index;
|
|
|
|
int string_len;
|
|
|
|
HIST_ENTRY **the_history; /* local */
|
|
|
|
|
|
|
|
i = history_offset;
|
|
|
|
reverse = (direction < 0);
|
|
|
|
|
|
|
|
/* Take care of trivial cases first. */
|
|
|
|
if (string == 0 || *string == '\0')
|
|
|
|
return (-1);
|
|
|
|
|
2006-05-05 20:26:14 +02:00
|
|
|
if (!history_length || ((i >= history_length) && !reverse))
|
1999-04-16 03:34:55 +02:00
|
|
|
return (-1);
|
|
|
|
|
2006-05-05 20:26:14 +02:00
|
|
|
if (reverse && (i >= history_length))
|
|
|
|
i = history_length - 1;
|
1999-04-16 03:34:55 +02:00
|
|
|
|
|
|
|
#define NEXT_LINE() do { if (reverse) i--; else i++; } while (0)
|
|
|
|
|
|
|
|
the_history = history_list ();
|
|
|
|
string_len = strlen (string);
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
/* Search each line in the history list for STRING. */
|
|
|
|
|
|
|
|
/* At limit for direction? */
|
|
|
|
if ((reverse && i < 0) || (!reverse && i == history_length))
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
line = the_history[i]->line;
|
|
|
|
line_index = strlen (line);
|
|
|
|
|
|
|
|
/* If STRING is longer than line, no match. */
|
|
|
|
if (string_len > line_index)
|
|
|
|
{
|
|
|
|
NEXT_LINE ();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle anchored searches first. */
|
|
|
|
if (anchored == ANCHORED_SEARCH)
|
|
|
|
{
|
|
|
|
if (STREQN (string, line, string_len))
|
|
|
|
{
|
|
|
|
history_offset = i;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
NEXT_LINE ();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do substring search. */
|
|
|
|
if (reverse)
|
|
|
|
{
|
|
|
|
line_index -= string_len;
|
|
|
|
|
|
|
|
while (line_index >= 0)
|
|
|
|
{
|
|
|
|
if (STREQN (string, line + line_index, string_len))
|
|
|
|
{
|
|
|
|
history_offset = i;
|
|
|
|
return (line_index);
|
|
|
|
}
|
|
|
|
line_index--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
register int limit;
|
|
|
|
|
|
|
|
limit = line_index - string_len + 1;
|
|
|
|
line_index = 0;
|
|
|
|
|
|
|
|
while (line_index < limit)
|
|
|
|
{
|
|
|
|
if (STREQN (string, line + line_index, string_len))
|
|
|
|
{
|
|
|
|
history_offset = i;
|
|
|
|
return (line_index);
|
|
|
|
}
|
|
|
|
line_index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NEXT_LINE ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do a non-anchored search for STRING through the history in DIRECTION. */
|
|
|
|
int
|
|
|
|
history_search (string, direction)
|
Import of readline 4.3.
Non-readline modified files:
src/gdb/ChangeLog src/gdb/defs.h src/gdb/cli/cli-cmds.c
src/gdb/cli/cli-setshow.c src/gdb/tui/ChangeLog
src/gdb/tui/tuiWin.c
In readline directory:
* compat.c, mbutil.c, misc.c, rlmbutil.h, rltypedefs.h,
text.c, doc/history.0, doc/history.3, support/wcwidth.c,
examples/readlinebuf.h, examples/rlcat.c: New files.
* CHANGELOG, CHANGES, INSTALL, MANIFEST, Makefile.in, README,
aclocal.m4, ansi_stdlib.h, bind.c, callback.c, chardefs.h,
complete.c, config.h.in, configure, configure.in, display.c,
emacs_keymap.c, funmap.c, histexpand.c, histfile.c, histlib.h,
history.c, history.h, histsearch.c, input.c, isearch.c,
keymaps.c, keymaps.h, kill.c, macro.c, nls.c, parens.c,
posixdir.h, readline.c, readline.h, rlconf.h, rldefs.h,
rlprivate.h, rlshell.h, rlstdc.h, rltty.c, savestring.c,
search.c, shell.c, signals.c, terminal.c, tilde.c, tilde.h,
undo.c, util.c, vi_keymap.c, vi_mode.c, xmalloc.c, xmalloc.h,
doc/Makefile.in, doc/hist.texinfo, doc/hstech.texinfo,
doc/hsuser.texinfo, doc/manvers.texinfo, doc/readline.3,
doc/rlman.texinfo, doc/rltech.texinfo, doc/rluser.texinfo
doc/rluserman.texinfo, doc/texi2dvi, doc/texi2html,
shlib/Makefile.in, support/install.sh, support/mkdirs,
support/mkdist, support/shlib-install, support/shobj-conf,
examples/Inputrc, examples/Makefile.in, examples/fileman.c,
examples/histexamp.c, examples/manexamp.c, examples/rl.c,
examples/rlfe.c, examples/rltest.c, examples/rlversion.c:
Modified files.
2002-12-08 23:31:39 +01:00
|
|
|
const char *string;
|
1999-04-16 03:34:55 +02:00
|
|
|
int direction;
|
|
|
|
{
|
|
|
|
return (history_search_internal (string, direction, NON_ANCHORED_SEARCH));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do an anchored search for string through the history in DIRECTION. */
|
|
|
|
int
|
|
|
|
history_search_prefix (string, direction)
|
Import of readline 4.3.
Non-readline modified files:
src/gdb/ChangeLog src/gdb/defs.h src/gdb/cli/cli-cmds.c
src/gdb/cli/cli-setshow.c src/gdb/tui/ChangeLog
src/gdb/tui/tuiWin.c
In readline directory:
* compat.c, mbutil.c, misc.c, rlmbutil.h, rltypedefs.h,
text.c, doc/history.0, doc/history.3, support/wcwidth.c,
examples/readlinebuf.h, examples/rlcat.c: New files.
* CHANGELOG, CHANGES, INSTALL, MANIFEST, Makefile.in, README,
aclocal.m4, ansi_stdlib.h, bind.c, callback.c, chardefs.h,
complete.c, config.h.in, configure, configure.in, display.c,
emacs_keymap.c, funmap.c, histexpand.c, histfile.c, histlib.h,
history.c, history.h, histsearch.c, input.c, isearch.c,
keymaps.c, keymaps.h, kill.c, macro.c, nls.c, parens.c,
posixdir.h, readline.c, readline.h, rlconf.h, rldefs.h,
rlprivate.h, rlshell.h, rlstdc.h, rltty.c, savestring.c,
search.c, shell.c, signals.c, terminal.c, tilde.c, tilde.h,
undo.c, util.c, vi_keymap.c, vi_mode.c, xmalloc.c, xmalloc.h,
doc/Makefile.in, doc/hist.texinfo, doc/hstech.texinfo,
doc/hsuser.texinfo, doc/manvers.texinfo, doc/readline.3,
doc/rlman.texinfo, doc/rltech.texinfo, doc/rluser.texinfo
doc/rluserman.texinfo, doc/texi2dvi, doc/texi2html,
shlib/Makefile.in, support/install.sh, support/mkdirs,
support/mkdist, support/shlib-install, support/shobj-conf,
examples/Inputrc, examples/Makefile.in, examples/fileman.c,
examples/histexamp.c, examples/manexamp.c, examples/rl.c,
examples/rlfe.c, examples/rltest.c, examples/rlversion.c:
Modified files.
2002-12-08 23:31:39 +01:00
|
|
|
const char *string;
|
1999-04-16 03:34:55 +02:00
|
|
|
int direction;
|
|
|
|
{
|
|
|
|
return (history_search_internal (string, direction, ANCHORED_SEARCH));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for STRING in the history list. DIR is < 0 for searching
|
|
|
|
backwards. POS is an absolute index into the history list at
|
|
|
|
which point to begin searching. */
|
|
|
|
int
|
|
|
|
history_search_pos (string, dir, pos)
|
Import of readline 4.3.
Non-readline modified files:
src/gdb/ChangeLog src/gdb/defs.h src/gdb/cli/cli-cmds.c
src/gdb/cli/cli-setshow.c src/gdb/tui/ChangeLog
src/gdb/tui/tuiWin.c
In readline directory:
* compat.c, mbutil.c, misc.c, rlmbutil.h, rltypedefs.h,
text.c, doc/history.0, doc/history.3, support/wcwidth.c,
examples/readlinebuf.h, examples/rlcat.c: New files.
* CHANGELOG, CHANGES, INSTALL, MANIFEST, Makefile.in, README,
aclocal.m4, ansi_stdlib.h, bind.c, callback.c, chardefs.h,
complete.c, config.h.in, configure, configure.in, display.c,
emacs_keymap.c, funmap.c, histexpand.c, histfile.c, histlib.h,
history.c, history.h, histsearch.c, input.c, isearch.c,
keymaps.c, keymaps.h, kill.c, macro.c, nls.c, parens.c,
posixdir.h, readline.c, readline.h, rlconf.h, rldefs.h,
rlprivate.h, rlshell.h, rlstdc.h, rltty.c, savestring.c,
search.c, shell.c, signals.c, terminal.c, tilde.c, tilde.h,
undo.c, util.c, vi_keymap.c, vi_mode.c, xmalloc.c, xmalloc.h,
doc/Makefile.in, doc/hist.texinfo, doc/hstech.texinfo,
doc/hsuser.texinfo, doc/manvers.texinfo, doc/readline.3,
doc/rlman.texinfo, doc/rltech.texinfo, doc/rluser.texinfo
doc/rluserman.texinfo, doc/texi2dvi, doc/texi2html,
shlib/Makefile.in, support/install.sh, support/mkdirs,
support/mkdist, support/shlib-install, support/shobj-conf,
examples/Inputrc, examples/Makefile.in, examples/fileman.c,
examples/histexamp.c, examples/manexamp.c, examples/rl.c,
examples/rlfe.c, examples/rltest.c, examples/rlversion.c:
Modified files.
2002-12-08 23:31:39 +01:00
|
|
|
const char *string;
|
1999-04-16 03:34:55 +02:00
|
|
|
int dir, pos;
|
|
|
|
{
|
|
|
|
int ret, old;
|
|
|
|
|
|
|
|
old = where_history ();
|
|
|
|
history_set_pos (pos);
|
|
|
|
if (history_search (string, dir) == -1)
|
|
|
|
{
|
|
|
|
history_set_pos (old);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
ret = where_history ();
|
|
|
|
history_set_pos (old);
|
|
|
|
return ret;
|
|
|
|
}
|