CEDIT: EOL conversion (CRLF/LF/CR)

git-svn-id: svn://kolibrios.org@9180 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2021-09-06 21:06:31 +00:00
parent 9d2e5a6e3a
commit 0d7861018a
7 changed files with 112 additions and 46 deletions

Binary file not shown.

View File

@ -28,7 +28,7 @@ IMPORT
RW, Ini, box_lib, Icons, Tabs, Timer; RW, Ini, box_lib, Icons, Tabs, Timer;
CONST CONST
header = "CEdit (03-sep-2021)"; header = "CEdit (06-sep-2021)";
ShellFilter = ""; ShellFilter = "";
EditFilter = "SH|ASM|TXT|INC|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON"; EditFilter = "SH|ASM|TXT|INC|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON";
@ -62,10 +62,11 @@ CONST
btnEdit = 71; btnEdit = 71;
btnMenuSearch = 72; btnMenuSearch = 72;
btnEncoding = 73; btnEncoding = 73;
btnView = 74; btnEOL = 74;
btnSyntax = 75; btnView = 75;
btnProgram = 76; btnSyntax = 76;
btnTools = 77; btnProgram = 77;
btnTools = 78;
MainMenuHeight = fontHeight + 7; MainMenuHeight = fontHeight + 7;
@ -91,7 +92,8 @@ CONST
menuEditX = menuFileX + 4*fontWidth + 2 + 7; menuEditX = menuFileX + 4*fontWidth + 2 + 7;
menuSearchX = menuEditX + 4*fontWidth + 2 + 7; menuSearchX = menuEditX + 4*fontWidth + 2 + 7;
menuEncodingX = menuSearchX + 6*fontWidth + 2 + 7; menuEncodingX = menuSearchX + 6*fontWidth + 2 + 7;
menuViewX = menuEncodingX + 8*fontWidth + 2 + 7; menuEOLX = menuEncodingX + 8*fontWidth + 2 + 7;
menuViewX = menuEOLX + 3*fontWidth + 2 + 7;
menuSyntaxX = menuViewX + 4*fontWidth + 2 + 7; menuSyntaxX = menuViewX + 4*fontWidth + 2 + 7;
menuProgramX = menuSyntaxX + 6*fontWidth + 2 + 7; menuProgramX = menuSyntaxX + 6*fontWidth + 2 + 7;
menuToolsX = menuProgramX + 7*fontWidth + 2 + 7; menuToolsX = menuProgramX + 7*fontWidth + 2 + 7;
@ -169,6 +171,10 @@ CONST
menuNextBookmark = 132; menuNextBookmark = 132;
menuPrevBookmark = 133; menuPrevBookmark = 133;
menuLF = 140;
menuCRLF = 141;
menuCR = 142;
maxTexts = 32; maxTexts = 32;
scrollDelay = 40; scrollDelay = 40;
@ -203,7 +209,7 @@ VAR
mainTID, delay: INTEGER; mainTID, delay: INTEGER;
context, menuFile, menuEdit, menuSearch, menuEncoding, context, menuFile, menuEdit, menuSearch, menuEncoding,
menuView, menuSyntax, menuProgram, menuTools, menuEOL, menuView, menuSyntax, menuProgram, menuTools,
subCurLine, subIndent, subCase, subBookmark: Menu.tMenu; subCurLine, subIndent, subCase, subBookmark: Menu.tMenu;
menuActive: BOOLEAN; menuActive: BOOLEAN;
@ -414,11 +420,16 @@ END WriteModified;
PROCEDURE DrawState (text: T.tText; width, height: INTEGER); PROCEDURE DrawState (text: T.tText; width, height: INTEGER);
VAR VAR
y: INTEGER; y, w, x: INTEGER;
BEGIN BEGIN
y := (btnHeight - fontHeight) DIV 2 + btnTop; y := (btnHeight - fontHeight) DIV 2 + btnTop;
K.DrawRect(width - 16*fontWidth, y, 16*fontWidth, fontHeight, K.winColor); K.DrawRect(width - 32*fontWidth, y, 32*fontWidth, fontHeight, K.winColor);
K.DrawText(width - LENGTH(E.names[text.enc])*fontWidth, y, K.textColor, E.names[text.enc]); w := LENGTH(E.names[text.enc])*fontWidth;
x := width - w;
K.DrawText(x, y, K.textColor, E.names[text.enc]);
w := LENGTH(RW.eolNames[text.eol])*fontWidth;
DEC(x, w + 10);
K.DrawText(x, y, K.textColor, RW.eolNames[text.eol]);
y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2; y := height - (BOTTOM - scrollWidth) + (BOTTOM - scrollWidth - 16) DIV 2;
K.DrawRect(LEFT + 16*fontWidth, TOP + canvas.height + scrollWidth - 1, width - LEFT - 24*fontWidth, BOTTOM - scrollWidth + 1, K.winColor); K.DrawRect(LEFT + 16*fontWidth, TOP + canvas.height + scrollWidth - 1, width - LEFT - 24*fontWidth, BOTTOM - scrollWidth + 1, K.winColor);
K.DrawText866(LEFT + 16*fontWidth, y, K.textColor, text.fileName); K.DrawText866(LEFT + 16*fontWidth, y, K.textColor, text.fileName);
@ -606,6 +617,7 @@ BEGIN
drawMainMenu(menuEdit, menuEditX, btnEdit, "edit"); drawMainMenu(menuEdit, menuEditX, btnEdit, "edit");
drawMainMenu(menuSearch, menuSearchX, btnMenuSearch, "search"); drawMainMenu(menuSearch, menuSearchX, btnMenuSearch, "search");
drawMainMenu(menuEncoding, menuEncodingX, btnEncoding, "encoding"); drawMainMenu(menuEncoding, menuEncodingX, btnEncoding, "encoding");
drawMainMenu(menuEOL, menuEOLX, btnEOL, "eol");
drawMainMenu(menuView, menuViewX, btnView, "view"); drawMainMenu(menuView, menuViewX, btnView, "view");
drawMainMenu(menuSyntax, menuSyntaxX, btnSyntax, "syntax"); drawMainMenu(menuSyntax, menuSyntaxX, btnSyntax, "syntax");
drawMainMenu(menuProgram, menuProgramX, btnProgram, "program"); drawMainMenu(menuProgram, menuProgramX, btnProgram, "program");
@ -749,7 +761,7 @@ BEGIN
END; END;
OpenFile(fileName, EditFilter); OpenFile(fileName, EditFilter);
IF fileName # "" THEN IF fileName # "" THEN
IF T.save(text, fileName, text.enc, RW.EOL_CRLF) THEN IF T.save(text, fileName) THEN
T.setName(text, fileName); T.setName(text, fileName);
U.getFileName(fileName, name, U.SLASH); U.getFileName(fileName, name, U.SLASH);
Tabs.rename(tabs, curText, name) Tabs.rename(tabs, curText, name)
@ -785,7 +797,7 @@ PROCEDURE save (text: T.tText);
BEGIN BEGIN
IF text.modified THEN IF text.modified THEN
IF text.fileName # "" THEN IF text.fileName # "" THEN
IF ~T.save(text, text.fileName, text.enc, RW.EOL_CRLF) THEN IF ~T.save(text, text.fileName) THEN
saveError(text.fileName) saveError(text.fileName)
END END
ELSE ELSE
@ -1089,6 +1101,7 @@ BEGIN
Menu.close(menuEdit); Menu.close(menuEdit);
Menu.close(menuSearch); Menu.close(menuSearch);
Menu.close(menuEncoding); Menu.close(menuEncoding);
Menu.close(menuEOL);
Menu.close(menuView); Menu.close(menuView);
Menu.close(menuSyntax); Menu.close(menuSyntax);
Menu.close(menuProgram); Menu.close(menuProgram);
@ -1201,6 +1214,11 @@ BEGIN
Menu.setCheck(menu, menuCP866, ORD(text.enc = E.CP866)*2); Menu.setCheck(menu, menuCP866, ORD(text.enc = E.CP866)*2);
Menu.setCheck(menu, menuWin1251, ORD(text.enc = E.W1251)*2); Menu.setCheck(menu, menuWin1251, ORD(text.enc = E.W1251)*2);
INC(x, menuEncodingX) INC(x, menuEncodingX)
ELSIF menu = menuEOL THEN
Menu.setCheck(menu, menuCRLF, ORD(text.eol = RW.EOL_CRLF)*2);
Menu.setCheck(menu, menuLF, ORD(text.eol = RW.EOL_LF)*2);
Menu.setCheck(menu, menuCR, ORD(text.eol = RW.EOL_CR)*2);
INC(x, menuEOLX)
ELSIF menu = menuView THEN ELSIF menu = menuView THEN
Menu.setCheck(menu, menuNumbers, ORD(text.numbers)); Menu.setCheck(menu, menuNumbers, ORD(text.numbers));
Menu.setCheck(menu, menuFontSize, ORD(font = font2)); Menu.setCheck(menu, menuFontSize, ORD(font = font2));
@ -1400,6 +1418,12 @@ BEGIN
text.enc := E.CP866 text.enc := E.CP866
|menuWin1251: |menuWin1251:
text.enc := E.W1251 text.enc := E.W1251
|menuLF:
text.eol := RW.EOL_LF
|menuCRLF:
text.eol := RW.EOL_CRLF
|menuCR:
text.eol := RW.EOL_CR
|menuPipet: |menuPipet:
K.Run("/rd/1/develop/pipet", "") K.Run("/rd/1/develop/pipet", "")
|menuBoard: |menuBoard:
@ -1565,6 +1589,18 @@ BEGIN
END CreateMenuEncoding; END CreateMenuEncoding;
PROCEDURE CreateMenuEOL (): Menu.tMenu;
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]);
RETURN Menu.create(menu, MenuItemClick, MenuKeyDown)
END CreateMenuEOL;
PROCEDURE CreateMenuView (): Menu.tMenu; PROCEDURE CreateMenuView (): Menu.tMenu;
VAR VAR
menu: List.tList; menu: List.tList;
@ -1851,6 +1887,8 @@ BEGIN
ShowMenu(menuSearch) ShowMenu(menuSearch)
|btnEncoding: |btnEncoding:
ShowMenu(menuEncoding) ShowMenu(menuEncoding)
|btnEOL:
ShowMenu(menuEOL)
|btnView: |btnView:
ShowMenu(menuView) ShowMenu(menuView)
|btnSyntax: |btnSyntax:
@ -2100,6 +2138,7 @@ BEGIN
T.init(resetTimer); T.init(resetTimer);
T.setCanvas(canvas); T.setCanvas(canvas);
U.ptr2str(K.GetCommandLine(), fileName); U.ptr2str(K.GetCommandLine(), fileName);
context := CreateContextMenu(); context := CreateContextMenu();
menuFile := CreateMenuFile(); menuFile := CreateMenuFile();
subCurLine := CreateMenuCurLine(); subCurLine := CreateMenuCurLine();
@ -2113,6 +2152,7 @@ BEGIN
menuSearch := CreateMenuSearch(); menuSearch := CreateMenuSearch();
subBookmark.parent := menuSearch; subBookmark.parent := menuSearch;
menuEncoding := CreateMenuEncoding(); menuEncoding := CreateMenuEncoding();
menuEOL := CreateMenuEOL();
menuView := CreateMenuView(); menuView := CreateMenuView();
menuSyntax := CreateMenuSyntax(); menuSyntax := CreateMenuSyntax();
menuProgram := CreateMenuProgram(); menuProgram := CreateMenuProgram();

