MODULE UTILITIES;

(* USE AS FOLLOWS:
	FUNCTION  RENAME(F,NEWNAME); MUST BE PRECEEDED BY ASSIGN
	PROCEDURE EXTRACT(F,NAME);   RETURNS NAME FROM AN FILE
	FUNCTION  KEYPRESSED : BOOLEAN; TRUE IF KEY PRESSED
*)

(*$I FIBDEF.LIB*)

EXTERNAL FUNCTION @BDOS(FUNC,PARM:INTEGER):INTEGER;

FUNCTION RENAME(VAR F:FIB; VAR NEWNAME:STRING):INTEGER;

(* TO USE:

	ASSIGN(MYFILE,OLDNAME);
	IF RENAME(MYFILE,NEWNAME) = 255 THEN
	  OLDNAME NOT FOUND IN DIRECTORY
	ELSE
	  RENAME WAS SUCCESSFUL

*)
VAR
  TEMPFILE : RECORD
		CASE BOOLEAN OF
		TRUE: (FYLE:FILE);
		FALSE:(FIBB:FIB)
	     END;
  RESULT:INTEGER;
BEGIN
  ASSIGN(TEMPFILE.FYLE,NEWNAME);
  MOVE(TEMPFILE.FIBB.FCB,TEMPFILE.FIBB.FCB[16],12);
  MOVE(F.FCB,TEMPFILE.FIBB.FCB,12);
  RESULT := @BDOS(23,ADDR(TEMPFILE.FIBB.FCB));
  RENAME := RESULT
END;


PROCEDURE EXTRACT(VAR F:FIB; VAR OUTNAME : STRING);
BEGIN
  OUTNAME := F.FNAME
END;


FUNCTION KEYPRESSED:BOOLEAN;
BEGIN
  KEYPRESSED := (@BDOS(11,0) <> 0)
END;

MODEND.
