Diff for /embedaddon/readline/text.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2014/07/30 08:16:45 version 1.1.1.2, 2021/03/17 01:01:01
Line 1 Line 1
 /* text.c -- text handling commands for readline. */  /* text.c -- text handling commands for readline. */
   
/* Copyright (C) 1987-2010 Free Software Foundation, Inc./* Copyright (C) 1987-2020 Free Software Foundation, Inc.
   
    This file is part of the GNU Readline Library (Readline), a library     This file is part of the GNU Readline Library (Readline), a library
    for reading lines of text with interactive input and history editing.           for reading lines of text with interactive input and history editing.      
Line 71  static int _rl_char_search_callback PARAMS((_rl_callba Line 71  static int _rl_char_search_callback PARAMS((_rl_callba
    rl_insert_text.  Text blocks larger than this are divided. */     rl_insert_text.  Text blocks larger than this are divided. */
 #define TEXT_COUNT_MAX  1024  #define TEXT_COUNT_MAX  1024
   
   int _rl_optimize_typeahead = 1; /* rl_insert tries to read typeahead */
   
 /* **************************************************************** */  /* **************************************************************** */
 /*                                                                  */  /*                                                                  */
 /*                      Insert and Delete                           */  /*                      Insert and Delete                           */
Line 81  static int _rl_char_search_callback PARAMS((_rl_callba Line 83  static int _rl_char_search_callback PARAMS((_rl_callba
    way that you should do insertion.  _rl_insert_char () calls this     way that you should do insertion.  _rl_insert_char () calls this
    function.  Returns the number of characters inserted. */     function.  Returns the number of characters inserted. */
 int  int
rl_insert_text (string)rl_insert_text (const char *string)
     const char *string; 
 {  {
   register int i, l;    register int i, l;
   
Line 119  rl_insert_text (string) Line 120  rl_insert_text (string)
 /* Delete the string between FROM and TO.  FROM is inclusive, TO is not.  /* Delete the string between FROM and TO.  FROM is inclusive, TO is not.
    Returns the number of characters deleted. */     Returns the number of characters deleted. */
 int  int
rl_delete_text (from, to)rl_delete_text (int from, int to)
     int from, to; 
 {  {
   register char *text;    register char *text;
   register int diff, i;    register int diff, i;
Line 154  rl_delete_text (from, to) Line 154  rl_delete_text (from, to)
   
   rl_end -= diff;    rl_end -= diff;
   rl_line_buffer[rl_end] = '\0';    rl_line_buffer[rl_end] = '\0';
     _rl_fix_mark ();
   return (diff);    return (diff);
 }  }
   
Line 170  rl_delete_text (from, to) Line 171  rl_delete_text (from, to)
         } while (0)          } while (0)
   
 void  void
_rl_fix_point (fix_mark_too)_rl_fix_point (int fix_mark_too)
     int fix_mark_too; 
 {  {
   _RL_FIX_POINT (rl_point);    _RL_FIX_POINT (rl_point);
   if (fix_mark_too)    if (fix_mark_too)
     _RL_FIX_POINT (rl_mark);      _RL_FIX_POINT (rl_mark);
 }  }
   
   void
   _rl_fix_mark (void)
   {
     _RL_FIX_POINT (rl_mark);
   }
 #undef _RL_FIX_POINT  #undef _RL_FIX_POINT
   
 /* Replace the contents of the line buffer between START and END with  /* Replace the contents of the line buffer between START and END with
    TEXT.  The operation is undoable.  To replace the entire line in an     TEXT.  The operation is undoable.  To replace the entire line in an
    undoable mode, use _rl_replace_text(text, 0, rl_end); */     undoable mode, use _rl_replace_text(text, 0, rl_end); */
 int  int
_rl_replace_text (text, start, end)_rl_replace_text (const char *text, int start, int end)
     const char *text; 
     int start, end; 
 {  {
   int n;    int n;
   
Line 204  _rl_replace_text (text, start, end) Line 208  _rl_replace_text (text, start, end)
 /* Replace the current line buffer contents with TEXT.  If CLEAR_UNDO is  /* Replace the current line buffer contents with TEXT.  If CLEAR_UNDO is
    non-zero, we free the current undo list. */     non-zero, we free the current undo list. */
 void  void
rl_replace_line (text, clear_undo)rl_replace_line (const char *text, int clear_undo)
     const char *text; 
     int clear_undo; 
 {  {
   int len;    int len;
   
Line 257  rl_replace_line (text, clear_undo) Line 259  rl_replace_line (text, clear_undo)
   
 /* Move forward COUNT bytes. */  /* Move forward COUNT bytes. */
 int  int
rl_forward_byte (count, key)rl_forward_byte (int count, int key)
     int count, key; 
 {  {
   if (count < 0)    if (count < 0)
     return (rl_backward_byte (-count, key));      return (rl_backward_byte (-count, key));
Line 290  rl_forward_byte (count, key) Line 291  rl_forward_byte (count, key)
 }  }
   
 int  int
_rl_forward_char_internal (count)_rl_forward_char_internal (int count)
     int count; 
 {  {
   int point;    int point;
   
Line 304  _rl_forward_char_internal (count) Line 304  _rl_forward_char_internal (count)
 #endif  #endif
   
     if (rl_end < 0)      if (rl_end < 0)
        rl_end = 0;      rl_end = 0;
 #else  #else
   point = rl_point + count;    point = rl_point + count;
   #endif
   
   if (point > rl_end)    if (point > rl_end)
     point = rl_end;      point = rl_end;
     return (point);
   }
   
   int
   _rl_backward_char_internal (int count)
   {
     int point;
   
     point = rl_point;
   #if defined (HANDLE_MULTIBYTE)
     if (count > 0)
       {
         while (count > 0 && point > 0)
           {
             point = _rl_find_prev_mbchar (rl_line_buffer, point, MB_FIND_NONZERO);
             count--;
           }
         if (count > 0)
           return 0;       /* XXX - rl_ding() here? */
       }
   #else
     if (count > 0)
       point -= count;
 #endif  #endif
   
     if (point < 0)
       point = 0;
   return (point);    return (point);
 }  }
   
 #if defined (HANDLE_MULTIBYTE)  #if defined (HANDLE_MULTIBYTE)
 /* Move forward COUNT characters. */  /* Move forward COUNT characters. */
 int  int
rl_forward_char (count, key)rl_forward_char (int count, int key)
     int count, key; 
 {  {
   int point;    int point;
   
Line 348  rl_forward_char (count, key) Line 374  rl_forward_char (count, key)
 }  }
 #else /* !HANDLE_MULTIBYTE */  #else /* !HANDLE_MULTIBYTE */
 int  int
rl_forward_char (count, key)rl_forward_char (int count, int key)
     int count, key; 
 {  {
   return (rl_forward_byte (count, key));    return (rl_forward_byte (count, key));
 }  }
Line 357  rl_forward_char (count, key) Line 382  rl_forward_char (count, key)
       
 /* Backwards compatibility. */  /* Backwards compatibility. */
 int  int
rl_forward (count, key)rl_forward (int count, int key)
     int count, key; 
 {  {
   return (rl_forward_char (count, key));    return (rl_forward_char (count, key));
 }  }
   
 /* Move backward COUNT bytes. */  /* Move backward COUNT bytes. */
 int  int
rl_backward_byte (count, key)rl_backward_byte (int count, int key)
     int count, key; 
 {  {
   if (count < 0)    if (count < 0)
     return (rl_forward_byte (-count, key));      return (rl_forward_byte (-count, key));
Line 391  rl_backward_byte (count, key) Line 414  rl_backward_byte (count, key)
 #if defined (HANDLE_MULTIBYTE)  #if defined (HANDLE_MULTIBYTE)
 /* Move backward COUNT characters. */  /* Move backward COUNT characters. */
 int  int
rl_backward_char (count, key)rl_backward_char (int count, int key)
     int count, key; 
 {  {
   int point;    int point;
   
Line 424  rl_backward_char (count, key) Line 446  rl_backward_char (count, key)
 }  }
 #else  #else
 int  int
rl_backward_char (count, key)rl_backward_char (int count, int key)
     int count, key; 
 {  {
   return (rl_backward_byte (count, key));    return (rl_backward_byte (count, key));
 }  }
Line 433  rl_backward_char (count, key) Line 454  rl_backward_char (count, key)
   
 /* Backwards compatibility. */  /* Backwards compatibility. */
 int  int
rl_backward (count, key)rl_backward (int count, int key)
     int count, key; 
 {  {
   return (rl_backward_char (count, key));    return (rl_backward_char (count, key));
 }  }
   
 /* Move to the beginning of the line. */  /* Move to the beginning of the line. */
 int  int
rl_beg_of_line (count, key)rl_beg_of_line (int count, int key)
     int count, key; 
 {  {
   rl_point = 0;    rl_point = 0;
   return 0;    return 0;
Line 450  rl_beg_of_line (count, key) Line 469  rl_beg_of_line (count, key)
   
 /* Move to the end of the line. */  /* Move to the end of the line. */
 int  int
rl_end_of_line (count, key)rl_end_of_line (int count, int key)
     int count, key; 
 {  {
   rl_point = rl_end;    rl_point = rl_end;
   return 0;    return 0;
Line 459  rl_end_of_line (count, key) Line 477  rl_end_of_line (count, key)
   
 /* Move forward a word.  We do what Emacs does.  Handles multibyte chars. */  /* Move forward a word.  We do what Emacs does.  Handles multibyte chars. */
 int  int
rl_forward_word (count, key)rl_forward_word (int count, int key)
     int count, key; 
 {  {
   int c;    int c;
   
Line 469  rl_forward_word (count, key) Line 486  rl_forward_word (count, key)
   
   while (count)    while (count)
     {      {
         if (rl_point > rl_end)
           rl_point = rl_end;
       if (rl_point == rl_end)        if (rl_point == rl_end)
         return 0;          return 0;
   
Line 488  rl_forward_word (count, key) Line 507  rl_forward_word (count, key)
             }              }
         }          }
   
         if (rl_point > rl_end)
           rl_point = rl_end;
       if (rl_point == rl_end)        if (rl_point == rl_end)
         return 0;          return 0;
   
Line 508  rl_forward_word (count, key) Line 529  rl_forward_word (count, key)
   
 /* Move backward a word.  We do what Emacs does.  Handles multibyte chars. */  /* Move backward a word.  We do what Emacs does.  Handles multibyte chars. */
 int  int
rl_backward_word (count, key)rl_backward_word (int count, int key)
     int count, key; 
 {  {
   int c, p;    int c, p;
   
Line 558  rl_backward_word (count, key) Line 578  rl_backward_word (count, key)
   
 /* Clear the current line.  Numeric argument to C-l does this. */  /* Clear the current line.  Numeric argument to C-l does this. */
 int  int
rl_refresh_line (ignore1, ignore2)rl_refresh_line (int ignore1, int ignore2)
     int ignore1, ignore2; 
 {  {
  int curr_line;  _rl_refresh_line ();
 
  curr_line = _rl_current_display_line (); 
 
  _rl_move_vert (curr_line); 
  _rl_move_cursor_relative (0, rl_line_buffer);   /* XXX is this right */ 
 
  _rl_clear_to_eol (0);         /* arg of 0 means to not use spaces */ 
 
  rl_forced_update_display (); 
   rl_display_fixed = 1;    rl_display_fixed = 1;
   
   return 0;    return 0;
 }  }
   
Line 580  rl_refresh_line (ignore1, ignore2) Line 589  rl_refresh_line (ignore1, ignore2)
    the prompt and the current input line.  Given a numeric arg, redraw only     the prompt and the current input line.  Given a numeric arg, redraw only
    the current line. */     the current line. */
 int  int
rl_clear_screen (count, key)rl_clear_screen (int count, int key)
     int count, key; 
 {  {
   if (rl_explicit_arg)    if (rl_explicit_arg)
     {      {
Line 589  rl_clear_screen (count, key) Line 597  rl_clear_screen (count, key)
       return 0;        return 0;
     }      }
   
  _rl_clear_screen ();              /* calls termcap function to clear screen */  _rl_clear_screen (0);              /* calls termcap function to clear screen */
   rl_keep_mark_active ();
   rl_forced_update_display ();    rl_forced_update_display ();
   rl_display_fixed = 1;    rl_display_fixed = 1;
   
Line 597  rl_clear_screen (count, key) Line 606  rl_clear_screen (count, key)
 }  }
   
 int  int
rl_skip_csi_sequence (count, key)rl_clear_display (int count, int key)
     int count, key; 
 {  {
     _rl_clear_screen (1);         /* calls termcap function to clear screen and scrollback buffer */
     rl_forced_update_display ();
     rl_display_fixed = 1;
   
     return 0;
   }
   
   int
   rl_previous_screen_line (int count, int key)
   {
     int c;
   
     c = _rl_term_autowrap ? _rl_screenwidth : (_rl_screenwidth + 1);
     return (rl_backward_char (c, key));
   }
   
   int
   rl_next_screen_line (int count, int key)
   {
     int c;
   
     c = _rl_term_autowrap ? _rl_screenwidth : (_rl_screenwidth + 1);
     return (rl_forward_char (c, key));
   }
   
   int
   rl_skip_csi_sequence (int count, int key)
   {
   int ch;    int ch;
   
   RL_SETSTATE (RL_STATE_MOREINPUT);    RL_SETSTATE (RL_STATE_MOREINPUT);
Line 608  rl_skip_csi_sequence (count, key) Line 644  rl_skip_csi_sequence (count, key)
   while (ch >= 0x20 && ch < 0x40);    while (ch >= 0x20 && ch < 0x40);
   RL_UNSETSTATE (RL_STATE_MOREINPUT);    RL_UNSETSTATE (RL_STATE_MOREINPUT);
   
  return 0;  return (ch < 0);
 }  }
   
 int  int
rl_arrow_keys (count, c)rl_arrow_keys (int count, int key)
     int count, c; 
 {  {
   int ch;    int ch;
   
   RL_SETSTATE(RL_STATE_MOREINPUT);    RL_SETSTATE(RL_STATE_MOREINPUT);
   ch = rl_read_key ();    ch = rl_read_key ();
   RL_UNSETSTATE(RL_STATE_MOREINPUT);    RL_UNSETSTATE(RL_STATE_MOREINPUT);
     if (ch < 0)
       return (1);
   
   switch (_rl_to_upper (ch))    switch (_rl_to_upper (ch))
     {      {
Line 668  static mbstate_t ps = {0}; Line 705  static mbstate_t ps = {0};
    If C introduces a multibyte sequence, we read the whole sequence and     If C introduces a multibyte sequence, we read the whole sequence and
    then insert the multibyte char into the line buffer. */     then insert the multibyte char into the line buffer. */
 int  int
_rl_insert_char (count, c)_rl_insert_char (int count, int c)
     int count, c; 
 {  {
   register int i;    register int i;
   char *string;    char *string;
Line 691  _rl_insert_char (count, c) Line 727  _rl_insert_char (count, c)
       incoming[1] = '\0';        incoming[1] = '\0';
       incoming_length = 1;        incoming_length = 1;
     }      }
     else if (_rl_utf8locale && (c & 0x80) == 0)
       {
         incoming[0] = c;
         incoming[1] = '\0';
         incoming_length = 1;
       }
   else    else
     {      {
       wchar_t wc;        wchar_t wc;
Line 735  _rl_insert_char (count, c) Line 777  _rl_insert_char (count, c)
              effect of mbstate is undefined. */               effect of mbstate is undefined. */
           memset (&ps, 0, sizeof (mbstate_t));            memset (&ps, 0, sizeof (mbstate_t));
         }          }
         else if (ret == 1)
           {
             incoming[0] = pending_bytes[0];
             incoming[incoming_length = 1] = '\0';
             pending_bytes_length = 0;
           }
       else        else
         {          {
           /* We successfully read a single multibyte character. */            /* We successfully read a single multibyte character. */
Line 757  _rl_insert_char (count, c) Line 805  _rl_insert_char (count, c)
       i = 0;        i = 0;
       while (i < string_size)        while (i < string_size)
         {          {
          strncpy (string + i, incoming, incoming_length);          if (incoming_length == 1)
          i += incoming_length;            string[i++] = *incoming;
           else
             {
               strncpy (string + i, incoming, incoming_length);
               i += incoming_length;
             }
         }          }
       incoming_length = 0;        incoming_length = 0;
       stored_count = 0;        stored_count = 0;
Line 786  _rl_insert_char (count, c) Line 839  _rl_insert_char (count, c)
       i = 0;        i = 0;
       while (i < string_size)        while (i < string_size)
         {          {
          strncpy (string + i, incoming, incoming_length);          if (incoming_length == 1)
          i += incoming_length;            string[i++] = *incoming;
           else
             {
               strncpy (string + i, incoming, incoming_length);
               i += incoming_length;
             }
         }          }
   
       while (count)        while (count)
Line 853  _rl_insert_char (count, c) Line 911  _rl_insert_char (count, c)
    If C introduces a multibyte character sequence, read the entire sequence     If C introduces a multibyte character sequence, read the entire sequence
    before starting the overwrite loop. */     before starting the overwrite loop. */
 int  int
_rl_overwrite_char (count, c)_rl_overwrite_char (int count, int c)
     int count, c; 
 {  {
   int i;    int i;
 #if defined (HANDLE_MULTIBYTE)  #if defined (HANDLE_MULTIBYTE)
Line 887  _rl_overwrite_char (count, c) Line 944  _rl_overwrite_char (count, c)
 }  }
   
 int  int
rl_insert (count, c)rl_insert (int count, int c)
     int count, c; 
 {  {
  return (rl_insert_mode == RL_IM_INSERT ? _rl_insert_char (count, c)  int r, n, x;
                                         : _rl_overwrite_char (count, c));
   r = (rl_insert_mode == RL_IM_INSERT) ? _rl_insert_char (count, c) : _rl_overwrite_char (count, c);
 
   /* XXX -- attempt to batch-insert pending input that maps to self-insert */
   x = 0;
   n = (unsigned short)-2;
   while (_rl_optimize_typeahead &&
          rl_num_chars_to_read == 0 &&
          (RL_ISSTATE (RL_STATE_INPUTPENDING|RL_STATE_MACROINPUT) == 0) &&
          _rl_pushed_input_available () == 0 &&
          _rl_input_queued (0) &&
          (n = rl_read_key ()) > 0 &&
          _rl_keymap[(unsigned char)n].type == ISFUNC &&
          _rl_keymap[(unsigned char)n].function == rl_insert)
     {
       r = (rl_insert_mode == RL_IM_INSERT) ? _rl_insert_char (1, n) : _rl_overwrite_char (1, n);
       /* _rl_insert_char keeps its own set of pending characters to compose a
          complete multibyte character, and only returns 1 if it sees a character
          that's part of a multibyte character but too short to complete one.  We
          can try to read another character in the hopes that we will get the
          next one or just punt.  Right now we try to read another character.
          We don't want to call rl_insert_next if _rl_insert_char has already
          stored the character in the pending_bytes array because that will
          result in doubled input. */
       n = (unsigned short)-2;
       x++;              /* count of bytes of typeahead read, currently unused */
       if (r == 1)       /* read partial multibyte character */
         continue;
       if (rl_done || r != 0)
         break;
     }
 
   if (n != (unsigned short)-2)          /* -2 = sentinel value for having inserted N */
     {
       /* setting rl_pending_input inhibits setting rl_last_func so we do it
          ourselves here */
       rl_last_func = rl_insert; 
       _rl_reset_argument ();
       rl_executing_keyseq[rl_key_sequence_length = 0] = '\0';
       r = rl_execute_next (n);
     }
 
   return r;
 }  }
   
 /* Insert the next typed character verbatim. */  /* Insert the next typed character verbatim. */
 static int  static int
_rl_insert_next (count)_rl_insert_next (int count)
     int count; 
 {  {
   int c;    int c;
   
Line 906  _rl_insert_next (count) Line 1003  _rl_insert_next (count)
   RL_UNSETSTATE(RL_STATE_MOREINPUT);    RL_UNSETSTATE(RL_STATE_MOREINPUT);
   
   if (c < 0)    if (c < 0)
    return -1;    return 1;
   
   if (RL_ISSTATE (RL_STATE_MACRODEF))    if (RL_ISSTATE (RL_STATE_MACRODEF))
     _rl_add_macro_char (c);      _rl_add_macro_char (c);
Line 921  _rl_insert_next (count) Line 1018  _rl_insert_next (count)
   
 #if defined (READLINE_CALLBACKS)  #if defined (READLINE_CALLBACKS)
 static int  static int
_rl_insert_next_callback (data)_rl_insert_next_callback (_rl_callback_generic_arg *data)
     _rl_callback_generic_arg *data; 
 {  {
  int count;  int count, r;
   
   count = data->count;    count = data->count;
     r = 0;
   
     if (count < 0)
       {
         data->count++;
         r = _rl_insert_next (1);
         _rl_want_redisplay = 1;
         /* If we should keep going, leave the callback function installed */
         if (data->count < 0 && r == 0)
           return r;
         count = 0;        /* data->count == 0 || r != 0; force break below */
       }
   
   /* Deregister function, let rl_callback_read_char deallocate data */    /* Deregister function, let rl_callback_read_char deallocate data */
   _rl_callback_func = 0;    _rl_callback_func = 0;
   _rl_want_redisplay = 1;    _rl_want_redisplay = 1;
 
   if (count == 0)
     return r;
 
   return _rl_insert_next (count);    return _rl_insert_next (count);
 }  }
 #endif  #endif
       
 int  int
rl_quoted_insert (count, key)rl_quoted_insert (int count, int key)
     int count, key; 
 {  {
   /* Let's see...should the callback interface futz with signal handling? */    /* Let's see...should the callback interface futz with signal handling? */
 #if defined (HANDLE_SIGNALS)  #if defined (HANDLE_SIGNALS)
Line 954  rl_quoted_insert (count, key) Line 1064  rl_quoted_insert (count, key)
       return (0);        return (0);
     }      }
 #endif  #endif
      
   /* A negative count means to quote the next -COUNT characters. */
   if (count < 0)
     {
       int r;
 
       do
         r = _rl_insert_next (1);
       while (r == 0 && ++count < 0);
       return r;
     }
 
   return _rl_insert_next (count);    return _rl_insert_next (count);
 }  }
   
 /* Insert a tab character. */  /* Insert a tab character. */
 int  int
rl_tab_insert (count, key)rl_tab_insert (int count, int key)
     int count, key; 
 {  {
   return (_rl_insert_char (count, '\t'));    return (_rl_insert_char (count, '\t'));
 }  }
Line 970  rl_tab_insert (count, key) Line 1090  rl_tab_insert (count, key)
    KEY is the key that invoked this command.  I guess it could have     KEY is the key that invoked this command.  I guess it could have
    meaning in the future. */     meaning in the future. */
 int  int
rl_newline (count, key)rl_newline (int count, int key)
     int count, key; 
 {  {
     if (rl_mark_active_p ())
       {
         rl_deactivate_mark ();
         (*rl_redisplay_function) ();
         _rl_want_redisplay = 0;
       }
   
   rl_done = 1;    rl_done = 1;
   
   if (_rl_history_preserve_point)    if (_rl_history_preserve_point)
Line 1004  rl_newline (count, key) Line 1130  rl_newline (count, key)
    is just a stub, you bind keys to it and the code in _rl_dispatch ()     is just a stub, you bind keys to it and the code in _rl_dispatch ()
    is special cased. */     is special cased. */
 int  int
rl_do_lowercase_version (ignore1, ignore2)rl_do_lowercase_version (int ignore1, int ignore2)
     int ignore1, ignore2; 
 {  {
   return 0;    return 0;
 }  }
Line 1014  rl_do_lowercase_version (ignore1, ignore2) Line 1139  rl_do_lowercase_version (ignore1, ignore2)
    rubout in overwrite mode has one oddity:  it replaces a control     rubout in overwrite mode has one oddity:  it replaces a control
    character that's displayed as two characters (^X) with two spaces. */     character that's displayed as two characters (^X) with two spaces. */
 int  int
_rl_overwrite_rubout (count, key)_rl_overwrite_rubout (int count, int key)
     int count, key; 
 {  {
   int opoint;    int opoint;
   int i, l;    int i, l;
Line 1057  _rl_overwrite_rubout (count, key) Line 1181  _rl_overwrite_rubout (count, key)
       
 /* Rubout the character behind point. */  /* Rubout the character behind point. */
 int  int
rl_rubout (count, key)rl_rubout (int count, int key)
     int count, key; 
 {  {
   if (count < 0)    if (count < 0)
     return (rl_delete (-count, key));      return (rl_delete (-count, key));
Line 1066  rl_rubout (count, key) Line 1189  rl_rubout (count, key)
   if (!rl_point)    if (!rl_point)
     {      {
       rl_ding ();        rl_ding ();
      return -1;      return 1;
     }      }
   
   if (rl_insert_mode == RL_IM_OVERWRITE)    if (rl_insert_mode == RL_IM_OVERWRITE)
Line 1076  rl_rubout (count, key) Line 1199  rl_rubout (count, key)
 }  }
   
 int  int
_rl_rubout_char (count, key)_rl_rubout_char (int count, int key)
     int count, key; 
 {  {
   int orig_point;    int orig_point;
   unsigned char c;    unsigned char c;
Line 1089  _rl_rubout_char (count, key) Line 1211  _rl_rubout_char (count, key)
   if (rl_point == 0)    if (rl_point == 0)
     {      {
       rl_ding ();        rl_ding ();
      return -1;      return 1;
     }      }
   
   orig_point = rl_point;    orig_point = rl_point;
Line 1103  _rl_rubout_char (count, key) Line 1225  _rl_rubout_char (count, key)
       c = rl_line_buffer[--rl_point];        c = rl_line_buffer[--rl_point];
       rl_delete_text (rl_point, orig_point);        rl_delete_text (rl_point, orig_point);
       /* The erase-at-end-of-line hack is of questionable merit now. */        /* The erase-at-end-of-line hack is of questionable merit now. */
      if (rl_point == rl_end && ISPRINT (c) && _rl_last_c_pos)      if (rl_point == rl_end && ISPRINT ((unsigned char)c) && _rl_last_c_pos)
         {          {
           int l;            int l;
           l = rl_character_len (c, rl_point);            l = rl_character_len (c, rl_point);
Line 1122  _rl_rubout_char (count, key) Line 1244  _rl_rubout_char (count, key)
 /* Delete the character under the cursor.  Given a numeric argument,  /* Delete the character under the cursor.  Given a numeric argument,
    kill that many characters instead. */     kill that many characters instead. */
 int  int
rl_delete (count, key)rl_delete (int count, int key)
     int count, key; 
 {  {
   int xpoint;    int xpoint;
   
Line 1133  rl_delete (count, key) Line 1254  rl_delete (count, key)
   if (rl_point == rl_end)    if (rl_point == rl_end)
     {      {
       rl_ding ();        rl_ding ();
      return -1;      return 1;
     }      }
   
   if (count > 1 || rl_explicit_arg)    if (count > 1 || rl_explicit_arg)
Line 1160  rl_delete (count, key) Line 1281  rl_delete (count, key)
    behind the cursor is deleted.  COUNT is obeyed and may be used     behind the cursor is deleted.  COUNT is obeyed and may be used
    to delete forward or backward that many characters. */           to delete forward or backward that many characters. */      
 int  int
rl_rubout_or_delete (count, key)rl_rubout_or_delete (int count, int key)
     int count, key; 
 {  {
   if (rl_end != 0 && rl_point == rl_end)    if (rl_end != 0 && rl_point == rl_end)
     return (_rl_rubout_char (count, key));      return (_rl_rubout_char (count, key));
Line 1171  rl_rubout_or_delete (count, key) Line 1291  rl_rubout_or_delete (count, key)
   
 /* Delete all spaces and tabs around point. */  /* Delete all spaces and tabs around point. */
 int  int
rl_delete_horizontal_space (count, ignore)rl_delete_horizontal_space (int count, int ignore)
     int count, ignore; 
 {  {
   int start;    int start;
   
Line 1200  rl_delete_horizontal_space (count, ignore) Line 1319  rl_delete_horizontal_space (count, ignore)
    is caught before this is invoked, so this really does the same thing as     is caught before this is invoked, so this really does the same thing as
    delete-char-or-list-or-eof, as long as it's bound to the eof character. */     delete-char-or-list-or-eof, as long as it's bound to the eof character. */
 int  int
rl_delete_or_show_completions (count, key)rl_delete_or_show_completions (int count, int key)
     int count, key; 
 {  {
   if (rl_end != 0 && rl_point == rl_end)    if (rl_end != 0 && rl_point == rl_end)
     return (rl_possible_completions (count, key));      return (rl_possible_completions (count, key));
Line 1216  rl_delete_or_show_completions (count, key) Line 1334  rl_delete_or_show_completions (count, key)
 /* Turn the current line into a comment in shell history.  /* Turn the current line into a comment in shell history.
    A K*rn shell style function. */     A K*rn shell style function. */
 int  int
rl_insert_comment (count, key)rl_insert_comment (int count, int key)
     int count, key; 
 {  {
   char *rl_comment_text;    char *rl_comment_text;
   int rl_comment_len;    int rl_comment_len;
Line 1255  rl_insert_comment (count, key) Line 1372  rl_insert_comment (count, key)
   
 /* Uppercase the word at point. */  /* Uppercase the word at point. */
 int  int
rl_upcase_word (count, key)rl_upcase_word (int count, int key)
     int count, key; 
 {  {
   return (rl_change_case (count, UpCase));    return (rl_change_case (count, UpCase));
 }  }
   
 /* Lowercase the word at point. */  /* Lowercase the word at point. */
 int  int
rl_downcase_word (count, key)rl_downcase_word (int count, int key)
     int count, key; 
 {  {
   return (rl_change_case (count, DownCase));    return (rl_change_case (count, DownCase));
 }  }
   
 /* Upcase the first letter, downcase the rest. */  /* Upcase the first letter, downcase the rest. */
 int  int
rl_capitalize_word (count, key)rl_capitalize_word (int count, int key)
     int count, key; 
 {  {
  return (rl_change_case (count, CapCase));   return (rl_change_case (count, CapCase));
 }  }
Line 1283  rl_capitalize_word (count, key) Line 1397  rl_capitalize_word (count, key)
    If a negative argument is given, leave point where it started,     If a negative argument is given, leave point where it started,
    otherwise, leave it where it moves to. */     otherwise, leave it where it moves to. */
 static int  static int
rl_change_case (count, op)rl_change_case (int count, int op)
     int count, op; 
 {  {
   int start, next, end;    int start, next, end;
  int inword, c, nc, nop;  int inword, nc, nop;
   wchar_t c;
 #if defined (HANDLE_MULTIBYTE)  #if defined (HANDLE_MULTIBYTE)
   wchar_t wc, nwc;    wchar_t wc, nwc;
   char mb[MB_LEN_MAX+1];    char mb[MB_LEN_MAX+1];
Line 1303  rl_change_case (count, op) Line 1417  rl_change_case (count, op)
   if (op != UpCase && op != DownCase && op != CapCase)    if (op != UpCase && op != DownCase && op != CapCase)
     {      {
       rl_ding ();        rl_ding ();
      return -1;      return 1;
     }      }
   
   if (count < 0)    if (count < 0)
Line 1337  rl_change_case (count, op) Line 1451  rl_change_case (count, op)
         }          }
       else        else
         nop = op;          nop = op;
      if (MB_CUR_MAX == 1 || rl_byte_oriented || isascii (c))      /* Can't check isascii here; some languages (e.g, Turkish) have
          multibyte upper and lower case equivalents of single-byte ascii
          characters */
       if (MB_CUR_MAX == 1 || rl_byte_oriented)
         {          {
           nc = (nop == UpCase) ? _rl_to_upper (c) : _rl_to_lower (c);            nc = (nop == UpCase) ? _rl_to_upper (c) : _rl_to_lower (c);
           rl_line_buffer[start] = nc;            rl_line_buffer[start] = nc;
Line 1353  rl_change_case (count, op) Line 1470  rl_change_case (count, op)
           nwc = (nop == UpCase) ? _rl_to_wupper (wc) : _rl_to_wlower (wc);            nwc = (nop == UpCase) ? _rl_to_wupper (wc) : _rl_to_wlower (wc);
           if  (nwc != wc)       /*  just skip unchanged characters */            if  (nwc != wc)       /*  just skip unchanged characters */
             {              {
              mlen = wcrtomb (mb, nwc, &mps);              char *s, *e;
               mbstate_t ts;
 
               memset (&ts, 0, sizeof (mbstate_t));
               mlen = wcrtomb (mb, nwc, &ts);
               if (mlen < 0)
                 {
                   nwc = wc;
                   memset (&ts, 0, sizeof (mbstate_t));
                   mlen = wcrtomb (mb, nwc, &ts);
                   if (mlen < 0)         /* should not happen */
                     strncpy (mb, rl_line_buffer + start, mlen = m);
                 }
               if (mlen > 0)                if (mlen > 0)
                 mb[mlen] = '\0';                  mb[mlen] = '\0';
              /* Assume the same width */              /* what to do if m != mlen? adjust below */
              strncpy (rl_line_buffer + start, mb, mlen);              /* m == length of old char, mlen == length of new char */
               s = rl_line_buffer + start;
               e = rl_line_buffer + rl_end;
               if (m == mlen)
                 memcpy (s, mb, mlen);
               else if (m > mlen)
                 {
                   memcpy (s, mb, mlen);
                   memmove (s + mlen, s + m, (e - s) - m);
                   next -= m - mlen;     /* next char changes */
                   end -= m - mlen;      /* end of word changes */
                   rl_end -= m - mlen;   /* end of line changes */
                   rl_line_buffer[rl_end] = 0;
                 }
               else if (m < mlen)
                 {
                   rl_extend_line_buffer (rl_end + mlen + (e - s) - m + 2);
                   s = rl_line_buffer + start;   /* have to redo this */
                   e = rl_line_buffer + rl_end;
                   memmove (s + mlen, s + m, (e - s) - m);
                   memcpy (s, mb, mlen);
                   next += mlen - m;     /* next char changes */
                   end += mlen - m;      /* end of word changes */
                   rl_end += mlen - m;   /* end of line changes */
                   rl_line_buffer[rl_end] = 0;
                 }
             }              }
         }          }
 #endif  #endif
Line 1378  rl_change_case (count, op) Line 1532  rl_change_case (count, op)
 /* Transpose the words at point.  If point is at the end of the line,  /* Transpose the words at point.  If point is at the end of the line,
    transpose the two words before point. */     transpose the two words before point. */
 int  int
rl_transpose_words (count, key)rl_transpose_words (int count, int key)
     int count, key; 
 {  {
   char *word1, *word2;    char *word1, *word2;
   int w1_beg, w1_end, w2_beg, w2_end;    int w1_beg, w1_end, w2_beg, w2_end;
Line 1403  rl_transpose_words (count, key) Line 1556  rl_transpose_words (count, key)
     {      {
       rl_ding ();        rl_ding ();
       rl_point = orig_point;        rl_point = orig_point;
      return -1;      return 1;
     }      }
   
   /* Get the text of the words. */    /* Get the text of the words. */
Line 1439  rl_transpose_words (count, key) Line 1592  rl_transpose_words (count, key)
 /* Transpose the characters at point.  If point is at the end of the line,  /* Transpose the characters at point.  If point is at the end of the line,
    then transpose the characters before point. */     then transpose the characters before point. */
 int  int
rl_transpose_chars (count, key)rl_transpose_chars (int count, int key)
     int count, key; 
 {  {
 #if defined (HANDLE_MULTIBYTE)  #if defined (HANDLE_MULTIBYTE)
   char *dummy;    char *dummy;
Line 1456  rl_transpose_chars (count, key) Line 1608  rl_transpose_chars (count, key)
   if (!rl_point || rl_end < 2)    if (!rl_point || rl_end < 2)
     {      {
       rl_ding ();        rl_ding ();
      return -1;      return 1;
     }      }
   
   rl_begin_undo_group ();    rl_begin_undo_group ();
Line 1504  rl_transpose_chars (count, key) Line 1656  rl_transpose_chars (count, key)
   
 int  int
 #if defined (HANDLE_MULTIBYTE)  #if defined (HANDLE_MULTIBYTE)
_rl_char_search_internal (count, dir, smbchar, len)_rl_char_search_internal (int count, int dir, char *smbchar, int len)
     int count, dir; 
     char *smbchar; 
     int len; 
 #else  #else
_rl_char_search_internal (count, dir, schar)_rl_char_search_internal (int count, int dir, int schar)
     int count, dir, schar; 
 #endif  #endif
 {  {
   int pos, inc;    int pos, inc;
Line 1519  _rl_char_search_internal (count, dir, schar) Line 1667  _rl_char_search_internal (count, dir, schar)
 #endif  #endif
   
   if (dir == 0)    if (dir == 0)
    return -1;    return 1;
   
   pos = rl_point;    pos = rl_point;
   inc = (dir < 0) ? -1 : 1;    inc = (dir < 0) ? -1 : 1;
Line 1528  _rl_char_search_internal (count, dir, schar) Line 1676  _rl_char_search_internal (count, dir, schar)
       if ((dir < 0 && pos <= 0) || (dir > 0 && pos >= rl_end))        if ((dir < 0 && pos <= 0) || (dir > 0 && pos >= rl_end))
         {          {
           rl_ding ();            rl_ding ();
          return -1;          return 1;
         }          }
   
 #if defined (HANDLE_MULTIBYTE)  #if defined (HANDLE_MULTIBYTE)
Line 1574  _rl_char_search_internal (count, dir, schar) Line 1722  _rl_char_search_internal (count, dir, schar)
    that there are two separate versions of this function. */     that there are two separate versions of this function. */
 #if defined (HANDLE_MULTIBYTE)  #if defined (HANDLE_MULTIBYTE)
 static int  static int
_rl_char_search (count, fdir, bdir)_rl_char_search (int count, int fdir, int bdir)
     int count, fdir, bdir; 
 {  {
   char mbchar[MB_LEN_MAX];    char mbchar[MB_LEN_MAX];
   int mb_len;    int mb_len;
Line 1583  _rl_char_search (count, fdir, bdir) Line 1730  _rl_char_search (count, fdir, bdir)
   mb_len = _rl_read_mbchar (mbchar, MB_LEN_MAX);    mb_len = _rl_read_mbchar (mbchar, MB_LEN_MAX);
   
   if (mb_len <= 0)    if (mb_len <= 0)
    return -1;    return 1;
   
   if (count < 0)    if (count < 0)
     return (_rl_char_search_internal (-count, bdir, mbchar, mb_len));      return (_rl_char_search_internal (-count, bdir, mbchar, mb_len));
Line 1592  _rl_char_search (count, fdir, bdir) Line 1739  _rl_char_search (count, fdir, bdir)
 }  }
 #else /* !HANDLE_MULTIBYTE */  #else /* !HANDLE_MULTIBYTE */
 static int  static int
_rl_char_search (count, fdir, bdir)_rl_char_search (int count, int fdir, int bdir)
     int count, fdir, bdir; 
 {  {
   int c;    int c;
   
  RL_SETSTATE(RL_STATE_MOREINPUT);  c = _rl_bracketed_read_key ();
  c = rl_read_key (); 
  RL_UNSETSTATE(RL_STATE_MOREINPUT); 
 
   if (c < 0)    if (c < 0)
    return -1;    return 1;
   
   if (count < 0)    if (count < 0)
     return (_rl_char_search_internal (-count, bdir, c));      return (_rl_char_search_internal (-count, bdir, c));
Line 1624  _rl_char_search_callback (data) Line 1767  _rl_char_search_callback (data)
 #endif  #endif
   
 int  int
rl_char_search (count, key)rl_char_search (int count, int key)
     int count, key; 
 {  {
 #if defined (READLINE_CALLBACKS)  #if defined (READLINE_CALLBACKS)
   if (RL_ISSTATE (RL_STATE_CALLBACK))    if (RL_ISSTATE (RL_STATE_CALLBACK))
Line 1642  rl_char_search (count, key) Line 1784  rl_char_search (count, key)
 }  }
   
 int  int
rl_backward_char_search (count, key)rl_backward_char_search (int count, int key)
     int count, key; 
 {  {
 #if defined (READLINE_CALLBACKS)  #if defined (READLINE_CALLBACKS)
   if (RL_ISSTATE (RL_STATE_CALLBACK))    if (RL_ISSTATE (RL_STATE_CALLBACK))
Line 1667  rl_backward_char_search (count, key) Line 1808  rl_backward_char_search (count, key)
   
 /* Set the mark at POSITION. */  /* Set the mark at POSITION. */
 int  int
_rl_set_mark_at_pos (position)_rl_set_mark_at_pos (int position)
     int position; 
 {  {
  if (position > rl_end)  if (position < 0 || position > rl_end)
    return -1;    return 1;
   
   rl_mark = position;    rl_mark = position;
   return 0;    return 0;
Line 1679  _rl_set_mark_at_pos (position) Line 1819  _rl_set_mark_at_pos (position)
   
 /* A bindable command to set the mark. */  /* A bindable command to set the mark. */
 int  int
rl_set_mark (count, key)rl_set_mark (int count, int key)
     int count, key; 
 {  {
   return (_rl_set_mark_at_pos (rl_explicit_arg ? count : rl_point));    return (_rl_set_mark_at_pos (rl_explicit_arg ? count : rl_point));
 }  }
   
 /* Exchange the position of mark and point. */  /* Exchange the position of mark and point. */
 int  int
rl_exchange_point_and_mark (count, key)rl_exchange_point_and_mark (int count, int key)
     int count, key; 
 {  {
   if (rl_mark > rl_end)    if (rl_mark > rl_end)
     rl_mark = -1;      rl_mark = -1;
   
  if (rl_mark == -1)  if (rl_mark < 0)
     {      {
       rl_ding ();        rl_ding ();
      return -1;      rl_mark = 0;              /* like _RL_FIX_POINT */
       return 1;
     }      }
   else    else
    SWAP (rl_point, rl_mark);    {
       SWAP (rl_point, rl_mark);
       rl_activate_mark ();
     }
   
   return 0;    return 0;
   }
   
   /* Active mark support */
   
   /* Is the region active? */
   static int mark_active = 0;
   
   /* Does the current command want the mark to remain active when it completes? */
   int _rl_keep_mark_active;
   
   void
   rl_keep_mark_active (void)
   {
     _rl_keep_mark_active++;
   }
   
   void
   rl_activate_mark (void)
   {
     mark_active = 1;
     rl_keep_mark_active ();
   }
   
   void
   rl_deactivate_mark (void)
   {
     mark_active = 0;
   }
   
   int
   rl_mark_active_p (void)
   {
     return (mark_active);
 }  }

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>