ðïSyntax10.Scn.FntaSyntax10b.Scn.Fnt  BP-Syntax10i.Scn.Fnt1@#‡ a1 MODULE Registry; (* MH 27.1.93 *) (* The registry provides a consistent interface for programs to store configuration data. The data is organized in a two-level hierarchy. The first level is called "section", the second level is called "key". The registry serves to associate a value with a (section, key) pair. *) IMPORT S := SYSTEM, Kernel; CONST Done* = 0; RegistryNotFound* = 1; NotFound* = 2; TYPE EntryHandler* = PROCEDURE (key, value: ARRAY OF CHAR); LPSZ = LONGINT; VAR res-: INTEGER; Inifile: ARRAY 128 OF CHAR; GetPrivProfileString: PROCEDURE (section, key, default, buf: LPSZ; buflen: LONGINT; inifile: LPSZ): LONGINT; WritePrivProfileString: PROCEDURE (section, key, string, inifile: LPSZ): LONGINT; PROCEDURE QueryValue (VAR section, key: ARRAY OF CHAR; VAR value: ARRAY OF CHAR); VAR r, len: LONGINT; default: ARRAY 8 OF CHAR; BEGIN len := LEN(value); default := "@#$%"; r := GetPrivProfileString(S.ADR(section), S.ADR(key), S.ADR(default), S.ADR(value), len, S.ADR(Inifile)); IF value = default THEN res := NotFound END ; END QueryValue; PROCEDURE Set* (section, key, value: ARRAY OF CHAR); (** associates a value to a (section, key) pair **) VAR r: LONGINT; val: LONGINT; BEGIN res := Done; IF value = "" THEN val := 0 ELSE val := S.ADR(value) END ; IF Inifile # "" THEN IF WritePrivProfileString(S.ADR(section), S.ADR(key), val, S.ADR(Inifile)) = 0 THEN res := NotFound; END ELSE res := RegistryNotFound END END Set; PROCEDURE Get* (section, key: ARRAY OF CHAR; VAR value: ARRAY OF CHAR); (** retrieves the value associated to a (section, key) pair **) BEGIN res := Done; IF Inifile # "" THEN QueryValue(section, key, value); ELSE res := RegistryNotFound END END Get; PROCEDURE Enumerate* (section: ARRAY OF CHAR; handler: EntryHandler); CONST bufLen = 1024; VAR buf: ARRAY bufLen OF CHAR; default: ARRAY 8 OF CHAR; key, value: ARRAY 64 OF CHAR; i, j: INTEGER; r: LONGINT; BEGIN res := Done; default := "@#$%"; IF Inifile # "" THEN r := GetPrivProfileString(S.ADR(section), 0, S.ADR(default), S.ADR(buf), bufLen, S.ADR(Inifile)); IF buf # default THEN i := 0; WHILE buf[i] # 0X DO j := 0; WHILE buf[i] # 0X DO key[j] := buf[i]; INC(i); INC(j) END ; key[j] := 0X; INC(i); Get(section, key, value); IF res = Done THEN handler(key, value) END ; END ELSE res := NotFound END ELSE res := RegistryNotFound END END Enumerate; PROCEDURE Init; VAR mod: LONGINT; InifilePtr: POINTER TO RECORD name: ARRAY 128 OF CHAR END ; BEGIN mod := Kernel.LoadLibrary("Kernel32"); Kernel.GetAdr(mod, "WritePrivateProfileStringA", S.VAL(LONGINT, WritePrivProfileString)); Kernel.GetAdr(mod, "GetPrivateProfileStringA", S.VAL(LONGINT, GetPrivProfileString)); Kernel.GetAdr(0, "Inifile", S.VAL(LONGINT, InifilePtr)); COPY(InifilePtr.name, Inifile); END Init; BEGIN Init; END Registry.