ex_undo.c revision 19304
119304Speter/*- 219304Speter * Copyright (c) 1992, 1993, 1994 319304Speter * The Regents of the University of California. All rights reserved. 419304Speter * Copyright (c) 1992, 1993, 1994, 1995, 1996 519304Speter * Keith Bostic. All rights reserved. 619304Speter * 719304Speter * See the LICENSE file for redistribution information. 819304Speter */ 919304Speter 1019304Speter#include "config.h" 1119304Speter 1219304Speter#ifndef lint 1319304Speterstatic const char sccsid[] = "@(#)ex_undo.c 10.6 (Berkeley) 3/6/96"; 1419304Speter#endif /* not lint */ 1519304Speter 1619304Speter#include <sys/types.h> 1719304Speter#include <sys/queue.h> 1819304Speter 1919304Speter#include <bitstring.h> 2019304Speter#include <limits.h> 2119304Speter#include <stdio.h> 2219304Speter#include <stdlib.h> 2319304Speter 2419304Speter#include "../common/common.h" 2519304Speter 2619304Speter/* 2719304Speter * ex_undo -- u 2819304Speter * Undo the last change. 2919304Speter * 3019304Speter * PUBLIC: int ex_undo __P((SCR *, EXCMD *)); 3119304Speter */ 3219304Speterint 3319304Speterex_undo(sp, cmdp) 3419304Speter SCR *sp; 3519304Speter EXCMD *cmdp; 3619304Speter{ 3719304Speter EXF *ep; 3819304Speter MARK m; 3919304Speter 4019304Speter /* 4119304Speter * !!! 4219304Speter * Historic undo always set the previous context mark. 4319304Speter */ 4419304Speter m.lno = sp->lno; 4519304Speter m.cno = sp->cno; 4619304Speter if (mark_set(sp, ABSMARK1, &m, 1)) 4719304Speter return (1); 4819304Speter 4919304Speter /* 5019304Speter * !!! 5119304Speter * Multiple undo isn't available in ex, as there's no '.' command. 5219304Speter * Whether 'u' is undo or redo is toggled each time, unless there 5319304Speter * was a change since the last undo, in which case it's an undo. 5419304Speter */ 5519304Speter ep = sp->ep; 5619304Speter if (!F_ISSET(ep, F_UNDO)) { 5719304Speter F_SET(ep, F_UNDO); 5819304Speter ep->lundo = FORWARD; 5919304Speter } 6019304Speter switch (ep->lundo) { 6119304Speter case BACKWARD: 6219304Speter if (log_forward(sp, &m)) 6319304Speter return (1); 6419304Speter ep->lundo = FORWARD; 6519304Speter break; 6619304Speter case FORWARD: 6719304Speter if (log_backward(sp, &m)) 6819304Speter return (1); 6919304Speter ep->lundo = BACKWARD; 7019304Speter break; 7119304Speter case NOTSET: 7219304Speter abort(); 7319304Speter } 7419304Speter sp->lno = m.lno; 7519304Speter sp->cno = m.cno; 7619304Speter return (0); 7719304Speter} 78