Subversion Repositories Kolibri OS

Rev

Rev 9599 | Rev 9671 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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