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

View File

@ -124,7 +124,7 @@ BEGIN
canvas := m.canvas;
G.SetColor(canvas, backColor);
G.clear(canvas);
G.SetColor(canvas, ORD((-BITS(backColor))*{0..23}) );
G.SetColor(canvas, foreColor);
G.Rect(canvas, 0, 0, m.width, m.height);
y := TOP;
i := 0;
@ -172,7 +172,7 @@ BEGIN
INC(y, fontHeight);
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)
END;
INC(i);

View File

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

View File

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

View File

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

View File

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