CEdit: reduced memory usage

git-svn-id: svn://kolibrios.org@9902 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2023-02-22 15:56:05 +00:00
parent 6dae04e665
commit 56ed41fae1
13 changed files with 253 additions and 186 deletions

Binary file not shown.

View File

@ -77,7 +77,7 @@ KW2 = ABS,ASR,ASSERT,BITS,BOOLEAN,BYTE,CHAR,CHR,COPY,DEC,DISPOSE,EXCL,FLOOR,FLT,
KW3 = KW3 =
[lang_Pascal] [lang_Pascal]
KW1 = AND,ARRAY,BEGIN,CASE,CONST,DIV,DO,DOWNTO,ELSE,END,FILE,FOR,FUNCTION,GOTO,IF,IMPLEMENTATION,IN,INTERFACE,LABEL,MOD,NIL,NOT,OF,OR,PACKED,PROCEDURE,PROGRAM,RECORD,REPEAT,SET,SHL,SHR,STRING,THEN,TO,TYPE,UNIT,UNTIL,USES,VAR,WHILE,WITH,XOR KW1 = and,array,begin,case,const,div,do,downto,else,end,file,for,function,goto,if,implementation,in,interface,label,mod,nil,not,of,or,packed,procedure,program,record,repeat,set,shl,shr,string,then,to,type,unit,until,uses,var,while,with,xor
KW2 = KW2 =
KW3 = KW3 =

View File

