mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 12:32:27 +01:00
14decc4fbc
(Mostly in DBUG_PRINT() and unused arguments) Fixed bug in query cache when used with traceing (--with-debug) Fixed memory leak in mysqldump Removed warnings from mysqltest scripts (replaced -- with #) BitKeeper/etc/ignore: added mysql-test/r/*.warnings BUILD/SETUP.sh: Don't build with BDB as default client/client_priv.h: Added OPT_DEBUG_INFO client/mysqlbinlog.cc: Fixed compiler warning client/mysqldump.c: Removed compiler warnings Added option --debug-info to detect memory leaks Fixed memory leak Don't backup cluster replication tables (if used with 5.1) cmd-line-utils/readline/bind.c: Fixed compiler warning cmd-line-utils/readline/chardefs.h: Fixed compiler warning cmd-line-utils/readline/complete.c: Fixed compiler warning cmd-line-utils/readline/display.c: Fixed compiler warning cmd-line-utils/readline/histexpand.c: Fixed compiler warning cmd-line-utils/readline/input.c: Fixed compiler warning cmd-line-utils/readline/isearch.c: Fixed compiler warning cmd-line-utils/readline/kill.c: Fixed compiler warning cmd-line-utils/readline/macro.c: Fixed compiler warning cmd-line-utils/readline/misc.c: Fixed compiler warning cmd-line-utils/readline/nls.c: Fixed compiler warning cmd-line-utils/readline/readline.c: Fixed compiler warning cmd-line-utils/readline/rltty.c: Fixed compiler warning cmd-line-utils/readline/search.c: Fixed compiler warning cmd-line-utils/readline/terminal.c: Fixed compiler warning cmd-line-utils/readline/text.c: Fixed compiler warning cmd-line-utils/readline/tilde.c: Fixed compiler warning cmd-line-utils/readline/undo.c: Fixed compiler warning cmd-line-utils/readline/util.c: Fixed compiler warning cmd-line-utils/readline/vi_mode.c: Fixed compiler warning dbug/dbug_analyze.c: Fixed compiler warning extra/yassl/src/ssl.cpp: Fixed compiler warning extra/yassl/testsuite/testsuite.cpp: Fixed compiler warning heap/_check.c: Fixed compiler warning heap/hp_delete.c: Fixed compiler warning heap/hp_hash.c: Fixed compiler warning heap/hp_open.c: Fixed compiler warning heap/hp_rkey.c: Fixed compiler warning heap/hp_rrnd.c: Fixed compiler warning heap/hp_write.c: Fixed compiler warning libmysql/libmysql.c: Fixed compiler warning libmysqld/libmysqld.c: Fixed compiler warning myisam/mi_close.c: Fixed compiler warning myisam/mi_delete.c: Fixed compiler warning myisam/mi_dynrec.c: Fixed compiler warning myisam/mi_keycache.c: Fixed compiler warning myisam/mi_page.c: Fixed compiler warning myisam/mi_statrec.c: Fixed compiler warning myisam/mi_test2.c: Fixed compiler warning myisam/mi_write.c: Fixed compiler warning myisam/myisampack.c: Fixed compiler warning myisammrg/myrg_extra.c: Fixed compiler warning mysql-test/mysql-test-run.pl: Remove .reject, .progress, .log and .warnings flag at start cluster -> mysql database (for 5.1) mysql-test/include/federated.inc: Remove mysqltest warnings mysql-test/include/sp-vars.inc: Remove mysqltest warnings mysql-test/mysql-test-run.sh: Fix so that 'make test' works again Remove .reject, .progress .log and .warnings files at startup mysql-test/r/ctype_cp1250_ch.result: Drop used tables at startup mysql-test/t/create.test: Remove mysqltest warnings mysql-test/t/csv.test: Remove mysqltest warnings mysql-test/t/ctype_collate.test: Remove mysqltest warnings mysql-test/t/ctype_cp1250_ch.test: Drop used tables at startup mysql-test/t/ctype_ucs.test: Remove mysqltest warnings mysql-test/t/func_sapdb.test: Remove mysqltest warnings mysql-test/t/func_str.test: Remove mysqltest warnings mysql-test/t/grant.test: Remove mysqltest warnings mysql-test/t/greedy_optimizer.test: Remove mysqltest warnings mysql-test/t/group_min_max.test: Remove mysqltest warnings mysql-test/t/innodb.test: Remove mysqltest warnings mysql-test/t/join.test: Remove mysqltest warnings mysql-test/t/limit.test: Remove mysqltest warnings mysql-test/t/null.test: Remove mysqltest warnings mysql-test/t/select.test: Remove mysqltest warnings mysql-test/t/sp-prelocking.test: Remove mysqltest warnings mysql-test/t/strict.test: Remove mysqltest warnings mysql-test/t/subselect.test: Remove mysqltest warnings mysql-test/t/type_newdecimal.test: Remove mysqltest warnings mysql-test/t/view_grant.test: Remove mysqltest warnings mysys/default.c: Fixed compiler warning mysys/hash.c: Fixed compiler warning mysys/list.c: Fixed compiler warning mysys/mf_iocache.c: Fixed compiler warning mysys/mf_keycache.c: Fixed compiler warning mysys/mf_keycaches.c: Fixed compiler warning mysys/my_alloc.c: Fixed compiler warning mysys/my_dup.c: Fixed compiler warning mysys/my_fopen.c: Fixed compiler warning mysys/my_fstream.c: Fixed compiler warning mysys/my_getwd.c: Fixed compiler warning mysys/my_handler.c: Fixed compiler warning Added missing enums in switch mysys/my_lib.c: Fixed compiler warning mysys/my_lread.c: Fixed compiler warning mysys/my_lwrite.c: Fixed compiler warning mysys/my_malloc.c: Fixed compiler warning mysys/my_pread.c: Fixed compiler warning mysys/my_read.c: Fixed compiler warning mysys/my_realloc.c: Fixed compiler warning mysys/my_seek.c: Fixed compiler warning mysys/my_write.c: Fixed compiler warning mysys/safemalloc.c: Fixed compiler warning mysys/thr_lock.c: Fixed compiler warning mysys/tree.c: Fixed compiler warning mysys/typelib.c: Fixed compiler warning ndb/include/logger/LogHandler.hpp: Changed SetErrorStr() to take const char* to remove compiler warnings (as many arguments to this are const strings) ndb/include/ndb_global.h.in: Added LINT_SET_PTR macro to be able to remove some compiler warnings ndb/include/util/InputStream.hpp: Fixed compiler warning ndb/include/util/OutputStream.hpp: Fixed compiler warning ndb/include/util/SimpleProperties.hpp: Fixed compiler warning ndb/src/common/debugger/EventLogger.cpp: remove if on 'signal' as this is a function pointer and is always true ndb/src/common/debugger/signaldata/BackupSignalData.cpp: Add missing enums ndb/src/common/logger/LogHandler.cpp: Changed SetErrorStr() to take const char* to remove compiler warnings (as many arguments to this are const strings) ndb/src/common/portlib/NdbMutex.c: Fixed compiler warning ndb/src/common/portlib/NdbThread.c: Fixed compiler warning ndb/src/common/transporter/Transporter.cpp: Swapped arguments to remove compiler warnings ndb/src/cw/cpcd/CPCD.hpp: Fixed compiler warning ndb/src/kernel/blocks/backup/Backup.cpp: Fixed compiler warning ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp: Fixed compiler warning ndb/src/kernel/blocks/dbdict/Dbdict.cpp: Fixed compiler warning ndb/src/kernel/blocks/dbtux/DbtuxSearch.cpp: Fixed compiler warning ndb/src/kernel/blocks/ndbcntr/NdbcntrMain.cpp: Added missing enums ndb/src/kernel/blocks/qmgr/QmgrMain.cpp: Fixed compiler warning ndb/src/kernel/error/ErrorReporter.cpp: Fixed compiler warning ndb/src/kernel/error/ErrorReporter.hpp: Fixed compiler warning ndb/src/kernel/error/ndbd_exit_codes.c: Fixed compiler warning ndb/src/kernel/vm/TransporterCallback.cpp: Fixed compiler warning ndb/src/mgmapi/mgmapi.cpp: Fixed compiler warning ndb/src/mgmclient/CommandInterpreter.cpp: Fixed compiler warning ndb/src/mgmsrv/MgmtSrvr.cpp: Fixed compiler warning ndb/src/mgmsrv/Services.cpp: Fixed compiler warning ndb/src/ndbapi/ClusterMgr.cpp: Fixed compiler warning ndb/src/ndbapi/DictCache.cpp: Fixed compiler warning ndb/src/ndbapi/Ndb.cpp: Fixed compiler warning ndb/src/ndbapi/NdbOperationDefine.cpp: Fixed compiler warning ndb/src/ndbapi/NdbOperationExec.cpp: Fixed compiler warning ndb/src/ndbapi/NdbOperationInt.cpp: Fixed compiler warning ndb/src/ndbapi/NdbOperationSearch.cpp: Fixed compiler warning ndb/src/ndbapi/NdbTransaction.cpp: Fixed compiler warning ndb/src/ndbapi/Ndbif.cpp: Fixed compiler warning ndb/src/ndbapi/Ndbinit.cpp: Fixed compiler warning ndb/src/ndbapi/ndb_cluster_connection.cpp: Fixed compiler warning ndb/tools/drop_index.cpp: Fixed compiler warning ndb/tools/drop_tab.cpp: Fixed compiler warning ndb/tools/ndb_config.cpp: Fixed compiler warning regex/regexec.c: Fixed compiler warning server-tools/instance-manager/mysql_connection.cc: Fixed compiler warning sql/Makefile.am: Fix for bison 1.875, which adds an attribute statement that gcc 4.1.0 can't parse sql/filesort.cc: Fixed compiler warning sql/ha_archive.cc: Fixed compiler warning sql/ha_federated.cc: Fixed compiler warning sql/ha_federated.h: Fixed compiler warning sql/ha_innodb.cc: Fixed compiler warning sql/ha_myisam.cc: Fixed compiler warning sql/ha_myisammrg.cc: Fixed compiler warning sql/ha_ndbcluster.cc: Fixed compiler warning sql/handler.cc: Fixed compiler warning sql/item_cmpfunc.cc: Fixed compiler warning sql/item_subselect.cc: Fixed compiler warning sql/item_timefunc.cc: Fixed compiler warning sql/log_event.cc: Fixed compiler warning sql/mysqld.cc: Fixed compiler warning sql/net_serv.cc: Fixed compiler warning sql/opt_range.cc: Fixed compiler warning Formated DBUG statements to be as rest of code sql/slave.cc: Fixed compiler warning sql/sql_acl.cc: Fixed compiler warning sql/sql_cache.cc: Fixed compiler warning Fixed bug in query cache when used with DBUG traceing sql/sql_class.cc: Fixed compiler warning sql/sql_class.h: Fixed compiler warning sql/sql_delete.cc: Fixed compiler warning sql/sql_parse.cc: Fixed compiler warning Hack to fix my_sprintf() strings with %b sql/sql_prepare.cc: Fixed compiler warning Hack to fix my_sprintf() strings with %b sql/sql_repl.cc: Fixed compiler warning sql/sql_select.cc: Fixed compiler warning sql/sql_update.cc: Fixed compiler warning sql/sql_view.cc: Fixed compiler warning sql/strfunc.cc: Fixed compiler warning sql-common/client.c: Fixed compiler warning sql-common/my_time.c: Fixed compiler warning sql/table.cc: Fixed compiler warning sql/tztime.cc: Fixed compiler warning sql/unireg.cc: Fixed compiler warning strings/decimal.c: Fixed compiler warning tests/mysql_client_test.c: Fixed compiler warning vio/viosocket.c: Fixed compiler warning vio/viossl.c: Fixed compiler warning vio/viosslfactories.c: Fixed compiler warning
471 lines
12 KiB
C
471 lines
12 KiB
C
/* search.c - code for non-incremental searching in emacs and vi modes. */
|
|
|
|
/* Copyright (C) 1992 Free Software Foundation, Inc.
|
|
|
|
This file is part of the Readline Library (the Library), a set of
|
|
routines for providing Emacs style line input to programs that ask
|
|
for it.
|
|
|
|
The Library is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
any later version.
|
|
|
|
The Library is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
The GNU General Public License is often shipped with GNU software, and
|
|
is generally kept in a file called COPYING or LICENSE. If you do not
|
|
have a copy of the license, write to the Free Software Foundation,
|
|
59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
|
#define READLINE_LIBRARY
|
|
|
|
#include "config_readline.h"
|
|
|
|
#include <sys/types.h>
|
|
#include <stdio.h>
|
|
|
|
#if defined (HAVE_UNISTD_H)
|
|
# include <unistd.h>
|
|
#endif
|
|
|
|
#if defined (HAVE_STDLIB_H)
|
|
# include <stdlib.h>
|
|
#else
|
|
# include "ansi_stdlib.h"
|
|
#endif
|
|
|
|
#include "rldefs.h"
|
|
#include "rlmbutil.h"
|
|
|
|
#include "readline.h"
|
|
#include "history.h"
|
|
|
|
#include "rlprivate.h"
|
|
#include "xmalloc.h"
|
|
|
|
#ifdef abs
|
|
# undef abs
|
|
#endif
|
|
#define abs(x) (((x) >= 0) ? (x) : -(x))
|
|
|
|
extern HIST_ENTRY *_rl_saved_line_for_history;
|
|
|
|
/* Functions imported from the rest of the library. */
|
|
extern int _rl_free_history_entry PARAMS((HIST_ENTRY *));
|
|
|
|
static char *noninc_search_string = (char *) NULL;
|
|
static int noninc_history_pos;
|
|
|
|
static char *prev_line_found = (char *) NULL;
|
|
|
|
static int rl_history_search_len;
|
|
static int rl_history_search_pos;
|
|
static char *history_search_string;
|
|
static int history_string_size;
|
|
|
|
static void make_history_line_current PARAMS((HIST_ENTRY *));
|
|
static int noninc_search_from_pos PARAMS((char *, int, int));
|
|
static void noninc_dosearch PARAMS((char *, int));
|
|
static void noninc_search PARAMS((int, int));
|
|
static int rl_history_search_internal PARAMS((int, int));
|
|
static void rl_history_search_reinit PARAMS((void));
|
|
|
|
/* Make the data from the history entry ENTRY be the contents of the
|
|
current line. This doesn't do anything with rl_point; the caller
|
|
must set it. */
|
|
static void
|
|
make_history_line_current (entry)
|
|
HIST_ENTRY *entry;
|
|
{
|
|
#if 0
|
|
rl_replace_line (entry->line, 1);
|
|
rl_undo_list = (UNDO_LIST *)entry->data;
|
|
#else
|
|
_rl_replace_text (entry->line, 0, rl_end);
|
|
_rl_fix_point (1);
|
|
#endif
|
|
|
|
if (_rl_saved_line_for_history)
|
|
_rl_free_history_entry (_rl_saved_line_for_history);
|
|
_rl_saved_line_for_history = (HIST_ENTRY *)NULL;
|
|
}
|
|
|
|
/* Search the history list for STRING starting at absolute history position
|
|
POS. If STRING begins with `^', the search must match STRING at the
|
|
beginning of a history line, otherwise a full substring match is performed
|
|
for STRING. DIR < 0 means to search backwards through the history list,
|
|
DIR >= 0 means to search forward. */
|
|
static int
|
|
noninc_search_from_pos (string, pos, dir)
|
|
char *string;
|
|
int pos, dir;
|
|
{
|
|
int ret, old;
|
|
|
|
if (pos < 0)
|
|
return -1;
|
|
|
|
old = where_history ();
|
|
if (history_set_pos (pos) == 0)
|
|
return -1;
|
|
|
|
RL_SETSTATE(RL_STATE_SEARCH);
|
|
if (*string == '^')
|
|
ret = history_search_prefix (string + 1, dir);
|
|
else
|
|
ret = history_search (string, dir);
|
|
RL_UNSETSTATE(RL_STATE_SEARCH);
|
|
|
|
if (ret != -1)
|
|
ret = where_history ();
|
|
|
|
history_set_pos (old);
|
|
return (ret);
|
|
}
|
|
|
|
/* Search for a line in the history containing STRING. If DIR is < 0, the
|
|
search is backwards through previous entries, else through subsequent
|
|
entries. */
|
|
static void
|
|
noninc_dosearch (string, dir)
|
|
char *string;
|
|
int dir;
|
|
{
|
|
int oldpos, pos;
|
|
HIST_ENTRY *entry;
|
|
|
|
if (string == 0 || *string == '\0' || noninc_history_pos < 0)
|
|
{
|
|
rl_ding ();
|
|
return;
|
|
}
|
|
|
|
pos = noninc_search_from_pos (string, noninc_history_pos + dir, dir);
|
|
if (pos == -1)
|
|
{
|
|
/* Search failed, current history position unchanged. */
|
|
rl_maybe_unsave_line ();
|
|
rl_clear_message ();
|
|
rl_point = 0;
|
|
rl_ding ();
|
|
return;
|
|
}
|
|
|
|
noninc_history_pos = pos;
|
|
|
|
oldpos = where_history ();
|
|
history_set_pos (noninc_history_pos);
|
|
entry = current_history ();
|
|
#if defined (VI_MODE)
|
|
if (rl_editing_mode != vi_mode)
|
|
#endif
|
|
history_set_pos (oldpos);
|
|
|
|
make_history_line_current (entry);
|
|
|
|
rl_point = 0;
|
|
rl_mark = rl_end;
|
|
|
|
rl_clear_message ();
|
|
}
|
|
|
|
/* Search non-interactively through the history list. DIR < 0 means to
|
|
search backwards through the history of previous commands; otherwise
|
|
the search is for commands subsequent to the current position in the
|
|
history list. PCHAR is the character to use for prompting when reading
|
|
the search string; if not specified (0), it defaults to `:'. */
|
|
static void
|
|
noninc_search (dir, pchar)
|
|
int dir;
|
|
int pchar;
|
|
{
|
|
int saved_point, saved_mark, c;
|
|
char *p;
|
|
#if defined (HANDLE_MULTIBYTE)
|
|
char mb[MB_LEN_MAX];
|
|
#endif
|
|
|
|
rl_maybe_save_line ();
|
|
saved_point = rl_point;
|
|
saved_mark = rl_mark;
|
|
|
|
/* Clear the undo list, since reading the search string should create its
|
|
own undo list, and the whole list will end up being freed when we
|
|
finish reading the search string. */
|
|
rl_undo_list = 0;
|
|
|
|
/* Use the line buffer to read the search string. */
|
|
rl_line_buffer[0] = 0;
|
|
rl_end = rl_point = 0;
|
|
|
|
p = _rl_make_prompt_for_search (pchar ? pchar : ':');
|
|
rl_message (p, 0, 0);
|
|
free (p);
|
|
|
|
#define SEARCH_RETURN rl_restore_prompt (); RL_UNSETSTATE(RL_STATE_NSEARCH); return
|
|
|
|
RL_SETSTATE(RL_STATE_NSEARCH);
|
|
/* Read the search string. */
|
|
while (1)
|
|
{
|
|
RL_SETSTATE(RL_STATE_MOREINPUT);
|
|
c = rl_read_key ();
|
|
RL_UNSETSTATE(RL_STATE_MOREINPUT);
|
|
|
|
#if defined (HANDLE_MULTIBYTE)
|
|
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
|
c = _rl_read_mbstring (c, mb, MB_LEN_MAX);
|
|
#endif
|
|
|
|
if (c == 0)
|
|
break;
|
|
|
|
switch (c)
|
|
{
|
|
case CTRL('H'):
|
|
case RUBOUT:
|
|
if (rl_point == 0)
|
|
{
|
|
rl_maybe_unsave_line ();
|
|
rl_clear_message ();
|
|
rl_point = saved_point;
|
|
rl_mark = saved_mark;
|
|
SEARCH_RETURN;
|
|
}
|
|
_rl_rubout_char (1, c);
|
|
break;
|
|
|
|
case CTRL('W'):
|
|
rl_unix_word_rubout (1, c);
|
|
break;
|
|
|
|
case CTRL('U'):
|
|
rl_unix_line_discard (1, c);
|
|
break;
|
|
|
|
case RETURN:
|
|
case NEWLINE:
|
|
goto dosearch;
|
|
/* NOTREACHED */
|
|
break;
|
|
|
|
case CTRL('C'):
|
|
case CTRL('G'):
|
|
rl_maybe_unsave_line ();
|
|
rl_clear_message ();
|
|
rl_point = saved_point;
|
|
rl_mark = saved_mark;
|
|
rl_ding ();
|
|
SEARCH_RETURN;
|
|
|
|
default:
|
|
#if defined (HANDLE_MULTIBYTE)
|
|
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
|
rl_insert_text (mb);
|
|
else
|
|
#endif
|
|
_rl_insert_char (1, c);
|
|
break;
|
|
}
|
|
(*rl_redisplay_function) ();
|
|
}
|
|
|
|
dosearch:
|
|
rl_mark = saved_mark;
|
|
|
|
/* If rl_point == 0, we want to re-use the previous search string and
|
|
start from the saved history position. If there's no previous search
|
|
string, punt. */
|
|
if (rl_point == 0)
|
|
{
|
|
if (!noninc_search_string)
|
|
{
|
|
rl_ding ();
|
|
SEARCH_RETURN;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
/* We want to start the search from the current history position. */
|
|
noninc_history_pos = where_history ();
|
|
FREE (noninc_search_string);
|
|
noninc_search_string = savestring (rl_line_buffer);
|
|
}
|
|
|
|
rl_restore_prompt ();
|
|
noninc_dosearch (noninc_search_string, dir);
|
|
RL_UNSETSTATE(RL_STATE_NSEARCH);
|
|
}
|
|
|
|
/* Search forward through the history list for a string. If the vi-mode
|
|
code calls this, KEY will be `?'. */
|
|
int
|
|
rl_noninc_forward_search (int count __attribute__((unused)), int key)
|
|
{
|
|
noninc_search (1, (key == '?') ? '?' : 0);
|
|
return 0;
|
|
}
|
|
|
|
/* Reverse search the history list for a string. If the vi-mode code
|
|
calls this, KEY will be `/'. */
|
|
int
|
|
rl_noninc_reverse_search (int count __attribute__((unused)), int key)
|
|
{
|
|
noninc_search (-1, (key == '/') ? '/' : 0);
|
|
return 0;
|
|
}
|
|
|
|
/* Search forward through the history list for the last string searched
|
|
for. If there is no saved search string, abort. */
|
|
int
|
|
rl_noninc_forward_search_again (int count __attribute__((unused)),
|
|
int key __attribute__((unused)))
|
|
{
|
|
if (!noninc_search_string)
|
|
{
|
|
rl_ding ();
|
|
return (-1);
|
|
}
|
|
noninc_dosearch (noninc_search_string, 1);
|
|
return 0;
|
|
}
|
|
|
|
/* Reverse search in the history list for the last string searched
|
|
for. If there is no saved search string, abort. */
|
|
int
|
|
rl_noninc_reverse_search_again (int count __attribute__((unused)),
|
|
int key __attribute__((unused)))
|
|
{
|
|
if (!noninc_search_string)
|
|
{
|
|
rl_ding ();
|
|
return (-1);
|
|
}
|
|
noninc_dosearch (noninc_search_string, -1);
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
rl_history_search_internal (count, dir)
|
|
int count, dir;
|
|
{
|
|
HIST_ENTRY *temp;
|
|
int ret, oldpos;
|
|
|
|
rl_maybe_save_line ();
|
|
temp = (HIST_ENTRY *)NULL;
|
|
|
|
/* Search COUNT times through the history for a line whose prefix
|
|
matches history_search_string. When this loop finishes, TEMP,
|
|
if non-null, is the history line to copy into the line buffer. */
|
|
while (count)
|
|
{
|
|
ret = noninc_search_from_pos (history_search_string, rl_history_search_pos + dir, dir);
|
|
if (ret == -1)
|
|
break;
|
|
|
|
/* Get the history entry we found. */
|
|
rl_history_search_pos = ret;
|
|
oldpos = where_history ();
|
|
history_set_pos (rl_history_search_pos);
|
|
temp = current_history ();
|
|
history_set_pos (oldpos);
|
|
|
|
/* Don't find multiple instances of the same line. */
|
|
if (prev_line_found && STREQ (prev_line_found, temp->line))
|
|
continue;
|
|
prev_line_found = temp->line;
|
|
count--;
|
|
}
|
|
|
|
/* If we didn't find anything at all, return. */
|
|
if (temp == 0)
|
|
{
|
|
rl_maybe_unsave_line ();
|
|
rl_ding ();
|
|
/* If you don't want the saved history line (last match) to show up
|
|
in the line buffer after the search fails, change the #if 0 to
|
|
#if 1 */
|
|
#if 0
|
|
if (rl_point > rl_history_search_len)
|
|
{
|
|
rl_point = rl_end = rl_history_search_len;
|
|
rl_line_buffer[rl_end] = '\0';
|
|
rl_mark = 0;
|
|
}
|
|
#else
|
|
rl_point = rl_history_search_len; /* rl_maybe_unsave_line changes it */
|
|
rl_mark = rl_end;
|
|
#endif
|
|
return 1;
|
|
}
|
|
|
|
/* Copy the line we found into the current line buffer. */
|
|
make_history_line_current (temp);
|
|
|
|
rl_point = rl_history_search_len;
|
|
rl_mark = rl_end;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void
|
|
rl_history_search_reinit ()
|
|
{
|
|
rl_history_search_pos = where_history ();
|
|
rl_history_search_len = rl_point;
|
|
prev_line_found = (char *)NULL;
|
|
if (rl_point)
|
|
{
|
|
if (rl_history_search_len >= history_string_size - 2)
|
|
{
|
|
history_string_size = rl_history_search_len + 2;
|
|
history_search_string = (char *)xrealloc (history_search_string, history_string_size);
|
|
}
|
|
history_search_string[0] = '^';
|
|
strncpy (history_search_string + 1, rl_line_buffer, rl_point);
|
|
history_search_string[rl_point + 1] = '\0';
|
|
}
|
|
_rl_free_saved_history_line ();
|
|
}
|
|
|
|
/* 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 &&
|
|
rl_last_func != rl_history_search_backward)
|
|
rl_history_search_reinit ();
|
|
|
|
if (rl_history_search_len == 0)
|
|
return (rl_get_next_history (count, ignore));
|
|
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_forward &&
|
|
rl_last_func != rl_history_search_backward)
|
|
rl_history_search_reinit ();
|
|
|
|
if (rl_history_search_len == 0)
|
|
return (rl_get_previous_history (count, ignore));
|
|
return (rl_history_search_internal (abs (count), (count > 0) ? -1 : 1));
|
|
}
|