2021-05-23 11:43:28 +02:00
|
|
|
(*
|
2023-02-22 16:56:05 +01:00
|
|
|
Copyright 2021-2023 Anton Krotov
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
This file is part of CEdit.
|
|
|
|
|
|
|
|
CEdit is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
CEdit is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with CEdit. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE ChangeLog;
|
|
|
|
|
2021-12-20 20:09:01 +01:00
|
|
|
IMPORT List, Lines, API, SYSTEM;
|
2021-05-23 11:43:28 +02:00
|
|
|
|
2023-02-24 16:02:24 +01:00
|
|
|
CONST
|
|
|
|
boolItemSize = 8;
|
|
|
|
fillMap = {0..boolItemSize-1};
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
TYPE
|
2023-02-24 16:02:24 +01:00
|
|
|
tIntItem = POINTER TO RECORD (List.tItem)
|
|
|
|
cnt: INTEGER;
|
|
|
|
adr, val: ARRAY 8 OF INTEGER
|
|
|
|
END;
|
|
|
|
|
|
|
|
tBoolItem = POINTER TO RECORD (List.tItem)
|
|
|
|
map: SET;
|
|
|
|
data: ARRAY boolItemSize OF
|
|
|
|
RECORD
|
|
|
|
line: Lines.tLine;
|
|
|
|
adr: INTEGER;
|
|
|
|
val, save: BOOLEAN
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
tUntypedPtr = POINTER TO RECORD (List.tItem)
|
|
|
|
cnt: INTEGER;
|
|
|
|
p: ARRAY 64 OF INTEGER
|
|
|
|
END;
|
|
|
|
|
|
|
|
tTypedPtr = POINTER TO RECORD (List.tItem)
|
|
|
|
cnt: INTEGER;
|
|
|
|
p: ARRAY 64 OF List.tItem
|
|
|
|
END;
|
|
|
|
|
|
|
|
tGuard* = POINTER TO RECORD (List.tItem)
|
|
|
|
saved*: BOOLEAN
|
|
|
|
END;
|
|
|
|
|
|
|
|
tLog* = POINTER TO RECORD
|
|
|
|
Log*, TPointers, UPointers: List.tList;
|
|
|
|
guard, first: tGuard;
|
|
|
|
isLast: BOOLEAN
|
|
|
|
END;
|
2021-07-11 01:39:41 +02:00
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
VAR
|
2023-02-24 16:02:24 +01:00
|
|
|
CL*: tLog;
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isLastGuard* (guard: tGuard): BOOLEAN;
|
|
|
|
VAR
|
2023-02-24 16:02:24 +01:00
|
|
|
item: List.tItem;
|
|
|
|
res: BOOLEAN;
|
2021-05-23 11:43:28 +02:00
|
|
|
BEGIN
|
2023-02-24 16:02:24 +01:00
|
|
|
IF guard # NIL THEN
|
|
|
|
item := CL.Log.last;
|
|
|
|
WHILE ~(item IS tGuard) DO
|
|
|
|
item := item.prev
|
|
|
|
END;
|
|
|
|
res := guard = item
|
|
|
|
ELSE
|
|
|
|
res := TRUE
|
|
|
|
END
|
|
|
|
RETURN res
|
2021-05-23 11:43:28 +02:00
|
|
|
END isLastGuard;
|
|
|
|
|
|
|
|
|
2022-01-24 23:03:13 +01:00
|
|
|
PROCEDURE getFirstGuard (): tGuard;
|
2021-05-23 11:43:28 +02:00
|
|
|
VAR
|
2022-01-24 23:03:13 +01:00
|
|
|
item: List.tItem;
|
2021-05-23 11:43:28 +02:00
|
|
|
BEGIN
|
2022-01-24 23:03:13 +01:00
|
|
|
item := CL.Log.first;
|
|
|
|
WHILE ~(item IS tGuard) DO
|
|
|
|
item := item.next
|
|
|
|
END
|
|
|
|
RETURN item(tGuard)
|
|
|
|
END getFirstGuard;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isFirstGuard* (guard: tGuard): BOOLEAN;
|
|
|
|
BEGIN
|
|
|
|
ASSERT(guard # NIL);
|
|
|
|
IF CL.first = NIL THEN
|
|
|
|
CL.first := getFirstGuard()
|
|
|
|
END
|
|
|
|
RETURN guard = CL.first
|
2021-05-23 11:43:28 +02:00
|
|
|
END isFirstGuard;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE setGuard* (_guard: tGuard);
|
|
|
|
BEGIN
|
2023-02-24 16:02:24 +01:00
|
|
|
CL.guard := _guard;
|
|
|
|
CL.isLast := isLastGuard(_guard)
|
2021-05-23 11:43:28 +02:00
|
|
|
END setGuard;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE redo* (item: List.tItem);
|
2023-02-22 16:56:05 +01:00
|
|
|
VAR
|
|
|
|
i: INTEGER;
|
2021-05-23 11:43:28 +02:00
|
|
|
BEGIN
|
2023-02-22 16:56:05 +01:00
|
|
|
IF item IS tIntItem THEN
|
|
|
|
FOR i := 0 TO item(tIntItem).cnt - 1 DO
|
|
|
|
SYSTEM.PUT(item(tIntItem).adr[i], item(tIntItem).val[i])
|
|
|
|
END
|
|
|
|
ELSIF item IS tBoolItem THEN
|
2023-02-24 16:02:24 +01:00
|
|
|
FOR i := 0 TO boolItemSize - 1 DO
|
|
|
|
IF i IN item(tBoolItem).map THEN
|
|
|
|
SYSTEM.PUT(item(tBoolItem).data[i].adr, item(tBoolItem).data[i].val)
|
|
|
|
END
|
|
|
|
END
|
2023-02-22 16:56:05 +01:00
|
|
|
END
|
2021-05-23 11:43:28 +02:00
|
|
|
END redo;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE clear (guard: tGuard);
|
|
|
|
VAR
|
2023-02-24 16:02:24 +01:00
|
|
|
item: List.tItem;
|
2021-05-23 11:43:28 +02:00
|
|
|
BEGIN
|
2023-02-24 16:02:24 +01:00
|
|
|
CL.isLast := TRUE;
|
|
|
|
REPEAT
|
|
|
|
item := List.pop(CL.Log);
|
|
|
|
IF item # guard THEN
|
|
|
|
DISPOSE(item)
|
|
|
|
END
|
|
|
|
UNTIL item = guard;
|
|
|
|
List.append(CL.Log, item)
|
2021-05-23 11:43:28 +02:00
|
|
|
END clear;
|
|
|
|
|
|
|
|
|
2021-07-21 18:13:29 +02:00
|
|
|
PROCEDURE save* (guard: tGuard);
|
|
|
|
VAR
|
2021-12-21 17:19:39 +01:00
|
|
|
item: List.tItem;
|
|
|
|
boolItem: tBoolItem;
|
|
|
|
cur: List.tItem;
|
2023-02-24 16:02:24 +01:00
|
|
|
i: INTEGER;
|
2021-07-21 18:13:29 +02:00
|
|
|
BEGIN
|
2023-02-24 16:02:24 +01:00
|
|
|
item := CL.Log.first;
|
|
|
|
WHILE item # NIL DO
|
|
|
|
IF item IS tGuard THEN
|
|
|
|
item(tGuard).saved := FALSE
|
|
|
|
END;
|
|
|
|
item := item.next
|
|
|
|
END;
|
|
|
|
guard.saved := TRUE;
|
|
|
|
|
|
|
|
cur := CL.guard.prev;
|
|
|
|
WHILE cur # NIL DO
|
|
|
|
IF cur IS tBoolItem THEN
|
|
|
|
boolItem := cur(tBoolItem);
|
|
|
|
FOR i := 0 TO boolItemSize - 1 DO
|
|
|
|
IF (i IN boolItem.map) & boolItem.data[i].save &
|
|
|
|
boolItem.data[i].line.modified THEN
|
|
|
|
EXCL(boolItem.map, i)
|
|
|
|
END
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
cur := cur.prev;
|
|
|
|
IF boolItem.map = {} THEN
|
|
|
|
List.delete(CL.Log, boolItem);
|
|
|
|
DISPOSE(boolItem)
|
|
|
|
END
|
|
|
|
END
|
2021-07-21 18:13:29 +02:00
|
|
|
END save;
|
|
|
|
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
PROCEDURE changeWord (adrV, adrX: INTEGER);
|
|
|
|
VAR
|
2023-02-22 16:56:05 +01:00
|
|
|
item: tIntItem;
|
|
|
|
cur: List.tItem;
|
2021-05-23 11:43:28 +02:00
|
|
|
BEGIN
|
2023-02-22 16:56:05 +01:00
|
|
|
IF ~CL.isLast THEN
|
|
|
|
clear(CL.guard)
|
|
|
|
END;
|
|
|
|
cur := CL.Log.last;
|
|
|
|
WHILE (cur # NIL) & ~(cur IS tGuard) & ~(cur IS tIntItem) DO
|
|
|
|
cur := cur.prev
|
|
|
|
END;
|
|
|
|
IF (cur IS tIntItem) & (cur(tIntItem).cnt < LEN(cur(tIntItem).adr)) THEN
|
|
|
|
item := cur(tIntItem)
|
|
|
|
ELSE
|
|
|
|
NEW(item);
|
|
|
|
item.cnt := 0;
|
|
|
|
List.append(CL.Log, item)
|
|
|
|
END;
|
|
|
|
item.adr[item.cnt] := adrV;
|
|
|
|
SYSTEM.GET(adrX, item.val[item.cnt]);
|
|
|
|
INC(item.cnt)
|
2021-05-23 11:43:28 +02:00
|
|
|
END changeWord;
|
|
|
|
|
|
|
|
|
2021-07-21 18:13:29 +02:00
|
|
|
PROCEDURE delSaved*;
|
|
|
|
VAR
|
2023-02-24 16:02:24 +01:00
|
|
|
boolItem: tBoolItem;
|
|
|
|
cur: List.tItem;
|
|
|
|
i: INTEGER;
|
2021-07-21 18:13:29 +02:00
|
|
|
BEGIN
|
2023-02-24 16:02:24 +01:00
|
|
|
cur := CL.guard.next;
|
|
|
|
WHILE cur # NIL DO
|
|
|
|
IF cur IS tBoolItem THEN
|
|
|
|
boolItem := cur(tBoolItem);
|
|
|
|
FOR i := 0 TO boolItemSize - 1 DO
|
|
|
|
IF (i IN boolItem.map) & boolItem.data[i].save THEN
|
|
|
|
EXCL(boolItem.map, i)
|
|
|
|
END
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
cur := cur.next;
|
|
|
|
IF boolItem.map = {} THEN
|
|
|
|
List.delete(CL.Log, boolItem);
|
|
|
|
DISPOSE(boolItem)
|
|
|
|
END
|
|
|
|
END
|
2021-07-21 18:13:29 +02:00
|
|
|
END delSaved;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE delCurSaved*;
|
|
|
|
VAR
|
2023-02-24 16:02:24 +01:00
|
|
|
boolItem: tBoolItem;
|
|
|
|
cur: List.tItem;
|
|
|
|
i: INTEGER;
|
2021-07-21 18:13:29 +02:00
|
|
|
BEGIN
|
2023-02-24 16:02:24 +01:00
|
|
|
cur := CL.guard.prev;
|
|
|
|
WHILE (cur # NIL) & ~(cur IS tGuard) DO
|
|
|
|
IF cur IS tBoolItem THEN
|
|
|
|
boolItem := cur(tBoolItem);
|
|
|
|
FOR i := 0 TO boolItemSize - 1 DO
|
|
|
|
IF (i IN boolItem.map) & boolItem.data[i].save THEN
|
|
|
|
SYSTEM.PUT(boolItem.data[i].adr, ~boolItem.data[i].val);
|
|
|
|
EXCL(boolItem.map, i)
|
|
|
|
END
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
cur := cur.prev;
|
|
|
|
IF boolItem.map = {} THEN
|
|
|
|
List.delete(CL.Log, boolItem);
|
|
|
|
DISPOSE(boolItem)
|
|
|
|
END
|
|
|
|
END
|
2021-07-21 18:13:29 +02:00
|
|
|
END delCurSaved;
|
|
|
|
|
|
|
|
|
2023-02-24 16:02:24 +01:00
|
|
|
PROCEDURE _changeBool (fn2: BOOLEAN; line: Lines.tLine; VAR v: BOOLEAN; x: BOOLEAN);
|
2021-07-21 18:13:29 +02:00
|
|
|
VAR
|
2023-02-24 16:02:24 +01:00
|
|
|
item: tBoolItem;
|
|
|
|
cur: List.tItem;
|
|
|
|
i: INTEGER;
|
|
|
|
BEGIN
|
|
|
|
IF fn2 THEN
|
|
|
|
cur := CL.guard.prev
|
|
|
|
ELSE
|
|
|
|
IF ~CL.isLast THEN
|
|
|
|
clear(CL.guard)
|
|
|
|
END;
|
|
|
|
cur := CL.Log.last
|
|
|
|
END;
|
|
|
|
|
|
|
|
WHILE (cur # NIL) & ~(cur IS tGuard) &
|
|
|
|
(~(cur IS tBoolItem) OR (cur(tBoolItem).map = fillMap)) DO
|
|
|
|
cur := cur.prev
|
|
|
|
END;
|
|
|
|
IF (cur IS tBoolItem) & (cur(tBoolItem).map # fillMap) THEN
|
|
|
|
item := cur(tBoolItem)
|
|
|
|
ELSE
|
|
|
|
NEW(item);
|
|
|
|
item.map := {};
|
|
|
|
IF fn2 THEN
|
|
|
|
List.insert(CL.Log, CL.guard.prev, item)
|
|
|
|
ELSE
|
|
|
|
List.append(CL.Log, item)
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
i := 0;
|
|
|
|
WHILE i < boolItemSize DO
|
|
|
|
IF ~(i IN item.map) THEN
|
|
|
|
item.data[i].line := line;
|
|
|
|
item.data[i].adr := SYSTEM.ADR(v);
|
|
|
|
item.data[i].val := x;
|
|
|
|
item.data[i].save := fn2;
|
|
|
|
INCL(item.map, i);
|
|
|
|
i := boolItemSize
|
|
|
|
END;
|
|
|
|
INC(i)
|
|
|
|
END
|
|
|
|
END _changeBool;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE changeBool (line: Lines.tLine; VAR v: BOOLEAN; x: BOOLEAN);
|
|
|
|
BEGIN
|
|
|
|
_changeBool(FALSE, line, v, x)
|
|
|
|
END changeBool;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE changeBool2 (line: Lines.tLine; VAR v: BOOLEAN; x: BOOLEAN);
|
2021-07-21 18:13:29 +02:00
|
|
|
BEGIN
|
2023-02-24 16:02:24 +01:00
|
|
|
_changeBool(TRUE, line, v, x)
|
2021-07-21 18:13:29 +02:00
|
|
|
END changeBool2;
|
|
|
|
|
|
|
|
|
2021-11-27 18:19:15 +01:00
|
|
|
PROCEDURE changeInt* (VAR v: INTEGER; x: INTEGER);
|
2021-05-23 11:43:28 +02:00
|
|
|
BEGIN
|
2023-02-24 16:02:24 +01:00
|
|
|
changeWord(SYSTEM.ADR(v), SYSTEM.ADR(x))
|
2021-05-23 11:43:28 +02:00
|
|
|
END changeInt;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE changePtr (VAR v: List.tItem; x: List.tItem);
|
|
|
|
BEGIN
|
2023-02-24 16:02:24 +01:00
|
|
|
changeWord(SYSTEM.ADR(v), SYSTEM.ADR(x))
|
2021-05-23 11:43:28 +02:00
|
|
|
END changePtr;
|
|
|
|
|
2021-12-20 20:09:01 +01:00
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
PROCEDURE typedPtr (p: List.tItem);
|
|
|
|
VAR
|
2023-02-22 16:56:05 +01:00
|
|
|
item: tTypedPtr;
|
2021-05-23 11:43:28 +02:00
|
|
|
BEGIN
|
2023-02-22 16:56:05 +01:00
|
|
|
item := CL.TPointers.last(tTypedPtr);
|
|
|
|
IF (item = NIL) OR (item.cnt = LEN(item.p)) THEN
|
|
|
|
NEW(item);
|
|
|
|
item.cnt := 0;
|
|
|
|
List.append(CL.TPointers, item)
|
|
|
|
END;
|
|
|
|
item.p[item.cnt] := p;
|
|
|
|
INC(item.cnt)
|
2021-05-23 11:43:28 +02:00
|
|
|
END typedPtr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE untypedPtr (p: INTEGER);
|
|
|
|
VAR
|
2023-02-22 16:56:05 +01:00
|
|
|
item: tUntypedPtr;
|
2021-05-23 11:43:28 +02:00
|
|
|
BEGIN
|
2023-02-22 16:56:05 +01:00
|
|
|
item := CL.UPointers.last(tUntypedPtr);
|
|
|
|
IF (item = NIL) OR (item.cnt = LEN(item.p)) THEN
|
|
|
|
NEW(item);
|
|
|
|
item.cnt := 0;
|
|
|
|
List.append(CL.UPointers, item)
|
|
|
|
END;
|
|
|
|
item.p[item.cnt] := p;
|
|
|
|
INC(item.cnt)
|
2021-05-23 11:43:28 +02:00
|
|
|
END untypedPtr;
|
2021-12-20 20:09:01 +01:00
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
|
2023-02-22 16:56:05 +01:00
|
|
|
PROCEDURE setLog* (_CL: tLog);
|
2021-07-11 01:39:41 +02:00
|
|
|
BEGIN
|
2023-02-24 16:02:24 +01:00
|
|
|
CL := _CL
|
2023-02-22 16:56:05 +01:00
|
|
|
END setLog;
|
2021-07-11 01:39:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE create* (VAR maxLength: INTEGER): tLog;
|
|
|
|
VAR
|
2023-02-24 16:02:24 +01:00
|
|
|
newLog: tLog;
|
2021-07-11 01:39:41 +02:00
|
|
|
BEGIN
|
2023-02-24 16:02:24 +01:00
|
|
|
NEW(newLog);
|
|
|
|
newLog.guard := NIL;
|
|
|
|
newLog.first := NIL;
|
|
|
|
newLog.isLast := TRUE;
|
|
|
|
newLog.Log := List.create(NIL);
|
|
|
|
newLog.TPointers := List.create(NIL);
|
|
|
|
newLog.UPointers := List.create(NIL);
|
|
|
|
CL := newLog;
|
|
|
|
Lines.setMaxLength(maxLength)
|
|
|
|
RETURN newLog
|
2021-07-11 01:39:41 +02:00
|
|
|
END create;
|
|
|
|
|
|
|
|
|
2021-12-20 20:09:01 +01:00
|
|
|
PROCEDURE destroy* (VAR log: tLog);
|
|
|
|
VAR
|
|
|
|
item: List.tItem;
|
2023-02-22 16:56:05 +01:00
|
|
|
res, i: INTEGER;
|
2021-12-20 20:09:01 +01:00
|
|
|
BEGIN
|
|
|
|
IF log # NIL THEN
|
|
|
|
item := List.pop(log.Log);
|
|
|
|
WHILE item # NIL DO
|
|
|
|
DISPOSE(item);
|
|
|
|
item := List.pop(log.Log)
|
|
|
|
END;
|
|
|
|
DISPOSE(log.Log);
|
|
|
|
|
2023-02-22 16:56:05 +01:00
|
|
|
item := List.pop(log.TPointers);
|
|
|
|
WHILE item # NIL DO
|
|
|
|
FOR i := 0 TO item(tTypedPtr).cnt - 1 DO
|
|
|
|
DISPOSE(item(tTypedPtr).p[i])
|
|
|
|
END;
|
|
|
|
DISPOSE(item);
|
|
|
|
item := List.pop(log.TPointers)
|
|
|
|
END;
|
|
|
|
DISPOSE(log.TPointers);
|
|
|
|
|
|
|
|
item := List.pop(log.UPointers);
|
2021-12-20 20:09:01 +01:00
|
|
|
WHILE item # NIL DO
|
2023-02-22 16:56:05 +01:00
|
|
|
FOR i := 0 TO item(tUntypedPtr).cnt - 1 DO
|
|
|
|
res := API._DISPOSE(item(tUntypedPtr).p[i])
|
|
|
|
END;
|
2021-12-20 20:09:01 +01:00
|
|
|
DISPOSE(item);
|
2023-02-22 16:56:05 +01:00
|
|
|
item := List.pop(log.UPointers)
|
2021-12-20 20:09:01 +01:00
|
|
|
END;
|
2023-02-22 16:56:05 +01:00
|
|
|
DISPOSE(log.UPointers);
|
2021-12-20 20:09:01 +01:00
|
|
|
|
|
|
|
DISPOSE(log)
|
|
|
|
END
|
|
|
|
END destroy;
|
|
|
|
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
BEGIN
|
2023-02-24 16:02:24 +01:00
|
|
|
List.init(changeInt, changePtr);
|
|
|
|
Lines.init(changeInt, changePtr, changeBool, changeBool2, typedPtr, untypedPtr)
|
2021-05-23 11:43:28 +02:00
|
|
|
END ChangeLog.
|