/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* undo.c: multi level undo facility
*
* The saved lines are stored in a list of lists (one for each buffer):
*
* b_u_oldhead------------------------------------------------+
* |
* V
* +--------------+ +--------------+ +--------------+
* b_u_newhead--->| u_header | | u_header | | u_header |
* | uh_next------>| uh_next------>| uh_next---->NULL
* NULL<--------uh_prev |<---------uh_prev |<---------uh_prev |
* | uh_entry | | uh_entry | | uh_entry |
* +--------|-----+ +--------|-----+ +--------|-----+
* | | |
* V V V
* +--------------+ +--------------+ +--------------+
* | u_entry | | u_entry | | u_entry |
* | ue_next | | ue_next | | ue_next |
* +--------|-----+ +--------|-----+ +--------|-----+
* | | |
* V V V
* +--------------+ NULL NULL
* | u_entry |
* | ue_next |
* +--------|-----+
* |
* V
* etc.
*
* Each u_entry list contains the information for one undo or redo.
* curbuf->b_u_curhead points to the header of the last undo (the next redo),
* or is NULL if nothing has been undone.
*
* All data is allocated with U_ALLOC_LINE(), it will be freed as soon as the
* buffer is unloaded.
*/
#include "vim.h"
/* See below: use malloc()/free() for memory management. */
#define U_USE_MALLOC 1
static u_entry_T *u_get_headentry __ARGS((void));
static void u_getbot __ARGS((void));
static int u_savecommon __ARGS((linenr_T, linenr_T, linenr_T));
static void u_doit __ARGS((int count));
static void u_undoredo __ARGS((void));
static void u_undo_end __ARGS((void));
static void u_freelist __ARGS((buf_T *buf, struct u_header *));
static void u_freeentry __ARGS((u_entry_T *, long));
#ifdef U_USE_MALLOC
# define U_FREE_LINE(ptr) vim_free(ptr)
# define U_ALLOC_LINE(size) lalloc((long_u)((size) + 1), FALSE)
#else
static