OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [gdb-5.0/] [readline/] [kill.c] - Diff between revs 579 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 579 Rev 1765
/* kill.c -- kill ring management. */
/* kill.c -- kill ring management. */
 
 
/* Copyright (C) 1994 Free Software Foundation, Inc.
/* Copyright (C) 1994 Free Software Foundation, Inc.
 
 
   This file is part of the GNU Readline Library, a library for
   This file is part of the GNU Readline Library, a library for
   reading lines of text with interactive input and history editing.
   reading lines of text with interactive input and history editing.
 
 
   The GNU Readline Library is free software; you can redistribute it
   The GNU Readline Library is free software; you can redistribute it
   and/or modify it under the terms of the GNU General Public License
   and/or modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 1, or
   as published by the Free Software Foundation; either version 1, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   The GNU Readline Library is distributed in the hope that it will be
   The GNU Readline Library is distributed in the hope that it will be
   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   The GNU General Public License is often shipped with GNU software, and
   The GNU General Public License is often shipped with GNU software, and
   is generally kept in a file called COPYING or LICENSE.  If you do not
   is generally kept in a file called COPYING or LICENSE.  If you do not
   have a copy of the license, write to the Free Software Foundation,
   have a copy of the license, write to the Free Software Foundation,
   675 Mass Ave, Cambridge, MA 02139, USA. */
   675 Mass Ave, Cambridge, MA 02139, USA. */
#define READLINE_LIBRARY
#define READLINE_LIBRARY
 
 
#if defined (HAVE_CONFIG_H)
#if defined (HAVE_CONFIG_H)
#  include <config.h>
#  include <config.h>
#endif
#endif
 
 
#include <sys/types.h>
#include <sys/types.h>
 
 
#if defined (HAVE_UNISTD_H)
#if defined (HAVE_UNISTD_H)
#  include <unistd.h>           /* for _POSIX_VERSION */
#  include <unistd.h>           /* for _POSIX_VERSION */
#endif /* HAVE_UNISTD_H */
#endif /* HAVE_UNISTD_H */
 
 
#if defined (HAVE_STDLIB_H)
#if defined (HAVE_STDLIB_H)
#  include <stdlib.h>
#  include <stdlib.h>
#else
#else
#  include "ansi_stdlib.h"
#  include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */
#endif /* HAVE_STDLIB_H */
 
 
#include <stdio.h>
#include <stdio.h>
 
 
/* System-specific feature definitions and include files. */
/* System-specific feature definitions and include files. */
#include "rldefs.h"
#include "rldefs.h"
 
 
/* Some standard library routines. */
/* Some standard library routines. */
#include "readline.h"
#include "readline.h"
#include "history.h"
#include "history.h"
 
 
extern int _rl_last_command_was_kill;
extern int _rl_last_command_was_kill;
extern int rl_editing_mode;
extern int rl_editing_mode;
extern int rl_explicit_arg;
extern int rl_explicit_arg;
extern Function *rl_last_func;
extern Function *rl_last_func;
 
 
extern void _rl_init_argument ();
extern void _rl_init_argument ();
extern int _rl_set_mark_at_pos ();
extern int _rl_set_mark_at_pos ();
extern void _rl_fix_point ();
extern void _rl_fix_point ();
extern void _rl_abort_internal ();
extern void _rl_abort_internal ();
 
 
extern char *xmalloc (), *xrealloc ();
extern char *xmalloc (), *xrealloc ();
 
 
/* **************************************************************** */
/* **************************************************************** */
/*                                                                  */
/*                                                                  */
/*                      Killing Mechanism                           */
/*                      Killing Mechanism                           */
/*                                                                  */
/*                                                                  */
/* **************************************************************** */
/* **************************************************************** */
 
 
/* What we assume for a max number of kills. */
/* What we assume for a max number of kills. */
#define DEFAULT_MAX_KILLS 10
#define DEFAULT_MAX_KILLS 10
 
 
/* The real variable to look at to find out when to flush kills. */
/* The real variable to look at to find out when to flush kills. */
static int rl_max_kills =  DEFAULT_MAX_KILLS;
static int rl_max_kills =  DEFAULT_MAX_KILLS;
 
 
/* Where to store killed text. */
/* Where to store killed text. */
static char **rl_kill_ring = (char **)NULL;
static char **rl_kill_ring = (char **)NULL;
 
 
/* Where we are in the kill ring. */
/* Where we are in the kill ring. */
static int rl_kill_index;
static int rl_kill_index;
 
 
/* How many slots we have in the kill ring. */
/* How many slots we have in the kill ring. */
static int rl_kill_ring_length;
static int rl_kill_ring_length;
 
 
/* How to say that you only want to save a certain amount
/* How to say that you only want to save a certain amount
   of kill material. */
   of kill material. */
