(* GLOBAL.PAS -- global definitions ** Copyright (c) 1995,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 global; INTERFACE CONST FileMode_RO = 0; (* FileMode values *) FileMode_WO = 1; FileMode_RW = 2; (* default *) FUNCTION AddExt(path: STRING; ext: STRING): STRING; (* return complete PATH (with EXT) *) FUNCTION GetFileName(path: STRING): STRING; (* return file name w/o path, extension *) FUNCTION GetString(VAR m; sz: BYTE): STRING; (* return M[0..SZ-1] *) PROCEDURE PutString(VAR m; str: STRING); (* M[0..LENGTH(STR)-1] := STR *) FUNCTION long2str(l: LongInt; w: ShortInt): STRING; (* = Str(l,w), for w < 0 fill with 0s *) FUNCTION real2str(r: REAL; w, d: BYTE): STRING; (* = Str(r,w,d) *) FUNCTION HexStr(val: LongInt; min_width: BYTE): STRING; (* Str for hexedecimal *) IMPLEMENTATION USES Dos; FUNCTION AddExt(path: STRING; ext: STRING): STRING; VAR D: DirStr; N: NameStr; E: ExtStr; BEGIN FSplit(path, D, N, E); IF E = '' THEN E := ext; AddExt := D + N + E; END; (* AddExt *) FUNCTION GetFileName(path: STRING): STRING; VAR D: DirStr; N: NameStr; E: ExtStr; BEGIN FSplit(path, D, N, E); GetFileName := N; END; (* GetFileName *) FUNCTION GetString(VAR m; sz: BYTE): STRING; VAR s: STRING; BEGIN s[0] := CHAR(sz); Move(m, s[1], sz); GetString := s; END; (* GetString *) PROCEDURE PutString(VAR m; str: STRING); BEGIN Move(str[1], m, Length(str)); END; (* PutString *) FUNCTION long2str(l: LongInt; w: ShortInt): STRING; VAR s: STRING; i: BYTE; BEGIN Str(l:ABS(w), s); IF w < 0 THEN BEGIN FOR i := 1 TO Length(s) DO IF (s[i] = ' ') OR (s[i] = '-') THEN s[i] := '0'; IF l < 0 THEN s[1] := '-'; END; (* if *) long2str := s; END; (* long2str *) FUNCTION real2str(r: REAL; w, d: BYTE): STRING; VAR s: STRING; BEGIN Str(r:w:d, s); real2str := s; END; (* real2str *) FUNCTION HexStr(val: LongInt; min_width: BYTE): STRING; CONST hdigit : ARRAY [0..15] OF CHAR = '0123456789ABCDEF'; VAR result: STRING; BEGIN result := ''; WHILE val <> 0 DO BEGIN result := hdigit[val AND $F] + result; val := (val AND NOT $F) SHR 4; END; WHILE Length(result) < min_width DO result := '0' + result; HexStr := result; END; (* HexStr *) END. (* global *)