Subversion Repositories Kolibri OS

Rev

Rev 9904 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8728 leency 1
(*
9904 akron1 2
    Copyright 2021-2023 Anton Krotov
8728 leency 3
 
4
    This file is part of CEdit.
5
 
6
    CEdit is free software: you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation, either version 3 of the License, or
9
    (at your option) any later version.
10
 
11
    CEdit is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
15
 
16
    You should have received a copy of the GNU General Public License
17
    along with CEdit. If not, see .
18
*)
19
 
20
MODULE Ini;
21
 
22
IMPORT
23
 
9904 akron1 24
    SYSTEM, RW, Text, Utils, File, List, Languages, Lines;
8728 leency 25
 
26
 
27
CONST
28
 
29
    fileName = "cedit.ini";
9913 akron1 30
    libName = "libini.obj";
8728 leency 31
 
32
    MAX_LEN = 32;
33
    MAX_SECTIONS* = 10;
34
 
35
 
36
TYPE
37
 
38
    tString = ARRAY 128 OF CHAR;
39
 
40
    tSectionName = ARRAY MAX_LEN OF WCHAR;
41
    tASCIISectionName = ARRAY MAX_LEN OF CHAR;
42
 
43
    tSection* = POINTER TO RECORD (List.tItem)
44
        name*: tSectionName
45
    END;
46
 
47
 
48
VAR
49
 
50
    IniFileName: RW.tFileName;
51
    sections*: List.tList;
52
 
53
    curSection*: tASCIISectionName;
54
    curSectionNum*: INTEGER;
55
 
9671 akron1 56
    blink*, font*, theme*: INTEGER;
57
    buildScript*, runScript*, debugScript*: RW.tFileName;
58
    lineNumbers*, autoIndents*, autoBrackets*, trimSpace*: BOOLEAN;
8728 leency 59
 
9645 akron1 60
 
9913 akron1 61
PROCEDURE [stdcall,  libName, "ini_get_color"]     get_color (f_name: RW.tFileName; sec_name: tASCIISectionName; key_name: tString; def_val: INTEGER): INTEGER; END;
62
PROCEDURE [stdcall,  libName, "ini_get_int"]       get_int (f_name: RW.tFileName; sec_name: tASCIISectionName; key_name: tString; def_val: INTEGER): INTEGER; END;
63
PROCEDURE [stdcall,  libName, "ini_get_str"]       get_str (f_name, sec_name, key_name, buffer, buf_len, def_val: INTEGER): INTEGER; END;
64
PROCEDURE [stdcall,  libName, "ini_enum_sections"] enum_sections (f_name: RW.tFileName; callback: INTEGER); END;
65
PROCEDURE [stdcall-, libName, "ini_set_int"]       set_int (f_name, sec_name, key_name, val: INTEGER): INTEGER; END;
9671 akron1 66
 
8728 leency 67
PROCEDURE getColor (key: tString; def: INTEGER): INTEGER;
68
    RETURN get_color(IniFileName, curSection, key, def)
69
END getColor;
70
 
71
 
72
PROCEDURE getStr* (secName, keyName: ARRAY OF CHAR; VAR s: ARRAY OF CHAR);
73
BEGIN
74
    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
75
        s[0] := 0X
76
    END
77
END getStr;
78
 
79
 
9671 akron1 80
PROCEDURE setInt* (secName, keyName: ARRAY OF CHAR; val: INTEGER);
81
BEGIN
82
    set_int(SYSTEM.ADR(IniFileName[0]), SYSTEM.ADR(secName[0]), SYSTEM.ADR(keyName[0]), val)
83
END setInt;
84
 
85
 
8728 leency 86
PROCEDURE [stdcall] section_callback (fileName, sectionName: RW.tFileName): INTEGER;
87
VAR
88
    section: tSection;
89
    name: tSectionName;
90
    i: INTEGER;
91
BEGIN
92
    IF sections.count < MAX_SECTIONS THEN
93
        i := 0;
