C PCFTP - PR1ME (PRIMOS) END OF PERSONAL COMPUTER FILE TRANSFER PROTOCOL
C DICK GILLMANN, JUNE 1982
      DOUBLE PRECISION WAY
      INTEGER FNAME(6)
      INTEGER*2 LINE(200),TAB,LF,CHAR
$INSERT SYSCOM>A$KEYS
      DATA TAB/:104640/,LF/:105240/
      READ(1,1) FNAME
1     FORMAT(6A4)
      READ(1,2) WAY
2     FORMAT(A8)
      IF(WAY.EQ.'UP') GOTO 1000
C PRIME TO PC
      CALL OPEN$A(A$READ,FNAME,INTS(24),INTS(1))
C MAIN LOOP
200   READ(5,5,ERR=300,END=300) LINE
5     FORMAT(200A1)
      WRITE(1,5) LINE
      GOTO 200
C DONE
300   WRITE(1,6)
6     FORMAT('!E!')
      CALL CLOS$A(INTS(1))
      CALL EXIT
C PC TO PRIME
1000  IF(EXST$A(FNAME,INTS(24))) CALL DELE$A(FNAME,INTS(24))
      CALL OPEN$A(A$WRIT,FNAME,INTS(24),INTS(2))
C MAIN LOOP
1100  DO 1110 I=1,200
1110  LINE(I)=' '
      DO 1120 I=1,200
1115  CALL T1IN(CHAR)
      IF(AND(CHAR,:177).EQ.0) GO TO 1115
      IF(AND(CHAR,:177).EQ.8) GO TO 1122
      CHAR=LS(CHAR,8)+:240
      IF(CHAR.EQ.LF) GO TO 1122
1120  LINE(I)=CHAR
1122  IF(LINE(1).EQ.'!'.AND.LINE(2).EQ.'E'.AND.LINE(3).EQ.'!')
     & GOTO 1200
C EXPAND TABS
      DO 1175 I=1,200
      IF(LINE(I).NE.TAB) GOTO 1175
      J=((I-1)/8)*8 + 9
      N=J-I-1
      IF(N.LE.0) GOTO 1135
      M=201-J
      IF(M.LE.0) GOTO 1135
      DO 1125 K=1,M
      KK=201-K
1125  LINE(KK)=LINE(KK-N)
1135  KK=MIN0(J-1,132)
      DO 1150 K=I,KK
1150  LINE(K)=' '
1175  CONTINUE
      WRITE(6,5) LINE
      GOTO 1100
C DONE
1200  CALL CLOS$A(INTS(2))
      CALL EXIT
      END
