CEdit: refactoring, minor fixes

git-svn-id: svn://kolibrios.org@9659 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2022-01-20 17:15:39 +00:00
parent 23e31695bd
commit c327661fd8
15 changed files with 374 additions and 486 deletions

Binary file not shown.

View File

@ -28,7 +28,7 @@ IMPORT
RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar;
CONST
HEADER = "CEdit (18-jan-2022)";
HEADER = "CEdit (20-jan-2022)";
ShellFilter = "";
EditFilter = "SH|INC|TXT|ASM|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON";
@ -354,7 +354,7 @@ BEGIN
SB.setWidth(canvas.width + scrollWidth);
SB.setPos(line, col);
SB.setSel(chars, lines);
SB.setEnc(RW.eolNames[T.getEol(text)], E.names[T.getEnc(text)]);
SB.setEnc(E.eolNames[T.getEol(text)], E.names[T.getEnc(text)]);
SB.draw(LEFT, height - BOTTOM + scrollWidth - 1);
Tabs.modify(tabs, getIdx(text), text.modified)
END Status;
@ -833,19 +833,19 @@ BEGIN
END createSearchForm;
PROCEDURE EditBox_GetValue (edit: EB.tEditBox; VAR s: ARRAY OF WCHAR);
PROCEDURE EditBox_Get (edit: EB.tEditBox; VAR s: ARRAY OF WCHAR);
VAR
str: ARRAY EDITBOX_MAXCHARS + 1 OF CHAR;
i: INTEGER;
BEGIN
EB.getValue(edit, str);
EB.get(edit, str);
i := 0;
WHILE str[i] # 0X DO
s[i] := WCHR(E.cp866[ORD(str[i])]);
INC(i)
END;
s[i] := 0X
END EditBox_GetValue;
END EditBox_Get;
PROCEDURE Search;
@ -927,7 +927,7 @@ PROCEDURE goto;
VAR
gotoVal: INTEGER;
BEGIN
EditBox_GetValue(GotoEdit, gotoText);
EditBox_Get(GotoEdit, gotoText);
IF U.str2int(gotoText, gotoVal) & T.goto(text, gotoVal) THEN
SetFocus(GotoEdit, FALSE)
END
@ -957,7 +957,7 @@ BEGIN
END;
IF new_searchText[i] = 0X THEN
searchText := new_searchText;
EB.setValue(FindEdit, searchText);
EB.set(FindEdit, searchText);
notFound := ~T.search(text, searchText, cs, whole);
END
END
@ -1077,9 +1077,9 @@ BEGIN
Menu.setEnabled(subCase, menuUpper, selected);
Menu.setEnabled(subCase, menuLower, selected);
Menu.option(subEOL, menuCRLF, T.getEol(text) = RW.EOL_CRLF);
Menu.option(subEOL, menuLF, T.getEol(text) = RW.EOL_LF);
Menu.option(subEOL, menuCR, T.getEol(text) = RW.EOL_CR);
Menu.option(subEOL, menuCRLF, T.getEol(text) = E.EOL_CRLF);
Menu.option(subEOL, menuLF, T.getEol(text) = E.EOL_LF);
Menu.option(subEOL, menuCR, T.getEol(text) = E.EOL_CR);
IF menu # NIL THEN
timerEnabled := FALSE;
@ -1209,11 +1209,11 @@ BEGIN
|menuWin1251:
T.setEnc(text, E.W1251)
|menuLF:
T.setEol(text, RW.EOL_LF)
T.setEol(text, E.EOL_LF)
|menuCRLF:
T.setEol(text, RW.EOL_CRLF)
T.setEol(text, E.EOL_CRLF)
|menuCR:
T.setEol(text, RW.EOL_CR)
T.setEol(text, E.EOL_CR)
|menuPipet:
K.Run("/sys/develop/pipet", "")
|menuMagnify:
@ -1344,9 +1344,9 @@ VAR
menu: List.tList;
BEGIN
menu := List.create(NIL);
Menu.AddMenuItem(menu, menuCRLF, RW.eolNames[RW.EOL_CRLF]);
Menu.AddMenuItem(menu, menuLF, RW.eolNames[RW.EOL_LF]);
Menu.AddMenuItem(menu, menuCR, RW.eolNames[RW.EOL_CR]);
Menu.AddMenuItem(menu, menuCRLF, E.eolNames[E.EOL_CRLF]);
Menu.AddMenuItem(menu, menuLF, E.eolNames[E.EOL_LF]);
Menu.AddMenuItem(menu, menuCR, E.eolNames[E.EOL_CR]);
RETURN Menu.create(menu)
END CreateMenuEOL;
@ -1591,7 +1591,7 @@ BEGIN
SetFocus(ReplaceEdit, TRUE)
ELSE
EB.key(FindEdit, key);
EditBox_GetValue(FindEdit, new_searchText);
EditBox_Get(FindEdit, new_searchText);
IF new_searchText # searchText THEN
searchText := new_searchText;
notFound := ~T.search(text, searchText, cs, whole)
@ -1602,7 +1602,7 @@ BEGIN
SetFocus(GotoEdit, TRUE)
ELSE
EB.key(ReplaceEdit, key);
EditBox_GetValue(ReplaceEdit, replaceText)
EditBox_Get(ReplaceEdit, replaceText)
END
ELSIF EditBox_Focus(GotoEdit) THEN
IF keyCode = 15 THEN (* Tab *)
@ -1886,11 +1886,9 @@ BEGIN
cliHeight := height;
resize;
resized := TRUE
END;
K.SetEventsMask({0, 1, 2, 5, 31})
END
ELSE
SetCaption(text.fileName);
K.SetEventsMask({0, 30, 31})
SetCaption(text.fileName)
END;
draw_window;
IF SkinHeight # K.SkinHeight() THEN
@ -1921,6 +1919,7 @@ VAR
width, height, cliWidth, cliHeight: INTEGER;
resized: BOOLEAN;
firstClickX, firstClickY, time, blink, i: INTEGER;
key, scr: INTEGER;
BEGIN
header := "";
K.GetSystemColors;
@ -2047,8 +2046,9 @@ BEGIN
timerEnabled := TRUE;
CursorTime := K.GetTickCount();
WHILE TRUE DO
CurrentTime := K.GetTickCount();
IF (CurrentTime - CursorTime > blink) & (blink > 0) & timerEnabled THEN
IF (CurrentTime - CursorTime > blink) & (blink > 0) & timerEnabled & ~K.RolledUp() THEN
CursorTime := CurrentTime;
T.toggleCursor;
repaint
@ -2057,9 +2057,18 @@ BEGIN
CASE K.EventTimeout(10) OF
|0:
|1: Redraw(resized, width, height, cliWidth, cliHeight)
|2: KeyDown(K.GetKey())
|2:
key := K.GetKey();
IF ~K.RolledUp() THEN
KeyDown(key)
END
|3: BtnClick
|6: MouseEvent(resized, firstClickX, firstClickY, time)
|6:
IF ~K.RolledUp() THEN
MouseEvent(resized, firstClickX, firstClickY, time)
ELSE
scr := K.Scroll()
END
END
END
END main;

View File

