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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [readline/] [undo.c] - Diff between revs 834 and 842

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

Rev 834 Rev 842
/* readline.c -- a general facility for reading lines of input
/* readline.c -- a general facility for reading lines of input
   with emacs style editing and completion. */
   with emacs style editing and completion. */
 
 
/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
/* Copyright (C) 1987, 1989, 1992 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 2, or
   as published by the Free Software Foundation; either version 2, 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,
   59 Temple Place, Suite 330, Boston, MA 02111 USA. */
   59 Temple Place, Suite 330, Boston, MA 02111 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"
 
 
#include "rlprivate.h"
#include "rlprivate.h"
#include "xmalloc.h"
#include "xmalloc.h"
 
 
/* Non-zero tells rl_delete_text and rl_insert_text to not add to
/* Non-zero tells rl_delete_text and rl_insert_text to not add to
   the undo list. */
   the undo list. */
int _rl_doing_an_undo = 0;
int _rl_doing_an_undo = 0;
 
 
/* How many unclosed undo groups we currently have. */
/* How many unclosed undo groups we currently have. */
int _rl_undo_group_level = 0;
int _rl_undo_group_level = 0;
 
 
/* The current undo list for THE_LINE. */
/* The current undo list for THE_LINE. */
UNDO_LIST *rl_undo_list = (UNDO_LIST *)NULL;
UNDO_LIST *rl_undo_list = (UNDO_LIST *)NULL;
 
 
/* **************************************************************** */
/* **************************************************************** */
/*                                                                  */
/*                                                                  */
/*                      Undo, and Undoing                           */
/*                      Undo, and Undoing                           */
/*                                                                  */
/*                                                                  */
/* **************************************************************** */
/* **************************************************************** */
 
 
/* Remember how to undo something.  Concatenate some undos if that
/* Remember how to undo something.  Concatenate some undos if that
   seems right. */
   seems right. */
void
void
rl_add_undo (what, start, end, text)
rl_add_undo (what, start, end, text)
     enum undo_code what;
     enum undo_code what;
     int start, end;
     int start, end;
     char *text;
     char *text;
{
{
  UNDO_LIST *temp = (UNDO_LIST *)xmalloc (sizeof (UNDO_LIST));
  UNDO_LIST *temp = (UNDO_LIST *)xmalloc (sizeof (UNDO_LIST));
  temp->what = what;
  temp->what = what;
  temp->start = start;
  temp->start = start;
  temp->end = end;
  temp->end = end;
  temp->text = text;
  temp->text = text;
  temp->next = rl_undo_list;
  temp->next = rl_undo_list;
  rl_undo_list = temp;
  rl_undo_list = temp;
}
}
 
 
/* Free the existing undo list. */
/* Free the existing undo list. */
void
void
rl_free_undo_list ()
rl_free_undo_list ()
{
{
  while (rl_undo_list)
  while (rl_undo_list)
    {
    {
      UNDO_LIST *release = rl_undo_list;
      UNDO_LIST *release = rl_undo_list;
      rl_undo_list = rl_undo_list->next;
      rl_undo_list = rl_undo_list->next;
 
 
      if (release->what == UNDO_DELETE)
      if (release->what == UNDO_DELETE)
        free (release->text);
        free (release->text);
 
 
      free (release);
      free (release);
    }
    }
  rl_undo_list = (UNDO_LIST *)NULL;
  rl_undo_list = (UNDO_LIST *)NULL;
}
}
 
 
/* Undo the next thing in the list.  Return 0 if there
/* Undo the next thing in the list.  Return 0 if there
   is nothing to undo, or non-zero if there was. */
   is nothing to undo, or non-zero if there was. */
