Imported from ../bash-2.05b.tar.gz.
[platform/upstream/bash.git] / lib / readline / search.c
index 9c2feb1..7e0d60b 100644 (file)
@@ -40,6 +40,8 @@
 #endif
 
 #include "rldefs.h"
+#include "rlmbutil.h"
+
 #include "readline.h"
 #include "history.h"
 
@@ -80,15 +82,8 @@ static void
 make_history_line_current (entry)
      HIST_ENTRY *entry;
 {
-  int line_len;
-
-  line_len = strlen (entry->line);
-  if (line_len >= rl_line_buffer_len)
-    rl_extend_line_buffer (line_len);
-  strcpy (rl_line_buffer, entry->line);
-
+  rl_replace_line (entry->line, 0);
   rl_undo_list = (UNDO_LIST *)entry->data;
-  rl_end = line_len;
 
   if (_rl_saved_line_for_history)
     _rl_free_history_entry (_rl_saved_line_for_history);
@@ -169,6 +164,8 @@ noninc_dosearch (string, dir)
   make_history_line_current (entry);
 
   rl_point = 0;
+  rl_mark = rl_end;
+
   rl_clear_message ();
 }
 
@@ -182,11 +179,15 @@ noninc_search (dir, pchar)
      int dir;
      int pchar;
 {
-  int saved_point, c;
+  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;
 
   /* Use the line buffer to read the search string. */
   rl_line_buffer[0] = 0;
@@ -206,6 +207,11 @@ noninc_search (dir, pchar)
       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;
 
@@ -218,9 +224,10 @@ noninc_search (dir, pchar)
              rl_maybe_unsave_line ();
              rl_clear_message ();
              rl_point = saved_point;
+             rl_mark = saved_mark;
              SEARCH_RETURN;
            }
-         rl_rubout (1, c);
+         _rl_rubout_char (1, c);
          break;
 
        case CTRL('W'):
@@ -242,17 +249,25 @@ noninc_search (dir, pchar)
          rl_maybe_unsave_line ();
          rl_clear_message ();
          rl_point = saved_point;
+         rl_mark = saved_mark;
          rl_ding ();
          SEARCH_RETURN;
 
        default:
-         rl_insert (1, c);
+#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. */
@@ -373,9 +388,11 @@ rl_history_search_internal (count, dir)
         {
           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;
     }
@@ -384,6 +401,8 @@ rl_history_search_internal (count, dir)
   make_history_line_current (temp);
 
   rl_point = rl_history_search_len;
+  rl_mark = rl_end;
+
   return 0;
 }