1/* $NetBSD: ex_undo.c,v 1.1.1.2 2008/05/18 14:31:20 aymeric Exp $ */ 2 3/*- 4 * Copyright (c) 1992, 1993, 1994 5 * The Regents of the University of California. All rights reserved. 6 * Copyright (c) 1992, 1993, 1994, 1995, 1996 7 * Keith Bostic. All rights reserved. 8 * 9 * See the LICENSE file for redistribution information. 10 */ 11 12#include "config.h" 13 14#ifndef lint 15static const char sccsid[] = "Id: ex_undo.c,v 10.7 2001/06/25 15:19:21 skimo Exp (Berkeley) Date: 2001/06/25 15:19:21"; 16#endif /* not lint */ 17 18#include <sys/types.h> 19#include <sys/queue.h> 20 21#include <bitstring.h> 22#include <limits.h> 23#include <stdio.h> 24#include <stdlib.h> 25 26#include "../common/common.h" 27 28/* 29 * ex_undo -- u 30 * Undo the last change. 31 * 32 * PUBLIC: int ex_undo __P((SCR *, EXCMD *)); 33 */ 34int 35ex_undo(SCR *sp, EXCMD *cmdp) 36{ 37 EXF *ep; 38 MARK m; 39 40 /* 41 * !!! 42 * Historic undo always set the previous context mark. 43 */ 44 m.lno = sp->lno; 45 m.cno = sp->cno; 46 if (mark_set(sp, ABSMARK1, &m, 1)) 47 return (1); 48 49 /* 50 * !!! 51 * Multiple undo isn't available in ex, as there's no '.' command. 52 * Whether 'u' is undo or redo is toggled each time, unless there 53 * was a change since the last undo, in which case it's an undo. 54 */ 55 ep = sp->ep; 56 if (!F_ISSET(ep, F_UNDO)) { 57 F_SET(ep, F_UNDO); 58 ep->lundo = FORWARD; 59 } 60 switch (ep->lundo) { 61 case BACKWARD: 62 if (log_forward(sp, &m)) 63 return (1); 64 ep->lundo = FORWARD; 65 break; 66 case FORWARD: 67 if (log_backward(sp, &m)) 68 return (1); 69 ep->lundo = BACKWARD; 70 break; 71 case NOTSET: 72 abort(); 73 } 74 sp->lno = m.lno; 75 sp->cno = m.cno; 76 return (0); 77} 78