int
int
rl_do_undo ()
rl_do_undo ()
{
{
  UNDO_LIST *release;
  UNDO_LIST *release;
  int waiting_for_begin, start, end;
  int waiting_for_begin, start, end;
 
 
#define TRANS(i) ((i) == -1 ? rl_point : ((i) == -2 ? rl_end : (i)))
#define TRANS(i) ((i) == -1 ? rl_point : ((i) == -2 ? rl_end : (i)))
 
 
  start = end = waiting_for_begin = 0;
  start = end = waiting_for_begin = 0;
  do
  do
    {
    {
      if (!rl_undo_list)
      if (!rl_undo_list)
        return (0);
        return (0);
 
 
      _rl_doing_an_undo = 1;
      _rl_doing_an_undo = 1;
      RL_SETSTATE(RL_STATE_UNDOING);
      RL_SETSTATE(RL_STATE_UNDOING);
 
 
      /* To better support vi-mode, a start or end value of -1 means
      /* To better support vi-mode, a start or end value of -1 means
         rl_point, and a value of -2 means rl_end. */
         rl_point, and a value of -2 means rl_end. */
      if (rl_undo_list->what == UNDO_DELETE || rl_undo_list->what == UNDO_INSERT)
      if (rl_undo_list->what == UNDO_DELETE || rl_undo_list->what == UNDO_INSERT)
        {
        {
          start = TRANS (rl_undo_list->start);
          start = TRANS (rl_undo_list->start);
          end = TRANS (rl_undo_list->end);
          end = TRANS (rl_undo_list->end);
        }
        }
 
 
      switch (rl_undo_list->what)
      switch (rl_undo_list->what)
        {
        {
        /* Undoing deletes means inserting some text. */
        /* Undoing deletes means inserting some text. */
        case UNDO_DELETE:
        case UNDO_DELETE:
          rl_point = start;
          rl_point = start;
          rl_insert_text (rl_undo_list->text);
          rl_insert_text (rl_undo_list->text);
          free (rl_undo_list->text);
          free (rl_undo_list->text);
          break;
          break;
 
 
        /* Undoing inserts means deleting some text. */
        /* Undoing inserts means deleting some text. */
        case UNDO_INSERT:
        case UNDO_INSERT:
          rl_delete_text (start, end);
          rl_delete_text (start, end);
          rl_point = start;
          rl_point = start;
          break;
          break;
 
 
        /* Undoing an END means undoing everything 'til we get to a BEGIN. */
        /* Undoing an END means undoing everything 'til we get to a BEGIN. */
        case UNDO_END:
        case UNDO_END:
          waiting_for_begin++;
          waiting_for_begin++;
          break;
          break;
 
 
        /* Undoing a BEGIN means that we are done with this group. */
        /* Undoing a BEGIN means that we are done with this group. */
        case UNDO_BEGIN:
        case UNDO_BEGIN:
          if (waiting_for_begin)
          if (waiting_for_begin)
            waiting_for_begin--;
            waiting_for_begin--;
          else
          else
            rl_ding ();
            rl_ding ();
          break;
          break;
        }
        }
 
 
      _rl_doing_an_undo = 0;
      _rl_doing_an_undo = 0;
      RL_UNSETSTATE(RL_STATE_UNDOING);
      RL_UNSETSTATE(RL_STATE_UNDOING);
 
 
      release = rl_undo_list;
      release = rl_undo_list;
      rl_undo_list = rl_undo_list->next;
      rl_undo_list = rl_undo_list->next;
      free (release);
      free (release);
    }
    }
  while (waiting_for_begin);
  while (waiting_for_begin);
 
 
  return (1);
  return (1);
}
}
#undef TRANS
#undef TRANS
 
 
int
int
_rl_fix_last_undo_of_type (type, start, end)
_rl_fix_last_undo_of_type (type, start, end)
     int type, start, end;
     int type, start, end;
{
{
  UNDO_LIST *rl;
  UNDO_LIST *rl;
 
 
  for (rl = rl_undo_list; rl; rl = rl->next)
  for (rl = rl_undo_list; rl; rl = rl->next)
    {
    {
      if (rl->what == type)
      if (rl->what == type)
        {
        {
          rl->start = start;
          rl->start = start;
          rl->end = end;
          rl->end = end;
          return 0;
          return 0;
        }
        }
    }
    }
  return 1;
  return 1;
}
}
 
 
/* Begin a group.  Subsequent undos are undone as an atomic operation. */
/* Begin a group.  Subsequent undos are undone as an atomic operation. */
int
int
rl_begin_undo_group ()
rl_begin_undo_group ()
{
{
  rl_add_undo (UNDO_BEGIN, 0, 0, 0);
  rl_add_undo (UNDO_BEGIN, 0, 0, 0);
  _rl_undo_group_level++;
  _rl_undo_group_level++;
  return 0;
  return 0;
}
}
 
 
/* End an undo group started with rl_begin_undo_group (). */
/* End an undo group started with rl_begin_undo_group (). */
int
int
rl_end_undo_group ()
rl_end_undo_group ()
{
{
  rl_add_undo (UNDO_END, 0, 0, 0);
  rl_add_undo (UNDO_END, 0, 0, 0);
  _rl_undo_group_level--;
  _rl_undo_group_level--;
  return 0;
  return 0;
}
}
 
 
/* Save an undo entry for the text from START to END. */
/* Save an undo entry for the text from START to END. */
int
int
rl_modifying (start, end)
rl_modifying (start, end)
     int start, end;
     int start, end;
{
{
  if (start > end)
  if (start > end)
    {
    {
      SWAP (start, end);
      SWAP (start, end);
    }
    }
 
 
  if (start != end)
  if (start != end)
    {
    {
      char *temp = rl_copy_text (start, end);
      char *temp = rl_copy_text (start, end);
      rl_begin_undo_group ();
      rl_begin_undo_group ();
      rl_add_undo (UNDO_DELETE, start, end, temp);
      rl_add_undo (UNDO_DELETE, start, end, temp);
      rl_add_undo (UNDO_INSERT, start, end, (char *)NULL);
      rl_add_undo (UNDO_INSERT, start, end, (char *)NULL);
      rl_end_undo_group ();
      rl_end_undo_group ();
    }
    }
  return 0;
  return 0;
}
}
 
 
/* Revert the current line to its previous state. */
/* Revert the current line to its previous state. */
int
int
rl_revert_line (count, key)
rl_revert_line (count, key)
     int count, key;
     int count, key;
{
{
  if (!rl_undo_list)
  if (!rl_undo_list)
    rl_ding ();
    rl_ding ();
  else
  else
    {
    {
      while (rl_undo_list)
      while (rl_undo_list)
        rl_do_undo ();
        rl_do_undo ();
#if defined (VI_MODE)
#if defined (VI_MODE)
      if (rl_editing_mode == vi_mode)
      if (rl_editing_mode == vi_mode)
        rl_point = rl_mark = 0;          /* rl_end should be set correctly */
        rl_point = rl_mark = 0;          /* rl_end should be set correctly */
#endif
#endif
    }
    }
 
 
  return 0;
  return 0;
}
}
 
 
/* Do some undoing of things that were done. */
/* Do some undoing of things that were done. */
int
int
rl_undo_command (count, key)
rl_undo_command (count, key)
     int count, key;
     int count, key;
{
{
  if (count < 0)
  if (count < 0)
    return 0;    /* Nothing to do. */
    return 0;    /* Nothing to do. */
 
 
  while (count)
  while (count)
    {
    {
      if (rl_do_undo ())
      if (rl_do_undo ())
        count--;
        count--;
      else
      else
        {
        {
          rl_ding ();
          rl_ding ();
          break;
          break;
        }
        }
    }
    }
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

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