Subversion Repositories Kolibri OS

Rev

Rev 9645 | 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
(*
9577 akron1 2
    Copyright 2021, 2022 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
 
9645 akron1 24
    SYSTEM, RW, Text, Utils, File, List, Languages, KolibriOS, Lines;
8728 leency 25
 
26
 
27
CONST
28
 
29
    fileName = "cedit.ini";
30
 
31
    MAX_LEN = 32;
32
    MAX_SECTIONS* = 10;
33
 
34
 
35
TYPE
36
 
37
    tString = ARRAY 128 OF CHAR;
38
 
39
    tSectionName = ARRAY MAX_LEN OF WCHAR;
40
    tASCIISectionName = ARRAY MAX_LEN OF CHAR;
41
 
42
    tSection* = POINTER TO RECORD (List.tItem)
43
        name*: tSectionName
44
    END;
45
 
46
 
47
VAR
48
 
49
    IniFileName: RW.tFileName;
50
    sections*: List.tList;
51
 
52
    curSection*: tASCIISectionName;
53
    curSectionNum*: INTEGER;
54
 
9671 akron1 55
    blink*, font*, theme*: INTEGER;
56
    buildScript*, runScript*, debugScript*: RW.tFileName;
57
    lineNumbers*, autoIndents*, autoBrackets*, trimSpace*: BOOLEAN;
8728 leency 58
 
9645 akron1 59
 
9671 akron1 60
PROCEDURE [stdcall,  "libini.obj", "ini_get_color"]     get_color (f_name: RW.tFileName; sec_name: tASCIISectionName; key_name: tString; def_val: INTEGER): INTEGER; END;
61
PROCEDURE [stdcall,  "libini.obj", "ini_get_int"]       get_int (f_name: RW.tFileName; sec_name: tASCIISectionName; key_name: tString; def_val: INTEGER): INTEGER; END;
62
PROCEDURE [stdcall,  "libini.obj", "ini_get_str"]       get_str (f_name, sec_name, key_name, buffer, buf_len, def_val: INTEGER): INTEGER; END;
63
PROCEDURE [stdcall,  "libini.obj", "ini_enum_sections"] enum_sections (f_name: RW.tFileName; callback: INTEGER); END;
64
PROCEDURE [stdcall-, "libini.obj", "ini_set_int"]       set_int (f_name, sec_name, key_name, val: INTEGER): INTEGER; END;
65
 
8728 leency 66
PROCEDURE getColor (key: tString; def: INTEGER): INTEGER;
67
    RETURN get_color(IniFileName, curSection, key, def)
68
END getColor;
69
 
70
 
71
PROCEDURE getStr* (secName, keyName: ARRAY OF CHAR; VAR s: ARRAY OF CHAR);
72
BEGIN
73
    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
74
        s[0] := 0X
75
    END
76
END getStr;
77
 
78
 
9671 akron1 79
PROCEDURE setInt* (secName, keyName: ARRAY OF CHAR; val: INTEGER);
80
BEGIN
81
    set_int(SYSTEM.ADR(IniFileName[0]), SYSTEM.ADR(secName[0]), SYSTEM.ADR(keyName[0]), val)
82
END setInt;
83
 
84
 
8728 leency 85
PROCEDURE [stdcall] section_callback (fileName, sectionName: RW.tFileName): INTEGER;
86
VAR
87
    section: tSection;
88
    name: tSectionName;
89
    i: INTEGER;
90
BEGIN
91
    IF sections.count < MAX_SECTIONS THEN
92
        i := 0;
93
        WHILE (i < MAX_LEN - 1) & (sectionName[i] # 0X) DO
94
            name[i] := WCHR(ORD(sectionName[i]));
95
            INC(i)
96
        END;
97
        name[i] := 0X
98
    END;
99
    IF Utils.streq(SYSTEM.ADR(name[0]), SYSTEM.WSADR("color_"), 6) THEN
100
        Utils.reverse(name);
101
        name[LENGTH(name) - 6] := 0X;
102
        Utils.reverse(name);
103
        NEW(section);
104
        section.name := name;
105
        List.append(sections, section)
106
    END
107
    RETURN 1
108
END section_callback;
109
 
110
 
111
PROCEDURE selectSection* (idx: INTEGER);
112
VAR
113
    i: INTEGER;
114
    item: List.tItem;
115
    section: tSection;
116
 
117
    text, back, seltext, selback, modified, saved, curline, numtext, numback,
9413 akron1 118
    comment, string, escape, num, delim, key1, key2, key3: INTEGER;
8728 leency 119
BEGIN
120
    IF (0 <= idx) & (idx < sections.count) THEN
121
        curSectionNum := idx;
122
        item := List.getItem(sections, idx);
123
        section := item(tSection);
124
        i := 0;
125
        WHILE section.name[i] # 0X DO
126
            curSection[i] := CHR(ORD(section.name[i]));
127
            INC(i)
128
        END;
129
        curSection[i] := 0X;
130
        Utils.reverse8(curSection);
131
        Utils.append8(curSection, "_roloc");
132
        Utils.reverse8(curSection)
133
    ELSE
134
        curSection := ""
135
    END;
136
 
137
    text     := getColor("text",     0000000H);
138
    back     := getColor("back",     0FFFFFFH);
139
    seltext  := getColor("seltext",  0FFFFFFH);
140
    selback  := getColor("selback",  00000FFH);
141
    modified := getColor("modified", 0E8E800H);
142
    saved    := getColor("saved",    000D000H);
143
    curline  := getColor("curline",  0FFFFC8H);
144
    numtext  := getColor("numtext",  0000000H);
145
    numback  := getColor("numback",  0E6E6E6H);
146
 
147
    comment  := getColor("comment",  0800080H);
148
    string   := getColor("string",   0008000H);
149
    num      := getColor("num",      0800000H);
150
    delim    := getColor("delim",    0000080H);
151
    key1     := getColor("key1",     0000080H);
152
    key2     := getColor("key2",     0008080H);
153
    key3     := getColor("key3",     0008080H);
9413 akron1 154
    escape   := getColor("escape",   string);
8728 leency 155
 
156
    Text.setColors(text, back, seltext, selback, modified, saved, curline, numtext, numback,
9413 akron1 157
        comment, string, escape, num, delim, key1, key2, key3);
8728 leency 158
END selectSection;
159
 
160
 
9671 akron1 161
PROCEDURE getSettings*;
9174 akron1 162
BEGIN
163
	Lines.setTabs(get_int(IniFileName, "settings", "tab", 4));
164
	blink := get_int(IniFileName, "settings", "blink", 70);
9671 akron1 165
	lineNumbers  := get_int(IniFileName, "settings", "line_numbers",  1) # 0;
166
	autoIndents  := get_int(IniFileName, "settings", "auto_indents",  1) # 0;
167
	autoBrackets := get_int(IniFileName, "settings", "auto_brackets", 0) # 0;
168
	trimSpace    := get_int(IniFileName, "settings", "trim_space",    1) # 0;
169
	font := get_int(IniFileName, "settings", "font", 1);
170
	IF ~((0 <= font) & (font <= 2)) THEN
171
		font := 1
172
	END;
173
	theme := get_int(IniFileName, "settings", "theme", 0);
174
	IF ~((0 <= theme) & (theme <= sections.count - 1)) THEN
175
		theme := 0
176
	END;
177
    getStr("settings", "build", buildScript);
178
    getStr("settings", "run",   runScript);
179
    getStr("settings", "debug", debugScript);
9174 akron1 180
END getSettings;
181
 
182
 
8728 leency 183
PROCEDURE load* (path: RW.tFileName);
184
BEGIN
185
    sections := List.create(NIL);
9174 akron1 186
 
187
    Utils.getPath(path, IniFileName);
188
    Utils.append8(IniFileName, Utils.SLASH);
189
    Utils.append8(IniFileName, fileName);
190
 
191
    IF ~File.Exists(IniFileName) THEN
9671 akron1 192
    	IniFileName := "/sys/settings/" + fileName
8728 leency 193
    END;
194
 
195
    enum_sections(IniFileName, SYSTEM.ADR(section_callback));
196
    Languages.init(getStr);
9671 akron1 197
    selectSection(theme);
8728 leency 198
END load;
199
 
200
 
201
END Ini.