compile/run/debug with fasm without script; support docpack; convert cp866 <=> cp1251

git-svn-id: svn://kolibrios.org@9674 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2022-01-28 15:47:03 +00:00
parent 8fdd480786
commit 2edd1b82f9
9 changed files with 294 additions and 70 deletions

Binary file not shown.

View File

@ -101,7 +101,7 @@ delim = =
KW1 = KW1 =
KW2 = KW2 =
KW3 = KW3 =
delim = {}[]<>:,()&*/|+-\# delim = {}[]<>=:,()&*/|+-\#
[lang_JSON] [lang_JSON]
KW1 = KW1 =

View File

@ -40,6 +40,7 @@
ctrl+F9 компилировать ctrl+F9 компилировать
F9 выполнить F9 выполнить
ctrl+F8 отладка
перемещение по тексту: перемещение по тексту:
(ctrl+)Home, (ctrl+)End, (ctrl+)PageUp, (ctrl+)PageDown (ctrl+)Home, (ctrl+)End, (ctrl+)PageUp, (ctrl+)PageDown

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, KOSAPI, SYSTEM,
RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar; RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar;
CONST CONST
HEADER = "CEdit (26-jan-2022)"; HEADER = "CEdit (28-jan-2022)";
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";
@ -119,12 +119,15 @@ CONST
menuRunScript = 53; menuRunScript = 53;
menuDebug = 54; menuDebug = 54;
menuDebugScript = 55; menuDebugScript = 55;
menuFASM = 56;
menuUTF8BOM = 60; menuUTF8BOM = 60;
menuUTF8 = 61; menuUTF8 = 61;
menuCP866 = 62; menuCP866 = 62;
menuWin1251 = 63; menuWin1251 = 63;
menuEOL = 140; menuEOL = 140;
menuConv1251_866 = 64;
menuConv866_1251 = 65;
menuPipet = 70; menuPipet = 70;
menuMagnify = 71; menuMagnify = 71;
@ -413,8 +416,8 @@ BEGIN
Toolbar.enable(toolbar, btnRedo, ~ChangeLog.isLastGuard(text.edition)); Toolbar.enable(toolbar, btnRedo, ~ChangeLog.isLastGuard(text.edition));
Toolbar.enable(toolbar, btnUpper, T.selected(text)); Toolbar.enable(toolbar, btnUpper, T.selected(text));
Toolbar.enable(toolbar, btnLower, T.selected(text)); Toolbar.enable(toolbar, btnLower, T.selected(text));
Toolbar.enable(toolbar, btnBuild, buildScript # ""); Toolbar.enable(toolbar, btnBuild, (buildScript # "") OR text.fasm);
Toolbar.enable(toolbar, btnRun, runScript # ""); Toolbar.enable(toolbar, btnRun, (runScript # "") OR text.fasm);
Toolbar.drawIcons(toolbar) Toolbar.drawIcons(toolbar)
END END
END repaint; END repaint;
@ -795,7 +798,7 @@ BEGIN
IF fileName # "" THEN IF fileName # "" THEN
n := getFileNum(fileName); n := getFileNum(fileName);
IF n = -1 THEN IF n = -1 THEN
nov := T.open(fileName, err); nov := T.open(fileName, 0, 0, err);
IF nov = NIL THEN IF nov = NIL THEN
error("error opening file"); error("error opening file");
SwitchTab(curText); SwitchTab(curText);
@ -1060,9 +1063,13 @@ BEGIN
Menu.option(menu, menuOberon, text.lang = Languages.langOberon); Menu.option(menu, menuOberon, text.lang = Languages.langOberon);
Menu.option(menu, menuPascal, text.lang = Languages.langPascal); Menu.option(menu, menuPascal, text.lang = Languages.langPascal);
ELSIF menu = menuProgram THEN ELSIF menu = menuProgram THEN
Menu.setEnabled(menu, menuBuild, buildScript # ""); Menu.setEnabled(menu, menuBuild, (buildScript # "") OR text.fasm);
Menu.setEnabled(menu, menuDebug, debugScript # ""); Menu.setEnabled(menu, menuDebug, (debugScript # "") OR text.fasm);
Menu.setEnabled(menu, menuRun, runScript # "") Menu.setEnabled(menu, menuRun, (runScript # "") OR text.fasm);
Menu.setEnabled(menu, menuBuildScript, ~text.fasm);
Menu.setEnabled(menu, menuDebugScript, ~text.fasm);
Menu.setEnabled(menu, menuRunScript, ~text.fasm);
Menu.check(menu, menuFASM, text.fasm)
ELSIF menu = menuOptions THEN ELSIF menu = menuOptions THEN
Menu.check(menu, menuLineNumbers, T.lineNumbers); Menu.check(menu, menuLineNumbers, T.lineNumbers);
Menu.check(menu, menuAutoIndents, T.autoIndents); Menu.check(menu, menuAutoIndents, T.autoIndents);
@ -1106,6 +1113,64 @@ BEGIN
END setScript; END setScript;
PROCEDURE FasmCompile (run, debug: BOOLEAN);
VAR
curFileName, ext, outfile, path, param: RW.tFileName;
BEGIN
curFileName := texts[curText].fileName;
U.getFileName(curFileName, param, U.SLASH);
U.getFileName(curFileName, ext, ".");
U.getPath(curFileName, path);
outfile := param;
IF (ext # "") & ((LENGTH(ext) + 1) < LENGTH(outfile)) THEN
outfile[LENGTH(outfile) - LENGTH(ext) - 1] := 0X
ELSE
U.append8(outfile, ".kex")
END;
U.append8(param, ",");
U.append8(param, outfile);
U.append8(param, ",");
U.append8(param, path);
U.append8(param, U.SLASH);
IF run THEN
U.append8(param, ",run")
ELSIF debug THEN
U.append8(param, ",dbg")
END;
K.Run("/sys/develop/fasm", param)
END FasmCompile;
PROCEDURE ProgramBuild;
BEGIN
IF ~text.fasm THEN
Script(buildScript)
ELSE
FasmCompile(FALSE, FALSE)
END
END ProgramBuild;
PROCEDURE ProgramRun;
BEGIN
IF ~text.fasm THEN
Script(runScript)
ELSE
FasmCompile(TRUE, FALSE)
END
END ProgramRun;
PROCEDURE ProgramDebug;
BEGIN
IF ~text.fasm THEN
Script(debugScript)
ELSE
FasmCompile(FALSE, TRUE)
END
END ProgramDebug;
PROCEDURE ClickMenu; PROCEDURE ClickMenu;
VAR VAR
item: List.tItem; item: List.tItem;
@ -1187,17 +1252,19 @@ BEGIN
|menuPascal: |menuPascal:
T.setLang(text, Languages.langPascal) T.setLang(text, Languages.langPascal)
|menuBuild: |menuBuild:
Script(buildScript) ProgramBuild
|menuBuildScript: |menuBuildScript:
setScript(buildScript) setScript(buildScript)
|menuRun: |menuRun:
Script(runScript) ProgramRun
|menuRunScript: |menuRunScript:
setScript(runScript) setScript(runScript)
|menuDebug: |menuDebug:
Script(debugScript) ProgramDebug
|menuDebugScript: |menuDebugScript:
setScript(debugScript) setScript(debugScript)
|menuFASM:
text.fasm := ~text.fasm
|menuUTF8BOM: |menuUTF8BOM:
T.setEnc(text, E.UTF8BOM) T.setEnc(text, E.UTF8BOM)
|menuUTF8: |menuUTF8:
@ -1212,6 +1279,10 @@ BEGIN
T.setEol(text, E.EOL_CRLF) T.setEol(text, E.EOL_CRLF)
|menuCR: |menuCR:
T.setEol(text, E.EOL_CR) T.setEol(text, E.EOL_CR)
|menuConv1251_866:
T.convert(text, E.cp866, E.W1251)
|menuConv866_1251:
T.convert(text, E.cp1251, E.CP866)
|menuPipet: |menuPipet:
K.Run("/sys/develop/pipet", "") K.Run("/sys/develop/pipet", "")
|menuMagnify: |menuMagnify:
@ -1346,6 +1417,9 @@ BEGIN
Menu.delimiter(menu); Menu.delimiter(menu);
Menu.AddMenuItem(menu, menuEOL, "EOL"); Menu.AddMenuItem(menu, menuEOL, "EOL");
Menu.child(menu, subEOL); Menu.child(menu, subEOL);
Menu.delimiter(menu);
Menu.AddMenuItem(menu, menuConv1251_866, "convert 1251 >> 866");
Menu.AddMenuItem(menu, menuConv866_1251, "convert 866 >> 1251");
RETURN Menu.create(menu) RETURN Menu.create(menu)
END CreateMenuEncoding; END CreateMenuEncoding;
@ -1415,8 +1489,10 @@ BEGIN
Menu.AddMenuItem(menu, menuRun, "run F9"); Menu.AddMenuItem(menu, menuRun, "run F9");
Menu.AddMenuItem(menu, menuRunScript, "script"); Menu.AddMenuItem(menu, menuRunScript, "script");
Menu.delimiter(menu); Menu.delimiter(menu);
Menu.AddMenuItem(menu, menuDebug, "debug"); Menu.AddMenuItem(menu, menuDebug, "debug ctrl-F8");
Menu.AddMenuItem(menu, menuDebugScript, "script"); Menu.AddMenuItem(menu, menuDebugScript, "script");
Menu.delimiter(menu);
Menu.AddMenuItem(menu, menuFASM, "Fasm");
RETURN Menu.create(menu) RETURN Menu.create(menu)
END CreateMenuProgram; END CreateMenuProgram;
@ -1511,6 +1587,7 @@ BEGIN
Menu.AddShortcut(31 + CTRL, menuSave); Menu.AddShortcut(31 + CTRL, menuSave);
Menu.AddShortcut(49 + CTRL, menuNew); Menu.AddShortcut(49 + CTRL, menuNew);
Menu.AddShortcut(67 + CTRL, menuBuild); Menu.AddShortcut(67 + CTRL, menuBuild);
Menu.AddShortcut(66 + CTRL, menuDebug);
Menu.AddShortcut(83 + CTRL, menuRemove); Menu.AddShortcut(83 + CTRL, menuRemove);
Menu.AddShortcut(22 + CTRL, menuUpper); Menu.AddShortcut(22 + CTRL, menuUpper);
Menu.AddShortcut(38 + CTRL, menuLower); Menu.AddShortcut(38 + CTRL, menuLower);
@ -1570,12 +1647,17 @@ BEGIN
ELSE ELSE
T.gotoLabel(text, ~shift) T.gotoLabel(text, ~shift)
END END
ELSIF keyCode = 66 THEN (* F8 *)
key := -1;
IF ctrl THEN
ProgramDebug
END
ELSIF keyCode = 67 THEN (* F9 *) ELSIF keyCode = 67 THEN (* F9 *)
key := -1; key := -1;
IF ctrl THEN IF ctrl THEN
Script(buildScript) ProgramBuild
ELSE ELSE
Script(runScript) ProgramRun
END END
ELSIF keyCode = 68 THEN (* F10 *) ELSIF keyCode = 68 THEN (* F10 *)
IF shift THEN IF shift THEN
@ -1767,9 +1849,9 @@ BEGIN
|btnLower: |btnLower:
T.chCase(text, FALSE) T.chCase(text, FALSE)
|btnBuild: |btnBuild:
Script(buildScript) ProgramBuild
|btnRun: |btnRun:
Script(runScript) ProgramRun
|btnFindNext: |btnFindNext:
IF searchText # "" THEN IF searchText # "" THEN
notFound := ~T.findNext(text, BKW.value); notFound := ~T.findNext(text, BKW.value);
@ -1940,6 +2022,47 @@ BEGIN
END ScrollChange; END ScrollChange;
PROCEDURE docpack (VAR param: RW.tFileName);
VAR
i, size, errno: INTEGER;
ptr, ptr2: INTEGER;
s: ARRAY 32 OF WCHAR;
BEGIN
U.reverse8(param);
param[LENGTH(param) - 1] := 0X;
U.reverse8(param);
i := 0;
WHILE param[i] # 0X DO
s[i] := WCHR(ORD(param[i]));
INC(i)
END;
IF U.str2int(s, size) THEN
INC(size, 20);
ptr := KOSAPI.malloc(size);
IF ptr # 0 THEN
SYSTEM.PUT32(ptr, 0);
SYSTEM.PUT32(ptr + 4, 8);
KOSAPI.sysfunc4(60, 1, ptr, size);
K.SetEventsMask({6});
IF K.EventTimeout(200) = 7 THEN
SYSTEM.PUT32(ptr, 1);
SYSTEM.GET(ptr + 12, size);
ptr2 := KOSAPI.malloc(size);
IF ptr2 # 0 THEN
SYSTEM.MOVE(ptr + 16, ptr2, size);
text := T.open("", ptr2, size, errno);
IF text # NIL THEN
insert(0, text);
T.SetPos(text, 0, 0)
END
END
END;
ptr := KOSAPI.free(ptr)
END
END
END docpack;
PROCEDURE main; PROCEDURE main;
VAR VAR
fileName, filePath: RW.tFileName; fileName, filePath: RW.tFileName;
@ -2042,8 +2165,12 @@ BEGIN
END; END;
FOR i := 1 TO Args.argc - 1 DO FOR i := 1 TO Args.argc - 1 DO
Args.GetArg(i, fileName); Args.GetArg(i, fileName);
IF open(fileName) THEN IF fileName[0] # "*" THEN
U.getPath(fileName, filePath) IF open(fileName) THEN
U.getPath(fileName, filePath)
END
ELSE
docpack(fileName)
END END
END; END;
IF textsCount = 0 THEN IF textsCount = 0 THEN

View File

@ -1,5 +1,5 @@
(* (*
Copyright 2021 Anton Krotov Copyright 2021, 2022 Anton Krotov
This file is part of CEdit. This file is part of CEdit.

View File

@ -28,12 +28,12 @@ CONST
CR = 0DX; LF = 0AX; CR = 0DX; LF = 0AX;
TYPE TYPE
CP = ARRAY 256 OF INTEGER; CP* = ARRAY 256 OF INTEGER;
tEOL* = ARRAY 3 OF WCHAR; tEOL* = ARRAY 3 OF WCHAR;
VAR VAR
cpW1251*, 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 INTEGER;
@ -117,8 +117,8 @@ BEGIN
UNI[i, W1251] := UNDEF UNI[i, W1251] := UNDEF
END; END;
FOR i := 0 TO 255 DO FOR i := 0 TO 255 DO
IF cpW1251[i] # UNDEF THEN IF cp1251[i] # UNDEF THEN
UNI[cpW1251[i], W1251] := i UNI[cp1251[i], W1251] := i
END; END;
IF cp866[i] # UNDEF THEN IF cp866[i] # UNDEF THEN
UNI[cp866[i], CP866] := i UNI[cp866[i], CP866] := i
@ -138,7 +138,7 @@ BEGIN
names[W1251] := "Windows-1251"; names[W1251] := "Windows-1251";
names[UTF8] := "UTF-8"; names[UTF8] := "UTF-8";
names[UTF8BOM] := "UTF-8-BOM"; names[UTF8BOM] := "UTF-8-BOM";
InitW1251(cpW1251); InitW1251(cp1251);
InitCP866(cp866); InitCP866(cp866);
setUNI setUNI
END Encodings. END Encodings.

View File

@ -51,6 +51,8 @@ TYPE
tVectorItem = tLine; tVectorItem = tLine;
fConvert* = PROCEDURE (VAR c: WCHAR): BOOLEAN;
VAR VAR
@ -497,19 +499,14 @@ BEGIN
END copy; END copy;
PROCEDURE chCase* (line: tLine; pos1, pos2: INTEGER; upper: BOOLEAN): BOOLEAN; PROCEDURE convert* (line: tLine; pos1, pos2: INTEGER; func: fConvert): BOOLEAN;
VAR VAR
i: INTEGER; i: INTEGER;
modified: BOOLEAN; modified: BOOLEAN;
c: WCHAR; c: WCHAR;
func: PROCEDURE (VAR c: WCHAR): BOOLEAN;
BEGIN BEGIN
ASSERT(func # NIL);
modified := FALSE; modified := FALSE;
IF upper THEN
func := Utils.cap
ELSE
func := Utils.low
END;
i := pos2; i := pos2;
WHILE i >= pos1 DO WHILE i >= pos1 DO
c := getChar(line, i); c := getChar(line, i);
@ -532,7 +529,7 @@ BEGIN
modify(line) modify(line)
END END
RETURN modified RETURN modified
END chCase; END convert;
PROCEDURE init* (movInt: PmovInt; movPtr: PmovPtr; movBool, movBool2: PmovBool; typedPtr: PTypedPtr; untypedPtr: PUntypedPtr); PROCEDURE init* (movInt: PmovInt; movPtr: PmovPtr; movBool, movBool2: PmovBool; typedPtr: PTypedPtr; untypedPtr: PUntypedPtr);

View File

@ -144,7 +144,7 @@ END getCharUTF8;
PROCEDURE getCharW1251 (file: tInput): INTEGER; PROCEDURE getCharW1251 (file: tInput): INTEGER;
RETURN E.cpW1251[getByte(file)] RETURN E.cp1251[getByte(file)]
END getCharW1251; END getCharW1251;
@ -344,23 +344,17 @@ BEGIN
END createStrBuf; END createStrBuf;
PROCEDURE load* (name: tFileName; VAR enc, eol: INTEGER): tInput; PROCEDURE _loadFromMem (ptr, size: INTEGER; cp866: BOOLEAN; VAR enc, eol: INTEGER): tInput;
VAR VAR
res: tInput; res: tInput;
fsize: INTEGER;
BEGIN BEGIN
NEW(res); NEW(res);
res.pos := 0; res.pos := 0;
res.CR := FALSE; res.CR := FALSE;
res.getChar := NIL; res.getChar := NIL;
res.clipbrd := FALSE; res.clipbrd := FALSE;
fsize := File.FileSize(name); res.buffer := ptr;
IF fsize = 0 THEN res.cnt := size;
res.buffer := KOSAPI.malloc(4096);
res.cnt := 0
ELSE
res.buffer := File.Load(name, res.cnt)
END;
IF res.buffer = 0 THEN IF res.buffer = 0 THEN
DISPOSE(res) DISPOSE(res)
ELSE ELSE
@ -370,13 +364,37 @@ BEGIN
ELSIF enc = E.CP866 THEN ELSIF enc = E.CP866 THEN
res.getChar := getCharCP866 res.getChar := getCharCP866
ELSIF enc = E.W1251 THEN ELSIF enc = E.W1251 THEN
res.getChar := getCharW1251 IF cp866 THEN
enc := E.CP866;
res.getChar := getCharCP866
ELSE
res.getChar := getCharW1251
END
END; END;
eol := detectEOL(res); eol := detectEOL(res);
createStrBuf(res) createStrBuf(res)
END END
RETURN res RETURN res
END load; END _loadFromMem;
PROCEDURE loadFromMem* (ptr, size: INTEGER; VAR enc, eol: INTEGER): tInput;
RETURN _loadFromMem(ptr, size, TRUE, enc, eol)
END loadFromMem;
PROCEDURE loadFromFile* (name: tFileName; VAR enc, eol: INTEGER): tInput;
VAR
ptr, size: INTEGER;
BEGIN
size := File.FileSize(name);
IF size = 0 THEN
ptr := KOSAPI.malloc(4096)
ELSE
ptr := File.Load(name, size)
END
RETURN _loadFromMem(ptr, size, FALSE, enc, eol)
END loadFromFile;
PROCEDURE clipboard* (): tInput; PROCEDURE clipboard* (): tInput;

View File

@ -67,13 +67,12 @@ TYPE
CurX: INTEGER; CurX: INTEGER;
smallChange: INTEGER; smallChange: INTEGER;
modified*, smallMove, modified*, smallMove,
comments, guard, comments, guard, fasm*,
search, cs, whole: BOOLEAN; search, cs, whole: BOOLEAN;
edition*: tGuard; edition*: tGuard;
curLine: tLine; curLine: tLine;
lang*: INTEGER; lang*: INTEGER;
enc, eol: INTEGER; enc, eol: INTEGER;
table: Search.IdxTable;
foundList: List.tList; foundList: List.tList;
foundSel: INTEGER; foundSel: INTEGER;
searchText: tString; searchText: tString;
@ -101,11 +100,15 @@ 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);
BEGIN BEGIN
text.lang := lang; IF text.lang # lang THEN
text.fasm := lang = Lang.langFasm;
text.lang := lang
END;
text.comments := TRUE; text.comments := TRUE;
Lang.setCurLang(text.lang) Lang.setCurLang(text.lang)
END setLang; END setLang;
@ -298,6 +301,18 @@ BEGIN
END Comments; END Comments;
PROCEDURE leadingSpaces (line: tLine): INTEGER;
VAR
i: INTEGER;
BEGIN
i := 0;
WHILE Lines.isSpace(Lines.getChar(line, i)) DO
INC(i)
END
RETURN i
END leadingSpaces;
PROCEDURE parse (text: tText; line: tLine; y: INTEGER; backColor: INTEGER; lang: INTEGER); PROCEDURE parse (text: tText; line: tLine; y: INTEGER; backColor: INTEGER; lang: INTEGER);
VAR VAR
c: WCHAR; c: WCHAR;
@ -813,7 +828,7 @@ BEGIN
ELSIF lang = Lang.langIni THEN ELSIF lang = Lang.langIni THEN
IF depth = 0 THEN IF depth = 0 THEN
IF (c = ";") OR (c = "#") THEN IF ((c = ";") OR (c = "#")) & (leadingSpaces(line) = i) THEN
PrintLex(text, line, i, n, y, colors.comment, backColor); PrintLex(text, line, i, n, y, colors.comment, backColor);
i := n i := n
ELSIF c = '"' THEN ELSIF c = '"' THEN
@ -844,18 +859,6 @@ BEGIN
END parse; END parse;
PROCEDURE leadingSpaces (line: tLine): INTEGER;
VAR
i: INTEGER;
BEGIN
i := 0;
WHILE Lines.isSpace(Lines.getChar(line, i)) DO
INC(i)
END
RETURN i
END leadingSpaces;
PROCEDURE plain (text: tText): CB.tBuffer; PROCEDURE plain (text: tText): CB.tBuffer;
VAR VAR
buf: CB.tBuffer; buf: CB.tBuffer;
@ -908,8 +911,8 @@ BEGIN
END; END;
IF text.searchText # "" THEN IF text.searchText # "" THEN
plainText := plain(text); plainText := plain(text);
idxData := Search.index(plainText, text.table, cs); idxData := Search.index(plainText, idxTable, cs);
Search.find(plainText, text.table, text.searchText, whole, text.foundList); Search.find(plainText, idxTable, text.searchText, whole, text.foundList);
res := text.foundList.count > 0 res := text.foundList.count > 0
END; END;
CB.destroy(plainText); CB.destroy(plainText);
@ -1771,6 +1774,7 @@ PROCEDURE changeCase (text: tText; upper: BOOLEAN);
VAR VAR
i: INTEGER; i: INTEGER;
line: tLine; line: tLine;
func: Lines.fConvert;
BEGIN BEGIN
line := text.curLine; line := text.curLine;
i := text.cursor.X - 1; i := text.cursor.X - 1;
@ -1779,7 +1783,13 @@ BEGIN
DEC(i) DEC(i)
END; END;
IF Lines.chCase(line, i + 1, text.cursor.X - 1, upper) THEN IF upper THEN
func := U.cap
ELSE
func := U.low
END;
IF Lines.convert(line, i + 1, text.cursor.X - 1, func) THEN
INC(text.smallChange); INC(text.smallChange);
modify(text) modify(text)
END END
@ -1791,6 +1801,7 @@ VAR
selBeg, selEnd: tPoint; selBeg, selEnd: tPoint;
first, line: Lines.tLine; first, line: Lines.tLine;
cnt: INTEGER; cnt: INTEGER;
func: Lines.fConvert;
modified: BOOLEAN; modified: BOOLEAN;
BEGIN BEGIN
modified := FALSE; modified := FALSE;
@ -1799,23 +1810,30 @@ BEGIN
first := getLine2(text, selBeg.Y); first := getLine2(text, selBeg.Y);
line := first; line := first;
cnt := selEnd.Y - selBeg.Y; cnt := selEnd.Y - selBeg.Y;
IF upper THEN
func := U.cap
ELSE
func := U.low
END;
IF cnt = 0 THEN IF cnt = 0 THEN
IF Lines.chCase(line, selBeg.X, selEnd.X - 1, upper) THEN IF Lines.convert(line, selBeg.X, selEnd.X - 1, func) THEN
modified := TRUE modified := TRUE
END END
ELSE ELSE
IF Lines.chCase(line, selBeg.X, line.length - 1, upper) THEN IF Lines.convert(line, selBeg.X, line.length - 1, func) THEN
modified := TRUE modified := TRUE
END; END;
WHILE cnt > 1 DO WHILE cnt > 1 DO
NextLine(line); NextLine(line);
IF Lines.chCase(line, 0, line.length - 1, upper) THEN IF Lines.convert(line, 0, line.length - 1, func) THEN
modified := TRUE modified := TRUE
END; END;
DEC(cnt) DEC(cnt)
END; END;
NextLine(line); NextLine(line);
IF Lines.chCase(line, 0, selEnd.X - 1, upper) THEN IF Lines.convert(line, 0, selEnd.X - 1, func) THEN
modified := TRUE modified := TRUE
END END
END END
@ -2536,7 +2554,7 @@ BEGIN
END destroy; END destroy;
PROCEDURE open* (name: RW.tFileName; VAR errno: INTEGER): tText; PROCEDURE open* (name: RW.tFileName; ptr, size: INTEGER; VAR errno: INTEGER): tText;
VAR VAR
text: tText; text: tText;
file: RW.tInput; file: RW.tInput;
@ -2547,7 +2565,11 @@ BEGIN
errno := 0; errno := 0;
text := create(name); text := create(name);
IF text # NIL THEN IF text # NIL THEN
file := RW.load(name, enc, eol); IF ptr = 0 THEN
file := RW.loadFromFile(name, enc, eol)
ELSE
file := RW.loadFromMem(ptr, size, enc, eol)
END;
IF file = NIL THEN IF file = NIL THEN
destroy(text) destroy(text)
END END
@ -2699,6 +2721,65 @@ BEGIN
END replaceAll; END replaceAll;
PROCEDURE conv (VAR c: WCHAR; cp: E.CP; enc: INTEGER): BOOLEAN;
VAR
code: INTEGER;
res: BOOLEAN;
BEGIN
res := FALSE;
IF (c # 0X) & (c # Lines.NUL) & (c # Lines.TAB1) THEN
code := E.UNI[ORD(c), enc];
IF (0 <= code) & (code <= 255) THEN
code := cp[code]
ELSE
code := ORD(c)
END;
res := WCHR(code) # c;
c := WCHR(code)
END
RETURN res
END conv;
PROCEDURE conv1251to866 (VAR c: WCHAR): BOOLEAN;
RETURN conv(c, E.cp866, E.W1251)
END conv1251to866;
PROCEDURE conv866to1251 (VAR c: WCHAR): BOOLEAN;
RETURN conv(c, E.cp1251, E.CP866)
END conv866to1251;
PROCEDURE convert* (text: tText; cp: E.CP; enc: INTEGER);
VAR
line: tLine;
func: Lines.fConvert;
modified: BOOLEAN;
BEGIN
modified := FALSE;
line := text.first(tLine);
IF enc = E.CP866 THEN
func := conv866to1251
ELSIF enc = E.W1251 THEN
func := conv1251to866
ELSE
line := NIL
END;
WHILE line # NIL DO
IF Lines.convert(line, 0, line.length - 1, func) THEN
modified := TRUE
END;
NextLine(line)
END;
IF modified THEN
modify(text)
END
END convert;
PROCEDURE New* (): tText; PROCEDURE New* (): tText;
VAR VAR
text: tText; text: tText;