unit iz_cfg;

interface
uses
  Windows, iz_gfx, iz_types, iz_utils;

type
 izTextFile = record
   f : TextFile;
 end;

var
  zTextFite : izTextFile;

function Cfg_ReadInt(FileName, Ident : string; Default: int) : int;
function Cfg_ReadStr(FileName, Ident, Default : string) : string;
function Scr_Read_Str(Ident, Default : string) : string;
function Scr_Read_Int(Ident : string; Default: int) : int;
function Scr_Read_Open(FileName : string) : bool;
function Scr_Read_Close() : bool;

implementation

function Cfg_ReadInt(FileName, Ident : string; Default: int) : int;
begin
  Result := StrToInt(Cfg_ReadStr(FileName, Ident, IntToStr(Default)));
end;

function Cfg_ReadStr(FileName, Ident, Default : string) : string;
var
  f : TextFile;
  buf : string;
  com : string;
begin
  Result := '';
  AssignFile(f, FileName);
  Reset(f);
  while not EOF(f) do
  begin
    ReadLn(f, buf);
    com := SplitString('=', buf);
    if com = Ident then
    begin
      Result := buf;
      break;
    end;
  end;
  CloseFile(f);
  if Result = '' then
    Result := Default;
end;

function Scr_Read_Open(FileName : string) : bool;
begin
  Result := false;
  AssignFile(zTextFite.f,FileName);
  Reset(zTextFite.f);
  Result := true;
end;

function Scr_Read_Str(Ident, Default : string) : string;
var
  buf,com : string;
begin
  Result := Default;
  Reset(zTextFite.f);
  //Seek(0);
  while not EOF(zTextFite.f) do
  begin
    ReadLn(zTextFite.f, buf);
    com := SplitString('=', buf);
    if com = Ident then
    begin
      Result := buf;
      break;
    end;
  end;
end;

function Scr_Read_Int(Ident : string; Default : int) : int;
begin
  Result := StrToInt(Scr_Read_Str(Ident, IntToStr(Default)));
end;

function Scr_Read_Close() : bool;
begin
  CloseFile(zTextFite.f);
end;

end.
