-- FTPUserHot.mesa, Edit: HGM July 31, 1980  5:34 PM  

-- Copyright  Xerox Corporation 1979, 1980

DIRECTORY
  Inline USING [DIVMOD],
  FTPDefs,
  FTPPrivateDefs;

FTPUserHot: PROGRAM
  IMPORTS Inline, FTPPrivateDefs EXPORTS FTPPrivateDefs SHARES FTPDefs =
  BEGIN OPEN FTPDefs, FTPPrivateDefs;


  -- **********************!  Byte Primitive  !***********************

  AdvanceBytePointer: PUBLIC PROCEDURE [
    bytePointer: BytePointer, byteCount: CARDINAL] =
    BEGIN
    -- local variables
    wordCount: CARDINAL;
    -- update count
    bytePointer.count ← bytePointer.count - byteCount;
    -- update offset
    [wordCount, byteCount] ← Inline.DIVMOD[byteCount, bytesPerWord];
    IF byteCount = 1 THEN bytePointer.offset ← ~bytePointer.offset;
    -- update address
    bytePointer.address ←
      bytePointer.address + wordCount +
	(IF byteCount = 1 AND ~bytePointer.offset THEN 1 ELSE 0);
    END;


  -- **********************!  State Verification Primitive  !***********************

  FTPUserIsNil: ERROR = CODE;

  VerifyPurposeAndState: PUBLIC PROCEDURE [
    ftpuser: FTPUser, expectedPurpose: Purpose, expectedState: UserState] =
    BEGIN OPEN ftpuser;
    IF ftpuser = NIL THEN ERROR FTPUserIsNil;
    -- verify connection purpose
    SELECT expectedPurpose FROM
      files => IF purpose = mail THEN Abort[connectionNotOpenedForFiles];
      mail => IF purpose = files THEN Abort[connectionNotOpenedForMail];
      ENDCASE;
    -- verify connection state
    IF state # expectedState THEN
      Abort[
	IF state = unconnected THEN noConnectionEstablished
	ELSE illegalProcedureCallSequence];
    END;


  END. -- of FTPUserCommon