@ -24,11 +24,11 @@ IMPORT
U := Utils, Lines, Menu, List, U := Utils, Lines, Menu, List,
G := Graph, T := Text, E := Encodings, G := Graph, T := Text, E := Encodings,
CB := Clipboard, Languages, CB := Clipboard, Languages,
ChangeLog, Scroll, CheckBox, ChangeLog, Scroll, CheckBox, Icons,
RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar; RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar;
CONST CONST
HEADER = "CEdit (21-jan-2023)"; HEADER = "CEdit (22-feb-2023)";
ShellFilter = ""; ShellFilter = "";
EditFilter = "SH|INC|TXT|ASM|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON"; EditFilter = "SH|INC|TXT|ASM|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON";
@ -2149,20 +2149,20 @@ BEGIN
Shortcuts; Shortcuts;
Toolbar.create(toolbar, LEFT_PADDING + 5, toolbarTop); Toolbar.create(toolbar, LEFT_PADDING + 5, toolbarTop);
Toolbar.add(toolbar, btnNew, 2, ""); Toolbar.add(toolbar, btnNew, Icons.icoNew, "");
Toolbar.add(toolbar, btnOpen, 0, ""); Toolbar.add(toolbar, btnOpen, Icons.icoOpen, "");
Toolbar.add(toolbar, btnSave, 5, ""); Toolbar.add(toolbar, btnSave, Icons.icoSave, "");
Toolbar.delimiter(toolbar); Toolbar.delimiter(toolbar);
Toolbar.add(toolbar, btnSearch, 49, ""); Toolbar.add(toolbar, btnSearch, Icons.icoSearch, "");
Toolbar.delimiter(toolbar); Toolbar.delimiter(toolbar);
Toolbar.add(toolbar, btnUndo, 37, ""); Toolbar.add(toolbar, btnUndo, Icons.icoUndo, "");
Toolbar.add(toolbar, btnRedo, 36, ""); Toolbar.add(toolbar, btnRedo, Icons.icoRedo, "");
Toolbar.delimiter(toolbar); Toolbar.delimiter(toolbar);
Toolbar.add(toolbar, btnUpper, -1, "AB"); Toolbar.add(toolbar, btnUpper, -1, "AB");
Toolbar.add(toolbar, btnLower, -1, "ab"); Toolbar.add(toolbar, btnLower, -1, "ab");
Toolbar.delimiter(toolbar); Toolbar.delimiter(toolbar);
Toolbar.add(toolbar, btnBuild, 54, ""); Toolbar.add(toolbar, btnBuild, Icons.icoBuild, "");
Toolbar.add(toolbar, btnRun, 53, ""); Toolbar.add(toolbar, btnRun, Icons.icoRun, "");
filePath := "/sys"; filePath := "/sys";
IF Args.argc = 1 THEN IF Args.argc = 1 THEN

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021, 2022 Anton Krotov Copyright 2021-2023 Anton Krotov
This file is part of CEdit. This file is part of CEdit.
@ -23,7 +23,8 @@ IMPORT List, Lines, API, SYSTEM;
TYPE TYPE
tIntItem = POINTER TO RECORD (List.tItem) tIntItem = POINTER TO RECORD (List.tItem)
adr, val: INTEGER cnt: INTEGER;
adr, val: ARRAY 8 OF INTEGER
END; END;
tBoolItem = POINTER TO RECORD (List.tItem) tBoolItem = POINTER TO RECORD (List.tItem)
@ -33,11 +34,13 @@ TYPE
END; END;
tUntypedPtr = POINTER TO RECORD (List.tItem) tUntypedPtr = POINTER TO RECORD (List.tItem)
p: INTEGER cnt: INTEGER;
p: ARRAY 64 OF INTEGER
END; END;
tTypedPtr = POINTER TO RECORD (List.tItem) tTypedPtr = POINTER TO RECORD (List.tItem)
p: List.tItem cnt: INTEGER;
p: ARRAY 64 OF List.tItem
END; END;
tGuard* = POINTER TO RECORD (List.tItem) tGuard* = POINTER TO RECORD (List.tItem)
@ -45,7 +48,7 @@ TYPE
END; END;
tLog* = POINTER TO RECORD tLog* = POINTER TO RECORD
Log*, Pointers*: List.tList; Log*, TPointers, UPointers: List.tList;
guard, first: tGuard; guard, first: tGuard;
isLast: BOOLEAN isLast: BOOLEAN
END; END;
@ -103,12 +106,16 @@ END setGuard;
PROCEDURE redo* (item: List.tItem); PROCEDURE redo* (item: List.tItem);
VAR
i: INTEGER;
BEGIN BEGIN
IF item IS tIntItem THEN IF item IS tIntItem THEN
SYSTEM.PUT(item(tIntItem).adr, item(tIntItem).val) FOR i := 0 TO item(tIntItem).cnt - 1 DO
ELSIF item IS tBoolItem THEN SYSTEM.PUT(item(tIntItem).adr[i], item(tIntItem).val[i])
SYSTEM.PUT(item(tBoolItem).adr, item(tBoolItem).val) END
END ELSIF item IS tBoolItem THEN
SYSTEM.PUT(item(tBoolItem).adr, item(tBoolItem).val)
END
END redo; END redo;
@ -162,15 +169,26 @@ END save;
PROCEDURE changeWord (adrV, adrX: INTEGER); PROCEDURE changeWord (adrV, adrX: INTEGER);
VAR VAR
item: tIntItem; item: tIntItem;
cur: List.tItem;
BEGIN BEGIN
NEW(item); IF ~CL.isLast THEN
item.adr := adrV; clear(CL.guard)
SYSTEM.GET(adrX, item.val); END;
IF ~CL.isLast THEN cur := CL.Log.last;
clear(CL.guard) WHILE (cur # NIL) & ~(cur IS tGuard) & ~(cur IS tIntItem) DO
END; cur := cur.prev
List.append(CL.Log, item) 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)
END changeWord; END changeWord;
@ -264,28 +282,38 @@ END changePtr;
PROCEDURE typedPtr (p: List.tItem); PROCEDURE typedPtr (p: List.tItem);
VAR VAR
item: tTypedPtr; item: tTypedPtr;
BEGIN BEGIN
NEW(item); item := CL.TPointers.last(tTypedPtr);
item.p := p; IF (item = NIL) OR (item.cnt = LEN(item.p)) THEN
List.append(CL.Pointers, item) NEW(item);
item.cnt := 0;
List.append(CL.TPointers, item)
END;
item.p[item.cnt] := p;
INC(item.cnt)
END typedPtr; END typedPtr;
PROCEDURE untypedPtr (p: INTEGER); PROCEDURE untypedPtr (p: INTEGER);
VAR VAR
item: tUntypedPtr; item: tUntypedPtr;
BEGIN BEGIN
NEW(item); item := CL.UPointers.last(tUntypedPtr);
item.p := p; IF (item = NIL) OR (item.cnt = LEN(item.p)) THEN
List.append(CL.Pointers, item) NEW(item);
item.cnt := 0;
List.append(CL.UPointers, item)
END;
item.p[item.cnt] := p;
INC(item.cnt)
END untypedPtr; END untypedPtr;
PROCEDURE set* (_CL: tLog); PROCEDURE setLog* (_CL: tLog);
BEGIN BEGIN
CL := _CL CL := _CL
END set; END setLog;
PROCEDURE create* (VAR maxLength: INTEGER): tLog; PROCEDURE create* (VAR maxLength: INTEGER): tLog;
@ -297,7 +325,8 @@ BEGIN
newLog.first := NIL; newLog.first := NIL;
newLog.isLast := TRUE; newLog.isLast := TRUE;
newLog.Log := List.create(NIL); newLog.Log := List.create(NIL);
newLog.Pointers := List.create(NIL); newLog.TPointers := List.create(NIL);
newLog.UPointers := List.create(NIL);
CL := newLog; CL := newLog;
Lines.setMaxLength(maxLength) Lines.setMaxLength(maxLength)
RETURN newLog RETURN newLog
@ -307,7 +336,7 @@ END create;
PROCEDURE destroy* (VAR log: tLog); PROCEDURE destroy* (VAR log: tLog);
VAR VAR
item: List.tItem; item: List.tItem;
res: INTEGER; res, i: INTEGER;
BEGIN BEGIN
IF log # NIL THEN IF log # NIL THEN
item := List.pop(log.Log); item := List.pop(log.Log);
@ -317,17 +346,25 @@ BEGIN
END; END;
DISPOSE(log.Log); DISPOSE(log.Log);
item := List.pop(log.Pointers); item := List.pop(log.TPointers);
WHILE item # NIL DO WHILE item # NIL DO
IF item IS tUntypedPtr THEN FOR i := 0 TO item(tTypedPtr).cnt - 1 DO
res := API._DISPOSE(item(tUntypedPtr).p) DISPOSE(item(tTypedPtr).p[i])
ELSIF item IS tTypedPtr THEN END;
DISPOSE(item(tTypedPtr).p)
END;
DISPOSE(item); DISPOSE(item);
item := List.pop(log.Pointers) item := List.pop(log.TPointers)
END; END;
DISPOSE(log.Pointers); DISPOSE(log.TPointers);
item := List.pop(log.UPointers);
WHILE item # NIL DO
FOR i := 0 TO item(tUntypedPtr).cnt - 1 DO
res := API._DISPOSE(item(tUntypedPtr).p[i])
END;
DISPOSE(item);
item := List.pop(log.UPointers)
END;
DISPOSE(log.UPointers);
DISPOSE(log) DISPOSE(log)
END END

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021, 2022 Anton Krotov Copyright 2021-2023 Anton Krotov
This file is part of CEdit. This file is part of CEdit.
@ -22,7 +22,7 @@ MODULE Encodings;
CONST CONST
CP866* = 0; CP1251* = 1; UTF8* = 2; UTF8BOM* = 3; (*UTF16LE* = 4;*) CP866* = 0; CP1251* = 1; UTF8* = 2; UTF8BOM* = 3; (*UTF16LE* = 4;*)
UNDEF* = -1; UNDEF* = ORD("?");
EOL_CRLF* = 0; EOL_LF* = 1; EOL_CR* = 2; EOL_CRLF* = 0; EOL_LF* = 1; EOL_CR* = 2;
CR = 0DX; LF = 0AX; CR = 0DX; LF = 0AX;
@ -35,7 +35,7 @@ TYPE
VAR VAR
cp1251*, cp866*: CP; cp1251*, cp866*: CP;
names*: ARRAY 4, 16 OF WCHAR; names*: ARRAY 4, 16 OF WCHAR;
UNI*: ARRAY 65536, 2 OF INTEGER; UNI*: ARRAY 65536, 2 OF BYTE;
eol*: ARRAY 3 OF tEOL; eol*: ARRAY 3 OF tEOL;
eolNames*: ARRAY 3, 16 OF WCHAR; eolNames*: ARRAY 3, 16 OF WCHAR;
@ -117,12 +117,8 @@ BEGIN
UNI[i, CP1251] := UNDEF UNI[i, CP1251] := UNDEF
END; END;
FOR i := 0 TO 255 DO FOR i := 0 TO 255 DO
IF cp1251[i] # UNDEF THEN UNI[cp1251[i], CP1251] := i;
UNI[cp1251[i], CP1251] := i UNI[cp866[i], CP866] := i
END;
IF cp866[i] # UNDEF THEN
UNI[cp866[i], CP866] := i
END
END END
END setUNI; END setUNI;

