rework initial error handling -- since we check for any screens on
[nvi.git] / ex / ex_undo.c
blob5a8c0977d26e2bea61e8a0d02272f78eb49107bb
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.4 1993/12/29 16:12:04 bostic Exp $ (Berkeley) $Date: 1993/12/29 16:12:04 $";
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.
21 int
22 ex_undol(sp, ep, cmdp)
23 SCR *sp;
24 EXF *ep;
25 EXCMDARG *cmdp;
27 if (log_setline(sp, ep))
28 return (1);
30 sp->cno = 0;
31 return (0);
35 * ex_undo -- u
36 * Undo the last change.
38 int
39 ex_undo(sp, ep, cmdp)
40 SCR *sp;
41 EXF *ep;
42 EXCMDARG *cmdp;
44 MARK m;
47 * !!!
48 * Multiple undo isn't available in ex, as there's no '.' command.
49 * Whether 'u' is undo or redo is toggled each time, unless there
50 * was a change since the last undo, in which case it's an undo.
52 if (!F_ISSET(ep, F_UNDO)) {
53 F_SET(ep, F_UNDO);
54 ep->lundo = FORWARD;
56 switch (ep->lundo) {
57 case BACKWARD:
58 if (log_forward(sp, ep, &m))
59 return (1);
60 ep->lundo = FORWARD;
61 break;
62 case FORWARD:
63 if (log_backward(sp, ep, &m))
64 return (1);
65 ep->lundo = BACKWARD;
66 break;
67 case NOTSET:
68 abort();
70 sp->lno = m.lno;
71 sp->cno = m.cno;
72 return (0);