Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
8728 leency 1
(*
2
    Copyright 2021 Anton Krotov
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
 
8762 leency 24
    KOSAPI, SYSTEM, RW, Text, Utils, File, List, Languages, KolibriOS;
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
    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;
51
    enum_sections: PROCEDURE [stdcall] (f_name: RW.tFileName; callback: INTEGER);
52
 
53
    IniFileName: RW.tFileName;
54
    sections*: List.tList;
55
 
56
    curSection*: tASCIISectionName;
57
    curSectionNum*: INTEGER;
58
 
59
 
60
PROCEDURE getColor (key: tString; def: INTEGER): INTEGER;
61
    RETURN get_color(IniFileName, curSection, key, def)
62
END getColor;
63
 
64
 
65
PROCEDURE getStr* (secName, keyName: ARRAY OF CHAR; VAR s: ARRAY OF CHAR);
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
68
        s[0] := 0X
69
    END
70
END getStr;
71
 
72
 
73
PROCEDURE [stdcall] section_callback (fileName, sectionName: RW.tFileName): INTEGER;
74
VAR
75
    section: tSection;
76
    name: tSectionName;
77
    i: INTEGER;
78
BEGIN
79
    IF sections.count < MAX_SECTIONS THEN
80
        i := 0;
81
        WHILE (i < MAX_LEN - 1) & (sectionName[i] # 0X) DO
82
            name[i] := WCHR(ORD(sectionName[i]));
83
            INC(i)
84
        END;
85
        name[i] := 0X
86
    END;
87
    IF Utils.streq(SYSTEM.ADR(name[0]), SYSTEM.WSADR("color_"), 6) THEN
88
        Utils.reverse(name);
89
        name[LENGTH(name) - 6] := 0X;
90
        Utils.reverse(name);
91
        NEW(section);
92
        section.name := name;
93
        List.append(sections, section)
94
    END
95
    RETURN 1
96
END section_callback;
97
 
98
 
99
PROCEDURE selectSection* (idx: INTEGER);
100
VAR
101
    i: INTEGER;
102
    item: List.tItem;
103
    section: tSection;
104
 
105
    text, back, seltext, selback, modified, saved, curline, numtext, numback,
106
    comment, string, num, delim, key1, key2, key3: INTEGER;
107
BEGIN
108
    IF (0 <= idx) & (idx < sections.count) THEN
109
        curSectionNum := idx;
110
        item := List.getItem(sections, idx);
111
        section := item(tSection);
112
        i := 0;
113
        WHILE section.name[i] # 0X DO
114
            curSection[i] := CHR(ORD(section.name[i]));
115
            INC(i)
116
        END;
117
        curSection[i] := 0X;
118
        Utils.reverse8(curSection);
119
        Utils.append8(curSection, "_roloc");
120
        Utils.reverse8(curSection)
121
    ELSE
122
        curSection := ""
123
    END;
124
 
125
    text     := getColor("text",     0000000H);
126
    back     := getColor("back",     0FFFFFFH);
127
    seltext  := getColor("seltext",  0FFFFFFH);
128
    selback  := getColor("selback",  00000FFH);
129
    modified := getColor("modified", 0E8E800H);
130
    saved    := getColor("saved",    000D000H);
131
    curline  := getColor("curline",  0FFFFC8H);
132
    numtext  := getColor("numtext",  0000000H);
133
    numback  := getColor("numback",  0E6E6E6H);
134
 
135
    comment  := getColor("comment",  0800080H);
136
    string   := getColor("string",   0008000H);
137
    num      := getColor("num",      0800000H);
138
    delim    := getColor("delim",    0000080H);
139
    key1     := getColor("key1",     0000080H);
140
    key2     := getColor("key2",     0008080H);
141
    key3     := getColor("key3",     0008080H);
142
 
143
    Text.setColors(text, back, seltext, selback, modified, saved, curline, numtext, numback,
8762 leency 144
        comment, string, num, delim, key1, key2, key3);
8728 leency 145
END selectSection;
146
 
147
 
148
PROCEDURE load* (path: RW.tFileName);
149
VAR
150
    Lib: INTEGER;
151
 
152
    PROCEDURE GetProc(Lib, v: INTEGER; name: ARRAY OF CHAR);
153
    VAR
154
        a: INTEGER;
155
    BEGIN
156
        a := KOSAPI.GetProcAdr(name, Lib);
157
        ASSERT(a # 0);
158
        SYSTEM.PUT(v, a)
159
    END GetProc;
160
 
161
BEGIN
162
    sections := List.create(NIL);
163
    IF File.Exists("/rd/1/settings/cedit.ini") THEN
164
        IniFileName := "/rd/1/settings/cedit.ini"
165
    ELSE
166
        Utils.getPath(path, IniFileName);
167
        Utils.append8(IniFileName, Utils.SLASH);
168
        Utils.append8(IniFileName, fileName);
169
    END;
170
 
171
    Lib := KOSAPI.LoadLib("/rd/1/Lib/Libini.obj");
172
    GetProc(Lib, SYSTEM.ADR(get_color), "ini_get_color");
173
    GetProc(Lib, SYSTEM.ADR(get_str), "ini_get_str");
174
    GetProc(Lib, SYSTEM.ADR(enum_sections), "ini_enum_sections");
175
 
176
    enum_sections(IniFileName, SYSTEM.ADR(section_callback));
177
    Languages.init(getStr);
178
    selectSection(0);
179
END load;
180
 
181
 
182
END Ini.