kolibrios-fun/programs/develop/cedit/SRC/Encodings.ob07
Anton Krotov f8df2f2297 CEdit: minor fix
git-svn-id: svn://kolibrios.org@9906 a494cfbc-eb01-0410-851d-a64ba20cac60
2023-03-05 21:40:21 +00:00

140 lines
3.6 KiB
Plaintext

(*
Copyright 2021-2023 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 Encodings;
CONST
CP866* = 0; CP1251* = 1; UTF8* = 2; UTF8BOM* = 3; (*UTF16LE* = 4;*)
UNDEF* = ORD("?");
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
cp1251*, cp866*: CP;
names*: ARRAY 4, 16 OF WCHAR;
UNI*: ARRAY 65536, 2 OF BYTE;
eol*: ARRAY 3 OF tEOL;
eolNames*: ARRAY 3, 16 OF WCHAR;
PROCEDURE InitCP (VAR cp: CP);
VAR
i: INTEGER;
BEGIN
FOR i := 0H TO 7FH DO
cp[i] := i
END
END InitCP;
PROCEDURE Init8 (VAR cp: CP; VAR n: INTEGER; a, b, c, d, e, f, g, h: INTEGER);
BEGIN
cp[n] := a; INC(n);
cp[n] := b; INC(n);
cp[n] := c; INC(n);
cp[n] := d; INC(n);
cp[n] := e; INC(n);
cp[n] := f; INC(n);
cp[n] := g; INC(n);
cp[n] := h; INC(n);
END Init8;
PROCEDURE InitCP1251 (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);
Init8(cp, n, 0452H, 2018H, 2019H, 201CH, 201DH, 2022H, 2013H, 2014H);
Init8(cp, n, UNDEF, 2122H, 0459H, 203AH, 045AH, 045CH, 045BH, 045FH);
Init8(cp, n, 00A0H, 040EH, 045EH, 0408H, 00A4H, 0490H, 00A6H, 00A7H);
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);
END InitCP1251;
PROCEDURE InitCP866 (VAR cp: CP);
VAR
n, i: INTEGER;
BEGIN
InitCP(cp);
FOR i := 0410H TO 043FH DO
cp[i - 390H] := i
END;
FOR i := 0440H TO 044FH DO
cp[i - 360H] := i
END;
n := 0B0H;
Init8(cp, n, 2591H, 2592H, 2593H, 2502H, 2524H, 2561H, 2562H, 2556H);
Init8(cp, n, 2555H, 2563H, 2551H, 2557H, 255DH, 255CH, 255BH, 2510H);
Init8(cp, n, 2514H, 2534H, 252CH, 251CH, 2500H, 253CH, 255EH, 255FH);
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);
END InitCP866;
PROCEDURE setUNI;
VAR
i: INTEGER;
BEGIN
FOR i := 0 TO 65535 DO
UNI[i, CP866] := UNDEF;
UNI[i, CP1251] := UNDEF
END;
FOR i := 0 TO 255 DO
UNI[cp1251[i], CP1251] := i;
UNI[cp866[i], CP866] := i
END
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[CP1251] := "CP1251";
names[UTF8] := "UTF-8";
names[UTF8BOM] := "UTF-8-BOM";
InitCP1251(cp1251);
InitCP866(cp866);
setUNI
END Encodings.