View File

@ -268,7 +268,7 @@ PROCEDURE TextOut* (canvas: tCanvas; x, y: INTEGER; text: INTEGER; n: INTEGER; d
CONST CONST
WCHAR_SIZE = 2; WCHAR_SIZE = 2;
VAR VAR
color, i, ch: INTEGER; color, i: INTEGER;
font: tFont; font: tFont;
c: WCHAR; c: WCHAR;
BEGIN BEGIN
@ -299,12 +299,7 @@ BEGIN
c := 0X c := 0X
END; END;
IF font = fonts[0] THEN IF font = fonts[0] THEN
ch := E.UNI[ORD(c), E.CP866]; c := WCHR(E.UNI[ORD(c), E.CP866])
IF ch = E.UNDEF THEN
c := "?"
ELSE
c := WCHR(ch)
END
END; END;
KOSAPI.sysfunc6(4, x*65536 + y, font.flags + color, SYSTEM.ADR(c), 1, canvas.bitmap - 8) KOSAPI.sysfunc6(4, x*65536 + y, font.flags + color, SYSTEM.ADR(c), 1, canvas.bitmap - 8)
END; END;

View File

@ -20,123 +20,125 @@
MODULE Icons; MODULE Icons;
IMPORT IMPORT
Graph, File, SYSTEM, KOSAPI; Graph, File, SYSTEM, KOSAPI;
CONST CONST
fileName = "/sys/Icons16.png"; fileName = "/sys/Icons16.png";
SIZE* = 18; SIZE* = 18;
VAR icoNew *= 0;
source: INTEGER; icoOpen *= 1;
icoSave *= 2;
icoSearch *= 3;
icoUndo *= 4;
icoRedo *= 5;
icoBuild *= 6;
icoRun *= 7;
NumberOfIcons = 8;
(*
PROCEDURE copy (src, dst: INTEGER);
VAR
src_width, src_height,
dst_width, dst_height,
src_data, dst_data: INTEGER;
BEGIN
LibImg.GetInf(src, src_width, src_height, src_data);
LibImg.GetInf(dst, dst_width, dst_height, dst_data);
ASSERT(src_width = dst_width);
ASSERT(src_height = dst_height);
SYSTEM.MOVE(src_data, dst_data, src_width*src_height*4)
END copy;
*)
PROCEDURE [stdcall, "libimg.obj", ""] img_decode (data, size, options: INTEGER): INTEGER; END; PROCEDURE [stdcall, "libimg.obj", ""] img_decode (data, size, options: INTEGER): INTEGER; END;
PROCEDURE [stdcall, "Libimg.obj", ""] img_convert (src, dst, dst_type, flags, param: INTEGER): INTEGER; END; PROCEDURE [stdcall, "Libimg.obj", ""] img_convert (src, dst, dst_type, flags, param: INTEGER): INTEGER; END;
PROCEDURE [stdcall, "Libimg.obj", ""] img_destroy (img: INTEGER); END; PROCEDURE [stdcall, "Libimg.obj", ""] img_destroy (img: INTEGER); END;
PROCEDURE GetInf (img: INTEGER; VAR width, height, data: INTEGER);
BEGIN
SYSTEM.GET(img + 4, width);
SYSTEM.GET(img + 8, height);
SYSTEM.GET(img + 24, data);
END GetInf;
PROCEDURE GetImg (ptr, size: INTEGER): INTEGER; PROCEDURE GetImg (ptr, size: INTEGER): INTEGER;
VAR VAR
image_data, dst, x, Type: INTEGER; image_data, dst, x, Type: INTEGER;
BEGIN BEGIN
image_data := img_decode(ptr, size, 0); image_data := img_decode(ptr, size, 0);
IF image_data # 0 THEN IF image_data # 0 THEN
SYSTEM.GET(image_data + 4, x); SYSTEM.GET(image_data + 4, x);
ASSERT(x = SIZE); ASSERT(x = SIZE);
SYSTEM.GET(image_data + 20, Type); SYSTEM.GET(image_data + 20, Type);
IF Type # 3 THEN IF Type # 3 THEN
dst := img_convert(image_data, 0, 3, 0, 0); dst := img_convert(image_data, 0, 3, 0, 0);
img_destroy(image_data); img_destroy(image_data);
image_data := dst image_data := dst
END END
END END
RETURN image_data RETURN image_data
END GetImg; END GetImg;
PROCEDURE load (): INTEGER; PROCEDURE load (): INTEGER;
VAR VAR
size, res, ptr: INTEGER; size, res, ptr: INTEGER;
BEGIN BEGIN
res := 0; res := 0;
ptr := File.Load(fileName, size); ptr := File.Load(fileName, size);
IF ptr # 0 THEN IF ptr # 0 THEN
res := GetImg(ptr, size); res := GetImg(ptr, size);
ptr := KOSAPI.free(ptr) ptr := KOSAPI.free(ptr)
END END
RETURN res RETURN res
END load; END load;
PROCEDURE draw* (icons, n, x, y: INTEGER); PROCEDURE draw* (icons, n, x, y: INTEGER);
VAR
width, height, data: INTEGER;
BEGIN BEGIN
GetInf(icons, width, height, data); KOSAPI.sysfunc7(65, icons + SIZE*SIZE*4*n, SIZE*65536 + SIZE, x*65536 + y, 32, 0, 0)
KOSAPI.sysfunc7(65, data + SIZE*SIZE*4*n, SIZE*65536 + SIZE, x*65536 + y, 32, 0, 0)
END draw; END draw;
PROCEDURE copy (img: INTEGER; n: INTEGER; dst: INTEGER; m: INTEGER);
VAR
data: INTEGER;
BEGIN
SYSTEM.GET(img + 24, data);
SYSTEM.MOVE(data + SIZE*SIZE*4*n, dst + SIZE*SIZE*4*m, SIZE*SIZE*4)
END copy;
PROCEDURE iconsBackColor (icons: INTEGER; BackColor: INTEGER); PROCEDURE iconsBackColor (icons: INTEGER; BackColor: INTEGER);
VAR VAR
width, height, data, x, y, pix: INTEGER; data, x, y, pix: INTEGER;
b, g, r, gr: BYTE; b, g, r, gr: BYTE;
BEGIN BEGIN
GetInf(icons, width, height, data); data := icons;
FOR y := 0 TO height - 1 DO FOR y := 0 TO SIZE*NumberOfIcons - 1 DO
FOR x := 0 TO width - 1 DO FOR x := 0 TO SIZE - 1 DO
SYSTEM.GET32(data, pix); SYSTEM.GET32(data, pix);
Graph.getRGB(pix, r, g, b); Graph.getRGB(pix, r, g, b);
gr := (r + g + b) DIV 3; gr := (r + g + b) DIV 3;
IF BackColor = -1 THEN IF BackColor = -1 THEN
pix := gr + 256*gr + 65536*gr pix := gr + 256*gr + 65536*gr
ELSIF gr = 255 THEN ELSIF gr = 255 THEN
pix := BackColor pix := BackColor
END; END;
SYSTEM.PUT32(data, pix); SYSTEM.PUT32(data, pix);
INC(data, 4) INC(data, 4)
END END
END END
END iconsBackColor; END iconsBackColor;
PROCEDURE get* (VAR icons, grayIcons: INTEGER; BackColor: INTEGER); PROCEDURE get* (VAR icons, grayIcons: INTEGER; BackColor: INTEGER);
VAR
source: INTEGER;
BEGIN BEGIN
IF source = 0 THEN source := load();
source := load(); IF source # 0 THEN
icons := load(); icons := KOSAPI.malloc(SIZE*SIZE*4*NumberOfIcons*2);
grayIcons := load(); grayIcons := icons + SIZE*SIZE*4*NumberOfIcons;
iconsBackColor(grayIcons, -1);
iconsBackColor(grayIcons, BackColor); copy(source, 2, icons, icoNew);
iconsBackColor(icons, BackColor) copy(source, 0, icons, icoOpen);
(*ELSE copy(source, 5, icons, icoSave);
copy(source, icons); copy(source, 49, icons, icoSearch);
copy(source, grayIcons)*) copy(source, 37, icons, icoUndo);
END copy(source, 36, icons, icoRedo);
copy(source, 54, icons, icoBuild);
copy(source, 53, icons, icoRun);
img_destroy(source);
source := 0;
SYSTEM.MOVE(icons, grayIcons, SIZE*SIZE*4*NumberOfIcons);
iconsBackColor(grayIcons, -1);
iconsBackColor(grayIcons, BackColor);
iconsBackColor(icons, BackColor)
END
END get; END get;
BEGIN
source := 0
END Icons. END Icons.

View File

@ -439,7 +439,8 @@ PROCEDURE loadKW (lang: INTEGER; VAR KW: ARRAY OF tKeyWords; VAR delim: tDelimit
VAR VAR
s: ARRAY 16*1024 OF CHAR; s: ARRAY 16*1024 OF CHAR;
key: ARRAY 4 OF CHAR; key: ARRAY 4 OF CHAR;
i: INTEGER; i, j, k: INTEGER;
w: WCHAR;
BEGIN BEGIN
FOR i := 0 TO LEN(delim) - 1 DO FOR i := 0 TO LEN(delim) - 1 DO
delim[i] := FALSE delim[i] := FALSE
@ -458,6 +459,19 @@ BEGIN
IF ~(lang IN csLang) THEN IF ~(lang IN csLang) THEN
Utils.upcase(s) Utils.upcase(s)
END; END;
IF lang = langOberon THEN
k := LENGTH(s);
s[k] := ",";
FOR j := 0 TO k - 1 DO
s[j + k + 1] := s[j];
w := WCHR(ORD(s[j]));
IF Utils.low(w) THEN
s[j + k + 1] := CHR(ORD(w) MOD 256)
END
END;
k := 2*k + 1;
s[k] := 0X
END;
EnterKW(s, KW[i]) EnterKW(s, KW[i])
END END
END loadKW; END loadKW;

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021, 2022 Anton Krotov Copyright 2021-2023 Anton Krotov
This file is part of CEdit. This file is part of CEdit.
@ -238,6 +238,7 @@ BEGIN
m.active := FALSE; m.active := FALSE;
resetTimer; resetTimer;
m.tid := 0; m.tid := 0;
G.destroy(m.canvas);
K.Exit K.Exit
END exit; END exit;
@ -249,6 +250,7 @@ BEGIN
resetTimer resetTimer
END; END;
m.tid := 0; m.tid := 0;
G.destroy(m.canvas);
K.Exit K.Exit
END escape; END escape;
@ -354,6 +356,7 @@ BEGIN
END; END;
temp := m.tid; temp := m.tid;
m.tid := 0; m.tid := 0;
G.destroy(m.canvas);
K.ExitID(temp); K.ExitID(temp);
m.active := FALSE m.active := FALSE
END END
@ -509,6 +512,7 @@ BEGIN
IF m.parent # NIL THEN IF m.parent # NIL THEN
temp := m.parent.tid; temp := m.parent.tid;
m.parent.tid := 0; m.parent.tid := 0;
G.destroy(m.parent.canvas);
K.ExitID(temp) K.ExitID(temp)
END; END;
exit(m) exit(m)
@ -567,6 +571,10 @@ BEGIN
IF K.GetThreadSlot(TIDs[L]) = 0 THEN IF K.GetThreadSlot(TIDs[L]) = 0 THEN
m.winX := x; m.winX := x;
m.winY := y; m.winY := y;
IF m.canvas = NIL THEN
m.canvas := G.CreateCanvas(m.width + 1, m.height + 1);
G.SetFont(m.canvas, m.font)
END;
SYSTEM.PUT(SYSTEM.ADR(stack[L][LEN(stack[0]) - 1]), m); SYSTEM.PUT(SYSTEM.ADR(stack[L][LEN(stack[0]) - 1]), m);
m.tid := K.CreateThread(SYSTEM.ADR(window), stack[L]); m.tid := K.CreateThread(SYSTEM.ADR(window), stack[L]);
TIDs[L] := m.tid TIDs[L] := m.tid
@ -678,8 +686,8 @@ BEGIN
m.width := maxLength*fontWidth + LEFT + RIGHT; m.width := maxLength*fontWidth + LEFT + RIGHT;
m.height := items.count*itemHeight - 2; m.height := items.count*itemHeight - 2;
m.font := G.fonts[1]; m.font := G.fonts[1];
m.canvas := G.CreateCanvas(m.width + 1, m.height + 1); (* m.canvas := G.CreateCanvas(m.width + 1, m.height + 1);
G.SetFont(m.canvas, m.font) G.SetFont(m.canvas, m.font)*)
RETURN m RETURN m
END create; END create;

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021, 2022 Anton Krotov Copyright 2021-2023 Anton Krotov
This file is part of CEdit. This file is part of CEdit.
@ -136,7 +136,7 @@ BEGIN
END; END;
IF n = -1 THEN IF n = -1 THEN
code := E.UNDEF code := -1
END END
RETURN code RETURN code
@ -244,7 +244,7 @@ BEGIN
text.cnt := cnt; text.cnt := cnt;
text.pos := pos; text.pos := pos;
WHILE (text.cnt > 0) & continue DO WHILE (text.cnt > 0) & continue DO
IF getCharUTF8(text) = E.UNDEF THEN IF getCharUTF8(text) = -1 THEN
continue := FALSE continue := FALSE
END END
END; END;
@ -470,40 +470,27 @@ BEGIN
putByte(file, (code DIV 64) MOD 64 + 080H); putByte(file, (code DIV 64) MOD 64 + 080H);
putByte(file, code MOD 64 + 080H) putByte(file, code MOD 64 + 080H)
ELSE ELSE
putByte(file, ORD("?")) putByte(file, E.UNDEF)
END END
END putCharUTF8; END putCharUTF8;
PROCEDURE putCharCP (file: tOutput; code, cp: INTEGER);
VAR
n: INTEGER;
BEGIN
n := E.UNI[code, cp];
IF n # E.UNDEF THEN
putByte(file, n)
ELSE
putByte(file, ORD("?"))
END
END putCharCP;
PROCEDURE putCharCP1251 (file: tOutput; code: INTEGER); PROCEDURE putCharCP1251 (file: tOutput; code: INTEGER);
BEGIN BEGIN
putCharCP(file, code, E.CP1251) putByte(file, E.UNI[code, E.CP1251])
END putCharCP1251; END putCharCP1251;
PROCEDURE putCharCP866 (file: tOutput; code: INTEGER); PROCEDURE putCharCP866 (file: tOutput; code: INTEGER);
BEGIN BEGIN
putCharCP(file, code, E.CP866) putByte(file, E.UNI[code, E.CP866])
END putCharCP866; END putCharCP866;
(* (*
PROCEDURE putCharUTF16LE (file: tOutput; code: INTEGER); PROCEDURE putCharUTF16LE (file: tOutput; code: INTEGER);
BEGIN BEGIN
IF ~((0 <= code) & (code <= 65535)) THEN IF ~((0 <= code) & (code <= 65535)) THEN
code := ORD("?") code := E.UNDEF
END; END;
putByte(file, code MOD 256); putByte(file, code MOD 256);
putByte(file, code DIV 256) putByte(file, code DIV 256)

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021, 2022 Anton Krotov Copyright 2021-2023 Anton Krotov
This file is part of CEdit. This file is part of CEdit.
@ -24,17 +24,19 @@ IMPORT
TYPE TYPE
tBuffer* = CB.tBuffer; tBuffer* = CB.tBuffer;
IdxTable* = ARRAY 65536, 2 OF INTEGER; tIdxTable = ARRAY 65536, 2 OF INTEGER;
tPos* = POINTER TO RECORD (List.tItem) tPos* = POINTER TO RECORD (List.tItem)
pos*: INTEGER pos*: INTEGER
END; END;
VAR
table: POINTER TO RECORD data: tIdxTable END;
PROCEDURE index* (text: tBuffer; VAR table: IdxTable; cs: BOOLEAN): tBuffer;
PROCEDURE _index (text: tBuffer; cs: BOOLEAN; VAR table: tIdxTable): tBuffer;
VAR VAR
pChar, cnt, i: INTEGER; pChar, cnt, i: INTEGER;
c: WCHAR; c: WCHAR;
@ -80,19 +82,29 @@ BEGIN
END END
RETURN res RETURN res
END _index;
PROCEDURE index* (text: tBuffer; cs: BOOLEAN): tBuffer;
BEGIN
IF table = NIL THEN
NEW(table)
END
RETURN _index(text, cs, table.data)
END index; END index;
PROCEDURE find* (text: tBuffer; table: IdxTable; s: ARRAY OF WCHAR; whole: BOOLEAN; list: List.tList); PROCEDURE find* (text: tBuffer; s: ARRAY OF WCHAR; whole: BOOLEAN; list: List.tList);
VAR VAR
k, pos, n, x, prev_item_pos: INTEGER; k, pos, n, x, prev_item_pos: INTEGER;
item: tPos; item: tPos;
c1, c2: WCHAR; c1, c2: WCHAR;
flag: BOOLEAN; flag: BOOLEAN;
BEGIN BEGIN
ASSERT(table # NIL);
n := LENGTH(s); n := LENGTH(s);
k := table[ORD(s[0]), 1]; k := table.data[ORD(s[0]), 1];
pos := table[ORD(s[0]), 0]; pos := table.data[ORD(s[0]), 0];
prev_item_pos := 0; prev_item_pos := 0;
WHILE k > 0 DO WHILE k > 0 DO
SYSTEM.GET(pos, x); SYSTEM.GET(pos, x);
@ -105,7 +117,8 @@ BEGIN
c1 := 0X c1 := 0X
END; END;
SYSTEM.GET(text.dataPtr + (x + n)*SYSTEM.SIZE(WCHAR), c2); SYSTEM.GET(text.dataPtr + (x + n)*SYSTEM.SIZE(WCHAR), c2);
flag := Utils.isLetter(c1) OR Utils.isLetter(c2) OR Utils.isDigit(c1) OR Utils.isDigit(c2) OR (c1 = "_") OR (c2 = "_") flag := Utils.isLetter(c1) OR Utils.isLetter(c2) OR Utils.isDigit(c1) OR Utils.isDigit(c2) OR
(c1 = "_") OR (c2 = "_")
END; END;
IF ~flag & (x >= prev_item_pos) THEN IF ~flag & (x >= prev_item_pos) THEN
prev_item_pos := x + n; prev_item_pos := x + n;
@ -120,4 +133,14 @@ BEGIN
END find; END find;
PROCEDURE close*;
BEGIN
IF table # NIL THEN
DISPOSE(table)
END
END close;
BEGIN
table := NIL
END Search. END Search.

View File

@ -100,7 +100,6 @@ VAR
size, textsize: tPoint; size, textsize: tPoint;
charWidth, charHeight: INTEGER; charWidth, charHeight: INTEGER;
autoIndents*, lineNumbers*, autoBrackets*, trimSpace*: BOOLEAN; autoIndents*, lineNumbers*, autoBrackets*, trimSpace*: BOOLEAN;
idxTable: Search.IdxTable;
PROCEDURE setLang* (text: tText; lang: INTEGER); PROCEDURE setLang* (text: tText; lang: INTEGER);
@ -911,9 +910,11 @@ BEGIN
END; END;
IF text.searchText # "" THEN IF text.searchText # "" THEN
plainText := plain(text); plainText := plain(text);
idxData := Search.index(plainText, idxTable, cs); idxData := Search.index(plainText, cs);
Search.find(plainText, idxTable, text.searchText, whole, text.foundList); Search.find(plainText, text.searchText, whole, text.foundList);
res := text.foundList.count > 0 res := text.foundList.count > 0
ELSE
Search.close
END; END;
CB.destroy(plainText); CB.destroy(plainText);
CB.destroy(idxData); CB.destroy(idxData);
@ -2462,7 +2463,7 @@ END draw;
PROCEDURE switch* (text: tText); PROCEDURE switch* (text: tText);
BEGIN BEGIN
ChangeLog.set(text.chLog); ChangeLog.setLog(text.chLog);
Lines.setMaxLength(text.maxLength); Lines.setMaxLength(text.maxLength);
Lang.setCurLang(text.lang) Lang.setCurLang(text.lang)
END switch; END switch;

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021, 2022 Anton Krotov Copyright 2021-2023 Anton Krotov
This file is part of CEdit. This file is part of CEdit.
@ -92,7 +92,9 @@ VAR
button: tButton; button: tButton;
BEGIN BEGIN
setColors(toolbar); setColors(toolbar);
Icons.get(toolbar.icons, toolbar.grayIcons, toolbar.colors.back); IF (toolbar.icons = 0) OR (toolbar.grayIcons = 0) THEN
Icons.get(toolbar.icons, toolbar.grayIcons, toolbar.colors.back)
END;
i := 0; i := 0;
WHILE i < toolbar.cnt DO WHILE i < toolbar.cnt DO
button := toolbar.buttons[i]; button := toolbar.buttons[i];
@ -160,7 +162,9 @@ BEGIN
toolbar.x := x; toolbar.x := x;
toolbar.y := y; toolbar.y := y;
toolbar.cnt := 0; toolbar.cnt := 0;
toolbar.width := 0 toolbar.width := 0;
toolbar.icons := 0;
toolbar.grayIcons := 0;
END create; END create;