PRMKEY.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
10-AUG-81  KGT     New Version of OMSI Pascal V1.2H initializes variable space
                   to 1's.  Fields in the rab, fab and xab have to be init. to
                   0's to accept the default values.  Modifications here 
                   initialize the rab and fab if not done previously and 
                   initialize the xab when a new one is created.  

DESCRIPTION :

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

}

{$E+ External procedure}
{$C
	.TITLE	PRMKEY
	.IDENT	"810810"
}
@prmconst.pas
CONST
@RMSCONST.PAS
TYPE
@RMSTYPE.PAS
@Fab.pas
@rab.Pas
@Xab.pas
@PRMTYPE.PAS
  
{ Define a single key of and indexed file, use in conj. with PrmCre }
{ Define keys in ascending order starting with key 0 definition }
PROCEDURE PRMKey (VAR Filebuf : RmsFileDesc ;
                  VAR KeyBuf : IdxKeyDesc ;
                  VAR Status  : RmsStatus ) ;	{ Prm status }
VAR
  Xptr 		: ^XabRec ;
  NPtr		: ^XabRec ;
  FirstXab 	: BOOLEAN ;
  i		: integer ;

BEGIN
  FirstXab := FALSE ;

  { clear the rab and fab allocated buffer area before using }
  IF FileBuf.Fab.Ctx <> 1   { previous call to PrmKey cleared the buffers? }
    THEN	{ PRMKEY call will set Fab.Ctx after init }
      BEGIN
        FOR i := 1 TO 40 DO	{ 40 = length of the rab and fab buffers }
          BEGIN
            FileBuf.Rab.AllRab[i] := 0 ;
            FileBuf.Fab.AllFab[i] := 0 ;
          END ;
        FileBuf.Fab.Ctx := 1 ;	{ indicate that rab & fab have been cleared }
        FirstXab := TRUE ;	{ this is the first call of prmkey }
      END ;

  XPtr := FileBuf.Fab.Xab ;
  IF XPtr <> Nil 
    THEN	{ get XPtr to point to last xab in the linked list }
      WHILE XPtr^.Nxt <> Nil DO XPtr := XPtr^.Nxt ;

  New ( NPtr ) ;		{ get a new xab }
  FOR i := 1 TO 26 DO NPtr^.AllXab[i] := 0 ;	{ clear the xab }

  IF FirstXab		
    THEN FileBuf.Fab.Xab := NPtr 	{ add it to the fab }
    ELSE XPtr^.Nxt := NPtr ;	{ add it to the end xab }

  WITH NPtr^ DO
  WITH KeyBuf DO
    BEGIN		{ load the xab }
      Nxt := Nil ;
      cod := chr(1) ;	{ indicate this is a key type xab }
      Bln := chr(55) ;	{ size of this xab }

      { load the key of ref. and check for ascending order of load }
      Status[1] := 1 ;
      Ref := chr(KeyNum) ;	
      If FirstXab 
        THEN If KeyNum <> 0 THEN Status[1] := PrKy0 { spec. key 0 first }
        ELSE IF KeyNum-1 <> ord(XPtr^.Ref) THEN Status[1] := PrAsc ;
                          { specify keys in ascending order }

      IF ((ord(KeyNul) > 1) AND (NOT FirstXab))
        THEN 		{ user specified a null key value }
          BEGIN
            Nul := KeyNul ;	
            Flg := chr(ord(Flg) OR XbNul) ;
          END ;
      IF KeyDup = 'Y' THEN Flg := chr(ord(Flg) OR XbDup) ;
      IF ((KeyChg='Y') AND (NOT FirstXab)) 
        THEN Flg := chr(ord(Flg) OR XbChg) ;
      IF KeyTyp = IntKey THEN Dtp := chr(XbIn2) ;	{ signed integer key }
      Pos[1] := KeyPos ;
      Siz[1] := chr(KeySiz) ;
      Nsg := chr(1) ;		{ one segment only, no segmented key supt. }
    END ;
END ;
/