@ -34,7 +34,6 @@ TYPE
tCheckBox* = RECORD
left*, top*: INTEGER;
width, height: INTEGER;
value*, mouse: BOOLEAN;
text: ARRAY 32 OF WCHAR;
canvas: G.tCanvas
@ -56,14 +55,14 @@ BEGIN
G.Rect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
IF chkbox.value THEN
G.SetColor(canvas, fColor);
G.DLine(canvas, 2, 6, 6, -1);
G.DLine(canvas, 2, 6, 7, -1);
G.DLine(canvas, 7, 13, 9, 1);
G.DLine(canvas, 7, 13, 10, 1);
G.DLine(canvas, 2, 6, 8, -1);
G.DLine(canvas, 7, 13, 11, 1);
G.DLine(canvas, 2, 6, 5, -1);
G.DLine(canvas, 7, 13, 8, 1);
G.DLine(canvas, 2, 6, 6, -1);
G.DLine(canvas, 2, 6, 7, -1);
G.DLine(canvas, 7, 13, 9, 1);
G.DLine(canvas, 7, 13, 10, 1);
G.DLine(canvas, 2, 6, 8, -1);
G.DLine(canvas, 7, 13, 11, 1);
G.DLine(canvas, 2, 6, 5, -1);
G.DLine(canvas, 7, 13, 8, 1);
END;
G.SetTextColor(canvas, K.colors.work_text);
G.SetBkColor(canvas, K.colors.work);
@ -84,8 +83,6 @@ BEGIN
COPY(text, res.text);
res.canvas := G.CreateCanvas(fontHeight + padding + LENGTH(res.text)*fontWidth, fontHeight + 1);
G.SetFont(res.canvas, G.CreateFont(1, "", {}));
res.width := res.canvas.width;
res.height := res.canvas.height;
chkbox := res
END create;
@ -101,8 +98,8 @@ BEGIN
DEC(x, chkbox.left);
DEC(y, chkbox.top);
chkbox.mouse := TRUE;
IF U.between(0, x, chkbox.width - 1) & U.between(0, y, chkbox.height - 1) THEN
chkbox.value := ~chkbox.value;
IF U.between(0, x, chkbox.canvas.width - 1) & U.between(0, y, chkbox.canvas.height - 1) THEN
chkbox.value := ~chkbox.value
END;
draw(chkbox)
END

View File

