This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / readline / text.c
index 9053e96903bb1c7bb78323a42c80a35061042a14..2a7b724f48126f3cac71b4cd00132458a8e2ba18 100644 (file)
@@ -1,6 +1,6 @@
 /* text.c -- text handling commands for readline. */
 
-/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
 
    This file is part of the GNU Readline Library, a library for
    reading lines of text with interactive input and history editing.
 static int rl_change_case PARAMS((int, int));
 static int _rl_char_search PARAMS((int, int, int));
 
-#if defined (READLINE_CALLBACKS)
-static int _rl_insert_next_callback PARAMS((_rl_callback_generic_arg *));
-static int _rl_char_search_callback PARAMS((_rl_callback_generic_arg *));
-#endif
-
 /* **************************************************************** */
 /*                                                                 */
 /*                     Insert and Delete                           */
@@ -175,9 +170,6 @@ _rl_fix_point (fix_mark_too)
 }
 #undef _RL_FIX_POINT
 
-/* Replace the contents of the line buffer between START and END with
-   TEXT.  The operation is undoable.  To replace the entire line in an
-   undoable mode, use _rl_replace_text(text, 0, rl_end); */
 int
 _rl_replace_text (text, start, end)
      const char *text;
@@ -425,7 +417,8 @@ rl_end_of_line (count, key)
   return 0;
 }
 
-/* Move forward a word.  We do what Emacs does.  Handles multibyte chars. */
+/* XXX - these might need changes for multibyte characters */
+/* Move forward a word.  We do what Emacs does. */
 int
 rl_forward_word (count, key)
      int count, key;
@@ -442,80 +435,68 @@ rl_forward_word (count, key)
 
       /* If we are not in a word, move forward until we are in one.
         Then, move forward until we hit a non-alphabetic character. */
-      c = _rl_char_value (rl_line_buffer, rl_point);
-
-      if (_rl_walphabetic (c) == 0)
+      c = rl_line_buffer[rl_point];
+      if (rl_alphabetic (c) == 0)
        {
-         rl_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
-         while (rl_point < rl_end)
+         while (++rl_point < rl_end)
            {
-             c = _rl_char_value (rl_line_buffer, rl_point);
-             if (_rl_walphabetic (c))
+             c = rl_line_buffer[rl_point];
+             if (rl_alphabetic (c))
                break;
-             rl_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
            }
        }
 
       if (rl_point == rl_end)
        return 0;
 
-      rl_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
-      while (rl_point < rl_end)
+      while (++rl_point < rl_end)
        {
-         c = _rl_char_value (rl_line_buffer, rl_point);
-         if (_rl_walphabetic (c) == 0)
+         c = rl_line_buffer[rl_point];
+         if (rl_alphabetic (c) == 0)
            break;
-         rl_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
        }
-
       --count;
     }
 
   return 0;
 }
 
-/* Move backward a word.  We do what Emacs does.  Handles multibyte chars. */
+/* Move backward a word.  We do what Emacs does. */
 int
 rl_backward_word (count, key)
      int count, key;
 {
-  int c, p;
+  int c;
 
   if (count < 0)
     return (rl_forward_word (-count, key));
 
   while (count)
     {
-      if (rl_point == 0)
+      if (!rl_point)
        return 0;
 
       /* Like rl_forward_word (), except that we look at the characters
         just before point. */
 
-      p = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO);
-      c = _rl_char_value (rl_line_buffer, p);
-
-      if (_rl_walphabetic (c) == 0)
+      c = rl_line_buffer[rl_point - 1];
+      if (rl_alphabetic (c) == 0)
        {
-         rl_point = p;
-         while (rl_point > 0)
+         while (--rl_point)
            {
-             p = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO);
-             c = _rl_char_value (rl_line_buffer, p);
-             if (_rl_walphabetic (c))
+             c = rl_line_buffer[rl_point - 1];
+             if (rl_alphabetic (c))
                break;
-             rl_point = p;
            }
        }
 
       while (rl_point)
        {
-         p = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO);
-         c = _rl_char_value (rl_line_buffer, p);         
-         if (_rl_walphabetic (c) == 0)
+         c = rl_line_buffer[rl_point - 1];
+         if (rl_alphabetic (c) == 0)
            break;
          else
-           rl_point = p;
+           --rl_point;
        }
 
       --count;
