View of xos/usr/lib/readline/kill.c


XOS | Parent Directory | View | Download

/* Copyright (C) 2008  Emmanuel Varoquaux
 
   This file is part of XOS.
 
   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
 
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
#include "kill.h"
 
#include <string.h>
 
#define KILL_RING_SIZE 10
 
static char *kill_ring[KILL_RING_SIZE];
static int last = -1;
static int top = -1;
 
void kill_ring_add(char *text)
{
  if (last == -1)
    last = 0;
  else if (last == KILL_RING_SIZE - 1)
    memmove(kill_ring, kill_ring + 1, (KILL_RING_SIZE - 1) * sizeof (char *));
  else
    last++;
  kill_ring[last] = text;
  top = last;
}
 
char *kill_ring_get()
{
  if (top == -1)
    return NULL;
  return kill_ring[top];
}
 
/* Doit etre appele apres un kill_ring_add() et avant un kill_ring_rotate(). */
void kill_ring_replace(char *text)
{
  kill_ring[last] = text;
}
 
char *kill_ring_rotate()
{
  if (top == -1)
    return NULL;
  if (top == 0)
    top = last;
  else
    top--;
  return kill_ring[top];
}