View File

@ -124,7 +124,7 @@ BEGIN
canvas := m.canvas; canvas := m.canvas;
G.SetColor(canvas, backColor); G.SetColor(canvas, backColor);
G.clear(canvas); G.clear(canvas);
G.SetColor(canvas, ORD((-BITS(backColor))*{0..23}) ); G.SetColor(canvas, foreColor);
G.Rect(canvas, 0, 0, m.width, m.height); G.Rect(canvas, 0, 0, m.width, m.height);
y := TOP; y := TOP;
i := 0; i := 0;
@ -172,7 +172,7 @@ BEGIN
INC(y, fontHeight); INC(y, fontHeight);
IF item.delim THEN IF item.delim THEN
G.SetColor(canvas, ORD((-BITS(backColor))*{0..23})); G.SetColor(canvas, foreColor);
G.HLine(canvas, y - 2, 1, m.width - 1) G.HLine(canvas, y - 2, 1, m.width - 1)
END; END;
INC(i); INC(i);

View File

@ -33,7 +33,7 @@ CONST
NAME_LEN = 1024; NAME_LEN = 1024;
EOL_LF* = 0; EOL_CRLF* = 1; EOL_CR* = 2; EOL_CRLF* = 0; EOL_LF* = 1; EOL_CR* = 2;
TYPE TYPE
@ -45,7 +45,6 @@ TYPE
tInput* = POINTER TO RECORD tInput* = POINTER TO RECORD
buffer: INTEGER; buffer: INTEGER;
pos, cnt: INTEGER; pos, cnt: INTEGER;
enc: INTEGER;
CR: BOOLEAN; CR: BOOLEAN;
clipbrd: BOOLEAN; clipbrd: BOOLEAN;
getChar: PROCEDURE (file: tInput): INTEGER getChar: PROCEDURE (file: tInput): INTEGER
@ -63,6 +62,7 @@ TYPE
VAR VAR
eol*: ARRAY 3 OF tEOL; eol*: ARRAY 3 OF tEOL;
eolNames*: ARRAY 3, 16 OF WCHAR;
PROCEDURE getByte (file: tInput): BYTE; PROCEDURE getByte (file: tInput): BYTE;
@ -296,7 +296,35 @@ BEGIN
END detectEncoding; END detectEncoding;
PROCEDURE load* (name: tFileName; VAR enc: INTEGER): tInput; PROCEDURE detectEOL (text: tInput): INTEGER;
VAR
pos, cnt, c, res: INTEGER;
BEGIN
res := -1;
pos := text.pos;
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
ELSE
res := EOL_CR
END
END
END;
text.cnt := cnt;
text.pos := pos;
IF res = -1 THEN
res := EOL_CRLF
END
RETURN res
END detectEOL;
PROCEDURE load* (name: tFileName; VAR enc, eol: INTEGER): tInput;
VAR VAR
res: tInput; res: tInput;
fsize: INTEGER; fsize: INTEGER;
@ -325,7 +353,7 @@ BEGIN
ELSIF enc = E.W1251 THEN ELSIF enc = E.W1251 THEN
res.getChar := getCharW1251 res.getChar := getCharW1251
END; END;
res.enc := enc eol := detectEOL(res)
END END
RETURN res RETURN res
END load; END load;
@ -340,7 +368,6 @@ BEGIN
res.CR := FALSE; res.CR := FALSE;
res.clipbrd := TRUE; res.clipbrd := TRUE;
res.getChar := NIL; res.getChar := NIL;
res.enc := E.CP866;
res.getChar := getCharCP866; res.getChar := getCharCP866;
res.buffer := CB.get(res.cnt); res.buffer := CB.get(res.cnt);
IF res.buffer = 0 THEN IF res.buffer = 0 THEN
@ -524,7 +551,10 @@ END destroy;
BEGIN BEGIN
eol[EOL_LF] := LF;
eol[EOL_CRLF] := CR + LF; eol[EOL_CRLF] := CR + LF;
eol[EOL_CR] := CR eol[EOL_LF] := LF;
eol[EOL_CR] := CR;
eolNames[EOL_CRLF] := "CRLF";
eolNames[EOL_LF] := "LF";
eolNames[EOL_CR] := "CR"
END RW. END RW.