int
int
rl_set_retained_kills (num)
rl_set_retained_kills (num)
     int num;
     int num;
{
{
  return 0;
  return 0;
}
}
 
 
/* Add TEXT to the kill ring, allocating a new kill ring slot as necessary.
/* Add TEXT to the kill ring, allocating a new kill ring slot as necessary.
   This uses TEXT directly, so the caller must not free it.  If APPEND is
   This uses TEXT directly, so the caller must not free it.  If APPEND is
   non-zero, and the last command was a kill, the text is appended to the
   non-zero, and the last command was a kill, the text is appended to the
   current kill ring slot, otherwise prepended. */
   current kill ring slot, otherwise prepended. */
static int
static int
_rl_copy_to_kill_ring (text, append)
_rl_copy_to_kill_ring (text, append)
     char *text;
     char *text;
     int append;
     int append;
{
{
  char *old, *new;
  char *old, *new;
  int slot;
  int slot;
 
 
  /* First, find the slot to work with. */
  /* First, find the slot to work with. */
  if (_rl_last_command_was_kill == 0)
  if (_rl_last_command_was_kill == 0)
    {
    {
      /* Get a new slot.  */
      /* Get a new slot.  */
      if (rl_kill_ring == 0)
      if (rl_kill_ring == 0)
        {
        {
          /* If we don't have any defined, then make one. */
          /* If we don't have any defined, then make one. */
          rl_kill_ring = (char **)
          rl_kill_ring = (char **)
            xmalloc (((rl_kill_ring_length = 1) + 1) * sizeof (char *));
            xmalloc (((rl_kill_ring_length = 1) + 1) * sizeof (char *));
          rl_kill_ring[slot = 0] = (char *)NULL;
          rl_kill_ring[slot = 0] = (char *)NULL;
        }
        }
      else
      else
        {
        {
          /* We have to add a new slot on the end, unless we have
          /* We have to add a new slot on the end, unless we have
             exceeded the max limit for remembering kills. */
             exceeded the max limit for remembering kills. */
          slot = rl_kill_ring_length;
          slot = rl_kill_ring_length;
          if (slot == rl_max_kills)
          if (slot == rl_max_kills)
            {
            {
              register int i;
              register int i;
              free (rl_kill_ring[0]);
              free (rl_kill_ring[0]);
              for (i = 0; i < slot; i++)
              for (i = 0; i < slot; i++)
                rl_kill_ring[i] = rl_kill_ring[i + 1];
                rl_kill_ring[i] = rl_kill_ring[i + 1];
            }
            }
          else
          else
            {
            {
              slot = rl_kill_ring_length += 1;
              slot = rl_kill_ring_length += 1;
              rl_kill_ring = (char **)xrealloc (rl_kill_ring, slot * sizeof (char *));
              rl_kill_ring = (char **)xrealloc (rl_kill_ring, slot * sizeof (char *));
            }
            }
          rl_kill_ring[--slot] = (char *)NULL;
          rl_kill_ring[--slot] = (char *)NULL;
        }
        }
    }
    }
  else
  else
    slot = rl_kill_ring_length - 1;
    slot = rl_kill_ring_length - 1;
 
 
  /* If the last command was a kill, prepend or append. */
  /* If the last command was a kill, prepend or append. */
  if (_rl_last_command_was_kill && rl_editing_mode != vi_mode)
  if (_rl_last_command_was_kill && rl_editing_mode != vi_mode)
    {
    {
      old = rl_kill_ring[slot];
      old = rl_kill_ring[slot];
      new = xmalloc (1 + strlen (old) + strlen (text));
      new = xmalloc (1 + strlen (old) + strlen (text));
 
 
      if (append)
      if (append)
        {
        {
          strcpy (new, old);
          strcpy (new, old);
          strcat (new, text);
          strcat (new, text);
        }
        }
      else
      else
        {
        {
          strcpy (new, text);
          strcpy (new, text);
          strcat (new, old);
          strcat (new, old);
        }
        }
      free (old);
      free (old);
      free (text);
      free (text);
      rl_kill_ring[slot] = new;
      rl_kill_ring[slot] = new;
    }
    }
  else
  else
    rl_kill_ring[slot] = text;
    rl_kill_ring[slot] = text;
 
 
  rl_kill_index = slot;
  rl_kill_index = slot;
  return 0;
  return 0;
}
}
 
 
/* The way to kill something.  This appends or prepends to the last
/* The way to kill something.  This appends or prepends to the last
   kill, if the last command was a kill command.  if FROM is less
   kill, if the last command was a kill command.  if FROM is less
   than TO, then the text is appended, otherwise prepended.  If the
   than TO, then the text is appended, otherwise prepended.  If the
   last command was not a kill command, then a new slot is made for
   last command was not a kill command, then a new slot is made for
   this kill. */
   this kill. */
