2021-05-23 11:43:28 +02:00
|
|
|
(*
|
2023-02-26 20:26:25 +01:00
|
|
|
Copyright 2021-2023 Anton Krotov
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
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 Ini;
|
|
|
|
|
|
|
|
IMPORT
|
|
|
|
|
2023-02-26 20:26:25 +01:00
|
|
|
SYSTEM, RW, Text, Utils, File, List, Languages, Lines;
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
CONST
|
|
|
|
|
|
|
|
fileName = "cedit.ini";
|
2023-04-13 21:16:45 +02:00
|
|
|
libName = "libini.obj";
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
MAX_LEN = 32;
|
|
|
|
MAX_SECTIONS* = 10;
|
|
|
|
|
|
|
|
|
|
|
|
TYPE
|
|
|
|
|
|
|
|
tString = ARRAY 128 OF CHAR;
|
|
|
|
|
|
|
|
tSectionName = ARRAY MAX_LEN OF WCHAR;
|
|
|
|
tASCIISectionName = ARRAY MAX_LEN OF CHAR;
|
|
|
|
|
|
|
|
tSection* = POINTER TO RECORD (List.tItem)
|
|
|
|
name*: tSectionName
|
|
|
|
END;
|
|
|
|
|
|
|
|
|
|
|
|
VAR
|
|
|
|
|
|
|
|
IniFileName: RW.tFileName;
|
|
|
|
sections*: List.tList;
|
|
|
|
|
|
|
|
curSection*: tASCIISectionName;
|
|
|
|
curSectionNum*: INTEGER;
|
|
|
|
|
2023-10-01 14:50:05 +02:00
|
|
|
blink*, font*, theme*, lineSpacing*: INTEGER;
|
2022-01-25 22:57:14 +01:00
|
|
|
buildScript*, runScript*, debugScript*: RW.tFileName;
|
|
|
|
lineNumbers*, autoIndents*, autoBrackets*, trimSpace*: BOOLEAN;
|
2021-05-23 11:43:28 +02:00
|
|
|
|
2022-01-25 22:57:14 +01:00
|
|
|
|
2023-04-13 21:16:45 +02:00
|
|
|
PROCEDURE [stdcall, libName, "ini_get_color"] get_color (f_name: RW.tFileName; sec_name: tASCIISectionName; key_name: tString; def_val: INTEGER): INTEGER; END;
|
|
|
|
PROCEDURE [stdcall, libName, "ini_get_int"] get_int (f_name: RW.tFileName; sec_name: tASCIISectionName; key_name: tString; def_val: INTEGER): INTEGER; END;
|
|
|
|
PROCEDURE [stdcall, libName, "ini_get_str"] get_str (f_name, sec_name, key_name, buffer, buf_len, def_val: INTEGER): INTEGER; END;
|
|
|
|
PROCEDURE [stdcall, libName, "ini_enum_sections"] enum_sections (f_name: RW.tFileName; callback: INTEGER); END;
|
|
|
|
PROCEDURE [stdcall-, libName, "ini_set_int"] set_int (f_name, sec_name, key_name, val: INTEGER): INTEGER; END;
|
2022-01-16 08:18:30 +01:00
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
PROCEDURE getColor (key: tString; def: INTEGER): INTEGER;
|
|
|
|
RETURN get_color(IniFileName, curSection, key, def)
|
|
|
|
END getColor;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE getStr* (secName, keyName: ARRAY OF CHAR; VAR s: ARRAY OF CHAR);
|
|
|
|
BEGIN
|
|
|
|
IF get_str(SYSTEM.ADR(IniFileName[0]), SYSTEM.ADR(secName[0]), SYSTEM.ADR(keyName[0]), SYSTEM.ADR(s[0]), LEN(s) - 1, SYSTEM.SADR("")) = -1 THEN
|
|
|
|
s[0] := 0X
|
|
|
|
END
|
|
|
|
END getStr;
|
|
|
|
|
|
|
|
|
2022-01-25 22:57:14 +01:00
|
|
|
PROCEDURE setInt* (secName, keyName: ARRAY OF CHAR; val: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
set_int(SYSTEM.ADR(IniFileName[0]), SYSTEM.ADR(secName[0]), SYSTEM.ADR(keyName[0]), val)
|
|
|
|
END setInt;
|
|
|
|
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
PROCEDURE [stdcall] section_callback (fileName, sectionName: RW.tFileName): INTEGER;
|
|
|
|
VAR
|
|
|
|
section: tSection;
|
|
|
|
name: tSectionName;
|
|
|
|
i: INTEGER;
|
|
|
|
BEGIN
|
|
|
|
IF sections.count < MAX_SECTIONS THEN
|
|
|
|
i := 0;
|
|
|
|
WHILE (i < MAX_LEN - 1) & (sectionName[i] # 0X) DO
|
|
|
|
name[i] := WCHR(ORD(sectionName[i]));
|
|
|
|
INC(i)
|
|
|
|
END;
|
|
|
|
name[i] := 0X
|
|
|
|
END;
|
|
|
|
IF Utils.streq(SYSTEM.ADR(name[0]), SYSTEM.WSADR("color_"), 6) THEN
|
|
|
|
Utils.reverse(name);
|
|
|
|
name[LENGTH(name) - 6] := 0X;
|
|
|
|
Utils.reverse(name);
|
|
|
|
NEW(section);
|
|
|
|
section.name := name;
|
|
|
|
List.append(sections, section)
|
|
|
|
END
|
|
|
|
RETURN 1
|
|
|
|
END section_callback;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE selectSection* (idx: INTEGER);
|
|
|
|
VAR
|
|
|
|
i: INTEGER;
|
|
|
|
item: List.tItem;
|
|
|
|
section: tSection;
|
|
|
|
|
|
|
|
text, back, seltext, selback, modified, saved, curline, numtext, numback,
|
2021-12-11 19:27:02 +01:00
|
|
|
comment, string, escape, num, delim, key1, key2, key3: INTEGER;
|
2021-05-23 11:43:28 +02:00
|
|
|
BEGIN
|
|
|
|
IF (0 <= idx) & (idx < sections.count) THEN
|
|
|
|
curSectionNum := idx;
|
|
|
|
item := List.getItem(sections, idx);
|
|
|
|
section := item(tSection);
|
|
|
|
i := 0;
|
|
|
|
WHILE section.name[i] # 0X DO
|
|
|
|
curSection[i] := CHR(ORD(section.name[i]));
|
|
|
|
INC(i)
|
|
|
|
END;
|
|
|
|
curSection[i] := 0X;
|
|
|
|
Utils.reverse8(curSection);
|
|
|
|
Utils.append8(curSection, "_roloc");
|
|
|
|
Utils.reverse8(curSection)
|
|
|
|
ELSE
|
|
|
|
curSection := ""
|
|
|
|
END;
|
|
|
|
|
|
|
|
text := getColor("text", 0000000H);
|
|
|
|
back := getColor("back", 0FFFFFFH);
|
|
|
|
seltext := getColor("seltext", 0FFFFFFH);
|
|
|
|
selback := getColor("selback", 00000FFH);
|
|
|
|
modified := getColor("modified", 0E8E800H);
|
|
|
|
saved := getColor("saved", 000D000H);
|
|
|
|
curline := getColor("curline", 0FFFFC8H);
|
|
|
|
numtext := getColor("numtext", 0000000H);
|
|
|
|
numback := getColor("numback", 0E6E6E6H);
|
|
|
|
|
|
|
|
comment := getColor("comment", 0800080H);
|
|
|
|
string := getColor("string", 0008000H);
|
|
|
|
num := getColor("num", 0800000H);
|
|
|
|
delim := getColor("delim", 0000080H);
|
|
|
|
key1 := getColor("key1", 0000080H);
|
|
|
|
key2 := getColor("key2", 0008080H);
|
|
|
|
key3 := getColor("key3", 0008080H);
|
2021-12-11 19:27:02 +01:00
|
|
|
escape := getColor("escape", string);
|
2021-05-23 11:43:28 +02:00
|
|
|
|
|
|
|
Text.setColors(text, back, seltext, selback, modified, saved, curline, numtext, numback,
|
2021-12-11 19:27:02 +01:00
|
|
|
comment, string, escape, num, delim, key1, key2, key3);
|
2021-05-23 11:43:28 +02:00
|
|
|
END selectSection;
|
|
|
|
|
|
|
|
|
2022-01-25 22:57:14 +01:00
|
|
|
PROCEDURE getSettings*;
|
2021-09-03 01:15:33 +02:00
|
|
|
BEGIN
|
|
|
|
Lines.setTabs(get_int(IniFileName, "settings", "tab", 4));
|
|
|
|
blink := get_int(IniFileName, "settings", "blink", 70);
|
2022-01-25 22:57:14 +01:00
|
|
|
lineNumbers := get_int(IniFileName, "settings", "line_numbers", 1) # 0;
|
|
|
|
autoIndents := get_int(IniFileName, "settings", "auto_indents", 1) # 0;
|
|
|
|
autoBrackets := get_int(IniFileName, "settings", "auto_brackets", 0) # 0;
|
|
|
|
trimSpace := get_int(IniFileName, "settings", "trim_space", 1) # 0;
|
|
|
|
font := get_int(IniFileName, "settings", "font", 1);
|
2023-02-26 20:26:25 +01:00
|
|
|
IF (font < 0) OR (font > 2) THEN
|
2022-01-25 22:57:14 +01:00
|
|
|
font := 1
|
|
|
|
END;
|
2023-10-01 14:50:05 +02:00
|
|
|
lineSpacing := get_int(IniFileName, "settings", "line_spacing", 2);
|
|
|
|
IF (lineSpacing < 0) OR (lineSpacing > Text.MaxLineSpacing) THEN
|
|
|
|
lineSpacing := 2
|
|
|
|
END;
|
2022-01-25 22:57:14 +01:00
|
|
|
theme := get_int(IniFileName, "settings", "theme", 0);
|
2023-02-26 20:26:25 +01:00
|
|
|
IF (theme < 0) OR (theme >= sections.count) THEN
|
2022-01-25 22:57:14 +01:00
|
|
|
theme := 0
|
|
|
|
END;
|
|
|
|
getStr("settings", "build", buildScript);
|
|
|
|
getStr("settings", "run", runScript);
|
|
|
|
getStr("settings", "debug", debugScript);
|
2021-09-03 01:15:33 +02:00
|
|
|
END getSettings;
|
|
|
|
|
|
|
|
|
2021-05-23 11:43:28 +02:00
|
|
|
PROCEDURE load* (path: RW.tFileName);
|
|
|
|
BEGIN
|
|
|
|
sections := List.create(NIL);
|
2021-09-03 01:15:33 +02:00
|
|
|
|
|
|
|
Utils.getPath(path, IniFileName);
|
|
|
|
Utils.append8(IniFileName, Utils.SLASH);
|
|
|
|
Utils.append8(IniFileName, fileName);
|
|
|
|
|
|
|
|
IF ~File.Exists(IniFileName) THEN
|
2022-01-25 22:57:14 +01:00
|
|
|
IniFileName := "/sys/settings/" + fileName
|
2021-05-23 11:43:28 +02:00
|
|
|
END;
|
|
|
|
|
|
|
|
enum_sections(IniFileName, SYSTEM.ADR(section_callback));
|
|
|
|
Languages.init(getStr);
|
2022-01-25 22:57:14 +01:00
|
|
|
selectSection(theme);
|
2021-05-23 11:43:28 +02:00
|
|
|
END load;
|
|
|
|
|
|
|
|
|
|
|
|
END Ini.
|