@@ -772,8 +753,10 @@ _rl_insert_char (count, c)
       return 0;
     }
 
+#if defined (HANDLE_MULTIBYTE)
   if (MB_CUR_MAX == 1 || rl_byte_oriented)
     {
+#endif
       /* We are inserting a single character.
         If there is pending input, then make a string of all of the
         pending characters that are bound to rl_insert, and insert
@@ -789,8 +772,8 @@ _rl_insert_char (count, c)
          str[0] = c;
          rl_insert_text (str);
        }
-    }
 #if defined (HANDLE_MULTIBYTE)
+    }
   else
     {
       rl_insert_text (incoming);
@@ -818,10 +801,13 @@ _rl_overwrite_char (count, c)
     k = _rl_read_mbstring (c, mbkey, MB_LEN_MAX);
 #endif
 
-  rl_begin_undo_group ();
-
   for (i = 0; i < count; i++)
     {
+      rl_begin_undo_group ();
+
+      if (rl_point < rl_end)
+       rl_delete (1, c);
+
 #if defined (HANDLE_MULTIBYTE)
       if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
        rl_insert_text (mbkey);
@@ -829,12 +815,9 @@ _rl_overwrite_char (count, c)
 #endif
        _rl_insert_char (1, c);
 
-      if (rl_point < rl_end)
-       rl_delete (1, c);
+      rl_end_undo_group ();
     }
 
-  rl_end_undo_group ();
-
   return 0;
 }
 
@@ -847,63 +830,27 @@ rl_insert (count, c)
 }
 
 /* Insert the next typed character verbatim. */
-static int
-_rl_insert_next (count)
-     int count;
+int
+rl_quoted_insert (count, key)
+     int count, key;
 {
   int c;
 
+#if defined (HANDLE_SIGNALS)
+  _rl_disable_tty_signals ();
+#endif
+
   RL_SETSTATE(RL_STATE_MOREINPUT);
   c = rl_read_key ();
   RL_UNSETSTATE(RL_STATE_MOREINPUT);
 
 #if defined (HANDLE_SIGNALS)
-  if (RL_ISSTATE (RL_STATE_CALLBACK) == 0)
-    _rl_restore_tty_signals ();
+  _rl_restore_tty_signals ();
 #endif
 
   return (_rl_insert_char (count, c));  
 }
 
-#if defined (READLINE_CALLBACKS)
-static int
-_rl_insert_next_callback (data)
-     _rl_callback_generic_arg *data;
-{
-  int count;
-
-  count = data->count;
-
-  /* Deregister function, let rl_callback_read_char deallocate data */
-  _rl_callback_func = 0;
-  _rl_want_redisplay = 1;
-  return _rl_insert_next (count);
-}
-#endif
-  
-int
-rl_quoted_insert (count, key)
-     int count, key;
-{
-  /* Let's see...should the callback interface futz with signal handling? */
-#if defined (HANDLE_SIGNALS)
-  if (RL_ISSTATE (RL_STATE_CALLBACK) == 0)
-    _rl_disable_tty_signals ();
-#endif
-
-#if defined (READLINE_CALLBACKS)
-  if (RL_ISSTATE (RL_STATE_CALLBACK))
-    {
-      _rl_callback_data = _rl_callback_data_alloc (count);
-      _rl_callback_func = _rl_insert_next_callback;
-      return (0);
-    }
-#endif
-      
-  return _rl_insert_next (count);
-}
-
 /* Insert a tab character. */
 int
 rl_tab_insert (count, key)
@@ -930,8 +877,7 @@ rl_newline (count, key)
   if (rl_editing_mode == vi_mode)
     {
       _rl_vi_done_inserting ();
-      if (_rl_vi_textmod_command (_rl_vi_last_command) == 0)   /* XXX */
-       _rl_vi_reset_last ();
+      _rl_vi_reset_last ();
     }
 #endif /* VI_MODE */
 
@@ -989,12 +935,9 @@ _rl_overwrite_rubout (count, key)
     rl_delete_text (opoint, rl_point);
 
   /* Emacs puts point at the beginning of the sequence of spaces. */
-  if (rl_point < rl_end)
-    {
-      opoint = rl_point;
-      _rl_insert_char (l, ' ');
-      rl_point = opoint;
-    }
+  opoint = rl_point;
+  _rl_insert_char (l, ' ');
+  rl_point = opoint;
 
   rl_end_undo_group ();
 
@@ -1038,17 +981,43 @@ _rl_rubout_char (count, key)
       return -1;
     }
 