int
int
rl_kill_text (from, to)
rl_kill_text (from, to)
     int from, to;
     int from, to;
{
{
  char *text;
  char *text;
 
 
  /* Is there anything to kill? */
  /* Is there anything to kill? */
  if (from == to)
  if (from == to)
    {
    {
      _rl_last_command_was_kill++;
      _rl_last_command_was_kill++;
      return 0;
      return 0;
    }
    }
 
 
  text = rl_copy_text (from, to);
  text = rl_copy_text (from, to);
 
 
  /* Delete the copied text from the line. */
  /* Delete the copied text from the line. */
  rl_delete_text (from, to);
  rl_delete_text (from, to);
 
 
  _rl_copy_to_kill_ring (text, from < to);
  _rl_copy_to_kill_ring (text, from < to);
 
 
  _rl_last_command_was_kill++;
  _rl_last_command_was_kill++;
  return 0;
  return 0;
}
}
 
 
/* Now REMEMBER!  In order to do prepending or appending correctly, kill
/* Now REMEMBER!  In order to do prepending or appending correctly, kill
   commands always make rl_point's original position be the FROM argument,
   commands always make rl_point's original position be the FROM argument,
   and rl_point's extent be the TO argument. */
   and rl_point's extent be the TO argument. */
 
 
/* **************************************************************** */
/* **************************************************************** */
/*                                                                  */
/*                                                                  */
/*                      Killing Commands                            */
/*                      Killing Commands                            */
/*                                                                  */
/*                                                                  */
/* **************************************************************** */
/* **************************************************************** */
 
 
/* Delete the word at point, saving the text in the kill ring. */
/* Delete the word at point, saving the text in the kill ring. */
int
int
rl_kill_word (count, key)
rl_kill_word (count, key)
     int count, key;
     int count, key;
{
{
  int orig_point = rl_point;
  int orig_point = rl_point;
 
 
  if (count < 0)
  if (count < 0)
    return (rl_backward_kill_word (-count, key));
    return (rl_backward_kill_word (-count, key));
  else
  else
    {
    {
      rl_forward_word (count, key);
      rl_forward_word (count, key);
 
 
      if (rl_point != orig_point)
      if (rl_point != orig_point)
        rl_kill_text (orig_point, rl_point);
        rl_kill_text (orig_point, rl_point);
 
 
      rl_point = orig_point;
      rl_point = orig_point;
    }
    }
  return 0;
  return 0;
}
}
 
 
/* Rubout the word before point, placing it on the kill ring. */
/* Rubout the word before point, placing it on the kill ring. */
int
int
rl_backward_kill_word (count, ignore)
rl_backward_kill_word (count, ignore)
     int count, ignore;
     int count, ignore;
{
{
  int orig_point = rl_point;
  int orig_point = rl_point;
 
 
  if (count < 0)
  if (count < 0)
    return (rl_kill_word (-count, ignore));
    return (rl_kill_word (-count, ignore));
  else
  else
    {
    {
      rl_backward_word (count, ignore);
      rl_backward_word (count, ignore);
 
 
      if (rl_point != orig_point)
      if (rl_point != orig_point)
        rl_kill_text (orig_point, rl_point);
        rl_kill_text (orig_point, rl_point);
    }
    }
  return 0;
  return 0;
}
}
 
 
/* Kill from here to the end of the line.  If DIRECTION is negative, kill
/* Kill from here to the end of the line.  If DIRECTION is negative, kill
   back to the line start instead. */
   back to the line start instead. */
