TheGNUGeneralPublicLicenseisoftenshippedwithGNUsoftware,and isgenerallykeptinafilecalledCOPYINGorLICENSE.Ifyoudonot haveacopyofthelicense,writetotheFreeSoftwareFoundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA. */ #define READLINE_LIBRARY
#ifdefined (HAVE_CONFIG_H) # include "config_readline.h" #endif
#include <sys/types.h> #include <stdio.h>
#ifdefined (HAVE_UNISTD_H) # include <unistd.h> #endif
#ifdefined (HAVE_STDLIB_H) # include <stdlib.h> #else # include "ansi_stdlib.h" #endif
/* Make the data from the history entry ENTRY be the contents of the currentline.Thisdoesn'tdoanythingwithrl_point;thecaller
must set it. */ staticvoid
make_history_line_current (entry)
HIST_ENTRY *entry;
{
_rl_replace_text (entry->line, 0, rl_end);
_rl_fix_point (1); #ifdefined (VI_MODE) if (rl_editing_mode == vi_mode) /* POSIX.2 says that the `U' command doesn't affect the copy of any commandlinestotheeditline.We'regoingtoimplementthatby makingtheundoliststartafterthematchinglineiscopiedtothe
current editing buffer. */
rl_free_undo_list (); #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.IfSTRINGbeginswith`^',thesearchmustmatchSTRINGatthe beginningofahistoryline,otherwiseafullsubstringmatchisperformed forSTRING.DIR<0meanstosearchbackwardsthroughthehistorylist,
DIR >= 0 means to search forward. */ staticint
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 searchisbackwardsthroughpreviousentries,elsethroughsubsequent
entries. Returns 1 if the search was successful, 0 otherwise. */ staticint
noninc_dosearch (string, dir) char *string; int dir;
{ int oldpos, pos;
HIST_ENTRY *entry;
/* Clear the undo list, since reading the search string should create its ownundolist,andthewholelistwillendupbeingfreedwhenwe
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;
/* Process just-read character C according to search context CXT. Return -1 ifthecallershouldabortthesearch,0ifweshouldbreakoutofthe
loop, and 1 if we should continue to read characters. */ staticint
_rl_nsearch_dispatch (cxt, c)
_rl_search_cxt *cxt; int c;
{ switch (c)
{ case CTRL('W'):
rl_unix_word_rubout (1, c); break;
case CTRL('U'):
rl_unix_line_discard (1, c); break;
caseRETURN: case NEWLINE: return0;
case CTRL('H'): case RUBOUT: if (rl_point == 0)
{
_rl_nsearch_abort (cxt); return -1;
}
_rl_rubout_char (1, c); break;
case CTRL('C'): case CTRL('G'):
rl_ding ();
_rl_nsearch_abort (cxt); return -1;
/* Perform one search according to CXT, using NONINC_SEARCH_STRING. Return -1ifthesearchshouldbeaborted,anyothervaluemeanstocleanup using_rl_nsearch_cleanup().Returns1ifthesearchwassuccessful,
0 otherwise. */ staticint
_rl_nsearch_dosearch (cxt)
_rl_search_cxt *cxt;
{
rl_mark = cxt->save_mark;
/* If rl_point == 0, we want to re-use the previous search string and startfromthesavedhistoryposition.Ifthere'snoprevioussearch
string, punt. */ if (rl_point == 0)
{ if (noninc_search_string == 0)
{
rl_ding ();
rl_restore_prompt ();
RL_UNSETSTATE (RL_STATE_NSEARCH); return -1;
}
} else
{ /* We want to start the search from the current history position. */
noninc_history_pos = cxt->save_line;
FREE (noninc_search_string);
noninc_search_string = savestring (rl_line_buffer);
/* If we don't want the subsequent undo list generated by the search matchingahistorylinetoincludethecontentsofthesearchstring, weneedtoclearrl_line_bufferhere.Fornow,wejustclearthe undolistgeneratedbyreadingthesearchstring.(Ifthesearch
fails, the old undo list will be restored by rl_maybe_unsave_line.) */
rl_free_undo_list ();
}
/* Search non-interactively through the history list. DIR < 0 means to searchbackwardsthroughthehistoryofpreviouscommands;otherwise thesearchisforcommandssubsequenttothecurrentpositioninthe historylist.PCHARisthecharactertouseforpromptingwhenreading
the search string; if not specified (0), it defaults to `:'. */ staticint
noninc_search (dir, pchar) int dir; int pchar;
{
_rl_search_cxt *cxt; int c, r;
cxt = _rl_nsearch_init (dir, pchar);
if (RL_ISSTATE (RL_STATE_CALLBACK)) return (0);
/* Read the search string. */
r = 0; while (1)
{
c = _rl_search_getchar (cxt);
if (c == 0) break;
r = _rl_nsearch_dispatch (cxt, c); if (r < 0) return1; elseif (r == 0) break;
}
/* Search forward through the history list for a string. If the vi-mode
code calls this, KEY will be `?'. */ int
rl_noninc_forward_search (count, key) int count __attribute__((unused)), key;
{ return noninc_search (1, (key == '?') ? '?' : 0);
}
/* Reverse search the history list for a string. If the vi-mode code
calls this, KEY will be `/'. */ int
rl_noninc_reverse_search (count, key) int count __attribute__((unused)), key;
{ return noninc_search (-1, (key == '/') ? '/' : 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 (count, key) int count __attribute__((unused)), key __attribute__((unused));
{ int r;
if (!noninc_search_string)
{
rl_ding (); return (-1);
}
r = noninc_dosearch (noninc_search_string, 1); return (r != 1);
}
/* 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 (count, key) int count __attribute__((unused)), key __attribute__((unused));
{ int r;
if (!noninc_search_string)
{
rl_ding (); return (-1);
}
r = noninc_dosearch (noninc_search_string, -1); return (r != 1);
}
#ifdefined (READLINE_CALLBACKS) int
_rl_nsearch_callback (cxt)
_rl_search_cxt *cxt;
{ int c, r;
c = _rl_search_getchar (cxt);
r = _rl_nsearch_dispatch (cxt, c); if (r != 0) return1;
staticint
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 matcheshistory_search_string.Whenthisloopfinishes,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 inthelinebufferafterthesearchfails,changethe#if0to
#if 1 */ #if0 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 return1;
}
/* Copy the line we found into the current line buffer. */
make_history_line_current (temp);
/* Search forward in the history for the string of characters fromthestartofthelinetorl_point.Thisisanon-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 ();
/* Search backward through the history for the string of characters fromthestartofthelinetorl_point.Thisisanon-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 ();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.