The following listing contains the interface of the GPCUtil unit.
This unit provides some utility routines for compatibility to some units available for BP, like some Turbo Power units.
{ Some utility routines for compatibility to some units available
for BP, like some Turbo Power units.
@@NOTE - SOME OF THE ROUTINES IN THIS UNIT MAY NOT WORK CORRECTLY.
TEST CAREFULLY AND USE WITH CARE!
Copyright (C) 1998-2005 Free Software Foundation, Inc.
Authors: Prof. Abimbola A. Olowofoyeku <African_Chief@bigfoot.com>
Frank Heckenbach <frank@pascal.gnu.de>
This file is part of GNU Pascal.
GNU Pascal 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.
GNU Pascal 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 GNU Pascal; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
As a special exception, if you link this file with files compiled
with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public
License. This exception does not however invalidate any other
reasons why the executable file might be covered by the GNU
General Public License. }
{$gnu-pascal,I-}
{$if __GPC_RELEASE__ < 20030412}
{$error This unit requires GPC release 20030412 or newer.}
{$endif}
module GPCUtil;
export GPCUtil = all
(
{ Return the current working directory }
GetCurrentDirectory => ThisDirectory,
{ Does a directory exist? }
DirectoryExists => IsDirectory,
{ Does file name s exist? }
FileExists => ExistFile,
{ Return just the directory path of Path. Returns
DirSelf + DirSeparator if Path contains no directory. }
DirFromPath => JustPathName,
{ Return just the file name part without extension of Path.
Empty if Path contains no file name. }
NameFromPath => JustFileName,
{ Return just the extension of Path. Empty if Path contains
no extension. }
ExtFromPath => JustExtension,
{ Return the full pathname of Path }
FExpand => FullPathName,
{ Add a DirSeparator to the end of s if there is not
already one. }
ForceAddDirSeparator => AddBackSlash,
{ Return a string stripped of leading spaces }
TrimLeftStr => TrimLead,
{ Return a string stripped of trailing spaces }
TrimRightStr => TrimTrail,
{ Return a string stripped of leading and trailing spaces }
TrimBothStr => Trim,
{ Convert a string to lowercase }
LoCaseStr => StLoCase,
{ Convert a string to uppercase }
UpCaseStr => StUpCase
);
import GPC;
{ Replace all occurences of OldC with NewC in s and return the
result }
function ReplaceChar (const s: String; OldC, NewC: Char) = Res:
TString;
{ Break a string into 2 parts, using Ch as a marker }
function BreakStr (const Src: String; var Dest1, Dest2: String; ch:
Char): Boolean; attribute (ignorable);
{ Convert a CString to an Integer }
function PChar2Int (s: CString) = i: Integer;
{ Convert a CString to a LongInt }
function PChar2Long (s: CString) = i: LongInt;
{ Convert a CString to a Double }
function PChar2Double (s: CString) = x: Double;
{ Search for s as an executable in the path and return its location
(full pathname) }
function PathLocate (const s: String): TString;
{ Copy file Src to Dest and return the number of bytes written }
function CopyFile (const Src, Dest: String; BufSize: Integer):
LongInt; attribute (ignorable);
{ Copy file Src to Dest and return the number of bytes written;
report the number of bytes written versus total size of the source
file }
function CopyFileEx (const Src, Dest: String; BufSize: Integer;
function Report (Reached, Total: LongInt): LongInt) = BytesCopied:
LongInt; attribute (ignorable);
{ Turbo Power compatibility }
{ Execute the program prog. Dummy1 and Dummy2 are for compatibility
only; they are ignored. }
function ExecDos (const Prog: String; Dummy1: Boolean; Dummy2:
Pointer): Integer; attribute (ignorable);
{ Return whether Src exists in the path as an executable -- if so
return its full location in Dest }
function ExistOnPath (const Src: String; var Dest: String) =
Existing: Boolean;
{ Change the extension of s to Ext (do not include the dot!) }
function ForceExtension (const s, Ext: String) = Res: TString;
{ Convert Integer to PChar; uses NewCString to allocate memory for
the result, so you must call StrDispose to free the memory later }
function Int2PChar (i: Integer): PChar;
{ Convert Integer to string }
function Int2Str (i: Integer) = s: TString;
{ Convert string to Integer }
function Str2Int (const s: String; var i: Integer): Boolean;
attribute (ignorable);
{ Convert string to LongInt }
function Str2Long (const s: String; var i: LongInt): Boolean;
attribute (ignorable);
{ Convert string to Double }
function Str2Real (const s: String; var i: Double): Boolean;
attribute (ignorable);
{ Return a string right-padded to length Len with ch }
function PadCh (const s: String; ch: Char; Len: Integer) = Padded:
TString;
{ Return a string right-padded to length Len with spaces }
function Pad (const s: String; Len: Integer): TString;
{ Return a string left-padded to length Len with ch }
function LeftPadCh (const s: String; ch: Char; Len: Byte) = Padded:
TString;
{ Return a string left-padded to length Len with blanks }
function LeftPad (const s: String; Len: Integer): TString;
{ Uniform access to big memory blocks for GPC and BP. Of course, for
programs that are meant only for GPC, you can use the usual
New/Dispose routines. But for programs that should compile with
GPC and BP, you can use the following routines for GPC. In the GPC
unit for BP (gpc-bp.pas), you can find emulations for BP that try
to provide access to as much memory as possible, despite the
limitations of BP. The drawback is that this memory cannot be used
freely, but only with the following moving routines. }
type
PBigMem = ^TBigMem;
TBigMem (MaxNumber: SizeType) = record
{ Public fields }
Number, BlockSize: SizeType;
Mappable: Boolean;
{ Private fields }
Pointers: array [1 .. Max (1, MaxNumber)] of ^Byte
end;
{ Note: the number of blocks actually allocated may be smaller than
WantedNumber. Check the Number field of the result. }
function AllocateBigMem (WantedNumber, aBlockSize: SizeType;
WantMappable: Boolean) = p: PBigMem;
procedure DisposeBigMem (p: PBigMem);
procedure MoveToBigMem (var Source; p: PBigMem; BlockNumber:
SizeType);
procedure MoveFromBigMem (p: PBigMem; BlockNumber: SizeType; var
Dest);
{ Maps a big memory block into normal addressable memory and returns
its address. The memory must have been allocated with
WantMappable = True. The mapping is only valid until the next
MapBigMem call. }
function MapBigMem (p: PBigMem; BlockNumber: SizeType): Pointer;