(* CFG.PAS -- access configuration files for cvt2xxx ** Copyright (c) 1996 Jochen Metzinger ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2, or (at your option) ** any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *) UNIT cfg; INTERFACE USES DOS, global, errors; PROCEDURE cfg_open; (* open configuration file *) PROCEDURE cfg_close; (* close configuration file *) FUNCTION cfg_line(VAR gtype: INTEGER; VAR class, jobs: STRING): BOOLEAN; (* get next line *) IMPLEMENTATION CONST GeosTypeName: ARRAY [0..15] OF STRING[4] = ('C=64', 'BAS', 'ASM', 'DATA', 'SYS', 'HELP', 'APPL', 'DOC', 'FONT', 'PRT', 'IN', 'DISK', 'STRT', 'TMP', 'SELF', 'MOUS'); VAR cfg_file: TEXT; lno: LongInt; PROCEDURE cfg_open; VAR D: DirStr; N: NameStr; E: ExtStr; BEGIN lno := 0; FSplit(ParamStr(0), D, N, E); IF N = 'TURBO' THEN N := 'CVT2XXX'; (*$I-*) FileMode := FileMode_RO; Assign(cfg_file, N + '.CFG'); Reset(cfg_file); IF IOResult <> 0 THEN BEGIN Assign(cfg_file, D + N + '.CFG'); Reset(cfg_file); IF IOResult <> 0 THEN FATAL('unable to open configuration file'); END; (* if *) FileMode := FileMode_RW; (*$I+*) END; (* cfg_open *) PROCEDURE cfg_close; BEGIN Close(cfg_file); END; (* cfg_close *) FUNCTION cfg_line(VAR gtype: INTEGER; VAR class, jobs: STRING): BOOLEAN; VAR line, geos_name: STRING; i, p: BYTE; BEGIN cfg_line := TRUE; gtype := -1; class := ''; jobs := ''; WHILE NOT EoF(cfg_file) DO BEGIN (* read line *) ReadLn(cfg_file, line); INC(lno); (* spaces *) WHILE Copy(line,1,1) = ' ' DO Delete(line,1,1); IF (line <> '') AND (Copy(line,1,1) <> '#') THEN BEGIN (* geos type *) p := Pos(' ',line); IF p < 1 THEN p := $FF; i := Pos('"',line); IF i < 1 THEN i := $FF; IF i < p THEN p := i; geos_name := Copy(line,1,p-1); Delete(line,1,p-1); IF geos_name = '*' THEN gtype := -1 ELSE BEGIN FOR i := 1 TO Length(geos_name) DO geos_name[i] := Upcase(geos_name[i]); gtype := -2; FOR i := 0 TO 15 DO IF GeosTypeName[i] = geos_name THEN gtype := i; IF gtype < 0 THEN FATAL('unknown geos type at line '+long2str(lno,0)); END; (* else *) (* remove spaces *) WHILE Copy(line,1,1) = ' ' DO Delete(line,1,1); (* "" *) IF Copy(line,1,1) <> '"' THEN FATAL('bad class definition at line '+long2str(lno,0)); Delete(line,1,1); p := Pos('"',line); IF p < 1 THEN FATAL('no closing quotes at line '+long2str(lno,0)); class := Copy(line,1,p-1); Delete(line,1,p); (* remove spaces *) WHILE Copy(line,1,1) = ' ' DO Delete(line,1,1); jobs := line; EXIT; END; (* if *) END; (* while *) cfg_line := FALSE; END; (* cfg_line *) END. (* cfg *)