PRMRET.PAS/-AU=
{
DATE : 

AUTHOR : 
     Kenneth G. Tibesar
     3M Engineering Systems and Technology Labs
     3M Center, Bldg 518-1
     St. Paul, Minn. 55144

REVISION HISTORY :

  DATE     BY      DESCRIPTION

08-JUL-81  KGT     Check to see if file has been opened or created properly 
                   before executing the record operation.  An available field
                   in the FAB (CTX) is set to a +1 if PRMOpe or PRMCre
                   was successful.
25-AUG-81  KGT     Reset the RbKgt and RbKge bits for random access.  When EQ
                   record access was selected after a GT or GE access, the
                   bits were never reset and the operation would fail.

29-APR-82  ARO     Added Rbkey option to RAC field of RAB for relative file
		   operations.  Relative get operations were not working.
DESCRIPTION :

ENVIROMENT :          
     DEC PDP-11 
     RSX-11M or RSX-11M+

}

{$E+ External procedure}
{$C
	.TITLE	PRMRET
	.IDENT	"810825"
}
@[300,47]prmconst.pas
CONST
@RMSCONST.PAS
TYPE
@RMSTYPE.PAS
@FAB.PAS
@RAB.PAS
@PRMTYPE.PAS

PROCEDURE PrmRet ( Operation : RecOps ;		{ spec. PGET or PFIND }
                   VAR FileBuf : RmsFileDesc ;	{ spec. the file to access }
                   VAR RetData : RetRecord ;	{ retrieve specifications }
                   VAR RecBuf  : RecDef ;	{ rec. buffer to load }
                   VAR Status  : RmsStatus ) ;	{ STA & STV returned }

VAR
  RecOk	: BOOLEAN ;	{ TRUE if recordsize in Filebuf <> 0 }

BEGIN { RMS High Level Get }

WITH FileBuf DO
BEGIN
IF Fab.Ctx <> 1 
   { Fab loaded by PRMOpe or PRMCre, loaded with -1 or not loaded at all }
  THEN Status[1] := PrIni 	{ file not properly initialized }
  ELSE  
    BEGIN
      Rab.Kbf := @RetData.KeyData ;	{ prt to REL rec # or IDX key data }
      CASE RetData.Search OF
        RFA : 
          BEGIN	
            Rab.Rac := chr(RbRfa) ;
            Rab.Rfa.low := RetData.keynum[1] ;
            Rab.Rfa.middle := RetData.KeyNum[2] ;
            Rab.Rfa.high := RetData.KeyNum[3] ;
          END ;
        NEX : Rab.Rac := chr(RbSeq) ;
        EQ,GE,GT :			{ set-up random key search }
          BEGIN			
            Rab.Rac := chr(RbKey) ;
            Rab.Krf := chr(RetData.KeyNum[1]) ;
            Rab.Ksz := chr(RetData.KeySize) ;
            Rab.Rop := (Rab.Rop AND EqMask ) ; { init. the Kge & Kgt bits }
            IF RetData.Search = GE THEN Rab.Rop := (Rab.Rop OR RbKge) ;
            IF RetData.Search = GT THEN Rab.Rop := (Rab.Rop OR RbKgt) ;
          END ;	{ CASE ... EQ,GE,GT }
        REC :
          BEGIN			
            Rab.Rac := chr(RbKey) ;
	    Rab.Ksz := chr(4)			{ relative file }
	  END;
      END ;	{ CASE }

      Rab.Ubf := @RecBuf ;	{ transfer data to this buffer }

      RecOk := TRUE ;		    { assume user record buffer is o.k. }
      IF RetData.RecSize > 0		
        THEN Rab.Usz := RetData.RecSize { user specified a recordsize }
        ELSE 
          BEGIN
              RecOk := FALSE ;
              Status[1] := PrRsz  ; 	{ invalid rec. sz. during ret }
              Status[2] := RetData.RecSize ;	{ rec. sz. specified }
              RetData.RecSize := 0 ;		{ no record returned }
            END ;

      IF RecOk		{ perform operation if user record buffer is <> 0 }
        THEN
          BEGIN
            IF Operation = PGET
              THEN 
                BEGIN
                {$C
                  .mcall $get
                  mov filebuf(sp), r0	; addr. of filebuf
                  add #rab, r0		; calc addr. of rab in filebuf
                  $get r0		; Get the record
                }
                END
              ELSE 
                BEGIN
                {$C
                  .mcall $find
                  mov filebuf(sp), r0	; addr. of filebuf
                  add #rab, r0		; calc addr. of rab in filebuf
                  $find r0		; locate the record
                }
                END ;
      
           IF RetData.Search <> RFA
              THEN			{ pass back RFA if not RFA access }
                BEGIN
                  RetData.RFAOut[1] := Rab.Rfa.low ;
                  RetData.RFAOut[2] := Rab.Rfa.middle ;
                  RetData.RFAOut[3] := Rab.Rfa.high ;
                END ;
      
            RetData.RecSize := Rab.Rsz ;	{ pass back rec. size }
            Status[1] := Rab.Sts ;
            Status[2] := Rab.Stv ;
         END	{ IF RecOk THEN }
    END ;	{ ELSE }
END ;	{ WITH }
END; { get }
/
