Category : Pascal Source Code
Archive   : USNGTP.ZIP
Filename : STD-UTIL.INC

 
Output of file : STD-UTIL.INC contained in archive : USNGTP.ZIP


{ STD-UTIL.INC Miscelaneous global subprograms }

{ Forward declaration of error handling routines which use some of the
routines in the STD-UTIL.INC file and are also used by some of these
routines. The formal definition of these forward declared procedures
is in the STD-DISP.INC Include file, which must be included at some
point following STD-UTIL.INC. }

procedure Disp_IO_Error(device_name: File_ID); forward;

procedure Disp_Error_Msg(err_msg: Str_80); forward;

procedure Beep;
begin
Write(BELL); { Use this statement for non-IBM-PC systems. }
(* begin { This routine may be substituted on IBM-PC systems. }
Sound(440); Delay(250); NoSound;
end; *)
end; { Beep }

procedure Repeat_Char(character : Char; { Character to be output. }
count : Integer); { Number of times to output. }
var i : Integer;

begin
io_status := ZERO;
i := ZERO;
{$I-}
while (io_status = ZERO) and (i < count) do
begin
Write(character);
io_status := IOresult;
i := Succ(i);
end;
{$I+}
if (io_status <> ZERO) then
Disp_IO_Error(output_id);
end; { Repeat_Char }

procedure Strip_Trailing_Char(var inp_str : Str_255; { String to strip.}
len : Byte; { Maximum length. }
strip : Char); { Char. to strip. }

{ Scan inp_str from len downto 0 until a character <> strip is found.
Set the length of inp_str equal to the position of the character
found if any. Note that inp_str is set to null if it contains only
strip characters. }

begin
inp_str[0] := Chr(0); { Set inp_str length byte to ZERO. }
while (inp_str[len] = strip) and (len > ZERO) do
len := Pred(len);
inp_str[0] := Chr(len); { Set inp_str length to len. }
end; { Strip_Trailing_Char }

{ Alternate implementation. See disscussion of Stripped. }

(* function Trailing_Stripped(inp_str : Str_255;
len : Byte;
strip : Char): Str_255;
begin
inp_str[0] := Chr(0); { Set inp_str length to ZERO }
while (inp_str[len] = strip) and (len > ZERO) do
len := Pred(len);
inp_str[0] := Chr(len); { Set inp_str length to len }
Trailing_Stripped := inp_str;
end; { Trailing_Stripped }
*)

procedure Strip_Leading_Char(var inp_str : Str_255; { String to strip. }
len : Byte; { Maximum length. }
strip : Char); { Char. to strip. }

var i : Byte;

{ Find the first occurrence, if any, of a character not equal to strip.
Copy the remainder of inp_str into the new inp_str. Note inp_str is set
to null if it is null initially or it contains only strip characters. }

begin
i := 1;
While (inp_str[i] = strip) and (i <= len) do
i := Succ(i);
inp_str := Copy(inp_str,i,len);
end; { Strip_Leading_Char }

{ Alternate implementation. See discussion of Stripped. }
(*
function Leading_Stripped(inp_str : Str_255;
len : Byte;
strip : Char): Str_255;
var i : Byte;

begin
i := 1;
While (inp_str[i] = strip) and (i <= len) do
i := Succ(i);
inp_str := Copy(inp_str,i,len);
Leading_Stripped := inp_str;
end; { Leading_Stripped }
*)

function Stripped(var inp_str : Str_255; { String to strip. }
len : Byte; { Maximum length. }
strip : Char): Str_255; { Char. to strip. }

{ Uses procedures defined in Listing 8-8 and 8-9 to strip leading
and trailing occurances of the character strip from inp_str. }

begin
Strip_Trailing_Char(inp_str,len,strip);
Strip_Leading_Char(inp_str,len,strip);
Stripped := inp_str;
end; { Stripped }

(* Alternate version of Stripped using alternate functions defined in
Listing 8-8 and 8-9. See text for explanation.

begin
inp_str := Trailing_Stripped(inp_str,len,strip);
Stripped := Leading_Stripped(inp_str,len,strip);
end; { Stripped }
*)

function Exist(file_name: File_ID): Boolean;
var chk_file : File;

begin
Assign(chk_file,file_name);
{$I-} Reset(chk_file); {$I+}
Exist := (IOresult = ZERO);
Close(chk_file);
end; { Exist }