-  orig_point = rl_point;
   if (count > 1 || rl_explicit_arg)
     {
-      rl_backward_char (count, key);
+      orig_point = rl_point;
+#if defined (HANDLE_MULTIBYTE)
+      if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
+       rl_backward_char (count, key);
+      else
+#endif
+        rl_backward_byte (count, key);
       rl_kill_text (orig_point, rl_point);
     }
-  else if (MB_CUR_MAX == 1 || rl_byte_oriented)
+  else
     {
-      c = rl_line_buffer[--rl_point];
-      rl_delete_text (rl_point, orig_point);
-      /* The erase-at-end-of-line hack is of questionable merit now. */
+#if defined (HANDLE_MULTIBYTE)
+      if (MB_CUR_MAX == 1 || rl_byte_oriented)
+       {
+#endif
+         c = rl_line_buffer[--rl_point];
+         rl_delete_text (rl_point, rl_point + 1);
+#if defined (HANDLE_MULTIBYTE)
+       }
+      else
+       {
+         int orig_point;
+
+         orig_point = rl_point;
+         rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO);
+         c = rl_line_buffer[rl_point];
+         rl_delete_text (rl_point, orig_point);
+       }
+#endif /* HANDLE_MULTIBYTE */
+
+      /* I don't think that the hack for end of line is needed for
+        multibyte chars. */
+#if defined (HANDLE_MULTIBYTE)
+      if (MB_CUR_MAX == 1 || rl_byte_oriented)
+#endif
       if (rl_point == rl_end && ISPRINT (c) && _rl_last_c_pos)
        {
          int l;
@@ -1056,11 +1025,6 @@ _rl_rubout_char (count, key)
          _rl_erase_at_end_of_line (l);
        }
     }
-  else
-    {
-      rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO);
-      rl_delete_text (rl_point, orig_point);
-    }
 
   return 0;
 }
@@ -1085,9 +1049,11 @@ rl_delete (count, key)
   if (count > 1 || rl_explicit_arg)
     {
       int orig_point = rl_point;
+#if defined (HANDLE_MULTIBYTE)
       if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
        rl_forward_char (count, key);
       else
+#endif
        rl_forward_byte (count, key);
 
       r = rl_kill_text (orig_point, rl_point);
@@ -1097,8 +1063,11 @@ rl_delete (count, key)
   else
     {
       int new_point;
-
-      new_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
+      if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
+       new_point = _rl_find_next_mbchar (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
+      else
+       new_point = rl_point + 1;
+       
       return (rl_delete_text (rl_point, new_point));
     }
 }
@@ -1137,10 +1106,6 @@ rl_delete_horizontal_space (count, ignore)
       rl_delete_text (start, rl_point);
       rl_point = start;
     }
-
-  if (rl_point < 0)
-    rl_point = 0;
-
   return 0;
 }
 
