2021-05-23 11:43:28 +02:00
|
|
|
(*
|
2022-01-28 16:47:03 +01:00
|
|
|
Copyright 2021, 2022 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
|
|
|
|
|
|
|
TYPE
|
|
|
|
tIntItem = POINTER TO RECORD (List.tItem)
|
|
|
|
adr, val: INTEGER
|
|
|
|
END;
|
|
|
|
|
|
|
|
tBoolItem = POINTER TO RECORD (List.tItem)
|
2021-12-21 17:19:39 +01:00
|
|
|
line: Lines.tLine;
|
|
|
|
adr: INTEGER;
|
|
|
|
val, save: BOOLEAN
|
2021-05-23 11:43:28 +02:00
|
|
|
END;
|
2021-12-20 20:09:01 +01:00
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
tUntypedPtr = POINTER TO RECORD (List.tItem)
|
|
|
|
p: INTEGER
|
|
|
|
END;
|
|
|
|
|
|
|
|
tTypedPtr = POINTER TO RECORD (List.tItem)
|
|
|
|
p: List.tItem
|
|
|
|
END;
|
2021-12-20 20:09:01 +01:00
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
tGuard* = POINTER TO RECORD (List.tItem)
|
2021-07-21 18:13:29 +02:00
|
|
|
saved*: BOOLEAN
|
2021-05-23 11:43:28 +02:00
|
|
|
END;
|
|
|
|
|
2021-07-11 01:39:41 +02:00
|
|
|
tLog* = POINTER TO RECORD
|
2021-12-20 20:09:01 +01:00
|
|
|
Log*, Pointers*: List.tList;
|
2022-01-24 23:03:13 +01:00
|
|
|
guard, first: tGuard;
|
2021-07-11 01:39:41 +02:00
|
|
|
isLast: BOOLEAN
|
|
|
|
END;
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
VAR
|
2021-07-11 01:39:41 +02:00
|
|
|
CL*: tLog;
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isLastGuard* (guard: tGuard): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
item: List.tItem;
|
|
|
|
res: BOOLEAN;
|
|
|
|
BEGIN
|
|
|
|
IF guard # NIL THEN
|
2021-07-11 01:39:41 +02:00
|
|
|
item := CL.Log.last;
|
2021-05-23 11:43:28 +02:00
|
|
|
WHILE ~(item IS tGuard) DO
|
|
|
|
item := item.prev
|
|
|
|
END;
|
|
|
|
res := guard = item
|
|
|
|
ELSE
|
|
|
|
res := TRUE
|
|
|
|
END
|
|
|
|
RETURN res
|
|
|
|
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
|
2021-07-11 01:39:41 +02:00
|
|
|
CL.guard := _guard;
|
|
|
|
CL.isLast := isLastGuard(_guard)
|
2021-05-23 11:43:28 +02:00
|
|
|
END setGuard;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE redo* (item: List.tItem);
|
|
|
|
BEGIN
|
|
|
|
IF item IS tIntItem THEN
|
|
|
|
SYSTEM.PUT(item(tIntItem).adr, item(tIntItem).val)
|
|
|
|
ELSIF item IS tBoolItem THEN
|
|
|
|
SYSTEM.PUT(item(tBoolItem).adr, item(tBoolItem).val)
|
|
|
|
END
|
|
|
|
END redo;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE clear (guard: tGuard);
|
|
|
|
VAR
|
|
|
|
item: List.tItem;
|
|
|
|
BEGIN
|
2021-07-11 01:39:41 +02:00
|
|
|
CL.isLast := TRUE;
|
2021-05-23 11:43:28 +02:00
|
|
|
REPEAT
|
2021-07-11 01:39:41 +02:00
|
|
|
item := List.pop(CL.Log);
|
2021-05-23 11:43:28 +02:00
|
|
|
IF item # guard THEN
|
|
|
|
DISPOSE(item)
|
|
|
|
END
|
|
|
|
UNTIL item = guard;
|
2021-07-11 01:39:41 +02:00
|
|
|
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;
|
|
|
|
del: BOOLEAN;
|
2021-07-21 18:13:29 +02:00
|
|
|
BEGIN
|
|
|
|
item := CL.Log.first;
|
|
|
|
WHILE item # NIL DO
|
|
|
|
IF item IS tGuard THEN
|
|
|
|
item(tGuard).saved := FALSE
|
|
|
|
END;
|
|
|
|
item := item.next
|
|
|
|
END;
|
2021-12-21 17:19:39 +01:00
|
|
|
guard.saved := TRUE;
|
|
|
|
|
|
|
|
cur := CL.guard.prev;
|
|
|
|
WHILE cur # NIL DO
|
|
|
|
IF cur IS tBoolItem THEN
|
|
|
|
boolItem := cur(tBoolItem);
|
|
|
|
del := boolItem.save & boolItem.line.modified
|
|
|
|
ELSE
|
|
|
|
del := FALSE
|
|
|
|
END;
|
|
|
|
cur := cur.prev;
|
|
|
|
IF del 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
|
|
|
|
item: tIntItem;
|
|
|
|
BEGIN
|
|
|
|
NEW(item);
|
|
|
|
item.adr := adrV;
|
|
|
|
SYSTEM.GET(adrX, item.val);
|
2021-07-11 01:39:41 +02:00
|
|
|
IF ~CL.isLast THEN
|
|
|
|
clear(CL.guard)
|
2021-05-23 11:43:28 +02:00
|
|
|
END;
|
2021-07-11 01:39:41 +02:00
|
|
|
List.append(CL.Log, item)
|
2021-05-23 11:43:28 +02:00
|
|
|
END changeWord;
|
|
|
|
|
|
|
|
|
2021-12-21 17:19:39 +01:00
|
|
|
PROCEDURE changeBool (line: Lines.tLine; VAR v: BOOLEAN; x: BOOLEAN);
|
2021-05-23 11:43:28 +02:00
|
|
|
VAR
|
|
|
|
item: tBoolItem;
|
|
|
|
BEGIN
|
|
|
|
NEW(item);
|
2021-12-21 17:19:39 +01:00
|
|
|
item.line := line;
|
2021-05-23 11:43:28 +02:00
|
|
|
item.adr := SYSTEM.ADR(v);
|
|
|
|
item.val := x;
|
2021-07-21 18:13:29 +02:00
|
|
|
item.save := FALSE;
|
2021-07-11 01:39:41 +02:00
|
|
|
IF ~CL.isLast THEN
|
|
|
|
clear(CL.guard)
|
2021-05-23 11:43:28 +02:00
|
|
|
END;
|
2021-07-11 01:39:41 +02:00
|
|
|
List.append(CL.Log, item)
|
2021-05-23 11:43:28 +02:00
|
|
|
END changeBool;
|
|
|
|
|
|
|
|
|
2021-07-21 18:13:29 +02:00
|
|
|
PROCEDURE delSaved*;
|
|
|
|
VAR
|
|
|
|
boolItem: tBoolItem;
|
|
|
|
cur: List.tItem;
|
|
|
|
del: BOOLEAN;
|
|
|
|
BEGIN
|
|
|
|
cur := CL.guard.next;
|
|
|
|
WHILE cur # NIL DO
|
|
|
|
IF cur IS tBoolItem THEN
|
|
|
|
boolItem := cur(tBoolItem);
|
|
|
|
del := boolItem.save
|
|
|
|
ELSE
|
|
|
|
del := FALSE
|
|
|
|
END;
|
|
|
|
cur := cur.next;
|
|
|
|
IF del THEN
|
|
|
|
List.delete(CL.Log, boolItem);
|
|
|
|
DISPOSE(boolItem)
|
|
|
|
END
|
|
|
|
END
|
|
|
|
END delSaved;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE delCurSaved*;
|
|
|
|
VAR
|
|
|
|
boolItem: tBoolItem;
|
|
|
|
cur: List.tItem;
|
|
|
|
del: BOOLEAN;
|
|
|
|
BEGIN
|
|
|
|
cur := CL.guard.prev;
|
|
|
|
WHILE (cur # NIL) & ~(cur IS tGuard) DO
|
|
|
|
IF cur IS tBoolItem THEN
|
|
|
|
boolItem := cur(tBoolItem);
|
|
|
|
del := boolItem.save
|
|
|
|
ELSE
|
|
|
|
del := FALSE
|
|
|
|
END;
|
|
|
|
cur := cur.prev;
|
|
|
|
IF del THEN
|
|
|
|
SYSTEM.PUT(boolItem.adr, ~boolItem.val);
|
|
|
|
List.delete(CL.Log, boolItem);
|
|
|
|
DISPOSE(boolItem)
|
|
|
|
END
|
|
|
|
END
|
|
|
|
END delCurSaved;
|
|
|
|
|
|
|
|
|
2021-12-21 17:19:39 +01:00
|
|
|
PROCEDURE changeBool2 (line: Lines.tLine; VAR v: BOOLEAN; x: BOOLEAN);
|
2021-07-21 18:13:29 +02:00
|
|
|
VAR
|
2021-12-21 17:19:39 +01:00
|
|
|
item: tBoolItem;
|
2021-07-21 18:13:29 +02:00
|
|
|
BEGIN
|
|
|
|
NEW(item);
|
2021-12-21 17:19:39 +01:00
|
|
|
item.line := line;
|
2021-07-21 18:13:29 +02:00
|
|
|
item.adr := SYSTEM.ADR(v);
|
|
|
|
item.val := x;
|
|
|
|
item.save := TRUE;
|
|
|
|
List.insert(CL.Log, CL.guard.prev, item)
|
|
|
|
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
|
|
|
|
changeWord(SYSTEM.ADR(v), SYSTEM.ADR(x))
|
|
|
|
END changeInt;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE changePtr (VAR v: List.tItem; x: List.tItem);
|
|
|
|
BEGIN
|
|
|
|
changeWord(SYSTEM.ADR(v), SYSTEM.ADR(x))
|
|
|
|
END changePtr;
|
|
|
|
|
2021-12-20 20:09:01 +01:00
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
PROCEDURE typedPtr (p: List.tItem);
|
|
|
|
VAR
|
|
|
|
item: tTypedPtr;
|
|
|
|
BEGIN
|
|
|
|
NEW(item);
|
|
|
|
item.p := p;
|
2021-12-20 20:09:01 +01:00
|
|
|
List.append(CL.Pointers, item)
|
2021-05-23 11:43:28 +02:00
|
|
|
END typedPtr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE untypedPtr (p: INTEGER);
|
|
|
|
VAR
|
|
|
|
item: tUntypedPtr;
|
|
|
|
BEGIN
|
|
|
|
NEW(item);
|
|
|
|
item.p := p;
|
2021-12-20 20:09:01 +01:00
|
|
|
List.append(CL.Pointers, item)
|
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
|
|
|
|
2021-07-11 01:39:41 +02:00
|
|
|
PROCEDURE set* (_CL: tLog);
|
|
|
|
BEGIN
|
|
|
|
CL := _CL
|
|
|
|
END set;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE create* (VAR maxLength: INTEGER): tLog;
|
|
|
|
VAR
|
|
|
|
newLog: tLog;
|
|
|
|
BEGIN
|
|
|
|
NEW(newLog);
|
|
|
|
newLog.guard := NIL;
|
2022-01-24 23:03:13 +01:00
|
|
|
newLog.first := NIL;
|
2021-07-11 01:39:41 +02:00
|
|
|
newLog.isLast := TRUE;
|
|
|
|
newLog.Log := List.create(NIL);
|
2021-12-20 20:09:01 +01:00
|
|
|
newLog.Pointers := List.create(NIL);
|
2021-07-11 01:39:41 +02:00
|
|
|
CL := newLog;
|
|
|
|
Lines.setMaxLength(maxLength)
|
|
|
|
RETURN newLog
|
|
|
|
END create;
|
|
|
|
|
|
|
|
|
2021-12-20 20:09:01 +01:00
|
|
|
PROCEDURE destroy* (VAR log: tLog);
|
|
|
|
VAR
|
|
|
|
item: List.tItem;
|
|
|
|
res: INTEGER;
|
|
|
|
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);
|
|
|
|
|
|
|
|
item := List.pop(log.Pointers);
|
|
|
|
WHILE item # NIL DO
|
|
|
|
IF item IS tUntypedPtr THEN
|
|
|
|
res := API._DISPOSE(item(tUntypedPtr).p)
|
|
|
|
ELSIF item IS tTypedPtr THEN
|
|
|
|
DISPOSE(item(tTypedPtr).p)
|
|
|
|
END;
|
|
|
|
DISPOSE(item);
|
|
|
|
item := List.pop(log.Pointers)
|
|
|
|
END;
|
|
|
|
DISPOSE(log.Pointers);
|
|
|
|
|
|
|
|
DISPOSE(log)
|
|
|
|
END
|
|
|
|
END destroy;
|
|
|
|
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
BEGIN
|
|
|
|
List.init(changeInt, changePtr);
|
2021-12-20 20:09:01 +01:00
|
|
|
Lines.init(changeInt, changePtr, changeBool, changeBool2, typedPtr, untypedPtr)
|
2021-05-23 11:43:28 +02:00
|
|
|
END ChangeLog.
|