-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathundo.c
66 lines (58 loc) · 1.09 KB
/
undo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <mouse.h>
#include <keyboard.h>
#include "a.h"
enum { Stacksize = 1024 };
Undo ustack[Stacksize];
int ucount = 0;
int ucur = -1;
int
canundo(void)
{
return ucur >= 0;
}
void
undo(Undo *undo)
{
undo->action = ustack[ucur].action;
undo->index = ustack[ucur].index;
undo->value = ustack[ucur].value;
undo->newvalue = ustack[ucur].newvalue;
undo->modified = ustack[ucur].modified;
ucur -= 1;
}
int
canredo(void)
{
return ucur < ucount - 1;
}
void
redo(Undo *undo)
{
ucur += 1;
undo->action = ustack[ucur].action;
undo->index = ustack[ucur].index;
undo->value = ustack[ucur].value;
undo->newvalue = ustack[ucur].newvalue;
undo->modified = ustack[ucur].modified;
}
void
pushundo(int action, int index, uchar value, uchar newvalue, int modified)
{
if(ucur == Stacksize - 1)
return;
ucur += 1;
ucount = ucur + 1;
ustack[ucur].action = action;
ustack[ucur].index = index;
ustack[ucur].value = value;
ustack[ucur].newvalue = newvalue;
ustack[ucur].modified = modified;
}
void
patchundo(uchar value)
{
ustack[ucur].newvalue = value;
}