include "scanfile.s7i";
const type: iniKeyValueType is hash [string] string;
const type: iniDataType is hash [string] iniKeyValueType;
const func string: getParamValue (in iniDataType: iniData,
in string: sectionName, in string: propertyName) is func
result
var string: propertyValue is "";
begin
if sectionName in iniData then
if propertyName in iniData[sectionName] then
propertyValue := iniData[sectionName][propertyName];
end if;
end if;
end func;
const proc: getKeyValuePair (inout file: inFile,
inout string: propertyName, inout string: propertyValue) is func
begin
skipWhiteSpace(inFile);
propertyName := getName(inFile);
skipWhiteSpace(inFile);
if inFile.bufferChar = '=' then
inFile.bufferChar := getc(inFile);
propertyValue := getLine(inFile);
else
propertyValue := "";
skipLine(inFile);
end if;
end func;
const func string: getIniSection (inout file: inFile) is func
result
var string: symbol is "";
begin
repeat
inFile.bufferChar := getc(inFile);
until inFile.bufferChar not in space_or_tab;
while inFile.bufferChar <> ']' and inFile.bufferChar <> '\n' and inFile.bufferChar <> EOF do
symbol &:= str(inFile.bufferChar);
inFile.bufferChar := getc(inFile);
end while;
symbol := trim(symbol);
end func;
const func iniDataType: readIniFile (inout file: inFile) is func
result
var iniDataType: iniData is iniDataType.value;
local
var string: sectionName is "";
var string: propertyName is "";
var string: propertyValue is "";
begin
inFile.bufferChar := getc(inFile);
while inFile.bufferChar <> EOF do
skipWhiteSpace(inFile);
if inFile.bufferChar = '[' then
sectionName := getIniSection(inFile);
skipLine(inFile);
elsif inFile.bufferChar = ';' then
skipLineComment(inFile);
elsif inFile.bufferChar <> EOF then
getKeyValuePair(inFile, propertyName, propertyValue);
if sectionName not in iniData then
iniData @:= [sectionName] iniKeyValueType.value;
end if;
iniData[sectionName] @:= [propertyName] propertyValue;
end if;
end while;
end func;
const func iniDataType: readIniFile (in string: fileName) is func
result
var iniDataType: iniData is iniDataType.value;
local
var file: inFile is STD_NULL;
begin
inFile := open(fileName, "r");
if inFile <> STD_NULL then
iniData := readIniFile(inFile);
close(inFile);
end if;
end func;