CEdit: null character support; reduced memory usage when replacing text and moving lines

git-svn-id: svn://kolibrios.org@9560 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2022-01-02 18:57:13 +00:00
parent 544a2a9702
commit a218cacd34
8 changed files with 113 additions and 128 deletions

Binary file not shown.

View File

@ -1,5 +1,5 @@
(*
Copyright 2021 Anton Krotov
Copyright 2021, 2022 Anton Krotov
This file is part of CEdit.
@ -28,7 +28,7 @@ IMPORT
RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar;
CONST
HEADER = "CEdit (30-dec-2021)";
HEADER = "CEdit (02-jan-2022)";
ShellFilter = "";
EditFilter = "SH|INC|TXT|ASM|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON";
@ -1793,16 +1793,19 @@ BEGIN
|btnFindNext:
IF searchText # "" THEN
notFound := ~T.findNext(text, BKW.value);
SetFocus(FindEdit, FALSE);
repaint
END
|btnReplace:
T.replace(text, replaceText, LENGTH(searchText));
SetFocus(FindEdit, FALSE);
repaint
|btnReplaceAll:
notFound := ~T.search(text, searchText, cs, whole);
IF ~notFound THEN
replaced := T.replaceAll(text, replaceText, LENGTH(searchText));
END;
SetFocus(FindEdit, FALSE);
repaint
|btnGoto:
goto;

View File

@ -1,5 +1,5 @@
(*
Copyright 2021 Anton Krotov
Copyright 2021, 2022 Anton Krotov
This file is part of CEdit.
@ -24,7 +24,6 @@ IMPORT SYSTEM, KOSAPI, E := Encodings, Lines, K := KolibriOS;
CONST
TTEXT = 0;
lenEOL* = 2;
TAB = 9X;
TYPE
tBuffer* = POINTER TO RECORD
@ -60,11 +59,14 @@ BEGIN
ptr := buffer.dataPtr;
WHILE cnt > 0 DO
SYSTEM.GET(ptr, wch);
IF wch # Lines.TAB1 THEN
SYSTEM.PUT(pchar, CHR(E.UNI[ORD(wch), E.CP866] MOD 256));
IF wch = Lines.TAB1 THEN
DEC(size)
ELSIF wch = Lines.NUL THEN
SYSTEM.PUT(pchar, 0X);
INC(pchar)
ELSE
DEC(size);
SYSTEM.PUT(pchar, CHR(E.UNI[ORD(wch), E.CP866] MOD 256));
INC(pchar)
END;
INC(ptr, 2);
DEC(cnt)

View File

@ -1,5 +1,5 @@
(*
Copyright 2021 Anton Krotov
Copyright 2021, 2022 Anton Krotov
This file is part of CEdit.
@ -282,6 +282,9 @@ BEGIN
ELSE
color := canvas.textColor
END;
IF c = Lines.NUL THEN
c := 0X
END;
KOSAPI.sysfunc6(4, x*65536 + y, font + color, SYSTEM.ADR(c), 1, canvas.bitmap - 8)
END;
INC(x, canvas.font.width);

View File

@ -1,5 +1,5 @@
(*
Copyright 2021 Anton Krotov
Copyright 2021, 2022 Anton Krotov
This file is part of CEdit.
@ -26,7 +26,8 @@ CONST
WCHAR_SIZE = 2;
SPACE* = 20X;
TAB* = 9X;
TAB1* = 0FFFEX;
NUL* = 0FDD0X;
TAB1* = 0FDD1X;
TYPE

View File

@ -1,5 +1,5 @@
(*
Copyright 2021 Anton Krotov
Copyright 2021, 2022 Anton Krotov
This file is part of CEdit.
@ -151,52 +151,28 @@ PROCEDURE _insert* (list: tList; item, newItem: tItem);
VAR
next: tItem;
BEGIN
next := item.next;
IF next # NIL THEN
movPtr(next.prev, newItem);
movPtr(newItem.next, next);
movPtr(item.next, newItem);
movPtr(newItem.prev, item);
movInt(list.count, list.count + 1)
IF item # NIL THEN
next := item.next;
IF next # NIL THEN
movPtr(next.prev, newItem);
movPtr(newItem.next, next);
movPtr(item.next, newItem);
movPtr(newItem.prev, item);
movInt(list.count, list.count + 1)
ELSE
_append(list, newItem)
END
ELSE
_append(list, newItem)
ASSERT(list.first # NIL);
movPtr(newItem.prev, NIL);
movPtr(newItem.next, list.first);
movPtr(list.first.prev, newItem);
movPtr(list.first, newItem);
movInt(list.count, list.count + 1)
END
END _insert;
PROCEDURE _exchange* (list: tList; a, b: tItem);
VAR
a0, b0: tItem;
BEGIN
IF (a # NIL) & (b # NIL) THEN
ASSERT((a.next = b) & (b.prev = a));
a0 := a.prev;
b0 := b.next;
movPtr(b.prev, a0);
movPtr(a.next, b0);
movPtr(b.next, a);
movPtr(a.prev, b);
IF a0 # NIL THEN
IF b0 # NIL THEN
movPtr(a0.next, b);
movPtr(b0.prev, a);
ELSE
movPtr(a0.next, b);
movPtr(list.last, a)
END
ELSE
IF b0 # NIL THEN
movPtr(b0.prev, a);
movPtr(list.first, b)
ELSE
movPtr(list.first, b);
movPtr(list.last, a)
END
END
END
END _exchange;
PROCEDURE append* (list: tList; item: tItem);
BEGIN
item.prev := list.last;

View File

@ -1,5 +1,5 @@
(*
Copyright 2021 Anton Krotov
Copyright 2021, 2022 Anton Krotov
This file is part of CEdit.
@ -178,11 +178,14 @@ BEGIN
c := WCHR(file.getChar(file) MOD 65536);
IF c = Lines.TAB1 THEN
c := SPACE
ELSIF c = 0X THEN
c := Lines.NUL
END;
IF c = CR THEN
eol := TRUE;
file.CR := TRUE
ELSIF (c = LF) OR (c = 0X) THEN
ELSIF c = LF THEN
IF ~file.CR THEN
eol := TRUE
END;
@ -424,8 +427,12 @@ VAR
BEGIN
FOR i := 0 TO n - 1 DO
c := Lines.getChar(line, i);
IF c # Lines.TAB1 THEN
file.putChar(file, ORD(c))
IF c = Lines.TAB1 THEN
(* nothing to do *)
ELSIF c = Lines.NUL THEN
file.putChar(file, 0)
ELSE
file.putChar(file, ORD(c))
END
END
END putString;

View File

@ -1,5 +1,5 @@
(*
Copyright 2021 Anton Krotov
Copyright 2021, 2022 Anton Krotov
This file is part of CEdit.
@ -1805,77 +1805,78 @@ BEGIN
END dupLine;
PROCEDURE exchange (text: tText; first, second: tLine);
BEGIN
List._exchange(text, first, second);
Lines.modify(text.curLine);
modify(text);
UpDown(text, 0)
END exchange;
PROCEDURE upLine (text: tText);
BEGIN
DEC(text.cursor.Y);
exchange(text, text.curLine.prev(tLine), text.curLine)
END upLine;
PROCEDURE downLine (text: tText);
BEGIN
INC(text.cursor.Y);
exchange(text, text.curLine, text.curLine.next(tLine))
END downLine;
PROCEDURE MoveLines* (text: tText; down: BOOLEAN);
VAR
last: tLine;
last, first, line: tLine;
selBeg, selEnd, temp: tPoint;
n, step: INTEGER;
step: INTEGER;
frw: BOOLEAN;
moveLine: PROCEDURE (text: tText);
BEGIN
getSelect(text, selBeg, selEnd);
IF (selBeg.Y > 0) & ~down OR (selEnd.Y < text.count - 1) & down THEN
IF down THEN
step := -2;
moveLine := downLine
ELSE
step := 2;
moveLine := upLine
END;
frw := (text.cursor.X = selEnd.X) & (text.cursor.Y = selEnd.Y);
IF selEnd.Y # selBeg.Y THEN
IF ((selBeg.Y > 0) & ~down OR (selEnd.Y < text.count - 1) & down) THEN
modify(text);
step := ORD(down)*2 - 1;
IF selBeg.Y # selEnd.Y THEN
frw := (text.cursor.X = selEnd.X) & (text.cursor.Y = selEnd.Y);
IF down # frw THEN
temp := text.cursor^;
SetPos(text, 0, text.select.Y);
setSelect(text);
text.select^ := temp
END;
ASSERT(selBeg.Y < selEnd.Y);
first := getLine(text, selBeg.Y);
last := getLine(text, selEnd.Y);
line := first;
Lines.modify(line);
REPEAT
NextLine(line);
Lines.modify(line)
UNTIL line = last;
IF down THEN
text.curLine := last.prev(tLine)
ELSE
text.curLine := first.next(tLine)
END;
selBeg.X := 0;
selEnd.X := last.length;
n := selEnd.Y - selBeg.Y + 1;
WHILE n > 0 DO
moveLine(text);
SetPos(text, 0, text.cursor.Y + step);
DEC(n)
END
IF down THEN
last := last.next(tLine);
List._delete(text, last);
List._insert(text, first.prev, last)
ELSE
first := first.prev(tLine);
List._delete(text, first);
List._insert(text, last, first)
END;
IF down THEN
temp := selBeg;
selBeg := selEnd;
selEnd := temp;
END;
SetPos(text, selBeg.X, selBeg.Y + step);
setSelect(text);
text.select.X := selEnd.X;
text.select.Y := selEnd.Y + step
ELSE
moveLine(text)
END;
IF frw THEN
temp := selBeg;
selBeg := selEnd;
selEnd := temp
END;
step := step DIV 2;
SetPos(text, selBeg.X, selBeg.Y - step);
setSelect(text);
text.select.X := selEnd.X;
text.select.Y := selEnd.Y - step
first := getLine(text, selBeg.Y);
Lines.modify(first);
IF down THEN
last := first.next(tLine)
ELSE
last := first.prev.prev(tLine)
END;
List._delete(text, first);
List._insert(text, last, first);
INC(text.cursor.Y, step);
INC(text.select.Y, step);
SetPos(text, text.cursor.X, text.cursor.Y)
END
END
END MoveLines;
@ -2541,18 +2542,6 @@ BEGIN
END findNext;
PROCEDURE rewrite (line: tLine; repl: ARRAY OF WCHAR; pos, n: INTEGER);
BEGIN
IF n > 0 THEN
Lines.copy(line)
END;
WHILE n > 0 DO
DEC(n);
Lines.setChar(line, pos + n, repl[n])
END
END rewrite;
PROCEDURE replace* (text: tText; s: ARRAY OF WCHAR; n: INTEGER);
VAR
line: tLine;
@ -2564,12 +2553,16 @@ BEGIN
i := text.cursor.X;
IF sLen > n THEN
Lines.insert3(line, i, sLen - n)
ELSIF n > sLen THEN
Lines.delCharN(line, i, n - sLen)
ELSE (* n = sLen *)
Lines.copy(line)
END;
SetPos(text, i + sLen, text.cursor.Y);
rewrite(line, s, i, sLen);
IF n > sLen THEN
Lines.delCharN(line, text.cursor.X, n - sLen)
END;
WHILE sLen > 0 DO
DEC(sLen);
Lines.setChar(line, i + sLen, s[sLen])
END;
resetSelect(text);
Lines.modify(line);
modify(text)