1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE a_modes.inc}
21 function config_open(FileName
: string): Boolean;
22 function config_read_int(param
: string; def
: Integer): Integer;
23 function config_read_str(param
: string; def
: string): string;
24 function config_read_bool(param
: string; def
: Boolean): Boolean;
25 procedure config_close();
32 cfg_data
: array of ShortString = nil;
34 function tostr(i
: Integer): string;
39 function toint(s
: string; var i
: Integer): Boolean;
48 function readparam(param
: string; var s
: string): Boolean;
50 a
, b
, len
, d_len
: Integer;
54 if cfg_data
= nil then Exit
;
56 d_len
:= Length(cfg_data
);
58 for a
:= 0 to d_len
do
60 len
:= Length(cfg_data
[a
]);
64 if cfg_data
[a
][b
] = '=' then
65 if Copy(cfg_data
[a
], 1, b
-1) = param
then
67 s
:= Copy(cfg_data
[a
], b
+1, len
);
74 function config_open(FileName
: string): Boolean;
78 len
, d_len
, line
: Integer;
82 if cfg_data
<> nil then config_close();
84 AssignFile(f
, FileName
);
90 if IOResult
<> 0 then Exit
;
93 SetLength(cfg_data
, d_len
);
101 if len
< 3 then Continue
;
102 if str
[1] = ';' then Continue
;
104 if line
>= d_len
then
107 SetLength(cfg_data
, d_len
);
110 cfg_data
[line
] := str
;
119 function config_read_int(param
: string; def
: Integer): Integer;
125 if not readparam(param
, s
) then Exit
;
127 if not toint(s
, Result
) then Result
:= def
;
130 function config_read_str(param
: string; def
: string): string;
136 if not readparam(param
, s
) then Exit
;
141 function config_read_bool(param
: string; def
: Boolean): Boolean;
147 if not readparam(param
, s
) then Exit
;
152 procedure config_close();
154 if cfg_data
<> nil then cfg_data
:= nil;