move configure.in to configure.ac
[nvi.git] / ex / ex_undo.c
blob0fac6d8ccba5623425d3bf045591fa5f4a675bcf
1 /*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static 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 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
20 #include <limits.h>
21 #include <stdio.h>
22 #include <stdlib.h>
24 #include "../common/common.h"
27 * ex_undo -- u
28 * Undo the last change.
30 * PUBLIC: int ex_undo __P((SCR *, EXCMD *));
32 int
33 ex_undo(SCR *sp, EXCMD *cmdp)
35 EXF *ep;
36 MARK m;
39 * !!!
40 * Historic undo always set the previous context mark.
42 m.lno = sp->lno;
43 m.cno = sp->cno;
44 if (mark_set(sp, ABSMARK1, &m, 1))
45 return (1);
48 * !!!
49 * Multiple undo isn't available in ex, as there's no '.' command.
50 * Whether 'u' is undo or redo is toggled each time, unless there
51 * was a change since the last undo, in which case it's an undo.
53 ep = sp->ep;
54 if (!F_ISSET(ep, F_UNDO)) {
55 F_SET(ep, F_UNDO);
56 ep->lundo = FORWARD;
58 switch (ep->lundo) {
59 case BACKWARD:
60 if (log_forward(sp, &m))
61 return (1);
62 ep->lundo = FORWARD;
63 break;
64 case FORWARD:
65 if (log_backward(sp, &m))
66 return (1);
67 ep->lundo = BACKWARD;
68 break;
69 case NOTSET:
70 abort();
72 sp->lno = m.lno;
73 sp->cno = m.cno;
74 return (0);