int
int
rl_kill_line (direction, ignore)
rl_kill_line (direction, ignore)
     int direction, ignore;
     int direction, ignore;
{
{
  int orig_point = rl_point;
  int orig_point = rl_point;
 
 
  if (direction < 0)
  if (direction < 0)
    return (rl_backward_kill_line (1, ignore));
    return (rl_backward_kill_line (1, ignore));
  else
  else
    {
    {
      rl_end_of_line (1, ignore);
      rl_end_of_line (1, ignore);
      if (orig_point != rl_point)
      if (orig_point != rl_point)
        rl_kill_text (orig_point, rl_point);
        rl_kill_text (orig_point, rl_point);
      rl_point = orig_point;
      rl_point = orig_point;
    }
    }
  return 0;
  return 0;
}
}
 
 
/* Kill backwards to the start of the line.  If DIRECTION is negative, kill
/* Kill backwards to the start of the line.  If DIRECTION is negative, kill
   forwards to the line end instead. */
   forwards to the line end instead. */
int
int
rl_backward_kill_line (direction, ignore)
rl_backward_kill_line (direction, ignore)
     int direction, ignore;
     int direction, ignore;
{
{
  int orig_point = rl_point;
  int orig_point = rl_point;
 
 
  if (direction < 0)
  if (direction < 0)
    return (rl_kill_line (1, ignore));
    return (rl_kill_line (1, ignore));
  else
  else
    {
    {
      if (!rl_point)
      if (!rl_point)
        ding ();
        ding ();
      else
      else
        {
        {
          rl_beg_of_line (1, ignore);
          rl_beg_of_line (1, ignore);
          rl_kill_text (orig_point, rl_point);
          rl_kill_text (orig_point, rl_point);
        }
        }
    }
    }
  return 0;
  return 0;
}
}
 
 
/* Kill the whole line, no matter where point is. */
/* Kill the whole line, no matter where point is. */
int
int
rl_kill_full_line (count, ignore)
rl_kill_full_line (count, ignore)
     int count, ignore;
     int count, ignore;
{
{
  rl_begin_undo_group ();
  rl_begin_undo_group ();
  rl_point = 0;
  rl_point = 0;
  rl_kill_text (rl_point, rl_end);
  rl_kill_text (rl_point, rl_end);
  rl_end_undo_group ();
  rl_end_undo_group ();
  return 0;
  return 0;
}
}
 
 
/* The next two functions mimic unix line editing behaviour, except they
/* The next two functions mimic unix line editing behaviour, except they
   save the deleted text on the kill ring.  This is safer than not saving
   save the deleted text on the kill ring.  This is safer than not saving
   it, and since we have a ring, nobody should get screwed. */
   it, and since we have a ring, nobody should get screwed. */
 
 
/* This does what C-w does in Unix.  We can't prevent people from
/* This does what C-w does in Unix.  We can't prevent people from
   using behaviour that they expect. */
   using behaviour that they expect. */
