bug, wrong value to getcount for 'z' command
[nvi.git] / vi / v_undo.c
blob266ef645a63c01ccf911ae0ccc4ed886594ea517
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: v_undo.c,v 8.1 1993/06/09 22:28:33 bostic Exp $ (Berkeley) $Date: 1993/06/09 22:28:33 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include <errno.h>
15 #include <stdlib.h>
16 #include <string.h>
18 #include "vi.h"
19 #include "vcmd.h"
22 * v_Undo -- U
23 * Undo changes to this line, or roll forward.
25 * Historic vi moved the cursor to the first non-blank character
26 * of the line when this happened. We do not, since we know where
27 * the cursor actually was when the changes began.
29 int
30 v_Undo(sp, ep, vp, fm, tm, rp)
31 SCR *sp;
32 EXF *ep;
33 VICMDARG *vp;
34 MARK *fm, *tm, *rp;
36 if (O_ISSET(sp, O_NUNDO))
37 return (log_forward(sp, ep, rp));
38 return (log_setline(sp, ep, rp));
42 * v_undo -- u
43 * Undo the last change.
45 int
46 v_undo(sp, ep, vp, fm, tm, rp)
47 SCR *sp;
48 EXF *ep;
49 VICMDARG *vp;
50 MARK *fm, *tm, *rp;
52 if (O_ISSET(sp, O_NUNDO))
53 return (log_backward(sp, ep, rp));
55 if (!F_ISSET(ep, F_UNDO)) {
56 ep->lundo = UFORWARD;
57 F_SET(ep, F_UNDO);
60 switch (ep->lundo) {
61 case UBACKWARD:
62 if (log_forward(sp, ep, rp)) {
63 F_CLR(ep, F_UNDO);
64 return (1);
66 ep->lundo = UFORWARD;
67 break;
68 case UFORWARD:
69 if (log_backward(sp, ep, rp)) {
70 F_CLR(ep, F_UNDO);
71 return (1);
73 ep->lundo = UBACKWARD;
74 break;
76 return (0);