C+
C	XMITR.FTN
C
C	  XMIT PROGRAM TO TRANSMIT FILES TO AND RECEIVE FILES FROM
C	  REMOTE COMPUTER SYSTEMS
C
C	  WRITTEN BY MICHAEL LAMPI
C
C	  REVISED 2-JAN-79 TO INCLUDE HOOKS FOR TRANSFERRING CHECKSUMMED
C		BINARY FILES   (ROUTINES FOR DOING SO ARE NOT YET
C		IMPLEMENTED)
C
C	    LAST UPDATE 30-OCT-79
C	REVISED BY G. EVERHART FOR IAS V3. USES READ/WRITE INSTEAD
C		OF INPUT AST TO HANDLE TERMINALS; IAS INPUT AST IS
C		NOT SUITABLE.
C
C ==============================================================
C
C	FORMAT OF 'ITRANS' CONTROL WORD:
C
C	BIT 0	- ON = FILE BEING RECEIVED FROM REMOTE (& WRITTEN TO DISK)
C	    1	- ON = FILE BEING TRANSMITTED TO REMOTE (FROM DISK)
C	    2	- ON = ECHO CHARACTERS READ FROM/WRITTEN TO FILES
C	BIT 3	- ON = DUPLEX (ECHO CHARACTERS TYPED AT THE KEYBOARD)
C	    4	- OFF= DO NOT COPY CHARACTERS TYPED AT THE KEYBOARD TO
C		       THE OUTPUT DISK FILE (IF IN THE PROCESS OF RECEIVING
C		       A FILE)
C		  ON = COPY EACH TYPED CHARACTER TO THE RECEIVED FILE
C	    5	- OFF= 7-BIT CHARACTERS WILL BE HANDLED, NO PARITY GENERATED
C		- ON = 8-BIT CHARACTERS WILL BE HANDLED, PARITY CAN BE
C		       GENERATED IF DESIRED
C	BIT 6	- OFF= ASCII (CHARACTER MODE) FILES WILL BE RECEIVED
C		- ON = BINARY FILES WILL BE RECEIVED
C	    7	- OFF= ASCII (CHARACTER MODE) FILES WILL BE TRANSMITTED
C		- ON = BINARY FILES WILL BE TRANSMITTED
C	    8	- OFF= PROMPTLESS FILE TRANSMISSION
C		- ON = PROMPTED TRANSMISSION OF EACH LINE OF DISK FILE INPUT
C
C	BIT 9	- OFF= CONTROL CHARACTERS ARE PASSED TO THE REMOTE
C		- ON = CONTROL CHARACTER TRANSLATION (REDEFINITION) IS
C		       PERFORMED ON ALL CHARACTERS SENT TO THE REMOTE
C	 10-11	- OFF/OFF = NO PARITY
C		- OFF/ON  = EVEN PARITY
C		- ON/OFF  = ODD PARITY
C		- ON/ON   = MARK PARITY (PARITY BIT ALWAYS ON)
C
C	BITS 12-15 ARE CURRENTLY UNUSED
C
C-
	COMMON ISTACK,IEND,ISTCK,IPTR
	COMMON/INPFIL/INPTR,INEND,INPSUM,INYBBL,IDELAY,IPRMPT,ISENT,
     C		      LINEI(256),ICHECK,LENI,IFLAGI,NIREC
	COMMON/CTRL/ CTRL(32),IBREAK
	COMMON/DOTCNT/ IDOTS
	COMMON/OUTFIL/ILINE(256),IPOS,IOTSUM,IONYBL,NOREC,IFLAGO,
     C			LENO
	INTEGER PRVCHR
	LOGICAL*1 ISTACK(8000),CTRL
	DATA IEND/8000/,IDOTS/0/
	DATA CTRL/0,"23,3,13*0,"17,6*0,"21,"32,"25,6*0/
	DATA ISTCK/1/,IPTR/1/
	DATA ICHECK,ISENT,IDELAY/0,0,0/
	DATA ITCHAR/0/,IPRMPT/"15/