int
int
rl_unix_word_rubout (count, key)
rl_unix_word_rubout (count, key)
     int count, key;
     int count, key;
{
{
  int orig_point;
  int orig_point;
 
 
  if (rl_point == 0)
  if (rl_point == 0)
    ding ();
    ding ();
  else
  else
    {
    {
      orig_point = rl_point;
      orig_point = rl_point;
      if (count <= 0)
      if (count <= 0)
        count = 1;
        count = 1;
 
 
      while (count--)
      while (count--)
        {
        {
          while (rl_point && whitespace (rl_line_buffer[rl_point - 1]))
          while (rl_point && whitespace (rl_line_buffer[rl_point - 1]))
            rl_point--;
            rl_point--;
 
 
          while (rl_point && (whitespace (rl_line_buffer[rl_point - 1]) == 0))
          while (rl_point && (whitespace (rl_line_buffer[rl_point - 1]) == 0))
            rl_point--;
            rl_point--;
        }
        }
 
 
      rl_kill_text (orig_point, rl_point);
      rl_kill_text (orig_point, rl_point);
    }
    }
  return 0;
  return 0;
}
}
 
 
/* Here is C-u doing what Unix does.  You don't *have* to use these
/* Here is C-u doing what Unix does.  You don't *have* to use these
   key-bindings.  We have a choice of killing the entire line, or
   key-bindings.  We have a choice of killing the entire line, or
   killing from where we are to the start of the line.  We choose the
   killing from where we are to the start of the line.  We choose the
   latter, because if you are a Unix weenie, then you haven't backspaced
   latter, because if you are a Unix weenie, then you haven't backspaced
   into the line at all, and if you aren't, then you know what you are
   into the line at all, and if you aren't, then you know what you are
   doing. */
   doing. */
int
int
rl_unix_line_discard (count, key)
rl_unix_line_discard (count, key)
     int count, key;
     int count, key;
{
{
  if (rl_point == 0)
  if (rl_point == 0)
    ding ();
    ding ();
  else
  else
    {
    {
      rl_kill_text (rl_point, 0);
      rl_kill_text (rl_point, 0);
      rl_point = 0;
      rl_point = 0;
    }
    }
  return 0;
  return 0;
}
}
 
 
/* Copy the text in the `region' to the kill ring.  If DELETE is non-zero,
/* Copy the text in the `region' to the kill ring.  If DELETE is non-zero,
   delete the text from the line as well. */
   delete the text from the line as well. */
static int
static int
region_kill_internal (delete)
region_kill_internal (delete)
     int delete;
     int delete;
{
{
  char *text;
  char *text;
 
 
  if (rl_mark == rl_point)
  if (rl_mark == rl_point)
    {
    {
      _rl_last_command_was_kill++;
      _rl_last_command_was_kill++;
      return 0;
      return 0;
    }
    }
 
 
  text = rl_copy_text (rl_point, rl_mark);
  text = rl_copy_text (rl_point, rl_mark);
  if (delete)
  if (delete)
    rl_delete_text (rl_point, rl_mark);
    rl_delete_text (rl_point, rl_mark);
  _rl_copy_to_kill_ring (text, rl_point < rl_mark);
  _rl_copy_to_kill_ring (text, rl_point < rl_mark);
 
 
  _rl_last_command_was_kill++;
  _rl_last_command_was_kill++;
  return 0;
  return 0;
}
}
 
 
/* Copy the text in the region to the kill ring. */
/* Copy the text in the region to the kill ring. */
int
int
rl_copy_region_to_kill (count, ignore)
rl_copy_region_to_kill (count, ignore)
     int count, ignore;
     int count, ignore;
{
{
  return (region_kill_internal (0));
  return (region_kill_internal (0));
}
}
 
 
/* Kill the text between the point and mark. */
/* Kill the text between the point and mark. */
int
int
rl_kill_region (count, ignore)
rl_kill_region (count, ignore)
     int count, ignore;
     int count, ignore;
{
{
  int r;
  int r;
 
 
  r = region_kill_internal (1);
  r = region_kill_internal (1);
  _rl_fix_point (1);
  _rl_fix_point (1);
  return r;
  return r;
}
}
 
 
/* Copy COUNT words to the kill ring.  DIR says which direction we look
/* Copy COUNT words to the kill ring.  DIR says which direction we look
   to find the words. */
   to find the words. */
