Subversion Repositories Kolibri OS

Rev

Rev 8728 | Rev 9174 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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