lint
[nvi.git] / ex / ex_undo.c
blob91efe32aad43172d44dde26660954da6ccf155de
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: ex_undo.c,v 8.1 1993/06/09 22:26:06 bostic Exp $ (Berkeley) $Date: 1993/06/09 22:26:06 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include "vi.h"
15 #include "excmd.h"
18 * ex_undol -- U
19 * Undo changes to this line, or roll forward.
21 int
22 ex_undol(sp, ep, cmdp)
23 SCR *sp;
24 EXF *ep;
25 EXCMDARG *cmdp;
27 MARK m;
29 if (O_ISSET(sp, O_NUNDO)) {
30 if (log_forward(sp, ep, &m))
31 return (1);
32 } else {
33 if (log_setline(sp, ep, &m))
34 return (1);
37 sp->lno = m.lno;
38 sp->cno = m.cno;
40 F_SET(sp, S_AUTOPRINT);
42 return (0);
46 * ex_undo -- u
47 * Undo the last change.
49 int
50 ex_undo(sp, ep, cmdp)
51 SCR *sp;
52 EXF *ep;
53 EXCMDARG *cmdp;
55 MARK m;
57 if (O_ISSET(sp, O_NUNDO)) {
58 if (log_backward(sp, ep, &m))
59 return (1);
60 } else {
61 if (!F_ISSET(ep, F_UNDO)) {
62 ep->lundo = UFORWARD;
63 F_SET(ep, F_UNDO);
66 switch (ep->lundo) {
67 case UBACKWARD:
68 if (log_forward(sp, ep, &m)) {
69 F_CLR(ep, F_UNDO);
70 return (1);
72 ep->lundo = UFORWARD;
73 break;
74 case UFORWARD:
75 if (log_backward(sp, ep, &m)) {
76 F_CLR(ep, F_UNDO);
77 return (1);
79 ep->lundo = UBACKWARD;
80 break;
83 sp->lno = m.lno;
84 sp->cno = m.cno;
86 F_SET(sp, S_AUTOPRINT);
88 return (0);