static int
static int
_rl_copy_word_as_kill (count, dir)
_rl_copy_word_as_kill (count, dir)
     int count, dir;
     int count, dir;
{
{
  int om, op, r;
  int om, op, r;
 
 
  om = rl_mark;
  om = rl_mark;
  op = rl_point;
  op = rl_point;
 
 
  if (dir > 0)
  if (dir > 0)
    rl_forward_word (count, 0);
    rl_forward_word (count, 0);
  else
  else
    rl_backward_word (count, 0);
    rl_backward_word (count, 0);
 
 
  rl_mark = rl_point;
  rl_mark = rl_point;
 
 
  if (dir > 0)
  if (dir > 0)
    rl_backward_word (count, 0);
    rl_backward_word (count, 0);
  else
  else
    rl_forward_word (count, 0);
    rl_forward_word (count, 0);
 
 
  r = region_kill_internal (0);
  r = region_kill_internal (0);
 
 
  rl_mark = om;
  rl_mark = om;
  rl_point = op;
  rl_point = op;
 
 
  return r;
  return r;
}
}
 
 
int
int
rl_copy_forward_word (count, key)
rl_copy_forward_word (count, key)
     int count, key;
     int count, key;
{
{
  if (count < 0)
  if (count < 0)
    return (rl_copy_backward_word (-count, key));
    return (rl_copy_backward_word (-count, key));
 
 
  return (_rl_copy_word_as_kill (count, 1));
  return (_rl_copy_word_as_kill (count, 1));
}
}
 
 
int
int
rl_copy_backward_word (count, key)
rl_copy_backward_word (count, key)
     int count, key;
     int count, key;
{
{
  if (count < 0)
  if (count < 0)
    return (rl_copy_forward_word (-count, key));
    return (rl_copy_forward_word (-count, key));
 
 
  return (_rl_copy_word_as_kill (count, -1));
  return (_rl_copy_word_as_kill (count, -1));
}
}
 
 
/* Yank back the last killed text.  This ignores arguments. */
/* Yank back the last killed text.  This ignores arguments. */
int
int
rl_yank (count, ignore)
rl_yank (count, ignore)
     int count, ignore;
     int count, ignore;
{
{
  if (rl_kill_ring == 0)
  if (rl_kill_ring == 0)
    {
    {
      _rl_abort_internal ();
      _rl_abort_internal ();
      return -1;
      return -1;
    }
    }
 
 
  _rl_set_mark_at_pos (rl_point);
  _rl_set_mark_at_pos (rl_point);
  rl_insert_text (rl_kill_ring[rl_kill_index]);
  rl_insert_text (rl_kill_ring[rl_kill_index]);
  return 0;
  return 0;
}
}
 
 
/* If the last command was yank, or yank_pop, and the text just
/* If the last command was yank, or yank_pop, and the text just
   before point is identical to the current kill item, then
   before point is identical to the current kill item, then
   delete that text from the line, rotate the index down, and
   delete that text from the line, rotate the index down, and
   yank back some other text. */
   yank back some other text. */