94
        WHILE (i < MAX_LEN - 1) & (sectionName[i] # 0X) DO
95
            name[i] := WCHR(ORD(sectionName[i]));
96
            INC(i)
97
        END;
98
        name[i] := 0X
99
    END;
100
    IF Utils.streq(SYSTEM.ADR(name[0]), SYSTEM.WSADR("color_"), 6) THEN
101
        Utils.reverse(name);
102
        name[LENGTH(name) - 6] := 0X;
103
        Utils.reverse(name);
104
        NEW(section);
105
        section.name := name;
106
        List.append(sections, section)
107
    END
108
    RETURN 1
109
END section_callback;
110
 
111
 
112
PROCEDURE selectSection* (idx: INTEGER);
113
VAR
114
    i: INTEGER;
115
    item: List.tItem;
116
    section: tSection;
117
 
118
    text, back, seltext, selback, modified, saved, curline, numtext, numback,
9413 akron1 119
    comment, string, escape, num, delim, key1, key2, key3: INTEGER;
8728 leency 120
BEGIN
121
    IF (0 <= idx) & (idx < sections.count) THEN
122
        curSectionNum := idx;
123
        item := List.getItem(sections, idx);
124
        section := item(tSection);
125
        i := 0;
126
        WHILE section.name[i] # 0X DO
127
            curSection[i] := CHR(ORD(section.name[i]));
128
            INC(i)
129
        END;
130
        curSection[i] := 0X;
131
        Utils.reverse8(curSection);
132
        Utils.append8(curSection, "_roloc");
133
        Utils.reverse8(curSection)
134
    ELSE
135
        curSection := ""
136
    END;
137
 
138
    text     := getColor("text",     0000000H);
139
    back     := getColor("back",     0FFFFFFH);
140
    seltext  := getColor("seltext",  0FFFFFFH);
141
    selback  := getColor("selback",  00000FFH);
142
    modified := getColor("modified", 0E8E800H);
143
    saved    := getColor("saved",    000D000H);
144
    curline  := getColor("curline",  0FFFFC8H);
145
    numtext  := getColor("numtext",  0000000H);
146
    numback  := getColor("numback",  0E6E6E6H);
147
 
148
    comment  := getColor("comment",  0800080H);
149
    string   := getColor("string",   0008000H);
150
    num      := getColor("num",      0800000H);
151
    delim    := getColor("delim",    0000080H);
152
    key1     := getColor("key1",     0000080H);
153
    key2     := getColor("key2",     0008080H);
154
    key3     := getColor("key3",     0008080H);
9413 akron1 155
    escape   := getColor("escape",   string);
8728 leency 156
 
157
    Text.setColors(text, back, seltext, selback, modified, saved, curline, numtext, numback,
9413 akron1 158
        comment, string, escape, num, delim, key1, key2, key3);
8728 leency 159
END selectSection;
160
 
161
 
9671 akron1 162
PROCEDURE getSettings*;
9174 akron1 163
BEGIN
164
	Lines.setTabs(get_int(IniFileName, "settings", "tab", 4));
165
	blink := get_int(IniFileName, "settings", "blink", 70);
9671 akron1 166
	lineNumbers  := get_int(IniFileName, "settings", "line_numbers",  1) # 0;
167
	autoIndents  := get_int(IniFileName, "settings", "auto_indents",  1) # 0;
168
	autoBrackets := get_int(IniFileName, "settings", "auto_brackets", 0) # 0;
169
	trimSpace    := get_int(IniFileName, "settings", "trim_space",    1) # 0;
170
	font := get_int(IniFileName, "settings", "font", 1);
9904 akron1 171
	IF (font < 0) OR (font > 2) THEN
9671 akron1 172
		font := 1
173
	END;
174
	theme := get_int(IniFileName, "settings", "theme", 0);
9904 akron1 175
	IF (theme < 0) OR (theme >= sections.count) THEN
9671 akron1 176
		theme := 0
177
	END;
178
    getStr("settings", "build", buildScript);
179
    getStr("settings", "run",   runScript);
180
    getStr("settings", "debug", debugScript);
9174 akron1 181
END getSettings;
182
 
183
 
8728 leency 184
PROCEDURE load* (path: RW.tFileName);
185
BEGIN
186
    sections := List.create(NIL);
9174 akron1 187
 
188
    Utils.getPath(path, IniFileName);
189
    Utils.append8(IniFileName, Utils.SLASH);
190
    Utils.append8(IniFileName, fileName);
191
 
192
    IF ~File.Exists(IniFileName) THEN
9671 akron1 193
    	IniFileName := "/sys/settings/" + fileName
8728 leency 194
    END;
195
 
196
    enum_sections(IniFileName, SYSTEM.ADR(section_callback));
197
    Languages.init(getStr);
9671 akron1 198
    selectSection(theme);
8728 leency 199
END load;
200
 
201
 
202
END Ini.