IMPLEMENTATION MODULE ReqTools;

(*
**	$Filename: libraries/reqtools.h $
**	$Release: 1.0 $
**
**	(C) Copyright 1991 Nico François
**	    All Rights Reserved
*)

FROM SYSTEM    IMPORT ADR, ADDRESS, STRPTR, TERMPROC;
FROM Libraries IMPORT LibraryPtr, OpenLibrary, CloseLibrary;
FROM Strings   IMPORT AssignStr;
FROM TagItem   IMPORT TagItemPtr;
FROM Tasks     IMPORT SignalSet;


PROCEDURE CloseReqLib;
BEGIN
  IF ReqToolsBase # NIL THEN
    CloseLibrary(LibraryPtr(ReqToolsBase));
  END;
END CloseReqLib;


PROCEDURE OpenReqToolsLib() : BOOLEAN;
(* Open the Requester Tools Library and return TRUE if successful. *)
VAR
  LibPtr : LibraryPtr;
BEGIN
  IF ReqToolsBase = NIL THEN
    LibPtr := OpenLibrary(ADR(ReqToolsName),ReqToolsVersion);
    ReqToolsBase := ReqToolsBaseRecPtr(LibPtr);
    RETURN (ReqToolsBase # NIL);
  END;
  RETURN FALSE;
END OpenReqToolsLib;


PROCEDURE AllocRequest(type : LONGINT) : ADDRESS;
BEGIN
  RETURN AllocRequestA(type, NIL);
END AllocRequest;


PROCEDURE ChangeReqAttr(req : ADDRESS) : LONGINT;
BEGIN
  RETURN ChangeReqAttrA(req, NIL);
END ChangeReqAttr;


(*$S+*)
PROCEDURE FileRequest(filereq : rtFileRequesterPtr;
                      VAR filename : ARRAY OF CHAR;
                      VAR directory : ARRAY OF CHAR;
                      title : ARRAY OF CHAR) : BOOLEAN;
BEGIN
  IF FileRequestA(filereq, filename, ADR(title), NIL) THEN
    AssignStr(directory, filereq^.Dir^);  (* CAUTION make sure AssignStr
                                             doesn't copy 65000 chars on
                                             stack *)
    RETURN TRUE;
  END;
  RETURN FALSE;
END FileRequest;


(*$S+*)
PROCEDURE EZRequest(bodyfmt : ARRAY OF CHAR; gadfmt : ARRAY OF CHAR;
                    reqinfo : rtReqInfoPtr; argarray : ADDRESS) : LONGINT;
BEGIN
  RETURN EZRequestA(ADR(bodyfmt), ADR(gadfmt), reqinfo, argarray, NIL);
END EZRequest;


(*$S+*)
PROCEDURE EZRequestTags(bodyfmt : ARRAY OF CHAR; gadfmt : ARRAY OF CHAR;
                        reqinfo : rtReqInfoPtr;
                        argarray : ADDRESS; taglist : TagItemPtr) : LONGINT;
BEGIN
  RETURN EZRequestA(ADR(bodyfmt), ADR(gadfmt), reqinfo, argarray, taglist);
END EZRequestTags;


(*$S+*)
PROCEDURE vEZRequestA(bodyfmt : ARRAY OF CHAR; gadfmt : ARRAY OF CHAR;
                      reqinfo : rtReqInfoPtr;
                      taglist : TagItemPtr; argarray : ADDRESS);
VAR
  ret : LONGINT;
BEGIN
  ret := EZRequestA(ADR(bodyfmt), ADR(gadfmt), reqinfo, argarray, taglist);
END vEZRequestA;


(*$S+*)
PROCEDURE vEZRequest(bodyfmt : ARRAY OF CHAR; gadfmt : ARRAY OF CHAR;
                     reqinfo : rtReqInfoPtr; argarray : ADDRESS);
BEGIN
  vEZRequestA(bodyfmt, gadfmt, reqinfo, NIL, argarray);
END vEZRequest;


(*$S+*)
PROCEDURE GetString(VAR buffer : ARRAY OF CHAR; maxchars : LONGINT;
                    title : ARRAY OF CHAR; reqinfo : rtReqInfoPtr) : BOOLEAN;
BEGIN
  RETURN GetStringA(buffer, maxchars, ADR(title), reqinfo, NIL);
END GetString;


(*$S+*)
PROCEDURE GetLong(VAR longvar : LONGINT; title : ARRAY OF CHAR;
                  reqinfo : rtReqInfoPtr) : BOOLEAN;
BEGIN
  RETURN GetLongA(longvar, ADR(title), reqinfo, NIL);
END GetLong;


(*$S+*)
PROCEDURE FontRequest(fontreq : rtFontRequesterPtr;
                      title : ARRAY OF CHAR) : BOOLEAN;
BEGIN
  RETURN FontRequestA(fontreq, ADR(title), NIL);
END FontRequest;


(*$S+*)
PROCEDURE PaletteRequest(title : ARRAY OF CHAR; reqinfo : rtReqInfoPtr) : LONGINT;
BEGIN
  RETURN PaletteRequestA(ADR(title), reqinfo, NIL);
END PaletteRequest;


PROCEDURE ReqHandler(handlerinfo : rtHandlerInfoPtr; sigs : SignalSet) : LONGINT;
BEGIN
  RETURN ReqHandlerA(handlerinfo, sigs, NIL);
END ReqHandler;


BEGIN
  ReqToolsBase := NIL;
END ReqTools.