int
int
rl_yank_pop (count, key)
rl_yank_pop (count, key)
     int count, key;
     int count, key;
{
{
  int l, n;
  int l, n;
 
 
  if (((rl_last_func != rl_yank_pop) && (rl_last_func != rl_yank)) ||
  if (((rl_last_func != rl_yank_pop) && (rl_last_func != rl_yank)) ||
      !rl_kill_ring)
      !rl_kill_ring)
    {
    {
      _rl_abort_internal ();
      _rl_abort_internal ();
      return -1;
      return -1;
    }
    }
 
 
  l = strlen (rl_kill_ring[rl_kill_index]);
  l = strlen (rl_kill_ring[rl_kill_index]);
  n = rl_point - l;
  n = rl_point - l;
  if (n >= 0 && STREQN (rl_line_buffer + n, rl_kill_ring[rl_kill_index], l))
  if (n >= 0 && STREQN (rl_line_buffer + n, rl_kill_ring[rl_kill_index], l))
    {
    {
      rl_delete_text (n, rl_point);
      rl_delete_text (n, rl_point);
      rl_point = n;
      rl_point = n;
      rl_kill_index--;
      rl_kill_index--;
      if (rl_kill_index < 0)
      if (rl_kill_index < 0)
        rl_kill_index = rl_kill_ring_length - 1;
        rl_kill_index = rl_kill_ring_length - 1;
      rl_yank (1, 0);
      rl_yank (1, 0);
      return 0;
      return 0;
    }
    }
  else
  else
    {
    {
      _rl_abort_internal ();
      _rl_abort_internal ();
      return -1;
      return -1;
    }
    }
}
}
 
 
/* Yank the COUNTh argument from the previous history line, skipping
/* Yank the COUNTh argument from the previous history line, skipping
   HISTORY_SKIP lines before looking for the `previous line'. */
   HISTORY_SKIP lines before looking for the `previous line'. */
static int
static int
rl_yank_nth_arg_internal (count, ignore, history_skip)
rl_yank_nth_arg_internal (count, ignore, history_skip)
     int count, ignore, history_skip;
     int count, ignore, history_skip;
{
{
  register HIST_ENTRY *entry;
  register HIST_ENTRY *entry;
  char *arg;
  char *arg;
  int i;
  int i;
 
 
  if (history_skip)
  if (history_skip)
    {
    {
      for (i = 0; i < history_skip; i++)
      for (i = 0; i < history_skip; i++)
        entry = previous_history ();
        entry = previous_history ();
    }
    }
 
 
  entry = previous_history ();
  entry = previous_history ();
  if (entry)
  if (entry)
    {
    {
      if (history_skip)
      if (history_skip)
        {
        {
          for (i = 0; i < history_skip; i++)
          for (i = 0; i < history_skip; i++)
            next_history ();
            next_history ();
        }
        }
      next_history ();
      next_history ();
    }
    }
  else
  else
    {
    {
      ding ();
      ding ();
      return -1;
      return -1;
    }
    }
 
 
  arg = history_arg_extract (count, count, entry->line);
  arg = history_arg_extract (count, count, entry->line);
  if (!arg || !*arg)
  if (!arg || !*arg)
    {
    {
      ding ();
      ding ();
      return -1;
      return -1;
    }
    }
 
 
  rl_begin_undo_group ();
  rl_begin_undo_group ();
 
 
#if defined (VI_MODE)
#if defined (VI_MODE)
  /* Vi mode always inserts a space before yanking the argument, and it
  /* Vi mode always inserts a space before yanking the argument, and it
     inserts it right *after* rl_point. */
     inserts it right *after* rl_point. */
  if (rl_editing_mode == vi_mode)
  if (rl_editing_mode == vi_mode)
    {
    {
      rl_vi_append_mode (1, ignore);
      rl_vi_append_mode (1, ignore);
      rl_insert_text (" ");
      rl_insert_text (" ");
    }
    }
#endif /* VI_MODE */
#endif /* VI_MODE */
 
 
  rl_insert_text (arg);
  rl_insert_text (arg);
  free (arg);
  free (arg);
 
 
  rl_end_undo_group ();
  rl_end_undo_group ();
  return 0;
  return 0;
}
}
 
 
/* Yank the COUNTth argument from the previous history line. */
/* Yank the COUNTth argument from the previous history line. */
int
int
rl_yank_nth_arg (count, ignore)
rl_yank_nth_arg (count, ignore)
     int count, ignore;
     int count, ignore;
{
{
  return (rl_yank_nth_arg_internal (count, ignore, 0));
  return (rl_yank_nth_arg_internal (count, ignore, 0));
}
}
 
 
/* Yank the last argument from the previous history line.  This `knows'
/* Yank the last argument from the previous history line.  This `knows'
   how rl_yank_nth_arg treats a count of `$'.  With an argument, this
   how rl_yank_nth_arg treats a count of `$'.  With an argument, this
   behaves the same as rl_yank_nth_arg. */
   behaves the same as rl_yank_nth_arg. */
