]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - lib/readline/isearch.c
Imported from ../bash-2.05.tar.gz.
[thirdparty/bash.git] / lib / readline / isearch.c
index 952c10ddf8eab91c65649f8200d5d4d0c8b7104b..f8d76951b014dd743df3acc7e33d016d0f78472d 100644 (file)
@@ -55,7 +55,7 @@
 unsigned char *_rl_isearch_terminators = (unsigned char *)NULL;
 
 /* Variables imported from other files in the readline library. */
-extern HIST_ENTRY *saved_line_for_history;
+extern HIST_ENTRY *_rl_saved_line_for_history;
 
 /* Forward declarations */
 static int rl_search_history __P((int, int));
@@ -64,6 +64,8 @@ static int rl_search_history __P((int, int));
    identical lines many times in a row. */
 static char *prev_line_found;
 
+static unsigned char *default_isearch_terminators = "\033\012";
+
 /* Search backwards through the history looking for a string which is typed
    interactively.  Start with the current line. */
 int
@@ -176,6 +178,7 @@ rl_search_history (direction, invoking_key)
      been set, we use that value, otherwise we use ESC and C-J. */
   unsigned char *isearch_terminators;
 
+  RL_SETSTATE(RL_STATE_ISEARCH);
   orig_point = rl_point;
   last_found_line = orig_line = where_history ();
   reverse = direction < 0;
@@ -183,10 +186,10 @@ rl_search_history (direction, invoking_key)
   allocated_line = (char *)NULL;
 
   isearch_terminators = _rl_isearch_terminators ? _rl_isearch_terminators
-                                               : (unsigned char *)"\033\012";
+                                               : default_isearch_terminators;
 
   /* Create an arrary of pointers to the lines that we want to search. */
-  maybe_replace_line ();
+  rl_maybe_replace_line ();
   i = 0;
   if (hlist)
     for (i = 0; hlist[i]; i++);
@@ -197,8 +200,8 @@ rl_search_history (direction, invoking_key)
   for (i = 0; i < hlen; i++)
     lines[i] = hlist[i]->line;
 
-  if (saved_line_for_history)
-    lines[i] = saved_line_for_history->line;
+  if (_rl_saved_line_for_history)
+    lines[i] = _rl_saved_line_for_history->line;
   else
     {
       /* Keep track of this so we can free it. */
@@ -232,10 +235,12 @@ rl_search_history (direction, invoking_key)
   found = failed = 0;
   for (;;)
     {
-      Function *f = (Function *)NULL;
+      rl_command_func_t *f = (rl_command_func_t *)NULL;
 
       /* Read a key and decide how to proceed. */
+      RL_SETSTATE(RL_STATE_MOREINPUT);
       c = rl_read_key ();
+      RL_UNSETSTATE(RL_STATE_MOREINPUT);
 
       if (_rl_keymap[c].type == ISFUNC)
        {
@@ -273,6 +278,8 @@ rl_search_history (direction, invoking_key)
 
       if (c >= 0 && (CTRL_CHAR (c) || META_CHAR (c) || c == RUBOUT) && c != CTRL ('G'))
        {
+         /* This sets rl_pending_input to c; it will be picked up the next
+            time rl_read_key is called. */
          rl_execute_next (c);
          break;
        }
@@ -287,7 +294,7 @@ rl_search_history (direction, invoking_key)
          else if (line_index != sline_len)
            ++line_index;
          else
-           ding ();
+           rl_ding ();
          break;
 
          /* switch directions */
@@ -305,13 +312,14 @@ rl_search_history (direction, invoking_key)
          if (allocated_line)
            free (allocated_line);
          free (lines);
+         RL_UNSETSTATE(RL_STATE_ISEARCH);
          return 0;
 
 #if 0
        /* delete character from search string. */
        case -3:
          if (search_string_index == 0)
-           ding ();
+           rl_ding ();
          else
            {
              search_string[--search_string_index] = '\0';
@@ -384,7 +392,7 @@ rl_search_history (direction, invoking_key)
       if (failed)
        {
          /* We cannot find the search string.  Ding the bell. */
-         ding ();
+         rl_ding ();
          i = last_found_line;
          continue;             /* XXX - was break */
        }
@@ -438,5 +446,7 @@ rl_search_history (direction, invoking_key)
     free (allocated_line);
   free (lines);
 
+  RL_UNSETSTATE(RL_STATE_ISEARCH);
+
   return 0;
 }