C	INITIALIZE FILE FORMAT (0=ASCII) AND TRANSMIT MODE
C	REDEFINE MODE ("1000)	AND UNDUPLEXED
	DATA ITRANS/"1000/
	DATA PRVCHR/0/,IBREAK/-1/
C
C	  NOW SET THE TERMINAL CHARACTERISTICS (UPPER & LOWER CASE,ETC)
	TYPE*,'Terminal Transmission Program V3.3'
	CALL SETUP
C
C	  NOW GO INTO THE CHARACTER-AT-A-TIME LOOP
C	    DETERMINE WHERE INPUT IS COMING FROM
C
 100	CALL TWAIT
	ITCHAR=ITTINR(IDUMMY)
	CALL WTSGEV
	KBD=0
	IF(ITCHAR.LT.0) GOTO 110
C	  IF HE WANTED A BREAK THEN GIVE IT TO HIM
	IF(ITCHAR.NE.IBREAK) GOTO 101
	CALL ABREAK
	GOTO 100
 101	IF(ITCHAR.NE."12.OR.PRVCHR.NE."15) GOTO 102
C	  SEND A LINE-FEED IF NOT IN ECHO MODE AND A FILE IS BEING
C	  TRANSFERRED (OTHERWISE KEYBOARD STUFF GETS OVERWRITTEN)
	IF((ITRANS.AND.4).EQ.0.AND.(ITRANS.AND.3).NE.0) CALL ENQUE("12)
	PRVCHR=ITCHAR
	GOTO 100
C	  SEE IF WE ARE IN TRANSLATE MODE
 102	IF((ITRANS.AND."1000).EQ.0.OR.ITCHAR.GT."37.OR.ITCHAR.EQ."3)
     C		GOTO 104
C	  YES - CHECK IF IN TRANSLATION TABLE
C	  IF IN TABLE, THEN SUBSTITUTE NEW CHAR
	IF(CTRL(ITCHAR+1).EQ.0) GOTO 104
	ITCHAR=CTRL(ITCHAR+1)
	KBD=1
	GOTO 105
 104	PRVCHR=ITCHAR
	KBD=1
	IF(ITCHAR.NE.25.AND.ITCHAR.NE.3) GOTO 105
C THIS ALLOWS CONTROL-Y OR CONTROL-C TO BE ATTN CHAR.
	CALL CTLSUB(ITRANS)
	GOTO 100
 105	IF((ITRANS.AND."10).NE.0) CALL ENQUE(ITCHAR)
 110	IF((ITRANS.AND.1).EQ.0) GOTO 120
	CALL OUTFIL(ITCHAR,ITRANS,1)
 120	IF((ITRANS.AND.2).EQ.0) GOTO 140
	IF(KBD.NE.0.OR.ITCHAR.GE.0) GOTO 140
	CALL INPFIL(ITCHAR,ITRANS,1)
	IF(ITCHAR.LT.0.OR.(ITRANS.AND.1).EQ.0.OR.(ITRANS.AND."20).EQ.0)
     C	  GOTO 140
	CALL OUTFIL(ITCHAR,ITRANS,4)
 140	CONTINUE
	IF(ITCHAR.LT.0) GOTO 300
C	  NOW CHECK IF WE NEED TO SET PARITY
	IF((ITRANS.AND."40).NE.0) GOTO 200
C	  MUST SET PARITY BIT IN 7-BIT MODE
	I=(ITRANS.AND."6000)
	ITCHAR=(ITCHAR.AND."177)
C	  NO PARITY?
	IF(I.EQ.0) GOTO 200
	IF(I.NE."6000) GOTO 150
C	  MARK PARITY
	ITCHAR=ITCHAR+"200
	GOTO 200
 150	J=(ICNT(ITCHAR).AND.1)*"200
	IF(I.NE."2000) GOTO 160
C	  EVEN PARITY
	ITCHAR=ITCHAR+"200-J
	GOTO 200
C	  ODD PARITY
 160	ITCHAR=ITCHAR+J
C
C	  IF WE HAVE A CHARACTER SEND IT TO REMOTE
C
 200	CALL TWAIT
 205	I=IOUTT1(ITCHAR)
C	WAIT FOR A SIG EVENT IF WE CAN'T SEND A CHARACTER
	IF (I.NE.0)CALL WTSGEV
C	IF(I.NE.0) GOTO 205
C
C	  NOW WAIT IDELAY CLOCK TICKS BETWEEN CHARACTERS (MINIMUM)
C
	IF(IDELAY.EQ.0) GOTO 300
	CALL MARK(17,IDELAY,1)
	CALL WAITFR(17)
C
C	  IF TRANSFER IS OK QUEUE UP KEYBOARD CHAR TO SHIP BACK TO
C	   CONSOLE ELSE WAIT FOR REMOTE TO BECOME READY
C
C	  CHECK FOR OUTPUT FROM THE REMOTE
C
 300	CONTINUE
C REMOVE C NEXT. ALLOW INSTANT REPLY FROM REMOTE.
	IF (((ITRANS.AND.1).EQ.1).OR.((ITRANS.AND.2).EQ.2))GOTO 301
	CALL TWAIT
 301	INCHAR=INPTT1(IDUMMY)
	IREM=0
	IF(INCHAR.LT.0) GOTO 310
	IREM=1
C	  REMOVE PARITY BIT IN 7-BIT MODE
	IF((ITRANS.AND."40).EQ.0) INCHAR=INCHAR.AND."177
C	  IF NO FILE I/O THEN ECHO REMOTE'S OUTPUT
	IF((ITRANS.AND.3).EQ.0) CALL ENQUE(INCHAR.AND."177)
 310	IF((ITRANS.AND.1).EQ.0) GOTO 320
	IF(IREM.EQ.0) GOTO 320
	CALL OUTFIL(INCHAR,ITRANS,2)
 320	IF((ITRANS.AND.2).EQ.0) GOTO 340
	IF(IREM.EQ.0) GOTO 340
C MAJOR LOOP FOR INPUT FROM FILE TO REMOTE IS HERE.
C WILL AWAIT ABSENCE OF REPLY FROM REMOTE.
	CALL INPFIL(INCHAR,ITRANS,2)
340	IF(IREM.NE.0) GOTO 300
C
C	  DUMP THE QUEUE TO THE TERMINAL
C
 400	IF(ISTCK.EQ.IPTR) GOTO 100
	IOPTR=IPTR
	IPTR=IPTR+1
	IF(IPTR.GT.IEND) IPTR=1
	INCHAR=ISTACK(IPTR)
	I=ITTOUR(INCHAR)
C
C	  IF WE CAN'T PRINT QUEUE, THEN START THIS LOOP OVER
C
	IF(I.EQ.0) GOTO 400
 420	IPTR=IOPTR
	GOTO 100
	END