@ -51,28 +51,27 @@ TYPE
PROCEDURE [stdcall, "box_lib.obj", "edit_box_draw"] draw* (eb: tEditBox); END;
PROCEDURE [stdcall, "box_lib.obj", "edit_box_mouse"] mouse* (eb: tEditBox); END;
PROCEDURE [stdcall, "box_lib.obj", "edit_box_set_text"] _setValue (eb: tEditBox; text: INTEGER); END;
PROCEDURE [stdcall, "box_lib.obj", "edit_box_set_text"] set_text (eb: tEditBox; text: INTEGER); END;
PROCEDURE [stdcall, "box_lib.obj", "edit_box_key_safe"] key* (eb: tEditBox; key: INTEGER); END;
PROCEDURE getValue* (text: tEditBox; VAR str: ARRAY OF CHAR);
PROCEDURE get* (text: tEditBox; VAR str: ARRAY OF CHAR);
VAR
ptr, max, i: INTEGER;
ptr, max, i: INTEGER;
BEGIN
ptr := text.text;
max := text.max;
ASSERT(max < LEN(str));
i := 0;
REPEAT
SYSTEM.GET(ptr, str[i]);
INC(i);
INC(ptr)
UNTIL (str[i - 1] = 0X) OR (i = max);
str[i] := 0X
END getValue;
ptr := text.text;
max := text.max;
ASSERT(max < LEN(str));
i := 0;
REPEAT
SYSTEM.GET(ptr, str[i]);
INC(i);
INC(ptr)
UNTIL (str[i - 1] = 0X) OR (i = max);
str[i] := 0X
END get;
PROCEDURE setValue* (text: tEditBox; str: ARRAY OF WCHAR);
PROCEDURE set* (text: tEditBox; str: ARRAY OF WCHAR);
VAR
i: INTEGER;
temp: ARRAY MAX_LENGTH OF CHAR;
@ -83,25 +82,25 @@ BEGIN
temp[i] := CHR(Encodings.UNI[ORD(str[i]), Encodings.CP866] MOD 256);
INC(i)
UNTIL str[i - 1] = 0X;
_setValue(text, SYSTEM.ADR(temp[0]))
END setValue;
set_text(text, SYSTEM.ADR(temp[0]))
END set;
PROCEDURE create* (tlx, tly, width, max_chars: INTEGER; VAR editbox: tEditBox);
PROCEDURE create* (x, y, width, max_chars: INTEGER; VAR editbox: tEditBox);
BEGIN
editbox.width := width;
editbox.left := tlx;
editbox.top := tly;
editbox.color := 0FFFFFFH;
editbox.shift_color := 06A9480H;
editbox.focus_border_color := 0;
editbox.blur_border_color := 06A9480H;
editbox.text_color := 30000000H;
editbox.max := max_chars;
editbox.text := KOSAPI.malloc(max_chars + 2);
ASSERT(editbox.text # 0);
editbox.mouse_variable := 0;
editbox.flags := {14}
editbox.width := width;
editbox.left := x;
editbox.top := y;
editbox.color := 0FFFFFFH;
editbox.shift_color := 06A9480H;
editbox.focus_border_color := 0;
editbox.blur_border_color := 06A9480H;
editbox.text_color := 30000000H;
editbox.max := max_chars;
editbox.text := KOSAPI.malloc(max_chars + 2);
ASSERT(editbox.text # 0);
editbox.mouse_variable := 0;
editbox.flags := {14}
END create;

View File

@ -1,5 +1,5 @@
(*
Copyright 2021 Anton Krotov
Copyright 2021, 2022 Anton Krotov
This file is part of CEdit.
@ -20,18 +20,26 @@
MODULE Encodings;
CONST
CP866* = 0; W1251* = 1; UTF8* = 2; UTF8BOM* = 3; UTF16LE* = 4;
CP866* = 0; W1251* = 1; UTF8* = 2; UTF8BOM* = 3; (*UTF16LE* = 4;*)
UNDEF* = -1;
EOL_CRLF* = 0; EOL_LF* = 1; EOL_CR* = 2;
CR = 0DX; LF = 0AX;
TYPE
CP = ARRAY 256 OF INTEGER;
tEOL* = ARRAY 3 OF WCHAR;
VAR
cpW1251*, cp866*: CP;
names*: ARRAY 4, 16 OF WCHAR;
UNI*: ARRAY 65536, 2 OF INTEGER;
eol*: ARRAY 3 OF tEOL;
eolNames*: ARRAY 3, 16 OF WCHAR;
PROCEDURE InitCP (VAR cp: CP);
VAR
@ -60,6 +68,10 @@ PROCEDURE InitW1251 (VAR cp: CP);
VAR
n, i: INTEGER;
BEGIN
InitCP(cp);
FOR i := 0410H TO 044FH DO
cp[i - 350H] := i
END;
n := 80H;
Init8(cp, n, 0402H, 0403H, 201AH, 0453H, 201EH, 2026H, 2020H, 2021H);
Init8(cp, n, 20ACH, 2030H, 0409H, 2039H, 040AH, 040CH, 040BH, 040FH);
@ -69,10 +81,6 @@ BEGIN
Init8(cp, n, 0401H, 00A9H, 0404H, 00ABH, 00ACH, 00ADH, 00AEH, 0407H);
Init8(cp, n, 00B0H, 00B1H, 0406H, 0456H, 0491H, 00B5H, 00B6H, 00B7H);
Init8(cp, n, 0451H, 2116H, 0454H, 00BBH, 0458H, 0405H, 0455H, 0457H);
FOR i := 0410H TO 044FH DO
cp[i - 350H] := i
END;
InitCP(cp)
END InitW1251;
@ -80,11 +88,12 @@ PROCEDURE InitCP866 (VAR cp: CP);
VAR
n, i: INTEGER;
BEGIN
InitCP(cp);
FOR i := 0410H TO 043FH DO
cp[i - 0410H + 80H] := i
cp[i - 390H] := i
END;
FOR i := 0440H TO 044FH DO
cp[i - 0440H + 0E0H] := i
cp[i - 360H] := i
END;
n := 0B0H;
Init8(cp, n, 2591H, 2592H, 2593H, 2502H, 2524H, 2561H, 2562H, 2556H);
@ -93,12 +102,9 @@ BEGIN
Init8(cp, n, 255AH, 2554H, 2569H, 2566H, 2560H, 2550H, 256CH, 2567H);
Init8(cp, n, 2568H, 2564H, 2565H, 2559H, 2558H, 2552H, 2553H, 256BH);
Init8(cp, n, 256AH, 2518H, 250CH, 2588H, 2584H, 258CH, 2590H, 2580H);
n := 0F0H;
Init8(cp, n, 0401H, 0451H, 0404H, 0454H, 0407H, 0457H, 040EH, 045EH);
Init8(cp, n, 00B0H, 2219H, 00B7H, 221AH, 2116H, 00A4H, 25A0H, 00A0H);
InitCP(cp)
END InitCP866;
@ -108,7 +114,7 @@ VAR
BEGIN
FOR i := 0 TO 65535 DO
UNI[i, CP866] := UNDEF;
UNI[i, W1251] := UNDEF;
UNI[i, W1251] := UNDEF
END;
FOR i := 0 TO 255 DO
IF cpW1251[i] # UNDEF THEN
@ -122,6 +128,12 @@ END setUNI;
BEGIN
eol[EOL_CRLF] := CR + LF;
eol[EOL_LF] := LF;
eol[EOL_CR] := CR;
eolNames[EOL_CRLF] := "CRLF";
eolNames[EOL_LF] := "LF";
eolNames[EOL_CR] := "CR";
names[CP866] := "CP866";
names[W1251] := "Windows-1251";
names[UTF8] := "UTF-8";

View File

@ -20,106 +20,123 @@
MODULE Icons;
IMPORT
LibImg, K := KolibriOS, Graph, SYSTEM;
Graph, File, SYSTEM, KOSAPI;
CONST
fileName = "/sys/Icons16.png";
SIZE* = 18;
fileName = "/sys/Icons16.png";
SIZE* = 18;
VAR
source: INTEGER;
source: INTEGER;
(*
PROCEDURE copy (src, dst: INTEGER);
VAR
src_sizeX, src_sizeY, dst_sizeX, dst_sizeY,
src_data, dst_data: INTEGER;
src_width, src_height,
dst_width, dst_height,
src_data, dst_data: INTEGER;
BEGIN
LibImg.GetInf(src, src_sizeX, src_sizeY, src_data);
LibImg.GetInf(dst, dst_sizeX, dst_sizeY, dst_data);
ASSERT(src_sizeX = dst_sizeX);
ASSERT(src_sizeY = dst_sizeY);
SYSTEM.MOVE(src_data, dst_data, src_sizeX*src_sizeY*3)
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_convert (src, dst, dst_type, flags, param: INTEGER): 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;
VAR
image_data, dst, x, type: INTEGER;
BEGIN
image_data := img_decode(ptr, size, 0);
IF image_data # 0 THEN
SYSTEM.GET(image_data + 4, x);
ASSERT(x = SIZE);
SYSTEM.GET(image_data + 20, type);
IF type # 3 THEN
dst := img_convert(image_data, 0, 3, 0, 0);
img_destroy(image_data);
image_data := dst
END
END
RETURN image_data
END GetImg;
PROCEDURE load (): INTEGER;
VAR
y: INTEGER;
size, res, ptr: INTEGER;
BEGIN
RETURN LibImg.LoadFromFile(fileName, SIZE, y)
res := 0;
ptr := File.Load(fileName, size);
IF ptr # 0 THEN
res := GetImg(ptr, size);
ptr := KOSAPI.free(ptr)
END
RETURN res
END load;
PROCEDURE draw* (icons, n, x, y: INTEGER);
VAR
sizeX, sizeY, data: INTEGER;
width, height, data: INTEGER;
BEGIN
LibImg.GetInf(icons, sizeX, sizeY, data);
K.DrawImage(data + SIZE*SIZE*3*n, SIZE, SIZE, x, y)
GetInf(icons, width, height, data);
KOSAPI.sysfunc7(65, data + SIZE*SIZE*4*n, SIZE*65536 + SIZE, x*65536 + y, 32, 0, 0)
END draw;
PROCEDURE gray (icons: INTEGER);
VAR
sizeX, sizeY, data, x, y: INTEGER;
b, g, r, gr: BYTE;
BEGIN
LibImg.GetInf(icons, sizeX, sizeY, data);
FOR y := 0 TO sizeY - 1 DO
FOR x := 0 TO sizeX - 1 DO
SYSTEM.GET8(data, b);
SYSTEM.GET8(data + 1, g);
SYSTEM.GET8(data + 2, r);
gr := (r + g + b) DIV 3;
SYSTEM.PUT8(data, gr);
SYSTEM.PUT8(data + 1, gr);
SYSTEM.PUT8(data + 2, gr);
INC(data, 3);
END
END
END gray;
PROCEDURE iconsBackColor (icons: INTEGER; BackColor: INTEGER);
VAR
sizeX, sizeY, data, x, y: INTEGER;
b, g, r: BYTE;
width, height, data, x, y, pix: INTEGER;
b, g, r, gr: BYTE;
BEGIN
LibImg.GetInf(icons, sizeX, sizeY, data);
FOR y := 0 TO sizeY - 1 DO
FOR x := 0 TO sizeX - 1 DO
SYSTEM.GET8(data, b);
SYSTEM.GET8(data + 1, g);
SYSTEM.GET8(data + 2, r);
IF b + g + r = 765 THEN
Graph.getRGB(BackColor, r, g, b)
END;
SYSTEM.PUT8(data, b);
SYSTEM.PUT8(data + 1, g);
SYSTEM.PUT8(data + 2, r);
INC(data, 3);
END
END
GetInf(icons, width, height, data);
FOR y := 0 TO height - 1 DO
FOR x := 0 TO width - 1 DO
SYSTEM.GET32(data, pix);
Graph.getRGB(pix, r, g, b);
gr := (r + g + b) DIV 3;
IF BackColor = -1 THEN
pix := gr + 256*gr + 65536*gr
ELSIF gr = 255 THEN
pix := BackColor
END;
SYSTEM.PUT32(data, pix);
INC(data, 4)
END
END
END iconsBackColor;
PROCEDURE get* (VAR icons, grayIcons: INTEGER; BackColor: INTEGER);
BEGIN
IF source = 0 THEN
source := load();
icons := load();
grayIcons := load()
ELSE
copy(source, icons);
copy(source, grayIcons)
END;
gray(grayIcons);
iconsBackColor(icons, BackColor);
iconsBackColor(grayIcons, BackColor)
IF source = 0 THEN
source := load();
icons := load();
grayIcons := load();
iconsBackColor(grayIcons, -1);
iconsBackColor(grayIcons, BackColor);
iconsBackColor(icons, BackColor)
(*ELSE
copy(source, icons);
copy(source, grayIcons)*)
END;
END get;
BEGIN
source := 0
source := 0
END Icons.

View File

@ -1,5 +1,5 @@
(*
Copyright 2021 Anton Krotov
Copyright 2021, 2022 Anton Krotov
This file is part of CEdit.
@ -215,31 +215,18 @@ BEGIN
END C;
PROCEDURE getChar (line: tLine; i: INTEGER): WCHAR;
VAR
res: WCHAR;
BEGIN
IF i >= line.length THEN
res := 0X
ELSE
res := Lines.getChar(line, i)
END
RETURN res
END getChar;
PROCEDURE LuaLong* (line: tLine; pos: INTEGER): INTEGER;
VAR
res: INTEGER;
BEGIN
res := -1;
IF getChar(line, pos) = "[" THEN
IF Lines.getChar(line, pos) = "[" THEN
INC(pos);
WHILE getChar(line, pos) = "=" DO
WHILE Lines.getChar(line, pos) = "=" DO
INC(res);
INC(pos)
END;
IF getChar(line, pos) = "[" THEN
IF Lines.getChar(line, pos) = "[" THEN
INC(res)
ELSE
res := -1

View File

@ -184,10 +184,14 @@ END resize;
PROCEDURE getChar* (line: tLine; i: INTEGER): WCHAR;
VAR
c: WCHAR;
res: WCHAR;
BEGIN
SYSTEM.GET(line.ptr + i*WCHAR_SIZE, c)
RETURN c
IF i >= line.length THEN
res := 0X
ELSE
SYSTEM.GET(line.ptr + i*WCHAR_SIZE, res)
END
RETURN res
END getChar;

View File

@ -88,7 +88,6 @@ TYPE
key, MenuItem: INTEGER
END;
tClick = PROCEDURE (menu: tMenu; id: INTEGER);
tProc = PROCEDURE;
VAR

View File

@ -33,15 +33,11 @@ CONST
NAME_LEN = 1024;
EOL_CRLF* = 0; EOL_LF* = 1; EOL_CR* = 2;
TYPE
tFileName* = ARRAY NAME_LEN OF CHAR;
tEOL = ARRAY 3 OF WCHAR;
tInput* = POINTER TO RECORD
buffer: INTEGER;
strBuf: Lines.tLine;
@ -55,18 +51,12 @@ TYPE
handle: File.FS;
buffer: ARRAY BUF_SIZE OF BYTE;
pos: INTEGER;
eol: tEOL;
eol: E.tEOL;
putChar: PROCEDURE (file: tOutput; code: INTEGER);
error: BOOLEAN
END;
VAR
eol*: ARRAY 3 OF tEOL;
eolNames*: ARRAY 3, 16 OF WCHAR;
PROCEDURE getByte (file: tInput): BYTE;
VAR
res: BYTE;
@ -109,7 +99,9 @@ BEGIN
ELSIF (0E0H <= b) & (b <= 0EFH) THEN
DEC(b, 0E0H);
n := 2
ELSIF (0F0H <= b) & (b <= 0F7H) THEN
ELSE
n := -1
(* ELSIF (0F0H <= b) & (b <= 0F7H) THEN
DEC(b, 0F0H);
n := 3
ELSIF (0F8H <= b) & (b <= 0FBH) THEN
@ -124,15 +116,15 @@ BEGIN
ELSIF b = 0FFH THEN
n := -1
ELSIF (080H <= b) & (b <= 0BFH) THEN
n := -1
n := -1*)
END;
code := b;
(*
IF n > 2 THEN
n := -1
END;
*)
WHILE n > 0 DO
DEC(n);
b := peakByte(file);
@ -160,11 +152,11 @@ PROCEDURE getCharCP866 (file: tInput): INTEGER;
RETURN E.cp866[getByte(file)]
END getCharCP866;
(*
PROCEDURE getCharUTF16LE (file: tInput): INTEGER;
RETURN getByte(file) + getByte(file) * 256
END getCharUTF16LE;
*)
PROCEDURE getString* (file: tInput; line: Lines.tLine; tabs: BOOLEAN; VAR eol: BOOLEAN): INTEGER;
VAR
@ -299,20 +291,20 @@ BEGIN
cnt := text.cnt;
WHILE (text.cnt > 0) & (res = -1) DO
c := text.getChar(text);
IF c = 10 THEN
res := EOL_LF
ELSIF c = 13 THEN
IF text.getChar(text) = 10 THEN
res := EOL_CRLF
IF CHR(c) = LF THEN
res := E.EOL_LF
ELSIF CHR(c) = CR THEN
IF CHR(text.getChar(text)) = LF THEN
res := E.EOL_CRLF
ELSE
res := EOL_CR
res := E.EOL_CR
END
END
END;
text.cnt := cnt;
text.pos := pos;
IF res = -1 THEN
res := EOL_CRLF
res := E.EOL_CRLF
END
RETURN res
END detectEOL;
@ -373,7 +365,7 @@ BEGIN
DISPOSE(res)
ELSE
enc := detectEncoding(res);
IF (enc = E.UTF8BOM) OR (enc = E.UTF8) THEN
IF enc IN {E.UTF8BOM, E.UTF8} THEN
res.getChar := getCharUTF8
ELSIF enc = E.CP866 THEN
res.getChar := getCharCP866
@ -427,11 +419,9 @@ VAR
BEGIN
FOR i := 0 TO n - 1 DO
c := Lines.getChar(line, i);
IF c = Lines.TAB1 THEN
(* nothing to do *)
ELSIF c = Lines.NUL THEN
IF c = Lines.NUL THEN
file.putChar(file, 0)
ELSE
ELSIF c # Lines.TAB1 THEN
file.putChar(file, ORD(c))
END
END
@ -467,32 +457,31 @@ BEGIN
END putCharUTF8;
PROCEDURE putCharW1251 (file: tOutput; code: INTEGER);
PROCEDURE putCharCP (file: tOutput; code, cp: INTEGER);
VAR
n: INTEGER;
BEGIN
n := E.UNI[code, E.W1251];
n := E.UNI[code, cp];
IF n # E.UNDEF THEN
putByte(file, n)
ELSE
putByte(file, ORD("?"))
END
END putCharCP;
PROCEDURE putCharW1251 (file: tOutput; code: INTEGER);
BEGIN
putCharCP(file, code, E.W1251)
END putCharW1251;
PROCEDURE putCharCP866 (file: tOutput; code: INTEGER);
VAR
n: INTEGER;
BEGIN
n := E.UNI[code, E.CP866];
IF n # E.UNDEF THEN
putByte(file, n)
ELSE
putByte(file, ORD("?"))
END
putCharCP(file, code, E.CP866)
END putCharCP866;
(*
PROCEDURE putCharUTF16LE (file: tOutput; code: INTEGER);
BEGIN
IF ~((0 <= code) & (code <= 65535)) THEN
@ -500,7 +489,7 @@ BEGIN
END;
putByte(file, code MOD 256);
putByte(file, code DIV 256)
END putCharUTF16LE;
END putCharUTF16LE;*)
PROCEDURE close* (VAR file: tOutput): BOOLEAN;
@ -528,15 +517,15 @@ VAR
BEGIN
NEW(res);
res.pos := 0;
res.eol := eol[nl];
res.eol := E.eol[nl];
res.putChar := NIL;
IF (enc = E.UTF8) OR (enc = E.UTF8BOM) THEN
res.putChar := putCharUTF8;
IF enc IN {E.UTF8BOM, E.UTF8} THEN
IF enc = E.UTF8BOM THEN
res.putChar(res, ORD(BOM))
END
ELSIF enc = E.UTF16LE THEN
res.putChar := putCharUTF16LE;
putCharUTF8(res, ORD(BOM))
END;
res.putChar := putCharUTF8
(*ELSIF enc = E.UTF16LE THEN
res.putChar := putCharUTF16LE*)
ELSIF enc = E.W1251 THEN
res.putChar := putCharW1251
ELSIF enc = E.CP866 THEN
@ -568,11 +557,4 @@ BEGIN
END destroy;
BEGIN
eol[EOL_CRLF] := CR + LF;
eol[EOL_LF] := LF;
eol[EOL_CR] := CR;
eolNames[EOL_CRLF] := "CRLF";
eolNames[EOL_LF] := "LF";
eolNames[EOL_CR] := "CR"
END RW.

View File

@ -1,5 +1,5 @@
(*
Copyright 2021 Anton Krotov
Copyright 2021, 2022 Anton Krotov
This file is part of CEdit.
@ -41,7 +41,7 @@ VAR
res: tBuffer;
BEGIN
pChar := text.dataPtr;
cnt := CB.bufSize(text) DIV 2;
cnt := CB.bufSize(text) DIV SYSTEM.SIZE(WCHAR);
FOR i := 0 TO 65535 DO
table[i, 1] := 0
@ -54,15 +54,15 @@ BEGIN
SYSTEM.PUT(pChar, c)
END;
INC(table[ORD(c), 1]);
INC(pChar, 2);
INC(pChar, SYSTEM.SIZE(WCHAR));
DEC(i)
END;
res := CB.create(cnt * SYSTEM.SIZE(INTEGER));
res := CB.create(cnt*SYSTEM.SIZE(INTEGER));
table[0, 0] := res.dataPtr;
FOR i := 1 TO 65535 DO
table[i, 0] := table[i - 1, 0] + table[i - 1, 1] * SYSTEM.SIZE(INTEGER)
table[i, 0] := table[i - 1, 0] + table[i - 1, 1]*SYSTEM.SIZE(INTEGER)
END;
pChar := text.dataPtr;
@ -71,12 +71,12 @@ BEGIN
SYSTEM.GET(pChar, c);
SYSTEM.PUT(table[ORD(c), 0], i);
INC(table[ORD(c), 0], SYSTEM.SIZE(INTEGER));
INC(pChar, 2);
INC(pChar, SYSTEM.SIZE(WCHAR));
INC(i)
END;
FOR i := 0 TO 65535 DO
DEC(table[i, 0], table[i, 1] * SYSTEM.SIZE(INTEGER))
DEC(table[i, 0], table[i, 1]*SYSTEM.SIZE(INTEGER))
END
RETURN res
@ -96,15 +96,15 @@ BEGIN
prev_item_pos := 0;
WHILE k > 0 DO
SYSTEM.GET(pos, x);
IF Utils.streq(text.dataPtr + x*2, SYSTEM.ADR(s[0]), n) THEN
IF Utils.streq(text.dataPtr + x*SYSTEM.SIZE(WCHAR), SYSTEM.ADR(s[0]), n) THEN
flag := whole;
IF flag THEN
IF x > 0 THEN
SYSTEM.GET(text.dataPtr + (x - 1)*2, c1);
SYSTEM.GET(text.dataPtr + (x - 1)*SYSTEM.SIZE(WCHAR), c1);
ELSE
c1 := 0X
END;
SYSTEM.GET(text.dataPtr + (x + n)*2, 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 = "_")
END;
IF ~flag & (x >= prev_item_pos) THEN

View File

@ -173,19 +173,6 @@ BEGIN
END hideCursor;
PROCEDURE getChar (line: tLine; i: INTEGER): WCHAR;
VAR
res: WCHAR;
BEGIN
IF i >= line.length THEN
res := 0X
ELSE
res := Lines.getChar(line, i)
END
RETURN res
END getChar;
PROCEDURE getString (src: tLine; pos, cnt: INTEGER; VAR dst: ARRAY OF WCHAR): INTEGER;
VAR
i: INTEGER;
@ -193,7 +180,7 @@ BEGIN
i := 0;
WHILE (pos < src.length) & (cnt > 0) DO
IF i < LEN(dst) - 1 THEN
dst[i] := getChar(src, pos);
dst[i] := Lines.getChar(src, pos);
INC(i)
END;
INC(pos);
@ -322,10 +309,10 @@ VAR
s: ARRAY 32 OF WCHAR;
color: INTEGER;
BEGIN
c := getChar(line, i);
c := Lines.getChar(line, i);
WHILE U.isLetter(c) OR (c = "_") OR U.isDigit(c) DO
INC(i);
c := getChar(line, i);
c := Lines.getChar(line, i);
END;
DEC(i);
lexLen := getString(line, first, i - first + 1, s);
@ -360,7 +347,7 @@ VAR
End := i - 1;
k := Start;
WHILE k <= End DO
c := getChar(line, k);
c := Lines.getChar(line, k);
IF c = "\" THEN
j := k;
Lang.SkipEsc(line, k, line.length - 1, text.lang);
@ -381,7 +368,7 @@ BEGIN
END;
cond := 0;
WHILE i <= n DO
c := getChar(line, i);
c := Lines.getChar(line, i);
IF lang = Lang.langFasm THEN
@ -396,17 +383,17 @@ BEGIN
hex := FALSE;
k := i;
INC(i);
c := getChar(line, i);
IF (cap(c) = "X") & (getChar(line, i - 1) = "0") THEN
c := Lines.getChar(line, i);
IF (cap(c) = "X") & (Lines.getChar(line, i - 1) = "0") THEN
INC(i);
hex := TRUE
END;
WHILE U.isHex(cap(getChar(line, i))) DO
WHILE U.isHex(cap(Lines.getChar(line, i))) DO
INC(i)
END;
IF (cap(getChar(line, i)) = "H") & ~hex THEN
IF (cap(Lines.getChar(line, i)) = "H") & ~hex THEN
INC(i)
END;
@ -435,13 +422,13 @@ BEGIN
IF (c = "'") OR (c = '"') THEN
String(text, line, i, y, backColor);
ELSE
ident(text, i, i - ORD((lang = Lang.langC) & (i > 0) & (getChar(line, i - 1) = "#")), y, line, backColor, Lang.isCS(lang))
ident(text, i, i - ORD((lang = Lang.langC) & (i > 0) & (Lines.getChar(line, i - 1) = "#")), y, line, backColor, Lang.isCS(lang))
END;
IF lang = Lang.langJSON THEN
WHILE Lines.isSpace(getChar(line, i + 1)) DO
WHILE Lines.isSpace(Lines.getChar(line, i + 1)) DO
INC(i)
END;
IF getChar(line, i + 1) = ":" THEN
IF Lines.getChar(line, i + 1) = ":" THEN
PrintLex(text, line, k, i, y, colors.key1, backColor)
END
END;
@ -449,15 +436,15 @@ BEGIN
ELSIF U.isDigit(c) THEN
k := i;
INC(i);
c := getChar(line, i);
c := Lines.getChar(line, i);
IF c = "." THEN
DEC(i);
c := getChar(line, i)
c := Lines.getChar(line, i)
END;
IF (cap(c) = "X") & (getChar(line, i - 1) = "0") THEN
IF (cap(c) = "X") & (Lines.getChar(line, i - 1) = "0") THEN
REPEAT
INC(i);
c := getChar(line, i)
c := Lines.getChar(line, i)
UNTIL ~U.isHex(cap(c));
IF UL(c) THEN
INC(i)
@ -467,27 +454,27 @@ BEGIN
ELSIF U.isDigit(c) THEN
REPEAT
INC(i)
UNTIL ~U.isDigit(getChar(line, i));
c := getChar(line, i);
UNTIL ~U.isDigit(Lines.getChar(line, i));
c := Lines.getChar(line, i);
IF UL(c) THEN
INC(i)
ELSIF c = "." THEN
INC(i);
WHILE U.isDigit(getChar(line, i)) DO
WHILE U.isDigit(Lines.getChar(line, i)) DO
INC(i)
END;
c := getChar(line, i);
c := Lines.getChar(line, i);
IF cap(c) = "E" THEN
INC(i);
c := getChar(line, i);
c := Lines.getChar(line, i);
IF (c = "+") OR (c = "-") THEN
INC(i)
END;
IF U.isDigit(getChar(line, i)) THEN
WHILE U.isDigit(getChar(line, i)) DO
IF U.isDigit(Lines.getChar(line, i)) THEN
WHILE U.isDigit(Lines.getChar(line, i)) DO
INC(i)
END;
c := getChar(line, i);
c := Lines.getChar(line, i);
IF FL(c) THEN
INC(i)
END
@ -531,30 +518,30 @@ BEGIN
color := colors.num;
k := i;
INC(i);
WHILE U.isHex(getChar(line, i)) DO
WHILE U.isHex(Lines.getChar(line, i)) DO
INC(i)
END;
IF i <= n THEN
IF getChar(line, i) = "." THEN
IF Lines.getChar(line, i) = "." THEN
INC(i);
IF getChar(line, i) = "." THEN
IF Lines.getChar(line, i) = "." THEN
DEC(i)
END;
WHILE U.isDigit(getChar(line, i)) DO
WHILE U.isDigit(Lines.getChar(line, i)) DO
INC(i)
END;
IF getChar(line, i) = "E" THEN
IF Lines.getChar(line, i) = "E" THEN
INC(i);
IF (getChar(line, i) = "+") OR (getChar(line, i) = "-") THEN
IF (Lines.getChar(line, i) = "+") OR (Lines.getChar(line, i) = "-") THEN
INC(i)
END;
WHILE U.isDigit(getChar(line, i)) DO
WHILE U.isDigit(Lines.getChar(line, i)) DO
INC(i)
END
END
ELSIF getChar(line, i) = "H" THEN
ELSIF Lines.getChar(line, i) = "H" THEN
INC(i)
ELSIF getChar(line, i) = "X" THEN
ELSIF Lines.getChar(line, i) = "X" THEN
color := colors.string;
INC(i)
END
@ -618,7 +605,7 @@ BEGIN
cond := 0
ELSIF U.isDigit(c) THEN
k := i;
IF (c = "0") & (cap(getChar(line, i + 1)) = "X") THEN
IF (c = "0") & (cap(Lines.getChar(line, i + 1)) = "X") THEN
isDgt := U.isHex;
hex := TRUE;
INC(i, 2)
@ -626,24 +613,24 @@ BEGIN
isDgt := U.isDigit;
hex := FALSE
END;
WHILE isDgt(cap(getChar(line, i))) DO
WHILE isDgt(cap(Lines.getChar(line, i))) DO
INC(i)
END;
IF getChar(line, i) = "." THEN
IF Lines.getChar(line, i) = "." THEN
INC(i);
IF getChar(line, i) = "." THEN
IF Lines.getChar(line, i) = "." THEN
DEC(i)
END;
WHILE isDgt(cap(getChar(line, i))) DO
WHILE isDgt(cap(Lines.getChar(line, i))) DO
INC(i)
END
END;
IF (cap(getChar(line, i)) = "E") OR hex & (cap(getChar(line, i)) = "P") THEN
IF (cap(Lines.getChar(line, i)) = "E") OR hex & (cap(Lines.getChar(line, i)) = "P") THEN
INC(i);
IF (getChar(line, i) = "-") OR (getChar(line, i) = "+") THEN
IF (Lines.getChar(line, i) = "-") OR (Lines.getChar(line, i) = "+") THEN
INC(i)
END;
WHILE isDgt(cap(getChar(line, i))) DO
WHILE isDgt(cap(Lines.getChar(line, i))) DO
INC(i)
END
END;
@ -692,7 +679,7 @@ BEGIN
String(text, line, i, y, backColor);
cond := 0
ELSIF c = "{" THEN
IF getChar(line, i + 1) = "$" THEN
IF Lines.getChar(line, i + 1) = "$" THEN
depth := 3
ELSE
depth := 1
@ -703,21 +690,21 @@ BEGIN
ELSIF c = "#" THEN
k := i;
INC(i);
WHILE U.isDigit(getChar(line, i)) DO
WHILE U.isDigit(Lines.getChar(line, i)) DO
INC(i)
END;
DEC(i);
PrintLex(text, line, k, i, y, colors.string, backColor);
cond := 0
ELSIF c = "$" THEN
IF (i > 0 ) & (getChar(line, i - 1) = "#") THEN
IF (i > 0 ) & (Lines.getChar(line, i - 1) = "#") THEN
color := colors.string
ELSE
color := colors.num
END;
k := i;
INC(i);
WHILE U.isHex(cap(getChar(line, i))) DO
WHILE U.isHex(cap(Lines.getChar(line, i))) DO
INC(i)
END;
DEC(i);
@ -725,23 +712,23 @@ BEGIN
cond := 0
ELSIF U.isDigit(c) THEN
k := i;
WHILE U.isDigit(getChar(line, i)) DO
WHILE U.isDigit(Lines.getChar(line, i)) DO
INC(i)
END;
IF getChar(line, i) = "." THEN
IF Lines.getChar(line, i) = "." THEN
INC(i);
IF getChar(line, i) = "." THEN
IF Lines.getChar(line, i) = "." THEN
DEC(i)
END;
WHILE U.isDigit(getChar(line, i)) DO
WHILE U.isDigit(Lines.getChar(line, i)) DO
INC(i)
END;
IF cap(getChar(line, i)) = "E" THEN
IF cap(Lines.getChar(line, i)) = "E" THEN
INC(i);
IF (getChar(line, i) = "-") OR (getChar(line, i) = "+") THEN
IF (Lines.getChar(line, i) = "-") OR (Lines.getChar(line, i) = "+") THEN
INC(i)
END;
WHILE U.isDigit(getChar(line, i)) DO
WHILE U.isDigit(Lines.getChar(line, i)) DO
INC(i)
END
END
@ -784,7 +771,7 @@ BEGIN
PrintComment(text, line, depth, i, 1, y, backColor)
ELSIF U.isDigit(c) THEN
k := i;
WHILE U.isDigit(getChar(line, i)) DO
WHILE U.isDigit(Lines.getChar(line, i)) DO
INC(i)
END;
DEC(i);
@ -809,7 +796,7 @@ VAR
i: INTEGER;
BEGIN
i := 0;
WHILE Lines.isSpace(getChar(line, i)) DO
WHILE Lines.isSpace(Lines.getChar(line, i)) DO
INC(i)
END
RETURN i
@ -977,15 +964,15 @@ BEGIN
END
END;
cursor.X := MIN(MAX(x, 0), text.curLine.length);
c := getChar(text.curLine, cursor.X);
c := Lines.getChar(text.curLine, cursor.X);
IF c = TAB1 THEN
n := cursor.X;
WHILE getChar(text.curLine, n) = TAB1 DO
WHILE Lines.getChar(text.curLine, n) = TAB1 DO
INC(n)
END;
R := n - cursor.X;
n := cursor.X;
WHILE getChar(text.curLine, n) # TAB DO
WHILE Lines.getChar(text.curLine, n) # TAB DO
DEC(n)
END;
L := cursor.X - n;
@ -1078,8 +1065,8 @@ BEGIN
IF i < curLine.length THEN
n := i;
INC(i);
IF getChar(curLine, i - 1) = TAB THEN
WHILE getChar(curLine, i) = TAB1 DO
IF Lines.getChar(curLine, i - 1) = TAB THEN
WHILE Lines.getChar(curLine, i) = TAB1 DO
INC(i)
END
END;
@ -1105,7 +1092,7 @@ VAR
pos: INTEGER;
BEGIN
pos := text.cursor.X + d;
WHILE getChar(text.curLine, pos) = TAB1 DO
WHILE Lines.getChar(text.curLine, pos) = TAB1 DO
INC(pos, d)
END;
SetPos(text, pos, text.cursor.Y)
@ -1148,7 +1135,7 @@ BEGIN
Lines.delCharN(curLine, 0, i);
Lines.insert3(curLine, 0, k);
WHILE k > 0 DO
Lines.setChar(curLine, k - 1, getChar(line2, k - 1));
Lines.setChar(curLine, k - 1, Lines.getChar(line2, k - 1));
DEC(k)
END;
Lines.modify(curLine);
@ -1197,7 +1184,7 @@ BEGIN
SetPos(text, n, text.cursor.Y);
resetSelect(text);
WHILE n > 0 DO
Lines.setChar(text.curLine, n - 1, getChar(line2, n - 1));
Lines.setChar(text.curLine, n - 1, Lines.getChar(line2, n - 1));
DEC(n)
END;
Lines.modify(newLine)
@ -1464,7 +1451,7 @@ VAR
BEGIN
res := 0;
FOR i := first TO last DO
IF getChar(line, i) # TAB1 THEN
IF Lines.getChar(line, i) # TAB1 THEN
INC(res)
END
END
@ -1480,15 +1467,13 @@ BEGIN
IF lines > 1 THEN
chars := charCnt(first, selBeg.X, first.length - 1) + charCnt(last, 0, selEnd.X - 1) + lenEOL;
line := first.next(tLine)
line := first.next(tLine);
WHILE line # last DO
INC(chars, charCnt(line, 0, line.length - 1) + lenEOL);
NextLine(line)
END
ELSE
chars := charCnt(first, selBeg.X, selEnd.X - 1);
line := last
END;
WHILE line # last DO
INC(chars, charCnt(line, 0, line.length - 1) + lenEOL);
NextLine(line)
chars := charCnt(first, selBeg.X, selEnd.X - 1)
END
ELSE
chars := 0;
@ -1572,7 +1557,7 @@ VAR
res := pos;
i := 0;
REPEAT
c := getChar(line, i);
c := Lines.getChar(line, i);
IF c = TAB THEN
INC(res, Lines.tab - res MOD Lines.tab)
ELSIF c # TAB1 THEN
@ -1707,7 +1692,7 @@ BEGIN
line := text.curLine;
i := text.cursor.X - 1;
WHILE (i >= 0) & U.isLetter(getChar(line, i)) DO
WHILE (i >= 0) & U.isLetter(Lines.getChar(line, i)) DO
DEC(i)
END;
@ -1915,8 +1900,8 @@ BEGIN
INC(i)
END;
IF (i # n) OR
((x1 > 0) & isWordChar(getChar(curLine, x1 - 1))) OR
((x2 < curLine.length) & isWordChar(getChar(curLine, x2))) THEN
((x1 > 0) & isWordChar(Lines.getChar(curLine, x1 - 1))) OR
((x2 < curLine.length) & isWordChar(Lines.getChar(curLine, x2))) THEN
str := ""
END
END;
@ -1928,17 +1913,17 @@ PROCEDURE getWordPos (line: tLine; pos: INTEGER): INTEGER;
VAR
c: WCHAR;
BEGIN
c := getChar(line, pos);
c := Lines.getChar(line, pos);
IF isWordChar(c) THEN
WHILE (pos < line.length) & isWordChar(getChar(line, pos)) DO
WHILE (pos < line.length) & isWordChar(Lines.getChar(line, pos)) DO
INC(pos)
END
ELSIF Lines.isSpace(c) THEN
WHILE (pos < line.length) & Lines.isSpace(getChar(line, pos)) DO
WHILE (pos < line.length) & Lines.isSpace(Lines.getChar(line, pos)) DO
INC(pos)
END
ELSE
WHILE (pos < line.length) & ~Lines.isSpace(getChar(line, pos)) & ~isWordChar(getChar(line, pos)) DO
WHILE (pos < line.length) & ~Lines.isSpace(Lines.getChar(line, pos)) & ~isWordChar(Lines.getChar(line, pos)) DO
INC(pos)
END
END
@ -1986,11 +1971,10 @@ BEGIN
SetPos(text, 0, 0)
ELSE
n := leadingSpaces(text.curLine);
IF text.cursor.X > n THEN
SetPos(text, n, text.cursor.Y)
ELSE
SetPos(text, 0, text.cursor.Y)
END
IF text.cursor.X <= n THEN
n := 0
END;
SetPos(text, n, text.cursor.Y)
END
|37:
IF (text.cursor.X = 0) & (text.curLine.prev # NIL) THEN
@ -2036,17 +2020,13 @@ BEGIN
delete(text);
ShowCursor
END
|ORD("C"):
IF ctrl THEN
IF selected(text) THEN
copy(text)
END
END
|ORD("X"):
|ORD("C"), ORD("X"):
IF ctrl THEN
IF selected(text) THEN
copy(text);
delSelect(text)
IF code = ORD("X") THEN
delSelect(text)
END
END
END
|ORD("V"):
@ -2100,18 +2080,18 @@ BEGIN
cursorX := text.cursor.X;
line := text.curLine;
x1 := cursorX - 1;
IF (cursorX < line.length) & isWordChar(getChar(line, cursorX)) THEN
IF (cursorX < line.length) & isWordChar(Lines.getChar(line, cursorX)) THEN
x2 := cursorX;
WHILE (x2 < line.length) & isWordChar(getChar(line, x2)) DO
WHILE (x2 < line.length) & isWordChar(Lines.getChar(line, x2)) DO
INC(x2)
END
ELSE
WHILE (x1 >= 0) & ~isWordChar(getChar(line, x1)) DO
WHILE (x1 >= 0) & ~isWordChar(Lines.getChar(line, x1)) DO
DEC(x1)
END;
x2 := x1 + 1
END;
WHILE (x1 >= 0) & isWordChar(getChar(line, x1)) DO
WHILE (x1 >= 0) & isWordChar(Lines.getChar(line, x1)) DO
DEC(x1)
END;
INC(x1);
@ -2408,11 +2388,11 @@ BEGIN
END setColors;
PROCEDURE setCanvas* (Canvas: G.tCanvas);
PROCEDURE setCanvas* (_canvas: G.tCanvas);
BEGIN
canvas := Canvas;
charWidth := canvas.font.width;
charHeight := canvas.font.height + inter
canvas := _canvas;
charWidth := _canvas.font.width;
charHeight := _canvas.font.height + inter
END setCanvas;
@ -2608,9 +2588,9 @@ BEGIN
List._append(text, Lines.create(FALSE));
text.curLine := text.first(tLine);
ChangeLog.changeInt(text.enc, E.CP866);
ChangeLog.changeInt(text.eol, RW.EOL_CRLF);
ChangeLog.changeInt(text.eol, E.EOL_CRLF);
text.enc := E.CP866;
text.eol := RW.EOL_CRLF;
text.eol := E.EOL_CRLF;
SetPos(text, 0, 0);
resetSelect(text)
RETURN text

View File

@ -32,34 +32,32 @@ CONST
PROCEDURE streq* (s1, s2: INTEGER; n: INTEGER): BOOLEAN;
VAR
c1, c2: WCHAR;
res: BOOLEAN;
BEGIN
WHILE n > 0 DO
res := TRUE;
WHILE (n > 0) & res DO
SYSTEM.GET(s1, c1);
SYSTEM.GET(s2, c2);
INC(s1, 2);
INC(s2, 2);
IF c1 = c2 THEN
DEC(n)
ELSE
n := 0
END
res := c1 = c2;
INC(s1, SYSTEM.SIZE(WCHAR));
INC(s2, SYSTEM.SIZE(WCHAR));
DEC(n)
END
RETURN c1 = c2
RETURN res
END streq;
PROCEDURE append* (VAR s1: ARRAY OF WCHAR; s2: ARRAY OF WCHAR);
VAR
n1, n2, i, j: INTEGER;
n, i, j: INTEGER;
BEGIN
n1 := LENGTH(s1);
n2 := LENGTH(s2);
j := LENGTH(s1);
n := LENGTH(s2);
ASSERT(n1 + n2 < LEN(s1));
ASSERT(j + n < LEN(s1));
i := 0;
j := n1;
WHILE i < n2 DO
WHILE i < n DO
s1[j] := s2[i];
INC(i);
INC(j)
@ -71,16 +69,15 @@ END append;
PROCEDURE append8* (VAR s1: ARRAY OF CHAR; s2: ARRAY OF CHAR);
VAR
n1, n2, i, j: INTEGER;
n, i, j: INTEGER;
BEGIN
n1 := LENGTH(s1);
n2 := LENGTH(s2);
j := LENGTH(s1);
n := LENGTH(s2);
ASSERT(n1 + n2 < LEN(s1));
ASSERT(j + n < LEN(s1));
i := 0;
j := n1;
WHILE i < n2 DO
WHILE i < n DO
s1[j] := s2[i];
INC(i);
INC(j)

View File

@ -1,97 +0,0 @@
(*
Copyright 2016, 2021, 2022 Anton Krotov
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 LibImg;
IMPORT SYSTEM, KOSAPI, File;
VAR
file: INTEGER;
PROCEDURE [stdcall, "libimg.obj", ""] img_decode (data, size, options: INTEGER): INTEGER; END;
PROCEDURE [stdcall, "libimg.obj", ""] img_to_rgb2 (data, data_rgb: INTEGER); END;
PROCEDURE [stdcall, "libimg.obj", ""] img_scale (src, crop_x, crop_y, crop_width, crop_height, dst, scale, inter, param1, param2: INTEGER): INTEGER; END;
PROCEDURE [stdcall, "libimg.obj", ""] img_destroy* (img: INTEGER); END;
PROCEDURE GetInf*(img: INTEGER; VAR sizeX, sizeY, data: INTEGER);
BEGIN
SYSTEM.GET(img + 4, sizeX);
SYSTEM.GET(img + 8, sizeY);
SYSTEM.GET(img + 24, data);
END GetInf;
PROCEDURE GetImg*(ptr, n, Width: INTEGER; VAR sizeY: INTEGER): INTEGER;
VAR image_data, dst, x, y, type, rgb, data: INTEGER;
BEGIN
image_data := img_decode(ptr, n, 0);
IF image_data # 0 THEN
SYSTEM.GET(image_data + 4, x);
SYSTEM.GET(image_data + 8, y);
SYSTEM.GET(image_data + 20, type);
IF type # 2 THEN
rgb := KOSAPI.malloc(x * y * 3);
IF rgb # 0 THEN
img_to_rgb2(image_data, rgb);
SYSTEM.GET(image_data + 24, data);
data := KOSAPI.free(data);
SYSTEM.PUT(image_data + 24, rgb);
SYSTEM.PUT(image_data + 20, 2)
ELSE
img_destroy(image_data);
image_data := 0
END
END;
IF (x > Width) & (image_data # 0) THEN
dst := img_scale(image_data, 0, 0, x, y, dst, 3, 1, Width, (y * Width) DIV x);
img_destroy(image_data);
image_data := dst
END;
IF image_data # 0 THEN
SYSTEM.GET(image_data + 8, sizeY)
END
END
RETURN image_data
END GetImg;
PROCEDURE LoadFromFile* (FName: ARRAY OF CHAR; Width: INTEGER; VAR sizeY: INTEGER): INTEGER;
VAR F: File.FS; n, size, res: INTEGER;
BEGIN
res := 0;
F := File.Open(FName);
IF F # NIL THEN
size := File.Seek(F, 0, File.SEEK_END);
n := File.Seek(F, 0, File.SEEK_BEG);
file := KOSAPI.malloc(size + 1024);
IF file # 0 THEN
n := File.Read(F, file, size);
res := GetImg(file, n, Width, sizeY);
n := KOSAPI.free(file)
END;
File.Close(F)
END
RETURN res
END LoadFromFile;
END LibImg.

View File

@ -185,31 +185,32 @@ END resize;
PROCEDURE setValue* (VAR scroll: tScroll; value: INTEGER);
VAR
pos, maxPos, n, m: INTEGER;
pos, maxPos, maxVal, n, m: INTEGER;
BEGIN
maxVal := scroll.maxVal;
IF scroll.vertical THEN
maxPos := scroll.height
ELSE
maxPos := scroll.width
END;
maxPos := maxPos - scroll.btnSize*2 - scroll.sliderSize + 1;
IF (value < 0) OR (scroll.maxVal <= 0) THEN
IF (value < 0) OR (maxVal <= 0) THEN
value := 0;
pos := 0
ELSIF value > scroll.maxVal THEN
value := scroll.maxVal;
ELSIF value > maxVal THEN
value := maxVal;
pos := maxPos
ELSE
IF (maxPos + 1) >= scroll.maxVal THEN
n := (maxPos + 1) DIV scroll.maxVal;
m := (maxPos + 1) MOD scroll.maxVal;
IF (maxPos + 1) >= maxVal THEN
n := (maxPos + 1) DIV maxVal;
m := (maxPos + 1) MOD maxVal;
pos := value*n + MIN(value, m)
ELSE
pos := FLOOR(FLT(value)*FLT(maxPos + 1)/FLT(scroll.maxVal))
pos := FLOOR(FLT(value)*FLT(maxPos + 1)/FLT(maxVal))
END;
IF pos > maxPos THEN
pos := maxPos;
value := scroll.maxVal
value := maxVal
END
END;
scroll.pos := pos;
@ -224,9 +225,10 @@ END ceil;
PROCEDURE setPos (VAR scroll: tScroll; pos: INTEGER);
VAR
maxPos, value, n, m, x, x0, q: INTEGER;
maxPos, value, maxVal, n, m, x, x0, q: INTEGER;
BEGIN
IF scroll.maxVal > 0 THEN
maxVal := scroll.maxVal;
IF maxVal > 0 THEN
IF scroll.vertical THEN
maxPos := scroll.height
ELSE
@ -238,11 +240,11 @@ BEGIN
value := 0
ELSIF pos >= maxPos THEN
pos := maxPos;
value := scroll.maxVal
value := maxVal
ELSE
IF scroll.maxVal <= maxPos + 1 THEN
n := (maxPos + 1) DIV scroll.maxVal;
m := (maxPos + 1) MOD scroll.maxVal;
IF maxVal <= maxPos + 1 THEN
n := (maxPos + 1) DIV maxVal;
m := (maxPos + 1) MOD maxVal;
q := m*(n + 1);
IF q < pos THEN
@ -263,16 +265,16 @@ BEGIN
pos := x;
IF pos > maxPos THEN
pos := maxPos;
value := scroll.maxVal
value := maxVal
END
END
ELSE
value := FLOOR(FLT(scroll.maxVal)*FLT(pos)/FLT(maxPos + 1))
value := FLOOR(FLT(maxVal)*FLT(pos)/FLT(maxPos + 1))
END
END
ELSE
pos := 0;
scroll.value := 0
value := 0
END;
scroll.pos := pos;
scroll.value := value