int
int
rl_yank_last_arg (count, key)
rl_yank_last_arg (count, key)
     int count, key;
     int count, key;
{
{
  static int history_skip = 0;
  static int history_skip = 0;
  static int explicit_arg_p = 0;
  static int explicit_arg_p = 0;
  static int count_passed = 1;
  static int count_passed = 1;
  static int direction = 1;
  static int direction = 1;
  static int undo_needed = 0;
  static int undo_needed = 0;
  int retval;
  int retval;
 
 
  if (rl_last_func != rl_yank_last_arg)
  if (rl_last_func != rl_yank_last_arg)
    {
    {
      history_skip = 0;
      history_skip = 0;
      explicit_arg_p = rl_explicit_arg;
      explicit_arg_p = rl_explicit_arg;
      count_passed = count;
      count_passed = count;
      direction = 1;
      direction = 1;
    }
    }
  else
  else
    {
    {
      if (undo_needed)
      if (undo_needed)
        rl_do_undo ();
        rl_do_undo ();
      if (count < 1)
      if (count < 1)
        direction = -direction;
        direction = -direction;
      history_skip += direction;
      history_skip += direction;
      if (history_skip < 0)
      if (history_skip < 0)
        history_skip = 0;
        history_skip = 0;
    }
    }
 
 
  if (explicit_arg_p)
  if (explicit_arg_p)
    retval = rl_yank_nth_arg_internal (count_passed, key, history_skip);
    retval = rl_yank_nth_arg_internal (count_passed, key, history_skip);
  else
  else
    retval = rl_yank_nth_arg_internal ('$', key, history_skip);
    retval = rl_yank_nth_arg_internal ('$', key, history_skip);
 
 
  undo_needed = retval == 0;
  undo_needed = retval == 0;
  return retval;
  return retval;
}
}
 
 
/* A special paste command for users of Cygnus's cygwin32. */
/* A special paste command for users of Cygnus's cygwin32. */
#if defined (__CYGWIN32__)
#if defined (__CYGWIN32__)
#include <windows.h>
#include <windows.h>
 
 
int
int
rl_paste_from_clipboard (count, key)
rl_paste_from_clipboard (count, key)
     int count, key;
     int count, key;
{
{
  char *data, *ptr;
  char *data, *ptr;
  int len;
  int len;
 
 
  if (OpenClipboard (NULL) == 0)
  if (OpenClipboard (NULL) == 0)
    return (0);
    return (0);
 
 
  data = (char *)GetClipboardData (CF_TEXT);
  data = (char *)GetClipboardData (CF_TEXT);
  if (data)
  if (data)
    {
    {
      ptr = strchr (data, '\r');
      ptr = strchr (data, '\r');
      if (ptr)
      if (ptr)
        {
        {
          len = ptr - data;
          len = ptr - data;
          ptr = xmalloc (len + 1);
          ptr = xmalloc (len + 1);
          ptr[len] = '\0';
          ptr[len] = '\0';
          strncpy (ptr, data, len);
          strncpy (ptr, data, len);
        }
        }
      else
      else
        ptr = data;
        ptr = data;
      rl_insert_text (ptr);
      rl_insert_text (ptr);
      if (ptr != data)
      if (ptr != data)
        free (ptr);
        free (ptr);
      CloseClipboard ();
      CloseClipboard ();
    }
    }
  return (0);
  return (0);
}
}
#endif /* __CYGWIN32__ */
#endif /* __CYGWIN32__ */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.