@@ -1234,80 +1199,42 @@ static int
 rl_change_case (count, op)
      int count, op;
 {
-  int start, next, end;
-  int inword, c, nc, nop;
-#if defined (HANDLE_MULTIBYTE)
-  wchar_t wc, nwc;
-  char mb[MB_LEN_MAX+1];
-  int mblen, p;
-  mbstate_t ps;
-#endif
+  register int start, end;
+  int inword, c;
 
   start = rl_point;
   rl_forward_word (count, 0);
   end = rl_point;
 
-  if (op != UpCase && op != DownCase && op != CapCase)
-    {
-      rl_ding ();
-      return -1;
-    }
-
   if (count < 0)
     SWAP (start, end);
 
-#if defined (HANDLE_MULTIBYTE)
-  memset (&ps, 0, sizeof (mbstate_t));
-#endif
-
   /* We are going to modify some text, so let's prepare to undo it. */
   rl_modifying (start, end);
 
-  inword = 0;
-  while (start < end)
+  for (inword = 0; start < end; start++)
     {
-      c = _rl_char_value (rl_line_buffer, start);
-      /*  This assumes that the upper and lower case versions are the same width. */
-      next = MB_NEXTCHAR (rl_line_buffer, start, 1, MB_FIND_NONZERO);
-
-      if (_rl_walphabetic (c) == 0)
+      c = rl_line_buffer[start];
+      switch (op)
        {
-         inword = 0;
-         start = next;
-         continue;
-       }
+       case UpCase:
+         rl_line_buffer[start] = _rl_to_upper (c);
+         break;
 
-      if (op == CapCase)
-       {
-         nop = inword ? DownCase : UpCase;
-         inword = 1;
-       }
-      else
-       nop = op;
-      if (MB_CUR_MAX == 1 || rl_byte_oriented || isascii (c))
-       {
-         nc = (nop == UpCase) ? _rl_to_upper (c) : _rl_to_lower (c);
-         rl_line_buffer[start] = nc;
-       }
-#if defined (HANDLE_MULTIBYTE)
-      else
-       {
-         mbrtowc (&wc, rl_line_buffer + start, end - start, &ps);
-         nwc = (nop == UpCase) ? _rl_to_wupper (wc) : _rl_to_wlower (wc);
-         if  (nwc != wc)       /*  just skip unchanged characters */
-           {
-             mblen = wcrtomb (mb, nwc, &ps);
-             if (mblen > 0)
-               mb[mblen] = '\0';
-             /* Assume the same width */
-             strncpy (rl_line_buffer + start, mb, mblen);
-           }
-       }
-#endif
+       case DownCase:
+         rl_line_buffer[start] = _rl_to_lower (c);
+         break;
 
-      start = next;
-    }
+       case CapCase:
+         rl_line_buffer[start] = (inword == 0) ? _rl_to_upper (c) : _rl_to_lower (c);
+         inword = rl_alphabetic (rl_line_buffer[start]);
+         break;
 
+       default:
+         rl_ding ();
+         return -1;
+       }
+    }
   rl_point = end;
   return 0;
 }
@@ -1387,11 +1314,11 @@ rl_transpose_chars (count, key)
 {
 #if defined (HANDLE_MULTIBYTE)
   char *dummy;
-  int i;
+  int i, prev_point;
 #else
   char dummy[2];
 #endif
-  int char_length, prev_point;
+  int char_length;
 
   if (count == 0)
     return 0;
@@ -1406,12 +1333,20 @@ rl_transpose_chars (count, key)
 
   if (rl_point == rl_end)
     {
-      rl_point = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO);
+      if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
+       rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO);
+      else
+       --rl_point;
       count = 1;
     }
 
+#if defined (HANDLE_MULTIBYTE)
   prev_point = rl_point;
-  rl_point = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO);
+  if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
+    rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO);
+  else
+#endif
+    rl_point--;
 
 #if defined (HANDLE_MULTIBYTE)
   char_length = prev_point - rl_point;
@@ -1545,33 +1480,10 @@ _rl_char_search (count, fdir, bdir)
 }
 #endif /* !HANDLE_MULTIBYTE */
 
-#if defined (READLINE_CALLBACKS)
-static int
-_rl_char_search_callback (data)
-     _rl_callback_generic_arg *data;
-{
-  _rl_callback_func = 0;
-  _rl_want_redisplay = 1;
-
-  return (_rl_char_search (data->count, data->i1, data->i2));
-}
-#endif
-
 int
 rl_char_search (count, key)
      int count, key;
 {
-#if defined (READLINE_CALLBACKS)
-  if (RL_ISSTATE (RL_STATE_CALLBACK))
-    {
-      _rl_callback_data = _rl_callback_data_alloc (count);
-      _rl_callback_data->i1 = FFIND;
-      _rl_callback_data->i2 = BFIND;
-      _rl_callback_func = _rl_char_search_callback;
-      return (0);
-    }
-#endif
-  
   return (_rl_char_search (count, FFIND, BFIND));
 }
 
@@ -1579,17 +1491,6 @@ int
 rl_backward_char_search (count, key)
      int count, key;
 {
-#if defined (READLINE_CALLBACKS)
-  if (RL_ISSTATE (RL_STATE_CALLBACK))
-    {
-      _rl_callback_data = _rl_callback_data_alloc (count);
-      _rl_callback_data->i1 = BFIND;
-      _rl_callback_data->i2 = FFIND;
-      _rl_callback_func = _rl_char_search_callback;
-      return (0);
-    }
-#endif
-
   return (_rl_char_search (count, BFIND, FFIND));
 }
 
This page took 0.030258 seconds and 4 git commands to generate.