View File

@ -75,6 +75,7 @@ TYPE
fileName*: RW.tFileName; fileName*: RW.tFileName;
lang*: INTEGER; lang*: INTEGER;
enc*: INTEGER; enc*: INTEGER;
eol*: INTEGER;
table: Search.IdxTable; table: Search.IdxTable;
foundList: List.tList; foundList: List.tList;
idxData: Search.tBuffer; idxData: Search.tBuffer;
@ -1337,7 +1338,7 @@ BEGIN
END scroll; END scroll;
PROCEDURE save* (text: tText; name: RW.tFileName; enc, nl: INTEGER): BOOLEAN; PROCEDURE save* (text: tText; name: RW.tFileName): BOOLEAN;
CONST CONST
tempFile = "/tmp0/1/cedit~.tmp"; tempFile = "/tmp0/1/cedit~.tmp";
VAR VAR
@ -1348,7 +1349,7 @@ VAR
BEGIN BEGIN
ChangeLog.setGuard(text.edition); ChangeLog.setGuard(text.edition);
res := TRUE; res := TRUE;
file := RW.create(tempFile, enc, nl); file := RW.create(tempFile, text.enc, text.eol);
IF file # NIL THEN IF file # NIL THEN
ChangeLog.delSaved; ChangeLog.delSaved;
line := text.first(tLine); line := text.first(tLine);
@ -2304,34 +2305,30 @@ PROCEDURE open* (name: RW.tFileName; VAR errno: INTEGER): tText;
VAR VAR
text: tText; text: tText;
file: RW.tInput; file: RW.tInput;
n, enc: INTEGER; n, enc, eol: INTEGER;
eol: BOOLEAN; _eol: BOOLEAN;
line: tLine; line: tLine;
BEGIN BEGIN
errno := 0; errno := 0;
text := NIL; text := NIL;
file := RW.load(name, enc); file := RW.load(name, enc, eol);
IF file # NIL THEN IF file # NIL THEN
text := create(name); text := create(name);
text.enc := enc; text.enc := enc;
text.eol := eol;
line := Lines.create(FALSE);
List._append(text, line);
REPEAT REPEAT
line := Lines.create(FALSE); n := RW.getString(file, line, Lines.tabs, _eol);
n := RW.getString(file, line, Lines.tabs, eol); IF _eol THEN
IF n >= 0 THEN line := Lines.create(FALSE);
List._append(text, line) List._append(text, line)
ELSE
Lines.destroy(line)
END END
UNTIL n < 0; UNTIL ~_eol;
RW.destroy(file); RW.destroy(file);
IF n = -1 THEN text.curLine := text.first(tLine);
IF text.count = 0 THEN SetPos(text, 0, 0);
List._append(text, Lines.create(FALSE)) resetSelect(text)
END;
text.curLine := text.first(tLine);
SetPos(text, 0, 0);
resetSelect(text)
END
ELSE ELSE
errno := 1 errno := 1
END; END;
@ -2477,6 +2474,7 @@ BEGIN
List._append(text, Lines.create(FALSE)); List._append(text, Lines.create(FALSE));
text.curLine := text.first(tLine); text.curLine := text.first(tLine);
text.enc := E.CP866; text.enc := E.CP866;
text.eol := RW.EOL_CRLF;
SetPos(text, 0, 0); SetPos(text, 0, 0);
resetSelect(text) resetSelect(text)
RETURN text RETURN text

View File

@ -61,10 +61,8 @@ BEGIN
IF ~paused THEN IF ~paused THEN
DEC(cnt, step); DEC(cnt, step);
IF cnt <= 0 THEN IF cnt <= 0 THEN
cnt := time; K.SendIPC(mainTID, ID);
IF time > 0 THEN cnt := time
K.SendIPC(mainTID, ID)
END
END END
END END
END END

View File

@ -90,7 +90,7 @@ BEGIN
height := scroll.height; height := scroll.height;
canvas := scroll.canvas; canvas := scroll.canvas;
G.SetColor(canvas, K.winColor); G.SetColor(canvas, K.winColor);
G.FillRect(canvas, 0, 0, width - 1, height - 1); G.clear(canvas);
G.SetColor(canvas, K.borderColor); G.SetColor(canvas, K.borderColor);
G.Rect(canvas, 0, 0, width - 1, height - 1); G.Rect(canvas, 0, 0, width - 1, height - 1);
IF scroll.vertical THEN IF scroll.vertical THEN