ref: 15fe0eb1c1c82b9a90fdb924ae04a3c3e2cc23ad
dir: /undo.c/
#include <u.h> #include <libc.h> #include <draw.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; 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; } void pushundo(int action, int index, uchar value, uchar newvalue) { 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; } void patchundo(uchar value) { ustack[ucur].newvalue = value; }